Index: JAXBGroupSG.java
===================================================================
RCS file: /home/cvspublic/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBGroupSG.java,v
retrieving revision 1.13
diff -u -r1.13 JAXBGroupSG.java
--- JAXBGroupSG.java 27 Aug 2004 01:02:42 -0000 1.13
+++ JAXBGroupSG.java 27 Aug 2004 12:51:53 -0000
@@ -201,7 +201,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);
}
@@ -284,6 +284,9 @@
pMethod.addIf(fieldName + " == null");
pMethod.addTry();
if (child.getObjectSG().getTypeSG().isGlobalClass()) {
+ if (objectSG.getTypeSG().isGlobalClass()) {
+ elementInterface =objectSG.getClassContext().getXMLInterfaceName();
+ }
pMethod.addLine(fieldName + " = ("+ serializerClass+ ") ",
"getFactory().getJMXmlSerializer(", elementInterface,
".class);");
@@ -404,8 +407,8 @@
jm2.addIf(handlerFieldName, " == null");
ComplexTypeSG childSG = typeSG.getComplexTypeSG();
- JavaQName interfaceName = childSG.getClassContext().getXMLInterfaceName();
- JavaQName handlerClassName = childSG.getClassContext().getXMLHandlerName();
+ JavaQName interfaceName = objectSG.getClassContext().getXMLInterfaceName();
+ JavaQName handlerClassName = objectSG.getClassContext().getXMLHandlerName();
jm2.addTry();
if (typeSG.isGlobalClass()) {
jm2.addLine(handlerFieldName, " = getData().getFactory().getJMHandler(",
Index: JAXBObjectSG.java
===================================================================
RCS file: /home/cvspublic/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBObjectSG.java,v
retrieving revision 1.5
diff -u -r1.5 JAXBObjectSG.java
--- JAXBObjectSG.java 16 Feb 2004 23:39:55 -0000 1.5
+++ JAXBObjectSG.java 27 Aug 2004 12:51:54 -0000
@@ -55,9 +55,9 @@
public class JAXBObjectSG extends JAXBSGItem implements ObjectSGChain {
private final static Logger log = LoggerAccess.getLogger(JAXBObjectSG.class);
private final XSType type;
- private final TypeSG typeSG;
+ private TypeSG typeSG; //it can't be final as we will set its value in the init method
private final XsQName name;
- private final Context classContext;
+ private Context classContext;
/**
Creates a new, local instance of JAXBObjectSG, generating
* the given attribute within the given {@link Context}.
@@ -88,53 +88,16 @@
private JAXBObjectSG(SGFactory pFactory, SchemaSG pSchema, XSObject pObject,
Context pClassContext) throws SAXException {
super(pFactory, pSchema, pObject);
- final String mName = "(XSObject,Context)";
- boolean isClassGlobal;
if (pObject instanceof XSElement) {
- XSElement element = (XSElement) pObject;
- log.finest(mName, "->", new Object[]{element.getName(), pClassContext});
- type = element.getType();
- name = element.getName();
- isClassGlobal = !type.isSimple() && (type.isGlobal() || element.isGlobal());
- } else {
- throw new IllegalStateException("Unknown object type: " + pObject.getClass().getName());
- }
-
- Context myClassContext;
- final boolean useTypesContext = pClassContext != null;
- if (useTypesContext) {
- myClassContext = pClassContext;
- } else {
- myClassContext = new GlobalContext(name, pObject, null, null, pSchema);
- }
-
- if (isClassGlobal) {
- if (type.isGlobal()) {
- typeSG = pFactory.getTypeSG(type);
+ XSElement element = (XSElement) pObject;
+ type = element.getType();
+ name = element.getName();
} else {
- typeSG = pFactory.getTypeSG(type, name);
+ throw new IllegalStateException("Unknown object type: " + pObject.getClass().getName());
}
- } else {
- typeSG = pFactory.getTypeSG(type, myClassContext, name);
- }
+ classContext = pClassContext;
- if (useTypesContext) {
- if (typeSG.isComplex()) {
- classContext = typeSG.getComplexTypeSG().getClassContext();
- } else {
- classContext = pClassContext;
- }
- } else if (typeSG.isComplex()) {
- classContext = myClassContext;
- Context tctx = typeSG.getComplexTypeSG().getClassContext();
- AbstractContext ctx = (AbstractContext) classContext;
- ctx.setPMName(tctx.getPMName());
- ctx.setXMLSerializerName(tctx.getXMLSerializerName());
- ctx.setXMLValidatorName(tctx.getXMLValidatorName());
- } else {
- classContext = null;
- }
- log.finest(mName, "<-", new Object[]{typeSG, classContext});
+
}
/** Creates a new instance of JAXBObjectSG generating the given simple
@@ -163,11 +126,65 @@
}
public void init(ObjectSG pController) throws SAXException {
+ final String mName = "(XSObject,Context)";
+ XSElement element = (XSElement) getXSObject();
+ boolean isClassGlobal = !type.isSimple()
+ && (type.isGlobal() || element.isGlobal());
+ Context myClassContext;
+ boolean useTypesContext = getClassContext(pController) != null
+ && !((XSElement)getXSObject()).isGlobal();
+ //we need this second condition to prevent infinite loops in recursive referenced elements
+ //I noticed you changed the XSElement.isGlobal() to accept referenced elements as global
+ if (useTypesContext) {
+ myClassContext = getClassContext(pController);
+ } else {
+ myClassContext = new GlobalContext(name, getXSObject(), null, null, getSchema(pController));
+ }
+ if (isClassGlobal) {
+ if (type.isGlobal()) {
+ typeSG = getFactory().getTypeSG(type);
+ } else {//element is global, we check if a typeSG with the same XsQName has already been created
+ for (int i = 0; i < getFactory().getTypes().length; i++) {
+ if (getFactory().getTypes()[i].getName().equals(
+ element.getName())) {
+ typeSG = getFactory().getTypes()[i];
+ break;
+ }
+ }
+ if (typeSG == null) {
+ typeSG = getFactory().getTypeSG(type, name);
+ }
+ }
+ } else {
+ typeSG = getFactory().getTypeSG(type, myClassContext,
+ name);
+ }
+ if (useTypesContext) {
+ if (typeSG.isComplex()) {
+ classContext = typeSG.getComplexTypeSG().getClassContext();
+ }
+ }
+ else if (typeSG.isComplex()) {
+ classContext = myClassContext;
+ Context tctx = typeSG.getComplexTypeSG().getClassContext();
+ AbstractContext ctx = (AbstractContext) classContext;
+ ctx.setPMName(tctx.getPMName());
+ ctx.setXMLSerializerName(tctx.getXMLSerializerName());
+ ctx.setXMLValidatorName(tctx.getXMLValidatorName());
+ } else {
+ classContext = null;
+ }
+ log.finest(mName, "<-", new Object[] { typeSG, classContext });
}
public TypeSG getTypeSG(ObjectSG pController) {
if (typeSG == null) {
- throw new NullPointerException("ObjectSG not initialized");
+ try {
+ //as we go down the tree, it might not have been initialized
+ init(pController);
+ } catch (SAXException e) {
+ throw new NullPointerException("ObjectSG not initialized");
+ }
}
return typeSG;
}