001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.catalog;
018:
019: import java.io.IOException;
020: import java.util.Collections;
021: import java.util.EnumSet;
022: import java.util.List;
023:
024: /**
025: * Constants used to communicate Catalog Deltas.
026: * <p>
027: * For those familiar with IResourceChangeEvent and IResourceDelta from eclipse development there is
028: * one <b>important addition</b>. The constant REPLACE indicates a reaname, or substiution, you
029: * will need to replace any references you have to the oldObject with the newObject.
030: * </p>
031: * <p>
032: * For "bit mask" style interation please use: <code>EnumSet.of(Kind.ADDED, Kind.REPLACED)</code>
033: * </p>
034: *
035: * @author Jody Garnett
036: * @since 0.6.0
037: */
038: public interface IResolveDelta {
039: /** List indicating no children are present */
040: public static final List<IResolveDelta> NO_CHILDREN = Collections
041: .emptyList();
042:
043: /**
044: * Kind of Delta, used to indicate change.
045: *
046: * @author jgarnett
047: * @since 0.9.0
048: */
049: public enum Kind {
050: /**
051: * Delta kind constant indicating no change.
052: *
053: * @see getKind()
054: */
055: NO_CHANGE,
056:
057: /**
058: * The resource has been added to the catalog.
059: *
060: * @see getKind()
061: */
062: ADDED,
063:
064: /**
065: * The resource has been removed from the catalog.
066: *
067: * @see getKind()
068: */
069: REMOVED,
070:
071: /**
072: * The resource has been changed. getvalues will have values.
073: *
074: * @see getKind()
075: */
076: CHANGED,
077:
078: /**
079: * The resource has been replaced with another entry in the catalog.
080: *
081: * @see getKind()
082: */
083: REPLACED,
084: }
085:
086: /**
087: * Returns the kind of this delta.
088: * <p>
089: * Normally, one of <code>ADDED</code>, <code>REMOVED</code>, <code>CHANGED</code> or
090: * <code>REPLACED</code>.
091: * </p>
092: * <p>
093: * This set is still open, during shutdown we may throw a few more kinds around. Eclipse makes
094: * use of PHANTOM, and NON_PHANTOM not sure we care
095: * </p>
096: *
097: * @return the kind of this resource delta
098: * @see Kind.ADDED
099: * @see Kind.REMOVED
100: * @see Kind.CHANGED
101: * @see Kind.REPLACED
102: */
103: public Kind getKind();
104:
105: /**
106: * Accepts the given visitor.
107: * <p>
108: * The only kinds of resource delta that our visited are ADDED, REMOVED, CHANGED and REPLACED.
109: * </p>
110: * <p>
111: * This is a convenience method, equivalent to accepts( visitor, IService.NONE )
112: * </p>
113: *
114: * @param visitor
115: * @throws CoreException
116: */
117: public void accept(IResolveDeltaVisitor visitor) throws IOException;
118:
119: /**
120: * Resource deltas for all added, removed, changed, or replaced.
121: * <p>
122: * This is a short cut for:
123: *
124: * <pre><code>
125: * finally List list = new ArrayList();
126: * accept( IServiceDeltaVisitor() {
127: * public boolean visit(IResolveDelta delta) {
128: * switch (delta.getKind()) {
129: * case IDelta.ADDED :
130: * case IDelta.REMOVED :
131: * case IDelta.CHANGED :
132: * case IDelta.REPLACED :
133: * list.add( delta );
134: * default: // ignore
135: * }
136: * return true;
137: * }
138: * });
139: * return list.toArray();
140: * </code></pre>
141: *
142: * </p>
143: */
144: public List<IResolveDelta> getChildren();
145:
146: /**
147: * Finds and returns the delta information for a given resource.
148: *
149: * @kindMask Set of IDelta.Kind
150: * @return Array of IGeoResourceDelta
151: */
152: public List<IResolveDelta> getChildren(EnumSet<Kind> kindMask);
153:
154: /**
155: * Returns a handle for the affected handle.
156: * <p>
157: * For additions (<code>ADDED</code>), this handle describes the newly-added resolve; i.e.,
158: * the one in the "after" state.
159: * <p>
160: * For changes (<code>CHANGED</code>), this handle also describes the resource in the
161: * "after" state.
162: * <p>
163: * For removals (<code>REMOVED</code>), this handle describes the resource in the "before"
164: * state. Even though this handle not normally exist in the current workspace, the type of
165: * resource that was removed can be determined from the handle.
166: * <p>
167: * For removals (<code>REPLACE</code>), this handle describes the resource in the "before"
168: * state. The new handle can be determined with getNewResolve().
169: * <p>
170: *
171: * @return the affected resource (handle)
172: */
173: public IResolve getResolve();
174:
175: /**
176: * For replacement (<code>REPLACE</code>), this handle describes the resource in the "after"
177: * state. The old handle can be determined with getResolve().
178: * <p>
179: *
180: * @return The new resolve replacing the affected handle.
181: */
182: public IResolve getNewResolve();
183:
184: /**
185: * If {@link #getKind()}==Kind.CHANGED this method returns the new value of the item changed for example the new bounds of the IGeoResource.
186: * Otherwise it will return null.
187: *
188: * @return If {@link #getKind()}==Kind.CHANGED this method returns the new value of the item changed, otherwise it will return null.
189: */
190: public Object getNewValue();
191:
192: /**
193: * If {@link #getKind()}==Kind.CHANGED this method returns the old value of the item changed for example the old bounds of the IGeoResource.
194: * Otherwise it will return null.
195: *
196: * @return If {@link #getKind()}==Kind.CHANGED this method returns the old value of the item changed, otherwise it will return null.
197: */
198: public Object getOldValue();
199: }
|