Source Reflection: handling of multidimensional arrays
Hello I'm new to this list and rather new to JAXME, too, so please point me to an appropriate manual if I'm missing something. I did a quick look at the archive, but found nothing about this. What I want to do is Java source reflection, with JaxMeJs, for proxy generation. I noticed that the parser can't handle multidimensional arrays as input parameter for methods. Possibly also elsewhere, but I did only look at this specific subject. public void testArray2Nested(de.ahring.generated.Test_InNested[][] foo2) throws RemoteException; when I parse the source (js.parse), get the list of methods (js.getMethods), get the parameters of this method (method.getParams) and look at the returned type (param.getType) the type is de.ahring.generated.Text_InNested[] - so only one dimension is read. I did a bit of debugging and found that in JavaParser.java, parseIdentifier(AST, StringBuffer) the JavaToken 'DOT' is used with a loop, getting all childelements, whereas the JavaToken 'ARRAY_DECLARATOR' only appends '[]' one time, then quits. case JavaTokenTypes.ARRAY_DECLARATOR: sb.append("[]"); break; The AST - without having looked into the complete source I assume this is the preparsed structure the ANTLR generates - does have the second '[', in the down-AST. So I changed it to: case JavaTokenTypes.ARRAY_DECLARATOR: sb.append("[]"); // 08.07.2005 FAHRING Hack for multi dimension arrays for (AST child = pAST.getFirstChild(); child != null; child = child.getNextSibling()) { parseIdentifier(child, sb); } // END HACK break; Now it get's parsed correctly: type is [EMAIL PROTECTED], holding itself an [EMAIL PROTECTED] and only then the [EMAIL PROTECTED] I have not yet checked what sideeffects this might have nor if it would be necessary to make other changes as well to fully support it. I would like to hear your opinion of this. was it a missing feature (bug) or left out on purpose? Would my hack fix it or break things in other places? Feel free to comment. If it's a good idea, commit it to the CVS. Frankly, I've no idea how to do this since I've never done it before :) :Frederic: - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: ws-jaxme/src/js/org/apache/ws/jaxme/js/util JavaParser.java
jochen 2005/07/08 07:45:07 Modified:.status.xml src/js/org/apache/ws/jaxme/js/util JavaParser.java Log: The JavaParser didn't handle multidimensional arrays properly. Submitted by: [EMAIL PROTECTED] Revision ChangesPath 1.59 +4 -0 ws-jaxme/status.xml Index: status.xml === RCS file: /home/cvs/ws-jaxme/status.xml,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- status.xml6 Jul 2005 21:34:14 - 1.58 +++ status.xml8 Jul 2005 14:45:07 - 1.59 @@ -42,6 +42,10 @@ Fixed that the handler and driver classes could not be compiled, if enumerations had default values. + +The JavaParser didn't handle multidimensional arrays +properly. (Frederic Ahring, [EMAIL PROTECTED]) + 1.8 +4 -0 ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java Index: JavaParser.java === RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- JavaParser.java 9 Sep 2004 00:41:46 - 1.7 +++ JavaParser.java 8 Jul 2005 14:45:07 - 1.8 @@ -168,6 +168,10 @@ break; case JavaTokenTypes.ARRAY_DECLARATOR: sb.append("[]"); +for (AST child = pAST.getFirstChild(); child != null; + child = child.getNextSibling()) { + parseIdentifier(child, sb); +} break; default: throw new IllegalStateException("Unknown token: " + pAST.getType()); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: ws-jaxme status.xml
jochen 2005/07/08 07:45:17 Modified:src/js/org/apache/ws/jaxme/js/util Tag: v0_4 JavaParser.java .Tag: v0_4 status.xml Log: The JavaParser didn't handle multidimensional arrays properly. Submitted by: [EMAIL PROTECTED] Revision ChangesPath No revision No revision 1.7.2.1 +4 -0 ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java Index: JavaParser.java === RCS file: /home/cvs/ws-jaxme/src/js/org/apache/ws/jaxme/js/util/JavaParser.java,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -r1.7 -r1.7.2.1 --- JavaParser.java 9 Sep 2004 00:41:46 - 1.7 +++ JavaParser.java 8 Jul 2005 14:45:17 - 1.7.2.1 @@ -168,6 +168,10 @@ break; case JavaTokenTypes.ARRAY_DECLARATOR: sb.append("[]"); +for (AST child = pAST.getFirstChild(); child != null; + child = child.getNextSibling()) { + parseIdentifier(child, sb); +} break; default: throw new IllegalStateException("Unknown token: " + pAST.getType()); No revision No revision 1.45.2.12 +4 -0 ws-jaxme/status.xml Index: status.xml === RCS file: /home/cvs/ws-jaxme/status.xml,v retrieving revision 1.45.2.11 retrieving revision 1.45.2.12 diff -u -r1.45.2.11 -r1.45.2.12 --- status.xml5 Jul 2005 08:03:42 - 1.45.2.11 +++ status.xml8 Jul 2005 14:45:17 - 1.45.2.12 @@ -39,6 +39,10 @@ Fixed that the handler and driver classes could not be compiled, if enumerations had default values. + +The JavaParser didn't handle multidimensional arrays +properly. (Frederic Ahring, [EMAIL PROTECTED]) + - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Source Reflection: handling of multidimensional arrays
Thanks, excellent evaluation! Applied to 0.4 branch and HEAD. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Source Reflection: handling of multidimensional arrays
Hi, Frederic, rein neugierdehalber: Was hast Du mit dem JavaParser denn vor? Gruß und nochmals danke für den Bugreport, Jochen - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JaxMe
Hi, Marc, Cobery, Marc (Marc) wrote: I am looking to add the jm:javasorce element to my schema similar to this example for JaxMe1. http://jaxme.sourceforge.net/examples/misc/implements.xsd public void update(java.util.Observable o, Object arg) { if (arg instanceof Integer) { if (eObservedNumbers == null) { eObservedNumbers = new java.util.ArrayList(); } eObservedNumbers.add(arg); } } Is this possible with JaxMe2? It appears to me that it would but I can not figure out how to do this modification with JaxMe2. Sorry to say, but this wasn't yet ported. In fact, you are the first one requesting it. Adding these things wouldn't be too possible, but for me it has low priority. However, note, that with the CVS version of JM2, you have the advantage that inheritance (xs:extension) works fine. Jochen - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit ParserTest.java
jochen 2005/07/08 13:44:02 Modified:src/xs/org/apache/ws/jaxme/xs/junit ParserTest.java src/jaxme/org/apache/ws/jaxme/generator/sg/impl JAXBGroupSG.java JAXBComplexContentTypeSG.java JAXBParticleSG.java JAXBComplexTypeSG.java JAXBSchemaSG.java .status.xml src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg GroupHandlerSG.java ParticleWalker.java src/pm/org/apache/ws/jaxme/pm/generator/jdbc JaxMeJdbcSG.java src/test/jaxb build.xml src/jaxme/org/apache/ws/jaxme/generator/sg ComplexContentSG.java src/jaxme/org/apache/ws/jaxme/junit ParserTest.java Log: Fixed that the generator didn't detect and refuse a complex type with a group of muliplicity > 1. Revision ChangesPath 1.25 +31 -0 ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/ParserTest.java Index: ParserTest.java === RCS file: /home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/ParserTest.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- ParserTest.java 19 May 2005 20:30:33 - 1.24 +++ ParserTest.java 8 Jul 2005 20:43:30 - 1.25 @@ -1520,4 +1520,35 @@ testRecursiveXsInclude(newXSParser()); testRecursiveXsInclude(newJAXBParser()); } + + + private void testGroupMultiplicity(XSParser pParser) throws Exception { + final String schemaSource = + "\n" + + "\n" + + " \n" + + "\n" + + " \n" + + " \n" + + " \n" + + "\n" + + " \n" + + "\n"; +InputSource isource = new InputSource(new StringReader(schemaSource)); +isource.setSystemId("testElementReferenceGlobal.xsd"); +XSSchema schema = pParser.parse(isource); +XSElement[] elements = schema.getElements(); +assertEquals(1, elements.length); +XSElement parameters = elements[0]; +XSParticle particle = assertComplexContent(assertComplexType(parameters.getType())); +assertEquals(1, particle.getMinOccurs()); +assertEquals(-1, particle.getMaxOccurs()); + } + + /** Test the representation of groups with multiplicity > 1. + */ + public void testGroupMultiplicity() throws Exception { + testGroupMultiplicity(newXSParser()); + testGroupMultiplicity(newJAXBParser()); + } } 1.21 +1 -1 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.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- JAXBGroupSG.java 14 Mar 2005 02:16:09 - 1.20 +++ JAXBGroupSG.java 8 Jul 2005 20:43:31 - 1.21 @@ -64,7 +64,7 @@ } public Object newParticleSG(GroupSG pController, XSParticle pParticle) throws SAXException { - return new JAXBParticleSG(pController, pParticle, classContext); + return new JAXBParticleSG(pController.getFactory(), pParticle, classContext); } public Context getClassContext(GroupSG pController) { return classContext; } 1.10 +17 -8 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexContentTypeSG.java Index: JAXBComplexContentTypeSG.java === RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexContentTypeSG.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- JAXBComplexContentTypeSG.java 29 Apr 2005 09:55:27 - 1.9 +++ JAXBComplexContentTypeSG.java 8 Jul 2005 20:43:31 - 1.10 @@ -21,9 +21,11 @@ import org.apache.ws.jaxme.generator.sg.ComplexContentSG; import org.apache.ws.jaxme.generator.sg.ComplexContentSGChain; 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.logging.Logger; import org.apache.ws.jaxme.logging.LoggerAccess; import org.apache.ws.jaxme.xs.XSGroup; @
cvs commit: ws-jaxme/src/pm/org/apache/ws/jaxme/pm/generator/jdbc JaxMeJdbcSG.java
jochen 2005/07/08 13:45:19 Modified:src/jaxme/org/apache/ws/jaxme/generator/sg/impl Tag: v0_4 JAXBParticleSG.java JAXBComplexTypeSG.java JAXBComplexContentTypeSG.java JAXBGroupSG.java JAXBSchemaSG.java src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg Tag: v0_4 GroupBeanSG.java GroupDriverSG.java GroupHandlerSG.java .Tag: v0_4 status.xml src/xs/org/apache/ws/jaxme/xs/junit Tag: v0_4 ParserTest.java src/jaxme/org/apache/ws/jaxme/junit Tag: v0_4 ParserTest.java src/jaxme/org/apache/ws/jaxme/generator/sg Tag: v0_4 ComplexContentSG.java src/test/jaxb Tag: v0_4 build.xml src/pm/org/apache/ws/jaxme/pm/generator/jdbc Tag: v0_4 JaxMeJdbcSG.java Log: Fixed that the generator didn't detect and refuse a complex type with a group of muliplicity > 1. Revision ChangesPath No revision No revision 1.8.2.1 +6 -7 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBParticleSG.java Index: JAXBParticleSG.java === RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBParticleSG.java,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -u -r1.8 -r1.8.2.1 --- JAXBParticleSG.java 8 Apr 2005 23:10:46 - 1.8 +++ JAXBParticleSG.java 8 Jul 2005 20:44:34 - 1.8.2.1 @@ -49,24 +49,23 @@ /** Creates a new instance of JAXBParticleSG.java. */ -public JAXBParticleSG(GroupSG pGroup, XSParticle pParticle, Context pClassContext) throws SAXException { -minOccurs = pParticle.getMinOccurs(); +public JAXBParticleSG(SGFactory pFactory, XSParticle pParticle, Context pClassContext) throws SAXException { + minOccurs = pParticle.getMinOccurs(); maxOccurs = pParticle.getMaxOccurs(); type = pParticle.getType(); -SGFactory factory = pGroup.getFactory(); if (pParticle.isGroup()) { -groupSG = factory.getGroupSG(pParticle.getGroup(), pClassContext); +groupSG = pFactory.getGroupSG(pParticle.getGroup(), pClassContext); objectSG = null; } else if (pParticle.isElement()) { element = pParticle.getElement(); if (element.isGlobal()) { -objectSG = factory.getObjectSG(element); +objectSG = pFactory.getObjectSG(element); } else { - objectSG = factory.getObjectSG(element, pClassContext); + objectSG = pFactory.getObjectSG(element, pClassContext); } groupSG = null; } else if (pParticle.isWildcard()) { - objectSG = factory.getObjectSG(pParticle.getWildcard(), pClassContext); + objectSG = pFactory.getObjectSG(pParticle.getWildcard(), pClassContext); groupSG = null; wildcard = pParticle.getWildcard(); } else { 1.17.2.2 +3 -3 ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexTypeSG.java Index: JAXBComplexTypeSG.java === RCS file: /home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/JAXBComplexTypeSG.java,v retrieving revision 1.17.2.1 retrieving revision 1.17.2.2 diff -u -r1.17.2.1 -r1.17.2.2 --- JAXBComplexTypeSG.java4 Jul 2005 23:59:19 - 1.17.2.1 +++ JAXBComplexTypeSG.java8 Jul 2005 20:44:34 - 1.17.2.2 @@ -222,7 +222,7 @@ if (ccSG.isEmpty()) { return new EmptyElementBeanSG(pController, pJs); } else { - GroupSG group = ccSG.getGroupSG(); + GroupSG group = ccSG.getRootParticle().getGroupSG(); if (group.isAll()) { return new AllBeanSG(pController, pJs); } else if (group.isChoice()) { @@ -278,7 +278,7 @@ if (ccSG.isEmpty()) { return new EmptyElementDriverSG(pController, pSource); } else { - GroupSG group = ccSG.getGroupSG(); + GroupSG group = ccSG.getRootParticle().getGroupSG(); if (group.isSequence()) { return new SequenceDriverSG(pController, pSource); } else if (group.isChoice()) { @@ -341,7 +341,7 @@