Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-11-22 12:01:02 -0500
committerkmoore2010-11-22 12:01:02 -0500
commita79c013a97a2982dc5dfb16758579b0d44a8fe0f (patch)
treef13633968708c404d9a05ee92cf4095b17c51dda
parent8ada8a51a9c2f73516b44a130790ccc1323498c3 (diff)
downloadwebtools.dali-a79c013a97a2982dc5dfb16758579b0d44a8fe0f.tar.gz
webtools.dali-a79c013a97a2982dc5dfb16758579b0d44a8fe0f.tar.xz
webtools.dali-a79c013a97a2982dc5dfb16758579b0d44a8fe0f.zip
refactored context collection/list containers to support context model that is not a JaxbContextNode, ie: Strings
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java128
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java16
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java6
3 files changed, 128 insertions, 22 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
index 2723279592..9286879a1e 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java
@@ -117,7 +117,7 @@ public abstract class AbstractJaxbNode
protected JaxbPlatform getJaxbPlatform() {
return this.getJaxbProject().getJaxbPlatform();
}
-
+
// protected JaxbPlatform.Version getJaxbPlatformVersion() {
// return this.getJaxbPlatform().getJaxbPlatformVersion();
// }
@@ -185,14 +185,14 @@ public abstract class AbstractJaxbNode
}
}
-
+
/**
* Adapter used to synchronize a context collection container with its corresponding
* resource container.
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class CollectionContainer<C extends JaxbContextNode, R> {
+ protected abstract class CollectionContainer<C, R> {
protected final Vector<C> contextElements = new Vector<C>();
@@ -248,14 +248,14 @@ public abstract class AbstractJaxbNode
* specified index.
*/
public C addContextElement(int index, R resourceElement) {
- return this.addContextElement(index, this.buildContextElement(resourceElement));
+ return this.addContextElement_(index, this.buildContextElement(resourceElement));
}
/**
* Add the specified context element to the collection ignoring
* the specified index as we only have a collection
*/
- protected C addContextElement(@SuppressWarnings("unused") int index, C contextElement) {
+ protected C addContextElement_(@SuppressWarnings("unused") int index, C contextElement) {
AbstractJaxbNode.this.addItemToCollection(contextElement, this.contextElements, this.getContextElementsPropertyName());
return contextElement;
}
@@ -263,7 +263,7 @@ public abstract class AbstractJaxbNode
/**
* Remove the specified context element from the container.
*/
- protected void removeContextElement(C element) {
+ public void removeContextElement(C element) {
AbstractJaxbNode.this.removeItemFromCollection(element, this.contextElements, this.getContextElementsPropertyName());
}
@@ -271,7 +271,19 @@ public abstract class AbstractJaxbNode
protected void moveContextElement(int index, C element) {
//no-op, not a list
}
+ }
+ /**
+ * Adapter used to synchronize a context collection container with its corresponding
+ * resource container.
+ * @param <C> the type of context elements
+ * @param <R> the type of resource elements
+ */
+ protected abstract class ContextCollectionContainer<C extends JaxbContextNode, R> extends CollectionContainer<C, R> {
+
+ protected ContextCollectionContainer() {
+ super();
+ }
/**
* Using the specified adapter, synchronize a context container with its
@@ -336,16 +348,16 @@ public abstract class AbstractJaxbNode
}
}
}
-
+
/**
* Adapter used to synchronize a context list container with its corresponding
* resource container.
* @param <C> the type of context elements
* @param <R> the type of resource elements
*/
- protected abstract class ListContainer<C extends JaxbContextNode, R>
+ protected abstract class ListContainer<C, R>
extends CollectionContainer<C, R> {
-
+
protected ListContainer() {
super();
}
@@ -355,6 +367,9 @@ public abstract class AbstractJaxbNode
return new LiveCloneListIterable<C>(this.contextElements);
}
+ @Override
+ protected abstract ListIterable<R> getResourceElements();
+
/**
* Return the index of the specified context element.
*/
@@ -362,12 +377,16 @@ public abstract class AbstractJaxbNode
return this.contextElements.indexOf(contextElement);
}
+ public C contextElementAt(int index) {
+ return this.contextElements.elementAt(index);
+ }
+
/**
* Add a context element for the specified resource element at the
* specified index.
*/
@Override
- protected C addContextElement(int index, C contextElement) {
+ protected C addContextElement_(int index, C contextElement) {
AbstractJaxbNode.this.addItemToList(index, contextElement, this.contextElements, this.getContextElementsPropertyName());
return contextElement;
}
@@ -384,7 +403,94 @@ public abstract class AbstractJaxbNode
* Move the specified context element to the specified index.
*/
@Override
- protected void moveContextElement(int index, C element) {
+ public void moveContextElement(int index, C element) {
+ AbstractJaxbNode.this.moveItemInList(index, element, this.contextElements, this.getContextElementsPropertyName());
+ }
+
+ /**
+ * Remove the context element at the specified index from the container.
+ */
+ public void removeContextElement(int index) {
+ AbstractJaxbNode.this.removeItemFromList(index, this.contextElements, this.getContextElementsPropertyName());
+ }
+
+ public void synchronizeWithResourceModel() {
+ ListIterable<R> resourceElements = getResourceElements();
+
+ int index = 0;
+ for (R resourceElement : resourceElements) {
+ if (this.getContextElementsSize() > index) {
+ if (this.contextElementAt(index) != resourceElement) {
+ this.addContextElement(index, resourceElement);
+ }
+ }
+ else {
+ this.addContextElement(index, resourceElement);
+ }
+ index++;
+ }
+
+ for ( ; index < this.getContextElementsSize(); ) {
+ this.removeContextElement(index);
+ }
+ }
+ }
+
+ /**
+ * Adapter used to synchronize a context list container with its corresponding
+ * resource container.
+ * @param <C> the type of context elements
+ * @param <R> the type of resource elements
+ */
+ protected abstract class ContextListContainer<C extends JaxbContextNode, R>
+ extends ContextCollectionContainer<C, R> {
+
+ protected ContextListContainer() {
+ super();
+ }
+
+ @Override
+ public ListIterable<C> getContextElements() {
+ return new LiveCloneListIterable<C>(this.contextElements);
+ }
+
+ @Override
+ protected abstract ListIterable<R> getResourceElements();
+
+ /**
+ * Return the index of the specified context element.
+ */
+ public int indexOfContextElement(C contextElement) {
+ return this.contextElements.indexOf(contextElement);
+ }
+
+ public C contextElementAt(int index) {
+ return this.contextElements.elementAt(index);
+ }
+
+ /**
+ * Add a context element for the specified resource element at the
+ * specified index.
+ */
+ @Override
+ protected C addContextElement_(int index, C contextElement) {
+ AbstractJaxbNode.this.addItemToList(index, contextElement, this.contextElements, this.getContextElementsPropertyName());
+ return contextElement;
+ }
+
+ /**
+ * Move the context element at the specified target index to the
+ * specified source index.
+ */
+ public void moveContextElement(int targetIndex, int sourceIndex) {
+ this.moveContextElement(targetIndex, this.contextElements.get(sourceIndex));
+ }
+
+ /**
+ * Move the specified context element to the specified index.
+ */
+ @Override
+ public void moveContextElement(int index, C element) {
AbstractJaxbNode.this.moveItemInList(index, element, this.contextElements, this.getContextElementsPropertyName());
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java
index 3329a9c12f..03422c80da 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaPackageInfo.java
@@ -185,8 +185,8 @@ public class GenericJavaPackageInfo
}
@SuppressWarnings("unchecked")
- protected Iterable<XmlSchemaTypeAnnotation> getXmlSchemaTypeAnnotations() {
- return (Iterable<XmlSchemaTypeAnnotation>) this.resourcePackage.getAnnotations(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
+ protected ListIterable<XmlSchemaTypeAnnotation> getXmlSchemaTypeAnnotations() {
+ return (ListIterable<XmlSchemaTypeAnnotation>) this.resourcePackage.getAnnotations(XmlSchemaTypeAnnotation.ANNOTATION_NAME);
}
@@ -228,15 +228,15 @@ public class GenericJavaPackageInfo
}
@SuppressWarnings("unchecked")
- protected Iterable<XmlJavaTypeAdapterAnnotation> getXmlJavaTypeAdapterAnnotations() {
- return (Iterable<XmlJavaTypeAdapterAnnotation>) this.resourcePackage.getAnnotations(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
+ protected ListIterable<XmlJavaTypeAdapterAnnotation> getXmlJavaTypeAdapterAnnotations() {
+ return (ListIterable<XmlJavaTypeAdapterAnnotation>) this.resourcePackage.getAnnotations(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME);
}
/**
* xml schema type container
*/
protected class XmlSchemaTypeContainer
- extends ListContainer<XmlSchemaType, XmlSchemaTypeAnnotation>
+ extends ContextListContainer<XmlSchemaType, XmlSchemaTypeAnnotation>
{
@Override
protected String getContextElementsPropertyName() {
@@ -247,7 +247,7 @@ public class GenericJavaPackageInfo
return GenericJavaPackageInfo.this.buildXmlSchemaType(resourceElement);
}
@Override
- protected Iterable<XmlSchemaTypeAnnotation> getResourceElements() {
+ protected ListIterable<XmlSchemaTypeAnnotation> getResourceElements() {
return GenericJavaPackageInfo.this.getXmlSchemaTypeAnnotations();
}
@Override
@@ -260,7 +260,7 @@ public class GenericJavaPackageInfo
* xml java type adapter container
*/
protected class XmlJavaTypeAdapterContainer
- extends ListContainer<XmlJavaTypeAdapter, XmlJavaTypeAdapterAnnotation>
+ extends ContextListContainer<XmlJavaTypeAdapter, XmlJavaTypeAdapterAnnotation>
{
@Override
protected String getContextElementsPropertyName() {
@@ -271,7 +271,7 @@ public class GenericJavaPackageInfo
return GenericJavaPackageInfo.this.buildXmlJavaTypeAdapter(resourceElement);
}
@Override
- protected Iterable<XmlJavaTypeAdapterAnnotation> getResourceElements() {
+ protected ListIterable<XmlJavaTypeAdapterAnnotation> getResourceElements() {
return GenericJavaPackageInfo.this.getXmlJavaTypeAdapterAnnotations();
}
@Override
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 b91dfcd4e2..3b78581597 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
@@ -221,7 +221,7 @@ public class GenericJavaXmlSchema
this.xmlNsPrefixContainer.synchronizeWithResourceModel();
}
- protected Iterable<XmlNsAnnotation> getXmlNsAnnotations() {
+ protected ListIterable<XmlNsAnnotation> getXmlNsAnnotations() {
return getXmlSchemaAnnotation().getXmlns();
}
@@ -230,7 +230,7 @@ public class GenericJavaXmlSchema
* xml ns prefix container adapter
*/
protected class XmlNsPrefixContainer
- extends ListContainer<XmlNs, XmlNsAnnotation>
+ extends ContextListContainer<XmlNs, XmlNsAnnotation>
{
@Override
protected String getContextElementsPropertyName() {
@@ -241,7 +241,7 @@ public class GenericJavaXmlSchema
return GenericJavaXmlSchema.this.buildXmlNs(resourceElement);
}
@Override
- protected Iterable<XmlNsAnnotation> getResourceElements() {
+ protected ListIterable<XmlNsAnnotation> getResourceElements() {
return GenericJavaXmlSchema.this.getXmlNsAnnotations();
}
@Override

Back to the top