You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2004/08/27 15:19:26 UTC
cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg ObjectSG.java GroupSG.java
jochen 2004/08/27 06:19:26
Modified: src/jaxme/org/apache/ws/jaxme/impl JAXBContextImpl.java
src/jaxme/org/apache/ws/jaxme/generator/sg/impl
JAXBGroupSG.java JAXBObjectSG.java
JAXBSGFactory.java
src/jaxme/org/apache/ws/jaxme/junit RecursionTest.java
. status.xml
src/test/jaxb recursion.xsd
src/jaxme/org/apache/ws/jaxme/generator/sg ObjectSG.java
GroupSG.java
Log:
Implemented recursion for element references.
PR: JAXME-26
Revision Changes Path
1.5 +29 -10 ws-jaxme/src/jaxme/org/apache/ws/jaxme/impl/JAXBContextImpl.java
Index: JAXBContextImpl.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/impl/JAXBContextImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JAXBContextImpl.java 16 Feb 2004 23:39:57 -0000 1.4
+++ JAXBContextImpl.java 27 Aug 2004 13:19:26 -0000 1.5
@@ -58,6 +58,8 @@
* @version $Id$
*/
public class JAXBContextImpl extends JAXBContext {
+ /** The namespace of JaxMe's configuration files.
+ */
public static final String CONFIGURATION_URI = "http://ws.apache.org/jaxme/namespaces/jaxme2/configuration";
private static final SAXParserFactory spf;
private static final DatatypeConverterImpl datatypeConverter = new DatatypeConverterImpl();
@@ -197,7 +199,7 @@
/** <p>Returns a Manager for the given QName.</p>
*
- * @throws ConfiguratorException No Manager is registered for the
+ * @throws JAXBException No Manager is registered for the
* given QName.
*/
public JMManager getManager(QName pQName) throws JAXBException {
@@ -210,7 +212,7 @@
/** <p>Returns a Manager for the given element interface.</p>
*
- * @throws ConfiguratorException No Manager is registered for the
+ * @throws JAXBException No Manager is registered for the
* given QName.
*/
public JMManager getManager(Class pElementInterface) throws JAXBException {
@@ -225,7 +227,7 @@
/** <p>Returns a new instance of a class implementing the
* element interface <code>pElementInterface</code>.</p>
*
- * @throws ConfiguratorException A Manager for <code>pQName</code>
+ * @throws JAXBException A Manager for <code>pQName</code>
* was not declared or creating the instance caused an exception.
*/
public Object getElement(Class pElementInterface) throws JAXBException {
@@ -247,7 +249,7 @@
/** <p>Returns a new handler instance for <code>pQName</code>.</p>
*
- * @throws ConfiguratorException A Manager for <code>pQName</code>
+ * @throws UnmarshalException A Manager for <code>pQName</code>
* was not declared or creating the instance caused an exception.
*/
public JMHandler getJMHandler(QName pQName) throws UnmarshalException {
@@ -269,11 +271,15 @@
/** <p>Returns a new handler instance for <code>pQName</code>.</p>
*
- * @throws ConfiguratorException A Manager for <code>pQName</code>
+ * @throws UnmarshalException A Manager for <code>pQName</code>
* was not declared or creating the instance caused an exception.
*/
public JMHandler getJMHandler(Class pElementInterface) throws UnmarshalException {
- Class c = getManagerByInterface(pElementInterface).getHandlerClass();
+ JMManager manager = getManagerByInterface(pElementInterface);
+ if (manager == null) {
+ throw new UnmarshalException("No manager configured for " + pElementInterface.getName());
+ }
+ Class c = manager.getHandlerClass();
if (c == null) {
throw new UnmarshalException("No handler class configured for " +
pElementInterface.getName());
@@ -288,7 +294,7 @@
/** <p>Returns a new serializer instance for <code>pElementInterface</code>.</p>
*
- * @throws ConfiguratorException A Manager for <code>pElementInterface</code>
+ * @throws MarshalException A Manager for <code>pElementInterface</code>
* was not declared or creating the instance caused an exception.
*/
public JMXmlSerializer getJMXmlSerializer(Class pElementInterface) throws MarshalException {
@@ -309,7 +315,7 @@
/** <p>Returns a new serializer instance for <code>pQName</code>.</p>
*
- * @throws ConfiguratorException A Manager for <code>pQName</code>
+ * @throws MarshalException A Manager for <code>pQName</code>
* was not declared or creating the instance caused an exception.
*/
public JMXmlSerializer getJMXmlSerializer(QName pQName) throws MarshalException {
@@ -468,10 +474,16 @@
}
}
+ /** Creates a new instance of {@link javax.xml.bind.JAXBContext}.
+ * Invoked implicitly by
+ * {@link javax.xml.bind.JAXBContext#newInstance(java.lang.String)}.
+ */
public static JAXBContextImpl createContext() throws JAXBException {
return createContext(null, JAXBContextImpl.class.getClassLoader());
}
+ /** Invoked from the SAX handler when loading the config file.
+ */
public Configuration createConfiguration(Attributes pAttributes) throws JAXBException {
String className = pAttributes.getValue("", "className");
if (className == null || className.length() == 0) {
@@ -495,8 +507,12 @@
e.printStackTrace(System.err);
}
+ /** Creates a new instance of {@link javax.xml.bind.JAXBContext}.
+ * Invoked implicitly by
+ * {@link javax.xml.bind.JAXBContext#newInstance(String, ClassLoader)}
+ */
public static JAXBContextImpl createContext(String pPackageNames,
- ClassLoader pClassLoader)
+ ClassLoader pClassLoader)
throws JAXBException {
try {
JAXBContextImpl result = new JAXBContextImpl();
@@ -513,6 +529,9 @@
}
}
+ /** Invoked from the SAX handler when reading the config file
+ * for adding another instance of JMManager.
+ */
public void addManager(JMManager pManager) throws JAXBException {
Class elementInterface = pManager.getElementInterface();
if (elementInterface == null) {
1.14 +28 -14 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBGroupSG.java
Index: JAXBGroupSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBGroupSG.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JAXBGroupSG.java 27 Aug 2004 01:02:42 -0000 1.13
+++ JAXBGroupSG.java 27 Aug 2004 13:19:26 -0000 1.14
@@ -104,17 +104,21 @@
public SGFactory getFactory(GroupSG pController) { return getFactory(); }
public SchemaSG getSchema(GroupSG pController) { return getSchema(); }
public Locator getLocator(GroupSG pController) { return getLocator(); }
- public ParticleSG[] getParticles(GroupSG pController) { return particles; }
+ public ParticleSG[] getParticles(GroupSG pController) throws SAXException {
+ if (particles == null) {
+ XSParticle[] xsParticles = ((XSGroup) getXSObject()).getParticles();
+ particles = new ParticleSG[xsParticles.length];
+ for (int i = 0; i < xsParticles.length; i++) {
+ ParticleSGChain chain = (ParticleSGChain) pController.newParticleSG(xsParticles[i]);
+ ParticleSG particle = new ParticleSGImpl(chain);
+ particle.init();
+ particles[i] = particle;
+ }
+ }
+ return particles;
+ }
public void init(GroupSG pController) throws SAXException {
- XSParticle[] xsParticles = ((XSGroup) getXSObject()).getParticles();
- particles = new ParticleSG[xsParticles.length];
- for (int i = 0; i < xsParticles.length; i++) {
- ParticleSGChain chain = (ParticleSGChain) pController.newParticleSG(xsParticles[i]);
- ParticleSG particle = new ParticleSGImpl(chain);
- particle.init();
- particles[i] = particle;
- }
}
public boolean isAll(GroupSG pController) { return isAll; }
@@ -177,8 +181,8 @@
ObjectSG elementSG = particle.getObjectSG();
TypeSG typeSG = elementSG.getTypeSG();
if (!typeSG.isGlobalType() && !typeSG.isGlobalClass() && typeSG.isComplex()) {
- ComplexTypeSG complexTypeSG = typeSG.getComplexTypeSG();
- complexTypeSG.getXMLInterface(pSource);
+ ComplexTypeSG complexTypeSG = typeSG.getComplexTypeSG();
+ complexTypeSG.getXMLInterface(pSource);
}
} else if (particle.isGroup()) {
GroupSG groupSG = particle.getGroupSG();
@@ -201,7 +205,7 @@
if (particle.isElement()) {
ObjectSG elementSG = particle.getObjectSG();
TypeSG typeSG = elementSG.getTypeSG();
- if (!typeSG.isGlobalType() && typeSG.isComplex()) {
+ if (!typeSG.isGlobalType() && !typeSG.isGlobalClass() && typeSG.isComplex()) {
ComplexTypeSG complexTypeSG = typeSG.getComplexTypeSG();
complexTypeSG.getXMLImplementation(pSource);
}
@@ -280,10 +284,15 @@
Context myClassContext =
child.getObjectSG().getTypeSG().getComplexTypeSG().getClassContext();
JavaQName serializerClass = myClassContext.getXMLSerializerName();
- JavaQName elementInterface = myClassContext.getXMLInterfaceName();
pMethod.addIf(fieldName + " == null");
pMethod.addTry();
if (child.getObjectSG().getTypeSG().isGlobalClass()) {
+ JavaQName elementInterface;
+ if (objectSG.isGlobal()) {
+ elementInterface = objectSG.getClassContext().getXMLInterfaceName();
+ } else {
+ elementInterface = myClassContext.getXMLInterfaceName();
+ }
pMethod.addLine(fieldName + " = ("+ serializerClass+ ") ",
"getFactory().getJMXmlSerializer(", elementInterface,
".class);");
@@ -404,10 +413,15 @@
jm2.addIf(handlerFieldName, " == null");
ComplexTypeSG childSG = typeSG.getComplexTypeSG();
- JavaQName interfaceName = childSG.getClassContext().getXMLInterfaceName();
JavaQName handlerClassName = childSG.getClassContext().getXMLHandlerName();
jm2.addTry();
if (typeSG.isGlobalClass()) {
+ JavaQName interfaceName;
+ if (objectSG.isGlobal()) {
+ interfaceName = objectSG.getClassContext().getXMLInterfaceName();
+ } else {
+ interfaceName = childSG.getClassContext().getXMLInterfaceName();
+ }
jm2.addLine(handlerFieldName, " = getData().getFactory().getJMHandler(",
interfaceName, ".class);");
} else {
1.6 +9 -2 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBObjectSG.java
Index: JAXBObjectSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBObjectSG.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JAXBObjectSG.java 16 Feb 2004 23:39:55 -0000 1.5
+++ JAXBObjectSG.java 27 Aug 2004 13:19:26 -0000 1.6
@@ -58,6 +58,7 @@
private final TypeSG typeSG;
private final XsQName name;
private final Context classContext;
+ private final boolean global;
/** <p>Creates a new, local instance of JAXBObjectSG, generating
* the given attribute within the given {@link Context}.</p>
@@ -95,7 +96,8 @@
log.finest(mName, "->", new Object[]{element.getName(), pClassContext});
type = element.getType();
name = element.getName();
- isClassGlobal = !type.isSimple() && (type.isGlobal() || element.isGlobal());
+ global = element.isGlobal();
+ isClassGlobal = !type.isSimple() && (type.isGlobal() || global);
} else {
throw new IllegalStateException("Unknown object type: " + pObject.getClass().getName());
}
@@ -144,7 +146,7 @@
public JAXBObjectSG(SGFactory pFactory, SchemaSG pSchema, TypeSG pComplexType,
XSSimpleContentType pContainer, XSType pType) throws SAXException {
super(pFactory, pSchema, pType);
-
+ global = false;
type = pType;
name = null;
classContext = pComplexType.getComplexTypeSG().getClassContext();
@@ -160,6 +162,7 @@
name = null;
classContext = null;
typeSG = null;
+ global = false;
}
public void init(ObjectSG pController) throws SAXException {
@@ -315,5 +318,9 @@
myTypeSG.generate();
}
log.finest(mName, "<-");
+ }
+
+ public boolean isGlobal(ObjectSG pController) throws SAXException {
+ return global;
}
}
1.7 +4 -2 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSGFactory.java
Index: JAXBSGFactory.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSGFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JAXBSGFactory.java 16 Feb 2004 23:39:55 -0000 1.6
+++ JAXBSGFactory.java 27 Aug 2004 13:19:26 -0000 1.7
@@ -70,7 +70,9 @@
private List objectsByOrder = new ArrayList();
private List typesByOrder = new ArrayList();
- public JAXBSGFactory(Generator pGenerator) {
+ /** Creates a new instance for the given {@link Generator}.
+ */
+ public JAXBSGFactory(Generator pGenerator) {
generator = pGenerator;
}
@@ -206,7 +208,7 @@
public TypeSG getTypeSG(SGFactory pController, XSType pType, Context pClassContext, XsQName pName) throws SAXException {
final String mName = "getTypeSG(XSType,ClassContext)";
log.finest(mName, "->", new Object[]{pType, pClassContext});
- TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType, pClassContext, pName);
+ TypeSGChain chain = (TypeSGChain) pController.newTypeSG(pType, pClassContext, pName);
TypeSG result = new TypeSGImpl(chain);
typesByOrder.add(result);
result.init();
1.2 +15 -0 ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/RecursionTest.java
Index: RecursionTest.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/RecursionTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RecursionTest.java 27 Aug 2004 01:02:41 -0000 1.1
+++ RecursionTest.java 27 Aug 2004 13:19:26 -0000 1.2
@@ -9,6 +9,7 @@
import javax.xml.bind.Unmarshaller;
import org.apache.ws.jaxme.impl.JMMarshallerImpl;
+import org.apache.ws.jaxme.test.recursion.Attribute;
import org.apache.ws.jaxme.test.recursion.DirectEmployee;
import org.apache.ws.jaxme.test.recursion.IndirectEmployee;
import org.apache.ws.jaxme.test.recursion.PotEmployee;
@@ -85,6 +86,20 @@
"</rec:PotEmployee>";
unmarshalMarshalUnmarshal(PotEmployee.class, xml2);
}
+
+ /** Tests recursion using element references.
+ */
+ public void testElementRecursion() throws Exception {
+ final String xml =
+ "<rec:Attribute name=\"Sam\" id=\"1\" xmlns:rec=\"http://ws.apache.org/jaxme/test/recursion\">\n" +
+ " <rec:AttributeList>\n" +
+ " <rec:Attribute name=\"Sonny\" id=\"2\">\n" +
+ " <rec:AttributeList/>\n" +
+ " </rec:Attribute>\n" +
+ " </rec:AttributeList>\n" +
+ "</rec:Attribute>";
+ unmarshalMarshalUnmarshal(Attribute.class, xml);
+ }
private void unmarshalMarshalUnmarshal(Class pClass, String pXML) throws Exception {
Object o = unmarshal(pClass, pXML);
1.25 +5 -0 ws-jaxme/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/ws-jaxme/status.xml,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- status.xml 27 Aug 2004 00:48:49 -0000 1.24
+++ status.xml 27 Aug 2004 13:19:26 -0000 1.25
@@ -36,6 +36,11 @@
</action>
</release>
<release version="0.3.1-dev" date="unreleased">
+ <action dev="JW" type="fix" context="generator">
+ Added support for recursive elements and types.
+ (Nacho G. Mac Dowell, igonzalez at informa.es)
+ See JAXME-26 in Jira.
+ </action>
<action dev="JW" type="fix" context="xs">
An element reference in a group wasn't flagged as global.
See JAXME-13 in Jira.
1.2 +2 -2 ws-jaxme/src/test/jaxb/recursion.xsd
Index: recursion.xsd
===================================================================
RCS file: /home/cvs/ws-jaxme/src/test/jaxb/recursion.xsd,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- recursion.xsd 27 Aug 2004 01:02:41 -0000 1.1
+++ recursion.xsd 27 Aug 2004 13:19:26 -0000 1.2
@@ -53,7 +53,7 @@
<element name="Attribute">
<complexType>
<sequence>
- <element name="AttributeList">
+ <element name="AttributeList" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element ref="rec:Attribute"/>
@@ -62,8 +62,8 @@
</element>
</sequence>
<attribute name="id" type="string" use="required"/>
+ <attribute name="name" type="string" use="required"/>
<attribute name="value" type="string" use="optional"/>
</complexType>
</element>
-
</schema>
1.3 +5 -0 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ObjectSG.java
Index: ObjectSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/ObjectSG.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ObjectSG.java 16 Feb 2004 23:39:50 -0000 1.2
+++ ObjectSG.java 27 Aug 2004 13:19:26 -0000 1.3
@@ -16,6 +16,7 @@
*/
package org.apache.ws.jaxme.generator.sg;
+import org.apache.ws.jaxme.js.JavaQName;
import org.apache.ws.jaxme.js.JavaSource;
import org.apache.ws.jaxme.xs.xml.XsQName;
import org.xml.sax.SAXException;
@@ -57,4 +58,8 @@
/** <p>Generates the objects sources.</p>
*/
public void generate() throws SAXException;
+
+ /** Returns whether the <code>ObjectSG</code> is global.
+ */
+ public boolean isGlobal() throws SAXException;
}
1.3 +1 -1 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/GroupSG.java
Index: GroupSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/GroupSG.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GroupSG.java 16 Feb 2004 23:39:50 -0000 1.2
+++ GroupSG.java 27 Aug 2004 13:19:26 -0000 1.3
@@ -81,7 +81,7 @@
/** <p>Returns the groups particles.</p>
*/
- public ParticleSG[] getParticles();
+ public ParticleSG[] getParticles() throws SAXException;
/** <p>Creates a new instance of
* {@link org.apache.ws.jaxme.generator.sg.ParticleSGChain} generating the
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org