pax_global_header00006660000000000000000000000064116665476600014533gustar00rootroot0000000000000052 comment=f0fd6352302d4ac95ddb6e68cef9a55092b97a87 modello1.4-1.4.1/000077500000000000000000000000001166654766000134145ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/000077500000000000000000000000001166654766000157755ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/pom.xml000066400000000000000000000030101166654766000173040ustar00rootroot00000000000000 modello org.codehaus.modello 1.4.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.plexus plexus-utils maven-assembly-plugin jar-with-dependencies org.codehaus.modello.ModelloCli modello1.4-1.4.1/modello-core/src/000077500000000000000000000000001166654766000165645ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/000077500000000000000000000000001166654766000175105ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/000077500000000000000000000000001166654766000204315ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/000077500000000000000000000000001166654766000212205ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/000077500000000000000000000000001166654766000230135ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000244465ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/Modello.java000066400000000000000000000051701166654766000267070ustar00rootroot00000000000000package 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 ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/ModelloCli.java000066400000000000000000000077431166654766000273470ustar00rootroot00000000000000package 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 " + " []" ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/ModelloException.java000066400000000000000000000031141166654766000305620ustar00rootroot00000000000000package 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 ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/ModelloParameterConstants.java000066400000000000000000000042671166654766000324530ustar00rootroot00000000000000package 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() { } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/ModelloRuntimeException.java000066400000000000000000000031561166654766000321340ustar00rootroot00000000000000package 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 ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/000077500000000000000000000000001166654766000253765ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/AbstractModelloCore.java000066400000000000000000000041371166654766000321360ustar00rootroot00000000000000package 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 ); } } DefaultGeneratorPluginManager.java000066400000000000000000000040221166654766000340650ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/corepackage 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 1419 2010-02-14 10:08:10Z hboutemy $ */ public class DefaultGeneratorPluginManager extends AbstractPluginManager implements GeneratorPluginManager { public ModelloGenerator getGeneratorPlugin( String generatorId ) { ModelloGenerator generator = getPlugin( generatorId ); if ( generator == null ) { throw new ModelloRuntimeException( "No such generator plugin: '" + generatorId + "'." ); } return generator; } public boolean hasGeneratorPlugin( String generatorId ) { return hasPlugin( generatorId ); } } DefaultMetadataPluginManager.java000066400000000000000000000037761166654766000336760ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/corepackage 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 1419 2010-02-14 10:08:10Z hboutemy $ */ public class DefaultMetadataPluginManager extends AbstractPluginManager implements MetadataPluginManager { public MetadataPlugin getMetadataPlugin( String metadataId ) { MetadataPlugin metadata = getPlugin( metadataId ); if ( metadata == null ) { throw new ModelloRuntimeException( "No such metadata plugin: '" + metadataId + "'." ); } return metadata; } public boolean hasMetadataPlugin( String metadataId ) { return hasPlugin( metadataId ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/DefaultModelloCore.java000066400000000000000000000336351166654766000317640ustar00rootroot00000000000000package 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.InterfaceMetadata; 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.ModelInterface; 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.Collection; import java.util.Collections; import java.util.Map; import java.util.Properties; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * * @version $Id: DefaultModelloCore.java 1469 2010-04-20 16:45:36Z 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 ) { String 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 ( ModelClass clazz : model.getAllClasses() ) { 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 ( ModelField field : clazz.getAllFields() ) { 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() ) ) { getLogger().warn( "'Content' type is deprecated: use 'String' type and add xml.content='true' to the field" ); 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 { Collection plugins = metadataPluginManager.getPlugins().values(); for ( MetadataPlugin plugin : plugins ) { Map attributes = 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 ( ModelClass clazz : model.getAllClasses() ) { Map attributes = modelReader.getAttributesForClass( clazz ); attributes = Collections.unmodifiableMap( attributes ); for ( MetadataPlugin plugin : plugins ) { ClassMetadata metadata = plugin.getClassMetadata( clazz, attributes ); if ( metadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } clazz.addMetadata( metadata ); } for ( ModelField field : clazz.getAllFields() ) { 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 ( MetadataPlugin plugin : plugins ) { 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 { attributes = modelReader.getAttributesForField( field ); attributes = Collections.unmodifiableMap( attributes ); for ( MetadataPlugin plugin : plugins ) { FieldMetadata metadata = plugin.getFieldMetadata( field, attributes ); if ( metadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } field.addMetadata( metadata ); } } } } for ( ModelInterface iface : model.getAllInterfaces() ) { Map attributes = modelReader.getAttributesForInterface( iface ); attributes = Collections.unmodifiableMap( attributes ); for ( MetadataPlugin plugin : plugins ) { InterfaceMetadata metadata = plugin.getInterfaceMetadata( iface, attributes ); if ( metadata == null ) { throw new ModelloException( "A meta data plugin must not return null." ); } iface.addMetadata( metadata ); } } } /** * Validate the entire model. * * @throws ModelValidationException */ private void validate( Model model ) throws ModelValidationException { model.validate(); for ( ModelDefault modelDefault : model.getDefaults() ) { modelDefault.validateElement(); } for ( ModelClass modelClass : model.getAllClasses() ) { modelClass.validate(); } for ( ModelClass modelClass : model.getAllClasses() ) { for ( ModelField field : modelClass.getAllFields() ) { field.validate(); } for ( CodeSegment codeSegment : modelClass.getAllCodeSegments() ) { 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 ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/GeneratorPluginManager.java000066400000000000000000000033211166654766000326400ustar00rootroot00000000000000package 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 1419 2010-02-14 10:08:10Z hboutemy $ */ public interface GeneratorPluginManager { String ROLE = GeneratorPluginManager.class.getName(); Map getPlugins(); Iterator getPluginsIterator(); ModelloGenerator getGeneratorPlugin( String generatorId ); boolean hasGeneratorPlugin( String generatorId ); } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/MetadataPluginManager.java000066400000000000000000000033041166654766000324330ustar00rootroot00000000000000package 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 1413 2010-02-13 21:23:01Z hboutemy $ */ public interface MetadataPluginManager { String ROLE = MetadataPluginManager.class.getName(); Map getPlugins(); Iterator getPluginsIterator(); MetadataPlugin getMetadataPlugin( String metadataId ); boolean hasMetadataPlugin( String metadataId ); } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/ModelloCore.java000066400000000000000000000043111166654766000304440ustar00rootroot00000000000000package 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; } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/io/000077500000000000000000000000001166654766000260055ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/core/io/ModelReader.java000066400000000000000000000476671166654766000310570ustar00rootroot00000000000000package 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; import java.util.ArrayList; import java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: ModelReader.java 1436 2010-04-14 23:04:58Z bentmann $ */ public class ModelReader { private Map modelAttributes = new HashMap(); private Map> classAttributes = new HashMap>(); private Map> interfaceAttributes = new HashMap>(); private Map> fieldAttributes = new HashMap>(); private Map> associationAttributes = new HashMap>(); public Map getAttributesForModel() { return modelAttributes; } public Map getAttributesForClass( ModelClass modelClass ) { return classAttributes.get( modelClass.getName() ); } public Map getAttributesForInterface( ModelInterface modelInterface ) { return interfaceAttributes.get( modelInterface.getName() ); } public Map getAttributesForField( ModelField modelField ) { return fieldAttributes.get( modelField.getModelClass().getName() + ':' + modelField.getName() + ':' + modelField.getVersionRange() ); } public Map getAttributesForAssociation( ModelAssociation modelAssociation ) { return 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 ( "id".equals( parser.getName() ) ) { model.setId( parser.nextText() ); } else if ( "defaults".equals( parser.getName() ) ) { parseDefaults( model, parser ); } else if ( "versionDefinition".equals( parser.getName() ) ) { parseVersionDefinition( model, parser ); } else if ( "interfaces".equals( parser.getName() ) ) { parseInterfaces( model, parser ); } else if ( "classes".equals( parser.getName() ) ) { parseClasses( model, parser ); } else if ( "model".equals( parser.getName() ) ) { 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 ( "default".equals( parser.getName() ) ) { ModelDefault modelDefault = new ModelDefault(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "key".equals( parser.getName() ) ) { modelDefault.setKey( parser.nextText() ); } else if ( "value".equals( parser.getName() ) ) { 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 ( "interface".equals( parser.getName() ) ) { ModelInterface modelInterface = new ModelInterface(); Map attributes = getAttributes( parser ); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( modelInterface, parser ) ) { } else if ( "superInterface".equals( parser.getName() ) ) { modelInterface.setSuperInterface( parser.nextText() ); } else if ( "packageName".equals( parser.getName() ) ) { modelInterface.setPackageName( parser.nextText() ); } else if ( "codeSegments".equals( parser.getName() ) ) { parseCodeSegment( modelInterface, parser ); } else { parser.nextText(); } } model.addInterface( modelInterface ); interfaceAttributes.put( modelInterface.getName(), attributes ); } else { parser.next(); } } } private void parseClasses( Model model, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "class".equals( parser.getName() ) ) { ModelClass modelClass = new ModelClass(); Map attributes = getAttributes( parser ); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( modelClass, parser ) ) { } else if ( "interfaces".equals( parser.getName() ) ) { parseClassInterfaces( modelClass, parser ); } else if ( "superClass".equals( parser.getName() ) ) { modelClass.setSuperClass( parser.nextText() ); } else if ( "packageName".equals( parser.getName() ) ) { modelClass.setPackageName( parser.nextText() ); } else if ( "fields".equals( parser.getName() ) ) { parseFields( modelClass, parser ); } else if ( "codeSegments".equals( parser.getName() ) ) { 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 ( "interface".equals( parser.getName() ) ) { modelClass.addInterface( parser.nextText() ); } else { parser.nextText(); } } } private void parseFields( ModelClass modelClass, XmlPullParser parser ) throws XmlPullParserException, IOException { while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "field".equals( parser.getName() ) ) { 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 ( "association".equals( parser.getName() ) ) { aAttributes = getAttributes( parser ); modelAssociation = parseAssociation( parser ); } else if ( "alias".equals( parser.getName() ) ) { modelField.setAlias( parser.nextText() ); } else if ( "type".equals( parser.getName() ) ) { modelField.setType( parser.nextText() ); } else if ( "defaultValue".equals( parser.getName() ) ) { modelField.setDefaultValue( parser.nextText() ); } else if ( "typeValidator".equals( parser.getName() ) ) { modelField.setTypeValidator( parser.nextText() ); } else if ( "required".equals( parser.getName() ) ) { modelField.setRequired( Boolean.valueOf( parser.nextText() ).booleanValue() ); } else if ( "identifier".equals( parser.getName() ) ) { 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() ); modelAssociation.setAnnotations( modelField.getAnnotations() ); // 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 ( "type".equals( parser.getName() ) ) { modelAssociation.setTo( parser.nextText() ); } else if ( "multiplicity".equals( parser.getName() ) ) { 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 ( "codeSegment".equals( parser.getName() ) ) { CodeSegment codeSegment = new CodeSegment(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( codeSegment, parser ) ) { } else if ( "code".equals( parser.getName() ) ) { 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 ( "codeSegment".equals( parser.getName() ) ) { CodeSegment codeSegment = new CodeSegment(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( parseBaseElement( codeSegment, parser ) ) { } else if ( "code".equals( parser.getName() ) ) { codeSegment.setCode( parser.nextText() ); } else { parser.nextText(); } } modelInterface.addCodeSegment( codeSegment ); } else { parser.next(); } } } private boolean parseBaseElement( BaseElement element, XmlPullParser parser ) throws XmlPullParserException, IOException { if ( "name".equals( parser.getName() ) ) { element.setName( parser.nextText() ); } else if ( "description".equals( parser.getName() ) ) { element.setDescription( parser.nextText() ); } else if ( "version".equals( parser.getName() ) ) { element.setVersionRange( new VersionRange( parser.nextText() ) ); } else if ( "comment".equals( parser.getName() ) ) { element.setComment( parser.nextText() ); } else if ( "annotations".equals( parser.getName() ) ) { List annotationsList = new ArrayList(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "annotation".equals( parser.getName() ) ) { annotationsList.add( parser.nextText() ); } } element.setAnnotations( annotationsList ); } 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; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/000077500000000000000000000000001166654766000262265ustar00rootroot00000000000000AbstractMetadataPlugin.java000066400000000000000000000037721166654766000334060ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadatapackage 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.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.StringUtils; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: AbstractMetadataPlugin.java 1417 2010-02-13 22:36:04Z hboutemy $ */ public abstract class AbstractMetadataPlugin extends AbstractLogEnabled implements MetadataPlugin { protected boolean getBoolean( Map data, String key, boolean defaultValue ) { String value = data.get( key ); if ( StringUtils.isEmpty( value ) ) { return defaultValue; } return Boolean.valueOf( value ).booleanValue(); } protected String getString( Map data, String key ) { String value = data.get( key ); return StringUtils.isEmpty( value ) ? null : value; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/AssociationMetadata.java000066400000000000000000000025421166654766000330110ustar00rootroot00000000000000package 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 { } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/ClassMetadata.java000066400000000000000000000025261166654766000316040ustar00rootroot00000000000000package 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 { } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/FieldMetadata.java000066400000000000000000000025261166654766000315620ustar00rootroot00000000000000package 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 { } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/InterfaceMetadata.java000066400000000000000000000025401166654766000324330ustar00rootroot00000000000000package 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: InterfaceMetadata.java 1436 2010-04-14 23:04:58Z bentmann $ */ public interface InterfaceMetadata extends Metadata { } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/Metadata.java000066400000000000000000000024671166654766000306220ustar00rootroot00000000000000package 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 { } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/MetadataPlugin.java000066400000000000000000000044061166654766000317740ustar00rootroot00000000000000package 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.modello.model.ModelInterface; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: MetadataPlugin.java 1436 2010-04-14 23:04:58Z bentmann $ */ public interface MetadataPlugin { String ROLE = MetadataPlugin.class.getName(); ModelMetadata getModelMetadata( Model model, Map data ) throws ModelloException; ClassMetadata getClassMetadata( ModelClass clazz, Map data ) throws ModelloException; InterfaceMetadata getInterfaceMetadata( ModelInterface iface, Map data ) throws ModelloException; FieldMetadata getFieldMetadata( ModelField field, Map data ) throws ModelloException; AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) throws ModelloException; } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/metadata/ModelMetadata.java000066400000000000000000000025261166654766000315770ustar00rootroot00000000000000package 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 { } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/000077500000000000000000000000001166654766000255465ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/BaseElement.java000066400000000000000000000144551166654766000306060ustar00rootroot00000000000000package 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; import java.util.ArrayList; import java.util.List; /** * 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 1433 2010-04-14 12:34:49Z bentmann $ */ public abstract class BaseElement { private String name; private String description; private String comment; private List annotations = new ArrayList(); 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 T getMetadata( Class type, String key ) { Metadata metadata = this.metadata.get( key ); if ( metadata == null ) { throw new ModelloRuntimeException( "No such metadata: '" + key + "' for element: '" + getName() + "'." ); } if ( !type.isInstance( metadata ) ) { throw new ModelloRuntimeException( "The metadata is not of the expected type. Key: '" + key + "', expected type: '" + type.getName() + "'." ); } return type.cast( 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(); } /** * @return the annotations */ public List getAnnotations() { return annotations; } /** * @param annotations the annotations to set */ public void setAnnotations( List annotations ) { this.annotations = annotations; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/CodeSegment.java000066400000000000000000000031261166654766000306100ustar00rootroot00000000000000package 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() { } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/Model.java000066400000000000000000000332571166654766000274630ustar00rootroot00000000000000package 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 org.codehaus.plexus.util.StringUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: Model.java 1459 2010-04-19 10:36:55Z bentmann $ */ 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 getMetadata( ModelMetadata.class, key ); } public String getRoot( Version version ) { List classes = getClasses( version ); String className = null; for ( ModelClass currentClass : classes ) { 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 ) { List classList = new ArrayList(); for ( ModelClass currentClass : classes ) { 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 ) { List classList = classMap.get( type ); ModelClass value = null; if ( classList != null ) { for ( ModelClass modelClass : classList ) { 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() ) ) { List classList = classMap.get( modelClass.getName() ); for ( ModelClass currentClass : classList ) { if ( VersionUtil.isInConflict( modelClass.getVersionRange(), currentClass.getVersionRange() ) ) { throw new ModelloRuntimeException( "Duplicate class: " + modelClass.getName() + "." ); } } } else { List classList = new ArrayList(); classMap.put( modelClass.getName(), classList ); } getAllClasses().add( modelClass ); classMap.get( modelClass.getName() ).add( modelClass ); } // ---------------------------------------------------------------------- // Defaults // ---------------------------------------------------------------------- public List getDefaults() { return defaults; } public ModelDefault getDefault( String key ) { ModelDefault modelDefault = (ModelDefault) defaultMap.get( key ); if ( modelDefault == null ) { try { modelDefault = ModelDefault.getDefault( key ); } catch ( ModelValidationException mve ) { throw new ModelloRuntimeException( mve.getMessage(), mve); } } 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 = getDefault( ModelDefault.PACKAGE ).getValue(); if ( withVersion ) { packageName += "." + version.toString( "v", "_" ); } return packageName; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public List getAllInterfaces() { return interfaces; } public List getInterfaces( Version version ) { List interfaceList = new ArrayList(); for ( ModelInterface currentInterface : interfaces ) { 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 ) { List interfaceList = interfaceMap.get( type ); if ( interfaceList != null ) { for ( ModelInterface modelInterface : interfaceList ) { 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() ) ) { List interfaceList = interfaceMap.get( modelInterface.getName() ); for ( ModelInterface currentInterface : interfaceList ) { if ( VersionUtil.isInConflict( modelInterface.getVersionRange(), currentInterface.getVersionRange() ) ) { throw new ModelloRuntimeException( "Duplicate interface: " + modelInterface.getName() + "." ); } } } else { List interfaceList = new ArrayList(); interfaceMap.put( modelInterface.getName(), interfaceList ); } getAllInterfaces().add( modelInterface ); 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 ( ModelClass modelClass : classes ) { modelClass.initialize( this ); } for ( ModelInterface modelInterface : interfaces ) { modelInterface.initialize( this ); } } public void validateElement() { } public ModelClass getLocationTracker( Version version ) { List modelClasses = getClasses( version ); ModelClass locationTracker = null; for ( ModelClass modelClass : modelClasses ) { ModelClassMetadata metadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); if ( metadata != null && StringUtils.isNotEmpty( metadata.getLocationTracker() ) ) { if ( locationTracker == null ) { locationTracker = modelClass; } else { throw new ModelloRuntimeException( "There are multiple location tracker classes (" + locationTracker.getName() + " vs. " + modelClass.getName() + ") for this version " + version + "." ); } } } return locationTracker; } public ModelClass getSourceTracker( Version version ) { List modelClasses = getClasses( version ); ModelClass sourceTracker = null; for ( ModelClass modelClass : modelClasses ) { ModelClassMetadata metadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); if ( metadata != null && StringUtils.isNotEmpty( metadata.getSourceTracker() ) ) { if ( sourceTracker == null ) { sourceTracker = modelClass; } else { throw new ModelloRuntimeException( "There are multiple source tracker classes (" + sourceTracker.getName() + " vs. " + modelClass.getName() + ") for this version " + version + "." ); } } } return sourceTracker; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/ModelAssociation.java000066400000000000000000000151071166654766000316520ustar00rootroot00000000000000package 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 1433 2010-04-14 12:34:49Z bentmann $ */ 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 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 ( !"String".equals( to ) ) { 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 ( "n".equals( multiplicity ) || "*".equals( multiplicity ) ) { multiplicity = MANY_MULTIPLICITY; } if ( !ONE_MULTIPLICITY.equals( multiplicity ) && !MANY_MULTIPLICITY.equals( 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 ( "Set".equalsIgnoreCase( getType() ) ) { setType( ModelDefault.SET ); } else if ( "List".equalsIgnoreCase( getType() ) ) { setType( ModelDefault.LIST ); } else if ( "Map".equalsIgnoreCase( getType() ) ) { setType( ModelDefault.MAP ); } else if ( "Properties".equalsIgnoreCase( getType() ) ) { 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; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/ModelClass.java000066400000000000000000000175551166654766000304540ustar00rootroot00000000000000package 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.List; import java.util.Map; /** * @author Jason van Zyl * @author Emmanuel Venisse * * @version $Id: ModelClass.java 1433 2010-04-14 12:34:49Z bentmann $ */ 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 ) { List fieldList = fieldMap.get( type ); if ( fieldList != null ) { for ( ModelField modelField : fieldList ) { 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() ) ) { List fieldList = fieldMap.get( modelField.getName() ); for ( ModelField currentField : fieldList ) { if ( VersionUtil.isInConflict( modelField.getVersionRange(), currentField.getVersionRange() ) ) { throw new ModelloRuntimeException( "Duplicate field in " + getName() + ": " + modelField.getName() + "." ); } } } else { List fieldList = new ArrayList(); fieldMap.put( modelField.getName(), fieldList ); } getAllFields().add( modelField ); fieldMap.get( modelField.getName() ).add( modelField ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public boolean hasSuperClass() { return StringUtils.isNotEmpty( superClass ); } public boolean isInternalSuperClass() { return isInternalSuperClass; } public ClassMetadata getMetadata( String key ) { return getMetadata( ClassMetadata.class, key ); } public void initialize( Model model ) { super.initialize( model ); for ( ModelField modelField : getAllFields() ) { 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; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/ModelDefault.java000066400000000000000000000122601166654766000307570ustar00rootroot00000000000000package 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. */ /** * Default values for a model, that can be overrided with defaults element of the model descriptor. * * @author Emmanuel Venisse * * @version $Id: ModelDefault.java 1360 2010-01-19 22:21:46Z 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()"; public static final String STRICT_XML_ATTRIBUTES = "strictXmlAttributes"; public static final String STRICT_XML_ATTRIBUTES_VALUE = "true"; 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 ); } else if ( PACKAGE.equalsIgnoreCase( key ) ) { modelDefault.setValue( PACKAGE_VALUE ); } else if ( LIST.equalsIgnoreCase( key ) ) { modelDefault.setValue( LIST_VALUE ); } else if ( MAP.equalsIgnoreCase( key ) ) { modelDefault.setValue( MAP_VALUE ); } else if ( PROPERTIES.equalsIgnoreCase( key ) ) { modelDefault.setValue( PROPERTIES_VALUE ); } else if ( SET.equalsIgnoreCase( key ) ) { modelDefault.setValue( SET_VALUE ); } else if ( STRICT_XML_ATTRIBUTES.equalsIgnoreCase( key ) ) { modelDefault.setValue( STRICT_XML_ATTRIBUTES_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 ) && ! STRICT_XML_ATTRIBUTES.equalsIgnoreCase( key ) ) { throw new ModelValidationException( "The key of default element must be ' "+ SET +"', '" + LIST + "', '" + MAP + "', '" + PROPERTIES + "', '" + CHECK_DEPRECATION + "', '" + PACKAGE + "' or '" + STRICT_XML_ATTRIBUTES + "', was '" + key + "'." ); } } protected boolean isEmpty( String string ) { return string == null || string.trim().length() == 0; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/ModelField.java000066400000000000000000000151701166654766000304210ustar00rootroot00000000000000package 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 1484 2010-05-08 17:25:54Z bentmann $ */ 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 = { "boolean", "Boolean", "char", "Character", "byte", "Byte", "short", "Short", "int", "Integer", "long", "Long", "float", "Float", "double", "Double", "String", "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 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(); for ( int i = 0; i < PRIMITIVE_TYPES.length; i++ ) { String validType = PRIMITIVE_TYPES[i] + "[]"; if ( validType.equals( type ) ) { 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 ) || "short".equals( type ) || "byte".equals( type ) ) { defaultValue = "0"; } else if ( "char".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 ) ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/ModelInterface.java000066400000000000000000000046041166654766000312760ustar00rootroot00000000000000package 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 1413 2010-02-13 21:23:01Z 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 { } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/ModelType.java000066400000000000000000000165561166654766000303300ustar00rootroot00000000000000package 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.List; import java.util.Map; /** * Either a model class or interface. * * @author Hervé Boutemy * * @version $Id: ModelType.java 1413 2010-02-13 21:23:01Z 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 ) { List codeSegments = getAllCodeSegments(); List codeSegmentsList = new ArrayList(); if ( codeSegments != null ) { for ( CodeSegment codeSegment : codeSegments ) { 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 ) { List fieldList = new ArrayList(); for ( ModelField currentField : getAllFields() ) { if ( version.inside( currentField.getVersionRange() ) ) { fieldList.add( currentField ); } } return fieldList; } public List getAllFields( Version version, boolean withInheritedField ) { List allFieldsList = new ArrayList(); List fieldList = new ArrayList(); for ( ModelField currentField : getAllFields( withInheritedField ) ) { if ( version.inside( currentField.getVersionRange() ) ) { allFieldsList.add( currentField ); } } for ( ModelField currentField : allFieldsList ) { 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 ( ModelField field : getFields( version ) ) { if ( field.isIdentifier() ) { identifierFields.add( field ); } } return identifierFields; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- public void initialize( Model model ) { this.model = model; if ( packageName == null ) { packageName = model.getDefaultPackageName( false, null ); } } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/ModelValidationException.java000066400000000000000000000030051166654766000333410ustar00rootroot00000000000000package 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 ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/Version.java000066400000000000000000000153151166654766000300430ustar00rootroot00000000000000package 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 1413 2010-02-13 21:23:01Z 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( Version otherVersion ) { if ( greaterThan( otherVersion ) ) { return +1; } else if ( equals( otherVersion ) ) { return 0; } else { return -1; } } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/VersionDefinition.java000066400000000000000000000027711166654766000320560ustar00rootroot00000000000000package 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; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/VersionRange.java000066400000000000000000000075151166654766000310230ustar00rootroot00000000000000package 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( "", "." ) + "]"; } } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/model/VersionUtil.java000066400000000000000000000031101166654766000306670ustar00rootroot00000000000000package 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() ) ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000257445ustar00rootroot00000000000000AbstractModelloGenerator.java000066400000000000000000000217471166654766000334710ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/pluginpackage 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 1413 2010-02-13 21:23:01Z hboutemy $ */ 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; } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractPluginManager.java000066400000000000000000000045151166654766000330310ustar00rootroot00000000000000package 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.HashMap; import java.util.Iterator; import java.util.Map; /** * @author Trygve Laugstøl * @version $Id: AbstractPluginManager.java 1419 2010-02-14 10:08:10Z hboutemy $ */ public abstract class AbstractPluginManager extends AbstractLogEnabled implements Initializable { /* injected by Plexus: see META-INF/plexus/components.xml */ private Map plugins = new HashMap(); public void initialize() { } public Map getPlugins() { return plugins; } public Iterator getPluginsIterator() { return plugins.values().iterator(); } public T getPlugin( String name ) { T 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 ); } } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/ModelloGenerator.java000066400000000000000000000030261166654766000320520ustar00rootroot00000000000000package 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; } modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/model/000077500000000000000000000000001166654766000270445ustar00rootroot00000000000000ModelAssociationMetadata.java000066400000000000000000000030031166654766000345220ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/modelpackage 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(); } ModelClassMetadata.java000066400000000000000000000042401166654766000333170ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/modelpackage 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 1459 2010-04-19 10:36:55Z bentmann $ */ public class ModelClassMetadata implements ClassMetadata { public static final String ID = ModelClassMetadata.class.getName(); private boolean rootElement = false; private String locationTracker; private String sourceTracker; public boolean isRootElement() { return rootElement; } public void setRootElement( boolean rootElement ) { this.rootElement = rootElement; } public String getLocationTracker() { return locationTracker; } public void setLocationTracker( String locationTracker ) { this.locationTracker = locationTracker; } public String getSourceTracker() { return sourceTracker; } public void setSourceTracker( String sourceTracker ) { this.sourceTracker = sourceTracker; } } ModelFieldMetadata.java000066400000000000000000000027451166654766000333050ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/modelpackage 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(); } ModelInterfaceMetadata.java000066400000000000000000000027721166654766000341620ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/modelpackage 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.InterfaceMetadata; /** * @author Emmanuel Venisse * @version $Id: ModelInterfaceMetadata.java 1436 2010-04-14 23:04:58Z bentmann $ */ public class ModelInterfaceMetadata implements InterfaceMetadata { public static final String ID = ModelInterfaceMetadata.class.getName(); } ModelMetadataPlugin.java000066400000000000000000000066161166654766000335210ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/modelpackage 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.InterfaceMetadata; 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 org.codehaus.modello.model.ModelInterface; import java.util.Map; /** * @author Emmanuel Venisse * @version $Id: ModelMetadataPlugin.java 1459 2010-04-19 10:36:55Z bentmann $ */ public class ModelMetadataPlugin extends AbstractMetadataPlugin implements MetadataPlugin { public static final String ROOT_ELEMENT = "rootElement"; public static final String LOCATION_TRACKER = "locationTracker"; public static final String SOURCE_TRACKER = "sourceTracker"; // ---------------------------------------------------------------------- // 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 ) ); metadata.setLocationTracker( getString( data, LOCATION_TRACKER ) ); metadata.setSourceTracker( getString( data, SOURCE_TRACKER ) ); return metadata; } public InterfaceMetadata getInterfaceMetadata( ModelInterface iface, Map data ) { return new ModelInterfaceMetadata(); } public FieldMetadata getFieldMetadata( ModelField field, Map data ) { return new ModelFieldMetadata(); } public AssociationMetadata getAssociationMetadata( ModelAssociation association, Map data ) { return new ModelAssociationMetadata(); } } ModelModelMetadata.java000066400000000000000000000027451166654766000333220ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/java/org/codehaus/modello/plugin/modelpackage 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(); } modello1.4-1.4.1/modello-core/src/main/resources/000077500000000000000000000000001166654766000215225ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/resources/META-INF/000077500000000000000000000000001166654766000226625ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000242025ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/main/resources/META-INF/plexus/components.xml000066400000000000000000000032761166654766000271210ustar00rootroot00000000000000 org.codehaus.modello.core.ModelloCore org.codehaus.modello.core.DefaultModelloCore per-lookup org.codehaus.modello.core.MetadataPluginManager org.codehaus.modello.core.GeneratorPluginManager org.codehaus.modello.core.MetadataPluginManager org.codehaus.modello.core.DefaultMetadataPluginManager per-lookup plugins org.codehaus.modello.metadata.MetadataPlugin org.codehaus.modello.core.GeneratorPluginManager org.codehaus.modello.core.DefaultGeneratorPluginManager per-lookup plugins org.codehaus.modello.plugin.ModelloGenerator org.codehaus.modello.metadata.MetadataPlugin model org.codehaus.modello.plugin.model.ModelMetadataPlugin modello1.4-1.4.1/modello-core/src/site/000077500000000000000000000000001166654766000175305ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/site/site.xml000066400000000000000000000005571166654766000212250ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-core/src/test/000077500000000000000000000000001166654766000175435ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/000077500000000000000000000000001166654766000204645ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/org/000077500000000000000000000000001166654766000212535ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/000077500000000000000000000000001166654766000230465ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000245015ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/modello/core/000077500000000000000000000000001166654766000254315ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/modello/core/DefaultModelloCoreTest.java000066400000000000000000000056371166654766000326600ustar00rootroot00000000000000package 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; /** * @author Trygve Laugstøl * @version $Id: DefaultModelloCoreTest.java 1388 2010-02-06 09:13:19Z hboutemy $ */ public class DefaultModelloCoreTest extends PlexusTestCase { public void testModelWithDuplicateClasses() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); try { modello.loadModel( 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( 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( getTestFile( "src/test/resources/models/duplicate-associations.mdo" ) ); fail( "Expected ModelloRuntimeException." ); } catch( ModelloRuntimeException ex ) { assertEquals( "Duplicate field in MyClass: MyAssociation.", ex.getMessage() ); } } } modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/modello/core/io/000077500000000000000000000000001166654766000260405ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/modello/core/io/ModelReaderTest.java000066400000000000000000000132411166654766000317270ustar00rootroot00000000000000package 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 java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * * @version $Id: ModelReaderTest.java 1413 2010-02-13 21:23:01Z hboutemy $ */ public class ModelReaderTest extends PlexusTestCase { public void testBasic() throws Exception { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( 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( 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() ); } } modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/modello/model/000077500000000000000000000000001166654766000256015ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/java/org/codehaus/modello/model/VersionTest.java000066400000000000000000000070711166654766000307360ustar00rootroot00000000000000package 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 ) ) ); } } modello1.4-1.4.1/modello-core/src/test/resources/000077500000000000000000000000001166654766000215555ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/resources/models/000077500000000000000000000000001166654766000230405ustar00rootroot00000000000000modello1.4-1.4.1/modello-core/src/test/resources/models/association.mdo000066400000000000000000000030031166654766000260510ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-core/src/test/resources/models/duplicate-associations.mdo000066400000000000000000000007761166654766000302220ustar00rootroot00000000000000 duplicate-associations Duplicate Associations Test Model MyClass MyAssociation String MyAssociation String modello1.4-1.4.1/modello-core/src/test/resources/models/duplicate-classes.mdo000066400000000000000000000003331166654766000271450ustar00rootroot00000000000000 duplicate-classes Duplicate Classes Test Model MyClass MyClass modello1.4-1.4.1/modello-core/src/test/resources/models/duplicate-fields.mdo000066400000000000000000000005041166654766000267560ustar00rootroot00000000000000 duplicate-fields Duplicate Fields Test Model MyClass MyField MyField modello1.4-1.4.1/modello-core/src/test/resources/models/simple.mdo000066400000000000000000000022521166654766000250330ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/000077500000000000000000000000001166654766000165265ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/000077500000000000000000000000001166654766000236455ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/pom.xml000066400000000000000000000031051166654766000251610ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 org.codehaus.plexus plexus-utils stax stax-api 1.0.1 test org.codehaus.woodstox wstx-asl 3.2.0 test maven-dependency-plugin modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/000077500000000000000000000000001166654766000244345ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/000077500000000000000000000000001166654766000253605ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/java/000077500000000000000000000000001166654766000263015ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/java/org/000077500000000000000000000000001166654766000270705ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/000077500000000000000000000000001166654766000306635ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000323165ustar00rootroot00000000000000000077500000000000000000000000001166654766000335355ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin000077500000000000000000000000001166654766000357275ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/convertersConverterGenerator.java000066400000000000000000000470511166654766000424170ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converterspackage 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.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 ( String version : versions ) { allVersions.add( new Version( version ) ); } Collections.sort( allVersions ); Version nextVersion = null; for ( Version v : allVersions ) { if ( v.greaterThan( getGeneratedVersion() ) ) { nextVersion = v; break; } } 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 ( ModelClass modelClass : objectModel.getClasses( fromVersion ) ) { 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 ( ModelField modelField : modelClass.getFields( fromVersion ) ) { 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 ( Version v : allVersions ) { 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 ( Version sourceVersion : allVersions ) { 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 ( Version targetVersion : allVersions ) { 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(); } } modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/resources/000077500000000000000000000000001166654766000273725ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/resources/META-INF/000077500000000000000000000000001166654766000305325ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000320525ustar00rootroot00000000000000components.xml000066400000000000000000000005541166654766000347060ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/main/resources/META-INF/plexus org.codehaus.modello.plugin.ModelloGenerator converters org.codehaus.modello.plugin.converters.ConverterGenerator per-lookup modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/site/000077500000000000000000000000001166654766000254005ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/site/site.xml000066400000000000000000000005571166654766000270750ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/site/xdoc/000077500000000000000000000000001166654766000263355ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/site/xdoc/index.xml000066400000000000000000000046141166654766000301730ustar00rootroot00000000000000 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
modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/000077500000000000000000000000001166654766000254135ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/java/000077500000000000000000000000001166654766000263345ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/java/org/000077500000000000000000000000001166654766000271235ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/000077500000000000000000000000001166654766000307165ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000323515ustar00rootroot00000000000000000077500000000000000000000000001166654766000335705ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin000077500000000000000000000000001166654766000357625ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/convertersConverterGeneratorTest.java000066400000000000000000000077771166654766000433250ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/java/org/codehaus/modello/plugin/converterspackage 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 java.io.Reader; import java.util.Properties; /** * @version $Id: ConverterGeneratorTest.java 1473 2010-04-24 16:46:13Z bentmann $ */ public class ConverterGeneratorTest extends AbstractModelloJavaGeneratorTest { public ConverterGeneratorTest() { super( "converters" ); } public void testConverterGenerator() throws Throwable { generateConverterClasses( getXmlResourceReader( "/models/maven.mdo" ), "3.0.0", "4.0.0" ); generateConverterClasses( getXmlResourceReader( "/features.mdo" ), "1.0.0", "1.1.0" ); addDependency( "stax", "stax-api" ); addDependency( "org.codehaus.woodstox", "wstx-asl" ); compileGeneratedSources(); verifyCompiledGeneratedSources( "ConvertersVerifier" ); } private void generateConverterClasses( Reader modelReader, String fromVersion, String toVersion ) throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( modelReader ); Properties parameters = new Properties(); parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() ); parameters.setProperty( ModelloParameterConstants.ALL_VERSIONS, fromVersion + "," + toVersion ); 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 ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/resources/000077500000000000000000000000001166654766000274255ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/resources/models/000077500000000000000000000000001166654766000307105ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/resources/models/maven.mdo000066400000000000000000001623451166654766000325320ustar00rootroot00000000000000 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
modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/verifiers/000077500000000000000000000000001166654766000274115ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/000077500000000000000000000000001166654766000316035ustar00rootroot00000000000000ConvertersVerifier.java000066400000000000000000000077641166654766000362330ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/* * 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; } } expected-v3.xml000066400000000000000000000124701166654766000344010ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters ../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 expected.xml000066400000000000000000000077061166654766000340610ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters 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 modello1.4-1.4.1/modello-plugins/modello-plugin-converters/src/test/verifiers/converters/input.xml000066400000000000000000000134161166654766000334710ustar00rootroot00000000000000 ../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 modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/000077500000000000000000000000001166654766000224705ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/pom.xml000066400000000000000000000030521166654766000240050ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 org.codehaus.plexus plexus-utils dom4j dom4j 1.6.1 test xmlunit xmlunit 1.2 test maven-dependency-plugin modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/000077500000000000000000000000001166654766000232575ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/000077500000000000000000000000001166654766000242035ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/000077500000000000000000000000001166654766000251245ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/000077500000000000000000000000001166654766000257135ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/000077500000000000000000000000001166654766000275065ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000311415ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000324375ustar00rootroot00000000000000000077500000000000000000000000001166654766000333755ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4jDom4jReaderGenerator.java000066400000000000000000001144661166654766000402230ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4jpackage 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.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.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 { private boolean requiresDomSupport; public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); requiresDomSupport = false; 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.InputStream" ); 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.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 ); ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); JClass rootType = new JClass( root.getName() ); // ---------------------------------------------------------------------- // Write the read(XMLStreamReader,boolean) method which will do the unmarshalling. // ---------------------------------------------------------------------- JMethod unmarshall = new JMethod( "read", rootType, null ); unmarshall.getModifiers().makePrivate(); unmarshall.addParameter( new JParameter( new JClass( "Document" ), "document" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); JSourceCode sc = unmarshall.getSourceCode(); String className = root.getName(); String variableName = uncapitalise( className ); sc.add( "String encoding = document.getXMLEncoding();" ); sc.add( className + ' ' + variableName + " = parse" + root.getName() + "( \"" + resolveTagName( root ) + "\", document.getRootElement(), strict );" ); sc.add( variableName + ".setModelEncoding( encoding );" ); sc.add( "return " + variableName + ";" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the read(Reader[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, 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" ) ); sc = unmarshall.getSourceCode(); sc.add( "SAXReader parser = new SAXReader();" ); sc.add( "Document document = parser.read( reader );" ); sc.add( "return read( document, strict );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, 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 ); // ---------------------------------------------------------------------- // Write the read(InputStream[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "stream" ) ); 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( stream );" ); sc.add( "return read( document, strict );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "stream" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( stream, true );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the read(URL[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, 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( "return read( document, strict );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, 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 ); if ( requiresDomSupport ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); writeDomHelpers( jClass ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClassesParser( Model objectModel, JClass jClass ) { ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); for ( ModelClass clazz : getClasses( objectModel ) ) { 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.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "DocumentException" ) ); JSourceCode sc = unmarshall.getSourceCode(); sc.add( className + " " + uncapClassName + " = new " + className + "();" ); ModelField contentField = null; List modelFields = getFieldsForXml( modelClass, getGeneratedVersion() ); // read all XML attributes first for ( ModelField field : modelFields ) { 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 ) { 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 )" ); // TODO: attach other NodeTypes to model in some way sc.add( "{" ); sc.indent(); sc.add( "Element childElement = (Element) node;" ); boolean addElse = false; for ( ModelField field : modelFields ) { 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( "checkUnknownElement( childElement, strict );" ); 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 ) );" ); 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 )" ); // TODO: track the whitespace in the model (other NodeTypes) sc.add( "{" ); sc.indent(); sc.add( "Element listElement = (Element) n;" ); sc.add( "if ( \"" + valuesTagName + "\".equals( listElement.getName() ) )" ); sc.add( "{" ); sc.indent(); } else { sc.add( ( addElse ? "else " : "" ) + "if ( \"" + valuesTagName + "\".equals( childElement.getName() ) )" ); 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 ) );" ); } 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 )" ); // TODO: track the whitespace in the model (other NodeTypes) sc.add( "{" ); sc.indent(); sc.add( "Element listElement = (Element) n;" ); sc.add( "if ( \"" + valuesTagName + "\".equals( listElement.getName() ) )" ); 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 )" ); // TODO: track the whitespace in the model (other NodeTypes) sc.add( "{" ); sc.indent(); sc.add( "Element propertyElement = (Element) nd;" ); sc.add( "if ( \"key\".equals( propertyElement.getName() ) )" ); sc.add( "{" ); sc.addIndented( "key = propertyElement.getText();" ); sc.add( "}" ); sc.add( "else if ( \"value\".equals( propertyElement.getName() ) )" ); 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 )" ); // TODO: track the whitespace in the model (other NodeTypes) 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 + " ) );" ); requiresDomSupport = true; } 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(), e )" ); 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.add( tagName ) )" ); sc.add( "{" ); sc.addIndented( "throw new DocumentException( \"Duplicated tag: '\" + tagName + \"'\" );" ); sc.add( "}" ); sc.add( "return true;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "checkUnknownElement", null, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "Element" ), "element" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); method.addException( new JClass( "DocumentException" ) ); sc = method.getSourceCode(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new DocumentException( \"Unrecognised tag: '\" + element.getName() + \"'\" );" ); sc.add( "}" ); jClass.addMethod( method ); } private void writeDomHelpers( JClass jClass ) { JMethod method = new JMethod( "writeElementToXpp3Dom", new JClass( "Xpp3Dom" ), null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "Element" ), "element" ) ); JSourceCode 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 ); } 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 nfe )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new DocumentException( \"Unable to parse element '\" + attribute + \"', must be " + typeDesc + "\", nfe );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return 0;" ); return method; } } Dom4jWriterGenerator.java000066400000000000000000000436141166654766000402710ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4jpackage 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.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.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 { private boolean requiresDomSupport; public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); requiresDomSupport = false; 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.OutputStream" ); 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.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 ); String variableName = uncapitalise( root ); // ---------------------------------------------------------------------- // Write the write( Reader, Model ) 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 ), variableName ) ); marshall.addException( new JClass( "java.io.IOException" ) ); JSourceCode sc = marshall.getSourceCode(); sc.add( "Document document = new DocumentFactory().createDocument();" ); sc.add( "write" + root + "( " + variableName + ", \"" + 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 ); // ---------------------------------------------------------------------- // Write the write( OutputStream, Model ) method which will do the unmarshalling. // ---------------------------------------------------------------------- marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( "OutputStream" ), "stream" ) ); marshall.addParameter( new JParameter( new JClass( root ), variableName ) ); marshall.addException( new JClass( "java.io.IOException" ) ); sc = marshall.getSourceCode(); sc.add( "Document document = new DocumentFactory().createDocument();" ); sc.add( "write" + root + "( " + variableName + ", \"" + rootElement + "\", document );" ); // TODO: pretty printing optional sc.add( "OutputFormat format = OutputFormat.createPrettyPrint();" ); sc.add( "format.setLineSeparator( System.getProperty( \"line.separator\" ) );" ); sc.add( "format.setEncoding( " + variableName + ".getModelEncoding() );" ); sc.add( "XMLWriter serializer = new XMLWriter( stream, format );" ); sc.add( "serializer.write( document );" ); jClass.addMethod( marshall ); writeAllClasses( objectModel, jClass ); if ( requiresDomSupport ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); writeDomHelpers( jClass ); } jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClasses( Model objectModel, JClass jClass ) throws ModelloException { for ( ModelClass clazz : getClasses( objectModel ) ) { 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 ); marshall.addParameter( new JParameter( new JClass( "org.dom4j.Branch" ), "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 = getFieldsForXml( modelClass, getGeneratedVersion() ); // XML attributes for ( ModelField field : modelFields ) { 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 ( ModelField field : modelFields ) { 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 );" ); requiresDomSupport = true; } else { sc.add( "element.addElement( \"" + fieldTagName + "\" ).setText( " + getValue( field.getType(), value, xmlFieldMetadata ) + " );" ); } sc.unindent(); sc.add( "}" ); } } private void writeDomHelpers( 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 ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/resources/000077500000000000000000000000001166654766000262155ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/resources/META-INF/000077500000000000000000000000001166654766000273555ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000306755ustar00rootroot00000000000000components.xml000066400000000000000000000012261166654766000335260ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/main/resources/META-INF/plexus org.codehaus.modello.plugin.ModelloGenerator dom4j-reader org.codehaus.modello.plugin.dom4j.Dom4jReaderGenerator per-lookup org.codehaus.modello.plugin.ModelloGenerator dom4j-writer org.codehaus.modello.plugin.dom4j.Dom4jWriterGenerator per-lookup modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/site/000077500000000000000000000000001166654766000242235ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/site/site.xml000066400000000000000000000005571166654766000257200ustar00rootroot00000000000000 Modello

modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/site/xdoc/000077500000000000000000000000001166654766000251605ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/site/xdoc/index.xml000066400000000000000000000033071166654766000270140ustar00rootroot00000000000000 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
modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/000077500000000000000000000000001166654766000242365ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/000077500000000000000000000000001166654766000251575ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/000077500000000000000000000000001166654766000257465ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/000077500000000000000000000000001166654766000275415ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000311745ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000324725ustar00rootroot00000000000000000077500000000000000000000000001166654766000334305ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4jDom4jGeneratorTest.java000066400000000000000000000065201166654766000377620ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4jpackage 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.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( getXmlResourceReader( "/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 = getModelloParameters( "4.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "dom4j-writer", parameters ); modello.generate( model, "dom4j-reader", parameters ); addDependency( "dom4j", "dom4j" ); compileGeneratedSources(); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.dom4j.Dom4jVerifier" ); } } FeaturesDom4jGeneratorTest.java000066400000000000000000000044531166654766000414640ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4jpackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesDom4jGeneratorTest.java 1473 2010-04-24 16:46:13Z bentmann $ */ public class FeaturesDom4jGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesDom4jGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "dom4j-writer", parameters ); modello.generate( model, "dom4j-reader", parameters ); addDependency( "dom4j", "dom4j" ); addDependency( "xmlunit", "xmlunit" ); compileGeneratedSources(); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.dom4j.Dom4jFeaturesVerifier" ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/resources/000077500000000000000000000000001166654766000262505ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/resources/maven.mdo000066400000000000000000001641011166654766000300620ustar00rootroot00000000000000 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 * modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/000077500000000000000000000000001166654766000262345ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/000077500000000000000000000000001166654766000272515ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/Dom4jVerifier.java000066400000000000000000000363151166654766000325750ustar00rootroot00000000000000package 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() ); } } } modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/expected-encoding.xml000066400000000000000000000023271166654766000333640ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/dom4j/expected.xml000066400000000000000000000032561166654766000316020ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/000077500000000000000000000000001166654766000300525ustar00rootroot00000000000000Dom4jFeaturesVerifier.java000066400000000000000000000173431166654766000350160ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-dom4j/src/test/verifiers/featurespackage 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.InputStream; import java.io.IOException; import java.io.OutputStream; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; /** * @author Herve Boutemy * @version $Id: Dom4jFeaturesVerifier.java 1474 2010-04-24 19:59:00Z bentmann $ */ public class Dom4jFeaturesVerifier extends Verifier { public void verify() throws Exception { verifyAPI(); Features features = verifyReader(); features.getXmlFeatures().getXmlTransientFields().setTransientString( "NOT-TO-BE-WRITTEN" ); verifyWriter( features ); verifyBadVersion(); verifyWrongElement(); verifyTransientElement(); verifyEncoding(); } public void verifyAPI() throws Exception { assertReader( ModelloFeaturesTestDom4jReader.class, Features.class, Reader.class, DocumentException.class ); assertReader( ModelloFeaturesTestDom4jReader.class, Features.class, InputStream.class, DocumentException.class ); assertWriter( ModelloFeaturesTestDom4jWriter.class, Features.class, Writer.class, IOException.class ); assertWriter( ModelloFeaturesTestDom4jWriter.class, Features.class, OutputStream.class, IOException.class ); } 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... } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/000077500000000000000000000000001166654766000223745ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/pom.xml000066400000000000000000000050321166654766000237110ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.1 4.0.0 modello-plugin-java Modello Java Plugin Modello Java Plugin generates Java POJOs for the model. org.codehaus.plexus plexus-utils org.sonatype.plexus plexus-build-api javax.persistence persistence-api 1.0 test javax.xml.bind jaxb-api 2.1 test maven-dependency-plugin modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/000077500000000000000000000000001166654766000231635ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/000077500000000000000000000000001166654766000241075ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/000077500000000000000000000000001166654766000250305ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/000077500000000000000000000000001166654766000256175ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/000077500000000000000000000000001166654766000274125ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000310455ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000323435ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/000077500000000000000000000000001166654766000332645ustar00rootroot00000000000000AbstractJavaModelloGenerator.java000066400000000000000000000300071166654766000416000ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/javapackage 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.ArrayList; import java.util.Date; import java.util.List; 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.model.ModelType; 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.modello.plugin.model.ModelClassMetadata; 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 1484 2010-05-08 17:25:54Z bentmann $ */ 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 instanceof ModelType ) { basePackageName = ( (ModelType) baseElem ).getPackageName( isPackageWithVersion(), getGeneratedVersion() ); } // import interfaces for ( ModelInterface modelInterface : getModel().getInterfaces( getGeneratedVersion() ) ) { addModelImport( jClass, modelInterface, basePackageName ); } // import classes for ( ModelClass modelClass : getClasses( getModel() ) ) { addModelImport( jClass, modelClass, basePackageName ); } } private void addModelImport( JClass jClass, ModelType modelType, String basePackageName ) { String packageName = modelType.getPackageName( isPackageWithVersion(), getGeneratedVersion() ); if ( !packageName.equals( basePackageName ) ) { jClass.addImport( packageName + '.' + modelType.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 { String type = modelField.getType(); String value = modelField.getDefaultValue(); if ( "String".equals( type ) ) { return '"' + value + '"'; } else if ( "char".equals( type ) ) { return '\'' + value + '\''; } else if ( "long".equals( type ) ) { return value + 'L'; } else if ( "float".equals( type ) ) { return value + 'f'; } else if ( "Date".equals( type ) ) { DateFormat format = new SimpleDateFormat( DEFAULT_DATE_FORMAT, Locale.US ); try { Date date = format.parse( value ); return "new java.util.Date( " + date.getTime() + "L )"; } catch ( ParseException pe ) { throw new ModelloException( "Unparseable default date: " + value, pe ); } } else if ( value != null && value.length() > 0 ) { if ( "Character".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, "'" + value + "'", useJava5 ); } else if ( "Boolean".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, value, true ); } else if ( "Byte".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, "(byte) " + value, useJava5 ); } else if ( "Short".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, "(short) " + value, useJava5 ); } else if ( "Integer".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, value, useJava5 ); } else if ( "Long".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, value + 'L', useJava5 ); } else if ( "Float".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, value + 'f', useJava5 ); } else if ( "Double".equals( type ) && !value.contains( type ) ) { return newPrimitiveWrapper( type, value, useJava5 ); } } return value; } private String newPrimitiveWrapper( String type, String value, boolean useJava5 ) { if ( useJava5 ) { return type + ".valueOf( " + value + " )"; } else { return "new " + type + "( " + value + " )"; } } 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; } protected List getClasses( Model model ) { List modelClasses = new ArrayList(); for ( ModelClass modelClass : model.getClasses( getGeneratedVersion() ) ) { if ( isRelevant( modelClass ) ) { modelClasses.add( modelClass ); } } return modelClasses; } protected boolean isRelevant( ModelClass modelClass ) { return isJavaEnabled( modelClass ) && !isTrackingSupport( modelClass ); } protected boolean isJavaEnabled( ModelClass modelClass ) { JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.ID ); return javaClassMetadata.isEnabled(); } protected boolean isTrackingSupport( ModelClass modelClass ) { ModelClassMetadata modelClassMetadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); if ( StringUtils.isNotEmpty( modelClassMetadata.getLocationTracker() ) ) { return true; } if ( StringUtils.isNotEmpty( modelClassMetadata.getSourceTracker() ) ) { return true; } return false; } } JavaModelloGenerator.java000066400000000000000000002032671166654766000401260ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/javapackage 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.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; 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.JDocDescriptor; 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.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.JavaAssociationMetadata; 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.plexus.util.StringUtils; /** * @author Jason van Zyl * @version $Id: JavaModelloGenerator.java 1492 2010-09-01 20:06:11Z igorife $ */ 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(); ModelClass locationTrackerClass = objectModel.getLocationTracker( getGeneratedVersion() ); ModelClass sourceTrackerClass = objectModel.getSourceTracker( getGeneratedVersion() ); // ---------------------------------------------------------------------- // Generate the interfaces. // ---------------------------------------------------------------------- for ( ModelInterface modelInterface : objectModel.getInterfaces( getGeneratedVersion() ) ) { generateInterface( modelInterface ); } String locationTrackerInterface = generateLocationTracker( objectModel, locationTrackerClass ); // ---------------------------------------------------------------------- // Generate the classes. // ---------------------------------------------------------------------- for ( ModelClass modelClass : objectModel.getClasses( getGeneratedVersion() ) ) { 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() ); boolean superClassInModel = false; if ( modelClass.getSuperClass() != null ) { jClass.setSuperClass( modelClass.getSuperClass() ); superClassInModel = isClassInModel( modelClass.getSuperClass(), objectModel ); } for ( String implementedInterface : modelClass.getInterfaces() ) { jClass.addInterface( implementedInterface ); } jClass.addInterface( Serializable.class.getName() ); if ( useJava5 && !modelClass.getAnnotations().isEmpty() ) { for ( String annotation : modelClass.getAnnotations() ) { jClass.appendAnnotation( annotation ); } } JSourceCode jConstructorSource = new JSourceCode(); for ( ModelField modelField : modelClass.getFields( getGeneratedVersion() ) ) { 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 ); } boolean cloneLocations = !superClassInModel && modelClass != sourceTrackerClass; JMethod[] cloneMethods = generateClone( modelClass, cloneLocations ? locationTrackerClass : null ); if ( cloneMethods.length > 0 ) { jClass.addInterface( Cloneable.class.getName() ); jClass.addMethods( cloneMethods ); } if ( modelClass.getCodeSegments( getGeneratedVersion() ) != null ) { for ( CodeSegment codeSegment : modelClass.getCodeSegments( getGeneratedVersion() ) ) { jClass.addSourceCode( codeSegment.getCode() ); } } ModelClassMetadata modelClassMetadata = (ModelClassMetadata) modelClass.getMetadata( ModelClassMetadata.ID ); if ( modelClassMetadata != null ) { if ( modelClassMetadata.isRootElement() ) { ModelField modelEncoding = new ModelField( modelClass, "modelEncoding" ); modelEncoding.setType( "String" ); modelEncoding.setDefaultValue( "UTF-8" ); modelEncoding.addMetadata( new JavaFieldMetadata() ); createField( jClass, modelEncoding ); } } if ( modelClass == locationTrackerClass ) { jClass.addInterface( locationTrackerInterface ); generateLocationBean( jClass, modelClass, sourceTrackerClass ); generateLocationTracking( jClass, modelClass, locationTrackerClass ); } else if ( locationTrackerClass != null && modelClass != sourceTrackerClass && !superClassInModel) { jClass.addInterface( locationTrackerInterface ); generateLocationTracking( jClass, modelClass, locationTrackerClass ); } jClass.print( sourceWriter ); sourceWriter.close(); } } private void generateInterface( ModelInterface modelInterface ) throws ModelloException, IOException { Model objectModel = modelInterface.getModel(); 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 ( CodeSegment codeSegment : modelInterface.getCodeSegments( getGeneratedVersion() ) ) { jInterface.addSourceCode( codeSegment.getCode() ); } } if ( useJava5 && !modelInterface.getAnnotations().isEmpty() ) { for ( String annotation : modelInterface.getAnnotations() ) { jInterface.appendAnnotation( annotation ); } } jInterface.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 ( ModelField identifier : modelClass.getIdentifierFields( getGeneratedVersion() ) ) { 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 = 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 ( ModelField identifier : identifierFields ) { 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, ModelClass locationClass ) 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 ( ModelField modelField : modelClass.getFields( getGeneratedVersion() ) ) { 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(); JavaAssociationMetadata javaAssociationMetadata = getJavaAssociationMetadata( modelAssociation ); JType componentType = getComponentType( modelAssociation, javaAssociationMetadata ); sc.add( copyField + " = " + getDefaultValue( modelAssociation, componentType ) + ";" ); if ( isCollection( modelField.getType() ) ) { if ( deepClone ) { if ( useJava5 ) { sc.add( "for ( " + componentType.getName() + " item : " + thisField + " )" ); } else { sc.add( "for ( java.util.Iterator it = " + thisField + ".iterator(); it.hasNext(); )" ); } sc.add( "{" ); sc.indent(); if ( useJava5 ) { sc.add( copyField + ".add( ( (" + modelAssociation.getTo() + ") 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( "" ); } } } if ( locationClass != null ) { String locationField = ( (ModelClassMetadata) locationClass.getMetadata( ModelClassMetadata.ID ) ).getLocationTracker(); sc.add( "if ( copy." + locationField + " != null )" ); sc.add( "{" ); sc.indent(); sc.add( "copy." + locationField + " = new java.util.LinkedHashMap" + "( copy." + locationField + " );" ); 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(); } private String generateLocationTracker( Model objectModel, ModelClass locationClass ) throws ModelloException, IOException { if ( locationClass == null ) { return null; } String locationField = ( (ModelClassMetadata) locationClass.getMetadata( ModelClassMetadata.ID ) ).getLocationTracker(); String propertyName = capitalise( singular( locationField ) ); String interfaceName = locationClass.getName() + "Tracker"; String packageName = locationClass.getPackageName( isPackageWithVersion(), getGeneratedVersion() ); JSourceWriter sourceWriter = newJSourceWriter( packageName, interfaceName ); JInterface jInterface = new JInterface( packageName + '.' + interfaceName ); initHeader( jInterface ); suppressAllWarnings( objectModel, jInterface ); JMethodSignature jMethod = new JMethodSignature( "get" + propertyName, new JType( locationClass.getName() ) ); jMethod.setComment( "Gets the location of the specified field in the input source." ); addParameter( jMethod, "Object", "field", "The key of the field, must not be null." ); String returnDoc = "The location of the field in the input source or null if unknown."; jMethod.getJDocComment().addDescriptor( JDocDescriptor.createReturnDesc( returnDoc ) ); jInterface.addMethod( jMethod ); jMethod = new JMethodSignature( "set" + propertyName, null ); jMethod.setComment( "Sets the location of the specified field." ); addParameter( jMethod, "Object", "field", "The key of the field, must not be null." ); addParameter( jMethod, locationClass.getName(), singular( locationField ), "The location of the field, may be null." ); jInterface.addMethod( jMethod ); jInterface.print( sourceWriter ); sourceWriter.close(); return jInterface.getName(); } private void generateLocationTracking( JClass jClass, ModelClass modelClass, ModelClass locationClass ) throws ModelloException { if ( locationClass == null ) { return; } String superClass = modelClass.getSuperClass(); if ( StringUtils.isNotEmpty( superClass ) && isClassInModel( superClass, getModel() ) ) { return; } ModelClassMetadata metadata = (ModelClassMetadata) locationClass.getMetadata( ModelClassMetadata.ID ); String locationField = metadata.getLocationTracker(); String fieldType = "java.util.Map" + ( useJava5 ? "" : "" ); String fieldImpl = "java.util.LinkedHashMap" + ( useJava5 ? "" : "" ); // private java.util.Map locations; JField jField = new JField( new JType( fieldType ), locationField ); jClass.addField( jField ); JMethod jMethod; JSourceCode sc; // public Location getLocation( Object key ) jMethod = new JMethod( "get" + capitalise( singular( locationField ) ), new JType( locationClass.getName() ), null ); jMethod.addParameter( new JParameter( new JType( "Object" ), "key" ) ); sc = jMethod.getSourceCode(); sc.add( "return ( " + locationField + " != null ) ? " + locationField + ".get( key ) : null;" ); jMethod.setComment( "" ); jClass.addMethod( jMethod ); // public void setLocation( Object key, Location location ) jMethod = new JMethod( "set" + capitalise( singular( locationField ) ) ); jMethod.addParameter( new JParameter( new JType( "Object" ), "key" ) ); jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), singular( locationField ) ) ); sc = jMethod.getSourceCode(); sc.add( "if ( " + singular( locationField ) + " != null )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( this." + locationField + " == null )" ); sc.add( "{" ); sc.addIndented( "this." + locationField + " = new " + fieldImpl + "();" ); sc.add( "}" ); sc.add( "this." + locationField + ".put( key, " + singular( locationField ) + " );" ); sc.unindent(); sc.add( "}" ); jMethod.setComment( "" ); jClass.addMethod( jMethod ); } private void generateLocationBean( JClass jClass, ModelClass locationClass, ModelClass sourceClass ) throws ModelloException { jClass.getModifiers().setFinal( true ); String locationsField = ( (ModelClassMetadata) locationClass.getMetadata( ModelClassMetadata.ID ) ).getLocationTracker(); JavaFieldMetadata readOnlyField = new JavaFieldMetadata(); readOnlyField.setSetter( false ); // int lineNumber; ModelField lineNumber = new ModelField( locationClass, "lineNumber" ); lineNumber.setDescription( "The one-based line number. The value will be non-positive if unknown." ); lineNumber.setType( "int" ); lineNumber.setDefaultValue( "-1" ); lineNumber.addMetadata( readOnlyField ); createField( jClass, lineNumber ); // int columnNumber; ModelField columnNumber = new ModelField( locationClass, "columnNumber" ); columnNumber.setDescription( "The one-based column number. The value will be non-positive if unknown." ); columnNumber.setType( "int" ); columnNumber.setDefaultValue( "-1" ); columnNumber.addMetadata( readOnlyField ); createField( jClass, columnNumber ); // Source source; ModelField source = null; if ( sourceClass != null ) { ModelClassMetadata metadata = (ModelClassMetadata) sourceClass.getMetadata( ModelClassMetadata.ID ); String sourceField = metadata.getSourceTracker(); source = new ModelField( locationClass, sourceField ); source.setType( sourceClass.getName() ); source.addMetadata( readOnlyField ); createField( jClass, source ); } // Location( int lineNumber, int columnNumber ); JConstructor jConstructor = jClass.createConstructor(); JSourceCode sc = jConstructor.getSourceCode(); jConstructor.addParameter( new JParameter( JType.INT, lineNumber.getName() ) ); sc.add( "this." + lineNumber.getName() + " = " + lineNumber.getName() + ";" ); jConstructor.addParameter( new JParameter( JType.INT, columnNumber.getName() ) ); sc.add( "this." + columnNumber.getName() + " = " + columnNumber.getName() + ";" ); // Location( int lineNumber, int columnNumber, Source source ); if ( sourceClass != null ) { jConstructor = jClass.createConstructor( jConstructor.getParameters() ); sc.copyInto( jConstructor.getSourceCode() ); sc = jConstructor.getSourceCode(); jConstructor.addParameter( new JParameter( new JType( sourceClass.getName() ), source.getName() ) ); sc.add( "this." + source.getName() + " = " + source.getName() + ";" ); } String fieldType = "java.util.Map" + ( useJava5 ? "" : "" ); String fieldImpl = "java.util.LinkedHashMap" + ( useJava5 ? "" : "" ); // public Map getLocations() JMethod jMethod = new JMethod( "get" + capitalise( locationsField ), new JType( fieldType ), null ); sc = jMethod.getSourceCode(); sc.add( "return " + locationsField + ";" ); jMethod.setComment( "" ); jClass.addMethod( jMethod ); // public void setLocations( Map locations ) jMethod = new JMethod( "set" + capitalise( locationsField ) ); jMethod.addParameter( new JParameter( new JType( fieldType ), locationsField ) ); sc = jMethod.getSourceCode(); sc.add( "this." + locationsField + " = " + locationsField + ";" ); jMethod.setComment( "" ); jClass.addMethod( jMethod ); // public static Location merge( Location target, Location source, boolean sourceDominant ) jMethod = new JMethod( "merge", new JType( locationClass.getName() ), null ); jMethod.getModifiers().setStatic( true ); jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), "target" ) ); jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), "source" ) ); jMethod.addParameter( new JParameter( JType.BOOLEAN, "sourceDominant" ) ); sc = jMethod.getSourceCode(); sc.add( "if ( source == null )" ); sc.add( "{" ); sc.addIndented( "return target;" ); sc.add( "}" ); sc.add( "else if ( target == null )" ); sc.add( "{" ); sc.addIndented( "return source;" ); sc.add( "}" ); sc.add( "" ); sc.add( locationClass.getName() + " result =" ); sc.add( " new " + locationClass.getName() + "( target.getLineNumber(), target.getColumnNumber()" + ( sourceClass != null ? ", target.get" + capitalise( source.getName() ) + "()" : "" ) + " );" ); sc.add( "" ); sc.add( fieldType + " locations;" ); sc.add( fieldType + " sourceLocations = source.get" + capitalise( locationsField ) + "();" ); sc.add( fieldType + " targetLocations = target.get" + capitalise( locationsField ) + "();" ); sc.add( "if ( sourceLocations == null )" ); sc.add( "{" ); sc.addIndented( "locations = targetLocations;" ); sc.add( "}" ); sc.add( "else if ( targetLocations == null )" ); sc.add( "{" ); sc.addIndented( "locations = sourceLocations;" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "locations = new " + fieldImpl + "();" ); sc.addIndented( "locations.putAll( sourceDominant ? targetLocations : sourceLocations );" ); sc.addIndented( "locations.putAll( sourceDominant ? sourceLocations : targetLocations );" ); sc.add( "}" ); sc.add( "result.set" + capitalise( locationsField ) + "( locations );" ); sc.add( "" ); sc.add( "return result;" ); jClass.addMethod( jMethod ); // public static Location merge( Location target, Location source, Collection indices ) jMethod = new JMethod( "merge", new JType( locationClass.getName() ), null ); jMethod.getModifiers().setStatic( true ); jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), "target" ) ); jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), "source" ) ); jMethod.addParameter( new JParameter( new JCollectionType( "java.util.Collection", new JType( "Integer" ), useJava5 ), "indices" ) ); String intWrap = useJava5 ? "Integer.valueOf" : "new Integer"; sc = jMethod.getSourceCode(); sc.add( "if ( source == null )" ); sc.add( "{" ); sc.addIndented( "return target;" ); sc.add( "}" ); sc.add( "else if ( target == null )" ); sc.add( "{" ); sc.addIndented( "return source;" ); sc.add( "}" ); sc.add( "" ); sc.add( locationClass.getName() + " result =" ); sc.add( " new " + locationClass.getName() + "( target.getLineNumber(), target.getColumnNumber()" + ( sourceClass != null ? ", target.get" + capitalise( source.getName() ) + "()" : "" ) + " );" ); sc.add( "" ); sc.add( fieldType + " locations;" ); sc.add( fieldType + " sourceLocations = source.get" + capitalise( locationsField ) + "();" ); sc.add( fieldType + " targetLocations = target.get" + capitalise( locationsField ) + "();" ); sc.add( "if ( sourceLocations == null )" ); sc.add( "{" ); sc.addIndented( "locations = targetLocations;" ); sc.add( "}" ); sc.add( "else if ( targetLocations == null )" ); sc.add( "{" ); sc.addIndented( "locations = sourceLocations;" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.indent(); sc.add( "locations = new " + fieldImpl + "();" ); sc.add( "for ( java.util.Iterator" + ( useJava5 ? "" : "" ) + " it = indices.iterator(); it.hasNext(); )" ); sc.add( "{" ); sc.indent(); sc.add( locationClass.getName() + " location;" ); sc.add( "Integer index = " + ( useJava5 ? "" : "(Integer) " ) + "it.next();" ); sc.add( "if ( index.intValue() < 0 )" ); sc.add( "{" ); sc.addIndented( "location = sourceLocations.get( " + intWrap + "( ~index.intValue() ) );" ); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "location = targetLocations.get( index );" ); sc.add( "}" ); sc.add( "locations.put( " + intWrap + "( locations.size() ), location );" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "result.set" + capitalise( locationsField ) + "( locations );" ); sc.add( "" ); sc.add( "return result;" ); jClass.addMethod( jMethod ); } /** * 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 ( "boolean".equals( baseType ) ) { type = JType.BOOLEAN; } else if ( "byte".equals( baseType ) ) { type = JType.BYTE; } else if ( "char".equals( baseType ) ) { type = JType.CHAR; } else if ( "double".equals( baseType ) ) { type = JType.DOUBLE; } else if ( "float".equals( baseType ) ) { type = JType.FLOAT; } else if ( "int".equals( baseType ) ) { type = JType.INT; } else if ( "short".equals( baseType ) ) { type = JType.SHORT; } else if ( "long".equals( baseType ) ) { type = JType.LONG; } else if ( "Date".equals( baseType ) ) { type = new JClass( "java.util.Date" ); } else if ( "DOM".equals( baseType ) ) { // 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() ) ); } if ( useJava5 && !modelField.getAnnotations().isEmpty() ) { for ( String annotation : modelField.getAnnotations() ) { field.appendAnnotation( annotation ); } } 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 +" != null && !( " + 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 = getJavaAssociationMetadata( modelAssociation ); if ( modelAssociation.isManyMultiplicity() ) { JType componentType = getComponentType( modelAssociation, javaAssociationMetadata ); String defaultValue = getDefaultValue( modelAssociation, componentType ); JType type; if ( modelAssociation.isGenericType() ) { type = new JCollectionType( modelAssociation.getType(), componentType, useJava5 ); } else { type = new JClass( modelAssociation.getType() ); } JField jField = new JField( type, modelAssociation.getName() ); if ( !isEmpty( modelAssociation.getComment() ) ) { jField.setComment( modelAssociation.getComment() ); } if ( useJava5 && !modelAssociation.getAnnotations().isEmpty() ) { for ( String annotation : modelAssociation.getAnnotations() ) { jField.appendAnnotation( annotation ); } } if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.FIELD_INIT ) ) { jField.setInitString( defaultValue ); } if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), JavaAssociationMetadata.CONSTRUCTOR_INIT ) ) { jConstructorSource.add( "this." + jField.getName() + " = " + defaultValue + ";" ); } 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() + " = " + defaultValue + ";" ); 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 ); createBreakAssociation( jClass, modelAssociation ); } } } private String getDefaultValue( ModelAssociation modelAssociation, JType componentType ) { String defaultValue = getDefaultValue( modelAssociation ); if ( modelAssociation.isGenericType() ) { ModelDefault modelDefault = getModel().getDefault( modelAssociation.getType() ); if ( useJava5 ) { defaultValue = StringUtils.replace( modelDefault.getValue(), "", "<" + componentType.getName() + ">" ); } else { defaultValue = StringUtils.replace( modelDefault.getValue(), "", "/*<" + componentType.getName() + ">*/" ); } } return defaultValue; } private JavaAssociationMetadata getJavaAssociationMetadata( ModelAssociation modelAssociation ) throws ModelloException { 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 ); } return javaAssociationMetadata; } private JType getComponentType( ModelAssociation modelAssociation, JavaAssociationMetadata javaAssociationMetadata ) { JType componentType; if ( javaAssociationMetadata.getInterfaceName() != null ) { componentType = new JClass( javaAssociationMetadata.getInterfaceName() ); } else { componentType = new JClass( modelAssociation.getTo() ); } return componentType; } 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 ( ModelField modelField : toClass.getFields( getGeneratedVersion() ) ) { if ( !( modelField instanceof ModelAssociation ) ) { continue; } ModelAssociation modelAssociation = (ModelAssociation) modelField; if ( association == modelAssociation ) { continue; } 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() ) { JType componentType = getComponentType( modelAssociation, javaAssociationMetadata ); type = new JCollectionType( modelAssociation.getType(), componentType, useJava5 ); } else if ( useTo ) { type = new JClass( modelAssociation.getTo() ); } } return type; } private void addParameter( JMethodSignature jMethod, String type, String name, String comment ) { jMethod.addParameter( new JParameter( new JType( type ), name ) ); jMethod.getJDocComment().getParamDescriptor( name ).setDescription( comment ); } } 000077500000000000000000000000001166654766000353475ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasourceJAnnotations.java000066400000000000000000000024041166654766000406210ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasourcepackage org.codehaus.modello.plugin.java.javasource; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class JAnnotations { private List 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(); for ( Iterator iterator = annotations.iterator(); iterator.hasNext(); ) { sb.append( iterator.next() ); 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 ) { for ( Iterator iterator = annotations.iterator(); iterator.hasNext(); ) { jsw.writeln( iterator.next().toString() ); } } // -- print } JArrayType.java000066400000000000000000000034131166654766000402450ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/* * 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 (dim. 21 déc. 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() + "[]"; } // -------------------------------------------------------------------------- } JClass.java000066400000000000000000000666621166654766000374110ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1437 2010-04-15 21:46:36Z bentmann $ * * 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.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: 1437 $ $Date: 2010-04-15 23:46:36 +0200 (jeu. 15 avril 2010) $ */ 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 = 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 " ); } if ( modifiers.isFinal() ) { buffer.append( "final " ); } 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 ( String sourceCodeEntry : sourceCodeEntries ) { jsw.writeln( sourceCodeEntry ); } 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 JCollectionType.java000066400000000000000000000063051166654766000412650ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/* * 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 (dim. 21 déc. 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() + ">*/"; } // -------------------------------------------------------------------------- } JComment.java000066400000000000000000000264421166654766000377360ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (dim. 29 janv. 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 JCompUnit.java000066400000000000000000000466261166654766000401000ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1413 2010-02-13 21:23: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. */ import java.io.File; import java.util.Enumeration; 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: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $ **/ 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 = classes.get( i ); Enumeration e = jClass.getImports(); while ( e.hasMoreElements() ) { allImports.add( e.nextElement() ); } } for ( int i = 0; i < interfaces.size(); ++i ) { 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(); for ( String importName : allImports ) { 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 ( JInterface jInterface : interfaces ) { if ( jInterface.getModifiers().isPublic() == printPublic ) { if ( isFirst ) { Header.print( jsw, printPublic ); isFirst = false; } jInterface.print( jsw, true ); jsw.writeln(); } } //SortedSet classList = classes.sortedOnFullName(); for ( JClass jClass : classes ) { 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 JComponentizedType.java000066400000000000000000000044341166654766000420110ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/* * 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 (dim. 21 déc. 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; } // -------------------------------------------------------------------------- } JConstructor.java000066400000000000000000000211611166654766000406520ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (jeu. 23 juil. 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 JDocComment.java000066400000000000000000000177411166654766000403660ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1413 2010-02-13 21:23: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. */ import java.util.Enumeration; import java.util.Vector; /** * A class that "SOMEWHAT" represents a Java Doc Comment. * * @author Keith Visco * @version $Revision: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $ */ 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 JDocDescriptor.java000066400000000000000000000267401166654766000411010ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (dim. 26 août 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 JField.java000066400000000000000000000205771166654766000373620ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (jeu. 23 juil. 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 JInterface.java000066400000000000000000000420071166654766000402270ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1413 2010-02-13 21:23: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. */ import java.util.ArrayList; import java.util.Enumeration; 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: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $ **/ 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 ( String sourceCodeEntry : sourceCodeEntries ) { jsw.writeln( sourceCodeEntry ); } 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 JMember.java000066400000000000000000000100001166654766000375220ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (jeu. 23 juil. 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 JMethod.java000066400000000000000000000331311166654766000375450ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1413 2010-02-13 21:23: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. */ 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: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $ **/ 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 JMethodSignature.java000066400000000000000000000321421166654766000414300ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1413 2010-02-13 21:23: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. */ 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 1413 2010-02-13 21:23:01Z 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 } //-- JMethodSignatureJModifiers.java000066400000000000000000000262171166654766000402550ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1437 2010-04-15 21:46:36Z bentmann $ */ 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: 1437 $ $Date: 2010-04-15 23:46:36 +0200 (jeu. 15 avril 2010) $ **/ 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 final qualifier is present. *
This is only applicable to methods and classes. * @return true if the final qualifier is present **/ public boolean isFinal() { return isFinal; } //-- isFinal /** * 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 JNamedMap.java000066400000000000000000000172471166654766000400210ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1415 2010-02-13 22:23:37Z 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 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 **/ @SuppressWarnings( "unchecked" ) public Vector getNames() { return (Vector) names.clone(); } //-- getNames /** * Return a Vector of Objects * * @return a Vector of Objects **/ @SuppressWarnings( "unchecked" ) 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 } //-- JNamedMapJNaming.java000066400000000000000000000132351166654766000375410ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (dim. 29 janv. 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 } //-- JNamingJParameter.java000066400000000000000000000141261166654766000402500ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (ven. 24 juil. 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; } } //-- JParamaterJSourceCode.java000066400000000000000000000232251166654766000403630ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1413 2010-02-13 21:23: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. */ import org.codehaus.modello.ModelloRuntimeException; import java.util.Vector; /** * A class for holding in-memory Java source code. * * @author Keith Visco * @version $Revision: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $ **/ 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 JSourceWriter.java000066400000000000000000000365421166654766000407730ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (sam. 18 juil. 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 JStructure.java000066400000000000000000000662211166654766000403330ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 1413 2010-02-13 21:23: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. */ 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: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $ */ 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 ( "java.lang".equals( pkgName ) ) 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 JType.java000066400000000000000000000163351166654766000372550ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/** * 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 (dim. 21 déc. 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 000077500000000000000000000000001166654766000347655ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadataJavaAssociationMetadata.java000066400000000000000000000066711166654766000423610ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadatapackage 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 1413 2010-02-13 21:23:01Z hboutemy $ */ 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; } } JavaClassMetadata.java000066400000000000000000000053361166654766000411470ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadatapackage 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 1413 2010-02-13 21:23:01Z hboutemy $ */ 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; } } JavaFieldMetadata.java000066400000000000000000000041241166654766000411170ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadatapackage 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; } }JavaInterfaceMetadata.java000066400000000000000000000027771166654766000420100ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadatapackage 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.InterfaceMetadata; /** * @author Emmanuel Venisse * @version $Id: JavaInterfaceMetadata.java 1436 2010-04-14 23:04:58Z bentmann $ */ public class JavaInterfaceMetadata implements InterfaceMetadata { public static final String ID = JavaInterfaceMetadata.class.getName(); } JavaMetadataPlugin.java000066400000000000000000000114661166654766000413410ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadatapackage 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.InterfaceMetadata; 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 org.codehaus.modello.model.ModelInterface; import java.util.Map; /** * @author Emmanuel Venisse * @version $Id: JavaMetadataPlugin.java 1436 2010-04-14 23:04:58Z bentmann $ */ 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 InterfaceMetadata getInterfaceMetadata( ModelInterface iface, Map data ) { return new JavaInterfaceMetadata(); } 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; } } JavaModelMetadata.java000066400000000000000000000034031166654766000411330ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadatapackage 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; } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/resources/000077500000000000000000000000001166654766000261215ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/resources/META-INF/000077500000000000000000000000001166654766000272615ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000306015ustar00rootroot00000000000000components.xml000066400000000000000000000012141166654766000334270ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/resources/META-INF/plexus org.codehaus.modello.plugin.ModelloGenerator java org.codehaus.modello.plugin.java.JavaModelloGenerator per-lookup org.codehaus.modello.metadata.MetadataPlugin java org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin per-lookup modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/000077500000000000000000000000001166654766000241425ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/000077500000000000000000000000001166654766000250635ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/000077500000000000000000000000001166654766000256525ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/000077500000000000000000000000001166654766000274455ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000311005ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000323765ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/000077500000000000000000000000001166654766000333175ustar00rootroot00000000000000AbstractAnnotationsVerifier.java000066400000000000000000000041031166654766000415560ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.lang.annotation.Annotation; import org.codehaus.modello.verifier.Verifier; /** * @author Hervé Boutemy * @version $Id: AbstractAnnotationsVerifier.java 1410 2010-02-13 10:29:16Z hboutemy $ */ public abstract class AbstractAnnotationsVerifier extends Verifier { protected void assertAnnotations( String message, Annotation[] annotations, Class... classes ) { assertEquals( classes.length, annotations.length ); for ( Class expectedClass : classes ) { boolean found = false; for ( Annotation annotation : annotations ) { if ( expectedClass.equals( annotation.annotationType() ) ) { found = true; break; } } if ( !found ) { fail( message + " is missing annotation: " + expectedClass ); } } } } AbstractPrincipal.java000066400000000000000000000011511166654766000375060ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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; } } AnnotationsJava4GeneratorTest.java000066400000000000000000000041521166654766000417770ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.util.Properties; import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; /** * Check that annotations are not added to generated sources when Java 5 features are not enabled. * * @version $Id: AnnotationsJava4GeneratorTest.java 1412 2010-02-13 17:59:15Z hboutemy $ */ public class AnnotationsJava4GeneratorTest extends AbstractModelloJavaGeneratorTest { public AnnotationsJava4GeneratorTest() { super( "annotations-java4" ); } public void testJava4GeneratorWithAnnotations() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/annotations.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0", false ); modello.generate( model, "java", parameters ); compileGeneratedSources( false ); } }AnnotationsJavaGeneratorTest.java000066400000000000000000000043711166654766000417160ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.util.Properties; import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; /** * @version $Id: TmpJavaGeneratorTest.java 1125 2009-01-10 20:29:32Z hboutemy $ */ public class AnnotationsJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public AnnotationsJavaGeneratorTest() { super( "annotations" ); } public void testJavaGeneratorWithAnnotations() throws Throwable { if ( skipJava5FeatureTest() ) { return; } ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/annotations.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0", true ); modello.generate( model, "java", parameters ); addDependency( "javax.xml.bind", "jaxb-api" ); addDependency( "javax.persistence", "persistence-api" ); compileGeneratedSources( true ); verifyCompiledGeneratedSources( "AnnotationsVerifier" ); } }AssociationGeneratorTest.java000066400000000000000000000041671166654766000410760ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: AssociationGeneratorTest.java 1408 2010-02-12 21:51:29Z hboutemy $ */ public class AssociationGeneratorTest extends AbstractModelloJavaGeneratorTest { public AssociationGeneratorTest() { super( "oneToManyAssociation" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/oneToManyAssociation.mdo" ) ); Properties parameters = getModelloParameters( "4.0.0" ); modello.generate( model, "java", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "OneToManyAssociationVerifier" ); } } BiDirectionalOverrideJavaGeneratorTest.java000066400000000000000000000033111166654766000436220ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * BiDirectionalOverrideJavaGeneratorTest * * @author Joakim Erdfelt * @version $Id: BiDirectionalOverrideJavaGeneratorTest.java 1408 2010-02-12 21:51:29Z hboutemy $ */ public class BiDirectionalOverrideJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public BiDirectionalOverrideJavaGeneratorTest() { super( "bidirectional" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/bidirectional-override.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0", false ); modello.generate( model, "java", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "JavaVerifier" ); } } FeaturesJava5GeneratorTest.java000066400000000000000000000042211166654766000412560ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Benjamin Bentmann * @version $Id: FeaturesJava5GeneratorTest.java 1408 2010-02-12 21:51:29Z hboutemy $ */ public class FeaturesJava5GeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesJava5GeneratorTest() { super( "features-java5" ); } public void testJavaGenerator() throws Throwable { if ( skipJava5FeatureTest() ) { return; } ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "2.0.0", true ); modello.generate( model, "java", parameters ); compileGeneratedSources( "features", true ); verifyCompiledGeneratedSources( "JavaVerifier" ); } } FeaturesJavaGeneratorTest.java000066400000000000000000000040351166654766000411740ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesJavaGeneratorTest.java 1408 2010-02-12 21:51:29Z hboutemy $ */ public class FeaturesJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesJavaGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "2.0.0" ); modello.generate( model, "java", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "JavaVerifier" ); } } FeaturesVersionJavaGeneratorTest.java000066400000000000000000000051211166654766000425370ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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 1408 2010-02-12 21:51:29Z 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 ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters(); parameters.setProperty( ModelloParameterConstants.ALL_VERSIONS, ALL_VERSIONS ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( true ) ); String[] versions = ALL_VERSIONS.split( "," ); for ( int i = 0; i < versions.length; i++ ) { parameters.setProperty( ModelloParameterConstants.VERSION, versions[i] ); modello.generate( model, "java", parameters ); } compileGeneratedSources(); verifyCompiledGeneratedSources( "JavaVerifier" ); } } InterfaceAssociationTest.java000066400000000000000000000017241166654766000410440ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage org.codehaus.modello.plugin.java; import java.util.Properties; import org.codehaus.modello.AbstractModelloJavaGeneratorTest; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; public class InterfaceAssociationTest extends AbstractModelloJavaGeneratorTest { public InterfaceAssociationTest() { super( "interfaceAssociationTest" ); } public void testJavaGenerator() throws Throwable { if ( skipJava5FeatureTest() ) { return; } ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/interfaceAssociation.mdo" ) ); Properties parameters = getModelloParameters( "4.0.0", true ); modello.generate( model, "java", parameters ); compileGeneratedSources( true ); verifyCompiledGeneratedSources( "InterfaceAssociationVerifier" ); } } JavaGeneratorTest.java000066400000000000000000000040631166654766000374760ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: JavaGeneratorTest.java 1408 2010-02-12 21:51:29Z hboutemy $ */ public class JavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public JavaGeneratorTest() { super( "java" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/maven.mdo" ) ); Properties parameters = getModelloParameters( "4.0.0" ); modello.generate( model, "java", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "JavaVerifier" ); } } LocationsJavaGeneratorTest.java000066400000000000000000000040541166654766000413520ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Benjamin Bentmann * @version $Id: LocationsJavaGeneratorTest.java 1459 2010-04-19 10:36:55Z bentmann $ */ public class LocationsJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public LocationsJavaGeneratorTest() { super( "locations" ); } public void testLocations() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/locations.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "JavaLocationsVerifier" ); } } PackageVersionJavaTest.java000066400000000000000000000044241166654766000404520ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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 java.util.Properties; /** * @author Trygve Laugstøl * @version $Id: PackageVersionJavaTest.java 1408 2010-02-12 21:51:29Z hboutemy $ */ public class PackageVersionJavaTest extends AbstractModelloJavaGeneratorTest { public PackageVersionJavaTest() { super( "packageversion" ); } public void testThatTheCorrectVersionIsInThePackageName() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/maven.mdo" ) ); Properties parameters = getModelloParameters( "4.0.0" ); parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( true ) ); modello.generate( model, "java", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "PackageVersionVerifier" ); } } Permission.java000066400000000000000000000020331166654766000362310ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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 ); } Role.java000066400000000000000000000024401166654766000350040ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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 1415 2010-02-13 22:23:37Z 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(); } TmpJavaGeneratorTest.java000066400000000000000000000043251166654766000401600ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/javapackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * MODELLO-83: check that tmp can be used as a field name without interference with generated code for * hashCode(). * * @author Vincent Siveton * @version $Id: TmpJavaGeneratorTest.java 1399 2010-02-06 22:57:42Z hboutemy $ */ public class TmpJavaGeneratorTest extends AbstractModelloJavaGeneratorTest { public TmpJavaGeneratorTest() { super( "tmp" ); } /** * MODELLO-83 * @throws Throwable */ public void testJavaGeneratorWithTmp() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/models/tmp.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); compileGeneratedSources(); } } 000077500000000000000000000000001166654766000354025ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasourceJavaSourceTest.java000066400000000000000000000133071166654766000411530ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasourcepackage 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() ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/000077500000000000000000000000001166654766000261545ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/models/000077500000000000000000000000001166654766000274375ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/models/annotations.mdo000066400000000000000000000152271166654766000325040ustar00rootroot00000000000000 1.0.0 untitledModel Param 1.0.0 id int @javax.persistence.Id @javax.persistence.SequenceGenerator(name="param_seq", sequenceName="param_pk_seq") @javax.persistence.GeneratedValue(strategy=javax.persistence.GenerationType.SEQUENCE, generator="param_seq") @javax.persistence.Column(name="param_id") 1.0.0 name String @javax.persistence.Column(name="param_name") 1.0.0 value String @javax.persistence.Column(name="param_value") 1.0.0 Group @javax.xml.bind.annotation.XmlRootElement 1.0.0 id int @javax.persistence.Id @javax.persistence.SequenceGenerator(name="group_seq", sequenceName="group_pk_seq") @javax.persistence.GeneratedValue(strategy=javax.persistence.GenerationType.SEQUENCE, generator="group_seq") @javax.persistence.Column(name="group_id") 1.0.0 groupName String @javax.persistence.Column(name="group_name") 1.0.0 users 1.0.0 @javax.persistence.ManyToMany @javax.persistence.JoinTable(name="users_group",joinColumns=@javax.persistence.JoinColumn(name="group_id", referencedColumnName="group_id"),inverseJoinColumns=@javax.persistence.JoinColumn(name="user_id", referencedColumnName="user_id")) User * User 1.0.0 id int @javax.persistence.Id @javax.persistence.SequenceGenerator(name="user_seq", sequenceName="user_pk_seq") @javax.persistence.GeneratedValue(strategy=javax.persistence.GenerationType.SEQUENCE, generator="user_seq") @javax.persistence.Column(name="user_id") 1.0.0 login String @javax.persistence.Column(name="login") 1.0.0 password String @javax.persistence.Column(name="password") 1.0.0 email String @javax.persistence.Column(name="mail") 1.0.0 expirationDate Date @javax.persistence.Column(name="exp_date") 1.0.0 admin boolean @javax.persistence.Column(name="admin") 1.0.0 groups 1.0.0 @javax.persistence.ManyToMany @javax.persistence.JoinTable(name="users_group",inverseJoinColumns=@javax.persistence.JoinColumn(name="group_id", referencedColumnName="group_id"),joinColumns=@javax.persistence.JoinColumn(name="user_id", referencedColumnName="user_id")) Group * SimpleInterface 1.0.0 @javax.xml.bind.annotation.XmlRootElement bidirectional-override.mdo000066400000000000000000000054261166654766000345150ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/models 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 * interfaceAssociation.mdo000066400000000000000000000022021166654766000342120ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/models interface-association-test InterfaceAssociationTest package org.codehaus.modello.ifaceassociation.package1 Location persons Person * relatives Set Person * mother Person Person IPerson modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/models/maven.mdo000066400000000000000000001617211166654766000312560ustar00rootroot00000000000000 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 oneToManyAssociation.mdo000066400000000000000000000037631166654766000342000ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/models 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 * modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/resources/models/tmp.mdo000066400000000000000000000013041166654766000307360ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/000077500000000000000000000000001166654766000261405ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/annotations/000077500000000000000000000000001166654766000304755ustar00rootroot00000000000000AnnotationsVerifier.java000066400000000000000000000041321166654766000352520ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/annotationsimport java.lang.annotation.Annotation; /* * 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.java.AbstractAnnotationsVerifier; /** * @author Brian Demers * @version $Id: AnnotationsVerifier.java 1410 2010-02-13 10:29:16Z hboutemy $ */ public class AnnotationsVerifier extends AbstractAnnotationsVerifier { public void verify() throws Exception { assertAnnotations( "class annotation test", model.Group.class.getAnnotations(), javax.xml.bind.annotation.XmlRootElement.class ); assertAnnotations( "field annotation test", model.Group.class.getDeclaredField( "id" ).getAnnotations(), javax.persistence.Id.class, javax.persistence.SequenceGenerator.class, javax.persistence.GeneratedValue.class, javax.persistence.Column.class ); assertAnnotations( "interface annotation test", model.SimpleInterface.class.getAnnotations(), javax.xml.bind.annotation.XmlRootElement.class ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/bidirectional/000077500000000000000000000000001166654766000307505ustar00rootroot00000000000000JavaVerifier.java000066400000000000000000000017031166654766000341120ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/bidirectionalimport 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() ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/000077500000000000000000000000001166654766000314415ustar00rootroot00000000000000JavaVerifier.java000066400000000000000000000033551166654766000346100ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/* * 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(); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/features/000077500000000000000000000000001166654766000277565ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/features/JavaVerifier.java000066400000000000000000000547141166654766000332110ustar00rootroot00000000000000/* * 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.NodeItem; 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 1484 2010-05-08 17:25:54Z bentmann $ */ 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" , 1234567890123L , simple.getPrimitiveLong() ); Assert.assertEquals( "primitiveFloat" , 12.12f , simple.getPrimitiveFloat(), 0f ); Assert.assertEquals( "primitiveDouble" , 12.12 , simple.getPrimitiveDouble(), 0 ); Assert.assertEquals( "objectBoolean" , Boolean.TRUE , simple.isObjectBoolean() ); Assert.assertEquals( "objectByte" , 12 , simple.getObjectByte().byteValue() ); Assert.assertEquals( "objectChar" , 'H' , simple.getObjectCharacter().charValue() ); Assert.assertEquals( "objectShort" , (short) 1212 , simple.getObjectShort().shortValue() ); Assert.assertEquals( "objectInt" , 121212 , simple.getObjectInteger().intValue() ); Assert.assertEquals( "objectLong" , 1234567890123L , simple.getObjectLong().longValue() ); Assert.assertEquals( "objectFloat" , 12.12f , simple.getObjectFloat().floatValue(), 0f ); Assert.assertEquals( "objectDouble" , 12.12 , simple.getObjectDouble().doubleValue(), 0 ); 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" , 1234567890123L , xmlAttributes.getPrimitiveLong() ); Assert.assertEquals( "primitiveFloat" , 12.12f , xmlAttributes.getPrimitiveFloat(), 0f ); Assert.assertEquals( "primitiveDouble" , 12.12 , xmlAttributes.getPrimitiveDouble(), 0 ); Assert.assertEquals( "objectBoolean" , Boolean.TRUE , xmlAttributes.isObjectBoolean() ); Assert.assertEquals( "objectByte" , 12 , xmlAttributes.getObjectByte().byteValue() ); Assert.assertEquals( "objectChar" , 'H' , xmlAttributes.getObjectCharacter().charValue() ); Assert.assertEquals( "objectShort" , (short) 1212 , xmlAttributes.getObjectShort().shortValue() ); Assert.assertEquals( "objectInt" , 121212 , xmlAttributes.getObjectInteger().intValue() ); Assert.assertEquals( "objectLong" , 1234567890123L , xmlAttributes.getObjectLong().longValue() ); Assert.assertEquals( "objectFloat" , 12.12f , xmlAttributes.getObjectFloat().floatValue(), 0f ); Assert.assertEquals( "objectDouble" , 12.12 , xmlAttributes.getObjectDouble().doubleValue(), 0 ); 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() ); // class with single association to itself, but not bidi! NodeItem parentNode = new NodeItem(); NodeItem childNode = new NodeItem(); parentNode.setChild( childNode ); assertSame( childNode, parentNode.getChild() ); assertNull( childNode.getChild() ); // 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() ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTest/000077500000000000000000000000001166654766000331355ustar00rootroot00000000000000InterfaceAssociationVerifier.java000066400000000000000000000026111166654766000415120ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTestimport junit.framework.Assert; import org.codehaus.modello.ifaceassociation.package1.IPerson; import org.codehaus.modello.ifaceassociation.package1.Person; import org.codehaus.modello.ifaceassociation.package1.Location; import org.codehaus.modello.verifier.Verifier; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import junit.framework.Assert; public class InterfaceAssociationVerifier extends Verifier { public void verify() throws Exception { Location location = new Location(); IPerson person = new Person(); // check List persons attribute getters/setters location.addPerson( person ); List persons = location.getPersons(); location.setPersons( new ArrayList( persons ) ); location.removePerson( person ); // check Set relatives attribute getters/setters location.addRelative( person ); Set relatives = location.getRelatives(); location.setRelatives( new HashSet( relatives ) ); location.removeRelative( person ); IPerson mother = new Person(); location.setMother( mother ); Assert.assertNotNull( location.getMother() ); location.setMother( null ); Assert.assertNull( location.getMother() ); } } 000077500000000000000000000000001166654766000336455ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTest/org000077500000000000000000000000001166654766000354405ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTest/org/codehaus000077500000000000000000000000001166654766000370735ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTest/org/codehaus/modello000077500000000000000000000000001166654766000423775ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTest/org/codehaus/modello/ifaceassociation000077500000000000000000000000001166654766000440535ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTest/org/codehaus/modello/ifaceassociation/package1IPerson.java000066400000000000000000000001321166654766000462710ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/interfaceAssociationTest/org/codehaus/modello/ifaceassociation/package1package org.codehaus.modello.ifaceassociation.package1; public interface IPerson { }modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/java/000077500000000000000000000000001166654766000270615ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/java/JavaVerifier.java000066400000000000000000000112401166654766000322770ustar00rootroot00000000000000/* * 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() ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/locations/000077500000000000000000000000001166654766000301335ustar00rootroot00000000000000JavaLocationsVerifier.java000066400000000000000000000035351166654766000351560ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/locations/* * 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.locations.Item; import org.codehaus.modello.test.locations.Location; import org.codehaus.modello.test.locations.LocationTracker; import org.codehaus.modello.test.locations.Model; import org.codehaus.modello.verifier.Verifier; /** * @author Benjamin Bentmann * @version $Id: JavaLocationsVerifier.java 1459 2010-04-19 10:36:55Z bentmann $ */ public class JavaLocationsVerifier extends Verifier { public void verify() throws Exception { assertTrue( LocationTracker.class.isAssignableFrom( Model.class ) ); assertTrue( LocationTracker.class.isAssignableFrom( Item.class ) ); assertTrue( LocationTracker.class.isAssignableFrom( Location.class ) ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/oneToManyAssociation/000077500000000000000000000000001166654766000322465ustar00rootroot00000000000000OneToManyAssociationVerifier.java000066400000000000000000000103021166654766000405700ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/oneToManyAssociationimport 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() ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/packageversion/000077500000000000000000000000001166654766000311415ustar00rootroot00000000000000PackageVersionVerifier.java000066400000000000000000000112771166654766000363320ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/test/verifiers/packageversion/* * 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() ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/000077500000000000000000000000001166654766000224045ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/pom.xml000066400000000000000000000035301166654766000237220ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 dom4j dom4j 1.6.1 test maven-dependency-plugin modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/000077500000000000000000000000001166654766000231735ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/000077500000000000000000000000001166654766000241175ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/000077500000000000000000000000001166654766000250405ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/org/000077500000000000000000000000001166654766000256275ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/000077500000000000000000000000001166654766000274225ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000310555ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000323535ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/000077500000000000000000000000001166654766000333045ustar00rootroot00000000000000AbstractJDOMGenerator.java000066400000000000000000000027041166654766000401570ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdompackage 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 { } JDOMWriterGenerator.java000066400000000000000000001127231166654766000376730ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/* ========================================================================== * 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.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.List; import java.util.Properties; /** * @author mkleint@codehaus.org */ public class JDOMWriterGenerator extends AbstractJDOMGenerator { private boolean requiresDomSupport; public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); requiresDomSupport = false; 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" ); 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 ); if ( requiresDomSupport ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); jClass.addMethods( generateDomMethods() ); } 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 ) { String variableName = uncapitalise( root ); JMethod marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( root ), variableName ) ); 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 + "( " + variableName + ", \"" + 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 ) { String variableName = uncapitalise( root ); JMethod marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( root ), variableName ) ); 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( " + variableName + ", document, writer, format );" ); return marshall; } private JMethod generateWriteModel3( String root, String rootElement ) { String variableName = uncapitalise( root ); JMethod marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( root ), variableName ) ); 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 + "( " + variableName + ", \"" + 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 ( shouldExist )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( element == null )" ); sc.add( "{" ); sc.indent(); sc.add( "element = factory.element( name, parent.getNamespace() );" ); sc.add( "insertAtPreferredLocation( parent, element, counter );" ); sc.unindent(); sc.add( "}" ); sc.add( "counter.increaseCount();" ); sc.unindent(); sc.add( "}" ); sc.add( "else if ( 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;" ); return new JMethod[] { findRSElement, updateElement, insAtPref, findRSProps, findRSLists }; } private JMethod[] generateDomMethods() { 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(); JSourceCode 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[] { findRSDom, findRSDom2 }; } private void writeAllClasses( Model objectModel, JClass jClass, ModelClass rootClass ) throws ModelloException { List alwaysExistingElements = new ArrayList(); alwaysExistingElements.add( rootClass ); for ( ModelClass clazz : getClasses( objectModel ) ) { updateClass( clazz, jClass, alwaysExistingElements ); } } private void updateClass( ModelClass clazz, JClass jClass, List alwaysExisting ) throws ModelloException { String className = clazz.getName(); String capClassName = capitalise( className ); String uncapClassName = uncapitalise( className ); JMethod marshall = new JMethod( "update" + capClassName ); marshall.addParameter( new JParameter( new JClass( className ), uncapClassName ) ); 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(); JSourceCode sc = marshall.getSourceCode(); boolean shouldExist = alwaysExisting.contains( clazz ); if ( shouldExist ) { sc.add( "Element root = element;" ); } else { sc.add( "boolean shouldExist = ( " + uncapClassName + " != 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 = getFieldsForXml( clazz, getGeneratedVersion() ); for ( ModelField field : modelFields ) { 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.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 + " );" ); requiresDomSupport = true; } 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 ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/resources/000077500000000000000000000000001166654766000261315ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/resources/META-INF/000077500000000000000000000000001166654766000272715ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000306115ustar00rootroot00000000000000components.xml000066400000000000000000000005501166654766000334410ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/main/resources/META-INF/plexus org.codehaus.modello.plugin.ModelloGenerator jdom-writer org.codehaus.modello.plugin.jdom.JDOMWriterGenerator per-lookup modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/site/000077500000000000000000000000001166654766000241375ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/site/site.xml000066400000000000000000000005571166654766000256340ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/site/xdoc/000077500000000000000000000000001166654766000250745ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/site/xdoc/index.xml000066400000000000000000000024741166654766000267340ustar00rootroot00000000000000 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
modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/000077500000000000000000000000001166654766000241525ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/java/000077500000000000000000000000001166654766000250735ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/java/org/000077500000000000000000000000001166654766000256625ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/000077500000000000000000000000001166654766000274555ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000311105ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000324065ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/plugin/jdom/000077500000000000000000000000001166654766000333375ustar00rootroot00000000000000FeaturesJDOMGeneratorTest.java000066400000000000000000000045731166654766000410730ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/java/org/codehaus/modello/plugin/jdompackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesJDOMGeneratorTest.java 1473 2010-04-24 16:46:13Z bentmann $ */ public class FeaturesJDOMGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesJDOMGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "dom4j-reader", parameters ); modello.generate( model, "jdom-writer", parameters ); addDependency( "dom4j", "dom4j" ); // needed to read features.xml with dom4j addDependency( "org.jdom", "jdom" ); addDependency( "xmlunit", "xmlunit" ); compileGeneratedSources(); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.jdom.JDOMFeaturesVerifier" ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/verifiers/000077500000000000000000000000001166654766000261505ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/000077500000000000000000000000001166654766000277665ustar00rootroot00000000000000JDOMFeaturesVerifier.java000066400000000000000000000104121166654766000344740ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-jdom/src/test/verifiers/featurespackage 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 1338 2010-01-09 00:04:15Z hboutemy $ */ 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 ); System.err.println( "known features missing: MODELLO-161 = attributes, MODELLO-202 = Content type, " + "and much more: Properties, xml.tagName, ..." ); /*throw*/ new VerifierException( "writer result is not the same as original content: " + diff ) .printStackTrace( System.err ); } } } modello1.4-1.4.1/modello-plugins/modello-plugin-stax/000077500000000000000000000000001166654766000224325ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/pom.xml000066400000000000000000000044261166654766000237550ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 org.codehaus.plexus plexus-utils stax stax-api 1.0.1 test org.codehaus.woodstox wstx-asl 3.2.0 test xmlunit xmlunit 1.2 test maven-dependency-plugin modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/000077500000000000000000000000001166654766000232215ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/000077500000000000000000000000001166654766000241455ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/000077500000000000000000000000001166654766000250665ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/000077500000000000000000000000001166654766000256555ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/000077500000000000000000000000001166654766000274505ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000311035ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000324015ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/000077500000000000000000000000001166654766000333605ustar00rootroot00000000000000AbstractStaxGenerator.java000066400000000000000000000106401166654766000404170ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/staxpackage 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.List; import java.util.Properties; import java.util.Set; /** * @author Trygve Laugstøl * @version $Id: AbstractStaxGenerator.java 1413 2010-02-13 21:23:01Z 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 = 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 ( ModelClass clazz : modelClass.getModel().getClasses( getGeneratedVersion() ) ) { for ( ModelField modelField : clazz.getFields( getGeneratedVersion() ) ) { 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 ); } } DummyIdModelField.java000066400000000000000000000024731166654766000374470ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/staxpackage 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"; } } GeneratorNode.java000066400000000000000000000073331166654766000367060ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/staxpackage 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; } } StaxReaderGenerator.java000066400000000000000000002077461166654766000400750ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/staxpackage 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.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.List; import java.util.Properties; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: StaxReaderGenerator.java 1480 2010-04-27 18:43:34Z bentmann $ */ public class StaxReaderGenerator extends AbstractStaxGenerator { private boolean requiresDomSupport; public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); requiresDomSupport = false; 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.InputStream" ); 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.*" ); addModelImports( jClass, null ); // ---------------------------------------------------------------------- // Write reference resolvers. // ---------------------------------------------------------------------- ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); JClass rootType = new JClass( root.getName() ); GeneratorNode rootNode = findRequiredReferenceResolvers( root, null ); writeReferenceResolvers( rootNode, jClass ); for ( GeneratorNode node : rootNode.getNodesWithReferencableChildren().values() ) { writeReferenceResolvers( node, jClass ); } // ---------------------------------------------------------------------- // Write the read(XMLStreamReader,boolean) method which will do the unmarshalling. // ---------------------------------------------------------------------- JMethod unmarshall = new JMethod( "read", rootType, null ); unmarshall.getModifiers().makePrivate(); unmarshall.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XMLStreamException" ) ); JSourceCode sc = unmarshall.getSourceCode(); String tagName = resolveTagName( root ); String className = root.getName(); String variableName = uncapitalise( className ); sc.add( "int eventType = xmlStreamReader.getEventType();" ); sc.add( "while ( eventType != XMLStreamConstants.END_DOCUMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( eventType == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict && ! \"" + tagName + "\".equals( xmlStreamReader.getLocalName() ) )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Expected root element '" + tagName + "' but " + "found '\" + xmlStreamReader.getLocalName() + \"'\", xmlStreamReader.getLocation(), null );" ); sc.add( "}" ); VersionDefinition versionDefinition = objectModel.getVersionDefinition(); if ( versionDefinition != null && "namespace".equals( versionDefinition.getType() ) ) { sc.add( "String modelVersion = getVersionFromRootNamespace( xmlStreamReader );" ); writeModelVersionCheck( sc ); } sc.add( className + ' ' + variableName + " = parse" + root.getName() + "( xmlStreamReader, strict );" ); sc.add( variableName + ".setModelEncoding( xmlStreamReader.getCharacterEncodingScheme() );" ); sc.add( "resolveReferences( " + variableName + " );" ); sc.add( "return " + variableName + ';' ); sc.unindent(); sc.add( "}" ); sc.add( "eventType = xmlStreamReader.next();" ); sc.unindent(); sc.add( "}" ); sc.add( "throw new XMLStreamException( \"Expected root element '" + tagName + "' but " + "found no element at all: invalid XML document\", xmlStreamReader.getLocation(), null );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the read(Reader[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, 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( "XMLStreamException" ) ); sc = unmarshall.getSourceCode(); sc.add( "XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader( reader );" ); sc.add( "" ); sc.add( "return read( xmlStreamReader, strict );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XMLStreamException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( reader, true );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the read(InputStream[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "stream" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XMLStreamException" ) ); sc = unmarshall.getSourceCode(); sc.add( "XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader( stream );" ); sc.add( "" ); sc.add( "return read( xmlStreamReader, strict );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "stream" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XMLStreamException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( stream, true );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the read(String[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "String" ), "filePath" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XMLStreamException" ) ); sc = unmarshall.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( "return read( xmlStreamReader, strict );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "String" ), "filePath" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XMLStreamException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( filePath, true );" ); jClass.addMethod( unmarshall ); // 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. if ( versionDefinition != null ) { writeDetermineVersionMethod( jClass, objectModel ); } // ---------------------------------------------------------------------- // Write the class parsers // ---------------------------------------------------------------------- writeAllClassesParser( objectModel, jClass ); // ---------------------------------------------------------------------- // Write helpers // ---------------------------------------------------------------------- writeHelpers( jClass ); if ( requiresDomSupport ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); 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 ( String version : versions ) { 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 ( \"3\".equals( modelVersion ) )" ); sc.add( "{" ); sc.addIndented( "modelVersion = \"3.0.0\";" ); sc.add( "}" ); } 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 ( ModelClass clazz : getClasses( objectModel ) ) { 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( "XMLStreamReader" ), "xmlStreamReader" ) ); unmarshall.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); 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 ); 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 ( ( strict ? xmlStreamReader.nextTag() : nextTag( xmlStreamReader ) ) == XMLStreamConstants.START_ELEMENT )" ); sc.add( "{" ); sc.indent(); boolean addElse = false; // Write other fields for ( ModelField field : modelClass.getAllFields( getGeneratedVersion(), true ) ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( !xmlFieldMetadata.isAttribute() && !xmlFieldMetadata.isTransient() ) { processField( field, xmlFieldMetadata, addElse, sc, uncapClassName, rootElement, jClass ); addElse = true; } } /* 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( "checkUnknownElement( xmlStreamReader, strict );" ); if ( addElse ) { 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 ( ModelField field : modelClass.getAllFields( getGeneratedVersion(), true ) ) { 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 ( GeneratorNode child : value.getChildren() ) { 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 ( GeneratorNode child : node.getChildren() ) { 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 ( ModelField field : modelClass.getAllFields( getGeneratedVersion(), true ) ) { 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() + "( xmlStreamReader, strict ) );" ); } 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 ( \"" + valuesTagName + "\".equals( xmlStreamReader.getLocalName() ) )" ); sc.add( "{" ); sc.indent(); } else { sc.add( ( addElse ? "else " : "" ) + "if ( \"" + valuesTagName + "\".equals( xmlStreamReader.getLocalName() ) )" ); 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() + "( xmlStreamReader, strict ) );" ); } else { sc.add( objectName + ".add" + capitalise( singular( associationName ) ) + "( parse" + association.getTo() + "( xmlStreamReader, strict ) );" ); } } 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 ( \"" + valuesTagName + "\".equals( xmlStreamReader.getLocalName() ) )" ); 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 ( \"key\".equals( xmlStreamReader.getLocalName() ) )" ); sc.add( "{" ); sc.addIndented( "key = xmlStreamReader.getElementText();" ); sc.add( "}" ); sc.add( "else if ( \"value\".equals( xmlStreamReader.getLocalName() ) )" ); 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 ( !\"" + getGeneratedVersion() + "\".equals( modelVersion ) )" ); 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 )"; } */ 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 ) );" ); requiresDomSupport = true; } 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(), xmlStreamReader.getLocation(), e )" ); 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.add( tagName ) )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Duplicated tag: '\" + tagName + \"'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); sc.add( "return true;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "checkUnknownElement", null, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); method.addException( new JClass( "XMLStreamException" ) ); sc = method.getSourceCode(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XMLStreamException( \"Unrecognised tag: '\" + xmlStreamReader.getLocalName() + " + "\"'\", xmlStreamReader.getLocation() );" ); sc.add( "}" ); 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( "}" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "nextTag", JType.INT, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "XMLStreamReader" ), "xmlStreamReader" ) ); method.addException( new JClass( "XMLStreamException" ) ); sc = method.getSourceCode(); sc.add( "while ( true )" ); sc.add( "{" ); sc.indent(); sc.add( "int eventType = xmlStreamReader.next();" ); sc.add( "switch ( eventType )" ); sc.add( "{" ); sc.indent(); sc.add( "case XMLStreamConstants.CHARACTERS:" ); sc.add( "case XMLStreamConstants.CDATA:" ); sc.add( "case XMLStreamConstants.SPACE:" ); sc.add( "case XMLStreamConstants.PROCESSING_INSTRUCTION:" ); sc.add( "case XMLStreamConstants.COMMENT:" ); sc.addIndented( "break;" ); sc.add( "case XMLStreamConstants.START_ELEMENT:" ); sc.add( "case XMLStreamConstants.END_ELEMENT:" ); sc.addIndented( "return eventType;" ); sc.add( "default:" ); sc.addIndented( "throw new XMLStreamException( \"expected start or end tag\", xmlStreamReader.getLocation() );" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); 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 nfe )" ); 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(), nfe );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return 0;" ); return method; } } StaxSerializerGenerator.java000066400000000000000000000357371166654766000410030ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/staxpackage 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.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.plexus.util.StringUtils; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; /** * Generates the IndentingXMLStreamWriter used by the writer for pretty printing. * * @author Benjamin Bentmann * @version $Id: StaxSerializerGenerator.java 1447 2010-04-17 16:45:58Z bentmann $ */ public class StaxSerializerGenerator extends AbstractStaxGenerator { public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); try { generateStaxSerializer(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating StAX serializer.", ex ); } } private void generateStaxSerializer() throws ModelloException, IOException { Model objectModel = getModel(); String packageName = objectModel.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) + ".io.stax"; String className = "IndentingXMLStreamWriter"; JSourceWriter sourceWriter = newJSourceWriter( packageName, className ); JClass jClass = new JClass( packageName + '.' + className ); jClass.getModifiers().makePackage(); jClass.addInterface( "XMLStreamWriter" ); initHeader( jClass ); suppressAllWarnings( objectModel, jClass ); jClass.addImport( "javax.xml.namespace.NamespaceContext" ); jClass.addImport( "javax.xml.stream.XMLStreamException" ); jClass.addImport( "javax.xml.stream.XMLStreamWriter" ); addField( jClass, "XMLStreamWriter", "out", null, false ); addField( jClass, "String", "NEW_LINE", "\"\\n\"", true ); addField( jClass, "String", "newLine", "NEW_LINE", false ); addField( jClass, "String", "indent", "\" \"", false ); addField( jClass, "char[]", "linePrefix", "\" \".toCharArray()", false ); addField( jClass, "int", "depth", null, false ); addField( jClass, "byte[]", "states", "{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }", false ); addField( jClass, "int", "ELEMENT_HAS_DATA", "0x1", true ); addField( jClass, "int", "ELEMENT_HAS_MARKUP", "0x2", true ); JConstructor constructor = jClass.createConstructor(); constructor.addParameter( new JParameter( new JType( "XMLStreamWriter" ), "out" ) ); constructor.getSourceCode().add( "this.out = out;" ); JMethod jMethod; JSourceCode sc; jMethod = new JMethod( "setNewLine" ); jMethod.addParameter( new JParameter( new JType( "String" ), "newLine" ) ); jMethod.getSourceCode().add( "this.newLine = newLine;" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "getLineSeparator", new JType( "String" ), null ); sc = jMethod.getSourceCode(); sc.add( "try" ); sc.add( "{" ); sc.addIndented( "return System.getProperty( \"line.separator\", NEW_LINE );" ); sc.add( "}" ); sc.add( "catch ( Exception e )" ); sc.add( "{" ); sc.addIndented( "return NEW_LINE;" ); sc.add( "}" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "beforeMarkup" ); jMethod.getModifiers().makePrivate(); sc = jMethod.getSourceCode(); sc.add( "int state = states[depth];" ); sc.add( "if ( ( state & ELEMENT_HAS_DATA ) == 0 && ( depth > 0 || state != 0 ) )" ); sc.add( "{" ); sc.indent(); sc.add( "newLine( depth );" ); sc.add( "if ( depth > 0 && indent.length() > 0 )" ); sc.add( "{" ); sc.addIndented( "afterMarkup();" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "afterMarkup" ); jMethod.getModifiers().makePrivate(); jMethod.getSourceCode().add( "states[depth] |= ELEMENT_HAS_MARKUP;" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "beforeStartElement" ); jMethod.getModifiers().makePrivate(); sc = jMethod.getSourceCode(); sc.add( "beforeMarkup();" ); sc.add( "if ( states.length <= depth + 1 )" ); sc.add( "{" ); sc.indent(); sc.add( "byte[] tmp = new byte[states.length * 2];" ); sc.add( "System.arraycopy( states, 0, tmp, 0, states.length );" ); sc.add( "states = tmp;" ); sc.unindent(); sc.add( "}" ); sc.add( "states[depth + 1] = 0;" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "afterStartElement" ); jMethod.getModifiers().makePrivate(); sc = jMethod.getSourceCode(); sc.add( "afterMarkup();" ); sc.add( "depth++;" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "beforeEndElement" ); jMethod.getModifiers().makePrivate(); sc = jMethod.getSourceCode(); sc.add( "if ( depth > 0 && states[depth] == ELEMENT_HAS_MARKUP )" ); sc.add( "{" ); sc.addIndented( "newLine( depth - 1 );" ); sc.add( "}" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "afterEndElement" ); jMethod.getModifiers().makePrivate(); sc = jMethod.getSourceCode(); sc.add( "if ( depth > 0 )" ); sc.add( "{" ); sc.indent(); sc.add( "depth--;" ); sc.add( "if ( depth <= 0 )" ); sc.add( "{" ); sc.addIndented( "newLine( 0 );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "afterData" ); jMethod.getModifiers().makePrivate(); jMethod.getSourceCode().add( "states[depth] |= ELEMENT_HAS_DATA;" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "newLine" ); jMethod.addParameter( new JParameter( JType.INT, "depth" ) ); jMethod.getModifiers().makePrivate(); sc = jMethod.getSourceCode(); sc.add( "try" ); sc.add( "{" ); sc.indent(); sc.add( "out.writeCharacters( newLine );" ); sc.add( "int prefixLength = depth * indent.length();" ); sc.add( "while ( linePrefix.length < prefixLength )" ); sc.add( "{" ); sc.indent(); sc.add( "char[] tmp = new char[linePrefix.length * 2];" ); sc.add( "System.arraycopy( linePrefix, 0, tmp, 0, linePrefix.length );" ); sc.add( "System.arraycopy( linePrefix, 0, tmp, linePrefix.length, linePrefix.length );" ); sc.add( "linePrefix = tmp;" ); sc.unindent(); sc.add( "}" ); sc.add( "out.writeCharacters( linePrefix, 0, prefixLength );" ); sc.unindent(); sc.add( "}" ); sc.add( "catch ( Exception e )" ); sc.add( "{" ); sc.add( "}" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "close" ); jMethod.addException( new JClass( "XMLStreamException" ) ); jMethod.getSourceCode().add( "out.close();" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "flush" ); jMethod.addException( new JClass( "XMLStreamException" ) ); jMethod.getSourceCode().add( "out.flush();" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "getNamespaceContext", new JType( "NamespaceContext" ), null ); jMethod.getSourceCode().add( "return out.getNamespaceContext();" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "getPrefix", new JType( "String" ), null ); jMethod.addException( new JClass( "XMLStreamException" ) ); jMethod.addParameter( param( "String", "uri" ) ); jMethod.getSourceCode().add( "return out.getPrefix( uri );" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "getProperty", new JType( "Object" ), null ); jMethod.addException( new JClass( "IllegalArgumentException" ) ); jMethod.addParameter( param( "String", "name" ) ); jMethod.getSourceCode().add( "return out.getProperty( name );" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "setDefaultNamespace" ); jMethod.addException( new JClass( "XMLStreamException" ) ); jMethod.addParameter( param( "String", "uri" ) ); jMethod.getSourceCode().add( "out.setDefaultNamespace( uri );" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "setNamespaceContext" ); jMethod.addException( new JClass( "XMLStreamException" ) ); jMethod.addParameter( param( "NamespaceContext", "context" ) ); jMethod.getSourceCode().add( "out.setNamespaceContext( context );" ); jClass.addMethod( jMethod ); jMethod = new JMethod( "setPrefix" ); jMethod.addException( new JClass( "XMLStreamException" ) ); jMethod.addParameter( param( "String", "prefix" ) ); jMethod.addParameter( param( "String", "uri" ) ); jMethod.getSourceCode().add( "out.setPrefix( prefix, uri );" ); jClass.addMethod( jMethod ); add( jClass, "Attribute", null, null, param( "String", "localName" ), param( "String", "value" ) ); add( jClass, "Attribute", null, null, param( "String", "namespaceURI" ), param( "String", "localName" ), param( "String", "value" ) ); add( jClass, "Attribute", null, null, param( "String", "prefix" ), param( "String", "namespaceURI" ), param( "String", "localName" ), param( "String", "value" ) ); add( jClass, "CData", null, "Data", param( "String", "data" ) ); add( jClass, "Characters", null, "Data", param( "String", "text" ) ); add( jClass, "Characters", null, "Data", param( "char[]", "text" ), param( "int", "start" ), param( "int", "len" ) ); add( jClass, "Comment", "Markup", "Markup", param( "String", "data" ) ); add( jClass, "DTD", "Markup", "Markup", param( "String", "dtd" ) ); add( jClass, "DefaultNamespace", null, null, param( "String", "namespaceURI" ) ); add( jClass, "EmptyElement", "Markup", "Markup", param( "String", "localName" ) ); add( jClass, "EmptyElement", "Markup", "Markup", param( "String", "namespaceURI" ), param( "String", "localName" ) ); add( jClass, "EmptyElement", "Markup", "Markup", param( "String", "prefix" ), param( "String", "namespaceURI" ), param( "String", "localName" ) ); add( jClass, "EndDocument", null, null ); add( jClass, "EndElement", "EndElement", "EndElement" ); add( jClass, "EntityRef", null, "Data", param( "String", "name" ) ); add( jClass, "Namespace", null, null, param( "String", "prefix" ), param( "String", "namespaceURI" ) ); add( jClass, "ProcessingInstruction", "Markup", "Markup", param( "String", "target" ) ); add( jClass, "ProcessingInstruction", "Markup", "Markup", param( "String", "target" ), param( "String", "data" ) ); add( jClass, "StartDocument", "Markup", "Markup" ); add( jClass, "StartDocument", "Markup", "Markup", param( "String", "version" ) ); add( jClass, "StartDocument", "Markup", "Markup", param( "String", "encoding" ), param( "String", "version" ) ); add( jClass, "StartElement", "StartElement", "StartElement", param( "String", "localName" ) ); add( jClass, "StartElement", "StartElement", "StartElement", param( "String", "namespaceURI" ), param( "String", "localName" ) ); add( jClass, "StartElement", "StartElement", "StartElement", param( "String", "prefix" ), param( "String", "localName" ), param( "String", "namespaceURI" ) ); jClass.print( sourceWriter ); sourceWriter.close(); } private void addField( JClass jClass, String fieldType, String fieldName, String initializer, boolean constant ) { JField jField = new JField( new JType( fieldType ), fieldName ); jField.setInitString( initializer ); if ( constant ) { jField.getModifiers().setFinal( true ); jField.getModifiers().setStatic( true ); } jClass.addField( jField ); } private void add( JClass jClass, String name, String before, String after, JParameter... params ) { List names = new ArrayList(); JMethod jMethod = new JMethod( "write" + name ); jMethod.addException( new JClass( "XMLStreamException" ) ); for ( JParameter param : params ) { jMethod.addParameter( param ); names.add( param.getName() ); } JSourceCode sc = jMethod.getSourceCode(); if ( before != null ) { sc.add( "before" + before + "();" ); } sc.add( "out.write" + name + "( " + StringUtils.join( names.iterator(), ", " ) + " );" ); if ( after != null ) { sc.add( "after" + after + "();" ); } jClass.addMethod( jMethod ); } private static JParameter param( String type, String name ) { return new JParameter( new JType( type ), name ); } } StaxWriterGenerator.java000066400000000000000000000611561166654766000401400ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/staxpackage 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.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.List; import java.util.Properties; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: StaxWriterGenerator.java 1474 2010-04-24 19:59:00Z bentmann $ */ public class StaxWriterGenerator extends AbstractStaxGenerator { private boolean requiresDomSupport; private StaxSerializerGenerator serializerGenerator; public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); requiresDomSupport = false; try { generateStaxWriter(); } catch ( IOException ex ) { throw new ModelloException( "Exception while generating StAX Writer.", ex ); } serializerGenerator.generate( model, parameters ); } 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.IOException" ); jClass.addImport( "java.io.OutputStream" ); 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.*" ); 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 write( Writer, Model ) 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 ); // ---------------------------------------------------------------------- // Write the write( OutputStream, Model ) method which will do the unmarshalling. // ---------------------------------------------------------------------- marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( "OutputStream" ), "stream" ) ); marshall.addParameter( new JParameter( new JClass( root ), rootElementParameterName ) ); marshall.addException( new JClass( "java.io.IOException" ) ); marshall.addException( new JClass( "XMLStreamException" ) ); 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( stream, " + rootElementParameterName + ".getModelEncoding() ) );" ); 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 ); writeAllClasses( objectModel, jClass ); if ( requiresDomSupport ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3Dom" ); createWriteDomMethod( jClass ); } jClass.print( sourceWriter ); sourceWriter.close(); } private void writeAllClasses( Model objectModel, JClass jClass ) throws ModelloException { for ( ModelClass clazz : getClasses( objectModel ) ) { 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 = getFieldsForXml( modelClass, getGeneratedVersion() ); // XML attributes for ( ModelField field : modelFields ) { 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 ( ModelField field : modelFields ) { 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 );" ); requiresDomSupport = true; } 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 ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/resources/000077500000000000000000000000001166654766000261575ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/resources/META-INF/000077500000000000000000000000001166654766000273175ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000306375ustar00rootroot00000000000000components.xml000066400000000000000000000023341166654766000334710ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/main/resources/META-INF/plexus org.codehaus.modello.plugin.ModelloGenerator stax-reader org.codehaus.modello.plugin.stax.StaxReaderGenerator per-lookup org.codehaus.modello.plugin.ModelloGenerator stax-writer org.codehaus.modello.plugin.stax.StaxWriterGenerator per-lookup serializerGenerator org.codehaus.modello.plugin.stax.StaxSerializerGenerator stax-serializer org.codehaus.modello.plugin.stax.StaxSerializerGenerator stax-serializer org.codehaus.modello.plugin.stax.StaxSerializerGenerator per-lookup modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/site/000077500000000000000000000000001166654766000241655ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/site/site.xml000066400000000000000000000005571166654766000256620ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/site/xdoc/000077500000000000000000000000001166654766000251225ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/site/xdoc/index.xml000066400000000000000000000050211166654766000267510ustar00rootroot00000000000000 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
modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/000077500000000000000000000000001166654766000242005ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/000077500000000000000000000000001166654766000251215ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/000077500000000000000000000000001166654766000257105ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/000077500000000000000000000000001166654766000275035ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000311365ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/000077500000000000000000000000001166654766000331245ustar00rootroot00000000000000000077500000000000000000000000001166654766000336455ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml000077500000000000000000000000001166654766000346245ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxAbstractStaxGeneratorTestCase.java000066400000000000000000000062441166654766000434030ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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.ModelloParameterConstants; import org.codehaus.modello.core.ModelloCore; import org.codehaus.modello.model.Model; import org.codehaus.plexus.util.StringUtils; 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 Exception { verifyModel( model, className, null ); } protected void verifyModel( Model model, String className, String[] versions ) throws Exception { Properties parameters = getModelloParameters( "4.0.0" ); 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( "stax", "stax-api" ); addDependency( "org.codehaus.woodstox", "wstx-asl" ); compileGeneratedSources(); verifyCompiledGeneratedSources( className ); } } FeaturesStaxGeneratorTest.java000066400000000000000000000050161166654766000426160ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesStaxGeneratorTest.java 1473 2010-04-24 16:46:13Z bentmann $ */ public class FeaturesStaxGeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesStaxGeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "stax-writer", parameters ); modello.generate( model, "stax-reader", parameters ); addDependency( "stax", "stax-api" ); addDependency( "org.codehaus.woodstox", "wstx-asl" ); addDependency( "xmlunit", "xmlunit" ); compileGeneratedSources(); // TODO: see why without this, version system property is set to "2.4.1" value after verify System.setProperty( "version", getModelloVersion() ); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.stax.StaxFeaturesVerifier" ); } } StaxGeneratorPartsTest.java000066400000000000000000000042241166654766000421310ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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 java.util.List; /** * @version $Id: StaxGeneratorPartsTest.java 1413 2010-02-13 21:23:01Z hboutemy $ */ public class StaxGeneratorPartsTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorPartsTest() throws ComponentLookupException { super( "stax-parts" ); } public void testStaxReaderParts() throws Throwable { Model model = modello.loadModel( getXmlResourceReader( "/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" ); } } StaxGeneratorTest.java000066400000000000000000000060311166654766000411150ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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 java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorTest.java 1413 2010-02-13 21:23:01Z hboutemy $ */ public class StaxGeneratorTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorTest() throws ComponentLookupException { super( "stax" ); } public void testStaxGenerator() throws Throwable { Model model = modello.loadModel( getXmlResourceReader( "/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" ); } } StaxGeneratorVersionInFieldTest.java000066400000000000000000000024061166654766000437200ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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 java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorVersionInFieldTest.java 1413 2010-02-13 21:23:01Z hboutemy $ */ public class StaxGeneratorVersionInFieldTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionInFieldTest() throws ComponentLookupException { super( "stax-version-in-field" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( getXmlResourceReader( "/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" ); } } StaxGeneratorVersionInNamespaceTest.java000066400000000000000000000024361166654766000445740ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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 java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorVersionInNamespaceTest.java 1413 2010-02-13 21:23:01Z hboutemy $ */ public class StaxGeneratorVersionInNamespaceTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionInNamespaceTest() throws ComponentLookupException { super( "stax-version-in-namespace" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( getXmlResourceReader( "/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" ); } } StaxGeneratorVersionReaderDelegateTest.java000066400000000000000000000037161166654766000452500ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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; /** * @version $Id: StaxGeneratorVersionReaderDelegateTest.java 1389 2010-02-06 11:19:28Z hboutemy $ */ public class StaxGeneratorVersionReaderDelegateTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionReaderDelegateTest() throws ComponentLookupException { super( "stax-version-reader-delegate" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( getXmlResourceReader( "/version-in-namespace.mdo" ) ); verifyModel( model, "org.codehaus.modello.generator.xml.stax.StaxVerifierVersionReaderDelegate", new String[] { "4.0.0", "4.0.1" } ); } } StaxGeneratorWrongVersionInNamespaceTest.java000066400000000000000000000024661166654766000456140ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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 java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorWrongVersionInNamespaceTest.java 1413 2010-02-13 21:23:01Z 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( getXmlResourceReader( "/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" ); } } StaxGeneratorWrongVersionTest.java000066400000000000000000000023731166654766000435050ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/staxpackage 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 java.util.List; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: StaxGeneratorWrongVersionTest.java 1413 2010-02-13 21:23:01Z hboutemy $ */ public class StaxGeneratorWrongVersionTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorWrongVersionTest() throws ComponentLookupException { super( "stax-wrong-version" ); } public void testStaxReaderVersionInField() throws Throwable { Model model = modello.loadModel( getXmlResourceReader( "/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" ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/resources/000077500000000000000000000000001166654766000262125ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/resources/maven.mdo000066400000000000000000001643621166654766000300350ustar00rootroot00000000000000 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 * modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/resources/parts.mdo000066400000000000000000000231461166654766000300520ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/resources/version-in-field.mdo000066400000000000000000000025231166654766000320670ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/resources/version-in-namespace.mdo000066400000000000000000000021031166654766000327320ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/000077500000000000000000000000001166654766000261765ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/features/000077500000000000000000000000001166654766000300145ustar00rootroot00000000000000StaxFeaturesVerifier.java000066400000000000000000000213031166654766000347110ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/featurespackage 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.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import javax.xml.stream.XMLStreamException; /** * @author Herve Boutemy * @version $Id: StaxFeaturesVerifier.java 1479 2010-04-26 17:09:32Z bentmann $ */ public class StaxFeaturesVerifier extends Verifier { public void verify() throws Exception { verifyAPI(); Features features = verifyReader(); features.getXmlFeatures().getXmlTransientFields().setTransientString( "NOT-TO-BE-WRITTEN" ); verifyWriter( features ); verifyBadVersion(); verifyWrongElement(); verifyWrongContent(); verifyTransientElement(); verifyEncoding(); } public void verifyAPI() throws Exception { assertReader( ModelloFeaturesTestStaxReader.class, Features.class, Reader.class, XMLStreamException.class ); assertReader( ModelloFeaturesTestStaxReader.class, Features.class, InputStream.class, XMLStreamException.class ); assertWriter( ModelloFeaturesTestStaxWriter.class, Features.class, Writer.class, XMLStreamException.class ); assertWriter( ModelloFeaturesTestStaxWriter.class, Features.class, OutputStream.class, XMLStreamException.class ); } 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 verifyWrongContent() throws Exception { ModelloFeaturesTestStaxReader reader = new ModelloFeaturesTestStaxReader(); // reading with strict=false should accept unexpected text content reader.read( getClass().getResourceAsStream( "/features-wrong-content.xml" ), false ); // by default, strict=true: reading should not accept unexpected content try { reader.read( getClass().getResourceAsStream( "/features-wrong-content.xml" ) ); throw new VerifierException( "Reading a document with a bad content under strict option should fail." ); } catch ( XMLStreamException xse ) { checkExpectedFailure( xse, "non-all-whitespace CHARACTERS or CDATA event" ); } } 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" ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-parts/000077500000000000000000000000001166654766000303045ustar00rootroot00000000000000StaxVerifierParts.java000066400000000000000000000223531166654766000345220ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-partspackage 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" ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-parts/parts.xml000066400000000000000000000054121166654766000321610ustar00rootroot00000000000000 parent single Single Reference other Other Reference another Another Reference Dummy 1 Description 1 Dummy 2 Description 2 Dummy 3 Description 3 content value modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-field/000077500000000000000000000000001166654766000323255ustar00rootroot00000000000000StaxVerifierVersionInField.java000066400000000000000000000046721166654766000403360ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-fieldpackage 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() ); } } version-in-field.xml000066400000000000000000000002611166654766000361410ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-field Something out of place. 4.0.0 Maven modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespace/000077500000000000000000000000001166654766000331765ustar00rootroot00000000000000StaxVerifierVersionInNamespace.java000066400000000000000000000045041166654766000420520ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespacepackage 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() ); } } version-in-namespace.xml000066400000000000000000000005511166654766000376650ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-in-namespace Something out of place. Maven 000077500000000000000000000000001166654766000335715ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegateStaxVerifierVersionReaderDelegate.java000066400000000000000000000050421166654766000431740ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegatepackage 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() ); } } input-4.0.0.xml000066400000000000000000000027371166654766000361200ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate Something out of place. Maven input-4.0.1.xml000066400000000000000000000027371166654766000361210ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-version-reader-delegate Something out of place. Maven 000077500000000000000000000000001166654766000342515ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespaceStaxVerifierWrongVersionNamespace.java000066400000000000000000000047601166654766000437360ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespacepackage 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'" ) ); } } } wrong-version-in-namespace.xml000066400000000000000000000005511166654766000421510ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version-in-namespace Something out of place. Maven modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version/000077500000000000000000000000001166654766000317725ustar00rootroot00000000000000StaxVerifierWrongVersion.java000066400000000000000000000046701166654766000375630ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-versionpackage 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'" ) ); } } } wrong-version.xml000066400000000000000000000002611166654766000352530ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax-wrong-version Something out of place. 1.2.3 Maven modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/000077500000000000000000000000001166654766000271555ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/StaxVerifier.java000066400000000000000000000401521166654766000324350ustar00rootroot00000000000000package 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() ); } } } expected-default-extend.xml000066400000000000000000000004501166654766000343270ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/expected-encoding.xml000066400000000000000000000032271166654766000332700ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-stax/src/test/verifiers/stax/expected.xml000066400000000000000000000036661166654766000315130ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/000077500000000000000000000000001166654766000224105ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/pom.xml000066400000000000000000000023261166654766000237300ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 org.codehaus.modello modello-plugin-xsd org.codehaus.plexus plexus-utils maven-dependency-plugin modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/000077500000000000000000000000001166654766000231775ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/000077500000000000000000000000001166654766000241235ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/000077500000000000000000000000001166654766000250445ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/000077500000000000000000000000001166654766000256335ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/000077500000000000000000000000001166654766000274265ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000310615ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000323575ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/000077500000000000000000000000001166654766000333145ustar00rootroot00000000000000XdocGenerator.java000066400000000000000000000606121166654766000366510ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdocpackage 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.HashSet; 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.plugin.xsd.XsdModelHelper; 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.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; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: XdocGenerator.java 1469 2010-04-20 16:45:36Z hboutemy $ */ 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 = getId( tagName, modelClass ); 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 ) ); List elementFields = getFieldsForXml( modelClass, getGeneratedVersion() ); ModelField contentField = getContentField( elementFields ); 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 = getXmlAttributeFields( elementFields ); elementFields.removeAll( attributeFields ); 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 ( ModelField f : elementFields ) { if ( isInnerAssociation( f ) ) { ModelAssociation assoc = (ModelAssociation) f; ModelClass fieldModelClass = getModel().getClass( assoc.getTo(), getGeneratedVersion() ); if ( !written.contains( getId( resolveTagName( fieldModelClass, assoc ), fieldModelClass ) ) ) { writeElementDescriptor( w, fieldModelClass, assoc, written ); } } } } private String getId( String tagName, ModelClass modelClass ) { return tagName + '/' + modelClass.getPackageName() + '.' + modelClass.getName(); } /** * 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 ( ModelField f : fields ) { 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( tagName ).append( "" ); boolean addNewline = false; if ( stack.size() == 0 ) { // try to add XML Schema reference try { String targetNamespace = XsdModelHelper.getTargetNamespace( modelClass.getModel(), getGeneratedVersion() ); XmlModelMetadata xmlModelMetadata = (XmlModelMetadata) modelClass.getModel().getMetadata( XmlModelMetadata.ID ); if ( StringUtils.isNotBlank( targetNamespace ) && ( xmlModelMetadata.getSchemaLocation() != null ) ) { String schemaLocation = xmlModelMetadata.getSchemaLocation( getGeneratedVersion() ); sb.append( " xmlns=\"" + targetNamespace + "\"" ); sb.append( " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" ); sb.append( " xsi:schemaLocation=\"" + targetNamespace ); sb.append( " " + schemaLocation + "\"" ); addNewline = true; } } catch ( ModelloException me ) { // ignore unavailable XML Schema configuration } } String id = tagName + '/' + modelClass.getPackageName() + '.' + modelClass.getName(); if ( stack.contains( id ) ) { // recursion detected sb.append( ">...recursion...<" ).append( tagName ).append( ">\n" ); return sb.toString(); } List fields = getFieldsForXml( modelClass, getGeneratedVersion() ); List attributeFields = getXmlAttributeFields( fields); if ( attributeFields.size() > 0 ) { for ( ModelField f : attributeFields ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) f.getMetadata( XmlFieldMetadata.ID ); if ( addNewline ) { addNewline = false; sb.append( "\n " ); } else { sb.append( ' ' ); } sb.append( resolveTagName( f, xmlFieldMetadata ) ).append( "=.." ); } sb.append( ' ' ); } fields.removeAll( attributeFields ); if ( ( fields.size() == 0 ) || ( ( fields.size() == 1 ) && hasContentField( fields ) ) ) { sb.append( "/>\n" ); } else { sb.append( ">\n" ); stack.push( id ); for ( ModelField f : fields ) { 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(); } } 000077500000000000000000000000001166654766000350155ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadataXdocAssociationMetadata.java000066400000000000000000000027341166654766000424210ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadatapackage 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(); } XdocClassMetadata.java000066400000000000000000000026761166654766000412170ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadatapackage 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(); } XdocFieldMetadata.java000066400000000000000000000033471166654766000411710ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadatapackage 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; } } XdocInterfaceMetadata.java000066400000000000000000000027221166654766000420420ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadatapackage 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.InterfaceMetadata; /** * @author Hervé Boutemy * @version $Id: XdocInterfaceMetadata.java 1436 2010-04-14 23:04:58Z bentmann $ */ public class XdocInterfaceMetadata implements InterfaceMetadata { public static final String ID = XdocInterfaceMetadata.class.getName(); } XdocMetadataPlugin.java000066400000000000000000000060321166654766000413760ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadatapackage 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.InterfaceMetadata; 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 org.codehaus.modello.model.ModelInterface; import java.util.Map; /** * @author Hervé Boutemy * @version $Id: XdocMetadataPlugin.java 1436 2010-04-14 23:04:58Z bentmann $ */ 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 InterfaceMetadata getInterfaceMetadata( ModelInterface iface, Map data ) { return new XdocInterfaceMetadata(); } 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(); } } XdocModelMetadata.java000066400000000000000000000026761166654766000412120ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/metadatapackage 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(); } modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/resources/000077500000000000000000000000001166654766000261355ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/resources/META-INF/000077500000000000000000000000001166654766000272755ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000306155ustar00rootroot00000000000000components.xml000066400000000000000000000012051166654766000334430ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/main/resources/META-INF/plexus org.codehaus.modello.plugin.ModelloGenerator xdoc org.codehaus.modello.plugin.xdoc.XdocGenerator per-lookup org.codehaus.modello.metadata.MetadataPlugin xdoc org.codehaus.modello.plugin.xdoc.metadata.XdocMetadataPlugin per-lookup modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/site/000077500000000000000000000000001166654766000241435ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/site/site.xml000066400000000000000000000007171166654766000256360ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/site/xdoc/000077500000000000000000000000001166654766000251005ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/site/xdoc/index.xml000066400000000000000000000014401166654766000267300ustar00rootroot00000000000000 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.

modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/000077500000000000000000000000001166654766000241565ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/java/000077500000000000000000000000001166654766000250775ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/000077500000000000000000000000001166654766000256665ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/000077500000000000000000000000001166654766000274615ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000311145ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000324125ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/000077500000000000000000000000001166654766000333475ustar00rootroot00000000000000XdocGeneratorTest.java000066400000000000000000000133771166654766000375520ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdocpackage 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.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 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 1413 2010-02-13 21:23:01Z hboutemy $ */ 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( getXmlResourceReader( "/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 = getModelloParameters( "4.0.0" ); 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 ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "1.5.0" ); 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xml/000077500000000000000000000000001166654766000222535ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/pom.xml000066400000000000000000000020271166654766000235710ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 org.codehaus.plexus plexus-utils modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/000077500000000000000000000000001166654766000230425ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/000077500000000000000000000000001166654766000237665ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/000077500000000000000000000000001166654766000247075ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/000077500000000000000000000000001166654766000254765ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/000077500000000000000000000000001166654766000272715ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000307245ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/000077500000000000000000000000001166654766000324055ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/000077500000000000000000000000001166654766000332055ustar00rootroot00000000000000AbstractXmlGenerator.java000066400000000000000000000112511166654766000400640ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xmlpackage 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.model.Version; 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 1413 2010-02-13 21:23:01Z hboutemy $ */ 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 ); } 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 XML attribute. * * @param modelFields The collection of model fields from which to extract the XML attributes, must not be * null. * @return The list of XML attributes fields, can be empty but never null. */ protected List getXmlAttributeFields( List modelFields ) { return XmlModelHelpers.getXmlAttributeFields( modelFields ); } /** * Return the XML fields of this class, with proper XML order and no XML transient fields. * * @param modelClass current class * @param version the version of the class to use * @return the list of XML fields of this class */ protected List getFieldsForXml( ModelClass modelClass, Version version ) { return XmlModelHelpers.getFieldsForXml( modelClass, version ); } } AbstractXmlJavaGenerator.java000066400000000000000000000157061166654766000406770ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xmlpackage 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 java.util.Properties; import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; 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.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 1413 2010-02-13 21:23:01Z hboutemy $ */ public abstract class AbstractXmlJavaGenerator extends AbstractJavaModelloGenerator { protected boolean strictXmlAttributes; protected void initialize( Model model, Properties parameters ) throws ModelloException { super.initialize( model, parameters ); strictXmlAttributes = model.getDefault( ModelDefault.STRICT_XML_ATTRIBUTES ).getBoolean(); } 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 ); } /** * Return the XML fields of this class, with proper XML order and no XML transient fields. * * @param modelClass current class * @param version the version of the class to use * @return the list of XML fields of this class */ protected List getFieldsForXml( ModelClass modelClass, Version version ) { return XmlModelHelpers.getFieldsForXml( modelClass, version ); } 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;" ); } } XmlModelHelpers.java000066400000000000000000000203641166654766000370420ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xmlpackage org.codehaus.modello.plugins.xml; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.modello.ModelloRuntimeException; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; 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 1413 2010-02-13 21:23:01Z 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 ( ModelField field : modelFields ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isContent() ) { return field; } } return null; } /** * Gets all fields that are not marked as XML attribute. * * @param modelFields The collection of model fields from which to extract the XML attributes, must not be * null. * @return The list of XML attributes fields, can be empty but never null. */ static List getXmlAttributeFields( List modelFields ) { List xmlAttributeFields = new ArrayList(); for ( ModelField field : modelFields ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isAttribute() ) { xmlAttributeFields.add( field ); } } return xmlAttributeFields; } /** * Return the XML fields of this class, with proper XML order and no XML transient fields. * * @param modelClass current class * @param version the version of the class to use * @return the list of XML fields of this class */ static List getFieldsForXml( ModelClass modelClass, Version version ) { List classes = new ArrayList(); // get the full inheritance while ( modelClass != null ) { classes.add( modelClass ); String superClass = modelClass.getSuperClass(); if ( superClass != null ) { modelClass = modelClass.getModel().getClass( superClass, version ); } else { modelClass = null; } } List fields = new ArrayList(); for ( int i = classes.size() - 1; i >= 0; i-- ) { modelClass = (ModelClass) classes.get( i ); Iterator parentIter = fields.iterator(); fields = new ArrayList(); for ( ModelField field : modelClass.getFields( version ) ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isTransient() ) { // just ignore xml.transient fields continue; } if ( xmlFieldMetadata.getInsertParentFieldsUpTo() != null ) { // insert fields from parent up to the specified field boolean found = false; while ( !found && parentIter.hasNext() ) { ModelField parentField = (ModelField) parentIter.next(); fields.add( parentField ); found = parentField.getName().equals( xmlFieldMetadata.getInsertParentFieldsUpTo() ); } if ( !found ) { // interParentFieldsUpTo not found throw new ModelloRuntimeException( "parent field not found: class " + modelClass.getName() + " xml.insertParentFieldUpTo='" + xmlFieldMetadata.getInsertParentFieldsUpTo() + "'" ); } } fields.add( field ); } // add every remaining fields from parent class while ( parentIter.hasNext() ) { fields.add( parentIter.next() ); } } return fields; } } 000077500000000000000000000000001166654766000347065ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadataXmlAssociationMetadata.java000066400000000000000000000066411166654766000421560ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadatapackage 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; } } XmlClassMetadata.java000066400000000000000000000032441166654766000407430ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadatapackage 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; } } XmlFieldMetadata.java000066400000000000000000000062631166654766000407250ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadatapackage 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 1328 2010-01-04 23:43:59Z 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; private String insertParentFieldsUpTo; 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; } public String getInsertParentFieldsUpTo() { return insertParentFieldsUpTo; } public void setInsertParentFieldsUpTo( String insertParentFieldsUpTo ) { this.insertParentFieldsUpTo = insertParentFieldsUpTo; } } XmlInterfaceMetadata.java000066400000000000000000000027751166654766000416060ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadatapackage 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.InterfaceMetadata; /** * @author Trygve Laugstøl * @version $Id: XmlInterfaceMetadata.java 1436 2010-04-14 23:04:58Z bentmann $ */ public class XmlInterfaceMetadata implements InterfaceMetadata { public static final String ID = XmlInterfaceMetadata.class.getName(); } XmlMetadataPlugin.java000066400000000000000000000117051166654766000411350ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadatapackage 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.InterfaceMetadata; 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 org.codehaus.modello.model.ModelInterface; import java.util.Map; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: XmlMetadataPlugin.java 1469 2010-04-20 16:45:36Z hboutemy $ */ public class XmlMetadataPlugin extends AbstractMetadataPlugin implements MetadataPlugin { public static final String XML_ATTRIBUTE = "xml.attribute"; public static final String XML_CONTENT = "xml.content"; 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"; public static final String XML_INSERT_PARENT_FIELDS_UP_TO = "xml.insertParentFieldsUpTo"; // ---------------------------------------------------------------------- // 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 InterfaceMetadata getInterfaceMetadata( ModelInterface iface, Map data ) { return new XmlInterfaceMetadata(); } 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 ) ); metadata.setInsertParentFieldsUpTo( getString( data, XML_INSERT_PARENT_FIELDS_UP_TO ) ); 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; } } XmlModelMetadata.java000066400000000000000000000050761166654766000407430ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/java/org/codehaus/modello/plugins/xml/metadatapackage 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; } } modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/resources/000077500000000000000000000000001166654766000260005ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/000077500000000000000000000000001166654766000271405ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/modello/000077500000000000000000000000001166654766000305735ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/modello/plugins.xml000066400000000000000000000003051166654766000327740ustar00rootroot00000000000000 xml org.codehaus.modello.plugins.xml.metadata.XmlMetaDataPlugin modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000304605ustar00rootroot00000000000000components.xml000066400000000000000000000004451166654766000333130ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/main/resources/META-INF/plexus org.codehaus.modello.metadata.MetadataPlugin xml org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/site/000077500000000000000000000000001166654766000240065ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/site/site.xml000066400000000000000000000005571166654766000255030ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/000077500000000000000000000000001166654766000240215ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/java/000077500000000000000000000000001166654766000247425ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/java/org/000077500000000000000000000000001166654766000255315ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/000077500000000000000000000000001166654766000273245ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000307575ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/plugins/000077500000000000000000000000001166654766000324405ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/plugins/xml/000077500000000000000000000000001166654766000332405ustar00rootroot00000000000000XmlModelloPluginTest.java000066400000000000000000000075511166654766000401270ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/java/org/codehaus/modello/plugins/xmlpackage 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 java.util.List; /** * @author Trygve Laugstøl * @version $Id: XmlModelloPluginTest.java 1413 2010-02-13 21:23:01Z 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( 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() ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/resources/000077500000000000000000000000001166654766000260335ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xml/src/test/resources/model.mdo000066400000000000000000000036361166654766000276440ustar00rootroot00000000000000 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+ modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/000077500000000000000000000000001166654766000223455ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/pom.xml000066400000000000000000000026271166654766000236710ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 maven-dependency-plugin modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/000077500000000000000000000000001166654766000231345ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/000077500000000000000000000000001166654766000235505ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/000077500000000000000000000000001166654766000257545ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/pom.xml000066400000000000000000000025271166654766000272770ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/000077500000000000000000000000001166654766000265435ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/main/000077500000000000000000000000001166654766000274675ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/main/mdo/000077500000000000000000000000001166654766000302465ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/main/mdo/maven.mdo000066400000000000000000003205531166654766000320650ustar00rootroot00000000000000 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
modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/000077500000000000000000000000001166654766000275225ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/000077500000000000000000000000001166654766000304435ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/000077500000000000000000000000001166654766000312325ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/000077500000000000000000000000001166654766000330255ustar00rootroot00000000000000000077500000000000000000000000001166654766000344015ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modello000077500000000000000000000000001166654766000352735ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modello/xpp3Xpp3ParsingTest.java000066400000000000000000000016721166654766000411620ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/java/org/codehaus/modello/xpp3package 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 ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models/000077500000000000000000000000001166654766000310055ustar00rootroot00000000000000model-with-missing-elements.xml000066400000000000000000000002171166654766000370020ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models one two 1.0 model-with-wrong-root-tag.xml000066400000000000000000000002131166654766000364010ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/it/maven-model/src/test/models one two 1.0 modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/000077500000000000000000000000001166654766000240605ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/000077500000000000000000000000001166654766000250015ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/000077500000000000000000000000001166654766000255705ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/000077500000000000000000000000001166654766000273635ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000310165ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000323145ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3/000077500000000000000000000000001166654766000332065ustar00rootroot00000000000000AbstractXpp3Generator.java000066400000000000000000000027041166654766000401620ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3package 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 { } Xpp3ExtendedReaderGenerator.java000066400000000000000000000031321166654766000412760ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3package 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.model.ModelClass; /** * The generator for XPP3-based parsers that support input location tracking. * * @author Benjamin Bentmann */ public class Xpp3ExtendedReaderGenerator extends Xpp3ReaderGenerator { @Override protected boolean isRelevant( ModelClass modelClass ) { return isJavaEnabled( modelClass ); } @Override protected boolean isLocationTracking() { return true; } } Xpp3ReaderGenerator.java000066400000000000000000002151671166654766000376320ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3package 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.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.plugin.model.ModelClassMetadata; 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 1480 2010-04-27 18:43:34Z bentmann $ */ public class Xpp3ReaderGenerator extends AbstractXpp3Generator { private static final String SOURCE_PARAM = "source"; private static final String LOCATION_VAR = "_location"; private ModelClass locationTracker; private String locationField; private ModelClass sourceTracker; private String trackingArgs; protected boolean isLocationTracking() { return false; } public void generate( Model model, Properties parameters ) throws ModelloException { initialize( model, parameters ); locationTracker = sourceTracker = null; trackingArgs = locationField = ""; if ( isLocationTracking() ) { locationTracker = model.getLocationTracker( getGeneratedVersion() ); if ( locationTracker == null ) { throw new ModelloException( "No model class has been marked as location tracker" + " via the attribute locationTracker=\"locations\"" + ", cannot generate extended reader." ); } locationField = ( (ModelClassMetadata) locationTracker.getMetadata( ModelClassMetadata.ID ) ).getLocationTracker(); sourceTracker = model.getSourceTracker( getGeneratedVersion() ); if ( sourceTracker != null ) { trackingArgs += ", " + SOURCE_PARAM; } } 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" + ( isLocationTracking() ? "Ex" : "" ) ); 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 ); ModelClass root = objectModel.getClass( objectModel.getRoot( getGeneratedVersion() ), getGeneratedVersion() ); JClass rootType = new JClass( root.getName() ); // ---------------------------------------------------------------------- // Write the read(XmlPullParser,boolean) method which will do the unmarshalling. // ---------------------------------------------------------------------- JMethod unmarshall = new JMethod( "read", rootType, null ); unmarshall.getModifiers().makePrivate(); unmarshall.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); unmarshall.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); addTrackingParameters( unmarshall ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); JSourceCode sc = unmarshall.getSourceCode(); String tagName = resolveTagName( root ); String className = root.getName(); String variableName = uncapitalise( className ); sc.add( "int eventType = parser.getEventType();" ); sc.add( "while ( eventType != XmlPullParser.END_DOCUMENT )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( eventType == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict && ! \"" + tagName + "\".equals( parser.getName() ) )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Expected root element '" + tagName + "' but " + "found '\" + parser.getName() + \"'\", parser, null );" ); sc.add( "}" ); sc.add( className + ' ' + variableName + " = parse" + root.getName() + "( parser, strict" + trackingArgs + " );" ); sc.add( variableName + ".setModelEncoding( parser.getInputEncoding() );" ); sc.add( "return " + variableName + ';' ); sc.unindent(); sc.add( "}" ); sc.add( "eventType = parser.next();" ); sc.unindent(); sc.add( "}" ); sc.add( "throw new XmlPullParserException( \"Expected root element '" + tagName + "' but " + "found no element at all: invalid XML document\", parser, null );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- // Write the read(Reader[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.setComment( "@see ReaderFactory#newXmlReader" ); unmarshall.addParameter( new JParameter( new JClass( "Reader" ), "reader" ) ); unmarshall.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); addTrackingParameters( unmarshall ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); sc = unmarshall.getSourceCode(); sc.add( "XmlPullParser parser = new MXParser();" ); sc.add( "" ); sc.add( "parser.setInput( reader );" ); sc.add( "" ); sc.add( "initParser( parser );" ); sc.add( "" ); sc.add( "return read( parser, strict" + trackingArgs + " );" ); jClass.addMethod( unmarshall ); // ---------------------------------------------------------------------- if ( locationTracker == null ) { unmarshall = new JMethod( "read", rootType, 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 read(InputStream[,boolean]) methods which will do the unmarshalling. // ---------------------------------------------------------------------- unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "in" ) ); unmarshall.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); addTrackingParameters( unmarshall ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( ReaderFactory.newXmlReader( in ), strict" + trackingArgs + " );" ); jClass.addMethod( unmarshall ); // -------------------------------------------------------------------- if ( locationTracker == null ) { unmarshall = new JMethod( "read", rootType, null ); unmarshall.addParameter( new JParameter( new JClass( "InputStream" ), "in" ) ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); sc = unmarshall.getSourceCode(); sc.add( "return read( ReaderFactory.newXmlReader( in ) );" ); 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 ( ModelClass clazz : getClasses( objectModel ) ) { if ( isTrackingSupport( clazz ) ) { 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( "XmlPullParser" ), "parser" ) ); unmarshall.addParameter( new JParameter( JClass.BOOLEAN, "strict" ) ); addTrackingParameters( unmarshall ); unmarshall.addException( new JClass( "IOException" ) ); unmarshall.addException( new JClass( "XmlPullParserException" ) ); JSourceCode sc = unmarshall.getSourceCode(); sc.add( "String tagName = parser.getName();" ); sc.add( className + " " + uncapClassName + " = new " + className + "();" ); if ( locationTracker != null ) { sc.add( locationTracker.getName() + " " + LOCATION_VAR + ";" ); writeNewSetLocation( "\"\"", uncapClassName, null, sc ); } ModelField contentField = null; List modelFields = getFieldsForXml( modelClass, getGeneratedVersion() ); // read all XML attributes first contentField = writeClassAttributesParser( modelFields, uncapClassName, rootElement, sc, jClass ); // then read content, either content field or elements if ( contentField != null ) { writePrimitiveField( contentField, contentField.getType(), uncapClassName, uncapClassName, "\"\"", "set" + capitalise( contentField.getName() ), sc, jClass ); } else { //Write other fields sc.add( "java.util.Set parsed = new java.util.HashSet();" ); sc.add( "while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); boolean addElse = false; for ( ModelField field : modelFields ) { 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( "checkUnknownElement( parser, strict );" ); if ( addElse ) { sc.unindent(); sc.add( "}" ); } sc.unindent(); sc.add( "}" ); } sc.add( "return " + uncapClassName + ";" ); jClass.addMethod( unmarshall ); } private ModelField writeClassAttributesParser( List modelFields, String objectName, boolean rootElement, JSourceCode sc, JClass jClass ) { ModelField contentField = null; sc.add( "for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )" ); sc.add( "{" ); sc.indent(); sc.add( "String name = parser.getAttributeName( i );" ); sc.add( "String value = parser.getAttributeValue( i );" ); sc.add( "" ); sc.add( "if ( name.indexOf( ':' ) >= 0 )" ); sc.add( "{" ); sc.addIndented( "// just ignore attributes with non-default namespace (for example: xmlns:xsi)" ); sc.add( "}" ); if ( rootElement ) { sc.add( "else if ( \"xmlns\".equals( name ) )" ); sc.add( "{" ); sc.addIndented( "// ignore xmlns attribute in root class, which is a reserved attribute name" ); sc.add( "}" ); } for ( ModelField field : modelFields ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); if ( xmlFieldMetadata.isAttribute() ) { String tagName = resolveTagName( field, xmlFieldMetadata ); sc.add( "else if ( \"" + tagName + "\".equals( name ) )"); sc.add( "{" ); sc.indent(); writePrimitiveField( field, field.getType(), objectName, objectName, "\"" + field.getName() + "\"", "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; } } sc.add( "else" ); sc.add( "{" ); sc.addIndented( "checkUnknownAttribute( parser, name, tagName, strict );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); return contentField; } /** * 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, objectName, "\"" + field.getName() + "\"", "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() + "( parser, strict" + trackingArgs + " ) );" ); 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(); boolean inModel = isClassInModel( association.getTo(), field.getModelClass().getModel() ); if ( wrappedItems ) { sc.add( tagComparison ); sc.add( "{" ); sc.indent(); sc.add( type + " " + associationName + " = " + association.getDefaultValue() + ";" ); sc.add( objectName + ".set" + capFieldName + "( " + associationName + " );" ); if ( !inModel && locationTracker != null ) { sc.add( locationTracker.getName() + " " + LOCATION_VAR + "s;" ); writeNewSetLocation( field, objectName, LOCATION_VAR + "s", sc ); } sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( \"" + valuesTagName + "\".equals( parser.getName() ) )" ); sc.add( "{" ); sc.indent(); } else { sc.add( ( addElse ? "else " : "" ) + "if ( \"" + valuesTagName + "\".equals( parser.getName() ) )" ); 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 ( !inModel && locationTracker != null ) { sc.add( locationTracker.getName() + " " + LOCATION_VAR + "s = " + objectName + ".get" + capitalise( singular( locationField ) ) + "( \"" + field.getName() + "\" );" ); sc.add( "if ( " + LOCATION_VAR + "s == null )" ); sc.add( "{" ); sc.indent(); writeNewSetLocation( field, objectName, LOCATION_VAR + "s", sc ); sc.unindent(); sc.add( "}" ); } } if ( inModel ) { sc.add( associationName + ".add( parse" + association.getTo() + "( parser, strict" + trackingArgs + " ) );" ); } else { String key; if ( ModelDefault.SET.equals( type ) ) { key = "?"; } else { key = ( useJava5 ? "Integer.valueOf" : "new java.lang.Integer" ) + "( " + associationName + ".size() )"; } writePrimitiveField( association, association.getTo(), associationName, LOCATION_VAR + "s", key, "add", sc, jClass ); } if ( wrappedItems ) { sc.unindent(); sc.add( "}" ); sc.add( "else" ); sc.add( "{" ); sc.addIndented( "checkUnknownElement( parser, strict );" ); 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 ( locationTracker != null ) { sc.add( locationTracker.getName() + " " + LOCATION_VAR + "s;" ); writeNewSetLocation( field, objectName, LOCATION_VAR + "s", sc ); } if ( xmlAssociationMetadata.isMapExplode() ) { sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( \"" + valuesTagName + "\".equals( parser.getName() ) )" ); sc.add( "{" ); sc.indent(); sc.add( "String key = null;" ); sc.add( "String value = null;" ); writeNewLocation( LOCATION_VAR, sc ); sc.add( "// " + xmlAssociationMetadata.getMapStyle() + " mode." ); sc.add( "while ( parser.nextTag() == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( \"key\".equals( parser.getName() ) )" ); sc.add( "{" ); sc.addIndented( "key = parser.nextText();" ); sc.add( "}" ); sc.add( "else if ( \"value\".equals( parser.getName() ) )" ); sc.add( "{" ); sc.indent(); writeNewLocation( LOCATION_VAR, sc ); sc.add( "value = parser.nextText()" + ( xmlFieldMetadata.isTrim() ? ".trim()" : "" ) + ";" ); sc.unindent(); 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 );" ); writeSetLocation( "key", LOCATION_VAR + "s", LOCATION_VAR, sc ); 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();" ); writeNewSetLocation( "key", LOCATION_VAR + "s", null, sc ); 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 locatorName, String locationKey, String setterName, JSourceCode sc, JClass jClass ) { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); String tagName = resolveTagName( field, xmlFieldMetadata); String parserGetter; if ( xmlFieldMetadata.isAttribute() ) { parserGetter = "value"; // local variable created in the parsing block } else { parserGetter = "parser.nextText()"; } /* TODO: this and a default if ( xmlFieldMetadata.isRequired() ) { parserGetter = "getRequiredAttributeValue( " + parserGetter + ", \"" + tagName + "\", parser, strict )"; } */ if ( xmlFieldMetadata.isTrim() ) { parserGetter = "getTrimmedValue( " + parserGetter + " )"; } String keyCapture = ""; writeNewLocation( null, sc ); if ( locationTracker != null && "?".equals( locationKey ) ) { sc.add( "Object _key;" ); locationKey = "_key"; keyCapture = "_key = "; } else { writeSetLocation( locationKey, locatorName, null, sc ); } if ( "boolean".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getBooleanValue( " + parserGetter + ", \"" + tagName + "\", parser, \"" + field.getDefaultValue() + "\" ) );" ); } else if ( "char".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getCharacterValue( " + parserGetter + ", \"" + tagName + "\", parser ) );" ); } else if ( "double".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getDoubleValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "float".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getFloatValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "int".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getIntegerValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "long".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getLongValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "short".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getShortValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "byte".equals( type ) ) { sc.add( objectName + "." + setterName + "( " + keyCapture + "getByteValue( " + parserGetter + ", \"" + tagName + "\", parser, strict ) );" ); } else if ( "String".equals( type ) || "Boolean".equals( type ) ) { // TODO: other Primitive types sc.add( objectName + "." + setterName + "( " + keyCapture + parserGetter + " );" ); } else if ( "Date".equals( type ) ) { sc.add( "String dateFormat = " + ( xmlFieldMetadata.getFormat() != null ? "\"" + xmlFieldMetadata.getFormat() + "\"" : "null" ) + ";" ); sc.add( objectName + "." + setterName + "( " + keyCapture + "getDateValue( " + parserGetter + ", \"" + tagName + "\", dateFormat, parser ) );" ); } else if ( "DOM".equals( type ) ) { jClass.addImport( "org.codehaus.plexus.util.xml.Xpp3DomBuilder" ); sc.add( objectName + "." + setterName + "( " + keyCapture + "Xpp3DomBuilder.build( parser ) );" ); } else { throw new IllegalArgumentException( "Unknown type: " + type ); } if ( keyCapture.length() > 0 ) { writeSetLocation( locationKey, locatorName, null, sc ); } } 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(), parser, e )" ); 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.add( tagName ) )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Duplicated tag: '\" + tagName + \"'\", parser, null );" ); sc.add( "}" ); sc.add( "return true;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "checkUnknownElement", null, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); method.addException( new JClass( "XmlPullParserException" ) ); method.addException( new JClass( "IOException" ) ); sc = method.getSourceCode(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Unrecognised tag: '\" + parser.getName() + \"'\", parser, null );" ); sc.add( "}" ); sc.add( "" ); sc.add( "for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )" ); sc.add( "{" ); sc.indent(); sc.add( "int eventType = parser.next();" ); sc.add( "if ( eventType == XmlPullParser.START_TAG )" ); sc.add( "{" ); sc.addIndented( "unrecognizedTagCount++;" ); sc.add( "}" ); sc.add( "else if ( eventType == XmlPullParser.END_TAG )" ); sc.add( "{" ); sc.addIndented( "unrecognizedTagCount--;" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "checkUnknownAttribute", null, null ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addParameter( new JParameter( new JClass( "String" ), "attribute" ) ); method.addParameter( new JParameter( new JClass( "String" ), "tagName" ) ); method.addParameter( new JParameter( JType.BOOLEAN, "strict" ) ); method.addException( new JClass( "XmlPullParserException" ) ); method.addException( new JClass( "IOException" ) ); sc = method.getSourceCode(); if ( strictXmlAttributes ) { sc.add( "// strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too" ); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Unknown attribute '\" + attribute + \"' for tag '\" + tagName + \"'\", parser, null );" ); sc.add( "}" ); } else { sc.add( "// strictXmlAttributes = false for model: always ignore unknown XML attribute, even if strict == true" ); } jClass.addMethod( method ); // -------------------------------------------------------------------- method = new JMethod( "nextTag", JType.INT, null ); method.addException( new JClass( "IOException" ) ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); sc = method.getSourceCode(); sc.add( "int eventType = parser.next();" ); sc.add( "if ( eventType == XmlPullParser.TEXT )" ); sc.add( "{" ); sc.addIndented( "eventType = parser.next();" ); sc.add( "}" ); sc.add( "if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"expected START_TAG or END_TAG not \" + XmlPullParser.TYPES[eventType], parser, null );" ); sc.add( "}" ); sc.add( "return eventType;" ); jClass.addMethod( method ); // -------------------------------------------------------------------- jClass.addMethod( initParser() ); } 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 nfe )" ); sc.add( "{" ); sc.indent(); sc.add( "if ( strict )" ); sc.add( "{" ); sc.addIndented( "throw new XmlPullParserException( \"Unable to parse element '\" + attribute + \"', must be " + typeDesc + "\", parser, nfe );" ); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.unindent(); sc.add( "}" ); sc.add( "return 0;" ); return method; } private JMethod initParser() { JMethod method = new JMethod( "initParser" ); method.addParameter( new JParameter( new JClass( "XmlPullParser" ), "parser" ) ); method.addException( new JClass( "XmlPullParserException" ) ); method.getModifiers().makePrivate(); JSourceCode sc = method.getSourceCode(); writeParserInitialization( sc ); return method; } private void addTrackingParameters( JMethod method ) { if ( sourceTracker != null ) { method.addParameter( new JParameter( new JClass( sourceTracker.getName() ), SOURCE_PARAM ) ); } } private void writeNewSetLocation( ModelField field, String objectName, String trackerVariable, JSourceCode sc ) { writeNewSetLocation( "\"" + field.getName() + "\"", objectName, trackerVariable, sc ); } private void writeNewSetLocation( String key, String objectName, String trackerVariable, JSourceCode sc ) { writeNewLocation( trackerVariable, sc ); writeSetLocation( key, objectName, trackerVariable, sc ); } private void writeNewLocation( String trackerVariable, JSourceCode sc ) { if ( locationTracker == null ) { return; } String constr = "new " + locationTracker.getName() + "( parser.getLineNumber(), parser.getColumnNumber()"; constr += ( sourceTracker != null ) ? ", " + SOURCE_PARAM : ""; constr += " )"; sc.add( ( ( trackerVariable != null ) ? trackerVariable : LOCATION_VAR ) + " = " + constr + ";" ); } private void writeSetLocation( String key, String objectName, String trackerVariable, JSourceCode sc ) { if ( locationTracker == null ) { return; } String variable = ( trackerVariable != null ) ? trackerVariable : LOCATION_VAR; sc.add( objectName + ".set" + capitalise( singular( locationField ) ) + "( " + key + ", " + variable + " );" ); } } Xpp3WriterGenerator.java000066400000000000000000000430771166654766000377030ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/java/org/codehaus/modello/plugin/xpp3package 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.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.List; import java.util.Properties; /** * @author Jason van Zyl * @author Emmanuel Venisse * @version $Id: Xpp3WriterGenerator.java 1474 2010-04-24 19:59:00Z bentmann $ */ 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.OutputStream" ); 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( Writer, Model ) 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" ) ); 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 ); // ---------------------------------------------------------------------- // Write the write( OutputStream, Model ) method which will do the unmarshalling. // ---------------------------------------------------------------------- marshall = new JMethod( "write" ); marshall.addParameter( new JParameter( new JClass( "OutputStream" ), "stream" ) ); marshall.addParameter( new JParameter( new JClass( root ), rootElementParameterName ) ); marshall.addException( new JClass( "java.io.IOException" ) ); 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( stream, " + rootElementParameterName + ".getModelEncoding() );" ); 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 ( ModelClass clazz : getClasses( objectModel ) ) { 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(); 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 = getFieldsForXml( modelClass, getGeneratedVersion() ); // XML attributes for ( ModelField field : modelFields ) { 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 ( ModelField field : modelFields ) { 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 );" ); jClass.addMethod( marshall ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/resources/000077500000000000000000000000001166654766000260725ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/resources/META-INF/000077500000000000000000000000001166654766000272325ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000305525ustar00rootroot00000000000000components.xml000066400000000000000000000017111166654766000334020ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/main/resources/META-INF/plexus org.codehaus.modello.plugin.ModelloGenerator xpp3-reader org.codehaus.modello.plugin.xpp3.Xpp3ReaderGenerator per-lookup org.codehaus.modello.plugin.ModelloGenerator xpp3-extended-reader org.codehaus.modello.plugin.xpp3.Xpp3ExtendedReaderGenerator per-lookup org.codehaus.modello.plugin.ModelloGenerator xpp3-writer org.codehaus.modello.plugin.xpp3.Xpp3WriterGenerator per-lookup modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/site/000077500000000000000000000000001166654766000241005ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/site/site.xml000066400000000000000000000005601166654766000255670ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/site/xdoc/000077500000000000000000000000001166654766000250355ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/site/xdoc/index.xml000066400000000000000000000036131166654766000266710ustar00rootroot00000000000000 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
modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/000077500000000000000000000000001166654766000241135ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/000077500000000000000000000000001166654766000250345ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/000077500000000000000000000000001166654766000256235ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/000077500000000000000000000000001166654766000274165ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000310515ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/000077500000000000000000000000001166654766000330375ustar00rootroot00000000000000000077500000000000000000000000001166654766000335605ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml000077500000000000000000000000001166654766000344525ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3FeaturesXpp3GeneratorTest.java000066400000000000000000000043771166654766000423700ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3package 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Hervé Boutemy * @version $Id: FeaturesXpp3GeneratorTest.java 1473 2010-04-24 16:46:13Z bentmann $ */ public class FeaturesXpp3GeneratorTest extends AbstractModelloJavaGeneratorTest { public FeaturesXpp3GeneratorTest() { super( "features" ); } public void testJavaGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "xpp3-writer", parameters ); modello.generate( model, "xpp3-reader", parameters ); addDependency( "xmlunit", "xmlunit" ); compileGeneratedSources(); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.xpp3.Xpp3FeaturesVerifier" ); } } LocationsSourceXpp3GeneratorTest.java000066400000000000000000000044151166654766000437170ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3package 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Benjamin Bentmann * @version $Id: LocationsSourceXpp3GeneratorTest.java 1459 2010-04-19 10:36:55Z bentmann $ */ public class LocationsSourceXpp3GeneratorTest extends AbstractModelloJavaGeneratorTest { public LocationsSourceXpp3GeneratorTest() { super( "locations+src" ); } public void testLocationsWithSource() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/locations+source.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "xpp3-reader", parameters ); modello.generate( model, "xpp3-extended-reader", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.xpp3.Xpp3LocationsSourceVerifier" ); } } LocationsXpp3GeneratorTest.java000066400000000000000000000043441166654766000425370ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3package 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Benjamin Bentmann * @version $Id: LocationsXpp3GeneratorTest.java 1459 2010-04-19 10:36:55Z bentmann $ */ public class LocationsXpp3GeneratorTest extends AbstractModelloJavaGeneratorTest { public LocationsXpp3GeneratorTest() { super( "locations" ); } public void testLocationsOnly() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/locations.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "xpp3-reader", parameters ); modello.generate( model, "xpp3-extended-reader", parameters ); compileGeneratedSources(); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.xpp3.Xpp3LocationsVerifier" ); } } Xpp3GeneratorTest.java000066400000000000000000000073131166654766000406620ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3package 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.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; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: Xpp3GeneratorTest.java 1473 2010-04-24 16:46:13Z bentmann $ */ public class Xpp3GeneratorTest extends AbstractModelloJavaGeneratorTest { public Xpp3GeneratorTest() { super( "xpp3" ); } public void testXpp3Generator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/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 = getModelloParameters( "4.0.0" ); modello.generate( model, "java", parameters ); modello.generate( model, "xpp3-writer", parameters ); modello.generate( model, "xpp3-reader", parameters ); addDependency( "xmlunit", "xmlunit" ); compileGeneratedSources(); // TODO: see why without this, version system property is set to "2.4.1" value after verify System.setProperty( "version", getModelloVersion() ); verifyCompiledGeneratedSources( "org.codehaus.modello.generator.xml.xpp3.Xpp3Verifier" ); } } _AbstractElementTest.java000066400000000000000000000044701166654766000413760ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/java/org/codehaus/modello/generator/xml/xpp3package 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.core.ModelloCore; import org.codehaus.modello.model.Model; import java.util.Properties; /** * @author Trygve Laugstøl * @author Emmanuel Venisse * @version $Id: _AbstractElementTest.java 1399 2010-02-06 22:57:42Z 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( getXmlResourceReader( "/abstract.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); 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 ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/resources/000077500000000000000000000000001166654766000261255ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/resources/abstract.mdo000066400000000000000000000031651166654766000304360ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/resources/maven.mdo000066400000000000000000001673541166654766000277540ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/000077500000000000000000000000001166654766000261115ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/000077500000000000000000000000001166654766000277275ustar00rootroot00000000000000Xpp3FeaturesVerifier.java000066400000000000000000000233161166654766000345450ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/featurespackage 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.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; /** * @author Herve Boutemy * @version $Id: Xpp3FeaturesVerifier.java 1479 2010-04-26 17:09:32Z bentmann $ */ public class Xpp3FeaturesVerifier extends Verifier { public void verify() throws Exception { verifyAPI(); Features features = verifyReader(); features.getXmlFeatures().getXmlTransientFields().setTransientString( "NOT-TO-BE-WRITTEN" ); verifyWriter( features ); verifyBadVersion(); verifyWrongElement(); verifyWrongAttribute(); verifyWrongContent(); verifyTransientElement(); verifyEncoding(); } public void verifyAPI() throws Exception { assertReader( ModelloFeaturesTestXpp3Reader.class, Features.class, Reader.class, XmlPullParserException.class ); assertReader( ModelloFeaturesTestXpp3Reader.class, Features.class, InputStream.class, XmlPullParserException.class ); assertWriter( ModelloFeaturesTestXpp3Writer.class, Features.class, Writer.class, XmlPullParserException.class ); assertWriter( ModelloFeaturesTestXpp3Writer.class, Features.class, OutputStream.class, XmlPullParserException.class ); } 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 verifyWrongAttribute() throws Exception { ModelloFeaturesTestXpp3Reader reader = new ModelloFeaturesTestXpp3Reader(); // reading with strict=false should accept unknown element reader.read( getClass().getResourceAsStream( "/features-wrong-attribute.xml" ), false ); // by default, strict=true: reading should not accept unknown attribute try { reader.read( getClass().getResourceAsStream( "/features-wrong-attribute.xml" ) ); throw new VerifierException( "Reading a document with an unknown attribute under strict option should fail." ); } catch ( XmlPullParserException xppe ) { checkExpectedFailure( xppe, "Unknown attribute 'invalidAttribute' for tag 'attributes'" ); } } public void verifyWrongContent() throws Exception { ModelloFeaturesTestXpp3Reader reader = new ModelloFeaturesTestXpp3Reader(); // reading with strict=false should accept unexpected text content reader.read( getClass().getResourceAsStream( "/features-wrong-content.xml" ), false ); // by default, strict=true: reading should not accept unexpected content try { reader.read( getClass().getResourceAsStream( "/features-wrong-content.xml" ) ); throw new VerifierException( "Reading a document with a bad content under strict option should fail." ); } catch ( XmlPullParserException xppe ) { checkExpectedFailure( xppe, "expected START_TAG or END_TAG not TEXT" ); } } 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" ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/locations+src/000077500000000000000000000000001166654766000306675ustar00rootroot00000000000000Xpp3LocationsSourceVerifier.java000066400000000000000000000116571166654766000370500ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/locations+srcpackage 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.locationssrc.Item; import org.codehaus.modello.test.locationssrc.Location; import org.codehaus.modello.test.locationssrc.Model; import org.codehaus.modello.test.locationssrc.Source; import org.codehaus.modello.test.locationssrc.io.xpp3.LocationsSourceTestXpp3ReaderEx; import org.codehaus.modello.verifier.Verifier; /** * @author Benjamin Bentmann * @version $Id: Xpp3LocationsSourceVerifier.java 1459 2010-04-19 10:36:55Z bentmann $ */ public class Xpp3LocationsSourceVerifier extends Verifier { public void verify() throws Exception { Source source = new Source(); LocationsSourceTestXpp3ReaderEx reader = new LocationsSourceTestXpp3ReaderEx(); Model model = reader.read( getClass().getResourceAsStream( "/locations.xml" ), true, source ); assertLocation( model.getLocation( "" ), -1, -1, source ); assertLocation( model.getLocation( "string" ), 4, 11, source ); assertLocation( model.getLocation( "flatListStrings" ), -1, -1, source ); assertLocation( model.getLocation( "flatListStrings" ).getLocation( new Integer( 0 ) ), 6, 19, source ); assertLocation( model.getLocation( "flatListStrings" ).getLocation( new Integer( 1 ) ), 7, 19, source ); assertLocation( model.getLocation( "flatListStrings" ).getLocation( new Integer( 2 ) ), 8, 19, source ); assertLocation( model.getLocation( "flatSetStrings" ), -1, -1, source ); assertLocation( model.getLocation( "flatSetStrings" ).getLocation( "a" ), 10, 18, source ); assertLocation( model.getLocation( "flatSetStrings" ).getLocation( "b" ), 11, 18, source ); assertLocation( model.getLocation( "flatSetStrings" ).getLocation( "c" ), 12, 18, source ); assertLocation( model.getLocation( "wrappedListStrings" ), -1, -1, source ); assertLocation( model.getLocation( "wrappedListStrings" ).getLocation( new Integer( 0 ) ), 15, 24, source ); assertLocation( model.getLocation( "wrappedListStrings" ).getLocation( new Integer( 1 ) ), 16, 24, source ); assertLocation( model.getLocation( "wrappedListStrings" ).getLocation( new Integer( 2 ) ), 17, 24, source ); assertLocation( model.getLocation( "wrappedSetStrings" ), -1, -1, source ); assertLocation( model.getLocation( "wrappedSetStrings" ).getLocation( "a" ), 21, 23, source ); assertLocation( model.getLocation( "wrappedSetStrings" ).getLocation( "b" ), 22, 23, source ); assertLocation( model.getLocation( "wrappedSetStrings" ).getLocation( "c" ), 23, 23, source ); assertLocation( model.getLocation( "inlinedProperties" ), -1, -1, source ); assertLocation( model.getLocation( "inlinedProperties" ).getLocation( "a" ), 27, 8, source ); assertLocation( model.getLocation( "inlinedProperties" ).getLocation( "b" ), 28, 8, source ); assertLocation( model.getLocation( "explodedProperties" ), -1, -1, source ); assertLocation( model.getLocation( "explodedProperties" ).getLocation( "a" ), 34, 14, source ); assertLocation( model.getLocation( "explodedProperties" ).getLocation( "b" ), 38, 14, source ); Item item = model.getItems().get( 0 ); assertNotNull( item ); assertLocation( item.getLocation( "" ), -1, -1, source ); assertLocation( item.getLocation( "string" ), 45, 15, source ); } private void assertLocation( Location location, int line, int column, Source src ) throws Exception { assertNotNull( location ); assertSame( src, location.getSource() ); if ( line >= 0 ) { assertEquals( line, location.getLineNumber() ); } if ( column >= 0 ) { assertEquals( column, location.getColumnNumber() ); } } } modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/locations/000077500000000000000000000000001166654766000301045ustar00rootroot00000000000000Xpp3LocationsVerifier.java000066400000000000000000000110221166654766000350660ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/locationspackage 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.locations.Item; import org.codehaus.modello.test.locations.Location; import org.codehaus.modello.test.locations.Model; import org.codehaus.modello.test.locations.io.xpp3.LocationsTestXpp3ReaderEx; import org.codehaus.modello.verifier.Verifier; /** * @author Benjamin Bentmann * @version $Id: Xpp3LocationsVerifier.java 1459 2010-04-19 10:36:55Z bentmann $ */ public class Xpp3LocationsVerifier extends Verifier { public void verify() throws Exception { LocationsTestXpp3ReaderEx reader = new LocationsTestXpp3ReaderEx(); Model model = reader.read( getClass().getResourceAsStream( "/locations.xml" ), true ); assertLocation( model.getLocation( "" ), -1, -1 ); assertLocation( model.getLocation( "string" ), 4, 11 ); assertLocation( model.getLocation( "flatListStrings" ), -1, -1 ); assertLocation( model.getLocation( "flatListStrings" ).getLocation( new Integer( 0 ) ), 6, 19 ); assertLocation( model.getLocation( "flatListStrings" ).getLocation( new Integer( 1 ) ), 7, 19 ); assertLocation( model.getLocation( "flatListStrings" ).getLocation( new Integer( 2 ) ), 8, 19 ); assertLocation( model.getLocation( "flatSetStrings" ), -1, -1 ); assertLocation( model.getLocation( "flatSetStrings" ).getLocation( "a" ), 10, 18 ); assertLocation( model.getLocation( "flatSetStrings" ).getLocation( "b" ), 11, 18 ); assertLocation( model.getLocation( "flatSetStrings" ).getLocation( "c" ), 12, 18 ); assertLocation( model.getLocation( "wrappedListStrings" ), -1, -1 ); assertLocation( model.getLocation( "wrappedListStrings" ).getLocation( new Integer( 0 ) ), 15, 24 ); assertLocation( model.getLocation( "wrappedListStrings" ).getLocation( new Integer( 1 ) ), 16, 24 ); assertLocation( model.getLocation( "wrappedListStrings" ).getLocation( new Integer( 2 ) ), 17, 24 ); assertLocation( model.getLocation( "wrappedSetStrings" ), -1, -1 ); assertLocation( model.getLocation( "wrappedSetStrings" ).getLocation( "a" ), 21, 23 ); assertLocation( model.getLocation( "wrappedSetStrings" ).getLocation( "b" ), 22, 23 ); assertLocation( model.getLocation( "wrappedSetStrings" ).getLocation( "c" ), 23, 23 ); assertLocation( model.getLocation( "inlinedProperties" ), -1, -1 ); assertLocation( model.getLocation( "inlinedProperties" ).getLocation( "a" ), 27, 8 ); assertLocation( model.getLocation( "inlinedProperties" ).getLocation( "b" ), 28, 8 ); assertLocation( model.getLocation( "explodedProperties" ), -1, -1 ); assertLocation( model.getLocation( "explodedProperties" ).getLocation( "a" ), 34, 14 ); assertLocation( model.getLocation( "explodedProperties" ).getLocation( "b" ), 38, 14 ); Item item = model.getItems().get( 0 ); assertNotNull( item ); assertLocation( item.getLocation( "" ), -1, -1 ); assertLocation( item.getLocation( "string" ), 45, 15 ); } private void assertLocation( Location location, int line, int column ) throws Exception { assertNotNull( location ); if ( line >= 0 ) { assertEquals( line, location.getLineNumber() ); } if ( column >= 0 ) { assertEquals( column, location.getColumnNumber() ); } } } modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/000077500000000000000000000000001166654766000270035ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/Xpp3Verifier.java000066400000000000000000000577371166654766000322170ustar00rootroot00000000000000package 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() ); } } } modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/expected-encoding.xml000066400000000000000000000032151166654766000331130ustar00rootroot00000000000000 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3/expected.xml000066400000000000000000000034201166654766000313250ustar00rootroot00000000000000 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 model-with-missing-root-element.xml000066400000000000000000000004251166654766000355770ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3 Mailing list Super Subscribe Duper Unsubscribe ?ber Archive model-with-wrong-element.xml000066400000000000000000000033711166654766000343040ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3 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 model-with-wrong-element2.xml000066400000000000000000000034211166654766000343620ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3 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 model-with-wrong-root-element.xml000066400000000000000000000033311166654766000352610ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xpp3/src/test/verifiers/xpp3 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/000077500000000000000000000000001166654766000222515ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/pom.xml000066400000000000000000000024721166654766000235730ustar00rootroot00000000000000 modello-plugins org.codehaus.modello 1.4.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 org.codehaus.plexus plexus-utils xml-apis xml-apis 1.3.04 test xerces xercesImpl 2.8.1 test modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/000077500000000000000000000000001166654766000230405ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/000077500000000000000000000000001166654766000237645ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/000077500000000000000000000000001166654766000247055ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/000077500000000000000000000000001166654766000254745ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/000077500000000000000000000000001166654766000272675ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/000077500000000000000000000000001166654766000307225ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000322205ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/000077500000000000000000000000001166654766000330165ustar00rootroot00000000000000XsdGenerator.java000066400000000000000000000445751166654766000362260ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsdpackage 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.plugins.xml.AbstractXmlGenerator; import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; 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.List; import java.util.Properties; import java.util.Set; /** * @author Brett Porter * @version $Id: XsdGenerator.java 1484 2010-05-08 17:25:54Z bentmann $ */ 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() ); String namespace = XsdModelHelper.getNamespace( root.getModel(), getGeneratedVersion() ); w.addAttribute( "xmlns", namespace ); String targetNamespace = XsdModelHelper.getTargetNamespace( root.getModel(), getGeneratedVersion(), namespace ); // 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 = getFieldsForXml( modelClass, getGeneratedVersion() ); ModelField contentField = getContentField( fields ); boolean hasContentField = contentField != null; List attributeFields = getXmlAttributeFields( fields ); fields.removeAll( attributeFields ); if ( hasContentField ) { // yes it's only an extension of xs:string w.startElement( "xs:simpleContent" ); w.startElement( "xs:extension" ); w.addAttribute( "base", getXsdType( contentField.getType() ) ); } 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 ( !hasContentField ) { if ( compositorAll ) { w.startElement( "xs:all" ); } else { w.startElement( "xs:sequence" ); } } for ( ModelField field : fields ) { 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() ) || "Character".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\"" ); } w.addAttribute( "name", resolveTagName( fieldTagName, xmlAssociationMetadata ) ); w.addAttribute( "type", fieldModelClass.getName() ); w.addAttribute( "maxOccurs", "unbounded" ); writeFieldDocumentation( w, field ); } } 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 ) { w.endElement(); // xs:all or xs:sequence } } for ( ModelField field : attributeFields ) { 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() ) || "Character".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 ) { w.endElement(); //xs:extension w.endElement(); //xs:simpleContent } w.endElement(); // xs:complexType for ( ModelClass fieldModelClass : toWrite ) { 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; } } } XsdModelHelper.java000066400000000000000000000066731166654766000364750ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsdpackage org.codehaus.modello.plugin.xsd; import org.codehaus.modello.ModelloException; import org.codehaus.modello.model.Model; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugin.xsd.metadata.XsdModelMetadata; import org.codehaus.modello.plugins.xml.metadata.XmlModelMetadata; import org.codehaus.plexus.util.StringUtils; /* * 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 schema representation of the model. * * @author Hervé Boutemy * @version $Id: XsdModelHelper.java 1426 2010-03-28 15:35:15Z hboutemy $ */ public class XsdModelHelper { public static String getNamespace( Model model, Version version ) throws ModelloException { XmlModelMetadata xmlModelMetadata = (XmlModelMetadata) model.getMetadata( XmlModelMetadata.ID ); XsdModelMetadata xsdModelMetadata = (XsdModelMetadata) model.getMetadata( XsdModelMetadata.ID ); String namespace; if ( StringUtils.isNotEmpty( xsdModelMetadata.getNamespace() ) ) { namespace = xsdModelMetadata.getNamespace( version ); } 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( version ); } return namespace; } public static String getTargetNamespace( Model model, Version version, String namespace ) { XsdModelMetadata xsdModelMetadata = (XsdModelMetadata) model.getMetadata( XsdModelMetadata.ID ); String targetNamespace; if ( xsdModelMetadata.getTargetNamespace() == null ) { // xsd.target-namespace not set, using namespace targetNamespace = namespace; } else { targetNamespace = xsdModelMetadata.getTargetNamespace( version ); } return targetNamespace; } public static String getTargetNamespace( Model model, Version version ) throws ModelloException { return getTargetNamespace( model, version, getNamespace( model, version ) ); } } 000077500000000000000000000000001166654766000345175ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadataXsdAssociationMetadata.java000066400000000000000000000020271166654766000417570ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadatapackage 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(); } XsdClassMetadata.java000066400000000000000000000030531166654766000405500ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadatapackage 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; } } } XsdFieldMetadata.java000066400000000000000000000017631166654766000405340ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadatapackage 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(); } XsdInterfaceMetadata.java000066400000000000000000000020131166654766000413760ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadatapackage 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.InterfaceMetadata; /** * XsdFieldMetadata * * @author Joakim Erdfelt * @version $Id: XsdInterfaceMetadata.java 1436 2010-04-14 23:04:58Z bentmann $ */ public class XsdInterfaceMetadata implements InterfaceMetadata { public static final String ID = XsdInterfaceMetadata.class.getName(); } XsdMetadataPlugin.java000066400000000000000000000055671166654766000407550ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadatapackage 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.InterfaceMetadata; 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 org.codehaus.modello.model.ModelInterface; import java.util.Map; /** * XsdMetadataPlugin * * @author Joakim Erdfelt * @version $Id: XsdMetadataPlugin.java 1436 2010-04-14 23:04:58Z bentmann $ */ 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 InterfaceMetadata getInterfaceMetadata( ModelInterface iface, Map data ) throws ModelloException { return new XsdInterfaceMetadata(); } 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; } } XsdModelMetadata.java000066400000000000000000000041241166654766000405430ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/metadatapackage 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; } } modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/resources/000077500000000000000000000000001166654766000257765ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/resources/META-INF/000077500000000000000000000000001166654766000271365ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/resources/META-INF/plexus/000077500000000000000000000000001166654766000304565ustar00rootroot00000000000000components.xml000066400000000000000000000007771166654766000333210ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/main/resources/META-INF/plexus 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 modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/site/000077500000000000000000000000001166654766000240045ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/site/site.xml000066400000000000000000000005571166654766000255010ustar00rootroot00000000000000 Modello modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/000077500000000000000000000000001166654766000240175ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/000077500000000000000000000000001166654766000247405ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/000077500000000000000000000000001166654766000255275ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/000077500000000000000000000000001166654766000273225ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/000077500000000000000000000000001166654766000307555ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/000077500000000000000000000000001166654766000322535ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/000077500000000000000000000000001166654766000330515ustar00rootroot00000000000000ChangesXsdGeneratorTest.java000077500000000000000000000043361166654766000404040ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsdpackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; /** * @author Brett Porter * @version $Id: ChangesXsdGeneratorTest.java 1399 2010-02-06 22:57:42Z 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( getXmlResourceReader( "/changes.mdo" ) ); // generate XSD file Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "xsd", parameters ); //addDependency( "modello", "modello-core", "1.0-SNAPSHOT" ); // TODO write verifier that compiles generated schema: use jaxp //verify( "org.codehaus.modello.generator.xml.xsd.XsdVerifier", "xsd" ); } } FeaturesXsdGeneratorTest.java000066400000000000000000000071241166654766000406050ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsdpackage 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.core.ModelloCore; import org.codehaus.modello.model.Model; import org.xml.sax.SAXParseException; import java.io.File; import java.util.Properties; import javax.xml.XMLConstants; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; /** * @author Hervé Boutemy * @version $Id: FeaturesXsdGeneratorTest.java 1422 2010-02-14 22:00:45Z hboutemy $ */ public class FeaturesXsdGeneratorTest extends AbstractModelloGeneratorTest { public FeaturesXsdGeneratorTest() { super( "features" ); } public void testXsdGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) ); Properties parameters = getModelloParameters( "1.0.0" ); modello.generate( model, "xsd", parameters ); SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ); Schema schema = sf.newSchema( new StreamSource( new File( getOutputDirectory(), "features-1.0.0.xsd" ) ) ); Validator validator = schema.newValidator(); try { validator.validate( new StreamSource( getClass().getResourceAsStream( "/features.xml" ) ) ); } catch ( SAXParseException e ) { throw new ModelloException( "line " + e.getLineNumber() + " column " + e.getColumnNumber(), e ); } try { validator.validate( new StreamSource( getClass().getResourceAsStream( "/features-invalid.xml" ) ) ); fail( "parsing of features-invalid.xml should have failed" ); } catch ( SAXParseException e ) { // ok, expected exception assertTrue( String.valueOf( e.getMessage() ).indexOf( "invalidElement" ) >= 0 ); } try { validator.validate( new StreamSource( getClass().getResourceAsStream( "/features-invalid-transient.xml" ) ) ); fail( "XSD did not prohibit appearance of transient fields" ); } catch ( SAXParseException e ) { // ok, expected exception assertTrue( String.valueOf( e.getMessage() ).indexOf( "transientString" ) >= 0 ); } } } ModelloXsdGeneratorTest.java000066400000000000000000000076461166654766000404330ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsdpackage 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.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 1461 2010-04-19 10:43:44Z bentmann $ */ public class ModelloXsdGeneratorTest extends AbstractModelloGeneratorTest { public ModelloXsdGeneratorTest() { super( "modello" ); } public void testXsdGenerator() throws Throwable { ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); Properties parameters = getModelloParameters( "1.4.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.4.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; } } } XsdGeneratorTest.java000066400000000000000000000065571166654766000371170ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsdpackage 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.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; /** * @author Brett Porter * @version $Id: XsdGeneratorTest.java 1413 2010-02-13 21:23:01Z 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( getXmlResourceReader( "/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 = getModelloParameters( "4.0.0" ); 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" ); } } modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/resources/000077500000000000000000000000001166654766000260315ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/resources/changes.mdo000077500000000000000000000272351166654766000301560ustar00rootroot00000000000000 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.

    ]]>
    modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/resources/features-invalid.xml000066400000000000000000000004471166654766000320220ustar00rootroot00000000000000 modello1.4-1.4.1/modello-plugins/modello-plugin-xsd/src/test/resources/maven.mdo000066400000000000000000001640511166654766000276470ustar00rootroot00000000000000 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
    modello1.4-1.4.1/modello-plugins/pom.xml000066400000000000000000000044201166654766000200430ustar00rootroot00000000000000 modello org.codehaus.modello 1.4.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 maven-dependency-plugin 2.1 copy-test-libs process-test-resources copy-dependencies ${project.build.directory}/test-libs true true modello1.4-1.4.1/modello-plugins/src/000077500000000000000000000000001166654766000173155ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/src/site/000077500000000000000000000000001166654766000202615ustar00rootroot00000000000000modello1.4-1.4.1/modello-plugins/src/site/site.xml000066400000000000000000000006131166654766000217470ustar00rootroot00000000000000 Modello modello1.4-1.4.1/pom.xml000066400000000000000000000561241166654766000147410ustar00rootroot00000000000000 4.0.0 org.codehaus.modello modello 1.4.1 pom Modello 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. http://modello.codehaus.org/ 2001 Codehaus http://www.codehaus.org/ The MIT License http://opensource.org/licenses/mit-license.php repo 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 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 modello-maven-plugin modello-core modello-test modello-plugins scm:svn:http://svn.codehaus.org/modello/tags/modello-1.4.1 scm:svn:https://svn.codehaus.org/modello/tags/modello-1.4.1 http://svn.modello.codehaus.org/browse/modello/tags/modello-1.4.1 jira http://jira.codehaus.org/browse/MODELLO mail
    dev@modello.codehaus.org
    codehaus-nexus-staging Modello Repository https://nexus.codehaus.org/service/local/staging/deploy/maven2 codehaus-nexus-snapshots Modello Development Repository ${modelloDistMgmtSnapshotsUrl} codehaus.org dav:https://dav.codehaus.org/modello UTF-8 UTF-8 2.0.7 https://nexus.codehaus.org/content/repositories/snapshots 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-model ${maven.version} org.apache.maven maven-artifact ${maven.version} 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 junit junit 3.8.2 junit junit test org.apache.maven.plugins maven-site-plugin org.apache.maven.plugins maven-assembly-plugin 2.2-beta-5 org.apache.maven.plugins maven-clean-plugin 2.4 org.apache.maven.plugins maven-compiler-plugin 2.1 1.5 1.5 org.apache.maven.plugins maven-deploy-plugin 2.5 org.apache.maven.plugins maven-gpg-plugin 1.0 org.apache.maven.plugins maven-install-plugin 2.3 org.apache.maven.plugins maven-jar-plugin 2.3 true true org.apache.maven.plugins maven-plugin-plugin 2.6 maven-release-plugin 2.0 https://svn.codehaus.org/modello/tags true false deploy -Pmodello-release org.apache.maven.plugins maven-resources-plugin 2.4.1 org.apache.maven.plugins maven-source-plugin 2.1.1 org.apache.maven.plugins maven-site-plugin 2.1 org.apache.maven.plugins maven-surefire-plugin 2.4.3 maven-project-info-reports-plugin 2.1.2 false true modello-release maven-assembly-plugin org.apache.apache.resources apache-source-release-assembly-descriptor 1.0.2 source-release-assembly package single true source-release gnu org.apache.maven.plugins maven-gpg-plugin ${gpg.passphrase} sign-artifacts sign org.apache.maven.plugins maven-source-plugin attach-sources jar-no-fork org.apache.maven.plugins maven-javadoc-plugin attach-javadocs jar model org.codehaus.modello modello-maven-plugin ${project.version} src/main/mdo/modello.mdo 1.4.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/tags/maven-checkstyle-plugin-2.2/src/main/resources/config/maven_checks.xml http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.2/src/main/resources/config/maven-header.txt org.apache.maven.plugins maven-pmd-plugin 2.4 1.5 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.4 org.apache.maven.plugins maven-jxr-plugin 2.1 ${project.build.sourceEncoding} org.apache.maven.plugins maven-javadoc-plugin 2.6.1 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-3 ${basedir} org.apache.maven.plugins maven-site-plugin 3.0-beta-1-SNAPSHOT org.apache.maven.plugins maven-project-info-reports-plugin 2.2-SNAPSHOT
    modello1.4-1.4.1/src/000077500000000000000000000000001166654766000142035ustar00rootroot00000000000000modello1.4-1.4.1/src/main/000077500000000000000000000000001166654766000151275ustar00rootroot00000000000000modello1.4-1.4.1/src/main/mdo/000077500000000000000000000000001166654766000157065ustar00rootroot00000000000000modello1.4-1.4.1/src/main/mdo/modello.mdo000066400000000000000000001032271166654766000200470ustar00rootroot00000000000000 modello Modello This is a reference for the Modello descriptor used to describe a model with Modello. 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. VersionedElement An element with version information. 1.0.0+ BaseElement 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).]]> annotations 1.3.0+ String * Java annotations for the element (inserted in generated sources for the model only if Java 5 source generation feature is enabled). 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+ Information on model version recognition support. 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+ keysincedefault valueusage package model The package where java classes are generated by default if no packageName defined in class or interface model java.util.List new java.util.ArrayList<?>() The default code generated for List fields initialization java.util.Set new java.util.HashSet<?>() The default code generated for Set fields initialization java.util.Map new java.util.HashMap() The default code generated for Map fields initialization java.util.Properties new java.util.Properties() The default code generated for Properties fields initialization strictXmlAttributes1.2 true If set to true, reading an XML document with strict parsing enabled not only checks elements but attributes too (new in Modello 1.2). Setting this property to false makes strict parsing behave like previously, ie ignoring attributes. checkDeprecation false If set to true, checks that if a class has a version range with a specified upper version, its deprecatedVersion is not null ]]> key 1.0.0+ true String checkDeprecation, package, java.util.List, java.util.Map, java.util.Properties, java.util.Set, strictXmlAttributes.]]> 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. VersionedElement 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. name 1.0.0/1.2.9 String The name of the element (unused). 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).]]> description 1.0.0/1.2.9 String A user-level description of the element (unused). comment 1.0.0+ String A private comment about the element. code 1.0.0+ String The code block. ModelClass 1.0.0+ A class for this model. VersionedElement 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 locationTracker 1.4.0+ String see org.codehaus.modello.plugin.model.ModelMetadataPlugin sourceTracker 1.4.0+ String locationTracker to store the source tracking information and indirectly controls the names of the generated accessors. This attribute is only relevant in combination with locationTracker and must not be used on the same class.]]> 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.]]> 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.]]> see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin compositor 1.0.0+ String all all, sequence.]]> see org.codehaus.modello.plugins.xsd.metadata.XsdMetadataPlugin superClass 1.0.0+ String The name of the super class for this class. interfaces 1.0.0+ String * A set of interfaces implemented by 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. VersionedElement 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 content 1.4.0+ boolean Consider this field as the content of the class' 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 see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin insertParentFieldsUpTo 1.2.0+ String 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. Not that Content type is deprecated in favor of xml.content="true" field attribute.]]> 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. 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. 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.]]> 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
    modello1.4-1.4.1/src/site/000077500000000000000000000000001166654766000151475ustar00rootroot00000000000000modello1.4-1.4.1/src/site/apt/000077500000000000000000000000001166654766000157335ustar00rootroot00000000000000modello1.4-1.4.1/src/site/apt/location-tracking.apt000066400000000000000000000076331166654766000220620ustar00rootroot00000000000000 ------ Location Tracking ------ Benjamin Bentmann ------ 2010-04-18 ------ Location Tracking Starting with Modello 1.4, some parsers (currently only XPP3) support the tracking of line/column information for the input data. This means that additional metadata is stored in the model that can be used to query the location of some model element in the input source, e.g. for means of better error reporting to the user. To store the line/column information, one class of the model has to be specifically attributed: +----+ Location 1.0.0+ +----+ The attribute <<>> in the snippet above signals to Modello that this class should be used to record line/column metadata during parsing. The class can be modelled as usual but the fields to save the line and column number along with their accessors are automatically generated by Modello. All other model classes will be equipped with a field to hold instances of the <<>> class and accessors to query them. This way, each model class keeps track of the input locations for its fields: +----+ public class Model { private Map locations; public Location getLocation( Object field ) { return ( locations != null ) ? locations.get( field ) : null; } [...] } +----+ The location map shown above is keyed by field name. An empty string is used to query the location of the bean itself (or its text contents). For collections or maps, the returned <<>> instance can be further queried for its items. The key to query an item depends on the type of collection. For lists the zero-based index is used, for sets the item itself is used and for maps/properties the mapping key is used. For example, consider this input XML: +----+ hello list set value +----+ For this data model, one could query the location metadata like this (neglecting null checking): +----+ Model model = ; // to query the location of the element itself Location location1 = model.getLocation( "" ); // to query the location of the contents of , i.e. "hello" Location location2 = model.getLocation( "someString" ); // to query the location of the first list item, i.e. "list" Location location3 = model.getLocation( "listItems" ).getLocation( Integer.valueOf( 0 ) ); // to query the location of the set item, i.e. "set" Location location4 = model.getLocation( "setItems" ).getLocation( "set" ); // to query the location of the properties data, i.e. "value" Location location5 = model.getLocation( "properties" ).getLocation( "key" ); +----+ For performance reasons, generation of location metadata during parsing has to be explicitly requested. Usually, this means to use an reader instead of the normal reader generated by Modello. Occasionally, just tracking the line/column number is not enough but the input file of the model needs to be recorded as well. For this reason, another class of the model can be marked as a source tracker: +----+ Source 1.0.0+ +----+ The fields of this source tracking class are entirely up to the application, Modello will merely extend the generated <<>> class to support a reference to the <<>> class. An instance of the source tracking class can be provided to the extended readers which will then use it to populate all the generated <<>> instances. modello1.4-1.4.1/src/site/apt/release-notes.apt000066400000000000000000000421741166654766000212170ustar00rootroot00000000000000 ------ Release Notes ------ Hervé Boutemy ------ 2010-04-01 ------ Modello * 1.4.1 Release Notes (2010-09-25) The {{{http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10510&version=16774}full list of changes}} can be found in our {{{./issue-tracking.html}issue management system}}, and is reproduced below. ** Bug * [MODELLO-248] - bad deep clone implementation when using java5 and interface associations * 1.4 Release Notes (2010-05-29) The {{{http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10510&version=16153}full list of changes}} can be found in our {{{./issue-tracking.html}issue management system}}, and is reproduced below. ** Bug * [MODELLO-23] - ModelloGeneratorTest is not repository independent * [MODELLO-52] - Modello-core testCase broken * [MODELLO-226] - Recursive descent fails for tree-like data model starting with root element * [MODELLO-237] - Non-strict parsing mode doesn't properly skip over unknown elements with child elements * [MODELLO-245] - Associations to same class are erroneously interpreted as bidirectional ** Improvement * [MODELLO-206] - improve generated XML schema for content * [MODELLO-239] - Modello plugin is not thread-safe * [MODELLO-241] - Remove dependency on stax-utils for StAX-based writers * [MODELLO-242] - Remove dependency on plexus-utils for models that don't use DOM fields * [MODELLO-243] - Add read() methods that take InputStream as data source * [MODELLO-244] - Add write() methods that marshal to output stream * [MODELLO-246] - Make non-strict parsing ignore text inside element-only sections ** New Feature * [MODELLO-85] - Allow an element to have a text and attributes at the same time * [MODELLO-240] - Provide support to track line/column number of source elements * 1.3 Release Notes (2010-04-01) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10510&version=15584}issue management system}}, and is reproduced below. ** Bug * [MODELLO-234] - XML readers' generated code doesn't compile if root xml.tagName contains a dot or minus * [MODELLO-235] - Can't null association fields when java.useInterface=true ** Improvement * [MODELLO-236] - add XML Schema reference to generated xdoc ** New Feature * [MODELLO-214] - Add Java annotations generation ** Task * [MODELLO-230] - upgrade Modello code to Java 5 (without changing generated code: Java 1.4 code still generated by default) ** Wish * [MODELLO-231] - remove name and description elements from codeSegment in Modello's meta-model * 1.2 Release Notes (2010-01-19) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10510&version=15583}issue management system}}, and is reproduced below. ** Bug * [MODELLO-168] - Recursive descent fails for tree-like data model * [MODELLO-176] - Strict mode does not detect problems when data fields are encoded as XML attributes * [MODELLO-222] - java5 associations do not respect java.useInterface ** Improvement * [MODELLO-224] - XML representation of inherited fields: allow more flexibility than only append at end * [MODELLO-229] - Improve Modello model documentation: fields order is counter intuitive * 1.1 Release Notes (2009-08-21) The full list of changes can be found in our {{{http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=10510&version=14908}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/ReleaseNote.jspa?projectId=10510&version=15080}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/ReleaseNote.jspa?projectId=10510&version=14892}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/ReleaseNote.jspa?projectId=10510&version=13956}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/ReleaseNote.jspa?projectId=10510&version=14742}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/ReleaseNote.jspa?projectId=10510&version=14469}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/ReleaseNote.jspa?projectId=10510&version=14466}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/ReleaseNote.jspa?projectId=10510&version=14339}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/ReleaseNote.jspa?projectId=10510&version=13717}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/ReleaseNote.jspa?projectId=10510&version=13637}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/ReleaseNote.jspa?projectId=10510&version=13272}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/ReleaseNote.jspa?projectId=10510&version=13068}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/ReleaseNote.jspa?projectId=10510&version=12956}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/ReleaseNote.jspa?projectId=10510&version=12790}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. modello1.4-1.4.1/src/site/resources/000077500000000000000000000000001166654766000171615ustar00rootroot00000000000000modello1.4-1.4.1/src/site/resources/css/000077500000000000000000000000001166654766000177515ustar00rootroot00000000000000modello1.4-1.4.1/src/site/resources/css/site.css000066400000000000000000000001221166654766000214220ustar00rootroot00000000000000table.bodyTable tr.a:hover, table.bodyTable tr.b:hover { background: #dfe3db; } modello1.4-1.4.1/src/site/resources/modello-deps.png000066400000000000000000000526101166654766000222570ustar00rootroot00000000000000PNG  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`modello1.4-1.4.1/src/site/site.xml000066400000000000000000000032401166654766000166340ustar00rootroot00000000000000 Modello http://modello.codehaus.org/ Codehaus http://media.codehaus.org/images/unity-codehaus-logo.png http://codehaus.org/ org.apache.maven.skins maven-default-skin 1.0 modello1.4-1.4.1/src/site/xdoc/000077500000000000000000000000001166654766000161045ustar00rootroot00000000000000modello1.4-1.4.1/src/site/xdoc/index.xml000066400000000000000000000044301166654766000177360ustar00rootroot00000000000000 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.

    modello1.4-1.4.1/src/site/xdoc/modello-deps.odg000066400000000000000000000314071166654766000211700ustar00rootroot00000000000000PKAj&:.++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/