Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-11-02 15:31:15 -0400
committerkmoore2010-11-02 15:31:15 -0400
commit1bdd5d40f985fda14d7f1b0a7bd347f45f8dc535 (patch)
tree407d5c6dcbaca50f199236ec19678f1b615cdcbe
parent76ef3920822f59fe02978808600a793896d78bce (diff)
downloadwebtools.dali-1bdd5d40f985fda14d7f1b0a7bd347f45f8dc535.tar.gz
webtools.dali-1bdd5d40f985fda14d7f1b0a7bd347f45f8dc535.tar.xz
webtools.dali-1bdd5d40f985fda14d7f1b0a7bd347f45f8dc535.zip
Added XmlSchema xmlns context model support along with tests
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNs.java41
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchema.java14
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java7
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java7
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java5
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java113
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java114
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlSchemaAnnotation.java15
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlNsAnnotation.java50
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlNsAnnotation.java12
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java329
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/AbstractModel.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/ChangeSupport.java9
15 files changed, 685 insertions, 53 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java
index d1761cda27..74a7fafd62 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/JaxbFactory.java
@@ -18,8 +18,10 @@ import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
+import org.eclipse.jpt.jaxb.core.context.XmlNs;
import org.eclipse.jpt.jaxb.core.context.XmlSchema;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
/**
* Use a JAXB factory to build any core (e.g. {@link JaxbProject})
@@ -87,4 +89,6 @@ public interface JaxbFactory
JaxbPackageInfo buildJavaPackageInfo(JaxbPackage parent, JavaResourcePackage resourcePackage);
XmlSchema buildJavaXmlSchema(JaxbPackageInfo parent);
+
+ XmlNs buildJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation);
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNs.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNs.java
new file mode 100644
index 0000000000..c83049ccc9
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlNs.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.context;
+
+import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
+
+/**
+ *
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 3.0
+ * @since 3.0
+ */
+public interface XmlNs
+ extends
+ JaxbContextNode
+{
+ XmlNsAnnotation getResourceXmlNs();
+
+ // ********** namespaceURI **********
+ String getNamespaceURI();
+ void setNamespaceURI(String namespaceURI);
+ String NAMESPACE_URI_PROPERTY = "namespaceURI"; //$NON-NLS-1$
+
+ // ********** prefix **********
+ String getPrefix();
+ void setPrefix(String prefix);
+ String PREFIX_PROPERTY = "prefix"; //$NON-NLS-1$
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchema.java
index 7eabe8e387..10ecf31a6c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchema.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchema.java
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.jaxb.core.context;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+
/**
*
* <p>
@@ -124,5 +126,15 @@ public interface XmlSchema
*/
String SPECIFIED_ELEMENT_FROM_DEFAULT_PROPERTY = "specifiedElementFormDefault"; //$NON-NLS-1$
-// * xmlns - @XmlNs array; specifies prefixes for namespaces involved in XML instances representing this package; default is no prefixes
+
+ // ********** xml namespace prefixes **********
+
+ ListIterable<XmlNs> getXmlNsPrefixes();
+ int getXmlNsPrefixesSize();
+ XmlNs addXmlNsPrefix(int index);
+ void removeXmlNsPrefix(int index);
+ void removeXmlNsPrefix(XmlNs xmlNsPrefix);
+ void moveXmlNsPrefix(int targetIndex, int sourceIndex);
+ String XML_NS_PREFIXES_LIST = "xmlNsPrefixes"; //$NON-NLS-1$
+
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java
index 008ff3d3ee..ffc294a62c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbFactory.java
@@ -19,12 +19,15 @@ import org.eclipse.jpt.jaxb.core.JaxbProject.Config;
import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.JaxbRootContextNode;
+import org.eclipse.jpt.jaxb.core.context.XmlNs;
import org.eclipse.jpt.jaxb.core.context.XmlSchema;
import org.eclipse.jpt.jaxb.core.internal.context.GenericPackage;
import org.eclipse.jpt.jaxb.core.internal.context.GenericRootContextNode;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaPackageInfo;
+import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaXmlNs;
import org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaXmlSchema;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
/**
* Central class that allows extenders to easily replace implementations of
@@ -67,4 +70,8 @@ public abstract class AbstractJaxbFactory
public XmlSchema buildJavaXmlSchema(JaxbPackageInfo parent) {
return new GenericJavaXmlSchema(parent);
}
+
+ public XmlNs buildJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation) {
+ return new GenericJavaXmlNs(parent, xmlNsAnnotation);
+ }
}
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 757b76797e..9d5ac555fc 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
@@ -20,6 +20,7 @@ import org.eclipse.jpt.jaxb.core.JaxbFactory;
import org.eclipse.jpt.jaxb.core.JaxbFile;
import org.eclipse.jpt.jaxb.core.JaxbNode;
import org.eclipse.jpt.jaxb.core.JaxbProject;
+import org.eclipse.jpt.jaxb.core.context.JaxbContextNode;
import org.eclipse.jpt.jaxb.core.platform.JaxbPlatform;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
import org.eclipse.jpt.utility.internal.model.CallbackChangeSupport;
@@ -122,6 +123,12 @@ public abstract class AbstractJaxbNode
return this.getJaxbProject().getJaxbFile(file);
}
+ protected void updateNodes(Iterable<? extends JaxbContextNode> nodes) {
+ for (JaxbContextNode node : nodes) {
+ node.update();
+ }
+ }
+
// ********** CallbackChangeSupport.Listener support **********
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
index 8379c872d9..085844fad3 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbProject.java
@@ -34,7 +34,6 @@ import org.eclipse.jpt.core.JpaResourceModelListener;
import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.internal.utility.PlatformTools;
import org.eclipse.jpt.core.resource.ResourceLocator;
-import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
import org.eclipse.jpt.jaxb.core.JaxbFile;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
@@ -705,8 +704,8 @@ public abstract class AbstractJaxbProject
})
{
@Override
- protected boolean accept(JavaResourcePackage packageInfo) {
- return packageInfo != null;
+ protected boolean accept(JavaResourcePackage resourcePackage) {
+ return resourcePackage != null;
}
};
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java
new file mode 100644
index 0000000000..585e4809af
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal.context.java;
+
+import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
+import org.eclipse.jpt.jaxb.core.context.XmlNs;
+import org.eclipse.jpt.jaxb.core.context.XmlSchema;
+import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
+import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
+
+public class GenericJavaXmlNs
+ extends AbstractJaxbContextNode
+ implements XmlNs
+{
+
+ protected final XmlNsAnnotation resourceXmlNs;
+
+ protected String namespaceURI;
+
+ protected String prefix;
+
+ public GenericJavaXmlNs(XmlSchema parent, XmlNsAnnotation xmlNsAnnotation) {
+ super(parent);
+ this.resourceXmlNs = xmlNsAnnotation;
+ this.namespaceURI = this.getResourceNamespaceURI();
+ this.prefix = this.getResourcePrefix();
+ }
+
+ public XmlNsAnnotation getResourceXmlNs() {
+ return this.resourceXmlNs;
+ }
+
+ // ********** synchronize/update **********
+
+ public void synchronizeWithResourceModel() {
+ this.setNamespaceURI_(this.getResourceNamespaceURI());
+ this.setPrefix_(this.getResourcePrefix());
+ }
+
+ public void update() {
+ //nothing yet
+ }
+
+
+ @Override
+ public JaxbPackageInfo getParent() {
+ return (JaxbPackageInfo) super.getParent();
+ }
+
+ protected JavaResourcePackage getResourcePackage() {
+ return getParent().getResourcePackage();
+ }
+
+
+ // ********** namespaceURI **********
+
+ public String getNamespaceURI() {
+ return this.namespaceURI;
+ }
+
+ public void setNamespaceURI(String namespace) {
+ this.resourceXmlNs.setNamespaceURI(namespace);
+ this.setNamespaceURI_(namespace);
+ }
+
+ protected void setNamespaceURI_(String namespaceURI) {
+ String old = this.namespaceURI;
+ this.namespaceURI = namespaceURI;
+ this.firePropertyChanged(NAMESPACE_URI_PROPERTY, old, namespaceURI);
+ }
+
+ protected String getResourceNamespaceURI() {
+ return this.resourceXmlNs.getNamespaceURI();
+ }
+
+ // ********** prefix **********
+
+ public String getPrefix() {
+ return this.prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.resourceXmlNs.setPrefix(prefix);
+ this.setPrefix_(prefix);
+ }
+
+ protected void setPrefix_(String prefix) {
+ String old = this.prefix;
+ this.prefix = prefix;
+ this.firePropertyChanged(PREFIX_PROPERTY, old, prefix);
+ }
+
+ protected String getResourcePrefix() {
+ return this.resourceXmlNs.getPrefix();
+ }
+
+
+ //****************** miscellaneous ********************
+
+ @Override
+ public void toString(StringBuilder sb) {
+ super.toString(sb);
+ sb.append(this.namespaceURI);
+ }
+}
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 e7cb35ca01..af2bfb53f9 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
@@ -9,12 +9,18 @@
******************************************************************************/
package org.eclipse.jpt.jaxb.core.internal.context.java;
+import java.util.Vector;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
+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.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.utility.internal.iterables.LiveCloneListIterable;
public class GenericJavaXmlSchema
extends AbstractJaxbContextNode
@@ -29,12 +35,16 @@ public class GenericJavaXmlSchema
protected XmlNsForm specifiedElementFormDefault;
+ protected final Vector<XmlNs> xmlNsPrefixes = new Vector<XmlNs>();
+ protected final XmlNsPrefixContainerAdapter xmlNsPrefixContainerAdapter = new XmlNsPrefixContainerAdapter();
+
public GenericJavaXmlSchema(JaxbPackageInfo parent) {
super(parent);
this.namespace = this.getResourceNamespace();
this.specifiedLocation = this.getResourceLocation();
this.specifiedAttributeFormDefault = this.getResourceAttributeFormDefault();
this.specifiedElementFormDefault = this.getResourceElementFormDefault();
+ this.initializeXmlNsPrefixes();
}
@@ -45,10 +55,11 @@ public class GenericJavaXmlSchema
this.setSpecifiedLocation_(this.getResourceLocation());
this.setSpecifiedAttributeFormDefault_(this.getResourceAttributeFormDefault());
this.setSpecifiedElementFormDefault_(this.getResourceElementFormDefault());
+ this.syncXmlNsPrefixes();
}
public void update() {
- //nothing yet
+ this.updateNodes(getXmlNsPrefixes());
}
@@ -176,4 +187,105 @@ public class GenericJavaXmlSchema
return XmlNsForm.fromJavaResourceModel(getXmlSchemaAnnotation().getElementFormDefault());
}
+
+ // ********** xml namespace prefixes **********
+
+ public ListIterable<XmlNs> getXmlNsPrefixes() {
+ return new LiveCloneListIterable<XmlNs>(this.xmlNsPrefixes);
+ }
+
+ public int getXmlNsPrefixesSize() {
+ return this.xmlNsPrefixes.size();
+ }
+
+ public XmlNs getXmlNsPrefix(int index) {
+ return this.xmlNsPrefixes.get(index);
+ }
+
+ public XmlNs addXmlNsPrefix() {
+ return this.addXmlNsPrefix(this.xmlNsPrefixes.size());
+ }
+
+ public XmlNs addXmlNsPrefix(int index) {
+ XmlNsAnnotation annotation = this.getXmlSchemaAnnotation().addXmlns(index);
+ return this.addXmlNsPrefix_(index, annotation);
+ }
+
+ public void removeXmlNsPrefix(XmlNs xmlNsPrefix) {
+ this.removeXmlNsPrefix(this.xmlNsPrefixes.indexOf(xmlNsPrefix));
+ }
+
+ public void removeXmlNsPrefix(int index) {
+ this.getXmlSchemaAnnotation().removeXmlns(index);
+ this.removeXmlNsPrefix_(index);
+ }
+
+ protected void removeXmlNsPrefix_(int index) {
+ this.removeItemFromList(index, this.xmlNsPrefixes, XML_NS_PREFIXES_LIST);
+ }
+
+ public void moveXmlNsPrefix(int targetIndex, int sourceIndex) {
+ this.getXmlSchemaAnnotation().moveXmlns(targetIndex, sourceIndex);
+ this.moveItemInList(targetIndex, sourceIndex, this.xmlNsPrefixes, XML_NS_PREFIXES_LIST);
+ }
+
+ protected void initializeXmlNsPrefixes() {
+ for (XmlNsAnnotation xmlNsAnnotation : this.getXmlNsAnnotations()) {
+ this.xmlNsPrefixes.add(this.buildXmlNs(xmlNsAnnotation));
+ }
+ }
+
+ protected XmlNs buildXmlNs(XmlNsAnnotation xmlNsAnnotation) {
+ return this.getFactory().buildJavaXmlNs(this, xmlNsAnnotation);
+ }
+
+ protected void syncXmlNsPrefixes() {
+ ContextContainerTools.synchronizeWithResourceModel(this.xmlNsPrefixContainerAdapter);
+ }
+
+ protected Iterable<XmlNsAnnotation> getXmlNsAnnotations() {
+ return getXmlSchemaAnnotation().getXmlns();
+ }
+
+ protected void moveXmlNsPrefix_(int index, XmlNs xmlNs) {
+ this.moveItemInList(index, xmlNs, this.xmlNsPrefixes, XML_NS_PREFIXES_LIST);
+ }
+
+ protected XmlNs addXmlNsPrefix_(int index, XmlNsAnnotation xmlNsAnnotation) {
+ XmlNs xmlNs = this.buildXmlNs(xmlNsAnnotation);
+ this.addItemToList(index, xmlNs, this.xmlNsPrefixes, XML_NS_PREFIXES_LIST);
+ return xmlNs;
+ }
+
+ protected void removeXmlNsPrefix_(XmlNs xmlNs) {
+ this.removeXmlNsPrefix_(this.xmlNsPrefixes.indexOf(xmlNs));
+ }
+
+
+ /**
+ * xml ns prefix container adapter
+ */
+ protected class XmlNsPrefixContainerAdapter
+ implements ContextContainerTools.Adapter<XmlNs, XmlNsAnnotation>
+ {
+ public Iterable<XmlNs> getContextElements() {
+ return GenericJavaXmlSchema.this.getXmlNsPrefixes();
+ }
+ public Iterable<XmlNsAnnotation> getResourceElements() {
+ return GenericJavaXmlSchema.this.getXmlSchemaAnnotation().getXmlns();
+ }
+ public XmlNsAnnotation getResourceElement(XmlNs contextElement) {
+ return contextElement.getResourceXmlNs();
+ }
+ public void moveContextElement(int index, XmlNs element) {
+ GenericJavaXmlSchema.this.moveXmlNsPrefix_(index, element);
+ }
+ public void addContextElement(int index, XmlNsAnnotation resourceElement) {
+ GenericJavaXmlSchema.this.addXmlNsPrefix_(index, resourceElement);
+ }
+ public void removeContextElement(XmlNs element) {
+ GenericJavaXmlSchema.this.removeXmlNsPrefix_(element);
+ }
+ }
+
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlSchemaAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlSchemaAnnotation.java
index c406f747a4..60704850fb 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlSchemaAnnotation.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/NullXmlSchemaAnnotation.java
@@ -15,6 +15,7 @@ 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.XmlNsForm;
import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation;
+import org.eclipse.jpt.utility.internal.iterables.EmptyListIterable;
import org.eclipse.jpt.utility.internal.iterables.ListIterable;
/**
@@ -103,33 +104,27 @@ public final class NullXmlSchemaAnnotation
}
public ListIterable<XmlNsAnnotation> getXmlns() {
- // TODO Auto-generated method stub
- return null;
+ return EmptyListIterable.instance();
}
public int getXmlnsSize() {
- // TODO Auto-generated method stub
return 0;
}
public XmlNsAnnotation xmlnsAt(int index) {
- // TODO Auto-generated method stub
return null;
}
public XmlNsAnnotation addXmlns(int index) {
- // TODO Auto-generated method stub
- return null;
+ return this.addAnnotation().addXmlns(index);
}
public void moveXmlns(int targetIndex, int sourceIndex) {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
public void removeXmlns(int index) {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlNsAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlNsAnnotation.java
index 34534c24ec..8893189d45 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlNsAnnotation.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlNsAnnotation.java
@@ -30,9 +30,9 @@ public class SourceXmlNsAnnotation
extends SourceAnnotation<AnnotatedPackage>
implements XmlNsAnnotation {
- private final DeclarationAnnotationElementAdapter<String> namespaceDeclarationAdapter;
- private final AnnotationElementAdapter<String> namespaceAdapter;
- private String namespace;
+ private final DeclarationAnnotationElementAdapter<String> namespaceURIDeclarationAdapter;
+ private final AnnotationElementAdapter<String> namespaceURIAdapter;
+ private String namespaceURI;
private final DeclarationAnnotationElementAdapter<String> prefixDeclarationAdapter;
private final AnnotationElementAdapter<String> prefixAdapter;
@@ -41,14 +41,14 @@ public class SourceXmlNsAnnotation
public SourceXmlNsAnnotation(JavaResourceNode parent, AnnotatedPackage pack, IndexedDeclarationAnnotationAdapter idaa) {
super(parent, pack, idaa, new ElementIndexedAnnotationAdapter(pack, idaa));
- this.namespaceDeclarationAdapter = buildNamespaceDeclarationAdapter(idaa);
- this.namespaceAdapter = buildAdapter(this.namespaceDeclarationAdapter);
- this.prefixDeclarationAdapter = buildPrefixDeclarationAdapter(idaa);
+ this.namespaceURIDeclarationAdapter = this.buildNamespaceURIDeclarationAdapter(idaa);
+ this.namespaceURIAdapter = this.buildAdapter(this.namespaceURIDeclarationAdapter);
+ this.prefixDeclarationAdapter = this.buildPrefixDeclarationAdapter(idaa);
this.prefixAdapter = buildAdapter(this.prefixDeclarationAdapter);
}
- protected DeclarationAnnotationElementAdapter<String> buildNamespaceDeclarationAdapter(
+ protected DeclarationAnnotationElementAdapter<String> buildNamespaceURIDeclarationAdapter(
DeclarationAnnotationAdapter daa) {
return ConversionDeclarationAnnotationElementAdapter.forStrings(daa, JAXB.XML_NS__NAMESPACE_URI, false);
@@ -69,46 +69,46 @@ public class SourceXmlNsAnnotation
}
public void initialize(CompilationUnit astRoot) {
- this.namespace = buildNamespace(astRoot);
+ this.namespaceURI = buildNamespaceURI(astRoot);
this.prefix = buildPrefix(astRoot);
}
public void synchronizeWith(CompilationUnit astRoot) {
- syncNamespace(buildNamespace(astRoot));
+ syncNamespaceURI(buildNamespaceURI(astRoot));
syncPrefix(buildPrefix(astRoot));
}
@Override
public void toString(StringBuilder sb) {
- sb.append(this.namespace);
+ sb.append(this.namespaceURI);
}
// **************** namespace *********************************************
- public String getNamespace() {
- return this.namespace;
+ public String getNamespaceURI() {
+ return this.namespaceURI;
}
- public void setNamespace(String namespace) {
- if (attributeValueHasChanged(this.namespace, namespace)) {
- this.namespace = namespace;
- this.namespaceAdapter.setValue(namespace);
+ public void setNamespaceURI(String namespaceURI) {
+ if (attributeValueHasChanged(this.namespaceURI, namespaceURI)) {
+ this.namespaceURI = namespaceURI;
+ this.namespaceURIAdapter.setValue(namespaceURI);
}
}
- private String buildNamespace(CompilationUnit astRoot) {
- return this.namespaceAdapter.getValue(astRoot);
+ private String buildNamespaceURI(CompilationUnit astRoot) {
+ return this.namespaceURIAdapter.getValue(astRoot);
}
- private void syncNamespace(String namespace) {
- String old = this.namespace;
- this.namespace = namespace;
- firePropertyChanged(NAMESPACE_PROPERTY, old, namespace);
+ private void syncNamespaceURI(String namespaceURI) {
+ String old = this.namespaceURI;
+ this.namespaceURI = namespaceURI;
+ firePropertyChanged(NAMESPACE_URI_PROPERTY, old, namespaceURI);
}
- public TextRange getNamespaceTextRange(CompilationUnit astRoot) {
- return this.getElementTextRange(this.namespaceDeclarationAdapter, astRoot);
+ public TextRange getNamespaceURITextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(this.namespaceURIDeclarationAdapter, astRoot);
}
@@ -144,7 +144,7 @@ public class SourceXmlNsAnnotation
public void initializeFrom(NestableAnnotation oldAnnotation) {
XmlNsAnnotation oldXmlNsAnnotation = (XmlNsAnnotation) oldAnnotation;
- this.setNamespace(oldXmlNsAnnotation.getNamespace());
+ this.setNamespaceURI(oldXmlNsAnnotation.getNamespaceURI());
this.setPrefix(oldXmlNsAnnotation.getPrefix());
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlNsAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlNsAnnotation.java
index cdce62b895..338ba909ff 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlNsAnnotation.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlNsAnnotation.java
@@ -31,23 +31,23 @@ public interface XmlNsAnnotation
String ANNOTATION_NAME = JAXB.XML_NS;
/**
- * Corresponds to the 'namespace' element of the XmlNs annotation.
+ * Corresponds to the 'namespaceURI' element of the XmlNs annotation.
* Return null if the element does not exist in Java.
*/
- String getNamespace();
- String NAMESPACE_PROPERTY = "namespace"; //$NON-NLS-1$
+ String getNamespaceURI();
+ String NAMESPACE_URI_PROPERTY = "namespaceURI"; //$NON-NLS-1$
/**
- * Corresponds to the 'namespace' element of the XmlNs annotation.
+ * Corresponds to the 'namespaceURI' element of the XmlNs annotation.
* Set to null to remove the element.
*/
- void setNamespace(String namespace);
+ void setNamespaceURI(String namespaceURI);
/**
* Return the {@link TextRange} for the 'namespace' element. If the element
* does not exist return the {@link TextRange} for the XmlNs annotation.
*/
- TextRange getNamespaceTextRange(CompilationUnit astRoot);
+ TextRange getNamespaceURITextRange(CompilationUnit astRoot);
/**
* Corresponds to the 'prefix' element of the XmlNs annotation.
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java
index a108280c1e..98fd49d045 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java
@@ -9,8 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.jaxb.core.tests.internal.context.java;
+import java.util.ListIterator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.NormalAnnotation;
@@ -19,14 +21,17 @@ import org.eclipse.jpt.core.utility.jdt.Member;
import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo;
import org.eclipse.jpt.jaxb.core.context.XmlAccessType;
+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.resource.java.JAXB;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation;
import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation;
import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase;
import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
@SuppressWarnings("nls")
@@ -43,6 +48,12 @@ public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase
JAXB.XML_SCHEMA);
}
+ private ICompilationUnit createPackageInfoWithAccessorType() throws CoreException {
+ return createTestPackageInfo(
+ "@XmlAccessorType(value = XmlAccessType.PROPERTY)",
+ JAXB.XML_ACCESS_TYPE, JAXB.XML_ACCESSOR_TYPE);
+ }
+
public void testModifyNamespace() throws Exception {
createPackageInfoWithXmlSchema();
JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
@@ -350,6 +361,317 @@ public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase
assertNull(contextXmlSchema.getSpecifiedElementFormDefault());
}
+ public void testGetXmlNsPrefixes() throws Exception {
+ this.createPackageInfoWithXmlSchema();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ ListIterable<XmlNs> xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes();
+ assertFalse(xmlNsPrefixes.iterator().hasNext());
+
+ //add 2 XmlNs prefixes
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 0, "bar", "barPrefix");
+ GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 1, "foo", "fooPrefix");
+ }
+ });
+
+ xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes();
+ ListIterator<XmlNs> xmlNsPrefixesIterator = xmlNsPrefixes.iterator();
+ assertTrue(xmlNsPrefixesIterator.hasNext());
+ XmlNs xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("bar", xmlNsPref.getNamespaceURI());
+ assertEquals("barPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("foo", xmlNsPref.getNamespaceURI());
+ assertEquals("fooPrefix", xmlNsPref.getPrefix());
+ assertFalse(xmlNsPrefixesIterator.hasNext());
+ }
+
+ protected void addXmlNs(ModifiedDeclaration declaration, int index, String namespaceURI, String prefix) {
+ NormalAnnotation arrayElement = this.newXmlNsAnnotation(declaration.getAst(), namespaceURI, prefix);
+ this.addArrayElement(declaration.getAnnotationNamed(XmlSchemaAnnotation.ANNOTATION_NAME), index, JAXB.XML_SCHEMA__XMLNS, arrayElement);
+ }
+
+ protected NormalAnnotation newXmlNsAnnotation(AST ast, String namespaceURI, String prefix) {
+ NormalAnnotation annotation = this.newNormalAnnotation(ast, JAXB.XML_NS);
+ this.addMemberValuePair(annotation, JAXB.XML_NS__NAMESPACE_URI, namespaceURI);
+ this.addMemberValuePair(annotation, JAXB.XML_NS__PREFIX, prefix);
+ return annotation;
+ }
+
+ public void testGetXmlNsPrexiesSize() throws Exception {
+ this.createPackageInfoWithXmlSchema();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ assertEquals(0, contextXmlSchema.getXmlNsPrefixesSize());
+
+ //add 2 XmlNs prefixes
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 0, "bar", "barPrefix");
+ GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 1, "foo", "fooPrefix");
+ }
+ });
+ assertEquals(2, contextXmlSchema.getXmlNsPrefixesSize());
+ }
+
+ public void testAddXmlNsPrefix() throws Exception {
+ //create a package info with an annotation other than XmlSchema to test
+ //adding things to the null schema annotation
+ this.createPackageInfoWithAccessorType();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ XmlNs xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0);
+ xmlNsPrefix.setNamespaceURI("bar");
+ xmlNsPrefix.setPrefix("barPrefix");
+ xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0);
+ xmlNsPrefix.setNamespaceURI("foo");
+ xmlNsPrefix.setPrefix("fooPrefix");
+ xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0);
+ xmlNsPrefix.setNamespaceURI("baz");
+ xmlNsPrefix.setPrefix("bazPrefix");
+
+ XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
+ ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+
+ XmlNsAnnotation xmlNsAnnotation = xmlNsPrefixes.next();
+ assertEquals("baz", xmlNsAnnotation.getNamespaceURI());
+ assertEquals("bazPrefix", xmlNsAnnotation.getPrefix());
+ xmlNsAnnotation = xmlNsPrefixes.next();
+ assertEquals("foo", xmlNsAnnotation.getNamespaceURI());
+ assertEquals("fooPrefix", xmlNsAnnotation.getPrefix());
+ xmlNsAnnotation = xmlNsPrefixes.next();
+ assertEquals("bar", xmlNsAnnotation.getNamespaceURI());
+ assertEquals("barPrefix", xmlNsAnnotation.getPrefix());
+ assertFalse(xmlNsPrefixes.hasNext());
+ }
+
+ public void testAddXmlNsPrefix2() throws Exception {
+ this.createPackageInfoWithXmlSchema();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ XmlNs xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0);
+ xmlNsPrefix.setNamespaceURI("bar");
+ xmlNsPrefix.setPrefix("barPrefix");
+ xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(1);
+ xmlNsPrefix.setNamespaceURI("foo");
+ xmlNsPrefix.setPrefix("fooPrefix");
+ xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0);
+ xmlNsPrefix.setNamespaceURI("baz");
+ xmlNsPrefix.setPrefix("bazPrefix");
+
+ XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
+ ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+
+ XmlNsAnnotation xmlNsAnnotation = xmlNsPrefixes.next();
+ assertEquals("baz", xmlNsAnnotation.getNamespaceURI());
+ assertEquals("bazPrefix", xmlNsAnnotation.getPrefix());
+ xmlNsAnnotation = xmlNsPrefixes.next();
+ assertEquals("bar", xmlNsAnnotation.getNamespaceURI());
+ assertEquals("barPrefix", xmlNsAnnotation.getPrefix());
+ xmlNsAnnotation = xmlNsPrefixes.next();
+ assertEquals("foo", xmlNsAnnotation.getNamespaceURI());
+ assertEquals("fooPrefix", xmlNsAnnotation.getPrefix());
+ assertFalse(xmlNsPrefixes.hasNext());
+ }
+
+ public void testRemoveXmlNsPrefix() throws Exception {
+ this.createPackageInfoWithXmlSchema();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ contextXmlSchema.addXmlNsPrefix(0).setNamespaceURI("bar");
+ contextXmlSchema.addXmlNsPrefix(1).setNamespaceURI("foo");
+ contextXmlSchema.addXmlNsPrefix(2).setNamespaceURI("baz");
+
+ XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
+ assertEquals(3, schemaAnnotation.getXmlnsSize());
+
+ contextXmlSchema.removeXmlNsPrefix(1);
+
+ ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+ assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI());
+ assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI());
+ assertFalse(xmlNsPrefixes.hasNext());
+
+ contextXmlSchema.removeXmlNsPrefix(1);
+ xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+ assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI());
+ assertFalse(xmlNsPrefixes.hasNext());
+
+ contextXmlSchema.removeXmlNsPrefix(0);
+ xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+ assertFalse(xmlNsPrefixes.hasNext());
+ }
+
+ public void testMoveXmlNsPrefix() throws Exception {
+ this.createPackageInfoWithXmlSchema();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ contextXmlSchema.addXmlNsPrefix(0).setNamespaceURI("bar");
+ contextXmlSchema.addXmlNsPrefix(1).setNamespaceURI("foo");
+ contextXmlSchema.addXmlNsPrefix(2).setNamespaceURI("baz");
+
+
+ XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
+
+ assertEquals(3, schemaAnnotation.getXmlnsSize());
+
+ contextXmlSchema.moveXmlNsPrefix(2, 0);
+ ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+ assertEquals("foo", xmlNsPrefixes.next().getNamespaceURI());
+ assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI());
+ assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI());
+ assertFalse(xmlNsPrefixes.hasNext());
+
+ ListIterator<XmlNsAnnotation> xmlNsAnnotations = schemaAnnotation.getXmlns().iterator();
+ assertEquals("foo", xmlNsAnnotations.next().getNamespaceURI());
+ assertEquals("baz", xmlNsAnnotations.next().getNamespaceURI());
+ assertEquals("bar", xmlNsAnnotations.next().getNamespaceURI());
+
+
+ contextXmlSchema.moveXmlNsPrefix(0, 1);
+ xmlNsPrefixes = schemaAnnotation.getXmlns().iterator();
+ assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI());
+ assertEquals("foo", xmlNsPrefixes.next().getNamespaceURI());
+ assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI());
+ assertFalse(xmlNsPrefixes.hasNext());
+
+ xmlNsAnnotations = schemaAnnotation.getXmlns().iterator();
+ assertEquals("baz", xmlNsAnnotations.next().getNamespaceURI());
+ assertEquals("foo", xmlNsAnnotations.next().getNamespaceURI());
+ assertEquals("bar", xmlNsAnnotations.next().getNamespaceURI());
+ }
+
+ public void testSyncXmlNsPrefixes() throws Exception {
+ this.createPackageInfoWithXmlSchema();
+ JaxbPackageInfo contextPackageInfo = CollectionTools.get(getRootContextNode().getPackages(), 0).getPackageInfo();
+ XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
+ JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
+
+ ListIterable<XmlNs> xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes();
+ assertFalse(xmlNsPrefixes.iterator().hasNext());
+
+ //add 3 XmlNs prefixes
+ AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 0, "bar", "barPrefix");
+ GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 1, "foo", "fooPrefix");
+ GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 2, "baz", "bazPrefix");
+ }
+ });
+
+ xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes();
+ ListIterator<XmlNs> xmlNsPrefixesIterator = xmlNsPrefixes.iterator();
+ assertTrue(xmlNsPrefixesIterator.hasNext());
+ XmlNs xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("bar", xmlNsPref.getNamespaceURI());
+ assertEquals("barPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("foo", xmlNsPref.getNamespaceURI());
+ assertEquals("fooPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("baz", xmlNsPref.getNamespaceURI());
+ assertEquals("bazPrefix", xmlNsPref.getPrefix());
+ assertFalse(xmlNsPrefixesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.moveXmlNsPrefix(declaration, 2, 0);
+ }
+ });
+
+ xmlNsPrefixesIterator = xmlNsPrefixes.iterator();
+ assertTrue(xmlNsPrefixesIterator.hasNext());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("foo", xmlNsPref.getNamespaceURI());
+ assertEquals("fooPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("baz", xmlNsPref.getNamespaceURI());
+ assertEquals("bazPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("bar", xmlNsPref.getNamespaceURI());
+ assertEquals("barPrefix", xmlNsPref.getPrefix());
+ assertFalse(xmlNsPrefixesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.moveXmlNsPrefix(declaration, 0, 1);
+ }
+ });
+
+ xmlNsPrefixesIterator = xmlNsPrefixes.iterator();
+ assertTrue(xmlNsPrefixesIterator.hasNext());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("baz", xmlNsPref.getNamespaceURI());
+ assertEquals("bazPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("foo", xmlNsPref.getNamespaceURI());
+ assertEquals("fooPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("bar", xmlNsPref.getNamespaceURI());
+ assertEquals("barPrefix", xmlNsPref.getPrefix());
+ assertFalse(xmlNsPrefixesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.removeXmlNsPrefix(declaration, 1);
+ }
+ });
+
+ xmlNsPrefixesIterator = xmlNsPrefixes.iterator();
+ assertTrue(xmlNsPrefixesIterator.hasNext());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("baz", xmlNsPref.getNamespaceURI());
+ assertEquals("bazPrefix", xmlNsPref.getPrefix());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("bar", xmlNsPref.getNamespaceURI());
+ assertEquals("barPrefix", xmlNsPref.getPrefix());
+ assertFalse(xmlNsPrefixesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.removeXmlNsPrefix(declaration, 1);
+ }
+ });
+
+ xmlNsPrefixesIterator = xmlNsPrefixes.iterator();
+ assertTrue(xmlNsPrefixesIterator.hasNext());
+ xmlNsPref = xmlNsPrefixesIterator.next();
+ assertEquals("baz", xmlNsPref.getNamespaceURI());
+ assertEquals("bazPrefix", xmlNsPref.getPrefix());
+ assertFalse(xmlNsPrefixesIterator.hasNext());
+
+
+ annotatedElement.edit(new Member.Editor() {
+ public void edit(ModifiedDeclaration declaration) {
+ GenericJavaXmlSchemaTests.this.removeXmlNsPrefix(declaration, 0);
+ }
+ });
+
+ xmlNsPrefixesIterator = xmlNsPrefixes.iterator();
+ assertFalse(xmlNsPrefixesIterator.hasNext());
+ }
+
protected void addXmlSchemaEnumMemberValuePair(ModifiedDeclaration declaration, String elementName, String value) {
this.addEnumMemberValuePair((MarkerAnnotation) this.getXmlSchemaAnnotation(declaration), elementName, value);
}
@@ -373,4 +695,11 @@ public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase
return declaration.getAnnotationNamed(XmlSchemaAnnotation.ANNOTATION_NAME);
}
+ protected void moveXmlNsPrefix(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) {
+ this.moveArrayElement((NormalAnnotation) getXmlSchemaAnnotation(declaration), JAXB.XML_SCHEMA__XMLNS, targetIndex, sourceIndex);
+ }
+
+ protected void removeXmlNsPrefix(ModifiedDeclaration declaration, int index) {
+ this.removeArrayElement((NormalAnnotation) getXmlSchemaAnnotation(declaration), JAXB.XML_SCHEMA__XMLNS, index);
+ }
}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java
index 957331d75f..492a60976b 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java
@@ -188,14 +188,14 @@ public class XmlSchemaAnnotationTests
XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA);
XmlNsAnnotation xmlnsAnnotation = schemaAnnotation.xmlnsAt(0);
- assertNotNull(xmlnsAnnotation.getNamespace());
+ assertNotNull(xmlnsAnnotation.getNamespaceURI());
- xmlnsAnnotation.setNamespace(null);
- assertNull(xmlnsAnnotation.getNamespace());
+ xmlnsAnnotation.setNamespaceURI(null);
+ assertNull(xmlnsAnnotation.getNamespaceURI());
assertSourceContains("@XmlSchema(xmlns = @XmlNs)", cu);
- xmlnsAnnotation.setNamespace(TEST_NAMESPACE_2);
- assertEquals(TEST_NAMESPACE_2, xmlnsAnnotation.getNamespace());
+ xmlnsAnnotation.setNamespaceURI(TEST_NAMESPACE_2);
+ assertEquals(TEST_NAMESPACE_2, xmlnsAnnotation.getNamespaceURI());
assertSourceContains("@XmlSchema(xmlns = @XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 + "\"))", cu);
}
@@ -233,10 +233,10 @@ public class XmlSchemaAnnotationTests
assertSourceContains("@XmlSchema(xmlns = {@XmlNs,@XmlNs})", cu);
XmlNsAnnotation xmlnsAnnotation1 = schemaAnnotation.xmlnsAt(0);
- xmlnsAnnotation1.setNamespace(TEST_NAMESPACE);
+ xmlnsAnnotation1.setNamespaceURI(TEST_NAMESPACE);
xmlnsAnnotation1.setPrefix(TEST_PREFIX);
XmlNsAnnotation xmlnsAnnotation2 = schemaAnnotation.xmlnsAt(1);
- xmlnsAnnotation2.setNamespace(TEST_NAMESPACE_2);
+ xmlnsAnnotation2.setNamespaceURI(TEST_NAMESPACE_2);
xmlnsAnnotation2.setPrefix(TEST_PREFIX_2);
assertSourceContains(
"@XmlSchema(xmlns = {@XmlNs(namespaceURI = \"" + TEST_NAMESPACE
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/AbstractModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/AbstractModel.java
index 6cd31fc447..5e6e3b4e33 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/AbstractModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/AbstractModel.java
@@ -536,6 +536,10 @@ public abstract class AbstractModel
this.getChangeSupport().moveItemInList(targetIndex, sourceIndex, list, listName);
}
+ protected <E> void moveItemInList(int targetIndex, E item, List<E> list, String listName) {
+ this.getChangeSupport().moveItemInList(targetIndex, item, list, listName);
+ }
+
protected boolean clearList(List<?> list, String listName) {
return this.getChangeSupport().clearList(list, listName);
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/ChangeSupport.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/ChangeSupport.java
index 6acfac1993..4a53834951 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/ChangeSupport.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/ChangeSupport.java
@@ -2262,6 +2262,15 @@ public class ChangeSupport
}
/**
+ * Move an item in the specified list from the specified source index to the
+ * specified target index.
+ * Return whether the list changed.
+ */
+ public <E> boolean moveItemInList(int targetIndex, E item, List<E> list, String listName) {
+ return this.moveItemInList(targetIndex, list.indexOf(item), list, listName);
+ }
+
+ /**
* Clear the entire list
* and fire the appropriate event if necessary.
* Return whether the list changed.

Back to the top