Author: ajith
Date: Sat Mar 22 10:49:04 2008
New Revision: 640022
URL: http://svn.apache.org/viewvc?rev=640022&view=rev
Log:
1. Fixed the issue 309
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?rev=640022&r1=640021&r2=640022&view=diff
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
Sat Mar 22 10:49:04 2008
@@ -565,39 +565,10 @@
if (elementObj.id != null)
serializedEl.setAttribute("id", elementObj.id);
- if (elementObj.maxOccurs < Long.MAX_VALUE && elementObj.maxOccurs > 1)
- serializedEl.setAttribute("maxOccurs",
- elementObj.maxOccurs + "");
- else if (elementObj.maxOccurs == Long.MAX_VALUE)
- serializedEl.setAttribute("maxOccurs",
- "unbounded");
- //else not serialized
-
- /*if(elementObj.minOccurs >1)
- serializedEl.setAttribute("minOccurs",
- elementObj.minOccurs + "");*/
-
- //Change - SK and Ragu cos it wasnt picking up
- // minOccurs = 0
- if (elementObj.minOccurs < Long.MAX_VALUE && elementObj.minOccurs != 1)
- serializedEl.setAttribute("minOccurs",
- elementObj.minOccurs + "");
- else if (elementObj.minOccurs == Long.MAX_VALUE)
- serializedEl.setAttribute("minOccurs",
- "unbounded");
-
- /*
- if(elementObj.maxOccursString != null)
- serializedEl.setAttribute("maxOccurs",
- elementObj.maxOccursString);
- else if(elementObj.maxOccurs > 1)
- serializedEl.setAttribute("maxOccurs",
- elementObj.maxOccurs + "");
-
- if(elementObj.minOccurs > 1)
- serializedEl.setAttribute("minOccurs",
- elementObj.minOccurs + "");
- */
+
+ serializeMaxMinOccurs(elementObj, serializedEl);
+
+
if (elementObj.substitutionGroup != null) {
String resolvedQName = resolveQName(elementObj.substitutionGroup,
schema);
serializedEl.setAttribute("substitutionGroup",
@@ -1008,20 +979,7 @@
sequence.setAttribute("id", sequenceObj.id);
- if (sequenceObj.maxOccurs < Long.MAX_VALUE &&
- (sequenceObj.maxOccurs > 1 || sequenceObj.maxOccurs == 0))
- sequence.setAttribute("maxOccurs",
- sequenceObj.maxOccurs + "");
- else if (sequenceObj.maxOccurs == Long.MAX_VALUE)
- sequence.setAttribute("maxOccurs",
- "unbounded");
- //else not serialized
-
- //1 is the default and hence not serialized
- //there is no valid case where min occurs can be unbounded!
- if (sequenceObj.minOccurs > 1 || sequenceObj.minOccurs == 0)
- sequence.setAttribute("minOccurs",
- sequenceObj.minOccurs + "");
+ serializeMaxMinOccurs(sequenceObj, sequence);
XmlSchemaObjectCollection seqColl = sequenceObj.items;
int containLength = seqColl.getCount();
@@ -1056,6 +1014,29 @@
}
/**
+ * A common method to serialize the max/min occurs
+ * @param particle
+ * @param element
+ */
+ private void serializeMaxMinOccurs(XmlSchemaParticle particle,
+ Element element) {
+ if (particle.maxOccurs < Long.MAX_VALUE &&
+ (particle.maxOccurs > 1 || particle.maxOccurs == 0))
+ element.setAttribute("maxOccurs",
+ particle.maxOccurs + "");
+ else if (particle.maxOccurs == Long.MAX_VALUE)
+ element.setAttribute("maxOccurs",
+ "unbounded");
+ //else not serialized
+
+ //1 is the default and hence not serialized
+ //there is no valid case where min occurs can be unbounded!
+ if (particle.minOccurs > 1 || particle.minOccurs == 0)
+ element.setAttribute("minOccurs",
+ particle.minOccurs + "");
+ }
+
+ /**
* *********************************************************************
* Element serializeAttribute(Document doc, XmlSchemaAttribute
attributeObj,
* XmlSchema schema) throws XmlSchemaSerializerException{
@@ -1216,17 +1197,7 @@
choice.setAttribute("id", choiceObj.id);
- if (choiceObj.maxOccurs < Long.MAX_VALUE && choiceObj.maxOccurs != 1)
- choice.setAttribute("maxOccurs",
- choiceObj.maxOccurs + "");
- else if (choiceObj.maxOccurs == Long.MAX_VALUE)
- choice.setAttribute("maxOccurs",
- "unbounded");
- //else not serialized
-
- if (choiceObj.minOccurs != 1)
- choice.setAttribute("minOccurs",
- choiceObj.minOccurs + "");
+ serializeMaxMinOccurs(choiceObj, choice);
/*
@@ -1306,9 +1277,7 @@
Element allEl = createNewElement(doc, "all", schema.schema_ns_prefix,
XmlSchema.SCHEMA_NS);
- if (allObj.minOccurs == 0)
- allEl.setAttribute("minOccurs", "0");
-
+ serializeMaxMinOccurs(allObj, allEl);
if (allObj.annotation != null) {
Element annotation = serializeAnnotation(doc, allObj.annotation,
@@ -1472,18 +1441,8 @@
if (anyObj.id.length() > 0)
anyEl.setAttribute("id", anyObj.id);
-
- if (anyObj.maxOccurs < Long.MAX_VALUE && anyObj.maxOccurs > 1)
- anyEl.setAttribute("maxOccurs",
- anyObj.maxOccurs + "");
- else if (anyObj.maxOccurs == Long.MAX_VALUE)
- anyEl.setAttribute("maxOccurs",
- "unbounded");
- //else not serialized
-
- if (anyObj.minOccurs > 1)
- anyEl.setAttribute("minOccurs",
- anyObj.minOccurs + "");
+ serializeMaxMinOccurs(anyObj, anyEl);
+
if (anyObj.namespace != null)
anyEl.setAttribute("namespace",
@@ -1600,17 +1559,8 @@
} else
throw new XmlSchemaSerializerException("Group must have name or
ref");
- if (groupRefObj.maxOccurs < Long.MAX_VALUE && groupRefObj.maxOccurs >
1)
- groupRef.setAttribute("maxOccurs",
- groupRefObj.maxOccurs + "");
- else if (groupRefObj.maxOccurs == Long.MAX_VALUE)
- groupRef.setAttribute("maxOccurs",
- "unbounded");
- //else not serialized
-
- if (groupRefObj.minOccurs > 1)
- groupRef.setAttribute("minOccurs",
- groupRefObj.minOccurs + "");
+
+ serializeMaxMinOccurs(groupRefObj, groupRef);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]