modello-1.1/0000755000175000017500000000000011260056270011771 5ustar mkochmkochmodello-1.1/modello-plugins/0000755000175000017500000000000011260056267015111 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/0000755000175000017500000000000011260056266021014 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/pom.xml0000644000175000017500000000455511243557055022345 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-stax Modello StAX Plugin Modello StAX Plugin generates XML readers and writers based on StAX API, plus reader delegates to be able to read multiple model versions. org.codehaus.modello modello-plugin-xml org.codehaus.modello modello-plugin-java net.java.dev.stax-utils stax-utils 20060502 com.bea.xml jsr173-ri test stax stax-api 1.0.1 test org.codehaus.woodstox wstx-asl 3.2.0 test xmlunit xmlunit 1.2 test modello-1.1/modello-plugins/modello-plugin-stax/src/0000755000175000017500000000000011260056266021603 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/0000755000175000017500000000000011260056265022561 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/0000755000175000017500000000000011260056266024560 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespace/0000755000175000017500000000000011260056266032712 5ustar mkochmkoch././@LongLink0000000000000000000000000000021200000000000011560 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespace/StaxVerifierWrongVersionNamespace.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespace/S0000644000175000017500000000476011127507731033046 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.vin.Model; import org.codehaus.modello.test.model.vin.io.stax.VersionInNamespaceStaxReader; import org.codehaus.modello.verifier.Verifier; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.io.IOException; import java.io.Reader; import javax.xml.stream.XMLStreamException; /** * @version $Id: StaxVerifierWrongVersionNamespace.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxVerifierWrongVersionNamespace extends Verifier { public void verify() throws IOException, XMLStreamException { File file = new File( "src/test/verifiers/stax-wrong-version-in-namespace/wrong-version-in-namespace.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); VersionInNamespaceStaxReader modelReader = new VersionInNamespaceStaxReader(); Assert.assertEquals( "3.2.1", modelReader.determineVersion( reader ) ); reader = ReaderFactory.newXmlReader( file ); try { modelReader.read( reader ); Assert.fail( "Should have choked on the version" ); } catch ( XMLStreamException e ) { Assert.assertTrue( e.getMessage().endsWith( "Document model version of '3.2.1' doesn't match reader version of '4.0.0'" ) ); } } } ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespace/wrong-version-in-namespace.xmlmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespace/w0000644000175000017500000000055111127507731033104 0ustar mkochmkoch Something out of place. Maven modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version/0000755000175000017500000000000011260056266030354 5ustar mkochmkoch././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version/StaxVerifierWrongVersion.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version/StaxVerifierWr0000644000175000017500000000467011127507731033232 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.vif.Model; import org.codehaus.modello.test.model.vif.io.stax.VersionInFieldStaxReader; import org.codehaus.modello.verifier.Verifier; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.io.IOException; import java.io.Reader; import javax.xml.stream.XMLStreamException; /** * @version $Id: StaxVerifierWrongVersion.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxVerifierWrongVersion extends Verifier { public void verify() throws IOException, XMLStreamException { File file = new File( "src/test/verifiers/stax-wrong-version/wrong-version.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); VersionInFieldStaxReader modelReader = new VersionInFieldStaxReader(); Assert.assertEquals( "1.2.3", modelReader.determineVersion( reader ) ); reader = ReaderFactory.newXmlReader( file ); try { modelReader.read( reader ); Assert.fail( "Should have choked on the version" ); } catch ( XMLStreamException e ) { Assert.assertTrue( e.getMessage().endsWith( "Document model version of '1.2.3' doesn't match reader version of '4.0.0'" ) ); } } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version/wrong-version.xmlmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version/wrong-version.0000644000175000017500000000026111127507731033173 0ustar mkochmkoch Something out of place. 1.2.3 Maven modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-parts/0000755000175000017500000000000011260056265026665 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-parts/parts.xml0000644000175000017500000000541211222235713030535 0ustar mkochmkoch parent single Single Reference other Other Reference another Another Reference Dummy 1 Description 1 Dummy 2 Description 2 Dummy 3 Description 3 content value ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-parts/StaxVerifierParts.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-parts/StaxVerifierParts.java0000644000175000017500000002235311127507731033163 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.parts.Model; import org.codehaus.modello.test.model.parts.SingleReference; import org.codehaus.modello.test.model.parts.Reference; import org.codehaus.modello.test.model.parts.DummyReference; import org.codehaus.modello.test.model.parts.DummyIdReference; import org.codehaus.modello.test.model.parts.io.stax.PartsStaxReader; import org.codehaus.modello.test.model.parts.io.stax.PartsStaxWriter; import org.codehaus.modello.verifier.Verifier; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.io.IOException; import java.io.Reader; import java.io.StringWriter; import javax.xml.stream.XMLStreamException; /** * @version $Id: StaxVerifierParts.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxVerifierParts extends Verifier { public void verify() throws IOException, XMLStreamException { File file = new File( "src/test/verifiers/stax-parts/parts.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); PartsStaxReader modelReader = new PartsStaxReader(); Model model = modelReader.read( reader ); Assert.assertNotNull( model.getSingleReference() ); Assert.assertNotNull( model.getSingleReference().getReference() ); Assert.assertEquals( "single", model.getSingleReference().getReference().getId() ); Assert.assertEquals( "Single Reference", model.getSingleReference().getReference().getName() ); Assert.assertEquals( "single", model.getSecondReference().getReference().getId() ); Assert.assertEquals( "Single Reference", model.getSecondReference().getReference().getName() ); Assert.assertEquals( "other", model.getThirdReference().getReference().getId() ); Assert.assertEquals( "Other Reference", model.getThirdReference().getReference().getName() ); Assert.assertNull( model.getNullReference().getReference() ); Assert.assertEquals( "single", model.getDualReference().getFirst().getId() ); Assert.assertEquals( "Single Reference", model.getDualReference().getFirst().getName() ); Assert.assertEquals( "other", model.getDualReference().getSecond().getId() ); Assert.assertEquals( "Other Reference", model.getDualReference().getSecond().getName() ); Assert.assertEquals( "single", model.getDupeReference().getFirst().getId() ); Assert.assertEquals( "Single Reference", model.getDupeReference().getFirst().getName() ); Assert.assertEquals( "single", model.getDupeReference().getSecond().getId() ); Assert.assertEquals( "Single Reference", model.getDupeReference().getSecond().getName() ); Assert.assertEquals( "single", ((Reference)model.getReferenceList().getItems().get( 0 )).getId() ); Assert.assertEquals( "Single Reference", ((Reference)model.getReferenceList().getItems().get( 0 )).getName() ); Assert.assertEquals( "single", ((Reference)model.getReferenceList().getItems().get( 1 )).getId() ); Assert.assertEquals( "Single Reference", ((Reference)model.getReferenceList().getItems().get( 1 )).getName() ); Assert.assertEquals( "other", ((Reference)model.getReferenceList().getItems().get( 2 )).getId() ); Assert.assertEquals( "Other Reference", ((Reference)model.getReferenceList().getItems().get( 2 )).getName() ); Assert.assertEquals( "another", ((Reference)model.getReferenceList().getItems().get( 3 )).getId() ); Assert.assertEquals( "Another Reference", ((Reference)model.getReferenceList().getItems().get( 3 )).getName() ); Assert.assertEquals( "other", ((SingleReference)model.getSingleReferences().get( 0 )).getReference().getId() ); Assert.assertEquals( "Other Reference", ((SingleReference)model.getSingleReferences().get( 0 )).getReference().getName() ); Assert.assertEquals( "single", ((SingleReference)model.getSingleReferences().get( 1 )).getReference().getId() ); Assert.assertEquals( "Single Reference", ((SingleReference)model.getSingleReferences().get( 1 )).getReference().getName() ); Assert.assertEquals( "another", ((SingleReference)model.getSingleReferences().get( 2 )).getReference().getId() ); Assert.assertEquals( "Another Reference", ((SingleReference)model.getSingleReferences().get( 2 )).getReference().getName() ); Assert.assertEquals( "parent", model.getNestedReference().getId() ); Assert.assertEquals( model.getNestedReference(), model.getNestedReference().getChildReference().getParentReference() ); Assert.assertEquals( 3, model.getReferences().size() ); Assert.assertNotNull( model.getDummyReference() ); Assert.assertNotNull( model.getDummyReference().getReference() ); Assert.assertEquals( "Dummy 2", model.getDummyReference().getReference().getName() ); Assert.assertEquals( "Description 2", model.getDummyReference().getReference().getDescription() ); Assert.assertNotNull( model.getOtherDummyReference() ); Assert.assertNotNull( model.getOtherDummyReference().getReference() ); Assert.assertEquals( "Dummy 1", model.getOtherDummyReference().getReference().getName() ); Assert.assertEquals( "Description 1", model.getOtherDummyReference().getReference().getDescription() ); Assert.assertEquals( 3, model.getDummyIdReferences().size() ); Assert.assertEquals( 4, model.getDummyReferences().size() ); Assert.assertEquals( "Dummy 3", ((DummyReference)model.getDummyReferences().get( 0 )).getReference().getName() ); Assert.assertEquals( "Description 3", ((DummyReference)model.getDummyReferences().get( 0 )).getReference().getDescription() ); Assert.assertEquals( "Dummy 1", ((DummyReference)model.getDummyReferences().get( 1 )).getReference().getName() ); Assert.assertEquals( "Description 1", ((DummyReference)model.getDummyReferences().get( 1 )).getReference().getDescription() ); Assert.assertEquals( "Dummy 1", ((DummyReference)model.getDummyReferences().get( 2 )).getReference().getName() ); Assert.assertEquals( "Description 1", ((DummyReference)model.getDummyReferences().get( 2 )).getReference().getDescription() ); Assert.assertEquals( "Dummy 2", ((DummyReference)model.getDummyReferences().get( 3 )).getReference().getName() ); Assert.assertEquals( "Description 2", ((DummyReference)model.getDummyReferences().get( 3 )).getReference().getDescription() ); Assert.assertEquals( 4, model.getDummyPointers().size() ); Assert.assertEquals( "Dummy 3", ((DummyIdReference)model.getDummyPointers().get( 0 )).getName() ); Assert.assertEquals( "Description 3", ((DummyIdReference)model.getDummyPointers().get( 0 )).getDescription() ); Assert.assertEquals( "Dummy 1", ((DummyIdReference)model.getDummyPointers().get( 1 )).getName() ); Assert.assertEquals( "Description 1", ((DummyIdReference)model.getDummyPointers().get( 1 )).getDescription() ); Assert.assertEquals( "Dummy 1", ((DummyIdReference)model.getDummyPointers().get( 2 )).getName() ); Assert.assertEquals( "Description 1", ((DummyIdReference)model.getDummyPointers().get( 2 )).getDescription() ); Assert.assertEquals( "Dummy 2", ((DummyIdReference)model.getDummyPointers().get( 3 )).getName() ); Assert.assertEquals( "Description 2", ((DummyIdReference)model.getDummyPointers().get( 3 )).getDescription() ); String expected = FileUtils.fileRead( file ); PartsStaxWriter modelWriter = new PartsStaxWriter(); StringWriter w = new StringWriter(); modelWriter.write( w, model ); Assert.assertEquals( cleanLineEndings( expected ).trim(), scrubXmlDeclQuotes( w.toString() ).trim() ); } private String scrubXmlDeclQuotes( String s ) { s = cleanLineEndings( s ); if ( s.startsWith( "")) { return "" + s.substring( "".length() ); } return s; } private String cleanLineEndings( String s ) { return s.replaceAll( "\r\n", "\n" ); } } modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespace/0000755000175000017500000000000011260056265031557 5ustar mkochmkoch././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespace/StaxVerifierVersionInNamespace.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespace/StaxVer0000644000175000017500000000450411127507731033102 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.vin.Model; import org.codehaus.modello.test.model.vin.io.stax.VersionInNamespaceStaxReader; import org.codehaus.modello.verifier.Verifier; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.io.IOException; import java.io.Reader; import javax.xml.stream.XMLStreamException; /** * @version $Id: StaxVerifierVersionInNamespace.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxVerifierVersionInNamespace extends Verifier { public void verify() throws IOException, XMLStreamException { File file = new File( "src/test/verifiers/stax-version-in-namespace/version-in-namespace.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); VersionInNamespaceStaxReader modelReader = new VersionInNamespaceStaxReader(); Assert.assertEquals( "4.0.0", modelReader.determineVersion( reader ) ); reader = ReaderFactory.newXmlReader( file ); Model model = modelReader.read( reader ); Assert.assertEquals( "Maven", model.getName() ); Assert.assertEquals( "Something out of place.", model.getDescription() ); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespace/version-in-namespace.xmlmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespace/version0000644000175000017500000000055111127507731033171 0ustar mkochmkoch Something out of place. Maven modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/features/0000755000175000017500000000000011260056266026376 5ustar mkochmkoch././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/features/StaxFeaturesVerifier.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/features/StaxFeaturesVerifier.jav0000644000175000017500000001634111241472401033207 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.features.Features; import org.codehaus.modello.test.features.io.stax.ModelloFeaturesTestStaxReader; import org.codehaus.modello.test.features.io.stax.ModelloFeaturesTestStaxWriter; import org.codehaus.modello.verifier.Verifier; import org.codehaus.modello.verifier.VerifierException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.io.StringWriter; import javax.xml.stream.XMLStreamException; /** * @author Herve Boutemy * @version $Id: StaxFeaturesVerifier.java 1302 2009-08-15 08:42:41Z hboutemy $ */ public class StaxFeaturesVerifier extends Verifier { public void verify() throws Exception { Features features = verifyReader(); features.getXmlFeatures().getXmlTransientFields().setTransientString( "NOT-TO-BE-WRITTEN" ); verifyWriter( features ); verifyBadVersion(); verifyWrongElement(); verifyTransientElement(); verifyEncoding(); } public Features verifyReader() throws Exception { ModelloFeaturesTestStaxReader reader = new ModelloFeaturesTestStaxReader(); return reader.read( getXmlResourceReader( "/features.xml" ) ); } public void verifyWriter( Features features ) throws Exception { ModelloFeaturesTestStaxWriter writer = new ModelloFeaturesTestStaxWriter(); StringWriter buffer = new StringWriter(); writer.write( buffer, features ); String initialXml = IOUtil.toString( getXmlResourceReader( "/features.xml" ) ); String actualXml = buffer.toString(); // alias is rendered as default field name => must be reverted here to let the test pass actualXml = actualXml.replaceFirst( "alias", "alias" ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreComments( true ); Diff diff = XMLUnit.compareXML( initialXml, actualXml ); if ( !diff.identical() ) { System.err.println( actualXml ); throw new VerifierException( "writer result is not the same as original content: " + diff ); } } public void verifyBadVersion() throws Exception { ModelloFeaturesTestStaxReader reader = new ModelloFeaturesTestStaxReader(); try { reader.read( getXmlResourceReader( "/features-bad-version.xml" ) ); throw new VerifierException( "Reading a document with a version different from the version of the parser should fail." ); } catch ( XMLStreamException xse ) { // expected failure checkExpectedFailure( xse, "Document model version of '2.0.0' doesn't match reader version of '1.0.0'" ); } } public void verifyWrongElement() throws Exception { ModelloFeaturesTestStaxReader reader = new ModelloFeaturesTestStaxReader(); // reading with strict=false should accept unknown element reader.read( getXmlResourceReader( "/features-wrong-element.xml" ), false ); reader.read( getXmlResourceReader( "/features-wrong-element2.xml" ), false ); // by default, strict=true: reading should not accept unknown element try { reader.read( getXmlResourceReader( "/features-wrong-element.xml" ) ); throw new VerifierException( "Reading a document with an unknown element under strict option should fail." ); } catch ( XMLStreamException xse ) { // expected failure checkExpectedFailure( xse, "'invalidElement'" ); } try { reader.read( getXmlResourceReader( "/features-wrong-element2.xml" ) ); throw new VerifierException( "Reading a document with an unknown element under strict option should fail." ); } catch ( XMLStreamException xse ) { checkExpectedFailure( xse, "'invalidElement'" ); } } public void verifyTransientElement() throws Exception { ModelloFeaturesTestStaxReader reader = new ModelloFeaturesTestStaxReader(); try { reader.read( getXmlResourceReader( "/features-invalid-transient.xml" ) ); fail( "Transient fields should not be processed by parser." ); } catch ( XMLStreamException e ) { checkExpectedFailure( e, "transientString" ); } } private void checkExpectedFailure( XMLStreamException xse, String expectedMessage ) throws VerifierException { if ( xse.getMessage().indexOf( expectedMessage ) < 0 ) { throw new VerifierException( "Unexpected failure: \"" + xse.getMessage() + "\"", xse ); } } private void checkEncoding( String resource, String encoding ) throws Exception { ModelloFeaturesTestStaxReader reader = new ModelloFeaturesTestStaxReader(); Features features = reader.read( getXmlResourceReader( resource ) ); assertEquals( "modelEncoding", encoding, features.getModelEncoding() ); ModelloFeaturesTestStaxWriter writer = new ModelloFeaturesTestStaxWriter(); StringWriter buffer = new StringWriter(); writer.write( buffer, features ); String xmlHeader = buffer.toString().substring( 0, 44 ); if ( encoding == null ) { assertTrue( xmlHeader, xmlHeader.startsWith( "" ) ); } else { assertTrue( xmlHeader, xmlHeader.startsWith( "" ) ); } } public void verifyEncoding() throws Exception { checkEncoding( "/features.xml", null ); checkEncoding( "/features-UTF-8.xml", "UTF-8" ); checkEncoding( "/features-Latin-15.xml", "ISO-8859-15" ); } } modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate/0000755000175000017500000000000011260056266032232 5ustar mkochmkoch././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate/input-4.0.0.xmlmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate/inpu0000644000175000017500000000273711127507731033141 0ustar mkochmkoch Something out of place. Maven ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate/input-4.0.1.xmlmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate/inpu0000644000175000017500000000273711127507731033141 0ustar mkochmkoch Something out of place. Maven ././@LongLink0000000000000000000000000000020700000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate/StaxVerifierVersionReaderDelegate.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate/Stax0000644000175000017500000000504211127507731033075 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.vin.io.stax.VersionInNamespaceStaxReaderDelegate; import org.codehaus.modello.verifier.Verifier; import java.io.File; import java.io.IOException; import javax.xml.stream.XMLStreamException; /** * @version $Id: StaxVerifierVersionReaderDelegate.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxVerifierVersionReaderDelegate extends Verifier { public void verify() throws IOException, XMLStreamException { VersionInNamespaceStaxReaderDelegate modelReader = new VersionInNamespaceStaxReaderDelegate(); String path = "src/test/verifiers/stax-version-reader-delegate/input-4.0.0.xml"; org.codehaus.modello.test.model.vin.v4_0_0.Model model400 = (org.codehaus.modello.test.model.vin.v4_0_0.Model) modelReader.read( new File( path ) ); Assert.assertEquals( "Maven", model400.getName() ); Assert.assertEquals( "Something out of place.", model400.getDescription() ); path = "src/test/verifiers/stax-version-reader-delegate/input-4.0.1.xml"; org.codehaus.modello.test.model.vin.v4_0_1.Model model401 = (org.codehaus.modello.test.model.vin.v4_0_1.Model) modelReader.read( new File( path ) ); Assert.assertEquals( "Maven", model401.getName() ); Assert.assertEquals( "Something out of place.", model401.getDescription() ); } } modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-field/0000755000175000017500000000000011260056265030706 5ustar mkochmkoch././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-field/version-in-field.xmlmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-field/version-in-0000644000175000017500000000026111127507731032777 0ustar mkochmkoch Something out of place. 4.0.0 Maven ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-field/StaxVerifierVersionInField.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-field/StaxVerifie0000644000175000017500000000467211127507731033074 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.vif.Model; import org.codehaus.modello.test.model.vif.io.stax.VersionInFieldStaxReader; import org.codehaus.modello.verifier.Verifier; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.io.IOException; import java.io.Reader; import javax.xml.stream.XMLStreamException; /** * @version $Id: StaxVerifierVersionInField.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxVerifierVersionInField extends Verifier { /** * TODO: Add a association thats not under the root element */ public void verify() throws IOException, XMLStreamException { File file = new File( "src/test/verifiers/stax-version-in-field/version-in-field.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); VersionInFieldStaxReader modelReader = new VersionInFieldStaxReader(); Assert.assertEquals( "4.0.0", modelReader.determineVersion( reader ) ); reader = ReaderFactory.newXmlReader( file ); Model model = modelReader.read( reader ); Assert.assertEquals( "4.0.0", model.getModelVersion() ); Assert.assertEquals( "Maven", model.getName() ); Assert.assertEquals( "Something out of place.", model.getDescription() ); } } modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/0000755000175000017500000000000011260056265025536 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/expected-default-extend.xml0000644000175000017500000000045011127507731032770 0ustar mkochmkoch modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/StaxVerifier.java0000644000175000017500000004015211127507731031017 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.Build; import org.codehaus.modello.test.model.Component; import org.codehaus.modello.test.model.MailingList; import org.codehaus.modello.test.model.Model; import org.codehaus.modello.test.model.Organization; import org.codehaus.modello.test.model.Repository; import org.codehaus.modello.test.model.Scm; import org.codehaus.modello.test.model.SourceModification; import org.codehaus.modello.test.model.io.stax.MavenStaxReader; import org.codehaus.modello.test.model.io.stax.MavenStaxWriter; import org.codehaus.modello.verifier.Verifier; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.Xpp3Dom; import java.io.File; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.text.DateFormat; import java.util.Calendar; import java.util.List; import java.util.Locale; import java.util.Properties; import java.util.TimeZone; import javax.xml.stream.XMLStreamException; /** * @author Trygve Laugstøl * @version $Id: StaxVerifier.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxVerifier extends Verifier { /** * TODO: Add a association thats not under the root element */ public void verify() throws IOException, XMLStreamException { TimeZone.setDefault( TimeZone.getTimeZone( "America/New_York" ) ); verifyWriter(); verifyReader(); verifyReaderAliases(); verifyReaderDuplicates(); } public void verifyEncodedRead() throws IOException, XMLStreamException { File file = new File( "src/test/verifiers/stax/expected-encoding.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); MavenStaxReader modelReader = new MavenStaxReader(); Model model = modelReader.read( reader ); Assert.assertEquals( "Maven\u00A9", model.getName() ); } public void verifyReadDefaultAttribute() throws IOException, XMLStreamException { File file = new File( "src/test/verifiers/stax/expected-default-extend.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); MavenStaxReader modelReader = new MavenStaxReader(); Model model = modelReader.read( reader ); Assert.assertEquals( "foo", model.getExtend() ); } public void verifyWriter() throws IOException, XMLStreamException { String expectedXml = FileUtils.fileRead( getTestFile( "src/test/verifiers/stax/expected.xml" ) ); // ---------------------------------------------------------------------- // Build the model thats going to be written. // ---------------------------------------------------------------------- Model expected = new Model(); expected.setExtend( "/foo/bar" ); expected.setName( "Maven" ); expected.setModelVersion( "4.0.0" ); MailingList mailingList = new MailingList(); mailingList.setName( "Mailing list" ); mailingList.setSubscribe( "Super Subscribe" ); mailingList.setUnsubscribe( "Duper Unsubscribe" ); mailingList.setArchive( "?ber Archive" ); expected.addMailingList( mailingList ); Scm scm = new Scm(); String connection = "connection"; String developerConnection = "developerConnection"; String url = "url"; scm.setConnection( connection ); scm.setDeveloperConnection( developerConnection ); scm.setUrl( url ); expected.setScm( scm ); Build build = new Build(); build.setSourceDirectory( "src/main/java" ); build.setUnitTestSourceDirectory( "src/test/java" ); SourceModification sourceModification = new SourceModification(); sourceModification.setClassName( "excludeEclipsePlugin" ); sourceModification.setDirectory( "foo" ); sourceModification.addExclude( "de/abstrakt/tools/codegeneration/eclipse/*.java" ); build.addSourceModification( sourceModification ); expected.setBuild( build ); Component component = new Component(); component.setName( "component1" ); expected.addComponent( component ); component = new Component(); component.setName( "component2" ); component.setComment( "comment2" ); expected.addComponent( component ); Component c2 = new Component(); c2.setName( "sub" ); c2.setComment( "subcomment" ); component.getComponents().add( c2 ); component = new Component(); component.setName( "component3" ); Xpp3Dom xpp3Dom = new Xpp3Dom( "custom" ); Xpp3Dom child = new Xpp3Dom( "foo" ); child.setValue( "bar" ); xpp3Dom.addChild( child ); child = new Xpp3Dom( "bar" ); child.setAttribute( "att1", "value" ); child.setValue( "baz" ); xpp3Dom.addChild( child ); child = new Xpp3Dom( "el1" ); xpp3Dom.addChild( child ); Xpp3Dom el1 = child; child = new Xpp3Dom( "el2" ); child.setValue( "te&xt" ); el1.addChild( child ); component.setCustom( xpp3Dom ); expected.addComponent( component ); component = new Component(); component.setName( "component4" ); expected.addComponent( component ); Properties properties = new Properties(); properties.setProperty( "name", "value" ); component.setFlatProperties( properties ); properties = new Properties(); properties.setProperty( "key", "theValue" ); component.setProperties( properties ); Repository repository = new Repository(); repository.setId( "foo" ); expected.addRepository( repository ); repository = new Repository(); repository.setId( "bar" ); expected.addRepository( repository ); // ---------------------------------------------------------------------- // Write out the model // ---------------------------------------------------------------------- MavenStaxWriter writer = new MavenStaxWriter(); StringWriter buffer = new StringWriter(); writer.write( buffer, expected ); String actualXml = buffer.toString(); // System.out.println( expectedXml ); // // System.out.println( actualXml ); Assert.assertEquals( cleanLineEndings( expectedXml.trim() ), scrubXmlDeclQuotes( actualXml.trim() ) ); MavenStaxReader reader = new MavenStaxReader(); Model actual = reader.read( new StringReader( actualXml ) ); Assert.assertNotNull( "Actual", actual ); assertModel( expected, actual ); buffer = new StringWriter(); writer.write( buffer, actual ); Assert.assertEquals( cleanLineEndings( expectedXml.trim() ), scrubXmlDeclQuotes( buffer.toString().trim() ) ); } private String cleanLineEndings( String s ) { return s.replaceAll( "\r\n", "\n" ); } private String scrubXmlDeclQuotes( String s ) { s = cleanLineEndings( s ); if ( s.startsWith( "")) { return "" + s.substring( "".length() ); } return s; } public void verifyReader() throws IOException, XMLStreamException { MavenStaxReader reader = new MavenStaxReader(); // ---------------------------------------------------------------------- // Test that the entities is properly resolved // ---------------------------------------------------------------------- String xml = "\n" + " Laugst\u00f8l\n" + ""; Model expected = new Model(); String groupId = "Laugst\u00f8l"; expected.setGroupId( groupId ); Model actual = reader.read( new StringReader( xml ) ); assertModel( expected, actual ); } public void verifyReaderAliases() throws IOException, XMLStreamException { MavenStaxReader reader = new MavenStaxReader(); String xml = "\n" + " http://maven.apache.org/website\n" + " my-org\n" + ""; Model expected = new Model(); expected.setUrl( "http://maven.apache.org/website" ); Organization org = new Organization(); org.setName( "my-org" ); expected.setOrganization( org ); Model actual = reader.read( new StringReader( xml ) ); assertModel( expected, actual ); } public void verifyReaderDuplicates() throws IOException, XMLStreamException { MavenStaxReader reader = new MavenStaxReader(); String xml = "\n" + " \n" + ""; try { reader.read( new StringReader( xml ) ); Assert.fail( "Should have obtained a parse error for duplicate sourceDirectory" ); } catch ( XMLStreamException expected ) { Assert.assertTrue( true ); } xml = "\n" + " \n" + " \n" + ""; try { reader.read( new StringReader( xml ) ); Assert.fail( "Should have obtained a parse error for duplicate build" ); } catch ( XMLStreamException expected ) { Assert.assertTrue( true ); } } // ---------------------------------------------------------------------- // Assertions // ---------------------------------------------------------------------- public void assertModel( Model expected, Model actual ) { Assert.assertNotNull( "Actual model", actual ); Assert.assertEquals( "/model/extend", expected.getExtend(), actual.getExtend() ); // assertParent( expected.getParent(), actual.getParent() ); Assert.assertEquals( "/model/modelVersion", expected.getModelVersion(), actual.getModelVersion() ); Assert.assertEquals( "/model/groupId", expected.getGroupId(), actual.getGroupId() ); Assert.assertEquals( "/model/artifactId", expected.getArtifactId(), actual.getArtifactId() ); Assert.assertEquals( "/model/type", expected.getType(), actual.getType() ); Assert.assertEquals( "/model/name", expected.getName(), actual.getName() ); Assert.assertEquals( "/model/version", expected.getVersion(), actual.getVersion() ); Assert.assertEquals( "/model/shortDescription", expected.getShortDescription(), actual.getShortDescription() ); Assert.assertEquals( "/model/description", expected.getDescription(), actual.getDescription() ); Assert.assertEquals( "/model/url", expected.getUrl(), actual.getUrl() ); Assert.assertEquals( "/model/logo", expected.getLogo(), actual.getLogo() ); // assertIssueManagement(); // assertCiManagement(); Assert.assertEquals( "/model/inceptionYear", expected.getInceptionYear(), actual.getInceptionYear() ); // assertEquals( "/model/siteAddress", expected.getSiteAddress(), actual.getSiteAddress() ); // assertEquals( "/model/siteDirectory", expected.getSiteDirectory(), actual.getSiteDirectory() ); // assertEquals( "/model/distributionSite", expected.getDistributionSite(), actual.getDistributionSite() ); // assertEquals( "/model/distributionDirectory", expected.getDistributionDirectory(), actual.getDistributionDirectory() ); assertMailingLists( expected.getMailingLists(), actual.getMailingLists() ); /* assertDevelopers( ); assertContributors( ); assertDependencies( ); assertLicenses( ); assertPackageGroups( ); assertReports( ); */ assertScm( expected.getScm(), actual.getScm() ); /* assertBuild( ); assertOrganization( expected.getOrganization(), actual.getOrganization() ); */ assertBuild( expected.getBuild(), actual.getBuild() ); } public void assertMailingLists( List expected, List actual ) { Assert.assertNotNull( "/model/mailingLists", actual ); Assert.assertEquals( "/model/mailingLists.size", expected.size(), actual.size() ); for ( int i = 0; i < expected.size(); i++ ) { assertMailingList( i, (MailingList) expected.get( i ), actual.get( i ) ); } } public void assertMailingList( int i, MailingList expected, Object actualObject ) { Assert.assertNotNull( "/model/mailingLists[" + i + "]", actualObject ); Assert.assertEquals( "/model/mailingLists", MailingList.class, actualObject.getClass() ); MailingList actual = (MailingList) actualObject; Assert.assertEquals( "/model/mailingLists[" + i + "]/name", expected.getName(), actual.getName() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/subscribe", expected.getSubscribe(), actual.getSubscribe() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/unsubscribe", expected.getUnsubscribe(), actual.getUnsubscribe() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/archive", expected.getArchive(), actual.getArchive() ); } public void assertScm( Scm expected, Object actualObject ) { if ( expected == null ) { Assert.assertNull( "/model/scm", actualObject ); } else { Assert.assertNotNull( "/model/scm", actualObject ); Assert.assertEquals( "/model/scm", Scm.class, actualObject.getClass() ); Scm actual = (Scm) actualObject; Assert.assertEquals( "/model/scm/connection", expected.getConnection(), actual.getConnection() ); Assert.assertEquals( "/model/scm/developerConnection", expected.getDeveloperConnection(), actual.getDeveloperConnection() ); Assert.assertEquals( "/model/scm/url", expected.getUrl(), actual.getUrl() ); } } public void assertBuild( Build expected, Object actualObject ) { if ( expected == null ) { Assert.assertNull( "/model/builder", actualObject ); } else { Assert.assertNotNull( "/model/builder", actualObject ); Assert.assertEquals( "/model/builder", Build.class, actualObject.getClass() ); Build actual = (Build) actualObject; Assert.assertEquals( "/model/builder/sourceDirectory", expected.getSourceDirectory(), actual.getSourceDirectory() ); Assert.assertEquals( "/model/builder/unitTestSourceDirectory", expected.getUnitTestSourceDirectory(), actual.getUnitTestSourceDirectory() ); } } } modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/expected-encoding.xml0000644000175000017500000000322711127507731031652 0ustar mkochmkoch Maven#&x00A9; component1 component2 sub component3 bar baz text component4 key theValue value foo Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java modello-1.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/expected.xml0000644000175000017500000000366611127507731030075 0ustar mkochmkoch Maven component1 component2 sub component3 bar baz te&xt component4 key theValue value foo bar Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java modello-1.1/modello-plugins/modello-plugin-stax/src/test/java/0000755000175000017500000000000011260056265023502 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/0000755000175000017500000000000011260056265024271 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/0000755000175000017500000000000011260056265026064 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056265027517 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/0000755000175000017500000000000011260056265031505 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/0000755000175000017500000000000011260056265032305 5ustar mkochmkoch././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/modello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000755000175000017500000000000011260056265033015 5ustar mkochmkoch././@LongLink0000000000000000000000000000021700000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInNamespaceTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000256411127507731033027 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorVersionInNamespaceTest.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxGeneratorVersionInNamespaceTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionInNamespaceTest() throws ComponentLookupException { super( "stax-version-in-namespace" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/version-in-namespace.mdo" ) ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 1, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifierVersionInNamespace" ); } } ././@LongLink0000000000000000000000000000021300000000000011561 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInFieldTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000252011127507731033017 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorVersionInFieldTest.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxGeneratorVersionInFieldTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionInFieldTest() throws ComponentLookupException { super( "stax-version-in-field" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/version-in-field.mdo" ) ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 1, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifierVersionInField" ); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000614311127737073033030 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorTest.java 1098 2009-01-03 19:36:27Z hboutemy $ */ public class StaxGeneratorTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorTest() throws ComponentLookupException { super( "stax" ); } public void testStaxGenerator() throws Throwable { Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/maven.mdo" ) ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 27, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); ModelField extend = clazz.getField( "extend", new Version( "4.0.0" ) ); assertTrue( extend.hasMetadata( XmlFieldMetadata.ID ) ); XmlFieldMetadata xml = (XmlFieldMetadata) extend.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertTrue( xml.isAttribute() ); assertEquals( "extender", xml.getTagName() ); ModelField build = clazz.getField( "build", new Version( "4.0.0" ) ); assertTrue( build.hasMetadata( XmlFieldMetadata.ID ) ); xml = (XmlFieldMetadata) build.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertEquals( "builder", xml.getTagName() ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifier" ); } } ././@LongLink0000000000000000000000000000020500000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/FeaturesStaxGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000573311176576243033040 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesStaxGeneratorTest.java 1225 2009-05-01 13:44:03Z hboutemy $ */ public class FeaturesStaxGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesStaxGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "java", parameters ); modello.generate( model, "stax-writer", parameters ); modello.generate( model, "stax-reader", parameters ); addDependency( "stax", "stax-api", "1.0.1" ); addDependency( "org.codehaus.woodstox", "wstx-asl", "3.2.0" ); addDependency( "net.java.dev.stax-utils", "stax-utils", "20060502" ); addDependency( "xmlunit", "xmlunit", "1.2" ); compile( getOutputDirectory(), getOutputClasses() ); // TODO: see why without this, version system property is set to "2.4.1" value after verify System.setProperty( "version", getModelloVersion() ); verify( "org.codehaus.modello.generator.xml.stax.StaxFeaturesVerifier", getName() ); } } ././@LongLink0000000000000000000000000000022200000000000011561 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionReaderDelegateTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000405511127507731033024 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.model.Model; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; /** * @version $Id: StaxGeneratorVersionReaderDelegateTest.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxGeneratorVersionReaderDelegateTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionReaderDelegateTest() throws ComponentLookupException { super( "stax-version-reader-delegate" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/version-in-namespace.mdo" ) ) ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifierVersionReaderDelegate", new String[]{"4.0.0", "4.0.1"} ); } } ././@LongLink0000000000000000000000000000021100000000000011557 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/AbstractStaxGeneratorTestCase.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000740211132202454033011 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.compiler.CompilerException; import org.codehaus.plexus.util.StringUtils; import java.io.IOException; import java.util.Properties; public abstract class AbstractStaxGeneratorTestCase extends AbstractModelloJavaGeneratorTest { protected ModelloCore modello; protected AbstractStaxGeneratorTestCase( String name ) { super( name ); } protected void setUp() throws Exception { super.setUp(); modello = (ModelloCore) container.lookup( ModelloCore.ROLE ); } protected void verifyModel( Model model, String className ) throws IOException, ModelloException, CompilerException { verifyModel( model, className, null ); } protected void verifyModel( Model model, String className, String[] versions ) throws IOException, ModelloException, CompilerException { Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); modello.generate( model, "java", parameters ); modello.generate( model, "stax-writer", parameters ); modello.generate( model, "stax-reader", parameters ); if ( versions != null && versions.length > 0 ) { parameters.setProperty( ModelloParameterConstants.ALL_VERSIONS, StringUtils.join( versions, "," ) ); for ( int i = 0; i < versions.length; i++ ) { parameters.setProperty( ModelloParameterConstants.VERSION, versions[i] ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( true ) ); modello.generate( model, "java", parameters ); modello.generate( model, "stax-writer", parameters ); modello.generate( model, "stax-reader", parameters ); } } addDependency( "net.java.dev.stax-utils", "stax-utils", "20060502" ); addDependency( "stax", "stax-api", "1.0.1" ); addDependency( "org.codehaus.woodstox", "wstx-asl", "3.2.0" ); compile( getOutputDirectory(), getOutputClasses() ); verify( className, getName() ); } } ././@LongLink0000000000000000000000000000021100000000000011557 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000250511127507731033022 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorWrongVersionTest.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxGeneratorWrongVersionTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorWrongVersionTest() throws ComponentLookupException { super( "stax-wrong-version" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/version-in-field.mdo" ) ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 1, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifierWrongVersion" ); } } ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorPartsTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000433611222235713033020 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @version $Id: StaxGeneratorPartsTest.java 1267 2009-06-29 22:10:19Z hboutemy $ */ public class StaxGeneratorPartsTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorPartsTest() throws ComponentLookupException { super( "stax-parts" ); } public void testStaxReaderParts() throws Throwable { Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/parts.mdo" ) ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 12, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifierParts" ); } } ././@LongLink0000000000000000000000000000022400000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionInNamespaceTest.javamodello-1.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/sta0000644000175000017500000000261411127507731033023 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.stax; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorWrongVersionInNamespaceTest.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class StaxGeneratorWrongVersionInNamespaceTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorWrongVersionInNamespaceTest() throws ComponentLookupException { super( "stax-wrong-version-in-namespace" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/version-in-namespace.mdo" ) ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 1, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifierWrongVersionNamespace" ); } } modello-1.1/modello-plugins/modello-plugin-stax/src/test/resources/0000755000175000017500000000000011260056265024573 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/test/resources/parts.mdo0000644000175000017500000002314611222235713026426 0ustar mkochmkoch maven Parts package org.codehaus.modello.test.model.parts Model 3.0.0+ singleReference 3.0.0+ SingleReference secondReference 3.0.0+ SingleReference thirdReference 3.0.0+ SingleReference nullReference 3.0.0+ SingleReference nothingReference 3.0.0+ NothingReference dualReference 3.0.0+ DualReference dupeReference 3.0.0+ DualReference referenceList 3.0.0+ ReferenceList singleReferences 3.0.0+ SingleReference * nestedReference 3.0.0+ ParentReference references 3.0.0+ Reference * dummyReference 3.0.0+ DummyReference dummyIdReferences 3.0.0+ DummyIdReference * otherDummyReference 3.0.0+ DummyReference dummyReferences 3.0.0+ DummyReference * dummyPointers 3.0.0+ DummyIdReference * content 1.0.0+ Content type: in fact, an association to a class with attributes and one Content field.]]> ContentTest 1 Reference 3.0.0+ id String 3.0.0+ true name String 3.0.0+ IntReference 3.0.0+ id int 3.0.0+ true name String 3.0.0+ ParentReference 3.0.0+ id String 3.0.0+ true childReference 3.0.0+ ChildReference ChildReference 3.0.0+ parentReference 3.0.0+ ParentReference ReferenceList 3.0.0+ items 3.0.0+ Reference * SingleReference 3.0.0+ reference 3.0.0+ Reference NothingReference 3.0.0+ DualReference 3.0.0+ first 3.0.0+ Reference second 3.0.0+ Reference DummyReference 3.0.0+ reference 3.0.0+ DummyIdReference DummyIdReference 3.0.0+ name 3.0.0+ String description 3.0.0+ String ContentTest Content type.]]> 1.0.0+ content Content type.]]> 1.5.0+ Content attr An XML attribute. 1.0.0+ String modello-1.1/modello-plugins/modello-plugin-stax/src/test/resources/maven.mdo0000644000175000017500000016436211127507731026417 0ustar mkochmkoch maven Maven Maven's model for Java project. package org.codehaus.modello.test.model Model 3.0.0+ extend 3.0.0+ The location of the parent project, if one exists. Values from the parent project will be the default for this project if they are left unspecified. The path may be absolute, or relative to the current project.xml file. String foo parent 4.0.0 Specified which project to extend. Parent modelVersion 4.0.0 true The version of this model you are using. String pomVersion 3.0.0 true String id 3.0.0 true The id of the project. String groupId 3.0.0+ true The primary grouping for your project. String artifactId 3.0.0+ true The identifier used when generating the artifact for your project. String type 4.0.0 The type of artifact this project produces. String jar name 3.0.0+ true Human readable name of the project. String currentVersion 3.0.0 true String version 4.0.0 true The current version of the project. String shortDescription 3.0.0+ An abbreviated description of the project. String description 3.0.0+ A detailed description of the project. This element is usually specified as CDATA to enable the use of HTML tags within the description. This description is used to generate the <a href="plugins/site/index.html">front page</a> of the project's web site. String url website 3.0.0+ The URL where the project can be found. String logo 3.0.0+ The logo for the project. String issueTrackingUrl 3.0.0 The URL where the issue tracking system used by the project can be found. String issueManagement 4.0.0 The project's issue management information. IssueManagement ciManagement 4.0.0 The project's continuous integration management information. CiManagement inceptionYear 3.0.0+ true The year the project started. String gumpRepositoryId 3.0.0 Hint for the gump continuous integration build system. String siteAddress 3.0.0 The FQDN of the host where the project's site is uploaded. String siteDirectory 3.0.0 The directory on the site host where site documentation is placed when the site is uploaded. String distributionSite 3.0.0 The FQDN of the host where the project's artifacts are uploaded. String This naming is inconsistent and distribution should occur from a repository structure. distributionDirectory 3.0.0 The directory on the distribution host where artifacts are placed when uploaded. String This naming is inconsistent and distribution should occur from a repository structure. components 4.0.0 Component * repositories 4.0.0 The lists of the remote repositories Repository * pluginRepositories 4.0.0 The lists of the remote repositories for discovering plugins This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own. Repository * mailingLists 3.0.0+ The mailing lists for the project. MailingList * developers 3.0.0+ This element describes all of the developers associated with a project. Each developer is described by a <code>developer</code> element, which is then described by additional elements (described below). The auto-generated site documentation references this information. Developer * contributors 3.0.0+ This element describes all of the contributors associated with a project who are not developers. Each contributor is described by a <code>contributor</code> element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Contributor * dependencies 3.0.0+ This element describes all of the dependencies associated with a project. Each dependency is described by a <code>dependency</code> element, which is then described by additional elements (described below). Dependency * These should ultimately only be compile time dependencies when transitive dependencies come into play. overrides 4.0.0 This element describes all of the dependency overrides for a project. Each dependency is described by a <code>override</code> element, which is then described by additional elements (described below). Override * licenses 3.0.0+ This element describes all of the licenses for this project. Each license is described by a <code>license</code> element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. License * versions 3.0.0 The released versions of the project. Version * branches 3.0.0 The SCM branches create for the project. Branch * packageGroups 3.0.0+ Package groups required for complete javadocs. PackageGroup * reports 3.0.0+ This element includes the specification of reports to be included in a Maven-generated site. These reports will be run when a user executes <code>maven site</code>. All of the reports will be included in the navigation bar for browsing in the order they are specified. String * scm 4.0.0 Specification for the SCM use by the project. Scm repository 3.0.0 Specification for the SCM use by the project. Repository This element needs to be renamed as it conflicts with the existing notion of repositories in Maven. build 3.0.0+ true Information required to build the project. Build organization organisation 3.0.0+ This element describes various attributes of the organziation to which the project belongs. These attributes are utilized when documentation is created (for copyright notices and links). Organization distributionManagement 4.0.0 Distribution information for a project. DistributionManagement local 4.0.0 false Local configuration information. Local properties 3.0.0+ Properties about the project. This allows you to configure your project and the plugins it uses. Properties String * preGoals 4.0.0 Set of decorator(s) injected before the target goal(s). PreGoal * postGoals 4.0.0 Set of decorator(s) injected after the target goal(s). PostGoal * 3.0.0 public void setVersion(String version) { this.currentVersion = version; } public String getVersion() { return currentVersion; } 3.0.0+ private String packageName; public void setPackage(String packageName) { this.packageName = packageName; } public String getPackage() { return packageName; } 4.0.0 public String getId() { StringBuffer id = new StringBuffer(); id.append( getGroupId() ); id.append( ":" ); id.append( getArtifactId() ); id.append( ":" ); id.append( getType() ); id.append( ":" ); id.append( getVersion() ); return id.toString(); } Branch 3.0.0+ This element describes each of the branches of the project. Each branch is described by a <code>tag</code> element tag 3.0.0+ true The branch tag in the version control system (e.g. cvs) used by the project for the source code associated with this branch of the project. String description 4.0.0 A description of the branch and its strategy. String lastMergeTag 4.0.0 This is the tag in the version control system that was last used to merge from the branch to the current codebase. Future merges should merge only the changes from this tag to the next. String Build 3.0.0+ nagEmailAddress 3.0.0 An address to which notifications regarding the status of builds for this project can be sent. This is intended for use by tools which do unattended builds, for example those providing for continuous integration. Currently this is used by the <a href="build-file.html#maven:gump-descriptor">maven:gump-descriptor</a> target. String This should be moved out of the build section. Vestigal for use with Gump. sourceDirectory 3.0.0+ true This element specifies a directory containing the source of the project. The generated build system will compile the source in this directory when the project is built. The path given is relative to the project descriptor. String unitTestSourceDirectory 3.0.0+ true This element specifies a directory containing the unit test source of the project. The generated build system will compile these directories when the project is being tested. The unit tests must use the JUnit test framework. The path given is relative to the project descriptor. String aspectSourceDirectory 3.0.0+ This element specifies a directory containing Aspect sources of the project. The generated build system will compile the Aspects in this directory when the project is built if Aspects have been enabled (see the <a href="plugins/aspectj/goals.html">Aspectj goals</a> document). The path given is relative to the project descriptor. String integrationUnitTestSourceDirectory 3.0.0+ This element specifies a directory containing integration test sources of the project. String sourceModifications 3.0.0+ true This element describes all of the sourceModifications associated with a project. Each source modification is described by a <code>sourceModification</code> element, which is then described by additional elements (described below). These modifications are used to exclude or include various source depending on the environment the build is running in. SourceModification * unitTest 3.0.0+ true This element specifies unit tests associated with the project. UnitTest new UnitTest() resources 3.0.0+ This element describes all of the resources associated with a project or unit tests. Each resource is described by a resource element, which is then described by additional elements (described <a href="#resource">below</a>). These resources are used to complete the jar file or to run unit test. Resource * directory 4.0.0 The directory where all generated by the build is placed. String output 4.0.0 The directory where compiled application classes are placed. String finalName 4.0.0 The filename (including an extension, but with no path information) that the produced artifact will be called. The default value is artifactId-version.extension (where extension is derived from type). String testOutput 4.0.0 The directory where compiled test classes are placed. String CiManagement 4.0.0 system 4.0.0 The name of the continuous integration system i.e. Bugzilla String url 4.0.0 Url for the continuous integration system use by the project. String nagEmailAddress 4.0.0 Email address for the party to be notified on unsuccessful builds. String Contributor 3.0.0+ name 3.0.0+ The full name of the contributor. String email 3.0.0+ The email address of the contributor. String url 3.0.0+ The URL for the homepage of the contributor. String organization 3.0.0+ The organization to which the contributor belongs. String roles 3.0.0+ The roles the contributor plays in the project. Each role is describe by a <code>role</code> element, the body of which is a role name. String * timezone 3.0.0+ The timezone the contributor is in. This is a number in the range -14 to 14. String Dependency 3.0.0+ id 3.0.0 true The id of the project. String groupId 3.0.0+ true The project group that produced the dependency, e.g. <code>geronimo</code>. String artifactId 3.0.0+ true The unique id for an artifact produced by the project group, e.g. <code>germonimo-jms</code> String version 3.0.0+ true The version of the dependency., e.g. <code>3.2.1</code> String url 3.0.0+ This url will be provided to the user if the jar file cannot be downloaded from the central repository. String The URL should really be gleaned from a shared database of dependency information. jar 3.0.0 Literal name of the artifact. String artifact 4.0.0+ Literal name of the artifact String type 3.0.0+ Other known recognised dependency types are: <code>ejb</code> and <code>plugin</code>. String jar properties 3.0.0+ Properties about the dependency. Various plugins allow you to <code>mark</code> dependencies with properties. For example the <a href="plugins/war/index.html">war</a> plugin looks for a <code>war.bundle</code> property, and if found will include the dependency in <code>WEB-INF/lib</code>. For example syntax, check the war plugin docs. Properties String * 4.0.0 public String getId() { return groupId + ":" + artifactId + ":" + type + ":" + version; } public String toString() { return groupId + "/" + type + "s:" + artifactId + "-" + version; } 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } return getArtifactId() + "-" + getVersion() + "." + getExtension(); } public String getExtension() { if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( o == null ) { return false; } if ( getClass() != o.getClass() ) { return false; } if ( getId() != null ) { return getId().equals( ( (Dependency) o ).getId() ); } else { return ( (Dependency) o ).getId() == null; } } public int hashCode() { if ( getId() != null ) { return getId().hashCode(); } else { return super.hashCode(); } } ]]> Override 4.0.0 groupId 4.0.0 true The project group that produced the dependency, e.g. <code>geronimo</code>. String artifactId 4.0.0 true The unique id for an artifact produced by the project group, e.g. <code>germonimo-jms</code> String type 4.0.0 Other known recognised dependency types are: <code>ejb</code> and <code>plugin</code>. String jar version 4.0.0 true The version of the dependency., e.g. <code>3.2.1</code> String file 4.0.0 true The filename of the dependency that will be used to override the one from the repository, e.g. <code>lib/non-distributable-code-1.3.jar</code> String Contributor Developer 3.0.0+ id 3.0.0+ The username of the developer. String IssueManagement 4.0.0 system 4.0.0 The name of the issue management system i.e. Bugzilla String url 4.0.0 Url for the issue management system use by the project. String DistributionManagement 4.0.0 This elements describes all that pertains to distribution for a project. repository 4.0.0 Information needed for deploying to remote repository artifacts generated by the project Repository site Information needed for deploying website files of the project. 4.0.0 Site License 3.0.0+ name 3.0.0+ The full legal name of the license. String url 3.0.0+ The official url for the license text. String distribution 3.0.0 The primary method by which this project may be distributed. <dl> <dt>repo</dt> <dd>may be downloaded from the Maven repository</dd> <dt>manual</dt> <dd>user must manually download and install the dependency.</dd> </dl> String comments 3.0.0+ the description String MailingList 3.0.0+ This element describes all of the mailing lists associated with a project. Each mailing list is described by a <code>mailingList</code> element, which is then described by additional elements (described below). The auto-generated site documentation references this information. name 3.0.0+ The name of the mailing list. String subscribe 3.0.0+ The email address or link that can be used to subscribe to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String unsubscribe 3.0.0+ The email address or link that can be used to unsubscribe to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String post 4.0.0 The email address or link that can be used to post to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String archive 3.0.0+ The link to a URL where you can browse the archive. String This should probably be removed from 4.0.0 before alpha-1 archives 4.0.0 The link to a URL where you can browse the archive. String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization 3.0.0+ name 3.0.0+ The full name of the organization. String url 3.0.0+ The URL to the organization's home page. String logo 3.0.0+ The URL to the organization's logo image. This can be an URL relative to the base directory of the generated web site, (e.g., <code>/images/org-logo.png</code>) or an absolute URL (e.g., <code>http://my.corp/logo.png</code>). This value is used when generating the project documentation. String PackageGroup 3.0.0+ title 3.0.0+ the description String packages 3.0.0+ the description String PatternSet 3.0.0+ includes 3.0.0+ the description String * excludes 3.0.0+ the description String * 3.0.0+ public java.util.List getDefaultExcludes() { java.util.List defaultExcludes = new java.util.ArrayList(); defaultExcludes.add( "**/*~" ); defaultExcludes.add( "**/#*#" ); defaultExcludes.add( "**/.#*" ); defaultExcludes.add( "**/%*%" ); defaultExcludes.add( "**/._*" ); // CVS defaultExcludes.add( "**/CVS" ); defaultExcludes.add( "**/CVS/**" ); defaultExcludes.add( "**/.cvsignore" ); // SCCS defaultExcludes.add( "**/SCCS" ); defaultExcludes.add( "**/SCCS/**" ); // Visual SourceSafe defaultExcludes.add( "**/vssver.scc" ); // Subversion defaultExcludes.add( "**/.svn" ); defaultExcludes.add( "**/.svn/**" ); // Mac defaultExcludes.add( "**/.DS_Store" ); return defaultExcludes; } Parent 4.0.0 artifactId 4.0.0 The artifact id of the project to extend. String groupId 4.0.0 The group id of the project to extend. String version 4.0.0 The versi>on of the project to extend. String Repository 3.0.0 connection 3.0.0 The source configuration management system URL that describes the repository and how to connect to the repository. This is used by Maven when <a href="plugins/dist/index.html">building versions</a> from specific ID. String developerConnection 3.0.0 Just like connection, but for developers, i.e. this scm connection will not be read only. String url 3.0.0 The URL to the project's browsable CVS repository. String Scm 4.0.0 connection 4.0.0 The source configuration management system URL that describes the repository and how to connect to the repository. This is used by Maven when <a href="plugins/dist/index.html">building versions</a> from specific ID. String developerConnection 4.0.0 Just like connection, but for developers, i.e. this scm connection will not be read only. String url 4.0.0 The URL to the project's browsable CVS repository. String branches 4.0.0 The SCM branches that are currently active for the project. These should only be those forked from the current branch or trunk that are intended to be used. String * Resource 3.0.0+ PatternSet directory 3.0.0+ Describe the directory where the resource is stored. The path may be absolute, or relative to the project.xml file. String targetPath 3.0.0+ Describe the resource target path. For example, if you want that resource appear into a specific package ( <code>org.apache.maven.messages</code>), you must specify this element with this value : <code>org/apache/maven/messages</code> String filtering 3.0.0+ Describe if resources are filtered or not. String false 3.0.0+ public boolean isFiltering() { return !"false".equals( filtering ); } public void setFiltering( boolean filtering ) { this.filtering = ( filtering ? "true" : "false" ); } SourceModification 3.0.0+ Resource className 3.0.0+ If the class with this name can <strong>not</strong> be loaded, then the includes and excludes specified below will be applied to the contents of the <a href="#sourceDirectory">sourceDirectory</a> String property 3.0.0+ the description String UnitTest 3.0.0+ PatternSet resources 3.0.0+ the description Resource * Version 3.0.0 This element describes each of the previous versions of the project. Each version is described by a <code>version</code> element name 3.0.0 The external version number under which this release was distributed. Examples include: <code>1.0</code>, <code>1.1-alpha1</code>, <code>1.2-beta</code>, <code>1.3.2</code> etc. String tag 3.0.0 The name given in the version control system (e.g. cvs) used by the project for the source code associated with this version of the project. String id 3.0.0 A unique identifier for a version. This ID is used to specify the version that <a href="plugins/dist/index.html"> <code>maven:dist</code> </a> builds. String Repository 4.0.0 Repository contains the information needed for establishing connections with remote repoistory id 4.0.0 A unique identifier for a repository. String name 4.0.0 Human readable name of the repository String url 4.0.0 The url of of the repository String 4.0.0 public boolean equals( Object obj ) { Repository other = ( Repository ) obj; boolean retValue = false; if ( id != null ) { retValue = id.equals( other.id ); } return retValue; } Site 4.0.0 Site contains the information needed for deploying websites. id 4.0.0 A unique identifier for a deployment locataion. String name 4.0.0 Human readable name of the deployment location String url 4.0.0 The url of of the location where website is deployed String GoalDecorator 4.0.0 name 4.0.0 The target goal which should be decorated. String attain 4.0.0 The goal which should be injected into the execution chain. String GoalDecorator PreGoal 4.0.0 GoalDecorator PostGoal 4.0.0 Local 4.0.0 Local contains the information that is specific to the user's local environment. This would only be expected in a user or site pom, not a project POM. repository 4.0.0 The local repository that contains downloaded artifacts. String online 4.0.0 Whether to run the build online. If not, no remote repositories are consulted for plugins or dependencies and this configuration may be used by other plugins requiring online access. boolean true Component 4.0.0 name 4.0.0 String comment 4.0.0 String components 4.0.0 Component * custom DOM 4.0.0 properties 4.0.0 Properties String * flatProperties 4.0.0 Properties String * modello-1.1/modello-plugins/modello-plugin-stax/src/test/resources/version-in-field.mdo0000644000175000017500000000252311127507731030451 0ustar mkochmkoch maven VersionInField package org.codehaus.modello.test.model.vif field modelVersion Model 3.0.0+ modelVersion 4.0.0 true The version of this model you are using. String name 3.0.0+ true Human readable name of the project. String description 3.0.0+ true Human readable description of the project. String modello-1.1/modello-plugins/modello-plugin-stax/src/test/resources/version-in-namespace.mdo0000644000175000017500000000210311127507731031314 0ustar mkochmkoch maven VersionInNamespace package org.codehaus.modello.test.model.vin namespace Model 3.0.0+ name 3.0.0+ true Human readable name of the project. String description 3.0.0+ true Human readable description of the project. String modello-1.1/modello-plugins/modello-plugin-stax/src/site/0000755000175000017500000000000011260056266022547 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/site/site.xml0000644000175000017500000000022511112331565024226 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-stax/src/site/xdoc/0000755000175000017500000000000011260056266023504 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/site/xdoc/index.xml0000644000175000017500000000502111131476544025335 0ustar mkochmkoch Modello StAX Plugin Hervé Boutemy

Modello StAX Plugin generates XML readers and writers based on StAX API, plus reader delegates to be able to read multiple model versions.

stax-reader generator creates my.model.package.io.stax.ModelNameStaxReader class with following public methods:

  • public RootClass ( Reader reader, boolean strict )
        throws IOException, XMLStreamException
  • public RootClass read( Reader reader )
        throws IOException, XMLStreamException
  • public RootClass read( String filePath, boolean strict )
        throws IOException, XMLStreamException
  • public RootClass read( String filePath )
        throws IOException, XMLStreamException

In addition, if multiple model reader versions are generated (each in its own package), it creates a delegate my.model.package.io.xpp3.ModelNameStaxReaderDelegate class with following public methods:

  • public Object read( File f, boolean strict )
        throws IOException, XMLStreamException
  • public Object read( File f )
        throws IOException, XMLStreamException

Depending on the model version found in the XML content, the returned Object will be of the right version package.

stax-writer generator creates my.model.package.io.stax.ModelNameStaxWriter class with following public methods:

  • public void write( Writer writer, RootClass root )
        throws IOException, XMLStreamException
modello-1.1/modello-plugins/modello-plugin-stax/src/main/0000755000175000017500000000000011260056266022527 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/0000755000175000017500000000000011260056266023450 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/0000755000175000017500000000000011260056266024237 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/0000755000175000017500000000000011260056266026032 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056266027465 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056266030763 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/0000755000175000017500000000000011260056266031742 5ustar mkochmkoch././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/DummyIdModelField.javamodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/Dummy0000644000175000017500000000247311127507731032766 0ustar mkochmkochpackage org.codehaus.modello.plugin.stax; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.model.ModelField; public class DummyIdModelField extends ModelField { public String getName() { return "modello.refid"; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.javamodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxR0000644000175000017500000020350211243356043032725 0ustar mkochmkochpackage org.codehaus.modello.plugin.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.model.VersionDefinition; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JField; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JType; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlModelMetadata; import org.codehaus.plexus.util.StringUtils; import java.io.IOException; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: StaxReaderGenerator.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public class StaxReaderGenerator extends AbstractStaxGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateStaxReader(); VersionDefinition versionDefinition = model.getVersionDefinition(); if ( versionDefinition != null ) { String versions = parameters.getProperty( ModelloParameterConstants.ALL_VERSIONS ); if ( versions != null ) { generateStaxReaderDelegate( Arrays.asList( versions.split( "," ) ) ); } } } catch ( IOException ex ) { throw new ModelloException( "Exception while generating StAX Reader.", ex ); } } /** * Generate a StAX reader, a ModelNameStaxReader class in io.stax sub-package * with public RootClass read( ... ) methods. * * @throws ModelloException * @throws IOException */ private void generateStaxReader() throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.stax"; String unmarshallerName = getFileName( "StaxReader" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, unmarshallerName ); JClass jClass = new JClass( packageName + '.' + unmarshallerName ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); jClass.addImport( "java.io.IOException" ); jClass.addImport( "java.io.Reader" ); jClass.addImport( "java.io.File" ); jClass.addImport( "java.io.FileInputStream" ); jClass.addImport( "java.io.StringWriter" ); jClass.addImport( "java.io.StringReader" ); jClass.addImport( "java.io.ByteArrayInputStream" ); jClass.addImport( "java.io.InputStreamReader" ); jClass.addImport( "java.text.DateFormat" ); jClass.addImport( "java.text.ParsePosition" ); jClass.addImport( "java.util.regex.Matcher" ); jClass.addImport( "java.util.regex.Pattern" ); jClass.addImport( "java.util.Locale" ); jClass.addImport( "javax.xml.stream.*" ); jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); addModelImports( jClass, null ); // ---------------------------------------------------------------------- // Write the parse method which will do the unmarshalling. // ---------------------------------------------------------------------- ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); GeneratorNode rootNode = findRequiredReferenceResolvers( root, null ); writeReferenceResolvers( rootNode, jClass ); for ( Iterator i = rootNode.getNodesWithReferencableChildren().values().iterator(); i.hasNext(); ) { GeneratorNode node = (GeneratorNode) i.next(); writeReferenceResolvers( node, jClass ); } JClass returnType = new JClass( root.getName() ); JMethod method = new JMethod( "read", returnType, null ); method.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader( reader );" ); sc.add( "" ); sc.add( "String encoding = xmlStreamReader.getCharacterEncodingScheme();" ); sc.add( returnType + " value = parse" + root.getName() + "( \"" + resolveTagName( root ) + "\", xmlStreamReader, strict, encoding );" ); sc.add( "resolveReferences( value );" ); sc.add( "return value;" ); jClass.addMethod( method ); // ---------------------------------------------------------------------- method = new JMethod( "read", returnType, null ); method.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); sc = method.getSourceCode(); sc.add( "return read( reader, true );" ); jClass.addMethod( method ); // ---------------------------------------------------------------------- method = new JMethod( "read", returnType, null ); method.addParameter( new JParameter( new JClass( "String" ), "filePath" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); sc = method.getSourceCode(); sc.add( "File file = new File(filePath);" ); sc.add( "XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader( " + "file.toURL().toExternalForm(), new FileInputStream(file) );" ); sc.add( "" ); sc.add( "String encoding = xmlStreamReader.getCharacterEncodingScheme();" ); sc.add( returnType + " value = parse" + root.getName() + "( \"" + resolveTagName( root ) + "\", xmlStreamReader, strict, encoding );" ); sc.add( "resolveReferences( value );" ); sc.add( "return value;" ); jClass.addMethod( method ); // ---------------------------------------------------------------------- method = new JMethod( "read", returnType, null ); method.addParameter( new JParameter( new JClass( "String" ), "filePath" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); sc = method.getSourceCode(); sc.add( "return read( filePath, true );" ); jClass.addMethod( method ); // Determine the version. Currently, it causes the document to be reparsed, but could be made more efficient in // future by buffering the read XML and piping that into any consequent read method. VersionDefinition versionDefinition = objectModel.getVersionDefinition(); if ( versionDefinition != null ) { writeDetermineVersionMethod( jClass, objectModel ); } // ---------------------------------------------------------------------- // Write the class parsers // ---------------------------------------------------------------------- writeAllClassesParser( objectModel, jClass ); // ---------------------------------------------------------------------- // Write helpers // ---------------------------------------------------------------------- writeHelpers( jClass ); writeBuildDomMethod( jClass ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- jClass.print( sourceWriter ); sourceWriter.close(); } private void generateStaxReaderDelegate( List/**/ versions ) throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( false, null ) + ".io.stax"; String unmarshallerName = getFileName( "StaxReaderDelegate" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, unmarshallerName ); JClass jClass = new JClass( packageName + '.' + unmarshallerName ); jClass.addImport( "java.io.File" ); jClass.addImport( "java.io.IOException" ); jClass.addImport( "java.io.Reader" ); jClass.addImport( "javax.xml.stream.*" ); jClass.addImport( "org.codehaus.plexus.util.IOUtil" ); jClass.addImport( "org.codehaus.plexus.util.ReaderFactory" ); JMethod method = new JMethod( "read", new JClass( "Object" ), null ); method.addParameter( new JParameter( new JClass( "File" ), "f" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); jClass.addMethod( method ); JSourceCode sc = method.getSourceCode(); sc.add( "String modelVersion;" ); sc.add( "Reader reader = ReaderFactory.newXmlReader( f );" ); sc.add( "try" ); sc.add( "{" ); sc.addIndented( "modelVersion = determineVersion( reader );" ); sc.add( "}" ); sc.add( "finally" ); sc.add( "{" ); sc.addIndented( "IOUtil.close( reader );" ); sc.add( "}" ); sc.add( "reader = ReaderFactory.newXmlReader( f );" ); sc.add( "try" ); sc.add( "{" ); sc.indent(); writeModelVersionHack( sc ); String prefix = ""; for ( Iterator i = versions.iterator(); i.hasNext(); ) { String version = (String) i.next(); sc.add( prefix + "if ( \"" + version + "\".equals( modelVersion ) )" ); sc.add( "{" ); sc.addIndented( "return new " + getModel().getDefaultPackageName( true, new Version( version ) ) + ".io.stax." + getFileName( "StaxReader" ) + "().read( reader, strict );" ); sc.add( "}" ); prefix = "else "; } sc.add( "else" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Document version '\" + modelVersion + \"' has no " + "corresponding reader.\" );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "finally" ); sc.add( "{" ); sc.addIndented( "IOUtil.close( reader );" ); sc.add( "}" ); // ---------------------------------------------------------------------- method = new JMethod( "read", new JClass( "Object" ), null ); method.addParameter( new JParameter( new JClass( "File" ), "f" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); sc = method.getSourceCode(); sc.add( "return read( f, true );" ); jClass.addMethod( method ); writeDetermineVersionMethod( jClass, objectModel ); jClass.print( sourceWriter ); sourceWriter.close(); } private static void writeModelVersionHack( JSourceCode sc ) { sc.add( "// legacy hack for pomVersion == 3" ); sc.add( "if ( modelVersion.equals( \"3\" ) ) modelVersion = \"3.0.0\";" ); } private void writeDetermineVersionMethod( JClass jClass, Model objectModel ) throws ModelloException { VersionDefinition versionDefinition = objectModel.getVersionDefinition(); JMethod method = new JMethod( "determineVersion", new JClass( "String" ), null ); method.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader( reader );" ); sc.add( "while ( xmlStreamReader.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "int eventType = xmlStreamReader.next();" ); sc.add( "if ( eventType == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); if ( "namespace".equals( versionDefinition.getType() ) ) { XmlModelMetadata xmlModelMetadata = (XmlModelMetadata) objectModel.getMetadata( XmlModelMetadata.ID ); String namespace = xmlModelMetadata.getNamespace(); if ( namespace == null || namespace.indexOf( "${version}" ) < 0 ) { throw new ModelloException( "versionDefinition is namespace, but the model does not declare " + "xml.namespace on the model element" ); } sc.add( "return getVersionFromRootNamespace( xmlStreamReader );" ); writeNamespaceVersionGetMethod( namespace, jClass ); } else { String value = versionDefinition.getValue(); ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); ModelField field = root.getField( value, getGeneratedVersion() ); if ( field == null ) { throw new ModelloException( "versionDefinition is field, but the model root element does not declare a " + "field '" + value + "'." ); } if ( !"String".equals( field.getType() ) ) { throw new ModelloException( "versionDefinition is field, but the field is not of type String" ); } sc.add( "return getVersionFromField( xmlStreamReader );" ); writeFieldVersionGetMethod( field, jClass ); } sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "throw new XMLStreamException( \"Version not found in document\", xmlStreamReader.getLocation() );" ); jClass.addMethod( method ); } private static void writeFieldVersionGetMethod( ModelField field, JClass jClass ) { JMethod method = new JMethod( "getVersionFromField", new JType( "String" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JType( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addException( new JClass( "XMLStreamException" ) ); jClass.addMethod( method ); JSourceCode sc = method.getSourceCode(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); String value = xmlFieldMetadata.getTagName(); if ( value == null ) { value = field.getName(); } // we are now at the root element. Search child elements for the correct tag name sc.add( "int depth = 0;" ); sc.add( "while ( depth >= 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "int eventType = xmlStreamReader.next();" ); sc.add( "if ( eventType == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( depth == 0 && \"" + value + "\".equals( xmlStreamReader.getLocalName() ) )" ); sc.add( "{" ); sc.addIndented( "return xmlStreamReader.getElementText();" ); sc.add( "}" ); if ( field.getAlias() != null ) { sc.add( "if ( depth == 0 && \"" + field.getAlias() + "\".equals( xmlStreamReader.getLocalName() ) )" ); sc.add( "{" ); sc.addIndented( "return xmlStreamReader.getElementText();" ); sc.add( "}" ); } sc.add( "depth++;" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( eventType == XMLStreamConstants.END_ELEMENT )" ); sc.add( "{" ); sc.addIndented( "depth--;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "throw new XMLStreamException( \"Field: '" + value + "' does not exist in the document.\", xmlStreamReader.getLocation() );" ); } private static void writeNamespaceVersionGetMethod( String namespace, JClass jClass ) { JMethod method = new JMethod( "getVersionFromRootNamespace", new JType( "String" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JType( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addException( new JClass( "XMLStreamException" ) ); jClass.addMethod( method ); JSourceCode sc = method.getSourceCode(); sc.add( "String uri = xmlStreamReader.getNamespaceURI( \"\" );" ); sc.add( "if ( uri == null )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"No namespace specified, but versionDefinition requires it\", " + "xmlStreamReader.getLocation() );" ); sc.add( "}" ); int index = namespace.indexOf( "${version}" ); sc.add( "String uriPrefix = \"" + namespace.substring( 0, index ) + "\";" ); sc.add( "String uriSuffix = \"" + namespace.substring( index + 10 ) + "\";" ); sc.add( "if ( !uri.startsWith( uriPrefix ) || !uri.endsWith( uriSuffix ) )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Namespace URI: '\" + uri + \"' does not match pattern '" + namespace + "'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.add( "return uri.substring( uriPrefix.length(), uri.length() - uriSuffix.length() );" ); } /** * Write code to parse every classes from a model. * * @param objectModel the model * @param jClass the generated class source file * @throws ModelloException * @see {@link #writeClassParser(ModelClass, JClass, boolean)} */ private void writeAllClassesParser( Model objectModel, JClass jClass ) throws ModelloException { ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) clazz.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } writeClassParser( clazz, jClass, root.getName().equals( clazz.getName() ) ); } } /** * Write a private ClassName parseClassName( ... ) method to parse a class from a model. * * @param modelClass the model class * @param jClass the generated class source file * @param rootElement is this class the root from the model? * @throws ModelloException */ private void writeClassParser( ModelClass modelClass, JClass jClass, boolean rootElement ) throws ModelloException { String className = modelClass.getName(); String capClassName = capitalise( className ); String uncapClassName = uncapitalise( className ); JMethod unmarshall = new JMethod( "parse" + capClassName, new JClass( className ), null ); unmarshall.getModifiers().makePrivate(); unmarshall.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); unmarshall.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addParameter( new JParameter( new JClass( "String" ), "encoding" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = unmarshall.getSourceCode(); sc.add( className + ' ' + uncapClassName + " = new " + className + "();" ); ModelField contentField = getContentField( modelClass.getAllFields( getGeneratedVersion(), true ) ); if ( contentField != null ) { writeAttributes( modelClass, uncapClassName, sc ); writePrimitiveField( contentField, contentField.getType(), uncapClassName, "set" + capitalise( contentField.getName() ), sc ); } else { sc.add( "java.util.Set parsed = new java.util.HashSet();" ); String instanceFieldName = getInstanceFieldName( className ); if ( rootElement ) { // encoding parameter is only used in root class sc.add( uncapClassName + ".setModelEncoding( encoding );" ); sc.add( "boolean foundRoot = false;" ); sc.add( "while ( xmlStreamReader.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "int eventType = xmlStreamReader.next();" ); sc.add( "if ( eventType == XMLStreamConstants.START_ELEMENT )" ); } else { writeAttributes( modelClass, uncapClassName, sc ); if ( isAssociationPartToClass( modelClass ) ) { jClass.addField( new JField( new JType( "java.util.Map" ), instanceFieldName ) ); sc.add( "if ( " + instanceFieldName + " == null )" ); sc.add( "{" ); sc.addIndented( instanceFieldName + " = new java.util.HashMap();" ); sc.add( "}" ); sc.add( "String v = xmlStreamReader.getAttributeValue( null, \"modello.id\" );" ); sc.add( "if ( v != null )" ); sc.add( "{" ); sc.addIndented( instanceFieldName + ".put( v, " + uncapClassName + " );" ); sc.add( "}" ); } sc.add( "while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )" ); } sc.add( "{" ); sc.indent(); boolean addElse = false; if ( rootElement ) { sc.add( "if ( xmlStreamReader.getLocalName().equals( tagName ) )" ); sc.add( "{" ); sc.indent(); VersionDefinition versionDefinition = modelClass.getModel().getVersionDefinition(); if ( versionDefinition != null && "namespace".equals( versionDefinition.getType() ) ) { sc.add( "String modelVersion = getVersionFromRootNamespace( xmlStreamReader );" ); writeModelVersionCheck( sc ); } writeAttributes( modelClass, uncapClassName, sc ); sc.add( "foundRoot = true;" ); sc.unindent(); sc.add( "}" ); addElse = true; } // Write other fields for ( Iterator i = modelClass.getAllFields( getGeneratedVersion(), true ).iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( !xmlFieldMetadata.isAttribute() && !xmlFieldMetadata.isTransient() ) { processField( field, xmlFieldMetadata, addElse, sc, uncapClassName, rootElement, jClass ); addElse = true; } } if ( !rootElement ) { /* if ( modelClass.getFields( getGeneratedVersion() ).size() > 0 ) { sc.add( "else" ); sc.add( "{" ); sc.addIndented( "parser.nextText();" ); sc.add( "}" ); } */ if ( addElse ) { sc.add( "else" ); sc.add( "{" ); sc.indent(); } sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Unrecognised tag: '\" + xmlStreamReader.getLocalName() + " + "\"'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "int unrecognizedTagCount = 1;" ); sc.add( "while( unrecognizedTagCount != 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "xmlStreamReader.next();" ); sc.add( "if ( xmlStreamReader.getEventType() == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.addIndented( "unrecognizedTagCount++;" ); sc.add( "}" ); sc.add( "else if ( xmlStreamReader.getEventType() == XMLStreamConstants.END_ELEMENT )" ); sc.add( "{" ); sc.addIndented( "unrecognizedTagCount--;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); if ( addElse ) { sc.unindent(); sc.add( "}" ); } } else { // rootElement == true sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "if ( foundRoot )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Unrecognised tag: '\" + xmlStreamReader.getLocalName() + " + "\"'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } sc.unindent(); sc.add( "}" ); // This must be last so that we guarantee the ID has been filled already if ( isAssociationPartToClass( modelClass ) ) { List identifierFields = modelClass.getIdentifierFields( getGeneratedVersion() ); if ( identifierFields.size() == 1 ) { ModelField field = (ModelField) identifierFields.get( 0 ); String v = uncapClassName + ".get" + capitalise( field.getName() ) + "()"; v = getValue( field.getType(), v, (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ) ); sc.add( instanceFieldName + ".put( " + v + ", " + uncapClassName + " );" ); } } } sc.add( "return " + uncapClassName + ";" ); jClass.addMethod( unmarshall ); } private GeneratorNode findRequiredReferenceResolvers( ModelClass modelClass, GeneratorNode parent ) throws ModelloException { String className = modelClass.getName(); GeneratorNode value = new GeneratorNode( className, parent ); for ( Iterator i = modelClass.getAllFields( getGeneratedVersion(), true ).iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); if ( field instanceof ModelAssociation ) { ModelAssociation association = (ModelAssociation) field; if ( isClassInModel( association.getTo(), getModel() ) ) { ModelField referenceIdentifierField = getReferenceIdentifierField( association ); GeneratorNode child = null; if ( referenceIdentifierField != null ) { child = new GeneratorNode( association, parent ); child.setReferencable( true ); } else { if ( !value.getChain().contains( association.getTo() ) ) { // descend into child child = findRequiredReferenceResolvers( association.getToClass(), value ); child.setAssociation( association ); } } if ( child != null ) { value.addChild( child ); } } } } // propagate the flag up for ( Iterator i = value.getChildren().iterator(); i.hasNext(); ) { GeneratorNode child = (GeneratorNode) i.next(); if ( child.isReferencable() || child.isReferencableChildren() ) { value.setReferencableChildren( true ); } value.addNodesWithReferencableChildren( child.getNodesWithReferencableChildren() ); } return value; } private void writeReferenceResolvers( GeneratorNode node, JClass jClass ) { JMethod unmarshall = new JMethod( "resolveReferences" ); unmarshall.addParameter( new JParameter( new JClass( node.getTo() ), "value" ) ); unmarshall.getModifiers().makePrivate(); JSourceCode sc = unmarshall.getSourceCode(); sc.add( "java.util.Map refs;" ); for ( Iterator i = node.getChildren().iterator(); i.hasNext(); ) { GeneratorNode child = (GeneratorNode) i.next(); if ( child.isReferencable() ) { ModelAssociation association = child.getAssociation(); String refFieldName = getRefFieldName( association ); String to = association.getTo(); String instanceFieldName = getInstanceFieldName( to ); sc.add( "if ( " + refFieldName + " != null )" ); sc.add( "{" ); sc.indent(); sc.add( "refs = (java.util.Map) " + refFieldName + ".get( value );" ); sc.add( "if ( refs != null )" ); sc.add( "{" ); sc.indent(); String capAssocName = capitalise( association.getName() ); if ( association.isOneMultiplicity() ) { sc.add( "String id = (String) refs.get( \"" + association.getName() + "\" );" ); sc.add( to + " ref = (" + to + ") " + instanceFieldName + ".get( id );" ); // Don't set if it already is, since the Java plugin generates create/break that will throw an // exception sc.add( "if ( ref != null && !ref.equals( value.get" + capAssocName + "() ) )" ); sc.add( "{" ); sc.addIndented( "value.set" + capAssocName + "( ref );" ); sc.add( "}" ); } else { sc.add( "for ( int i = 0; i < value.get" + capAssocName + "().size(); i++ )" ); sc.add( "{" ); sc.indent(); sc.add( "String id = (String) refs.get( \"" + association.getName() + ".\" + i );" ); sc.add( to + " ref = (" + to + ") " + instanceFieldName + ".get( id );" ); sc.add( "if ( ref != null )" ); sc.add( "{" ); sc.addIndented( "value.get" + capAssocName + "().set( i, ref );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } if ( child.isReferencableChildren() ) { ModelAssociation association = child.getAssociation(); if ( association.isOneMultiplicity() ) { sc.add( "resolveReferences( value.get" + capitalise( association.getName() ) + "() );" ); } else { sc.add( "for ( java.util.Iterator i = value.get" + capitalise( association.getName() ) + "().iterator(); i.hasNext(); )" ); sc.add( "{" ); sc.addIndented( "resolveReferences( (" + association.getTo() + ") i.next() );" ); sc.add( "}" ); } } } jClass.addMethod( unmarshall ); } private static String getRefFieldName( ModelAssociation association ) { return uncapitalise( association.getTo() ) + "References"; } private static String getInstanceFieldName( String to ) { return uncapitalise( to ) + "Instances"; } /** * Add code to parse fields of a model class that are XML attributes. * * @param modelClass the model class * @param uncapClassName * @param sc the source code to add to * @throws ModelloException */ private void writeAttributes( ModelClass modelClass, String uncapClassName, JSourceCode sc ) throws ModelloException { for ( Iterator i = modelClass.getAllFields( getGeneratedVersion(), true ).iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isAttribute() && !xmlFieldMetadata.isTransient() ) { writePrimitiveField( field, field.getType(), uncapClassName, "set" + capitalise( field.getName() ), sc ); } } } /** * Generate code to process a field represented as an XML element. * * @param field the field to process * @param xmlFieldMetadata its XML metadata * @param addElse add an else statement before generating a new if * @param sc the method source code to add to * @param objectName the object name in the source * @param rootElement is the enclosing model class the root class (for model version field handling) * @param jClass the generated class source file * @throws ModelloException */ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, boolean addElse, JSourceCode sc, String objectName, boolean rootElement, JClass jClass ) throws ModelloException { String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String capFieldName = capitalise( field.getName() ); String singularName = singular( field.getName() ); String alias; if ( StringUtils.isEmpty( field.getAlias() ) ) { alias = "null"; } else { alias = "\"" + field.getAlias() + "\""; } String tagComparison = ( addElse ? "else " : "" ) + "if ( checkFieldWithDuplicate( xmlStreamReader, \"" + fieldTagName + "\", " + alias + ", parsed ) )"; if ( !( field instanceof ModelAssociation ) ) { sc.add( tagComparison ); sc.add( "{" ); sc.indent(); //ModelField writePrimitiveField( field, field.getType(), objectName, "set" + capFieldName, sc ); if ( rootElement && field.isModelVersionField() ) { sc.add( "String modelVersion = " + objectName + ".get" + capFieldName + "();" ); writeModelVersionCheck( sc ); } sc.unindent(); sc.add( "}" ); } else { // model association ModelAssociation association = (ModelAssociation) field; String associationName = association.getName(); if ( association.isOneMultiplicity() ) { sc.add( tagComparison ); sc.add( "{" ); sc.indent(); ModelField referenceIdentifierField = getReferenceIdentifierField( association ); if ( referenceIdentifierField != null ) { addCodeToAddReferences( association, jClass, sc, referenceIdentifierField, objectName ); // gobble the rest of the tag sc.add( "while ( xmlStreamReader.getEventType() != XMLStreamConstants.END_ELEMENT )" ); sc.add( "{" ); sc.addIndented( "xmlStreamReader.next();" ); sc.add( "}" ); } else { sc.add( objectName + ".set" + capFieldName + "( parse" + association.getTo() + "( \"" + fieldTagName + "\", xmlStreamReader, strict, encoding ) );" ); } sc.unindent(); sc.add( "}" ); } else { //MANY_MULTIPLICITY XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); String type = association.getType(); boolean wrappedItems = xmlAssociationMetadata.isWrappedItems(); if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { if ( wrappedItems ) { sc.add( tagComparison ); sc.add( "{" ); sc.indent(); sc.add( type + " " + associationName + " = " + association.getDefaultValue() + ";" ); sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" ); sc.add( "while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( xmlStreamReader.getLocalName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); } else { sc.add( ( addElse ? "else " : "" ) + "if ( xmlStreamReader.getLocalName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); sc.add( type + " " + associationName + " = " + objectName + ".get" + capFieldName + "();" ); sc.add( "if ( " + associationName + " == null )" ); sc.add( "{" ); sc.indent(); sc.add( associationName + " = " + association.getDefaultValue() + ";" ); sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" ); sc.unindent(); sc.add( "}" ); } if ( isClassInModel( association.getTo(), field.getModelClass().getModel() ) ) { ModelField referenceIdentifierField = getReferenceIdentifierField( association ); if ( referenceIdentifierField != null ) { addCodeToAddReferences( association, jClass, sc, referenceIdentifierField, objectName ); } if ( association.getTo().equals( field.getModelClass().getName() ) ) { // HACK: the addXXX method will cause an OOME when compiling a self-referencing class, so we // just add it to the array. This could disrupt the links if you are using break/create // constraints in modello. sc.add( associationName + ".add( parse" + association.getTo() + "( \"" + valuesTagName + "\", xmlStreamReader, strict, encoding ) );" ); } else { sc.add( objectName + ".add" + capitalise( singular( associationName ) ) + "( parse" + association.getTo() + "( \"" + valuesTagName + "\", xmlStreamReader, strict, encoding ) );" ); } } else { writePrimitiveField( association, association.getTo(), associationName, "add", sc ); } if ( wrappedItems ) { sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Unrecognised tag: '\" + " + "xmlStreamReader.getLocalName() + \"'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } else { sc.unindent(); sc.add( "}" ); } } else { //Map or Properties sc.add( tagComparison ); sc.add( "{" ); sc.indent(); if ( xmlAssociationMetadata.isMapExplode() ) { sc.add( "while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( xmlStreamReader.getLocalName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = null;" ); sc.add( "String value = null;" ); sc.add( "// " + xmlAssociationMetadata.getMapStyle() + " mode." ); sc.add( "while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( xmlStreamReader.getLocalName().equals( \"key\" ) )" ); sc.add( "{" ); sc.addIndented( "key = xmlStreamReader.getElementText();" ); sc.add( "}" ); sc.add( "else if ( xmlStreamReader.getLocalName().equals( \"value\" ) )" ); sc.add( "{" ); sc.addIndented( "value = xmlStreamReader.getElementText()" + ( xmlFieldMetadata.isTrim() ? ".trim()" : "" ) + ";" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "xmlStreamReader.getText();" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( objectName + ".add" + capitalise( singularName ) + "( key, value );" ); sc.unindent(); sc.add( "}" ); sc.add( "xmlStreamReader.next();" ); sc.unindent(); sc.add( "}" ); } else { //INLINE Mode sc.add( "while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = xmlStreamReader.getLocalName();" ); sc.add( "String value = xmlStreamReader.getElementText()" + ( xmlFieldMetadata.isTrim() ? ".trim()" : "" ) + ";" ); sc.add( objectName + ".add" + capitalise( singularName ) + "( key, value );" ); sc.unindent(); sc.add( "}" ); } sc.unindent(); sc.add( "}" ); } } } } private static void addCodeToAddReferences( ModelAssociation association, JClass jClass, JSourceCode sc, ModelField referenceIdentifierField, String referredFromClass ) { String refFieldName = getRefFieldName( association ); if ( jClass.getField( refFieldName ) == null ) { jClass.addField( new JField( new JType( "java.util.Map" ), refFieldName ) ); } sc.add( "String value = xmlStreamReader.getAttributeValue( null, \"" + referenceIdentifierField.getName() + "\" );" ); sc.add( "if ( value != null )" ); sc.add( "{" ); sc.indent(); sc.add( "// This is a reference to an element elsewhere in the model" ); sc.add( "if ( " + refFieldName + " == null )" ); sc.add( "{" ); sc.addIndented( refFieldName + " = new java.util.HashMap();" ); sc.add( "}" ); sc.add( "java.util.Map refs = (java.util.Map) " + refFieldName + ".get( " + referredFromClass + " );" ); sc.add( "if ( refs == null )" ); sc.add( "{" ); sc.indent(); sc.add( "refs = new java.util.HashMap();" ); sc.add( refFieldName + ".put( " + referredFromClass + ", refs );" ); sc.unindent(); sc.add( "}" ); if ( association.isOneMultiplicity() ) { sc.add( "refs.put( \"" + association.getName() + "\", value );" ); } else { sc.add( "refs.put( \"" + association.getName() + ".\" + " + association.getName() + ".size(), value );" ); } sc.unindent(); sc.add( "}" ); } private void writeModelVersionCheck( JSourceCode sc ) { writeModelVersionHack( sc ); sc.add( "if ( !modelVersion.equals( \"" + getGeneratedVersion() + "\" ) )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Document model version of '\" + modelVersion + \"' doesn't match reader " + "version of '" + getGeneratedVersion() + "'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); } /** * Write code to set a primitive field with a value got from the parser, with appropriate default value, trimming * and required check logic. * * @param field the model field to set (either XML attribute or element) * @param type the type of the value read from XML * @param objectName the object name in source * @param setterName the setter method name * @param sc the source code to add to */ private void writePrimitiveField( ModelField field, String type, String objectName, String setterName, JSourceCode sc ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); String tagName = resolveTagName( field, xmlFieldMetadata); String parserGetter; if ( xmlFieldMetadata.isAttribute() ) { parserGetter = "xmlStreamReader.getAttributeValue( null, \"" + tagName + "\" )"; } else { parserGetter = "xmlStreamReader.getElementText()"; } /* TODO: if ( xmlFieldMetadata.isRequired() ) { parserGetter = "getRequiredAttributeValue( " + parserGetter + ", \"" + tagName + "\", parser, strict, encoding )"; } */ if ( field.getDefaultValue() != null ) { parserGetter = "getDefaultValue( " + parserGetter + ", \"" + field.getDefaultValue() + "\" )"; } if ( xmlFieldMetadata.isTrim() ) { parserGetter = "getTrimmedValue( " + parserGetter + " )"; } if ( "boolean".equals( type ) ) { sc.add( objectName + "." + setterName + "( getBooleanValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader ) );" ); } else if ( "char".equals( type ) ) { sc.add( objectName + "." + setterName + "( getCharacterValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader ) );" ); } else if ( "double".equals( type ) ) { sc.add( objectName + "." + setterName + "( getDoubleValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader, strict ) );" ); } else if ( "float".equals( type ) ) { sc.add( objectName + "." + setterName + "( getFloatValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader, strict ) );" ); } else if ( "int".equals( type ) ) { sc.add( objectName + "." + setterName + "( getIntegerValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader, strict ) );" ); } else if ( "long".equals( type ) ) { sc.add( objectName + "." + setterName + "( getLongValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader, strict ) );" ); } else if ( "short".equals( type ) ) { sc.add( objectName + "." + setterName + "( getShortValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader, strict ) );" ); } else if ( "byte".equals( type ) ) { sc.add( objectName + "." + setterName + "( getByteValue( " + parserGetter + ", \"" + tagName + "\", xmlStreamReader, strict ) );" ); } else if ( "String".equals( type ) || "Boolean".equals( type ) ) { // TODO: other Primitive types sc.add( objectName + "." + setterName + "( " + parserGetter + " );" ); } else if ( "Date".equals( type ) ) { sc.add( "String dateFormat = " + ( xmlFieldMetadata.getFormat() != null ? "\"" + xmlFieldMetadata.getFormat() + "\"" : "null" ) + ";" ); sc.add( objectName + "." + setterName + "( getDateValue( " + parserGetter + ", \"" + tagName + "\", dateFormat, xmlStreamReader ) );" ); } else if ( "DOM".equals( type ) ) { sc.add( objectName + "." + setterName + "( buildDom( xmlStreamReader ) );" ); } else { throw new IllegalArgumentException( "Unknown type: " + type ); } } private void writeBuildDomMethod( JClass jClass ) { JMethod method = new JMethod( "buildDom", new JType( "Xpp3Dom" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JType( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "java.util.List elements = new java.util.ArrayList();" ); sc.add( "java.util.List values = new java.util.ArrayList();" ); sc.add( "int eventType = xmlStreamReader.getEventType();" ); sc.add( "while ( xmlStreamReader.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( eventType == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "String rawName = xmlStreamReader.getLocalName();" ); sc.add( "Xpp3Dom childConfiguration = new Xpp3Dom( rawName );" ); sc.add( "int depth = elements.size();" ); sc.add( "if ( depth > 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "Xpp3Dom parent = (Xpp3Dom) elements.get( depth - 1 );" ); sc.add( "parent.addChild( childConfiguration );" ); sc.unindent(); sc.add( "}" ); sc.add( "elements.add( childConfiguration );" ); sc.add( "if ( xmlStreamReader.isEndElement() )" ); sc.add( "{" ); sc.addIndented( "values.add( null );" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "values.add( new StringBuffer() );" ); sc.add( "}" ); sc.add( "int attributesSize = xmlStreamReader.getAttributeCount();" ); sc.add( "for ( int i = 0; i < attributesSize; i++ )" ); sc.add( "{" ); sc.indent(); sc.add( "String name = xmlStreamReader.getAttributeLocalName( i );" ); sc.add( "String value = xmlStreamReader.getAttributeValue( i );" ); sc.add( "childConfiguration.setAttribute( name, value );" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "else if ( eventType == XMLStreamConstants.CHARACTERS )" ); sc.add( "{" ); sc.indent(); sc.add( "int depth = values.size() - 1;" ); sc.add( "StringBuffer valueBuffer = (StringBuffer) values.get( depth );" ); sc.add( "String text = xmlStreamReader.getText();" ); sc.add( "text = text.trim();" ); sc.add( "valueBuffer.append( text );" ); sc.unindent(); sc.add( "}" ); sc.add( "else if ( eventType == XMLStreamConstants.END_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "int depth = elements.size() - 1;" ); sc.add( "Xpp3Dom finishedConfiguration = (Xpp3Dom) elements.remove( depth );" ); sc.add( "// this Object could be null if it is a singleton tag" ); sc.add( "Object accumulatedValue = values.remove( depth );" ); sc.add( "if ( finishedConfiguration.getChildCount() == 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( accumulatedValue == null )" ); sc.add( "{" ); sc.addIndented( "finishedConfiguration.setValue( null );" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "finishedConfiguration.setValue( accumulatedValue.toString() );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( depth == 0 )" ); sc.add( "{" ); sc.addIndented( "return finishedConfiguration;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "eventType = xmlStreamReader.next();" ); sc.unindent(); sc.add( "}" ); sc.add( "throw new IllegalStateException( \"End of document found before returning to 0 depth\" );" ); jClass.addMethod( method ); } private void writeHelpers( JClass jClass ) { JMethod method = new JMethod( "getTrimmedValue", new JClass( "String" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "s = s.trim();" ); sc.add( "}" ); sc.add( "return s;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getDefaultValue", new JClass( "String" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "v" ) ); sc = method.getSourceCode(); sc.add( "if ( s == null )" ); sc.add( "{" ); sc.addIndented( "s = v;" ); sc.add( "}" ); sc.add( "return s;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getRequiredAttributeValue", new JClass( "String" ), null ); method.addException( new JClass( "XMLStreamException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); sc = method.getSourceCode(); sc.add( "if ( s == null )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Missing required value for attribute '\" + attribute + \"'\", " + "xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return s;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getBooleanValue", JType.BOOLEAN, null ); method.addException( new JClass( "XMLStreamException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "return Boolean.valueOf( s ).booleanValue();" ); sc.add( "}" ); sc.add( "return false;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getCharacterValue", JType.CHAR, null ); method.addException( new JClass( "XMLStreamException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "return s.charAt( 0 );" ); sc.add( "}" ); sc.add( "return 0;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getIntegerValue", JType.INT, "Integer.valueOf( s ).intValue()", "an integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getShortValue", JType.SHORT, "Short.valueOf( s ).shortValue()", "a short integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getByteValue", JType.BYTE, "Byte.valueOf( s ).byteValue()", "a byte" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getLongValue", JType.LONG, "Long.valueOf( s ).longValue()", "a long integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getFloatValue", JType.FLOAT, "Float.valueOf( s ).floatValue()", "a floating point number" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getDoubleValue", JType.DOUBLE, "Double.valueOf( s ).doubleValue()", "a floating point number" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getDateValue", new JClass( "java.util.Date" ), null ); method.addException( new JClass( "XMLStreamException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "String" ), "dateFormat" ) ); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addException( new JClass( "XMLStreamException" ) ); writeDateParsingHelper( method.getSourceCode(), "new XMLStreamException( e.getMessage() )" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "checkFieldWithDuplicate", JType.BOOLEAN, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); method.addParameter( new JParameter( new JClass( "String" ), "alias" ) ); method.addParameter( new JParameter( new JClass( "java.util.Set" ), "parsed" ) ); method.addException( new JClass( "XMLStreamException" ) ); sc = method.getSourceCode(); sc.add( "if ( !( xmlStreamReader.getLocalName().equals( tagName ) ||" + " xmlStreamReader.getLocalName().equals( alias ) ) )" ); sc.add( "{" ); sc.addIndented( "return false;" ); sc.add( "}" ); sc.add( "if ( parsed.contains( tagName ) )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Duplicated tag: '\" + tagName + \"'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.add( "parsed.add( tagName );" ); sc.add( "return true;" ); jClass.addMethod( method ); } private JMethod convertNumericalType( String methodName, JType returnType, String expression, String typeDesc ) { JMethod method = new JMethod( methodName, returnType, null ); method.addException( new JClass( "XMLStreamException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.indent(); sc.add( "try" ); sc.add( "{" ); sc.addIndented( "return " + expression + ";" ); sc.add( "}" ); sc.add( "catch ( NumberFormatException e )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Unable to parse element '\" + attribute + \"', must be " + typeDesc + " but was '\" + s + \"'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return 0;" ); return method; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxWriterGenerator.javamodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxW0000644000175000017500000005530111243356043032734 0ustar mkochmkochpackage org.codehaus.modello.plugin.stax; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JConstructor; import org.codehaus.modello.plugin.java.javasource.JField; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JType; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; import org.codehaus.modello.plugin.model.ModelClassMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlModelMetadata; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: StaxWriterGenerator.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public class StaxWriterGenerator extends AbstractStaxGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateStaxWriter(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating StAX Writer.", ex ); } } private void generateStaxWriter() throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.stax"; String marshallerName = getFileName( "StaxWriter" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, marshallerName ); JClass jClass = new JClass( packageName + '.' + marshallerName ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); jClass.addImport( "java.io.InputStream" ); jClass.addImport( "java.io.IOException" ); jClass.addImport( "java.io.Writer" ); jClass.addImport( "java.io.StringWriter" ); jClass.addImport( "java.text.DateFormat" ); jClass.addImport( "java.util.Iterator" ); jClass.addImport( "java.util.Locale" ); jClass.addImport( "java.util.jar.Manifest" ); jClass.addImport( "javax.xml.stream.*" ); jClass.addImport( "javanet.staxutils.IndentingXMLStreamWriter" ); jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); addModelImports( jClass, null ); jClass.addField( new JField( JType.INT, "curId" ) ); jClass.addField( new JField( new JType( "java.util.Map" ), "idMap" ) ); JConstructor constructor = new JConstructor( jClass ); constructor.getSourceCode().add( "idMap = new java.util.HashMap();" ); jClass.addConstructor( constructor ); String root = objectModel.getRoot( getGeneratedVersion() ); ModelClass rootClass = objectModel.getClass( root, getGeneratedVersion() ); String rootElement = resolveTagName( rootClass ); // Write the parse method which will do the unmarshalling. JMethod marshall = new JMethod( "write" ); String rootElementParameterName = uncapitalise( root ); marshall.addParameter( new JParameter( new JClass( "Writer" ), "writer" ) ); marshall.addParameter( new JParameter( new JClass( root ), rootElementParameterName ) ); marshall.addException( new JClass( "java.io.IOException" ) ); marshall.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "XMLOutputFactory factory = XMLOutputFactory.newInstance();" ); // currently, only woodstox supports Windows line endings. It works with Java 6/RI and stax <= 1.1.1 as well // but we have no way to detect them sc.add( "boolean supportWindowsLineEndings = false;" ); sc.add( "if ( factory.isPropertySupported( \"com.ctc.wstx.outputEscapeCr\" ) )" ); sc.add( "{" ); sc.indent(); sc.add( "factory.setProperty( \"com.ctc.wstx.outputEscapeCr\", Boolean.FALSE );" ); sc.add( "supportWindowsLineEndings = true;" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( factory.isPropertySupported( \"org.codehaus.stax2.automaticEmptyElements\" ) )" ); sc.add( "{" ); sc.addIndented( "factory.setProperty( \"org.codehaus.stax2.automaticEmptyElements\", Boolean.FALSE );" ); sc.add( "}" ); sc.add( "IndentingXMLStreamWriter serializer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter( writer ) );" ); sc.add( "if ( supportWindowsLineEndings )" ); sc.add( "{" ); sc.addIndented( "serializer.setNewLine( serializer.getLineSeparator() );" ); sc.add( "}" ); sc.add( "serializer.writeStartDocument( " + rootElementParameterName + ".getModelEncoding(), \"1.0\" );" ); sc.add( "write" + root + "( " + rootElementParameterName + ", \"" + rootElement + "\", serializer );" ); sc.add( "serializer.writeEndDocument();" ); jClass.addMethod( marshall ); createWriteDomMethod( jClass ); writeAllClasses( objectModel, jClass ); jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClasses( Model objectModel, JClass jClass ) throws ModelloException { for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) clazz.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } writeClass( clazz, jClass ); } } private void writeClass( ModelClass modelClass, JClass jClass ) throws ModelloException { String className = modelClass.getName(); String uncapClassName = uncapitalise( className ); JMethod marshall = new JMethod( "write" + className ); marshall.getModifiers().makePrivate(); marshall.addParameter( new JParameter( new JClass( className ), uncapClassName ) ); marshall.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); marshall.addParameter( new JParameter( new JClass( "XMLStreamWriter" ), "serializer" ) ); marshall.addException( new JClass( "java.io.IOException" ) ); marshall.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "if ( " + uncapClassName + " != null )" ); sc.add( "{" ); sc.indent(); ModelClassMetadata classMetadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); String namespace = null; XmlModelMetadata xmlModelMetadata = (XmlModelMetadata) modelClass.getModel().getMetadata( XmlModelMetadata.ID ); // add namespace information for root element only if ( classMetadata.isRootElement() && ( xmlModelMetadata.getNamespace() != null ) ) { namespace = xmlModelMetadata.getNamespace( getGeneratedVersion() ); sc.add( "serializer.setDefaultNamespace( \"" + namespace + "\" );" ); } sc.add( "serializer.writeStartElement( tagName );" ); if ( namespace != null ) { sc.add( "serializer.writeDefaultNamespace( \"" + namespace + "\" );" ); if ( xmlModelMetadata.getSchemaLocation() != null ) { String url = xmlModelMetadata.getSchemaLocation( getGeneratedVersion() ); sc.add( "serializer.setPrefix( \"xsi\", \"http://www.w3.org/2001/XMLSchema-instance\" );" ); sc.add( "serializer.writeNamespace( \"xsi\", \"http://www.w3.org/2001/XMLSchema-instance\" );" ); sc.add( "serializer.writeAttribute( \"http://www.w3.org/2001/XMLSchema-instance\", \"schemaLocation\", \"" + namespace + " " + url + "\" );" ); } } if ( isAssociationPartToClass( modelClass ) ) { if ( modelClass.getIdentifierFields( getGeneratedVersion() ).size() != 1 ) { writeIdMapCheck( sc, uncapClassName, "modello.id" ); } } ModelField contentField = null; String contentValue = null; List modelFields = modelClass.getAllFields( getGeneratedVersion(), true ); modelFields = getNonTransientFields( modelFields ); // XML attributes for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String type = field.getType(); String value = getFieldValue( uncapClassName, field ); if ( xmlFieldMetadata.isContent() ) { contentField = field; contentValue = value; continue; } if ( xmlFieldMetadata.isAttribute() ) { sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.addIndented( "serializer.writeAttribute( \"" + fieldTagName + "\", " + getValue( field.getType(), value, xmlFieldMetadata ) + " );" ); sc.add( "}" ); } } if ( contentField != null ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) contentField.getMetadata( XmlFieldMetadata.ID ); sc.add( "serializer.writeCharacters( " + getValue( contentField.getType(), contentValue, xmlFieldMetadata ) + " );" ); } // XML tags for ( Iterator fieldIterator = modelFields.iterator(); fieldIterator.hasNext(); ) { ModelField field = (ModelField) fieldIterator.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isContent() ) { // skip field with type Content continue; } String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String type = field.getType(); String value = getFieldValue( uncapClassName, field ); if ( xmlFieldMetadata.isAttribute() ) { continue; } if ( field instanceof ModelAssociation ) { ModelAssociation association = (ModelAssociation) field; String associationName = association.getName(); ModelField referenceIdentifierField = getReferenceIdentifierField( association ); if ( association.isOneMultiplicity() ) { sc.add( getValueChecker( type, value, association ) ); sc.add( "{" ); sc.indent(); if ( referenceIdentifierField != null ) { // if xml.reference, then store as a reference instead sc.add( "serializer.writeStartElement( \"" + fieldTagName + "\" );" ); writeElementAttribute( sc, referenceIdentifierField, value ); sc.add( "serializer.writeEndElement();" ); } else { sc.add( "write" + association.getTo() + "( (" + association.getTo() + ") " + value + ", \"" + fieldTagName + "\", serializer );" ); } sc.unindent(); sc.add( "}" ); } else { //MANY_MULTIPLICITY XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); type = association.getType(); String toType = association.getTo(); boolean wrappedItems = xmlAssociationMetadata.isWrappedItems(); if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { sc.add( getValueChecker( type, value, association ) ); sc.add( "{" ); sc.indent(); if ( wrappedItems ) { sc.add( "serializer.writeStartElement( " + "\"" + fieldTagName + "\" );" ); } sc.add( "for ( Iterator iter = " + value + ".iterator(); iter.hasNext(); )" ); sc.add( "{" ); sc.indent(); if ( isClassInModel( association.getTo(), modelClass.getModel() ) ) { sc.add( toType + " o = (" + toType + ") iter.next();" ); if ( referenceIdentifierField != null ) { sc.add( "serializer.writeStartElement( \"" + valuesTagName + "\" );" ); writeElementAttribute( sc, referenceIdentifierField, "o" ); sc.add( "serializer.writeEndElement();" ); } else { sc.add( "write" + toType + "( o, \"" + valuesTagName + "\", serializer );" ); } } else { sc.add( toType + " " + singular( uncapitalise( field.getName() ) ) + " = (" + toType + ") iter.next();" ); sc.add( "serializer.writeStartElement( " + "\"" + valuesTagName + "\" );" ); sc.add( "serializer.writeCharacters( " + singular( uncapitalise( field.getName() ) ) + " );" ); sc.add( "serializer.writeEndElement();" ); } sc.unindent(); sc.add( "}" ); if ( wrappedItems ) { sc.add( "serializer.writeEndElement();" ); } sc.unindent(); sc.add( "}" ); } else { //Map or Properties sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.indent(); if ( wrappedItems ) { sc.add( "serializer.writeStartElement( " + "\"" + fieldTagName + "\" );" ); } sc.add( "for ( Iterator iter = " + value + ".keySet().iterator(); iter.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = (String) iter.next();" ); sc.add( "String value = (String) " + value + ".get( key );" ); if ( xmlAssociationMetadata.isMapExplode() ) { sc.add( "serializer.writeStartElement( \"" + singular( associationName ) + "\" );" ); sc.add( "serializer.writeStartElement( \"key\" );" ); sc.add( "serializer.writeCharacters( key );" ); sc.add( "serializer.writeEndElement();" ); sc.add( "serializer.writeStartElement( \"value\" );" ); sc.add( "serializer.writeCharacters( value );" ); sc.add( "serializer.writeEndElement();" ); sc.add( "serializer.writeEndElement();" ); } else { sc.add( "serializer.writeStartElement( \"\" + key + \"\" );" ); sc.add( "serializer.writeCharacters( value );" ); sc.add( "serializer.writeEndElement();" ); } sc.unindent(); sc.add( "}" ); if ( wrappedItems ) { sc.add( "serializer.writeEndElement();" ); } sc.unindent(); sc.add( "}" ); } } } else { sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.indent(); if ( "DOM".equals( field.getType() ) ) { sc.add( "writeDom( (Xpp3Dom) " + value + ", serializer );" ); } else { sc.add( "serializer.writeStartElement( " + "\"" + fieldTagName + "\" );" ); sc.add( "serializer.writeCharacters( " + getValue( field.getType(), value, xmlFieldMetadata ) + " );" ); sc.add( "serializer.writeEndElement();" ); } sc.unindent(); sc.add( "}" ); } } sc.add( "serializer.writeEndElement();" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( marshall ); } private void writeElementAttribute( JSourceCode sc, ModelField referenceIdentifierField, String value ) { if ( referenceIdentifierField instanceof DummyIdModelField ) { writeIdMapCheck( sc, value, referenceIdentifierField.getName() ); } else { String v = getValue( referenceIdentifierField.getType(), getFieldValue( value, referenceIdentifierField ), (XmlFieldMetadata) referenceIdentifierField.getMetadata( XmlFieldMetadata.ID ) ); sc.add( "serializer.writeAttribute( \"" + referenceIdentifierField.getName() + "\", " + v + " );" ); } } private static void writeIdMapCheck( JSourceCode sc, String value, String attributeName ) { sc.add( "if ( !idMap.containsKey( " + value + " ) )" ); sc.add( "{" ); sc.indent(); sc.add( "++curId;" ); sc.add( "String id = String.valueOf( curId );" ); sc.add( "idMap.put( " + value + ", id );" ); sc.add( "serializer.writeAttribute( \"" + attributeName + "\", id );" ); sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "serializer.writeAttribute( \"" + attributeName + "\", (String) idMap.get( " + value + " ) );" ); sc.add( "}" ); } private String getFieldValue( String uncapClassName, ModelField field ) { JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) field.getMetadata( JavaFieldMetadata.ID ); return uncapClassName + "." + getPrefix( javaFieldMetadata ) + capitalise( field.getName() ) + "()"; } private void createWriteDomMethod( JClass jClass ) { JMethod method = new JMethod( "writeDom" ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JType( "Xpp3Dom" ), "dom" ) ); method.addParameter( new JParameter( new JType( "XMLStreamWriter" ), "serializer" ) ); method.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "serializer.writeStartElement( dom.getName() );" ); sc.add( "String[] attributeNames = dom.getAttributeNames();" ); sc.add( "for ( int i = 0; i < attributeNames.length; i++ )" ); sc.add( "{" ); sc.indent(); sc.add( "String attributeName = attributeNames[i];" ); sc.add( "serializer.writeAttribute( attributeName, dom.getAttribute( attributeName ) );" ); sc.unindent(); sc.add( "}" ); sc.add( "Xpp3Dom[] children = dom.getChildren();" ); sc.add( "for ( int i = 0; i < children.length; i++ )" ); sc.add( "{" ); sc.addIndented( "writeDom( children[i], serializer );" ); sc.add( "}" ); sc.add( "String value = dom.getValue();" ); sc.add( "if ( value != null )" ); sc.add( "{" ); sc.addIndented( "serializer.writeCharacters( value );" ); sc.add( "}" ); sc.add( "serializer.writeEndElement();" ); jClass.addMethod( method ); } } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/GeneratorNode.javamodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/Gener0000644000175000017500000000706211127507731032732 0ustar mkochmkochpackage org.codehaus.modello.plugin.stax; import org.codehaus.modello.model.ModelAssociation; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ class GeneratorNode { private final String to; private boolean referencableChildren; private List children = new LinkedList(); private ModelAssociation association; private boolean referencable; private Map nodesWithReferencableChildren = new HashMap(); private List chain; GeneratorNode( String to, GeneratorNode parent ) { this( to, parent, null ); } GeneratorNode( ModelAssociation association, GeneratorNode parent ) { this( association.getTo(), parent, association ); } private GeneratorNode( String to, GeneratorNode parent, ModelAssociation association ) { this.to = to; this.association = association; this.chain = parent != null ? new ArrayList( parent.getChain() ) : new ArrayList(); this.chain.add( to ); } public boolean isReferencableChildren() { return referencableChildren; } public void setReferencableChildren( boolean referencableChildren ) { this.referencableChildren = referencableChildren; } public void addChild( GeneratorNode child ) { children.add( child ); if ( child.referencableChildren ) { nodesWithReferencableChildren.put( child.to, child ); } } public List getChildren() { return children; } public String toString() { return "to = " + to + "; referencableChildren = " + referencableChildren + "; children = " + children; } public String getTo() { return to; } public ModelAssociation getAssociation() { return association; } public void setAssociation( ModelAssociation association ) { this.association = association; } public void setReferencable( boolean referencable ) { this.referencable = referencable; } public boolean isReferencable() { return referencable; } public Map getNodesWithReferencableChildren() { return nodesWithReferencableChildren; } public void addNodesWithReferencableChildren( Map allChildNodes ) { this.nodesWithReferencableChildren.putAll( allChildNodes ); } public List getChain() { return chain; } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/AbstractStaxGenerator.javamodello-1.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/Abstr0000644000175000017500000001112411133474166032741 0ustar mkochmkochpackage org.codehaus.modello.plugin.stax; /* * Copyright (c) 2004, Jason van Zyl * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugins.xml.AbstractXmlJavaGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Set; /** * @author Trygve Laugstøl * @version $Id: AbstractStaxGenerator.java 1136 2009-01-14 23:42:46Z hboutemy $ */ public abstract class AbstractStaxGenerator extends AbstractXmlJavaGenerator { private Set/**/ parts; protected void initialize( Model model, Properties parameters ) throws ModelloException { super.initialize( model, parameters ); parts = null; } protected ModelField getReferenceIdentifierField( ModelAssociation association ) throws ModelloException { XmlAssociationMetadata xmlAssocMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); ModelField referenceIdentifierField = null; if ( xmlAssocMetadata.isReference() ) { String associationName = association.getName(); ModelClass modelClass = association.getModelClass(); if ( !isClassInModel( association.getTo(), modelClass.getModel() ) ) { throw new ModelloException( "Can't use xml.reference on the '" + associationName + "' association of '" + modelClass.getName() + "' because the target class '" + association.getTo() + "' is not in the model" ); } List identifierFields = association.getToClass().getIdentifierFields( getGeneratedVersion() ); if ( identifierFields.size() == 1 ) { referenceIdentifierField = (ModelField) identifierFields.get( 0 ); } else { referenceIdentifierField = new DummyIdModelField(); referenceIdentifierField.setName( "modello.refid" ); } } return referenceIdentifierField; } protected boolean isAssociationPartToClass( ModelClass modelClass ) { if ( parts == null ) { parts = new HashSet(); for ( Iterator i = modelClass.getModel().getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); for ( Iterator j = clazz.getFields( getGeneratedVersion() ).iterator(); j.hasNext(); ) { ModelField modelField = (ModelField) j.next(); if ( modelField instanceof ModelAssociation ) { ModelAssociation assoc = (ModelAssociation) modelField; XmlAssociationMetadata xmlAssocMetadata = (XmlAssociationMetadata) assoc.getAssociationMetadata( XmlAssociationMetadata.ID ); if ( xmlAssocMetadata.isReference() ) { parts.add( assoc.getToClass() ); } } } } } return parts.contains( modelClass ); } } modello-1.1/modello-plugins/modello-plugin-stax/src/main/resources/0000755000175000017500000000000011260056266024541 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/resources/META-INF/0000755000175000017500000000000011260056266025701 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056266027221 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-stax/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000101411127507731032124 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator stax-reader org.codehaus.modello.plugin.stax.StaxReaderGenerator org.codehaus.modello.plugin.ModelloGenerator stax-writer org.codehaus.modello.plugin.stax.StaxWriterGenerator modello-1.1/modello-plugins/modello-plugin-jdom/0000755000175000017500000000000011260056267020767 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/pom.xml0000644000175000017500000000305311243557055022307 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-jdom Modello JDOM Plugin Modello JDOM Plugin generates XML writers based on JDOM API. org.codehaus.modello modello-plugin-java org.codehaus.plexus plexus-utils org.codehaus.modello modello-plugin-xml org.codehaus.modello modello-plugin-dom4j test org.jdom jdom 1.1 test xmlunit xmlunit 1.2 test modello-1.1/modello-plugins/modello-plugin-jdom/src/0000755000175000017500000000000011260056267021556 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/0000755000175000017500000000000011260056267022535 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/verifiers/0000755000175000017500000000000011260056267024533 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/0000755000175000017500000000000011260056267026351 5ustar mkochmkoch././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/JDOMFeaturesVerifier.javamodello-1.1/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/JDOMFeaturesVerifier.jav0000644000175000017500000001010611223745157032777 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.jdom; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.features.Features; import org.codehaus.modello.test.features.io.dom4j.ModelloFeaturesTestDom4jReader; import org.codehaus.modello.test.features.io.jdom.ModelloFeaturesTestJDOMWriter; import org.codehaus.modello.verifier.Verifier; import org.codehaus.modello.verifier.VerifierException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import org.jdom.Document; import org.jdom.Element; import org.jdom.output.Format; import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; /** * @author Herve Boutemy * @version $Id: JDOMFeaturesVerifier.java 1275 2009-07-04 21:32:31Z bentmann $ */ public class JDOMFeaturesVerifier extends Verifier { public void verify() throws Exception { Features features = read(); features.getXmlFeatures().getXmlTransientFields().setTransientString( "NOT-TO-BE-WRITTEN" ); verifyWriter( features ); } private Features read() throws Exception { // no JDOM reader: using Dom4j reader instead... ModelloFeaturesTestDom4jReader reader = new ModelloFeaturesTestDom4jReader(); return reader.read( getClass().getResource( "/features.xml" ) ); } public void verifyWriter( Features features ) throws Exception { ModelloFeaturesTestJDOMWriter writer = new ModelloFeaturesTestJDOMWriter(); StringWriter buffer = new StringWriter(); Document doc = new Document( new Element( "features" ) ); writer.write( features, doc, buffer, Format.getRawFormat() ); String initialXml = IOUtil.toString( getXmlResourceReader( "/features.xml" ) ); String actualXml = buffer.toString(); // workaround for MODELLO-... actualXml = actualXml.replaceFirst( "", "" ); // alias is rendered as default field name => must be reverted here to let the test pass actualXml = actualXml.replaceFirst( "alias", "alias" ); //assertTrue( actualXml.substring( 0, 38 ), actualXml.startsWith( "" ) ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreComments( true ); Diff diff = XMLUnit.compareXML( initialXml, actualXml ); if ( !diff.identical() ) { System.err.println( actualXml ); /*throw*/ new VerifierException( "writer result is not the same as original content: " + diff ) .printStackTrace( System.err ); } } } modello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/0000755000175000017500000000000011260056267023456 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/org/0000755000175000017500000000000011260056267024245 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/0000755000175000017500000000000011260056267026040 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056267027473 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056267030771 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/plugin/jdom/0000755000175000017500000000000011260056267031722 5ustar mkochmkoch././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/plugin/jdom/FeaturesJDOMGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/plugin/jdom/Featu0000644000175000017500000000537011176576243032725 0ustar mkochmkochpackage org.codehaus.modello.plugin.jdom; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesJDOMGeneratorTest.java 1225 2009-05-01 13:44:03Z hboutemy $ */ public class FeaturesJDOMGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesJDOMGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "java", parameters ); modello.generate( model, "dom4j-reader", parameters ); modello.generate( model, "jdom-writer", parameters ); addDependency( "dom4j", "dom4j", "1.6.1" ); // needed to read features.xml with dom4j addDependency( "org.jdom", "jdom", "1.1" ); addDependency( "xmlunit", "xmlunit", "1.2" ); compile( getOutputDirectory(), getOutputClasses() ); verify( "org.codehaus.modello.generator.xml.jdom.JDOMFeaturesVerifier", getName() ); } } modello-1.1/modello-plugins/modello-plugin-jdom/src/site/0000755000175000017500000000000011260056267022522 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/site/site.xml0000644000175000017500000000022511112331565024200 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-jdom/src/site/xdoc/0000755000175000017500000000000011260056267023457 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/site/xdoc/index.xml0000644000175000017500000000247411131476544025320 0ustar mkochmkoch Modello JDOM Plugin Hervé Boutemy

Modello JDOM Plugin generates XML writers based on JDOM API. It attempts to preserve formatting of not changed elements and even with the changed ones it does some tricks to keep the formatting in line with the rest.

jdom-writer generator creates my.model.package.io.jdom.ModelNameJDOMWriter class with following public methods:

  • public void write( RootClass root, Document document, OutputStream stream )
        throws IOException
  • public void write( RootClass root, Document document, OutputStreamWriter writer )
        throws IOException
  • public void write( RootClass root, Document document, Writer writer, Format jdomFormat )
        throws IOException
modello-1.1/modello-plugins/modello-plugin-jdom/src/main/0000755000175000017500000000000011260056267022502 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/0000755000175000017500000000000011260056267023423 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/0000755000175000017500000000000011260056267024212 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/0000755000175000017500000000000011260056267026005 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056267027440 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056267030736 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/0000755000175000017500000000000011260056267031667 5ustar mkochmkoch././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/JDOMWriterGenerator.javamodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/JDOMW0000644000175000017500000011355711243356043032502 0ustar mkochmkoch/* ========================================================================== * Copyright 2005 Mevenide Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ========================================================================= */ package org.codehaus.modello.plugin.jdom; import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JConstructor; import org.codehaus.modello.plugin.java.javasource.JField; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JType; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * @author mkleint@codehaus.org */ public class JDOMWriterGenerator extends AbstractJDOMGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateJDOMWriter(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating JDOM Writer.", ex ); } } private void generateJDOMWriter() throws ModelloException, IOException { Model objectModel = getModel(); String packageName= objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.jdom"; String marshallerName = getFileName( "JDOMWriter" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, marshallerName ); JClass jClass = new JClass( packageName + '.' + marshallerName ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); // ------------------------------------------------------------- // imports now // ------------------------------------------------------------- jClass.addImport( "java.io.OutputStream" ); jClass.addImport( "java.io.OutputStreamWriter" ); jClass.addImport( "java.io.Writer" ); jClass.addImport( "java.text.DateFormat" ); jClass.addImport( "java.util.ArrayList" ); jClass.addImport( "java.util.Collection" ); jClass.addImport( "java.util.Iterator" ); jClass.addImport( "java.util.List" ); jClass.addImport( "java.util.ListIterator" ); jClass.addImport( "java.util.Locale" ); jClass.addImport( "java.util.Map" ); jClass.addImport( "java.util.Properties" ); jClass.addImport( "org.jdom.Content" ); jClass.addImport( "org.jdom.DefaultJDOMFactory" ); jClass.addImport( "org.jdom.Document" ); jClass.addImport( "org.jdom.Element" ); jClass.addImport( "org.jdom.Text" ); jClass.addImport( "org.jdom.output.Format" ); jClass.addImport( "org.jdom.output.XMLOutputter" ); jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); addModelImports( jClass, null ); jClass.addField( new JField( new JClass( "DefaultJDOMFactory" ), "factory" ) ); jClass.addField( new JField( new JClass( "String" ), "lineSeparator" ) ); createCounter( jClass ); // constructor -- JConstructor constructor = jClass.createConstructor(); JSourceCode constCode = constructor.getSourceCode(); constCode.add( "factory = new DefaultJDOMFactory();" ); constCode.add( "lineSeparator = \"\\n\";" ); String root = objectModel.getRoot( getGeneratedVersion() ); ModelClass rootClass = objectModel.getClass( root, getGeneratedVersion() ); String rootElement = resolveTagName( rootClass ); // the public global write method.. jClass.addMethod( generateWriteModel( root, rootElement ) ); jClass.addMethod( generateWriteModel2( root, rootElement ) ); jClass.addMethod( generateWriteModel3( root, rootElement ) ); // the private utility classes; jClass.addMethods( generateUtilityMethods() ); writeAllClasses( objectModel, jClass, rootClass ); jClass.print( sourceWriter ); sourceWriter.close(); } private void createCounter( final JClass jClass ) throws IllegalArgumentException { // inner counter class JClass counter = jClass.createInnerClass( "Counter" ); counter.getModifiers().setStatic( true ); JField fld = new JField( new JType( "int" ), "currentIndex" ); fld.setInitString( "0" ); counter.addField( fld ); fld = new JField( new JType( "int" ), "level" ); counter.addField( fld ); JConstructor constr = counter.createConstructor( new JParameter[] { new JParameter( new JType( "int" ), "depthLevel" ) } ); constr.getSourceCode().append( "level = depthLevel;" ); JMethod inc = new JMethod( "increaseCount" ); inc.getSourceCode().add( "currentIndex = currentIndex + 1;" ); counter.addMethod( inc ); JMethod getter = new JMethod( "getCurrentIndex", new JType( "int" ), null ); getter.getSourceCode().add( "return currentIndex;" ); counter.addMethod( getter ); getter = new JMethod( "getDepth", new JType( "int" ), null ); getter.getSourceCode().add( "return level;" ); counter.addMethod( getter ); } private JMethod generateWriteModel( String root, String rootElement ) { JMethod marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( root ), rootElement ) ); marshall.addParameter( new JParameter( new JClass( "Document" ), "document" ) ); marshall.addParameter( new JParameter( new JClass( "OutputStream" ), "stream" ) ); marshall.addException( new JClass( "java.io.IOException" ) ); marshall.getJDocComment().appendComment( "\n@deprecated" ); JSourceCode sc = marshall.getSourceCode(); sc.add( "update" + root + "( " + rootElement + ", \"" + rootElement + "\", new Counter( 0 ), document.getRootElement() );" ); sc.add( "XMLOutputter outputter = new XMLOutputter();" ); sc.add( "outputter.setFormat( Format.getPrettyFormat()" ); sc.add( " .setIndent( \" \" )" ); sc.add( " .setLineSeparator( System.getProperty( \"line.separator\" ) ) );" ); sc.add( "outputter.output( document, stream );" ); return marshall; } private JMethod generateWriteModel2( String root, String rootElement ) { JMethod marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( root ), rootElement ) ); marshall.addParameter( new JParameter( new JClass( "Document" ), "document" ) ); marshall.addParameter( new JParameter( new JClass( "OutputStreamWriter" ), "writer" ) ); marshall.addException( new JClass( "java.io.IOException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "Format format = Format.getRawFormat()" ); sc.add( " .setEncoding( writer.getEncoding() )" ); sc.add( " .setLineSeparator( System.getProperty( \"line.separator\" ) );" ); sc.add( "write( " + rootElement + ", document, writer, format );" ); return marshall; } private JMethod generateWriteModel3( String root, String rootElement ) { JMethod marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( root ), rootElement ) ); marshall.addParameter( new JParameter( new JClass( "Document" ), "document" ) ); marshall.addParameter( new JParameter( new JClass( "Writer" ), "writer" ) ); marshall.addParameter( new JParameter( new JClass( "Format" ), "jdomFormat" ) ); marshall.addException( new JClass( "java.io.IOException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "update" + root + "( " + rootElement + ", \"" + rootElement + "\", new Counter( 0 ), document.getRootElement() );" ); sc.add( "XMLOutputter outputter = new XMLOutputter();" ); sc.add( "outputter.setFormat( jdomFormat );" ); sc.add( "outputter.output( document, writer );" ); return marshall; } private JMethod[] generateUtilityMethods() { JMethod findRSElement = new JMethod( "findAndReplaceSimpleElement", new JClass( "Element" ), null ); findRSElement.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); findRSElement.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); findRSElement.addParameter( new JParameter( new JClass( "String" ), "name" ) ); findRSElement.addParameter( new JParameter( new JClass( "String" ), "text" ) ); findRSElement.addParameter( new JParameter( new JClass( "String" ), "defaultValue" ) ); findRSElement.getModifiers().makeProtected(); JSourceCode sc = findRSElement.getSourceCode(); sc.add( "if ( ( defaultValue != null ) && ( text != null ) && defaultValue.equals( text ) )" ); sc.add( "{" ); sc.indent(); sc.add( "Element element = parent.getChild( name, parent.getNamespace() );" ); sc.add( "// if exist and is default value or if doesn't exist.. just keep the way it is.." ); sc.add( "if ( ( element != null && defaultValue.equals( element.getText() ) ) || element == null )" ); sc.add( "{" ); sc.addIndented( "return element;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "boolean shouldExist = ( text != null ) && ( text.trim().length() > 0 );" ); sc.add( "Element element = updateElement( counter, parent, name, shouldExist );" ); sc.add( "if ( shouldExist )" ); sc.add( "{" ); sc.addIndented( "element.setText( text );" ); sc.add( "}" ); sc.add( "return element;" ); JMethod updateElement = new JMethod( "updateElement", new JClass( "Element" ), null ); updateElement.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); updateElement.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); updateElement.addParameter( new JParameter( new JClass( "String" ), "name" ) ); updateElement.addParameter( new JParameter( new JType( "boolean" ), "shouldExist" ) ); updateElement.getModifiers().makeProtected(); sc = updateElement.getSourceCode(); sc.add( "Element element = parent.getChild( name, parent.getNamespace() );" ); sc.add( "if ( element != null && shouldExist )" ); sc.add( "{" ); sc.addIndented( "counter.increaseCount();" ); sc.add( "}" ); sc.add( "if ( element == null && shouldExist )" ); sc.add( "{" ); sc.indent(); sc.add( "element = factory.element( name, parent.getNamespace() );" ); sc.add( "insertAtPreferredLocation( parent, element, counter );" ); sc.add( "counter.increaseCount();" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( !shouldExist && element != null )" ); sc.add( "{" ); sc.indent(); sc.add( "int index = parent.indexOf( element );" ); sc.add( "if ( index > 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "Content previous = parent.getContent( index - 1 );" ); sc.add( "if ( previous instanceof Text )" ); sc.add( "{" ); sc.indent(); sc.add( "Text txt = (Text) previous;" ); sc.add( "if ( txt.getTextTrim().length() == 0 )" ); sc.add( "{" ); sc.addIndented( "parent.removeContent( txt );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "parent.removeContent( element );" ); sc.unindent(); sc.add( "}" ); sc.add( "return element;" ); JMethod insAtPref = new JMethod( "insertAtPreferredLocation" ); insAtPref.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); insAtPref.addParameter( new JParameter( new JClass( "Element" ), "child" ) ); insAtPref.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); insAtPref.getModifiers().makeProtected(); sc = insAtPref.getSourceCode(); sc.add( "int contentIndex = 0;" ); sc.add( "int elementCounter = 0;" ); sc.add( "Iterator it = parent.getContent().iterator();" ); sc.add( "Text lastText = null;" ); sc.add( "int offset = 0;" ); sc.add( "while ( it.hasNext() && elementCounter <= counter.getCurrentIndex() )" ); sc.add( "{" ); sc.indent(); sc.add( "Object next = it.next();" ); sc.add( "offset = offset + 1;" ); sc.add( "if ( next instanceof Element )" ); sc.add( "{" ); sc.indent(); sc.add( "elementCounter = elementCounter + 1;" ); sc.add( "contentIndex = contentIndex + offset;" ); sc.add( "offset = 0;" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( next instanceof Text && it.hasNext() )" ); sc.add( "{" ); sc.addIndented( "lastText = (Text) next;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); // sc.add("if ( lastText == null )" ); // sc.add( "{" ); // sc.indent(); // sc.add( "int index = parent.getParentElement().indexOf( parent );" ); // sc.add( "if ( index > 0 ) "); // sc.add( "{" ); // sc.indent(); // sc.add( "Content cont = parent.getParentElement().getContent( index - 1 );" ); // sc.add( "if ( cont instanceof Text )" ); // sc.add( "{" ); // sc.addIndented( "lastText = (Text) cont;" ); // sc.add( "}" ); // sc.unindent(); // sc.add( "}" ); // sc.unindent(); // sc.add( "}" ); sc.add( "if ( lastText != null && lastText.getTextTrim().length() == 0 )" ); sc.add( "{" ); sc.addIndented( "lastText = (Text) lastText.clone();" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "String starter = lineSeparator;" ); sc.add( "for ( int i = 0; i < counter.getDepth(); i++ )" ); sc.add( "{" ); sc.addIndented( "starter = starter + \" \"; //TODO make settable?" ); sc.add( "}" ); sc.add( "lastText = factory.text( starter );" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( parent.getContentSize() == 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "Text finalText = (Text) lastText.clone();" ); sc.add( "finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - \" \".length() ) );" ); sc.add( "parent.addContent( contentIndex, finalText );" ); sc.unindent(); sc.add( "}" ); sc.add( "parent.addContent( contentIndex, child );" ); sc.add( "parent.addContent( contentIndex, lastText );" ); JMethod findRSProps = new JMethod( "findAndReplaceProperties", new JClass( "Element" ), null ); findRSProps.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); findRSProps.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); findRSProps.addParameter( new JParameter( new JClass( "String" ), "name" ) ); findRSProps.addParameter( new JParameter( new JClass( "Map" ), "props" ) ); findRSProps.getModifiers().makeProtected(); sc = findRSProps.getSourceCode(); sc.add( "boolean shouldExist = ( props != null ) && ! props.isEmpty();" ); sc.add( "Element element = updateElement( counter, parent, name, shouldExist );" ); sc.add( "if ( shouldExist )" ); sc.add( "{" ); sc.indent(); sc.add( "Iterator it = props.keySet().iterator();" ); sc.add( "Counter innerCounter = new Counter( counter.getDepth() + 1 );" ); sc.add( "while ( it.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = (String) it.next();" ); sc.add( "findAndReplaceSimpleElement( innerCounter, element, key, (String) props.get( key ), null );" ); sc.unindent(); sc.add( "}" ); sc.add( "ArrayList lst = new ArrayList( props.keySet() );" ); sc.add( "it = element.getChildren().iterator();" ); sc.add( "while ( it.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "Element elem = (Element) it.next();" ); sc.add( "String key = elem.getName();" ); sc.add( "if ( !lst.contains( key ) )" ); sc.add( "{" ); sc.addIndented( "it.remove();" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return element;" ); JMethod findRSLists = new JMethod( "findAndReplaceSimpleLists", new JClass( "Element" ), null ); findRSLists.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); findRSLists.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); findRSLists.addParameter( new JParameter( new JClass( "java.util.Collection" ), "list" ) ); findRSLists.addParameter( new JParameter( new JClass( "String" ), "parentName" ) ); findRSLists.addParameter( new JParameter( new JClass( "String" ), "childName" ) ); findRSLists.getModifiers().makeProtected(); sc = findRSLists.getSourceCode(); sc.add( "boolean shouldExist = ( list != null ) && ( list.size() > 0 );" ); sc.add( "Element element = updateElement( counter, parent, parentName, shouldExist );" ); sc.add( "if ( shouldExist )" ); sc.add( "{" ); sc.indent(); sc.add( "Iterator it = list.iterator();" ); sc.add( "Iterator elIt = element.getChildren( childName, element.getNamespace() ).iterator();" ); sc.add( "if ( ! elIt.hasNext() )" ); sc.add( "{" ); sc.addIndented( " elIt = null;" ); sc.add( "}" ); sc.add( "Counter innerCount = new Counter( counter.getDepth() + 1 );" ); sc.add( "while ( it.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "String value = (String) it.next();" ); sc.add( "Element el;" ); sc.add( "if ( elIt != null && elIt.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "el = (Element) elIt.next();" ); sc.add( "if ( ! elIt.hasNext() )" ); sc.add( "{" ); sc.addIndented( "elIt = null;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "el = factory.element( childName, element.getNamespace() );" ); sc.add( "insertAtPreferredLocation( element, el, innerCount );" ); sc.unindent(); sc.add( "}" ); sc.add( "el.setText( value );" ); sc.add( "innerCount.increaseCount();" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( elIt != null )" ); sc.add( "{" ); sc.indent(); sc.add( "while ( elIt.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "elIt.next();" ); sc.add( "elIt.remove();" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return element;" ); JMethod findRSDom = new JMethod( "findAndReplaceXpp3DOM", new JClass( "Element" ), null ); findRSDom.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); findRSDom.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); findRSDom.addParameter( new JParameter( new JClass( "String" ), "name" ) ); findRSDom.addParameter( new JParameter( new JClass( "Xpp3Dom" ), "dom" ) ); findRSDom.getModifiers().makeProtected(); sc = findRSDom.getSourceCode(); sc.add( "boolean shouldExist = ( dom != null ) && ( dom.getChildCount() > 0 || dom.getValue() != null );" ); sc.add( "Element element = updateElement( counter, parent, name, shouldExist );" ); sc.add( "if ( shouldExist )" ); sc.add( "{" ); sc.addIndented( "replaceXpp3DOM( element, dom, new Counter( counter.getDepth() + 1 ) );" ); sc.add( "}" ); sc.add( "return element;" ); JMethod findRSDom2 = new JMethod( "replaceXpp3DOM" ); findRSDom2.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); findRSDom2.addParameter( new JParameter( new JClass( "Xpp3Dom" ), "parentDom" ) ); findRSDom2.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); findRSDom2.getModifiers().makeProtected(); sc = findRSDom2.getSourceCode(); sc.add( "if ( parentDom.getChildCount() > 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "Xpp3Dom[] childs = parentDom.getChildren();" ); sc.add( "Collection domChilds = new ArrayList();" ); sc.add( "for ( int i = 0; i < childs.length; i++ )" ); sc.add( "{" ); sc.addIndented( "domChilds.add( childs[i] );" ); sc.add( "}" ); sc.add( "ListIterator it = parent.getChildren().listIterator();" ); sc.add( "while ( it.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "Element elem = (Element) it.next();" ); sc.add( "Iterator it2 = domChilds.iterator();" ); sc.add( "Xpp3Dom corrDom = null;" ); sc.add( "while ( it2.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "Xpp3Dom dm = (Xpp3Dom) it2.next();" ); sc.add( "if ( dm.getName().equals( elem.getName() ) )" ); sc.add( "{" ); sc.indent(); sc.add( "corrDom = dm;" ); sc.add( "break;" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( corrDom != null )" ); sc.add( "{" ); sc.indent(); sc.add( "domChilds.remove( corrDom );" ); sc.add( "replaceXpp3DOM( elem, corrDom, new Counter( counter.getDepth() + 1 ) );" ); sc.add( "counter.increaseCount();" ); sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "it.remove();" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "Iterator it2 = domChilds.iterator();" ); sc.add( "while ( it2.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "Xpp3Dom dm = (Xpp3Dom) it2.next();" ); sc.add( "Element elem = factory.element( dm.getName(), parent.getNamespace() );" ); sc.add( "insertAtPreferredLocation( parent, elem, counter );" ); sc.add( "counter.increaseCount();" ); sc.add( "replaceXpp3DOM( elem, dm, new Counter( counter.getDepth() + 1 ) );" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( " else if ( parentDom.getValue() != null )" ); sc.add( "{" ); sc.addIndented( "parent.setText( parentDom.getValue() );" ); sc.add( "}" ); return new JMethod[]{findRSElement, updateElement, insAtPref, findRSProps, findRSLists, findRSDom, findRSDom2}; } private void writeAllClasses( Model objectModel, JClass jClass, ModelClass rootClass ) throws ModelloException { ArrayList alwaysExistingElements = new ArrayList(); alwaysExistingElements.add( rootClass ); for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) clazz.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } updateClass( clazz, jClass, alwaysExistingElements ); } } private void updateClass( ModelClass clazz, JClass jClass, ArrayList alwaysExisting ) throws ModelloException { String className = clazz.getName(); String uncapClassName = uncapitalise( className ); String clazzTagName = null; if ( clazz.hasMetadata( XmlFieldMetadata.ID ) ) { XmlFieldMetadata clazzMetadata = (XmlFieldMetadata) clazz.getMetadata( XmlFieldMetadata.ID ); clazzTagName = clazzMetadata.getTagName(); } JMethod marshall = new JMethod( "update" + className ); marshall.addParameter( new JParameter( new JClass( className ), "value" ) ); marshall.addParameter( new JParameter( new JClass( "String" ), "xmlTag" ) ); marshall.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); marshall.addParameter( new JParameter( new JClass( "Element" ), "element" ) ); marshall.getModifiers().makeProtected(); if ( clazzTagName == null ) { clazzTagName = uncapClassName; } JSourceCode sc = marshall.getSourceCode(); boolean shouldExist = alwaysExisting.contains( clazz ); if ( shouldExist ) { sc.add( "Element root = element;" ); } else { sc.add( "boolean shouldExist = ( value != null );" ); sc.add( "Element root = updateElement( counter, element, xmlTag, shouldExist );" ); sc.add( "if ( shouldExist )" ); sc.add( "{" ); sc.indent(); } sc.add( "Counter innerCount = new Counter( counter.getDepth() + 1 );" ); List modelFields = clazz.getAllFields( getGeneratedVersion(), true ); modelFields = getNonTransientFields( modelFields ); for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) field.getMetadata( JavaFieldMetadata.ID ); String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String type = field.getType(); String value = "value." + getPrefix( javaFieldMetadata ) + capitalise( field.getName() ) + "()"; if ( xmlFieldMetadata.isAttribute() ) { continue; } if ( field instanceof ModelAssociation ) { ModelAssociation association = (ModelAssociation) field; ModelClass toClass = association.getToClass(); if ( association.isOneMultiplicity() ) { sc.add( "update" + capitalise( field.getType() ) + "( " + value + ", \"" + fieldTagName + "\", innerCount, root );" ); } else { //MANY_MULTIPLICITY XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); //String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); // // type = association.getType(); // String toType = association.getTo(); // if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { // type = association.getType(); String toType = association.getTo(); if ( toClass != null ) { if ( xmlAssociationMetadata.isWrappedItems() ) { sc.add( "iterate" + capitalise( toType ) + "( innerCount, root, " + value + ",\"" + field.getName() + "\",\"" + singular( fieldTagName ) + "\" );" ); createIterateMethod( field.getName(), toClass, singular( fieldTagName ), jClass ); } else { //assume flat.. sc.add( "iterate2" + capitalise( toType ) + "( innerCount, root, " + value + ", \"" + singular( fieldTagName ) + "\" );" ); createIterateMethod2( field.getName(), toClass, singular( fieldTagName ), jClass ); } alwaysExisting.add( toClass ); } else { //list of strings? sc.add( "findAndReplaceSimpleLists( innerCount, root, " + value + ", \"" + fieldTagName + "\", \"" + singular( fieldTagName ) + "\" );" ); } } else { //Map or Properties sc.add( "findAndReplaceProperties( innerCount, root, \"" + fieldTagName + "\", " + value + " );" ); } } } else { if ( "DOM".equals( field.getType() ) ) { sc.add( "findAndReplaceXpp3DOM( innerCount, root, \"" + fieldTagName + "\", (Xpp3Dom) " + value + " );" ); } else { sc.add( "findAndReplaceSimpleElement( innerCount, root, \"" + fieldTagName + "\", " + getJdomValueChecker( type, value, field ) + getValue( type, value, xmlFieldMetadata ) + ", " + ( field.getDefaultValue() != null ? ( "\"" + field.getDefaultValue() + "\"" ) : "null" ) + " );" ); } } } if ( !shouldExist ) { sc.unindent(); sc.add( "}" ); } jClass.addMethod( marshall ); } private String getJdomValueChecker( String type, String value, ModelField field ) throws ModelloException { if ( "boolean".equals( type ) || "double".equals( type ) || "float".equals( type ) || "int".equals( type ) || "long".equals( type ) || "short".equals( type ) || "byte".equals( type ) || "char".equals( type ) ) { return value + " == " + getJavaDefaultValue( field ) + " ? null : "; } else if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) || ModelDefault.MAP.equals( type ) || ModelDefault.PROPERTIES.equals( type ) ) { return value + " == null || " + value + ".size() == 0 ? null : "; // } else if ( "String".equals( type ) && field.getDefaultValue() != null ) { // return "" + value + " == null || " + value + ".equals( \"" + field.getDefaultValue() + "\" ) ? null : "; } else if ( "Date".equals( type ) && field.getDefaultValue() != null ) { return "" + value + " == null || " + value + ".equals( " + getJavaDefaultValue( field ) + " ) ? null : "; } else { return value + " == null ? null : "; } } private void createIterateMethod( String field, ModelClass toClass, String childFieldTagName, JClass jClass ) { if ( jClass.getMethod( "iterate" + capitalise( toClass.getName() ), 0 ) != null ) { // System.out.println("method iterate" + capitalise(field) + " already exists"); return; } JMethod toReturn = new JMethod( "iterate" + capitalise( toClass.getName() ) ); toReturn.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); toReturn.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); toReturn.addParameter( new JParameter( new JClass( "java.util.Collection" ), "list" ) ); toReturn.addParameter( new JParameter( new JClass( "java.lang.String" ), "parentTag" ) ); toReturn.addParameter( new JParameter( new JClass( "java.lang.String" ), "childTag" ) ); toReturn.getModifiers().makeProtected(); JSourceCode sc = toReturn.getSourceCode(); sc.add( "boolean shouldExist = ( list != null ) && ( list.size() > 0 );" ); sc.add( "Element element = updateElement( counter, parent, parentTag, shouldExist );" ); sc.add( "if ( shouldExist )" ); sc.add( "{" ); sc.indent(); sc.add( "Iterator it = list.iterator();" ); sc.add( "Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();" ); sc.add( "if ( !elIt.hasNext() )" ); sc.add( "{" ); sc.addIndented( "elIt = null;" ); sc.add( "}" ); sc.add( "Counter innerCount = new Counter( counter.getDepth() + 1 );" ); sc.add( "while ( it.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( toClass.getName() + " value = (" + toClass.getName() + ") it.next();" ); sc.add( "Element el;" ); sc.add( "if ( elIt != null && elIt.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "el = (Element) elIt.next();" ); sc.add( "if ( ! elIt.hasNext() )" ); sc.add( "{" ); sc.addIndented( " elIt = null;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "el = factory.element( childTag, element.getNamespace() );" ); sc.add( "insertAtPreferredLocation( element, el, innerCount );" ); sc.unindent(); sc.add( "}" ); sc.add( "update" + toClass.getName() + "( value, childTag, innerCount, el );" ); sc.add( "innerCount.increaseCount();" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( elIt != null )" ); sc.add( "{" ); sc.indent(); sc.add( "while ( elIt.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "elIt.next();" ); sc.add( "elIt.remove();" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( toReturn ); } private void createIterateMethod2( String field, ModelClass toClass, String childFieldTagName, JClass jClass ) { if ( jClass.getMethod( "iterate2" + capitalise( toClass.getName() ), 0 ) != null ) { // System.out.println("method iterate" + capitalise(field) + " already exists"); return; } JMethod toReturn = new JMethod( "iterate2" + capitalise( toClass.getName() ) ); toReturn.addParameter( new JParameter( new JClass( "Counter" ), "counter" ) ); toReturn.addParameter( new JParameter( new JClass( "Element" ), "parent" ) ); toReturn.addParameter( new JParameter( new JClass( "java.util.Collection" ), "list" ) ); toReturn.addParameter( new JParameter( new JClass( "java.lang.String" ), "childTag" ) ); toReturn.getModifiers().makeProtected(); JSourceCode sc = toReturn.getSourceCode(); sc.add( "Iterator it = list.iterator();" ); sc.add( "Iterator elIt = parent.getChildren( childTag, parent.getNamespace() ).iterator();" ); sc.add( "if ( !elIt.hasNext() )" ); sc.add( "{" ); sc.addIndented( "elIt = null;" ); sc.add( "}" ); sc.add( "Counter innerCount = new Counter( counter.getDepth() + 1 );" ); sc.add( "while ( it.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( toClass.getName() + " value = (" + toClass.getName() + ") it.next();" ); sc.add( "Element el;" ); sc.add( "if ( elIt != null && elIt.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "el = (Element) elIt.next();" ); sc.add( "if ( ! elIt.hasNext() )" ); sc.add( "{" ); sc.addIndented( "elIt = null;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "el = factory.element( childTag, parent.getNamespace() );" ); sc.add( "insertAtPreferredLocation( parent, el, innerCount );" ); sc.unindent(); sc.add( "}" ); sc.add( "update" + toClass.getName() + "( value, childTag, innerCount, el );" ); sc.add( "innerCount.increaseCount();" ); sc.unindent(); sc.add( "}" ); sc.add( "if ( elIt != null )" ); sc.add( "{" ); sc.indent(); sc.add( "while ( elIt.hasNext() )" ); sc.add( "{" ); sc.indent(); sc.add( "elIt.next();" ); sc.add( "elIt.remove();" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( toReturn ); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/AbstractJDOMGenerator.javamodello-1.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/Abstr0000644000175000017500000000270411127674774032703 0ustar mkochmkochpackage org.codehaus.modello.plugin.jdom; /* * Copyright (c) 2004, Jason van Zyl * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.plugins.xml.AbstractXmlJavaGenerator; /** * @author Trygve Laugstøl * @version $Id: AbstractJDOMGenerator.java 1095 2009-01-03 14:45:16Z hboutemy $ */ public abstract class AbstractJDOMGenerator extends AbstractXmlJavaGenerator { } modello-1.1/modello-plugins/modello-plugin-jdom/src/main/resources/0000755000175000017500000000000011260056267024514 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/resources/META-INF/0000755000175000017500000000000011260056267025654 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056267027174 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-jdom/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000044611127507731032106 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator jdom-writer org.codehaus.modello.plugin.jdom.JDOMWriterGenerator modello-1.1/modello-plugins/modello-plugin-converters/0000755000175000017500000000000011260056264022225 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/pom.xml0000644000175000017500000000244711243557055023556 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-converters Modello Model Version Converter Plugin Modello Model Version Converter Plugin generates code to transform a model between two versions. org.codehaus.modello modello-plugin-java org.codehaus.modello modello-plugin-stax test stax stax-api 1.0.1 test stax stax 1.2.0 test modello-1.1/modello-plugins/modello-plugin-converters/src/0000755000175000017500000000000011260056264023014 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/0000755000175000017500000000000011260056263023772 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/verifiers/0000755000175000017500000000000011260056263025770 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/0000755000175000017500000000000011260056263030162 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/expected-v3.xml0000644000175000017500000001247011127507731033042 0ustar mkochmkoch ../project.xml 3 id groupId artifactId name 1.0 shortDesc description http://localhost/foo/ http://localhost/foo/logo.png http://localhost/bugzilla/ 2006 gumpy localhost /www/site/foo localhost /www/site/foo Users users-subscribe@maven.apache.org users-unsubscribe@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-users/ PMC root name2 root@localhost http://jroller.com/page/name organization role1 +1 n3 name3 root@localhost http://jroller.com/page/name organization role1 role3 name root@localhost http://jroller.com/page/name organization role1 role2 +10 name2 root@localhost http://jroller.com/page/name organization role1 +1 id version2 groupId artifactId version http://localhost/projects/groupId dummy dummy dummy.jar webapps sales 1.0-SNAPSHOT war servlet-api 2.3 false ASL2 http://www.apache.org/license/LICENSE-2.0.txt repo LGPL repo optional name tag_1 1 tag_1 tag_2 title org.apache.maven,org.apache.commons maven-checkstyle-report maven-javadoc-report scm:svn:... scm:svn:... http://... root@localhost src test aspects itests com.sun.corba.se.impl.activation.CommandHandler property src/java5 **/tiger/** dir target true **/*.properties **/*.ignoreme Apache http://www.apache.org http://www.apache.org/images/logo.gif 8080 localhost modello-1.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/input.xml0000644000175000017500000001341611127507731032053 0ustar mkochmkoch ../project.xml 3 id groupId artifactId 1.0 name shortDesc description http://localhost/foo/ http://localhost/foo/logo.png http://localhost/bugzilla/ 2006 gumpy localhost /www/site/foo localhost /www/site/foo Users users-subscribe@maven.apache.org users-unsubscribe@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-users/ PMC root name2 root@localhost http://jroller.com/page/name organization role1 +1 n3 name3 root@localhost http://jroller.com/page/name organization role1 role3 name root@localhost http://jroller.com/page/name organization role1 role2 +10 name2 root@localhost http://jroller.com/page/name organization role1 +1 id version2 groupId artifactId version http://localhost/projects/groupId dummy dummy dummy.jar webapps sales 1.0-SNAPSHOT war servlet-api 2.3 false ASL2 http://www.apache.org/license/LICENSE-2.0.txt repo LGPL repo optional name tag_1 1 tag_1 tag_2 title org.apache.maven,org.apache.commons maven-checkstyle-report maven-javadoc-report scm:svn:... scm:svn:... http://... root@localhost src test aspects itests src/java5 **/tiger/** com.sun.corba.se.impl.activation.CommandHandler property **/*.properties **/*.ignoreme dir target true Apache http://www.apache.org http://www.apache.org/images/logo.gif localhost 8080 ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/ConvertersVerifier.javamodello-1.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/ConvertersVerifi0000644000175000017500000000776411127507731033425 0ustar mkochmkoch/* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.verifier.Verifier; import junit.framework.Assert; import java.io.*; import org.codehaus.plexus.util.FileUtils; public class ConvertersVerifier extends Verifier { public void verify() throws Exception { // Note that this is *not* a full POM translation (fields like currentVersion are not mapped) File file = new File( "src/test/verifiers/converters/input.xml" ); org.codehaus.modello.test.maven.convert.ConverterTool convert = new org.codehaus.modello.test.maven.convert.ConverterTool(); org.codehaus.modello.test.maven.v3_0_0.Model modelV3 = convert.convertFromFile_v3_0_0( file ); StringWriter sw = new StringWriter(); org.codehaus.modello.test.maven.v3_0_0.io.stax.MavenStaxWriter writerV3 = new org.codehaus.modello.test.maven.v3_0_0.io.stax.MavenStaxWriter(); writerV3.write( sw, modelV3 ); Assert.assertEquals( convertLineEndings( FileUtils.fileRead( "src/test/verifiers/converters/expected-v3.xml" ).trim() ), convertLineEndings( scrubXmlDeclQuotes( sw.toString() ).trim() ) ); org.codehaus.modello.test.maven.v4_0_0.Model modelV4 = convert.convertFromFile_v4_0_0( file ); sw = new StringWriter(); org.codehaus.modello.test.maven.v4_0_0.io.stax.MavenStaxWriter writerV4 = new org.codehaus.modello.test.maven.v4_0_0.io.stax.MavenStaxWriter(); writerV4.write( sw, modelV4 ); Assert.assertEquals( convertLineEndings( FileUtils.fileRead( "src/test/verifiers/converters/expected.xml" ).trim() ), convertLineEndings( scrubXmlDeclQuotes( sw.toString() ).trim() ) ); org.codehaus.modello.test.maven.Model model = convert.convertFromFile( file ); sw = new StringWriter(); org.codehaus.modello.test.maven.io.stax.MavenStaxWriter writer = new org.codehaus.modello.test.maven.io.stax.MavenStaxWriter(); writer.write( sw, model ); Assert.assertEquals( convertLineEndings( FileUtils.fileRead( "src/test/verifiers/converters/expected.xml" ).trim() ), convertLineEndings( scrubXmlDeclQuotes( sw.toString() ).trim() ) ); // Test trying to convert to an old version try { modelV3 = convert.convertFromFile_v3_0_0( new File( "src/test/verifiers/converters/expected.xml" ) ); Assert.fail( "Should have failed to convert" ); } catch ( IllegalStateException e ) { Assert.assertTrue( true ); } } private String convertLineEndings( String s ) { return s.replaceAll( "\r\n", "\n" ); } private String scrubXmlDeclQuotes( String s ) { if ( s.startsWith( "")) { return "" + s.substring( "".length() ); } return s; } } modello-1.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/expected.xml0000644000175000017500000000770611127507731032522 0ustar mkochmkoch 4.0.0 artifactId name description http://localhost/foo/ 2006 Users users-subscribe@maven.apache.org users-unsubscribe@maven.apache.org http://mail-archives.apache.org/mod_mbox/maven-users/ PMC root name2 root@localhost http://jroller.com/page/name organization role1 +1 n3 name3 root@localhost http://jroller.com/page/name organization role1 role3 name root@localhost http://jroller.com/page/name organization role1 role2 +10 name2 root@localhost http://jroller.com/page/name organization role1 +1 version2 groupId artifactId version http://localhost/projects/groupId dummy dummy webapps sales 1.0-SNAPSHOT war 2.3 ASL2 http://www.apache.org/license/LICENSE-2.0.txt LGPL optional tag_1 tag_2 title org.apache.maven,org.apache.commons src test com.sun.corba.se.impl.activation.CommandHandler property src/java5 **/tiger/** dir target true **/*.properties **/*.ignoreme Apache http://www.apache.org 8080 localhost modello-1.1/modello-plugins/modello-plugin-converters/src/test/java/0000755000175000017500000000000011260056263024713 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/0000755000175000017500000000000011260056263025502 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/0000755000175000017500000000000011260056263027275 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056263030730 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056263032226 5ustar mkochmkoch././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/converters/modello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/conv0000755000175000017500000000000011260056263033114 5ustar mkochmkoch././@LongLink0000000000000000000000000000020700000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/converters/ConverterGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/conv0000644000175000017500000001041311205236043033110 0ustar mkochmkochpackage org.codehaus.modello.plugin.converters; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; import java.io.Reader; import java.util.Properties; /** * @version $Id: ConverterGeneratorTest.java 1232 2009-05-21 11:33:55Z hboutemy $ */ public class ConverterGeneratorTest extends AbstractModelloJavaGeneratorTest { private static final String MAVEN_MODEL_FILE = "src/test/resources/models/maven.mdo"; public ConverterGeneratorTest() { super( "converters" ); } public void testConverterGenerator() throws Throwable { generateConverterClasses( ReaderFactory.newXmlReader( getTestFile( MAVEN_MODEL_FILE ) ), "3.0.0", "4.0.0" ); generateConverterClasses( getXmlResourceReader( "/features.mdo" ), "1.0.0", "1.1.0" ); addDependency( "stax", "stax-api", "1.0.1" ); addDependency( "net.java.dev.stax-utils", "stax-utils", "20060502" ); addDependency( "org.codehaus.woodstox", "wstx-asl", "3.2.0" ); compile( getOutputDirectory(), getOutputClasses() ); verify( "ConvertersVerifier", "converters" ); } private void generateConverterClasses( Reader modelReader, String fromVersion, String toVersion ) throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.ALL_VERSIONS, fromVersion + "," + toVersion ); Model model = modello.loadModel( modelReader ); generateClasses( parameters, modello, model, fromVersion, toVersion, "java" ); generateClasses( parameters, modello, model, fromVersion, toVersion, "stax-reader" ); generateClasses( parameters, modello, model, fromVersion, toVersion, "stax-writer" ); generateClasses( parameters, modello, model, fromVersion, toVersion, "converters" ); } private void generateClasses( Properties parameters, ModelloCore modello, Model model, String fromVersion, String toVersion, String outputType ) throws ModelloException { parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, toVersion ); modello.generate( model, outputType, parameters ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( true ) ); parameters.setProperty( ModelloParameterConstants.VERSION, fromVersion ); modello.generate( model, outputType, parameters ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( true ) ); parameters.setProperty( ModelloParameterConstants.VERSION, toVersion ); modello.generate( model, outputType, parameters ); } } modello-1.1/modello-plugins/modello-plugin-converters/src/test/resources/0000755000175000017500000000000011260056263026004 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/resources/models/0000755000175000017500000000000011260056263027267 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/test/resources/models/maven.mdo0000644000175000017500000016234511127507731031114 0ustar mkochmkoch maven Maven package org.codehaus.modello.test.maven field modelVersion Model 3.0.0+ extend 3.0.0 String parent 4.0.0 Parent modelVersion pomVersion 3.0.0+ true String id 3.0.0 true String groupId 3.0.0 true String groupId 4.0.0 true String artifactId 3.0.0+ true String type 4.0.0 String jar name 3.0.0+ true String currentVersion 3.0.0 true String version 4.0.0 true String shortDescription 3.0.0 String description 3.0.0+ front page of the project's web site. ]]> String url 3.0.0+ String logo 3.0.0 String issueTrackingUrl 3.0.0 String issueManagement 4.0.0 IssueManagement ciManagement 4.0.0 CiManagement inceptionYear 3.0.0+ true String gumpRepositoryId 3.0.0 String siteAddress 3.0.0 String siteDirectory 3.0.0 String distributionSite 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. distributionDirectory 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. repositories 4.0.0 Repository * pluginRepositories 4.0.0 Repository * This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own. mailingLists 3.0.0+ MailingList * developers 3.0.0+ developer element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> Developer * contributors 3.0.0+ contributor element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. ]]> Contributor * dependencies 3.0.0+ dependency element, which is then described by additional elements (described below). ]]> Dependency * These should ultimately only be compile time dependencies when transitive dependencies come into play. overrides 4.0.0 override element, which is then described by additional elements (described below). ]]> Override * licenses 3.0.0+ license element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. ]]> License * versions 3.0.0 Version * branches 3.0.0+ Branch * packageGroups 3.0.0+ PackageGroup * reports 3.0.0 maven site. All of the reports will be included in the navigation bar for browsing in the order they are specified. ]]> String * scm 4.0.0 Scm repository 3.0.0 Repository This element needs to be renamed as it conflicts with the existing notion of repositories in Maven. build 3.0.0+ true Build organization 3.0.0+ Organization distributionManagement 4.0.0 DistributionManagement local 4.0.0 false Local properties 3.0.0+ Properties String * preGoals 4.0.0 PreGoal * postGoals 4.0.0 PostGoal * 3.0.0 public void setVersion(String version) { this.currentVersion = version; } public String getVersion() { return currentVersion; } 3.0.0+ private String packageName; public void setPackage(String packageName) { this.packageName = packageName; } public String getPackage() { return packageName; } 4.0.0 public String getId() { StringBuffer id = new StringBuffer(); id.append( getGroupId() ); id.append( ":" ); id.append( getArtifactId() ); id.append( ":" ); id.append( getType() ); id.append( ":" ); id.append( getVersion() ); return id.toString(); } Branch 3.0.0+ tag element ]]> tag 3.0.0+ true String description 4.0.0 String lastMergeTag 4.0.0 String Build 3.0.0+ nagEmailAddress 3.0.0 maven:gump-descriptor target. ]]> String This should be moved out of the build section. Vestigal for use with Gump. sourceDirectory 3.0.0+ true String unitTestSourceDirectory 3.0.0+ true String aspectSourceDirectory 3.0.0 Aspectj goals document). The path given is relative to the project descriptor. ]]> String integrationUnitTestSourceDirectory 3.0.0 String sourceModifications 3.0.0+ true sourceModification element, which is then described by additional elements (described below). These modifications are used to exclude or include various source depending on the environment the build is running in. ]]> SourceModification * unitTest 3.0.0 true new UnitTest() UnitTest resources 3.0.0+ below). These resources are used to complete the jar file or to run unit test. ]]> Resource * directory 4.0.0 String output 4.0.0 String finalName 4.0.0 String testOutput 4.0.0 String CiManagement 4.0.0 system 4.0.0 String url 4.0.0 String nagEmailAddress 4.0.0 String Contributor 3.0.0+ name 3.0.0+ String email 3.0.0+ String url 3.0.0+ String organization 3.0.0+ String roles 3.0.0+ role element, the body of which is a role name. ]]> String * timezone 3.0.0+ String Dependency 3.0.0+ id 3.0.0 true String groupId 3.0.0+ true geronimo. ]]> String artifactId 3.0.0+ true germonimo-jms ]]> String version 3.0.0+ true 3.2.1 ]]> String url 3.0.0+ String The URL should really be gleaned from a shared database of dependency information. jar 3.0.0 String artifact 4.0.0+ String type 3.0.0+ ejb and plugin. ]]> String jar properties 3.0.0 mark dependencies with properties. For example the war plugin looks for a war.bundle property, and if found will include the dependency in WEB-INF/lib. For example syntax, check the war plugin docs. ]]> Properties String * 3.0.0+ public String toString() { return groupId + "/" + type + "s:" + artifactId + "-" + version; } 4.0.0 public String getId() { return groupId + ":" + artifactId + ":" + type + ":" + version; } 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } return getArtifactId() + "-" + getVersion() + "." + getExtension(); } public String getExtension() { if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof Dependency ) ) { return false; } Dependency d = (Dependency) o; return getId().equals( d.getId() ); } public int hashCode() { return getId().hashCode(); } ]]> Override 4.0.0 groupId 4.0.0 true geronimo. ]]> String artifactId 4.0.0 true germonimo-jms ]]> String type 4.0.0 ejb and plugin. ]]> String jar version 4.0.0 true 3.2.1 ]]> String file 4.0.0 true lib/non-distributable-code-1.3.jar ]]> String Contributor Developer 3.0.0+ id 3.0.0+ String IssueManagement 4.0.0 system 4.0.0 String url 4.0.0 String DistributionManagement 4.0.0 repository 4.0.0 Repository site 4.0.0 Site License 3.0.0+ name 3.0.0+ String url 3.0.0+ String distribution 3.0.0
repo
may be downloaded from the Maven repository
manual
user must manually download and install the dependency.
]]>
String
comments 3.0.0+ String
MailingList 3.0.0+ mailingList element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> name 3.0.0+ String subscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String unsubscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String post 4.0.0 mailto: link will automatically be created when the documentation is created. ]]> String archive 3.0.0+ String This should probably be removed from 4.0.0 before alpha-1 archives 4.0.0 String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization 3.0.0+ name 3.0.0+ String url 3.0.0+ String logo 3.0.0 /images/org-logo.png) or an absolute URL (e.g., http://my.corp/logo.png). This value is used when generating the project documentation. ]]> String PackageGroup 3.0.0+ title 3.0.0+ String packages 3.0.0+ String PatternSet 3.0.0+ includes 3.0.0+ String * excludes 3.0.0+ String * 3.0.0+ public java.util.List getDefaultExcludes() { java.util.List defaultExcludes = new java.util.ArrayList(); defaultExcludes.add( "**/*~" ); defaultExcludes.add( "**/#*#" ); defaultExcludes.add( "**/.#*" ); defaultExcludes.add( "**/%*%" ); defaultExcludes.add( "**/._*" ); // CVS defaultExcludes.add( "**/CVS" ); defaultExcludes.add( "**/CVS/**" ); defaultExcludes.add( "**/.cvsignore" ); // SCCS defaultExcludes.add( "**/SCCS" ); defaultExcludes.add( "**/SCCS/**" ); // Visual SourceSafe defaultExcludes.add( "**/vssver.scc" ); // Subversion defaultExcludes.add( "**/.svn" ); defaultExcludes.add( "**/.svn/**" ); // Mac defaultExcludes.add( "**/.DS_Store" ); return defaultExcludes; } Parent 4.0.0 artifactId 4.0.0 String groupId 4.0.0 String version 4.0.0 on of the project to extend.]]> String Repository 3.0.0 connection 3.0.0 building versions from specific ID. ]]> String developerConnection 3.0.0 String url 3.0.0 String Scm 4.0.0 connection 4.0.0 building versions from specific ID. ]]> String developerConnection 4.0.0 String url 4.0.0 String branches 4.0.0 String * Resource 3.0.0+ PatternSet directory 3.0.0+ String targetPath 3.0.0+ org.apache.maven.messages), you must specify this element with this value : org/apache/maven/messages ]]> String filtering 3.0.0+ boolean false SourceModification 3.0.0+ Resource className 3.0.0+ not be loaded, then the includes and excludes specified below will be applied to the contents of the sourceDirectory ]]> String property 3.0.0+ String UnitTest 3.0.0+ PatternSet resources 3.0.0+ Resource * Version 3.0.0 version element ]]> name 3.0.0 1.0, 1.1-alpha1, 1.2-beta, 1.3.2 etc. ]]> String tag 3.0.0 String id 3.0.0 maven:dist builds. ]]> String Repository 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String 4.0.0 public boolean equals( Object obj ) { Repository other = ( Repository ) obj; boolean retValue = false; if ( id != null ) { retValue = id.equals( other.id ); } return retValue; } Site 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String GoalDecorator 4.0.0 name 4.0.0 String attain 4.0.0 String GoalDecorator PreGoal 4.0.0 GoalDecorator PostGoal 4.0.0 Local 4.0.0 repository 4.0.0 String online 4.0.0 boolean true
modello-1.1/modello-plugins/modello-plugin-converters/src/site/0000755000175000017500000000000011260056264023760 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/site/site.xml0000644000175000017500000000022511112331565025441 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-converters/src/site/xdoc/0000755000175000017500000000000011260056264024715 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/site/xdoc/index.xml0000644000175000017500000000461411133732202026543 0ustar mkochmkoch Modello Model Version Converter Plugin Hervé Boutemy

Modello Model Version Converter Plugin generates code to transform a model between two versions.

The source model version to convert from is in modello.version parameter: noted A.B.C.

The target model version is the greatest of modello.all.versions parameter: noted X.Y.Z.

converters generator creates my.model.package.vA_B_C.converter.VersionConverter interface and a BasicVersionConverter class implementing the interface to convert a class model from version A.B.C to X.Y.Z. If versions are different, model classes are supposed to be available in their corresponding java packages with version. If versions are equals, model classes are supposed to be available in the java package both with and without version, the package with version being the source model and the package without version being the target.

For every class in the source model, a method is generated in the interface and an automatic implementation generated in the class with following signature:

  • public my.model.package[.vX_Y_Z].ModelClass convertModelClass( my.model.package.vA_B_C.ModelClass )

In addition, if source and target versions are equals, a my.model.package.converter.ConverterTool is generated to automate reading a file, detect its model version (using StAX reader delegate generated code), and convert it to the target model version in the java package without version using generated BasicVersionConverter class:

  • public my.model.package.RootClass convertFromFile( File f )
        throws IOException, XMLStreamException
modello-1.1/modello-plugins/modello-plugin-converters/src/main/0000755000175000017500000000000011260056264023740 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/0000755000175000017500000000000011260056263024660 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/0000755000175000017500000000000011260056264025450 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/0000755000175000017500000000000011260056264027243 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056264030676 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056264032174 5ustar mkochmkoch././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converters/modello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/conv0000755000175000017500000000000011260056264033062 5ustar mkochmkoch././@LongLink0000000000000000000000000000020300000000000011560 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converters/ConverterGenerator.javamodello-1.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/conv0000644000175000017500000004774511243356043033104 0ustar mkochmkochpackage org.codehaus.modello.plugin.converters; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.model.VersionDefinition; import org.codehaus.modello.plugin.java.AbstractJavaModelloGenerator; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JInterface; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JMethodSignature; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JType; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; import org.codehaus.plexus.util.IOUtil; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * Generate a basic conversion class between two versions of a model. */ public class ConverterGenerator extends AbstractJavaModelloGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); String[] versions = parameters.getProperty( ModelloParameterConstants.ALL_VERSIONS ).split( "," ); List allVersions = new ArrayList( versions.length ); for ( int i = 0; i < versions.length; i++ ) { allVersions.add( new Version( versions[i] ) ); } Collections.sort( allVersions ); Version nextVersion = null; for ( Iterator i = allVersions.iterator(); i.hasNext() && nextVersion == null; ) { Version v = (Version) i.next(); if ( v.greaterThan( getGeneratedVersion() ) ) { nextVersion = v; } } try { // if nextVersion remains null, there is none greater so we are converting back to the unpackaged version generateConverters( nextVersion ); if ( nextVersion == null ) { generateConverterTool( allVersions ); } } catch ( IOException ex ) { throw new ModelloException( "Exception while generating model converters.", ex ); } } private void generateConverters( Version toVersion ) throws ModelloException, IOException { Model objectModel = getModel(); Version fromVersion = getGeneratedVersion(); String packageName = objectModel.getDefaultPackageName( true, fromVersion ) + ".convert"; Version effectiveToVersion = ( toVersion == null ) ? fromVersion : toVersion; String jDoc = "Converts from version " + fromVersion + " (with version in package name) to version " + effectiveToVersion + " (with" + ( toVersion != null ? "" : "out" ) + " version in package name) of the model."; JInterface conversionInterface = new JInterface( packageName + ".VersionConverter" ); initHeader( conversionInterface ); suppressAllWarnings( objectModel, conversionInterface ); conversionInterface.getJDocComment().setComment( jDoc ); JClass basicConverterClass = new JClass( packageName + ".BasicVersionConverter" ); initHeader( basicConverterClass ); suppressAllWarnings( objectModel, basicConverterClass ); basicConverterClass.getJDocComment().setComment( jDoc ); basicConverterClass.addInterface( conversionInterface ); VersionDefinition versionDefinition = objectModel.getVersionDefinition(); for ( Iterator i = objectModel.getClasses( fromVersion ).iterator(); i.hasNext(); ) { ModelClass modelClass = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip generation of those classes that are not enabled for the java plugin. continue; } // check if it's present in the next version if ( toVersion != null && !toVersion.inside( modelClass.getVersionRange() ) ) { // Don't convert - it's not there in the next one continue; } String methodName = "convert" + modelClass.getName(); String parameterName = uncapitalise( modelClass.getName() ); String sourceClass = getSourceClassName( modelClass, fromVersion ); String targetClass = modelClass.getPackageName( toVersion != null, toVersion ) + "." + modelClass.getName(); if ( !javaClassMetadata.isAbstract() ) { // Don't generate converter for abstract classes. JMethodSignature methodSig = new JMethodSignature( methodName, new JType( targetClass ) ); methodSig.addParameter( new JParameter( new JType( sourceClass ), parameterName ) ); conversionInterface.addMethod( methodSig ); // Method from interface, delegates to converter with the given implementation of the target class JMethod jMethod = new JMethod( methodName, new JType( targetClass ), null ); jMethod.addParameter( new JParameter( new JType( sourceClass ), parameterName ) ); basicConverterClass.addMethod( jMethod ); JSourceCode sc = jMethod.getSourceCode(); sc.add( "return " + methodName + "( " + parameterName + ", new " + targetClass + "() );" ); } // Actual conversion method, takes implementation as a parameter to facilitate being called as a superclass JMethod jMethod = new JMethod( methodName, new JType( targetClass ), null ); jMethod.addParameter( new JParameter( new JType( sourceClass ), parameterName ) ); jMethod.addParameter( new JParameter( new JType( targetClass ), "value" ) ); basicConverterClass.addMethod( jMethod ); JSourceCode sc = jMethod.getSourceCode(); sc.add( "if ( " + parameterName + " == null )" ); sc.add( "{" ); sc.indent(); sc.add( "return null;" ); sc.unindent(); sc.add( "}" ); if ( modelClass.getSuperClass() != null ) { sc.add( "// Convert super class" ); sc.add( "value = (" + targetClass + ") convert" + modelClass.getSuperClass() + "( " + parameterName + ", value );" ); sc.add( "" ); } for ( Iterator j = modelClass.getFields( fromVersion ).iterator(); j.hasNext(); ) { ModelField modelField = (ModelField) j.next(); String name = capitalise( modelField.getName() ); if ( toVersion != null ) { if ( versionDefinition != null && "field".equals( versionDefinition.getType() ) ) { if ( versionDefinition.getValue().equals( modelField.getName() ) || versionDefinition.getValue().equals( modelField.getAlias() ) ) { sc.add( "value.set" + name + "( \"" + toVersion + "\" );" ); continue; } } } // check if it's present in the next version if ( toVersion != null && !toVersion.inside( modelField.getVersionRange() ) ) { // check if it is present in a new definition instead ModelField newField = null; try { newField = modelClass.getField( modelField.getName(), toVersion ); } catch ( ModelloRuntimeException e ) { // Don't convert - it's not there in the next one continue; } if ( !newField.getType().equals( modelField.getType() ) ) { // Don't convert - it's a different type in the next one continue; } } if ( modelField instanceof ModelAssociation ) { ModelAssociation assoc = (ModelAssociation) modelField; if ( assoc.isManyMultiplicity() ) { String type = assoc.getType(); if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { sc.add( "{" ); sc.indent(); sc.add( assoc.getType() + " list = " + assoc.getDefaultValue() + ";" ); sc.add( "for ( java.util.Iterator i = " + parameterName + ".get" + name + "().iterator(); i.hasNext(); )" ); sc.add( "{" ); sc.indent(); if ( isClassInModel( assoc.getTo(), modelClass.getModel() ) ) { String className = getSourceClassName( assoc.getToClass(), fromVersion ); sc.add( className + " v = (" + className + ") i.next();" ); } else { sc.add( assoc.getTo() + " v = (" + assoc.getTo() + ") i.next();" ); } if ( isClassInModel( assoc.getTo(), objectModel ) ) { sc.add( "list.add( convert" + assoc.getTo() + "( v ) );" ); } else { sc.add( "list.add( v );" ); } sc.unindent(); sc.add( "}" ); sc.add( "value.set" + name + "( list );" ); sc.unindent(); sc.add( "}" ); } else { sc.add( "{" ); sc.indent(); // Map or Properties sc.add( assoc.getType() + " map = " + assoc.getDefaultValue() + ";" ); sc.add( "for ( java.util.Iterator i = " + parameterName + ".get" + name + "().entrySet().iterator(); i.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "java.util.Map.Entry entry = (java.util.Map.Entry) i.next();" ); if ( isClassInModel( assoc.getTo(), modelClass.getModel() ) ) { String className = getSourceClassName( assoc.getToClass(), fromVersion ); sc.add( className + " v = (" + className + ") entry.getValue();" ); } else { sc.add( assoc.getTo() + " v = (" + assoc.getTo() + ") entry.getValue();" ); } if ( isClassInModel( assoc.getTo(), objectModel ) ) { sc.add( "map.put( entry.getKey(), convert" + assoc.getTo() + "( v ) );" ); } else { sc.add( "map.put( entry.getKey(), v );" ); } sc.unindent(); sc.add( "}" ); sc.add( "value.set" + name + "( map );" ); sc.unindent(); sc.add( "}" ); } } else { sc.add( "value.set" + name + "( convert" + assoc.getTo() + "( " + parameterName + ".get" + name + "() ) );" ); } } else { sc.add( "// Convert field " + modelField.getName() ); JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) modelField.getMetadata( JavaFieldMetadata.ID ); String value = parameterName + "." + getPrefix( javaFieldMetadata ) + name + "()"; sc.add( "value.set" + name + "( " + value + " );" ); } } sc.add( "" ); sc.add( "return value;" ); } JSourceWriter interfaceWriter = null; JSourceWriter classWriter = null; try { interfaceWriter = newJSourceWriter( packageName, conversionInterface.getName( true ) ); classWriter = newJSourceWriter( packageName, basicConverterClass.getName( true ) ); conversionInterface.print( interfaceWriter ); basicConverterClass.print( classWriter ); } finally { IOUtil.close( classWriter ); IOUtil.close( interfaceWriter ); } } private void generateConverterTool( List allVersions ) throws ModelloException, IOException { Model objectModel = getModel(); String root = objectModel.getRoot( getGeneratedVersion() ); ModelClass rootClass = objectModel.getClass( root, getGeneratedVersion() ); String basePackage = objectModel.getDefaultPackageName( false, null ); String packageName = basePackage + ".convert"; String jDoc = "Converts between the available versions of the model."; JClass converterClass = new JClass( packageName + ".ConverterTool" ); initHeader( converterClass ); suppressAllWarnings( objectModel, converterClass ); converterClass.getJDocComment().setComment( jDoc ); converterClass.addImport( "java.io.File" ); converterClass.addImport( "java.io.IOException" ); converterClass.addImport( "javax.xml.stream.*" ); for ( Iterator i = allVersions.iterator(); i.hasNext(); ) { Version v = (Version) i.next(); writeConvertMethod( converterClass, objectModel, basePackage, allVersions, v, rootClass ); } writeConvertMethod( converterClass, objectModel, basePackage, allVersions, null, rootClass ); JSourceWriter classWriter = null; try { classWriter = newJSourceWriter( packageName, converterClass.getName( true ) ); converterClass.print( new JSourceWriter( classWriter ) ); } finally { IOUtil.close( classWriter ); } } private static void writeConvertMethod( JClass converterClass, Model objectModel, String basePackage, List allVersions, Version v, ModelClass rootClass ) { String modelName = objectModel.getName(); String rootClassName = rootClass.getName(); String targetPackage = objectModel.getDefaultPackageName( v != null, v ); String targetClass = targetPackage + "." + rootClassName; String methodName = "convertFromFile"; if ( v != null ) { methodName += "_" + v.toString( "v", "_" ); } JMethod method = new JMethod( methodName, new JType( targetClass ), null ); method.addParameter( new JParameter( new JType( "File" ), "f" ) ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XMLStreamException" ) ); converterClass.addMethod( method ); JSourceCode sc = method.getSourceCode(); sc.add( basePackage + ".io.stax." + modelName + "StaxReaderDelegate reader = new " + basePackage + ".io.stax." + modelName + "StaxReaderDelegate();" ); sc.add( "Object value = reader.read( f );" ); String prefix = ""; for ( Iterator j = allVersions.iterator(); j.hasNext(); ) { Version sourceVersion = (Version) j.next(); String sourcePackage = objectModel.getDefaultPackageName( true, sourceVersion ); String sourceClass = sourcePackage + "." + rootClassName; sc.add( prefix + "if ( value instanceof " + sourceClass + " )" ); sc.add( "{" ); sc.indent(); boolean foundFirst = false; for ( Iterator k = allVersions.iterator(); k.hasNext(); ) { Version targetVersion = (Version) k.next(); if ( !foundFirst ) { if ( targetVersion.equals( sourceVersion ) ) { foundFirst = true; } else { continue; } } if ( targetVersion.equals( v ) ) { break; } // TODO: need to be able to specify converter class implementation String p = objectModel.getDefaultPackageName( true, targetVersion ); String c = p + "." + rootClassName; sc.add( "value = new " + p + ".convert.BasicVersionConverter().convert" + rootClassName + "( (" + c + ") value );" ); } sc.unindent(); sc.add( "}" ); prefix = "else "; if ( sourceVersion.equals( v ) ) { break; } } sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "throw new IllegalStateException( \"Can't find converter for class '\" + value.getClass() + \"'\" );" ); sc.unindent(); sc.add( "}" ); sc.add( "return (" + targetClass + ") value;" ); } private static String getSourceClassName( ModelClass modelClass, Version generatedVersion ) { return modelClass.getPackageName( true, generatedVersion ) + "." + modelClass.getName(); } } modello-1.1/modello-plugins/modello-plugin-converters/src/main/resources/0000755000175000017500000000000011260056264025752 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/main/resources/META-INF/0000755000175000017500000000000011260056264027112 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-converters/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056264030432 5ustar mkochmkoch././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-converters/src/main/resources/META-INF/plexus/components.xmlmodello-1.1/modello-plugins/modello-plugin-converters/src/main/resources/META-INF/plexus/components.0000644000175000017500000000045211127507731032623 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator converters org.codehaus.modello.plugin.converters.ConverterGenerator modello-1.1/modello-plugins/modello-plugin-java/0000755000175000017500000000000011260056267020757 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/pom.xml0000644000175000017500000000366111243557055022304 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-java Modello Java Plugin Modello Java Plugin generates Java POJOs for the model. org.sonatype.plexus plexus-build-api modello-1.1/modello-plugins/modello-plugin-java/src/0000755000175000017500000000000011260056267021546 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/0000755000175000017500000000000011260056266022524 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/0000755000175000017500000000000011260056267024523 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/tmp/0000755000175000017500000000000011260056266025322 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/tmp/TmpVerifier.java0000644000175000017500000000247211127507731030426 0ustar mkochmkoch/* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.verifier.Verifier; import java.util.ArrayList; import java.util.List; import junit.framework.Assert; public class TmpVerifier extends Verifier { public void verify() { } } modello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/packageversion/0000755000175000017500000000000011260056267027524 5ustar mkochmkoch././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/packageversion/PackageVersionVerifier.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/packageversion/PackageVersionVeri0000644000175000017500000001127710231327220033171 0ustar mkochmkoch/* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.apache.maven.model.v4_0_0.MailingList; import org.apache.maven.model.v4_0_0.Model; import org.apache.maven.model.v4_0_0.Scm; import org.codehaus.modello.verifier.Verifier; import java.util.ArrayList; import java.util.List; import junit.framework.Assert; public class PackageVersionVerifier extends Verifier { public void verify() { Model model = new Model(); // The SCM tests one class that has a reference to another class. Scm scm = new Scm(); String connection = "connection"; String developerConnection = "developerConnection"; String url = "url"; try { scm.setConnection( connection ); scm.setDeveloperConnection( developerConnection ); scm.setUrl( url ); } catch( Exception e) { e.printStackTrace(); Assert.fail( e.getMessage() ); } Assert.assertEquals( "Scm.connection", connection, scm.getConnection() ); Assert.assertEquals( "Scm.developerConnection", developerConnection, scm.getDeveloperConnection() ); Assert.assertEquals( "Scm.url", url, scm.getUrl() ); testMailingLists(); } private void testMailingLists() { List expected = new ArrayList(); expected.add( createMailingList( 0 ) ); expected.add( createMailingList( 1 ) ); expected.add( createMailingList( 2 ) ); Model model = new Model(); List lists = model.getMailingLists(); Assert.assertNotNull( lists ); Assert.assertTrue( lists instanceof ArrayList ); try { model.setMailingLists( expected ); } catch( Exception e) { e.printStackTrace(); Assert.fail( e.getMessage() ); } List actual = model.getMailingLists(); Assert.assertEquals( "/model/mailinglists.size", expected.size(), actual.size() ); for( int i = 0; i < expected.size(); i++ ) { assertMailingList( (MailingList) expected.get( i ), (MailingList) actual.get( i ) ); } } public void testModelAddMailingList() { Model model = new Model(); model.addMailingList( createMailingList( 0 ) ); model.addMailingList( createMailingList( 1 ) ); model.addMailingList( createMailingList( 2 ) ); List actual = model.getMailingLists(); Assert.assertEquals( "/model/mailinglists.size", 3, actual.size() ); for( int i = 0; i < 3; i++ ) { assertMailingList( createMailingList( i ), (MailingList) actual.get( i ) ); } } private MailingList createMailingList( int i ) { MailingList mailingList = new MailingList(); try { mailingList.setName( "Mailing list #" + i ); mailingList.setSubscribe( "Subscribe #" + i ); mailingList.setUnsubscribe( "Unsubscribe #" + i ); mailingList.setArchive( "Archive #" + i ); } catch( Exception e) { e.printStackTrace(); Assert.fail( e.getMessage() ); } return mailingList; } private void assertMailingList( MailingList expected, MailingList actual ) { Assert.assertEquals( "Mailing list", expected.getName(), actual.getName() ); Assert.assertEquals( "Subscribe", expected.getSubscribe(), actual.getSubscribe() ); Assert.assertEquals( "Unsubscribe", expected.getUnsubscribe(), actual.getUnsubscribe() ); Assert.assertEquals( "Archive", expected.getArchive(), actual.getArchive() ); } } modello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/java/0000755000175000017500000000000011260056266025443 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/java/JavaVerifier.java0000644000175000017500000001124010231327220030645 0ustar mkochmkoch/* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.apache.maven.model.MailingList; import org.apache.maven.model.Model; import org.apache.maven.model.Scm; import org.codehaus.modello.verifier.Verifier; import java.util.ArrayList; import java.util.List; import junit.framework.Assert; public class JavaVerifier extends Verifier { public void verify() { Model model = new Model(); // The SCM tests one class that has a reference to another class. Scm scm = new Scm(); String connection = "connection"; String developerConnection = "developerConnection"; String url = "url"; try { scm.setConnection( connection ); scm.setDeveloperConnection( developerConnection ); scm.setUrl( url ); } catch( Exception e) { e.printStackTrace(); Assert.fail( e.getMessage() ); } Assert.assertEquals( "Scm.connection", connection, scm.getConnection() ); Assert.assertEquals( "Scm.developerConnection", developerConnection, scm.getDeveloperConnection() ); Assert.assertEquals( "Scm.url", url, scm.getUrl() ); testMailingLists(); } private void testMailingLists() { List expected = new ArrayList(); expected.add( createMailingList( 0 ) ); expected.add( createMailingList( 1 ) ); expected.add( createMailingList( 2 ) ); Model model = new Model(); List lists = model.getMailingLists(); Assert.assertNotNull( lists ); Assert.assertTrue( lists instanceof ArrayList ); try { model.setMailingLists( expected ); } catch( Exception e) { e.printStackTrace(); Assert.fail( e.getMessage() ); } List actual = model.getMailingLists(); Assert.assertEquals( "/model/mailinglists.size", expected.size(), actual.size() ); for( int i = 0; i < expected.size(); i++ ) { assertMailingList( (MailingList) expected.get( i ), (MailingList) actual.get( i ) ); } } public void testModelAddMailingList() { Model model = new Model(); model.addMailingList( createMailingList( 0 ) ); model.addMailingList( createMailingList( 1 ) ); model.addMailingList( createMailingList( 2 ) ); List actual = model.getMailingLists(); Assert.assertEquals( "/model/mailinglists.size", 3, actual.size() ); for( int i = 0; i < 3; i++ ) { assertMailingList( createMailingList( i ), (MailingList) actual.get( i ) ); } } private MailingList createMailingList( int i ) { MailingList mailingList = new MailingList(); try { mailingList.setName( "Mailing list #" + i ); mailingList.setSubscribe( "Subscribe #" + i ); mailingList.setUnsubscribe( "Unsubscribe #" + i ); mailingList.setArchive( "Archive #" + i ); } catch( Exception e) { e.printStackTrace(); Assert.fail( e.getMessage() ); } return mailingList; } private void assertMailingList( MailingList expected, MailingList actual ) { Assert.assertEquals( "Mailing list", expected.getName(), actual.getName() ); Assert.assertEquals( "Subscribe", expected.getSubscribe(), actual.getSubscribe() ); Assert.assertEquals( "Unsubscribe", expected.getUnsubscribe(), actual.getUnsubscribe() ); Assert.assertEquals( "Archive", expected.getArchive(), actual.getArchive() ); } } modello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/features/0000755000175000017500000000000011260056267026341 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/features/JavaVerifier.java0000644000175000017500000005113711224733460031565 0ustar mkochmkoch/* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.OrderedProperties; import org.codehaus.modello.verifier.Verifier; import org.codehaus.modello.verifier.VerifierException; import org.codehaus.modello.test.features.AssociationFeatures; import org.codehaus.modello.test.features.BaseClass; import org.codehaus.modello.test.features.Bidirectional; import org.codehaus.modello.test.features.BidiInList; import org.codehaus.modello.test.features.BidiInSet; import org.codehaus.modello.test.features.InterfacesFeature; import org.codehaus.modello.test.features.JavaAbstractFeature; import org.codehaus.modello.test.features.JavaFeatures; import org.codehaus.modello.test.features.Reference; import org.codehaus.modello.test.features.SimpleInterface; import org.codehaus.modello.test.features.SimpleTypes; import org.codehaus.modello.test.features.SubClassLevel1; import org.codehaus.modello.test.features.SubClassLevel2; import org.codehaus.modello.test.features.SubClassLevel3; import org.codehaus.modello.test.features.SubInterface; import org.codehaus.modello.test.features.Thing; import org.codehaus.modello.test.features.Thingy; import org.codehaus.modello.test.features.XmlAttributes; import org.codehaus.modello.test.features.XmlFeatures; import org.codehaus.modello.test.features.other.SubInterfaceInPackage; import org.codehaus.plexus.util.xml.Xpp3Dom; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import junit.framework.Assert; /** * @author Herve Boutemy * @version $Id: JavaVerifier.java 1280 2009-07-07 20:59:28Z hboutemy $ */ public class JavaVerifier extends Verifier { public void verify() { try { verifySimpleTypes(); verifyXmlAttributes(); verifyJavaFeatures(); } catch ( NoSuchFieldException nsfe ) { throw new VerifierException( "field not found", nsfe ); } catch ( NoSuchMethodException nsme ) { throw new VerifierException( "method not found", nsme ); } verifyDefaultValues(); verifyInterfaces(); verifyMisc(); verifyClone(); } /** * Check that a field has been propertly declared with public accessors. * * @param clazz the class that should contain the field * @param attributeName the field's attribute name * @param type the field expected type * @param getterName the expected getter method name * @param setterName the expected setter method name * @throws NoSuchFieldException * @throws NoSuchMethodException */ private void checkField( Class clazz, String attributeName, Class type, String getterName, String setterName ) throws NoSuchFieldException, NoSuchMethodException { checkField( clazz, attributeName, type, getterName, setterName, type /* by default, accessors use same type as corresponding field */ ); } /** * Check that a field has been propertly declared with public accessors. * * @param clazz the class that should contain the field * @param attributeName the field's attribute name * @param type the field expected type * @param getterName the expected getter method name * @param setterName the expected setter method name * @param getterAndSetterType the type expected in getter and setter methods * @throws NoSuchFieldException * @throws NoSuchMethodException */ private void checkField( Class clazz, String attributeName, Class type, String getterName, String setterName, Class getterAndSetterType) throws NoSuchFieldException, NoSuchMethodException { Field field = clazz.getDeclaredField( attributeName ); Assert.assertEquals( attributeName + " attribute type", type, field.getType() ); Assert.assertTrue( attributeName + " attribute should be private", Modifier.isPrivate( field.getModifiers() ) ); Method getter = clazz.getMethod( getterName, (Class[]) null ); Assert.assertNotNull( getterName + "() method", getter ); Assert.assertEquals( getterName + "() method return type", getterAndSetterType, getter.getReturnType() ); Assert.assertTrue( getterName + "() method should be public", Modifier.isPublic( getter.getModifiers() ) ); Method setter = clazz.getMethod( setterName, new Class[] { getterAndSetterType } ); Assert.assertNotNull( setterName + "( " + type.getName() + " ) method", setter ); Assert.assertTrue( setterName + "( " + type.getName() + " ) method should be public", Modifier.isPublic( setter.getModifiers() ) ); } /** * Check fields declaration common to SimpleTypes and XmlAttributes classes. * * @param clazz the actuel class to check * @throws NoSuchFieldException * @throws NoSuchMethodException */ private void checkCommonFields( Class clazz ) throws NoSuchFieldException, NoSuchMethodException { checkField( clazz, "primitiveBoolean", Boolean.TYPE , "isPrimitiveBoolean", "setPrimitiveBoolean" ); checkField( clazz, "primitiveByte" , Byte.TYPE , "getPrimitiveByte" , "setPrimitiveByte" ); checkField( clazz, "primitiveChar" , Character.TYPE, "getPrimitiveChar" , "setPrimitiveChar" ); checkField( clazz, "primitiveShort" , Short.TYPE , "getPrimitiveShort" , "setPrimitiveShort" ); checkField( clazz, "primitiveInt" , Integer.TYPE , "getPrimitiveInt" , "setPrimitiveInt" ); checkField( clazz, "primitiveLong" , Long.TYPE , "getPrimitiveLong" , "setPrimitiveLong" ); checkField( clazz, "primitiveFloat" , Float.TYPE , "getPrimitiveFloat" , "setPrimitiveFloat" ); checkField( clazz, "primitiveDouble" , Double.TYPE , "getPrimitiveDouble", "setPrimitiveDouble" ); checkField( clazz, "objectBoolean" , Boolean.class , "isObjectBoolean" , "setObjectBoolean" ); checkField( clazz, "objectString" , String.class , "getObjectString" , "setObjectString" ); checkField( clazz, "objectDate" , Date.class , "getObjectDate" , "setObjectDate" ); } /** * Verify SimpleTypes generated class. * * @throws NoSuchFieldException * @throws NoSuchMethodException */ public void verifySimpleTypes() throws NoSuchFieldException, NoSuchMethodException { checkCommonFields( SimpleTypes.class ); } /** * Verify XmlAttributes generated class. * * @throws NoSuchFieldException * @throws NoSuchMethodException */ public void verifyXmlAttributes() throws NoSuchFieldException, NoSuchMethodException { checkCommonFields( XmlAttributes.class ); } /** * Verify default values. */ public void verifyDefaultValues() { SimpleTypes simple = new SimpleTypes(); Assert.assertEquals( "primitiveBoolean", true , simple.isPrimitiveBoolean() ); Assert.assertEquals( "primitiveByte" , 12 , simple.getPrimitiveByte() ); Assert.assertEquals( "primitiveChar" , 'H' , simple.getPrimitiveChar() ); Assert.assertEquals( "primitiveShort" , (short) 1212 , simple.getPrimitiveShort() ); Assert.assertEquals( "primitiveInt" , 121212 , simple.getPrimitiveInt() ); Assert.assertEquals( "primitiveLong" , 12121212 , simple.getPrimitiveLong() ); Assert.assertEquals( "primitiveFloat" , 12.12f , simple.getPrimitiveFloat(), 0f ); Assert.assertEquals( "primitiveDouble" , 12.12 , simple.getPrimitiveDouble(), 0 ); Assert.assertEquals( "objectBoolean" , Boolean.FALSE , simple.isObjectBoolean() ); Assert.assertEquals( "objectString" , "default value", simple.getObjectString() ); XmlAttributes xmlAttributes = new XmlAttributes(); Assert.assertEquals( "primitiveBoolean", true , xmlAttributes.isPrimitiveBoolean() ); Assert.assertEquals( "primitiveByte" , 12 , xmlAttributes.getPrimitiveByte() ); Assert.assertEquals( "primitiveChar" , 'H' , xmlAttributes.getPrimitiveChar() ); Assert.assertEquals( "primitiveShort" , (short) 1212 , xmlAttributes.getPrimitiveShort() ); Assert.assertEquals( "primitiveInt" , 121212 , xmlAttributes.getPrimitiveInt() ); Assert.assertEquals( "primitiveLong" , 12121212 , xmlAttributes.getPrimitiveLong() ); Assert.assertEquals( "primitiveFloat" , 12.12f , xmlAttributes.getPrimitiveFloat(), 0f ); Assert.assertEquals( "primitiveDouble" , 12.12 , xmlAttributes.getPrimitiveDouble(), 0 ); Assert.assertEquals( "objectBoolean" , Boolean.FALSE , xmlAttributes.isObjectBoolean() ); Assert.assertEquals( "objectString" , "default value", xmlAttributes.getObjectString() ); } public void verifyJavaFeatures() throws NoSuchFieldException, NoSuchMethodException { // java.abstract feature if ( !Modifier.isAbstract( JavaAbstractFeature.class.getModifiers() ) ) { throw new VerifierException( "JavaAbstractFeature should be abstract" ); } // interfaces feature if ( !java.io.Serializable.class.isAssignableFrom( InterfacesFeature.class ) ) { throw new VerifierException( "InterfacesFeature should implement java.io.Serializable" ); } if ( !java.rmi.Remote.class.isAssignableFrom( InterfacesFeature.class ) ) { throw new VerifierException( "InterfacesFeature should implement java.rmi.Remote" ); } if ( !SubInterface.class.isAssignableFrom( InterfacesFeature.class ) ) { throw new VerifierException( "InterfacesFeature should implement SubInterface" ); } if ( !SubInterfaceInPackage.class.isAssignableFrom( InterfacesFeature.class ) ) { throw new VerifierException( "InterfacesFeature should implement SubInterfaceInPackage" ); } // superClass feature if ( !BaseClass.class.isAssignableFrom( SubClassLevel1.class ) ) { throw new VerifierException( "SubClassLevel1 should extend BaseClass" ); } if ( !SubClassLevel1.class.isAssignableFrom( SubClassLevel2.class ) ) { throw new VerifierException( "SubClassLevel2 should extend SubClassLevel1" ); } if ( !SubClassLevel2.class.isAssignableFrom( SubClassLevel3.class ) ) { throw new VerifierException( "SubClassLevel3 should extend SubClassLevel2" ); } // methods for collections AssociationFeatures association = new AssociationFeatures(); // add/remove for List association.setListReferences( new ArrayList() ); List list = association.getListReferences(); association.addListReference( new Reference() ); association.removeListReference( new Reference() ); // add/remove for Set association.setSetReferences( new HashSet() ); Set set = association.getSetReferences(); association.addSetReference( new Reference() ); association.removeSetReference( new Reference() ); // java.adder=false JavaFeatures java = new JavaFeatures(); java.setJavaListNoAdd( new ArrayList() ); list = java.getJavaListNoAdd(); checkNoMethod( JavaFeatures.class, "addJavaListNoAdd", Reference.class ); checkNoMethod( JavaFeatures.class, "removeJavaListNoAdd", Reference.class ); java.setJavaSetNoAdd( new HashSet() ); set = java.getJavaSetNoAdd(); checkNoMethod( JavaFeatures.class, "addJavaSetNoAdd", Reference.class ); checkNoMethod( JavaFeatures.class, "removeJavaSetNoAdd", Reference.class ); // bidi Bidirectional bidi = new Bidirectional(); association.setBidi( bidi ); Assert.assertEquals( "setting bidi in association should set the reverse association", association, bidi.getParent() ); bidi.setParent( null ); Assert.assertNull( "setting parent to null in bidi should remove value in association", association.getBidi() ); BidiInList bidiInList = new BidiInList(); association.addListOfBidi( bidiInList ); Assert.assertEquals( "setting bidi in many association should set the reverse association", association, bidiInList.getParent() ); bidiInList.setParent( null ); Assert.assertEquals( 0, association.getListOfBidis().size() ); bidiInList.setParent( association ); Assert.assertEquals( bidiInList, association.getListOfBidis().get( 0 ) ); association.removeListOfBidi( bidiInList ); Assert.assertEquals( 0, association.getListOfBidis().size() ); BidiInSet bidiInSet = new BidiInSet(); association.addSetOfBidi( bidiInSet ); Assert.assertEquals( "setting bidi in many association should set the reverse association", association, bidiInSet.getParent() ); bidiInSet.setParent( null ); Assert.assertEquals( 0, association.getSetOfBidis().size() ); bidiInSet.setParent( association ); Assert.assertEquals( bidiInSet, association.getSetOfBidis().iterator().next() ); association.removeSetOfBidi( bidiInSet ); Assert.assertEquals( 0, association.getSetOfBidis().size() ); // java.useInterface checkField( JavaFeatures.class, "useInterface", SubClassLevel1.class, "getUseInterface", "setUseInterface", BaseClass.class); } /** * Check that a method doesn't exist. * * @param clazz the class to check * @param method the method name that shouldn't exist * @param attribute the method attribute type */ private void checkNoMethod( Class clazz, String method, Class attribute ) { try { clazz.getMethod( method, new Class[] { attribute } ); throw new VerifierException( clazz.getName() + " should not contain " + method + "( " + attribute.getName() + " ) method." ); } catch ( NoSuchMethodException nsme ) { // ok, that's expected } } public void verifyInterfaces() { Assert.assertTrue( "SimpleInterface should be an interface", SimpleInterface.class.isInterface() ); Assert.assertTrue( "SubInterface should be an interface", SubInterface.class.isInterface() ); Assert.assertTrue( "SubInterfaceInPackage should be an interface", SubInterfaceInPackage.class.isInterface() ); // superInterface feature if ( !SimpleInterface.class.isAssignableFrom( SubInterface.class ) ) { throw new VerifierException( "SubInterface should extend SimpleInterface" ); } if ( !SimpleInterface.class.isAssignableFrom( SubInterfaceInPackage.class ) ) { throw new VerifierException( "SubInterfaceInPackage should extend SimpleInterface" ); } // codeSegments Assert.assertNotNull( "SimpleInterface.CODE_SEGMENT should be here", SimpleInterface.CODE_SEGMENT ); } /** * Verify misc aspects of the generated classes. */ public void verifyMisc() { // java.util.Propertiesnew org.codehaus.modello.OrderedProperties() if (! ( new XmlFeatures().getExplodeProperties() instanceof OrderedProperties ) ) { throw new VerifierException( "java.util.Properties model default value was ignored" ); } } /** * Verify generated clone() methods. */ public void verifyClone() { checkCloneNullSafe(); checkClone(); } private void checkCloneNullSafe() { Thing orig = new Thing(); Thing copy = (Thing) orig.clone(); assertNotNull( copy ); assertNotSame( orig, copy ); } private void checkClone() { Thing orig = new Thing(); orig.setSomeBoolean( true ); orig.setSomeChar( 'X' ); orig.setSomeByte( (byte) 7 ); orig.setSomeShort( (short) 11 ); orig.setSomeInt( 13 ); orig.setSomeLong( 17 ); orig.setSomeFloat( -2.5f ); orig.setSomeDouble( 3.14 ); orig.setSomeString( "test" ); orig.setSomeDate( new Date() ); orig.setSomeDom( new Xpp3Dom( "test" ) ); orig.addSomeStringList( "string" ); orig.addSomeStringSet( "string" ); orig.setDeepThingy( new Thingy() ); orig.addDeepThingyList( new Thingy() ); orig.addDeepThingySet( new Thingy() ); orig.setShallowThingy( new Thingy() ); orig.addShallowThingyList( new Thingy() ); orig.addShallowThingySet( new Thingy() ); orig.addSomeProperty( "key", "value" ); orig.customProperties.setProperty( "key", "value" ); Thing copy = (Thing) orig.clone(); assertNotNull( copy ); assertNotSame( orig, copy ); assertEquals( orig.isSomeBoolean(), copy.isSomeBoolean() ); assertEquals( orig.getSomeChar(), copy.getSomeChar() ); assertEquals( orig.getSomeByte(), copy.getSomeByte() ); assertEquals( orig.getSomeShort(), copy.getSomeShort() ); assertEquals( orig.getSomeInt(), copy.getSomeInt() ); assertEquals( orig.getSomeLong(), copy.getSomeLong() ); assertEquals( orig.getSomeFloat(), copy.getSomeFloat(), 0.1 ); assertEquals( orig.getSomeDouble(), copy.getSomeDouble(), 0.1 ); assertEquals( orig.getSomeString(), copy.getSomeString() ); assertEquals( orig.getSomeDate(), copy.getSomeDate() ); assertNotSame( orig.getSomeDate(), copy.getSomeDate() ); assertEquals( orig.getSomeDom(), copy.getSomeDom() ); assertNotSame( orig.getSomeDom(), copy.getSomeDom() ); assertEquals( orig.getSomeStringList(), copy.getSomeStringList() ); assertNotSame( orig.getSomeStringList(), copy.getSomeStringList() ); assertEquals( orig.getSomeStringSet(), copy.getSomeStringSet() ); assertNotSame( orig.getSomeStringSet(), copy.getSomeStringSet() ); assertNotSame( orig.getDeepThingy(), copy.getDeepThingy() ); assertNotSame( orig.getDeepThingyList(), copy.getDeepThingyList() ); assertNotSame( orig.getDeepThingyList().iterator().next(), copy.getDeepThingyList().iterator().next() ); assertNotSame( orig.getDeepThingySet(), copy.getDeepThingySet() ); assertNotSame( orig.getDeepThingySet().iterator().next(), copy.getDeepThingySet().iterator().next() ); assertSame( orig.getShallowThingy(), copy.getShallowThingy() ); assertNotSame( orig.getShallowThingyList(), copy.getShallowThingyList() ); assertSame( orig.getShallowThingyList().iterator().next(), copy.getShallowThingyList().iterator().next() ); assertNotSame( orig.getShallowThingySet(), copy.getShallowThingySet() ); assertSame( orig.getShallowThingySet().iterator().next(), copy.getShallowThingySet().iterator().next() ); assertEquals( orig.customProperties, copy.customProperties ); assertNotSame( orig.customProperties, copy.customProperties ); Thingy orig2 = new Thingy(); orig2.setSomeContent( "content" ); Thingy copy2 = (Thingy) orig2.clone(); assertNotNull( copy2 ); assertNotSame( orig2, copy2 ); assertEquals( "content", copy2.getSomeContent() ); } } modello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/0000755000175000017500000000000011260056266030023 5ustar mkochmkoch././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/JavaVerifier.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/JavaVerifier.jav0000644000175000017500000000335511214007427033102 0ustar mkochmkoch/* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.verifier.Verifier; import org.codehaus.modello.verifier.VerifierException; import junit.framework.Assert; /** * @author Herve Boutemy * @version $Id: JavaVerifier.java 1243 2009-06-10 19:52:55Z olamy $ */ public class JavaVerifier extends Verifier { public void verify() { Object v1_0_0 = new org.codehaus.modello.test.features.v1_0_0.Features(); Object v1_5_0 = new org.codehaus.modello.test.features.v1_5_0.Features(); Object v2_0_0 = new org.codehaus.modello.test.features.v2_0_0.Features(); Object v3_0_0 = new org.codehaus.modello.test.features.v3_0_0.Features(); } } modello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/bidirectional/0000755000175000017500000000000011260056267027333 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/bidirectional/JavaVerifier.java0000644000175000017500000000170311127507731032553 0ustar mkochmkochimport org.codehaus.modello.plugin.java.Role; import org.codehaus.modello.tests.bidiroverride.BiRole; import org.codehaus.modello.verifier.Verifier; import junit.framework.Assert; import java.util.List; public class JavaVerifier extends Verifier { public void verify() { Role parent = new BiRole(); parent.setName( "parent" ); Role child = new BiRole(); child.setName( "child" ); parent.addRole( child ); Assert.assertEquals( 1, parent.getRoles().size() ); List roles = parent.getRoles(); Assert.assertTrue( "Collection element should be of type BiRole.", (roles.get(0) instanceof BiRole) ); parent.removeRole( child ); Assert.assertEquals( 0, parent.getRoles().size() ); BiRole birole = (BiRole) parent; birole.setPrincipal( 22 ); Assert.assertEquals( 22, birole.getPrincipal() ); } } modello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/oneToManyAssociation/0000755000175000017500000000000011260056267030631 5ustar mkochmkoch././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/oneToManyAssociation/OneToManyAssociationVerifier.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/verifiers/oneToManyAssociation/OneToManyAss0000644000175000017500000001030210253010375033057 0ustar mkochmkochimport org.codehaus.modello.association.package1.ListSetMapProperties; import org.codehaus.modello.association.package1.Person; import org.codehaus.modello.association.package2.Location; import org.codehaus.modello.verifier.Verifier; import java.util.ArrayList; import java.util.List; import junit.framework.Assert; public class OneToManyAssociationVerifier extends Verifier { public void verify() { // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- Person person = new Person(); Location location = new Location(); location.getPersons().add( person ); Assert.assertNotNull( "Location.persons == null", location.getPersons() ); Assert.assertEquals( "Location.persons.length != 1", 1, location.getPersons().size() ); Assert.assertEquals( "Location.persons[0]", person, location.getPersons().get( 0 ) ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- person = new Person(); location = new Location(); person.setLocation( location ); Assert.assertNotNull( "Location.persons == null", location.getPersons() ); Assert.assertEquals( "Location.persons.length != 1", 1, location.getPersons().size() ); Assert.assertEquals( "Location.persons[0]", person, location.getPersons().get( 0 ) ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- testList(); testMap(); testProperty(); testSet(); } private void testList() { ListSetMapProperties foo = new ListSetMapProperties(); Person person1 = new Person(); Person person2 = new Person(); foo.addList( person1 ); List list = foo.getList(); Assert.assertEquals( "list.size", 1, list.size() ); Assert.assertEquals( "list[0]", person1, list.get( 0 ) ); foo.removeList( person1 ); Assert.assertEquals( "list.size", 0, list.size() ); list = new ArrayList(); list.add( person1 ); list.add( person2 ); foo.setList( list ); Assert.assertEquals( "list.size", 2, list.size() ); Assert.assertEquals( "list[0]", person1, list.get( 0 ) ); Assert.assertEquals( "list[1]", person2, list.get( 1 ) ); } private void testMap() { ListSetMapProperties foo = new ListSetMapProperties(); Integer i1 = new Integer( 1 ); Integer i2 = new Integer( 2 ); Person person1 = new Person(); Person person2 = new Person(); foo.addMap( i1, person1 ); Assert.assertEquals( "map.size", 1, foo.getMap().size() ); foo.addMap( i1, person1 ); Assert.assertEquals( "map.size", 1, foo.getMap().size() ); foo.addMap( i2, person2 ); Assert.assertEquals( "map.size", 2, foo.getMap().size() ); } private void testProperty() { ListSetMapProperties foo = new ListSetMapProperties(); String i1 = "1"; String i2 = "2"; Person person1 = new Person(); Person person2 = new Person(); foo.addProperty( i1, person1 ); Assert.assertEquals( "properties.size", 1, foo.getProperties().size() ); foo.addProperty( i1, person1 ); Assert.assertEquals( "properties.size", 1, foo.getProperties().size() ); foo.addProperty( i2, person2 ); Assert.assertEquals( "properties.size", 2, foo.getProperties().size() ); } private void testSet() { ListSetMapProperties foo = new ListSetMapProperties(); Person person1 = new Person(); Person person2 = new Person(); foo.addSet( person1 ); Assert.assertEquals( "set.size", 1, foo.getSet().size() ); foo.addSet( person1 ); Assert.assertEquals( "set.size", 1, foo.getSet().size() ); foo.addSet( person2 ); Assert.assertEquals( "set.size", 2, foo.getSet().size() ); } } modello-1.1/modello-plugins/modello-plugin-java/src/test/java/0000755000175000017500000000000011260056266023445 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/0000755000175000017500000000000011260056266024234 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/0000755000175000017500000000000011260056266026027 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056266027462 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056266030760 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/0000755000175000017500000000000011260056266031701 5ustar mkochmkoch././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Permission.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Permi0000644000175000017500000000203311127507731032676 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright 2001-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Test Interface used by {@link JavaGeneratorTest#testBiDirectionalJavaGenerator()} to ensure that * interface overrides can be used. * * @author Joakim Erdfelt * @version $Id: Permission.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public interface Permission { public String getName(); public void setName( String name ); } ././@LongLink0000000000000000000000000000020500000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/FeaturesVersionJavaGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Featu0000644000175000017500000000531311176576243032702 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesVersionJavaGeneratorTest.java 1225 2009-05-01 13:44:03Z hboutemy $ */ public class FeaturesVersionJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesVersionJavaGeneratorTest() { super( "features-version" ); } private static final String ALL_VERSIONS = "1.0.0,1.5.0,2.0.0,3.0.0"; public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.ALL_VERSIONS, ALL_VERSIONS ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( true ) ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); String[] versions = ALL_VERSIONS.split( "," ); for ( int i = 0; i < versions.length; i++ ) { parameters.setProperty( ModelloParameterConstants.VERSION, versions[i] ); modello.generate( model, "java", parameters ); } compile( getOutputDirectory(), getOutputClasses() ); verify( "JavaVerifier", "java" ); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/TmpJavaGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/TmpJa0000644000175000017500000000514011132202454032625 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; import java.util.Properties; /** * @author Vincent Siveton * @version $Id: TmpJavaGeneratorTest.java 1125 2009-01-10 20:29:32Z hboutemy $ */ public class TmpJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { private String modelFile = "src/test/resources/models/tmp.mdo"; public TmpJavaGeneratorTest() { super( "tmp" ); } /** * MODELLO-83 * @throws Throwable */ public void testJavaGeneratorWithTmp() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( modelFile ) ) ); modello.generate( model, "java", parameters ); compile( getOutputDirectory(), getOutputClasses() ); verify( "TmpVerifier", "java" ); } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasource/modello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javas0000755000175000017500000000000011260056266032726 5ustar mkochmkoch././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasource/JavaSourceTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000001330711232155760032732 0ustar mkochmkochpackage org.codehaus.modello.plugin.java.javasource; import java.io.File; import org.codehaus.modello.AbstractModelloGeneratorTest; public class JavaSourceTest extends AbstractModelloGeneratorTest { public JavaSourceTest() { super( "javasource" ); } public void testJavaSource() { checkJClass(); checkJCompUnit(); checkJInterface(); } private void checkJClass() { JClass testClass = new JClass( "org.acme.JClassTest" ); testClass.addSourceCode( "// source code" ); testClass.addSourceCode( "// source code 2" ); testClass.addImport( "java.util.Vector" ); testClass.appendAnnotation( "@SuppressWarnings( \"all\" )" ); testClass.appendAnnotation( "@Deprecated" ); testClass.addMember( new JField( JType.INT, "x" ) ); JClass jcString = new JClass( "String" ); JField field = null; field = new JField( JType.INT, "_z" ); field.appendAnnotation( "@Deprecated" ); field.getModifiers().setStatic( true ); testClass.addField( field ); testClass.getStaticInitializationCode().add( "_z = 75;" ); field = new JField( jcString, "myString" ); field.getModifiers().makePrivate(); testClass.addMember( field ); // generics test JType type = new JCollectionType( "java.util.List", jcString, true ); field = new JField( type, "generics" ); testClass.addMember( field ); type = new JCollectionType( "java.util.List", jcString, false ); field = new JField( type, "noGenerics" ); testClass.addMember( field ); //-- create constructor JConstructor cons = testClass.createConstructor(); cons.appendAnnotation( "@Deprecated" ); cons.getSourceCode().add( "this.x = 6;" ); JMethod jMethod = new JMethod( "getX", JType.INT, null ); jMethod.appendAnnotation( "@Deprecated" ); jMethod.setSourceCode( "return this.x;" ); testClass.addMethod( jMethod ); jMethod = new JMethod( "setX", null, null ); JParameter param = new JParameter( JType.INT, "x" ); jMethod.addParameter( param ); jMethod.setSourceCode( "this.x = x;" ); testClass.addMethod( jMethod ); jMethod = new JMethod( "checkParameterAnotation", JType.INT, null ); param = new JParameter( JType.LONG, "param" ); param.appendAnnotation( "@Test" ); param.appendAnnotation( "@Test2" ); jMethod.addParameter( param ); jMethod.setSourceCode( "return param;" ); testClass.addMethod( jMethod ); //-- create inner-class JClass innerClass = testClass.createInnerClass( "Foo" ); innerClass.appendAnnotation( "@Deprecated" ); innerClass.addImport( "java.util.Hashtable" ); innerClass.addMember( new JField( JType.INT, "_type" ) ); field = new JField( jcString, "_name" ); field.getModifiers().makePrivate(); innerClass.addMember( field ); testClass.createInnerClass( "Bar" ); //-- create constructor cons = innerClass.createConstructor(); cons.getSourceCode().add( "_name = \"foo\";" ); jMethod = new JMethod( "getName", jcString, null ); jMethod.setSourceCode( "return _name;" ); innerClass.addMethod( jMethod ); testClass.print( getOutputDirectory().toString(), null ); assertTrue( new File( getOutputDirectory(), "org/acme/JClassTest.java" ).exists() ); } private void checkJCompUnit() { JCompUnit unit = new JCompUnit( "com.acme", "JCompUnitTest.java" ); JClass testClass = new JClass( "Test" ); testClass.addImport( "java.util.Vector" ); testClass.addMember( new JField( JType.INT, "x" ) ); JField field = null; field = new JField( JType.INT, "_z" ); field.getModifiers().setStatic( true ); testClass.addField( field ); testClass.getStaticInitializationCode().add( "_z = 75;" ); JClass jcString = new JClass( "String" ); field = new JField( jcString, "myString" ); field.getModifiers().makePrivate(); testClass.addMember( field ); // -- create constructor JConstructor cons = testClass.createConstructor(); testClass.addConstructor( cons ); cons.getSourceCode().add( "this.x = 6;" ); JMethod jMethod = new JMethod( "getX", JType.INT, null ); jMethod.setSourceCode( "return this.x;" ); testClass.addMethod( jMethod ); unit.addClass( testClass ); JClass fooClass = new JClass( "Foo" ); unit.addClass( fooClass ); unit.print( getOutputDirectory().toString(), null ); assertTrue( new File( getOutputDirectory(), "com/acme/JCompUnitTest.java" ).exists() ); } private void checkJInterface() { JInterface jInterface = new JInterface( "InterfaceTest" ); // -- add an import jInterface.addImport( "java.util.Vector" ); JClass jString = new JClass( "String" ); // -- add an interface jInterface.addInterface( "java.io.Serializable" ); // -- add a static field JField jField = new JField( new JClass( "java.lang.String" ), "TEST" ); jField.setInitString( "\"Test\"" ); jField.getModifiers().setStatic( true ); jField.getModifiers().makePublic(); jInterface.addField( jField ); // -- add a method signature JMethodSignature jMethodSig = new JMethodSignature( "getName", jString ); jInterface.addMethod( jMethodSig ); jInterface.print( getOutputDirectory().toString(), null ); assertTrue( new File( getOutputDirectory(), "InterfaceTest.java" ).exists() ); } } ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/FeaturesJavaGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Featu0000644000175000017500000000460011176576243032700 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesJavaGeneratorTest.java 1225 2009-05-01 13:44:03Z hboutemy $ */ public class FeaturesJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesJavaGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "2.0.0" ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "java", parameters ); compile( getOutputDirectory(), getOutputClasses() ); verify( "JavaVerifier", "java" ); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/PackageVersionJavaTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Packa0000644000175000017500000000512411132202454032633 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Jason van Zyl * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: PackageVersionJavaTest.java 1125 2009-01-10 20:29:32Z hboutemy $ */ public class PackageVersionJavaTest extends AbstractModelloJavaGeneratorTest { private String modelFile = "src/test/resources/models/maven.mdo"; public PackageVersionJavaTest() { super( "packageversion" ); } public void testThatTheCorrectVersionIsInThePackageName() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( true ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( modelFile ) ) ); modello.generate( model, "java", parameters ); compile( getOutputDirectory(), getOutputClasses() ); verify( "PackageVersionVerifier", "java" ); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/AssociationGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Assoc0000644000175000017500000000513311132202454032664 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: AssociationGeneratorTest.java 1125 2009-01-10 20:29:32Z hboutemy $ */ public class AssociationGeneratorTest extends AbstractModelloJavaGeneratorTest { private String modelFile = "src/test/resources/models/oneToManyAssociation.mdo"; public AssociationGeneratorTest() { super( "oneToManyAssociation" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( modelFile ) ) ); modello.generate( model, "java", parameters ); compile( getOutputDirectory(), getOutputClasses() ); verify( "OneToManyAssociationVerifier", "java" ); } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/JavaGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/JavaG0000644000175000017500000000502711132202454032606 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: JavaGeneratorTest.java 1125 2009-01-10 20:29:32Z hboutemy $ */ public class JavaGeneratorTest extends AbstractModelloJavaGeneratorTest { private String modelFile = "src/test/resources/models/maven.mdo"; public JavaGeneratorTest() { super( "java" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( modelFile ) ) ); modello.generate( model, "java", parameters ); compile( getOutputDirectory(), getOutputClasses() ); verify( "JavaVerifier", "java" ); } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/FeaturesJava5GeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Featu0000644000175000017500000000546511221402126032665 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Benjamin Bentmann * @version $Id: FeaturesJava5GeneratorTest.java 1252 2009-06-27 11:36:54Z bentmann $ */ public class FeaturesJava5GeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesJava5GeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { String javaVersion = System.getProperty( "java.specification.version", "1.5" ); if ( "1.5".compareTo( javaVersion ) > 0 ) { System.out.println( "Skipped Java 5 feature test, not supported by current test environment (" + javaVersion + ")" ); return; } ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "2.0.0" ); parameters.setProperty( ModelloParameterConstants.USE_JAVA5, Boolean.toString( true ) ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "java", parameters ); compile( getOutputDirectory(), getOutputClasses(), true ); verify( "JavaVerifier", "java" ); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Role.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Role.0000644000175000017500000000246111127507731032606 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright 2001-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; /** * Test Interface used by {@link JavaGeneratorTest#testBiDirectionalJavaGenerator()} to ensure that * interface overrides can be used. * * @author Joakim Erdfelt * @version $Id: Role.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public interface Role { public String getName(); public void setName(String name); public void setRoles(List roles); public List getRoles(); public void addRole(Role role); public void removeRole(Role role); public void setPermission(Permission permission); public Permission getPermission(); } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/AbstractPrincipal.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Abstr0000644000175000017500000000115111127507731032675 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /** * Test Abstract Class used by {@link JavaGeneratorTest#testBiDirectionalJavaGenerator()} to ensure that * externally referenced classes can be used in the <superClass> element. * * @author Joakim Erdfelt * @version $Id: AbstractPrincipal.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public abstract class AbstractPrincipal { private int principal; public int getPrincipal() { return principal; } public void setPrincipal( int principal ) { this.principal = principal; } } ././@LongLink0000000000000000000000000000021300000000000011561 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/BiDirectionalOverrideJavaGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/BiDir0000644000175000017500000000425111132202454032605 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright 2001-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; import java.util.Properties; /** * BiDirectionalOverrideJavaGeneratorTest * * @author Joakim Erdfelt * @version $Id: BiDirectionalOverrideJavaGeneratorTest.java 1125 2009-01-10 20:29:32Z hboutemy $ */ public class BiDirectionalOverrideJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { private String modelFile = "src/test/resources/models/bidirectional-override.mdo"; public BiDirectionalOverrideJavaGeneratorTest() { super( "bidirectional" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( modelFile ) ) ); modello.generate( model, "java", parameters ); compile( getOutputDirectory(), getOutputClasses() ); verify( "JavaVerifier", getName() ); } } modello-1.1/modello-plugins/modello-plugin-java/src/test/resources/0000755000175000017500000000000011260056266024536 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/test/resources/models/0000755000175000017500000000000011260056266026021 5ustar mkochmkoch././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/test/resources/models/bidirectional-override.mdomodello-1.1/modello-plugins/modello-plugin-java/src/test/resources/models/bidirectional-override.mdo0000644000175000017500000000542611127507731033156 0ustar mkochmkoch bidirectional-override BiDirModel 1.0.0 package org.codehaus.modello.tests.bidiroverride BiRole 1.0.0 org.codehaus.modello.plugin.java.Role org.codehaus.modello.plugin.java.AbstractPrincipal name 1.0.0 String roles 1.0.0 BiRole * Child Roles permission 1.0.0 BiPermission 1 BiPermission 1.0.0 org.codehaus.modello.plugin.java.Permission name 1.0.0 String operations 1.0.0 String * tasks 1.0.0 String * resources 1.0.0 String * statusIndicators 1.0.0 Map String * modello-1.1/modello-plugins/modello-plugin-java/src/test/resources/models/maven.mdo0000644000175000017500000016172111122565013027630 0ustar mkochmkoch maven Maven package org.apache.maven.model Model 3.0.0+ extend 3.0.0+ String parent 4.0.0 Parent modelVersion 4.0.0 true String pomVersion 3.0.0 true String id 3.0.0 true String groupId 3.0.0+ true String artifactId 3.0.0+ true String type 4.0.0 String jar name 3.0.0+ true String currentVersion 3.0.0 true String version 4.0.0 true String shortDescription 3.0.0+ String description 3.0.0+ front page of the project's web site. ]]> String url 3.0.0+ String logo 3.0.0+ String issueTrackingUrl 3.0.0 String issueManagement 4.0.0 IssueManagement ciManagement 4.0.0 CiManagement inceptionYear 3.0.0+ true String gumpRepositoryId 3.0.0 String siteAddress 3.0.0 String siteDirectory 3.0.0 String distributionSite 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. distributionDirectory 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. repositories 4.0.0 Repository * pluginRepositories 4.0.0 Repository * This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own. mailingLists 3.0.0+ MailingList * developers 3.0.0+ developer element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> Developer * contributors 3.0.0+ contributor element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. ]]> Contributor * dependencies 3.0.0+ dependency element, which is then described by additional elements (described below). ]]> Dependency * These should ultimately only be compile time dependencies when transitive dependencies come into play. overrides 4.0.0 override element, which is then described by additional elements (described below). ]]> Override * licenses 3.0.0+ license element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. ]]> License * versions 3.0.0 Version * branches 3.0.0 Branch * packageGroups 3.0.0+ PackageGroup * reports 3.0.0+ maven site. All of the reports will be included in the navigation bar for browsing in the order they are specified. ]]> String * scm 4.0.0 Scm repository 3.0.0 Repository This element needs to be renamed as it conflicts with the existing notion of repositories in Maven. build 3.0.0+ true Build organization 3.0.0+ Organization distributionManagement 4.0.0 DistributionManagement local 4.0.0 false Local properties 3.0.0+ Properties String * preGoals 4.0.0 PreGoal * postGoals 4.0.0 PostGoal * 3.0.0 public void setVersion(String version) { this.currentVersion = version; } public String getVersion() { return currentVersion; } 3.0.0+ private String packageName; public void setPackage(String packageName) { this.packageName = packageName; } public String getPackage() { return packageName; } 4.0.0 public String getId() { StringBuffer id = new StringBuffer(); id.append( getGroupId() ); id.append( ":" ); id.append( getArtifactId() ); id.append( ":" ); id.append( getType() ); id.append( ":" ); id.append( getVersion() ); return id.toString(); } Branch 3.0.0+ tag element ]]> tag 3.0.0+ true String description 4.0.0 String lastMergeTag 4.0.0 String Build 3.0.0+ nagEmailAddress 3.0.0 maven:gump-descriptor target. ]]> String This should be moved out of the build section. Vestigal for use with Gump. sourceDirectory 3.0.0+ true String unitTestSourceDirectory 3.0.0+ true String aspectSourceDirectory 3.0.0+ Aspectj goals document). The path given is relative to the project descriptor. ]]> String integrationUnitTestSourceDirectory 3.0.0+ String sourceModifications 3.0.0+ true sourceModification element, which is then described by additional elements (described below). These modifications are used to exclude or include various source depending on the environment the build is running in. ]]> SourceModification * unitTest 3.0.0+ true new UnitTest() UnitTest resources 3.0.0+ below). These resources are used to complete the jar file or to run unit test. ]]> Resource * directory 4.0.0 String output 4.0.0 String finalName 4.0.0 String testOutput 4.0.0 String CiManagement 4.0.0 system 4.0.0 String url 4.0.0 String nagEmailAddress 4.0.0 String Contributor 3.0.0+ name 3.0.0+ String email 3.0.0+ String url 3.0.0+ String organization 3.0.0+ String roles 3.0.0+ role element, the body of which is a role name. ]]> String * timezone 3.0.0+ String Dependency 3.0.0+ id 3.0.0 true String groupId 3.0.0+ true geronimo. ]]> String artifactId 3.0.0+ true germonimo-jms ]]> String version 3.0.0+ true 3.2.1 ]]> String url 3.0.0+ String The URL should really be gleaned from a shared database of dependency information. jar 3.0.0 String artifact 4.0.0+ String type 3.0.0+ ejb and plugin. ]]> String jar properties 3.0.0+ mark dependencies with properties. For example the war plugin looks for a war.bundle property, and if found will include the dependency in WEB-INF/lib. For example syntax, check the war plugin docs. ]]> Properties String * 3.0.0+ public String toString() { return groupId + "/" + type + "s:" + artifactId + "-" + version; } 4.0.0 public String getId() { return groupId + ":" + artifactId + ":" + type + ":" + version; } 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } return getArtifactId() + "-" + getVersion() + "." + getExtension(); } public String getExtension() { if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof Dependency ) ) { return false; } Dependency d = (Dependency) o; return getId().equals( d.getId() ); } public int hashCode() { return getId().hashCode(); } ]]> Override 4.0.0 groupId 4.0.0 true geronimo. ]]> String artifactId 4.0.0 true germonimo-jms ]]> String type 4.0.0 ejb and plugin. ]]> String jar version 4.0.0 true 3.2.1 ]]> String file 4.0.0 true lib/non-distributable-code-1.3.jar ]]> String Contributor Developer 3.0.0+ id 3.0.0+ String IssueManagement 4.0.0 system 4.0.0 String url 4.0.0 String DistributionManagement 4.0.0 repository 4.0.0 Repository site 4.0.0 Site License 3.0.0+ name 3.0.0+ String url 3.0.0+ String distribution 3.0.0
repo
may be downloaded from the Maven repository
manual
user must manually download and install the dependency.
]]>
String
comments 3.0.0+ String
MailingList 3.0.0+ mailingList element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> name 3.0.0+ String subscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String unsubscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String post 4.0.0 mailto: link will automatically be created when the documentation is created. ]]> String archive 3.0.0+ String This should probably be removed from 4.0.0 before alpha-1 archives 4.0.0 String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization 3.0.0+ name 3.0.0+ String url 3.0.0+ String logo 3.0.0+ /images/org-logo.png) or an absolute URL (e.g., http://my.corp/logo.png). This value is used when generating the project documentation. ]]> String PackageGroup 3.0.0+ title 3.0.0+ String packages 3.0.0+ String PatternSet 3.0.0+ includes 3.0.0+ String * excludes 3.0.0+ String * 3.0.0+ public java.util.List getDefaultExcludes() { java.util.List defaultExcludes = new java.util.ArrayList(); defaultExcludes.add( "**/*~" ); defaultExcludes.add( "**/#*#" ); defaultExcludes.add( "**/.#*" ); defaultExcludes.add( "**/%*%" ); defaultExcludes.add( "**/._*" ); // CVS defaultExcludes.add( "**/CVS" ); defaultExcludes.add( "**/CVS/**" ); defaultExcludes.add( "**/.cvsignore" ); // SCCS defaultExcludes.add( "**/SCCS" ); defaultExcludes.add( "**/SCCS/**" ); // Visual SourceSafe defaultExcludes.add( "**/vssver.scc" ); // Subversion defaultExcludes.add( "**/.svn" ); defaultExcludes.add( "**/.svn/**" ); // Mac defaultExcludes.add( "**/.DS_Store" ); return defaultExcludes; } Parent 4.0.0 artifactId 4.0.0 String groupId 4.0.0 String version 4.0.0 on of the project to extend.]]> String Repository 3.0.0 connection 3.0.0 building versions from specific ID. ]]> String developerConnection 3.0.0 String url 3.0.0 String Scm 4.0.0 connection 4.0.0 building versions from specific ID. ]]> String developerConnection 4.0.0 String url 4.0.0 String branches 4.0.0 String * Resource 3.0.0+ PatternSet directory 3.0.0+ String targetPath 3.0.0+ org.apache.maven.messages), you must specify this element with this value : org/apache/maven/messages ]]> String filtering 3.0.0+ boolean false SourceModification 3.0.0+ Resource className 3.0.0+ not be loaded, then the includes and excludes specified below will be applied to the contents of the sourceDirectory ]]> String property 3.0.0+ String UnitTest 3.0.0+ PatternSet resources 3.0.0+ Resource * Version 3.0.0 version element ]]> name 3.0.0 1.0, 1.1-alpha1, 1.2-beta, 1.3.2 etc. ]]> String tag 3.0.0 String id 3.0.0 maven:dist builds. ]]> String Repository 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String 4.0.0 public boolean equals( Object obj ) { Repository other = ( Repository ) obj; boolean retValue = false; if ( id != null ) { retValue = id.equals( other.id ); } return retValue; } Site 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String GoalDecorator 4.0.0 name 4.0.0 String attain 4.0.0 String GoalDecorator PreGoal 4.0.0 GoalDecorator PostGoal 4.0.0 Local 4.0.0 repository 4.0.0 String online 4.0.0 boolean true
modello-1.1/modello-plugins/modello-plugin-java/src/test/resources/models/tmp.mdo0000644000175000017500000000130411127507731027320 0ustar mkochmkoch tmp Modello Test Model with tmp package foo.bar MyClass 1.0.0 id 1.0.0 true String true tmp 1.0.0 double true modello-1.1/modello-plugins/modello-plugin-java/src/test/resources/models/oneToManyAssociation.mdo0000644000175000017500000000376311122565060032633 0ustar mkochmkoch association-test AssociationTest package org.codehaus.modello.association.package1 Person location Location Location org.codehaus.modello.association.package2 persons Person * ListSetMapProperties 4.0.0 list 4.0.0 List Person * set 4.0.0 Set Person * map 4.0.0 Map Person * properties 4.0.0 Properties Person * modello-1.1/modello-plugins/modello-plugin-java/src/main/0000755000175000017500000000000011260056267022472 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/0000755000175000017500000000000011260056267023413 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/0000755000175000017500000000000011260056267024202 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/0000755000175000017500000000000011260056267025775 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056267027430 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056267030726 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/0000755000175000017500000000000011260056267031647 5ustar mkochmkoch././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/modello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metad0000755000175000017500000000000011260056267032662 5ustar mkochmkoch././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metad0000644000175000017500000000532611221417324032662 0ustar mkochmkochpackage org.codehaus.modello.plugin.java.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.List; import org.codehaus.modello.metadata.ClassMetadata; /** * @author Emmanuel Venisse * @version $Id: JavaClassMetadata.java 1257 2009-06-27 13:29:56Z bentmann $ */ public class JavaClassMetadata implements ClassMetadata { public static final String ID = JavaClassMetadata.class.getName(); public static final String CLONE_NONE = "none"; public static final String CLONE_SHALLOW = "shallow"; public static final String CLONE_DEEP = "deep"; public final static List CLONE_MODES; static { CLONE_MODES = new ArrayList(); CLONE_MODES.add( CLONE_NONE ); CLONE_MODES.add( CLONE_SHALLOW ); CLONE_MODES.add( CLONE_DEEP ); } private boolean abstractMode; private boolean enabled; private String cloneMode; private String cloneHook; public void setAbstract( boolean abstractMode ) { this.abstractMode = abstractMode; } public boolean isAbstract() { return abstractMode; } public boolean isEnabled() { return enabled; } public void setEnabled( boolean generate ) { this.enabled = generate; } public String getCloneMode() { return cloneMode; } public void setCloneMode( String cloneMode ) { this.cloneMode = cloneMode; } public String getCloneHook() { return cloneHook; } public void setCloneHook( String cloneHook ) { this.cloneHook = cloneHook; } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaFieldMetadata.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metad0000644000175000017500000000412411136702120032651 0ustar mkochmkochpackage org.codehaus.modello.plugin.java.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.FieldMetadata; /** * @author Emmanuel Venisse * @version $Id: JavaFieldMetadata.java 1155 2009-01-24 21:12:48Z hboutemy $ */ public class JavaFieldMetadata implements FieldMetadata { public static final String ID = JavaFieldMetadata.class.getName(); private boolean getter = true; private boolean booleanGetter = false; private boolean setter = true; public boolean isGetter() { return getter; } public void setGetter( boolean getter ) { this.getter = getter; } public boolean isBooleanGetter() { return booleanGetter; } public void setBooleanGetter( boolean booleanGetter ) { this.booleanGetter = booleanGetter; } public boolean isSetter() { return setter; } public void setSetter( boolean setter ) { this.setter = setter; } }././@LongLink0000000000000000000000000000020500000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metad0000644000175000017500000000663111221417324032662 0ustar mkochmkochpackage org.codehaus.modello.plugin.java.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AssociationMetadata; import java.util.ArrayList; import java.util.List; /** * @author Emmanuel Venisse * @version $Id: JavaAssociationMetadata.java 1257 2009-06-27 13:29:56Z bentmann $ */ public class JavaAssociationMetadata implements AssociationMetadata { public static final String ID = JavaAssociationMetadata.class.getName(); public static final String LAZY_INIT = "lazy"; public static final String CONSTRUCTOR_INIT = "constructor"; public static final String FIELD_INIT = "field"; public final static List INIT_TYPES; static { INIT_TYPES = new ArrayList(); INIT_TYPES.add( LAZY_INIT ); INIT_TYPES.add( CONSTRUCTOR_INIT ); INIT_TYPES.add( FIELD_INIT ); } public static final String CLONE_SHALLOW = "shallow"; public static final String CLONE_DEEP = "deep"; public final static List CLONE_MODES; static { CLONE_MODES = new ArrayList(); CLONE_MODES.add( CLONE_SHALLOW ); CLONE_MODES.add( CLONE_DEEP ); } private boolean adder = true; private boolean bidi; private String interfaceName; private String initializationMode; private String cloneMode; public boolean isAdder() { return adder; } public void setAdder( boolean adder ) { this.adder = adder; } public boolean isBidi() { return bidi; } public void setBidi( boolean bidi ) { this.bidi = bidi; } public String getInterfaceName() { return interfaceName; } public void setInterfaceName( String interfaceName ) { this.interfaceName = interfaceName; } public String getInitializationMode() { return initializationMode; } public void setInitializationMode( String initializationMode ) { if ( initializationMode == null ) { this.initializationMode = LAZY_INIT; } else { this.initializationMode = initializationMode; } } public String getCloneMode() { return cloneMode; } public void setCloneMode( String cloneMode ) { this.cloneMode = cloneMode; } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaModelMetadata.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metad0000644000175000017500000000340311243356043032660 0ustar mkochmkochpackage org.codehaus.modello.plugin.java.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.ModelMetadata; /** * @author Emmanuel Venisse * @version $Id: JavaModelMetadata.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public class JavaModelMetadata implements ModelMetadata { public static final String ID = JavaModelMetadata.class.getName(); private boolean suppressAllWarnings = true; public void setSuppressAllWarnings( boolean suppressAllWarnings ) { this.suppressAllWarnings = suppressAllWarnings; } public boolean isSuppressAllWarnings() { return suppressAllWarnings; } } ././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaMetadataPlugin.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metad0000644000175000017500000001075711243356043032672 0ustar mkochmkochpackage org.codehaus.modello.plugin.java.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AbstractMetadataPlugin; import org.codehaus.modello.metadata.AssociationMetadata; import org.codehaus.modello.metadata.ClassMetadata; import org.codehaus.modello.metadata.FieldMetadata; import org.codehaus.modello.metadata.MetadataPlugin; import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import java.util.Map; /** * @author Emmanuel Venisse * @version $Id: JavaMetadataPlugin.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public class JavaMetadataPlugin extends AbstractMetadataPlugin implements MetadataPlugin { public static final String JAVA_ABSTRACT = "java.abstract"; public static final String JAVA_ADDER = "java.adder"; public static final String JAVA_BIDI = "java.bidi"; public static final String JAVA_ENABLED = "java.enabled"; public static final String JAVA_GETTER = "java.getter"; public static final String JAVA_INIT = "java.init"; public static final String JAVA_SETTER = "java.setter"; public static final String JAVA_USE_INTERFACE = "java.useInterface"; public static final String JAVA_CLONE = "java.clone"; public static final String JAVA_CLONE_HOOK = "java.clone.hook"; public static final String JAVA_SUPPRESS_ALL_WARNINGS = "java.suppressAllWarnings"; // ---------------------------------------------------------------------- // Map to Metadata // ---------------------------------------------------------------------- public ModelMetadata getModelMetadata( Model model, Map data ) { JavaModelMetadata metadata = new JavaModelMetadata(); metadata.setSuppressAllWarnings( getBoolean( data, JAVA_SUPPRESS_ALL_WARNINGS, true ) ); return metadata; } public ClassMetadata getClassMetadata( ModelClass clazz, Map data ) { JavaClassMetadata metadata = new JavaClassMetadata(); metadata.setEnabled( getBoolean( data, JAVA_ENABLED, true ) ); metadata.setAbstract( getBoolean( data, JAVA_ABSTRACT, false ) ); metadata.setCloneMode( getString( data, JAVA_CLONE ) ); metadata.setCloneHook( getString( data, JAVA_CLONE_HOOK ) ); return metadata; } public FieldMetadata getFieldMetadata( ModelField field, Map data ) { JavaFieldMetadata metadata = new JavaFieldMetadata(); metadata.setGetter( getBoolean( data, JAVA_GETTER, true ) ); String fieldType = field.getType(); metadata.setBooleanGetter( ( fieldType != null ) && fieldType.endsWith( "oolean" ) ); metadata.setSetter( getBoolean( data, JAVA_SETTER, true ) ); return metadata; } public AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) { JavaAssociationMetadata metadata = new JavaAssociationMetadata(); metadata.setAdder( getBoolean( data, JAVA_ADDER, true ) ); metadata.setBidi( getBoolean( data, JAVA_BIDI, true ) ); metadata.setInterfaceName( getString( data, JAVA_USE_INTERFACE ) ); metadata.setInitializationMode( getString( data, JAVA_INIT ) ); metadata.setCloneMode( getString( data, JAVA_CLONE ) ); return metadata; } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaM0000644000175000017500000013772211243356043032600 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.model.CodeSegment; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.ModelInterface; import org.codehaus.modello.plugin.java.javasource.JArrayType; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JCollectionType; import org.codehaus.modello.plugin.java.javasource.JConstructor; import org.codehaus.modello.plugin.java.javasource.JField; import org.codehaus.modello.plugin.java.javasource.JInterface; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JType; import org.codehaus.modello.plugin.java.metadata.JavaAssociationMetadata; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; import org.codehaus.modello.plugin.java.metadata.JavaModelMetadata; import org.codehaus.modello.plugin.model.ModelClassMetadata; import org.codehaus.plexus.util.StringUtils; import java.io.IOException; import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * @author Jason van Zyl * @version $Id: JavaModelloGenerator.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public class JavaModelloGenerator extends AbstractJavaModelloGenerator { private Collection immutableTypes = new HashSet( Arrays.asList( new String[] { "boolean", "Boolean", "byte", "Byte", "char", "Character", "short", "Short", "int", "Integer", "long", "Long", "float", "Float", "double", "Double", "String" } ) ); public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateJava(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating Java.", ex ); } } private void generateJava() throws ModelloException, IOException { Model objectModel = getModel(); // ---------------------------------------------------------------------- // Generate the interfaces. // ---------------------------------------------------------------------- for ( Iterator i = objectModel.getInterfaces( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelInterface modelInterface = (ModelInterface) i.next(); String packageName = modelInterface.getPackageName( isPackageWithVersion(), getGeneratedVersion() ); JSourceWriter sourceWriter = newJSourceWriter( packageName, modelInterface.getName() ); JInterface jInterface = new JInterface( packageName + '.' + modelInterface.getName() ); initHeader( jInterface ); suppressAllWarnings( objectModel, jInterface ); if ( modelInterface.getSuperInterface() != null ) { // check if we need an import: if it is a generated superInterface in another package try { ModelInterface superInterface = objectModel.getInterface( modelInterface.getSuperInterface(), getGeneratedVersion() ); String superPackageName = superInterface.getPackageName( isPackageWithVersion(), getGeneratedVersion() ); if ( ! packageName.equals( superPackageName ) ) { jInterface.addImport( superPackageName + '.' + superInterface.getName() ); } } catch ( ModelloRuntimeException mre ) { // no problem if the interface does not exist in the model, it can be in the jdk } jInterface.addInterface( modelInterface.getSuperInterface() ); } if ( modelInterface.getCodeSegments( getGeneratedVersion() ) != null ) { for ( Iterator iterator = modelInterface.getCodeSegments( getGeneratedVersion() ).iterator(); iterator.hasNext(); ) { CodeSegment codeSegment = (CodeSegment) iterator.next(); jInterface.addSourceCode( codeSegment.getCode() ); } } jInterface.print( sourceWriter ); sourceWriter.close(); } // ---------------------------------------------------------------------- // Generate the classes. // ---------------------------------------------------------------------- for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass modelClass = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip generation of those classes that are not enabled for the java plugin. continue; } String packageName = modelClass.getPackageName( isPackageWithVersion(), getGeneratedVersion() ); JSourceWriter sourceWriter = newJSourceWriter( packageName, modelClass.getName() ); JClass jClass = new JClass( packageName + '.' + modelClass.getName() ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); if ( StringUtils.isNotEmpty( modelClass.getDescription() ) ) { jClass.getJDocComment().setComment( appendPeriod( modelClass.getDescription() ) ); } addModelImports( jClass, modelClass ); jClass.getModifiers().setAbstract( javaClassMetadata.isAbstract() ); if ( modelClass.getSuperClass() != null ) { jClass.setSuperClass( modelClass.getSuperClass() ); } for ( Iterator j = modelClass.getInterfaces().iterator(); j.hasNext(); ) { String implementedInterface = (String) j.next(); jClass.addInterface( implementedInterface ); } jClass.addInterface( Serializable.class.getName() ); JSourceCode jConstructorSource = new JSourceCode(); for ( Iterator j = modelClass.getFields( getGeneratedVersion() ).iterator(); j.hasNext(); ) { ModelField modelField = (ModelField) j.next(); if ( modelField instanceof ModelAssociation ) { createAssociation( jClass, (ModelAssociation) modelField, jConstructorSource ); } else { createField( jClass, modelField ); } } if ( !jConstructorSource.isEmpty() ) { // Ironic that we are doing lazy init huh? JConstructor jConstructor = jClass.createConstructor(); jConstructor.setSourceCode( jConstructorSource ); jClass.addConstructor( jConstructor ); } // ---------------------------------------------------------------------- // equals() / hashCode() / toString() // ---------------------------------------------------------------------- List identifierFields = modelClass.getIdentifierFields( getGeneratedVersion() ); if ( identifierFields.size() != 0 ) { JMethod equals = generateEquals( modelClass ); jClass.addMethod( equals ); JMethod hashCode = generateHashCode( modelClass ); jClass.addMethod( hashCode ); JMethod toString = generateToString( modelClass ); jClass.addMethod( toString ); } JMethod[] cloneMethods = generateClone( modelClass ); if ( cloneMethods.length > 0 ) { jClass.addInterface( Cloneable.class.getName() ); jClass.addMethods( cloneMethods ); } if ( modelClass.getCodeSegments( getGeneratedVersion() ) != null ) { for ( Iterator iterator = modelClass.getCodeSegments( getGeneratedVersion() ).iterator(); iterator.hasNext(); ) { CodeSegment codeSegment = (CodeSegment) iterator.next(); jClass.addSourceCode( codeSegment.getCode() ); } } ModelClassMetadata metadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); if ( ( metadata != null ) && metadata.isRootElement() ) { ModelField modelEncoding = new ModelField( modelClass, "modelEncoding" ); modelEncoding.setType( "String" ); modelEncoding.setDefaultValue( "UTF-8" ); modelEncoding.addMetadata( new JavaFieldMetadata() ); createField( jClass, modelEncoding ); } jClass.print( sourceWriter ); sourceWriter.close(); } } private JMethod generateEquals( ModelClass modelClass ) { JMethod equals = new JMethod( "equals", JType.BOOLEAN, null ); equals.addParameter( new JParameter( new JClass( "Object" ), "other" ) ); JSourceCode sc = equals.getSourceCode(); sc.add( "if ( this == other )" ); sc.add( "{" ); sc.addIndented( "return true;" ); sc.add( "}" ); sc.add( "" ); sc.add( "if ( !( other instanceof " + modelClass.getName() + " ) )" ); sc.add( "{" ); sc.addIndented( "return false;" ); sc.add( "}" ); sc.add( "" ); sc.add( modelClass.getName() + " that = (" + modelClass.getName() + ") other;" ); sc.add( "boolean result = true;" ); sc.add( "" ); for ( Iterator j = modelClass.getIdentifierFields( getGeneratedVersion() ).iterator(); j.hasNext(); ) { ModelField identifier = (ModelField) j.next(); String name = identifier.getName(); if ( "boolean".equals( identifier.getType() ) || "byte".equals( identifier.getType() ) || "char".equals( identifier.getType() ) || "double".equals( identifier.getType() ) || "float".equals( identifier.getType() ) || "int".equals( identifier.getType() ) || "short".equals( identifier.getType() ) || "long".equals( identifier.getType() ) ) { sc.add( "result = result && " + name + " == that." + name + ";" ); } else { name = "get" + capitalise( name ) + "()"; sc.add( "result = result && ( " + name + " == null ? that." + name + " == null : " + name + ".equals( that." + name + " ) );" ); } } if ( modelClass.getSuperClass() != null ) { sc.add( "result = result && ( super.equals( other ) );" ); } sc.add( "" ); sc.add( "return result;" ); return equals; } private JMethod generateToString( ModelClass modelClass ) { JMethod toString = new JMethod( "toString", new JType( String.class.getName() ), null ); List identifierFields = modelClass.getIdentifierFields( getGeneratedVersion() ); JSourceCode sc = toString.getSourceCode(); if ( identifierFields.size() == 0 ) { sc.add( "return super.toString();" ); return toString; } if ( useJava5 ) { sc.add( "StringBuilder buf = new StringBuilder( 128 );" ); } else { sc.add( "StringBuffer buf = new StringBuffer( 128 );" ); } sc.add( "" ); for ( Iterator j = identifierFields.iterator(); j.hasNext(); ) { ModelField identifier = (ModelField) j.next(); String getter = "boolean".equals( identifier.getType() ) ? "is" : "get"; sc.add( "buf.append( \"" + identifier.getName() + " = '\" );" ); sc.add( "buf.append( " + getter + capitalise( identifier.getName() ) + "() );" ); sc.add( "buf.append( \"'\" );" ); if ( j.hasNext() ) { sc.add( "buf.append( \"\\n\" ); " ); } } if ( modelClass.getSuperClass() != null ) { sc.add( "buf.append( \"\\n\" );" ); sc.add( "buf.append( super.toString() );" ); } sc.add( "" ); sc.add( "return buf.toString();" ); return toString; } private JMethod generateHashCode( ModelClass modelClass ) { JMethod hashCode = new JMethod( "hashCode", JType.INT, null ); List identifierFields = modelClass.getIdentifierFields( getGeneratedVersion() ); JSourceCode sc = hashCode.getSourceCode(); if ( identifierFields.size() == 0 ) { sc.add( "return super.hashCode();" ); return hashCode; } sc.add( "int result = 17;" ); sc.add( "" ); for ( Iterator j = identifierFields.iterator(); j.hasNext(); ) { ModelField identifier = (ModelField) j.next(); sc.add( "result = 37 * result + " + createHashCodeForField( identifier ) + ";" ); } if ( modelClass.getSuperClass() != null ) { sc.add( "result = 37 * result + super.hashCode();" ); } sc.add( "" ); sc.add( "return result;" ); return hashCode; } private JMethod[] generateClone( ModelClass modelClass ) throws ModelloException { String cloneModeClass = getCloneMode( modelClass ); if ( JavaClassMetadata.CLONE_NONE.equals( cloneModeClass ) ) { return new JMethod[0]; } JType returnType; if ( useJava5 ) { returnType = new JClass( modelClass.getName() ); } else { returnType = new JClass( "Object" ); } JMethod cloneMethod = new JMethod( "clone", returnType, null ); JSourceCode sc = cloneMethod.getSourceCode(); sc.add( "try" ); sc.add( "{" ); sc.indent(); sc.add( modelClass.getName() + " copy = (" + modelClass.getName() + ") super.clone();" ); sc.add( "" ); for ( Iterator j = modelClass.getFields( getGeneratedVersion() ).iterator(); j.hasNext(); ) { ModelField modelField = (ModelField) j.next(); String thisField = "this." + modelField.getName(); String copyField = "copy." + modelField.getName(); if ( "DOM".equals( modelField.getType() ) ) { sc.add( "if ( " + thisField + " != null )" ); sc.add( "{" ); sc.addIndented( copyField + " = new org.codehaus.plexus.util.xml.Xpp3Dom( (org.codehaus.plexus.util.xml.Xpp3Dom) " + thisField + " );" ); sc.add( "}" ); sc.add( "" ); } else if ( "Date".equalsIgnoreCase( modelField.getType() ) || "java.util.Date".equals( modelField.getType() ) ) { sc.add( "if ( " + thisField + " != null )" ); sc.add( "{" ); sc.addIndented( copyField + " = (java.util.Date) " + thisField + ".clone();" ); sc.add( "}" ); sc.add( "" ); } else if ( ModelDefault.PROPERTIES.equals( modelField.getType() ) ) { sc.add( "if ( " + thisField + " != null )" ); sc.add( "{" ); sc.addIndented( copyField + " = (" + ModelDefault.PROPERTIES + ") " + thisField + ".clone();" ); sc.add( "}" ); sc.add( "" ); } else if ( modelField instanceof ModelAssociation ) { ModelAssociation modelAssociation = (ModelAssociation) modelField; String cloneModeAssoc = getCloneMode( modelAssociation, cloneModeClass ); boolean deepClone = JavaAssociationMetadata.CLONE_DEEP.equals( cloneModeAssoc ) && !immutableTypes.contains( modelAssociation.getTo() ); if ( modelAssociation.isOneMultiplicity() ) { if ( deepClone ) { sc.add( "if ( " + thisField + " != null )" ); sc.add( "{" ); sc.addIndented( copyField + " = (" + modelAssociation.getTo() + ") " + thisField + ".clone();" ); sc.add( "}" ); sc.add( "" ); } } else { sc.add( "if ( " + thisField + " != null )" ); sc.add( "{" ); sc.indent(); sc.add( copyField + " = " + getDefaultValue( modelAssociation ) + ";" ); if ( isCollection( modelField.getType() ) ) { if ( deepClone ) { if ( useJava5 ) { sc.add( "for ( " + modelAssociation.getTo() + " item : " + thisField + " )" ); } else { sc.add( "for ( java.util.Iterator it = " + thisField + ".iterator(); it.hasNext(); )" ); } sc.add( "{" ); sc.indent(); if ( useJava5 ) { sc.add( copyField + ".add( item.clone() );" ); } else { sc.add( copyField + ".add( ( (" + modelAssociation.getTo() + ") it.next() ).clone() );" ); } sc.unindent(); sc.add( "}" ); } else { sc.add( copyField + ".addAll( " + thisField + " );" ); } } else if ( isMap( modelField.getType() ) ) { sc.add( copyField + ".clear();" ); sc.add( copyField + ".putAll( " + thisField + " );" ); } sc.unindent(); sc.add( "}" ); sc.add( "" ); } } } String cloneHook = getCloneHook( modelClass ); if ( StringUtils.isNotEmpty( cloneHook ) && !"false".equalsIgnoreCase( cloneHook ) ) { if ( "true".equalsIgnoreCase( cloneHook ) ) { cloneHook = "cloneHook"; } sc.add( cloneHook + "( copy );" ); sc.add( "" ); } sc.add( "return copy;" ); sc.unindent(); sc.add( "}" ); sc.add( "catch ( " + Exception.class.getName() + " ex )" ); sc.add( "{" ); sc.indent(); sc.add( "throw (" + RuntimeException.class.getName() + ") new " + UnsupportedOperationException.class.getName() + "( getClass().getName()" ); sc.addIndented( "+ \" does not support clone()\" ).initCause( ex );" ); sc.unindent(); sc.add( "}" ); return new JMethod[] { cloneMethod }; } private String getCloneMode( ModelClass modelClass ) throws ModelloException { String cloneMode = null; for ( ModelClass currentClass = modelClass;; ) { JavaClassMetadata javaClassMetadata = (JavaClassMetadata) currentClass.getMetadata( JavaClassMetadata.ID ); cloneMode = javaClassMetadata.getCloneMode(); if ( cloneMode != null ) { break; } String superClass = currentClass.getSuperClass(); if ( StringUtils.isEmpty( superClass ) || !isClassInModel( superClass, getModel() ) ) { break; } currentClass = getModel().getClass( superClass, getGeneratedVersion() ); } if ( cloneMode == null ) { cloneMode = JavaClassMetadata.CLONE_NONE; } else if ( !JavaClassMetadata.CLONE_MODES.contains( cloneMode ) ) { throw new ModelloException( "The Java Modello Generator cannot use '" + cloneMode + "' as a value for , " + "only the following values are acceptable " + JavaClassMetadata.CLONE_MODES ); } return cloneMode; } private String getCloneMode( ModelAssociation modelAssociation, String cloneModeClass ) throws ModelloException { JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation.getAssociationMetadata( JavaAssociationMetadata.ID ); String cloneModeAssoc = javaAssociationMetadata.getCloneMode(); if ( cloneModeAssoc == null ) { cloneModeAssoc = cloneModeClass; } else if ( !JavaAssociationMetadata.CLONE_MODES.contains( cloneModeAssoc ) ) { throw new ModelloException( "The Java Modello Generator cannot use '" + cloneModeAssoc + "' as a value for , " + "only the following values are acceptable " + JavaAssociationMetadata.CLONE_MODES ); } return cloneModeAssoc; } private String getCloneHook( ModelClass modelClass ) throws ModelloException { JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.ID ); return javaClassMetadata.getCloneHook(); } /** * Utility method that adds a period to the end of a string, if the last * non-whitespace character of the string is not a punctuation mark or an * end-tag. * * @param string The string to work with * @return The string that came in but with a period at the end */ private String appendPeriod( String string ) { if ( string == null ) { return string; } String trimmedString = string.trim(); if ( trimmedString.endsWith( "." ) || trimmedString.endsWith( "!" ) || trimmedString.endsWith( "?" ) || trimmedString.endsWith( ">" ) ) { return string; } else { return string + "."; } } private String createHashCodeForField( ModelField identifier ) { String name = identifier.getName(); String type = identifier.getType(); if ( "boolean".equals( type ) ) { return "( " + name + " ? 0 : 1 )"; } else if ( "byte".equals( type ) || "char".equals( type ) || "short".equals( type ) || "int".equals( type ) ) { return "(int) " + name; } else if ( "long".equals( type ) ) { return "(int) ( " + name + " ^ ( " + name + " >>> 32 ) )"; } else if ( "float".equals( type ) ) { return "Float.floatToIntBits( " + name + " )"; } else if ( "double".equals( type ) ) { return "(int) ( Double.doubleToLongBits( " + identifier.getName() + " ) ^ ( Double.doubleToLongBits( " + identifier.getName() + " ) >>> 32 ) )"; } else { return "( " + name + " != null ? " + name + ".hashCode() : 0 )"; } } private JField createField( ModelField modelField ) throws ModelloException { JType type; String baseType = modelField.getType(); if ( modelField.isArray() ) { // remove [] at the end of the type baseType = baseType.substring( 0, baseType.length() - 2 ); } if ( baseType.equals( "boolean" ) ) { type = JType.BOOLEAN; } else if ( baseType.equals( "byte" ) ) { type = JType.BYTE; } else if ( baseType.equals( "char" ) ) { type = JType.CHAR; } else if ( baseType.equals( "double" ) ) { type = JType.DOUBLE; } else if ( baseType.equals( "float" ) ) { type = JType.FLOAT; } else if ( baseType.equals( "int" ) ) { type = JType.INT; } else if ( baseType.equals( "short" ) ) { type = JType.SHORT; } else if ( baseType.equals( "long" ) ) { type = JType.LONG; } else if ( baseType.equals( "Date" ) ) { type = new JClass( "java.util.Date" ); } else if ( baseType.equals( "DOM" ) ) { // TODO: maybe DOM is not how to specify it in the model, but just Object and markup Xpp3Dom for the Xpp3Reader? // not sure how we'll treat it for the other sources, eg sql. type = new JClass( "Object" ); } else { type = new JClass( baseType ); } if ( modelField.isArray() ) { type = new JArrayType( type, useJava5 ); } JField field = new JField( type, modelField.getName() ); if ( modelField.isModelVersionField() ) { field.setInitString( "\"" + getGeneratedVersion() + "\"" ); } if ( modelField.getDefaultValue() != null ) { field.setInitString( getJavaDefaultValue( modelField ) ); } if ( StringUtils.isNotEmpty( modelField.getDescription() ) ) { field.setComment( appendPeriod( modelField.getDescription() ) ); } return field; } private void createField( JClass jClass, ModelField modelField ) throws ModelloException { JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) modelField.getMetadata( JavaFieldMetadata.ID ); JField field = createField( modelField ); jClass.addField( field ); if ( javaFieldMetadata.isGetter() ) { jClass.addMethod( createGetter( field, modelField ) ); } if ( javaFieldMetadata.isSetter() ) { jClass.addMethod( createSetter( field, modelField ) ); } } private JMethod createGetter( JField field, ModelField modelField ) { String propertyName = capitalise( field.getName() ); JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) modelField.getMetadata( JavaFieldMetadata.ID ); String prefix = javaFieldMetadata.isBooleanGetter() ? "is" : "get"; JType returnType = field.getType(); String interfaceCast = ""; if ( modelField instanceof ModelAssociation ) { ModelAssociation modelAssociation = (ModelAssociation) modelField; JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation .getAssociationMetadata( JavaAssociationMetadata.ID ); if ( StringUtils.isNotEmpty( javaAssociationMetadata.getInterfaceName() ) && !javaFieldMetadata.isBooleanGetter() ) { returnType = new JClass( javaAssociationMetadata.getInterfaceName() ); interfaceCast = "(" + javaAssociationMetadata.getInterfaceName() + ") "; } } JMethod getter = new JMethod( prefix + propertyName, returnType, null ); StringBuffer comment = new StringBuffer( "Get " ); if ( StringUtils.isEmpty( modelField.getDescription() ) ) { comment.append( "the " ); comment.append( field.getName() ); comment.append( " field" ); } else { comment.append( StringUtils.lowercaseFirstLetter( modelField.getDescription().trim() ) ); } getter.getJDocComment().setComment( appendPeriod( comment.toString() ) ); getter.getSourceCode().add( "return " + interfaceCast + "this." + field.getName() + ";" ); return getter; } private JMethod createSetter( JField field, ModelField modelField ) throws ModelloException { String propertyName = capitalise( field.getName() ); JMethod setter = new JMethod( "set" + propertyName ); StringBuffer comment = new StringBuffer( "Set " ); if ( StringUtils.isEmpty( modelField.getDescription() ) ) { comment.append( "the " ); comment.append( field.getName() ); comment.append( " field" ); } else { comment.append( StringUtils.lowercaseFirstLetter( modelField.getDescription().trim() ) ); } setter.getJDocComment().setComment( appendPeriod( comment.toString() ) ); JType parameterType = getDesiredType( modelField, false ); setter.addParameter( new JParameter( parameterType, field.getName() ) ); JSourceCode sc = setter.getSourceCode(); if ( modelField instanceof ModelAssociation ) { ModelAssociation modelAssociation = (ModelAssociation) modelField; JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation .getAssociationMetadata( JavaAssociationMetadata.ID ); boolean isOneMultiplicity = isBidirectionalAssociation( modelAssociation ) && modelAssociation.isOneMultiplicity(); if ( isOneMultiplicity && javaAssociationMetadata.isBidi() ) { sc.add( "if ( this." + field.getName() + " != null )" ); sc.add( "{" ); sc.indent(); sc.add( "this." + field.getName() + ".break" + modelAssociation.getModelClass().getName() + "Association( this );" ); sc.unindent(); sc.add( "}" ); sc.add( "" ); } String interfaceCast = ""; if ( StringUtils.isNotEmpty( javaAssociationMetadata.getInterfaceName() ) && modelAssociation.isOneMultiplicity() ) { interfaceCast = "(" + field.getType().getName() + ") "; createClassCastAssertion( sc, modelAssociation, "set" ); } sc.add( "this." + field.getName() + " = " + interfaceCast + field.getName() + ";" ); if ( isOneMultiplicity && javaAssociationMetadata.isBidi() ) { sc.add( "" ); sc.add( "if ( " + field.getName() + " != null )" ); sc.add( "{" ); sc.indent(); sc.add( "this." + field.getName() + ".create" + modelAssociation.getModelClass().getName() + "Association( this );" ); sc.unindent(); sc.add( "}" ); } } else { sc.add( "this." + field.getName() + " = " + field.getName() + ";" ); } return setter; } private void createClassCastAssertion( JSourceCode sc, ModelAssociation modelAssociation, String crudModifier ) throws ModelloException { JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation.getAssociationMetadata( JavaAssociationMetadata.ID ); if ( StringUtils.isEmpty( javaAssociationMetadata.getInterfaceName() ) ) { return; // java.useInterface feature not used, no class cast assertion needed } String propertyName = capitalise( modelAssociation.getName() ); JField field = createField( modelAssociation ); String fieldName = field.getName(); JType type = new JClass( modelAssociation.getTo() ); if ( modelAssociation.isManyMultiplicity() ) { fieldName = uncapitalise( modelAssociation.getTo() ); } String instanceName = type.getName(); // Add sane class cast exception message // When will sun ever fix this? sc.add( "if ( !( " + fieldName + " instanceof " + instanceName + " ) )" ); sc.add( "{" ); sc.indent(); sc.add( "throw new ClassCastException( \"" + modelAssociation.getModelClass().getName() + "." + crudModifier + propertyName + "( " + fieldName + " ) parameter must be instanceof \" + " + instanceName + ".class.getName() );" ); sc.unindent(); sc.add( "}" ); } private void createAssociation( JClass jClass, ModelAssociation modelAssociation, JSourceCode jConstructorSource ) throws ModelloException { JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) modelAssociation.getMetadata( JavaFieldMetadata.ID ); JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation.getAssociationMetadata( JavaAssociationMetadata.ID ); if ( !JavaAssociationMetadata.INIT_TYPES.contains( javaAssociationMetadata.getInitializationMode() ) ) { throw new ModelloException( "The Java Modello Generator cannot use '" + javaAssociationMetadata.getInitializationMode() + "' as a " + "value, the only the following are acceptable " + JavaAssociationMetadata.INIT_TYPES ); } if ( modelAssociation.isManyMultiplicity() ) { JType type; if ( modelAssociation.isGenericType() ) { type = new JCollectionType( modelAssociation.getType(), new JClass( modelAssociation.getTo() ), useJava5 ); } else { type = new JClass( modelAssociation.getType() ); } JField jField = new JField( type, modelAssociation.getName() ); if ( !isEmpty( modelAssociation.getComment() ) ) { jField.setComment( modelAssociation.getComment() ); } if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.FIELD_INIT ) ) { jField.setInitString( getDefaultValue ( modelAssociation ) ); } if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.CONSTRUCTOR_INIT ) ) { jConstructorSource.add( "this." + jField.getName() + " = " + getDefaultValue ( modelAssociation ) + ";" ); } jClass.addField( jField ); if ( javaFieldMetadata.isGetter() ) { String propertyName = capitalise( jField.getName() ); JMethod getter = new JMethod( "get" + propertyName, jField.getType(), null ); JSourceCode sc = getter.getSourceCode(); if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.LAZY_INIT ) ) { sc.add( "if ( this." + jField.getName() + " == null )" ); sc.add( "{" ); sc.indent(); sc.add( "this." + jField.getName() + " = " + getDefaultValue ( modelAssociation ) + ";" ); sc.unindent(); sc.add( "}" ); sc.add( "" ); } sc.add( "return this." + jField.getName() + ";" ); jClass.addMethod( getter ); } if ( javaFieldMetadata.isSetter() ) { jClass.addMethod( createSetter( jField, modelAssociation ) ); } if ( javaAssociationMetadata.isAdder() ) { createAdder( modelAssociation, jClass ); } } else { createField( jClass, modelAssociation ); } if ( isBidirectionalAssociation( modelAssociation ) ) { if ( javaAssociationMetadata.isBidi() ) { createCreateAssociation( jClass, modelAssociation ); } if ( javaAssociationMetadata.isBidi() ) { createBreakAssociation( jClass, modelAssociation ); } } } private void createCreateAssociation( JClass jClass, ModelAssociation modelAssociation ) { JMethod createMethod = new JMethod( "create" + modelAssociation.getTo() + "Association" ); JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation.getAssociationMetadata( JavaAssociationMetadata.ID ); createMethod.addParameter( new JParameter( new JClass( modelAssociation.getTo() ), uncapitalise( modelAssociation.getTo() ) ) ); // TODO: remove after tested // createMethod.addException( new JClass( "Exception" ) ); JSourceCode sc = createMethod.getSourceCode(); if ( modelAssociation.isOneMultiplicity() ) { if ( javaAssociationMetadata.isBidi() ) { sc.add( "if ( this." + modelAssociation.getName() + " != null )" ); sc.add( "{" ); sc.indent(); sc.add( "break" + modelAssociation.getTo() + "Association( this." + modelAssociation.getName() + " );" ); sc.unindent(); sc.add( "}" ); sc.add( "" ); } sc.add( "this." + modelAssociation.getName() + " = " + uncapitalise( modelAssociation.getTo() ) + ";" ); } else { jClass.addImport( "java.util.Collection" ); sc.add( "Collection " + modelAssociation.getName() + " = get" + capitalise( modelAssociation.getName() ) + "();" ); sc.add( "" ); sc.add( "if ( " + modelAssociation.getName() + ".contains( " + uncapitalise( modelAssociation.getTo() ) + " ) )" ); sc.add( "{" ); sc.indent(); sc.add( "throw new IllegalStateException( \"" + uncapitalise( modelAssociation.getTo() ) + " is already assigned.\" );" ); sc.unindent(); sc.add( "}" ); sc.add( "" ); sc.add( modelAssociation.getName() + ".add( " + uncapitalise( modelAssociation.getTo() ) + " );" ); } jClass.addMethod( createMethod ); } private void createBreakAssociation( JClass jClass, ModelAssociation modelAssociation ) { JSourceCode sc; JMethod breakMethod = new JMethod( "break" + modelAssociation.getTo() + "Association" ); breakMethod.addParameter( new JParameter( new JClass( modelAssociation.getTo() ), uncapitalise( modelAssociation.getTo() ) ) ); // TODO: remove after tested // breakMethod.addException( new JClass( "Exception" ) ); sc = breakMethod.getSourceCode(); if ( modelAssociation.isOneMultiplicity() ) { sc.add( "if ( this." + modelAssociation.getName() + " != " + uncapitalise( modelAssociation.getTo() ) + " )" ); sc.add( "{" ); sc.indent(); sc.add( "throw new IllegalStateException( \"" + uncapitalise( modelAssociation.getTo() ) + " isn't associated.\" );" ); sc.unindent(); sc.add( "}" ); sc.add( "" ); sc.add( "this." + modelAssociation.getName() + " = null;" ); } else { sc.add( "if ( ! get" + capitalise( modelAssociation.getName() ) + "().contains( " + uncapitalise( modelAssociation.getTo() ) + " ) )" ); sc.add( "{" ); sc.indent(); sc.add( "throw new IllegalStateException( \"" + uncapitalise( modelAssociation.getTo() ) + " isn't associated.\" );" ); sc.unindent(); sc.add( "}" ); sc.add( "" ); sc.add( "get" + capitalise( modelAssociation.getName() ) + "().remove( " + uncapitalise( modelAssociation.getTo() ) + " );" ); } jClass.addMethod( breakMethod ); } private void createAdder( ModelAssociation modelAssociation, JClass jClass ) throws ModelloException { String fieldName = modelAssociation.getName(); JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation.getAssociationMetadata( JavaAssociationMetadata.ID ); String parameterName = uncapitalise( modelAssociation.getTo() ); String implementationParameterName = parameterName; boolean bidirectionalAssociation = isBidirectionalAssociation( modelAssociation ); JType addType; if ( StringUtils.isNotEmpty( javaAssociationMetadata.getInterfaceName() ) ) { addType = new JClass( javaAssociationMetadata.getInterfaceName() ); implementationParameterName = "( (" + modelAssociation.getTo() + ") " + parameterName + " )"; } else if ( modelAssociation.getToClass() != null ) { addType = new JClass( modelAssociation.getToClass().getName() ); } else { addType = new JClass( "String" ); } if ( modelAssociation.getType().equals( ModelDefault.PROPERTIES ) || modelAssociation.getType().equals( ModelDefault.MAP ) ) { JMethod adder = new JMethod( "add" + capitalise( singular( fieldName ) ) ); if ( modelAssociation.getType().equals( ModelDefault.MAP ) ) { adder.addParameter( new JParameter( new JClass( "Object" ), "key" ) ); } else { adder.addParameter( new JParameter( new JClass( "String" ), "key" ) ); } adder.addParameter( new JParameter( new JClass( modelAssociation.getTo() ), "value" ) ); adder.getSourceCode().add( "get" + capitalise( fieldName ) + "().put( key, value );" ); jClass.addMethod( adder ); } else { JMethod adder = new JMethod( "add" + singular( capitalise( fieldName ) ) ); adder.addParameter( new JParameter( addType, parameterName ) ); createClassCastAssertion( adder.getSourceCode(), modelAssociation, "add" ); adder.getSourceCode().add( "get" + capitalise( fieldName ) + "().add( " + implementationParameterName + " );" ); if ( bidirectionalAssociation && javaAssociationMetadata.isBidi() ) { // TODO: remove after tested // adder.addException( new JClass( "Exception" ) ); adder.getSourceCode().add( implementationParameterName + ".create" + modelAssociation.getModelClass().getName() + "Association( this );" ); } jClass.addMethod( adder ); JMethod remover = new JMethod( "remove" + singular( capitalise( fieldName ) ) ); remover.addParameter( new JParameter( addType, parameterName ) ); createClassCastAssertion( remover.getSourceCode(), modelAssociation, "remove" ); if ( bidirectionalAssociation && javaAssociationMetadata.isBidi() ) { // TODO: remove after tested // remover.addException( new JClass( "Exception" ) ); remover.getSourceCode().add( parameterName + ".break" + modelAssociation.getModelClass().getName() + "Association( this );" ); } remover.getSourceCode().add( "get" + capitalise( fieldName ) + "().remove( " + implementationParameterName + " );" ); jClass.addMethod( remover ); } } private boolean isBidirectionalAssociation( ModelAssociation association ) { Model model = association.getModelClass().getModel(); if ( !isClassInModel( association.getTo(), model ) ) { return false; } ModelClass toClass = association.getToClass(); for ( Iterator j = toClass.getFields( getGeneratedVersion() ).iterator(); j.hasNext(); ) { ModelField modelField = (ModelField) j.next(); if ( !( modelField instanceof ModelAssociation ) ) { continue; } ModelAssociation modelAssociation = (ModelAssociation) modelField; if ( !isClassInModel( modelAssociation.getTo(), model ) ) { continue; } ModelClass totoClass = modelAssociation.getToClass(); if ( association.getModelClass().equals( totoClass ) ) { return true; } } return false; } private JType getDesiredType( ModelField modelField, boolean useTo ) throws ModelloException { JField field = createField( modelField ); JType type = field.getType(); if ( modelField instanceof ModelAssociation ) { ModelAssociation modelAssociation = (ModelAssociation) modelField; JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) modelAssociation .getAssociationMetadata( JavaAssociationMetadata.ID ); if ( StringUtils.isNotEmpty( javaAssociationMetadata.getInterfaceName() ) && ! modelAssociation.isManyMultiplicity() ) { type = new JClass( javaAssociationMetadata.getInterfaceName() ); } else if ( modelAssociation.isManyMultiplicity() && modelAssociation.isGenericType() ) { type = new JCollectionType( modelAssociation.getType(), new JClass( modelAssociation.getTo() ), useJava5 ); } else if ( useTo ) { type = new JClass( modelAssociation.getTo() ); } } return type; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/modello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000755000175000017500000000000011260056267032674 5ustar mkochmkoch././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JStructure.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000006612611243356043032705 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2001-2002 (C) Intalio, Inc. All Rights Reserved. * * $Id: JStructure.java 1311 2009-08-20 23:28:35Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.util.Enumeration; import java.util.Vector; import org.codehaus.plexus.util.WriterFactory; /** * This class represents the basic Java "structure" for a Java * source file. This is the base class for JClass and JInterface. * * This is a useful utility when creating in memory source code. * The code in this package was modelled after the Java Reflection API * as much as possible to reduce the learning curve. * * @author Martin Skopp * @author Keith Visco * @version $Revision: 1311 $ $Date: 2009-08-21 01:28:35 +0200 (Fr, 21. Aug 2009) $ */ public abstract class JStructure extends JType { /** * The Id for Source control systems * I needed to separate this line to prevent CVS from * expanding it here! ;-) */ static final String DEFAULT_HEADER = "$" + "Id$"; /** * The source control version for listed in the JavaDoc * I needed to separate this line to prevent CVS from * expanding it here! ;-) */ static final String version = "$" + "Revision$ $" + "Date$"; /** * The source header */ private JComment header = null; /** * List of imported classes and packages */ private Vector imports = null; /** * The set of interfaces implemented/extended by this JStructure */ private Vector interfaces = null; /** * The Javadoc for this JStructure */ private JDocComment jdc = null; /** * The JModifiers for this JStructure, which allows us to * change the resulting qualifiers */ private JModifiers modifiers = null; /** * The package to which this JStructure belongs */ private String packageName = null; private JAnnotations annotations = null; /** * Creates a new JStructure with the given name. * * @param name the name of the JStructure. * @throws java.lang.IllegalArgumentException when the given name * is not a valid Class name. */ protected JStructure( String name ) throws IllegalArgumentException { super( name ); //-- verify name is a valid java class name if ( !isValidClassName( name ) ) { String lname = getLocalName(); String err = "'" + lname + "' is "; if ( JNaming.isKeyword( lname ) ) err += "a reserved word and may not be used as " + " a class name."; else err += "not a valid Java identifier."; throw new IllegalArgumentException( err ); } this.packageName = getPackageFromClassName( name ); imports = new Vector(); interfaces = new Vector(); jdc = new JDocComment(); modifiers = new JModifiers(); //-- initialize default Java doc jdc.addDescriptor( JDocDescriptor.createVersionDesc( version ) ); } //-- JStructure /** * Adds the given JField to this JStructure. *

* This method is implemented by subclasses and * should only accept the proper fields for the * subclass otherwise an IllegalArgumentException * will be thrown. For example a JInterface will * only accept static fields. *

* @param jField, the JField to add * @exception java.lang.IllegalArgumentException when the given * JField has a name of an existing JField */ public abstract void addField( JField jField ) throws IllegalArgumentException; /** * Adds the given JMember to this JStructure. *

* This method is implemented by subclasses and * should only accept the proper types for the * subclass otherwise an IllegalArgumentException * will be thrown. *

* @param jMember the JMember to add to this JStructure. * @throws java.lang.IllegalArgumentException when the given * JMember has the same name of an existing JField * or JMethod respectively. */ public abstract void addMember( JMember jMember ) throws IllegalArgumentException; /** * Adds the given import to this JStructure * * @param the className of the class to import. */ public void addImport( String className ) { if ( className == null ) return; if ( className.length() == 0 ) return; //-- getPackageName String pkgName = getPackageFromClassName( className ); if ( pkgName != null ) { if ( pkgName.equals( this.packageName ) ) return; //-- XXX: Fix needed for this... //-- This may cause issues if the current package //-- defines any classes that have the same name //-- name as the java.lang package. if ( pkgName.equals( "java.lang" ) ) return; //-- for readabilty keep import list sorted, and make sure //-- we do not include more than one of the same import for ( int i = 0; i < imports.size(); i++ ) { String imp = (String) imports.elementAt( i ); if ( imp.equals( className ) ) return; if ( imp.compareTo( className ) > 0 ) { imports.insertElementAt( className, i ); return; } } imports.addElement( className ); } } //-- addImport /** * Adds the given interface to the list of interfaces this * JStructure inherits method declarations from, and either * implements (JClass) or extends (JInterface). * * @param interfaceName the name of the interface to "inherit" * method declarations from. */ public void addInterface( String interfaceName ) { if ( !interfaces.contains( interfaceName ) ) interfaces.addElement( interfaceName ); } //-- addInterface /** * Adds the given interface to the list of interfaces this * JStructure inherits method declarations from, and either * implements (JClass) or extends (JInterface). * * @param jInterface the JInterface to inherit from. */ public void addInterface( JInterface jInterface ) { if ( jInterface == null ) return; String interfaceName = jInterface.getName(); if ( !interfaces.contains( interfaceName ) ) { interfaces.addElement( interfaceName ); } } //-- addInterface /** * Adds the given JMethodSignature to this JClass * * @param jMethodSig the JMethodSignature to add. * @throws java.lang.IllegalArgumentException when the given * JMethodSignature conflicts with an existing * method signature. */ /* public void addMethod(JMethodSignature jMethodSig) throws IllegalArgumentException { if (jMethodSig == null) { String err = "The JMethodSignature cannot be null."; throw new IllegalArgumentException(err); } //-- XXXX: check method name and signatures *add later* //-- keep method list sorted for esthetics when printing //-- START SORT :-) boolean added = false; short modifierVal = 0; JModifiers modifiers = jMethodSig.getModifiers(); for (int i = 0; i < methods.size(); i++) { JMethodSignature tmp = (JMethodSignature) methods.elementAt(i); //-- first compare modifiers if (tmp.getModifiers().isProtected()) { if (!modifiers.isProtected()) { methods.insertElementAt(jMethodSig, i); added = true; break; } } //-- compare names if (jMethodSig.getName().compareTo(tmp.getName()) < 0) { methods.insertElementAt(jMethodSig, i); added = true; break; } } //-- END SORT if (!added) methods.addElement(jMethodSig); //-- check parameter packages to make sure we have them //-- in our import list String[] pkgNames = jMethodSig.getParameterClassNames(); for (int i = 0; i < pkgNames.length; i++) { addImport(pkgNames[i]); } //-- check return type to make sure it's included in the //-- import list JType jType = jMethodSig.getReturnType(); if (jType != null) { while (jType.isArray()) jType = jType.getComponentType(); if (!jType.isPrimitive()) addImport(jType.getName()); } //-- check exceptions JClass[] exceptions = jMethodSig.getExceptions(); for (int i = 0; i < exceptions.length; i++) { addImport(exceptions[i].getName()); } } //-- addMethod */ /** * Returns the field with the given name, or null if no field * was found with the given name. * * @param name the name of the field to return. * @return the field with the given name, or null if no field * was found with the given name. */ public abstract JField getField( String name ); /** * Returns an array of all the JFields of this JStructure * * @return an array of all the JFields of this JStructure */ public abstract JField[] getFields(); /** * Returns the name of the file that this JStructure would be * printed to, given a call to #print. * * @param destDir the destination directory. This may be null. * @return the name of the file that this JInterface would be * printed as, given a call to #print. */ public String getFilename( String destDir ) { String filename = getLocalName() + ".java"; //-- Convert Java package to path string String javaPackagePath = ""; if ( ( packageName != null ) && ( packageName.length() > 0 ) ) { javaPackagePath = packageName.replace( '.', File.separatorChar ); } //-- Create fully qualified path (including 'destDir') to file File pathFile; if ( destDir == null ) pathFile = new File( javaPackagePath ); else pathFile = new File( destDir, javaPackagePath ); if ( !pathFile.exists() ) { pathFile.mkdirs(); } //-- Prefix filename with path if ( pathFile.toString().length() > 0 ) filename = pathFile.toString() + File.separator + filename; return filename; } //-- getFilename /** * Returns the JComment header to display at the top of the source file * for this JStructure, or null if no header was set. * * @return the JComment header or null if none exists. */ public JComment getHeader() { return this.header; } //-- getHeader /** * Returns an Enumeration of imported package and * class names for this JStructure. * * @return the Enumeration of imports. May be empty. */ public Enumeration getImports() { return imports.elements(); } //-- getImports /** * Returns an Enumeration of interface names that this * JStructure inherits from. * * @return the Enumeration of interface names for this * JStructure. May be empty. */ public Enumeration getInterfaces() { return interfaces.elements(); } //-- getInterfaces /** * Returns the Java Doc comment for this JStructure * * @return the JDocComment for this JStructure */ public JDocComment getJDocComment() { return jdc; } //-- getJDocComment /** * Returns an array of all the JMethodSignatures of this JInterface. * * @return an array of all the JMethodSignatures of this JInterface. */ /* public JMethodSignature[] getMethods() { JMethodSignature[] marray = new JMethodSignature[methods.size()]; methods.copyInto(marray); return marray; } //-- getMethods */ /** * Returns the JMethodSignature with the given name, * and occuring at or after the given starting index. * * @param name the name of the JMethodSignature to return. * @param startIndex the starting index to begin searching * from. * @return the JMethodSignature, or null if not found. */ /* public JMethodSignature getMethod(String name, int startIndex) { for (int i = startIndex; i < methods.size(); i++) { JMethodSignature jMethod = (JMethodSignature)methods.elementAt(i); if (jMethod.getName().equals(name)) return jMethod; } return null; } //-- getMethod */ /** * Returns the JMethodSignature at the given index. * * @param index the index of the JMethodSignature to return. * @return the JMethodSignature at the given index. */ /* public JMethodSignature getMethod(int index) { return (JMethodSignature)methods.elementAt(index); } //-- getMethod */ /** * Returns the JModifiers which allows the qualifiers to be changed. * * @return the JModifiers for this JStructure. */ public JModifiers getModifiers() { return modifiers; } //-- getModifiers /** * Returns the name of the package that this JStructure is a member * of. * * @return the name of the package that this JStructure is a member * of, or null if there is no current package name defined. */ public String getPackageName() { return this.packageName; } //-- getPackageName /** * Returns the name of the interface. * * @param stripPackage a boolean that when true indicates that only * the local name (no package) should be returned. * @return the name of the class. */ public String getName( boolean stripPackage ) { String name = super.getName(); if ( stripPackage ) { int period = name.lastIndexOf( "." ); if ( period > 0 ) name = name.substring( period + 1 ); } return name; } //-- getName /** * Returns true if the given classname exists in the imports * of this JStructure * * @param classname the class name to check for * @return true if the given classname exists in the imports list */ public boolean hasImport( String classname ) { return imports.contains( classname ); } //-- hasImport public boolean removeImport( String className ) { boolean result = false; if ( className == null ) return result; if ( className.length() == 0 ) return result; result = imports.removeElement( className ); return result; } //-- removeImport public boolean isAbstract() { return modifiers.isAbstract(); } public static boolean isValidClassName( String name ) { if ( name == null ) return false; //-- ignore package information, for now int period = name.lastIndexOf( "." ); if ( period > 0 ) name = name.substring( period + 1 ); return JNaming.isValidJavaIdentifier( name ); } //-- isValidClassName /** * Prints the source code for this JStructure in the current * working directory. Sub-directories will be created if necessary * for the package. */ public void print() { print( (String) null, (String) null ); } //-- printSrouce /** * Prints the source code for this JStructure to the destination * directory. Sub-directories will be created if necessary for the * package. * * @param lineSeparator the line separator to use at the end of each line. * If null, then the default line separator for the runtime platform will * be used. */ public void print( String destDir, String lineSeparator ) { // String name = getLocalName(); //-- open output file String filename = getFilename( destDir ); File file = new File( filename ); JSourceWriter jsw = null; try { jsw = new JSourceWriter( WriterFactory.newPlatformWriter( file ) ); } catch ( java.io.IOException ioe ) { System.out.println( "unable to create class file: " + filename ); return; } if ( lineSeparator == null ) { lineSeparator = System.getProperty( "line.separator" ); } jsw.setLineSeparator( lineSeparator ); print( jsw ); jsw.close(); } //-- print /** * Prints the source code for this JStructure to the given * JSourceWriter. * * @param jsw the JSourceWriter to print to. */ public abstract void print( JSourceWriter jsw ); /** * A utility method that prints the header to the given * JSourceWriter * * @param jsw the JSourceWriter to print to. */ public void printHeader( JSourceWriter jsw ) { if ( jsw == null ) { throw new IllegalArgumentException( "argument 'jsw' should not be null." ); } //-- write class header JComment header = getHeader(); if ( header != null ) header.print( jsw ); else { jsw.writeln( "/*" ); jsw.writeln( " * " + DEFAULT_HEADER ); jsw.writeln( " */" ); } jsw.writeln(); jsw.flush(); } //-- printHeader /** * A utility method that prints the imports to the given * JSourceWriter * * @param jsw the JSourceWriter to print to. */ public void printImportDeclarations( JSourceWriter jsw ) { if ( jsw == null ) { throw new IllegalArgumentException( "argument 'jsw' should not be null." ); } //-- print imports if ( imports.size() > 0 ) { jsw.writeln( " //---------------------------------/" ); jsw.writeln( " //- Imported classes and packages -/" ); jsw.writeln( "//---------------------------------/" ); jsw.writeln(); Enumeration e = imports.elements(); while ( e.hasMoreElements() ) { jsw.write( "import " ); jsw.write( e.nextElement() ); jsw.writeln( ';' ); } jsw.writeln(); jsw.flush(); } } //-- printImportDeclarations /** * A utility method that prints the packageDeclaration to * the given JSourceWriter * * @param jsw the JSourceWriter to print to. */ public void printPackageDeclaration( JSourceWriter jsw ) { if ( jsw == null ) { throw new IllegalArgumentException( "argument 'jsw' should not be null." ); } //-- print package name if ( ( packageName != null ) && ( packageName.length() > 0 ) ) { jsw.write( "package " ); jsw.write( packageName ); jsw.writeln( ';' ); jsw.writeln(); } jsw.flush(); } //-- printPackageDeclaration /** * Prints the source code for this JStructure to the given * JSourceWriter. * * @param jsw the JSourceWriter to print to. * public abstract void print(JSourceWriter jsw); StringBuffer buffer = new StringBuffer(); printHeader(); printPackageDeclaration(); printImportDeclarations(); //------------/ //- Java Doc -/ //------------/ jdc.print(jsw); //-- print class information //-- we need to add some JavaDoc API adding comments buffer.setLength(0); if (modifiers.isPrivate()) { buffer.append("private "); } else if (modifiers.isPublic()) { buffer.append("public "); } if (modifiers.isAbstract()) { buffer.append("abstract "); } buffer.append("interface "); buffer.append(getLocalName()); buffer.append(' '); if (interfaces.size() > 0) { boolean endl = false; if (interfaces.size() > 1) { jsw.writeln(buffer.toString()); buffer.setLength(0); endl = true; } buffer.append("extends "); for (int i = 0; i < interfaces.size(); i++) { if (i > 0) buffer.append(", "); buffer.append(interfaces.elementAt(i)); } if (endl) { jsw.writeln(buffer.toString()); buffer.setLength(0); } else buffer.append(' '); } buffer.append('{'); jsw.writeln(buffer.toString()); buffer.setLength(0); jsw.writeln(); jsw.indent(); //-- print method signatures if (methods.size() > 0) { jsw.writeln(); jsw.writeln(" //-----------/"); jsw.writeln(" //- Methods -/"); jsw.writeln("//-----------/"); jsw.writeln(); } for (int i = 0; i < methods.size(); i++) { JMethodSignature signature = (JMethodSignature) methods.elementAt(i); signature.print(jsw); jsw.writeln(';'); } jsw.unindent(); jsw.writeln('}'); jsw.flush(); jsw.close(); } //-- printSource */ /** * Sets the header comment for this JStructure * * @param comment the comment to display at the top of the source file * when printed */ public void setHeader( JComment comment ) { this.header = comment; } //-- setHeader /** * Allows changing the package name of this JStructure * * @param packageName the package name to use * @deprecated removed in future version of javasource */ public void setPackageName( String packageName ) { this.packageName = packageName; changePackage( packageName ); } //-- setPackageName //---------------------/ //- Protected Methods -/ //---------------------/ protected int getInterfaceCount() { return interfaces.size(); } /** * Prints the given source string to the JSourceWriter using the given prefix at * the beginning of each new line. * * @param prefix the prefix for each new line. * @param source the source code to print * @param jsw the JSourceWriter to print to. */ protected static void printlnWithPrefix( String prefix, String source, JSourceWriter jsw ) { jsw.write( prefix ); if ( source == null ) return; char[] chars = source.toCharArray(); int lastIdx = 0; for ( int i = 0; i < chars.length; i++ ) { char ch = chars[i]; if ( ch == '\n' ) { //-- free buffer jsw.write( chars, lastIdx, ( i - lastIdx ) + 1 ); lastIdx = i + 1; if ( i < chars.length ) { jsw.write( prefix ); } } } //-- free buffer if ( lastIdx < chars.length ) { jsw.write( chars, lastIdx, chars.length - lastIdx ); } jsw.writeln(); } //-- printlnWithPrefix /** * Returns the package name from the given class name */ protected static String getPackageFromClassName( String className ) { int idx = -1; if ( ( idx = className.lastIndexOf( '.' ) ) > 0 ) { return className.substring( 0, idx ); } return null; } //-- getPackageFromClassName /** * @return the annotations */ public JAnnotations getAnnotations() { return annotations; } /** * @param annotation the annotation to append */ public void appendAnnotation( String annotation ) { if ( annotations == null ) { annotations = new JAnnotations(); } annotations.appendAnnotation( annotation ); } /** * @param annotations the annotations to set */ public void setAnnotations( JAnnotations annotations ) { this.annotations = annotations; } } //-- JStructure ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceCode.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000002316211123452344032674 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2001 (C) Intalio, Inc. All Rights Reserved. * * $Id: JSourceCode.java 1040 2008-12-21 14:38:28Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import java.util.Vector; /** * A class for holding in-memory Java source code. * * @author Keith Visco * @version $Revision: 1040 $ $Date: 2008-12-21 15:38:28 +0100 (So, 21. Dez 2008) $ **/ public class JSourceCode { /** * A list of JCodeStatements **/ private Vector source = null; /** * The indent size **/ private short indentSize = 4; /** * The current indent size **/ private short currentIndent = indentSize; /** * Creates an empty JSourceCode **/ public JSourceCode() { super(); source = new Vector(); } //-- JSourceCode /** * Creates a JSourceCode and adds the given String * to it's contents * @param sourceCode the source to add **/ public JSourceCode( String sourceCode ) { this(); this.source.addElement( new JCodeStatement( sourceCode, currentIndent ) ); } //-- JSourceCode /** * Adds the given statement to this JSourceCode. The statement * will be added on a new line. * @param statement the statement to add **/ public void add( String statement ) { JCodeStatement jcs = new JCodeStatement( statement, currentIndent ); source.addElement( jcs ); } //-- add /** * Adds the given statement to this JSourceCode. The statement * will be added on a new line. * @param statement the statement to add * @param the indentSize is the size of the indentation to use * when printing this JSourceCode * @see #print * @deprecated this method is not here any mode in castor codegen 1.3rc1 **/ public void add( String statement, short indentSize ) { JCodeStatement jcs = new JCodeStatement( statement, indentSize ); source.addElement( jcs ); } //-- add /** * Adds the given statement to this JSourceCode. The statement * will be added on a new line and added with increased indent. * This is a convenience method for the sequence * * indent(); * add(statement); * unindent(); * * @param statement the statement to add **/ public void addIndented( String statement ) { indent(); JCodeStatement jcs = new JCodeStatement( statement, currentIndent ); source.addElement( jcs ); unindent(); } //-- add /** * Appends the given String to the last line in this * JSourceCode * @param segment the String to append **/ public void append( String segment ) { if ( source.isEmpty() ) add( segment ); else { JCodeStatement jcs = (JCodeStatement) source.lastElement(); jcs.append( segment ); } } //-- append(String) /** * Clears all the code statements from this JSourceCode **/ public void clear() { source.removeAllElements(); } //-- clear(); /** * Copies the contents of this JSourceCode into the given JSourceCode * @param jsc the JSourceCode to copy this JSourceCode into **/ public void copyInto( JSourceCode jsc ) { for ( int i = 0; i < source.size(); i++ ) { jsc.addCodeStatement( (JCodeStatement) source.elementAt( i ) ); } } //-- copyInto /** * Increases the current indent level by 1 **/ public void indent() { currentIndent += indentSize; } //-- indent(); /** * Returns true if this JSourceCode is empty (ie. no source). * @return true if this JSourceCode is empty. **/ public boolean isEmpty() { return source.isEmpty(); } //-- isEmpty /** * Prints this JSourceCode to the given JSourceWriter * @param jsw the JSourceWriter to print to **/ public void print( JSourceWriter jsw ) { for ( int i = 0; i < source.size(); i++ ) jsw.writeln( source.elementAt( i ).toString() ); } //-- print /** * Decreases the indent level by 1 **/ public void unindent() { if ( currentIndent == 0 ) { throw new ModelloRuntimeException( "Cannot unindent: current indent is 0." ); } currentIndent -= indentSize; } //-- unindent /** * Returns the String representation of this JSourceCode * @return the String representation of this JSourceCode **/ public String toString() { StringBuffer sb = new StringBuffer(); String lineSeparator = System.getProperty( "line.separator" ); for ( int i = 0; i < source.size(); i++ ) { sb.append( source.elementAt( i ).toString() ); sb.append( lineSeparator ); } return sb.toString(); } //-- toString /** * Adds the given JCodeStatement to this JSourceCode * @param jcs the JCodeStatement to add **/ private void addCodeStatement( JCodeStatement jcs ) { short indent = (short) ( jcs.getIndent() + currentIndent - JCodeStatement.DEFAULT_INDENTSIZE ); source.addElement( new JCodeStatement( jcs.getStatement(), indent ) ); } //-- addCodeStatement(JCodeStatement) } //-- JSourceCode /** * Represents a line of code, used by JSourceCode class * @author Keith Visco **/ class JCodeStatement { private StringBuffer value = null; static public short DEFAULT_INDENTSIZE = 4; private short indentSize = DEFAULT_INDENTSIZE; JCodeStatement() { super(); value = new StringBuffer(); } //-- JCodeStatement JCodeStatement( String statement ) { this(); this.value.append( statement ); } //-- JCodeStatement JCodeStatement( String statement, short indentSize ) { this( statement ); this.indentSize = indentSize; } //-- JCodeStatement void append( String segment ) { value.append( segment ); } short getIndent() { return indentSize; } //-- getIndent String getStatement() { return value.toString(); } //-- getStatement public String toString() { if ( value.length() == 0 ) { return ""; } StringBuffer sb = new StringBuffer( indentSize + value.length() ); for ( int i = 0; i < indentSize; i++ ) sb.append( ' ' ); sb.append( value.toString() ); return sb.toString(); } } //-- JCodeStatement ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JNaming.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000001323310367232700032673 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved. * * $Id: JNaming.java 555 2006-01-29 21:38:08Z jvanzyl $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * A utility class used to validate identifiers * and class names * @author Keith Visco * @version $Revision: 555 $ $Date: 2006-01-29 22:38:08 +0100 (So, 29. Jan 2006) $ **/ class JNaming { private static final String[] keywords = { "abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while" }; //-- keywords private JNaming() { super(); } /** * Returns true if the given String is a Java keyword which * will cause a problem when used as a variable name **/ public static boolean isKeyword( String name ) { if ( name == null ) return false; for ( int i = 0; i < keywords.length; i++ ) { if ( keywords[i].equals( name ) ) return true; } return false; } //-- isKeyword /** * Returns true if the given String matches the * production of a valid Java identifier * * @param string, the String to check the production of * @return true if the given String matches the * production of a valid Java name, otherwise false **/ public static boolean isValidJavaIdentifier( String string ) { if ( ( string == null ) || ( string.length() == 0 ) ) return false; char[] chars = string.toCharArray(); //-- make sure starting character is valid if ( !Character.isJavaIdentifierStart( chars[0] ) ) return false; for ( int i = 1; i < chars.length; i++ ) { if ( !Character.isJavaIdentifierPart( chars[i] ) ) return false; } if ( isKeyword( string ) ) return false; return true; } //-- isValidJavaIdentifier } //-- JNaming././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JComment.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000002644010367232700032677 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. * * $Id: JComment.java 555 2006-01-29 21:38:08Z jvanzyl $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * A class that represents a Java comment. * @author Keith Visco * @version $Revision: 555 $ $Date: 2006-01-29 22:38:08 +0100 (So, 29. Jan 2006) $ **/ public class JComment { /** * The auto style, allows this JComment to automatically * choose a style for this comment **/ public static final short AUTO_STYLE = 0; /** * The block comment style: \/* *\/ **/ public static final short BLOCK_STYLE = 1; /** * The line comment style: \/\/ **/ public static final short LINE_STYLE = 2; /** * The header style, similiar to block, but with an '*' * at the start of each line. **/ public static final short HEADER_STYLE = 3; /** * Similiar to HEADER_STYLE, but starts with: \/** **/ public static final short JAVADOC_STYLE = 4; private static final String START_BLOCK = "/*"; private static final String END_BLOCK = " */"; private static final String START_JAVADOC = "/**"; private static final String END_JAVADOC = " */"; private static final String ASTERIX_PREFIX = " * "; private static final String LINE_COMMENT_PREFIX = "// "; private static final String SPACE_PREFIX = " "; /** * The style of this comment **/ private short style = AUTO_STYLE; /** * The main comment for this JDocComment **/ private StringBuffer _comment = null; /** * The maximum number of characters per line **/ protected static final int MAX_LENGTH = 65; /** * Creates a new Java Comment **/ public JComment() { super(); _comment = new StringBuffer(); } //-- JComment /** * Creates a new Java comment with the given style **/ public JComment( short style ) { this(); this.style = style; } //-- JComment /** * Appends the comment String to this JDocComment * @param comment the comment to append **/ public void appendComment( String comment ) { _comment.append( comment ); } //-- appendComment /** * prints this JComment using the given JSourceWriter * @param jsw the JSourceWriter to print to **/ public void print( JSourceWriter jsw ) { if ( jsw == null ) return; //-- nothing to do LineFormatter formatter = null; //-- calculate comment length short currentIndent = jsw.getIndentSize(); int maxLength = MAX_LENGTH - currentIndent; //-- a simple to check to make sure we have some room //-- to print the comment if ( maxLength <= 17 ) maxLength = MAX_LENGTH / 2; short resolvedStyle = style; if ( style == AUTO_STYLE ) { //-- estimation of number of lines int nbrLines = _comment.length() / maxLength; if ( nbrLines > 2 ) resolvedStyle = BLOCK_STYLE; else resolvedStyle = LINE_STYLE; } //-- start comment String prefix = null; String start = null; String end = null; switch ( resolvedStyle ) { case BLOCK_STYLE: start = START_BLOCK; end = END_BLOCK; prefix = SPACE_PREFIX; break; case HEADER_STYLE: start = START_BLOCK; end = END_BLOCK; prefix = ASTERIX_PREFIX; break; case JAVADOC_STYLE: start = START_JAVADOC; end = END_JAVADOC; prefix = ASTERIX_PREFIX; break; default: //-- LINE prefix = LINE_COMMENT_PREFIX; break; } if ( start != null ) jsw.writeln( start ); //-- print main comment formatter = new LineFormatter( _comment.toString(), maxLength, prefix ); while ( formatter.hasMoreLines() ) { jsw.writeln( formatter.nextLine() ); } if ( end != null ) jsw.writeln( end ); jsw.flush(); } //-- print /** * Sets the comment String of this JDocComment * @param comment the comment String of this JDocComment **/ public void setComment( String comment ) { _comment.setLength( 0 ); _comment.append( comment ); } //-- setComment /** * Sets the style for this JComment * @param style the style to use for this JComment **/ public void setStyle( short style ) { this.style = style; } //-- setStyle /** * Returns the String representation of this Java Doc Comment * @return the String representation of this Java Doc Comment **/ public String toString() { return ""; } //-- toString } //-- JComment /** * Formats a given String for use within a Java comment * @author Keith Visco **/ class LineFormatter { String comment = null; int maxLength = 65; int offset = 0; int length = 0; String prefix = null; private StringBuffer sb = null; /** * Creates a LineFormatter for the given comment * @param comment the String to format **/ LineFormatter( String comment ) { this.comment = comment; if ( comment != null ) this.length = comment.length(); sb = new StringBuffer(); } //-- LineFormatter /** * Creates a new LineFormatter for the given comment * @param comment the String to format * @param maxLength the maximum number of characters per line **/ LineFormatter( String comment, int maxLength ) { this( comment, maxLength, null ); } //-- LineFormatter /** * Creates a new LineFormatter for the given comment * @param comment the String to format * @param maxLength the maximum number of characters per line * @param prefix a prefix to append to the beginning of each line **/ LineFormatter( String comment, int maxLength, String prefix ) { this( comment ); this.maxLength = maxLength; this.prefix = prefix; } //-- LineFormatter boolean hasMoreLines() { if ( comment == null ) return false; return ( offset < length ); } //-- isFinished String nextLine() { if ( comment == null ) return null; if ( offset >= length ) return null; sb.setLength( 0 ); if ( prefix != null ) sb.append( prefix ); int max = offset + maxLength; if ( max > this.length ) max = this.length; int index = offset; int breakable = offset; for ( ; index < max; index++ ) { char ch = comment.charAt( index ); if ( isNewLine( ch ) ) { sb.append( comment.substring( offset, index ) ); offset = index + 1; return sb.toString(); } if ( isWhitespace( ch ) ) breakable = index; } if ( index < length - 1 ) { //-- if we could not find a breakable character, we must look //-- ahead if ( offset == breakable ) { while ( index < length ) { if ( isBreakable( comment.charAt( index ) ) ) break; ++index; } } else index = breakable; } sb.append( comment.substring( offset, index ) ); offset = index + 1; return sb.toString(); } //-- getNextLine /** * Sets the prefix that should be appended to the beginning of * each line * @param prefix the prefix for this LineFormatter **/ void setPrefix( String prefix ) { this.prefix = prefix; } //-- setPrefix private boolean isBreakable( char ch ) { return ( isWhitespace( ch ) || isNewLine( ch ) ); } private boolean isWhitespace( char ch ) { return ( ( ch == ' ' ) || ( ch == '\t' ) ); } //-- isWhitespace private boolean isNewLine( char ch ) { return ( ( ch == '\n' ) || ( ch == '\r' ) ); } //-- isNewLineChar } //-- LineFormatter ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JAnnotations.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000000241311232155760032673 0ustar mkochmkochpackage org.codehaus.modello.plugin.java.javasource; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class JAnnotations { private List/*String*/ annotations; public JAnnotations() { this.annotations = new ArrayList(); } public void appendAnnotation( String annotation ) { annotations.add( annotation ); } /** * Returns the String representation of this JAnnotations * @return the String representation of this JAnnotations **/ public String toString() { StringBuffer sb = new StringBuffer(); Iterator iterator = annotations.iterator(); while ( iterator.hasNext() ) { sb.append( iterator.next().toString() ); if ( iterator.hasNext() ) { sb.append( ' ' ); } } return sb.toString(); } //-- toString /** * prints this Annotations using the given JSourceWriter * * @param jsw the JSourceWriter to print to */ public void print( JSourceWriter jsw ) { Iterator iterator = annotations.iterator(); while ( iterator.hasNext() ) { jsw.writeln( iterator.next().toString() ); } } // -- print } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JNamedMap.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000001701310367232700032673 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. * * $Id: JNamedMap.java 555 2006-01-29 21:38:08Z jvanzyl $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Vector; /** * A simple String to Object mapping which preserves order. * *
* Note: * This class is not synchronized. So be careful. :-) * * @author Keith Visco **/ public class JNamedMap { private Vector names = null; private Vector objects = null; /** * Creates a new JNamedMap **/ public JNamedMap() { names = new Vector(); objects = new Vector(); } //-- JNamedMap /** * Creates a new JNamedMap with the given size. * * @param size the initial size for this NamedMap **/ public JNamedMap( int size ) { names = new Vector( size ); objects = new Vector( size ); } //-- JNamedMap /** * Returns the Object associated with the given name. * * @param name the name to search for * @return the Object associated with the given name **/ public Object get( String name ) { int i = indexOf( name ); if ( i >= 0 ) return objects.elementAt( i ); return null; } //-- get /** * Returns the Object at the given index. * * @param index the index of the Object to return * @return the Object at the given index **/ public Object get( int index ) throws IndexOutOfBoundsException { return objects.elementAt( index ); } //-- get /** * Returns the name associated with the given Object * * @param obj the Object to search for * @return the name of the given Object **/ public String getNameByObject( Object obj ) { int i = objects.indexOf( obj ); if ( i >= 0 ) return (String) names.elementAt( i ); return null; } //-- getNameByObject /** * Return a Vector of names * * @return a Vector of names **/ public Vector getNames() { return (Vector) names.clone(); } //-- getNames /** * Return a Vector of Objects * * @return a Vector of Objects **/ public Vector getObjects() { return (Vector) objects.clone(); } //-- getObjects /** * Returns the index of the Object which has been * mapped (associated) with the given name * * @return the index of the Object which has been mapped (associated) * to the given name **/ public int indexOf( String name ) { for ( int i = 0; i < names.size(); i++ ) { String iName = (String) names.elementAt( i ); if ( iName.equals( name ) ) return i; } return -1; } //-- indexOf /** * Maps (associates) an Object with a name * * @param name the name to associate with the given Object * @param obj the Object to be mapped **/ public void put( String name, Object obj ) { int idx = indexOf( name ); if ( idx >= 0 ) objects.setElementAt( obj, idx ); else { //-- we may need some synchronization here //-- if we are in a multithreaded environment names.addElement( name ); objects.addElement( obj ); } } //-- put /** * Removes and returns the Object located at the given index * * @param name the name of the Object to remove * @return the object removed from the map. **/ public Object remove( int index ) throws IndexOutOfBoundsException { Object obj = objects.elementAt( index ); objects.removeElementAt( index ); names.removeElementAt( index ); return obj; } //-- remove /** * Removes and returns the Object associated with the given name * * @param name the name of the Object to remove * @return the object removed from the map. **/ public Object remove( String name ) { Object obj = null; int idx = indexOf( name ); if ( idx >= 0 ) { obj = objects.elementAt( idx ); objects.removeElementAt( idx ); names.removeElementAt( idx ); } return obj; } //-- remove /** * Returns the number of Object associations currently in * this named map * * @return the number of Object associations currently in * this named map **/ public int size() { return names.size(); } //-- size } //-- JNamedMap././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JClass.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000006645311231735057032713 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved. * * $Id: JClass.java 1297 2009-07-23 01:17:35Z hboutemy $ * * Contributors: * -------------- * Keith Visco (kvisco@intalio.com) - Original Author * Martin Skopp (skopp@riege.de) - Moved some core code into JStructure * and revised to extend JStructure * */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Vector; /** * A representation of the Java Source code for a Java Class. This is * a useful utility when creating in memory source code. * This package was modelled after the Java Reflection API * as much as possible to reduce the learning curve. * * @author Keith Visco * @author Martin Skopp * @version $Revision: 1297 $ $Date: 2009-07-23 03:17:35 +0200 (Do, 23. Jul 2009) $ */ public class JClass extends JStructure { /** * The list of constructors for this JClass */ private Vector _constructors = null; /** * The list of member variables (fields) of this JClass */ private JNamedMap _fields = null; private Vector _innerClasses = null; /** * The list of methods of this JClass */ private Vector _methods = null; /** * The superclass for this JClass */ private String _superClass = null; /** * The source code for static initialization **/ private JSourceCode _staticInitializer = new JSourceCode(); /** * Creates a new JClass with the given name * @param name the name of the JClass to create * @exception java.lang.IllegalArgumentException when the given name * is not a valid Class name **/ public JClass( String name ) throws IllegalArgumentException { super( name ); _constructors = new Vector(); _fields = new JNamedMap(); _methods = new Vector(); _innerClasses = new Vector(); //-- initialize default Java doc getJDocComment().appendComment( "Class " + getLocalName() + "." ); } //-- JClass /** * Adds the given Constructor to this classes list of constructors. * The constructor must have been created with this JClass' * createConstructor. * * @throws java.lang.IllegalArgumentException */ public void addConstructor( JConstructor constructor ) throws IllegalArgumentException { if ( constructor == null ) throw new IllegalArgumentException( "Constructors cannot be null" ); if ( constructor.getDeclaringClass() == this ) { /** check signatures (add later) **/ if ( !_constructors.contains( constructor ) ) { _constructors.addElement( constructor ); } } else { String err = "The given JConstructor was not created "; err += "by this JClass"; throw new IllegalArgumentException( err ); } } /** * Adds the given JField to this JClass * * @param jField, the JField to add * @exception java.lang.IllegalArgumentException when the given * JField has a name of an existing JField **/ public void addField( JField jField ) throws IllegalArgumentException { if ( jField == null ) { throw new IllegalArgumentException( "Class members cannot be null" ); } String name = jField.getName(); if ( _fields.get( name ) != null ) { String err = "duplicate name found: " + name; throw new IllegalArgumentException( err ); } _fields.put( name, jField ); } //-- addField /** * Adds the given JMember to this JClass * * @param jMember, the JMember to add * @exception java.lang.IllegalArgumentException when the given * JMember has the same name of an existing JField * or JMethod respectively, or if the JMember is of an * unrecognized class. **/ public void addMember( JMember jMember ) throws IllegalArgumentException { if ( jMember instanceof JField ) addField( (JField) jMember ); else if ( jMember instanceof JMethod ) addMethod( (JMethod) jMember ); else { String error = null; if ( jMember == null ) { error = "the argument 'jMember' must not be null."; } else { error = "Cannot add JMember '" + jMember.getClass().getName() + "' to JClass, unrecognized type."; } throw new IllegalArgumentException( error ); } } //-- addMember /** * Adds the given JMethod to this JClass * * @param jMethod, the JMethod to add * @param importReturnType true if we add the importReturnType to * the class import lists. It could be useful to set it to false when * all types are fully qualified. * @exception java.lang.IllegalArgumentException when the given * JMethod has the same name of an existing JMethod. **/ public void addMethod( JMethod jMethod ) { addMethod( jMethod, true ); } /** * Adds the given JMethod to this JClass * * @param jMethod, the JMethod to add * @param importReturnType true if we add the importReturnType to * the class import lists. It could be useful to set it to false when * all types are fully qualified. * @exception java.lang.IllegalArgumentException when the given * JMethod has the same name of an existing JMethod. **/ public void addMethod( JMethod jMethod, boolean importReturnType ) throws IllegalArgumentException { if ( jMethod == null ) { throw new IllegalArgumentException( "Class methods cannot be null" ); } //-- check method name and signatures *add later* //-- keep method list sorted for esthetics when printing //-- START SORT :-) boolean added = false; // short modifierVal = 0; JModifiers modifiers = jMethod.getModifiers(); if ( modifiers.isAbstract() ) { getModifiers().setAbstract( true ); } for ( int i = 0; i < _methods.size(); i++ ) { JMethod tmp = (JMethod) _methods.elementAt( i ); //-- first compare modifiers if ( tmp.getModifiers().isPrivate() ) { if ( !modifiers.isPrivate() ) { _methods.insertElementAt( jMethod, i ); added = true; break; } } //-- compare names if ( jMethod.getName().compareTo( tmp.getName() ) < 0 ) { _methods.insertElementAt( jMethod, i ); added = true; break; } } //-- END SORT if ( !added ) _methods.addElement( jMethod ); } //-- addMethod /** * Adds the given array of JMethods to this JClass * * @param jMethods, the JMethod[] to add * @exception java.lang.IllegalArgumentException when any of the given * JMethods has the same name of an existing JMethod. **/ public void addMethods( JMethod[] jMethods ) throws IllegalArgumentException { for ( int i = 0; i < jMethods.length; i++ ) addMethod( jMethods[i] ); } //-- addMethods /** * Creates a new JConstructor and adds it to this * JClass. * * @return the newly created constructor */ public JConstructor createConstructor() { return createConstructor( null ); } //-- createConstructor /** * Creates a new JConstructor and adds it to this * JClass. * * @return the newly created constructor */ public JConstructor createConstructor( JParameter[] params ) { JConstructor cons = new JConstructor( this ); if ( params != null ) { for ( int i = 0; i < params.length; i++ ) cons.addParameter( params[i] ); } addConstructor( cons ); return cons; } //-- createConstructor /** * Creates and returns an inner-class for this JClass * * @param localname the name of the class (no package name) * @return the new JClass */ public JClass createInnerClass( String localname ) { if ( localname == null ) { String err = "argument 'localname' must not be null."; throw new IllegalArgumentException( err ); } if ( localname.indexOf( '.' ) >= 0 ) { String err = "The name of an inner-class must not contain a package name."; throw new IllegalArgumentException( err ); } String classname = getPackageName(); if ( classname != null ) { classname = classname + "." + localname; } else { classname = localname; } JClass innerClass = new JInnerClass( classname ); _innerClasses.addElement( innerClass ); return innerClass; } //-- createInnerClass /** * Returns the constructor at the specified index. * * @param index the index of the constructor to return * @return the JConstructor at the specified index. */ public JConstructor getConstructor( int index ) { return (JConstructor) _constructors.elementAt( index ); } //-- getConstructor /** * Returns the an array of the JConstructors contained within this JClass * * @return an array of JConstructor */ public JConstructor[] getConstructors() { int size = _constructors.size(); JConstructor[] jcArray = new JConstructor[size]; for ( int i = 0; i < _constructors.size(); i++ ) { jcArray[i] = (JConstructor) _constructors.elementAt( i ); } return jcArray; } //-- getConstructors /** * Returns the member with the given name, or null if no member * was found with the given name * @param name the name of the member to return * @return the member with the given name, or null if no member * was found with the given name **/ public JField getField( String name ) { return (JField) _fields.get( name ); } //-- getField /** * Returns an array of all the JFields of this JClass * @return an array of all the JFields of this JClass **/ public JField[] getFields() { int size = _fields.size(); JField[] farray = new JField[size]; for ( int i = 0; i < size; i++ ) { farray[i] = (JField) _fields.get( i ); } return farray; } //-- getFields /** * Returns an array of JClass (the inner classes) * contained within this JClass. * * @return an array of JClass contained within this JClass */ public JClass[] getInnerClasses() { int size = _innerClasses.size(); JClass[] carray = new JClass[size]; _innerClasses.copyInto( carray ); return carray; } //-- getInnerClasses; /** * Returns an array of all the JMethods of this JClass * * @return an array of all the JMethods of this JClass */ public JMethod[] getMethods() { int size = _methods.size(); JMethod[] marray = new JMethod[size]; for ( int i = 0; i < _methods.size(); i++ ) { marray[i] = (JMethod) _methods.elementAt( i ); } return marray; } //-- getMethods /** * Returns the first occurrence of the method with the * given name, starting from the specified index. * * @param name the name of the method to look for * @param startIndex the starting index to begin the search * @return the method if found, otherwise null. */ public JMethod getMethod( String name, int startIndex ) { for ( int i = startIndex; i < _methods.size(); i++ ) { JMethod jMethod = (JMethod) _methods.elementAt( i ); if ( jMethod.getName().equals( name ) ) return jMethod; } return null; } //-- getMethod /** * Returns the JMethod located at the specified index * * @param index the index of the JMethod to return. * @return the JMethod */ public JMethod getMethod( int index ) { return (JMethod) _methods.elementAt( index ); } //-- getMethod /** * Returns the JSourceCode for the static initializer * of this JClass * * @return the JSourceCode for the static initializer * of this JClass */ public JSourceCode getStaticInitializationCode() { return _staticInitializer; } //-- getStaticInitializationCode /** * Gets the super Class that this class extends * @return superClass the super Class that this Class extends */ public String getSuperClass() { return _superClass; } //-- getSuperClass /** * Prints the source code for this JClass to the given JSourceWriter * * @param jsw the JSourceWriter to print to. [May not be null] */ public void print( JSourceWriter jsw ) { print( jsw, false ); } //-- print /** * Prints the source code for this JClass to the given JSourceWriter * * @param jsw the JSourceWriter to print to. [May not be null] */ public void print( JSourceWriter jsw, boolean classOnly ) { if ( jsw == null ) { throw new IllegalArgumentException( "argument 'jsw' should not be null." ); } StringBuffer buffer = new StringBuffer(); if ( !classOnly ) { printHeader( jsw ); printPackageDeclaration( jsw ); //-- get imports from inner-classes Vector removeImports = null; if ( _innerClasses.size() > 0 ) { removeImports = new Vector(); for ( int i = 0; i < _innerClasses.size(); i++ ) { JClass iClass = (JClass) _innerClasses.elementAt( i ); Enumeration e = iClass.getImports(); while ( e.hasMoreElements() ) { String classname = (String) e.nextElement(); if ( !hasImport( classname ) ) { addImport( classname ); removeImports.addElement( classname ); } } } } printImportDeclarations( jsw ); //-- remove imports from inner-classes, if necessary if ( removeImports != null ) { for ( int i = 0; i < removeImports.size(); i++ ) { removeImport( (String) removeImports.elementAt( i ) ); } } } //------------/ //- Java Doc -/ //------------/ getJDocComment().print( jsw ); JAnnotations annotations = getAnnotations(); if ( annotations != null ) annotations.print( jsw ); //-- print class information //-- we need to add some JavaDoc API adding comments buffer.setLength( 0 ); JModifiers modifiers = getModifiers(); if ( modifiers.isPrivate() ) { buffer.append( "private " ); } else if ( modifiers.isPublic() ) { buffer.append( "public " ); } if ( modifiers.isAbstract() ) { buffer.append( "abstract " ); } buffer.append( "class " ); buffer.append( getLocalName() ); jsw.writeln( buffer.toString() ); buffer.setLength( 0 ); jsw.indent(); if ( _superClass != null ) { buffer.append( "extends " ); buffer.append( _superClass ); jsw.writeln( buffer.toString() ); buffer.setLength( 0 ); } if ( getInterfaceCount() > 0 ) { buffer.append( "implements " ); Enumeration e = getInterfaces(); while ( e.hasMoreElements() ) { buffer.append( e.nextElement() ); if ( e.hasMoreElements() ) buffer.append( ", " ); } jsw.writeln( buffer.toString() ); buffer.setLength( 0 ); } jsw.unindent(); jsw.writeln( '{' ); jsw.indent(); //-- declare members if ( _fields.size() > 0 ) { jsw.writeln(); jsw.writeln( " //--------------------------/" ); jsw.writeln( " //- Class/Member Variables -/" ); jsw.writeln( "//--------------------------/" ); jsw.writeln(); } for ( int i = 0; i < _fields.size(); i++ ) { JField jField = (JField) _fields.get( i ); //-- print Java comment JDocComment comment = jField.getComment(); if ( comment != null ) comment.print( jsw ); JAnnotations fieldAnnotations = jField.getAnnotations(); if ( fieldAnnotations != null ) fieldAnnotations.print( jsw ); // -- print member jsw.write( jField.getModifiers().toString() ); jsw.write( ' ' ); JType type = jField.getType(); String typeName = type.toString(); //-- for esthetics use short name in some cases if ( typeName.equals( toString() ) ) { typeName = type.getLocalName(); } jsw.write( typeName ); jsw.write( ' ' ); jsw.write( jField.getName() ); String init = jField.getInitString(); if ( init != null ) { jsw.write( " = " ); jsw.write( init ); } jsw.writeln( ';' ); jsw.writeln(); } //----------------------/ //- Static Initializer -/ //----------------------/ if ( !_staticInitializer.isEmpty() ) { jsw.writeln(); jsw.writeln( "static" ); jsw.writeln( "{" ); _staticInitializer.print( jsw ); jsw.writeln( "};" ); jsw.writeln(); } //-- print constructors if ( _constructors.size() > 0 ) { jsw.writeln(); jsw.writeln( " //----------------/" ); jsw.writeln( " //- Constructors -/" ); jsw.writeln( "//----------------/" ); jsw.writeln(); } for ( int i = 0; i < _constructors.size(); i++ ) { JConstructor jConstructor = (JConstructor) _constructors.elementAt( i ); jConstructor.print( jsw ); jsw.writeln(); } //-- print methods if ( _methods.size() > 0 ) { jsw.writeln(); jsw.writeln( " //-----------/" ); jsw.writeln( " //- Methods -/" ); jsw.writeln( "//-----------/" ); jsw.writeln(); } for ( int i = 0; i < _methods.size(); i++ ) { JMethod jMethod = (JMethod) _methods.elementAt( i ); jMethod.print( jsw ); jsw.writeln(); } //-- print inner-classes if ( _innerClasses.size() > 0 ) { jsw.writeln(); jsw.writeln( " //-----------------/" ); jsw.writeln( " //- Inner Classes -/" ); jsw.writeln( "//-----------------/" ); jsw.writeln(); } for ( int i = 0; i < _innerClasses.size(); i++ ) { JClass jClass = (JClass) _innerClasses.elementAt( i ); jClass.print( jsw, true ); jsw.writeln(); } for ( Iterator iterator = sourceCodeEntries.iterator(); iterator.hasNext(); ) { jsw.writeln( (String) iterator.next() ); } jsw.unindent(); jsw.writeln( '}' ); jsw.flush(); } //-- printSource private List sourceCodeEntries = new ArrayList(); public void addSourceCode( String sourceCode ) { sourceCodeEntries.add( sourceCode ); } /** * Removes the given constructor from this JClass * * @param constructor the JConstructor to remove * @return true if the constructor was removed, otherwise false. */ public boolean removeConstructor( JConstructor constructor ) { return _constructors.removeElement( constructor ); } //-- removeConstructor /** * Removes the field with the given name from this JClass * * @param name the name of the field to remove **/ public JField removeField( String name ) { if ( name == null ) return null; JField field = (JField) _fields.remove( name ); //-- clean up imports //-- NOT YET IMPLEMENTED return field; } //-- removeField /** * Removes the given JField from this JClass * * @param jField, the JField to remove **/ public boolean removeField( JField jField ) { if ( jField == null ) return false; Object field = _fields.get( jField.getName() ); if ( field == jField ) { _fields.remove( jField.getName() ); return true; } //-- clean up imports //-- NOT YET IMPLEMENTED return false; } //-- removeField /** * Removes the given inner-class (JClass) from this JClass. * * @param jClass the JClass (inner-class) to remove. * @return true if the JClass was removed, otherwise false. */ public boolean removeInnerClass( JClass jClass ) { return _innerClasses.removeElement( jClass ); } //-- removeInnerClass /** * Sets the super Class that this class extends * @param superClass the super Class that this Class extends */ public void setSuperClass( String superClass ) { _superClass = superClass; } //-- setSuperClass /** * Test drive method...to be removed or commented out **/ /*public static void main( String[] args ) { JClass testClass = new JClass( "org.acme.Test" ); testClass.addImport( "java.util.Vector" ); testClass.addMember( new JField( JType.INT, "x" ) ); JClass jcString = new JClass( "String" ); JField field = null; field = new JField( JType.INT, "_z" ); field.getModifiers().setStatic( true ); testClass.addField( field ); testClass.getStaticInitializationCode().add( "_z = 75;" ); field = new JField( jcString, "myString" ); field.getModifiers().makePrivate(); testClass.addMember( field ); //-- create constructor JConstructor cons = testClass.createConstructor(); cons.getSourceCode().add( "this.x = 6;" ); JMethod jMethod = new JMethod( "getX", JType.INT, null ); jMethod.setSourceCode( "return this.x;" ); testClass.addMethod( jMethod ); //-- create inner-class JClass innerClass = testClass.createInnerClass( "Foo" ); innerClass.addImport( "java.util.Hashtable" ); innerClass.addMember( new JField( JType.INT, "_type" ) ); field = new JField( jcString, "_name" ); field.getModifiers().makePrivate(); innerClass.addMember( field ); //-- create constructor cons = innerClass.createConstructor(); cons.getSourceCode().add( "_name = \"foo\";" ); jMethod = new JMethod( "getName", jcString, null ); jMethod.setSourceCode( "return _name;" ); innerClass.addMethod( jMethod ); testClass.print(); } //-- main */ final class JInnerClass extends JClass { JInnerClass( String name ) { super( name ); } /** * Allows changing the package name of this JStructure * * @param packageName the package name to use */ public void setPackageName( String packageName ) { throw new IllegalStateException( "Cannot change the package of an inner-class" ); } //-- setPackageName } //-- JInnerClass } //-- JClass ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JType.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000001633311123536732032702 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. * * $Id: JType.java 1041 2008-12-21 22:06:18Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Keith Visco * @version $Revision: 1041 $ $Date: 2008-12-21 23:06:18 +0100 (So, 21. Dez 2008) $ **/ public class JType { public static final JType BOOLEAN = new JType( "boolean" ); public static final JType BYTE = new JType( "byte" ); public static final JType CHAR = new JType( "char" ); public static final JType DOUBLE = new JType( "double" ); public static final JType FLOAT = new JType( "float" ); public static final JType INT = new JType( "int" ); public static final JType LONG = new JType( "long" ); public static final JType SHORT = new JType( "short" ); private String name = null; private boolean _isArray = false; /** * used for array types **/ private JType _componentType = null; /** * Creates a new JType with the given name * @param the name of the type **/ public JType( String name ) { super(); this.name = name; } //-- JType /** * Creates a JType Object representing an array of the current * JType. * @return the new JType which is represents an array. * @deprecated removed in javasource 1.3rc1, replaced by JArrayType **/ public final JType createArray() { JType jType = new JType( getName() ); jType._isArray = true; jType._componentType = this; return jType; } //-- createArray /** * If this JType is an array this method will returns the component type * of the array, otherwise null will be returned. * @return the component JType if this JType is an array, otherwise null. **/ public JType getComponentType() { return _componentType; } //-- getComponentType public String getLocalName() { //-- use getName method in case it's been overloaded String name = getName(); if ( name == null ) return null; int idx = name.lastIndexOf( '.' ); if ( idx >= 0 ) { name = name.substring( idx + 1 ); } return name; } //-- getLocalName public String getName() { return this.name; } //-- getName /** * Checks to see if this JType represents an array. * @return true if this JType represents an array, otherwise false **/ public final boolean isArray() { return _isArray; } /** * Checks to see if this JType represents a primitive * @return true if this JType represents a primitive, otherwise false **/ public boolean isPrimitive() { return ( ( this == BOOLEAN ) || ( this == BYTE ) || ( this == CHAR ) || ( this == DOUBLE ) || ( this == FLOAT ) || ( this == INT ) || ( this == LONG ) || ( this == SHORT ) ); } //-- isPrimitive /** * Returns the String representation of this JType, which is * simply the name of this type. * @return the String representation of this JType **/ public String toString() { if ( _isArray ) return _componentType.toString() + "[]"; else return this.name; } //-- toString //---------------------/ //- Protected methods -/ //---------------------/ /** * Allows subtypes, such as JClass to alter the package to which * this JType belongs * @param newPackage the new package to which this JType belongs *
* Note: The package name cannot be changed on a primitive type. **/ protected void changePackage( String newPackage ) { if ( this.name == null ) return; if ( this.isPrimitive() ) return; String localName = null; int idx = name.lastIndexOf( '.' ); if ( idx >= 0 ) localName = this.name.substring( idx + 1 ); else localName = this.name; if ( ( newPackage == null ) || ( newPackage.length() == 0 ) ) this.name = localName; else this.name = newPackage + "." + localName; } //-- changePackage } //-- JType ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethod.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000003310611231735057032700 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved. * * $Id: JMethod.java 1297 2009-07-23 01:17:35Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Vector; /** * A class which holds information about the methods of * a JClass. * Modelled closely after the Java Reflection API. * This class is part of package which is used to * create source code. * @author Keith Visco * @version $Revision: 1297 $ $Date: 2009-07-23 03:17:35 +0200 (Do, 23. Jul 2009) $ **/ public class JMethod implements JMember { /** * The set of classes that contain this JMethod. **/ private Vector _classes = null; /** * The JavaDoc comment for this JMethod. This * will overwrite the JavaDoc for the * JMethodSignature. **/ private JDocComment jdc = null; /** * The source code for this method **/ private JSourceCode source = null; /** * The signature for this method. **/ private JMethodSignature _signature = null; /** * The annotation(s) for this method. */ private JAnnotations annotations = null; /** * Creates a new JMethod with the given name and "void" return type. * * @param name, the method name. Must not be null. **/ public JMethod( String name ) { this( name, null, null ); } //-- JMethod /** * Creates a new JMethod with the given name and returnType. * For "void" return types, simply pass in null as the returnType. * * @param name, the method name. Must not be null. * @param returnType the return type of the method. May be null. * @deprecated removed in future version of javasource **/ public JMethod( JType returnType, String name ) { this( name, returnType, null ); } //-- JMethod /** * Creates a new JMethod with the given name and returnType. * For "void" return types, simply pass in null as the returnType. * * @param name, the method name. Must not be null. * @param returnType the return type of the method. May be null. * @param returnDoc Javadoc comment for the @return annotation. If * null, a default (and mostly useless) javadoc comment will be * generated. **/ public JMethod( final String name, final JType returnType, final String returnDoc ) { if ( ( name == null ) || ( name.length() == 0 ) ) { String err = "The method name must not be null or zero-length"; throw new IllegalArgumentException( err ); } _classes = new Vector( 1 ); this.source = new JSourceCode(); _signature = new JMethodSignature( name, returnType ); this.jdc = _signature.getJDocComment(); jdc.appendComment( "Method " + name + "." ); //-- create comment if ( returnType != null ) { if ( returnDoc != null && returnDoc.length() > 0 ) { jdc.addDescriptor( JDocDescriptor.createReturnDesc( returnDoc ) ); } else { jdc.addDescriptor( JDocDescriptor.createReturnDesc( returnType.getLocalName() ) ); } } } /** * Adds the given Exception to this Method's throws clause. * * @param exp the JClass representing the Exception **/ public void addException( JClass exp ) { _signature.addException( exp ); } //-- addException /** * Adds the given parameter to this JMethod's list of parameters. * * @param parameter the parameter to add to the this Methods * list of parameters. * @throws java.lang.IllegalArgumentException when a parameter already * exists for this Method with the same name as the new parameter **/ public void addParameter( JParameter parameter ) throws IllegalArgumentException { _signature.addParameter( parameter ); } //-- addParameter /** * Returns the JDocComment describing this member. * @return the JDocComment describing this member. **/ public JDocComment getJDocComment() { return this.jdc; } //-- getJDocComment /** * Returns the class in which this JMember has been declared * @return the class in which this JMember has been declared ** public JClass getDeclaringClass() { return _declaringClass; } //-- getDeclaringClass */ /** * Returns the exceptions that this JMember throws. * * @return the exceptions that this JMember throws. **/ public JClass[] getExceptions() { return _signature.getExceptions(); } //-- getExceptions /** * Returns the modifiers for this JMember. * * @return the modifiers for this JMember. **/ public JModifiers getModifiers() { return _signature.getModifiers(); } //-- getModifiers /** * Returns the name of this JMember. * * @return the name of this JMember. **/ public String getName() { return _signature.getName(); } //-- getName /** * Returns the JParameter at the given index. * * @param index the index of the JParameter to return. * @return the JParameter at the given index. **/ public JParameter getParameter( int index ) { return _signature.getParameter( index ); } //-- getParameter /** * Returns the set of JParameters for this JMethod. *
* Note: the array is a copy, the params in the array * are the actual references. * * @return the set of JParameters for this JMethod **/ public JParameter[] getParameters() { return _signature.getParameters(); } //-- getParameters /** * Returns the JType that represents the return type of the method. * * @return the JType that represents the return type of the method. **/ public JType getReturnType() { return _signature.getReturnType(); } //-- getReturnType /** * Returns the JMethodSignature for this JMethod. * * @return the JMethodSignature for this JMethod. **/ public JMethodSignature getSignature() { return _signature; } //-- getSignature /** * Returns the JSourceCode for the method body. * * @return the JSourceCode for the method body. **/ public JSourceCode getSourceCode() { return this.source; } //-- getSourceCode /** * Sets the comment describing this member. The comment * will be printed when this member is printed with the * Class Printer. * * @param comment the comment for this member * @see #getJDocComment **/ public void setComment( String comment ) { jdc.setComment( comment ); } //-- setComment /** * Sets the JModifiers for this JMethod. This * JMethod will use only a copy of the JModifiers. * Note: The JModifiers will be set in the * containing JMethodSignature. If the JMethodSignature * is used by other methods, keep in mind that it will be * changed. * * @param modifiers the JModifiers to set. **/ public void setModifiers( JModifiers modifiers ) { _signature.setModifiers( modifiers ); } //-- setModifiers /** * Sets the given string as the source code (method body) * for this JMethod. * * @param source the String that represents the method body. **/ public void setSourceCode( String source ) { this.source = new JSourceCode( source ); } //-- setSource /** * Sets the given JSourceCode as the source code (method body) * for this JMethod. * * @param source the JSourceCode that represents the method body. **/ public void setSourceCode( JSourceCode source ) { this.source = source; } //-- setSource; /** * Prints this JMethod to the given JSourceWriter. * * @param jsw the JSourceWriter to print to. **/ public void print( JSourceWriter jsw ) { //------------/ //- Java Doc -/ //------------/ jdc.print( jsw ); //--------------------/ // - Annotations -/ //--------------------/ JAnnotations annotations = getAnnotations(); if ( annotations != null ) annotations.print( jsw ); //--------------------/ //- Method Signature -/ //--------------------/ _signature.print( jsw, false ); if ( _signature.getModifiers().isAbstract() ) { jsw.writeln( ";" ); } else { jsw.writeln(); jsw.writeln( "{" ); source.print( jsw ); jsw.write( "} //-- " ); jsw.writeln( toString() ); } } //-- print /** * Returns the String representation of this JMethod, * which is the method prototype. * @return the String representation of this JMethod, which * is simply the method prototype **/ public String toString() { return _signature.toString(); } //-- toString //---------------------/ //- PROTECTED METHODS -/ //---------------------/ /** * Adds the given JClass to the set of classes that * contain this method. * * @param jClass the JClass to add as one of * the JClasses that contain this method. **/ protected void addDeclaringClass( JClass jClass ) { _classes.addElement( jClass ); } //-- addDeclaringClass /** * Removes the given JClass from the set of classes that * contain this method. * * @param jClass the JClass to add as one of * the JClasses that contain this method. **/ protected void removeDeclaringClass( JClass jClass ) { _classes.removeElement( jClass ); } //-- removeDeclaringClass protected String[] getParameterClassNames() { return _signature.getParameterClassNames(); } //-- getParameterClassNames /** * @return the annotations */ public JAnnotations getAnnotations() { return annotations; } /** * @param annotation the annotation to append */ public void appendAnnotation( String annotation ) { if ( annotations == null ) { annotations = new JAnnotations(); } annotations.appendAnnotation( annotation ); } /** * @param annotations the annotations to set */ public void setAnnotations( JAnnotations annotations ) { this.annotations = annotations; } } //-- JMember ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceWriter.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000003654011230437043032676 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. * * $Id: JSourceWriter.java 1292 2009-07-18 21:26:59Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.Writer; /** * The writer used by the modello classes * @author Keith Visco * @version $Revision: 1292 $ $Date: 2009-07-18 23:26:59 +0200 (Sa, 18. Jul 2009) $ **/ public class JSourceWriter extends Writer { /** * The default character to use for indentation **/ public static final char DEFAULT_CHAR = ' '; /** * The default indentation size **/ public static final short DEFAULT_SIZE = 4; /** * The line separator to use for the writeln methods **/ private String lineSeparator = System.getProperty( "line.separator" ); /** * Flag for indicating whether we need to add * the whitespace to beginning of next write * call **/ private boolean addIndentation = true; /** * A flag indicating whether this JSourceWriter should perform * autoflush at the end of a new line **/ private boolean autoflush = false; /** * The tab (indentation) size **/ private short tabSize = DEFAULT_SIZE; /** * The tab representation **/ private char[] tab; /** * The character to use for indentation **/ private char tabChar = DEFAULT_CHAR; /** * The current tab level **/ private short tabLevel = 0; /** * The writer to send all output to **/ private Writer out = null; /** * Creates a new JSourceWriter * @param out the Writer to write the actual output to **/ public JSourceWriter( Writer out ) { this( out, DEFAULT_SIZE, DEFAULT_CHAR, false ); } //-- JSourceWriter /** * Creates a new JSourceWriter * @param out the Writer to write the actual output to * @param autoflush a boolean indicating whether or not to * perform automatic flush at the end of a line **/ public JSourceWriter( Writer out, boolean autoflush ) { this( out, DEFAULT_SIZE, DEFAULT_CHAR, autoflush ); } //-- JSourceWriter /** * Creates a new JSourceWriter * @param out the Writer to write the actual output to * @param tabSize the size of each indentation * @param autoflush a boolean indicating whether or not to * perform automatic flush at the end of a line **/ public JSourceWriter ( Writer out, short tabSize, boolean autoflush ) { this( out, tabSize, DEFAULT_CHAR, autoflush ); } //-- JSourceWriter /** * Creates a new JSourceWriter * @param out the Writer to write the actual output to * @param tabSize the size of each indentation * @param tabChar the character to use for indentation * @param autoflush a boolean indicating whether or not to * perform automatic flush at the end of a line **/ public JSourceWriter ( Writer out, short tabSize, char tabChar, boolean autoflush ) { this.out = out; this.autoflush = autoflush; this.tabChar = tabChar; this.tabSize = tabSize; createTab(); } //-- JSourceWriter /** * Returns the line separator being used by this JSourceWriter * @return the line separator being used by this JSourceWriter **/ public String getLineSeparator() { return lineSeparator; } //-- getLineSeparator /** * Increases the indentation level by 1 **/ public void indent() { ++tabLevel; } //-- increaseIndent /** * Checks to see if the cursor is positioned on a new line * @return true if the cursor is at the start of a new line, otherwise false **/ public boolean isNewline() { //-- if we need to add indentation, we are on a new line return addIndentation; } //-- isNewline /** * Sets the line separator to use at the end of each line * @param lineSeparator the String to use as a line * separator. *
* Typically a line separator will be one of the following: *
* "\r\n" for MS Windows
* "\n" for UNIX
* "\r" for Macintosh **/ public void setLineSeparator( String lineSeparator ) { this.lineSeparator = lineSeparator; } //-- setLineSeparator /** * Decreases the indentation level by 1 **/ public void unindent() { if ( tabLevel > 0 ) --tabLevel; } //-- decreaseIndent //----------------------------/ //- Additional write methods -/ //----------------------------/ public void write( float f ) { write( String.valueOf( f ) ); } //-- write(float) public void write( long l ) { write( String.valueOf( l ) ); } //-- write(long) public void write( double d ) { write( String.valueOf( d ) ); } //-- write(double) public void write( Object obj ) { write( obj.toString() ); } //-- write(Object) public void write( boolean b ) { write( String.valueOf( b ) ); } //-- write(boolean) //- writeln() methods public void writeln() { synchronized ( lock ) { linefeed(); addIndentation = true; } } //-- writeln public void writeln( float f ) { synchronized ( lock ) { ensureIndent(); try { out.write( String.valueOf( f ) ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(float) public void writeln( long l ) { synchronized ( lock ) { ensureIndent(); try { out.write( String.valueOf( l ) ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(long) public void writeln( int i ) { synchronized ( lock ) { ensureIndent(); try { out.write( String.valueOf( i ) ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(int) public void writeln( double d ) { synchronized ( lock ) { ensureIndent(); try { out.write( String.valueOf( d ) ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(double) public void writeln( Object obj ) { synchronized ( lock ) { ensureIndent(); try { out.write( obj.toString() ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(Object) public void writeln( String string ) { synchronized ( lock ) { if ( string.length() > 0 ) { ensureIndent(); try { out.write( string ); } catch ( java.io.IOException ioe ) { } } linefeed(); addIndentation = true; } } //-- writeln(String) public void writeln( char[] chars ) { synchronized ( lock ) { ensureIndent(); try { out.write( chars ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(char[]) public void writeln( boolean b ) { synchronized ( lock ) { ensureIndent(); try { out.write( String.valueOf( b ) ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(boolean) public void writeln( char c ) { synchronized ( lock ) { ensureIndent(); try { out.write( c ); } catch ( java.io.IOException ioe ) { } ; linefeed(); addIndentation = true; } } //-- writeln(char) //-----------------------/ //- Methods from Writer -/ //-----------------------/ public void close() { try { out.close(); } catch ( java.io.IOException ioe ) { } ; } //-- close public void flush() { try { out.flush(); } catch ( java.io.IOException ioe ) { } ; } //-- flush public void write( String s, int off, int len ) { synchronized ( lock ) { ensureIndent(); try { out.write( s, off, len ); } catch ( java.io.IOException ioe ) { } ; if ( autoflush ) flush(); } } //-- write public void write( String s ) { synchronized ( lock ) { ensureIndent(); try { out.write( s ); } catch ( java.io.IOException ioe ) { } ; if ( autoflush ) flush(); } } //-- write public void write( char[] buf ) { synchronized ( lock ) { ensureIndent(); try { out.write( buf ); } catch ( java.io.IOException ioe ) { } ; if ( autoflush ) flush(); } } //-- write public void write( int c ) { synchronized ( lock ) { ensureIndent(); try { out.write( c ); } catch ( java.io.IOException ioe ) { } ; if ( autoflush ) flush(); } } //-- write public void write( char[] buf, int off, int len ) { synchronized ( lock ) { ensureIndent(); try { out.write( buf, off, len ); } catch ( java.io.IOException ioe ) { } ; if ( autoflush ) flush(); } } //-- write //---------------------/ //- Protected Methods -/ //---------------------/ protected short getIndentLevel() { return tabLevel; } /** * Returns the current indent size (getIndentLevel()*tabSize); * @return the current indent size **/ protected short getIndentSize() { return (short) ( tabLevel * tabSize ); } //-- getIndentSize protected char getIndentChar() { return tabChar; } protected void writeIndent() { try { for ( int i = 0; i < tabLevel; i++ ) out.write( tab ); } catch ( java.io.IOException ioe ) { } ; } //-- writeIndent //-------------------/ //- Private Methods -/ //-------------------/ private void ensureIndent() { if ( addIndentation ) { writeIndent(); addIndentation = false; } } //-- ensureIndent /** * writes the line separator character to the writer **/ private void linefeed() { try { out.write( lineSeparator ); } catch ( java.io.IOException ioe ) { } ; } //-- linefeed /** * Creates the tab from the tabSize and the tabChar **/ private void createTab() { tab = new char[tabSize]; for ( int i = 0; i < tabSize; i++ ) { tab[i] = tabChar; } } //-- createTab } //-- JSourceWriter ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCollectionType.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000000630311123536732032676 0ustar mkochmkoch/* * Copyright 2006 Werner Guttmann * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.modello.plugin.java.javasource; /** * JType sub-class for collections. * * @author Werner Guttman * @version $Revision: 1041 $ $Date: 2008-12-21 23:06:18 +0100 (So, 21. Dez 2008) $ * @since 1.0.4 */ public final class JCollectionType extends JComponentizedType { // -------------------------------------------------------------------------- /** Name of the actual collection instance to be used, e.g. java.util.ArrayList. */ private String _instanceName; // -------------------------------------------------------------------------- /** * Creates an instance of a collection type, of type 'collectionName'. * * @param typeName Name of the collection type interface. * @param componentType Component type. * @param useJava50 True if Java 5.0 should be used. */ public JCollectionType( final String typeName, final JType componentType, final boolean useJava50 ) { super( typeName, componentType, useJava50 ); } /** * Creates an instance of a collection type, of type 'collectionName'. * * @param typeName Name of the collection type interface. * @param instanceName Name of the actual collection type instance. * @param componentType Component type. * @param useJava50 True if Java 5.0 should be used. */ public JCollectionType( final String typeName, final String instanceName, final JType componentType, final boolean useJava50 ) { super( typeName, componentType, useJava50 ); _instanceName = instanceName; } // -------------------------------------------------------------------------- /** * Returns the instance name of this collection type. * * @return The instance name of this collection type. */ public String getInstanceName() { if ( _instanceName != null ) { if ( isUseJava50() ) { return _instanceName + "<" + getComponentType().toString() + ">"; } return _instanceName + "/*<" + getComponentType().toString() + ">*/"; } return toString(); } /** * {@inheritDoc}
* Returns the String representation of this JType. */ public String toString() { if ( isUseJava50() ) { return getName() + "<" + getComponentType().toString() + ">"; } return getName() + "/*<" + getComponentType().toString() + ">*/"; } // -------------------------------------------------------------------------- } ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocDescriptor.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000002673610664275111032712 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. * * $Id: JDocDescriptor.java 858 2007-08-26 13:04:09Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * A descriptor for a JavaDoc comment * @author Keith Visco * @version $Revision: 858 $ $Date: 2007-08-26 15:04:09 +0200 (So, 26. Aug 2007) $ **/ public class JDocDescriptor { /** * The default version string **/ //-- separated using "+" so that CVS doesn't expand public static final String DEFAULT_VERSION = "$" + "Revision" + "$ $" + "Date" + "$"; //-- These are listed in order of how they should //-- appear in a JavaDoc list, so the numbers //-- are important...see #compareTo /** * The param descriptor (param) **/ public static final short PARAM = 0; /** * The exception descriptor (exception) **/ public static final short EXCEPTION = 1; /** * The return descriptor (return) **/ public static final short RETURN = 2; /** * The author descriptor **/ public static final short AUTHOR = 3; /** * the version descriptor (version) **/ public static final short VERSION = 4; /** * The reference descriptor (see) **/ public static final short REFERENCE = 5; private String description = null; private String name = null; private short type = -1; /** * Creates a new JDocDescriptor **/ private JDocDescriptor( short type ) { this.type = type; } //-- JDocDescriptor /** * Creates a new JDocDescriptor * @param name the name string for this descriptor * @param desc the description string for this descriptor **/ private JDocDescriptor( short type, String name, String desc ) { this.type = type; this.name = name; this.description = desc; } //-- JDocDescriptor /** * Compares the type of this JDocDescriptor with the given descriptor. * Enables sorting of descriptors. * @return 0 if the two descriptor types are equal, 1 if the type of * this descriptor is greater than the given descriptor, or -1 if the * type of this descriptor is less than the given descriptor **/ protected short compareTo( JDocDescriptor jdd ) { short jddType = jdd.getType(); if ( jddType == this.type ) return 0; // The ordering is as follows // #param // #exception // #author // #version // #see (reference) // return (short) ( ( jddType < this.type ) ? 1 : -1 ); } //-- compareTo /** * Creates a new author descriptor * @return the new JDocDescriptor **/ public static JDocDescriptor createAuthorDesc() { return new JDocDescriptor( AUTHOR ); } //-- createAuthorDesc /** * Creates a new author descriptor * @param name the author name string * @return the new JDocDescriptor **/ public static JDocDescriptor createAuthorDesc( String name ) { return new JDocDescriptor( AUTHOR, name, null ); } //-- createAuthorDesc /** * Creates a new exception descriptor * @return the new JDocDescriptor **/ public static JDocDescriptor createExceptionDesc() { return new JDocDescriptor( EXCEPTION ); } //-- createExceptionDesc /** * Creates a new exception descriptor * @param name the exception name * @param desc the description of when the exception is called * @return the new JDocDescriptor **/ public static JDocDescriptor createExceptionDesc ( String name, String desc ) { return new JDocDescriptor( EXCEPTION, name, desc ); } //-- createExceptionDesc /** * Creates a new param descriptor * @return the new JDocDescriptor **/ public static JDocDescriptor createParamDesc() { return new JDocDescriptor( PARAM ); } //-- createParamDesc /** * Creates a new param descriptor * @param name the param name * @param desc the param description string * @return the new JDocDescriptor **/ public static JDocDescriptor createParamDesc( String name, String desc ) { return new JDocDescriptor( PARAM, name, desc ); } //-- createParamDesc /** * Creates a new reference descriptor * @return the new JDocDescriptor **/ public static JDocDescriptor createReferenceDesc() { return new JDocDescriptor( REFERENCE ); } //-- createReferenceDesc /** * Creates a new reference descriptor * @param name the reference name string * @return the new JDocDescriptor **/ public static JDocDescriptor createReferenceDesc( String name ) { return new JDocDescriptor( REFERENCE, name, null ); } //-- createReferenceDesc /** * Creates a new return descriptor * @return the new JDocDescriptor **/ public static JDocDescriptor createReturnDesc() { return new JDocDescriptor( RETURN ); } //-- createReferenceDesc /** * Creates a new return descriptor * @param desc the return description * @return the new JDocDescriptor **/ public static JDocDescriptor createReturnDesc( String desc ) { return new JDocDescriptor( RETURN, null, desc ); } //-- createReturnDesc /** * Creates a new version descriptor * @return the new JDocDescriptor **/ public static JDocDescriptor createVersionDesc() { return new JDocDescriptor( VERSION ); } //-- createVersionDesc /** * Creates a new version descriptor * @param version the version string * @return the new JDocDescriptor **/ public static JDocDescriptor createVersionDesc( String version ) { return new JDocDescriptor( VERSION, null, version ); } //-- createVersionDesc /** * Returns the description String for this descriptor * @return the description string for this descriptor **/ public String getDescription() { return description; } //-- getDescription /** * Returns the name of the object being described. This * is valid for the following fields:
*

    *
  • author
  • *
  • exception
  • *
  • param
  • *
  • see
  • *
* @return the name of the object being described. This **/ public String getName() { return name; } //-- getName /** * Returns the type of this JDocDescriptor * @return the type of this JDocDescriptor **/ public short getType() { return this.type; } //-- getType /** * Sets the description String for this descriptor * @param desc the description of the object being described **/ public void setDescription( String desc ) { this.description = desc; } //-- setDescription /** * Sets the name value of the JavaDoc field. This is * only valid for the following fields:
*
    *
  • author
  • *
  • exception
  • *
  • param
  • *
  • see
  • *
* @param name the name value of the JavaDoc field **/ public void setName( String name ) { this.name = name; } //-- setName /** * Returns the String representation of this JDocDescriptor * @return the String representation of this JDocDescriptor **/ public String toString() { StringBuffer sb = new StringBuffer(); boolean allowName = true; switch ( type ) { case AUTHOR: sb.append( "@author" ); break; case EXCEPTION: sb.append( "@throws" ); break; case PARAM: sb.append( "@param" ); break; case REFERENCE: sb.append( "@see" ); break; case RETURN: sb.append( "@return" ); break; case VERSION: allowName = false; sb.append( "@version" ); break; default: break; } if ( ( name != null ) && allowName ) { sb.append( ' ' ); sb.append( name ); } if ( description != null ) { sb.append( ' ' ); sb.append( description ); } return sb.toString(); } //-- toString } //-- JDocDescriptor ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JParameter.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000001412411232357651032700 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. * * $Id: JParameter.java 1299 2009-07-24 16:22:01Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * Represents a parameter to a JMethod. * @author Keith Visco * @version $Revision: 1299 $ $Date: 2009-07-24 18:22:01 +0200 (Fr, 24. Jul 2009) $ **/ public class JParameter { /** * The type associated with this JParameter **/ private JType type = null; /** * The name of this JParameter **/ private String name = null; private JAnnotations annotations = null; /** * Creates a new JParameter with the given type, and name * @param type the type to associate with this JParameter * @param the name of the JParameter **/ public JParameter( JType type, String name ) throws IllegalArgumentException { super(); setType( type ); setName( name ); } //-- JParameter /** * Returns the name of the parameter * @return the name of the parameter **/ public String getName() { return this.name; } //-- getName /** * Returns the parameter type * @return the parameter type **/ public JType getType() { return this.type; } //-- getType /** * Sets the name of this parameter * @param name the new name of the parameter **/ public void setName( String name ) { this.name = name; } //-- setName /** * Sets the type of this parameter * @param type the new type of this parameter **/ public void setType( JType type ) throws IllegalArgumentException { if ( type == null ) { String err = "A Parameter cannot have a null type."; throw new IllegalArgumentException( err ); } this.type = type; } //-- setType /** * Returns the String representation of this JParameter. The * String returns will consist of the String representation * of the parameter type, followed by the name of the parameter * @return the String representation of this JParameter **/ public String toString() { StringBuffer sb = new StringBuffer(); if ( annotations != null ) { sb.append( annotations.toString() ); sb.append( ' ' ); } sb.append( this.type.toString() ); sb.append( ' ' ); sb.append( this.name ); return sb.toString(); } //-- toString /** * @return the annotations */ public JAnnotations getAnnotations() { return annotations; } /** * @param annotation the annotation to append */ public void appendAnnotation( String annotation ) { if ( annotations == null ) { annotations = new JAnnotations(); } annotations.appendAnnotation( annotation ); } /** * @param annotations the annotations to set */ public void setAnnotations( JAnnotations annotations ) { this.annotations = annotations; } } //-- JParamater././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethodSignature.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000003210211121002344032653 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved. * * $Id: JMethodSignature.java 1005 2008-12-13 18:54:28Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Vector; /** * A class which holds information about the signature * of a JMethod. * * The code in this package was modelled after the Java Reflection API * as much as possible to reduce the learning curve. * * @author Keith Visco * @version $Id: JMethodSignature.java 1005 2008-12-13 18:54:28Z hboutemy $ **/ public final class JMethodSignature { /** * The set of modifiers for this JMethod **/ private JModifiers modifiers = null; /** * The return type of this Method **/ private JType returnType = null; /** * The name of this method **/ private String name = null; /** * The list of parameters of this JMethodSignature in declared * order **/ private JNamedMap params = null; /** * The JavaDoc comment for this method signature. **/ private JDocComment jdc = null; /** * The exceptions that this method throws **/ private Vector exceptions = null; /** * Creates a new method with the given name and return type. * For "void" return types, simply pass in null as the returnType * * @param name, the method name. Must not be null. * @param returnType the return type of the method. May be null. **/ public JMethodSignature( String name, JType returnType ) { if ( ( name == null ) || ( name.length() == 0 ) ) { String err = "The method name must not be null or zero-length"; throw new IllegalArgumentException( err ); } this.jdc = new JDocComment(); this.returnType = returnType; this.name = name; this.modifiers = new JModifiers(); this.params = new JNamedMap( 3 ); this.exceptions = new Vector( 1 ); } //-- JMethodSignature /** * Adds the given Exception to this JMethodSignature's throws clause. * * @param exp the JClass representing the Exception **/ public void addException( JClass exp ) { if ( exp == null ) return; //-- make sure exception is not already added String expClassName = exp.getName(); for ( int i = 0; i < exceptions.size(); i++ ) { JClass jClass = (JClass) exceptions.elementAt( i ); if ( expClassName.equals( jClass.getName() ) ) return; } //-- add exception exceptions.addElement( exp ); //-- create comment jdc.addDescriptor( JDocDescriptor.createExceptionDesc( expClassName, null ) ); } //-- addException /** * Adds the given parameter to this JMethodSignature's list of * parameters. * * @param parameter the parameter to add to the this Methods * list of parameters. * @throws java.lang.IllegalArgumentException when a parameter already * exists for this Method with the same name as the new * parameter. **/ public void addParameter( JParameter parameter ) throws IllegalArgumentException { if ( parameter == null ) return; String pName = parameter.getName(); //-- check current params if ( params.get( pName ) != null ) { StringBuffer err = new StringBuffer(); err.append( "A parameter already exists for this method, " ); err.append( name ); err.append( ", with the name: " ); err.append( pName ); throw new IllegalArgumentException( err.toString() ); } params.put( pName, parameter ); //-- create comment jdc.addDescriptor( JDocDescriptor.createParamDesc( pName, null ) ); } //-- addParameter /** * Returns the exceptions that this JMethodSignature lists * in it's throws clause. * * @return the exceptions that this JMethodSignature lists * in it's throws clause. **/ public JClass[] getExceptions() { JClass[] jclasses = new JClass[exceptions.size()]; exceptions.copyInto( jclasses ); return jclasses; } //-- getExceptions /** * Returns the JDocComment describing this JMethodSignature * * @return the JDocComment describing this JMethodSignature **/ public JDocComment getJDocComment() { return this.jdc; } //-- getJDocComment /** * Returns the modifiers for this JMethodSignature. * * @return the modifiers for this JMethodSignature. **/ public JModifiers getModifiers() { return this.modifiers; } //-- getModifiers /** * Returns the name of the method. * * @return the name of the method. **/ public String getName() { return this.name; } //-- getName /** * Returns the JParameter at the given index. * * @param index the index of the JParameter to return. * @return the JParameter at the given index. **/ public JParameter getParameter( int index ) { return (JParameter) params.get( index ); } //-- getParameter /** * Returns the set of JParameters for this JMethodSignature *
* Note: the array is a copy, the params in the array * are the actual references. * @return the set of JParameters for this JMethod **/ public synchronized JParameter[] getParameters() { JParameter[] pArray = new JParameter[params.size()]; for ( int i = 0; i < pArray.length; i++ ) { pArray[i] = (JParameter) params.get( i ); } return pArray; } //-- getParameters /** * Returns the JType that represents the return type for the * method signature. * * @return the JType that represents the return type for the * method signature. **/ public JType getReturnType() { return returnType; } //-- getReturnType /** * Sets the comment describing this JMethodSignature. * * @param comment the comment for this member * @see #getJDocComment **/ public void setComment( String comment ) { jdc.setComment( comment ); } //-- setComment /** * Sets the JModifiers for this method signature. * * @param modifiers the JModifiers for this method signature. **/ public void setModifiers( JModifiers modifiers ) { this.modifiers = modifiers.copy(); this.modifiers.setFinal( false ); } //-- setModifiers /** * Prints the method signature. A semi-colon (end-of-statement * terminator ';') will Not be printed. * * @param jsw the JSourceWriter to print to. **/ public void print( JSourceWriter jsw ) { print( jsw, true ); } //-- print /** * Prints the method signature. A semi-colon (end-of-statement * terminator ';') will Not be printed. * * @param jsw the JSourceWriter to print to. * @param printJavaDoc a boolean that when true prints the JDocComment * associated with this method signature. **/ public void print( JSourceWriter jsw, boolean printJavaDoc ) { //------------/ //- Java Doc -/ //------------/ if ( printJavaDoc ) jdc.print( jsw ); //-----------------/ //- Method Source -/ //-----------------/ jsw.write( modifiers.toString() ); if ( modifiers.toString().length() > 0 ) { jsw.write( ' ' ); } if ( returnType != null ) { jsw.write( returnType ); } else jsw.write( "void" ); jsw.write( ' ' ); jsw.write( name ); jsw.write( '(' ); //-- print parameters if ( params.size() > 0 ) { jsw.write( ' ' ); for ( int i = 0; i < params.size(); i++ ) { if ( i > 0 ) jsw.write( ", " ); jsw.write( params.get( i ) ); } jsw.write( ' ' ); } jsw.write( ')' ); if ( exceptions.size() > 0 ) { jsw.writeln(); jsw.write( " throws " ); for ( int i = 0; i < exceptions.size(); i++ ) { if ( i > 0 ) jsw.write( ", " ); JClass jClass = (JClass) exceptions.elementAt( i ); jsw.write( jClass.getName() ); } } } //-- print /** * Returns the String representation of this JMethod, * which is the method prototype. * @return the String representation of this JMethod, which * is simply the method prototype **/ public String toString() { StringBuffer sb = new StringBuffer(); if ( returnType != null ) { sb.append( returnType ); } else sb.append( "void" ); sb.append( ' ' ); sb.append( name ); sb.append( '(' ); //-- print parameters if ( params.size() > 0 ) { sb.append( ' ' ); for ( int i = 0; i < params.size(); i++ ) { JParameter jParam = (JParameter) params.get( i ); if ( i > 0 ) sb.append( ", " ); sb.append( jParam.getType().getName() ); } sb.append( ' ' ); } sb.append( ')' ); return sb.toString(); } //-- toString protected String[] getParameterClassNames() { Vector names = new Vector( params.size() ); for ( int i = 0; i < params.size(); i++ ) { JType jType = ( (JParameter) params.get( i ) ).getType(); while ( jType.isArray() ) jType = jType.getComponentType(); if ( !jType.isPrimitive() ) { JClass jclass = (JClass) jType; names.addElement( jclass.getName() ); } } String[] names_array = new String[names.size()]; names.copyInto( names_array ); return names_array; } //-- getParameterClassNames } //-- JMethodSignature././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JField.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000002057511231735057032706 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved. * * $Id: JField.java 1297 2009-07-23 01:17:35Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * A class which holds information about a field. * Modelled closely after the Java Reflection API. * This class is part of package which is used to * create source code in memory. * @author Keith Visco * @version $Revision: 1297 $ $Date: 2009-07-23 03:17:35 +0200 (Do, 23. Jul 2009) $ **/ public class JField implements JMember { /** * The set of modifiers for this JField **/ private JModifiers modifiers = null; private JType type = null; private String name = null; private JDocComment comment = null; private String initString = null; private JAnnotations annotations = null; /** * The Class in this JField has been declared **/ private JClass declaringClass = null; public JField( JType type, String name ) { setName( name ); this.type = type; this.modifiers = new JModifiers(); this.modifiers.makePrivate(); comment = new JDocComment(); comment.appendComment( "Field " + name + "." ); annotations = new JAnnotations(); } //-- JField /** * Returns the comment describing this member. * @return the comment describing this member, or * null if no comment has been set. **/ public JDocComment getComment() { return this.comment; } //-- getComment /** * Returns the class in which this JField has been declared * @return the class in which this JField has been declared **/ public JClass getDeclaringClass() { return this.declaringClass; } //-- getDeclaringClass /** * Returns the initialization String for this JField * @return the initialization String for this JField, * or null if no initialization String was specified. **/ public String getInitString() { return initString; } //-- getInitString /** * Returns the modifiers for this JField * @return the modifiers for this JField **/ public JModifiers getModifiers() { return this.modifiers; } //-- getModifiers /** * Returns the name of this JField * @return the name of this JField **/ public String getName() { return this.name; } //-- getName /** * Returns the JType represting the type of this JField * @return the JClass represting the type of this JField **/ public JType getType() { return this.type; } //-- getType /** * Sets the comment describing this member. * @param comment the JDocComment for this member **/ public void setComment( JDocComment comment ) { this.comment = comment; } //-- setComment /** * Sets the comment describing this member. * @param comment the JDocComment for this member **/ public void setComment( String comment ) { if ( this.comment == null ) { this.comment = new JDocComment(); } this.comment.setComment( comment ); } //-- setComment /** * Sets the initialization string for this JField; * Allows some flexibility in declaring default values. * @param init the initialization string for this member. **/ public void setInitString( String init ) { this.initString = init; } //-- setInitString /** * Sets the name of this JField * @param name the name of this JField * @exception java.lang.IllegalArgumentException when the * name is not a valid Java member name, or if a member * with the given name already exists in the declaring class **/ public void setName( String name ) throws IllegalArgumentException { if ( !JNaming.isValidJavaIdentifier( name ) ) { String err = "'" + name + "' is "; if ( JNaming.isKeyword( name ) ) err += "a reserved word and may not be used as " + " a field name."; else err += "not a valid Java identifier."; throw new IllegalArgumentException( err ); } this.name = name; } //-- setName public void setModifiers( JModifiers modifiers ) { this.modifiers = modifiers; } //-- setModifiers protected void setDeclaringClass( JClass declaringClass ) { this.declaringClass = declaringClass; } //-- setDeclaringClass public String toString() { StringBuffer sb = new StringBuffer(); sb.append( modifiers.toString() ); sb.append( ' ' ); sb.append( type ); sb.append( ' ' ); sb.append( name ); return sb.toString(); } //-- toString /** * @return the annotations */ public JAnnotations getAnnotations() { return annotations; } /** * @param annotation the annotation to append */ public void appendAnnotation( String annotation ) { if ( annotations == null ) { annotations = new JAnnotations(); } annotations.appendAnnotation( annotation ); } /** * @param annotations the annotations to set */ public void setAnnotations( JAnnotations annotations ) { this.annotations = annotations; } } //-- JField ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMember.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000000777611231735057032716 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved. * * $Id: JMember.java 1297 2009-07-23 01:17:35Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * An interface which represents a Member of a JClass, * modelled closely after the Java Reflection API. * This class is part of a package used to represent * source code. * @author Keith Visco * @version $Revision: 1297 $ $Date: 2009-07-23 03:17:35 +0200 (Do, 23. Jul 2009) $ **/ interface JMember { /** * Returns the class in which this JMember has been declared * @return the class in which this JMember has been declared **/ //public JClass getDeclaringClass(); /** * Returns the modifiers for this JMember * @return the modifiers for this JMember **/ public JModifiers getModifiers(); /** * Returns the name of this JMember * @return the name of this JMember **/ public String getName(); public JAnnotations getAnnotations(); } //-- JMember ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCompUnit.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000004716310651463677032723 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2001-2002 (C) Intalio, Inc. All Rights Reserved. * * Contributors: * -------------- * Gary Shea (shea@gtsdesign.com) - Original Author * Keith Visco (kvisco@intalio.com) - Changed JCompElement references to * JStructure, some additional tweaking * to get it working with the current * Javasource package. * * $Id: JCompUnit.java 848 2007-07-24 20:57:35Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.util.Enumeration; import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; import java.util.Vector; import org.codehaus.plexus.util.WriterFactory; /** * A representation of the Java Source code for a Java compilation * unit. This is * a useful utility when creating in memory source code. * This package was modelled after the Java Reflection API * as much as possible to reduce the learning curve. * @author Gary Shea * @version $Revision: 848 $ $Date: 2007-07-24 22:57:35 +0200 (Di, 24. Jul 2007) $ **/ public class JCompUnit { /** * The Id for Source control systems * I needed to separate this line to prevent CVS from * expanding it here! ;-) **/ private static final String DEFAULT_HEADER = "$" + "Id$"; private JComment header = null; /** * The package for this JCompUnit **/ private String packageName = null; /** * The file to which this JCompUnit will be saved **/ private String fileName = null; /** * The set of top-level classes that live in this compilation unit. **/ //private TypeList classes = null; private Vector classes = null; /** * The set of top-level interfaces that live in this compilation unit. **/ //private TypeList interfaces = null; private Vector interfaces = null; /** * Creates a new JCompUnit * @param packageName the name of the package for this JCompUnit. * If packageName is null or empty, no 'package' line will be generated. * @param fileName the name of the file in which this JCompUnit * will be stored **/ public JCompUnit( String packageName, String fileName ) { this.packageName = packageName; this.fileName = fileName; init(); } //-- JCompUnit /** * Creates a new JCompUnit with the given JClass (which must have * been created with either a full class name or package/local * name) as the public class. Package and file name are taken * from jClass. * @param jClass the public class for this JCompUnit. **/ public JCompUnit( JClass jClass ) { this.packageName = jClass.getPackageName(); // The outer name is the package plus the simple name of the // outermost enclosing class. The file name is just the // simple name of the outermost enclosing class, so the // package name part must be stripped off. /* Commented out until inner-class support has been added. kvisco - 20021211 String outer = jClass.getOuterName(); int lastDot = outer.lastIndexOf("."); String filePrefix; if (lastDot != -1) { filePrefix = outer.substring (lastDot + 1); } else { filePrefix = outer; } */ String filePrefix = jClass.getLocalName(); this.fileName = filePrefix + ".java"; init(); classes.add( jClass ); } //-- JCompUnit /** * Creates a new JCompUnit with the given JInterface as public interface * Package and file name are taken from jInterface. * @param jInterface the public interface for this JCompUnit. **/ public JCompUnit( JInterface jInterface ) { this.packageName = jInterface.getPackageName(); this.fileName = jInterface.getLocalName() + ".java"; init(); interfaces.add( jInterface ); } //-- JCompUnit private void init() { classes = new Vector(); interfaces = new Vector(); } /** * Adds the given JStructure (either a JInterface or * a JClass) to this JCompUnit. * * @param jStructure the JStructure to add * @exception java.lang.IllegalArgumentException when the given * JStructure has the same name of an existing JStructure * or if the class of jStructure is unknown. */ public void addStructure( JStructure jStructure ) throws IllegalArgumentException { if ( jStructure instanceof JInterface ) addInterface( (JInterface) jStructure ); else if ( jStructure instanceof JClass ) addClass( (JClass) jStructure ); else { String err = "Unknown JStructure subclass '" + jStructure.getClass().getName() + "'."; throw new IllegalArgumentException( err ); } } //-- addStructure /** * Adds a JClass which should be printed in this file. **/ public void addClass( JClass jClass ) { classes.add( jClass ); } //-- addClass /** * Adds a JInterface which should be printed in this file. **/ public void addInterface( JInterface jInterface ) { interfaces.add( jInterface ); } //-- addInterface /** * returns a array of String containing all import classes/packages, * also imports within the same package of this object. * @return a array of String containing all import classes/packages, * also imports within the same package of this object. */ public SortedSet getImports() { SortedSet allImports = new TreeSet(); // add imports from classes for ( int i = 0; i < classes.size(); ++i ) { JClass jClass = (JClass) classes.get( i ); Enumeration e = jClass.getImports(); while ( e.hasMoreElements() ) { allImports.add( e.nextElement() ); } } for ( int i = 0; i < interfaces.size(); ++i ) { JInterface jInterface = (JInterface) interfaces.get( i ); Enumeration e = jInterface.getImports(); while ( e.hasMoreElements() ) { allImports.add( e.nextElement() ); } } return allImports; } /** * Returns the name of the file that this JCompUnit would be * printed as, given a call to #print. * * @param destDir the destination directory. This may be null. * @return the name of the file that this JCompUnit would be * printed as, given a call to #print. **/ public String getFilename( String destDir ) { String filename = new String( fileName ); //-- Convert Java package to path string String javaPackagePath = ""; if ( ( packageName != null ) && ( packageName.length() > 0 ) ) { javaPackagePath = packageName.replace( '.', File.separatorChar ); } //-- Create fully qualified path (including 'destDir') to file File pathFile; if ( destDir == null ) pathFile = new File( javaPackagePath ); else pathFile = new File( destDir, javaPackagePath ); if ( !pathFile.exists() ) { pathFile.mkdirs(); } //-- Prefix filename with path if ( pathFile.toString().length() > 0 ) filename = pathFile.toString() + File.separator + filename; return filename; } //-- getFilename /** * Returns the name of the package that this JCompUnit is a member of * @return the name of the package that this JCompUnit is a member of, * or null if there is no current package name defined **/ public String getPackageName() { return this.packageName; } //-- getPackageName protected static String getPackageFromClassName( String className ) { int idx = -1; if ( ( idx = className.lastIndexOf( '.' ) ) > 0 ) { return className.substring( 0, idx ); } return null; } //-- getPackageFromClassName /** * Prints the source code for this JClass in the current directory * with the default line seperator of the the runtime platform. * @see print(java.lang.String, java.lang.String) **/ public void print() { print( null, null ); } //-- print /** * Prints the source code for this JClass * with the default line seperator of the the runtime platform. * @param destDir the destination directory to generate the file. * @see print(java.lang.String, java.lang.String) **/ public void print( String destDir ) { print( destDir, null ); } //-- print /** * Prints the source code for this JCompUnit. * @param destDir the destination directory to generate the file. * @param lineSeparator the line separator to use at the end of each line. * If null, then the default line separator for the runtime platform will * be used. **/ public void print( String destDir, String lineSeparator ) { //-- open output file String filename = getFilename( destDir ); File file = new File( filename ); JSourceWriter jsw = null; try { jsw = new JSourceWriter( WriterFactory.newPlatformWriter( file ) ); } catch ( java.io.IOException ioe ) { System.out.println( "unable to create compilation unit file: " + filename ); return; } if ( lineSeparator == null ) { lineSeparator = System.getProperty( "line.separator" ); } jsw.setLineSeparator( lineSeparator ); print( jsw ); jsw.flush(); jsw.close(); } //-- print /** * Prints the source code for this JClass. * @param jsw the JSourceWriter to print to. **/ public void print( JSourceWriter jsw ) { // Traverse the nested class and interface heirarchy and // update the names to match the compilation unit. resolveNames(); StringBuffer buffer = new StringBuffer(); //-- write file header if ( header != null ) header.print( jsw ); else { jsw.writeln( "/*" ); jsw.writeln( " * " + DEFAULT_HEADER ); jsw.writeln( "*/" ); } jsw.writeln(); jsw.flush(); //-- print package name if ( ( packageName != null ) && ( packageName.length() > 0 ) ) { buffer.setLength( 0 ); buffer.append( "package " ); buffer.append( packageName ); buffer.append( ';' ); jsw.writeln( buffer.toString() ); jsw.writeln(); } //-- print imports jsw.writeln( " //---------------------------------------------/" ); jsw.writeln( " //- Imported classes, interfaces and packages -/" ); jsw.writeln( "//---------------------------------------------/" ); jsw.writeln(); SortedSet allImports = getImports(); String compUnitPackage = getPackageName(); Iterator iter = allImports.iterator(); while ( iter.hasNext() ) { String importName = (String) iter.next(); String importsPackage = JStructure.getPackageFromClassName( importName ); if ( importsPackage != null && !importsPackage.equals( compUnitPackage ) ) { jsw.write( "import " ); jsw.write( importName ); jsw.writeln( ';' ); } } jsw.writeln(); // Print the public elements, interfaces first, then classes. // There should only be one public element, but if there are // more we let the compiler catch it. printStructures( jsw, true ); // Print the remaining non-public elements, interfaces first. printStructures( jsw, false ); jsw.flush(); } //-- print /** * Print the source code for the contained JClass objects. * @param jsw the JSourceWriter to print to. * @param printPublic if true, print only public classes; if * false, print only non-public classes. **/ final public void printStructures( JSourceWriter jsw, boolean printPublic ) { //-- print class information //-- we need to add some JavaDoc API adding comments boolean isFirst = true; //SortedSet interfaceList = interfaces.sortedOnFullName(); for ( Enumeration e = interfaces.elements(); e.hasMoreElements(); ) { JInterface jInterface = (JInterface) e.nextElement(); if ( jInterface.getModifiers().isPublic() == printPublic ) { if ( isFirst ) { Header.print( jsw, printPublic ); isFirst = false; } jInterface.print( jsw, true ); jsw.writeln(); } } //SortedSet classList = classes.sortedOnFullName(); for ( Enumeration e = classes.elements(); e.hasMoreElements(); ) { JClass jClass = (JClass) e.nextElement(); if ( jClass.getModifiers().isPublic() == printPublic ) { if ( isFirst ) { Header.print( jsw, printPublic ); isFirst = false; } jClass.print( jsw, true ); jsw.writeln(); } } } //-- printElements(JSourceWriter, int) /** * Sets the header comment for this JCompUnit * @param comment the comment to display at the top of the source file * when printed **/ public void setHeader( JComment comment ) { this.header = comment; } //-- setHeader //-------------------/ //- Private Methods -/ //-------------------/ /** * Update the names of nested classes and interfaces. **/ private void resolveNames() { /* Commented out until support for inner-classes is added kvisco - 20021211 for (int i = 0; i < classes.size(); i++) { JClass jClass = (JClass) classes.get(i); jClass.resolveNames(packageName, null); } for (int i = 0; i < interfaces.size(); i++) { JInterface jInterface = (JInterface) interfaces.get(i); jInterface.resolveNames(packageName, null); } */ } //-- resolveNames /** * Test drive method...to be removed or commented out ** public static void main(String[] args) { JCompUnit unit = new JCompUnit("com.acme", "Test.java"); JClass testClass = new JClass("Test"); testClass.addImport("java.util.Vector"); testClass.addMember(new JField(JType.Int, "x")); JField field = null; field = new JField(JType.Int, "_z"); field.getModifiers().setStatic(true); testClass.addField(field); testClass.getStaticInitializationCode().add("_z = 75;"); JClass jcString = new JClass("String"); field = new JField(jcString, "myString"); field.getModifiers().makePrivate(); testClass.addMember(field); //-- create constructor JConstructor cons = testClass.createConstructor(); testClass.addConstructor(cons); cons.getSourceCode().add("this.x = 6;"); JMethod jMethod = new JMethod(JType.Int, "getX"); jMethod.setSourceCode("return this.x;"); testClass.addMethod(jMethod); unit.addClass (testClass); unit.print(); } //-- main /* */ } //-- JCompUnit /** * Print the headers delineating the public and non-public elements of * the compilation unit. **/ class Header { private static String[] publicHeader = { " //-----------------------------/", " //- Public Class / Interface -/", "//-----------------------------/", }; private static String[] nonPublicHeader = { " //-------------------------------------/", " //- Non-Public Classes / Interfaces -/", "//-------------------------------------/", }; /** * Print the specified header to the given Writer. * @params JSourceWriter an open JSourceWriter * @params boolean if true print the public header, otherwise * print the non-public header. **/ protected static void print( JSourceWriter jsw, boolean printPublic ) { String[] header = printPublic ? publicHeader : nonPublicHeader; for ( int j = 0; j < header.length; ++j ) { jsw.writeln( header[j] ); } jsw.writeln(); } } //-- Header ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocComment.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000001765310367232700032705 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2003 (C) Intalio, Inc. All Rights Reserved. * * $Id: JDocComment.java 555 2006-01-29 21:38:08Z jvanzyl $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Enumeration; import java.util.Vector; /** * A class that "SOMEWHAT" represents a Java Doc Comment. * * @author Keith Visco * @version $Revision: 555 $ $Date: 2006-01-29 22:38:08 +0100 (So, 29. Jan 2006) $ */ public class JDocComment { /** * An ordered list of descriptors */ private Vector _descriptors = null; /** * The internal buffer for this JDocComment */ private StringBuffer _comment = null; /** * Creates a new JavaDoc Comment */ public JDocComment() { super(); _descriptors = new Vector(); _comment = new StringBuffer(); } //-- JDocComment /** * Adds the given JDocDescriptor to this JDocComment * * @param jdesc the JDocDescriptor to add */ public void addDescriptor( JDocDescriptor jdesc ) { if ( jdesc == null ) return; //-- on the fly sorting of descriptors if ( _descriptors.size() == 0 ) { _descriptors.addElement( jdesc ); return; } for ( int i = 0; i < _descriptors.size(); i++ ) { JDocDescriptor jdd = (JDocDescriptor) _descriptors.elementAt( i ); short compare = jdesc.compareTo( jdd ); switch ( compare ) { case 0: // equal _descriptors.insertElementAt( jdesc, i + 1 ); return; case -1: //-- less than _descriptors.insertElementAt( jdesc, i ); return; case 1: //-- keep looking break; } } //-- if we make it here we need to add _descriptors.addElement( jdesc ); } //-- addException /** * Appends the comment String to this JDocComment * * @param comment the comment to append */ public void appendComment( String comment ) { _comment.append( comment ); } //-- appendComment /** * Returns the String value of this JDocComment. * * @return the String value of the JDocComment. */ public String getComment() { return _comment.toString(); } //-- getComment /** * Returns an enumeration of the parameters of this JDocComment * * @return an enumeration of the parameters of this JDocComment */ public Enumeration getDescriptors() { return _descriptors.elements(); } //-- getDescriptors /** * Returns the length of the comment * * @return the length of the comment */ public int getLength() { return _comment.length(); } //-- getLength /** * Returns the Parameter Descriptor associated with the * given name * * @return the Parameter Descriptor associated with the * given name */ public JDocDescriptor getParamDescriptor( String name ) { if ( name == null ) return null; for ( int i = 0; i < _descriptors.size(); i++ ) { JDocDescriptor jdd = (JDocDescriptor) _descriptors.elementAt( i ); if ( jdd.getType() == JDocDescriptor.PARAM ) { if ( name.equals( jdd.getName() ) ) return jdd; } } return null; } //-- getParamDescriptor /** * prints this JavaDoc comment using the given JSourceWriter * * @param jsw the JSourceWriter to print to */ public void print( JSourceWriter jsw ) { //-- I reuse JComment for printing JComment jComment = new JComment( JComment.JAVADOC_STYLE ); jComment.setComment( _comment.toString() ); //-- force a separating "*" for readability if ( _descriptors.size() > 0 ) { jComment.appendComment( "\n" ); } for ( int i = 0; i < _descriptors.size(); i++ ) { jComment.appendComment( "\n" ); jComment.appendComment( _descriptors.elementAt( i ).toString() ); } jComment.print( jsw ); } //-- print /** * Sets the comment String of this JDocComment * * @param comment the comment String of this JDocComment */ public void setComment( String comment ) { _comment.setLength( 0 ); _comment.append( comment ); } //-- setComment /** * Returns the String representation of this Java Doc Comment * * @return the String representation of this Java Doc Comment */ public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "/**\n" ); sb.append( " * " ); sb.append( " */\n" ); return sb.toString(); } //-- toString } //-- JDocComment ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JComponentizedType.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000000443211123536732032677 0ustar mkochmkoch/* * Copyright 2006 Werner Guttmann * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.modello.plugin.java.javasource; /** * JType sub-class for componentized types, such as array as collections. * * @author Werner Guttman * @version $Revision: 1041 $ $Date: 2008-12-21 23:06:18 +0100 (So, 21. Dez 2008) $ * @since 1.0.4 */ public class JComponentizedType extends JType { // -------------------------------------------------------------------------- /** Indicates the data type contained in this collection. */ private JType _componentType; /** Indicates whether Java 5.0 compliant code is required. */ private boolean _useJava50; // -------------------------------------------------------------------------- /** * Creates an instance of a componentized type, of type 'name'. * * @param name Type name for this componentized type. * @param componentType Component type. * @param useJava50 True if Java 5.0 should be used. */ protected JComponentizedType( final String name, final JType componentType, final boolean useJava50 ) { super( name ); _componentType = componentType; _useJava50 = useJava50; } // -------------------------------------------------------------------------- /** * Returns the component type. * * @return The component type. */ public final JType getComponentType() { return _componentType; } /** * Indicates whether Java 5.0 is used. * * @return True if Java 5.0 is used. */ public final boolean isUseJava50() { return _useJava50; } // -------------------------------------------------------------------------- } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JModifiers.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000002560110367232700032675 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved. * * $Id: JModifiers.java 555 2006-01-29 21:38:08Z jvanzyl $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * The set of modifiers for a Method or Member variable * @author Keith Visco * @version $Revision: 555 $ $Date: 2006-01-29 22:38:08 +0100 (So, 29. Jan 2006) $ **/ public class JModifiers { /* static members */ private static final String sAbstract = "abstract"; private static final String sFinal = "final"; private static final String sPrivate = "private"; private static final String sProtected = "protected"; private static final String sPackage = ""; private static final String sPublic = "public"; private static final String sStatic = "static"; private static final String sTransient = "transient"; private static final short vPrivate = 1; private static final short vProtected = 2; private static final short vPublic = 3; private static final short vPackage = 4; /* local members */ /** * The visibility **/ private short visibility = vPublic; /** * A flag indicating whether or not the object associated * with this JModifiers is static **/ private boolean isStatic = false; /** * A flag indicating whether or not the object associated * with this JModifiers is final **/ private boolean isFinal = false; /** * A flag indicating whether or not the object associated * with this JModifiers is abstract **/ private boolean isAbstract = false; /** * A flag indicating whether or not the object associated * with this JModifiers is transient **/ private boolean isTransient = false; /** * Creates a new JModifiers class, by default the * modifiers presented are public. **/ public JModifiers() { super(); } //-- JModifiers /** * Creates a new JModifiers * @param visibility the visibile qualifier * @param isStatic a boolean indicating the static qualifier. * A value of true indicates that this static qualifier is present. * @param isFinal a boolean indicating the final qualifier. A value * of true indicates that the final qualifier is present. **/ private JModifiers( short visibility, boolean isStatic, boolean isFinal ) { this.visibility = visibility; this.isStatic = isStatic; this.isFinal = isFinal; } //-- JModifiers /** * Creates a copy of this JModifiers * @return the copy of this JModifiers **/ public JModifiers copy() { JModifiers mods = new JModifiers( visibility, isStatic, isFinal ); mods.setAbstract( isAbstract ); mods.setTransient( isTransient ); return mods; } //-- copy /** * Changes the visibility qualifier to "private" **/ public void makePrivate() { this.visibility = vPrivate; } //-- makePrivate /** * Changes the visibility qualifier to "protected" **/ public void makeProtected() { this.visibility = vProtected; } //-- makeProtected /** * Changes the visibility qualifier to "public" **/ public void makePublic() { this.visibility = vPublic; } //-- makePublic /** * Changes the visibility qualifier to package (= without qualifier). **/ public void makePackage() { this.visibility = vPackage; } //-- makePackage /** * Returns true if the abstract qualifier is present. *
This is only applicable to methods and classes. * @return true if the abstract qualifier is present **/ public boolean isAbstract() { return isAbstract; } //-- isAbstract /** * Returns true if the modifier represented is private. * @return true if the modifier represented is private. **/ public boolean isPrivate() { return ( visibility == vPrivate ); } //-- isPrivate /** * Returns true if the modifier represented is protected. * @return true if the modifier represented is protected. **/ public boolean isProtected() { return ( visibility == vProtected ); } //-- isProtected /** * Returns true if the modifier represented is public. * @return true if the modifier represented is public. **/ public boolean isPublic() { return ( visibility == vPublic ); } //-- isPublic /** * Returns true if the modifier represented is package (= without qualifier). * @return true if the modifier represented is package (= without qualifier). **/ public boolean isPackage() { return ( visibility == vPackage ); } //-- isPackage /** * Returns true if the modifier represented is static. * @return true if the modifier represented is static. **/ public boolean isStatic() { return this.isStatic; } //-- isPublic /** * Returns true if the modifier represented is transient. * @return true if the modifier represented is transient. **/ public boolean isTransient() { return this.isTransient; } //-- isTransient /** * Sets whether or not the "abstract" qualifier is present *
This applies only to methods or classes. * @param isAbstract is a boolean which when true will indicate * that the abstract qualifier should be present **/ public void setAbstract( boolean isAbstract ) { this.isAbstract = isAbstract; } //-- setAbstract /** * Sets whether or not the "final" qualifier is present * @param isFinal is a boolean which when true will indicate * the final qualifiter is present **/ public void setFinal( boolean isFinal ) { this.isFinal = isFinal; } //-- setFinal /** * Sets whether or not the "static" qualifier is present * @param isStatic is a boolean which when true will indicate * the "static" qualifiter is present **/ public void setStatic( boolean isStatic ) { this.isStatic = isStatic; } //-- setStatic /** * Sets whether or not the "transient" qualifier is present * @param isTransient is a boolean which when true will indicate * the "transient" qualifiter is present **/ public void setTransient( boolean isTransient ) { this.isTransient = isTransient; } //-- setTransient /** * Returns the String represetation of this JModifiers * @return the String represetation of this JModifiers **/ public String toString() { StringBuffer sb = new StringBuffer(); //-- visibility switch ( visibility ) { case vPrivate: sb.append( sPrivate ); break; case vProtected: sb.append( sProtected ); break; case vPackage: sb.append( sPackage ); break; default: sb.append( sPublic ); break; } //-- static if ( isStatic ) { if ( sb.length() > 0 ) { sb.append( ' ' ); } sb.append( sStatic ); } //-- final if ( isFinal ) { if ( sb.length() > 0 ) { sb.append( ' ' ); } sb.append( sFinal ); } //-- abstract if ( isAbstract ) { if ( sb.length() > 0 ) { sb.append( ' ' ); } sb.append( sAbstract ); } //-- transient if ( isTransient ) { if ( sb.length() > 0 ) { sb.append( ' ' ); } sb.append( sTransient ); } return sb.toString(); } //-- toString } //-- JModifiers ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JInterface.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000004200711231735057032700 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2001-2002 (C) Intalio, Inc. All Rights Reserved. * * $Id: JInterface.java 1297 2009-07-23 01:17:35Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Vector; /** * A representation of the Java Source code for a Java Interface. * This is a useful utility when creating in memory source code. * The code in this package was modelled after the Java Reflection API * as much as possible to reduce the learning curve. * * @author Martin Skopp * @author Keith Visco * @version $Revision: 1297 $ $Date: 2009-07-23 03:17:35 +0200 (Do, 23. Jul 2009) $ **/ public final class JInterface extends JStructure { /** * The fields for this JInterface */ private JNamedMap fields = null; /** * The list of methods of this JInterface */ private Vector methods = null; /** * Creates a new JInterface with the given name. * * @param name the name of the JInterface. * @throws java.lang.IllegalArgumentException when the given name * is not a valid Class name. **/ public JInterface( String name ) throws IllegalArgumentException { super( name ); methods = new Vector(); //-- initialize default Java doc getJDocComment().appendComment( "Interface " + getLocalName() + "." ); } //-- JInterface /** * Adds the given JField to this JStructure. *

* This method is implemented by subclasses and * should only accept the proper fields for the * subclass otherwise an IllegalArgumentException * will be thrown. For example a JInterface will * only accept static fields. *

* @param jField, the JField to add * @exception java.lang.IllegalArgumentException when the given * JField has a name of an existing JField */ public void addField( JField jField ) throws IllegalArgumentException { if ( jField == null ) { throw new IllegalArgumentException( "argument 'jField' cannot be null" ); } String name = jField.getName(); //-- check for duplicate field name if ( ( fields != null ) && ( fields.get( name ) != null ) ) { String err = "duplicate name found: " + name; throw new IllegalArgumentException( err ); } //-- check for proper modifiers JModifiers modifiers = jField.getModifiers(); if ( !modifiers.isStatic() ) { throw new IllegalArgumentException( "Fields added to a JInterface must be static." ); } if ( modifiers.isPrivate() ) { throw new IllegalArgumentException( "Fields added to a JInterface must not be private." ); } //-- only initialize fields if we need it, many interfaces //-- don't contain any fields, no need to waste space if ( fields == null ) { fields = new JNamedMap( 3 ); } fields.put( name, jField ); } /** * Adds the given JMember to this JStructure. *

* This method is implemented by subclasses and * should only accept the proper types for the * subclass otherwise an IllegalArgumentException * will be thrown. *

* @param jMember the JMember to add to this JStructure. * @throws java.lang.IllegalArgumentException when the given * JMember has the same name of an existing JField * or JMethod respectively. */ public void addMember( JMember jMember ) throws IllegalArgumentException { if ( jMember == null ) { throw new IllegalArgumentException( "argument 'jMember' may not be null." ); } if ( jMember instanceof JField ) { addField( (JField) jMember ); } else { throw new IllegalArgumentException( "invalid member for JInterface: " + jMember.toString() ); } } //-- addMember /** * Adds the given JMethodSignature to this JClass * * @param jMethodSig the JMethodSignature to add. * @throws java.lang.IllegalArgumentException when the given * JMethodSignature conflicts with an existing * method signature. */ public void addMethod( JMethodSignature jMethodSig ) throws IllegalArgumentException { if ( jMethodSig == null ) { String err = "The JMethodSignature cannot be null."; throw new IllegalArgumentException( err ); } //-- check method name and signatures *add later* //-- keep method list sorted for esthetics when printing //-- START SORT :-) boolean added = false; // short modifierVal = 0; JModifiers modifiers = jMethodSig.getModifiers(); for ( int i = 0; i < methods.size(); i++ ) { JMethodSignature tmp = (JMethodSignature) methods.elementAt( i ); //-- first compare modifiers if ( tmp.getModifiers().isProtected() ) { if ( !modifiers.isProtected() ) { methods.insertElementAt( jMethodSig, i ); added = true; break; } } //-- compare names if ( jMethodSig.getName().compareTo( tmp.getName() ) < 0 ) { methods.insertElementAt( jMethodSig, i ); added = true; break; } } //-- END SORT if ( !added ) methods.addElement( jMethodSig ); //-- check return type to make sure it's included in the //-- import list JType jType = jMethodSig.getReturnType(); if ( jType != null ) { while ( jType.isArray() ) jType = jType.getComponentType(); if ( !jType.isPrimitive() ) addImport( jType.getName() ); } //-- check exceptions JClass[] exceptions = jMethodSig.getExceptions(); for ( int i = 0; i < exceptions.length; i++ ) { addImport( exceptions[i].getName() ); } } //-- addMethod /** * Returns the field with the given name, or null if no field * was found with the given name. * * @param name the name of the field to return. * @return the field with the given name, or null if no field * was found with the given name. */ public JField getField( String name ) { if ( fields == null ) return null; return (JField) fields.get( name ); } //-- getField /** * Returns an array of all the JFields of this JStructure * * @return an array of all the JFields of this JStructure */ public JField[] getFields() { if ( fields == null ) { return new JField[0]; } int size = fields.size(); JField[] farray = new JField[size]; for ( int i = 0; i < size; i++ ) { farray[i] = (JField) fields.get( i ); } return farray; } //-- getFields /** * Returns an array of all the JMethodSignatures of this JInterface. * * @return an array of all the JMethodSignatures of this JInterface. **/ public JMethodSignature[] getMethods() { JMethodSignature[] marray = new JMethodSignature[methods.size()]; methods.copyInto( marray ); return marray; } //-- getMethods /** * Returns the JMethodSignature with the given name, * and occuring at or after the given starting index. * * @param name the name of the JMethodSignature to return. * @param startIndex the starting index to begin searching * from. * @return the JMethodSignature, or null if not found. **/ public JMethodSignature getMethod( String name, int startIndex ) { for ( int i = startIndex; i < methods.size(); i++ ) { JMethodSignature jMethod = (JMethodSignature) methods.elementAt( i ); if ( jMethod.getName().equals( name ) ) return jMethod; } return null; } //-- getMethod /** * Returns the JMethodSignature at the given index. * * @param index the index of the JMethodSignature to return. * @return the JMethodSignature at the given index. **/ public JMethodSignature getMethod( int index ) { return (JMethodSignature) methods.elementAt( index ); } //-- getMethod /** * Prints the source code for this JInterface to the given JSourceWriter * * @param jsw the JSourceWriter to print to. [May not be null] */ public void print( JSourceWriter jsw ) { print( jsw, false ); } /** * Prints the source code for this JInterface to the given JSourceWriter * * @param jsw the JSourceWriter to print to. [May not be null] */ public void print( JSourceWriter jsw, boolean classOnly ) { if ( jsw == null ) { throw new IllegalArgumentException( "argument 'jsw' should not be null." ); } StringBuffer buffer = new StringBuffer(); if ( !classOnly ) { printHeader( jsw ); printPackageDeclaration( jsw ); printImportDeclarations( jsw ); } //------------/ //- Java Doc -/ //------------/ getJDocComment().print( jsw ); JAnnotations annotations = getAnnotations(); if ( annotations != null ) annotations.print( jsw ); //-- print class information //-- we need to add some JavaDoc API adding comments buffer.setLength( 0 ); JModifiers modifiers = getModifiers(); if ( modifiers.isPrivate() ) { buffer.append( "private " ); } else if ( modifiers.isPublic() ) { buffer.append( "public " ); } if ( modifiers.isAbstract() ) { buffer.append( "abstract " ); } buffer.append( "interface " ); buffer.append( getLocalName() ); jsw.writeln( buffer.toString() ); buffer.setLength( 0 ); jsw.indent(); if ( getInterfaceCount() > 0 ) { Enumeration e = getInterfaces(); buffer.append( "extends " ); while ( e.hasMoreElements() ) { buffer.append( e.nextElement() ); if ( e.hasMoreElements() ) buffer.append( ", " ); } jsw.writeln( buffer.toString() ); buffer.setLength( 0 ); } jsw.unindent(); jsw.writeln( '{' ); jsw.indent(); //-- declare static members if ( fields != null ) { if ( fields.size() > 0 ) { jsw.writeln(); jsw.writeln( " //--------------------------/" ); jsw.writeln( " //- Class/Member Variables -/" ); jsw.writeln( "//--------------------------/" ); jsw.writeln(); } for ( int i = 0; i < fields.size(); i++ ) { JField jField = (JField) fields.get( i ); //-- print Java comment JDocComment comment = jField.getComment(); if ( comment != null ) comment.print( jsw ); // -- print member jsw.write( jField.getModifiers().toString() ); jsw.write( ' ' ); JType type = jField.getType(); String typeName = type.toString(); //-- for esthetics use short name in some cases if ( typeName.equals( toString() ) ) { typeName = type.getLocalName(); } jsw.write( typeName ); jsw.write( ' ' ); jsw.write( jField.getName() ); String init = jField.getInitString(); if ( init != null ) { jsw.write( " = " ); jsw.write( init ); } jsw.writeln( ';' ); jsw.writeln(); } } //-- print method signatures if ( methods.size() > 0 ) { jsw.writeln(); jsw.writeln( " //-----------/" ); jsw.writeln( " //- Methods -/" ); jsw.writeln( "//-----------/" ); jsw.writeln(); } for ( int i = 0; i < methods.size(); i++ ) { JMethodSignature signature = (JMethodSignature) methods.elementAt( i ); signature.print( jsw ); jsw.writeln( ';' ); } for ( Iterator iterator = sourceCodeEntries.iterator(); iterator.hasNext(); ) { jsw.writeln( (String) iterator.next() ); } jsw.unindent(); jsw.writeln( '}' ); jsw.flush(); jsw.close(); } //-- printSource private List sourceCodeEntries = new ArrayList(); public void addSourceCode( String sourceCode ) { sourceCodeEntries.add( sourceCode ); } /** * Test drive method...to be removed or commented out ** public static void main(String[] args) { JInterface jInterface = new JInterface("Test"); //-- add an import jInterface.addImport("java.util.Vector"); JClass jString = new JClass("String"); //-- add an interface jInterface.addInterface("java.io.Serializable"); //-- add a static field JField jField = new JField(new JClass("java.lang.String"), "TEST"); jField.setInitString("\"Test\""); jField.getModifiers().setStatic(true); jField.getModifiers().makePublic(); jInterface.addField(jField); //-- add a method signature JMethodSignature jMethodSig = new JMethodSignature("getName", jString); jInterface.addMethod(jMethodSig); jInterface.print(); } //-- main /* */ } //-- JInterface ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JConstructor.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000002115711231735057032703 0ustar mkochmkoch/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Intalio, Inc. For written permission, * please contact info@codehaus.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Intalio, Inc. Exolab is a registered * trademark of Intalio, Inc. * * 5. Due credit should be given to the Exolab Project * (http://www.codehaus.org/). * * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. * * $Id: JConstructor.java 1297 2009-07-23 01:17:35Z hboutemy $ */ package org.codehaus.modello.plugin.java.javasource; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * A class for handling source code for a constructor of a JClass * @author Keith Visco * @version $Revision: 1297 $ $Date: 2009-07-23 03:17:35 +0200 (Do, 23. Jul 2009) $ **/ public class JConstructor { /** * The set of modifiers for this JMethod **/ private JModifiers modifiers = null; /** * List of parameters for this Constructor **/ private JNamedMap params = null; /** * The Class in this JMember has been declared **/ private JClass declaringClass = null; private JSourceCode sourceCode = null; private JAnnotations annotations = null; /** * Creates a new method with the given name and returnType. * For "void" return types, simply pass in null as the returnType **/ public JConstructor( JClass declaringClass ) { this.declaringClass = declaringClass; this.modifiers = new JModifiers(); this.params = new JNamedMap(); this.sourceCode = new JSourceCode(); } /** * Adds the given parameter to this Methods list of parameters * @param parameter the parameter to add to the this Methods * list of parameters. * @exception java.lang.IllegalArgumentException when a parameter already * exists for this Method with the same name as the new parameter **/ public void addParameter( JParameter parameter ) throws IllegalArgumentException { if ( parameter == null ) return; //-- check current params if ( params.get( parameter.getName() ) != null ) { StringBuffer err = new StringBuffer(); err.append( "A parameter already exists for the constructor, " ); err.append( this.declaringClass.getName() ); err.append( ", with the name: " ); err.append( parameter.getName() ); throw new IllegalArgumentException( err.toString() ); } params.put( parameter.getName(), parameter ); } //-- addParameter /** * Returns the class in which this JMember has been declared * @return the class in which this JMember has been declared **/ public JClass getDeclaringClass() { return this.declaringClass; } //-- getDeclaringClass /** * Returns the modifiers for this JConstructor * @return the modifiers for this JConstructor **/ public JModifiers getModifiers() { return this.modifiers; } //-- getModifiers /** * Returns an array of JParameters consisting of the parameters * of this Method in declared order * @return a JParameter array consisting of the parameters * of this Method in declared order **/ public JParameter[] getParameters() { JParameter[] jpArray = new JParameter[params.size()]; for ( int i = 0; i < jpArray.length; i++ ) { jpArray[i] = (JParameter) params.get( i ); } return jpArray; } //-- getParameters public JSourceCode getSourceCode() { return this.sourceCode; } //-- getSourceCode public void print( JSourceWriter jsw ) { JAnnotations annotations = getAnnotations(); if ( annotations != null ) annotations.print( jsw ); if ( modifiers.isPrivate() ) jsw.write( "private" ); else if ( modifiers.isProtected() ) jsw.write( "protected" ); else jsw.write( "public" ); jsw.write( ' ' ); jsw.write( declaringClass.getLocalName() ); jsw.write( '(' ); //-- print parameters for ( int i = 0; i < params.size(); i++ ) { if ( i > 0 ) jsw.write( ", " ); jsw.write( params.get( i ) ); } jsw.writeln( ')' ); jsw.writeln( '{' ); //jsw.indent(); sourceCode.print( jsw ); //jsw.unindent(); if ( !jsw.isNewline() ) jsw.writeln(); jsw.write( "} //-- " ); jsw.writeln( toString() ); } //-- print public void setModifiers( JModifiers modifiers ) { this.modifiers = modifiers.copy(); this.modifiers.setFinal( false ); } //-- setModifiers public void setSourceCode( String sourceCode ) { this.sourceCode = new JSourceCode( sourceCode ); } //-- setSourceCode public void setSourceCode( JSourceCode sourceCode ) { this.sourceCode = sourceCode; } //-- setSourceCode public String toString() { StringBuffer sb = new StringBuffer(); sb.append( declaringClass.getName() ); sb.append( '(' ); //-- print parameters for ( int i = 0; i < params.size(); i++ ) { JParameter jp = (JParameter) params.get( i ); if ( i > 0 ) sb.append( ", " ); sb.append( jp.getType().getName() ); } sb.append( ')' ); return sb.toString(); } //-- toString /** * @return the annotations */ public JAnnotations getAnnotations() { return annotations; } /** * @param annotation the annotation to append */ public void appendAnnotation( String annotation ) { if ( annotations == null ) { annotations = new JAnnotations(); } annotations.appendAnnotation( annotation ); } /** * @param annotations the annotations to set */ public void setAnnotations( JAnnotations annotations ) { this.annotations = annotations; } } //-- JConstructor ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JArrayType.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javas0000644000175000017500000000341111123536732032673 0ustar mkochmkoch/* * Copyright 2006 Werner Guttmann * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package org.codehaus.modello.plugin.java.javasource; /** * JType sub-class for Arrays. * * @author Werner Guttman * @version $Revision: 1041 $ $Date: 2008-12-21 23:06:18 +0100 (So, 21. Dez 2008) $ * @since 1.0.4 */ public final class JArrayType extends JComponentizedType { // -------------------------------------------------------------------------- /** * Creates an instance of a array type, of type 'name'. * * @param componentType Component type. * @param useJava50 True if Java 5.0 should be generated. */ public JArrayType( final JType componentType, final boolean useJava50 ) { super( componentType.getName(), componentType, useJava50 ); } // -------------------------------------------------------------------------- /** * Returns the String representation of this JType, which is simply the name of this type. * * @return The String representation of this JType. */ public String toString() { return getComponentType().toString() + "[]"; } // -------------------------------------------------------------------------- } ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/AbstractJavaModelloGenerator.javamodello-1.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/Abstr0000644000175000017500000002372611243356043032653 0ustar mkochmkochpackage org.codehaus.modello.plugin.java; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.Locale; import java.util.Properties; import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.model.BaseElement; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.ModelInterface; import org.codehaus.modello.plugin.AbstractModelloGenerator; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JComment; import org.codehaus.modello.plugin.java.javasource.JInterface; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JStructure; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; import org.codehaus.modello.plugin.java.metadata.JavaModelMetadata; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; /** * AbstractJavaModelloGenerator - similar in scope to {@link AbstractModelloGenerator} but with features that * java generators can use. * * @author Joakim Erdfelt * @version $Id: AbstractJavaModelloGenerator.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public abstract class AbstractJavaModelloGenerator extends AbstractModelloGenerator { protected boolean useJava5 = false; protected void initialize( Model model, Properties parameters ) throws ModelloException { super.initialize( model, parameters ); useJava5 = Boolean.valueOf( getParameter( parameters, ModelloParameterConstants.USE_JAVA5, "false" ) ).booleanValue(); } /** * Create a new java source file writer, with configured encoding. * * @param packageName the package of the source file to create * @param className the class of the source file to create * @return a JSourceWriter with configured encoding * @throws IOException */ protected JSourceWriter newJSourceWriter( String packageName, String className ) throws IOException { String directory = packageName.replace( '.', File.separatorChar ); File f = new File( new File( getOutputDirectory(), directory ), className + ".java" ); if ( !f.getParentFile().exists() ) { f.getParentFile().mkdirs(); } OutputStream os = getBuildContext().newFileOutputStream( f ); Writer writer = ( getEncoding() == null ) ? WriterFactory.newPlatformWriter( os ) : WriterFactory.newWriter( os, getEncoding() ); return new JSourceWriter( writer ); } private JComment getHeaderComment() { JComment comment = new JComment(); comment.setComment( getHeader() ); return comment; } protected void initHeader( JClass clazz ) { clazz.setHeader( getHeaderComment() ); } protected void initHeader( JInterface interfaze ) { interfaze.setHeader( getHeaderComment() ); } protected void suppressAllWarnings( Model objectModel, JStructure structure ) { JavaModelMetadata javaModelMetadata = (JavaModelMetadata) objectModel.getMetadata( JavaModelMetadata.ID ); if ( useJava5 && javaModelMetadata.isSuppressAllWarnings() ) { structure.appendAnnotation( "@SuppressWarnings( \"all\" )" ); } } protected void addModelImports( JClass jClass, BaseElement baseElem ) throws ModelloException { String basePackageName = null; if ( baseElem != null ) { if ( baseElem instanceof ModelInterface ) { basePackageName = ( (ModelInterface) baseElem ).getPackageName( isPackageWithVersion(), getGeneratedVersion() ); } else if ( baseElem instanceof ModelClass ) { basePackageName = ( (ModelClass) baseElem ).getPackageName( isPackageWithVersion(), getGeneratedVersion() ); } } // import interfaces for ( Iterator i = getModel().getInterfaces( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelInterface modelInterface = (ModelInterface) i.next(); String packageName = modelInterface.getPackageName( isPackageWithVersion(), getGeneratedVersion() ); if ( packageName.equals( basePackageName ) ) { continue; } jClass.addImport( packageName + '.' + modelInterface.getName() ); } // import classes for ( Iterator i = getModel().getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass modelClass = (ModelClass) i.next(); String packageName = modelClass.getPackageName( isPackageWithVersion(), getGeneratedVersion() ); if ( packageName.equals( basePackageName ) ) { continue; } JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } jClass.addImport( packageName + '.' + modelClass.getName() ); } } protected String getPrefix( JavaFieldMetadata javaFieldMetadata ) { return javaFieldMetadata.isBooleanGetter() ? "is" : "get"; } protected String getDefaultValue( ModelAssociation association ) { String value = association.getDefaultValue(); if ( useJava5 ) { value = StringUtils.replaceOnce( StringUtils.replaceOnce( value, "/*", "" ), "*/", "" ); } return value; } protected final static String DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; protected String getJavaDefaultValue( ModelField modelField ) throws ModelloException { if ( modelField.getType().equals( "String" ) ) { return '"' + modelField.getDefaultValue() + '"'; } else if ( modelField.getType().equals( "char" ) ) { return '\'' + modelField.getDefaultValue() + '\''; } else if ( modelField.getType().equals( "long" ) ) { return modelField.getDefaultValue() + 'L'; } else if ( modelField.getType().equals( "float" ) ) { return modelField.getDefaultValue() + 'f'; } else if ( modelField.getType().equals( "Date" ) ) { DateFormat format = new SimpleDateFormat( DEFAULT_DATE_FORMAT, Locale.US ); try { Date date = format.parse( modelField.getDefaultValue() ); return "new java.util.Date( " + date.getTime() + "L )"; } catch ( ParseException pe ) { throw new ModelloException( "Unparseable default date: " + modelField.getDefaultValue(), pe ); } } return modelField.getDefaultValue(); } protected String getValueChecker( String type, String value, ModelField field ) throws ModelloException { String retVal; if ( "boolean".equals( type ) || "double".equals( type ) || "float".equals( type ) || "int".equals( type ) || "long".equals( type ) || "short".equals( type ) || "byte".equals( type ) || "char".equals( type ) ) { retVal = "if ( " + value + " != " + getJavaDefaultValue( field ) + " )"; } else if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) || ModelDefault.MAP.equals( type ) || ModelDefault.PROPERTIES.equals( type ) ) { retVal = "if ( ( " + value + " != null ) && ( " + value + ".size() > 0 ) )"; } else if ( "String".equals( type ) && field.getDefaultValue() != null ) { retVal = "if ( ( " + value + " != null ) && !" + value + ".equals( \"" + field.getDefaultValue() + "\" ) )"; } else if ( "Date".equals( type ) && field.getDefaultValue() != null ) { retVal = "if ( ( " + value + " != null ) && !" + value + ".equals( " + getJavaDefaultValue( field ) + " ) )"; } else { retVal = "if ( " + value + " != null )"; } return retVal; } } modello-1.1/modello-plugins/modello-plugin-java/src/main/resources/0000755000175000017500000000000011260056267024504 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/resources/META-INF/0000755000175000017500000000000011260056267025644 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056267027164 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-java/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000101011127737506032067 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator java org.codehaus.modello.plugin.java.JavaModelloGenerator org.codehaus.modello.metadata.MetadataPlugin java org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin modello-1.1/modello-plugins/modello-plugin-xsd/0000755000175000017500000000000011260056265020632 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/pom.xml0000644000175000017500000000227311243557055022157 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-xsd Modello XSD Plugin Modello XSD Plugin generates an XML Schema from the model to be able to validate XML content. org.codehaus.modello modello-plugin-xml xml-apis xml-apis 1.3.04 test xerces xercesImpl 2.8.1 test modello-1.1/modello-plugins/modello-plugin-xsd/src/0000755000175000017500000000000011260056265021421 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/0000755000175000017500000000000011260056265022400 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/0000755000175000017500000000000011260056265023321 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/0000755000175000017500000000000011260056265024110 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/0000755000175000017500000000000011260056265025703 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056265027336 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056265030634 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/0000755000175000017500000000000011260056265031432 5ustar mkochmkoch././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/ChangesXsdGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/Changes0000755000175000017500000000521511132204506032722 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd; /* * Copyright (c) 2005, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Properties; import org.codehaus.modello.AbstractModelloGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; /** * @author Brett Porter * @version $Id: ChangesXsdGeneratorTest.java 1127 2009-01-10 20:47:02Z hboutemy $ */ public class ChangesXsdGeneratorTest extends AbstractModelloGeneratorTest { public ChangesXsdGeneratorTest() { super( "xsd-changes" ); } public void testXsdGenerator() throws Throwable { ModelloCore modello = (ModelloCore) container.lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/changes.mdo" ) ) ); // generate XSD file Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); modello.generate( model, "xsd", parameters ); //addDependency( "modello", "modello-core", "1.0-SNAPSHOT" ); // TODO write verfier which compile generated schema : use jaxp //verify( "org.codehaus.modello.generator.xml.xsd.XsdVerifier", "xsd" ); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/XsdGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/XsdGene0000644000175000017500000000742211132204506032706 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd; /* * Copyright (c) 2005, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; import java.util.Properties; /** * @author Brett Porter * @version $Id: XsdGeneratorTest.java 1127 2009-01-10 20:47:02Z hboutemy $ */ public class XsdGeneratorTest extends AbstractModelloGeneratorTest { public XsdGeneratorTest() { super( "xsd" ); } public void testXsdGenerator() throws Throwable { ModelloCore modello = (ModelloCore) container.lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/maven.mdo" ) ) ); // check misc. properties of the model loaded List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 26, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); ModelField extend = clazz.getField( "extend", new Version( "4.0.0" ) ); assertTrue( extend.hasMetadata( XmlFieldMetadata.ID ) ); XmlFieldMetadata xml = (XmlFieldMetadata) extend.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertTrue( xml.isAttribute() ); assertEquals( "extender", xml.getTagName() ); ModelField build = clazz.getField( "build", new Version( "4.0.0" ) ); assertTrue( build.hasMetadata( XmlFieldMetadata.ID ) ); xml = (XmlFieldMetadata) build.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertEquals( "builder", xml.getTagName() ); // generate XSD file Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); modello.generate( model, "xsd", parameters ); //addDependency( "modello", "modello-core", "1.0-SNAPSHOT" ); // TODO write verfier which compile generated schema : use jaxp //verify( "org.codehaus.modello.generator.xml.xsd.XsdVerifier", "xsd" ); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/ModelloXsdGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/Modello0000644000175000017500000001036211221417324032744 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import java.io.File; import java.util.Properties; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; /** * Check that features.mdo (which tries to be the most complete model) can be checked against XSD generated from * Modello model modello.mdo. * * @author Hervé Boutemy * @version $Id: ModelloXsdGeneratorTest.java 1257 2009-06-27 13:29:56Z bentmann $ */ public class ModelloXsdGeneratorTest extends AbstractModelloGeneratorTest { public ModelloXsdGeneratorTest() { super( "modello" ); } public void testXsdGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.1.0" ); Model model = modello.loadModel( getTestFile( "../../src/main/mdo/modello.mdo" ) ); modello.generate( model, "xsd", parameters ); /* only available in JAXP 1.3, JDK 5+ SchemaFactory factory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ); Schema schema = factory.newSchema( new StreamSource( new File( generatedSources, "features.xsd" ) ) ); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setSchema( schema ); SAXParser parser = spf.newSAXParser(); parser.parse( new InputSource( getClass().getResourceAsStream( "/features.xml" ) ) ); */ SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating( true ); factory.setNamespaceAware( true ); SAXParser saxParser = factory.newSAXParser(); saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema" ); saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource", new File( getOutputDirectory(), "modello-1.1.0.xsd" ) ); // first self-test: validate Modello model with xsd generated from it saxParser.parse( getTestFile( "../../src/main/mdo/modello.mdo" ), new Handler() ); // then features.mdo saxParser.parse( getClass().getResourceAsStream( "/features.mdo" ), new Handler() ); } private static class Handler extends DefaultHandler { public void warning ( SAXParseException e ) throws SAXException { throw e; } public void error ( SAXParseException e ) throws SAXException { throw e; } } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/FeaturesXsdGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/Feature0000644000175000017500000001177311223730002032744 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloGeneratorTest; import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import java.io.File; import java.util.Properties; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; /** * @author Hervé Boutemy * @version $Id: FeaturesXsdGeneratorTest.java 1274 2009-07-04 19:39:46Z hboutemy $ */ public class FeaturesXsdGeneratorTest extends AbstractModelloGeneratorTest { public FeaturesXsdGeneratorTest() { super( "features" ); } public void testXsdGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "xsd", parameters ); /* only available in JAXP 1.3, JDK 5+ SchemaFactory factory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ); Schema schema = factory.newSchema( new StreamSource( new File( generatedSources, "features.xsd" ) ) ); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setSchema( schema ); SAXParser parser = spf.newSAXParser(); parser.parse( new InputSource( getClass().getResourceAsStream( "/features.xml" ) ) ); */ SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating( true ); factory.setNamespaceAware( true ); SAXParser saxParser = factory.newSAXParser(); saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema" ); saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource", new File( getOutputDirectory(), "features-1.0.0.xsd" ) ); try { saxParser.parse( getClass().getResourceAsStream( "/features.xml" ), new Handler() ); } catch ( SAXParseException e ) { throw new ModelloException( "line " + e.getLineNumber() + " column " + e.getColumnNumber(), e ); } try { saxParser.parse( getClass().getResourceAsStream( "/features-invalid.xml" ), new Handler() ); fail( "parsing of features-invalid.xml should have failed" ); } catch ( SAXParseException e ) { // ok, expected exception e.printStackTrace(); assertTrue( String.valueOf( e.getMessage() ).indexOf( "invalidElement" ) >= 0 ); } try { saxParser.parse( getClass().getResourceAsStream( "/features-invalid-transient.xml" ), new Handler() ); fail( "XSD did not prohibit appearance of transient fields" ); } catch ( SAXParseException e ) { // ok, expected exception e.printStackTrace(); assertTrue( String.valueOf( e.getMessage() ).indexOf( "transientString" ) >= 0 ); } } private static class Handler extends DefaultHandler { public void warning ( SAXParseException e ) throws SAXException { throw e; } public void error ( SAXParseException e ) throws SAXException { throw e; } } } modello-1.1/modello-plugins/modello-plugin-xsd/src/test/resources/0000755000175000017500000000000011260056265024412 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/test/resources/features-invalid.xml0000644000175000017500000000043511223665473030406 0ustar mkochmkoch modello-1.1/modello-plugins/modello-plugin-xsd/src/test/resources/maven.mdo0000644000175000017500000016405110724510451026224 0ustar mkochmkoch maven Maven package org.apache.maven.model Model 3.0.0+ extend 3.0.0+ String parent 4.0.0 Parent modelVersion 4.0.0 true String pomVersion 3.0.0 true String builtOn 4.0.0 Date id 3.0.0 true String groupId 3.0.0+ true String artifactId 3.0.0+ true String type 4.0.0 String jar name 3.0.0+ true String currentVersion 3.0.0 true String version 4.0.0 true String shortDescription 3.0.0+ String description 3.0.0+ front page of the project's web site. ]]> String url 3.0.0+ String logo 3.0.0+ String issueTrackingUrl 3.0.0 String issueManagement 4.0.0 IssueManagement ciManagement 4.0.0 CiManagement inceptionYear 3.0.0+ true String gumpRepositoryId 3.0.0 String siteAddress 3.0.0 String siteDirectory 3.0.0 String distributionSite 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. distributionDirectory 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. repositories 4.0.0 Repository * pluginRepositories 4.0.0 Repository * This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own. mailingLists 3.0.0+ MailingList * developers 3.0.0+ developer element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> Developer * contributors 3.0.0+ contributor element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. ]]> Contributor * dependencies 3.0.0+ dependency element, which is then described by additional elements (described below). ]]> Dependency * These should ultimately only be compile time dependencies when transitive dependencies come into play. overrides 4.0.0 override element, which is then described by additional elements (described below). ]]> Override * licenses 3.0.0+ license element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. ]]> License * versions 3.0.0 Version * branches 3.0.0 Branch * packageGroups 3.0.0+ PackageGroup * reports 3.0.0+ maven site. All of the reports will be included in the navigation bar for browsing in the order they are specified. ]]> String * scm 4.0.0 Scm repository 3.0.0 Repository This element needs to be renamed as it conflicts with the existing notion of repositories in Maven. build 3.0.0+ true Build organization 3.0.0+ Organization distributionManagement 4.0.0 DistributionManagement local 4.0.0 false Local properties 3.0.0+ Properties String * preGoals 4.0.0 PreGoal * postGoals 4.0.0 PostGoal * 3.0.0 public void setVersion(String version) { this.currentVersion = version; } public String getVersion() { return currentVersion; } 3.0.0+ private String packageName; public void setPackage(String packageName) { this.packageName = packageName; } public String getPackage() { return packageName; } 4.0.0 public String getId() { StringBuffer id = new StringBuffer(); id.append( getGroupId() ); id.append( ":" ); id.append( getArtifactId() ); id.append( ":" ); id.append( getType() ); id.append( ":" ); id.append( getVersion() ); return id.toString(); } Branch 3.0.0+ tag element ]]> tag 3.0.0+ true String description 4.0.0 String lastMergeTag 4.0.0 String Build 3.0.0+ nagEmailAddress 3.0.0 maven:gump-descriptor target. ]]> String This should be moved out of the build section. Vestigal for use with Gump. sourceDirectory 3.0.0+ true String unitTestSourceDirectory 3.0.0+ true String aspectSourceDirectory 3.0.0+ Aspectj goals document). The path given is relative to the project descriptor. ]]> String integrationUnitTestSourceDirectory 3.0.0+ String sourceModifications 3.0.0+ true sourceModification element, which is then described by additional elements (described below). These modifications are used to exclude or include various source depending on the environment the build is running in. ]]> SourceModification * unitTest 3.0.0+ true new UnitTest() UnitTest resources 3.0.0+ below). These resources are used to complete the jar file or to run unit test. ]]> Resource * directory 4.0.0 String output 4.0.0 String finalName 4.0.0 String testOutput 4.0.0 String CiManagement 4.0.0 system 4.0.0 String url 4.0.0 String nagEmailAddress 4.0.0 String Contributor 3.0.0+ name 3.0.0+ String email 3.0.0+ String url 3.0.0+ String organization 3.0.0+ String roles 3.0.0+ role element, the body of which is a role name. ]]> String * timezone 3.0.0+ String Dependency 3.0.0+ id 3.0.0 true String groupId 3.0.0+ true geronimo. ]]> String artifactId 3.0.0+ true germonimo-jms ]]> String version 3.0.0+ true 3.2.1 ]]> String url 3.0.0+ String The URL should really be gleaned from a shared database of dependency information. jar 3.0.0 String artifact 4.0.0+ String type 3.0.0+ ejb and plugin. ]]> String jar properties 3.0.0+ mark dependencies with properties. For example the war plugin looks for a war.bundle property, and if found will include the dependency in WEB-INF/lib. For example syntax, check the war plugin docs. ]]> Properties String * 3.0.0+ public String toString() { return groupId + "/" + type + "s:" + artifactId + "-" + version; } 4.0.0 public String getId() { return groupId + ":" + artifactId + ":" + type + ":" + version; } 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } return getArtifactId() + "-" + getVersion() + "." + getExtension(); } public String getExtension() { if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof Dependency ) ) { return false; } Dependency d = (Dependency) o; return getId().equals( d.getId() ); } public int hashCode() { return getId().hashCode(); } ]]> Override 4.0.0 groupId 4.0.0 true geronimo. ]]> String artifactId 4.0.0 true germonimo-jms ]]> String type 4.0.0 ejb and plugin. ]]> String jar version 4.0.0 true 3.2.1 ]]> String file 4.0.0 true lib/non-distributable-code-1.3.jar ]]> String Contributor Developer 3.0.0+ id 3.0.0+ String IssueManagement 4.0.0 system 4.0.0 String url 4.0.0 String DistributionManagement 4.0.0 repository 4.0.0 Repository site 4.0.0 Site License 3.0.0+ name 3.0.0+ String url 3.0.0+ String distribution 3.0.0

repo
may be downloaded from the Maven repository
manual
user must manually download and install the dependency.
]]> String comments 3.0.0+ String
MailingList 3.0.0+ mailingList element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> name 3.0.0+ String subscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String unsubscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String post 4.0.0 mailto: link will automatically be created when the documentation is created. ]]> String archive 3.0.0+ String This should probably be removed from 4.0.0 before alpha-1 archives 4.0.0 String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization 3.0.0+ name 3.0.0+ String url 3.0.0+ String logo 3.0.0+ /images/org-logo.png) or an absolute URL (e.g., http://my.corp/logo.png). This value is used when generating the project documentation. ]]> String PackageGroup 3.0.0+ title 3.0.0+ String packages 3.0.0+ String PatternSet 3.0.0+ includes 3.0.0+ String * excludes 3.0.0+ String * 3.0.0+ public List getDefaultExcludes() { List defaultExcludes = new ArrayList(); defaultExcludes.add( "**/*~" ); defaultExcludes.add( "**/#*#" ); defaultExcludes.add( "**/.#*" ); defaultExcludes.add( "**/%*%" ); defaultExcludes.add( "**/._*" ); // CVS defaultExcludes.add( "**/CVS" ); defaultExcludes.add( "**/CVS/**" ); defaultExcludes.add( "**/.cvsignore" ); // SCCS defaultExcludes.add( "**/SCCS" ); defaultExcludes.add( "**/SCCS/**" ); // Visual SourceSafe defaultExcludes.add( "**/vssver.scc" ); // Subversion defaultExcludes.add( "**/.svn" ); defaultExcludes.add( "**/.svn/**" ); // Mac defaultExcludes.add( "**/.DS_Store" ); return defaultExcludes; } Parent 4.0.0 artifactId 4.0.0 String groupId 4.0.0 String version 4.0.0 on of the project to extend.]]> String Repository 3.0.0 connection 3.0.0 building versions from specific ID. ]]> String developerConnection 3.0.0 String url 3.0.0 String Scm 4.0.0 connection 4.0.0 building versions from specific ID. ]]> String developerConnection 4.0.0 String url 4.0.0 String branches 4.0.0 String * Resource 3.0.0+ PatternSet directory 3.0.0+ String targetPath 3.0.0+ org.apache.maven.messages), you must specify this element with this value : org/apache/maven/messages ]]> String filtering 3.0.0+ boolean false SourceModification 3.0.0+ Resource className 3.0.0+ not be loaded, then the includes and excludes specified below will be applied to the contents of the sourceDirectory ]]> String property 3.0.0+ String UnitTest 3.0.0+ PatternSet resources 3.0.0+ Resource * Version 3.0.0 version element ]]> name 3.0.0 1.0, 1.1-alpha1, 1.2-beta, 1.3.2 etc. ]]> String tag 3.0.0 String id 3.0.0 maven:dist builds. ]]> String Repository 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String 4.0.0 public boolean equals( Object obj ) { Repository other = ( Repository ) obj; boolean retValue = false; if ( id != null ) { retValue = id.equals( other.id ); } return retValue; } Site 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String GoalDecorator 4.0.0 name 4.0.0 String attain 4.0.0 String GoalDecorator PreGoal 4.0.0 GoalDecorator PostGoal 4.0.0 Local 4.0.0 repository 4.0.0 String online 4.0.0 boolean true modello-1.1/modello-plugins/modello-plugin-xsd/src/test/resources/changes.mdo0000755000175000017500000002723511127507731026540 0ustar mkochmkoch changes Changes A recording of changes made during each release of a project. This file should record every changes made to the project. package org.apache.maven.plugins.changes.model ChangesDocument Record every release with their subsequent changes. 1.0.0 properties 1.0.0 Properties 1 Contains the properties of this document. body 1.0.0 true Body Contains the releases of this project with the actions taken for each of the releases. Properties 1.0.0 title 1.0.0 true String Page Title. author 1.0.0 Page Author Author 1 Body 1.0.0 releases 1.0.0 Release * The list of releases for this project. Release 1.0.0 A single release of this project. version 1.0.0 true String The version number associated with this release. dateRelease 1.0.0 true String The date of this release.

This field can be any String, such as "in SVN" when the version isn't yet released.

]]>
description 1.0.0 String A short description of this release. actions 1.0.0 Action * The list of actions taken for this release.
Author 1.0.0 A description of the author page. name 1.0.0 Content The page author name. authorEmail 1.0.0 String The page author email. Action 1.0.0 A single action done on the project, during this release. action 1.0.0 Content A short description of the action taken. dev 1.0.0 true String Name of developer who committed the change.

This MUST be the name of the developer as described in the developers section of the pom.xml file.

]]>
dueTo 1.0.0 String Name of the person to be credited for this change. This can be used when a patch is submitted by a non-committer. dueToEmail 1.0.0 String Email of the person to be credited for this change. issue 1.0.0 true String Id of the issue related to this change. This is the id in your issue tracking system.

The Changes plugin will generate a URL out of this id. The URL is constructed using the value of the issueLinkTemplate parameter.

See the changes-report mojo for more details.

]]>
type 1.0.0 true String
  • add : added functionnality to the project.
  • fix : bug fix for the project.
  • update : updated some part of the project.
  • remove : removed some functionnality from the project.
  • ]]>
    system 1.0.0 String Id of issue tracking system. If empty 'default' value will be use.

    The Changes plugin will generate a URL out of this id. The URL is constructed using the value of the issueLinkTemplatePerSystem parameter.

    See the changes-report mojo for more details.

    ]]>
    date 1.0.0 String fix date dueTos 1.0.0 DueTo * A list of contibutors for this issue. fixedIssues 1.0.0 FixedIssue * A list of fix issues.
    1.0.9+
    DueTo 1.0.0 Extras Name and Email of the person to be credited for this change. This can be used when a patch is submitted by a non-committer. name 1.0.0 String Name of the person to be credited for this change. email 1.0.0 String Name of the person to be credited for this change. FixedIssue 1.0.0 A fixed issue. issue 1.0.0 String Id of the issue related to this change. This is the id in your issue tracking system.

    The Changes plugin will generate a URL out of this id. The URL is constructed using the value of the issueLinkTemplate parameter.

    See the changes-report mojo for more details.

    ]]>
    modello-1.1/modello-plugins/modello-plugin-xsd/src/site/0000755000175000017500000000000011260056265022365 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/site/site.xml0000644000175000017500000000022511112331565024045 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-xsd/src/main/0000755000175000017500000000000011260056265022345 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/0000755000175000017500000000000011260056265023266 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/0000755000175000017500000000000011260056265024055 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/0000755000175000017500000000000011260056265025650 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056265027303 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056265030601 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/0000755000175000017500000000000011260056265031377 5ustar mkochmkoch././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadata/modello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadat0000755000175000017500000000000011260056265032737 5ustar mkochmkoch././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadata/XsdModelMetadata.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadat0000644000175000017500000000412411127742507032745 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd.metadata; /* * Copyright 2001-2007 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.Version; import org.codehaus.plexus.util.StringUtils; /** * XsdModelMetadata * * @author Joakim Erdfelt * @version $Id: XsdModelMetadata.java 1101 2009-01-03 20:06:31Z hboutemy $ */ public class XsdModelMetadata implements ModelMetadata { public static final String ID = XsdModelMetadata.class.getName(); private String namespace; private String targetNamespace; public String getNamespace() { return namespace; } public void setNamespace( String namespace ) { this.namespace = namespace; } public String getTargetNamespace() { return targetNamespace; } public void setTargetNamespace( String targetNamespace ) { this.targetNamespace = targetNamespace; } public String getNamespace( Version version ) { String namespace = this.namespace; if ( version != null ) { namespace = StringUtils.replace( namespace, "${version}", version.toString() ); } return namespace; } public String getTargetNamespace( Version version ) { String targetNamespace = this.targetNamespace; if ( version != null ) { targetNamespace = StringUtils.replace( targetNamespace, "${version}", version.toString() ); } return targetNamespace; } } ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadata/XsdAssociationMetadata.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadat0000644000175000017500000000202711127507731032743 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd.metadata; /* * Copyright 2001-2007 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.modello.metadata.AssociationMetadata; /** * XsdAssociationMetadata * * @author Joakim Erdfelt * @version $Id: XsdAssociationMetadata.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class XsdAssociationMetadata implements AssociationMetadata { public static final String ID = XsdAssociationMetadata.class.getName(); } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadata/XsdMetadataPlugin.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadat0000644000175000017500000000476111137160065032746 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd.metadata; /* * Copyright 2001-2007 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.metadata.AbstractMetadataPlugin; import org.codehaus.modello.metadata.AssociationMetadata; import org.codehaus.modello.metadata.ClassMetadata; import org.codehaus.modello.metadata.FieldMetadata; import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import java.util.Map; /** * XsdMetadataPlugin * * @author Joakim Erdfelt * @version $Id: XsdMetadataPlugin.java 1169 2009-01-25 21:57:09Z hboutemy $ */ public class XsdMetadataPlugin extends AbstractMetadataPlugin { public static final String NAMESPACE = "xsd.namespace"; public static final String TARGET_NAMESPACE = "xsd.targetNamespace"; public static final String COMPOSITOR = "xsd.compositor"; public AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) throws ModelloException { return new XsdAssociationMetadata(); } public ClassMetadata getClassMetadata( ModelClass clazz, Map data ) throws ModelloException { XsdClassMetadata metadata = new XsdClassMetadata(); metadata.setCompositor( getString( data, COMPOSITOR ) ); return metadata; } public FieldMetadata getFieldMetadata( ModelField field, Map data ) throws ModelloException { return new XsdFieldMetadata(); } public ModelMetadata getModelMetadata( Model model, Map data ) throws ModelloException { XsdModelMetadata metadata = new XsdModelMetadata(); metadata.setNamespace( getString( data, NAMESPACE ) ); metadata.setTargetNamespace( getString( data, TARGET_NAMESPACE ) ); return metadata; } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadata/XsdClassMetadata.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadat0000644000175000017500000000305311127507731032743 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd.metadata; /* * Copyright 2001-2007 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.modello.metadata.ClassMetadata; /** * XsdClassMetadata * * @author Joakim Erdfelt * @version $Id: XsdClassMetadata.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class XsdClassMetadata implements ClassMetadata { public static final String ID = XsdClassMetadata.class.getName(); public static final String COMPOSITOR_ALL = "all"; public static final String COMPOSITOR_SEQUENCE = "sequence"; private String compositor = COMPOSITOR_ALL; public String getCompositor() { return compositor; } public void setCompositor( String compositor ) { if ( COMPOSITOR_ALL.equals( compositor ) || COMPOSITOR_SEQUENCE.equals( compositor ) ) { this.compositor = compositor; } else { // default this.compositor = COMPOSITOR_ALL; } } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadata/XsdFieldMetadata.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadat0000644000175000017500000000176311127507731032751 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd.metadata; /* * Copyright 2001-2007 The Codehaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.modello.metadata.FieldMetadata; /** * XsdFieldMetadata * * @author Joakim Erdfelt * @version $Id: XsdFieldMetadata.java 1094 2009-01-02 22:06:17Z hboutemy $ */ public class XsdFieldMetadata implements FieldMetadata { public static final String ID = XsdFieldMetadata.class.getName(); } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGenerator.javamodello-1.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGene0000644000175000017500000005070711223730002032653 0ustar mkochmkochpackage org.codehaus.modello.plugin.xsd; /* * Copyright (c) 2005, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.xsd.metadata.XsdClassMetadata; import org.codehaus.modello.plugin.xsd.metadata.XsdModelMetadata; import org.codehaus.modello.plugins.xml.AbstractXmlGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlModelMetadata; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; import java.io.File; import java.io.IOException; import java.io.Writer; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Set; /** * @author Brett Porter * @version $Id: XsdGenerator.java 1274 2009-07-04 19:39:46Z hboutemy $ */ public class XsdGenerator extends AbstractXmlGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateXsd( parameters ); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating xsd.", ex ); } } private void generateXsd( Properties parameters ) throws IOException, ModelloException { Model objectModel = getModel(); File directory = getOutputDirectory(); if ( isPackageWithVersion() ) { directory = new File( directory, getGeneratedVersion().toString() ); } if ( !directory.exists() ) { directory.mkdirs(); } // we assume parameters not null String xsdFileName = parameters.getProperty( ModelloParameterConstants.OUTPUT_XSD_FILE_NAME ); File f = new File( directory, objectModel.getId() + "-" + getGeneratedVersion() + ".xsd" ); if ( xsdFileName != null ) { f = new File( directory, xsdFileName ); } Writer writer = WriterFactory.newXmlWriter( f ); try { XMLWriter w = new PrettyPrintXMLWriter( writer ); writer.write( "\n" ); initHeader( w ); // TODO: the writer should be knowledgeable of namespaces, but this works w.startElement( "xs:schema" ); w.addAttribute( "xmlns:xs", "http://www.w3.org/2001/XMLSchema" ); w.addAttribute( "elementFormDefault", "qualified" ); ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); XmlModelMetadata xmlModelMetadata = (XmlModelMetadata) root.getModel().getMetadata( XmlModelMetadata.ID ); XsdModelMetadata xsdModelMetadata = (XsdModelMetadata) root.getModel().getMetadata( XsdModelMetadata.ID ); String namespace; if ( StringUtils.isNotEmpty( xsdModelMetadata.getNamespace() ) ) { namespace = xsdModelMetadata.getNamespace( getGeneratedVersion() ); } else { // xsd.namespace is not set, try using xml.namespace if ( StringUtils.isEmpty( xmlModelMetadata.getNamespace() ) ) { throw new ModelloException( "Cannot generate xsd without xmlns specification:" + " or " ); } namespace = xmlModelMetadata.getNamespace( getGeneratedVersion() ); } w.addAttribute( "xmlns", namespace ); String targetNamespace; if ( xsdModelMetadata.getTargetNamespace() == null ) { // xsd.target-namespace not set, using namespace targetNamespace = namespace; } else { targetNamespace = xsdModelMetadata.getTargetNamespace( getGeneratedVersion() ); } // add targetNamespace if attribute is not blank (specifically set to avoid a target namespace) if ( StringUtils.isNotBlank( targetNamespace ) ) { w.addAttribute( "targetNamespace", targetNamespace ); } w.startElement( "xs:element" ); String tagName = resolveTagName( root ); w.addAttribute( "name", tagName ); w.addAttribute( "type", root.getName() ); writeClassDocumentation( w, root ); w.endElement(); // Element descriptors // Traverse from root so "abstract" models aren't included int initialCapacity = objectModel.getClasses( getGeneratedVersion() ).size(); writeComplexTypeDescriptor( w, objectModel, root, new HashSet( initialCapacity ) ); w.endElement(); } finally { writer.close(); } } private static void writeClassDocumentation( XMLWriter w, ModelClass modelClass ) { writeDocumentation( w, modelClass.getVersionRange().toString(), modelClass.getDescription() ); } private static void writeFieldDocumentation( XMLWriter w, ModelField field ) { writeDocumentation( w, field.getVersionRange().toString(), field.getDescription() ); } private static void writeDocumentation( XMLWriter w, String version, String description ) { if ( version != null || description != null ) { w.startElement( "xs:annotation" ); if ( version != null ) { w.startElement( "xs:documentation" ); w.addAttribute( "source", "version" ); w.writeText( version ); w.endElement(); } if ( description != null ) { w.startElement( "xs:documentation" ); w.addAttribute( "source", "description" ); w.writeText( description ); w.endElement(); } w.endElement(); } } private void writeComplexTypeDescriptor( XMLWriter w, Model objectModel, ModelClass modelClass, Set written ) { written.add( modelClass ); w.startElement( "xs:complexType" ); w.addAttribute( "name", modelClass.getName() ); List fields = getFieldsForClass( modelClass ); fields = getNonTransientFields( fields ); boolean hasContentField = hasContentField( fields ); List attributeFields = getAttributeFieldsForClass( modelClass ); fields.removeAll( attributeFields ); boolean mixedContent = hasContentField && fields.size() > 0; // other fields with complexType // if yes it's a mixed content element and attribute if ( mixedContent ) { w.addAttribute( "mixed", "true" ); } else if ( hasContentField ) { // yes it's only an extension of xs:string w.startElement( "xs:simpleContent" ); w.startElement( "xs:extension" ); w.addAttribute( "base", "xs:string" ); } writeClassDocumentation( w, modelClass ); Set toWrite = new HashSet(); if ( fields.size() > 0 ) { XsdClassMetadata xsdClassMetadata = (XsdClassMetadata) modelClass.getMetadata( XsdClassMetadata.ID ); boolean compositorAll = XsdClassMetadata.COMPOSITOR_ALL.equals( xsdClassMetadata.getCompositor() ); if ( ( mixedContent ) || ( !hasContentField ) ) { if ( compositorAll ) { w.startElement( "xs:all" ); } else { w.startElement( "xs:sequence" ); } } for ( Iterator j = fields.iterator(); j.hasNext(); ) { ModelField field = (ModelField) j.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); String fieldTagName = resolveTagName( field, xmlFieldMetadata ); if ( !hasContentField ) { w.startElement( "xs:element" ); // Usually, would only do this if the field is not "required", but due to inheritance, it may be // present, even if not here, so we need to let it slide w.addAttribute( "minOccurs", "0" ); } String xsdType = getXsdType( field.getType() ); if ( "Date".equals( field.getType() ) && "long".equals( xmlFieldMetadata.getFormat() ) ) { xsdType = getXsdType( "long" ); } if ( xmlFieldMetadata.isContent() ) { // nothing to add } else if ( ( xsdType != null ) || "char".equals( field.getType() ) || "Char".equals( field.getType() ) ) { w.addAttribute( "name", fieldTagName ); if ( xsdType != null ) { // schema built-in datatype w.addAttribute( "type", xsdType ); } if ( field.getDefaultValue() != null ) { w.addAttribute( "default", field.getDefaultValue() ); } writeFieldDocumentation( w, field ); if ( xsdType == null ) { writeCharElement( w ); } } else { // TODO cleanup/split this part it's no really human readable :-) if ( isInnerAssociation( field ) ) { ModelAssociation association = (ModelAssociation) field; ModelClass fieldModelClass = objectModel.getClass( association.getTo(), getGeneratedVersion() ); toWrite.add( fieldModelClass ); if ( association.isManyMultiplicity() ) { XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); if ( xmlAssociationMetadata.isWrappedItems() ) { w.addAttribute( "name", fieldTagName ); writeFieldDocumentation( w, field ); writeListElement( w, xmlFieldMetadata, xmlAssociationMetadata, field, fieldModelClass.getName() ); } else { if ( compositorAll ) { // xs:all does not accept maxOccurs="unbounded", xs:sequence MUST be used // to be able to represent this constraint throw new IllegalStateException( field.getName() + " field is declared as xml.listStyle=\"flat\" " + "then class " + modelClass.getName() + " MUST be declared as xsd.compositor=\"sequence\"" ); } if ( mixedContent ) { w.startElement( "xs:element" ); w.addAttribute( "minOccurs", "0" ); } w.addAttribute( "name", resolveTagName( fieldTagName, xmlAssociationMetadata ) ); w.addAttribute( "type", fieldModelClass.getName() ); w.addAttribute( "maxOccurs", "unbounded" ); writeFieldDocumentation( w, field ); if ( mixedContent ) { w.endElement(); } } } else { // not many multiplicity w.addAttribute( "name", fieldTagName ); w.addAttribute( "type", fieldModelClass.getName() ); writeFieldDocumentation( w, field ); } } else // not inner association { w.addAttribute( "name", fieldTagName ); writeFieldDocumentation( w, field ); if ( List.class.getName().equals( field.getType() ) || Set.class.getName().equals( field.getType() ) ) { ModelAssociation association = (ModelAssociation) field; XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); writeListElement( w, xmlFieldMetadata, xmlAssociationMetadata, field, getXsdType( "String" ) ); } else if ( Properties.class.getName().equals( field.getType() ) || "DOM".equals( field.getType() ) ) { writePropertiesElement( w ); } else { throw new IllegalStateException( "Non-association field of a non-primitive type '" + field.getType() + "' for '" + field.getName() + "' in '" + modelClass.getName() + "' model class" ); } } } if ( !hasContentField ) { w.endElement(); } }// end fields iterator if ( !hasContentField || mixedContent ) { w.endElement(); // xs:all or xs:sequence } } for ( Iterator j = attributeFields.iterator(); j.hasNext(); ) { ModelField field = (ModelField) j.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); w.startElement( "xs:attribute" ); String xsdType = getXsdType( field.getType() ); String tagName = resolveTagName( field, xmlFieldMetadata ); w.addAttribute( "name", tagName ); if ( xsdType != null ) { w.addAttribute( "type", xsdType ); } if ( field.getDefaultValue() != null ) { w.addAttribute( "default", field.getDefaultValue() ); } writeFieldDocumentation( w, field ); if ( "char".equals( field.getType() ) || "Char".equals( field.getType() ) ) { writeCharElement( w ); } else if ( xsdType == null ) { throw new IllegalStateException( "Attribute field of a non-primitive type '" + field.getType() + "' for '" + field.getName() + "' in '" + modelClass.getName() + "' model class" ); } w.endElement(); } if ( hasContentField && !mixedContent ) { w.endElement(); //xs:extension w.endElement(); //xs:simpleContent } w.endElement(); // xs:complexType for ( Iterator iter = toWrite.iterator(); iter.hasNext(); ) { ModelClass fieldModelClass = (ModelClass) iter.next(); if ( !written.contains( fieldModelClass ) ) { writeComplexTypeDescriptor( w, objectModel, fieldModelClass, written ); } } } private static void writeCharElement( XMLWriter w ) { // a char, described as a simpleType base on string with a length restriction to 1 w.startElement( "xs:simpleType" ); w.startElement( "xs:restriction" ); w.addAttribute( "base", "xs:string" ); w.startElement( "xs:length" ); w.addAttribute( "value", "1" ); w.addAttribute( "fixed", "true" ); w.endElement(); w.endElement(); w.endElement(); } private static void writePropertiesElement( XMLWriter w ) { w.startElement( "xs:complexType" ); w.startElement( "xs:sequence" ); w.startElement( "xs:any" ); w.addAttribute( "minOccurs", "0" ); w.addAttribute( "maxOccurs", "unbounded" ); w.addAttribute( "processContents", "skip" ); w.endElement(); w.endElement(); w.endElement(); } private void writeListElement( XMLWriter w, XmlFieldMetadata xmlFieldMetadata, XmlAssociationMetadata xmlAssociationMetadata, ModelField field, String type ) { String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); w.startElement( "xs:complexType" ); w.startElement( "xs:sequence" ); w.startElement( "xs:element" ); w.addAttribute( "name", valuesTagName ); w.addAttribute( "minOccurs", "0" ); w.addAttribute( "maxOccurs", "unbounded" ); w.addAttribute( "type", type ); w.endElement(); w.endElement(); w.endElement(); } private static String getXsdType( String type ) { if ( "String".equals( type ) ) { return "xs:string"; } else if ( "boolean".equals( type ) || "Boolean".equals( type ) ) { return "xs:boolean"; } else if ( "byte".equals( type ) || "Byte".equals( type ) ) { return "xs:byte"; } else if ( "short".equals( type ) || "Short".equals( type ) ) { return "xs:short"; } else if ( "int".equals( type ) || "Integer".equals( type ) ) { return "xs:int"; } else if ( "long".equals( type ) || "Long".equals( type ) ) { return "xs:long"; } else if ("float".equals( type ) || "Float".equals( type ) ) { return "xs:float"; } else if ("double".equals( type ) || "Double".equals( type ) ) { return "xs:double"; } else if ( "Date".equals( type ) ) { return "xs:dateTime"; } else { return null; } } } modello-1.1/modello-plugins/modello-plugin-xsd/src/main/resources/0000755000175000017500000000000011260056265024357 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/resources/META-INF/0000755000175000017500000000000011260056265025517 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056265027037 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xsd/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000077710647207577031775 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator xsd org.codehaus.modello.plugin.xsd.XsdGenerator org.codehaus.modello.metadata.MetadataPlugin xsd org.codehaus.modello.plugin.xsd.metadata.XsdMetadataPlugin modello-1.1/modello-plugins/modello-plugin-xdoc/0000755000175000017500000000000011260056265020771 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/pom.xml0000644000175000017500000000151111243557055022310 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-xdoc Modello XDOC Plugin Modello XDOC Plugin generates model documentation using xdoc markup to be included in a Maven-generated reporting site. org.codehaus.modello modello-plugin-xml modello-1.1/modello-plugins/modello-plugin-xdoc/src/0000755000175000017500000000000011260056265021560 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/0000755000175000017500000000000011260056265022537 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/0000755000175000017500000000000011260056265023460 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/0000755000175000017500000000000011260056265024247 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/0000755000175000017500000000000011260056265026042 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056265027475 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056265030773 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/0000755000175000017500000000000011260056265031730 5ustar mkochmkoch././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocG0000644000175000017500000001464411223745157032674 0ustar mkochmkochpackage org.codehaus.modello.plugin.xdoc; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.modello.verifier.VerifierException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.util.HashSet; import java.util.List; import java.util.Properties; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import junit.framework.Assert; /** * @author Trygve Laugstøl * @version $Id: XdocGeneratorTest.java 1275 2009-07-04 21:32:31Z bentmann $ */ public class XdocGeneratorTest extends AbstractModelloGeneratorTest { public XdocGeneratorTest() { super( "xdoc" ); } protected File getOutputDirectory() { return getTestFile( "target/generated-site/xdoc" ); } public void testXdocGenerator() throws Exception { checkMavenXdocGenerator(); checkFeaturesXdocGenerator(); } private void checkMavenXdocGenerator() throws Exception { ModelloCore modello = (ModelloCore) container.lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/maven.mdo" ) ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 26, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); ModelField extend = clazz.getField( "extend", new Version( "4.0.0" ) ); assertTrue( extend.hasMetadata( XmlFieldMetadata.ID ) ); XmlFieldMetadata xml = (XmlFieldMetadata) extend.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertTrue( xml.isAttribute() ); assertEquals( "extender", xml.getTagName() ); ModelField build = clazz.getField( "build", new Version( "4.0.0" ) ); assertTrue( build.hasMetadata( XmlFieldMetadata.ID ) ); xml = (XmlFieldMetadata) build.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertEquals( "builder", xml.getTagName() ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); modello.generate( model, "xdoc", parameters ); //addDependency( "modello", "modello-core", "1.0-SNAPSHOT" ); //verify( "org.codehaus.modello.generator.xml.cdoc.XdocVerifier", "xdoc" ); checkInternalLinks( "maven.xml" ); } public void checkFeaturesXdocGenerator() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.5.0" ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "xdoc", parameters ); checkInternalLinks( "features.xml" ); String content = FileUtils.fileRead( new File( getOutputDirectory(), "features.xml" ), "UTF-8" ); assertTrue( "Transient fields were erroneously documented", content.indexOf( "transientString" ) < 0 ); } /** * Checks internal links in the xdoc content: for every 'a href="#xxx"' link, a 'a name="xxx"' must exist (or there * is a problem in the generated content). * * @param xdoc * @throws Exception */ private void checkInternalLinks( String filename ) throws Exception { String content = FileUtils.fileRead( new File( getOutputDirectory(), filename ), "UTF-8" ); Set hrefs = new HashSet(); Pattern p = Pattern.compile( " package org.apache.maven.model Model 3.0.0+ extend 3.0.0+ String parent 4.0.0 Parent modelVersion 4.0.0 true String pomVersion 3.0.0 true String id 3.0.0 true String groupId 3.0.0+ true String artifactId 3.0.0+ true String type 4.0.0 String jar name 3.0.0+ true String currentVersion 3.0.0 true String version 4.0.0 true String shortDescription 3.0.0+ String description 3.0.0+ front page of the project's web site. ]]> String url 3.0.0+ String logo 3.0.0+ String issueTrackingUrl 3.0.0 String issueManagement 4.0.0 IssueManagement ciManagement 4.0.0 CiManagement inceptionYear 3.0.0+ true String gumpRepositoryId 3.0.0 String siteAddress 3.0.0 String siteDirectory 3.0.0 String distributionSite 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. distributionDirectory 3.0.0 String This naming is inconsistent and distribution should occur from a repository structure. repositories 4.0.0 Repository * pluginRepositories 4.0.0 Repository * This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own. mailingLists 3.0.0+ MailingList * developers 3.0.0+ developer element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> Developer * contributors 3.0.0+ contributor element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. ]]> Contributor * dependencies 3.0.0+ dependency element, which is then described by additional elements (described below). ]]> Dependency * These should ultimately only be compile time dependencies when transitive dependencies come into play. overrides 4.0.0 override element, which is then described by additional elements (described below). ]]> Override * licenses 3.0.0+ license element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. ]]> License * versions 3.0.0 Version * branches 3.0.0 Branch * packageGroups 3.0.0+ PackageGroup * reports 3.0.0+ maven site. All of the reports will be included in the navigation bar for browsing in the order they are specified. ]]> String * scm 4.0.0 Scm repository 3.0.0 Repository This element needs to be renamed as it conflicts with the existing notion of repositories in Maven. build 3.0.0+ true Build organization 3.0.0+ Organization distributionManagement 4.0.0 DistributionManagement local 4.0.0 false Local properties 3.0.0+ Properties String * preGoals 4.0.0 PreGoal * postGoals 4.0.0 PostGoal * 3.0.0 public void setVersion(String version) { this.currentVersion = version; } public String getVersion() { return currentVersion; } 3.0.0+ private String packageName; public void setPackage(String packageName) { this.packageName = packageName; } public String getPackage() { return packageName; } 4.0.0 public String getId() { StringBuffer id = new StringBuffer(); id.append( getGroupId() ); id.append( ":" ); id.append( getArtifactId() ); id.append( ":" ); id.append( getType() ); id.append( ":" ); id.append( getVersion() ); return id.toString(); } Branch 3.0.0+ tag element ]]> tag 3.0.0+ true String description 4.0.0 String lastMergeTag 4.0.0 String Build 3.0.0+ nagEmailAddress 3.0.0 maven:gump-descriptor target. ]]> String This should be moved out of the build section. Vestigal for use with Gump. sourceDirectory 3.0.0+ true String unitTestSourceDirectory 3.0.0+ true String aspectSourceDirectory 3.0.0+ Aspectj goals document). The path given is relative to the project descriptor. ]]> String integrationUnitTestSourceDirectory 3.0.0+ String sourceModifications 3.0.0+ true sourceModification element, which is then described by additional elements (described below). These modifications are used to exclude or include various source depending on the environment the build is running in. ]]> SourceModification * unitTest 3.0.0+ true new UnitTest() UnitTest resources 3.0.0+ below). These resources are used to complete the jar file or to run unit test. ]]> Resource * directory 4.0.0 String output 4.0.0 String finalName 4.0.0 String testOutput 4.0.0 String CiManagement 4.0.0 system 4.0.0 String url 4.0.0 String nagEmailAddress 4.0.0 String Contributor 3.0.0+ name 3.0.0+ String email 3.0.0+ String url 3.0.0+ String organization 3.0.0+ String roles 3.0.0+ role element, the body of which is a role name. ]]> String * timezone 3.0.0+ String Dependency 3.0.0+ id 3.0.0 true String groupId 3.0.0+ true geronimo. ]]> String artifactId 3.0.0+ true germonimo-jms ]]> String version 3.0.0+ true 3.2.1 ]]> String url 3.0.0+ String The URL should really be gleaned from a shared database of dependency information. jar 3.0.0 String artifact 4.0.0+ String type 3.0.0+ ejb and plugin. ]]> String jar properties 3.0.0+ mark dependencies with properties. For example the war plugin looks for a war.bundle property, and if found will include the dependency in WEB-INF/lib. For example syntax, check the war plugin docs. ]]> Properties String * 3.0.0+ public String toString() { return groupId + "/" + type + "s:" + artifactId + "-" + version; } 4.0.0 public String getId() { return groupId + ":" + artifactId + ":" + type + ":" + version; } 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } return getArtifactId() + "-" + getVersion() + "." + getExtension(); } public String getExtension() { if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof Dependency ) ) { return false; } Dependency d = (Dependency) o; return getId().equals( d.getId() ); } public int hashCode() { return getId().hashCode(); } ]]> Override 4.0.0 groupId 4.0.0 true geronimo. ]]> String artifactId 4.0.0 true germonimo-jms ]]> String type 4.0.0 ejb and plugin. ]]> String jar version 4.0.0 true 3.2.1 ]]> String file 4.0.0 true lib/non-distributable-code-1.3.jar ]]> String Contributor Developer 3.0.0+ id 3.0.0+ String IssueManagement 4.0.0 system 4.0.0 String url 4.0.0 String DistributionManagement 4.0.0 repository 4.0.0 Repository site 4.0.0 Site License 3.0.0+ name 3.0.0+ String url 3.0.0+ String distribution 3.0.0
    repo
    may be downloaded from the Maven repository
    manual
    user must manually download and install the dependency.
    ]]>
    String
    comments 3.0.0+ String
    MailingList 3.0.0+ mailingList element, which is then described by additional elements (described below). The auto-generated site documentation references this information. ]]> name 3.0.0+ String subscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String unsubscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String post 4.0.0 mailto: link will automatically be created when the documentation is created. ]]> String archive 3.0.0+ String This should probably be removed from 4.0.0 before alpha-1 archives 4.0.0 String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization 3.0.0+ name 3.0.0+ String url 3.0.0+ String logo 3.0.0+ /images/org-logo.png) or an absolute URL (e.g., http://my.corp/logo.png). This value is used when generating the project documentation. ]]> String PackageGroup 3.0.0+ title 3.0.0+ String packages 3.0.0+ String PatternSet 3.0.0+ includes 3.0.0+ String * excludes 3.0.0+ String * 3.0.0+ public List getDefaultExcludes() { List defaultExcludes = new ArrayList(); defaultExcludes.add( "**/*~" ); defaultExcludes.add( "**/#*#" ); defaultExcludes.add( "**/.#*" ); defaultExcludes.add( "**/%*%" ); defaultExcludes.add( "**/._*" ); // CVS defaultExcludes.add( "**/CVS" ); defaultExcludes.add( "**/CVS/**" ); defaultExcludes.add( "**/.cvsignore" ); // SCCS defaultExcludes.add( "**/SCCS" ); defaultExcludes.add( "**/SCCS/**" ); // Visual SourceSafe defaultExcludes.add( "**/vssver.scc" ); // Subversion defaultExcludes.add( "**/.svn" ); defaultExcludes.add( "**/.svn/**" ); // Mac defaultExcludes.add( "**/.DS_Store" ); return defaultExcludes; } Parent 4.0.0 artifactId 4.0.0 String groupId 4.0.0 String version 4.0.0 on of the project to extend.]]> String Repository 3.0.0 connection 3.0.0 building versions from specific ID. ]]> String developerConnection 3.0.0 String url 3.0.0 String Scm 4.0.0 connection 4.0.0 building versions from specific ID. ]]> String developerConnection 4.0.0 String url 4.0.0 String branches 4.0.0 String * Resource 3.0.0+ PatternSet directory 3.0.0+ String targetPath 3.0.0+ org.apache.maven.messages), you must specify this element with this value : org/apache/maven/messages ]]> String filtering 3.0.0+ boolean false SourceModification 3.0.0+ Resource className 3.0.0+ not be loaded, then the includes and excludes specified below will be applied to the contents of the sourceDirectory ]]> String property 3.0.0+ String UnitTest 3.0.0+ PatternSet resources 3.0.0+ Resource * Version 3.0.0 version element ]]> name 3.0.0 1.0, 1.1-alpha1, 1.2-beta, 1.3.2 etc. ]]> String tag 3.0.0 String id 3.0.0 maven:dist builds. ]]> String Repository 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String 4.0.0 public boolean equals( Object obj ) { Repository other = ( Repository ) obj; boolean retValue = false; if ( id != null ) { retValue = id.equals( other.id ); } return retValue; } Site 4.0.0 id 4.0.0 String name 4.0.0 String url 4.0.0 String GoalDecorator 4.0.0 name 4.0.0 String attain 4.0.0 String GoalDecorator PreGoal 4.0.0 GoalDecorator PostGoal 4.0.0 Local 4.0.0 repository 4.0.0 String online 4.0.0 boolean true
    modello-1.1/modello-plugins/modello-plugin-xdoc/src/site/0000755000175000017500000000000011260056265022524 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/site/site.xml0000644000175000017500000000036511114063762024214 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-xdoc/src/site/xdoc/0000755000175000017500000000000011260056265023461 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/site/xdoc/index.xml0000644000175000017500000000144011132164624025306 0ustar mkochmkoch Modello XDOC Plugin Hervé Boutemy

    Modello XDOC Plugin generates model documentation using xdoc markup to be included in a Maven-generated reporting site.

    xdoc generator creates model-id.xdoc documentation containing an XML representation of the model, followed by a table with explanation for every model class.

    An example is available to see the resulting document.

    modello-1.1/modello-plugins/modello-plugin-xdoc/src/main/0000755000175000017500000000000011260056265022504 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/0000755000175000017500000000000011260056265023425 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/0000755000175000017500000000000011260056265024214 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/0000755000175000017500000000000011260056265026007 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056265027442 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056265030740 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/0000755000175000017500000000000011260056265031675 5ustar mkochmkoch././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.javamodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocG0000644000175000017500000005631711223745157032644 0ustar mkochmkochpackage org.codehaus.modello.plugin.xdoc; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Set; import java.util.Stack; import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.model.BaseElement; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.model.VersionRange; import org.codehaus.modello.plugin.xdoc.metadata.XdocFieldMetadata; import org.codehaus.modello.plugins.xml.AbstractXmlGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlClassMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: XdocGenerator.java 1275 2009-07-04 21:32:31Z bentmann $ */ public class XdocGenerator extends AbstractXmlGenerator { private static final VersionRange DEFAULT_VERSION_RANGE = new VersionRange( "0.0.0+" ); private Version firstVersion = DEFAULT_VERSION_RANGE.getFromVersion(); private Version version = DEFAULT_VERSION_RANGE.getFromVersion(); public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); if ( parameters.getProperty( ModelloParameterConstants.FIRST_VERSION ) != null ) { firstVersion = new Version( parameters.getProperty( ModelloParameterConstants.FIRST_VERSION ) ); } if ( parameters.getProperty( ModelloParameterConstants.VERSION ) != null ) { version = new Version( parameters.getProperty( ModelloParameterConstants.VERSION ) ); } try { generateXdoc( parameters ); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating XDoc.", ex ); } } private void generateXdoc( Properties parameters ) throws IOException { Model objectModel = getModel(); File directory = getOutputDirectory(); if ( isPackageWithVersion() ) { directory = new File( directory, getGeneratedVersion().toString() ); } if ( !directory.exists() ) { directory.mkdirs(); } // we assume parameters not null String xdocFileName = parameters.getProperty( ModelloParameterConstants.OUTPUT_XDOC_FILE_NAME ); File f = new File( directory, objectModel.getId() + ".xml" ); if ( xdocFileName != null ) { f = new File( directory, xdocFileName ); } Writer writer = WriterFactory.newXmlWriter( f ); XMLWriter w = new PrettyPrintXMLWriter( writer ); writer.write( "\n" ); initHeader( w ); w.startElement( "document" ); w.startElement( "properties" ); writeTextElement( w, "title", objectModel.getName() ); w.endElement(); // Body w.startElement( "body" ); w.startElement( "section" ); w.addAttribute( "name", objectModel.getName() ); writeMarkupElement( w, "p", getDescription( objectModel ) ); // XML representation of the model with links ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); writeMarkupElement( w, "source", "\n" + getModelXmlDescriptor( root ) ); // Element descriptors // Traverse from root so "abstract" models aren't included writeModelDescriptor( w, root ); w.endElement(); w.endElement(); w.endElement(); writer.flush(); writer.close(); } /** * Get the anchor name by which model classes can be accessed in the generated xdoc/html file. * * @param tagName the name of the XML tag of the model class * @return the corresponding anchor name */ private String getAnchorName( String tagName ) { return "class_" + tagName ; } /** * Write description of the whole model. * * @param w the output writer * @param rootModelClass the root class of the model */ private void writeModelDescriptor( XMLWriter w, ModelClass rootModelClass ) { writeElementDescriptor( w, rootModelClass, null, new HashSet() ); } /** * Write description of an element of the XML representation of the model. This method is recursive. * * @param w the output writer * @param modelClass the mode class to describe * @param association the association we are coming from (can be null) * @param written set of data already written */ private void writeElementDescriptor( XMLWriter w, ModelClass modelClass, ModelAssociation association, Set written ) { String tagName = resolveTagName( modelClass, association ); String id = tagName + '/' + modelClass.getPackageName() + '.' + modelClass.getName(); if ( written.contains( id ) ) { // tag already written for this model class accessed as this tag name return; } written.add( id ); written.add( tagName ); w.startElement( "a" ); w.addAttribute( "name", getAnchorName( tagName ) ); w.endElement(); w.startElement( "subsection" ); w.addAttribute( "name", tagName ); writeMarkupElement( w, "p", getDescription( modelClass ) ); ModelField contentField = getContentField( getNonTransientFields( getFieldsForClass( modelClass ) ) ); if ( contentField != null ) { // this model class has a Content field w.startElement( "p" ); writeTextElement( w, "b", "Element Content: " ); w.writeMarkup( getDescription( contentField ) ); w.endElement(); } List attributeFields = new ArrayList( getAttributeFieldsForClass( modelClass ) ); attributeFields = getNonTransientFields( attributeFields ); List elementFields = new ArrayList( getFieldsForClass( modelClass ) ); elementFields.removeAll( attributeFields ); elementFields = getNonTransientFields( elementFields ); writeFieldsTable( w, attributeFields, false ); // write attributes writeFieldsTable( w, elementFields, true ); // write elements w.endElement(); // check every fields that are inner associations to write their element descriptor for ( Iterator iter = elementFields.iterator(); iter.hasNext(); ) { ModelField f = (ModelField) iter.next(); if ( isInnerAssociation( f ) ) { ModelAssociation assoc = (ModelAssociation) f; ModelClass fieldModelClass = getModel().getClass( assoc.getTo(), getGeneratedVersion() ); if ( !written.contains( resolveTagName( fieldModelClass, assoc ) ) ) { writeElementDescriptor( w, fieldModelClass, assoc, written ); } } } } /** * Write a table containing model fields description. * * @param w the output writer * @param fields the fields to add in the table * @param elementFields true if fields are elements, false if fields are attributes */ private void writeFieldsTable( XMLWriter w, List fields, boolean elementFields ) { if ( fields == null || fields.isEmpty() ) { // skip empty table return; } // skip if only one element field with xml.content == true if ( elementFields && ( fields.size() == 1 ) && hasContentField( fields ) ) { return; } w.startElement( "table" ); w.startElement( "tr" ); writeTextElement( w, "th", elementFields ? "Element" : "Attribute" ); writeTextElement( w, "th", "Type" ); boolean showSinceColumn = version.greaterThan( firstVersion ); if ( showSinceColumn ) { writeTextElement( w, "th", "Since" ); } writeTextElement( w, "th", "Description" ); w.endElement(); // tr for ( Iterator j = fields.iterator(); j.hasNext(); ) { ModelField f = (ModelField) j.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) f.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isContent() ) { continue; } w.startElement( "tr" ); // Element/Attribute column String tagName = resolveTagName( f, xmlFieldMetadata ); w.startElement( "td" ); w.startElement( "code" ); boolean manyAssociation = false; if ( f instanceof ModelAssociation ) { ModelAssociation assoc = (ModelAssociation) f; XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) assoc.getAssociationMetadata( XmlAssociationMetadata.ID ); manyAssociation = assoc.isManyMultiplicity(); String itemTagName = manyAssociation ? resolveTagName( tagName, xmlAssociationMetadata ) : tagName; if ( manyAssociation && xmlAssociationMetadata.isWrappedItems() ) { w.writeText( tagName ); w.writeMarkup( "/" ); } if ( isInnerAssociation( f ) ) { w.startElement( "a" ); w.addAttribute( "href", "#" + getAnchorName( itemTagName ) ); w.writeText( itemTagName ); w.endElement(); } else if ( ModelDefault.PROPERTIES.equals( f.getType() ) ) { if ( xmlAssociationMetadata.isMapExplode() ) { w.writeText( "(key,value)" ); } else { w.writeMarkup( "key=value" ); } } else { w.writeText( itemTagName ); } if (manyAssociation ) { w.writeText( "*" ); } } else { w.writeText( tagName ); } w.endElement(); // code w.endElement(); // td // Type column w.startElement( "td" ); w.startElement( "code" ); if ( f instanceof ModelAssociation ) { ModelAssociation assoc = (ModelAssociation) f; if ( assoc.isOneMultiplicity() ) { w.writeText( assoc.getTo() ); } else { w.writeText( assoc.getType().substring( "java.util.".length() ) ); if ( assoc.isGenericType() ) { w.writeText( "<" + assoc.getTo() + ">" ); } } } else { w.writeText( f.getType() ); } w.endElement(); // code w.endElement(); // td // Since column if ( showSinceColumn ) { w.startElement( "td" ); if ( f.getVersionRange() != null ) { Version fromVersion = f.getVersionRange().getFromVersion(); if ( fromVersion != null && fromVersion.greaterThan( firstVersion ) ) { w.writeMarkup( fromVersion.toString() ); } } w.endElement(); } // Description column w.startElement( "td" ); if ( manyAssociation ) { w.writeMarkup( "(Many) " ); } w.writeMarkup( getDescription( f ) ); // Write the default value, if it exists. // But only for fields that are not a ModelAssociation if ( f.getDefaultValue() != null && !( f instanceof ModelAssociation ) ) { w.writeMarkup( "
    Default value is: " ); writeTextElement( w, "code", f.getDefaultValue() ); w.writeText( "." ); } w.endElement(); // td w.endElement(); // tr } w.endElement(); // table } /** * Build the pretty tree describing the XML representation of the model. * * @param rootModelClass the model root class * @return the String representing the tree model */ private String getModelXmlDescriptor( ModelClass rootModelClass ) { return getElementXmlDescriptor( rootModelClass, null, new Stack() ); } /** * Build the pretty tree describing the XML representation of an element of the model. This method is recursive. * * @param modelClass the class we are printing the model * @param association the association we are coming from (can be null) * @param stack the stack of elements that have been traversed to come to the current one * @return the String representing the tree model * @throws ModelloRuntimeException */ private String getElementXmlDescriptor( ModelClass modelClass, ModelAssociation association, Stack stack ) throws ModelloRuntimeException { StringBuffer sb = new StringBuffer(); appendSpacer( sb, stack.size() ); String tagName = resolveTagName( modelClass, association ); sb.append( "<" ); sb.append( tagName ).append( "" ); String id = tagName + '/' + modelClass.getPackageName() + '.' + modelClass.getName(); if ( stack.contains( id ) ) { // recursion detected sb.append( ">...recursion...<" ).append( tagName ).append( ">\n" ); return sb.toString(); } List attributeFields = getAttributeFieldsForClass( modelClass ); attributeFields = getNonTransientFields( attributeFields ); if ( attributeFields.size() > 0 ) { for ( Iterator iter = attributeFields.iterator(); iter.hasNext(); ) { ModelField f = (ModelField) iter.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) f.getMetadata( XmlFieldMetadata.ID ); sb.append( ' ' ); sb.append( resolveTagName( f, xmlFieldMetadata ) ).append( "=.." ); } sb.append( ' ' ); } List fields = getFieldsForClass( modelClass ); fields.removeAll( attributeFields ); fields = getNonTransientFields( fields ); if ( ( fields.size() == 0 ) || ( ( fields.size() == 1 ) && hasContentField( fields ) ) ) { sb.append( "/>\n" ); } else { sb.append( ">\n" ); stack.push( id ); for ( Iterator iter = fields.iterator(); iter.hasNext(); ) { ModelField f = (ModelField) iter.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) f.getMetadata( XmlFieldMetadata.ID ); XdocFieldMetadata xdocFieldMetadata = (XdocFieldMetadata) f.getMetadata( XdocFieldMetadata.ID ); if ( XdocFieldMetadata.BLANK.equals( xdocFieldMetadata.getSeparator() ) ) { sb.append( '\n' ); } String fieldTagName = resolveTagName( f, xmlFieldMetadata ); if ( isInnerAssociation( f ) ) { ModelAssociation assoc = (ModelAssociation) f; boolean wrappedItems = false; if ( assoc.isManyMultiplicity() ) { XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) assoc.getAssociationMetadata( XmlAssociationMetadata.ID ); wrappedItems = xmlAssociationMetadata.isWrappedItems(); } if ( wrappedItems ) { appendSpacer( sb, stack.size() ); sb.append( "<" ).append( fieldTagName ).append( ">\n" ); stack.push( fieldTagName ); } ModelClass fieldModelClass = getModel().getClass( assoc.getTo(), getGeneratedVersion() ); sb.append( getElementXmlDescriptor( fieldModelClass, assoc, stack ) ); if ( wrappedItems ) { stack.pop(); appendSpacer( sb, stack.size() ); sb.append( "</" ).append( fieldTagName ).append( ">\n" ); } } else if ( ModelDefault.PROPERTIES.equals( f.getType() ) ) { ModelAssociation assoc = (ModelAssociation) f; XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) assoc.getAssociationMetadata( XmlAssociationMetadata.ID ); appendSpacer( sb, stack.size() ); sb.append( "<" ).append( fieldTagName ).append( ">\n" ); if ( xmlAssociationMetadata.isMapExplode() ) { appendSpacer( sb, stack.size() + 1 ); sb.append( "<key/>\n" ); appendSpacer( sb, stack.size() + 1 ); sb.append( "<value/>\n" ); } else { appendSpacer( sb, stack.size() + 1 ); sb.append( "<key>value</key>\n" ); } appendSpacer( sb, stack.size() ); sb.append( "<" ).append( fieldTagName ).append( "/>\n" ); } else { appendSpacer( sb, stack.size() ); sb.append( "<" ).append( fieldTagName ).append( "/>\n" ); } } stack.pop(); appendSpacer( sb, stack.size() ); sb.append( "</" ).append( tagName ).append( ">\n" ); } return sb.toString(); } /** * Compute the tagName of a given class, living inside an association. * @param modelClass the class we are looking for the tag name * @param association the association where this class is used * @return the tag name to use * @todo refactor to use resolveTagName helpers instead */ private String resolveTagName( ModelClass modelClass, ModelAssociation association ) { XmlClassMetadata xmlClassMetadata = (XmlClassMetadata) modelClass.getMetadata( XmlClassMetadata.ID ); String tagName; if ( xmlClassMetadata == null || xmlClassMetadata.getTagName() == null ) { if ( association == null ) { tagName = uncapitalise( modelClass.getName() ); } else { tagName = association.getName(); if ( association.isManyMultiplicity() ) { tagName = singular( tagName ); } } } else { tagName = xmlClassMetadata.getTagName(); } if ( association != null ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) association.getMetadata( XmlFieldMetadata.ID ); XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); if ( xmlFieldMetadata != null ) { if ( xmlAssociationMetadata.getTagName() != null ) { tagName = xmlAssociationMetadata.getTagName(); } else if ( xmlFieldMetadata.getTagName() != null ) { tagName = xmlFieldMetadata.getTagName(); if ( association.isManyMultiplicity() ) { tagName = singular( tagName ); } } } } return tagName; } /** * Appends the required spacers to the given StringBuffer. * @param sb where to append the spacers * @param depth the depth of spacers to generate */ private static void appendSpacer( StringBuffer sb, int depth ) { for ( int i = 0; i < depth; i++ ) { sb.append( " " ); } } private static String getDescription( BaseElement element ) { return ( element.getDescription() == null ) ? "No description." : element.getDescription(); } private static void writeTextElement( XMLWriter w, String name, String text ) { w.startElement( name ); w.writeText( text ); w.endElement(); } private static void writeMarkupElement( XMLWriter w, String name, String markup ) { w.startElement( name ); w.writeMarkup( markup ); w.endElement(); } } ././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadata/modello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metad0000755000175000017500000000000011260056265032710 5ustar mkochmkoch././@LongLink0000000000000000000000000000020500000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadata/XdocAssociationMetadata.javamodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metad0000644000175000017500000000273411124302740032707 0ustar mkochmkochpackage org.codehaus.modello.plugin.xdoc.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AssociationMetadata; /** * @author Hervé Boutemy * @version $Id: XdocAssociationMetadata.java 1044 2008-12-24 00:44:16Z hboutemy $ */ public class XdocAssociationMetadata implements AssociationMetadata { public static final String ID = XdocAssociationMetadata.class.getName(); } ././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadata/XdocMetadataPlugin.javamodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metad0000644000175000017500000000532311136710116032707 0ustar mkochmkochpackage org.codehaus.modello.plugin.xdoc.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.metadata.AbstractMetadataPlugin; import org.codehaus.modello.metadata.AssociationMetadata; import org.codehaus.modello.metadata.ClassMetadata; import org.codehaus.modello.metadata.FieldMetadata; import org.codehaus.modello.metadata.MetadataPlugin; import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import java.util.Map; /** * @author Hervé Boutemy * @version $Id: XdocMetadataPlugin.java 1157 2009-01-24 22:03:58Z hboutemy $ */ public class XdocMetadataPlugin extends AbstractMetadataPlugin implements MetadataPlugin { public static final String XDOC_SEPARATOR = "xdoc.separator"; public ClassMetadata getClassMetadata( ModelClass clazz, Map data ) { return new XdocClassMetadata(); } public AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) throws ModelloException { return new XdocAssociationMetadata(); } public FieldMetadata getFieldMetadata( ModelField field, Map data ) throws ModelloException { XdocFieldMetadata metadata = new XdocFieldMetadata(); metadata.setSeparator( getString( data, XDOC_SEPARATOR ) ); return metadata; } public ModelMetadata getModelMetadata( Model model, Map data ) throws ModelloException { return new XdocModelMetadata(); } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadata/XdocClassMetadata.javamodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metad0000644000175000017500000000267611124302740032714 0ustar mkochmkochpackage org.codehaus.modello.plugin.xdoc.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.ClassMetadata; /** * @author Hervé Boutemy * @version $Id: XdocClassMetadata.java 1044 2008-12-24 00:44:16Z hboutemy $ */ public class XdocClassMetadata implements ClassMetadata { public static final String ID = XdocClassMetadata.class.getName(); } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadata/XdocFieldMetadata.javamodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metad0000644000175000017500000000334711124302740032710 0ustar mkochmkochpackage org.codehaus.modello.plugin.xdoc.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.FieldMetadata; /** * @author Hervé Boutemy * @version $Id: XdocFieldMetadata.java 1044 2008-12-24 00:44:16Z hboutemy $ */ public class XdocFieldMetadata implements FieldMetadata { public final static String ID = XdocFieldMetadata.class.getName(); public static final String NONE = "none"; public static final String BLANK = "blank"; private String separator; public String getSeparator() { return separator; } public void setSeparator( String separator ) { this.separator = separator; } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadata/XdocModelMetadata.javamodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metad0000644000175000017500000000267611124302740032714 0ustar mkochmkochpackage org.codehaus.modello.plugin.xdoc.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.ModelMetadata; /** * @author Hervé Boutemy * @version $Id: XdocModelMetadata.java 1044 2008-12-24 00:44:16Z hboutemy $ */ public class XdocModelMetadata implements ModelMetadata { public static final String ID = XdocModelMetadata.class.getName(); } modello-1.1/modello-plugins/modello-plugin-xdoc/src/main/resources/0000755000175000017500000000000011260056265024516 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/resources/META-INF/0000755000175000017500000000000011260056265025656 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056265027176 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xdoc/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000100111124302740032064 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator xdoc org.codehaus.modello.plugin.xdoc.XdocGenerator org.codehaus.modello.metadata.MetadataPlugin xdoc org.codehaus.modello.plugin.xdoc.metadata.XdocMetadataPlugin modello-1.1/modello-plugins/pom.xml0000644000175000017500000000302011243557055016423 0ustar mkochmkoch modello org.codehaus.modello 1.1 4.0.0 modello-plugins pom Modello Plugins Modello Plugins is the main component containing every Modello plugins that are able to generate various types of code and descriptors. modello-plugin-java modello-plugin-converters modello-plugin-xml modello-plugin-xdoc modello-plugin-xsd modello-plugin-xpp3 modello-plugin-stax modello-plugin-jdom modello-plugin-dom4j org.codehaus.plexus plexus-container-default org.codehaus.modello modello-core org.codehaus.modello modello-test test modello-1.1/modello-plugins/modello-plugin-dom4j/0000755000175000017500000000000011260056265021051 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/pom.xml0000644000175000017500000000244011243557055022372 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-dom4j Modello Dom4J Plugin Modello Dom4J Plugin generates XML readers and writers based on Dom4J API. org.codehaus.modello modello-plugin-java org.codehaus.modello modello-plugin-xml dom4j dom4j 1.6.1 test xmlunit xmlunit 1.2 test modello-1.1/modello-plugins/modello-plugin-dom4j/src/0000755000175000017500000000000011260056265021640 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/0000755000175000017500000000000011260056264022616 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/0000755000175000017500000000000011260056264024614 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/0000755000175000017500000000000011260056264026432 5ustar mkochmkoch././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/Dom4jFeaturesVerifier.javamodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/Dom4jFeaturesVerifier.j0000644000175000017500000001612011241500015032740 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.dom4j; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.features.Features; import org.codehaus.modello.test.features.io.dom4j.ModelloFeaturesTestDom4jReader; import org.codehaus.modello.test.features.io.dom4j.ModelloFeaturesTestDom4jWriter; import org.codehaus.modello.verifier.Verifier; import org.codehaus.modello.verifier.VerifierException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import org.dom4j.DocumentException; import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; /** * @author Herve Boutemy * @version $Id: Dom4jFeaturesVerifier.java 1306 2009-08-15 09:29:49Z hboutemy $ */ public class Dom4jFeaturesVerifier extends Verifier { public void verify() throws Exception { Features features = verifyReader(); features.getXmlFeatures().getXmlTransientFields().setTransientString( "NOT-TO-BE-WRITTEN" ); verifyWriter( features ); verifyBadVersion(); verifyWrongElement(); verifyTransientElement(); verifyEncoding(); } public Features verifyReader() throws Exception { ModelloFeaturesTestDom4jReader reader = new ModelloFeaturesTestDom4jReader(); return reader.read( getClass().getResource( "/features.xml" ) ); } public void verifyWriter( Features features ) throws Exception { ModelloFeaturesTestDom4jWriter writer = new ModelloFeaturesTestDom4jWriter(); StringWriter buffer = new StringWriter(); writer.write( buffer, features ); String initialXml = IOUtil.toString( getXmlResourceReader( "/features.xml" ) ); String actualXml = buffer.toString(); // alias is rendered as default field name => must be reverted here to let the test pass actualXml = actualXml.replaceFirst( "alias", "alias" ); //assertTrue( actualXml.substring( 0, 38 ), actualXml.startsWith( "" ) ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreComments( true ); Diff diff = XMLUnit.compareXML( initialXml, actualXml ); if ( !diff.identical() ) { System.err.println( actualXml ); throw new VerifierException( "writer result is not the same as original content: " + diff ); } } public void verifyBadVersion() throws Exception { ModelloFeaturesTestDom4jReader reader = new ModelloFeaturesTestDom4jReader(); try { reader.read( getClass().getResource( "/features-bad-version.xml" ) ); //throw new VerifierException( "Reading a document with a version different from the version of the parser should fail." ); System.err.print( "[WARNING] missing feature: reading a document with a version different from the version of the parser should fail." ); } catch ( DocumentException de ) { checkExpectedFailure( de, "Document model version of '2.0.0' doesn't match reader version of '1.0.0'" ); } } public void verifyWrongElement() throws Exception { ModelloFeaturesTestDom4jReader reader = new ModelloFeaturesTestDom4jReader(); // reading with strict=false should accept unknown element reader.read( getClass().getResource( "/features-wrong-element.xml" ), false ); reader.read( getClass().getResource( "/features-wrong-element2.xml" ), false ); // by default, strict=true: reading should not accept unknown element try { reader.read( getClass().getResource( "/features-wrong-element.xml" ) ); throw new VerifierException( "Reading a document with an unknown element under strict option should fail." ); } catch ( DocumentException de ) { checkExpectedFailure( de, "'invalidElement'" ); } try { reader.read( getClass().getResource( "/features-wrong-element2.xml" ) ); throw new VerifierException( "Reading a document with an unknown element under strict option should fail." ); } catch ( DocumentException de ) { checkExpectedFailure( de, "'invalidElement'" ); } } public void verifyTransientElement() throws Exception { ModelloFeaturesTestDom4jReader reader = new ModelloFeaturesTestDom4jReader(); try { reader.read( getClass().getResource( "/features-invalid-transient.xml" ) ); fail( "Transient fields should not be processed by parser." ); } catch ( DocumentException e ) { checkExpectedFailure( e, "transientString" ); } } private void checkExpectedFailure( DocumentException de, String expectedMessage ) throws VerifierException { if ( de.getMessage().indexOf( expectedMessage ) < 0 ) { throw new VerifierException( "Unexpected failure: \"" + de.getMessage() + "\"", de ); } } public void verifyEncoding() throws Exception { ModelloFeaturesTestDom4jReader reader = new ModelloFeaturesTestDom4jReader(); Features features = reader.read( getClass().getResource( "/features.xml" ) ); //assertEquals( "modelEncoding", null, features.getModelEncoding() ); features = reader.read( getClass().getResource( "/features-UTF-8.xml" ) ); //assertEquals( "modelEncoding", "UTF-8", features.getModelEncoding() ); features = reader.read( getClass().getResource( "/features-Latin-15.xml" ) ); // Dom4J's Document.getXMLEncoding() does not work: encoding used by the document is not stored... //assertEquals( "modelEncoding", "ISO-8859-15", features.getModelEncoding() ); // encoding is not set when reading file, not useful to check whether it is written back... } } modello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/0000755000175000017500000000000011260056264025631 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/Dom4jVerifier.java0000644000175000017500000003631511117305347031155 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.dom4j; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.Build; import org.codehaus.modello.test.model.Component; import org.codehaus.modello.test.model.MailingList; import org.codehaus.modello.test.model.Model; import org.codehaus.modello.test.model.Organization; import org.codehaus.modello.test.model.Repository; import org.codehaus.modello.test.model.Scm; import org.codehaus.modello.test.model.SourceModification; import org.codehaus.modello.test.model.io.dom4j.MavenDom4jReader; import org.codehaus.modello.test.model.io.dom4j.MavenDom4jWriter; import org.codehaus.modello.verifier.Verifier; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.dom4j.DocumentException; import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.io.Reader; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Properties; import java.util.TimeZone; /** * @author Trygve Laugstøl * @version $Id: Dom4jVerifier.java 985 2008-12-08 21:00:23Z hboutemy $ */ public class Dom4jVerifier extends Verifier { /** * TODO: Add a association thats not under the root element */ public void verify() throws IOException, DocumentException { verifyReader(); verifyReaderAliases(); verifyReaderDuplicates(); TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); verifyWriter(); } public void verifyEncodedRead() throws IOException, DocumentException { String path = "src/test/verifiers/dom4j/expected-encoding.xml"; Reader reader = ReaderFactory.newXmlReader( new File( path ) ); MavenDom4jReader modelReader = new MavenDom4jReader(); Model model = modelReader.read( reader ); Assert.assertEquals( "Maven\u00A9", model.getName() ); } public void verifyWriter() throws IOException, DocumentException { String expectedXml = FileUtils.fileRead( getTestFile( "src/test/verifiers/dom4j/expected.xml" ) ); // ---------------------------------------------------------------------- // Build the model thats going to be written. // ---------------------------------------------------------------------- Model expected = new Model(); expected.setExtend( "/foo/bar" ); expected.setName( "Maven" ); expected.setModelVersion( "4.0.0" ); MailingList mailingList = new MailingList(); mailingList.setName( "Mailing list" ); mailingList.setSubscribe( "Super Subscribe" ); mailingList.setUnsubscribe( "Duper Unsubscribe" ); mailingList.setArchive( "?ber Archive" ); expected.addMailingList( mailingList ); Scm scm = new Scm(); String connection = "connection"; String developerConnection = "developerConnection"; String url = "url"; scm.setConnection( connection ); scm.setDeveloperConnection( developerConnection ); scm.setUrl( url ); expected.setScm( scm ); Build build = new Build(); build.setSourceDirectory( "src/main/java" ); build.setUnitTestSourceDirectory( "src/test/java" ); SourceModification sourceModification = new SourceModification(); sourceModification.setClassName( "excludeEclipsePlugin" ); sourceModification.setDirectory( "foo" ); sourceModification.addExclude( "de/abstrakt/tools/codegeneration/eclipse/*.java" ); build.addSourceModification( sourceModification ); expected.setBuild( build ); Component component = new Component(); component.setName( "component1" ); expected.addComponent( component ); component = new Component(); component.setName( "component2" ); component.setComment( "comment2" ); expected.addComponent( component ); Component c2 = new Component(); c2.setName( "sub" ); c2.setComment( "subcomment" ); component.getComponents().add( c2 ); component = new Component(); component.setName( "component3" ); Xpp3Dom xpp3Dom = new Xpp3Dom( "custom" ); Xpp3Dom child = new Xpp3Dom( "foo" ); child.setValue( "bar" ); xpp3Dom.addChild( child ); child = new Xpp3Dom( "bar" ); child.setAttribute( "att1", "value" ); child.setValue( "baz" ); xpp3Dom.addChild( child ); child = new Xpp3Dom( "el1" ); xpp3Dom.addChild( child ); Xpp3Dom el1 = child; child = new Xpp3Dom( "el2" ); child.setValue( "text" ); el1.addChild( child ); component.setCustom( xpp3Dom ); expected.addComponent( component ); component = new Component(); component.setName( "component4" ); expected.addComponent( component ); Properties properties = new Properties(); properties.setProperty( "name", "value" ); component.setFlatProperties( properties ); properties = new Properties(); properties.setProperty( "key", "theValue" ); component.setProperties( properties ); Repository repository = new Repository(); repository.setId( "foo" ); expected.addRepository( repository ); // ---------------------------------------------------------------------- // Write out the model // ---------------------------------------------------------------------- MavenDom4jWriter writer = new MavenDom4jWriter(); StringWriter buffer = new StringWriter(); writer.write( buffer, expected ); String actualXml = buffer.toString(); // System.out.println( expectedXml ); // // System.err.println( actualXml ); Assert.assertEquals( expectedXml.trim(), actualXml.trim() ); MavenDom4jReader reader = new MavenDom4jReader(); Model actual = reader.read( new StringReader( actualXml ) ); Assert.assertNotNull( "Actual", actual ); assertModel( expected, actual ); buffer = new StringWriter(); writer.write( buffer, actual ); Assert.assertEquals( expectedXml.trim(), buffer.toString().trim() ); } public void verifyReader() throws IOException, DocumentException { MavenDom4jReader reader = new MavenDom4jReader(); // ---------------------------------------------------------------------- // Test that the entities is properly resolved // ---------------------------------------------------------------------- String xml = "\n" + "]>\n\n" + " Laugstøl\n" + ""; Model expected = new Model(); String groupId = "Laugst\u00f8l"; expected.setGroupId( groupId ); Model actual = reader.read( new StringReader( xml ) ); assertModel( expected, actual ); } public void verifyReaderAliases() throws IOException, DocumentException { MavenDom4jReader reader = new MavenDom4jReader(); String xml = "\n" + " http://maven.apache.org/website\n" + " my-org\n" + ""; Model expected = new Model(); expected.setUrl( "http://maven.apache.org/website" ); Organization org = new Organization(); org.setName( "my-org" ); expected.setOrganization( org ); Model actual = reader.read( new StringReader( xml ) ); assertModel( expected, actual ); } public void verifyReaderDuplicates() throws IOException, DocumentException { MavenDom4jReader reader = new MavenDom4jReader(); String xml = "\n" + " \n" + ""; /* TODO try { reader.read( new StringReader( xml ) ); Assert.fail( "Should have obtained a parse error for duplicate sourceDirectory" ); } catch ( DocumentException expected ) { Assert.assertTrue( true ); } xml = "\n" + " \n" + " \n" + ""; try { reader.read( new StringReader( xml ) ); Assert.fail( "Should have obtained a parse error for duplicate build" ); } catch ( DocumentException expected ) { Assert.assertTrue( true ); } */ } // ---------------------------------------------------------------------- // Assertions // ---------------------------------------------------------------------- public void assertModel( Model expected, Model actual ) { Assert.assertNotNull( "Actual model", actual ); Assert.assertEquals( "/model/extend", expected.getExtend(), actual.getExtend() ); // assertParent( expected.getParent(), actual.getParent() ); Assert.assertEquals( "/model/modelVersion", expected.getModelVersion(), actual.getModelVersion() ); Assert.assertEquals( "/model/groupId", expected.getGroupId(), actual.getGroupId() ); Assert.assertEquals( "/model/artifactId", expected.getArtifactId(), actual.getArtifactId() ); Assert.assertEquals( "/model/type", expected.getType(), actual.getType() ); Assert.assertEquals( "/model/name", expected.getName(), actual.getName() ); Assert.assertEquals( "/model/version", expected.getVersion(), actual.getVersion() ); Assert.assertEquals( "/model/shortDescription", expected.getShortDescription(), actual.getShortDescription() ); Assert.assertEquals( "/model/description", expected.getDescription(), actual.getDescription() ); Assert.assertEquals( "/model/url", expected.getUrl(), actual.getUrl() ); Assert.assertEquals( "/model/logo", expected.getLogo(), actual.getLogo() ); // assertIssueManagement(); // assertCiManagement(); Assert.assertEquals( "/model/inceptionYear", expected.getInceptionYear(), actual.getInceptionYear() ); // assertEquals( "/model/siteAddress", expected.getSiteAddress(), actual.getSiteAddress() ); // assertEquals( "/model/siteDirectory", expected.getSiteDirectory(), actual.getSiteDirectory() ); // assertEquals( "/model/distributionSite", expected.getDistributionSite(), actual.getDistributionSite() ); // assertEquals( "/model/distributionDirectory", expected.getDistributionDirectory(), actual.getDistributionDirectory() ); assertMailingLists( expected.getMailingLists(), actual.getMailingLists() ); /* assertDevelopers( ); assertContributors( ); assertDependencies( ); assertLicenses( ); assertPackageGroups( ); assertReports( ); */ assertScm( expected.getScm(), actual.getScm() ); /* assertBuild( ); assertOrganization( expected.getOrganization(), actual.getOrganization() ); */ assertBuild( expected.getBuild(), actual.getBuild() ); } public void assertMailingLists( List expected, List actual ) { Assert.assertNotNull( "/model/mailingLists", actual ); Assert.assertEquals( "/model/mailingLists.size", expected.size(), actual.size() ); for ( int i = 0; i < expected.size(); i++ ) { assertMailingList( i, (MailingList) expected.get( i ), actual.get( i ) ); } } public void assertMailingList( int i, MailingList expected, Object actualObject ) { Assert.assertNotNull( "/model/mailingLists[" + i + "]", actualObject ); Assert.assertEquals( "/model/mailingLists", MailingList.class, actualObject.getClass() ); MailingList actual = (MailingList) actualObject; Assert.assertEquals( "/model/mailingLists[" + i + "]/name", expected.getName(), actual.getName() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/subscribe", expected.getSubscribe(), actual.getSubscribe() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/unsubscribe", expected.getUnsubscribe(), actual.getUnsubscribe() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/archive", expected.getArchive(), actual.getArchive() ); } public void assertScm( Scm expected, Object actualObject ) { if ( expected == null ) { Assert.assertNull( "/model/scm", actualObject ); } else { Assert.assertNotNull( "/model/scm", actualObject ); Assert.assertEquals( "/model/scm", Scm.class, actualObject.getClass() ); Scm actual = (Scm) actualObject; Assert.assertEquals( "/model/scm/connection", expected.getConnection(), actual.getConnection() ); Assert.assertEquals( "/model/scm/developerConnection", expected.getDeveloperConnection(), actual.getDeveloperConnection() ); Assert.assertEquals( "/model/scm/url", expected.getUrl(), actual.getUrl() ); } } public void assertBuild( Build expected, Object actualObject ) { if ( expected == null ) { Assert.assertNull( "/model/builder", actualObject ); } else { Assert.assertNotNull( "/model/builder", actualObject ); Assert.assertEquals( "/model/builder", Build.class, actualObject.getClass() ); Build actual = (Build) actualObject; Assert.assertEquals( "/model/builder/sourceDirectory", expected.getSourceDirectory(), actual.getSourceDirectory() ); Assert.assertEquals( "/model/builder/unitTestSourceDirectory", expected.getUnitTestSourceDirectory(), actual.getUnitTestSourceDirectory() ); } } } modello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/expected-encoding.xml0000644000175000017500000000232710647207577031761 0ustar mkochmkoch Maven#&x00A9; component1 component2 sub foo Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java modello-1.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/expected.xml0000644000175000017500000000325611117305347030162 0ustar mkochmkoch Maven component1 component2 sub component3 bar baz text component4 key theValue value foo Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java modello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/0000755000175000017500000000000011260056264023537 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/0000755000175000017500000000000011260056264024326 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/0000755000175000017500000000000011260056264026121 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056264027554 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056264031052 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/0000755000175000017500000000000011260056264032067 5ustar mkochmkoch././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Dom4jGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Dom0000644000175000017500000000742011132202454032524 0ustar mkochmkochpackage org.codehaus.modello.plugin.dom4j; /* * Copyright (c) 2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import java.util.List; import java.util.Properties; /** * Test the generators. * * @author Brett Porter */ public class Dom4jGeneratorTest extends AbstractModelloJavaGeneratorTest { public Dom4jGeneratorTest() { super( "dom4j" ); } public void testDom4jGenerator() throws Throwable { ModelloCore modello = (ModelloCore) container.lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getTestFile( "src/test/resources/maven.mdo" ) ); List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 27, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); ModelField extend = clazz.getField( "extend", new Version( "4.0.0" ) ); assertTrue( extend.hasMetadata( XmlFieldMetadata.ID ) ); XmlFieldMetadata xml = (XmlFieldMetadata) extend.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertTrue( xml.isAttribute() ); assertEquals( "extender", xml.getTagName() ); ModelField build = clazz.getField( "build", new Version( "4.0.0" ) ); assertTrue( build.hasMetadata( XmlFieldMetadata.ID ) ); xml = (XmlFieldMetadata) build.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertEquals( "builder", xml.getTagName() ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); modello.generate( model, "java", parameters ); modello.generate( model, "dom4j-writer", parameters ); modello.generate( model, "dom4j-reader", parameters ); addDependency( "org.codehaus.modello", "modello-core", getModelloVersion() ); addDependency( "dom4j", "dom4j", "1.6.1" ); compile( getOutputDirectory(), getOutputClasses() ); verify( "org.codehaus.modello.generator.xml.dom4j.Dom4jVerifier", "dom4j" ); } } ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/FeaturesDom4jGeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Fea0000644000175000017500000000524111176576243032521 0ustar mkochmkochpackage org.codehaus.modello.plugin.dom4j; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesDom4jGeneratorTest.java 1225 2009-05-01 13:44:03Z hboutemy $ */ public class FeaturesDom4jGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesDom4jGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "java", parameters ); modello.generate( model, "dom4j-writer", parameters ); modello.generate( model, "dom4j-reader", parameters ); addDependency( "dom4j", "dom4j", "1.6.1" ); addDependency( "xmlunit", "xmlunit", "1.2" ); compile( getOutputDirectory(), getOutputClasses() ); verify( "org.codehaus.modello.generator.xml.dom4j.Dom4jFeaturesVerifier", getName() ); } } modello-1.1/modello-plugins/modello-plugin-dom4j/src/test/resources/0000755000175000017500000000000011260056264024630 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/test/resources/maven.mdo0000644000175000017500000016410111127507731026444 0ustar mkochmkoch maven Maven Maven's model for Java project. package org.codehaus.modello.test.model Model 3.0.0+ extend 3.0.0+ The location of the parent project, if one exists. Values from the parent project will be the default for this project if they are left unspecified. The path may be absolute, or relative to the current project.xml file. String parent 4.0.0 Specified which project to extend. Parent modelVersion 4.0.0 true The version of this model you are using. String pomVersion 3.0.0 true String id 3.0.0 true The id of the project. String groupId 3.0.0+ true The primary grouping for your project. String artifactId 3.0.0+ true The identifier used when generating the artifact for your project. String type 4.0.0 The type of artifact this project produces. String jar name 3.0.0+ true Human readable name of the project. String currentVersion 3.0.0 true String version 4.0.0 true The current version of the project. String shortDescription 3.0.0+ An abbreviated description of the project. String description 3.0.0+ A detailed description of the project. This element is usually specified as CDATA to enable the use of HTML tags within the description. This description is used to generate the <a href="plugins/site/index.html">front page</a> of the project's web site. String url website 3.0.0+ The URL where the project can be found. String logo 3.0.0+ The logo for the project. String issueTrackingUrl 3.0.0 The URL where the issue tracking system used by the project can be found. String issueManagement 4.0.0 The project's issue management information. IssueManagement ciManagement 4.0.0 The project's continuous integration management information. CiManagement inceptionYear 3.0.0+ true The year the project started. String gumpRepositoryId 3.0.0 Hint for the gump continuous integration build system. String siteAddress 3.0.0 The FQDN of the host where the project's site is uploaded. String siteDirectory 3.0.0 The directory on the site host where site documentation is placed when the site is uploaded. String distributionSite 3.0.0 The FQDN of the host where the project's artifacts are uploaded. String This naming is inconsistent and distribution should occur from a repository structure. distributionDirectory 3.0.0 The directory on the distribution host where artifacts are placed when uploaded. String This naming is inconsistent and distribution should occur from a repository structure. components 4.0.0 Component * repositories 4.0.0 The lists of the remote repositories Repository * pluginRepositories 4.0.0 The lists of the remote repositories for discovering plugins This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own. Repository * mailingLists 3.0.0+ The mailing lists for the project. MailingList * developers 3.0.0+ This element describes all of the developers associated with a project. Each developer is described by a <code>developer</code> element, which is then described by additional elements (described below). The auto-generated site documentation references this information. Developer * contributors 3.0.0+ This element describes all of the contributors associated with a project who are not developers. Each contributor is described by a <code>contributor</code> element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Contributor * dependencies 3.0.0+ This element describes all of the dependencies associated with a project. Each dependency is described by a <code>dependency</code> element, which is then described by additional elements (described below). Dependency * These should ultimately only be compile time dependencies when transitive dependencies come into play. overrides 4.0.0 This element describes all of the dependency overrides for a project. Each dependency is described by a <code>override</code> element, which is then described by additional elements (described below). Override * licenses 3.0.0+ This element describes all of the licenses for this project. Each license is described by a <code>license</code> element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. License * versions 3.0.0 The released versions of the project. Version * branches 3.0.0 The SCM branches create for the project. Branch * packageGroups 3.0.0+ Package groups required for complete javadocs. PackageGroup * reports 3.0.0+ This element includes the specification of reports to be included in a Maven-generated site. These reports will be run when a user executes <code>maven site</code>. All of the reports will be included in the navigation bar for browsing in the order they are specified. String * scm 4.0.0 Specification for the SCM use by the project. Scm repository 3.0.0 Specification for the SCM use by the project. Repository This element needs to be renamed as it conflicts with the existing notion of repositories in Maven. build 3.0.0+ true Information required to build the project. Build organization organisation 3.0.0+ This element describes various attributes of the organziation to which the project belongs. These attributes are utilized when documentation is created (for copyright notices and links). Organization distributionManagement 4.0.0 Distribution information for a project. DistributionManagement local 4.0.0 false Local configuration information. Local properties 3.0.0+ Properties about the project. This allows you to configure your project and the plugins it uses. Properties String * preGoals 4.0.0 Set of decorator(s) injected before the target goal(s). PreGoal * postGoals 4.0.0 Set of decorator(s) injected after the target goal(s). PostGoal * 3.0.0 public void setVersion(String version) { this.currentVersion = version; } public String getVersion() { return currentVersion; } 3.0.0+ private String packageName; public void setPackage(String packageName) { this.packageName = packageName; } public String getPackage() { return packageName; } 4.0.0 public String getId() { StringBuffer id = new StringBuffer(); id.append( getGroupId() ); id.append( ":" ); id.append( getArtifactId() ); id.append( ":" ); id.append( getType() ); id.append( ":" ); id.append( getVersion() ); return id.toString(); } Branch 3.0.0+ This element describes each of the branches of the project. Each branch is described by a <code>tag</code> element tag 3.0.0+ true The branch tag in the version control system (e.g. cvs) used by the project for the source code associated with this branch of the project. String description 4.0.0 A description of the branch and its strategy. String lastMergeTag 4.0.0 This is the tag in the version control system that was last used to merge from the branch to the current codebase. Future merges should merge only the changes from this tag to the next. String Build 3.0.0+ nagEmailAddress 3.0.0 An address to which notifications regarding the status of builds for this project can be sent. This is intended for use by tools which do unattended builds, for example those providing for continuous integration. Currently this is used by the <a href="build-file.html#maven:gump-descriptor">maven:gump-descriptor</a> target. String This should be moved out of the build section. Vestigal for use with Gump. sourceDirectory 3.0.0+ true This element specifies a directory containing the source of the project. The generated build system will compile the source in this directory when the project is built. The path given is relative to the project descriptor. String unitTestSourceDirectory 3.0.0+ true This element specifies a directory containing the unit test source of the project. The generated build system will compile these directories when the project is being tested. The unit tests must use the JUnit test framework. The path given is relative to the project descriptor. String aspectSourceDirectory 3.0.0+ This element specifies a directory containing Aspect sources of the project. The generated build system will compile the Aspects in this directory when the project is built if Aspects have been enabled (see the <a href="plugins/aspectj/goals.html">Aspectj goals</a> document). The path given is relative to the project descriptor. String integrationUnitTestSourceDirectory 3.0.0+ This element specifies a directory containing integration test sources of the project. String sourceModifications 3.0.0+ true This element describes all of the sourceModifications associated with a project. Each source modification is described by a <code>sourceModification</code> element, which is then described by additional elements (described below). These modifications are used to exclude or include various source depending on the environment the build is running in. SourceModification * unitTest 3.0.0+ true This element specifies unit tests associated with the project. UnitTest new UnitTest() resources 3.0.0+ This element describes all of the resources associated with a project or unit tests. Each resource is described by a resource element, which is then described by additional elements (described <a href="#resource">below</a>). These resources are used to complete the jar file or to run unit test. Resource * directory 4.0.0 The directory where all generated by the build is placed. String output 4.0.0 The directory where compiled application classes are placed. String finalName 4.0.0 The filename (including an extension, but with no path information) that the produced artifact will be called. The default value is artifactId-version.extension (where extension is derived from type). String testOutput 4.0.0 The directory where compiled test classes are placed. String CiManagement 4.0.0 system 4.0.0 The name of the continuous integration system i.e. Bugzilla String url 4.0.0 Url for the continuous integration system use by the project. String nagEmailAddress 4.0.0 Email address for the party to be notified on unsuccessful builds. String Contributor 3.0.0+ name 3.0.0+ The full name of the contributor. String email 3.0.0+ The email address of the contributor. String url 3.0.0+ The URL for the homepage of the contributor. String organization 3.0.0+ The organization to which the contributor belongs. String roles 3.0.0+ The roles the contributor plays in the project. Each role is describe by a <code>role</code> element, the body of which is a role name. String * timezone 3.0.0+ The timezone the contributor is in. This is a number in the range -14 to 14. String Dependency 3.0.0+ id 3.0.0 true The id of the project. String groupId 3.0.0+ true The project group that produced the dependency, e.g. <code>geronimo</code>. String artifactId 3.0.0+ true The unique id for an artifact produced by the project group, e.g. <code>germonimo-jms</code> String version 3.0.0+ true The version of the dependency., e.g. <code>3.2.1</code> String url 3.0.0+ This url will be provided to the user if the jar file cannot be downloaded from the central repository. String The URL should really be gleaned from a shared database of dependency information. jar 3.0.0 Literal name of the artifact. String artifact 4.0.0+ Literal name of the artifact String type 3.0.0+ Other known recognised dependency types are: <code>ejb</code> and <code>plugin</code>. String jar properties 3.0.0+ Properties about the dependency. Various plugins allow you to <code>mark</code> dependencies with properties. For example the <a href="plugins/war/index.html">war</a> plugin looks for a <code>war.bundle</code> property, and if found will include the dependency in <code>WEB-INF/lib</code>. For example syntax, check the war plugin docs. Properties String * 4.0.0 public String getId() { return groupId + ":" + artifactId + ":" + type + ":" + version; } public String toString() { return groupId + "/" + type + "s:" + artifactId + "-" + version; } 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } return getArtifactId() + "-" + getVersion() + "." + getExtension(); } public String getExtension() { if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( o == null ) { return false; } if ( getClass() != o.getClass() ) { return false; } if ( getId() != null ) { return getId().equals( ( (Dependency) o ).getId() ); } else { return ( (Dependency) o ).getId() == null; } } public int hashCode() { if ( getId() != null ) { return getId().hashCode(); } else { return super.hashCode(); } } ]]> Override 4.0.0 groupId 4.0.0 true The project group that produced the dependency, e.g. <code>geronimo</code>. String artifactId 4.0.0 true The unique id for an artifact produced by the project group, e.g. <code>germonimo-jms</code> String type 4.0.0 Other known recognised dependency types are: <code>ejb</code> and <code>plugin</code>. String jar version 4.0.0 true The version of the dependency., e.g. <code>3.2.1</code> String file 4.0.0 true The filename of the dependency that will be used to override the one from the repository, e.g. <code>lib/non-distributable-code-1.3.jar</code> String Contributor Developer 3.0.0+ id 3.0.0+ The username of the developer. String IssueManagement 4.0.0 system 4.0.0 The name of the issue management system i.e. Bugzilla String url 4.0.0 Url for the issue management system use by the project. String DistributionManagement 4.0.0 This elements describes all that pertains to distribution for a project. repository 4.0.0 Information needed for deploying to remote repository artifacts generated by the project Repository site Information needed for deploying website files of the project. 4.0.0 Site License 3.0.0+ name 3.0.0+ The full legal name of the license. String url 3.0.0+ The official url for the license text. String distribution 3.0.0 The primary method by which this project may be distributed. <dl> <dt>repo</dt> <dd>may be downloaded from the Maven repository</dd> <dt>manual</dt> <dd>user must manually download and install the dependency.</dd> </dl> String comments 3.0.0+ the description String MailingList 3.0.0+ This element describes all of the mailing lists associated with a project. Each mailing list is described by a <code>mailingList</code> element, which is then described by additional elements (described below). The auto-generated site documentation references this information. name 3.0.0+ The name of the mailing list. String subscribe 3.0.0+ The email address or link that can be used to subscribe to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String unsubscribe 3.0.0+ The email address or link that can be used to unsubscribe to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String post 4.0.0 The email address or link that can be used to post to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String archive 3.0.0+ The link to a URL where you can browse the archive. String This should probably be removed from 4.0.0 before alpha-1 archives 4.0.0 The link to a URL where you can browse the archive. String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization 3.0.0+ name 3.0.0+ The full name of the organization. String url 3.0.0+ The URL to the organization's home page. String logo 3.0.0+ The URL to the organization's logo image. This can be an URL relative to the base directory of the generated web site, (e.g., <code>/images/org-logo.png</code>) or an absolute URL (e.g., <code>http://my.corp/logo.png</code>). This value is used when generating the project documentation. String PackageGroup 3.0.0+ title 3.0.0+ the description String packages 3.0.0+ the description String PatternSet 3.0.0+ includes 3.0.0+ the description String * excludes 3.0.0+ the description String * 3.0.0+ public java.util.List getDefaultExcludes() { java.util.List defaultExcludes = new java.util.ArrayList(); defaultExcludes.add( "**/*~" ); defaultExcludes.add( "**/#*#" ); defaultExcludes.add( "**/.#*" ); defaultExcludes.add( "**/%*%" ); defaultExcludes.add( "**/._*" ); // CVS defaultExcludes.add( "**/CVS" ); defaultExcludes.add( "**/CVS/**" ); defaultExcludes.add( "**/.cvsignore" ); // SCCS defaultExcludes.add( "**/SCCS" ); defaultExcludes.add( "**/SCCS/**" ); // Visual SourceSafe defaultExcludes.add( "**/vssver.scc" ); // Subversion defaultExcludes.add( "**/.svn" ); defaultExcludes.add( "**/.svn/**" ); // Mac defaultExcludes.add( "**/.DS_Store" ); return defaultExcludes; } Parent 4.0.0 artifactId 4.0.0 The artifact id of the project to extend. String groupId 4.0.0 The group id of the project to extend. String version 4.0.0 The versi>on of the project to extend. String Repository 3.0.0 connection 3.0.0 The source configuration management system URL that describes the repository and how to connect to the repository. This is used by Maven when <a href="plugins/dist/index.html">building versions</a> from specific ID. String developerConnection 3.0.0 Just like connection, but for developers, i.e. this scm connection will not be read only. String url 3.0.0 The URL to the project's browsable CVS repository. String Scm 4.0.0 connection 4.0.0 The source configuration management system URL that describes the repository and how to connect to the repository. This is used by Maven when <a href="plugins/dist/index.html">building versions</a> from specific ID. String developerConnection 4.0.0 Just like connection, but for developers, i.e. this scm connection will not be read only. String url 4.0.0 The URL to the project's browsable CVS repository. String branches 4.0.0 The SCM branches that are currently active for the project. These should only be those forked from the current branch or trunk that are intended to be used. String * Resource 3.0.0+ PatternSet directory 3.0.0+ Describe the directory where the resource is stored. The path may be absolute, or relative to the project.xml file. String targetPath 3.0.0+ Describe the resource target path. For example, if you want that resource appear into a specific package ( <code>org.apache.maven.messages</code>), you must specify this element with this value : <code>org/apache/maven/messages</code> String filtering 3.0.0+ Describe if resources are filtered or not. String false 3.0.0+ public boolean isFiltering() { return !"false".equals( filtering ); } public void setFiltering( boolean filtering ) { this.filtering = ( filtering ? "true" : "false" ); } SourceModification 3.0.0+ Resource className 3.0.0+ If the class with this name can <strong>not</strong> be loaded, then the includes and excludes specified below will be applied to the contents of the <a href="#sourceDirectory">sourceDirectory</a> String property 3.0.0+ the description String UnitTest 3.0.0+ PatternSet resources 3.0.0+ the description Resource * Version 3.0.0 This element describes each of the previous versions of the project. Each version is described by a <code>version</code> element name 3.0.0 The external version number under which this release was distributed. Examples include: <code>1.0</code>, <code>1.1-alpha1</code>, <code>1.2-beta</code>, <code>1.3.2</code> etc. String tag 3.0.0 The name given in the version control system (e.g. cvs) used by the project for the source code associated with this version of the project. String id 3.0.0 A unique identifier for a version. This ID is used to specify the version that <a href="plugins/dist/index.html"> <code>maven:dist</code> </a> builds. String Repository 4.0.0 Repository contains the information needed for establishing connections with remote repoistory id 4.0.0 A unique identifier for a repository. String name 4.0.0 Human readable name of the repository String url 4.0.0 The url of of the repository String 4.0.0 public boolean equals( Object obj ) { Repository other = ( Repository ) obj; boolean retValue = false; if ( id != null ) { retValue = id.equals( other.id ); } return retValue; } Site 4.0.0 Site contains the information needed for deploying websites. id 4.0.0 A unique identifier for a deployment locataion. String name 4.0.0 Human readable name of the deployment location String url 4.0.0 The url of of the location where website is deployed String GoalDecorator 4.0.0 name 4.0.0 The target goal which should be decorated. String attain 4.0.0 The goal which should be injected into the execution chain. String GoalDecorator PreGoal 4.0.0 GoalDecorator PostGoal 4.0.0 Local 4.0.0 Local contains the information that is specific to the user's local environment. This would only be expected in a user or site pom, not a project POM. repository 4.0.0 The local repository that contains downloaded artifacts. String online 4.0.0 Whether to run the build online. If not, no remote repositories are consulted for plugins or dependencies and this configuration may be used by other plugins requiring online access. boolean true Component 4.0.0 name 4.0.0 String comment 4.0.0 String components 4.0.0 Component * custom DOM 4.0.0 properties 4.0.0 Properties String * flatProperties 4.0.0 Properties String * modello-1.1/modello-plugins/modello-plugin-dom4j/src/site/0000755000175000017500000000000011260056265022604 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/site/site.xml0000644000175000017500000000022511112331565024264 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-dom4j/src/site/xdoc/0000755000175000017500000000000011260056265023541 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/site/xdoc/index.xml0000644000175000017500000000330711131476544025400 0ustar mkochmkoch Modello Dom4J Plugin Hervé Boutemy

    Modello Dom4J Plugin generates XML readers and writers based on Dom4J API.

    dom4j-reader generator creates my.model.package.io.dom4j.ModelNameDom4JReader class with following public methods:

    • public RootClass read( Reader reader, boolean strict )
          throws IOException, DocumentException
    • public RootClass read( Reader reader )
          throws IOException, DocumentException
    • public RootClass read( URL url, boolean strict )
          throws IOException, DocumentException
    • public RootClass read( URL url )
          throws IOException, DocumentException

    dom4j-writer generator creates my.model.package.io.dom4j.ModelNameDom4JWriter class with following public methods:

    • public void write( Writer writer, RootClass root )
          throws java.io.IOException
    modello-1.1/modello-plugins/modello-plugin-dom4j/src/main/0000755000175000017500000000000011260056265022564 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/0000755000175000017500000000000011260056264023504 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/0000755000175000017500000000000011260056264024273 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/0000755000175000017500000000000011260056264026066 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056264027521 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056264031017 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/0000755000175000017500000000000011260056265032035 5ustar mkochmkoch././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jWriterGenerator.javamodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom0000644000175000017500000004217511243356043032506 0ustar mkochmkochpackage org.codehaus.modello.plugin.dom4j; /* * Copyright (c) 2006, Codehaus. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; import org.codehaus.modello.plugin.model.ModelClassMetadata; import org.codehaus.modello.plugins.xml.AbstractXmlJavaGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlModelMetadata; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * Generate a writer that uses Dom4J. *

    * TODO: chunks are lifted from xpp3, including the tests. Can we abstract it in some way? * * @author Brett Porter */ public class Dom4jWriterGenerator extends AbstractXmlJavaGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateDom4jWriter(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating Dom4j Writer.", ex ); } } private void generateDom4jWriter() throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.dom4j"; String marshallerName = getFileName( "Dom4jWriter" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, marshallerName ); JClass jClass = new JClass( packageName + '.' + marshallerName ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); jClass.addImport( "java.io.Writer" ); jClass.addImport( "java.util.Arrays" ); jClass.addImport( "java.util.Iterator" ); jClass.addImport( "java.util.Locale" ); jClass.addImport( "java.text.DateFormat" ); jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); jClass.addImport( "org.dom4j.Document" ); jClass.addImport( "org.dom4j.DocumentException" ); jClass.addImport( "org.dom4j.DocumentFactory" ); jClass.addImport( "org.dom4j.Element" ); jClass.addImport( "org.dom4j.io.OutputFormat" ); jClass.addImport( "org.dom4j.io.XMLWriter" ); addModelImports( jClass, null ); String root = objectModel.getRoot( getGeneratedVersion() ); ModelClass rootClass = objectModel.getClass( root, getGeneratedVersion() ); String rootElement = resolveTagName( rootClass ); // Write the parse method which will do the unmarshalling. JMethod marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( "Writer" ), "writer" ) ); marshall.addParameter( new JParameter( new JClass( root ), rootElement ) ); marshall.addException( new JClass( "java.io.IOException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "Document document = new DocumentFactory().createDocument();" ); sc.add( "write" + root + "( " + rootElement + ", \"" + rootElement + "\", document );" ); // TODO: pretty printing optional sc.add( "OutputFormat format = OutputFormat.createPrettyPrint();" ); sc.add( "format.setLineSeparator( System.getProperty( \"line.separator\" ) );" ); sc.add( "XMLWriter serializer = new XMLWriter( writer, format );" ); sc.add( "serializer.write( document );" ); jClass.addMethod( marshall ); writeAllClasses( objectModel, jClass ); writeHelpers( jClass ); jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClasses( Model objectModel, JClass jClass ) throws ModelloException { for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) clazz.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } writeClass( clazz, jClass ); } } private void writeClass( ModelClass modelClass, JClass jClass ) throws ModelloException { String className = modelClass.getName(); String uncapClassName = uncapitalise( className ); JMethod marshall = new JMethod( "write" + className ); marshall.getModifiers().makePrivate(); marshall.addParameter( new JParameter( new JClass( className ), uncapClassName ) ); marshall.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); ModelClassMetadata classMetadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); if ( classMetadata.isRootElement() ) { marshall.addParameter( new JParameter( new JClass( "Document" ), "parentElement" ) ); } else { marshall.addParameter( new JParameter( new JClass( "Element" ), "parentElement" ) ); } marshall.addException( new JClass( "java.io.IOException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "if ( " + uncapClassName + " != null )" ); sc.add( "{" ); sc.indent(); XmlModelMetadata xmlModelMetadata = (XmlModelMetadata) modelClass.getModel().getMetadata( XmlModelMetadata.ID ); // add namespace information for root element only if ( classMetadata.isRootElement() && ( xmlModelMetadata.getNamespace() != null ) ) { String namespace = xmlModelMetadata.getNamespace( getGeneratedVersion() ); sc.add( "Element element = parentElement.addElement( tagName, \"" + namespace + "\" );" ); if ( xmlModelMetadata.getSchemaLocation() != null ) { String url = xmlModelMetadata.getSchemaLocation( getGeneratedVersion() ); sc.add( "element.addAttribute( \"xmlns:xsi\", \"http://www.w3.org/2001/XMLSchema-instance\" );" ); sc.add( "element.addAttribute( \"xsi:schemaLocation\", \"" + namespace + " " + url + "\" );" ); } } else { sc.add( "Element element = parentElement.addElement( tagName );" ); } ModelField contentField = null; String contentValue = null; List modelFields = modelClass.getAllFields( getGeneratedVersion(), true ); modelFields = getNonTransientFields( modelFields ); // XML attributes for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) field.getMetadata( JavaFieldMetadata.ID ); String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String type = field.getType(); String value = uncapClassName + "." + getPrefix( javaFieldMetadata ) + capitalise( field.getName() ) + "()"; if ( xmlFieldMetadata.isContent() ) { contentField = field; contentValue = value; continue; } if ( xmlFieldMetadata.isAttribute() ) { sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.addIndented( "element.addAttribute( \"" + fieldTagName + "\", " + getValue( field.getType(), value, xmlFieldMetadata ) + " );" ); sc.add( "}" ); } } if ( contentField != null ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) contentField.getMetadata( XmlFieldMetadata.ID ); sc.add( "element.setText( " + getValue( contentField.getType(), contentValue, xmlFieldMetadata ) + " );" ); } // XML tags for ( Iterator fieldIterator = modelFields.iterator(); fieldIterator.hasNext(); ) { ModelField field = (ModelField) fieldIterator.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isContent() ) { // skip field with type Content continue; } if ( !xmlFieldMetadata.isAttribute() ) { processField( field, xmlFieldMetadata, uncapClassName, sc, modelClass, jClass ); } } sc.unindent(); sc.add( "}" ); jClass.addMethod( marshall ); } private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, String uncapClassName, JSourceCode sc, ModelClass modelClass, JClass jClass ) throws ModelloException { JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) field.getMetadata( JavaFieldMetadata.ID ); String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String type = field.getType(); String value = uncapClassName + "." + getPrefix( javaFieldMetadata ) + capitalise( field.getName() ) + "()"; if ( field instanceof ModelAssociation ) { ModelAssociation association = (ModelAssociation) field; String associationName = association.getName(); if ( association.isOneMultiplicity() ) { sc.add( getValueChecker( type, value, association ) ); sc.add( "{" ); sc.addIndented( "write" + association.getTo() + "( " + value + ", \"" + fieldTagName + "\", element );" ); sc.add( "}" ); } else { //MANY_MULTIPLICITY XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); type = association.getType(); String toType = association.getTo(); boolean wrappedItems = xmlAssociationMetadata.isWrappedItems(); if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { sc.add( getValueChecker( type, value, association ) ); sc.add( "{" ); sc.indent(); sc.add( "Element listElement = element;" ); if ( wrappedItems ) { sc.add( "listElement = element.addElement( \"" + fieldTagName + "\" );" ); } sc.add( "for ( Iterator iter = " + value + ".iterator(); iter.hasNext(); )" ); sc.add( "{" ); sc.indent(); if ( isClassInModel( association.getTo(), modelClass.getModel() ) ) { sc.add( toType + " o = (" + toType + ") iter.next();" ); sc.add( "write" + toType + "( o, \"" + valuesTagName + "\", listElement );" ); } else { sc.add( toType + " " + singular( uncapitalise( field.getName() ) ) + " = (" + toType + ") iter.next();" ); sc.add( "listElement.addElement( \"" + valuesTagName + "\" ).setText( " + singular( uncapitalise( field.getName() ) ) + " );" ); } sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } else { //Map or Properties sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.indent(); sc.add( "Element listElement = element;" ); if ( wrappedItems ) { sc.add( "listElement = element.addElement( \"" + fieldTagName + "\" );" ); } sc.add( "for ( Iterator iter = " + value + ".keySet().iterator(); iter.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = (String) iter.next();" ); sc.add( "String value = (String) " + value + ".get( key );" ); if ( xmlAssociationMetadata.isMapExplode() ) { sc.add( "Element assocElement = listElement.addElement( \"" + singular( associationName ) + "\" );" ); sc.add( "assocElement.addElement( \"key\" ).setText( key );" ); sc.add( "assocElement.addElement( \"value\" ).setText( value );" ); } else { sc.add( "listElement.addElement( key ).setText( value );" ); } sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } } } else { sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.indent(); if ( "DOM".equals( field.getType() ) ) { sc.add( "writeXpp3DomToElement( (Xpp3Dom) " + value + ", element );" ); } else { sc.add( "element.addElement( \"" + fieldTagName + "\" ).setText( " + getValue( field.getType(), value, xmlFieldMetadata ) + " );" ); } sc.unindent(); sc.add( "}" ); } } private void writeHelpers( JClass jClass ) { JMethod method = new JMethod( "writeXpp3DomToElement" ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "Xpp3Dom" ), "xpp3Dom" ) ); method.addParameter( new JParameter( new JClass( "Element" ), "parentElement" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "Element element = parentElement.addElement( xpp3Dom.getName() );" ); sc.add( "if ( xpp3Dom.getValue() != null )" ); sc.add( "{" ); sc.addIndented( "element.setText( xpp3Dom.getValue() );" ); sc.add( "}" ); sc.add( "for ( Iterator i = Arrays.asList( xpp3Dom.getAttributeNames() ).iterator(); i.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "String name = (String) i.next();" ); sc.add( "element.addAttribute( name, xpp3Dom.getAttribute( name ) );" ); sc.unindent(); sc.add( "}" ); sc.add( "for ( Iterator i = Arrays.asList( xpp3Dom.getChildren() ).iterator(); i.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Xpp3Dom child = (Xpp3Dom) i.next();" ); sc.add( "writeXpp3DomToElement( child, element );" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( method ); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jReaderGenerator.javamodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom0000644000175000017500000011167611243356043032511 0ustar mkochmkochpackage org.codehaus.modello.plugin.dom4j; /* * Copyright (c) 2006, Codehaus. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JType; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugins.xml.AbstractXmlJavaGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.plexus.util.StringUtils; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * Generator that reads a model using dom4j. * TODO: chunks are lifted from xpp3, including the tests. Can we abstract it in some way? * * @author Brett Porter */ public class Dom4jReaderGenerator extends AbstractXmlJavaGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateDom4jReader(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating Dom4j Reader.", ex ); } } private void generateDom4jReader() throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.dom4j"; String unmarshallerName = getFileName( "Dom4jReader" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, unmarshallerName ); JClass jClass = new JClass( packageName + '.' + unmarshallerName ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); jClass.addImport( "java.io.IOException" ); jClass.addImport( "java.io.Reader" ); jClass.addImport( "java.net.URL" ); jClass.addImport( "java.util.Date" ); jClass.addImport( "java.util.Locale" ); jClass.addImport( "java.text.DateFormat" ); jClass.addImport( "java.text.ParsePosition" ); jClass.addImport( "java.util.Iterator" ); jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); jClass.addImport( "org.dom4j.Attribute" ); jClass.addImport( "org.dom4j.Document" ); jClass.addImport( "org.dom4j.DocumentException" ); jClass.addImport( "org.dom4j.Element" ); jClass.addImport( "org.dom4j.Node" ); jClass.addImport( "org.dom4j.io.SAXReader" ); addModelImports( jClass, null ); // ---------------------------------------------------------------------- // Write the parse method which will do the unmarshalling. // ---------------------------------------------------------------------- ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); JMethod unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); JSourceCode sc = unmarshall.getSourceCode(); sc.add( "SAXReader parser = new SAXReader();" ); sc.add( "Document document = parser.read( reader );" ); sc.add( "String encoding = document.getXMLEncoding();" ); sc.add( "return parse" + root.getName() + "( \"" + resolveTagName( root ) + "\", document.getRootElement(), strict, encoding );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( reader, true );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.addParameter( new JParameter( new JClass( "URL" ), "url" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); sc = unmarshall.getSourceCode(); sc.add( "SAXReader parser = new SAXReader();" ); sc.add( "Document document = parser.read( url );" ); sc.add( "String encoding = document.getXMLEncoding();" ); sc.add( "return parse" + root.getName() + "( \"" + resolveTagName( root ) + "\", document.getRootElement(), strict, encoding );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.addParameter( new JParameter( new JClass( "URL" ), "url" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( url, true );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the class parsers // ---------------------------------------------------------------------- writeAllClassesParser( objectModel, jClass ); // ---------------------------------------------------------------------- // Write helpers // ---------------------------------------------------------------------- writeHelpers( jClass ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClassesParser( Model objectModel, JClass jClass ) { ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) clazz.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } writeClassParser( clazz, jClass, root.getName().equals( clazz.getName() ) ); } } private void writeClassParser( ModelClass modelClass, JClass jClass, boolean rootElement ) { String className = modelClass.getName(); String capClassName = capitalise( className ); String uncapClassName = uncapitalise( className ); JMethod unmarshall = new JMethod( "parse" + capClassName, new JClass( className ), null ); unmarshall.getModifiers().makePrivate(); unmarshall.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); unmarshall.addParameter( new JParameter( new JClass( "Element" ), "element" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addParameter( new JParameter( new JClass( "String" ), "encoding" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); JSourceCode sc = unmarshall.getSourceCode(); sc.add( className + " " + uncapClassName + " = new " + className + "();" ); ModelField contentField = null; List modelFields = modelClass.getAllFields( getGeneratedVersion(), true ); modelFields = getNonTransientFields( modelFields ); // read all XML attributes first for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isAttribute() ) { String tagName = xmlFieldMetadata.getTagName(); if ( tagName == null ) { tagName = field.getName(); } sc.add( "if ( element.attributeValue( \"" + tagName + "\" ) != null )"); sc.add( "{" ); sc.indent(); writePrimitiveField( field, field.getType(), uncapClassName, "set" + capitalise( field.getName() ), sc, jClass, "element", "childElement" ); sc.unindent(); sc.add( "}" ); } // TODO check if we have already one with this type and throws Exception if ( xmlFieldMetadata.isContent() ) { contentField = field; } } if ( rootElement ) { // encoding parameter is only used in root class sc.add( uncapClassName + ".setModelEncoding( encoding );" ); sc.add( "if ( strict )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( !element.getName().equals( tagName ) )" ); sc.add( "{" ); sc.addIndented( "throw new DocumentException( \"Error parsing model: root element tag is '\" + element.getName() + \"' instead of '\" + tagName + \"'\" );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } if ( contentField != null ) { writePrimitiveField( contentField, contentField.getType(), uncapClassName, "set" + capitalise( contentField.getName() ), sc, jClass, null, "element" ); } else { sc.add( "java.util.Set parsed = new java.util.HashSet();" ); sc.add( "for ( Iterator i = element.nodeIterator(); i.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Node node = (Node) i.next();" ); sc.add( "if ( node.getNodeType() != Node.ELEMENT_NODE )" ); sc.add( "{" ); sc.indent(); // TODO: attach to model in some way sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "Element childElement = (Element) node;" ); boolean addElse = false; for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( !xmlFieldMetadata.isAttribute() ) { processField( field, xmlFieldMetadata, addElse, sc, uncapClassName, jClass ); addElse = true; } } if ( addElse ) { sc.add( "else" ); sc.add( "{" ); sc.indent(); } sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new DocumentException( \"Unrecognised tag: '\" + childElement.getName() + \"'\" );" ); sc.add( "}" ); if ( addElse ) { sc.unindent(); sc.add( "}" ); } sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } sc.add( "return " + uncapClassName + ";" ); jClass.addMethod( unmarshall ); } /** * Generate code to process a field represented as an XML element. * * @param field the field to process * @param xmlFieldMetadata its XML metadata * @param addElse add an else statement before generating a new if * @param sc the method source code to add to * @param objectName the object name in the source * @param jClass the generated class source file */ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, boolean addElse, JSourceCode sc, String objectName, JClass jClass ) { String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String capFieldName = capitalise( field.getName() ); String singularName = singular( field.getName() ); String alias; if ( StringUtils.isEmpty( field.getAlias() ) ) { alias = "null"; } else { alias = "\"" + field.getAlias() + "\""; } String tagComparison = ( addElse ? "else " : "" ) + "if ( checkFieldWithDuplicate( childElement, \"" + fieldTagName + "\", " + alias + ", parsed ) )"; if ( field instanceof ModelAssociation ) { ModelAssociation association = (ModelAssociation) field; String associationName = association.getName(); if ( association.isOneMultiplicity() ) { sc.add( tagComparison ); sc.add( "{" ); sc.addIndented( objectName + ".set" + capFieldName + "( parse" + association.getTo() + "( \"" + fieldTagName + "\", childElement, strict, encoding ) );" ); sc.add( "}" ); } else { //MANY_MULTIPLICITY XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); String type = association.getType(); if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { boolean wrappedItems = xmlAssociationMetadata.isWrappedItems(); if ( wrappedItems ) { sc.add( tagComparison ); sc.add( "{" ); sc.indent(); sc.add( type + " " + associationName + " = " + association.getDefaultValue() + ";" ); sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" ); sc.add( "for ( Iterator j = childElement.nodeIterator(); j.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Node n = (Node) j.next();" ); sc.add( "if ( n.getNodeType() != Node.ELEMENT_NODE )" ); sc.add( "{" ); sc.indent(); // TODO: track the whitespace in the model sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "Element listElement = (Element) n;" ); sc.add( "if ( listElement.getName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); } else { sc.add( ( addElse ? "else " : "" ) + "if ( childElement.getName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); sc.add( "Element listElement = childElement;" ); sc.add( type + " " + associationName + " = " + objectName + ".get" + capFieldName + "();" ); sc.add( "if ( " + associationName + " == null )" ); sc.add( "{" ); sc.indent(); sc.add( associationName + " = " + association.getDefaultValue() + ";" ); sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" ); sc.unindent(); sc.add( "}" ); } if ( isClassInModel( association.getTo(), field.getModelClass().getModel() ) ) { sc.add( associationName + ".add( parse" + association.getTo() + "( \"" + valuesTagName + "\", listElement, strict, encoding ) );" ); } else { writePrimitiveField( association, association.getTo(), associationName, "add", sc, jClass, "childElement", "listElement" ); } if ( wrappedItems ) { sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } else { sc.unindent(); sc.add( "}" ); } } else { //Map or Properties sc.add( tagComparison ); sc.add( "{" ); sc.indent(); if ( xmlAssociationMetadata.isMapExplode() ) { sc.add( "for ( Iterator j = childElement.nodeIterator(); j.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Node n = (Node) j.next();" ); sc.add( "if ( n.getNodeType() != Node.ELEMENT_NODE )" ); sc.add( "{" ); sc.indent(); // TODO: track the whitespace in the model sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "Element listElement = (Element) n;" ); sc.add( "if ( listElement.getName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = null;" ); sc.add( "String value = null;" ); sc.add( "//" + xmlAssociationMetadata.getMapStyle() + " mode." ); sc.add( "for ( Iterator k = listElement.nodeIterator(); k.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Node nd = (Node) k.next();" ); sc.add( "if ( nd.getNodeType() != Node.ELEMENT_NODE )" ); sc.add( "{" ); sc.indent(); // TODO: track the whitespace in the model sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "Element propertyElement = (Element) nd;" ); sc.add( "if ( propertyElement.getName().equals( \"key\" ) )" ); sc.add( "{" ); sc.addIndented( "key = propertyElement.getText();" ); sc.add( "}" ); sc.add( "else if ( propertyElement.getName().equals( \"value\" ) )" ); sc.add( "{" ); sc.addIndented( "value = propertyElement.getText()" + ( xmlFieldMetadata.isTrim() ? ".trim()" : "" ) + ";" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( objectName + ".add" + capitalise( singularName ) + "( key, value );" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } else { //INLINE Mode sc.add( "for ( Iterator j = childElement.nodeIterator(); j.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Node n = (Node) j.next();" ); sc.add( "if ( n.getNodeType() != Node.ELEMENT_NODE )" ); sc.add( "{" ); sc.indent(); // TODO: track the whitespace in the model sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "Element listElement = (Element) n;" ); sc.add( "String key = listElement.getName();" ); sc.add( "String value = listElement.getText()" + ( xmlFieldMetadata.isTrim() ? ".trim()" : "" ) + ";" ); sc.add( objectName + ".add" + capitalise( singularName ) + "( key, value );" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } sc.unindent(); sc.add( "}" ); } } } else { sc.add( tagComparison ); sc.add( "{" ); sc.indent(); //ModelField writePrimitiveField( field, field.getType(), objectName, "set" + capitalise( field.getName() ), sc, jClass, "element", "childElement" ); sc.unindent(); sc.add( "}" ); } } private void writePrimitiveField( ModelField field, String type, String objectName, String setterName, JSourceCode sc, JClass jClass, String parentElementName, String childElementName ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); String tagName = resolveTagName( field, xmlFieldMetadata); String parserGetter; if ( xmlFieldMetadata.isAttribute() ) { parserGetter = parentElementName + ".attributeValue( \"" + tagName + "\" )"; } else { parserGetter = childElementName + ".getText()"; } // TODO: this and a default // if ( fieldMetaData.isRequired() ) // { // parserGetter = "getRequiredAttributeValue( " + parserGetter + ", \"" + tagName + "\", parser, strict, encoding )"; // } // if ( xmlFieldMetadata.isTrim() ) { parserGetter = "getTrimmedValue( " + parserGetter + " )"; } if ( "boolean".equals( type ) ) { sc.add( objectName + "." + setterName + "( getBooleanValue( " + parserGetter + ", \"" + tagName + "\" ) );" ); } else if ( "char".equals( type ) ) { sc.add( objectName + "." + setterName + "( getCharacterValue( " + parserGetter + ", \"" + tagName + "\" ) );" ); } else if ( "double".equals( type ) ) { sc.add( objectName + "." + setterName + "( getDoubleValue( " + parserGetter + ", \"" + tagName + "\", strict ) );" ); } else if ( "float".equals( type ) ) { sc.add( objectName + "." + setterName + "( getFloatValue( " + parserGetter + ", \"" + tagName + "\", strict ) );" ); } else if ( "int".equals( type ) ) { sc.add( objectName + "." + setterName + "( getIntegerValue( " + parserGetter + ", \"" + tagName + "\", strict ) );" ); } else if ( "long".equals( type ) ) { sc.add( objectName + "." + setterName + "( getLongValue( " + parserGetter + ", \"" + tagName + "\", strict ) );" ); } else if ( "short".equals( type ) ) { sc.add( objectName + "." + setterName + "( getShortValue( " + parserGetter + ", \"" + tagName + "\", strict ) );" ); } else if ( "byte".equals( type ) ) { sc.add( objectName + "." + setterName + "( getByteValue( " + parserGetter + ", \"" + tagName + "\", strict ) );" ); } else if ( "String".equals( type ) || "Boolean".equals( type ) ) { // TODO: other Primitive types sc.add( objectName + "." + setterName + "( " + parserGetter + " );" ); } else if ( "Date".equals( type ) ) { sc.add( "String dateFormat = " + ( xmlFieldMetadata.getFormat() != null ? "\"" + xmlFieldMetadata.getFormat() + "\"" : "null" ) + ";" ); sc.add( objectName + "." + setterName + "( getDateValue( " + parserGetter + ", \"" + tagName + "\", dateFormat ) );" ); } else if ( "DOM".equals( type ) ) { sc.add( objectName + "." + setterName + "( writeElementToXpp3Dom( " + childElementName + " ) );" ); } else { throw new IllegalArgumentException( "Unknown type: " + type ); } } private void writeHelpers( JClass jClass ) { JMethod method = new JMethod( "getTrimmedValue", new JClass( "String" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "s = s.trim();" ); sc.add( "}" ); sc.add( "return s;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- /* TODO method = new JMethod( new JClass( "String" ), "getRequiredAttributeValue" ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addParameter( new JParameter( JClass.Boolean, "strict" ) ); sc = method.getSourceCode(); sc.add( "if ( s == null )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Missing required value for attribute '\" + attribute + \"'\", parser, null );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return s;" ); jClass.addMethod( method ); */ // -------------------------------------------------------------------- method = new JMethod( "getBooleanValue", JType.BOOLEAN, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "return Boolean.valueOf( s ).booleanValue();" ); sc.add( "}" ); sc.add( "return false;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getCharacterValue", JType.CHAR, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "return s.charAt( 0 );" ); sc.add( "}" ); sc.add( "return 0;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getIntegerValue", JType.INT, "Integer.valueOf( s ).intValue()", "an integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getShortValue", JType.SHORT, "Short.valueOf( s ).shortValue()", "a short integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getByteValue", JType.BYTE, "Byte.valueOf( s ).byteValue()", "a byte" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getLongValue", JType.LONG, "Long.valueOf( s ).longValue()", "a long integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getFloatValue", JType.FLOAT, "Float.valueOf( s ).floatValue()", "a floating point number" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getDoubleValue", JType.DOUBLE, "Double.valueOf( s ).doubleValue()", "a floating point number" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getDateValue", new JClass( "java.util.Date" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "String" ), "dateFormat" ) ); method.addException( new JClass( "DocumentException" ) ); writeDateParsingHelper( method.getSourceCode(), "new DocumentException( e.getMessage() )" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "writeElementToXpp3Dom", new JClass( "Xpp3Dom" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "Element" ), "element" ) ); sc = method.getSourceCode(); sc.add( "Xpp3Dom xpp3Dom = new Xpp3Dom( element.getName() );" ); sc.add( "if ( element.elements().isEmpty() && element.getText() != null )" ); sc.add( "{" ); sc.addIndented( "xpp3Dom.setValue( element.getText() );" ); sc.add( "}" ); sc.add( "for ( Iterator i = element.attributeIterator(); i.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Attribute attribute = (Attribute) i.next();" ); sc.add( "xpp3Dom.setAttribute( attribute.getName(), attribute.getValue() );" ); sc.unindent(); sc.add( "}" ); // TODO: would be nice to track whitespace in here sc.add( "for ( Iterator i = element.elementIterator(); i.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "Element child = (Element) i.next();" ); sc.add( "xpp3Dom.addChild( writeElementToXpp3Dom( child ) );" ); sc.unindent(); sc.add( "}" ); sc.add( "return xpp3Dom;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "checkFieldWithDuplicate", JType.BOOLEAN, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "Element" ), "element" ) ); method.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); method.addParameter( new JParameter( new JClass( "String" ), "alias" ) ); method.addParameter( new JParameter( new JClass( "java.util.Set" ), "parsed" ) ); method.addException( new JClass( "DocumentException" ) ); sc = method.getSourceCode(); sc.add( "if ( !( element.getName().equals( tagName ) || element.getName().equals( alias ) ) )" ); sc.add( "{" ); sc.addIndented( "return false;" ); sc.add( "}" ); sc.add( "if ( parsed.contains( tagName ) )" ); sc.add( "{" ); sc.addIndented( "throw new DocumentException( \"Duplicated tag: '\" + tagName + \"'\" );" ); sc.add( "}" ); sc.add( "parsed.add( tagName );" ); sc.add( "return true;" ); jClass.addMethod( method ); } private JMethod convertNumericalType( String methodName, JType returnType, String expression, String typeDesc ) { JMethod method = new JMethod( methodName, returnType, null ); method.addException( new JClass( "DocumentException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.indent(); sc.add( "try" ); sc.add( "{" ); sc.addIndented( "return " + expression + ";" ); sc.add( "}" ); sc.add( "catch ( NumberFormatException e )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new DocumentException( \"Unable to parse element '\" + attribute + \"', must be " + typeDesc + "\" );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return 0;" ); return method; } } modello-1.1/modello-plugins/modello-plugin-dom4j/src/main/resources/0000755000175000017500000000000011260056265024576 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/resources/META-INF/0000755000175000017500000000000011260056265025736 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056265027256 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-dom4j/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000102210647207577032174 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator dom4j-reader org.codehaus.modello.plugin.dom4j.Dom4jReaderGenerator org.codehaus.modello.plugin.ModelloGenerator dom4j-writer org.codehaus.modello.plugin.dom4j.Dom4jWriterGenerator modello-1.1/modello-plugins/modello-plugin-xpp3/0000755000175000017500000000000011260056264020725 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/pom.xml0000644000175000017500000000241211243557055022246 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-xpp3 Modello XPP3 Plugin Modello XPP3 Plugin generates XML readers and writers based on XPP3 API (XML Pull Parser). org.codehaus.modello modello-plugin-java org.codehaus.plexus plexus-utils org.codehaus.modello modello-plugin-xml xmlunit xmlunit 1.2 test modello-1.1/modello-plugins/modello-plugin-xpp3/src/0000755000175000017500000000000011260056264021514 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/0000755000175000017500000000000011260056264022473 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/0000755000175000017500000000000011260056264024471 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/0000755000175000017500000000000011260056264025363 5ustar mkochmkoch././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-missing-root-element.xmlmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-missing-root-elem0000644000175000017500000000042511134200035032713 0ustar mkochmkoch Mailing list Super Subscribe Duper Unsubscribe ?ber Archive ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-wrong-element.xmlmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-wrong-element.xml0000644000175000017500000000337111127507731032745 0ustar mkochmkoch Maven component1 component2 sub component3 bar baz te&xt component4 key theValue value foo bar Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection baz developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-wrong-root-element.xmlmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-wrong-root-elemen0000644000175000017500000000333111127507731032737 0ustar mkochmkoch Maven component1 component2 sub component3 bar baz te&xt component4 key theValue value foo bar Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/Xpp3Verifier.java0000644000175000017500000005773711221502704030567 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.xpp3; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.model.Build; import org.codehaus.modello.test.model.Component; import org.codehaus.modello.test.model.ContentTest; import org.codehaus.modello.test.model.Local; import org.codehaus.modello.test.model.MailingList; import org.codehaus.modello.test.model.Model; import org.codehaus.modello.test.model.Organization; import org.codehaus.modello.test.model.Repository; import org.codehaus.modello.test.model.Scm; import org.codehaus.modello.test.model.SourceModification; import org.codehaus.modello.test.model.io.xpp3.MavenXpp3Reader; import org.codehaus.modello.test.model.io.xpp3.MavenXpp3Writer; import org.codehaus.modello.verifier.Verifier; import org.codehaus.modello.verifier.VerifierException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.io.Reader; import java.text.DateFormat; import java.util.Calendar; import java.util.List; import java.util.Locale; import java.util.Properties; import java.util.TimeZone; /** * @author Trygve Laugstøl * @version $Id: Xpp3Verifier.java 1259 2009-06-27 20:49:08Z hboutemy $ */ public class Xpp3Verifier extends Verifier { /** * TODO: Add a association thats not under the root element */ public void verify() throws Exception { TimeZone.setDefault(TimeZone.getTimeZone("America/New_York")); verifyWriter(); verifyReader(); verifyReaderAliases(); verifyReaderDefaultValue(); verifyReaderDuplicates(); verifyReaderMissingTags_DefaultMode(); verifyReaderMissingTags_StrictMode(); verifyReaderMissingTags_NonStrictMode(); verifyThrowingExceptionWithWrongRootElement(); verifyThrowingExceptionWithMissingRootElement(); verifyThrowingExceptionWithWrongElement(); verifyThrowingExceptionWithWrongElement2(); } public void verifyEncodedRead() throws IOException, XmlPullParserException { File file = new File( "src/test/verifiers/xpp3/expected-encoding.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); MavenXpp3Reader modelReader = new MavenXpp3Reader(); Model model = modelReader.read( reader ); Assert.assertEquals( "Maven\u00A9", model.getName() ); } public void verifyThrowingExceptionWithWrongRootElement() throws Exception { File file = new File( "src/test/verifiers/xpp3/model-with-wrong-root-element.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); MavenXpp3Reader modelReader = new MavenXpp3Reader(); try { modelReader.read( reader ); throw new VerifierException( "reading model-with-wrong-root-element.xml with strict=true should fail." ); } catch( XmlPullParserException e ) { Assert.assertTrue( e.getMessage().startsWith( "Expected root element 'mavenModel' but found" ) ); } reader = ReaderFactory.newXmlReader( file ); // no failure if it is wrong but strict is off modelReader.read( reader, false ); } public void verifyThrowingExceptionWithMissingRootElement() throws Exception { File file = new File( "src/test/verifiers/xpp3/model-with-missing-root-element.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); MavenXpp3Reader modelReader = new MavenXpp3Reader(); try { modelReader.read( reader ); throw new VerifierException( "reading model-with-missing-root-element.xml with strict=true should fail." ); } catch( XmlPullParserException e ) { Assert.assertTrue( e.getMessage().startsWith( "Expected root element 'mavenModel' but found" ) ); } reader = ReaderFactory.newXmlReader( file ); // no failure if it is wrong but strict is off modelReader.read( reader, false ); } public void verifyThrowingExceptionWithWrongElement() throws Exception { File file = new File( "src/test/verifiers/xpp3/model-with-wrong-element.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); MavenXpp3Reader modelReader = new MavenXpp3Reader(); try { modelReader.read( reader ); throw new VerifierException( "reading model-with-wrong-element.xml with strict=true should fail." ); } catch( XmlPullParserException e ) { Assert.assertTrue( e.getMessage().startsWith( "Unrecognised tag: 'bar'" ) ); } reader = ReaderFactory.newXmlReader( file ); // no failure if it is wrong but strict is off Model model = modelReader.read( reader, false ); // check nothing important was missed Assert.assertEquals( "connection", model.getScm().getConnection() ); Assert.assertEquals( "developerConnection", model.getScm().getDeveloperConnection() ); Assert.assertEquals( "url", model.getScm().getUrl() ); } public void verifyThrowingExceptionWithWrongElement2() throws Exception { File file = new File( "src/test/verifiers/xpp3/model-with-wrong-element2.xml" ); Reader reader = ReaderFactory.newXmlReader( file ); MavenXpp3Reader modelReader = new MavenXpp3Reader(); try { modelReader.read( reader ); throw new VerifierException( "reading model-with-wrong-element2.xml with strict=true should fail." ); } catch( XmlPullParserException e ) { Assert.assertTrue( e.getMessage().startsWith( "Unrecognised tag: 'bar'" ) ); } reader = ReaderFactory.newXmlReader( file ); // no failure if it is wrong but strict is off Model model = modelReader.read( reader, false ); // check nothing important was missed Assert.assertEquals( "connection", model.getScm().getConnection() ); Assert.assertEquals( "developerConnection", model.getScm().getDeveloperConnection() ); Assert.assertEquals( "url", model.getScm().getUrl() ); } public void verifyWriter() throws Exception { String expectedXml = FileUtils.fileRead( getTestFile( "src/test/verifiers/xpp3/expected.xml" ) ); // ---------------------------------------------------------------------- // Build the model thats going to be written. // ---------------------------------------------------------------------- Model expected = new Model(); expected.setExtend( "/foo/bar" ); expected.setName( "Maven" ); expected.setModelVersion( "4.0.0" ); MailingList mailingList = new MailingList(); mailingList.setName( "Mailing list" ); mailingList.setSubscribe( "Super Subscribe" ); mailingList.setUnsubscribe( "Duper Unsubscribe" ); mailingList.setArchive( "?ber Archive" ); expected.addMailingList( mailingList ); Scm scm = new Scm(); String connection = "connection"; String developerConnection = "developerConnection"; String url = "url"; scm.setConnection( connection ); scm.setDeveloperConnection( developerConnection ); scm.setUrl( url ); expected.setScm( scm ); Build build = new Build(); build.setSourceDirectory( "src/main/java" ); build.setUnitTestSourceDirectory( "src/test/java" ); SourceModification sourceModification = new SourceModification(); sourceModification.setClassName( "excludeEclipsePlugin" ); sourceModification.setDirectory( "foo" ); sourceModification.addExclude( "de/abstrakt/tools/codegeneration/eclipse/*.java" ); build.addSourceModification( sourceModification ); expected.setBuild( build ); Component component = new Component(); component.setName( "component1" ); expected.addComponent( component ); component = new Component(); component.setName( "component2" ); component.setComment( "comment2" ); expected.addComponent( component ); Component c2 = new Component(); c2.setName( "sub" ); c2.setComment( "subcomment" ); component.getComponents().add( c2 ); component = new Component(); component.setName( "component3" ); Xpp3Dom xpp3Dom = new Xpp3Dom( "custom" ); Xpp3Dom child = new Xpp3Dom( "foo" ); child.setValue( "bar" ); xpp3Dom.addChild( child ); child = new Xpp3Dom( "bar" ); child.setAttribute( "att1", "value" ); child.setValue( "baz" ); xpp3Dom.addChild( child ); child = new Xpp3Dom( "el1" ); xpp3Dom.addChild( child ); Xpp3Dom el1 = child; child = new Xpp3Dom( "el2" ); child.setValue( "te&xt" ); el1.addChild( child ); component.setCustom( xpp3Dom ); expected.addComponent( component ); component = new Component(); component.setName( "component4" ); expected.addComponent( component ); Properties properties = new Properties(); properties.setProperty( "name", "value" ); component.setFlatProperties( properties ); properties = new Properties(); properties.setProperty( "key", "theValue" ); component.setProperties( properties ); Repository repository = new Repository(); repository.setId( "foo" ); expected.addRepository( repository ); repository = new Repository(); repository.setId( "bar" ); expected.addRepository( repository ); ContentTest content = new ContentTest(); content.setContent( "content value" ); content.setAttr( "attribute" ); expected.setContent( content ); // ---------------------------------------------------------------------- // Write out the model // ---------------------------------------------------------------------- MavenXpp3Writer writer = new MavenXpp3Writer(); StringWriter buffer = new StringWriter(); writer.write( buffer, expected ); String actualXml = buffer.toString(); // System.out.println( expectedXml ); // // System.err.println( actualXml ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreComments( true ); Diff diff = XMLUnit.compareXML( expectedXml.trim(), actualXml.trim() ); if ( !diff.identical() ) { System.err.println( actualXml ); throw new VerifierException( "writer result is not the same as original content: " + diff ); } MavenXpp3Reader reader = new MavenXpp3Reader(); Model actual = reader.read( new StringReader( actualXml ) ); Assert.assertNotNull( "Actual", actual ); assertModel( expected, actual ); buffer = new StringWriter(); writer.write( buffer, actual ); diff = XMLUnit.compareXML( expectedXml.trim(), buffer.toString().trim() ); if ( !diff.identical() ) { System.err.println( actualXml ); throw new VerifierException( "re-writer result is not the same as original content: " + diff ); } } public void verifyReader() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); // ---------------------------------------------------------------------- // Test the "add default entities" flag // ---------------------------------------------------------------------- Assert.assertTrue( reader.getAddDefaultEntities() ); reader.setAddDefaultEntities( false ); Assert.assertFalse( reader.getAddDefaultEntities() ); reader.setAddDefaultEntities( true ); Assert.assertTrue( reader.getAddDefaultEntities() ); // ---------------------------------------------------------------------- // Test that the entities is properly resolved // ---------------------------------------------------------------------- String xml = "\n" + " Laugstøl\n" + ""; Model expected = new Model(); String groupId = "Laugst\u00f8l"; expected.setGroupId( groupId ); Model actual = reader.read( new StringReader( xml ) ); assertModel( expected, actual ); } public void verifyReaderAliases() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); String xml = "\n" + " http://maven.apache.org/website\n" + " my-org\n" + ""; Model expected = new Model(); expected.setUrl( "http://maven.apache.org/website" ); Organization org = new Organization(); org.setName( "my-org" ); expected.setOrganization( org ); Model actual = reader.read( new StringReader( xml ) ); assertModel( expected, actual ); } public void verifyReaderDefaultValue() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); // The defaultValue for local/online is true String xml = "\n" + " \n" + ""; Model expected = new Model(); Local local = new Local(); local.setOnline( true ); expected.setLocal( local ); Model actual = reader.read( new StringReader( xml ) ); assertModel( expected, actual ); } public void verifyReaderDuplicates() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); String xml = "\n" + " \n" + ""; try { reader.read( new StringReader( xml ) ); Assert.fail( "Should have obtained a parse error for duplicate sourceDirectory" ); } catch ( XmlPullParserException expected ) { Assert.assertTrue( true ); } xml = "\n" + " \n" + " \n" + ""; try { reader.read( new StringReader( xml ) ); Assert.fail( "Should have obtained a parse error for duplicate build" ); } catch ( XmlPullParserException expected ) { Assert.assertTrue( true ); } } public void verifyReaderMissingTags_DefaultMode() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); // The following is missing the and tags String xml = "\n" + " org.apache.cocooncocoon-core2.2.0-SNAPSHOT\n" + ""; try { reader.read( new StringReader( xml ) ); Assert.fail( "Should have obtained a parse error for missing dependency" ); } catch ( XmlPullParserException expected ) { Assert.assertTrue( true ); } } public void verifyReaderMissingTags_StrictMode() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); // The following is missing the and tags String xml = "\n" + " org.apache.cocooncocoon-core2.2.0-SNAPSHOT\n" + ""; try { reader.read( new StringReader( xml ), true ); Assert.fail( "Should have obtained a parse error for missing dependency" ); } catch ( XmlPullParserException expected ) { Assert.assertTrue( true ); } } public void verifyReaderMissingTags_NonStrictMode() throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); // The following is missing the and tags String xml = "\n" + " org.apache.cocooncocoon-core2.2.0-SNAPSHOT\n" + ""; reader.read( new StringReader( xml ), false ); } // ---------------------------------------------------------------------- // Assertions // ---------------------------------------------------------------------- public void assertModel( Model expected, Model actual ) { Assert.assertNotNull( "Actual model", actual ); Assert.assertEquals( "/model/extend", expected.getExtend(), actual.getExtend() ); // assertParent( expected.getParent(), actual.getParent() ); Assert.assertEquals( "/model/modelVersion", expected.getModelVersion(), actual.getModelVersion() ); Assert.assertEquals( "/model/groupId", expected.getGroupId(), actual.getGroupId() ); Assert.assertEquals( "/model/artifactId", expected.getArtifactId(), actual.getArtifactId() ); Assert.assertEquals( "/model/type", expected.getType(), actual.getType() ); Assert.assertEquals( "/model/name", expected.getName(), actual.getName() ); Assert.assertEquals( "/model/version", expected.getVersion(), actual.getVersion() ); Assert.assertEquals( "/model/shortDescription", expected.getShortDescription(), actual.getShortDescription() ); Assert.assertEquals( "/model/description", expected.getDescription(), actual.getDescription() ); Assert.assertEquals( "/model/url", expected.getUrl(), actual.getUrl() ); Assert.assertEquals( "/model/logo", expected.getLogo(), actual.getLogo() ); // assertIssueManagement(); // assertCiManagement(); Assert.assertEquals( "/model/inceptionYear", expected.getInceptionYear(), actual.getInceptionYear() ); // assertEquals( "/model/siteAddress", expected.getSiteAddress(), actual.getSiteAddress() ); // assertEquals( "/model/siteDirectory", expected.getSiteDirectory(), actual.getSiteDirectory() ); // assertEquals( "/model/distributionSite", expected.getDistributionSite(), actual.getDistributionSite() ); // assertEquals( "/model/distributionDirectory", expected.getDistributionDirectory(), actual.getDistributionDirectory() ); assertMailingLists( expected.getMailingLists(), actual.getMailingLists() ); /* assertDevelopers( ); assertContributors( ); assertDependencies( ); assertLicenses( ); assertPackageGroups( ); assertReports( ); */ assertScm( expected.getScm(), actual.getScm() ); /* assertBuild( ); assertOrganization( expected.getOrganization(), actual.getOrganization() ); */ assertBuild( expected.getBuild(), actual.getBuild() ); assertLocal( expected.getLocal(), actual.getLocal() ); } public void assertMailingLists( List expected, List actual ) { Assert.assertNotNull( "/model/mailingLists", actual ); Assert.assertEquals( "/model/mailingLists.size", expected.size(), actual.size() ); for ( int i = 0; i < expected.size(); i++ ) { assertMailingList( i, (MailingList) expected.get( i ), actual.get( i ) ); } } public void assertMailingList( int i, MailingList expected, Object actualObject ) { Assert.assertNotNull( "/model/mailingLists[" + i + "]", actualObject ); Assert.assertEquals( "/model/mailingLists", MailingList.class, actualObject.getClass() ); MailingList actual = (MailingList) actualObject; Assert.assertEquals( "/model/mailingLists[" + i + "]/name", expected.getName(), actual.getName() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/subscribe", expected.getSubscribe(), actual.getSubscribe() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/unsubscribe", expected.getUnsubscribe(), actual.getUnsubscribe() ); Assert.assertEquals( "/model/mailingLists[" + i + "]/archive", expected.getArchive(), actual.getArchive() ); } public void assertScm( Scm expected, Object actualObject ) { if ( expected == null ) { Assert.assertNull( "/model/scm", actualObject ); } else { Assert.assertNotNull( "/model/scm", actualObject ); Assert.assertEquals( "/model/scm", Scm.class, actualObject.getClass() ); Scm actual = (Scm) actualObject; Assert.assertEquals( "/model/scm/connection", expected.getConnection(), actual.getConnection() ); Assert.assertEquals( "/model/scm/developerConnection", expected.getDeveloperConnection(), actual.getDeveloperConnection() ); Assert.assertEquals( "/model/scm/url", expected.getUrl(), actual.getUrl() ); } } public void assertBuild( Build expected, Object actualObject ) { if ( expected == null ) { Assert.assertNull( "/model/builder", actualObject ); } else { Assert.assertNotNull( "/model/builder", actualObject ); Assert.assertEquals( "/model/builder", Build.class, actualObject.getClass() ); Build actual = (Build) actualObject; Assert.assertEquals( "/model/builder/sourceDirectory", expected.getSourceDirectory(), actual.getSourceDirectory() ); Assert.assertEquals( "/model/builder/unitTestSourceDirectory", expected.getUnitTestSourceDirectory(), actual.getUnitTestSourceDirectory() ); } } public void assertLocal( Local expected, Object actualObject ) { if ( expected == null ) { Assert.assertNull( "/model/local", actualObject ); } else { Assert.assertNotNull( "/model/local", actualObject ); Assert.assertEquals( "/model/local", Local.class, actualObject.getClass() ); Local actual = (Local) actualObject; Assert.assertEquals( "/model/local/online", expected.isOnline(), actual.isOnline() ); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-wrong-element2.xmlmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/model-with-wrong-element2.xm0000644000175000017500000000342111120003572032632 0ustar mkochmkoch Maven component1 component2 sub component3 bar baz te&xt component4 key theValue value foo bar Mailing list Super Subscribe Duper Unsubscribe ?ber Archive baz connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/expected-encoding.xml0000644000175000017500000000321511127507731031475 0ustar mkochmkoch Maven#&x00A9; component1 component2 sub component3 bar baz text component4 key theValue value foo Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/expected.xml0000644000175000017500000000342011221502704027675 0ustar mkochmkoch Maven component1 component2 sub component3 bar baz te&xt component4 key theValue value foo bar Mailing list Super Subscribe Duper Unsubscribe ?ber Archive connection developerConnection url src/main/java src/test/java excludeEclipsePlugin foo de/abstrakt/tools/codegeneration/eclipse/*.java content value modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/0000755000175000017500000000000011260056264026307 5ustar mkochmkoch././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/Xpp3FeaturesVerifier.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/Xpp3FeaturesVerifier.jav0000644000175000017500000001660011241516613033037 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.xpp3; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.Assert; import org.codehaus.modello.test.features.Features; import org.codehaus.modello.test.features.io.xpp3.ModelloFeaturesTestXpp3Reader; import org.codehaus.modello.test.features.io.xpp3.ModelloFeaturesTestXpp3Writer; import org.codehaus.modello.verifier.Verifier; import org.codehaus.modello.verifier.VerifierException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.io.StringWriter; /** * @author Herve Boutemy * @version $Id: Xpp3FeaturesVerifier.java 1307 2009-08-15 11:35:39Z hboutemy $ */ public class Xpp3FeaturesVerifier extends Verifier { public void verify() throws Exception { Features features = verifyReader(); features.getXmlFeatures().getXmlTransientFields().setTransientString( "NOT-TO-BE-WRITTEN" ); verifyWriter( features ); verifyBadVersion(); verifyWrongElement(); verifyTransientElement(); verifyEncoding(); } public Features verifyReader() throws Exception { ModelloFeaturesTestXpp3Reader reader = new ModelloFeaturesTestXpp3Reader(); return reader.read( getClass().getResourceAsStream( "/features.xml" ) ); } public void verifyWriter( Features features ) throws Exception { ModelloFeaturesTestXpp3Writer writer = new ModelloFeaturesTestXpp3Writer(); StringWriter buffer = new StringWriter(); writer.write( buffer, features ); String initialXml = IOUtil.toString( getXmlResourceReader( "/features.xml" ) ); String actualXml = buffer.toString(); // alias is rendered as default field name => must be reverted here to let the test pass actualXml = actualXml.replaceFirst( "alias", "alias" ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreComments( true ); Diff diff = XMLUnit.compareXML( initialXml, actualXml ); if ( !diff.identical() ) { System.err.println( actualXml ); throw new VerifierException( "writer result is not the same as original content: " + diff ); } } public void verifyBadVersion() throws Exception { ModelloFeaturesTestXpp3Reader reader = new ModelloFeaturesTestXpp3Reader(); try { reader.read( getClass().getResourceAsStream( "/features-bad-version.xml" ) ); //throw new VerifierException( "Reading a document with a version different from the version of the parser should fail." ); System.err.print( "[WARNING] missing feature: reading a document with a version different from the version of the parser should fail." ); } catch ( XmlPullParserException xppe ) { checkExpectedFailure( xppe, "Document model version of '2.0.0' doesn't match reader version of '1.0.0'" ); } } public void verifyWrongElement() throws Exception { ModelloFeaturesTestXpp3Reader reader = new ModelloFeaturesTestXpp3Reader(); // reading with strict=false should accept unknown element reader.read( getClass().getResourceAsStream( "/features-wrong-element.xml" ), false ); reader.read( getClass().getResourceAsStream( "/features-wrong-element2.xml" ), false ); // by default, strict=true: reading should not accept unknown element try { reader.read( getClass().getResourceAsStream( "/features-wrong-element.xml" ) ); throw new VerifierException( "Reading a document with an unknown element under strict option should fail." ); } catch ( XmlPullParserException xppe ) { checkExpectedFailure( xppe, "'invalidElement'" ); } try { reader.read( getClass().getResourceAsStream( "/features-wrong-element2.xml" ) ); throw new VerifierException( "Reading a document with an unknown element under strict option should fail." ); } catch ( XmlPullParserException xppe ) { checkExpectedFailure( xppe, "'invalidElement'" ); } } public void verifyTransientElement() throws Exception { ModelloFeaturesTestXpp3Reader reader = new ModelloFeaturesTestXpp3Reader(); try { reader.read( getClass().getResourceAsStream( "/features-invalid-transient.xml" ) ); fail( "Transient fields should not be processed by parser." ); } catch ( XmlPullParserException e ) { checkExpectedFailure( e, "transientString" ); } } private void checkExpectedFailure( XmlPullParserException xppe, String expectedMessage ) throws VerifierException { if ( xppe.getMessage().indexOf( expectedMessage ) < 0 ) { throw new VerifierException( "Unexpected failure: \"" + xppe.getMessage() + "\"", xppe ); } } private void checkEncoding( String resource, String encoding ) throws Exception { ModelloFeaturesTestXpp3Reader reader = new ModelloFeaturesTestXpp3Reader(); Features features = reader.read( getClass().getResourceAsStream( resource ) ); assertEquals( "modelEncoding", encoding, features.getModelEncoding() ); ModelloFeaturesTestXpp3Writer writer = new ModelloFeaturesTestXpp3Writer(); StringWriter buffer = new StringWriter(); writer.write( buffer, features ); String xmlHeader = buffer.toString().substring( 0, 44 ); if ( encoding == null ) { assertTrue( xmlHeader, xmlHeader.startsWith( "" ) ); } else { assertTrue( xmlHeader, xmlHeader.startsWith( "" ) ); } } public void verifyEncoding() throws Exception { checkEncoding( "/features.xml", null ); checkEncoding( "/features-UTF-8.xml", "UTF-8" ); checkEncoding( "/features-Latin-15.xml", "ISO-8859-15" ); } } modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/0000755000175000017500000000000011260056264023414 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/0000755000175000017500000000000011260056264024203 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/0000755000175000017500000000000011260056264025776 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056264027431 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/0000755000175000017500000000000011260056264031417 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/0000755000175000017500000000000011260056264032217 5ustar mkochmkoch././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3/modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp0000755000175000017500000000000011260056264032747 5ustar mkochmkoch././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3/Xpp3GeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp0000644000175000017500000001017711221502704032747 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.xpp3; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; import java.util.Properties; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: Xpp3GeneratorTest.java 1259 2009-06-27 20:49:08Z hboutemy $ */ public class Xpp3GeneratorTest extends AbstractModelloJavaGeneratorTest { public Xpp3GeneratorTest() { super( "xpp3" ); } public void testXpp3Generator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/maven.mdo" ) ) ); // check some elements read from the model List classesList = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 28, classesList.size() ); ModelClass clazz = (ModelClass) classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); ModelField extend = clazz.getField( "extend", new Version( "4.0.0" ) ); assertTrue( extend.hasMetadata( XmlFieldMetadata.ID ) ); XmlFieldMetadata xml = (XmlFieldMetadata) extend.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertTrue( xml.isAttribute() ); assertEquals( "extender", xml.getTagName() ); ModelField build = clazz.getField( "build", new Version( "4.0.0" ) ); assertTrue( build.hasMetadata( XmlFieldMetadata.ID ) ); xml = (XmlFieldMetadata) build.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertEquals( "builder", xml.getTagName() ); // now generate sources and test them Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.VERSION, "4.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); modello.generate( model, "java", parameters ); modello.generate( model, "xpp3-writer", parameters ); modello.generate( model, "xpp3-reader", parameters ); addDependency( "xmlunit", "xmlunit", "1.2" ); compile( getOutputDirectory(), getOutputClasses() ); // TODO: see why without this, version system property is set to "2.4.1" value after verify System.setProperty( "version", getModelloVersion() ); verify( "org.codehaus.modello.generator.xml.xpp3.Xpp3Verifier", "xpp3" ); } } ././@LongLink0000000000000000000000000000020500000000000011562 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3/FeaturesXpp3GeneratorTest.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp0000644000175000017500000000515411176576243032770 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.xpp3; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesXpp3GeneratorTest.java 1225 2009-05-01 13:44:03Z hboutemy $ */ public class FeaturesXpp3GeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesXpp3GeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); modello.generate( model, "java", parameters ); modello.generate( model, "xpp3-writer", parameters ); modello.generate( model, "xpp3-reader", parameters ); addDependency( "xmlunit", "xmlunit", "1.2" ); compile( getOutputDirectory(), getOutputClasses() ); verify( "org.codehaus.modello.generator.xml.xpp3.Xpp3FeaturesVerifier", getName() ); } } ././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3/_AbstractElementTest.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp0000644000175000017500000000534711132202454032752 0ustar mkochmkochpackage org.codehaus.modello.generator.xml.xpp3; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.ReaderFactory; import java.util.Properties; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: _AbstractElementTest.java 1125 2009-01-10 20:29:32Z hboutemy $ */ public class _AbstractElementTest extends AbstractModelloJavaGeneratorTest { public _AbstractElementTest() { super( "abstracto" ); } public void testAbstract() throws Throwable { ModelloCore modello = (ModelloCore) container.lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/abstract.mdo" ) ) ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) ); modello.generate( model, "java", parameters ); modello.generate( model, "xpp3-writer", parameters ); modello.generate( model, "xpp3-reader", parameters ); //addDependency( "org.codehaus.modello", "modello-core", getModelloVersion() ); // compile( generatedSources, classes ); } } modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/resources/0000755000175000017500000000000011260056264024505 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/test/resources/maven.mdo0000644000175000017500000016735411221502704026324 0ustar mkochmkoch maven Maven Maven's model for Java project. package org.codehaus.modello.test.model Model 3.0.0+ extend 3.0.0+ The location of the parent project, if one exists. Values from the parent project will be the default for this project if they are left unspecified. The path may be absolute, or relative to the current project.xml file. String parent 4.0.0 Specified which project to extend. Parent modelVersion 4.0.0 true The version of this model you are using. String pomVersion 3.0.0 true String id 3.0.0 true The id of the project. String groupId 3.0.0+ true The primary grouping for your project. String artifactId 3.0.0+ true The identifier used when generating the artifact for your project. String type 4.0.0 The type of artifact this project produces. String jar name 3.0.0+ true Human readable name of the project. String currentVersion 3.0.0 true String version 4.0.0 true The current version of the project. String shortDescription 3.0.0+ An abbreviated description of the project. String description 3.0.0+ A detailed description of the project. This element is usually specified as CDATA to enable the use of HTML tags within the description. This description is used to generate the <a href="plugins/site/index.html">front page</a> of the project's web site. String url website 3.0.0+ The URL where the project can be found. String logo 3.0.0+ The logo for the project. String issueTrackingUrl 3.0.0 The URL where the issue tracking system used by the project can be found. String issueManagement 4.0.0 The project's issue management information. IssueManagement ciManagement 4.0.0 The project's continuous integration management information. CiManagement inceptionYear 3.0.0+ true The year the project started. String gumpRepositoryId 3.0.0 Hint for the gump continuous integration build system. String siteAddress 3.0.0 The FQDN of the host where the project's site is uploaded. String siteDirectory 3.0.0 The directory on the site host where site documentation is placed when the site is uploaded. String distributionSite 3.0.0 The FQDN of the host where the project's artifacts are uploaded. String This naming is inconsistent and distribution should occur from a repository structure. distributionDirectory 3.0.0 The directory on the distribution host where artifacts are placed when uploaded. String This naming is inconsistent and distribution should occur from a repository structure. components 4.0.0 Component * repositories 4.0.0 The lists of the remote repositories Repository * pluginRepositories 4.0.0 The lists of the remote repositories for discovering plugins This may be removed or relocated in the near future. It is undecided whether plugins really need a remote repository set of their own. Repository * mailingLists 3.0.0+ The mailing lists for the project. MailingList * developers 3.0.0+ This element describes all of the developers associated with a project. Each developer is described by a <code>developer</code> element, which is then described by additional elements (described below). The auto-generated site documentation references this information. Developer * contributors 3.0.0+ This element describes all of the contributors associated with a project who are not developers. Each contributor is described by a <code>contributor</code> element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Contributor * dependencies 3.0.0+ This element describes all of the dependencies associated with a project. Each dependency is described by a <code>dependency</code> element, which is then described by additional elements (described below). Dependency * These should ultimately only be compile time dependencies when transitive dependencies come into play. overrides 4.0.0 This element describes all of the dependency overrides for a project. Each dependency is described by a <code>override</code> element, which is then described by additional elements (described below). Override * licenses 3.0.0+ This element describes all of the licenses for this project. Each license is described by a <code>license</code> element, which is then describe by additional elements (described below). The auto-generated site documentation references this information. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. License * versions 3.0.0 The released versions of the project. Version * branches 3.0.0 The SCM branches create for the project. Branch * packageGroups 3.0.0+ Package groups required for complete javadocs. PackageGroup * reports 3.0.0+ This element includes the specification of reports to be included in a Maven-generated site. These reports will be run when a user executes <code>maven site</code>. All of the reports will be included in the navigation bar for browsing in the order they are specified. String * scm 4.0.0 Specification for the SCM use by the project. Scm repository 3.0.0 Specification for the SCM use by the project. Repository This element needs to be renamed as it conflicts with the existing notion of repositories in Maven. build 3.0.0+ true Information required to build the project. Build organization organisation 3.0.0+ This element describes various attributes of the organziation to which the project belongs. These attributes are utilized when documentation is created (for copyright notices and links). Organization distributionManagement 4.0.0 Distribution information for a project. DistributionManagement local 4.0.0 false Local configuration information. Local properties 3.0.0+ Properties about the project. This allows you to configure your project and the plugins it uses. Properties String * preGoals 4.0.0 Set of decorator(s) injected before the target goal(s). PreGoal * postGoals 4.0.0 Set of decorator(s) injected after the target goal(s). PostGoal * content 1.0.0+ Content type: in fact, an association to a class with attributes and one Content field.]]> ContentTest 1 3.0.0 public void setVersion(String version) { this.currentVersion = version; } public String getVersion() { return currentVersion; } 3.0.0+ private String packageName; public void setPackage(String packageName) { this.packageName = packageName; } public String getPackage() { return packageName; } 4.0.0 public String getId() { StringBuffer id = new StringBuffer(); id.append( getGroupId() ); id.append( ":" ); id.append( getArtifactId() ); id.append( ":" ); id.append( getType() ); id.append( ":" ); id.append( getVersion() ); return id.toString(); } Branch 3.0.0+ This element describes each of the branches of the project. Each branch is described by a <code>tag</code> element tag 3.0.0+ true The branch tag in the version control system (e.g. cvs) used by the project for the source code associated with this branch of the project. String description 4.0.0 A description of the branch and its strategy. String lastMergeTag 4.0.0 This is the tag in the version control system that was last used to merge from the branch to the current codebase. Future merges should merge only the changes from this tag to the next. String Build 3.0.0+ nagEmailAddress 3.0.0 An address to which notifications regarding the status of builds for this project can be sent. This is intended for use by tools which do unattended builds, for example those providing for continuous integration. Currently this is used by the <a href="build-file.html#maven:gump-descriptor">maven:gump-descriptor</a> target. String This should be moved out of the build section. Vestigal for use with Gump. sourceDirectory 3.0.0+ true This element specifies a directory containing the source of the project. The generated build system will compile the source in this directory when the project is built. The path given is relative to the project descriptor. String unitTestSourceDirectory 3.0.0+ true This element specifies a directory containing the unit test source of the project. The generated build system will compile these directories when the project is being tested. The unit tests must use the JUnit test framework. The path given is relative to the project descriptor. String aspectSourceDirectory 3.0.0+ This element specifies a directory containing Aspect sources of the project. The generated build system will compile the Aspects in this directory when the project is built if Aspects have been enabled (see the <a href="plugins/aspectj/goals.html">Aspectj goals</a> document). The path given is relative to the project descriptor. String integrationUnitTestSourceDirectory 3.0.0+ This element specifies a directory containing integration test sources of the project. String sourceModifications 3.0.0+ true This element describes all of the sourceModifications associated with a project. Each source modification is described by a <code>sourceModification</code> element, which is then described by additional elements (described below). These modifications are used to exclude or include various source depending on the environment the build is running in. SourceModification * unitTest 3.0.0+ true This element specifies unit tests associated with the project. UnitTest new UnitTest() resources 3.0.0+ This element describes all of the resources associated with a project or unit tests. Each resource is described by a resource element, which is then described by additional elements (described <a href="#resource">below</a>). These resources are used to complete the jar file or to run unit test. Resource * directory 4.0.0 The directory where all generated by the build is placed. String output 4.0.0 The directory where compiled application classes are placed. String finalName 4.0.0 The filename (including an extension, but with no path information) that the produced artifact will be called. The default value is artifactId-version.extension (where extension is derived from type). String testOutput 4.0.0 The directory where compiled test classes are placed. String CiManagement 4.0.0 system 4.0.0 The name of the continuous integration system i.e. Bugzilla String url 4.0.0 Url for the continuous integration system use by the project. String nagEmailAddress 4.0.0 Email address for the party to be notified on unsuccessful builds. String Contributor 3.0.0+ name 3.0.0+ The full name of the contributor. String email 3.0.0+ The email address of the contributor. String url 3.0.0+ The URL for the homepage of the contributor. String organization 3.0.0+ The organization to which the contributor belongs. String roles 3.0.0+ The roles the contributor plays in the project. Each role is describe by a <code>role</code> element, the body of which is a role name. String * timezone 3.0.0+ The timezone the contributor is in. This is a number in the range -14 to 14. String Dependency 3.0.0+ id 3.0.0 true The id of the project. String groupId 3.0.0+ true The project group that produced the dependency, e.g. <code>geronimo</code>. String artifactId 3.0.0+ true The unique id for an artifact produced by the project group, e.g. <code>germonimo-jms</code> String version 3.0.0+ true The version of the dependency., e.g. <code>3.2.1</code> String url 3.0.0+ This url will be provided to the user if the jar file cannot be downloaded from the central repository. String The URL should really be gleaned from a shared database of dependency information. jar 3.0.0 Literal name of the artifact. String artifact 4.0.0+ Literal name of the artifact String type 3.0.0+ Other known recognised dependency types are: <code>ejb</code> and <code>plugin</code>. String jar properties 3.0.0+ Properties about the dependency. Various plugins allow you to <code>mark</code> dependencies with properties. For example the <a href="plugins/war/index.html">war</a> plugin looks for a <code>war.bundle</code> property, and if found will include the dependency in <code>WEB-INF/lib</code>. For example syntax, check the war plugin docs. Properties String * 4.0.0 public String getId() { return groupId + ":" + artifactId + ":" + type + ":" + version; } public String toString() { return groupId + "/" + type + "s:" + artifactId + "-" + version; } 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } return getArtifactId() + "-" + getVersion() + "." + getExtension(); } public String getExtension() { if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( o == null ) { return false; } if ( getClass() != o.getClass() ) { return false; } if ( getId() != null ) { return getId().equals( ( (Dependency) o ).getId() ); } else { return ( (Dependency) o ).getId() == null; } } public int hashCode() { if ( getId() != null ) { return getId().hashCode(); } else { return super.hashCode(); } } ]]> Override 4.0.0 groupId 4.0.0 true The project group that produced the dependency, e.g. <code>geronimo</code>. String artifactId 4.0.0 true The unique id for an artifact produced by the project group, e.g. <code>germonimo-jms</code> String type 4.0.0 Other known recognised dependency types are: <code>ejb</code> and <code>plugin</code>. String jar version 4.0.0 true The version of the dependency., e.g. <code>3.2.1</code> String file 4.0.0 true The filename of the dependency that will be used to override the one from the repository, e.g. <code>lib/non-distributable-code-1.3.jar</code> String Contributor Developer 3.0.0+ id 3.0.0+ The username of the developer. String IssueManagement 4.0.0 system 4.0.0 The name of the issue management system i.e. Bugzilla String url 4.0.0 Url for the issue management system use by the project. String DistributionManagement 4.0.0 This elements describes all that pertains to distribution for a project. repository 4.0.0 Information needed for deploying to remote repository artifacts generated by the project Repository site Information needed for deploying website files of the project. 4.0.0 Site License 3.0.0+ name 3.0.0+ The full legal name of the license. String url 3.0.0+ The official url for the license text. String distribution 3.0.0 The primary method by which this project may be distributed. <dl> <dt>repo</dt> <dd>may be downloaded from the Maven repository</dd> <dt>manual</dt> <dd>user must manually download and install the dependency.</dd> </dl> String comments 3.0.0+ the description String MailingList 3.0.0+ This element describes all of the mailing lists associated with a project. Each mailing list is described by a <code>mailingList</code> element, which is then described by additional elements (described below). The auto-generated site documentation references this information. name 3.0.0+ The name of the mailing list. String subscribe 3.0.0+ The email address or link that can be used to subscribe to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String unsubscribe 3.0.0+ The email address or link that can be used to unsubscribe to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String post 4.0.0 The email address or link that can be used to post to the mailing list. If this is an email address, a <code>mailto:</code> link will automatically be created when the documentation is created. String archive 3.0.0+ The link to a URL where you can browse the archive. String This should probably be removed from 4.0.0 before alpha-1 archives 4.0.0 The link to a URL where you can browse the archive. String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization 3.0.0+ name 3.0.0+ The full name of the organization. String url 3.0.0+ The URL to the organization's home page. String logo 3.0.0+ The URL to the organization's logo image. This can be an URL relative to the base directory of the generated web site, (e.g., <code>/images/org-logo.png</code>) or an absolute URL (e.g., <code>http://my.corp/logo.png</code>). This value is used when generating the project documentation. String PackageGroup 3.0.0+ title 3.0.0+ the description String packages 3.0.0+ the description String PatternSet 3.0.0+ includes 3.0.0+ the description String * excludes 3.0.0+ the description String * 3.0.0+ public java.util.List getDefaultExcludes() { java.util.List defaultExcludes = new java.util.ArrayList(); defaultExcludes.add( "**/*~" ); defaultExcludes.add( "**/#*#" ); defaultExcludes.add( "**/.#*" ); defaultExcludes.add( "**/%*%" ); defaultExcludes.add( "**/._*" ); // CVS defaultExcludes.add( "**/CVS" ); defaultExcludes.add( "**/CVS/**" ); defaultExcludes.add( "**/.cvsignore" ); // SCCS defaultExcludes.add( "**/SCCS" ); defaultExcludes.add( "**/SCCS/**" ); // Visual SourceSafe defaultExcludes.add( "**/vssver.scc" ); // Subversion defaultExcludes.add( "**/.svn" ); defaultExcludes.add( "**/.svn/**" ); // Mac defaultExcludes.add( "**/.DS_Store" ); return defaultExcludes; } Parent 4.0.0 artifactId 4.0.0 The artifact id of the project to extend. String groupId 4.0.0 The group id of the project to extend. String version 4.0.0 The versi>on of the project to extend. String Repository 3.0.0 connection 3.0.0 The source configuration management system URL that describes the repository and how to connect to the repository. This is used by Maven when <a href="plugins/dist/index.html">building versions</a> from specific ID. String developerConnection 3.0.0 Just like connection, but for developers, i.e. this scm connection will not be read only. String url 3.0.0 The URL to the project's browsable CVS repository. String Scm 4.0.0 connection 4.0.0 The source configuration management system URL that describes the repository and how to connect to the repository. This is used by Maven when <a href="plugins/dist/index.html">building versions</a> from specific ID. String developerConnection 4.0.0 Just like connection, but for developers, i.e. this scm connection will not be read only. String url 4.0.0 The URL to the project's browsable CVS repository. String branches 4.0.0 The SCM branches that are currently active for the project. These should only be those forked from the current branch or trunk that are intended to be used. String * Resource 3.0.0+ PatternSet directory 3.0.0+ Describe the directory where the resource is stored. The path may be absolute, or relative to the project.xml file. String targetPath 3.0.0+ Describe the resource target path. For example, if you want that resource appear into a specific package ( <code>org.apache.maven.messages</code>), you must specify this element with this value : <code>org/apache/maven/messages</code> String filtering 3.0.0+ Describe if resources are filtered or not. String false 3.0.0+ public boolean isFiltering() { return !"false".equals( filtering ); } public void setFiltering( boolean filtering ) { this.filtering = ( filtering ? "true" : "false" ); } SourceModification 3.0.0+ Resource className 3.0.0+ If the class with this name can <strong>not</strong> be loaded, then the includes and excludes specified below will be applied to the contents of the <a href="#sourceDirectory">sourceDirectory</a> String property 3.0.0+ the description String UnitTest 3.0.0+ PatternSet resources 3.0.0+ the description Resource * Version 3.0.0 This element describes each of the previous versions of the project. Each version is described by a <code>version</code> element name 3.0.0 The external version number under which this release was distributed. Examples include: <code>1.0</code>, <code>1.1-alpha1</code>, <code>1.2-beta</code>, <code>1.3.2</code> etc. String tag 3.0.0 The name given in the version control system (e.g. cvs) used by the project for the source code associated with this version of the project. String id 3.0.0 A unique identifier for a version. This ID is used to specify the version that <a href="plugins/dist/index.html"> <code>maven:dist</code> </a> builds. String Repository 4.0.0 Repository contains the information needed for establishing connections with remote repoistory id 4.0.0 A unique identifier for a repository. String name 4.0.0 Human readable name of the repository String url 4.0.0 The url of of the repository String 4.0.0 public boolean equals( Object obj ) { Repository other = ( Repository ) obj; boolean retValue = false; if ( id != null ) { retValue = id.equals( other.id ); } return retValue; } Site 4.0.0 Site contains the information needed for deploying websites. id 4.0.0 A unique identifier for a deployment locataion. String name 4.0.0 Human readable name of the deployment location String url 4.0.0 The url of of the location where website is deployed String GoalDecorator 4.0.0 name 4.0.0 The target goal which should be decorated. String attain 4.0.0 The goal which should be injected into the execution chain. String GoalDecorator PreGoal 4.0.0 GoalDecorator PostGoal 4.0.0 Local 4.0.0 Local contains the information that is specific to the user's local environment. This would only be expected in a user or site pom, not a project POM. repository 4.0.0 The local repository that contains downloaded artifacts. String online 4.0.0 Whether to run the build online. If not, no remote repositories are consulted for plugins or dependencies and this configuration may be used by other plugins requiring online access. boolean true Component 4.0.0 name 4.0.0 String comment 4.0.0 String components 4.0.0 Component * custom DOM 4.0.0 properties 4.0.0 Properties String * flatProperties 4.0.0 Properties String * ContentTest Content type.]]> 1.0.0+ content Content type.]]> 1.5.0+ Content attr An XML attribute. 1.0.0+ String modello-1.1/modello-plugins/modello-plugin-xpp3/src/test/resources/abstract.mdo0000644000175000017500000000316511127507731027020 0ustar mkochmkoch abstract Abstract package org.codehaus.modello.generator.xml.xpp3.test.abstracto Root 1.0.0+ Node leaves 1.0.0+ Leaf * Node 1.0.0+ id String 1.0.0+ true Leaf Node 1.0.0+ id String 1.0.0+ true modello-1.1/modello-plugins/modello-plugin-xpp3/src/site/0000755000175000017500000000000011260056264022460 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/site/site.xml0000644000175000017500000000022511112331565024141 0ustar mkochmkoch Modello

    modello-1.1/modello-plugins/modello-plugin-xpp3/src/site/xdoc/0000755000175000017500000000000011260056264023415 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/site/xdoc/index.xml0000644000175000017500000000361311131476544025255 0ustar mkochmkoch Modello XPP3 Plugin Hervé Boutemy

    Modello XPP3 Plugin generates XML readers and writers based on XPP3 API (XML Pull Parser).

    xpp3-reader generator creates my.model.package.io.xpp3.ModelNameXpp3Reader class with following public methods:

    • public RootClass read( Reader reader, boolean strict )
          throws IOException, XmlPullParserException
    • public RootClass read( Reader reader )
          throws IOException, XmlPullParserException
    • public RootClass read( InputStream in, boolean strict )
          throws IOException, XmlPullParserException
    • public RootClass read( InputStream in )
          throws IOException, XmlPullParserException
    • public void setAddDefaultEntities( boolean addDefaultEntities )
    • public boolean getAddDefaultEntities()

    xpp3-writer generator creates my.model.package.io.xpp3.ModelNameXpp3Writer class with following public methods:

    • public void write( Writer writer, RootClass root )
          throws IOException
    modello-1.1/modello-plugins/modello-plugin-xpp3/src/it/0000755000175000017500000000000011260056264022130 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/0000755000175000017500000000000011260056264024334 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/pom.xml0000644000175000017500000000252711127507731025661 0ustar mkochmkoch 4.0.0 org.codehaus.modello.xpp3 maven-model Maven Model 1.0-SNAPSHOT Maven Model org.codehaus.modello modello-maven-plugin 1.0-alpha-14-SNAPSHOT 4.0.0 src/main/mdo/maven.mdo java xpp3-reader org.codehaus.plexus plexus-utils 1.3 junit junit 3.8.1 modello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/0000755000175000017500000000000011260056264025123 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/0000755000175000017500000000000011260056264026102 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/0000755000175000017500000000000011260056264027023 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/0000755000175000017500000000000011260056264027612 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/0000755000175000017500000000000011260056264031405 5ustar mkochmkoch././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modello/modello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modell0000755000175000017500000000000011260056264032602 5ustar mkochmkoch././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modello/xpp3/modello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modell0000755000175000017500000000000011260056264032602 5ustar mkochmkoch././@LongLink0000000000000000000000000000020000000000000011555 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modello/xpp3/Xpp3ParsingTest.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modell0000644000175000017500000000167211127507731032614 0ustar mkochmkochpackage org.codehaus.modello.xpp3; import junit.framework.TestCase; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; /** @author Jason van Zyl */ public class Xpp3ParsingTest extends TestCase { public void testXpp3ParsingWithModelWithWrongRootTag() throws Exception { File model = new File( System.getProperty( "basedir" ), "src/test/models/model-with-wrong-root-tag.xml" ); MavenXpp3Reader reader = new MavenXpp3Reader(); reader.read( ReaderFactory.newXmlReader( model ), true ); } public void testXpp3ParsingWithModelWithMissingElements() throws Exception { File model = new File( System.getProperty( "basedir" ), "src/test/models/model-with-missing-elements.xml" ); MavenXpp3Reader reader = new MavenXpp3Reader(); reader.read( ReaderFactory.newXmlReader( model ), true ); } } modello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models/0000755000175000017500000000000011260056264027365 5ustar mkochmkoch././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models/model-with-missing-elements.xmlmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models/model-with-missin0000644000175000017500000000021711127507731032663 0ustar mkochmkoch one two 1.0 ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models/model-with-wrong-root-tag.xmlmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models/model-with-wrong-0000644000175000017500000000021311127507731032566 0ustar mkochmkoch one two 1.0 modello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/main/0000755000175000017500000000000011260056264026047 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/main/mdo/0000755000175000017500000000000011260056264026626 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/main/mdo/maven.mdo0000644000175000017500000032055311127507731030447 0ustar mkochmkoch maven Maven This is a reference for the Maven project descriptor used in Maven.

    An XSD is available at:

    ]]>
    package org.apache.maven.model Model ModelBase <project> element is the root of the descriptor. The following table lists all of the possible child elements. ]]> 3.0.0+ extend 3.0.0 project.xml file. For example, <extend>${basedir}/../project.xml</extend>. ]]> String parent 4.0.0 Parent modelVersion 4.0.0 true String pomVersion 3.0.0 true String 3.]]> groupId 3.0.0+ true org.apache.maven). ]]> String artifactId 3.0.0+ true String id 3.0.0 true Deprecated. When used, this sets both the groupId and artifactId elements if they were previously empty. ]]> String packaging 4.0.0 jar war ear pom. Plugins can create their own packaging, and therefore their own packaging types, so this list does not contain all possible types. ]]> String jar name 3.0.0+ true String currentVersion 3.0.0 true String version 4.0.0 true String shortDescription 3.0.0 String description 3.0.0+ String url 3.0.0+ String logo 3.0.0 /images/project-logo.png) or an absolute URL (e.g., http://my.corp/project-logo.png). This is used when generating the project documentation. ]]> String prerequisites 4.0.0 Describes the prerequisites in the build environment for this project. Prerequisites issueTrackingUrl 3.0.0 String issueManagement 4.0.0 IssueManagement ciManagement 4.0.0 CiManagement inceptionYear 3.0.0+ true String gumpRepositoryId 3.0.0 String siteAddress 3.0.0 String siteDirectory 3.0.0 String distributionSite 3.0.0 maven.repo.central and maven.repo.central.directory. ]]> String distributionDirectory 3.0.0 String mailingLists 3.0.0+ MailingList * developers 3.0.0+ Developer * contributors 3.0.0+ Contributor * licenses 3.0.0+ license element, which is then described by additional elements. Projects should only list the license(s) that applies to the project and not the licenses that apply to dependencies. If multiple licenses are listed, it is assumed that the user can select any of them, not that they must accept all. ]]> License * versions 3.0.0 Version * branches 3.0.0 Branch * packageGroups 3.0.0 PackageGroup * reports 3.0.0 maven site. All of the reports will be included in the navigation bar for browsing in the order they are specified. ]]> String * scm 4.0.0 Scm repository 3.0.0 Repository organization 3.0.0+ organisation Organization properties 3.0.0 <name>value</name>. ]]> Properties String * packageName 3.0.0 String build 3.0.0+ true Build profiles 4.0.0 Profile * 3.0.0 4.0.0 ModelBase 3.0.0+ modules 4.0.0 The modules (sometimes called subprojects) to build as a part of this project. Each module listed is a relative path to the directory containing the module. String * repositories 4.0.0 Repository * pluginRepositories 4.0.0 Repository * dependencies 3.0.0+ the dependency mechanism for more information. ]]> Dependency * reports 4.0.0 Deprecated. Now ignored by Maven. ]]> DOM reporting 4.0.0 mvn site. All of the reports will be included in the navigation bar for browsing. ]]> Reporting dependencyManagement 4.0.0 false DependencyManagement distributionManagement 4.0.0 DistributionManagement properties 4.0.0 <name>value</name>. ]]> Properties String * Branch 3.0.0 tag 3.0.0 true String PluginContainer 3.0.0+ plugins 4.0.0 The list of plugins to use. Plugin * 4.0.0 PluginConfiguration 3.0.0+ PluginContainer pluginManagement 4.0.0 false PluginManagement BuildBase 3.0.0+ PluginConfiguration defaultGoal 3.0.0+ String resources 3.0.0+ Resource * testResources 4.0.0 Resource * directory 4.0.0 String finalName 4.0.0 ${artifactId}-${version}. ]]> String filters 4.0.0 String * Build 3.0.0+ BuildBase nagEmailAddress 3.0.0 String sourceDirectory 3.0.0+ true String scriptSourceDirectory 4.0.0 true String unitTestSourceDirectory 3.0.0 true String testSourceDirectory 4.0.0 true String aspectSourceDirectory 3.0.0 String integrationUnitTestSourceDirectory 3.0.0 String sourceModifications 3.0.0 true SourceModification * unitTest 3.0.0 true new UnitTest() UnitTest outputDirectory 4.0.0 String testOutputDirectory 4.0.0 String extensions 4.0.0 A set of build extensions to use from this project. Extension * CiManagement 4.0.0 system 4.0.0 continuum.]]> String url 4.0.0 String notifiers 4.0.0 * Notifier Notifier Configures one method for notifying users/developers when a build breaks. 4.0.0 type 4.0.0 mail String The mechanism used to deliver notifications. sendOnError 4.0.0 true boolean Whether to send notifications on error. sendOnFailure 4.0.0 true boolean Whether to send notifications on failure. sendOnSuccess 4.0.0 true boolean Whether to send notifications on success. sendOnWarning 4.0.0 true boolean Whether to send notifications on warning. address 4.0.0 String Deprecated. Where to send the notification to - eg email address. ]]> configuration Extended configuration specific to this notifier goes here. Properties String * Contributor Description of a person who has contributed to the project, but who does not have commit privileges. Usually, these contributions come in the form of patches submitted. 3.0.0+ name 3.0.0+ String email 3.0.0+ String url 3.0.0+ String organization organisation 3.0.0+ String organizationUrl organisationUrl 3.0.0+ String roles 3.0.0+ role element, the body of which is a role name. This can also be used to describe the contribution. ]]> String * timezone 3.0.0+ String properties 3.0.0+ Properties String * Dependency 3.0.0+ id 3.0.0 true Deprecated. Please use groupId and artifactId together instead. ]]> String groupId 3.0.0+ true org.apache.maven. ]]> String artifactId 3.0.0+ true maven-artifact. ]]> String version 3.0.0+ 3.2.1. In Maven 2, this can also be specified as a range of versions. ]]> String url 3.0.0 String jar 3.0.0 String type 3.0.0 jar. While it usually represents the extension on the filename of the dependency, that is not always the case. Some examples are jar, war, and plugin. A dependency of type plugin is loaded as a Maven plugin and not added to the project build classpath. ]]> String jar type 4.0.0 jar. While it usually represents the extension on the filename of the dependency, that is not always the case. A type can be mapped to a different extension and a classifier. The type often correspongs to the packaging used, though this is also not always the case. Some examples are jar, war, ejb-client and test-jar. New types can be defined by plugins that set extensions to true, so this is not a complete list. ]]> String jar classifier 4.0.0 jdk14 and jdk15. ]]> String false properties 3.0.0 war.bundle property, and if found will include the dependency in WEB-INF/lib. ]]> Properties String * scope 4.0.0 compile, runtime, test, system, and provided. Used to calculate the various classpaths used for compilation, testing, and so on. It also assists in determining which artifacts to include in a distribution of this project. For more information, see the dependency mechanism.]]> String systemPath 4.0.0 discouraged and may be replaced in later versions. This specifies the path on the filesystem for this dependency. Requires an absolute path for the value, not relative. Use a property that gives the machine specific absolute path, e.g. ${java.home}. ]]> String exclusions 4.0.0 Lists a set of artifacts that should be excluded from this dependency's artifact list when it comes to calculating transitive dependencies. Exclusion * optional 4.0.0 Indicates the dependency is optional for use of this library. While the version of the dependency will be taken into account for dependency calculation if the library is used elsewhere, it will not be passed on transitively. boolean false 3.0.0 4.0.0 4.0.0 3.0.0 element is explicity used in the POM. if ( getJar() != null) { return getJar(); } String artifact; if ("ejb-client".equals(getType())) { artifact = getArtifactId() + "-" + getVersion() + "-client." + getExtension(); } else { artifact = getArtifactId() + "-" + getVersion() + "." + getExtension(); } return artifact; } public String getTypeDirectory() { String path; if (getType().equals("ejb-client")) { path = "ejbs"; } else { path = getType() + "s"; } return path; } public String getExtension() { if ("ejb".equals(getType()) || "ejb-client".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType()) || "uberjar".equals(getType())) return "jar"; return getType(); } public boolean isAddedToClasspath() { return ("jar".equals(getType()) || "ejb".equals(getType()) || "ejb-client".equals(getType()) || "sar".equals(getType())); } public boolean isPlugin() { return ("plugin".equals(getType())); } public String getProperty( String property ) { return getProperties().getProperty( property ); } public boolean equals( Object o ) { if ( this == o ) { return true; } if ( !( o instanceof Dependency ) ) { return false; } Dependency d = (Dependency) o; return getId().equals( d.getId() ); } public int hashCode() { return getId().hashCode(); } ]]> Contributor Developer 3.0.0+ id 3.0.0+ String Exclusion 4.0.0 artifactId 4.0.0 String true groupId 4.0.0 String true IssueManagement Information about the issue tracking (or bug tracking) system used to manage this project. 4.0.0 system 4.0.0 String url 4.0.0 String DistributionManagement 4.0.0 repository 4.0.0 DeploymentRepository snapshotRepository 4.0.0 repository element. ]]> DeploymentRepository site 4.0.0 Site downloadUrl 4.0.0+ url. This is given to assist in locating artifacts that are not in the repository due to licensing restrictions. ]]> String relocation 4.0.0 Relocation information of the artifact if it has been moved to a new group ID and/or artifact ID. Relocation status 4.0.0 none (default), converted (repository manager converted this from an Maven 1 POM), partner (directly synced from a partner Maven 2 repository), deployed (was deployed from a Maven 2 instance), verified (has been hand verified as correct and final). ]]> false String License 3.0.0+ name 3.0.0+ String url 3.0.0+ String distribution 3.0.0+
    repo
    may be downloaded from the Maven repository
    manual
    user must manually download and install the dependency.
    ]]>
    String
    comments Addendum information pertaining to this license. 3.0.0+ String
    MailingList 3.0.0+ name 3.0.0+ String subscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String unsubscribe 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String post 3.0.0+ mailto: link will automatically be created when the documentation is created. ]]> String archive 3.0.0+ String otherArchives 3.0.0+ String * We could probably have a specific element for a dev mailing list for things like CI, and maybe even a specific element for the user and scm mailing lists. Then leave the more lose structure for any other type of mailing list. Organization Specifies the organization that produces this project. 3.0.0+ name 3.0.0+ String url 3.0.0+ String logo 3.0.0 /images/org-logo.png) or an absolute URL (e.g., http://my.corp/logo.png). This value is used when generating the project documentation. ]]> String PackageGroup 3.0.0 A JavaDoc package group. title 3.0.0 String packages 3.0.0 String PatternSet 3.0.0+ includes 3.0.0+ **/*.xml.]]> String * excludes 3.0.0+ **/*.xml]]> String * Parent 4.0.0 artifactId 4.0.0 true String groupId 4.0.0 true String version 4.0.0 String relativePath 4.0.0 pom.xml file within the check out. The default value is ../pom.xml. Maven looks for the parent pom first in the reactor of currently building projects, then in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent pom. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM. This feature is only for enhancing the development in a local checkout of that project. ]]> String ../pom.xml 4.0.0 Repository 3.0.0 connection 3.0.0 URL format and list of supported SCMs. This connection is read-only. ]]> String developerConnection 3.0.0 connection, but for developers, i.e. this scm connection will not be read only. ]]> String url 3.0.0 String Scm 4.0.0 connection 4.0.0 URL format and list of supported SCMs. This connection is read-only. ]]> String developerConnection 4.0.0 connection, but for developers, i.e. this scm connection will not be read only. ]]> String tag 4.0.0 String HEAD url 4.0.0 String FileSet 3.0.0+ PatternSet directory 3.0.0+ String Resource 3.0.0+ FileSet targetPath 3.0.0+ org.apache.maven.messages), you must specify this element with this value: org/apache/maven/messages. This is not required if you simply put the resources in that directory structure at the source, however. ]]> String filtering 3.0.0+ properties element and from the properties in the files listed in the filters element. ]]> boolean false SourceModification 3.0.0 FileSet className 3.0.0 not be loaded, then the includes and excludes specified below will be applied to the contents of the sourceDirectory. ]]> String property 3.0.0 not set, then the includes and excludes specified below will be applied to the contents of the sourceDirectory. ]]> String UnitTest 3.0.0 PatternSet resources 3.0.0 Resource * Version 3.0.0 version element ]]> name 3.0.0 1.0, 1.1-alpha1, 1.2-beta, 1.3.2 etc. ]]> String tag 3.0.0 String id 3.0.0 String 3.0.0 RepositoryBase 4.0.0 id 4.0.0 settings.xml file, for example. ]]> String name 4.0.0 String url 4.0.0 protocol://hostname/path. ]]> String layout 4.0.0 legacy or default. ]]> String default 4.0.0 Repository RepositoryBase 4.0.0 A repository contains the information needed for establishing connections with remote repoistory. releases 4.0.0 How to handle downloading of releases from this repository. RepositoryPolicy snapshots 4.0.0 How to handle downloading of snapshots from this repository. RepositoryPolicy 4.0.0 DeploymentRepository RepositoryBase 4.0.0 Repository contains the information needed for deploying to the remote repoistory. uniqueVersion Whether to assign snapshots a unique version comprised of the timestamp and build number, or to use the same version each time boolean true 4.0.0 4.0.0 RepositoryPolicy 4.0.0 Download policy enabled 4.0.0 Whether to use this repository for downloading this type of artifact. boolean true updatePolicy 4.0.0 always, daily (default), interval:XXX (in minutes) or never (only if it doesn't exist locally). ]]> String checksumPolicy 4.0.0 ignore , fail or warn (the default). ]]> String Site 4.0.0 id 4.0.0 settings.xml file, for example. ]]> String name 4.0.0 String url 4.0.0 protocol://hostname/path. ]]> String ConfigurationContainer 4.0.0 inherited 4.0.0 String configuration DOM 4.0.0 Plugin 4.0.0 ConfigurationContainer groupId The group ID of the plugin in the repository. 4.0.0 String org.apache.maven.plugins artifactId The artifact ID of the plugin in the repository. 4.0.0 String true version 4.0.0 String extensions 4.0.0 boolean Whether to load Maven extensions (such as packaging and type handlers) from this plugin. For performance reasons, this should only be enabled when necessary. false executions 4.0.0 Multiple specifications of a set of goals to execute during the build lifecycle, each having (possibly) different configuration. PluginExecution * dependencies Additional dependencies that this project needs to introduce to the plugin's classloader. 4.0.0 Dependency * goals 4.0.0 Deprecated. Unused by Maven. ]]> DOM 4.0.0 elements.\nOffending execution\n\nId: \'" + exec.getId() + "\'\nPlugin:\'" + getKey() + "\'\n\n" ); } executionMap.put( exec.getId(), exec ); } } } return executionMap; } public String getKey() { return constructKey( groupId, artifactId ); } public static String constructKey( String groupId, String artifactId ) { return groupId + ":" + artifactId; } public boolean equals( Object other ) { if ( other instanceof Plugin ) { Plugin otherPlugin = (Plugin) other; return getKey().equals( otherPlugin.getKey() ); } return false; } public int hashCode() { return getKey().hashCode(); } public String toString() { return "Plugin [" + getKey() + "]"; } ]]> PluginExecution 4.0.0 ConfigurationContainer id 4.0.0 String default The identifier of this execution for labelling the goals during the build, and for matching exections to merge during inheritance. phase 4.0.0 String The build lifecycle phase to bind the goals in this execution to. If omitted, the goals will be bound to the default specified in their metadata. goals 4.0.0 The goals to execute with the given configuration. String * 4.0.0 DependencyManagement 4.0.0 Section for management of default dependency information for use in a group of POMs. dependencies 4.0.0 The dependencies specified here are not used until they are referenced in a POM within the group. This allows the specification of a "standard" version for a particular dependency. Dependency * PluginManagement 4.0.0 PluginContainer Section for management of default plugin information for use in a group of POMs. Reporting 4.0.0 Section for management of reports and their configuration. excludeDefaults 4.0.0 boolean If true, then the default reports are not included in the site generation. This includes the reports in the "Project Info" menu. false outputDirectory 4.0.0 String ${project.build.directory}/site . ]]> plugins 4.0.0 The reporting plugins to use and their configuration. ReportPlugin * 4.0.0 Profile ModelBase 4.0.0 id true 4.0.0 String The identifier of this build profile. This used both for command line activation, and identifies identical profiles to merge with during inheritance. activation 4.0.0 Activation build 4.0.0 true BuildBase 4.0.0 Activation 4.0.0 activeByDefault 4.0.0 boolean Flag specifying whether this profile is active by default. jdk 4.0.0 String 1.4 only activates on JDKs versioned 1.4, while !1.4 matches any JDK that is not version 1.4. ]]> os 4.0.0 ActivationOS property 4.0.0 ActivationProperty file 4.0.0 ActivationFile ActivationProperty 4.0.0 name 4.0.0 String true The name of the property to be used to activate a profile. value 4.0.0 String The value of the property required to activate a profile. ActivationOS 4.0.0 name 4.0.0 String ${os.name} Java property, such as Windows XP.]]> family 4.0.0 String windows or unix.]]> arch 4.0.0 String The architecture of the operating system to be used to activate the profile. version 4.0.0 String The version of the operating system to be used to activate the profile. ActivationFile 4.0.0 missing 4.0.0 String The name of the file that must be missing to activate the profile. exists 4.0.0 String The name of the file that must exist to activate the profile. ReportPlugin 4.0.0 groupId 4.0.0 String true org.apache.maven.plugins The group ID of the reporting plugin in the repository. artifactId 4.0.0 String true The artifact ID of the reporting plugin in the repository. version 4.0.0 String inherited 4.0.0 String Whether the configuration in this plugin should be made available to projects that inherit from this one. configuration 4.0.0 DOM The configuration of the reporting plugin. reportSets 4.0.0 execution in the build.]]> ReportSet * 4.0.0 ReportSet 4.0.0 Represents a set of reports and configuration to be used to generate them. id String true The unique id for this report set, to be used during POM inheritance. default configuration 4.0.0 Configuration of the report to be used when generating this set. DOM inherited 4.0.0 String reports 4.0.0 true String * 4.0.0 Prerequisites 4.0.0 Describes the prerequisites a project can have. maven 4.0.0 String 2.0 The minimum version of Maven required to build the project, or to use this plugin. false Relocation 4.0.0 Describes where an artifact has moved to. If any of the values are omitted, it is assumed to be the same as it was before. groupId 4.0.0 The group ID the artifact has moved to. String artifactId 4.0.0 The new artifact ID of the artifact. String version 4.0.0 The new version of the artifact. String message 4.0.0 An additional message to show the user about the move, such as the reason. String Extension 4.0.0 Describes a build extension to utilise. groupId 4.0.0 The group ID of the extension's artifact. true String artifactId 4.0.0 The artifact ID of the extension. true String version 4.0.0 The version of the extension. String 4.0.0
    modello-1.1/modello-plugins/modello-plugin-xpp3/src/main/0000755000175000017500000000000011260056264022440 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/0000755000175000017500000000000011260056264023361 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/0000755000175000017500000000000011260056264024150 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/0000755000175000017500000000000011260056264025743 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056264027376 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056264030674 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/0000755000175000017500000000000011260056264031566 5ustar mkochmkoch././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/Xpp3ReaderGenerator.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/Xpp3R0000644000175000017500000017063111243356043032474 0ustar mkochmkochpackage org.codehaus.modello.plugin.xpp3; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Properties; import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JField; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.javasource.JType; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.plexus.util.StringUtils; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: Xpp3ReaderGenerator.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public class Xpp3ReaderGenerator extends AbstractXpp3Generator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateXpp3Reader(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating XPP3 Reader.", ex ); } } private void generateXpp3Reader() throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.xpp3"; String unmarshallerName = getFileName( "Xpp3Reader" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, unmarshallerName ); JClass jClass = new JClass( packageName + '.' + unmarshallerName ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); jClass.addImport( "org.codehaus.plexus.util.ReaderFactory" ); jClass.addImport( "org.codehaus.plexus.util.xml.pull.MXParser" ); jClass.addImport( "org.codehaus.plexus.util.xml.pull.XmlPullParser" ); jClass.addImport( "org.codehaus.plexus.util.xml.pull.XmlPullParserException" ); jClass.addImport( "java.io.InputStream" ); jClass.addImport( "java.io.IOException" ); jClass.addImport( "java.io.Reader" ); jClass.addImport( "java.text.DateFormat" ); jClass.addImport( "java.util.Locale" ); addModelImports( jClass, null ); // ---------------------------------------------------------------------- // Write option setters // ---------------------------------------------------------------------- // The Field JField addDefaultEntities = new JField( JType.BOOLEAN, "addDefaultEntities" ); addDefaultEntities.setComment( "If set the parser will be loaded with all single characters from the XHTML specification.\n" + "The entities used:\n" + "
      \n" + "
    • http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
    • \n" + "
    • http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
    • \n" + "
    • http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent
    • \n" + "
    \n" ); addDefaultEntities.setInitString( "true" ); jClass.addField( addDefaultEntities ); // The setter JMethod addDefaultEntitiesSetter = new JMethod( "setAddDefaultEntities" ); addDefaultEntitiesSetter.addParameter( new JParameter( JType.BOOLEAN, "addDefaultEntities" ) ); addDefaultEntitiesSetter.setSourceCode( "this.addDefaultEntities = addDefaultEntities;" ); addDefaultEntitiesSetter.setComment( "Sets the state of the \"add default entities\" flag." ); jClass.addMethod( addDefaultEntitiesSetter ); // The getter JMethod addDefaultEntitiesGetter = new JMethod( "getAddDefaultEntities", JType.BOOLEAN, null ); addDefaultEntitiesGetter.setComment( "Returns the state of the \"add default entities\" flag." ); addDefaultEntitiesGetter.setSourceCode( "return addDefaultEntities;" ); jClass.addMethod( addDefaultEntitiesGetter ); // ---------------------------------------------------------------------- // Write the parse(Reader) method which will do the unmarshalling. // ---------------------------------------------------------------------- ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); JMethod unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.setComment( "@see ReaderFactory#newXmlReader" ); unmarshall.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); unmarshall.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); JSourceCode sc = unmarshall.getSourceCode(); sc.add( "XmlPullParser parser = new MXParser();" ); sc.add( "" ); sc.add( "parser.setInput( reader );" ); sc.add( "" ); writeParserInitialization( sc ); sc.add( "" ); sc.add( "parser.next();" ); sc.add( "return parse" + root.getName() + "( \"" + resolveTagName( root ) + "\", parser, strict );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.setComment( "@see ReaderFactory#newXmlReader" ); unmarshall.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( reader, true );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the parse(InputStream) method which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "in" ) ); unmarshall.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); sc = unmarshall.getSourceCode(); sc.add( "Reader reader = ReaderFactory.newXmlReader( in );" ); sc.add( "" ); sc.add( "return read( reader, strict );" ); jClass.addMethod( unmarshall ); // -------------------------------------------------------------------- unmarshall = new JMethod( "read", new JClass( root.getName() ), null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "in" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); sc = unmarshall.getSourceCode(); sc.add( "Reader reader = ReaderFactory.newXmlReader( in );" ); sc.add( "" ); sc.add( "return read( reader );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the class parsers // ---------------------------------------------------------------------- writeAllClassesParser( objectModel, jClass ); // ---------------------------------------------------------------------- // Write helpers // ---------------------------------------------------------------------- writeHelpers( jClass ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClassesParser( Model objectModel, JClass jClass ) { ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) clazz.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } writeClassParser( clazz, jClass, root.getName().equals( clazz.getName() ) ); } } private void writeClassParser( ModelClass modelClass, JClass jClass, boolean rootElement ) { JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.class.getName() ); // Skip abstract classes, no way to parse them out into objects if ( javaClassMetadata.isAbstract() ) { return; } String className = modelClass.getName(); String capClassName = capitalise( className ); String uncapClassName = uncapitalise( className ); JMethod unmarshall = new JMethod( "parse" + capClassName, new JClass( className ), null ); unmarshall.getModifiers().makePrivate(); unmarshall.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); unmarshall.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); unmarshall.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); JSourceCode sc = unmarshall.getSourceCode(); sc.add( className + " " + uncapClassName + " = new " + className + "();" ); ModelField contentField = null; List modelFields = modelClass.getAllFields( getGeneratedVersion(), true ); modelFields = getNonTransientFields( modelFields ); // read all XML attributes first for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isAttribute() ) { String tagName = resolveTagName( field, xmlFieldMetadata ); sc.add( "if ( parser.getAttributeValue( \"\", \"" + tagName + "\" ) != null )"); sc.add( "{" ); sc.indent(); writePrimitiveField( field, field.getType(), uncapClassName, "set" + capitalise( field.getName() ), sc, jClass ); sc.unindent(); sc.add( "}" ); } // TODO check if we have already one with this type and throws Exception if ( xmlFieldMetadata.isContent() ) { contentField = field; } } if ( contentField != null ) { writePrimitiveField( contentField, contentField.getType(), uncapClassName, "set" + capitalise( contentField.getName() ), sc, jClass ); } else { sc.add( "java.util.Set parsed = new java.util.HashSet();" ); if ( rootElement ) { sc.add( "int eventType = parser.getEventType();" ); sc.add( "boolean foundRoot = false;" ); sc.add( uncapClassName + ".setModelEncoding( parser.getInputEncoding() );" ); sc.add( "while ( eventType != XmlPullParser.END_DOCUMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( eventType == XmlPullParser.START_TAG )" ); } else { sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); } sc.add( "{" ); sc.indent(); boolean addElse = false; if ( rootElement ) { sc.add( "if ( parser.getName().equals( tagName ) )" ); sc.add( "{" ); sc.addIndented( "foundRoot = true;" ); sc.add( "}" ); sc.add( "else if ( strict && ! foundRoot )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Expected root element '\" + tagName + \"' but " + "found '\" + parser.getName() + \"'\", parser, null );" ); sc.add( "}" ); addElse = true; } //Write other fields for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( !xmlFieldMetadata.isAttribute() ) { processField( field, xmlFieldMetadata, addElse, sc, uncapClassName, jClass ); addElse = true; } } if ( !rootElement ) { /* if ( modelClass.getFields( getGeneratedVersion() ).size() > 0 ) { sc.add( "else" ); sc.add( "{" ); sc.addIndented( "parser.nextText();" ); sc.add( "}" ); } */ if ( addElse ) { sc.add( "else" ); sc.add( "{" ); sc.indent(); } sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Unrecognised tag: '\" + parser.getName() + \"'\", parser, null );" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "// swallow up to end tag since this is not valid" ); sc.add( "while ( parser.next() != XmlPullParser.END_TAG ) {}" ); sc.unindent(); sc.add( "}" ); if ( addElse ) { sc.unindent(); sc.add( "}" ); } } else { sc.add( "else if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Unrecognised tag: '\" + parser.getName() + \"'\", parser, null );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "eventType = parser.next();" ); } sc.unindent(); sc.add( "}" ); } sc.add( "return " + uncapClassName + ";" ); jClass.addMethod( unmarshall ); } /** * Generate code to process a field represented as an XML element. * * @param field the field to process * @param xmlFieldMetadata its XML metadata * @param addElse add an else statement before generating a new if * @param sc the method source code to add to * @param objectName the object name in the source * @param jClass the generated class source file */ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, boolean addElse, JSourceCode sc, String objectName, JClass jClass ) { String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String capFieldName = capitalise( field.getName() ); String singularName = singular( field.getName() ); String alias; if ( StringUtils.isEmpty( field.getAlias() ) ) { alias = "null"; } else { alias = "\"" + field.getAlias() + "\""; } String tagComparison = ( addElse ? "else " : "" ) + "if ( checkFieldWithDuplicate( parser, \"" + fieldTagName + "\", " + alias + ", parsed ) )"; if ( !( field instanceof ModelAssociation ) ) { //ModelField sc.add( tagComparison ); sc.add( "{" ); sc.indent(); writePrimitiveField( field, field.getType(), objectName, "set" + capitalise( field.getName() ), sc, jClass ); sc.unindent(); sc.add( "}" ); } else { // model association ModelAssociation association = (ModelAssociation) field; String associationName = association.getName(); if ( association.isOneMultiplicity() ) { sc.add( tagComparison ); sc.add( "{" ); sc.addIndented( objectName + ".set" + capFieldName + "( parse" + association.getTo() + "( \"" + fieldTagName + "\", parser, strict ) );" ); sc.add( "}" ); } else { //MANY_MULTIPLICITY XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); String type = association.getType(); if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { boolean wrappedItems = xmlAssociationMetadata.isWrappedItems(); if ( wrappedItems ) { sc.add( tagComparison ); sc.add( "{" ); sc.indent(); sc.add( type + " " + associationName + " = " + association.getDefaultValue() + ";" ); sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" ); sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( parser.getName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); } else { sc.add( ( addElse ? "else " : "" ) + "if ( parser.getName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); sc.add( type + " " + associationName + " = " + objectName + ".get" + capFieldName + "();" ); sc.add( "if ( " + associationName + " == null )" ); sc.add( "{" ); sc.indent(); sc.add( associationName + " = " + association.getDefaultValue() + ";" ); sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" ); sc.unindent(); sc.add( "}" ); } if ( isClassInModel( association.getTo(), field.getModelClass().getModel() ) ) { sc.add( associationName + ".add( parse" + association.getTo() + "( \"" + valuesTagName + "\", parser, strict ) );" ); } else { writePrimitiveField( association, association.getTo(), associationName, "add", sc, jClass ); } if ( wrappedItems ) { sc.unindent(); sc.add( "}" ); sc.add( "else if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Unrecognised association: '\" + " + "parser.getName() + \"'\", parser, null );" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "// swallow up to end tag since this is not valid" ); sc.add( "while ( parser.next() != XmlPullParser.END_TAG ) {}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); } else { sc.unindent(); sc.add( "}" ); } } else { //Map or Properties sc.add( tagComparison ); sc.add( "{" ); sc.indent(); if ( xmlAssociationMetadata.isMapExplode() ) { sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( parser.getName().equals( \"" + valuesTagName + "\" ) )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = null;" ); sc.add( "String value = null;" ); sc.add( "// " + xmlAssociationMetadata.getMapStyle() + " mode." ); sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( parser.getName().equals( \"key\" ) )" ); sc.add( "{" ); sc.addIndented( "key = parser.nextText();" ); sc.add( "}" ); sc.add( "else if ( parser.getName().equals( \"value\" ) )" ); sc.add( "{" ); sc.addIndented( "value = parser.nextText()" + ( xmlFieldMetadata.isTrim() ? ".trim()" : "" ) + ";" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "parser.nextText();" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( objectName + ".add" + capitalise( singularName ) + "( key, value );" ); sc.unindent(); sc.add( "}" ); sc.add( "parser.next();" ); sc.unindent(); sc.add( "}" ); } else { //INLINE Mode sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = parser.getName();" ); sc.add( "String value = parser.nextText()" + ( xmlFieldMetadata.isTrim() ? ".trim()" : "" ) + ";" ); sc.add( objectName + ".add" + capitalise( singularName ) + "( key, value );" ); sc.unindent(); sc.add( "}" ); } sc.unindent(); sc.add( "}" ); } } } } private void writePrimitiveField( ModelField field, String type, String objectName, String setterName, JSourceCode sc, JClass jClass ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); String tagName = resolveTagName( field, xmlFieldMetadata); String parserGetter; if ( xmlFieldMetadata.isAttribute() ) { parserGetter = "parser.getAttributeValue( \"\", \"" + tagName + "\" )"; } else { parserGetter = "parser.nextText()"; } /* TODO: this and a default if ( xmlFieldMetadata.isRequired() ) { parserGetter = "getRequiredAttributeValue( " + parserGetter + ", \"" + tagName + "\", parser, strict )"; } */ if ( xmlFieldMetadata.isTrim() ) { parserGetter = "getTrimmedValue( " + parserGetter + " )"; } if ( "boolean".equals( type ) ) { sc.add( objectName + "." + setterName + "( getBooleanValue( " + parserGetter + ", \"" + tagName + "\", parser, \"" + field.getDefaultValue() + "\" ) );" ); } else if ( "char".equals( type ) ) { sc.add( objectName + "." + setterName + "( getCharacterValue( " + parserGetter + ", \"" + tagName + "\", parser ) );" ); } else if ( "double".equals( type ) ) { sc.add( objectName + "." + setterName + "( getDoubleValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "float".equals( type ) ) { sc.add( objectName + "." + setterName + "( getFloatValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "int".equals( type ) ) { sc.add( objectName + "." + setterName + "( getIntegerValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "long".equals( type ) ) { sc.add( objectName + "." + setterName + "( getLongValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "short".equals( type ) ) { sc.add( objectName + "." + setterName + "( getShortValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "byte".equals( type ) ) { sc.add( objectName + "." + setterName + "( getByteValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "String".equals( type ) || "Boolean".equals( type ) ) { // TODO: other Primitive types sc.add( objectName + "." + setterName + "( " + parserGetter + " );" ); } else if ( "Date".equals( type ) ) { sc.add( "String dateFormat = " + ( xmlFieldMetadata.getFormat() != null ? "\"" + xmlFieldMetadata.getFormat() + "\"" : "null" ) + ";" ); sc.add( objectName + "." + setterName + "( getDateValue( " + parserGetter + ", \"" + tagName + "\", dateFormat, parser ) );" ); } else if ( "DOM".equals( type ) ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3DomBuilder" ); sc.add( objectName + "." + setterName + "( Xpp3DomBuilder.build( parser ) );" ); } else { throw new IllegalArgumentException( "Unknown type: " + type ); } } private void writeParserInitialization( JSourceCode sc ) { sc.add( "if ( addDefaultEntities )" ); sc.add( "{" ); sc.indent(); sc.add( "// ----------------------------------------------------------------------" ); sc.add( "// Latin 1 entities" ); sc.add( "// ----------------------------------------------------------------------" ); sc.add( "" ); sc.add( "parser.defineEntityReplacementText( \"nbsp\", \"\\u00a0\" );" ); sc.add( "parser.defineEntityReplacementText( \"iexcl\", \"\\u00a1\" );" ); sc.add( "parser.defineEntityReplacementText( \"cent\", \"\\u00a2\" );" ); sc.add( "parser.defineEntityReplacementText( \"pound\", \"\\u00a3\" );" ); sc.add( "parser.defineEntityReplacementText( \"curren\", \"\\u00a4\" );" ); sc.add( "parser.defineEntityReplacementText( \"yen\", \"\\u00a5\" );" ); sc.add( "parser.defineEntityReplacementText( \"brvbar\", \"\\u00a6\" );" ); sc.add( "parser.defineEntityReplacementText( \"sect\", \"\\u00a7\" );" ); sc.add( "parser.defineEntityReplacementText( \"uml\", \"\\u00a8\" );" ); sc.add( "parser.defineEntityReplacementText( \"copy\", \"\\u00a9\" );" ); sc.add( "parser.defineEntityReplacementText( \"ordf\", \"\\u00aa\" );" ); sc.add( "parser.defineEntityReplacementText( \"laquo\", \"\\u00ab\" );" ); sc.add( "parser.defineEntityReplacementText( \"not\", \"\\u00ac\" );" ); sc.add( "parser.defineEntityReplacementText( \"shy\", \"\\u00ad\" );" ); sc.add( "parser.defineEntityReplacementText( \"reg\", \"\\u00ae\" );" ); sc.add( "parser.defineEntityReplacementText( \"macr\", \"\\u00af\" );" ); sc.add( "parser.defineEntityReplacementText( \"deg\", \"\\u00b0\" );" ); sc.add( "parser.defineEntityReplacementText( \"plusmn\", \"\\u00b1\" );" ); sc.add( "parser.defineEntityReplacementText( \"sup2\", \"\\u00b2\" );" ); sc.add( "parser.defineEntityReplacementText( \"sup3\", \"\\u00b3\" );" ); sc.add( "parser.defineEntityReplacementText( \"acute\", \"\\u00b4\" );" ); sc.add( "parser.defineEntityReplacementText( \"micro\", \"\\u00b5\" );" ); sc.add( "parser.defineEntityReplacementText( \"para\", \"\\u00b6\" );" ); sc.add( "parser.defineEntityReplacementText( \"middot\", \"\\u00b7\" );" ); sc.add( "parser.defineEntityReplacementText( \"cedil\", \"\\u00b8\" );" ); sc.add( "parser.defineEntityReplacementText( \"sup1\", \"\\u00b9\" );" ); sc.add( "parser.defineEntityReplacementText( \"ordm\", \"\\u00ba\" );" ); sc.add( "parser.defineEntityReplacementText( \"raquo\", \"\\u00bb\" );" ); sc.add( "parser.defineEntityReplacementText( \"frac14\", \"\\u00bc\" );" ); sc.add( "parser.defineEntityReplacementText( \"frac12\", \"\\u00bd\" );" ); sc.add( "parser.defineEntityReplacementText( \"frac34\", \"\\u00be\" );" ); sc.add( "parser.defineEntityReplacementText( \"iquest\", \"\\u00bf\" );" ); sc.add( "parser.defineEntityReplacementText( \"Agrave\", \"\\u00c0\" );" ); sc.add( "parser.defineEntityReplacementText( \"Aacute\", \"\\u00c1\" );" ); sc.add( "parser.defineEntityReplacementText( \"Acirc\", \"\\u00c2\" );" ); sc.add( "parser.defineEntityReplacementText( \"Atilde\", \"\\u00c3\" );" ); sc.add( "parser.defineEntityReplacementText( \"Auml\", \"\\u00c4\" );" ); sc.add( "parser.defineEntityReplacementText( \"Aring\", \"\\u00c5\" );" ); sc.add( "parser.defineEntityReplacementText( \"AElig\", \"\\u00c6\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ccedil\", \"\\u00c7\" );" ); sc.add( "parser.defineEntityReplacementText( \"Egrave\", \"\\u00c8\" );" ); sc.add( "parser.defineEntityReplacementText( \"Eacute\", \"\\u00c9\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ecirc\", \"\\u00ca\" );" ); sc.add( "parser.defineEntityReplacementText( \"Euml\", \"\\u00cb\" );" ); sc.add( "parser.defineEntityReplacementText( \"Igrave\", \"\\u00cc\" );" ); sc.add( "parser.defineEntityReplacementText( \"Iacute\", \"\\u00cd\" );" ); sc.add( "parser.defineEntityReplacementText( \"Icirc\", \"\\u00ce\" );" ); sc.add( "parser.defineEntityReplacementText( \"Iuml\", \"\\u00cf\" );" ); sc.add( "parser.defineEntityReplacementText( \"ETH\", \"\\u00d0\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ntilde\", \"\\u00d1\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ograve\", \"\\u00d2\" );" ); sc.add( "parser.defineEntityReplacementText( \"Oacute\", \"\\u00d3\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ocirc\", \"\\u00d4\" );" ); sc.add( "parser.defineEntityReplacementText( \"Otilde\", \"\\u00d5\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ouml\", \"\\u00d6\" );" ); sc.add( "parser.defineEntityReplacementText( \"times\", \"\\u00d7\" );" ); sc.add( "parser.defineEntityReplacementText( \"Oslash\", \"\\u00d8\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ugrave\", \"\\u00d9\" );" ); sc.add( "parser.defineEntityReplacementText( \"Uacute\", \"\\u00da\" );" ); sc.add( "parser.defineEntityReplacementText( \"Ucirc\", \"\\u00db\" );" ); sc.add( "parser.defineEntityReplacementText( \"Uuml\", \"\\u00dc\" );" ); sc.add( "parser.defineEntityReplacementText( \"Yacute\", \"\\u00dd\" );" ); sc.add( "parser.defineEntityReplacementText( \"THORN\", \"\\u00de\" );" ); sc.add( "parser.defineEntityReplacementText( \"szlig\", \"\\u00df\" );" ); sc.add( "parser.defineEntityReplacementText( \"agrave\", \"\\u00e0\" );" ); sc.add( "parser.defineEntityReplacementText( \"aacute\", \"\\u00e1\" );" ); sc.add( "parser.defineEntityReplacementText( \"acirc\", \"\\u00e2\" );" ); sc.add( "parser.defineEntityReplacementText( \"atilde\", \"\\u00e3\" );" ); sc.add( "parser.defineEntityReplacementText( \"auml\", \"\\u00e4\" );" ); sc.add( "parser.defineEntityReplacementText( \"aring\", \"\\u00e5\" );" ); sc.add( "parser.defineEntityReplacementText( \"aelig\", \"\\u00e6\" );" ); sc.add( "parser.defineEntityReplacementText( \"ccedil\", \"\\u00e7\" );" ); sc.add( "parser.defineEntityReplacementText( \"egrave\", \"\\u00e8\" );" ); sc.add( "parser.defineEntityReplacementText( \"eacute\", \"\\u00e9\" );" ); sc.add( "parser.defineEntityReplacementText( \"ecirc\", \"\\u00ea\" );" ); sc.add( "parser.defineEntityReplacementText( \"euml\", \"\\u00eb\" );" ); sc.add( "parser.defineEntityReplacementText( \"igrave\", \"\\u00ec\" );" ); sc.add( "parser.defineEntityReplacementText( \"iacute\", \"\\u00ed\" );" ); sc.add( "parser.defineEntityReplacementText( \"icirc\", \"\\u00ee\" );" ); sc.add( "parser.defineEntityReplacementText( \"iuml\", \"\\u00ef\" );" ); sc.add( "parser.defineEntityReplacementText( \"eth\", \"\\u00f0\" );" ); sc.add( "parser.defineEntityReplacementText( \"ntilde\", \"\\u00f1\" );" ); sc.add( "parser.defineEntityReplacementText( \"ograve\", \"\\u00f2\" );" ); sc.add( "parser.defineEntityReplacementText( \"oacute\", \"\\u00f3\" );" ); sc.add( "parser.defineEntityReplacementText( \"ocirc\", \"\\u00f4\" );" ); sc.add( "parser.defineEntityReplacementText( \"otilde\", \"\\u00f5\" );" ); sc.add( "parser.defineEntityReplacementText( \"ouml\", \"\\u00f6\" );" ); sc.add( "parser.defineEntityReplacementText( \"divide\", \"\\u00f7\" );" ); sc.add( "parser.defineEntityReplacementText( \"oslash\", \"\\u00f8\" );" ); sc.add( "parser.defineEntityReplacementText( \"ugrave\", \"\\u00f9\" );" ); sc.add( "parser.defineEntityReplacementText( \"uacute\", \"\\u00fa\" );" ); sc.add( "parser.defineEntityReplacementText( \"ucirc\", \"\\u00fb\" );" ); sc.add( "parser.defineEntityReplacementText( \"uuml\", \"\\u00fc\" );" ); sc.add( "parser.defineEntityReplacementText( \"yacute\", \"\\u00fd\" );" ); sc.add( "parser.defineEntityReplacementText( \"thorn\", \"\\u00fe\" );" ); sc.add( "parser.defineEntityReplacementText( \"yuml\", \"\\u00ff\" );" ); sc.add( "" ); sc.add( "// ----------------------------------------------------------------------" ); sc.add( "// Special entities" ); sc.add( "// ----------------------------------------------------------------------" ); sc.add( "" ); // These are required to be handled by the parser by the XML specification // sc.add( "parser.defineEntityReplacementText( \"quot\", \"\\u0022\" );" ); // sc.add( "parser.defineEntityReplacementText( \"amp\", \"\\u0026\" );" ); // sc.add( "parser.defineEntityReplacementText( \"lt\", \"\\u003c\" );" ); // sc.add( "parser.defineEntityReplacementText( \"gt\", \"\\u003e\" );" ); // sc.add( "parser.defineEntityReplacementText( \"apos\", \"\\u0027\" );" ); sc.add( "parser.defineEntityReplacementText( \"OElig\", \"\\u0152\" );" ); sc.add( "parser.defineEntityReplacementText( \"oelig\", \"\\u0153\" );" ); sc.add( "parser.defineEntityReplacementText( \"Scaron\", \"\\u0160\" );" ); sc.add( "parser.defineEntityReplacementText( \"scaron\", \"\\u0161\" );" ); sc.add( "parser.defineEntityReplacementText( \"Yuml\", \"\\u0178\" );" ); sc.add( "parser.defineEntityReplacementText( \"circ\", \"\\u02c6\" );" ); sc.add( "parser.defineEntityReplacementText( \"tilde\", \"\\u02dc\" );" ); sc.add( "parser.defineEntityReplacementText( \"ensp\", \"\\u2002\" );" ); sc.add( "parser.defineEntityReplacementText( \"emsp\", \"\\u2003\" );" ); sc.add( "parser.defineEntityReplacementText( \"thinsp\", \"\\u2009\" );" ); sc.add( "parser.defineEntityReplacementText( \"zwnj\", \"\\u200c\" );" ); sc.add( "parser.defineEntityReplacementText( \"zwj\", \"\\u200d\" );" ); sc.add( "parser.defineEntityReplacementText( \"lrm\", \"\\u200e\" );" ); sc.add( "parser.defineEntityReplacementText( \"rlm\", \"\\u200f\" );" ); sc.add( "parser.defineEntityReplacementText( \"ndash\", \"\\u2013\" );" ); sc.add( "parser.defineEntityReplacementText( \"mdash\", \"\\u2014\" );" ); sc.add( "parser.defineEntityReplacementText( \"lsquo\", \"\\u2018\" );" ); sc.add( "parser.defineEntityReplacementText( \"rsquo\", \"\\u2019\" );" ); sc.add( "parser.defineEntityReplacementText( \"sbquo\", \"\\u201a\" );" ); sc.add( "parser.defineEntityReplacementText( \"ldquo\", \"\\u201c\" );" ); sc.add( "parser.defineEntityReplacementText( \"rdquo\", \"\\u201d\" );" ); sc.add( "parser.defineEntityReplacementText( \"bdquo\", \"\\u201e\" );" ); sc.add( "parser.defineEntityReplacementText( \"dagger\", \"\\u2020\" );" ); sc.add( "parser.defineEntityReplacementText( \"Dagger\", \"\\u2021\" );" ); sc.add( "parser.defineEntityReplacementText( \"permil\", \"\\u2030\" );" ); sc.add( "parser.defineEntityReplacementText( \"lsaquo\", \"\\u2039\" );" ); sc.add( "parser.defineEntityReplacementText( \"rsaquo\", \"\\u203a\" );" ); sc.add( "parser.defineEntityReplacementText( \"euro\", \"\\u20ac\" );" ); sc.add( "" ); sc.add( "// ----------------------------------------------------------------------" ); sc.add( "// Symbol entities" ); sc.add( "// ----------------------------------------------------------------------" ); sc.add( "" ); sc.add( "parser.defineEntityReplacementText( \"fnof\", \"\\u0192\" );" ); sc.add( "parser.defineEntityReplacementText( \"Alpha\", \"\\u0391\" );" ); sc.add( "parser.defineEntityReplacementText( \"Beta\", \"\\u0392\" );" ); sc.add( "parser.defineEntityReplacementText( \"Gamma\", \"\\u0393\" );" ); sc.add( "parser.defineEntityReplacementText( \"Delta\", \"\\u0394\" );" ); sc.add( "parser.defineEntityReplacementText( \"Epsilon\", \"\\u0395\" );" ); sc.add( "parser.defineEntityReplacementText( \"Zeta\", \"\\u0396\" );" ); sc.add( "parser.defineEntityReplacementText( \"Eta\", \"\\u0397\" );" ); sc.add( "parser.defineEntityReplacementText( \"Theta\", \"\\u0398\" );" ); sc.add( "parser.defineEntityReplacementText( \"Iota\", \"\\u0399\" );" ); sc.add( "parser.defineEntityReplacementText( \"Kappa\", \"\\u039a\" );" ); sc.add( "parser.defineEntityReplacementText( \"Lambda\", \"\\u039b\" );" ); sc.add( "parser.defineEntityReplacementText( \"Mu\", \"\\u039c\" );" ); sc.add( "parser.defineEntityReplacementText( \"Nu\", \"\\u039d\" );" ); sc.add( "parser.defineEntityReplacementText( \"Xi\", \"\\u039e\" );" ); sc.add( "parser.defineEntityReplacementText( \"Omicron\", \"\\u039f\" );" ); sc.add( "parser.defineEntityReplacementText( \"Pi\", \"\\u03a0\" );" ); sc.add( "parser.defineEntityReplacementText( \"Rho\", \"\\u03a1\" );" ); sc.add( "parser.defineEntityReplacementText( \"Sigma\", \"\\u03a3\" );" ); sc.add( "parser.defineEntityReplacementText( \"Tau\", \"\\u03a4\" );" ); sc.add( "parser.defineEntityReplacementText( \"Upsilon\", \"\\u03a5\" );" ); sc.add( "parser.defineEntityReplacementText( \"Phi\", \"\\u03a6\" );" ); sc.add( "parser.defineEntityReplacementText( \"Chi\", \"\\u03a7\" );" ); sc.add( "parser.defineEntityReplacementText( \"Psi\", \"\\u03a8\" );" ); sc.add( "parser.defineEntityReplacementText( \"Omega\", \"\\u03a9\" );" ); sc.add( "parser.defineEntityReplacementText( \"alpha\", \"\\u03b1\" );" ); sc.add( "parser.defineEntityReplacementText( \"beta\", \"\\u03b2\" );" ); sc.add( "parser.defineEntityReplacementText( \"gamma\", \"\\u03b3\" );" ); sc.add( "parser.defineEntityReplacementText( \"delta\", \"\\u03b4\" );" ); sc.add( "parser.defineEntityReplacementText( \"epsilon\", \"\\u03b5\" );" ); sc.add( "parser.defineEntityReplacementText( \"zeta\", \"\\u03b6\" );" ); sc.add( "parser.defineEntityReplacementText( \"eta\", \"\\u03b7\" );" ); sc.add( "parser.defineEntityReplacementText( \"theta\", \"\\u03b8\" );" ); sc.add( "parser.defineEntityReplacementText( \"iota\", \"\\u03b9\" );" ); sc.add( "parser.defineEntityReplacementText( \"kappa\", \"\\u03ba\" );" ); sc.add( "parser.defineEntityReplacementText( \"lambda\", \"\\u03bb\" );" ); sc.add( "parser.defineEntityReplacementText( \"mu\", \"\\u03bc\" );" ); sc.add( "parser.defineEntityReplacementText( \"nu\", \"\\u03bd\" );" ); sc.add( "parser.defineEntityReplacementText( \"xi\", \"\\u03be\" );" ); sc.add( "parser.defineEntityReplacementText( \"omicron\", \"\\u03bf\" );" ); sc.add( "parser.defineEntityReplacementText( \"pi\", \"\\u03c0\" );" ); sc.add( "parser.defineEntityReplacementText( \"rho\", \"\\u03c1\" );" ); sc.add( "parser.defineEntityReplacementText( \"sigmaf\", \"\\u03c2\" );" ); sc.add( "parser.defineEntityReplacementText( \"sigma\", \"\\u03c3\" );" ); sc.add( "parser.defineEntityReplacementText( \"tau\", \"\\u03c4\" );" ); sc.add( "parser.defineEntityReplacementText( \"upsilon\", \"\\u03c5\" );" ); sc.add( "parser.defineEntityReplacementText( \"phi\", \"\\u03c6\" );" ); sc.add( "parser.defineEntityReplacementText( \"chi\", \"\\u03c7\" );" ); sc.add( "parser.defineEntityReplacementText( \"psi\", \"\\u03c8\" );" ); sc.add( "parser.defineEntityReplacementText( \"omega\", \"\\u03c9\" );" ); sc.add( "parser.defineEntityReplacementText( \"thetasym\", \"\\u03d1\" );" ); sc.add( "parser.defineEntityReplacementText( \"upsih\", \"\\u03d2\" );" ); sc.add( "parser.defineEntityReplacementText( \"piv\", \"\\u03d6\" );" ); sc.add( "parser.defineEntityReplacementText( \"bull\", \"\\u2022\" );" ); sc.add( "parser.defineEntityReplacementText( \"hellip\", \"\\u2026\" );" ); sc.add( "parser.defineEntityReplacementText( \"prime\", \"\\u2032\" );" ); sc.add( "parser.defineEntityReplacementText( \"Prime\", \"\\u2033\" );" ); sc.add( "parser.defineEntityReplacementText( \"oline\", \"\\u203e\" );" ); sc.add( "parser.defineEntityReplacementText( \"frasl\", \"\\u2044\" );" ); sc.add( "parser.defineEntityReplacementText( \"weierp\", \"\\u2118\" );" ); sc.add( "parser.defineEntityReplacementText( \"image\", \"\\u2111\" );" ); sc.add( "parser.defineEntityReplacementText( \"real\", \"\\u211c\" );" ); sc.add( "parser.defineEntityReplacementText( \"trade\", \"\\u2122\" );" ); sc.add( "parser.defineEntityReplacementText( \"alefsym\", \"\\u2135\" );" ); sc.add( "parser.defineEntityReplacementText( \"larr\", \"\\u2190\" );" ); sc.add( "parser.defineEntityReplacementText( \"uarr\", \"\\u2191\" );" ); sc.add( "parser.defineEntityReplacementText( \"rarr\", \"\\u2192\" );" ); sc.add( "parser.defineEntityReplacementText( \"darr\", \"\\u2193\" );" ); sc.add( "parser.defineEntityReplacementText( \"harr\", \"\\u2194\" );" ); sc.add( "parser.defineEntityReplacementText( \"crarr\", \"\\u21b5\" );" ); sc.add( "parser.defineEntityReplacementText( \"lArr\", \"\\u21d0\" );" ); sc.add( "parser.defineEntityReplacementText( \"uArr\", \"\\u21d1\" );" ); sc.add( "parser.defineEntityReplacementText( \"rArr\", \"\\u21d2\" );" ); sc.add( "parser.defineEntityReplacementText( \"dArr\", \"\\u21d3\" );" ); sc.add( "parser.defineEntityReplacementText( \"hArr\", \"\\u21d4\" );" ); sc.add( "parser.defineEntityReplacementText( \"forall\", \"\\u2200\" );" ); sc.add( "parser.defineEntityReplacementText( \"part\", \"\\u2202\" );" ); sc.add( "parser.defineEntityReplacementText( \"exist\", \"\\u2203\" );" ); sc.add( "parser.defineEntityReplacementText( \"empty\", \"\\u2205\" );" ); sc.add( "parser.defineEntityReplacementText( \"nabla\", \"\\u2207\" );" ); sc.add( "parser.defineEntityReplacementText( \"isin\", \"\\u2208\" );" ); sc.add( "parser.defineEntityReplacementText( \"notin\", \"\\u2209\" );" ); sc.add( "parser.defineEntityReplacementText( \"ni\", \"\\u220b\" );" ); sc.add( "parser.defineEntityReplacementText( \"prod\", \"\\u220f\" );" ); sc.add( "parser.defineEntityReplacementText( \"sum\", \"\\u2211\" );" ); sc.add( "parser.defineEntityReplacementText( \"minus\", \"\\u2212\" );" ); sc.add( "parser.defineEntityReplacementText( \"lowast\", \"\\u2217\" );" ); sc.add( "parser.defineEntityReplacementText( \"radic\", \"\\u221a\" );" ); sc.add( "parser.defineEntityReplacementText( \"prop\", \"\\u221d\" );" ); sc.add( "parser.defineEntityReplacementText( \"infin\", \"\\u221e\" );" ); sc.add( "parser.defineEntityReplacementText( \"ang\", \"\\u2220\" );" ); sc.add( "parser.defineEntityReplacementText( \"and\", \"\\u2227\" );" ); sc.add( "parser.defineEntityReplacementText( \"or\", \"\\u2228\" );" ); sc.add( "parser.defineEntityReplacementText( \"cap\", \"\\u2229\" );" ); sc.add( "parser.defineEntityReplacementText( \"cup\", \"\\u222a\" );" ); sc.add( "parser.defineEntityReplacementText( \"int\", \"\\u222b\" );" ); sc.add( "parser.defineEntityReplacementText( \"there4\", \"\\u2234\" );" ); sc.add( "parser.defineEntityReplacementText( \"sim\", \"\\u223c\" );" ); sc.add( "parser.defineEntityReplacementText( \"cong\", \"\\u2245\" );" ); sc.add( "parser.defineEntityReplacementText( \"asymp\", \"\\u2248\" );" ); sc.add( "parser.defineEntityReplacementText( \"ne\", \"\\u2260\" );" ); sc.add( "parser.defineEntityReplacementText( \"equiv\", \"\\u2261\" );" ); sc.add( "parser.defineEntityReplacementText( \"le\", \"\\u2264\" );" ); sc.add( "parser.defineEntityReplacementText( \"ge\", \"\\u2265\" );" ); sc.add( "parser.defineEntityReplacementText( \"sub\", \"\\u2282\" );" ); sc.add( "parser.defineEntityReplacementText( \"sup\", \"\\u2283\" );" ); sc.add( "parser.defineEntityReplacementText( \"nsub\", \"\\u2284\" );" ); sc.add( "parser.defineEntityReplacementText( \"sube\", \"\\u2286\" );" ); sc.add( "parser.defineEntityReplacementText( \"supe\", \"\\u2287\" );" ); sc.add( "parser.defineEntityReplacementText( \"oplus\", \"\\u2295\" );" ); sc.add( "parser.defineEntityReplacementText( \"otimes\", \"\\u2297\" );" ); sc.add( "parser.defineEntityReplacementText( \"perp\", \"\\u22a5\" );" ); sc.add( "parser.defineEntityReplacementText( \"sdot\", \"\\u22c5\" );" ); sc.add( "parser.defineEntityReplacementText( \"lceil\", \"\\u2308\" );" ); sc.add( "parser.defineEntityReplacementText( \"rceil\", \"\\u2309\" );" ); sc.add( "parser.defineEntityReplacementText( \"lfloor\", \"\\u230a\" );" ); sc.add( "parser.defineEntityReplacementText( \"rfloor\", \"\\u230b\" );" ); sc.add( "parser.defineEntityReplacementText( \"lang\", \"\\u2329\" );" ); sc.add( "parser.defineEntityReplacementText( \"rang\", \"\\u232a\" );" ); sc.add( "parser.defineEntityReplacementText( \"loz\", \"\\u25ca\" );" ); sc.add( "parser.defineEntityReplacementText( \"spades\", \"\\u2660\" );" ); sc.add( "parser.defineEntityReplacementText( \"clubs\", \"\\u2663\" );" ); sc.add( "parser.defineEntityReplacementText( \"hearts\", \"\\u2665\" );" ); sc.add( "parser.defineEntityReplacementText( \"diams\", \"\\u2666\" );" ); sc.add( "" ); sc.unindent(); sc.add( "}" ); } private void writeHelpers( JClass jClass ) { JMethod method = new JMethod( "getTrimmedValue", new JClass( "String" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "s = s.trim();" ); sc.add( "}" ); sc.add( "return s;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getRequiredAttributeValue", new JClass( "String" ), null ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); sc = method.getSourceCode(); sc.add( "if ( s == null )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Missing required value for attribute '\" + attribute + \"'\", parser, null );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return s;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getBooleanValue", JType.BOOLEAN, null ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); sc = method.getSourceCode(); sc.add( "return getBooleanValue( s, attribute, parser, null );" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getBooleanValue", JType.BOOLEAN, null ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addParameter( new JParameter( new JClass( "String" ), "defaultValue" ) ); sc = method.getSourceCode(); sc.add( "if ( s != null && s.length() != 0 )" ); sc.add( "{" ); sc.addIndented( "return Boolean.valueOf( s ).booleanValue();" ); sc.add( "}" ); sc.add( "if ( defaultValue != null )" ); sc.add( "{" ); sc.addIndented( "return Boolean.valueOf( defaultValue ).booleanValue();" ); sc.add( "}" ); sc.add( "return false;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getCharacterValue", JType.CHAR, null ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.addIndented( "return s.charAt( 0 );" ); sc.add( "}" ); sc.add( "return 0;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getIntegerValue", JType.INT, "Integer.valueOf( s ).intValue()", "an integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getShortValue", JType.SHORT, "Short.valueOf( s ).shortValue()", "a short integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getByteValue", JType.BYTE, "Byte.valueOf( s ).byteValue()", "a byte" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getLongValue", JType.LONG, "Long.valueOf( s ).longValue()", "a long integer" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getFloatValue", JType.FLOAT, "Float.valueOf( s ).floatValue()", "a floating point number" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = convertNumericalType( "getDoubleValue", JType.DOUBLE, "Double.valueOf( s ).doubleValue()", "a floating point number" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getDateValue", new JClass( "java.util.Date" ), null ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addException( new JClass( "XmlPullParserException" ) ); sc = method.getSourceCode(); sc.add( "return getDateValue( s, attribute, null, parser );" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "getDateValue", new JClass( "java.util.Date" ), null ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "String" ), "dateFormat" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addException( new JClass( "XmlPullParserException" ) ); writeDateParsingHelper( method.getSourceCode(), "new XmlPullParserException( e.getMessage() )" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "checkFieldWithDuplicate", JType.BOOLEAN, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); method.addParameter( new JParameter( new JClass( "String" ), "alias" ) ); method.addParameter( new JParameter( new JClass( "java.util.Set" ), "parsed" ) ); method.addException( new JClass( "XmlPullParserException" ) ); sc = method.getSourceCode(); sc.add( "if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )" ); sc.add( "{" ); sc.addIndented( "return false;" ); sc.add( "}" ); sc.add( "if ( parsed.contains( tagName ) )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Duplicated tag: '\" + tagName + \"'\", parser, null );" ); sc.add( "}" ); sc.add( "parsed.add( tagName );" ); sc.add( "return true;" ); jClass.addMethod( method ); } private JMethod convertNumericalType( String methodName, JType returnType, String expression, String typeDesc ) { JMethod method = new JMethod( methodName, returnType, null ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "String" ), "s" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); JSourceCode sc = method.getSourceCode(); sc.add( "if ( s != null )" ); sc.add( "{" ); sc.indent(); sc.add( "try" ); sc.add( "{" ); sc.addIndented( "return " + expression + ";" ); sc.add( "}" ); sc.add( "catch ( NumberFormatException e )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Unable to parse element '\" + attribute + \"', must be " + typeDesc + "\", parser, null );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return 0;" ); return method; } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/AbstractXpp3Generator.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/Abstr0000644000175000017500000000270411127674774032605 0ustar mkochmkochpackage org.codehaus.modello.plugin.xpp3; /* * Copyright (c) 2004, Jason van Zyl * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.plugins.xml.AbstractXmlJavaGenerator; /** * @author Trygve Laugstøl * @version $Id: AbstractXpp3Generator.java 1095 2009-01-03 14:45:16Z hboutemy $ */ public abstract class AbstractXpp3Generator extends AbstractXmlJavaGenerator { } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/Xpp3WriterGenerator.javamodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/Xpp3W0000644000175000017500000004156711243356043032506 0ustar mkochmkochpackage org.codehaus.modello.plugin.xpp3; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JField; import org.codehaus.modello.plugin.java.javasource.JMethod; import org.codehaus.modello.plugin.java.javasource.JParameter; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugin.java.javasource.JSourceWriter; import org.codehaus.modello.plugin.java.metadata.JavaClassMetadata; import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; import org.codehaus.modello.plugin.model.ModelClassMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlModelMetadata; import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: Xpp3WriterGenerator.java 1311 2009-08-20 23:28:35Z hboutemy $ */ public class Xpp3WriterGenerator extends AbstractXpp3Generator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateXpp3Writer(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating XPP3 Writer.", ex ); } } private void generateXpp3Writer() throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.xpp3"; String marshallerName = getFileName( "Xpp3Writer" ); JSourceWriter sourceWriter = newJSourceWriter( packageName, marshallerName ); JClass jClass = new JClass( packageName + '.' + marshallerName ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); jClass.addImport( "org.codehaus.plexus.util.xml.pull.XmlSerializer" ); jClass.addImport( "org.codehaus.plexus.util.xml.pull.MXSerializer" ); jClass.addImport( "java.io.Writer" ); jClass.addImport( "java.text.DateFormat" ); jClass.addImport( "java.util.Iterator" ); jClass.addImport( "java.util.Locale" ); JField namespaceField = new JField( new JClass( "String" ), "NAMESPACE" ); namespaceField.getModifiers().setFinal( true ); namespaceField.getModifiers().setStatic( true ); namespaceField.setInitString( "null" ); jClass.addField( namespaceField ); addModelImports( jClass, null ); String root = objectModel.getRoot( getGeneratedVersion() ); ModelClass rootClass = objectModel.getClass( root, getGeneratedVersion() ); String rootElement = resolveTagName( rootClass ); // Write the write method which will do the marshalling. JMethod marshall = new JMethod( "write" ); String rootElementParameterName = uncapitalise( root ); marshall.addParameter( new JParameter( new JClass( "Writer" ), "writer" ) ); marshall.addParameter( new JParameter( new JClass( root ), rootElementParameterName ) ); marshall.addException( new JClass( "java.io.IOException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "XmlSerializer serializer = new MXSerializer();" ); sc.add( "serializer.setProperty( \"http://xmlpull.org/v1/doc/properties.html#serializer-indentation\", \" \" );" ); sc.add( "serializer.setProperty( \"http://xmlpull.org/v1/doc/properties.html#serializer-line-separator\", \"\\n\" );" ); sc.add( "serializer.setOutput( writer );" ); sc.add( "serializer.startDocument( " + rootElementParameterName + ".getModelEncoding(), null );" ); sc.add( "write" + root + "( " + rootElementParameterName + ", \"" + rootElement + "\", serializer );" ); sc.add( "serializer.endDocument();" ); jClass.addMethod( marshall ); writeAllClasses( objectModel, jClass ); jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClasses( Model objectModel, JClass jClass ) throws ModelloException { for ( Iterator i = objectModel.getClasses( getGeneratedVersion() ).iterator(); i.hasNext(); ) { ModelClass clazz = (ModelClass) i.next(); JavaClassMetadata javaClassMetadata = (JavaClassMetadata) clazz.getMetadata( JavaClassMetadata.ID ); if ( !javaClassMetadata.isEnabled() ) { // Skip import of those classes that are not enabled for the java plugin. continue; } writeClass( clazz, jClass ); } } private void writeClass( ModelClass modelClass, JClass jClass ) throws ModelloException { String className = modelClass.getName(); String uncapClassName = uncapitalise( className ); JMethod marshall = new JMethod( "write" + className ); marshall.addParameter( new JParameter( new JClass( className ), uncapClassName ) ); marshall.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); marshall.addParameter( new JParameter( new JClass( "XmlSerializer" ), "serializer" ) ); marshall.addException( new JClass( "java.io.IOException" ) ); marshall.getModifiers().makePrivate(); JSourceCode sc = marshall.getSourceCode(); sc.add( "if ( " + uncapClassName + " != null )" ); sc.add( "{" ); sc.indent(); ModelClassMetadata classMetadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); String namespace = null; XmlModelMetadata xmlModelMetadata = (XmlModelMetadata) modelClass.getModel().getMetadata( XmlModelMetadata.ID ); // add namespace information for root element only if ( classMetadata.isRootElement() && ( xmlModelMetadata.getNamespace() != null ) ) { namespace = xmlModelMetadata.getNamespace( getGeneratedVersion() ); sc.add( "serializer.setPrefix( \"\", \"" + namespace + "\" );" ); } if ( ( namespace != null ) && ( xmlModelMetadata.getSchemaLocation() != null ) ) { String url = xmlModelMetadata.getSchemaLocation( getGeneratedVersion() ); sc.add( "serializer.setPrefix( \"xsi\", \"http://www.w3.org/2001/XMLSchema-instance\" );" ); sc.add( "serializer.startTag( NAMESPACE, tagName );" ); sc.add( "serializer.attribute( \"\", \"xsi:schemaLocation\", \"" + namespace + " " + url + "\" );" ); } else { sc.add( "serializer.startTag( NAMESPACE, tagName );" ); } ModelField contentField = null; String contentValue = null; List modelFields = modelClass.getAllFields( getGeneratedVersion(), true ); modelFields = getNonTransientFields( modelFields ); // XML attributes for ( Iterator i = modelFields.iterator(); i.hasNext(); ) { ModelField field = (ModelField) i.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) field.getMetadata( JavaFieldMetadata.ID ); String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String type = field.getType(); String value = uncapClassName + "." + getPrefix( javaFieldMetadata ) + capitalise( field.getName() ) + "()"; if ( xmlFieldMetadata.isContent() ) { contentField = field; contentValue = value; continue; } if ( xmlFieldMetadata.isAttribute() ) { sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.addIndented( "serializer.attribute( NAMESPACE, \"" + fieldTagName + "\", " + getValue( field.getType(), value, xmlFieldMetadata ) + " );" ); sc.add( "}" ); } } if ( contentField != null ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) contentField.getMetadata( XmlFieldMetadata.ID ); sc.add( "serializer.text( " + getValue( contentField.getType(), contentValue, xmlFieldMetadata ) + " );" ); } // XML tags for ( Iterator fieldIterator = modelFields.iterator(); fieldIterator.hasNext(); ) { ModelField field = (ModelField) fieldIterator.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isContent() ) { // skip field with type Content continue; } JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) field.getMetadata( JavaFieldMetadata.ID ); String fieldTagName = resolveTagName( field, xmlFieldMetadata ); String type = field.getType(); String value = uncapClassName + "." + getPrefix( javaFieldMetadata ) + capitalise( field.getName() ) + "()"; if ( xmlFieldMetadata.isAttribute() ) { continue; } if ( field instanceof ModelAssociation ) { ModelAssociation association = (ModelAssociation) field; String associationName = association.getName(); if ( association.isOneMultiplicity() ) { sc.add( getValueChecker( type, value, association ) ); sc.add( "{" ); sc.addIndented( "write" + association.getTo() + "( (" + association.getTo() + ") " + value + ", \"" + fieldTagName + "\", serializer );" ); sc.add( "}" ); } else { //MANY_MULTIPLICITY XmlAssociationMetadata xmlAssociationMetadata = (XmlAssociationMetadata) association.getAssociationMetadata( XmlAssociationMetadata.ID ); String valuesTagName = resolveTagName( fieldTagName, xmlAssociationMetadata ); type = association.getType(); String toType = association.getTo(); boolean wrappedItems = xmlAssociationMetadata.isWrappedItems(); if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) { sc.add( getValueChecker( type, value, association ) ); sc.add( "{" ); sc.indent(); if ( wrappedItems ) { sc.add( "serializer.startTag( NAMESPACE, " + "\"" + fieldTagName + "\" );" ); } sc.add( "for ( Iterator iter = " + value + ".iterator(); iter.hasNext(); )" ); sc.add( "{" ); sc.indent(); if ( isClassInModel( association.getTo(), modelClass.getModel() ) ) { sc.add( toType + " o = (" + toType + ") iter.next();" ); sc.add( "write" + toType + "( o, \"" + valuesTagName + "\", serializer );" ); } else { sc.add( toType + " " + singular( uncapitalise( field.getName() ) ) + " = (" + toType + ") iter.next();" ); sc.add( "serializer.startTag( NAMESPACE, " + "\"" + valuesTagName + "\" ).text( " + singular( uncapitalise( field.getName() ) ) + " ).endTag( NAMESPACE, " + "\"" + valuesTagName + "\" );" ); } sc.unindent(); sc.add( "}" ); if ( wrappedItems ) { sc.add( "serializer.endTag( NAMESPACE, " + "\"" + fieldTagName + "\" );" ); } sc.unindent(); sc.add( "}" ); } else { //Map or Properties sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); sc.indent(); if ( wrappedItems ) { sc.add( "serializer.startTag( NAMESPACE, " + "\"" + fieldTagName + "\" );" ); } sc.add( "for ( Iterator iter = " + value + ".keySet().iterator(); iter.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = (String) iter.next();" ); sc.add( "String value = (String) " + value + ".get( key );" ); if ( xmlAssociationMetadata.isMapExplode() ) { sc.add( "serializer.startTag( NAMESPACE, \"" + singular( associationName ) + "\" );" ); sc.add( "serializer.startTag( NAMESPACE, \"key\" ).text( key ).endTag( NAMESPACE, \"key\" );" ); sc.add( "serializer.startTag( NAMESPACE, \"value\" ).text( value ).endTag( NAMESPACE, \"value\" );" ); sc.add( "serializer.endTag( NAMESPACE, \"" + singular( associationName ) + "\" );" ); } else { sc.add( "serializer.startTag( NAMESPACE, \"\" + key + \"\" ).text( value ).endTag( NAMESPACE, \"\" + key + \"\" );" ); } sc.unindent(); sc.add( "}" ); if ( wrappedItems ) { sc.add( "serializer.endTag( NAMESPACE, " + "\"" + fieldTagName + "\" );" ); } sc.unindent(); sc.add( "}" ); } } } else { sc.add( getValueChecker( type, value, field ) ); sc.add( "{" ); if ( "DOM".equals( field.getType() ) ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); sc.addIndented( "((Xpp3Dom) " + value + ").writeToSerializer( NAMESPACE, serializer );" ); } else { sc.addIndented( "serializer.startTag( NAMESPACE, " + "\"" + fieldTagName + "\" ).text( " + getValue( field.getType(), value, xmlFieldMetadata ) + " ).endTag( NAMESPACE, " + "\"" + fieldTagName + "\" );" ); } sc.add( "}" ); } } sc.add( "serializer.endTag( NAMESPACE, tagName );" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( marshall ); } } modello-1.1/modello-plugins/modello-plugin-xpp3/src/main/resources/0000755000175000017500000000000011260056264024452 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/resources/META-INF/0000755000175000017500000000000011260056264025612 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056264027132 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xpp3/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000101410647207577032052 0ustar mkochmkoch org.codehaus.modello.plugin.ModelloGenerator xpp3-reader org.codehaus.modello.plugin.xpp3.Xpp3ReaderGenerator org.codehaus.modello.plugin.ModelloGenerator xpp3-writer org.codehaus.modello.plugin.xpp3.Xpp3WriterGenerator modello-1.1/modello-plugins/src/0000755000175000017500000000000011260056267015700 5ustar mkochmkochmodello-1.1/modello-plugins/src/site/0000755000175000017500000000000011260056267016644 5ustar mkochmkochmodello-1.1/modello-plugins/src/site/site.xml0000644000175000017500000000026111112331565020322 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-xml/0000755000175000017500000000000011260056266020635 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/pom.xml0000644000175000017500000000163011243557055022155 0ustar mkochmkoch modello-plugins org.codehaus.modello 1.1 4.0.0 modello-plugin-xml Modello XML Plugin Modello XML Plugin contains shared code for every plugins working on XML representation of the model. org.codehaus.modello modello-plugin-java true modello-1.1/modello-plugins/modello-plugin-xml/src/0000755000175000017500000000000011260056266021424 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/0000755000175000017500000000000011260056266022403 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/0000755000175000017500000000000011260056266023324 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/org/0000755000175000017500000000000011260056266024113 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/0000755000175000017500000000000011260056266025706 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056266027341 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/plugins/0000755000175000017500000000000011260056266031022 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/plugins/xml/0000755000175000017500000000000011260056266031622 5ustar mkochmkoch././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/plugins/xml/XmlModelloPluginTest.javamodello-1.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/plugins/xml/XmlMod0000644000175000017500000000765211127737073032763 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.metadata.MetadataPlugin; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @author Trygve Laugstøl * @version $Id: XmlModelloPluginTest.java 1098 2009-01-03 19:36:27Z hboutemy $ */ public class XmlModelloPluginTest extends PlexusTestCase { public void testConfiguration() throws Exception { Object object = lookup( MetadataPlugin.ROLE, "xml" ); assertNotNull( object ); assertTrue( object instanceof XmlMetadataPlugin ); } public void testXmlPlugin() throws Exception { ModelloCore modello = (ModelloCore) container.lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/model.mdo" ) ) ); List classes = model.getClasses( new Version( "4.0.0" ) ); assertEquals( 2, classes.size() ); ModelClass clazz = (ModelClass) classes.get( 0 ); assertEquals( "Model", clazz.getName() ); assertEquals( 3, clazz.getFields( new Version( "4.0.0" ) ).size() ); ModelField extend = clazz.getField( "extend", new Version( "4.0.0" ) ); assertTrue( extend.hasMetadata( XmlFieldMetadata.ID ) ); XmlFieldMetadata xml = (XmlFieldMetadata) extend.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertFalse( xml.isAttribute() ); extend = clazz.getField( "extend", new Version( "4.1.0" ) ); assertTrue( extend.hasMetadata( XmlFieldMetadata.ID ) ); xml = (XmlFieldMetadata) extend.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertTrue( xml.isAttribute() ); ModelField parent = clazz.getField( "parent", new Version( "4.0.0" ) ); try { parent.getMetadata( "foo" ); fail( "Expected ModelloException" ); } catch( ModelloRuntimeException ex ) { // expected } ModelField builder = clazz.getField( "builder", new Version( "4.0.0" ) ); assertTrue( builder.hasMetadata( XmlFieldMetadata.ID ) ); xml = (XmlFieldMetadata) builder.getMetadata( XmlFieldMetadata.ID ); assertNotNull( xml ); assertEquals( "build", xml.getTagName() ); assertTrue( xml.isTrim() ); } } modello-1.1/modello-plugins/modello-plugin-xml/src/test/resources/0000755000175000017500000000000011260056266024415 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/test/resources/model.mdo0000644000175000017500000000363610753704633026232 0ustar mkochmkoch maven Maven Maven's model for Java project. package org.apache.maven.model Model 3.0.0+ extend 3.0.0/4.0.0 The location of the parent project, if one exists. Values from the parent project will be the default for this project if they are left unspecified. The path may be absolute, or relative to the current project.xml file. String extend 4.1.0+ The location of the parent project, if one exists. Values from the parent project will be the default for this project if they are left unspecified. The path may be absolute, or relative to the current project.xml file. String parent 4.0.0 Specified which project to extend. Parent builder 4.0.0 Specified the build part. Parent Parent 3.0.0+ modello-1.1/modello-plugins/modello-plugin-xml/src/site/0000755000175000017500000000000011260056266022370 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/site/site.xml0000644000175000017500000000022511112331565024047 0ustar mkochmkoch Modello modello-1.1/modello-plugins/modello-plugin-xml/src/main/0000755000175000017500000000000011260056266022350 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/0000755000175000017500000000000011260056266023271 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/0000755000175000017500000000000011260056266024060 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/0000755000175000017500000000000011260056266025653 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056266027306 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/0000755000175000017500000000000011260056266030767 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/0000755000175000017500000000000011260056266031567 5ustar mkochmkoch././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/XmlModelHelpers.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/XmlMod0000644000175000017500000001316211223730002032677 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.AbstractModelloGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlClassMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * Helper methods to deal with XML representation of the model. * * @author Hervé Boutemy * @version $Id: XmlModelHelpers.java 1274 2009-07-04 19:39:46Z hboutemy $ */ class XmlModelHelpers { /** * Resolve XML tag name for a class. Note: only root class needs such a resolution. * * @param modelClass the model class * @return the XML tag name for the class */ static String resolveTagName( ModelClass modelClass ) { XmlClassMetadata xmlClassMetadata = (XmlClassMetadata) modelClass.getMetadata( XmlClassMetadata.ID ); String tagName; if ( ( xmlClassMetadata == null ) || ( xmlClassMetadata.getTagName() == null ) ) { tagName = AbstractModelloGenerator.uncapitalise( modelClass.getName() ); } else { // tag name is overridden by xml.tagName attribute tagName = xmlClassMetadata.getTagName(); } return tagName; } /** * Resolve XML tag name for a field. * * @param modelField the model field * @param xmlFieldMetadata the XML metadata of the field * @return the XML tag name for the field */ static String resolveTagName( ModelField modelField, XmlFieldMetadata xmlFieldMetadata ) { String tagName; if ( ( xmlFieldMetadata == null ) || ( xmlFieldMetadata.getTagName() == null ) ) { tagName = modelField.getName(); } else { // tag name is overridden by xml.tagName attribute tagName = xmlFieldMetadata.getTagName(); } return tagName; } /** * Resolve XML tag name for an item in an association with many multiplicity. * * @param fieldTagName the XML tag name of the field containing the association * @param xmlAssociationMetadata the XML metadata of the association * @return the XML tag name for items */ static String resolveTagName( String fieldTagName, XmlAssociationMetadata xmlAssociationMetadata ) { String tagName; if ( ( xmlAssociationMetadata == null ) || ( xmlAssociationMetadata.getTagName() == null ) ) { tagName = AbstractModelloGenerator.singular( fieldTagName ); } else { // tag name is overridden by xml.tagName attribute tagName = xmlAssociationMetadata.getTagName(); } return tagName; } /** * Get the field which type is Content if any. * * @param modelFields the fields to check * @return the field, or null if no field is Content */ static ModelField getContentField( List/**/ modelFields ) { if ( modelFields == null ) { return null; } for ( Iterator j = modelFields.iterator(); j.hasNext(); ) { ModelField field = (ModelField) j.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isContent() ) { return field; } } return null; } /** * Gets all fields that are not marked as transient. * * @param modelFields The collection of model fields from which to extract the non-transient fields, must not be * null. * @return The list of non-transient fields, can be empty but never null. */ static List getNonTransientFields( List/**/ modelFields ) { List nonTransientFields = new ArrayList(); for ( Iterator it = modelFields.iterator(); it.hasNext(); ) { ModelField field = (ModelField) it.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( !xmlFieldMetadata.isTransient() ) { nonTransientFields.add( field ); } } return nonTransientFields; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadata/modello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metada0000755000175000017500000000000011260056266032743 5ustar mkochmkoch././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadata/XmlModelMetadata.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metada0000644000175000017500000000507611127742507032757 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.Version; import org.codehaus.plexus.util.StringUtils; /** * @author Trygve Laugstøl * @version $Id: XmlModelMetadata.java 1101 2009-01-03 20:06:31Z hboutemy $ */ public class XmlModelMetadata implements ModelMetadata { public static final String ID = XmlModelMetadata.class.getName(); private String namespace; private String schemaLocation; public String getNamespace() { return namespace; } public void setNamespace( String namespace ) { this.namespace = namespace; } public String getSchemaLocation() { return schemaLocation; } public void setSchemaLocation( String schemaLocation ) { this.schemaLocation = schemaLocation; } public String getNamespace( Version version ) { String namespace = this.namespace; if ( version != null ) { namespace = StringUtils.replace( namespace, "${version}", version.toString() ); } return namespace; } public String getSchemaLocation( Version version ) { String schemaLocation = this.schemaLocation; if ( version != null ) { schemaLocation = StringUtils.replace( schemaLocation, "${version}", version.toString() ); } return schemaLocation; } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadata/XmlClassMetadata.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metada0000644000175000017500000000324411127737073032754 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.ClassMetadata; /** * @author Trygve Laugstøl * @version $Id: XmlClassMetadata.java 1098 2009-01-03 19:36:27Z hboutemy $ */ public class XmlClassMetadata implements ClassMetadata { public static final String ID = XmlClassMetadata.class.getName(); private String tagName; public String getTagName() { return tagName; } public void setTagName( String tagName ) { this.tagName = tagName; } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadata/XmlFieldMetadata.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metada0000644000175000017500000000562011223730002032732 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.FieldMetadata; /** * @author Trygve Laugstøl * @version $Id: XmlFieldMetadata.java 1274 2009-07-04 19:39:46Z hboutemy $ */ public class XmlFieldMetadata implements FieldMetadata { public final static String ID = XmlFieldMetadata.class.getName(); private boolean attribute; private boolean content; private String tagName; private boolean trim = true; private String format; private boolean transientField; public String getFormat() { return format; } public void setFormat( String format ) { this.format = format; } public boolean isTrim() { return trim; } public void setTrim( boolean trim ) { this.trim = trim; } /** * @return Returns the attribute. */ public boolean isAttribute() { return attribute; } /** * @param attribute The attribute to set. */ public void setAttribute( boolean attribute ) { this.attribute = attribute; } public boolean isContent() { return content; } public void setContent( boolean content ) { this.content = content; } /** * @return Returns the tag name or the attribute name if it's an attribute. */ public String getTagName() { return tagName; } /** * @param tagName The tag or attribute name to set. */ public void setTagName( String tagName ) { this.tagName = tagName; } public boolean isTransient() { return transientField; } public void setTransient( boolean transientField ) { this.transientField = transientField; } } ././@LongLink0000000000000000000000000000020300000000000011560 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadata/XmlAssociationMetadata.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metada0000644000175000017500000000664111137073653032756 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AssociationMetadata; /** * @author Trygve Laugstøl * @version $Id: XmlAssociationMetadata.java 1163 2009-01-25 14:31:07Z hboutemy $ */ public class XmlAssociationMetadata implements AssociationMetadata { public static final String ID = XmlAssociationMetadata.class.getName(); public static final String EXPLODE_MODE = "explode"; public static final String INLINE_MODE = "inline"; public static final String ITEMS_STYLE_FLAT = "flat"; public static final String ITEMS_STYLE_WRAPPED = "wrapped"; private String tagName; private String itemsStyle = ITEMS_STYLE_WRAPPED; private String mapStyle = INLINE_MODE; private boolean reference; public String getTagName() { return tagName; } public void setTagName( String tagName ) { this.tagName = tagName; } public String getItemsStyle() { return itemsStyle; } public void setItemsStyle( String itemsStyle ) { if ( ITEMS_STYLE_FLAT.equals( itemsStyle ) || ITEMS_STYLE_WRAPPED.equals( itemsStyle ) ) { this.itemsStyle = itemsStyle; } else { // default this.itemsStyle = ITEMS_STYLE_WRAPPED; } } public boolean isFlatItems() { return ITEMS_STYLE_FLAT.equals( itemsStyle ); } public boolean isWrappedItems() { return ITEMS_STYLE_WRAPPED.equals( itemsStyle ); } /** * @return Returns the map style. */ public String getMapStyle() { return mapStyle; } /** * @param mapStyle The map style (inline or explode). */ public void setMapStyle( String mapStyle ) { if ( mapStyle == null ) { this.mapStyle = INLINE_MODE; } else { this.mapStyle = mapStyle; } } public boolean isMapInline() { return INLINE_MODE.equals( mapStyle ); } public boolean isMapExplode() { return EXPLODE_MODE.equals( mapStyle ); } public boolean isReference() { return reference; } public void setReference( boolean reference ) { this.reference = reference; } } ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadata/XmlMetadataPlugin.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metada0000644000175000017500000001145511223730002032735 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AbstractMetadataPlugin; import org.codehaus.modello.metadata.AssociationMetadata; import org.codehaus.modello.metadata.ClassMetadata; import org.codehaus.modello.metadata.FieldMetadata; import org.codehaus.modello.metadata.MetadataPlugin; import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import java.util.Collections; import java.util.Map; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: XmlMetadataPlugin.java 1274 2009-07-04 19:39:46Z hboutemy $ */ public class XmlMetadataPlugin extends AbstractMetadataPlugin implements MetadataPlugin { public static final String XML_ATTRIBUTE = "xml.attribute"; static final String XML_CONTENT = "xml._content_"; // not published in Modello's model yet public static final String XML_FORMAT = "xml.format"; public static final String XML_ITEMS_STYLE = "xml.itemsStyle"; public static final String XML_MAP_STYLE = "xml.mapStyle"; public static final String XML_NAMESPACE = "xml.namespace"; public static final String XML_REFERENCE = "xml.reference"; public static final String XML_SCHEMA_LOCATION = "xml.schemaLocation"; public static final String XML_TAG_NAME = "xml.tagName"; public static final String XML_TRIM = "xml.trim"; public static final String XML_TRANSIENT = "xml.transient"; // ---------------------------------------------------------------------- // Map to Metadata // ---------------------------------------------------------------------- public ModelMetadata getModelMetadata( Model model, Map data ) { XmlModelMetadata metadata = new XmlModelMetadata(); metadata.setNamespace( getString( data, XML_NAMESPACE ) ); metadata.setSchemaLocation( getString( data, XML_SCHEMA_LOCATION ) ); return metadata; } public ClassMetadata getClassMetadata( ModelClass clazz, Map data ) { XmlClassMetadata metadata = new XmlClassMetadata(); metadata.setTagName( getString( data, XML_TAG_NAME ) ); return metadata; } public FieldMetadata getFieldMetadata( ModelField field, Map data ) { XmlFieldMetadata metadata = new XmlFieldMetadata(); metadata.setAttribute( getBoolean( data, XML_ATTRIBUTE, false ) ); metadata.setContent( getBoolean( data, XML_CONTENT, false ) ); metadata.setTrim( getBoolean( data, XML_TRIM, true ) ); metadata.setTagName( getString( data, XML_TAG_NAME ) ); metadata.setFormat( getString( data, XML_FORMAT ) ); metadata.setTransient( getBoolean( data, XML_TRANSIENT, false ) ); return metadata; } public AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) { XmlAssociationMetadata metadata = new XmlAssociationMetadata(); metadata.setTagName( getString( data, XML_TAG_NAME ) ); metadata.setItemsStyle( getString( data, XML_ITEMS_STYLE ) ); metadata.setMapStyle( getString( data, XML_MAP_STYLE ) ); metadata.setReference( getBoolean( data, XML_REFERENCE, false ) ); return metadata; } // ---------------------------------------------------------------------- // Metadata to Map // ---------------------------------------------------------------------- public Map getFieldMap( ModelField field, FieldMetadata metadata ) { return Collections.EMPTY_MAP; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/AbstractXmlGenerator.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/Abstra0000644000175000017500000001266311223665473032743 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.AbstractModelloGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; /** * Abstract class for plugins working on XML representation of the model, without having any need to generate * Java code. * * @author Hervé Boutemy * @version $Id: AbstractXmlGenerator.java 1273 2009-07-04 14:46:19Z bentmann $ */ public abstract class AbstractXmlGenerator extends AbstractModelloGenerator { protected void initHeader( XMLWriter w ) { XmlWriterUtil.writeComment( w, getHeader() ); } /** * Resolve XML tag name for a class. Note: only root class needs such a resolution. * * @param modelClass the model class * @return the XML tag name for the class */ protected String resolveTagName( ModelClass modelClass ) { return XmlModelHelpers.resolveTagName( modelClass ); } /** * Resolve XML tag name for a field. * * @param modelField the model field * @param xmlFieldMetadata the XML metadata of the field * @return the XML tag name for the field */ protected String resolveTagName( ModelField modelField, XmlFieldMetadata xmlFieldMetadata ) { return XmlModelHelpers.resolveTagName( modelField, xmlFieldMetadata ); } /** * Resolve XML tag name for an item in an association with many multiplicity. * * @param fieldTagName the XML tag name of the field containing the association * @param xmlAssociationMetadata the XML metadata of the association * @return the XML tag name for items */ protected String resolveTagName( String fieldTagName, XmlAssociationMetadata xmlAssociationMetadata ) { return XmlModelHelpers.resolveTagName( fieldTagName, xmlAssociationMetadata ); } /** * Return the child attribute fields of this class. * @param modelClass current class * @return the list of attribute fields of this class */ protected List getAttributeFieldsForClass( ModelClass modelClass ) { List attributeFields = new ArrayList(); while ( modelClass != null ) { List allFields = modelClass.getFields( getGeneratedVersion() ); for (Iterator allFieldsIt = allFields.iterator(); allFieldsIt.hasNext(); ) { ModelField field = (ModelField) allFieldsIt.next(); XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isAttribute() ) { attributeFields.add( field ); } } String superClass = modelClass.getSuperClass(); if ( superClass != null ) { modelClass = getModel().getClass( superClass, getGeneratedVersion() ); } else { modelClass = null; } } return attributeFields; } protected boolean hasContentField( List/**/ modelFields ) { return ( getContentField( modelFields ) != null ); } /** * Get the field which type is Content if any. * * @param modelFields the fields to check * @return the field, or null if no field is Content */ protected ModelField getContentField( List/**/ modelFields ) { return XmlModelHelpers.getContentField( modelFields ); } /** * Gets all fields that are not marked as transient. * * @param modelFields The collection of model fields from which to extract the non-transient fields, must not be * null. * @return The list of non-transient fields, can be empty but never null. */ protected List getNonTransientFields( List/**/ modelFields ) { return XmlModelHelpers.getNonTransientFields( modelFields ); } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootmodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/AbstractXmlJavaGenerator.javamodello-1.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/Abstra0000644000175000017500000001477411223665473032750 0ustar mkochmkochpackage org.codehaus.modello.plugins.xml; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.List; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.plugin.java.AbstractJavaModelloGenerator; import org.codehaus.modello.plugin.java.javasource.JSourceCode; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; /** * Abstract class for plugins generating Java code for XML representation of the model. * * @author Hervé Boutemy * @version $Id: AbstractXmlJavaGenerator.java 1273 2009-07-04 14:46:19Z bentmann $ */ public abstract class AbstractXmlJavaGenerator extends AbstractJavaModelloGenerator { protected String getFileName( String suffix ) { String name = getModel().getName(); return name + suffix; } /** * Resolve XML tag name for a class. Note: only root class needs such a resolution. * * @param modelClass the model class * @return the XML tag name for the class */ protected String resolveTagName( ModelClass modelClass ) { return XmlModelHelpers.resolveTagName( modelClass ); } /** * Resolve XML tag name for a field. * * @param modelField the model field * @param xmlFieldMetadata the XML metadata of the field * @return the XML tag name for the field */ protected String resolveTagName( ModelField modelField, XmlFieldMetadata xmlFieldMetadata ) { return XmlModelHelpers.resolveTagName( modelField, xmlFieldMetadata ); } /** * Resolve XML tag name for an item in an association with many multiplicity. * * @param fieldTagName the XML tag name of the field containing the association * @param xmlAssociationMetadata the XML metadata of the association * @return the XML tag name for items */ protected String resolveTagName( String fieldTagName, XmlAssociationMetadata xmlAssociationMetadata ) { return XmlModelHelpers.resolveTagName( fieldTagName, xmlAssociationMetadata ); } /** * Get the field which type is Content if any. * * @param modelFields the fields to check * @return the field, or null if no field is Content */ protected ModelField getContentField( List/**/ modelFields ) { return XmlModelHelpers.getContentField( modelFields ); } /** * Gets all fields that are not marked as transient. * * @param modelFields The collection of model fields from which to extract the non-transient fields, must not be * null. * @return The list of non-transient fields, can be empty but never null. */ protected List getNonTransientFields( List/**/ modelFields ) { return XmlModelHelpers.getNonTransientFields( modelFields ); } protected String getValue( String type, String initialValue, XmlFieldMetadata xmlFieldMetadata ) { String textValue = initialValue; if ( "Date".equals( type ) ) { String dateFormat = xmlFieldMetadata.getFormat(); if ( xmlFieldMetadata.getFormat() == null ) { dateFormat = DEFAULT_DATE_FORMAT; } if ( "long".equals( dateFormat ) ) { textValue = "String.valueOf( " + textValue + ".getTime() )"; } else { textValue = "new java.text.SimpleDateFormat( \"" + dateFormat + "\", Locale.US ).format( " + textValue + " )"; } } else if ( !"String".equals( type ) ) { textValue = "String.valueOf( " + textValue + " )"; } return textValue; } protected void writeDateParsingHelper( JSourceCode sc, String exception ) { sc.add( "if ( s != null )" ); sc.add( "{" ); sc.indent(); sc.add( "String effectiveDateFormat = dateFormat;" ); sc.add( "if ( dateFormat == null )" ); sc.add( "{" ); sc.addIndented( "effectiveDateFormat = \"" + DEFAULT_DATE_FORMAT + "\";" ); sc.add( "}" ); sc.add( "if ( \"long\".equals( effectiveDateFormat ) )" ); // parse date as a long sc.add( "{" ); sc.indent(); sc.add( "try" ); sc.add( "{" ); sc.addIndented( "return new java.util.Date( Long.parseLong( s ) );" ); sc.add( "}" ); sc.add( "catch ( NumberFormatException e )" ); sc.add( "{" ); sc.addIndented( "throw " + exception + ";" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "else" ); // parse date as a SimpleDateFormat expression sc.add( "{" ); sc.indent(); sc.add( "try" ); sc.add( "{" ); sc.indent(); sc.add( "DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, Locale.US );" ); sc.add( "return dateParser.parse( s );" ); sc.unindent(); sc.add( "}" ); sc.add( "catch ( java.text.ParseException e )" ); sc.add( "{" ); sc.addIndented( "throw " + exception + ";" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return null;" ); } } modello-1.1/modello-plugins/modello-plugin-xml/src/main/resources/0000755000175000017500000000000011260056266024362 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/0000755000175000017500000000000011260056266025522 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/modello/0000755000175000017500000000000011260056266027155 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/modello/plugins.xml0000644000175000017500000000030511127737247031365 0ustar mkochmkoch xml org.codehaus.modello.plugins.xml.metadata.XmlMetaDataPlugin modello-1.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056266027042 5ustar mkochmkochmodello-1.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000044511127737247031763 0ustar mkochmkoch org.codehaus.modello.metadata.MetadataPlugin xml org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin modello-1.1/modello-core/0000755000175000017500000000000011260056263014354 5ustar mkochmkochmodello-1.1/modello-core/pom.xml0000644000175000017500000000304111243557055015675 0ustar mkochmkoch modello org.codehaus.modello 1.1 4.0.0 org.codehaus.modello modello-core Modello Core Modello Core contains the basis for model description, reading, and plugins system. org.sonatype.plexus plexus-build-api org.codehaus.plexus plexus-container-default org.codehaus.modello modello-test test maven-assembly-plugin jar-with-dependencies org.codehaus.modello.ModelloCli modello-1.1/modello-core/src/0000755000175000017500000000000011260056263015143 5ustar mkochmkochmodello-1.1/modello-core/src/test/0000755000175000017500000000000011260056262016121 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/0000755000175000017500000000000011260056262017042 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/org/0000755000175000017500000000000011260056262017631 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/org/codehaus/0000755000175000017500000000000011260056262021424 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/org/codehaus/modello/0000755000175000017500000000000011260056262023057 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/org/codehaus/modello/core/0000755000175000017500000000000011260056262024007 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/org/codehaus/modello/core/io/0000755000175000017500000000000011260056262024416 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/org/codehaus/modello/core/io/ModelReaderTest.java0000644000175000017500000001334710647207577030333 0ustar mkochmkochpackage org.codehaus.modello.core.io; /* * Copyright (c) 2004, Jason van Zyl * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.model.VersionRange; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.ReaderFactory; import java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * * @version $Id: ModelReaderTest.java 840 2007-07-17 18:50:39Z hboutemy $ */ public class ModelReaderTest extends PlexusTestCase { public void testBasic() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/models/simple.mdo" ) ) ); assertNotNull( model ); assertEquals( "field", model.getVersionDefinition().getType() ); assertEquals( "foo", model.getVersionDefinition().getValue() ); assertEquals( "simple", model.getId() ); assertEquals( "Simple Modello Test Model", model.getName() ); assertEquals( "foo.bar", model.getDefaultPackageName( false, null ) ); assertEquals( "Boy", model.getRoot( new Version( "1.0.0" ) ) ); List classes = model.getAllClasses(); assertNotNull( classes ); assertEquals( 2, classes.size() ); assertEquals( 2, model.getClasses( new Version( "1.0.0" ) ).size() ); assertBoy( classes.get( 0 ) ); assertBoy( model.getClass( "Boy", new VersionRange( "1.0.0" ) ) ); assertGirl( model.getClass( "Girl", new VersionRange( "1.0.0" ) ) ); } public void testAssociationDefaultValues() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/models/association.mdo" ) ) ); ModelField field = model.getClass( "Foo", new VersionRange( "1.0.0" ) ).getField( "bars", new VersionRange( "1.0.0" ) ); assertTrue( field instanceof ModelAssociation ); ModelAssociation association = (ModelAssociation) field; assertEquals( "bars", association.getName() ); assertEquals( "Foo", association.getModelClass().getName() ); assertEquals( "Bar", association.getTo() ); assertEquals( "Bar", association.getToClass().getName() ); // assertEquals( "bars", association.getFromRole() ); // assertEquals( "foo", association.getToRole() ); // assertEquals( "1", association.getFromMultiplicity() ); // assertEquals( "*", association.getToMultiplicity() ); } private void assertBoy( Object boyObject ) { assertTrue( boyObject instanceof ModelClass ); ModelClass boy = (ModelClass)boyObject; assertNotNull( boy ); assertEquals( "Boy", boy.getName() ); assertEquals( "1.0.0", boy.getVersionRange().toString() ); List fields = boy.getFields( new Version( "1.0.0" ) ); assertEquals( 2, fields.size() ); assertBoyName( fields.get( 0 ) ); assertBoyName( boy.getField( "name", new VersionRange( "1.0.0" ) ) ); } private void assertBoyName( Object nameObject ) { assertTrue( nameObject instanceof ModelField ); ModelField name = (ModelField) nameObject; assertEquals( "name", name.getName() ); assertEquals( "1.0.0", name.getVersionRange().toString() ); assertEquals( "String", name.getType() ); assertEquals( "moniker", name.getAlias() ); } private void assertGirl( Object girlObject ) { assertTrue( girlObject instanceof ModelClass ); ModelClass girl = (ModelClass)girlObject; assertNotNull( girl ); assertEquals( "Girl", girl.getName() ); assertEquals( "1.0.0", girl.getVersionRange().toString() ); List fields = girl.getFields( new Version( "1.0.0" ) ); assertEquals( 1, fields.size() ); assertGirlAge( fields.get( 0 ) ); assertGirlAge( girl.getField( "age", new VersionRange( "1.0.0" ) ) ); } private void assertGirlAge( Object ageObject ) { assertTrue( ageObject instanceof ModelField ); ModelField age = (ModelField) ageObject; assertEquals( "age", age.getName() ); assertEquals( "1.0.0+", age.getVersionRange().toString() ); assertEquals( "int", age.getType() ); } } modello-1.1/modello-core/src/test/java/org/codehaus/modello/core/DefaultModelloCoreTest.java0000644000175000017500000000604710647207577031251 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Jason van Zyl * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.ReaderFactory; /** * @author Trygve Laugstøl * @version $Id: DefaultModelloCoreTest.java 840 2007-07-17 18:50:39Z hboutemy $ */ public class DefaultModelloCoreTest extends PlexusTestCase { public void testModelWithDuplicateClasses() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); try { modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/models/duplicate-classes.mdo" ) ) ); fail( "Expected ModelloRuntimeException." ); } catch( ModelloRuntimeException ex ) { assertEquals( "Duplicate class: MyClass.", ex.getMessage() ); } } public void testModelWithDuplicateFields() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); try { modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/models/duplicate-fields.mdo" ) ) ); fail( "Expected ModelloRuntimeException." ); } catch( ModelloRuntimeException ex ) { assertEquals( "Duplicate field in MyClass: MyField.", ex.getMessage() ); } } public void testModelWithDuplicateAssociations() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); try { modello.loadModel( ReaderFactory.newXmlReader( getTestFile( "src/test/resources/models/duplicate-associations.mdo" ) ) ); fail( "Expected ModelloRuntimeException." ); } catch( ModelloRuntimeException ex ) { assertEquals( "Duplicate field in MyClass: MyAssociation.", ex.getMessage() ); } } } modello-1.1/modello-core/src/test/java/org/codehaus/modello/model/0000755000175000017500000000000011260056262024157 5ustar mkochmkochmodello-1.1/modello-core/src/test/java/org/codehaus/modello/model/VersionTest.java0000644000175000017500000000707110516107356027320 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Jason van Zyl * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import junit.framework.TestCase; /** * @author Trygve Laugstøl * @version $Id: VersionTest.java 665 2006-10-20 08:55:10Z brett $ */ public class VersionTest extends TestCase { // TODO: Add testing for multidigit version numbers // TODO: Add tests for invalid version strings public void testVersionParsing() { Version version = new Version( "1.2.3" ); assertEquals( 1, version.getMajor() ); assertEquals( 2, version.getMinor() ); assertEquals( 3, version.getMicro() ); } public void testVersionRange() { VersionRange range = new VersionRange( "2.0.0+" ); assertFalse( new Version( "1.0.0" ).inside( range ) ); assertTrue( new Version( "2.0.0" ).inside( range ) ); assertTrue( new Version( "3.0.0" ).inside( range ) ); assertTrue( new Version( "2.0.0" ).equals( range.getFromVersion() ) ); assertTrue( Version.INFINITE.equals( range.getToVersion() ) ); range = new VersionRange( "1.0.0" ); assertTrue( new Version( "1.0.0" ).equals( range.getFromVersion() ) ); assertTrue( new Version( "1.0.0" ).equals( range.getToVersion() ) ); range = new VersionRange( "1.0.0/3.0.0" ); assertTrue( new Version( "1.0.0" ).equals( range.getFromVersion() ) ); assertTrue( new Version( "3.0.0" ).equals( range.getToVersion() ) ); } public void testGreaterThanWhenFooIsLessThanBar() { assertNotGreaterThan( "1.0.0", "2.9.9" ); assertNotGreaterThan( "1.9.9", "2.0.0" ); assertNotGreaterThan( "0.1.0", "0.2.9" ); assertNotGreaterThan( "0.1.1", "0.2.0" ); assertNotGreaterThan( "0.0.1", "0.0.1" ); } public void testGreaterThanWhenFooIsEqualBar() { assertNotGreaterThan( "1.2.3", "1.2.3" ); } public void testGreaterThanWhenFooIsGreaterThanBar() { assertGreaterThan( "2.0.0", "1.9.9" ); assertGreaterThan( "2.9.9", "1.0.0" ); assertGreaterThan( "0.2.9", "0.1.0" ); assertGreaterThan( "0.2.0", "0.1.9" ); assertGreaterThan( "0.0.2", "0.0.1" ); } private void assertGreaterThan( String foo, String bar ) { assertTrue( new Version( foo ).greaterThan( new Version( bar ) ) ); } private void assertNotGreaterThan( String foo, String bar ) { assertFalse( new Version( foo ).greaterThan( new Version( bar ) ) ); } } modello-1.1/modello-core/src/test/resources/0000755000175000017500000000000011260056262020133 5ustar mkochmkochmodello-1.1/modello-core/src/test/resources/models/0000755000175000017500000000000011260056262021416 5ustar mkochmkochmodello-1.1/modello-core/src/test/resources/models/duplicate-classes.mdo0000644000175000017500000000033311127507731025527 0ustar mkochmkoch duplicate-classes Duplicate Classes Test Model MyClass MyClass modello-1.1/modello-core/src/test/resources/models/association.mdo0000644000175000017500000000300310647207577024446 0ustar mkochmkoch association-test AssociationTest package org.codehaus.modello.association Boy 1.0.0 name 1.0.0 String girlfriends 1.0.0 Girl * Girl 1.0.0 name 1.0.0 String boyfriend 1.0.0 Girl Foo 1.0.0 bars 1.0.0 Bar * Bar 1.0.0 modello-1.1/modello-core/src/test/resources/models/duplicate-fields.mdo0000644000175000017500000000050411127507731025340 0ustar mkochmkoch duplicate-fields Duplicate Fields Test Model MyClass MyField MyField modello-1.1/modello-core/src/test/resources/models/duplicate-associations.mdo0000644000175000017500000000077611127507731026604 0ustar mkochmkoch duplicate-associations Duplicate Associations Test Model MyClass MyAssociation String MyAssociation String modello-1.1/modello-core/src/test/resources/models/simple.mdo0000644000175000017500000000225210647207577023430 0ustar mkochmkoch simple Simple Modello Test Model package foo.bar field foo Boy 1.0.0 java.lang.Serializable name moniker 1.0.0 String true girlfriends 1.0.0 Girl * Girl 1.0.0 age 1.0.0+ int modello-1.1/modello-core/src/site/0000755000175000017500000000000011260056263016107 5ustar mkochmkochmodello-1.1/modello-core/src/site/site.xml0000644000175000017500000000022511112331565017571 0ustar mkochmkoch Modello modello-1.1/modello-core/src/main/0000755000175000017500000000000011260056263016067 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/0000755000175000017500000000000011260056262017007 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/0000755000175000017500000000000011260056262017576 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/0000755000175000017500000000000011260056262021371 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/0000755000175000017500000000000011260056263023025 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/0000755000175000017500000000000011260056262024604 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/Metadata.java0000644000175000017500000000246710126570640027201 0ustar mkochmkochpackage org.codehaus.modello.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: Metadata.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public interface Metadata { } modello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/AssociationMetadata.java0000644000175000017500000000254210126570640031370 0ustar mkochmkochpackage org.codehaus.modello.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: AssociationMetadata.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public interface AssociationMetadata extends Metadata { } modello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/ClassMetadata.java0000644000175000017500000000252610126570640030163 0ustar mkochmkochpackage org.codehaus.modello.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ClassMetadata.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public interface ClassMetadata extends Metadata { } modello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/MetadataPlugin.java0000644000175000017500000000466010544333624030360 0ustar mkochmkochpackage org.codehaus.modello.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: MetadataPlugin.java 765 2006-12-27 00:00:20Z aheritier $ */ public interface MetadataPlugin { String ROLE = MetadataPlugin.class.getName(); ModelMetadata getModelMetadata( Model model, Map data ) throws ModelloException; ClassMetadata getClassMetadata( ModelClass clazz, Map data ) throws ModelloException; FieldMetadata getFieldMetadata( ModelField field, Map data ) throws ModelloException; AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) throws ModelloException; Map getModelMap( Model model, ModelMetadata metadata ) throws ModelloException; Map getClassMap( ModelClass clazz, ClassMetadata metadata ) throws ModelloException; Map getFieldMap( ModelField field, FieldMetadata metadata ) throws ModelloException; Map getAssociationMap( ModelAssociation association, AssociationMetadata metadata ) throws ModelloException; } modello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/AbstractMetadataPlugin.java0000644000175000017500000000632211136706075032043 0ustar mkochmkochpackage org.codehaus.modello.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.StringUtils; import java.util.Collections; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: AbstractMetadataPlugin.java 1156 2009-01-24 21:46:37Z hboutemy $ */ public abstract class AbstractMetadataPlugin extends AbstractLogEnabled implements MetadataPlugin { // ---------------------------------------------------------------------- // MetadataPlugin Implementation // ---------------------------------------------------------------------- public Map getModelMap( Model model, ModelMetadata metadata ) throws ModelloException { return Collections.EMPTY_MAP; } public Map getClassMap( ModelClass clazz, ClassMetadata metadata ) throws ModelloException { return Collections.EMPTY_MAP; } public Map getFieldMap( ModelField field, FieldMetadata metadata ) throws ModelloException { return Collections.EMPTY_MAP; } public Map getAssociationMap( ModelAssociation association, AssociationMetadata metadata ) throws ModelloException { return Collections.EMPTY_MAP; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- protected boolean getBoolean( Map data, String key, boolean defaultValue ) { String value = (String) data.get( key ); if ( StringUtils.isEmpty( value ) ) { return defaultValue; } return Boolean.valueOf( value ).booleanValue(); } protected String getString( Map data, String key ) { String value = (String) data.get( key ); return StringUtils.isEmpty( value ) ? null : value; } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/ModelMetadata.java0000644000175000017500000000252610126570640030156 0ustar mkochmkochpackage org.codehaus.modello.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ModelMetadata.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public interface ModelMetadata extends Metadata { } modello-1.1/modello-core/src/main/java/org/codehaus/modello/metadata/FieldMetadata.java0000644000175000017500000000252610126570640030141 0ustar mkochmkochpackage org.codehaus.modello.metadata; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: FieldMetadata.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public interface FieldMetadata extends Metadata { } modello-1.1/modello-core/src/main/java/org/codehaus/modello/ModelloCli.java0000644000175000017500000000774311124013131025710 0ustar mkochmkochpackage org.codehaus.modello; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; import java.io.File; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: ModelloCli.java 1042 2008-12-22 22:36:09Z hboutemy $ */ public class ModelloCli { private static File modelFile; private static String outputType; private static Properties parameters; public static void main( String[] args ) throws Exception { Modello modello = new Modello(); parseArgumentsFromCommandLine( args ); modello.generate( ReaderFactory.newXmlReader( modelFile ), outputType, parameters ); } public static void parseArgumentsFromCommandLine( String[] args ) throws Exception { if ( args.length < 6 ) { usage(); System.exit( 1 ); } modelFile = new File( args[0] ); outputType = args[1]; parameters = new Properties(); String outputDirectory = args[2]; if ( StringUtils.isEmpty( outputDirectory ) ) { System.err.println( "Missing required parameter: output directory" ); usage(); System.exit( 1 ); } parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, outputDirectory ); String modelVersion = args[ 3 ]; if ( StringUtils.isEmpty( modelVersion ) ) { System.err.println( "Missing required parameter: model version" ); usage(); System.exit( 1 ); } parameters.setProperty( ModelloParameterConstants.VERSION, modelVersion ); String packageWithVersion = args[ 4 ]; if ( StringUtils.isEmpty( packageWithVersion ) ) { System.err.println( "Missing required parameter: package with version" ); usage(); System.exit( 1 ); } parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, packageWithVersion ); String useJava5 = args[ 5 ]; if ( StringUtils.isEmpty( useJava5 ) ) { System.err.println( "Missing required parameter: use Java 5" ); usage(); System.exit( 1 ); } parameters.setProperty( ModelloParameterConstants.USE_JAVA5, useJava5 ); if ( args.length > 6 ) { parameters.setProperty( ModelloParameterConstants.ENCODING, args[6] ); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- private static void usage() { System.err.println( "Usage: modello " + " []" ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/Modello.java0000644000175000017500000000517011112616510025257 0ustar mkochmkochpackage org.codehaus.modello; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.Reader; import java.io.Writer; import java.util.Properties; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelValidationException; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.DefaultPlexusContainer; /** * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: Modello.java 938 2008-11-24 21:31:52Z hboutemy $ */ public class Modello { private PlexusContainer container; private ModelloCore core; public Modello() throws ModelloException { try { container = new DefaultPlexusContainer(); core = (ModelloCore) container.lookup( ModelloCore.ROLE ); } catch ( Exception ex ) { throw new ModelloException( "Error while starting plexus.", ex ); } } public void generate( Reader modelReader, String outputType, Properties parameters ) throws ModelloException, ModelValidationException { Model model = core.loadModel( modelReader ); core.generate( model, outputType, parameters ); } public void translate( Reader reader, Writer writer, String outputType, Properties parameters ) throws ModelloException, ModelValidationException { Model model = core.translate( reader, outputType, parameters ); core.saveModel( model, writer ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/0000755000175000017500000000000011260056262023754 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/core/io/0000755000175000017500000000000011260056262024363 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/core/io/ModelReader.java0000644000175000017500000004552411126656246027434 0ustar mkochmkochpackage org.codehaus.modello.core.io; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.BaseElement; import org.codehaus.modello.model.CodeSegment; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.ModelInterface; import org.codehaus.modello.model.VersionDefinition; import org.codehaus.modello.model.VersionRange; import org.codehaus.plexus.util.xml.pull.MXParser; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.IOException; import java.io.Reader; import java.util.HashMap; import java.util.Map; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: ModelReader.java 1075 2008-12-31 11:51:02Z hboutemy $ */ public class ModelReader { private Map/**/ modelAttributes = new HashMap(); private Map/*>*/ classAttributes = new HashMap(); private Map/*>*/ fieldAttributes = new HashMap(); private Map/*>*/ associationAttributes = new HashMap(); public Map/**/ getAttributesForModel() { return (Map) modelAttributes; } public Map/**/ getAttributesForClass( ModelClass modelClass ) { return (Map) classAttributes.get( modelClass.getName() ); } public Map/**/ getAttributesForField( ModelField modelField ) { return (Map) fieldAttributes.get( modelField.getModelClass().getName() + ':' + modelField.getName() + ':' + modelField.getVersionRange() ); } public Map/**/ getAttributesForAssociation( ModelAssociation modelAssociation ) { return (Map) associationAttributes.get( modelAssociation.getModelClass().getName() + ':' + modelAssociation.getName() + ':' + modelAssociation.getVersionRange() ); } public Model loadModel( Reader reader ) throws ModelloException { try { Model model = new Model(); XmlPullParser parser = new MXParser(); parser.setInput( reader ); parseModel( model, parser ); return model; } catch ( IOException ex ) { throw new ModelloException( "Error parsing the model.", ex ); } catch ( XmlPullParserException ex ) { throw new ModelloException( "Error parsing the model.", ex ); } } public void parseModel( Model model, XmlPullParser parser ) throws XmlPullParserException, IOException { int eventType = parser.getEventType(); while ( eventType != XmlPullParser.END_DOCUMENT ) { if ( eventType == XmlPullParser.START_TAG ) { if ( parseBaseElement( model, parser ) ) { } else if ( parser.getName().equals( "id" ) ) { model.setId( parser.nextText() ); } else if ( parser.getName().equals( "defaults" ) ) { parseDefaults( model, parser ); } else if ( parser.getName().equals( "versionDefinition" ) ) { parseVersionDefinition( model, parser ); } else if ( parser.getName().equals( "interfaces" ) ) { parseInterfaces( model, parser ); } else if ( parser.getName().equals( "classes" ) ) { parseClasses( model, parser ); } else if ( parser.getName().equals( "model" ) ) { modelAttributes = getAttributes( parser ); } else { // parser.nextText(); } } eventType = parser.next(); } } private void parseDefaults( Model model, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "default" ) ) { ModelDefault modelDefault = new ModelDefault(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "key" ) ) { modelDefault.setKey( parser.nextText() ); } else if ( parser.getName().equals( "value" ) ) { modelDefault.setValue( parser.nextText() ); } else { parser.nextText(); } } model.addDefault( modelDefault ); } else { parser.next(); } } } private void parseVersionDefinition( Model model, XmlPullParser parser ) throws XmlPullParserException, IOException { if ( "versionDefinition".equals( parser.getName() ) ) { VersionDefinition versionDefinition = new VersionDefinition(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "type".equals( parser.getName() ) ) { versionDefinition.setType( parser.nextText() ); } else if ( "value".equals( parser.getName() ) ) { versionDefinition.setValue( parser.nextText() ); } else { parser.nextText(); } } model.setVersionDefinition( versionDefinition ); } } private void parseInterfaces( Model model, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "interface" ) ) { ModelInterface modelInterface = new ModelInterface(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( modelInterface, parser ) ) { } else if ( parser.getName().equals( "superInterface" ) ) { modelInterface.setSuperInterface( parser.nextText() ); } else if ( parser.getName().equals( "packageName" ) ) { modelInterface.setPackageName( parser.nextText() ); } else if ( parser.getName().equals( "codeSegments" ) ) { parseCodeSegment( modelInterface, parser ); } else { parser.nextText(); } } model.addInterface( modelInterface ); } else { parser.next(); } } } private void parseClasses( Model model, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "class" ) ) { ModelClass modelClass = new ModelClass(); Map/**/ attributes = getAttributes( parser ); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( modelClass, parser ) ) { } else if ( parser.getName().equals( "interfaces" ) ) { parseClassInterfaces( modelClass, parser ); } else if ( parser.getName().equals( "superClass" ) ) { modelClass.setSuperClass( parser.nextText() ); } else if ( parser.getName().equals( "packageName" ) ) { modelClass.setPackageName( parser.nextText() ); } else if ( parser.getName().equals( "fields" ) ) { parseFields( modelClass, parser ); } else if ( parser.getName().equals( "codeSegments" ) ) { parseCodeSegment( modelClass, parser ); } else { parser.nextText(); } } model.addClass( modelClass ); classAttributes.put( modelClass.getName(), attributes ); } else { parser.next(); } } } private void parseClassInterfaces( ModelClass modelClass, XmlPullParser parser ) throws IOException, XmlPullParserException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "interface" ) ) { modelClass.addInterface( parser.nextText() ); } else { parser.nextText(); } } } private void parseFields( ModelClass modelClass, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "field" ) ) { ModelField modelField = new ModelField(); ModelAssociation modelAssociation = null; Map fAttributes = getAttributes( parser ); Map aAttributes = new HashMap(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( modelField, parser ) ) { } else if ( parser.getName().equals( "association" ) ) { aAttributes = getAttributes( parser ); modelAssociation = parseAssociation( parser ); } else if ( parser.getName().equals( "alias" ) ) { modelField.setAlias( parser.nextText() ); } else if ( parser.getName().equals( "type" ) ) { modelField.setType( parser.nextText() ); } else if ( parser.getName().equals( "defaultValue" ) ) { modelField.setDefaultValue( parser.nextText() ); } else if ( parser.getName().equals( "typeValidator" ) ) { modelField.setTypeValidator( parser.nextText() ); } else if ( parser.getName().equals( "required" ) ) { modelField.setRequired( Boolean.valueOf( parser.nextText() ).booleanValue() ); } else if ( parser.getName().equals( "identifier" ) ) { modelField.setIdentifier( Boolean.valueOf( parser.nextText() ).booleanValue() ); } else { parser.nextText(); } } if ( modelField.getName() != null ) { fieldAttributes.put( modelClass.getName() + ":" + modelField.getName() + ":" + modelField.getVersionRange(), fAttributes ); } if ( modelAssociation != null ) { // Base element modelAssociation.setName( modelField.getName() ); modelAssociation.setDescription( modelField.getDescription() ); modelAssociation.setVersionRange( modelField.getVersionRange() ); modelAssociation.setComment( modelField.getComment() ); // model field fields modelAssociation.setType( modelField.getType() ); modelAssociation.setAlias( modelField.getAlias() ); modelAssociation.setDefaultValue( modelField.getDefaultValue() ); modelAssociation.setTypeValidator( modelField.getTypeValidator() ); modelAssociation.setRequired( modelField.isRequired() ); modelAssociation.setIdentifier( modelField.isIdentifier() ); if ( modelAssociation.getName() != null ) { associationAttributes.put( modelClass.getName() + ":" + modelAssociation.getName() + ":" + modelAssociation.getVersionRange(), aAttributes ); } modelClass.addField( modelAssociation ); } else { modelClass.addField( modelField ); } } else { parser.next(); } } } private ModelAssociation parseAssociation( XmlPullParser parser ) throws XmlPullParserException, IOException { ModelAssociation modelAssociation = new ModelAssociation(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( modelAssociation, parser ) ) { } else if ( parser.getName().equals( "type" ) ) { modelAssociation.setTo( parser.nextText() ); } else if ( parser.getName().equals( "multiplicity" ) ) { modelAssociation.setMultiplicity( parser.nextText() ); } else { parser.nextText(); } } return modelAssociation; } private void parseCodeSegment( ModelClass modelClass, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "codeSegment" ) ) { CodeSegment codeSegment = new CodeSegment(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( codeSegment, parser ) ) { } else if ( parser.getName().equals( "code" ) ) { codeSegment.setCode( parser.nextText() ); } else { parser.nextText(); } } modelClass.addCodeSegment( codeSegment ); } else { parser.next(); } } } private void parseCodeSegment( ModelInterface modelInterface, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parser.getName().equals( "codeSegment" ) ) { CodeSegment codeSegment = new CodeSegment(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( codeSegment, parser ) ) { } else if ( parser.getName().equals( "code" ) ) { codeSegment.setCode( parser.nextText() ); } else { parser.nextText(); } } modelInterface.addCodeSegment( codeSegment ); } else { parser.next(); } } } private boolean parseBaseElement( BaseElement element, XmlPullParser parser ) throws XmlPullParserException, IOException { if ( parser.getName().equals( "name" ) ) { element.setName( parser.nextText() ); } else if ( parser.getName().equals( "description" ) ) { element.setDescription( parser.nextText() ); } else if ( parser.getName().equals( "version" ) ) { element.setVersionRange( new VersionRange( parser.nextText() ) ); } else if ( parser.getName().equals( "comment" ) ) { element.setComment( parser.nextText() ); } else { return false; } return true; } private Map/**/ getAttributes( XmlPullParser parser ) { Map attributes = new HashMap(); for ( int i = 0; i < parser.getAttributeCount(); i++ ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); attributes.put( name, value ); } return attributes; } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/ModelloCore.java0000644000175000017500000000431110650074770027030 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelValidationException; import java.io.File; import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: ModelloCore.java 843 2007-07-20 09:01:44Z jvanzyl $ */ public interface ModelloCore { String ROLE = ModelloCore.class.getName(); MetadataPluginManager getMetadataPluginManager(); Model loadModel( File file ) throws IOException, ModelloException, ModelValidationException; Model loadModel( Reader reader ) throws ModelloException, ModelValidationException; void saveModel( Model model, Writer writer ) throws ModelloException; Model translate( Reader reader, String inputType, Properties parameters ) throws ModelloException, ModelValidationException; void generate( Model model, String outputType, Properties parameters ) throws ModelloException; } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/DefaultModelloCore.java0000644000175000017500000003506311223730002030325 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.core.io.ModelReader; import org.codehaus.modello.metadata.AssociationMetadata; import org.codehaus.modello.metadata.ClassMetadata; import org.codehaus.modello.metadata.FieldMetadata; import org.codehaus.modello.metadata.MetadataPlugin; import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.CodeSegment; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.ModelValidationException; import org.codehaus.modello.plugin.ModelloGenerator; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.Properties; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * * @version $Id: DefaultModelloCore.java 1274 2009-07-04 19:39:46Z hboutemy $ */ public class DefaultModelloCore extends AbstractModelloCore { /** * @requirement */ private MetadataPluginManager metadataPluginManager; /** * @requirement */ private GeneratorPluginManager generatorPluginManager; public MetadataPluginManager getMetadataPluginManager() { return metadataPluginManager; } public Model loadModel( File file ) throws IOException, ModelloException, ModelValidationException { Reader reader = null; try { reader = ReaderFactory.newXmlReader( file ); return loadModel( reader ); } finally { IOUtil.close( reader ); } } private void upgradeModifiedAttribute( String name, Map from, String newName, Map to, String warn ) { Object value = from.remove( name ); if ( value != null ) { getLogger().warn( warn ); to.put( newName, value ); } } private void upgradeModifiedAttribute( String name, Map from, Map to, String warn ) { upgradeModifiedAttribute( name, from, name, to, warn ); } private void upgradeModelloModel( ModelReader modelReader, Model model ) { Map modelAttributes = modelReader.getAttributesForModel(); upgradeModifiedAttribute( "xsd.target-namespace", modelAttributes, "xsd.targetNamespace", modelAttributes, "attribute 'xsd.target-namespace' for model element is deprecated: " + "it has been renamed to 'xsd.targetNamespace'" ); for ( Iterator classes = model.getAllClasses().iterator(); classes.hasNext(); ) { ModelClass clazz = (ModelClass) classes.next(); Map classAttributes = modelReader.getAttributesForClass( clazz ); // attributes moved from root class to model upgradeModifiedAttribute( "xml.namespace", classAttributes, modelAttributes, "attribute 'xml.namespace' for class element is deprecated: it should be moved to model element" ); upgradeModifiedAttribute( "xml.schemaLocation", classAttributes, modelAttributes, "attribute 'xml.schemaLocation' for class element is deprecated: it should be moved to model element" ); for ( Iterator fields = clazz.getAllFields().iterator(); fields.hasNext(); ) { ModelField field = (ModelField) fields.next(); if ( field instanceof ModelAssociation ) { Map fieldAttributes = modelReader.getAttributesForField( field ); Map associationAttributes = modelReader.getAttributesForAssociation( (ModelAssociation)field ); upgradeModifiedAttribute( "java.adder", fieldAttributes, associationAttributes, "attribute 'java.adder' for field element is deprecated: it should be moved to association" ); upgradeModifiedAttribute( "java.generate-create", associationAttributes, "java.bidi", associationAttributes, "attribute 'java.generate-create' for association " + "element is deprecated: it has been renamed to 'java.bidi'" ); upgradeModifiedAttribute( "java.generate-break", associationAttributes, "java.bidi", associationAttributes, "attribute 'java.generate-break' for association " + "element is deprecated: it has been renamed to 'java.bidi'" ); upgradeModifiedAttribute( "java.use-interface", associationAttributes, "java.useInterface", associationAttributes, "attribute 'xml.use-interface' for association " + "element is deprecated: it has been renamed to 'xml.useInterface'" ); upgradeModifiedAttribute( "xml.associationTagName", fieldAttributes, "xml.tagName", associationAttributes, "attribute 'xml.associationTagName' for field element is " + "deprecated: use 'xml.tagName' in association instead" ); upgradeModifiedAttribute( "xml.listStyle", fieldAttributes, "xml.itemsStyle", associationAttributes, "attribute 'xml.listStyle' for field element is " + "deprecated: use 'xml.itemsStyle' in association instead" ); } if ( "Content".equals( field.getType() ) ) { // TODO : add a deprecation Warning field.setType( "String" ); Map fieldAttributes = modelReader.getAttributesForField( field ); fieldAttributes.put( "xml._content_", "true" ); } } } } public Model loadModel( Reader reader ) throws ModelloException, ModelValidationException { ModelReader modelReader = new ModelReader(); Model model = modelReader.loadModel( reader ); model.initialize(); // keep backward compatibility with Modello attributes model changes upgradeModelloModel( modelReader, model ); handlePluginsMetadata( modelReader, model ); validate( model ); return model; } /** * Handle Plugins Metadata. * * @throws ModelloException */ private void handlePluginsMetadata( ModelReader modelReader, Model model ) throws ModelloException { for ( Iterator plugins = metadataPluginManager.getPluginsIterator(); plugins.hasNext(); ) { MetadataPlugin plugin = (MetadataPlugin) plugins.next(); Map attributes = Collections.unmodifiableMap( modelReader.getAttributesForModel() ); attributes = Collections.unmodifiableMap( attributes ); ModelMetadata metadata = plugin.getModelMetadata( model, attributes ); if ( metadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } model.addMetadata( metadata ); } for ( Iterator classes = model.getAllClasses().iterator(); classes.hasNext(); ) { ModelClass clazz = (ModelClass) classes.next(); Map attributes = Collections.unmodifiableMap( modelReader.getAttributesForClass( clazz ) ); attributes = Collections.unmodifiableMap( attributes ); for ( Iterator plugins = metadataPluginManager.getPluginsIterator(); plugins.hasNext(); ) { MetadataPlugin plugin = (MetadataPlugin) plugins.next(); ClassMetadata metadata = plugin.getClassMetadata( clazz, attributes ); if ( metadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } clazz.addMetadata( metadata ); } for ( Iterator fields = clazz.getAllFields().iterator(); fields.hasNext(); ) { Object field = fields.next(); if ( field instanceof ModelAssociation ) { ModelAssociation modelAssociation = (ModelAssociation) field; Map fieldAttributes = modelReader.getAttributesForField( modelAssociation ); fieldAttributes = Collections.unmodifiableMap( fieldAttributes ); Map associationAttributes = modelReader.getAttributesForAssociation( modelAssociation ); associationAttributes = Collections.unmodifiableMap( associationAttributes ); for ( Iterator plugins = metadataPluginManager.getPluginsIterator(); plugins.hasNext(); ) { MetadataPlugin plugin = (MetadataPlugin) plugins.next(); FieldMetadata fieldMetadata = plugin.getFieldMetadata( modelAssociation, fieldAttributes ); if ( fieldMetadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } modelAssociation.addMetadata( fieldMetadata ); AssociationMetadata associationMetadata = plugin.getAssociationMetadata( modelAssociation, associationAttributes ); if ( associationMetadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } modelAssociation.addMetadata( associationMetadata ); } } else { ModelField modelField = (ModelField) field; attributes = modelReader.getAttributesForField( modelField ); attributes = Collections.unmodifiableMap( attributes ); for ( Iterator plugins = metadataPluginManager.getPluginsIterator(); plugins.hasNext(); ) { MetadataPlugin plugin = (MetadataPlugin) plugins.next(); FieldMetadata metadata = plugin.getFieldMetadata( modelField, attributes ); if ( metadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } modelField.addMetadata( metadata ); } } } } } /** * Validate the entire model. * * @throws ModelValidationException */ private void validate( Model model ) throws ModelValidationException { model.validate(); for ( Iterator defaults = model.getDefaults().iterator(); defaults.hasNext(); ) { ModelDefault modelDefault = (ModelDefault) defaults.next(); modelDefault.validateElement(); } for ( Iterator classes = model.getAllClasses().iterator(); classes.hasNext(); ) { ModelClass modelClass = (ModelClass) classes.next(); modelClass.validate(); } for ( Iterator classes = model.getAllClasses().iterator(); classes.hasNext(); ) { ModelClass modelClass = (ModelClass) classes.next(); for ( Iterator fields = modelClass.getAllFields().iterator(); fields.hasNext(); ) { Object field = fields.next(); if ( field instanceof ModelAssociation ) { ModelAssociation modelAssociation = (ModelAssociation) field; modelAssociation.validate(); } else { ModelField modelField = (ModelField) field; modelField.validate(); } } for ( Iterator codeSegments = modelClass.getAllCodeSegments().iterator(); codeSegments.hasNext(); ) { CodeSegment codeSegment = (CodeSegment) codeSegments.next(); codeSegment.validate(); } } } public void saveModel( Model model, Writer writer ) throws ModelloException { throw new ModelloRuntimeException( "Not implemented." ); } public Model translate( Reader reader, String inputType, Properties parameters ) throws ModelloException { throw new ModelloRuntimeException( "Not implemented." ); } public void generate( Model model, String outputType, Properties parameters ) throws ModelloException { if ( model == null ) { throw new ModelloRuntimeException( "Illegal argument: model == null." ); } if ( outputType == null ) { throw new ModelloRuntimeException( "Illegal argument: outputType == null." ); } if ( parameters == null ) { parameters = new Properties(); } ModelloGenerator generator = generatorPluginManager.getGeneratorPlugin( outputType ); generator.generate( model, parameters ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/DefaultMetadataPluginManager.java0000644000175000017500000000377510126570640032333 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.metadata.MetadataPlugin; import org.codehaus.modello.plugin.AbstractPluginManager; /** * @author Trygve Laugstøl * @version $Id: DefaultMetadataPluginManager.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public class DefaultMetadataPluginManager extends AbstractPluginManager implements MetadataPluginManager { public MetadataPlugin getMetadataPlugin( String metadataId ) { MetadataPlugin metadata = (MetadataPlugin) getPlugin( metadataId ); if ( metadata == null ) { throw new ModelloRuntimeException( "No such metadata plugin: '" + metadataId + "'." ); } return metadata; } public boolean hasMetadataPlugin( String metadataId ) { return hasPlugin( metadataId ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/AbstractModelloCore.java0000644000175000017500000000413710327277064030524 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelValidationException; import org.codehaus.plexus.logging.AbstractLogEnabled; import java.io.Reader; import java.io.Writer; /** * @author Trygve Laugstøl * @version $Id: AbstractModelloCore.java 508 2005-10-25 00:37:08Z brett $ */ public abstract class AbstractModelloCore extends AbstractLogEnabled implements ModelloCore { // ---------------------------------------------------------------------- // Partial ModelloCore implementation // ---------------------------------------------------------------------- public Model input( Reader reader ) throws ModelloException, ModelValidationException { return loadModel( reader ); } public void output( Model model, Writer writer ) throws ModelloException { saveModel( model, writer ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/GeneratorPluginManager.java0000644000175000017500000000324510544333624031227 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.plugin.ModelloGenerator; import java.util.Iterator; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: GeneratorPluginManager.java 765 2006-12-27 00:00:20Z aheritier $ */ public interface GeneratorPluginManager { String ROLE = GeneratorPluginManager.class.getName(); Map getPlugins(); Iterator getPluginsIterator(); ModelloGenerator getGeneratorPlugin( String generatorId ); boolean hasGeneratorPlugin( String generatorId ); } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/MetadataPluginManager.java0000644000175000017500000000323410544333624031017 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.MetadataPlugin; import java.util.Iterator; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: MetadataPluginManager.java 765 2006-12-27 00:00:20Z aheritier $ */ public interface MetadataPluginManager { String ROLE = MetadataPluginManager.class.getName(); Map getPlugins(); Iterator getPluginsIterator(); MetadataPlugin getMetadataPlugin( String metadataId ); boolean hasMetadataPlugin( String metadataId ); } modello-1.1/modello-core/src/main/java/org/codehaus/modello/core/DefaultGeneratorPluginManager.java0000644000175000017500000000402110126570640032522 0ustar mkochmkochpackage org.codehaus.modello.core; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.plugin.AbstractPluginManager; import org.codehaus.modello.plugin.ModelloGenerator; /** * @author Trygve Laugstøl * @version $Id: DefaultGeneratorPluginManager.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public class DefaultGeneratorPluginManager extends AbstractPluginManager implements GeneratorPluginManager { public ModelloGenerator getGeneratorPlugin( String generatorId ) { ModelloGenerator generator = (ModelloGenerator) getPlugin( generatorId ); if ( generator == null ) { throw new ModelloRuntimeException( "No such generator plugin: '" + generatorId + "'." ); } return generator; } public boolean hasGeneratorPlugin( String generatorId ) { return hasPlugin( generatorId ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/ModelloParameterConstants.java0000644000175000017500000000426711124013131031014 0ustar mkochmkochpackage org.codehaus.modello; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ModelloParameterConstants.java 1042 2008-12-22 22:36:09Z hboutemy $ */ public class ModelloParameterConstants { public static final String VERSION = "modello.version"; public static final String OUTPUT_DIRECTORY = "modello.output.directory"; public static final String PACKAGE_WITH_VERSION = "modello.package.with.version"; public static final String STRICT_PARSER = "modello.strict.parser"; public static final String ALL_VERSIONS = "modello.all.versions"; public static final String FILENAME = "modello.output.filename"; public static final String FIRST_VERSION = "modello.first.version"; public static final String ENCODING = "modello.output.encoding"; public static final String USE_JAVA5 = "modello.output.useJava5"; public static final String OUTPUT_XDOC_FILE_NAME = "modello.output.xdoc.file"; public static final String OUTPUT_XSD_FILE_NAME = "modello.output.xsd.file"; private ModelloParameterConstants() { } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/0000755000175000017500000000000011260056262024124 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/model/CodeSegment.java0000644000175000017500000000312610126570640027167 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Jason van Zyl * @version $Id: CodeSegment.java 149 2004-09-29 17:32:16Z jvanzyl $ */ public class CodeSegment extends BaseElement { private String code; public CodeSegment() { super( false ); } public String getCode() { return code; } public void setCode( String code ) { this.code = code; } public void validateElement() { } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/ModelDefault.java0000644000175000017500000001120211124264413027326 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Emmanuel Venisse * * @version $Id: ModelDefault.java 1043 2008-12-23 22:41:15Z hboutemy $ */ public class ModelDefault { public static final String CHECK_DEPRECATION = "checkDeprecation"; public static final String CHECK_DEPRECATION_VALUE = "false"; public static final String PACKAGE = "package"; public static final String PACKAGE_VALUE = "model"; public static final String LIST = "java.util.List"; public static final String LIST_VALUE = "new java.util.ArrayList()"; public static final String MAP = "java.util.Map"; public static final String MAP_VALUE = "new java.util.HashMap()"; public static final String PROPERTIES = "java.util.Properties"; public static final String PROPERTIES_VALUE = "new java.util.Properties()"; public static final String SET = "java.util.Set"; public static final String SET_VALUE = "new java.util.HashSet()"; private String key; private String value; public static ModelDefault getDefault( String key ) throws ModelValidationException { validateKey( key ); ModelDefault modelDefault = new ModelDefault(); modelDefault.setKey( key ); if ( CHECK_DEPRECATION.equalsIgnoreCase( key ) ) { modelDefault.setValue( CHECK_DEPRECATION_VALUE ); } if ( PACKAGE.equalsIgnoreCase( key ) ) { modelDefault.setValue( PACKAGE_VALUE ); } if ( LIST.equalsIgnoreCase( key ) ) { modelDefault.setValue( LIST_VALUE ); } if ( MAP.equalsIgnoreCase( key ) ) { modelDefault.setValue( MAP_VALUE ); } if ( PROPERTIES.equalsIgnoreCase( key ) ) { modelDefault.setValue( PROPERTIES_VALUE ); } if ( SET.equalsIgnoreCase( key ) ) { modelDefault.setValue( SET_VALUE ); } return modelDefault; } public void setKey( String key ) { this.key = key; } public String getKey() { return key; } public void setValue( String value ) { this.value = value; } public String getValue() { return value; } public boolean getBoolean() { return Boolean.valueOf( value ).booleanValue(); } public void validateElement() throws ModelValidationException { if ( isEmpty( key ) ) { throw new ModelValidationException( "You must define the key of default element." ); } if ( isEmpty( value ) ) { throw new ModelValidationException( "You must define the value of default element." ); } validateKey( key ); } private static void validateKey( String key ) throws ModelValidationException { if ( ! SET.equalsIgnoreCase( key ) && ! LIST.equalsIgnoreCase( key ) && ! MAP.equalsIgnoreCase( key ) && ! PROPERTIES.equalsIgnoreCase( key ) && ! CHECK_DEPRECATION.equalsIgnoreCase( key ) && ! PACKAGE.equalsIgnoreCase( key ) ) { throw new ModelValidationException( "The key of default element must be ' "+ SET +"', '" + LIST + "', '" + MAP + "', '" + PROPERTIES + "', '" + CHECK_DEPRECATION + "' or 'package', was '" + key + "'." ); } } protected boolean isEmpty( String string ) { return string == null || string.trim().length() == 0; } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/BaseElement.java0000644000175000017500000001353111112616510027150 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.metadata.Metadata; import java.util.HashMap; import java.util.Map; /** * This is the base class for all elements of the model. * * The name attribute is immutable because it's used as the key. * * @author Jason van Zyl * @author Trygve Laugstøl * @author Emmanuel Venisse * * @version $Id: BaseElement.java 938 2008-11-24 21:31:52Z hboutemy $ */ public abstract class BaseElement { private String name; private String description; private String comment; private VersionRange versionRange = new VersionRange( "0.0.0+" ); private Version deprecatedVersion; private transient Map metadata = new HashMap(); private boolean nameRequired; public abstract void validateElement() throws ModelValidationException; public BaseElement( boolean nameRequired ) { this.nameRequired = nameRequired; this.name = null; } public BaseElement( boolean nameRequired, String name ) { this.nameRequired = nameRequired; this.name = name; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public String getDescription() { return description; } public void setDescription( String description ) { this.description = description; } public VersionRange getVersionRange() { return versionRange; } public void setVersionRange( VersionRange versionRange ) { this.versionRange = versionRange; } public void setDeprecatedVersion( Version deprecatedVersion ) { this.deprecatedVersion = deprecatedVersion; } public Version getDeprecatedVersion() { return deprecatedVersion; } public String getComment() { return comment; } public void setComment( String comment ) { this.comment = comment; } public boolean hasMetadata( String key ) { return metadata.containsKey( key ); } public void addMetadata( Metadata metadata ) { this.metadata.put( metadata.getClass().getName(), metadata ); } protected Metadata getMetadata( Class type, String key ) { Metadata metadata = (Metadata) this.metadata.get( key ); if ( metadata == null ) { throw new ModelloRuntimeException( "No such metadata: '" + key + "' for element: '" + getName() + "'." ); } if ( !type.isAssignableFrom( metadata.getClass() ) ) { throw new ModelloRuntimeException( "The metadata is not of the expected type. Key: '" + key + "', expected type: '" + type.getName() + "'." ); } return metadata; } // ---------------------------------------------------------------------- // Validation utils // ---------------------------------------------------------------------- protected void validateFieldNotEmpty( String objectName, String fieldName, String value ) throws ModelValidationException { if ( value == null ) { throw new ModelValidationException( "Missing value '" + fieldName + "' from " + objectName + "." ); } if ( isEmpty( value ) ) { throw new ModelValidationException( "Empty value '" + fieldName + "' from " + objectName + "." ); } } public final void validate() throws ModelValidationException { if ( nameRequired ) { validateFieldNotEmpty( "Element.name", "name", name ); } validateElement(); } protected boolean isEmpty( String string ) { return string == null || string.trim().length() == 0; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public boolean equals( Object other ) { if ( other == null || !( other instanceof BaseElement ) ) { return false; } // If we don't know how to identify this object it's not equal to any other object if ( !nameRequired ) { return false; } BaseElement baseElem = (BaseElement) other; return name.equals( baseElem.getName() ) && versionRange.equals( baseElem.getVersionRange() ); } public int hashCode() { if ( !nameRequired ) { return System.identityHashCode( this ); } return name.hashCode() + versionRange.toString().hashCode(); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/Model.java0000644000175000017500000003023411227712212026026 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.plugin.model.ModelClassMetadata; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: Model.java 1284 2009-07-16 20:58:50Z hboutemy $ */ public class Model extends BaseElement { private String id; private List classes = new ArrayList(); private List defaults = new ArrayList(); private List interfaces = new ArrayList(); private transient Map classMap = new HashMap(); private transient Map defaultMap = new HashMap(); private transient Map interfaceMap = new HashMap(); private VersionDefinition versionDefinition; public Model() { super( true ); } public String getId() { return id; } public void setId( String id ) { this.id = id; } public VersionDefinition getVersionDefinition() { return versionDefinition; } public void setVersionDefinition( VersionDefinition versionDefinition ) { this.versionDefinition = versionDefinition; } public ModelMetadata getMetadata( String key ) { return (ModelMetadata) getMetadata( ModelMetadata.class, key ); } public String getRoot( Version version ) { List classes = getClasses( version ); String className = null; for ( Iterator i = classes.iterator(); i.hasNext(); ) { ModelClass currentClass = (ModelClass) i.next(); ModelClassMetadata metadata = null; try { metadata = (ModelClassMetadata) currentClass.getMetadata( ModelClassMetadata.ID ); } catch ( Exception e ) { } if ( metadata != null && metadata.isRootElement() ) { if ( className == null ) { className = currentClass.getName(); } else { throw new ModelloRuntimeException( "There are more than one class as root element for this version " + version + "." ); } } } if ( className == null ) { throw new ModelloRuntimeException( "There aren't root element for version " + version + "." ); } return className; } /** * @deprecated This shouldn't be used, anything querying the model should read the * package of the class. Use getDefaultPackageName(..). */ public String getPackageName( boolean withVersion, Version version ) { return getDefaultPackageName( withVersion, version ); } public List getAllClasses() { return classes; } public List getClasses( Version version ) { ArrayList classList = new ArrayList(); for ( Iterator i = classes.iterator(); i.hasNext(); ) { ModelClass currentClass = (ModelClass) i.next(); if ( version.inside( currentClass.getVersionRange() ) ) { classList.add( currentClass ); } } return classList; } public ModelClass getClass( String type, Version version ) { return getClass( type, new VersionRange( version ) ); } public ModelClass getClass( String type, VersionRange versionRange ) { ModelClass value = getModelClass( type, versionRange ); if ( value != null ) { return value; } throw new ModelloRuntimeException( "There is no class '" + type + "' in the version range '" + versionRange.toString() + "'." ); } public boolean hasClass( String type, Version version ) { ModelClass value = getModelClass( type, new VersionRange( version ) ); return value != null; } private ModelClass getModelClass( String type, VersionRange versionRange ) { ArrayList classList = (ArrayList) classMap.get( type ); ModelClass value = null; if ( classList != null ) { for ( Iterator i = classList.iterator(); i.hasNext() && value == null; ) { ModelClass modelClass = (ModelClass) i.next(); if ( versionRange.getFromVersion().inside( modelClass.getVersionRange() ) && versionRange.getToVersion().inside( modelClass.getVersionRange() ) ) { value = modelClass; } } } return value; } public void addClass( ModelClass modelClass ) { if ( classMap.containsKey( modelClass.getName() ) ) { ArrayList classList = (ArrayList) classMap.get( modelClass.getName() ); for ( Iterator i = classList.iterator(); i.hasNext(); ) { ModelClass currentClass = (ModelClass) i.next(); if ( VersionUtil.isInConflict( modelClass.getVersionRange(), currentClass.getVersionRange() ) ) { throw new ModelloRuntimeException( "Duplicate class: " + modelClass.getName() + "." ); } } } else { ArrayList classList = new ArrayList(); classMap.put( modelClass.getName(), classList ); } getAllClasses().add( modelClass ); ( (ArrayList) classMap.get( modelClass.getName() ) ).add( modelClass ); } // ---------------------------------------------------------------------- // Defaults // ---------------------------------------------------------------------- public List getDefaults() { return defaults; } public ModelDefault getDefault( String key ) throws ModelValidationException { ModelDefault modelDefault = (ModelDefault) defaultMap.get( key ); if ( modelDefault == null ) { modelDefault = ModelDefault.getDefault( key ); } return modelDefault; } public void addDefault( ModelDefault modelDefault ) { if ( defaultMap.containsKey( modelDefault.getKey() ) ) { throw new ModelloRuntimeException( "Duplicate default: " + modelDefault.getKey() + "." ); } getDefaults().add( modelDefault ); defaultMap.put( modelDefault.getKey(), modelDefault ); } public String getDefaultPackageName( boolean withVersion, Version version ) { String packageName; try { packageName = getDefault( ModelDefault.PACKAGE ).getValue(); } catch ( ModelValidationException mve ) { packageName = ModelDefault.PACKAGE_VALUE; } if ( withVersion ) { packageName += "." + version.toString( "v", "_" ); } return packageName; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public List getAllInterfaces() { return interfaces; } public List getInterfaces( Version version ) { ArrayList interfaceList = new ArrayList(); for ( Iterator i = interfaces.iterator(); i.hasNext(); ) { ModelInterface currentInterface = (ModelInterface) i.next(); if ( version.inside( currentInterface.getVersionRange() ) ) { interfaceList.add( currentInterface ); } } return interfaceList; } public ModelInterface getInterface( String type, Version version ) { return getInterface( type, new VersionRange( version ) ); } public ModelInterface getInterface( String type, VersionRange versionRange ) { ModelInterface value = getModelInterface( type, versionRange ); if ( value != null ) { return value; } throw new ModelloRuntimeException( "There is no interface '" + type + "' in the version range '" + versionRange.toString() + "'." ); } private ModelInterface getModelInterface( String type, VersionRange versionRange ) { ArrayList interfaceList = (ArrayList) interfaceMap.get( type ); if ( interfaceList != null ) { for ( Iterator i = interfaceList.iterator(); i.hasNext(); ) { ModelInterface modelInterface = (ModelInterface) i.next(); if ( versionRange.getFromVersion().inside( modelInterface.getVersionRange() ) && versionRange.getToVersion().inside( modelInterface.getVersionRange() ) ) { return modelInterface; } } } return null; } public void addInterface( ModelInterface modelInterface ) { if ( interfaceMap.containsKey( modelInterface.getName() ) ) { ArrayList interfaceList = (ArrayList) interfaceMap.get( modelInterface.getName() ); for ( Iterator i = interfaceList.iterator(); i.hasNext(); ) { ModelInterface currentInterface = (ModelInterface) i.next(); if ( VersionUtil.isInConflict( modelInterface.getVersionRange(), currentInterface.getVersionRange() ) ) { throw new ModelloRuntimeException( "Duplicate interface: " + modelInterface.getName() + "." ); } } } else { ArrayList interfaceList = new ArrayList(); interfaceMap.put( modelInterface.getName(), interfaceList ); } getAllInterfaces().add( modelInterface ); ( (ArrayList) interfaceMap.get( modelInterface.getName() ) ).add( modelInterface ); } public ModelType getType( String type, Version version ) { return getType( type, new VersionRange( version ) ); } public ModelType getType( String type, VersionRange versionRange ) { ModelType value = getModelClass( type, versionRange ); if ( value != null ) { return value; } value = getModelInterface( type, versionRange ); if ( value != null ) { return value; } throw new ModelloRuntimeException( "There is no class or interface '" + type + "' in the version range '" + versionRange.toString() + "'." ); } public void initialize() { for ( Iterator i = classes.iterator(); i.hasNext(); ) { ModelClass modelClass = (ModelClass) i.next(); modelClass.initialize( this ); } for ( Iterator i = interfaces.iterator(); i.hasNext(); ) { ModelInterface modelInterface = (ModelInterface) i.next(); modelInterface.initialize( this ); } } public void validateElement() { } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/ModelAssociation.java0000644000175000017500000001513511137037532030233 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AssociationMetadata; import org.codehaus.plexus.util.StringUtils; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: ModelAssociation.java 1161 2009-01-25 10:30:50Z hboutemy $ */ public class ModelAssociation extends ModelField { public static final String ONE_MULTIPLICITY = "1"; public static final String MANY_MULTIPLICITY = "*"; // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- private String to; private String multiplicity; private ModelClass toClass; // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- /** * @param to The to to set. */ public void setTo( String to ) { this.to = to; } /** * @return Returns the to. */ public String getTo() { return to; } public String getType() { if ( ONE_MULTIPLICITY.equals( getMultiplicity() ) ) { return getTo(); } else { return super.getType(); } } /** * @return Returns the multiplicity. */ public String getMultiplicity() { return multiplicity; } /** * @param multiplicity The multiplicity to set. */ public void setMultiplicity( String multiplicity ) { this.multiplicity = multiplicity; } public boolean isManyMultiplicity() { return MANY_MULTIPLICITY.equals( multiplicity ); } public boolean isOneMultiplicity() { return ONE_MULTIPLICITY.equals( multiplicity ); } /** * @return Returns the to ModelClass. */ public ModelClass getToClass() { return toClass; } public AssociationMetadata getAssociationMetadata( String key ) { return (AssociationMetadata) getMetadata( AssociationMetadata.class, key ); } // ---------------------------------------------------------------------- // BaseElement overrides // ---------------------------------------------------------------------- public void validateElement() throws ModelValidationException { validateFieldNotEmpty( "Association", "name", getName() ); validateFieldNotEmpty( "Association '" + getName() + "'", "to", to ); if ( isEmpty( to ) ) { throw new ModelValidationException( "You must define the type of association." ); } if ( !to.equals( "String" ) ) { toClass = getModelClass().getModel().getClass( to, getVersionRange() ); if ( toClass == null ) { throw new ModelValidationException( "Association '" + getName() + "': Could not find to class." ); } } if ( isEmpty( multiplicity ) ) { multiplicity = ONE_MULTIPLICITY; } if ( multiplicity.equals( "n" ) || multiplicity.equals( "*" ) ) { multiplicity = MANY_MULTIPLICITY; } if ( !multiplicity.equals( ONE_MULTIPLICITY ) && !multiplicity.equals( MANY_MULTIPLICITY ) ) { throw new ModelValidationException( "Association multiplicity '" + getName() + "' is incorrect: " + "Possible values are '1', '*' or 'n'." ); } if ( isEmpty( getType() ) ) { ModelDefault modelDefault = getModelClass().getModel().getDefault( ModelDefault.LIST ); setType( modelDefault.getKey() ); setDefaultValue( getDefaultValue( modelDefault ) ); } else { if ( isManyMultiplicity() ) { if ( getType().equalsIgnoreCase( "Set" ) ) { setType( ModelDefault.SET ); } else if ( getType().equalsIgnoreCase( "List" ) ) { setType( ModelDefault.LIST ); } else if ( getType().equalsIgnoreCase( "Map" ) ) { setType( ModelDefault.MAP ); } else if ( getType().equalsIgnoreCase( "Properties" ) ) { setType( ModelDefault.PROPERTIES ); } else { throw new ModelValidationException( "The type of element '" + getName() + "' must be List, Map, Properties or Set." ); } if ( isEmpty( getDefaultValue() ) ) { ModelDefault modelDefault = getModelClass().getModel().getDefault( getType() ); // setType( modelDefault.getKey() ); setDefaultValue( getDefaultValue( modelDefault ) ); } } } } public boolean isGenericType() { return getType().equals( ModelDefault.LIST ) || getType().equals( ModelDefault.SET ); } private String getDefaultValue( ModelDefault modelDefault ) { String value = modelDefault.getValue(); if ( isGenericType() ) { value = StringUtils.replace( value, "", "/*<" + getTo() + ">*/" ); } return value; } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/Version.java0000644000175000017500000001534411112616510026415 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.plexus.util.StringUtils; /** * A version string is on the form ... * * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: Version.java 938 2008-11-24 21:31:52Z hboutemy $ */ public class Version implements Comparable { public static final Version INFINITE = new Version( "32767.32767.32767" ); private short major; private short minor; private short micro; public Version( String version ) { if ( version == null ) { throw new ModelloRuntimeException( "Syntax error in the version field: Missing. " ); } String[] splittedVersion = StringUtils.split( version.trim(), "." ); if ( splittedVersion.length > 3 ) { throw new ModelloRuntimeException( "Syntax error in the field: The field must be at more 3 parts long (major, minor and micro). Was: '" + version + "'." ); } String majorString = splittedVersion[0]; String minorString = "0"; String microString = "0"; if ( splittedVersion.length > 1 ) { minorString = splittedVersion[1]; if ( splittedVersion.length > 2 ) { microString = splittedVersion[2]; } } try { major = Short.parseShort( majorString ); minor = Short.parseShort( minorString ); micro = Short.parseShort( microString ); } catch ( NumberFormatException e ) { throw new ModelloRuntimeException( "Invalid version string: '" + version + "'." ); } } public int getMajor() { return major; } public int getMinor() { return minor; } public int getMicro() { return micro; } /** * Returns true if this is greater that other. * * @param other */ public boolean greaterThan( Version other ) { if ( this.major != other.major ) { return major > other.major; } if ( this.minor != other.minor ) { return this.minor > other.minor; } if ( this.micro != other.micro ) { return this.micro > other.micro; } return false; } /** * Returns true if this is greater or equals that other. * * @param other */ public boolean greaterOrEqualsThan( Version other ) { if ( this.major != other.major ) { return major >= other.major; } if ( this.minor != other.minor ) { return this.minor >= other.minor; } if ( this.micro != other.micro ) { return this.micro >= other.micro; } return false; } /** * Returns true if this is lesser that other. * * @param other */ public boolean lesserThan( Version other ) { if ( this.major != other.major ) { return major < other.major; } if ( this.minor != other.minor ) { return this.minor < other.minor; } if ( this.micro != other.micro ) { return this.micro < other.micro; } return false; } /** * Returns true if this is lesser or equals that other. * * @param other */ public boolean lesserOrEqualsThan( Version other ) { if ( this.major != other.major ) { return major <= other.major; } if ( this.minor != other.minor ) { return this.minor <= other.minor; } if ( this.micro != other.micro ) { return this.micro <= other.micro; } return false; } public boolean inside( VersionRange range ) { if ( range.getFromVersion().equals( this ) ) { return true; } else if ( ( this.greaterThan( range.getFromVersion() ) ) && ( this.lesserThan( range.getToVersion() ) ) ) { return true; } else if ( this.equals( range.getFromVersion() ) || this.equals( range.getToVersion() ) ) { return true; } return false; } // ---------------------------------------------------------------------- // Object overrides // ---------------------------------------------------------------------- public boolean equals( Object object ) { if ( !( object instanceof Version ) ) { return false; } Version other = (Version) object; return this.major == other.major && this.minor == other.minor && this.micro == other.micro; } public int hashCode() { return toString( "", null ).hashCode(); } public String toString() { return toString( "", "." ); } public String toString( String prefix, String separator ) { return prefix + major + separator + minor + separator + micro; } public int compareTo( Object o ) { Version otherVersion = (Version) o; if ( greaterThan( otherVersion ) ) { return +1; } else if ( equals( otherVersion ) ) { return 0; } else { return -1; } } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/ModelValidationException.java0000644000175000017500000000300511145652712031723 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ModelValidationException.java 1188 2009-02-14 23:37:46Z hboutemy $ */ public class ModelValidationException extends Exception { private static final long serialVersionUID = -8146274663701861789L; public ModelValidationException( String msg ) { super( msg ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/ModelType.java0000644000175000017500000001677211227712212026703 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** * Either a model class or interface. * * @author Hervé Boutemy * * @version $Id: ModelType.java 1284 2009-07-16 20:58:50Z hboutemy $ */ public abstract class ModelType extends BaseElement { private String packageName; private List codeSegments; private transient Model model; private transient Map codeSegmentMap = new HashMap(); public ModelType() { super( true ); } public ModelType( Model model, String name ) { super( true, name ); this.model = model; } public String getPackageName() { return getPackageName( false, null ); } public String getPackageName( boolean withVersion, Version version ) { String p; if ( packageName != null ) { p = packageName; } else { try { p = model.getDefault( ModelDefault.PACKAGE ).getValue(); } catch ( Exception e ) { p = ModelDefault.PACKAGE_VALUE; } } if ( withVersion ) { p += "." + version.toString( "v", "_" ); } return p; } public void setPackageName( String packageName ) { this.packageName = packageName; } public Model getModel() { return model; } // ---------------------------------------------------------------------- // CodeSegment // ---------------------------------------------------------------------- public List getAllCodeSegments() { if ( codeSegments == null ) { codeSegments = new ArrayList(); } return codeSegments; } public List getCodeSegments( Version version ) { return getCodeSegments( new VersionRange( version ) ); } public List getCodeSegments( VersionRange versionRange ) { ArrayList codeSegments = (ArrayList) getAllCodeSegments(); ArrayList codeSegmentsList = new ArrayList(); if ( codeSegments != null ) { for ( Iterator i = codeSegments.iterator(); i.hasNext(); ) { CodeSegment codeSegment = (CodeSegment) i.next(); if ( versionRange.getFromVersion().inside( codeSegment.getVersionRange() ) && versionRange.getToVersion().inside( codeSegment.getVersionRange() ) ) { codeSegmentsList.add( codeSegment ); } } } return codeSegmentsList; } public void addCodeSegment( CodeSegment codeSegment ) { getAllCodeSegments().add( codeSegment ); codeSegmentMap.put( codeSegment.getName(), codeSegment ); } // ---------------------------------------------------------------------- // Field // ---------------------------------------------------------------------- /** * Returns the list of all fields in this class. * * It does not include the fields of super classes. * * @return Returns the list of all fields in this class. It does not include the * fields of super classes. */ public abstract List getAllFields(); /** * Returns all the fields in this class and all super classes if withInheritedField equals to true. * * @return Returns all the fields in this class and all super classes. */ public abstract List getAllFields( boolean withInheritedField ); public abstract ModelField getField( String type, VersionRange versionRange ); /** * Returns the list of all fields in this class for a specific version. * * It does not include the fields of super classes. * * @return Returns the list of all fields in this class. It does not include the * fields of super classes. */ public List getFields( Version version ) { ArrayList fieldList = new ArrayList(); for ( Iterator i = getAllFields().iterator(); i.hasNext(); ) { ModelField currentField = (ModelField) i.next(); if ( version.inside( currentField.getVersionRange() ) ) { fieldList.add( currentField ); } } return fieldList; } public List getAllFields( Version version, boolean withInheritedField ) { ArrayList allFieldsList = new ArrayList(); ArrayList fieldList = new ArrayList(); for ( Iterator i = getAllFields( withInheritedField ).iterator(); i.hasNext(); ) { ModelField currentField = (ModelField) i.next(); if ( version.inside( currentField.getVersionRange() ) ) { allFieldsList.add( currentField ); } } for ( Iterator i = allFieldsList.iterator(); i.hasNext(); ) { ModelField currentField = (ModelField) i.next(); if ( version.inside( currentField.getVersionRange() ) ) { fieldList.add( currentField ); } } return fieldList; } public boolean hasField( String type, Version version ) { try { getField( type, new VersionRange( version ) ); return true; } catch ( Exception e ) { return false; } } public ModelField getField( String type, Version version ) { return getField( type, new VersionRange( version ) ); } public List getIdentifierFields( Version version ) { List identifierFields = new ArrayList(); for ( Iterator it = getFields( version ).iterator(); it.hasNext(); ) { ModelField field = (ModelField) it.next(); if ( field.isIdentifier() ) { identifierFields.add( field ); } } return identifierFields; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public void initialize( Model model ) { this.model = model; if ( packageName == null ) { packageName = model.getDefaultPackageName( false, null ); } } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/ModelInterface.java0000644000175000017500000000452411227712212027652 0ustar mkochmkochpackage org.codehaus.modello.model; import java.util.ArrayList; import java.util.List; import org.codehaus.modello.ModelloRuntimeException; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Emmanuel Venisse * * @version $Id: ModelInterface.java 1284 2009-07-16 20:58:50Z hboutemy $ */ public class ModelInterface extends ModelType { private String superInterface; public ModelInterface() { super(); } public ModelInterface( Model model, String name ) { super( model, name ); } public void setSuperInterface( String superInterface ) { this.superInterface = superInterface; } public String getSuperInterface() { return superInterface; } /** * {@inheritDoc} */ public List getAllFields() { return new ArrayList(); } /** * {@inheritDoc} */ public List getAllFields( boolean withInheritedField ) { return new ArrayList(); } public ModelField getField( String type, VersionRange versionRange ) { throw new ModelloRuntimeException( "There are no field '" + type + "' in an interface." ); } public void validateElement() throws ModelValidationException { } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/ModelField.java0000644000175000017500000001520011223730002026757 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.FieldMetadata; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: ModelField.java 1274 2009-07-04 19:39:46Z hboutemy $ */ public class ModelField extends BaseElement { private String type; private String defaultValue; private String typeValidator; private boolean required; private boolean identifier; private String alias; private transient ModelClass modelClass; private static final String[] PRIMITIVE_TYPES = new String[] { "boolean", "byte", "char", "short", "int", "long", "float", "double", "String", "Boolean", "Date", "DOM" }; public ModelField() { super( true ); } public ModelField( ModelClass modelClass, String name ) { super( true, name ); this.modelClass = modelClass; } // ---------------------------------------------------------------------- // Property accessors // ---------------------------------------------------------------------- public String getType() { return type; } public void setType( String type ) { this.type = type; } public String getDefaultValue() { return defaultValue; } public void setDefaultValue( String defaultValue ) { this.defaultValue = defaultValue; } public String getTypeValidator() { return typeValidator; } public void setTypeValidator( String typeValidator ) { this.typeValidator = typeValidator; } public boolean isRequired() { return required; } public void setRequired( boolean required ) { this.required = required; } public boolean isIdentifier() { return identifier; } public void setIdentifier( boolean identifier ) { this.identifier = identifier; } public String getAlias() { return alias; } public void setAlias( String alias ) { this.alias = alias; } // ---------------------------------------------------------------------- // Misc // ---------------------------------------------------------------------- public ModelClass getModelClass() { return modelClass; } public FieldMetadata getMetadata( String key ) { return (FieldMetadata) getMetadata( FieldMetadata.class, key ); } public boolean isPrimitive() { String type = getType(); // TODO: This should not happen if ( type == null ) { return false; } for ( int i = 0; i < PRIMITIVE_TYPES.length; i++ ) { String validType = PRIMITIVE_TYPES[i]; if ( type.equals( validType ) ) { return true; } } return false; } public boolean isArray() { return getType().endsWith( "[]" ); } public boolean isPrimitiveArray() { String type = getType(); // TODO: This should not happen if ( type == null ) { return false; } for ( int i = 0; i < PRIMITIVE_TYPES.length; i++ ) { String validType = PRIMITIVE_TYPES[i] + "[]"; if ( type.equals( validType ) ) { return true; } } return false; } // ---------------------------------------------------------------------- // BaseElement Overrides // ---------------------------------------------------------------------- public void initialize( ModelClass modelClass ) { this.modelClass = modelClass; if ( defaultValue == null ) { if ( "boolean".equals( type ) ) { defaultValue = "false"; } else if ( "float".equals( type ) || "double".equals( type ) ) { defaultValue = "0.0"; } else if ( "int".equals( type ) || "long".equals( type ) || "char".equals( type ) || "short".equals( type ) || "byte".equals( type ) ) { defaultValue = "0"; } } } public void validateElement() throws ModelValidationException { validateFieldNotEmpty( "field", "name", getName() ); validateFieldNotEmpty( "field '" + getName() + "'", "type", type ); // TODO: these definitions are duplicated throughout. Defined centrally, and loop through in the various uses if ( !isPrimitive() && !isPrimitiveArray() ) { throw new ModelValidationException( "Field '" + getName() + "': Illegal type: '" + type + "'." ); } } // ---------------------------------------------------------------------- // Object Overrides // ---------------------------------------------------------------------- public String toString() { return "[Field: name=" + getName() + ", alias: " + alias + ", type: " + type + ", " + "version: " + getVersionRange() + "]"; } public boolean isModelVersionField() { Model model = modelClass.getModel(); VersionDefinition versionDefinition = model.getVersionDefinition(); return ( versionDefinition != null ) && "field".equals( versionDefinition.getType() ) && ( versionDefinition.getValue().equals( getName() ) || versionDefinition.getValue().equals( alias ) ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/VersionDefinition.java0000644000175000017500000000277111127507731030440 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ public class VersionDefinition { private String type; private String value; public String getType() { return type; } public void setType( String type ) { this.type = type; } public String getValue() { return value; } public void setValue( String value ) { this.value = value; } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/VersionRange.java0000644000175000017500000000751511126671302027400 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * A version range. Can be of 3 forms:
      *
    • x.y.z: a range of only one precise version,
    • *
    • x.y.z+: a range starting form a precise version (included), without upper limit,
    • *
    • x.y.z/i.j.k: a range from one version to another (both included).
    • *
    * @author Emmanuel Venisse * @version $Id: VersionRange.java 1076 2008-12-31 13:25:22Z hboutemy $ */ public class VersionRange { private static final String VERSION_SEPARATOR = "/"; private Version fromVersion; private Version toVersion; public VersionRange( String versionRange ) { if ( versionRange.endsWith( "+" ) ) { fromVersion = new Version( versionRange.substring( 0, versionRange.length() - 1 ) ); toVersion = Version.INFINITE; } else if ( versionRange.indexOf( VERSION_SEPARATOR ) > 0 && ! versionRange.endsWith( VERSION_SEPARATOR ) ) { int pos = versionRange.indexOf( VERSION_SEPARATOR ); fromVersion = new Version( versionRange.substring( 0, pos ) ); toVersion = new Version( versionRange.substring( pos + 1 ) ); } else { fromVersion = new Version( versionRange ); toVersion = new Version( versionRange ); } } public VersionRange( Version version ) { fromVersion = version; toVersion = version; } public Version getFromVersion() { return fromVersion; } public Version getToVersion() { return toVersion; } public boolean isToInfinite() { return toVersion == Version.INFINITE; } // ---------------------------------------------------------------------- // Object overrides // ---------------------------------------------------------------------- public int hashCode() { return fromVersion.hashCode() + toVersion.hashCode(); } public boolean equals( Object obj ) { if ( !( obj instanceof VersionRange ) ) { return false; } VersionRange other = (VersionRange) obj; return fromVersion.equals( other.fromVersion ) && toVersion.equals( other.toVersion ); } public String toString() { if ( fromVersion.equals( toVersion ) ) { return fromVersion.toString( "", "." ); } else if ( toVersion.equals( Version.INFINITE ) ) { return fromVersion.toString( "", "." ) + "+"; } else { return "[" + fromVersion.toString( "", "." ) + " => " + toVersion.toString( "", "." ) + "]"; } } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/VersionUtil.java0000644000175000017500000000311011112616510027237 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Emmanuel Venisse * * @version $Id: VersionUtil.java 938 2008-11-24 21:31:52Z hboutemy $ */ public class VersionUtil { public static boolean isInConflict( VersionRange version1, VersionRange version2 ) { return !( version1.getToVersion().lesserThan( version2.getFromVersion() ) || version2.getToVersion().lesserThan( version1.getFromVersion() ) ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/model/ModelClass.java0000644000175000017500000002044111227712212027013 0ustar mkochmkochpackage org.codehaus.modello.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.metadata.ClassMetadata; import org.codehaus.plexus.util.StringUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /** * @author Jason van Zyl * @author Emmanuel Venisse * * @version $Id: ModelClass.java 1284 2009-07-16 20:58:50Z hboutemy $ */ public class ModelClass extends ModelType { private String superClass; private boolean isInternalSuperClass; private List interfaces; private List fields; private transient Map fieldMap = new HashMap(); public ModelClass() { super(); } public ModelClass( Model model, String name ) { super( model, name ); } public String getSuperClass() { return superClass; } public void setSuperClass( String superClass ) { this.superClass = superClass; } // ---------------------------------------------------------------------- // Interfaces // ---------------------------------------------------------------------- /** * Returns the list of all interfaces of this class. * * @return Returns the list of all interfaces of this class. */ public List getInterfaces() { if ( interfaces == null ) { interfaces = new ArrayList(); } return interfaces; } public void addInterface( String modelInterface ) { if ( getInterfaces().contains( modelInterface ) ) { throw new ModelloRuntimeException( "Duplicate interface in " + getName() + ": " + modelInterface + "." ); } getInterfaces().add( modelInterface ); } // ---------------------------------------------------------------------- // Field // ---------------------------------------------------------------------- /** * {@inheritDoc} */ public List getAllFields() { if ( fields == null ) { fields = new ArrayList(); } return fields; } /** * Returns all the fields in this class and all super classes if withInheritedField equals to true. * * @return Returns all the fields in this class and all super classes. */ public List getAllFields( boolean withInheritedField ) { if ( ! withInheritedField ) { return getAllFields(); } List fields = new ArrayList( getAllFields() ); ModelClass c = this; while ( c.hasSuperClass() && c.isInternalSuperClass() ) { ModelClass parent = getModel().getClass( c.getSuperClass(), getVersionRange() ); fields.addAll( parent.getAllFields() ); c = parent; } return fields; } public ModelField getField( String type, VersionRange versionRange ) { ArrayList fieldList = (ArrayList) fieldMap.get( type ); if ( fieldList != null ) { for ( Iterator i = fieldList.iterator(); i.hasNext(); ) { ModelField modelField = (ModelField) i.next(); if ( versionRange.getFromVersion().inside( modelField.getVersionRange() ) && versionRange.getToVersion().inside( modelField.getVersionRange() ) ) { return modelField; } } } throw new ModelloRuntimeException( "There are no field '" + type + "' in version range '" + versionRange.toString() + "'." ); } public void addField( ModelField modelField ) { if ( fieldMap.containsKey( modelField.getName() ) ) { ArrayList fieldList = (ArrayList) fieldMap.get( modelField.getName() ); for ( Iterator i = fieldList.iterator(); i.hasNext(); ) { ModelField currentField = (ModelField) i.next(); if ( VersionUtil.isInConflict( modelField.getVersionRange(), currentField.getVersionRange() ) ) { throw new ModelloRuntimeException( "Duplicate field in " + getName() + ": " + modelField.getName() + "." ); } } } else { ArrayList fieldList = new ArrayList(); fieldMap.put( modelField.getName(), fieldList ); } getAllFields().add( modelField ); ( (ArrayList) fieldMap.get( modelField.getName() ) ).add( modelField ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public boolean hasSuperClass() { return StringUtils.isNotEmpty( superClass ); } public boolean isInternalSuperClass() { return isInternalSuperClass; } public ClassMetadata getMetadata( String key ) { return (ClassMetadata) getMetadata( ClassMetadata.class, key ); } public void initialize( Model model ) { super.initialize( model ); for ( Iterator it = getAllFields().iterator(); it.hasNext(); ) { Object field = it.next(); if ( field instanceof ModelAssociation ) { ModelAssociation modelAssociation = (ModelAssociation) field; modelAssociation.initialize( this ); } else { ModelField modelField = (ModelField) field; modelField.initialize( this ); } } } public void validateElement() throws ModelValidationException { // Check if superClass exists if ( hasSuperClass() ) { try { getModel().getClass( superClass, getVersionRange() ); isInternalSuperClass = true; } catch ( ModelloRuntimeException e ) { isInternalSuperClass = false; } } if ( getModel().getDefault( ModelDefault.CHECK_DEPRECATION ).getBoolean() ) { if ( ! Version.INFINITE.equals( getVersionRange().getToVersion() ) && getDeprecatedVersion() == null ) { throw new ModelValidationException( "You must define the deprecated version of '" + getName() + "' class." ); } } } // ---------------------------------------------------------------------- // Object Overrides // ---------------------------------------------------------------------- public boolean equals( Object o ) { if ( ! super.equals( o ) ) { return false; } if ( !( o instanceof ModelClass ) ) { return false; } ModelClass other = (ModelClass) o; return getPackageName().equals( other.getPackageName() ); } public int hashCode() { int hashCode = getName().hashCode(); if ( !StringUtils.isEmpty( getPackageName() ) ) { hashCode += 37 * getPackageName().hashCode(); } return hashCode; } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/ModelloException.java0000644000175000017500000000311411145652712027144 0ustar mkochmkochpackage org.codehaus.modello; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ModelloException.java 1188 2009-02-14 23:37:46Z hboutemy $ */ public class ModelloException extends Exception { private static final long serialVersionUID = -8746896773615188345L; public ModelloException( String msg ) { super( msg ); } public ModelloException( String msg, Throwable cause ) { super( msg, cause ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/ModelloRuntimeException.java0000644000175000017500000000315611145652712030516 0ustar mkochmkochpackage org.codehaus.modello; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ModelloRuntimeException.java 1188 2009-02-14 23:37:46Z hboutemy $ */ public class ModelloRuntimeException extends RuntimeException { private static final long serialVersionUID = -637783066384319780L; public ModelloRuntimeException( String msg ) { super( msg ); } public ModelloRuntimeException( String msg, Throwable cause ) { super( msg, cause ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/0000755000175000017500000000000011260056263024323 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractModelloGenerator.java0000644000175000017500000002170311225661222032115 0ustar mkochmkochpackage org.codehaus.modello.plugin; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Properties; import org.codehaus.modello.ModelloException; import org.codehaus.modello.ModelloParameterConstants; import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelDefault; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.sonatype.plexus.build.incremental.BuildContext; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.context.Context; import org.codehaus.plexus.context.ContextException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.util.StringUtils; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: AbstractModelloGenerator.java 1281 2009-07-10 15:47:30Z bentmann $ */ public abstract class AbstractModelloGenerator extends AbstractLogEnabled implements ModelloGenerator, Contextualizable { private static final DateFormat DATE_FORMAT = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); private Model model; private File outputDirectory; private Version generatedVersion; private boolean packageWithVersion; private String encoding; private BuildContext buildContext; protected void initialize( Model model, Properties parameters ) throws ModelloException { this.model = model; outputDirectory = new File( getParameter( parameters, ModelloParameterConstants.OUTPUT_DIRECTORY ) ); String version = getParameter( parameters, ModelloParameterConstants.VERSION ); generatedVersion = new Version( version ); packageWithVersion = Boolean.valueOf( getParameter( parameters, ModelloParameterConstants.PACKAGE_WITH_VERSION ) ).booleanValue(); encoding = parameters.getProperty( ModelloParameterConstants.ENCODING ); } protected Model getModel() { return model; } protected Version getGeneratedVersion() { return generatedVersion; } protected boolean isPackageWithVersion() { return packageWithVersion; } public File getOutputDirectory() { return outputDirectory; } protected String getEncoding() { return encoding; } protected String getHeader() { String version = getClass().getPackage().getImplementationVersion(); return "=================== DO NOT EDIT THIS FILE ====================\n" + "Generated by Modello" + ( ( version == null ) ? "" : ( ' ' + version ) ) + " on " + DATE_FORMAT.format( new Date() ) + ",\n" + "any modifications will be overwritten.\n" + "=============================================================="; } protected boolean isClassInModel( String fieldType, Model model ) { try { return model.getClass( fieldType, generatedVersion ) != null; } catch ( Exception e ) { } return false; } /** * Return the child fields of this class. * @param modelClass current class * @return the list of fields of this class */ protected List getFieldsForClass( ModelClass modelClass ) { List fields = new ArrayList(); while ( modelClass != null ) { fields.addAll( modelClass.getFields( getGeneratedVersion() ) ); String superClass = modelClass.getSuperClass(); if ( superClass != null ) { modelClass = getModel().getClass( superClass, getGeneratedVersion() ); } else { modelClass = null; } } return fields; } protected boolean isInnerAssociation( ModelField field ) { return field instanceof ModelAssociation && isClassInModel( ( (ModelAssociation) field ).getTo(), getModel() ); } protected boolean isMap( String fieldType ) { return ModelDefault.MAP.equals( fieldType ) || ModelDefault.PROPERTIES.equals( fieldType ); } protected boolean isCollection( String fieldType ) { return ModelDefault.LIST.equals( fieldType ) || ModelDefault.SET.equals( fieldType ); } protected String capitalise( String str ) { if ( StringUtils.isEmpty( str ) ) { return str; } return new StringBuffer( str.length() ) .append( Character.toTitleCase( str.charAt( 0 ) ) ) .append( str.substring( 1 ) ) .toString(); } public static String singular( String name ) { if ( StringUtils.isEmpty( name ) ) { return name; } if ( name.endsWith( "ies" ) ) { return name.substring( 0, name.length() - 3 ) + "y"; } else if ( name.endsWith( "es" ) && name.endsWith( "ches" ) ) { return name.substring( 0, name.length() - 2 ); } else if ( name.endsWith( "xes" ) ) { return name.substring( 0, name.length() - 2 ); } else if ( name.endsWith( "s" ) && ( name.length() != 1 ) ) { return name.substring( 0, name.length() - 1 ); } return name; } public static String uncapitalise( String str ) { if ( StringUtils.isEmpty( str ) ) { return str; } return new StringBuffer( str.length() ) .append( Character.toLowerCase( str.charAt( 0 ) ) ) .append( str.substring( 1 ) ) .toString(); } // ---------------------------------------------------------------------- // Text utils // ---------------------------------------------------------------------- protected boolean isEmpty( String string ) { return string == null || string.trim().length() == 0; } // ---------------------------------------------------------------------- // Parameter utils // ---------------------------------------------------------------------- /** * @deprecated @{link Use getParameter( Properties, String )} instead */ protected String getParameter( String name, Properties parameters ) { return getParameter( parameters, name ); } protected String getParameter( Properties parameters, String name ) { String value = parameters.getProperty( name ); if ( value == null ) { throw new ModelloRuntimeException( "Missing parameter '" + name + "'." ); } return value; } protected String getParameter( Properties parameters, String name, String defaultValue ) { String value = parameters.getProperty( name ); if ( value == null ) { return defaultValue; } return value; } public void contextualize( Context ctx ) throws ContextException { PlexusContainer plexus = (PlexusContainer) ctx.get( PlexusConstants.PLEXUS_KEY ); try { buildContext = (BuildContext) plexus.lookup( BuildContext.class.getName() ); } catch( ComponentLookupException e ) { throw new ContextException( "Unable to lookup required component", e ); } } protected BuildContext getBuildContext() { return buildContext; } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/ModelloGenerator.java0000644000175000017500000000302610544333624030434 0ustar mkochmkochpackage org.codehaus.modello.plugin; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: ModelloGenerator.java 765 2006-12-27 00:00:20Z aheritier $ */ public interface ModelloGenerator { void generate( Model model, Properties parameters ) throws ModelloException; } modello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractPluginManager.java0000644000175000017500000000450310544333624031410 0ustar mkochmkochpackage org.codehaus.modello.plugin; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import java.util.Collections; import java.util.Iterator; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: AbstractPluginManager.java 765 2006-12-27 00:00:20Z aheritier $ */ public abstract class AbstractPluginManager extends AbstractLogEnabled implements Initializable { private Map plugins; public void initialize() { if ( plugins == null ) { plugins = Collections.EMPTY_MAP; } } public Map getPlugins() { return plugins; } public Iterator getPluginsIterator() { return plugins.values().iterator(); } public Object getPlugin( String name ) { Object plugin = plugins.get( name ); if ( plugin == null ) { throw new ModelloRuntimeException( "No such plugin: " + name ); } return plugin; } public boolean hasPlugin( String name ) { return plugins.containsKey( name ); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/0000755000175000017500000000000011260056263025423 5ustar mkochmkochmodello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/ModelMetadataPlugin.java0000644000175000017500000000545011136710116032146 0ustar mkochmkochpackage org.codehaus.modello.plugin.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AbstractMetadataPlugin; import org.codehaus.modello.metadata.AssociationMetadata; import org.codehaus.modello.metadata.ClassMetadata; import org.codehaus.modello.metadata.FieldMetadata; import org.codehaus.modello.metadata.MetadataPlugin; import org.codehaus.modello.metadata.ModelMetadata; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelAssociation; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import java.util.Map; /** * @author Emmanuel Venisse * @version $Id: ModelMetadataPlugin.java 1157 2009-01-24 22:03:58Z hboutemy $ */ public class ModelMetadataPlugin extends AbstractMetadataPlugin implements MetadataPlugin { public static final String ROOT_ELEMENT = "rootElement"; // ---------------------------------------------------------------------- // Map to Metadata // ---------------------------------------------------------------------- public ModelMetadata getModelMetadata( Model model, Map data ) { return new ModelModelMetadata(); } public ClassMetadata getClassMetadata( ModelClass clazz, Map data ) { ModelClassMetadata metadata = new ModelClassMetadata(); metadata.setRootElement( getBoolean( data, ROOT_ELEMENT, false ) ); return metadata; } public FieldMetadata getFieldMetadata( ModelField field, Map data ) { return new ModelFieldMetadata(); } public AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) { return new ModelAssociationMetadata(); } } modello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/ModelFieldMetadata.java0000644000175000017500000000274511112616510031734 0ustar mkochmkochpackage org.codehaus.modello.plugin.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.FieldMetadata; /** * @author Emmanuel Venisse * @version $Id: ModelFieldMetadata.java 938 2008-11-24 21:31:52Z hboutemy $ */ public class ModelFieldMetadata implements FieldMetadata { public static final String ID = ModelFieldMetadata.class.getName(); } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootmodello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/ModelAssociationMetadata.javamodello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/ModelAssociationMetadata.ja0000644000175000017500000000300311112616510032622 0ustar mkochmkochpackage org.codehaus.modello.plugin.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.AssociationMetadata; /** * @author Emmanuel Venisse * @version $Id: ModelAssociationMetadata.java 938 2008-11-24 21:31:52Z hboutemy $ */ public class ModelAssociationMetadata implements AssociationMetadata { public static final String ID = ModelAssociationMetadata.class.getName(); } modello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/ModelModelMetadata.java0000644000175000017500000000274511112616510031751 0ustar mkochmkochpackage org.codehaus.modello.plugin.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.ModelMetadata; /** * @author Emmanuel Venisse * @version $Id: ModelModelMetadata.java 938 2008-11-24 21:31:52Z hboutemy $ */ public class ModelModelMetadata implements ModelMetadata { public static final String ID = ModelModelMetadata.class.getName(); } modello-1.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/ModelClassMetadata.java0000644000175000017500000000330711127700153031754 0ustar mkochmkochpackage org.codehaus.modello.plugin.model; /* * Copyright (c) 2004, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.modello.metadata.ClassMetadata; /** * @author Emmanuel Venisse * @version $Id: ModelClassMetadata.java 1097 2009-01-03 15:12:43Z hboutemy $ */ public class ModelClassMetadata implements ClassMetadata { public static final String ID = ModelClassMetadata.class.getName(); private boolean rootElement = false; public boolean isRootElement() { return rootElement; } public void setRootElement( boolean rootElement ) { this.rootElement = rootElement; } } modello-1.1/modello-core/src/main/resources/0000755000175000017500000000000011260056263020101 5ustar mkochmkochmodello-1.1/modello-core/src/main/resources/META-INF/0000755000175000017500000000000011260056263021241 5ustar mkochmkochmodello-1.1/modello-core/src/main/resources/META-INF/plexus/0000755000175000017500000000000011260056263022561 5ustar mkochmkochmodello-1.1/modello-core/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000277011122564046025476 0ustar mkochmkoch org.codehaus.modello.core.ModelloCore org.codehaus.modello.core.DefaultModelloCore org.codehaus.modello.core.MetadataPluginManager org.codehaus.modello.core.GeneratorPluginManager org.codehaus.modello.core.MetadataPluginManager org.codehaus.modello.core.DefaultMetadataPluginManager plugins org.codehaus.modello.metadata.MetadataPlugin org.codehaus.modello.core.GeneratorPluginManager org.codehaus.modello.core.DefaultGeneratorPluginManager plugins org.codehaus.modello.plugin.ModelloGenerator org.codehaus.modello.metadata.MetadataPlugin model org.codehaus.modello.plugin.model.ModelMetadataPlugin modello-1.1/pom.xml0000644000175000017500000005341411243557055013325 0ustar mkochmkoch 4.0.0 org.codehaus.modello modello pom Modello 1.1 http://modello.codehaus.org/ Modello is a framework for code generation from a simple model. Modello generates code from a simple model format: based on a plugin architecture, various types of code and descriptors can be generated from the single model, including Java POJOs, XML marshallers/unmarshallers, XSD and documentation. UTF-8 UTF-8 2.0.7 jira http://jira.codehaus.org/browse/MODELLO mail
    dev@modello.codehaus.org
    2001 Modello Announce List http://xircles.codehaus.org/manage_email/announce@modello.codehaus.org http://xircles.codehaus.org/projects/modello/lists http://archive.codehaus.org/lists/org.codehaus.modello.announce http://markmail.org/list/org.codehaus.modello.announce Modello Developer List http://xircles.codehaus.org/manage_email/dev@modello.codehaus.org http://xircles.codehaus.org/projects/modello/lists http://archive.codehaus.org/lists/org.codehaus.modello.dev http://markmail.org/list/org.codehaus.modello.dev Modello User List http://xircles.codehaus.org/manage_email/user@modello.codehaus.org http://xircles.codehaus.org/projects/modello/lists http://archive.codehaus.org/lists/org.codehaus.modello.user http://markmail.org/list/org.codehaus.modello.user Modello Commits List http://xircles.codehaus.org/manage_email/scm@modello.codehaus.org http://xircles.codehaus.org/projects/modello/lists http://archive.codehaus.org/lists/org.codehaus.modello.scm http://markmail.org/list/org.codehaus.modello.scm Brett Porter brett@codehaus.org Developer -11 Jason van Zyl jason@maven.org Developer -5 Dan Diephouse dan@envoisolutions.com Developer -5 Emmanuel Evenisse emmanuel@venisse.net Developer +1 John Casey jdcasey@commonjava.org Developer -5 Trygve Laugstol trygvis@codehaus.org Developer -5 Arnaud Héritier aheritier@gmail.com Developer +1 Milos Kleint mkleint@codehaus.org Developer +1 Hervé Boutemy hboutemy@codehaus.org Developer +1 Dennis Lundberg dennisl@codehaus.org Developer +1 Olivier Lamy olamy@codehaus.org Developer +1 Benjamin Bentmann bentmann@codehaus.org Developer +1 The MIT License http://opensource.org/licenses/mit-license.php repo scm:svn:http://svn.codehaus.org/modello/tags/modello-1.1 scm:svn:https://svn.codehaus.org/modello/tags/modello-1.1 http://svn.modello.codehaus.org/browse/modello/tags/modello-1.1 Codehaus http://www.codehaus.org/ org.apache.maven.plugins maven-site-plugin org.apache.maven.wagon wagon-webdav 1.0-beta-2 org.apache.maven.plugins maven-clean-plugin 2.2 org.apache.maven.plugins maven-compiler-plugin 2.0.2 1.4 1.4 ${project.build.sourceEncoding} org.apache.maven.plugins maven-deploy-plugin 2.3 org.apache.maven.plugins maven-install-plugin 2.2 org.apache.maven.plugins maven-jar-plugin 2.2 true true org.apache.maven.plugins maven-plugin-plugin 2.4.3 maven-release-plugin 2.0-beta-9 https://svn.codehaus.org/modello/tags clean install true deploy -Prelease org.apache.maven.plugins maven-resources-plugin 2.2 ${project.build.sourceEncoding} org.apache.maven.plugins maven-source-plugin 2.0.4 org.apache.maven.plugins maven-site-plugin 2.0.1 org.apache.maven.plugins maven-surefire-plugin 2.4.3 maven-project-info-reports-plugin 2.1.2 false true modello-maven-plugin modello-core modello-test modello-plugins false codehaus-snapshots Codehaus Snapshot Development Repository http://snapshots.repository.codehaus.org/ junit junit 3.8.2 test org.codehaus.modello modello-core ${project.version} org.codehaus.modello modello-test ${project.version} test org.codehaus.modello modello-plugin-java ${project.version} org.codehaus.modello modello-plugin-xdoc ${project.version} org.codehaus.modello modello-plugin-converters ${project.version} org.codehaus.modello modello-plugin-stax ${project.version} org.codehaus.modello modello-plugin-xpp3 ${project.version} org.codehaus.modello modello-plugin-xml ${project.version} org.codehaus.modello modello-plugin-xsd ${project.version} org.codehaus.modello modello-plugin-dom4j ${project.version} org.codehaus.modello modello-plugin-jdom ${project.version} org.apache.maven maven-settings ${maven.version} org.apache.maven maven-plugin-api ${maven.version} org.apache.maven maven-project ${maven.version} org.apache.maven maven-artifact ${maven.version} org.apache.maven maven-artifact-manager ${maven.version} org.apache.maven.wagon wagon-provider-api 1.0-beta-2 org.codehaus.plexus plexus-container-default 1.0-alpha-30 org.codehaus.plexus plexus-utils 1.5.8 org.codehaus.plexus plexus-velocity 1.1.4 org.sonatype.plexus plexus-build-api 0.0.3 codehaus.org Modello Repository dav:https://dav.codehaus.org/repository/modello/ codehaus.org Modello Development Repository dav:https://dav.codehaus.org/snapshots.repository/modello/ codehaus.org dav:https://dav.codehaus.org/modello release org.apache.maven.plugins maven-source-plugin attach-sources jar org.apache.maven.plugins maven-javadoc-plugin attach-javadocs jar model org.codehaus.modello modello-maven-plugin src/main/mdo/modello.mdo 1.1.0 xdoc pre-site xdoc 1.0.0 xsd pre-site xsd ${basedir}/target/generated-site/resources/xsd reporting org.apache.maven.plugins maven-project-info-reports-plugin 2.1.2 org.apache.maven.plugins maven-surefire-report-plugin 2.4.3 org.apache.maven.plugins maven-checkstyle-plugin 2.2 http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven_checks.xml http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/config/maven-header.txt org.apache.maven.plugins maven-pmd-plugin 2.4 http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-pmd-plugin/src/main/resources/rulesets/maven.xml ${project.build.directory}/generated-sources/modello ${project.build.directory}/generated-sources/plugin org.codehaus.mojo taglist-maven-plugin 2.2 org.apache.maven.plugins maven-jxr-plugin 2.1 ${project.build.sourceEncoding} org.apache.maven.plugins maven-javadoc-plugin 2.5 http://java.sun.com/j2se/1.4.2/docs/api http://java.sun.com/j2ee/1.4/docs/api http://java.sun.com/j2se/1.5.0/docs/api http://commons.apache.org/collections/apidocs-COLLECTIONS_3_0/ http://commons.apache.org/dbcp/apidocs/ http://commons.apache.org/fileupload/apidocs/ http://commons.apache.org/httpclient/apidocs/ http://commons.apache.org/logging/apidocs/ http://commons.apache.org/pool/apidocs/ http://junit.sourceforge.net/javadoc/ http://logging.apache.org/log4j/1.2/apidocs/ http://jakarta.apache.org/regexp/apidocs/ http://velocity.apache.org/engine/releases/velocity-1.5/apidocs/ javadoc test-javadoc maven-repo-local maven.repo.local maven-surefire-plugin maven.repo.local ${maven.repo.local}
    modello-1.1/src/0000755000175000017500000000000011260056263012562 5ustar mkochmkochmodello-1.1/src/site/0000755000175000017500000000000011260056263013526 5ustar mkochmkochmodello-1.1/src/site/apt/0000755000175000017500000000000011260056263014312 5ustar mkochmkochmodello-1.1/src/site/apt/release-notes.apt0000644000175000017500000003467211243357641017607 0ustar mkochmkoch ------ Release Notes ------ Hervé Boutemy ------ 2009-08-21 ------ Modello * 1.1 Release Notes (2009-08-21) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=14908&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-200] - Not possible to read older version of xml file if there is an unrecognized tag even if "strict" is set to false * [MODELLO-201] - XSD generator fails on field type Set * [MODELLO-207] - Transient feature does not allow generate self Model * [MODELLO-208] - class cast assertion to wrong type in one multiplicity association setter when using java.useInterface ** Improvement * [MODELLO-181] - Add @SuppressWarnings to all generated sources if Java 5 is enabled * [MODELLO-185] - add Content type support to stax plugin * [MODELLO-203] - add Content type support to dom4j plugin * [MODELLO-210] - Misspelling by AbstractModelloGenerator#singular(..) method ** New Feature * [MODELLO-191] - Add support to generate clone() methods * [MODELLO-205] - Allow to exclude fields from parser/writer ** Wish * [MODELLO-165] - remove classCastAssertion * 1.0.2 Release Notes (2009-06-11) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=15080&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-88] - converters goal generates wrong class names for continuum-model - won't compile * [MODELLO-188] - Modello plugins are not available from ModelloCli or a standalone Modello instance * [MODELLO-189] - Generated Xpp3Reader does not reconstruct modelEncoding * [MODELLO-199] - java.getter attribute for field not initialize at all ** Improvement * [MODELLO-190] - Use StringBuilder for toString() when Java 1.5 is enabled * 1.0.1 Release Notes (2009-03-09) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=14892&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-167] - bi-directional association makes an OutOfMemoryException with xdoc plugin * [MODELLO-174] - Wrong XDoc for flat lists * [MODELLO-184] - Generated XSD is invalid for a field with "Content" type * [MODELLO-187] - add Content type support to xdoc plugin ** Improvement * [MODELLO-172] - Add timestamp and the generator in the generated files * [MODELLO-173] - Ignore leading/trailing whitespace of field descriptions when generating accessor comments * [MODELLO-177] - running modello generation during IDE incremental build * [MODELLO-178] - add xml.format="long" option to read/write a date field as a long value ** New Feature * [MODELLO-179] - add a type column in xdoc to describe fields types ** Task * [MODELLO-182] - Make tests respect maven.repo.local ** Wish * [MODELLO-180] - Avoid unused imports * 1.0 Release Notes (2009-01-29) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=13956&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-126] - Date formats supported by XML readers/writers are not consistent across plugins * [MODELLO-141] - XsdGenerator should throw an exception when no namespace was defined instead of using the POM namespace * [MODELLO-142] - EOL is not handled correctly in the XMLWriter * [MODELLO-146] - String[] not supported in java plugin * [MODELLO-147] - fix for building with newer maven * [MODELLO-149] - Support xml.namespace and xml.schemaLocation attributes in dom4j plugin * [MODELLO-150] - float field without default value in model generates invalid java code * [MODELLO-151] - geneated java source imports avery classes, even those which are disabled * [MODELLO-152] - Strict parsing mode doesn't detect missing root element * [MODELLO-153] - Default value doesn't work for attributes. * [MODELLO-154] - xsd plugin does not honour xml.associationTagName * [MODELLO-158] - trying to generate an interface with a codeSegment causes an infinite loop * [MODELLO-160] - some internal links are wrong ** Improvement * [MODELLO-101] - Support xml.namespace and xml.schemaLocation attributes in xpp3 plugin * [MODELLO-102] - Generate model classes with JDK 1.5 Generics * [MODELLO-104] - Remove support for "model" parameter and make the "models" parameter @required * [MODELLO-139] - add encoding support to CLI * [MODELLO-155] - support ${version} in xml.namespace, xsd.namespace and xsd.target-namespace (like xml.schemaLocation) * [MODELLO-156] - avoid namespace information duplication in model: xml.namespace, xsd.namespace and xsd.target-namespace * [MODELLO-159] - improve xdoc representation of properties ** New Feature * [MODELLO-143] - add an option to xdoc to add a separator before a field documentation * [MODELLO-145] - Create an XSD for Modello ** Task * [MODELLO-21] - Move the Java plugin out of core. * [MODELLO-135] - modelEncoding attribute should be available in root class only * [MODELLO-138] - improve API consistency between readers generated by different plugins ** Wish * [MODELLO-136] - parseXXX methods in generated writers should be private instead of public * [MODELLO-157] - move xml.namespace and xml.schemaLocation attributes from class element (where rootElemen="true") to model * [MODELLO-162] - move xml.listStyle from field attribute to association attribute, like xml.mapStyle * [MODELLO-163] - transform Modello xml.associationTagName in field element to xml.tagName in association element * [MODELLO-164] - move java.adder from field attribute to association attribute * [MODELLO-166] - remove java.generate-remove association attribute * [MODELLO-169] - rename xsd.target-namespace attribute to xsd.targetNamespace to be more consistent with other attributes * [MODELLO-170] - replace java.generate-create and java.generate-break attributes with java.bidi * [MODELLO-171] - rename java.use-interface attribute to java.useInterface to be more consistent with other attributes * 1.0-alpha-22 Release Notes (2008-12-12) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=14742&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-119] - [REGRESSION] strict flag doesn't fail on elements that aren't part of the model * [MODELLO-125] - generated java source for method signatures don't follow coding style * [MODELLO-127] - Dom4j plugin should support xml.format attribute * [MODELLO-128] - add support for byte and short to xsd plugin * [MODELLO-129] - xsd plugin does generate an invalid schema for Properties type * [MODELLO-130] - Date support in xsd plugin is broken * [MODELLO-132] - char default value not supported by java plugin * [MODELLO-134] - fix byte type support * [MODELLO-137] - default values not supported for float and long types ** Improvement * [MODELLO-121] - Add xsd support for Boolean attributes * [MODELLO-124] - create a shared test model to check common features support in every plugin * [MODELLO-133] - add char support in xsd plugin ** Task * [MODELLO-131] - remove modello modules relying on components being phased-out * 1.0-alpha-21 Release Notes (2008-08-06) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=14469&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-114] - Generated xsd is wrong when multiplicity is 1 * [MODELLO-115] - Not possible to configure the file name for generated xdoc with the xdoc mojo * [MODELLO-117] - Not possible to configure the file name for generated xsd with the xsd mojo ** Improvement * [MODELLO-116] - generated xdoc doesn't display attribute when the field is an attribute ** New Feature * [MODELLO-113] - Parsing xml element with attributes and a getter to the element content * 1.0-alpha-20 Release Notes (2008-07-25) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=14466&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-112] - strict flag not considered for handling of invalid nested elements within an association list. * 1.0-alpha-19 Release Notes (2008-07-14) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=14339&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-105] - Handle double and float types * [MODELLO-107] - modello-maven-plugin don't close opened files * [MODELLO-111] - Binary compatibility broken in generated XPP3 Reader classes ** Improvement * [MODELLO-94] - Added java.net repository ** New Feature * [MODELLO-109] - add an "encoding" parameter and use ${project.build.sourceEncoding} as default value ** Task * [MODELLO-110] - remove copy of plexus-utils' XML encoding support sources * 1.0-alpha-18 Release Notes (2008-01-15) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=13717&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-68] - Strict parsing lists * [MODELLO-72] - Generated code should be clean of warnings * [MODELLO-83] - Improvements for the generated methods equals(...), hashCode(), toString() * [MODELLO-86] - modello-plugin-converters fails test * [MODELLO-87] - xml.tagName not used to generate xdoc and xsd * [MODELLO-95] - AbstractModelloGenerator#singular( String name ) could throw NPE and return empty string * [MODELLO-98] - Reader doesn't handle * [MODELLO-99] - When a class is marked as abstract the xpp3 reader still wants to generate constructors for it... * [MODELLO-108] - Generated JDOMWriter throws ConcurrentModificationException when updating Xpp3Dom objects ** Improvement * [MODELLO-45] - Generated java sources should not have javadoc where was not specified. * [MODELLO-49] - Support for xml.attribute and xml.listStyle="flat" is missing in xsd plugin * [MODELLO-56] - Major modello-plugin-xdoc rewrite * [MODELLO-66] - Create possibility to have the same set of executions for several models in modello-maven-plugin * [MODELLO-100] - Add hyperlinks to associations in element descriptor table like it is done in model descriptor * 1.0-alpha-17 Release Notes (2007-07-30) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=13637&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-92] - XML encoding support for *.mdo files * [MODELLO-96] - Add more javadoc comments in the generated classes * 1.0-alpha-15 Release Notes (2007-03-23) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=13272&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-46] - make namespace of generated xsd configurable * [MODELLO-84] - Clean list in the registry before to rewrite it ** Improvement * [MODELLO-67] - Add option for JPOX mapping file to be in model package [Patch included] * 1.0-alpha-14 Release Notes (2007-02-20) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=13068&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-69] - Validation of the top level element * [MODELLO-74] - Test errors in modello-plugin-stax on Windows XP + Cygwin * [MODELLO-75] - NPE in plexus init * [MODELLO-76] - Can't build modello-maven-plugin * [MODELLO-79] - Modello maven plugin doesn't compile with maven 2.0.x * [MODELLO-80] - Plexus doesn't call initialise() method in DefaultVelocityComponent with maven-2.0.x * [MODELLO-82] - No carriage return for the last curly bracket ** New Feature * [MODELLO-77] - Add a read method with a path to allow to resolve relative entities * [MODELLO-78] - Show an optional column containing the model version in which an element was added ** Task * [MODELLO-58] - update modello's parent POM * 1.0-alpha-13 Release Notes (2006-12-07) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=12956&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-53] - java.lang.StackOverflowError when generating an xdoc for a modello model * [MODELLO-54] - Generate tag name instead of association tag name * [MODELLO-73] - Xml output doesn't use OS line separator, so tests in continuum or plexus-security failed on windows ** Improvement * [MODELLO-47] - Create goal pages on the site that describes how to use the modello-maven-plugin * [MODELLO-50] - [patch] Add support for the class/field/defaultValue element * [MODELLO-65] - Add in the DOM4J reader an URL parameter (to allow to use relative entities in XML) * 1.0-alpha-11 Release Notes (2006-09-20) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=12790&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below. ** Bug * [MODELLO-51] - Xpp3GeneratorTest failed for date format on french system * [MODELLO-57] - Dom4jGeneratorTest failed for date format on french system * [MODELLO-61] - [jdom-plugin] data loss when writing repository/pluginRepository in maven's settings.xml ** Improvement * [MODELLO-48] - Support for xml.attribute and xml.listStyle in generated xdoc * [MODELLO-64] - Allow generating jpox package.jdo in different places than META-INF. modello-1.1/src/site/site.xml0000644000175000017500000000236311226420741015216 0ustar mkochmkoch Modello http://modello.codehaus.org/ Codehaus http://media.codehaus.org/images/unity-codehaus-logo.png http://codehaus.org/ modello-1.1/src/site/resources/0000755000175000017500000000000011260056263015540 5ustar mkochmkochmodello-1.1/src/site/resources/css/0000755000175000017500000000000011260056263016330 5ustar mkochmkochmodello-1.1/src/site/resources/css/site.css0000644000175000017500000000012211134661506020003 0ustar mkochmkochtable.bodyTable tr.a:hover, table.bodyTable tr.b:hover { background: #dfe3db; } modello-1.1/src/site/resources/modello-deps.odg0000644000175000017500000003140711130657465020633 0ustar mkochmkochPKAj&:.++mimetypeapplication/vnd.oasis.opendocument.graphicsPKAj&:Configurations2/statusbar/PKAj&:'Configurations2/accelerator/current.xmlPKPKAj&:Configurations2/floater/PKAj&:Configurations2/popupmenu/PKAj&:Configurations2/progressbar/PKAj&:Configurations2/menubar/PKAj&:Configurations2/toolbar/PKAj&:Configurations2/images/Bitmaps/PKAj&: content.xml\r6SʑN4IIH$X$q/OJhl hn4|&ʎeL;醪,Q_?],#nSUZH ~+0:+u-%e\.3rYK|p.,ȡdc\Xx/;|(mE4U|!MUb{Kz XNᰓ˷E¥pA&+HGV6%ՏɊ*e X.3Lc[K[n=sqᡩXX86f_ :O{*RٹsexJi*P;;W4 {QE\B/8 ;ih  3ΉsQwwe4~9ܐge2i@vhqK=sULp;ǐCN=' F+X PF`aA}ԦT.('xl(?1T꿙wj#iXaMur&b|8.pö9Ęps!Z&ERa  I} PP?Uv& kZPx 8%dUJsow='Ň?@kdڵhui50@|6䴓 94g,(ȢYy,{z+pz*p6?&qلtY $&MT~& cݥ3ʝT]g)@Үr[ز k\U%lGK^sj1C%1eCx(e{Rt+/!k6nJ_%Bl*rgCzxJ?B+8 r@-t7 bt<}h*x̀ A`Ϩ'^rlj7%gxWBD-A?W Ơ'Gvve Bkjnبm<0΂ӑ{@4ƕ7& N*0~8dζe>kțUlّ&4%Uq beJ)b"h~`EA lmgYsP !@9D?6STP߆??jzN#4ɰ:}#(vt=|#fK;7=ʌ3_fDўx@4Lt2L fcZڏ*iC9 fGɸD}mEUk.FylӘUEal4@ANgV=~-X3%"eOCG;d;Q1kCĜv=w`9ߐ3'Fw$LEEE,b C w1/9`bn.Y\0fb:z=idրjWw\L"]':-FCH!cн.zә0R\߰/g#99Y3ϋG3:$f ҐL8ٷo'd'- 4CZ?_<~3O)hg`0q 䊎R|es_M 3(r;p_Nq.4_.:@w9mbo@b/1u#dDY ,1)4neٛdYNβatTzTιfRe+x1\30wWV"7.!1oយs 3 {~j2D\"B+,+_غ%c%)((((%⾰{iP\9bz'<3]> w_d,썙ۋ DAo}A_Voj+/ :Sp})v0kbҾ2]_RĐY`j=oYtPܚ/tIDaSls4YCs?K>`:&3N!pEkSگ ٖvśa8 ʘ&p!XaYhHfqvɖi urh䕝$IEKК I9Hocĺ"E *MC"DX*sRleY8fҮk H!!yb)[,֨B'쬷,^lXц _\582*f7SYN[3O2bn oo۶pi#4SJ2$VTbЪ>Pj_>VҎi'KL -x΀ӄۈՌbHMS\/!H.pbwntd 'PIct]Lm:PkXPz{F\Rۄ#ǵJbQ á|5Grϟ= š !+_-&AѸnq3 !!5Tt4Iܷ+W4of#0b(ܱfF"4QCٴGMBEle?vW67a$;dAh#a$;da$;dH93@ٝPa i_9\WJ󮎫&hs#鈦S^}ÿ89i{8( ⛞=f4C OpenOffice.org/2.4$Linux OpenOffice.org_project/680m17$Build-93102008-12-20T23:12:092009-01-06T14:16:4415PT4H21M56SPKAj&:Thumbnails/thumbnail.pngWWWETRTT RD@@=HNC H #Ћ~H""= %j/y^g9{{nEv=]-aa9rDU"pi=2{;·z۷n}fkF{&}N*EkK}k}9 Fՙ܏jp?l9Oͧ䩜g]!oA#Jihhm~yXe u]*"\W:Wr!"٤1Cw9!!aSbm<zmMe2oXXq2Y4,khò_mkiGP};UR/]:-SrC7e!RO7GP+uC&/x4Sr,` v&jJ[2Pt9$D:#SWm ~&.Rj&XpSU d4B#̧ P,b,`aοD H|Ldy!R DyȻgT7KwUCDhUH#kJ;ZD,K-L㸬+um$a`6O}N͝Â4֯zЏJ'8J0+Y DN * RMFfEQwsӄ.qKoZL[\[+cW8#m,5o,s{L 8MLĺBk~@쥥a @(4qD`>3XE3»m)Y Xad]zht_O3,> eBpa>Ш?Kfdl0u5e/̐o[Zd*H&-M܏9aIkKWM-kD3SSCKi2n'">Evb/| MҐ%zQAA3(h",\M=? h]gYuf8eqي麮.=[ 0hQ3:\Gsj*RFPQkvJ7!. 0c/6?G*c%=;8baqmzx]nui`-bmnDpK 3bַ d=GTV+˩n Pl$t4_V T&+#pMa5+Ɋݿ&^u aV<gvI;jR~[8^MN3&v{}͍7oa2\dKBbKm27C% k dYqn[vVgZjҪ086Uow^Ѡ:/ӽǣ`.fQwa+7HҰ"D_jI g.~Z{!Z9G߯\q'}@2+- Jj;jY:O7 ׋!lni* 3ȇ7܅{[4)3Ge@Y7UWo:XOq@?ſWt! ^Mng$痶S<1lK`GҎ]Qˢ O>U([M`;_zUt w>6֜ Z\,)KG0UF;eK(~h$A,y&*Pf3y)ˉhT,HeЯ]b.j5ʈ%Hpa?3Wa< P '<*u+9G=Fyi]9Vb +> HR )w#V hf.4YpuHqLH[#I=0ܢڵ#ZE@uŢI_ 6mW5iiɲ["I :P0wmKcDoD?8KKm|o ">.U4t5pXE<&Ι|SH,QaDm) Xڅox F⪷,S%K)F'TMuWA qMeud2Y['}⚼M cBb%SZ9\{: 4~M%Md]L13KzƦ/ޱ';Ch,I# 3f NJZ9XU47)uL8j`ՙ5t2LtDk Ba[ݻ>(B -[˂Րr|S}r_j숡^mBIU-||౷\w9XFǗS.`뮴Xg:^q j^gwk?}_2چEʜCļ~4G?wL*.V#JJy8}Y])DDuq5}uM]IJcV5 |(PUj~hyqn-PTZW\@/;]y 5?m3įhxf˛ Lzэ1B"ec IK;hx $"j"H:HG6yw2UZWd \}9J`qOۇpmM4>].j Q/K&Ame~Hi"T6rRzچZ/" PKO#RPKAj&: settings.xmlZms8~"wsC0$i 1aJ(1/iMXP%$cȯ?@K4T7ws|gW]-\\lBn¹m8&lrc ckL<(c>0"r&˫+̑$̐2mgՓ%lvcM |E9|T*@PH%GfLEY^9&t`X"xѶ/'Xxn~e 1 z[.Xm7&\]}?qwcis7OfDd# x`m2Ѓ)+Ju~;R œV4 @&TJ|ðQ5{!j1Jh r;c) fUlw- dCCbB̎$~)'r|O5~9K#2=[0-_sޓȒݪ 4F!=NɶutiQpeDk{tR']|$eU !V%Í,= H _rG?€]^x!ac'w }t Mhc7n8`+ڲJ&8IhP۰F7B50$')bpN:}J0G664m WHzf gjo;SKcbp#FpwƑpPmZY|?,iM]ܸ" $ N }Hq!GOt8=ѣ-:i ih7-,X3όԘr3 Ҵ}^PWQ aON3[<󍜚O # by*̪nJ^|Fțeq+ȬMk+AoeW$%C2&1z7f0 ݧD`8r]@3@;@20d{-u޼0ow ɅRo}Ni?kI!Dn) D[o:'vr3&ʣl8 c5OL9^ytT[18 Ն;q~ܻצ>8Ν3Wi> l|8}DV~;.Õ]6V/qP {c5;Zz/NV}E#븸{K[m[s[CT>4jݺ1s)4)n5> [M4 Z#FKa0ZZ(Y侇(dsMzG7X!'%d~"GD_*PK3kA#PKAj&:META-INF/manifest.xmlKj0@=VU1q-&fW6X; HFi[S0Oͣ)k7vc^aaӠNZu`ZVzEdZ>T yb`yʝ뛣V4cՊą0$c.mʛwS<&Bϒ8b<(sT)i]EX|H!_Tʝz18{oIjN7IQׂpqr՛5\AkagMv@|6s-,2O\څ'.?PKANPKAj&:.++mimetypePKAj&:QConfigurations2/statusbar/PKAj&:'Configurations2/accelerator/current.xmlPKAj&:Configurations2/floater/PKAj&:Configurations2/popupmenu/PKAj&:NConfigurations2/progressbar/PKAj&:Configurations2/menubar/PKAj&:Configurations2/toolbar/PKAj&:Configurations2/images/Bitmaps/PKAj&:& N 1content.xmlPKAj&:ZrE styles.xmlPKAj&:"PPmeta.xmlPKAj&:O#ROThumbnails/thumbnail.pngPKAj&:3kA# 'settings.xmlPKAj&:AN-META-INF/manifest.xmlPK/modello-1.1/src/site/resources/modello-deps.png0000644000175000017500000005261011130657465020645 0ustar mkochmkochPNG  IHDRFT8sRGBbKGDC pHYsGltIME %0+ IDATxw|SW:YBH-{,Ȑ!"r~JA eyEE AD("!{=e[Z:4i|-͍Fo՞c {%ո{P2ֱln&Ad  i{wo\aԛ)T <_+gk=sK+Xg^+#v}:BpIMO̙}5%{{r<͘)SGwUy>^y[#h=}`վܲXˌmQ n^>ESݮ-//!2c[l$o1'"" " AUqAO)_wϜ444 Ŧ{G@XStRs/&o^D{r}RA+_;R\u\\(R],0 o{iv˪}o?l&6݃Uh?V])x݃r5qe#""4uDDLJa=G./~+~Oj^WѿIt?͝_8y55ɡ߽Iqq}t8v$Jr;/:h_*s-qqI^:{T2MHǯF}lhSڿb0hԅEDH#"b3kvr_݃o2q ]FgÉz ..lB ~dŕ}"ܥ"FM#ƴ YC*F A,dlD$/5FѐT6 ƴ$"my!x/GA;6&W7w|T̡شj _۷|pqƯ>Otmצ=Lܷ "%+&`h4F<# |C+ 41~FNk8hHF#A$e#n~ofObcص">FܞCͫ|?u0A>8aѸ9ؘhNެRW "~8Cxb$ |-OizЃY[<54-"v4gܸ{ 3;az`òi:.kJrq<:/&SW7r-@Z3lv?͌ާ?tWpus۷(:f /yRShئ*u_ȹI.37l]W7wF$i\DhqC_ҹb.or 7cx dܪ,mu+h\D#""6~/"n֖yr NzH|ٿƚTfu`M+(h iщ?W|ɒY2}^ mJ!Q]\DA[D$h;dKcE\9sQ/\5;#,*vɸ:ft8W@ qhK:dm[6(mՖ")ӈ8-G~b0X5z.-""b@/qT@Qn/гS8w7l """ ੆8 KjȎBqN Ŕ7ׯqYWzm;?aD#, t_ ٿzӦ-"-`:VVz㦠-"-ztQч!ED!CN+#ª#mqlNvުo+m'9+:mq7n-m7&QQ2l~x찍5omԺLjw=> )""")rÀ_YQ$aftt,}~K޼P@FZ͛m_rKe>aafXb/w?<ԩOÆT`<=# `8?v ã7Uomhԏ~?ԩ_fcM'̟Xv@ۻvkz-ݟөS8ظq#` j[1_h4gߟn Or]MV4J>>--ݟO[%Z6ݩҥ %>)3gIXwJmZ],5K cgFl;+U*>tQcX$͚z?"E%]R8iD[DDΝg믑ܿ?c_w%pX""3ztKV~4'`DDL'2r1rٳ_9-@^ 2e=wgKo1ԫW~;ʼy[mwOqDDL'8?^ k׾OT nB@gdʔn>ӧ& [5RX~ב_2-T鯿J1oɿpJ*HHPfeK:ĉ|Nks_r.81}`ܸfY2ݛ2 FhPKcNen:uKp^$y~_jbG'={γȆ 9|2YDGR0b"92lل}~'יp{k?^|ikѢŴי_m;6Nx],GRZǂhQ}^zi**<ѣ%[g 8~۶ NR)KR8/#""bj(a+ʕLqWܥUs.ɠJ3aZV>odCܼ-qsɓ(U*8m-{L_|pDQ ~Ѣ x@IJh<`~,!d=چQQ1),g5ۙ_2-T9-zÔX?FEDiaBBP_6+>4kVkcV>VhQoӲ>?~gmdöm4jTM'XH1 F"ɗ/'hgٲ:t4iRt{H i~Io[2,YcǮe)I[2OR puHvY0na"#ٻ<:5v=G:6}-Um~.{'&&W<{ ˚e=ccټ$={.]>7>}ã8|2z-N[o>Ŧؾ=/i __֭?ܯElJtt,!!Mhٲjf?[@~9g)Ceˎ4'eI hD[DDkUcѢt<Ν'4o^iҥ;)KӦ̖69?Ԫ5\<2_ {QDӧQgM AVq4eɒ;v5sS-T_ }+q5֝dv_ٲ<ɚ×Y|7!!lل*Q(}8{v|րFEDiM֖$wnOrpgX]ƌi e]]]xzO45_ _&Biݺ:۷F?4-ذa@2 z5'79rU;srdƁtVJjLgK92_̯޹ J>(Z774aaϟ+YO=mۆہx{ÍZ :v|SߦT5_f!l.UΝI@pJ,Hh8m K.m;+%3k3㼠ml} Onߎ 66GЭB eD2RTT _xXN-"" uT/޽л bVj$~1k&jW1mZ[ʕ+̢E;8z QQ1++3bD ]Z/ݕ*U:mOm`мm{і?V+EDo.""b+08KG(4-"" """"" """""08-9ٚ6b}$0Z&FӇ!EDiOr"KJ:"":(h(PyrT[""-""""-""""" "$LѴQqfH[m@I[DDDD$\-""""Q -""""b """"" """"" """"" """""-""""-""""ݸe3׳W k@DAf Հ_R:"""""-""""-""""-""""" """"" """"" b@/ϑϗ-?~h[i6]j.ߧNΆn\>!ma>ޯOz4DA[}"vlCM5KحkwDu?{71+H~e/UmyP۪ן?u~Hߗ\9G3gn~z2k秙#Ӣ:[Fn;[!" c%Ļ9(h;yoQYQ7M7wo\豖~Dx9OuŮ_5[6%vA>"}f@,Ћcͫ,۝M ҧnN@T?I.q˧c+%]ǃ[ݧDͷAo\UF,Ʒe݅Dr8dΰ}[]$ErhidfaZHxӻj(FQ^L[~=Wi{T >n nOP!Ԁh`ΰ`r~F 4V 3+ԑd,ԇ xqjF,Kӵ0N}xtc{jx;1%woo01xNwIݟƥPiR?ws%[Wے87J\^lr6|kEKw39{di[oZPZ|1uZt⹖]X0""=uZȜZX9}~1=ЃS|ӗ#ynu<tiԾ|;/j6S%ui~6/ ۴\ۢ4O.v4|K3'M;,϶t>Aٚ ᗉ}xpaG9WlI4i}λ70+ݓ>1qxXO)UNTg1>^9r|,[~KJaiD;q3@epqMPLc i0XA?7w4=.9<鹺'^CXB[<3gmBmi3)}GuaHGdFPY[&DQ(]yDF`(Ʀg%o'=/Ëe|,?ls0RXim~ (h;>oEJVL.:h9e8WOV s&yOd'q[nOۧHI")Jvg\ySn K]vHvy! u[u5{#m3sA*ra~=>R[np 4p .V(h;Ezpbc9o3y)O{><~8CxbDz#vOi<~MDsN JlZ?\'!ZM}Ju,̨#2_+MP?W|Id=FSFL)auD?tDmvm%Qz=Jٚ ذt*vmPgQ['Cj%?~̽[׉S,4~~/wT 9 fb:fW 5xZilV|>r扖ka;-c֚u߿}|Ѽ/ ^2}Vr &uk>R ǯJvg a,؛%{ݗ0_8OBܻuQoǧ?W Eՙ:'Zc{\9`LWR[UϏ8`+̖+Sͻ U dO<]\-J΃0k9}LShئ*u_ȹ̙s6Rn.;U/ H9ÓAs6ҰM/Óߢcpfoߢ߷M}\̫Z'\ 󨹔Pw{twF׏,Z W77n;x3gn=rPޝV=9޾vvCp._L½nmX-@a>\_?(;вh\84`|٘mvϐTetW1UJ2nU1q1z]q.h Nc]X۶"k@Ljw!++̩,~/LjrQ~ H|i.A.ԶQ=,PE'\eoœx˦3]R̿b-ՅV#"-Ik;dKcE\9sQ/\5;#W oPc]DhS\Q _D23sj (h(h(hd[Ð=$A(Q _o dfvA;;w@]t{-:]}eNª5'\ϛ*E샂V'bd`O׏Q [/5ڝj@?xONnj@DA[,l%5 Ξ5 wScՀyJ`nՀ(`KV5 -N4ڭl`miDIVjrv$sCùµQ' [֎h[5 fiGՀ8iJA^ݪQVN_DEannQr`}Q445M`S:^Ψ>SQnǬmjKֶ+QyhcR(`;{UDE,li[5-Ym?m [vP>3_EE"li~k@aBufd(h8dh}6pQqnՀuVU" "N4m_5\S6\gu+`HAQg [p5ڞe[io = X v~ɮ\Յ#mF[ן?9ADVp,mlz–ovg] (\YT:"mg IF-a[E$Kv|[#X27/ӛO&_">w?I~bpJWY|5i٤pۨoݧ8} wϜj/ϜS.3Shy0uZt2[.7g {7$U,BoҲhrg2,OexDZin^>ؕ'-^X3Y;_"_"" )=qn27c=ltn[4}Έ>_NDѴ[(czp& ).P|Mڷo'\͆xgx5{wyn\ 5 ]aiss,fi]X;[sf[k-!gYhJ7ş0dVflb-f:/+O0}k-R}/ 's+|_=Z\ =B:/$n/KnD=ضky `);UeĒ}|#1Sz=%ڟ"*1mk~cnsn`1c[_lGa3ذlZ䨜3'7;55fvO՞Ϲi=G q݅0Y` B-^`ƶ('$>[xn\o1YZkǮva3\9nZNߝce7$aPj]=(W!G̱xmL÷DY=sҴCnYTm?3W:an#pҴ1x6>՞7ڷaS-Pؘhv_oQ5hB{gREJUfq:2Xg<_qtݾN6Ug&lexHz2xgx< j&#=szP1M?Ğ4n>i|G: M@gpsltDl^u5Y̒4wXS?fԑJu]z=1sYj6@ZʣwGy `z\S"L߸\jϛ^6߸|qus׺vl^Mor(d-woҲh\\𫥒ܦK&p@T*#ۦ',;Gʑӗ#i=&#݄gxȎmTn!7ZM#=sS:vxݱЃ)R5(m4-=׫.&YRk֬vq3qcG  *4,ssHpY#I;X=_Ņm[ď"R5G\tnKm4;[Y[&DQ(]yDF`(Ʀg]Ji:Avm;Ofא#i=Z|M97ۤN.s9^N, sckVhFFO@SȰF#aO&5Z[,O_!TxdȎts).:@@.WЯ$W-T|EoHU@:8u-gTkه}pqƯ>O Zoj7ڍGve$:4Bgv \vIrx]&6qk6Ϲ?ΥS TGvykgz{7QnGmrh{͖띭.%YRkoYxѸ9ؘhN;T?-?~Ep.f^ |-OizЃYFܞCͫ|?u0A>8wQ^;"CZi K"#Ql5=4ےpnKa;zg֖3\KϷY}=k/21dVlS9ki=<qr&bc9{x'%ZfKV, Ks5ckVh{(ĮunH$/f٬|+>`"Aعn WKrٽ~9aKݖ6R۰kO0{]w%ʚ>]k۷(w_·x*<6ya#0c-!}ɒY2}ʐL_&KR9#F3\KϷYy΍wcˋc͝nc2]5¨eM\8Oz<:~#luai~lͪ>뽂;޾Eiy0fmHqNpShئ*u_ȹ̙s6Rn.;U3]JΒyi)F`卛k4;mѴ\./o[}-}Ѥ [=Mׯtqq5]dA3̓BhҾ>Eqqu#wT5lx{T -dezDQs)Q&9pȁ_*4:-tp]o[.<ڝ#Z[N.֞s-=f9wܾvvCOl7d_4'7OH6_7O_|pszg GbօÚ5`|ro 7cx dܪPUXPϋu֑l#gUm٦xGODZΛ::ǹ-pp|Q~Lj7kK6jh;M'ɸ6L*&58VI]oGԥU "" "6 -Ȧ4ȘU$ գݖ>pe, EöBVf];=.lOE/m 2, Xio'_֮7G |zR'A[2SMh:O֎vgkT;P[8_R:o*P+h+t׃VF3˶oD}) ݪl{ʪ}N !Y L}@- ݢW1lk(h+tUd[ ):;yr}ք,sJKﳶ%;E[aL+WլU՝(h8A>;uBu̜r.'tsē: 8@_oCH(hK""Pᘨ@--ua" "ڞq " ڒ B[HNFEE2d@An 0oT'޸bc-+Չ sX]~ht ~r3IAOEpq{_=ozÖ,"7%Jӳ /Ju]Ğj!ǥ nOP?cvuK 40g[fͷAo\UF~&6mg.D"$s1'iD[M I}YyoaĢʛ?] ?M?xS~i6}? c\,X=?}9[Wϳ/M_S>vm 6JU}δ!ܸJg_ķxhɩ}vr_lHJpyL썷oQ:myc -ş]޾k\\\2z]l]_D2Fšó[k-!gYhJi|2o+3E1pFxO'5݃iڞߗ~n _ӷF0#$4x'֘?/a^8c-G cŚFY C;/՞cX27.ӷFвhڴڮ "- ٙ'6uAuptp+ӽut Cuqs\͆taht!-QwϜ4[iڞ/6c֮8*fŬ:pT5y feD? 6&[j ZY.G㬵Pvcωlj=i}*>4Ѳ͠X٪{I~DGݧ/gNuGXi "4uD.eJu]z=sYj6|?KW1+oqqI Nwo\aFV;'}Fc\y?WS YKݛ1W7h^owr傴oߜI fb:'6W }}LZA_?U<-״ L1sPgj/QS7':≿L?[F}f]{wX0+>\6f!X0  "QAqm4bÆCX]-[[o5AJ AW//o$""u~䭷i}/\gpz1c0kV,IϞmٱc37ٸ~)N"f' nx7=IDATY wɿvOa^烻G}#&Z3gnHWǻ n+Wc<$簅my9G_J,XtҊ'-kUPQD)>h ҥ˳y1j*Ε+Xj+ժf>WR8??sp#n^9V+ɸU6yz=``֮8@CWȨsZpdHf4h %JX1'n_jym+)'i}ϠRjE#M?[nnuo4[![2  4/M\\,WeG݀ėz(1p|?]M_-H)hת~ ۰]FgM׮|Wru =e=k<ܣkN:Zk33n߾JLUE' 3nW%h2ڲ)߹6k#q-H\}@EiFRh)<qusx=h:"ׂ_hw. _v S|> ر;Tlٌ_m۟Y=6eJ*ǖ-U1N #ʌ9x/"y#M#;vl6.+><<':)'*d2߿b;va_&6>~\vӧ3v`4DӦMǥ )*GzH63{ T:"""""-""""-""""-""""" """"" """"" """""-""""-""""-"""""i`v~9C[?wy*:NNfEܻaݼJEMZMpFf zb1`:"agr}|x坑{PgU FQ ]^qny͇ݺƿ+2z>u[u?wԽ.WB$Zh2o+9ryv 5p|ϼ܁c A$y>N4`pq0UH[,W+OŦ{]h's%bflb-pA-h"*1mk)d_4sGvSʳX/wD3faTѝuER}."\;wS_/""m[UoOqyDFtr |i/`FlL4xBOosh:ss^bcy&(=CDD*Hvz;n^5y5}~ó-:ОY?h9epro_RmpLZg%#G.BT ]OD>hD[DV^6&7nWEФL! 7C>xՍh-NS}y1t^MçwAQy_M7e`lsKiZ2R-F3p CqBcNNEc*4Y zc.#A13g|+O/ 毈)4!0pPiw6n mhm 6@6N;&XG? tSG6@pX}kbpM8mnm DoA6 hmyTm xUlA61l6.;&d~ƋM3E9or#A hmm `1`0\6yS]AOT?Ǖ!Q2m7Ez]bJd ɾZXvnuvjצt?>NK'jYPI[~v?}sw{}J 5xQO?oi/)-Df.UH*;evm`{Yzv۶#2Lz=SiSz.._ߥ:t&O^-[Q:ڭLci 5^ذWlHS_\h:NYdYJec6WvJsmWA!IRkk ־#zZ;4}zjj56^RFn9Ҡ{_A99qB?7Mvƌٳ*9yF?8Jvm~{UY,eVsUP0z|}Ej]+ێiV|\c#ّޕ/I,.ޣw>n-Kˑ$=qJiejk{G+Kg}iԃޥc^QGF?jϔ_-I1OjnjѢwuZ/~WVys$iϞ8IRvv9 hd_$陌 'B^  $IY$I"Iڿ5K7廋 I56e:a׾RɉӜ9KSi%I%%}/Y\$ig$//xIRQa{3Ջ/+:z\˖ЬY8 $ee׆ tbfՙ3Q©#څ$I>?E$iA[*|}-et㫚Ĭq)1vq7:{܏+Iԩ Ps՝q?#cLiի8zk,)TYYꫥ2*%e|x6'>r?M}N>UV1kѪر @WϏή;;?VhjJs[^?$;k0lީѣWjӦ &6g 'Am7l&hJlꏪ[FYC"6*}iM>~ }HHN ZiҤ=ڠ_~_=#|l657[5| IFSB%$Lѣ ڱVkUjjcP,Nt=U{9NgOԪU5_:ePV Ia2EtemmtOxW9Ck<ĭ '~HIR\\jkN?߬w`0iƌ,{Z#EGUu ܭU^~;Jl?+)ik~2LڸZZ  I55a]êYWxioEIR@`2>hujtD"JA"UQ}WcbUo?epX}+ ͖;@5N Su= VervnjZ'~~>Z }}x 55]ѧW3 CÆ R]]FSbVhp?q)  WV`Qи c&-JӘ{'(o 9iqu_JKG'ooO5B˗VyyF>>HTJLC5o^,4EFvU髯SvBtbM@II0XFyd>2(/o&N#[F&LSiisTXu`IEpމ+YsUx\}6m Ś?fhm >\pdžs c~.IENDB`modello-1.1/src/site/xdoc/0000755000175000017500000000000011260056263014463 5ustar mkochmkochmodello-1.1/src/site/xdoc/index.xml0000644000175000017500000000512311137131567016321 0ustar mkochmkoch Modello Herv Boutemy

    Modello is a framework for code generation from a simple model. Modello generates code from a simple model format: based on a plugin architecture, various types of code and descriptors can be generated from the single model, including Java POJOs, XML marshallers/unmarshallers, XSD and documentation.

    modello-1.1/src/main/0000755000175000017500000000000011260056263013506 5ustar mkochmkochmodello-1.1/src/main/mdo/0000755000175000017500000000000011260056263014265 5ustar mkochmkochmodello-1.1/src/main/mdo/modello.mdo0000644000175000017500000006707411243356565016450 0ustar mkochmkoch modello Modello This is a reference for the Modello descriptor used to describe a model with Modello.

    An XSD is available at http://modello.codehaus.org/xsd/modello-1.1.0.xsd.

    ]]>
    package org.codehaus.modello.model.self BaseElement Common attributes for most of the elements. 1.0.0+ name 1.0.0+ String The name of the element. description 1.0.0+ String A user-level description of the element. comment 1.0.0+ String A private comment about the element. versionRange 1.0.0+ String 1.0.0 (a precise version), 1.0.0+ (a version or higher), 1.0.0/2.0.0 (a version range).]]> Model Root tag for the description of a model. 1.0.0+ BaseElement suppressAllWarnings 1.1.0+ boolean true @SuppressWarnings( "all" ) to all generated sources if Java 5 is enabled.]]> see org.codehaus.modello.plugins.java.metadata.JavaMetadataPlugin namespace 1.0.0+ String ${version} placeholder, which will be replaced by the model version during generation. Before Modello 1.0, this attribute was in class element.]]> see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin schemaLocation 1.0.0+ String ${version} placeholder, which will be replaced by the model version during generation. Before Modello 1.0, this attribute was in class element.]]> see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin xsdNamespace 1.0.0+ String
  • if this value is not set, xml.namespace is used instead,
  • this value can contain ${version} placeholder, which will be replaced by the model version during generation.
  • ]]>
    see org.codehaus.modello.plugins.xsd.metadata.XsdMetadataPlugin
    xsdTargetNamespace 1.0.0+ String
  • if this value is not set, xml.namespace or xsd.namespace is used instead,
  • this value can contain ${version} placeholder, which will be replaced by the model version during generation.
  • ]]>
    see org.codehaus.modello.plugins.xsd.metadata.XsdMetadataPlugin
    id 1.0.0+ true String Unique identifier of this model. defaults 1.0.0+ ModelDefault * List of defaults settings for properties of this model. versionDefinition 1.0.0+ VersionDefinition interfaces 1.0.0+ ModelInterface * List of interfaces provided by the model. classes 1.0.0+ true ModelClass * List of classes provided by the model.
    ModelDefault 1.0.0+ A default setting for some of the property of this model. key 1.0.0+ true String checkDeprecation, package, java.util.List, java.util.Map, java.util.Properties, java.util.Set.]]> value 1.0.0+ true String The value of this property. VersionDefinition 1.0.0+ type 1.0.0+ true String field, namespace.]]> value 1.0.0+ String field, the name of the field containing the model version.]]> ModelInterface 1.0.0+ An interface provided by the model. BaseElement superInterface 1.0.0+ String The name of the super interface for this interface. packageName 1.0.0+ String The destination package name for this interface. codeSegments 1.0.0+ CodeSegment * List of code segments appended to this interface. CodeSegment 1.0.0+ A segment of code to be appended to this element. BaseElement code 1.0.0+ String The code block. ModelClass 1.0.0+ A class for this model. BaseElement rootElement 1.0.0+ boolean Indicates that this class is the root of the model (only one class in a model can have this attribute set to true). see org.codehaus.modello.plugin.model.ModelMetadataPlugin tagName 1.0.0+ String Define a tag name to be used in XML content, which can be different from the class name. see org.codehaus.modello.plugin.model.ModelMetadataPlugin enabled 1.0.0+ boolean true Enable or disable generation of a java source for this class in the model. see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin abstractMode 1.0.0+ boolean Mark this class as abstract. see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin javaClone 1.1.0+ String clone() method for this class. Allowed values are none, shallow and deep. The value is inherited from super classes and defaults to none if no super class declares otherwise. Since Modello 1.1]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin javaCloneHook 1.1.0+ String clone() method. The value of this attribute specifies the simple name of the hook method which is assumed to be provided as part of some code segment. For convenience, the boolean literal true can also be given to use the default method name cloneHook. The hook method itself must have a single parameter whose type matches this class in order to receive the cloned object for further manipulation before completion of the clone operation. Besides, the hook method must not have a return value and must not throw a checked exception. Since Modello 1.1]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin compositor 1.0.0+ String all all, sequence.]]> see org.codehaus.modello.plugins.xsd.metadata.XsdMetadataPlugin interfaces 1.0.0+ String * A set of interfaces implemented by this class. superClass 1.0.0+ String The name of the super class for this class. packageName 1.0.0+ String The destination package name for this class. fields 1.0.0+ ModelField * Fields available in this class. codeSegments 1.0.0+ CodeSegment * List of code segments appended to this class. ModelField 1.0.0+ A field to be defined in a class. BaseElement getter 1.0.0+ boolean true Generate a getter method for this field. see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin setter 1.0.0+ boolean true Generate a setter method for this field. see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin separator 1.0.0+ String blank.]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin attribute 1.0.0+ boolean Consider this field as an XML attribute instead of an element. see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin trim 1.0.0+ boolean true Trim the content when reading. see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin tagName 1.0.0+ String Define a tag name to be used in XML content, which can be different from the field name. see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin format 1.0.0+ String The date format to use when parsing/writing a date (see java SimpleDateFormat). see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin transientField 1.1.0+ boolean false Since Modello 1.1]]> see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin alias 1.0.0+ String Alias name for this field (a parser should allow for this name instead of the given name). type 1.0.0+ true String boolean, byte, char, short, int, long, float, double, String, Boolean, Date, DOM, Content.]]> defaultValue 1.0.0+ String The default value for this field. required 1.0.0+ boolean Whether this field is required in model or not. identifier 1.0.0+ boolean Whether this field is part of the identification of the object or not. association 1.0.0+ ModelAssociation An association allows to map a field to a complex type and/or to map a field to a many-multiplicity element. ModelAssociation 1.0.0+ An association allows for mapping of a field to a complex type, or to a many-multiplicity field. adder 1.0.0+ boolean true addFieldName( Type ) and removeFieldName( Type ) methods for this field (only for many multiplicity association).]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin bidi 1.0.0+ boolean true createTypeAssociation( Type ) and breakTypeAssociation( Type ) methods for this field (only for a bi-directional association: each class of the association has an association to the other, either one or many multiplicity).]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin interfaceName 1.0.0+ String add, remove, createAssociation and breakAssociation).]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin initializationMode 1.0.0+ String lazy lazy, constructor, field.]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin javaClone 1.1.0+ String shallow and deep. If the value is not specified, the clone mode of the container class will be used. Since Modello 1.1]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin associationTagName 1.0.0+ String Define a tag name to be used for every element inside a multiple association. By default, the name is calculated as the singular of the field tag name. see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin itemsStyle 1.0.0+ String wrapped wrapped, flat. wrapped means that the content items will be wrapped into an element, where flat doesn't add this wrapping element. Example:
    <wrappedElements>
      <wrappedElement>element type content</wrappedElement>
      ...
    <wrappedElements>
    <flatElement>element type content</flatElement>
    ...
    ]]>
    see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin
    mapStyle 1.0.0+ String inline inline, explode. Example:
    <inlineProperties>
      <the key>the value</the key>
      ...
    </inlineProperties>
    <explodeProperties>
      <explodeProperty>
        <key>the key</key>
        <value>the value</value>
      </explodeProperty>
      ...
    </explodeProperties>
    ]]>
    see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin
    reference 1.0.0+ boolean see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin to 1.0.0+ true String multiplicity 1.0.0+ String Can be 1 if only one such child is allowed, or * if any number (0 to infinity) is allowed. 1