Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-11-02 17:06:30 -0400
committerkmoore2010-11-02 17:06:30 -0400
commitcad6c8cf0ad64fe4743f1854a19e104e5e54cc5c (patch)
tree9a0c38b16412a9c232ca344a15ae21815ef2a7fc
parent1bdd5d40f985fda14d7f1b0a7bd347f45f8dc535 (diff)
downloadwebtools.dali-cad6c8cf0ad64fe4743f1854a19e104e5e54cc5c.tar.gz
webtools.dali-cad6c8cf0ad64fe4743f1854a19e104e5e54cc5c.tar.xz
webtools.dali-cad6c8cf0ad64fe4743f1854a19e104e5e54cc5c.zip
first pass at refactoring ContextContainerTools to hold the collection instead of using static methods
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/ContextContainer.java (renamed from jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/ContextContainerTools.java)109
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java16
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java16
3 files changed, 74 insertions, 67 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/ContextContainerTools.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/ContextContainer.java
index 772bf7a860..47fa74efcb 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/ContextContainerTools.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/ContextContainer.java
@@ -14,54 +14,53 @@ import java.util.Iterator;
import org.eclipse.jpt.jaxb.core.context.JaxbContextNode;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.Tools;
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
/**
- * Utility methods for manipulating context containers.
+ * Adapter used to synchronize a context container with its corresponding
+ * resource container.
+ * @param <C> the type of context elements
+ * @param <R> the type of resource elements
*/
-public class ContextContainerTools {
+public abstract class ContextContainer<C extends JaxbContextNode, R> extends AbstractModel {
+
+
+ protected ContextContainer() {
+ super();
+ }
/**
- * Adapter used to synchronize a context container with its corresponding
- * resource container.
- *
- * @param <C> the type of context elements
- * @param <R> the type of resource elements
+ * Return the container's context elements.
*/
- public interface Adapter<C extends JaxbContextNode, R> {
-
- /**
- * Return the container's context elements.
- */
- Iterable<C> getContextElements();
-
- /**
- * Return the container's current set of resource elements.
- * These are what the context elements will be synchronized to.
- */
- Iterable<R> getResourceElements();
-
- /**
- * Return the resource element corresponding to the specified context
- * element.
- */
- R getResourceElement(C contextElement);
-
- /**
- * Move the specified context element to the specified index.
- */
- void moveContextElement(int index, C element);
-
- /**
- * Add a context element for the specified resource element at the
- * specified index.
- */
- void addContextElement(int index, R resourceElement);
-
- /**
- * Remove the specified context element from the container.
- */
- void removeContextElement(C element);
- }
+ protected abstract Iterable<C> getContextElements();
+
+ /**
+ * Return the container's current set of resource elements.
+ * These are what the context elements will be synchronized to.
+ */
+ protected abstract Iterable<R> getResourceElements();
+
+ /**
+ * Return the resource element corresponding to the specified context
+ * element.
+ */
+ protected abstract R getResourceElement(C contextElement);
+
+ /**
+ * Move the specified context element to the specified index.
+ */
+ protected abstract void moveContextElement(int index, C element);
+
+ /**
+ * Add a context element for the specified resource element at the
+ * specified index.
+ */
+ protected abstract void addContextElement(int index, R resourceElement);
+
+ /**
+ * Remove the specified context element from the container.
+ */
+ protected abstract void removeContextElement(C element);
/**
@@ -76,15 +75,15 @@ public class ContextContainerTools {
* appropriate (as opposed to simply rebuilding them in place).
* </ul>
*/
- public static <C extends JaxbContextNode, R> void synchronizeWithResourceModel(Adapter<C, R> adapter) {
- sync(adapter, true); // true = sync
+ public void synchronizeWithResourceModel() {
+ sync(true); // true = sync
}
/**
* @see #synchronizeWithResourceModel(Adapter)
*/
- public static <C extends JaxbContextNode, R> void update(Adapter<C, R> adapter) {
- sync(adapter, false); // false = update
+ public void update() {
+ sync(false); // false = update
}
/**
@@ -92,17 +91,17 @@ public class ContextContainerTools {
* context nodes are either <em>synchronized</em> (<code>true</code>) or
* <em>updated</em> (<code>false</code>).
*/
- protected static <C extends JaxbContextNode, R> void sync(Adapter<C, R> adapter, boolean sync) {
- HashSet<C> contextElements = CollectionTools.set(adapter.getContextElements());
+ protected void sync(boolean sync) {
+ HashSet<C> contextElements = CollectionTools.set(this.getContextElements());
int resourceIndex = 0;
- for (R resourceElement : adapter.getResourceElements()) {
+ for (R resourceElement : this.getResourceElements()) {
boolean match = false;
for (Iterator<C> stream = contextElements.iterator(); stream.hasNext(); ) {
C contextElement = stream.next();
- if (Tools.valuesAreEqual(adapter.getResourceElement(contextElement), resourceElement)) {
+ if (Tools.valuesAreEqual(this.getResourceElement(contextElement), resourceElement)) {
// we don't know the source index because the element has been moved by previously moved elements
- adapter.moveContextElement(resourceIndex, contextElement);
+ this.moveContextElement(resourceIndex, contextElement);
stream.remove();
if (sync) {
contextElement.synchronizeWithResourceModel();
@@ -117,18 +116,14 @@ public class ContextContainerTools {
// added elements are sync'ed during construction or will be
// updated during the next "update" (which is triggered by
// their addition to the model)
- adapter.addContextElement(resourceIndex, resourceElement);
+ this.addContextElement(resourceIndex, resourceElement);
}
resourceIndex++;
}
// remove any leftover context elements
for (C contextElement : contextElements) {
- adapter.removeContextElement(contextElement);
+ this.removeContextElement(contextElement);
}
}
- private ContextContainerTools() {
- super();
- throw new UnsupportedOperationException();
- }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
index b1eb7d2790..1c59bc02e3 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/GenericRootContextNode.java
@@ -30,7 +30,7 @@ public class GenericRootContextNode
/* Main context objects. */
protected final Vector<JaxbPackage> packages = new Vector<JaxbPackage>();
- protected final PackageContainerAdapter packageContainerAdapter = new PackageContainerAdapter();
+ protected final PackageContainer packageContainer = new PackageContainer();
public GenericRootContextNode(JaxbProject jaxbProject) {
@@ -103,13 +103,13 @@ public class GenericRootContextNode
}
protected void syncPackages() {
- ContextContainerTools.synchronizeWithResourceModel(this.packageContainerAdapter);
+ this.packageContainer.synchronizeWithResourceModel();
}
protected void updatePackages() {
//In this case we need to actually "sync" the list of packages since this is dependent on JaxbFiles
//and an update will be called when jaxb files are added/removed, not a synchronizeWithResourceModel
- ContextContainerTools.update(this.packageContainerAdapter);
+ this.packageContainer.update();
}
protected JaxbPackage buildPackage(JavaResourcePackage resourcePackage) {
@@ -120,24 +120,30 @@ public class GenericRootContextNode
/**
* package container adapter
*/
- protected class PackageContainerAdapter
- implements ContextContainerTools.Adapter<JaxbPackage, JavaResourcePackage>
+ protected class PackageContainer
+ extends ContextContainer<JaxbPackage, JavaResourcePackage>
{
+ @Override
public Iterable<JaxbPackage> getContextElements() {
return GenericRootContextNode.this.getPackages();
}
+ @Override
public Iterable<JavaResourcePackage> getResourceElements() {
return GenericRootContextNode.this.getJaxbProject().getAnnotatedJavaResourcePackages();
}
+ @Override
public JavaResourcePackage getResourceElement(JaxbPackage contextElement) {
return contextElement.getResourcePackage();
}
+ @Override
public void moveContextElement(int index, JaxbPackage element) {
//ignore since we don't need order for packages
}
+ @Override
public void addContextElement(int index, JavaResourcePackage resourceElement) {
GenericRootContextNode.this.addPackage(resourceElement);
}
+ @Override
public void removeContextElement(JaxbPackage element) {
GenericRootContextNode.this.removePackage(element);
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
index af2bfb53f9..d3ebd1dfba 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
@@ -15,7 +15,7 @@ import org.eclipse.jpt.jaxb.core.context.XmlNs;
import org.eclipse.jpt.jaxb.core.context.XmlNsForm;
import org.eclipse.jpt.jaxb.core.context.XmlSchema;
import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
-import org.eclipse.jpt.jaxb.core.internal.context.ContextContainerTools;
+import org.eclipse.jpt.jaxb.core.internal.context.ContextContainer;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation;
@@ -36,7 +36,7 @@ public class GenericJavaXmlSchema
protected XmlNsForm specifiedElementFormDefault;
protected final Vector<XmlNs> xmlNsPrefixes = new Vector<XmlNs>();
- protected final XmlNsPrefixContainerAdapter xmlNsPrefixContainerAdapter = new XmlNsPrefixContainerAdapter();
+ protected final XmlNsPrefixContainer xmlNsPrefixContainer = new XmlNsPrefixContainer();
public GenericJavaXmlSchema(JaxbPackageInfo parent) {
super(parent);
@@ -240,7 +240,7 @@ public class GenericJavaXmlSchema
}
protected void syncXmlNsPrefixes() {
- ContextContainerTools.synchronizeWithResourceModel(this.xmlNsPrefixContainerAdapter);
+ this.xmlNsPrefixContainer.synchronizeWithResourceModel();
}
protected Iterable<XmlNsAnnotation> getXmlNsAnnotations() {
@@ -265,24 +265,30 @@ public class GenericJavaXmlSchema
/**
* xml ns prefix container adapter
*/
- protected class XmlNsPrefixContainerAdapter
- implements ContextContainerTools.Adapter<XmlNs, XmlNsAnnotation>
+ protected class XmlNsPrefixContainer
+ extends ContextContainer<XmlNs, XmlNsAnnotation>
{
+ @Override
public Iterable<XmlNs> getContextElements() {
return GenericJavaXmlSchema.this.getXmlNsPrefixes();
}
+ @Override
public Iterable<XmlNsAnnotation> getResourceElements() {
return GenericJavaXmlSchema.this.getXmlSchemaAnnotation().getXmlns();
}
+ @Override
public XmlNsAnnotation getResourceElement(XmlNs contextElement) {
return contextElement.getResourceXmlNs();
}
+ @Override
public void moveContextElement(int index, XmlNs element) {
GenericJavaXmlSchema.this.moveXmlNsPrefix_(index, element);
}
+ @Override
public void addContextElement(int index, XmlNsAnnotation resourceElement) {
GenericJavaXmlSchema.this.addXmlNsPrefix_(index, resourceElement);
}
+ @Override
public void removeContextElement(XmlNs element) {
GenericJavaXmlSchema.this.removeXmlNsPrefix_(element);
}

Back to the top