|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.schema2beans; import java.util.*; import java.beans.*; /** * The intent of this class is to provide a schema2beans graph registry, * where the graphs are stored by unique name and type. Combined with * the DDRegistryParser, the DDRegistry provides a sort of meta-schema2beans * graph where we can ask for all the graphs of one type and ask for a * parser on any set of graphs. These are the two main goals of this class. * * 1. provide a common and central place where we can keep track * of all the graphs that we have created. Naming the graphs by * unique name and type allows to get either one specific graph * or a set of graphs. * * 2. provide a meta-schema2beans graph view for parsing any set of graphs. * For example, to get a parser on all the graphs of type 'ejb' * (assuming we registered graphs of this type). * * Therefore, this class provides two kind of methods: to add/remove graphs * to the registry and to create a DDRegistry parser. A DDRegistryParser is * an Iterator that returns all the elements described a schema2beans tree path. * * The registry also provides a convenient class (DDChangeMarker) that helps * keeping track of any change. */ public class DDRegistry extends Object { /** * The goal of this class is to provide a simple way to know if a graph * or a set of graphs had their content changed. The ChangeMarker can * be used to implemenent a cache mechanism, in order to avoid parsing * the graphs if nothing in the graph changed since the last parsing. * * A ChangeMarker is created by the registry, ddReg.newChangeMarker(). * We can add to the changeMarger a BaseBean graph, a Cursor or another * ChangeMarker. So, ChangeMarker can be nested, and any modification in * a nested ChangeMarker would need that the upper ChangeMarker have been * been modified. */ public static class DDChangeMarker { private DDRegistry reg; private long timestamp; private ArrayList elts = null; DDChangeMarker(DDRegistry reg) { this.reg = reg; this.elts = new ArrayList(); this.timestamp = 0L; } public int size() { return this.elts.size(); } /** * If any graph of the added marker change, the current marker is * also considered changed. */ public void add(DDChangeMarker cm) { if (cm == this) { Thread.dumpStack(); } this.elts.add(cm); } /** * Add a graph to the marker list. If any change occurs in this graph * after resetMarker() is called, hasChanged() would return true. */ public void add(BaseBean b) { RegEntry re = this.reg.getRegEntry(b, false); if (re != null && !this.elts.contains(re)) { this.elts.add(re); } } /** * Add the graph the cursor belongs to, to the marker list */ public void add(DDRegistryParser.DDCursor c) { String id = this.reg.getID(c); if (id != null) { BaseBean b = this.reg.getRoot(id); this.add(b); } } /** * removal methods. */ public void remove(DDChangeMarker cm) { this.elts.remove(cm); } public void remove(BaseBean b) { RegEntry re = this.reg.getRegEntry(b, false); if (re != null) this.elts.remove(re); } public void remove(DDRegistryParser.DDCursor c) { String id = this.reg.getID(c); if (id != null) { BaseBean b = this.reg.getRoot(id); this.remove(b); } } /** * Reset the marke change time. Any change that happened before now * are ignored. */ public void resetTime() { this.timestamp = System.currentTimeMillis(); } /** * Return true if a change event happen between the last resetTime * and now. */ public boolean hasChanged() { boolean b = this.hasChanged(this.timestamp); return b; } private boolean hasChanged(long ts) { for(int i=0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.