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 2005/04/09 02:42:43 UTC
cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl JAXBSchemaSG.java
jochen 2005/04/08 17:42:43
Modified: . .cvsignore status.xml
src/jaxme/org/apache/ws/jaxme/generator/sg/impl
JAXBSchemaSG.java
Log:
The ObjectFactory does now contain methods for creating implementations
of anonymous content interfaces, like JAXB's does.
Revision Changes Path
1.5 +1 -0 ws-jaxme/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/ws-jaxme/.cvsignore,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- .cvsignore 8 Apr 2005 10:14:57 -0000 1.4
+++ .cvsignore 9 Apr 2005 00:42:43 -0000 1.5
@@ -3,3 +3,4 @@
dist
jaxme.properties
*.log
+xjc
1.44 +4 -0 ws-jaxme/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/ws-jaxme/status.xml,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- status.xml 8 Apr 2005 23:10:45 -0000 1.43
+++ status.xml 9 Apr 2005 00:42:43 -0000 1.44
@@ -31,6 +31,10 @@
<changes>
<release version="0.4-dev" date="unreleased">
<action dev="JW" type="enhancement" context="generator">
+ The ObjectFactory does now contain methods for creating
+ implementations of anonymous content interfaces.
+ </action>
+ <action dev="JW" type="enhancement" context="generator">
Added support for collection type "indexed".
</action>
<action dev="JW" type="fix" context="generator">
1.15 +73 -10 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSchemaSG.java
Index: JAXBSchemaSG.java
===================================================================
RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBSchemaSG.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- JAXBSchemaSG.java 14 Mar 2005 02:16:09 -0000 1.14
+++ JAXBSchemaSG.java 9 Apr 2005 00:42:43 -0000 1.15
@@ -33,9 +33,12 @@
import javax.xml.parsers.ParserConfigurationException;
import org.apache.ws.jaxme.XMLWriter;
+import org.apache.ws.jaxme.generator.sg.ComplexContentSG;
+import org.apache.ws.jaxme.generator.sg.ComplexTypeSG;
import org.apache.ws.jaxme.generator.sg.Context;
import org.apache.ws.jaxme.generator.sg.GroupSG;
import org.apache.ws.jaxme.generator.sg.ObjectSG;
+import org.apache.ws.jaxme.generator.sg.ParticleSG;
import org.apache.ws.jaxme.generator.sg.SGFactory;
import org.apache.ws.jaxme.generator.sg.SchemaSG;
import org.apache.ws.jaxme.generator.sg.SchemaSGChain;
@@ -451,7 +454,9 @@
}
}
- protected JavaSource getObjectFactory(SchemaSG pController, String pPackageName, List pContextList) {
+ protected JavaSource getObjectFactory(SchemaSG pController, String pPackageName,
+ List pContextList)
+ throws SAXException {
JavaQName qName = JavaQNameImpl.getInstance(pPackageName, "ObjectFactory");
JavaSource js = pController.getJavaSourceFactory().newJavaSource(qName, "public");
JavaField jf = js.newJavaField("jaxbContext", JAXBContextImpl.class, "private");
@@ -494,7 +499,7 @@
if (o instanceof ObjectSG) {
ObjectSG objectSG = ((ObjectSG) o);
typeSG = objectSG.getTypeSG();
- generateCreateMethod(js, objectSG.getClassContext());
+ generateCreateMethod(js, null, objectSG.getClassContext());
//NB: we don't have to check for duplicate element names since that would violate the XSD spec
} else if (o instanceof TypeSG) {
typeSG = (TypeSG) o;
@@ -502,27 +507,85 @@
continue;
}
- if (typeSG.isComplex() && !contextSet.contains(typeSG)) {
- // many global elements may have the same global complex type so must check first
- generateCreateMethod(js, typeSG.getComplexTypeSG().getClassContext());
- contextSet.add(typeSG);
- }
+ generateCreateMethod(js, contextSet, typeSG, null);
}
return js;
}
+ private void generateCreateMethod(JavaSource pJs, Set pContextSet,
+ TypeSG pType, String pPrefix) throws SAXException {
+ if (!pType.isComplex() || pContextSet.contains(pType)) {
+ return;
+ }
+ // many global elements may have the same global complex type so must check first
+ String prefix = generateCreateMethod(pJs, pPrefix, pType.getComplexTypeSG().getClassContext());
+ pContextSet.add(pType);
+ generateCreateMethods(pJs, pType, prefix, pContextSet);
+ }
+
+ /** Generate create methods for the given particles.
+ */
+ private void generateCreateMethods(JavaSource pJs, ParticleSG[] pParticles,
+ String pName, Set pContextSet)
+ throws SAXException {
+ for (int i = 0; i < pParticles.length; i++) {
+ ParticleSG particle = pParticles[i];
+ if (particle.isGroup()) {
+ GroupSG group = particle.getGroupSG();
+ generateCreateMethods(pJs, group.getParticles(), pName, pContextSet);
+ } else if (particle.isElement()) {
+ ObjectSG oSG = particle.getObjectSG();
+ if (oSG.isGlobal()) {
+ continue; // Will be generated elsewhere
+ }
+ TypeSG tSG = oSG.getTypeSG();
+ if (tSG.isGlobalType()) {
+ continue; // Will be generated elsewhere
+ }
+ generateCreateMethod(pJs, pContextSet, tSG, pName);
+ } else if (particle.isWildcard()) {
+ throw new IllegalStateException("TODO: Add support for wildcards here.");
+ } else {
+ throw new IllegalStateException("Invalid class type");
+ }
+ }
+ }
+
+ /** Generate create methods for the content.
+ */
+ private void generateCreateMethods(JavaSource pJs, TypeSG pType,
+ String pName, Set pContextSet)
+ throws SAXException {
+ ComplexTypeSG ctSG = pType.getComplexTypeSG();
+ if (ctSG.hasSimpleContent()) {
+ return; // No elements contained
+ }
+ ComplexContentSG ccSG = ctSG.getComplexContentSG();
+ if (ccSG.isEmpty()) {
+ return;
+ }
+ GroupSG group = ccSG.getGroupSG();
+ generateCreateMethods(pJs, group.getParticles(), pName, pContextSet);
+ }
+
/**
* Generic util method for generating the create<NAME> methods for the object factory.
* @param pSource the java source object to add the method
* @param pContext the Class Context from either an ObjectSG or a TypeSG
*/
- private void generateCreateMethod(JavaSource pSource, Context pContext) {
+ private String generateCreateMethod(JavaSource pSource, String pPrefix,
+ Context pContext) {
JavaQName resultName = pContext.getXMLInterfaceName();
- String className = resultName.getClassName();
- String methodName = "create" + Character.toUpperCase(className.charAt(0)) + className.substring(1);
+ String className = resultName.isInnerClass() ? resultName.getInnerClassName() : resultName.getClassName();
+ String result = Character.toUpperCase(className.charAt(0)) + className.substring(1);
+ if (pPrefix != null) {
+ result = pPrefix + result;
+ }
+ String methodName = "create" + result;
JavaMethod createMethod = pSource.newJavaMethod(methodName, resultName, "public");
createMethod.addThrows(JAXBException.class);
createMethod.addLine("return (", resultName, ") newInstance(", resultName, ".class);");
+ return result;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org
Re: JAXME-47
Posted by Jochen Wiedmann <jo...@gmail.com>.
On Apr 11, 2005 12:53 PM, Nacho G. Mac Dowell <ig...@informa.es> wrote:
> Would this be TypedValueImpl? I've noticed this may do exactly whay I am
> trying, the thing is I don't know how to pass it to JS. :-[
No, it is use of
SimpleTypeSG.getCastFromString(String)
In the case of the union type, you'd have to use that method for any
type in the union. The default value is invalid, if all throw an
exception.
Jochen
--
Outside of a dog, a book is man's best friend.
Inside of a dog, its too dark to read.
(Groucho Marx)
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org
Re: JAXME-47
Posted by "Nacho G. Mac Dowell" <ig...@informa.es>.
Jochen Wiedmann wrote:
>in that particular case, I'd beg you not to commit, but to attach your
>patch to the issue. See
>http://issues.apache.org/jira/browse/JAXME-47#action_57622 for the
>reason why: I believe that most of what you have done is already in
>place at a different point of the code.
>
>
>
Would this be TypedValueImpl? I've noticed this may do exactly whay I am
trying, the thing is I don't know how to pass it to JS. :-[
>>2. There is a test called defaultValues.xsd. Should I add my test case
>>to this one or should I create a jaxme47.xsd under src/test/jaxb/jira?
>>
>>
>
>Excellent, that you have a test case! Feel free, to choose what seems
>to make sense to you.
>
>
>
I'll go for the first option. It makes sense to have a full
defaultValues test.
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org
Re: JAXME-47
Posted by Jochen Wiedmann <jo...@gmail.com>.
Hi, Nacho,
On Apr 11, 2005 11:04 AM, Nacho G. Mac Dowell <ig...@informa.es> wrote:
> Hi Jochen, I was about to commit the changes for #JAXME-47 and I had a
> couple of questions:
in that particular case, I'd beg you not to commit, but to attach your
patch to the issue. See
http://issues.apache.org/jira/browse/JAXME-47#action_57622 for the
reason why: I believe that most of what you have done is already in
place at a different point of the code.
> 1. I created a DataTypeConverterUtil with some methods for retreiving
> the correct default value for a type. The thing is that the "natural"
> place for this would be jaxbapi, but since this class has nothing to do
> with jaxb I need advice on where to put this class (including package name).
As this class would be used by the generator and not at runtime, I'd
suggest org.apache.ws.jaxme.generator.util.
> 2. There is a test called defaultValues.xsd. Should I add my test case
> to this one or should I create a jaxme47.xsd under src/test/jaxb/jira?
Excellent, that you have a test case! Feel free, to choose what seems
to make sense to you.
Jochen
--
Outside of a dog, a book is man's best friend.
Inside of a dog, its too dark to read.
(Groucho Marx)
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org
JAXME-47
Posted by "Nacho G. Mac Dowell" <ig...@informa.es>.
Hi Jochen, I was about to commit the changes for #JAXME-47 and I had a
couple of questions:
1. I created a DataTypeConverterUtil with some methods for retreiving
the correct default value for a type. The thing is that the "natural"
place for this would be jaxbapi, but since this class has nothing to do
with jaxb I need advice on where to put this class (including package name).
2. There is a test called defaultValues.xsd. Should I add my test case
to this one or should I create a jaxme47.xsd under src/test/jaxb/jira?
Thanks!
Nacho
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org