Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2010-12-21 15:12:20 -0500
committerpfullbright2010-12-21 15:12:20 -0500
commit63ccc35ff60a482f3ba7c52ee1b8da0ab4a6647b (patch)
tree74d5ad8bbe7222f6d8338efd8a60cfa1a3afab82
parenta2670e9c36539504245aa9b0d9a82b420bf09774 (diff)
downloadwebtools.dali-63ccc35ff60a482f3ba7c52ee1b8da0ab4a6647b.tar.gz
webtools.dali-63ccc35ff60a482f3ba7c52ee1b8da0ab4a6647b.tar.xz
webtools.dali-63ccc35ff60a482f3ba7c52ee1b8da0ab4a6647b.zip
added specified/default namespace api
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/context/XmlSchema.java32
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java136
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java27
3 files changed, 111 insertions, 84 deletions
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 aed08b703e..5409f66620 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
@@ -24,17 +24,29 @@ import org.eclipse.jpt.utility.internal.iterables.ListIterable;
* @since 3.0
*/
public interface XmlSchema
- extends
- JaxbContextNode
-{
+ extends JaxbContextNode {
+
+ /**
+ * Return the specified namespace or "" (default value)
+ */
String getNamespace();
-
- void setNamespace(String namespace);
- /**
- * String constant associated with changes to the namespace
- */
- String NAMESPACE_PROPERTY = "namespace"; //$NON-NLS-1$
-
+
+ /**
+ * Return the specified namespace, null if it is not specified
+ */
+ String getSpecifiedNamespace();
+
+ /**
+ * Set the namespace, null to unspecify
+ */
+ void setSpecifiedNamespace(String namespace);
+
+ /**
+ * String constant associated with changes to the specified namespace
+ */
+ String SPECIFIED_NAMESPACE_PROPERTY = "specifiedNamespace"; //$NON-NLS-1$
+
+
/**
* Corresponds to the XmlSchema annotation location 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 0643d00a93..4ab5a1210a 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
@@ -20,210 +20,218 @@ import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation;
import org.eclipse.jpt.utility.internal.iterables.ListIterable;
public class GenericJavaXmlSchema
- extends AbstractJaxbContextNode
- implements XmlSchema
-{
-
- protected String namespace;
-
+ extends AbstractJaxbContextNode
+ implements XmlSchema {
+
+ protected String specifiedNamespace;
+
protected String location;
-
+
protected XmlNsForm attributeFormDefault;
-
+
protected XmlNsForm elementFormDefault;
-
+
protected final XmlNsPrefixContainer xmlNsPrefixContainer;
-
+
+
public GenericJavaXmlSchema(JaxbPackageInfo parent) {
super(parent);
- this.namespace = this.getResourceNamespace();
+ this.specifiedNamespace = this.getResourceNamespace();
this.location = this.getResourceLocation();
this.attributeFormDefault = this.getResourceAttributeFormDefault();
this.elementFormDefault = this.getResourceElementFormDefault();
this.xmlNsPrefixContainer = new XmlNsPrefixContainer();
}
-
-
+
+
// ********** synchronize/update **********
-
+
public void synchronizeWithResourceModel() {
- this.setNamespace_(this.getResourceNamespace());
+ this.setSpecifiedNamespace_(this.getResourceNamespace());
this.setLocation_(this.getResourceLocation());
this.setAttributeFormDefault_(this.getResourceAttributeFormDefault());
this.setElementFormDefault_(this.getResourceElementFormDefault());
this.syncXmlNsPrefixes();
}
-
+
public void update() {
this.updateNodes(getXmlNsPrefixes());
}
-
-
+
@Override
public JaxbPackageInfo getParent() {
return (JaxbPackageInfo) super.getParent();
}
-
+
protected JavaResourcePackage getResourcePackage() {
return getParent().getResourcePackage();
}
-
-
+
+
// ********** xml schema annotation **********
-
+
protected XmlSchemaAnnotation getXmlSchemaAnnotation() {
return (XmlSchemaAnnotation) this.getResourcePackage().getNonNullAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
}
-
+
// ********** namespace **********
-
+
public String getNamespace() {
- return this.namespace;
+ return (this.specifiedNamespace == null) ? "" : this.specifiedNamespace;
+ }
+
+ public String getSpecifiedNamespace() {
+ return this.specifiedNamespace;
}
- public void setNamespace(String namespace) {
+ public void setSpecifiedNamespace(String namespace) {
this.getXmlSchemaAnnotation().setNamespace(namespace);
- this.setNamespace_(namespace);
+ this.setSpecifiedNamespace_(namespace);
}
-
- protected void setNamespace_(String namespace) {
- String old = this.namespace;
- this.namespace = namespace;
- this.firePropertyChanged(NAMESPACE_PROPERTY, old, namespace);
+
+ protected void setSpecifiedNamespace_(String namespace) {
+ String old = this.specifiedNamespace;
+ this.specifiedNamespace = namespace;
+ this.firePropertyChanged(SPECIFIED_NAMESPACE_PROPERTY, old, namespace);
}
-
+
protected String getResourceNamespace() {
return getXmlSchemaAnnotation().getNamespace();
}
-
+
+
// ********** location **********
-
+
public String getLocation() {
return this.location;
}
-
+
public void setLocation(String location) {
this.getXmlSchemaAnnotation().setLocation(location);
this.setLocation_(location);
}
-
+
protected void setLocation_(String location) {
String old = this.location;
this.location = location;
this.firePropertyChanged(LOCATION_PROPERTY, old, location);
}
-
+
protected String getResourceLocation() {
return getXmlSchemaAnnotation().getLocation();
}
-
+
+
// ********** attribute form default **********
-
+
public XmlNsForm getAttributeFormDefault() {
return this.attributeFormDefault;
}
-
+
public void setAttributeFormDefault(XmlNsForm xmlNsForm) {
this.getXmlSchemaAnnotation().setAttributeFormDefault(XmlNsForm.toJavaResourceModel(xmlNsForm));
this.setAttributeFormDefault_(xmlNsForm);
}
-
+
protected void setAttributeFormDefault_(XmlNsForm xmlNsForm) {
XmlNsForm old = this.attributeFormDefault;
this.attributeFormDefault = xmlNsForm;
this.firePropertyChanged(ATTRIBUTE_FROM_DEFAULT_PROPERTY, old, xmlNsForm);
}
-
+
protected XmlNsForm getResourceAttributeFormDefault() {
return XmlNsForm.fromJavaResourceModel(getXmlSchemaAnnotation().getAttributeFormDefault());
}
-
+
+
// ********** element form default **********
-
+
public XmlNsForm getElementFormDefault() {
return this.elementFormDefault;
}
-
+
public void setElementFormDefault(XmlNsForm xmlNsForm) {
this.getXmlSchemaAnnotation().setElementFormDefault(XmlNsForm.toJavaResourceModel(xmlNsForm));
this.setElementFormDefault_(xmlNsForm);
}
-
+
protected void setElementFormDefault_(XmlNsForm xmlNsForm) {
XmlNsForm old = this.elementFormDefault;
this.elementFormDefault = xmlNsForm;
this.firePropertyChanged(ELEMENT_FROM_DEFAULT_PROPERTY, old, xmlNsForm);
}
-
+
protected XmlNsForm getResourceElementFormDefault() {
return XmlNsForm.fromJavaResourceModel(getXmlSchemaAnnotation().getElementFormDefault());
}
-
-
+
+
// ********** xml namespace prefixes **********
-
+
public ListIterable<XmlNs> getXmlNsPrefixes() {
return this.xmlNsPrefixContainer.getContextElements();
}
-
+
public int getXmlNsPrefixesSize() {
return this.xmlNsPrefixContainer.getContextElementsSize();
}
-
+
public XmlNs addXmlNsPrefix(int index) {
XmlNsAnnotation annotation = this.getXmlSchemaAnnotation().addXmlns(index);
return this.xmlNsPrefixContainer.addContextElement(index, annotation);
}
-
+
public void removeXmlNsPrefix(XmlNs xmlNsPrefix) {
this.removeXmlNsPrefix(this.xmlNsPrefixContainer.indexOfContextElement(xmlNsPrefix));
}
-
+
public void removeXmlNsPrefix(int index) {
this.getXmlSchemaAnnotation().removeXmlns(index);
this.xmlNsPrefixContainer.removeContextElement(index);
}
-
+
public void moveXmlNsPrefix(int targetIndex, int sourceIndex) {
this.getXmlSchemaAnnotation().moveXmlns(targetIndex, sourceIndex);
this.xmlNsPrefixContainer.moveContextElement(targetIndex, sourceIndex);
}
-
+
protected XmlNs buildXmlNs(XmlNsAnnotation xmlNsAnnotation) {
return this.getFactory().buildJavaXmlNs(this, xmlNsAnnotation);
}
-
+
protected void syncXmlNsPrefixes() {
this.xmlNsPrefixContainer.synchronizeWithResourceModel();
}
-
+
protected ListIterable<XmlNsAnnotation> getXmlNsAnnotations() {
return getXmlSchemaAnnotation().getXmlns();
}
-
-
+
+
/**
* xml ns prefix container adapter
*/
protected class XmlNsPrefixContainer
- extends ContextListContainer<XmlNs, XmlNsAnnotation>
- {
+ extends ContextListContainer<XmlNs, XmlNsAnnotation> {
+
@Override
protected String getContextElementsPropertyName() {
return XML_NS_PREFIXES_LIST;
}
+
@Override
protected XmlNs buildContextElement(XmlNsAnnotation resourceElement) {
return GenericJavaXmlSchema.this.buildXmlNs(resourceElement);
}
+
@Override
protected ListIterable<XmlNsAnnotation> getResourceElements() {
return GenericJavaXmlSchema.this.getXmlNsAnnotations();
}
+
@Override
protected XmlNsAnnotation getResourceElement(XmlNs contextElement) {
return contextElement.getResourceXmlNs();
}
}
-
}
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 e559fa6699..24bd638e08 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
@@ -59,25 +59,29 @@ public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase
JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo();
XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
-
- assertNull(contextXmlSchema.getNamespace());
- contextXmlSchema.setNamespace("foo");
+ assertEquals("", contextXmlSchema.getNamespace());
+ assertNull(contextXmlSchema.getSpecifiedNamespace());
+
+ contextXmlSchema.setSpecifiedNamespace("foo");
XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
assertEquals("foo", schemaAnnotation.getNamespace());
assertEquals("foo", contextXmlSchema.getNamespace());
+ assertEquals("foo", contextXmlSchema.getSpecifiedNamespace());
//set another annotation so the context model is not blown away by removing the XmlSchema annotation
contextPackageInfo.setSpecifiedAccessType(XmlAccessType.FIELD);
- contextXmlSchema.setNamespace(null);
+ contextXmlSchema.setSpecifiedNamespace(null);
schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
assertNull(schemaAnnotation);
- assertNull(contextXmlSchema.getNamespace());
+ assertEquals("", contextXmlSchema.getNamespace());
+ assertNull(contextXmlSchema.getSpecifiedNamespace());
//set namespace again, this time starting with no XmlSchema annotation
- contextXmlSchema.setNamespace("foo");
+ contextXmlSchema.setSpecifiedNamespace("foo");
schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME);
assertEquals("foo", schemaAnnotation.getNamespace());
+ assertEquals("foo", contextXmlSchema.getSpecifiedNamespace());
assertEquals("foo", contextXmlSchema.getNamespace());
}
@@ -86,8 +90,9 @@ public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase
JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo();
XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema();
JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage();
-
- assertNull(contextXmlSchema.getNamespace());
+
+ assertEquals("", contextXmlSchema.getNamespace());
+ assertNull(contextXmlSchema.getSpecifiedNamespace());
//add a namespace member value pair
AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage);
@@ -97,14 +102,16 @@ public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase
}
});
assertEquals("foo", contextXmlSchema.getNamespace());
-
+ assertEquals("foo", contextXmlSchema.getSpecifiedNamespace());
+
annotatedElement.edit(new Member.Editor() {
public void edit(ModifiedDeclaration declaration) {
GenericJavaXmlSchemaTests.this.removeXmlSchemaAnnotation(declaration);
}
});
contextXmlSchema = contextPackageInfo.getXmlSchema();
- assertNull(contextXmlSchema.getNamespace());
+ assertEquals("", contextXmlSchema.getNamespace());
+ assertNull(contextXmlSchema.getSpecifiedNamespace());
}
public void testModifyLocation() throws Exception {

Back to the top