Author: bimargulies
Date: Wed Dec 5 11:36:38 2007
New Revision: 601481
URL: http://svn.apache.org/viewvc?rev=601481&view=rev
Log:
Modularity in the direction of dealing with global elements.
Modified:
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
Modified:
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java?rev=601481&r1=601480&r2=601481&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
(original)
+++
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/ElementInfo.java
Wed Dec 5 11:36:38 2007
@@ -34,7 +34,6 @@
private SchemaCollection xmlSchemaCollection;
private String referencingURI;
private XmlSchemaType containingType;
- private boolean partElement;
public String getUtilsVarName() {
return utilsVarName;
@@ -78,11 +77,4 @@
public void setContainingType(XmlSchemaType containingType) {
this.containingType = containingType;
}
- public boolean isPartElement() {
- return partElement;
- }
- public void setPartElement(boolean partElement) {
- this.partElement = partElement;
- }
-
}
Modified:
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java?rev=601481&r1=601480&r2=601481&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
(original)
+++
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/JavascriptUtils.java
Wed Dec 5 11:36:38 2007
@@ -199,7 +199,6 @@
elementInfo.getReferencingURI(),
elementInfo.getElement(),
elementInfo.getContainingType());
-
// first question: optional?
if (optional) {
startIf(elementInfo.getElementJavascriptName() + " != null");
@@ -212,7 +211,7 @@
appendString("<" + elementInfo.getElementXmlName() + " " +
XmlSchemaUtils.NIL_ATTRIBUTES + "/>");
appendElse();
}
-
+
if (XmlSchemaUtils.isParticleArray(elementInfo.getElement())) {
// protected against null in arrays.
startIf(elementInfo.getElementJavascriptName() + " != null");
Modified:
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java?rev=601481&r1=601480&r2=601481&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
(original)
+++
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/service/ServiceJavascriptBuilder.java
Wed Dec 5 11:36:38 2007
@@ -487,7 +487,6 @@
elementInfo.setReferencingURI(serviceTargetNamespace);
elementInfo.setUtilsVarName("cxfutils");
elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
- elementInfo.setPartElement(true);
utils.generateCodeToSerializeElement(elementInfo);
} else {
@@ -508,7 +507,6 @@
elementInfo.setReferencingURI(serviceTargetNamespace);
elementInfo.setUtilsVarName("cxfutils");
elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
- elementInfo.setPartElement(true);
utils.generateCodeToSerializeElement(elementInfo);
px++;
}
Modified:
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties?rev=601481&r1=601480&r2=601481&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties
(original)
+++
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/Messages.properties
Wed Dec 5 11:36:38 2007
@@ -18,3 +18,5 @@
# under the License.
#
#
+ELEMENT_MISSING_TYPE= Root element {0} refers to undefined type {1} in {2}.
+UNSUPPORTED_TYPE_CONSTRUCT= Unsupported schema construct {0}.
\ No newline at end of file
Modified:
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java?rev=601481&r1=601480&r2=601481&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
(original)
+++
incubator/cxf/trunk/rt/javascript/src/main/java/org/apache/cxf/javascript/types/SchemaJavascriptBuilder.java
Wed Dec 5 11:36:38 2007
@@ -24,6 +24,7 @@
import javax.xml.namespace.QName;
+import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.common.xmlschema.SchemaCollection;
@@ -84,9 +85,48 @@
if (xmlSchemaObject instanceof XmlSchemaComplexType) {
try {
XmlSchemaComplexType complexType =
(XmlSchemaComplexType)xmlSchemaObject;
-
code.append(complexTypeConstructorAndAccessors(complexType));
- code.append(complexTypeSerializerFunction(complexType));
- code.append(domDeserializerFunction(complexType));
+ if (complexType.getName() != null) {
+
code.append(complexTypeConstructorAndAccessors(complexType.getQName(),
complexType));
+
code.append(complexTypeSerializerFunction(complexType.getQName(), complexType));
+
code.append(domDeserializerFunction(complexType.getQName(), complexType));
+ }
+ } catch (UnsupportedConstruct usc) {
+ LOG.warning(usc.toString());
+ continue; // it could be empty, but the style checker
would complain.
+ }
+ }
+ }
+
+ // now add in global elements with anonymous types.
+ schemaTypes = schema.getSchema().getElements();
+ namesIterator = schemaTypes.getNames();
+ while (namesIterator.hasNext()) {
+ QName name = (QName)namesIterator.next();
+ XmlSchemaObject xmlSchemaObject =
(XmlSchemaObject)schemaTypes.getItem(name);
+ if (xmlSchemaObject instanceof XmlSchemaElement) { // the
alternative is too wierd to contemplate.
+ try {
+ XmlSchemaElement element =
(XmlSchemaElement)xmlSchemaObject;
+ if (element.getSchemaTypeName() == null) {
+ Message message = new Message("ELEMENT_MISSING_TYPE",
LOG,
+ element.getQName(),
+
element.getSchemaTypeName(),
+
schema.getNamespaceURI());
+ LOG.warning(message.toString());
+ continue;
+ }
+ XmlSchemaType type =
schema.getSchema().getTypeByName(element.getSchemaTypeName());
+ if (!(xmlSchemaObject instanceof XmlSchemaComplexType)) {
+ // we never make classes for simple type.
+ continue;
+ }
+
+ XmlSchemaComplexType complexType =
(XmlSchemaComplexType)type;
+ // for named types we don't bother to generate for the
element.
+ if (complexType.getName() == null) {
+
code.append(complexTypeConstructorAndAccessors(element.getQName(),
complexType));
+
code.append(complexTypeSerializerFunction(element.getQName(), complexType));
+
code.append(domDeserializerFunction(element.getQName(), complexType));
+ }
} catch (UnsupportedConstruct usc) {
continue; // it could be empty, but the style checker
would complain.
}
@@ -98,9 +138,7 @@
return returnValue;
}
-
-
- public String complexTypeConstructorAndAccessors(XmlSchemaComplexType
type) {
+ public String complexTypeConstructorAndAccessors(QName name,
XmlSchemaComplexType type) {
StringBuilder code = new StringBuilder();
StringBuilder accessors = new StringBuilder();
JavascriptUtils utils = new JavascriptUtils(code);
@@ -108,7 +146,7 @@
final String elementPrefix = "this._";
- String typeObjectName = nameManager.getJavascriptName(type);
+ String typeObjectName = nameManager.getJavascriptName(name);
code.append("function " + typeObjectName + " () {\n");
for (int i = 0; i < sequence.getItems().getCount(); i++) {
@@ -175,7 +213,7 @@
* @param type
* @return
*/
- public String complexTypeSerializerFunction(XmlSchemaComplexType type) {
+ public String complexTypeSerializerFunction(QName name,
XmlSchemaComplexType type) {
StringBuilder bodyCode = new StringBuilder();
JavascriptUtils bodyUtils = new JavascriptUtils(bodyCode);
@@ -185,7 +223,7 @@
StringBuilder code = new StringBuilder();
JavascriptUtils utils = new JavascriptUtils(code);
- String functionName = nameManager.getJavascriptName(type) + "_" +
"serialize";
+ String functionName = nameManager.getJavascriptName(name) + "_" +
"serialize";
code.append("function " + functionName + "(cxfjsutils, elementName)
{\n");
utils.startXmlStringAccumulator("xml");
utils.startIf("elementName != null");
@@ -248,7 +286,6 @@
elementInfo.setReferencingURI(null);
elementInfo.setUtilsVarName("cxfjsutils");
elementInfo.setXmlSchemaCollection(xmlSchemaCollection);
- elementInfo.setPartElement(false);
utils.generateCodeToSerializeElement(elementInfo);
}
}
@@ -258,7 +295,7 @@
* @param type schema type for the process
* @return the string contents of the JavaScript.
*/
- public String domDeserializerFunction(XmlSchemaComplexType type) {
+ public String domDeserializerFunction(QName name, XmlSchemaComplexType
type) {
StringBuilder code = new StringBuilder();
JavascriptUtils utils = new JavascriptUtils(code);
XmlSchemaParticle particle = type.getParticle();
@@ -274,7 +311,7 @@
XmlSchemaUtils.unsupportedConstruct("NON_SEQUENCE_PARTICLE", type);
}
- String typeObjectName = nameManager.getJavascriptName(type);
+ String typeObjectName = nameManager.getJavascriptName(name);
code.append("function " + typeObjectName + "_deserialize (cxfjsutils,
element) {\n");
// create the object we are deserializing into.
utils.appendLine("var newobject = new " + typeObjectName + "();");