Author: tchemit Date: 2013-03-28 12:13:11 +0100 (Thu, 28 Mar 2013) New Revision: 1234 Url: http://nuiton.org/projects/eugene/repository/revisions/1234 Log: fixes #2634: Updates mavenpom to 3.4.8 refs #2633: Add JPA templates (entity, dao) Added: trunk/eugene-jpa-templates/ trunk/eugene-jpa-templates/LICENSE.txt trunk/eugene-jpa-templates/README.txt trunk/eugene-jpa-templates/changelog.txt trunk/eugene-jpa-templates/pom.xml trunk/eugene-jpa-templates/src/ trunk/eugene-jpa-templates/src/license/ trunk/eugene-jpa-templates/src/license/THIRD-PARTY.properties trunk/eugene-jpa-templates/src/main/ trunk/eugene-jpa-templates/src/main/java/ trunk/eugene-jpa-templates/src/main/java/org/ trunk/eugene-jpa-templates/src/main/java/org/nuiton/ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java trunk/eugene-jpa-templates/src/main/resources/ trunk/eugene-jpa-templates/src/main/resources/META-INF/ trunk/eugene-jpa-templates/src/main/resources/META-INF/services/ trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider trunk/eugene-jpa-templates/src/site/ trunk/eugene-jpa-templates/src/site/fr/ trunk/eugene-jpa-templates/src/site/fr/rst/ trunk/eugene-jpa-templates/src/site/fr/rst/index.rst trunk/eugene-jpa-templates/src/site/rst/ trunk/eugene-jpa-templates/src/site/rst/index.rst trunk/eugene-jpa-templates/src/site/site_en.xml trunk/eugene-jpa-templates/src/site/site_fr.xml trunk/eugene-jpa-templates/src/test/ trunk/eugene-jpa-templates/src/test/java/ trunk/eugene-jpa-templates/src/test/java/org/ trunk/eugene-jpa-templates/src/test/java/org/nuiton/ trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/ trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/ trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java trunk/eugene-jpa-templates/src/test/resources/ Modified: trunk/eugene-java-templates/pom.xml trunk/eugene-maven-plugin/pom.xml trunk/eugene/pom.xml trunk/pom.xml Modified: trunk/eugene/pom.xml =================================================================== --- trunk/eugene/pom.xml 2013-01-11 16:08:07 UTC (rev 1233) +++ trunk/eugene/pom.xml 2013-03-28 11:13:11 UTC (rev 1234) @@ -32,7 +32,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>eugene</artifactId> - <version>2.6.2-SNAPSHOT</version> + <version>2.7-SNAPSHOT</version> </parent> <groupId>org.nuiton.eugene</groupId> @@ -252,7 +252,7 @@ <plugin> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-maven-plugin</artifactId> - <version>1.3.8</version> + <version>${plexusPluginVersion}</version> </plugin> </plugins> </reporting> Modified: trunk/eugene-java-templates/pom.xml =================================================================== --- trunk/eugene-java-templates/pom.xml 2013-01-11 16:08:07 UTC (rev 1233) +++ trunk/eugene-java-templates/pom.xml 2013-03-28 11:13:11 UTC (rev 1234) @@ -29,7 +29,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>eugene</artifactId> - <version>2.6.2-SNAPSHOT</version> + <version>2.7-SNAPSHOT</version> </parent> <groupId>org.nuiton.eugene</groupId> @@ -57,7 +57,7 @@ <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> </dependency> - + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -135,7 +135,7 @@ <plugin> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-maven-plugin</artifactId> - <version>1.3.8</version> + <version>${plexusPluginVersion}</version> </plugin> </plugins> </reporting> Property changes on: trunk/eugene-jpa-templates ___________________________________________________________________ Added: svn:ignore + target .project .classpath .idea *.ipr *.iws *.iml Added: trunk/eugene-jpa-templates/LICENSE.txt =================================================================== --- trunk/eugene-jpa-templates/LICENSE.txt (rev 0) +++ trunk/eugene-jpa-templates/LICENSE.txt 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Property changes on: trunk/eugene-jpa-templates/LICENSE.txt ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/eugene-jpa-templates/README.txt ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/eugene-jpa-templates/changelog.txt ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/pom.xml =================================================================== --- trunk/eugene-jpa-templates/pom.xml (rev 0) +++ trunk/eugene-jpa-templates/pom.xml 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + EUGene :: JPA templates + + $HeadURL$ + %% + Copyright (C) 2013 CodeLutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>eugene</artifactId> + <version>2.7-SNAPSHOT</version> + </parent> + + <groupId>org.nuiton.eugene</groupId> + <artifactId>eugene-jpa-templates</artifactId> + + <dependencies> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>eugene</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <name>EUGene :: JPA templates</name> + + <inceptionYear>2013</inceptionYear> + + <properties> + <!-- extra files to include in release --> + <redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles> + </properties> + + <build> + + <plugins> + <plugin> + <groupId>org.nuiton.processor</groupId> + <artifactId>processor-maven-plugin</artifactId> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>process</goal> + </goals> + </execution> + </executions> + <configuration> + <includes>**/*.java</includes> + <filters> + org.nuiton.processor.filters.GeneratorTemplatesFilter + </filters> + </configuration> + </plugin> + + <!-- expose new plexus components --> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-metadata</artifactId> + <executions> + <execution> + <goals> + <goal>generate-metadata</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + + </build> + + <profiles> + + <!-- perform only on a release stage when using the maven-release-plugin --> + <profile> + <id>reporting</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + + <reporting> + <plugins> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-maven-plugin</artifactId> + <version>${plexusPluginVersion}</version> + </plugin> + </plugins> + </reporting> + + </profile> + </profiles> + +</project> + + + Property changes on: trunk/eugene-jpa-templates/pom.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/license/THIRD-PARTY.properties =================================================================== --- trunk/eugene-jpa-templates/src/license/THIRD-PARTY.properties (rev 0) +++ trunk/eugene-jpa-templates/src/license/THIRD-PARTY.properties 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,23 @@ +# Generated by org.codehaus.mojo.license.AddThirdPartyMojo +#------------------------------------------------------------------------------- +# Already used licenses in project : +# - BSD License +# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# - Common Public License Version 1.0 +# - Indiana University Extreme! Lab Software License, vesion 1.1.1 +# - Lesser General Public License (LGPL) v 3.0 +# - Lesser General Public License (LPGL) +# - Lesser General Public License (LPGL) v 2.1 +# - MIT License +# - Mozilla Public License Version 1.0 +# - New BSD License +# - The Apache Software License, Version 2.0 +# - The SAX License +# - The W3C License +# - http://jaxen.codehaus.org/license.html +#------------------------------------------------------------------------------- +# Please fill the missing licenses for dependencies : +# +# +#Thu Mar 28 12:01:53 CET 2013 +commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 Property changes on: trunk/eugene-jpa-templates/src/license/THIRD-PARTY.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,684 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +/*{generator option: parentheses = false}*/ +/*{generator option: writeString = +}*/ + +import org.nuiton.eugene.java.ObjectModelTransformerToJava; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelInterface; +import org.nuiton.eugene.models.object.ObjectModelJavaModifier; +import org.nuiton.eugene.models.object.ObjectModelOperation; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +/** + * Common class form jpa like transformer. + * + * @author tchemit <chemit@codelutin.com> + * @see JPAEntityTransformer + * @since 2.7 + */ +public abstract class AbstractJPATransformer extends ObjectModelTransformerToJava { + + public static final String DEFAULT_CONSTANT_PREFIX = "PROPERTY_"; + + protected void createPropertyConstant(ObjectModelClass output, + ObjectModelAttribute attr, + String prefix, + Set<String> constantNames) { + + String attrName = getAttributeName(attr); + + String constantName = prefix + builder.getConstantName(attrName); + + if (!constantNames.contains(constantName)) { + + addConstant(output, + constantName, + String.class, + "\"" + attrName + "\"", + ObjectModelJavaModifier.PUBLIC + ); + } + } + + protected String getAttributeName(ObjectModelAttribute attr) { + String attrName = attr.getName(); + if (attr.hasAssociationClass()) { + String assocAttrName = JPATemplatesGeneratorUtil.getAssocAttrName(attr); + attrName = JPATemplatesGeneratorUtil.toLowerCaseFirstLetter(assocAttrName); + } + return attrName; + } + + protected String getAttributeType(ObjectModelAttribute attr) { + String attrType = attr.getType(); + if (attr.hasAssociationClass()) { + attrType = attr.getAssociationClass().getName(); + } + return attrType; + } + + protected boolean containsMutiple(List<ObjectModelAttribute> attributes) { + + boolean result = false; + + for (ObjectModelAttribute attr : attributes) { + + if (JPATemplatesGeneratorUtil.isNMultiplicity(attr)) { + result = true; + + break; + } + + } + return result; + } + + protected void createProperty(ObjectModelClass output, + ObjectModelAttribute attr, + boolean usePCS, + boolean generateBooleanGetMethods) { + + String attrName = getAttributeName(attr); + String attrType = getAttributeType(attr); + + boolean multiple = JPATemplatesGeneratorUtil.isNMultiplicity(attr); + + String constantName = getConstantName(attrName); + String simpleType = JPATemplatesGeneratorUtil.getSimpleName(attrType); + + if (multiple) { + + createGetChildMethod(output, + attrName, + attrType, + simpleType + ); + + createIsEmptyMethod(output, + attrName + ); + + createSizeMethod(output, + attrName + ); + + createAddChildMethod(output, + attrName, + attrType, + constantName, + usePCS + ); + + createAddAllChildrenMethod(output, + attrName, + attrType, + constantName, + usePCS + ); + + createRemoveChildMethod(output, + attrName, + attrType, + constantName, + usePCS + ); + + createRemoveAllChildrenMethod(output, + attrName, + attrType, + constantName, + usePCS + ); + + createContainsChildMethod(output, + attrName, + attrType, + constantName, + usePCS + ); + + createContainsAllChildrenMethod(output, + attrName, + attrType, + constantName, + usePCS + ); + + // Change type for Multiple attribute + if (attr.isOrdered()) { + attrType = List.class.getName() + "<" + attrType + ">"; + } else { + attrType = Collection.class.getName() + "<" + attrType + ">"; + } + + simpleType = JPATemplatesGeneratorUtil.getSimpleName(attrType); + } + + boolean booleanProperty = JPATemplatesGeneratorUtil.isBooleanPrimitive(attr); + + if (booleanProperty && !multiple) { + + // creates a isXXX method + createGetMethod(output, + attrName, + attrType, + JPATemplatesGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX + ); + } + + if (multiple || !booleanProperty || generateBooleanGetMethods) { + + createGetMethod(output, + attrName, + attrType, + JPATemplatesGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX + ); + + } + createSetMethod(output, + attrName, + attrType, + simpleType, + constantName, + usePCS + ); + + // Add attribute to the class + addAttribute(output, + attrName, + attrType, + "", + ObjectModelJavaModifier.PROTECTED + ); + + } + + protected List<ObjectModelAttribute> getProperties(ObjectModelClass input) { + List<ObjectModelAttribute> attributes = + (List<ObjectModelAttribute>) input.getAttributes(); + + List<ObjectModelAttribute> attrs = + new ArrayList<ObjectModelAttribute>(); + for (ObjectModelAttribute attr : attributes) { + if (attr.isNavigable()) { + + // only keep navigable attributes + attrs.add(attr); + } + } + return attrs; + } + + protected void createGetMethod(ObjectModelClass output, + String attrName, + String attrType, + String methodPrefix) { + + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName(methodPrefix , attrName), + attrType, + ObjectModelJavaModifier.PUBLIC + ); + setOperationBody(operation, "" + /*{ + return <%=attrName%>; + }*/ + ); + } + + protected void createGetChildMethod(ObjectModelClass output, + String attrName, + String attrType, + String simpleType) { + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("get", attrName), + attrType, + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "int", "index"); + setOperationBody(operation, "" + /*{ + <%=simpleType%> o = getChild(<%=attrName%>, index); + return o; + }*/ + ); + } + + protected void createIsEmptyMethod(ObjectModelClass output, + String attrName) { + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("is", attrName)+"Empty", + boolean.class, + ObjectModelJavaModifier.PUBLIC + ); + setOperationBody(operation, "" + /*{ + return <%=attrName%> == null || <%=attrName%>.isEmpty(); + }*/ + ); + } + + protected void createSizeMethod(ObjectModelClass output, + String attrName) { + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("size", attrName), + int.class, + ObjectModelJavaModifier.PUBLIC + ); + setOperationBody(operation, "" + /*{ + return <%=attrName%> == null ? 0 : <%=attrName%>.size(); + }*/ + ); + } + protected void createAddChildMethod(ObjectModelClass output, + String attrName, + String attrType, + String constantName, + boolean usePCS) { + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("add", attrName), + "void", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, attrType, attrName); + + String methodName = getJavaBeanMethodName("get", attrName); + StringBuilder buffer = new StringBuilder("" + /*{ + <%=methodName%>().add(<%=attrName%>); + }*/ + ); + if (usePCS) { + buffer.append("" + /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>); + }*/ + ); + } + setOperationBody(operation, buffer.toString()); + } + + protected void createAddAllChildrenMethod(ObjectModelClass output, + String attrName, + String attrType, + String constantName, + boolean usePCS) { + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("addAll", attrName), + "void", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "java.util.Collection<" + attrType + ">", attrName); + + String methodName = getJavaBeanMethodName("get", attrName); + StringBuilder buffer = new StringBuilder("" + /*{ + <%=methodName%>().addAll(<%=attrName%>); + }*/ + ); + if (usePCS) { + buffer.append("" + /*{ firePropertyChange(<%=constantName%>, null, <%=attrName%>); + }*/ + ); + } + setOperationBody(operation, buffer.toString()); + } + + protected void createRemoveChildMethod(ObjectModelClass output, + String attrName, + String attrType, + String constantName, + boolean usePCS) { + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("remove", attrName), + "boolean", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, attrType, attrName); + String methodName = getJavaBeanMethodName("get", attrName); + StringBuilder buffer = new StringBuilder(); + buffer.append("" + /*{ + boolean removed = <%=methodName%>().remove(<%=attrName%>);}*/ + ); + + if (usePCS) { + buffer.append("" + /*{ + if (removed) { + firePropertyChange(<%=constantName%>, <%=attrName%>, null); + }}*/ + ); + } + buffer.append("" + /*{ + return removed; + }*/ + ); + setOperationBody(operation, buffer.toString()); + } + + protected void createRemoveAllChildrenMethod(ObjectModelClass output, + String attrName, + String attrType, + String constantName, + boolean usePCS) { + + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("removeAll", attrName), + "boolean", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "java.util.Collection<" + attrType + ">", attrName); + StringBuilder buffer = new StringBuilder(); + String methodName = getJavaBeanMethodName("get", attrName); + buffer.append("" + /*{ + boolean removed = <%=methodName%>().removeAll(<%=attrName%>);}*/ + ); + + if (usePCS) { + buffer.append("" + /*{ + if (removed) { + firePropertyChange(<%=constantName%>, <%=attrName%>, null); + }}*/ + ); + } + buffer.append("" + /*{ + return removed; + }*/ + ); + setOperationBody(operation, buffer.toString()); + } + + protected void createContainsChildMethod(ObjectModelClass output, + String attrName, + String attrType, + String constantName, + boolean usePCS) { + + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("contains", attrName), + "boolean", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, attrType, attrName); + StringBuilder buffer = new StringBuilder(); + String methodName = getJavaBeanMethodName("get", attrName); + buffer.append("" + /*{ + boolean contains = <%=methodName%>().contains(<%=attrName%>); + return contains; + }*/ + ); + setOperationBody(operation, buffer.toString()); + } + + protected void createContainsAllChildrenMethod(ObjectModelClass output, + String attrName, + String attrType, + String constantName, + boolean usePCS) { + + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("containsAll", attrName), + "boolean", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, "java.util.Collection<" + attrType + ">", attrName); + StringBuilder buffer = new StringBuilder(); + String methodName = getJavaBeanMethodName("get", attrName); + buffer.append("" + /*{ + boolean contains = <%=methodName%>().containsAll(<%=attrName%>); + return contains; + }*/ + ); + setOperationBody(operation, buffer.toString()); + } + + protected void createSetMethod(ObjectModelClass output, + String attrName, + String attrType, + String simpleType, + String constantName, + boolean usePCS) { + ObjectModelOperation operation = addOperation( + output, + getJavaBeanMethodName("set", attrName), + "void", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, attrType, attrName); + + if (usePCS) { + String methodName = getJavaBeanMethodName("get", attrName); + setOperationBody(operation, "" + /*{ + <%=simpleType%> oldValue = <%=methodName%>(); + this.<%=attrName%> = <%=attrName%>; + firePropertyChange(<%=constantName%>, oldValue, <%=attrName%>); + }*/ + ); + } else { + setOperationBody(operation, "" + /*{ + this.<%=attrName%> = <%=attrName%>; + }*/ + ); + } + } + + protected void addSerializable(ObjectModelClass input, + ObjectModelClass output, + boolean interfaceFound) { + if (!interfaceFound) { + addInterface(output, Serializable.class); + } + + // Generate the serialVersionUID + long serialVersionUID = JPATemplatesGeneratorUtil.generateSerialVersionUID(input); + + addConstant(output, + JPATemplatesGeneratorUtil.SERIAL_VERSION_UID, + "long", + serialVersionUID + "L", + ObjectModelJavaModifier.PRIVATE + ); + } + + /** + * Add all interfaces defines in input class and returns if + * {@link Serializable} interface was found. + * + * @param input the input model class to process + * @param output the output generated class + * @return {@code true} if {@link Serializable} was found from input, + * {@code false} otherwise + */ + protected boolean addInterfaces(ObjectModelClass input, + ObjectModelClass output) { + boolean foundSerializable = false; + for (ObjectModelInterface parentInterface : input.getInterfaces()) { + String fqn = parentInterface.getQualifiedName(); + addInterface(output, fqn); + if (Serializable.class.getName().equals(fqn)) { + foundSerializable = true; + } + } + return foundSerializable; + } + + protected void createPropertyChangeSupport(ObjectModelClass output) { + + addAttribute(output, + "pcs", + PropertyChangeSupport.class, + "new PropertyChangeSupport(this)", + ObjectModelJavaModifier.PROTECTED, + ObjectModelJavaModifier.FINAL, + ObjectModelJavaModifier.TRANSIENT + ); + + // Add PropertyListener + + ObjectModelOperation operation; + + operation = addOperation(output, + "addPropertyChangeListener", + "void", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, PropertyChangeListener.class, "listener"); + setOperationBody(operation, "" + /*{ + pcs.addPropertyChangeListener(listener); + }*/ + ); + + operation = addOperation(output, + "addPropertyChangeListener", + "void", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, String.class, "propertyName"); + addParameter(operation, PropertyChangeListener.class, "listener"); + setOperationBody(operation, "" + /*{ + pcs.addPropertyChangeListener(propertyName, listener); + }*/ + ); + + operation = addOperation(output, + "removePropertyChangeListener", + "void", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, PropertyChangeListener.class, "listener"); + setOperationBody(operation, "" + /*{ + pcs.removePropertyChangeListener(listener); + }*/ + ); + + operation = addOperation(output, + "removePropertyChangeListener", + "void", + ObjectModelJavaModifier.PUBLIC + ); + addParameter(operation, String.class, "propertyName"); + addParameter(operation, PropertyChangeListener.class, "listener"); + setOperationBody(operation, "" + /*{ + pcs.removePropertyChangeListener(propertyName, listener); + }*/ + ); + + operation = addOperation(output, + "firePropertyChange", + "void", + ObjectModelJavaModifier.PROTECTED + ); + addParameter(operation, String.class, "propertyName"); + addParameter(operation, Object.class, "oldValue"); + addParameter(operation, Object.class, "newValue"); + setOperationBody(operation, "" + /*{ + pcs.firePropertyChange(propertyName, oldValue, newValue); + }*/ + ); + + operation = addOperation(output, + "firePropertyChange", + "void", + ObjectModelJavaModifier.PROTECTED + ); + addParameter(operation, String.class, "propertyName"); + addParameter(operation, Object.class, "newValue"); + setOperationBody(operation, "" + /*{ + firePropertyChange(propertyName, null, newValue); + }*/ + ); + } + + protected void createGetChildMethod(ObjectModelClass output) { + ObjectModelOperation getChild = addOperation( + output, + "getChild", "<T> T", + ObjectModelJavaModifier.PROTECTED + ); + addImport(output, List.class); + + addParameter(getChild, "java.util.Collection<T>", "childs"); + addParameter(getChild, "int", "index"); + setOperationBody(getChild, "" +/*{ + T result = null; + if (childs != null) { + if (childs instanceof List) { + if (index < childs.size()) { + result = ((List<T>) childs).get(index); + } + } else { + int i = 0; + for (T o : childs) { + if (index == i) { + result = o; + break; + } + i++; + } + } + } + return result; +}*/ + ); + } +} Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/AbstractJPATransformer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,72 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + + +/*{generator option: parentheses = false}*/ +/*{generator option: writeString = +}*/ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.java.ObjectModelTransformerToJava; +import org.nuiton.eugene.models.object.ObjectModelClass; + +import java.util.Collection; + +/** + * JPADaoTransformer generates a dao for an entity. + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JPADaoTransformer" + * @since 2.7 + */ +public class JPADaoTransformer extends ObjectModelTransformerToJava { + + private static final Log log = LogFactory.getLog(JPADaoTransformer.class); + + @Override + public void transformFromClass(ObjectModelClass input) { + + if (!canGenerate(input)) { + + // not an entity, or skip, or already in classpath + return; + } + + //TODO + ObjectModelClass output = null; + } + + protected boolean canGenerate(ObjectModelClass input) { + boolean b = !JPATemplatesGeneratorUtil.hasSkipStereotype(input) && + JPATemplatesGeneratorUtil.hasEntityStereotype(input); + if (b) { + + // check if not found in class-path + b = !isInClassPath(input); + } + return b; + } +} \ No newline at end of file Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPADaoTransformer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,303 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelJavaModifier; +import org.nuiton.eugene.models.object.ObjectModelOperation; + +import javax.persistence.EntityManager; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/*{generator option: parentheses = false}*/ +/*{generator option: writeString = +}*/ + +/** + * JavaBeanTransformer generates simple bean with pcs support + * (and nothing else) according to the JavaBeans 1.1 norm. + * + * Since version 2.2.1, it is possible to + * <ul> + * <li>generate a simple POJO (says with no PCS support) by using the tag value {@link JPATemplatesTagValues#TAG_NO_PCS}.</li> + * <li>generate i18n keys using the tag value {@link JPATemplatesTagValues#TAG_I18N_PREFIX}.</li> + * </ul> + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.eugene.jpa.JPAEntityTransformer" + * @since 2.7 + */ +public class JPAEntityTransformer extends AbstractJPATransformer{ + + private static final Log log = LogFactory.getLog(JPAEntityTransformer.class); + + @Override + public void transformFromClass(ObjectModelClass input) { + + if (!canGenerate(input)) { + + // not an entity, or skip + return; + } + + EntityManager m; + + ObjectModelClass output = null; + + if (canGenerateAbstract(input)) { + + // nothing more to do + output = generateAbstract(input); + } + + if (canGenerateImpl(input, output)) { + + generateImpl(input); + } + } + + protected boolean canGenerate(ObjectModelClass input) { + boolean b = !JPATemplatesGeneratorUtil.hasSkipStereotype(input) && + JPATemplatesGeneratorUtil.hasEntityStereotype(input); + return b; + } + + protected boolean canGenerateAbstract(ObjectModelClass input) { + boolean b = !isInClassPath(input); + return b; + } + + protected boolean canGenerateImpl(ObjectModelClass input, + ObjectModelClass abstractOutput) { + String fqn = input.getQualifiedName() + "Impl"; + + if (isInClassPath(fqn)) { + + // already in class-path + return false; + } + + Collection<ObjectModelOperation> operations = input.getOperations(); + if (!operations.isEmpty()) { + + // this input have some specific operations (so Impl can not be generated) + return false; + } + + Collection<ObjectModelOperation> allOtherOperations = + input.getAllOtherOperations(true); + + if (!allOtherOperations.isEmpty()) { + + Collection<ObjectModelOperation> allExistingOperations = + new ArrayList<ObjectModelOperation>(input.getAllSuperclassOperations(true)); + + if (abstractOutput!=null) { + allExistingOperations.addAll(abstractOutput.getOperations()); + } + + for (ObjectModelOperation operation : allOtherOperations) { + if (!allExistingOperations.contains(operation)) { + + // found one method not on super classe, so can't generate Impl + return false; + } + } + } + return true; + +// boolean hasOperations = !allOtherOperations.isEmpty() || +// !operations.isEmpty(); +// +// // generate only if no user operations found +// return !hasOperations; + } + + + + + protected void createAbstractOperations(ObjectModelClass ouput, + Iterable<ObjectModelOperation> operations) { + JPATemplatesGeneratorUtil.cloneOperations( + this, + operations, + ouput, + true, + ObjectModelJavaModifier.ABSTRACT + ); + } + + protected ObjectModelClass generateAbstract(ObjectModelClass input) { + // test if a super class has bean stereotype + boolean superClassIsBean = false; + Collection<ObjectModelClass> superclasses = input.getSuperclasses(); + if(CollectionUtils.isNotEmpty(superclasses)) { + for (ObjectModelClass superclass : superclasses) { + if (JPATemplatesGeneratorUtil.hasEntityStereotype(superclass)) { + superClassIsBean = true; + break; + } + } + } + + String superClass = null; + + if (!superClassIsBean) { + + // try to find a super class by tag-value + superClass = + JPATemplatesGeneratorUtil.getEntitySuperClassTagValue( + model, input); + if (superClass != null) { + + // will act as if super class is a bean + superClassIsBean = true; + } + } + + ObjectModelClass output = + createAbstractClass(input.getName(), input.getPackageName()); + + if (superClass != null) { + setSuperClass(output, superClass); + } + if (log.isDebugEnabled()) { + log.debug("will generate " + output.getQualifiedName()); + } + + String i18nPrefix = JPATemplatesGeneratorUtil.getI18nPrefixTagValue(input, model); + if (!StringUtils.isEmpty(i18nPrefix)) { + generateI18nBlock(input, output, i18nPrefix); + } + + String noPCSTagValue = JPATemplatesGeneratorUtil.getNoPCSTagValue(model, input); + boolean usePCS = StringUtils.isEmpty(noPCSTagValue) || + !"true".equals(noPCSTagValue.trim()); + + String noGenerateBooleanGetMethods = + JPATemplatesGeneratorUtil.getDoNotGenerateBooleanGetMethods(model, input); + boolean generateBooleanGetMethods = + StringUtils.isEmpty(noGenerateBooleanGetMethods) || + !"true".equals(noGenerateBooleanGetMethods.trim()); + + String prefix = getConstantPrefix(input, DEFAULT_CONSTANT_PREFIX); + + setConstantPrefix(prefix); + + addSuperClass(input, output); + + boolean serializableFound = addInterfaces(input, output); + + if (superClassIsBean) { + serializableFound = true; + } + + addSerializable(input, output, serializableFound); + + Set<String> constantNames = addConstantsFromDependency(input, output); + + // Get available properties + List<ObjectModelAttribute> properties = getProperties(input); + + // Add properties constant + for (ObjectModelAttribute attr : properties) { + + createPropertyConstant(output, attr, prefix, constantNames); + } + + // Add properties field + javabean methods + for (ObjectModelAttribute attr : properties) { + + createProperty(output, attr, usePCS, generateBooleanGetMethods); + } + + // Add operations + createAbstractOperations(output, input.getOperations()); + + if (!superClassIsBean) { + + if (usePCS) { + + // Add property change support + createPropertyChangeSupport(output); + } + } + + boolean hasAMultipleProperty = containsMutiple(properties); + + // Add helper operations + if (hasAMultipleProperty) { + + if (!superClassIsBean) { + + // add getChild methods + createGetChildMethod(output); + } + + } + return output; + } + + protected ObjectModelClass generateImpl(ObjectModelClass input) { + + ObjectModelClass resultClassImpl = createClass( + input.getName() + "Impl", + input.getPackageName() + ); + + // set the abstract resulClass as the resultClassImpl super class + setSuperClass(resultClassImpl, input.getQualifiedName()); + + // add a fix serialVersionUID, since the class has no field nor method + addConstant(resultClassImpl, + JPATemplatesGeneratorUtil.SERIAL_VERSION_UID, + "long", + "1L", + ObjectModelJavaModifier.PRIVATE + ); + return resultClassImpl; + } + + protected void addSuperClass(ObjectModelClass input, + ObjectModelClass output) { + // Set superclass + Iterator<ObjectModelClass> j = input.getSuperclasses().iterator(); + if (j.hasNext()) { + ObjectModelClass p = j.next(); + // We want to set the inheritance to the implementation class of the father + // Ex for model : A -> B (a inherits B) we want : A -> BImpl -> B + String qualifiedName = p.getQualifiedName() + "Impl"; + setSuperClass(output, qualifiedName); + } + } +} \ No newline at end of file Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPAEntityTransformer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,84 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.eugene.java.JavaGeneratorUtil; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelClassifier; + +/** + * Utility class for pure jpa templates. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.7 + */ +public class JPATemplatesGeneratorUtil extends JavaGeneratorUtil { + + /** + * Check if the given classifier has the + * {@link JPATemplatesStereoTypes#STEREOTYPE_ENTITY} stereotype. + * + * @param classifier classifier to test + * @return {@code true} if stereotype was found, {@code false otherwise} + * @see JPATemplatesStereoTypes#STEREOTYPE_ENTITY + */ + public static boolean hasEntityStereotype(ObjectModelClassifier classifier) { + return classifier.hasStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY); + } + + /** + * Obtain the value of the {@link JPATemplatesTagValues#TAG_NO_PCS} + * tag value on the given model or classifier. + * <p/> + * It will first look on the model, and then in the given classifier. + * + * @param model model to seek + * @param classifier classifier to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see JPATemplatesTagValues#TAG_NO_PCS + * @since 2.3 + */ + public static String getNoPCSTagValue(ObjectModel model, ObjectModelClassifier classifier) { + String value = findTagValue(JPATemplatesTagValues.TAG_NO_PCS, classifier, model); + return value; + } + + /** + * Obtain the value of the {@link JPATemplatesTagValues#TAG_ENTITY_SUPER_CLASS} + * tag value on the given model or classifier. + * <p/> + * It will first look on the model, and then in the given classifier. + * + * @param model model to seek + * @param classifier classifier to seek + * @return the none empty value of the found tag value or {@code null} if not found nor empty. + * @see JPATemplatesTagValues#TAG_ENTITY_SUPER_CLASS + * @since 2.3 + */ + public static String getEntitySuperClassTagValue(ObjectModel model, ObjectModelClassifier classifier) { + String value = findTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, classifier, model); + return value; + } +} Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesGeneratorUtil.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,43 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.eugene.ModelPropertiesUtil; + +/** + * The JPA templates provider of tag values and stereotypes. + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider" role-hint="jpa" + * @since 2.7 + */ +public class JPATemplatesModelPropertiesProvider extends ModelPropertiesUtil.ModelPropertiesProvider { + + @Override + public void init() throws IllegalAccessException { + scanStereotypeClass(JPATemplatesStereoTypes.class); + scanTagValueClass(JPATemplatesTagValues.class); + } +} Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProvider.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,49 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.eugene.EugeneStereoTypes; +import org.nuiton.eugene.ModelPropertiesUtil; +import org.nuiton.eugene.models.object.ObjectModelClassifier; + +/** + * Defines all stereotypes managed by JPA templates. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.7 + */ +public interface JPATemplatesStereoTypes extends EugeneStereoTypes { + + /** + * Stereotype for JPA entities to place on a classifier. + * + * @see JPATemplatesGeneratorUtil#hasEntityStereotype(ObjectModelClassifier) + * @since 2.5.6 + */ + @ModelPropertiesUtil.StereotypeDefinition( + target = ObjectModelClassifier.class, + documentation = "To specify that a class is a JPA Entity") + String STEREOTYPE_ENTITY = "entity"; +} Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesStereoTypes.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,116 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.eugene.EugeneTagValues; +import org.nuiton.eugene.ModelPropertiesUtil; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelClassifier; + +/** + * Defines all tag values managed by JPA templates. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.7 + */ +public interface JPATemplatesTagValues extends EugeneTagValues { + + /** + * Tag value to set if do not want any pcs (says PropertyChangeSupport in a generated bean). + * <p/> + * You can globaly use it on the complete model or to a specific classifier. + * + * @see JPATemplatesGeneratorUtil#getNoPCSTagValue(ObjectModel, ObjectModelClassifier) + * @since 2.7 + */ + @ModelPropertiesUtil.TagValueDefinition( + target = {ObjectModel.class, ObjectModelClassifier.class}, + documentation = "To specify to not generate any propertyChange " + + "code for a class or any class of a model") + String TAG_NO_PCS = "noPCS"; + + /** + * Tag value to use a super class for generated bean. + * <p/> + * If the bean needs Property change support (says you do not add the {@link #TAG_NO_PCS} on classifier or model, + * then your class must provide evrything for it. + * <p/> + * More over, if you use some collections in your bean you must also define + * two method named {@code getChild(Collection list, int index)} and + * {@code getChild(List list, int index)} + * <p/> + * See new code to know minimum stuff to add in your class for this purpose. + * <pre> + * public abstract class AbstractEntity implements Serializable { + * + * private static final long serialVersionUID = 1L; + * + * protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + * + * public void addPropertyChangeListener(PropertyChangeListener listener) { + * pcs.addPropertyChangeListener(listener); + * } + * + * public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + * pcs.addPropertyChangeListener(propertyName, listener); + * } + * + * public void removePropertyChangeListener(PropertyChangeListener listener) { + * pcs.removePropertyChangeListener(listener); + * } + * + * public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + * pcs.removePropertyChangeListener(propertyName, listener); + * } + * + * protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + * pcs.firePropertyChange(propertyName, oldValue, newValue); + * } + * + * protected void firePropertyChange(String propertyName, Object newValue) { + * firePropertyChange(propertyName, null, newValue); + * } + * + * protected <T> T getChild(Collection<T> list, int index) { + * return CollectionUtil.getOrNull(list, index); + * } + * + * protected <T> T getChild(List<T> list, int index) { + * return CollectionUtil.getOrNull(list, index); + * } + * } + * </pre> + * <p/> + * You can globaly use it on the complete model or to a specific classifier. + * + * @see JPATemplatesGeneratorUtil#getEntitySuperClassTagValue(ObjectModel, ObjectModelClassifier) + * @since 2.7 + */ + @ModelPropertiesUtil.TagValueDefinition( + target = {ObjectModel.class, ObjectModelClassifier.class}, + documentation = "To specify a super-class to used on generated entities " + + "for a class or any class of a model") + String TAG_ENTITY_SUPER_CLASS = "entitySuperClass"; +} Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/JPATemplatesTagValues.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java =================================================================== --- trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java (rev 0) +++ trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,32 @@ +/** + * Eugene jpa package : JPA generators. + * <pre> + * - Generator : {@link JPAEntityTransformer } to generate a jap entity. + * - Generator : {@link JPADaoTransformer } to generate a dao. + * </pre> + */ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ Property changes on: trunk/eugene-jpa-templates/src/main/java/org/nuiton/eugene/jpa/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider =================================================================== --- trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider (rev 0) +++ trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1 @@ +org.nuiton.eugene.jpa.JPATemplatesModelPropertiesProvider \ No newline at end of file Property changes on: trunk/eugene-jpa-templates/src/main/resources/META-INF/services/org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/site/fr/rst/index.rst =================================================================== --- trunk/eugene-jpa-templates/src/site/fr/rst/index.rst (rev 0) +++ trunk/eugene-jpa-templates/src/site/fr/rst/index.rst 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,44 @@ +.. - +.. * #%L +.. * EUGene :: JPA templates +.. * $Id$ +.. * $HeadURL$ +.. * %% +.. * Copyright (C) 2013 CodeLutin, Tony Chemit +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Lesser General Public License as +.. * published by the Free Software Foundation, either version 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. - + +====== +Eugene +====== + +:Authors: tony CHEMIT +:Contact: chemit@codelutin.com +:Revision: $Revision$ +:Date: $Date$ + +.. contents:: + +Templates java +============== + +Ce module offre des templates pour générer des objets jpa, à savoir : + +- des entités (*org.nuiton.eugene.jpa.JPAEntityTransformer*) +- des dao (*org.nuiton.eugene.jpa.JPADaoTransformer*) + +*TODO Finir cette documentation avant la version 3.0 en donnant un exemple complet d'utilisation.* \ No newline at end of file Property changes on: trunk/eugene-jpa-templates/src/site/fr/rst/index.rst ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/site/rst/index.rst =================================================================== --- trunk/eugene-jpa-templates/src/site/rst/index.rst (rev 0) +++ trunk/eugene-jpa-templates/src/site/rst/index.rst 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,44 @@ +.. - +.. * #%L +.. * EUGene :: JPA templates +.. * $Id$ +.. * $HeadURL$ +.. * %% +.. * Copyright (C) 2013 CodeLutin, Tony Chemit +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Lesser General Public License as +.. * published by the Free Software Foundation, either version 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. - + +====== +Eugene +====== + +:Authors: tony CHEMIT +:Contact: chemit@codelutin.com +:Revision: $Revision$ +:Date: $Date$ + +.. contents:: + +JPA Templates +============= + +This module offers you some templates to generate some JPA stuff: + +- entities (*org.nuiton.eugene.jpa.JPAEntityTransformer*) +- dao (*org.nuiton.eugene.jpa.JPADaoTransformer*) + +* TODO Finish this documentation before version 3.0*. Property changes on: trunk/eugene-jpa-templates/src/site/rst/index.rst ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/site/site_en.xml =================================================================== --- trunk/eugene-jpa-templates/src/site/site_en.xml (rev 0) +++ trunk/eugene-jpa-templates/src/site/site_en.xml 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + EUGene :: JPA templates + $Id$ + $HeadURL$ + %% + Copyright (C) 2013 CodeLutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + + +<project name="${project.name}"> + + <bannerLeft> + <name>${project.name}</name> + </bannerLeft> + + <body> + + <head> + <script type="text/javascript" + src="http://maven-site.nuiton.org/public/js/maven-site-nuiton.org.js"> + </script> + </head> + + <breadcrumbs> + <item name="${project.name}" href="./index.html"/> + </breadcrumbs> + + <links> + <item name="[fr" href="fr/index.html"/> + <item name="en]" href="index.html"/> + </links> + + <menu ref="parent"/> + + <menu name="User"> + <item href="index.html" name="Home"/> + </menu> + + <menu ref="reports"/> + + <footer> + + <div id='projectMetas' locale='en' + projectversion='${project.version}' + platform='${project.platform}' + projectid='${project.projectId}' + scm='${project.scm.developerConnection}' + scmwebeditorenabled='${project.scmwebeditorEnabled}' + scmwebeditorurl='${project.scmwebeditorUrl}' + siteSourcesType='${project.siteSourcesType}' + piwikEnabled='${project.piwikEnabled}' + piwikId='${project.piwikId}'> + </div> + </footer> + + </body> +</project> Property changes on: trunk/eugene-jpa-templates/src/site/site_en.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/site/site_fr.xml =================================================================== --- trunk/eugene-jpa-templates/src/site/site_fr.xml (rev 0) +++ trunk/eugene-jpa-templates/src/site/site_fr.xml 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + EUGene :: JPA templates + $Id$ + $HeadURL$ + %% + Copyright (C) 2013 CodeLutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + + +<project name="${project.name}"> + + <bannerLeft> + <name>${project.name}</name> + </bannerLeft> + + <body> + + <head> + <script type="text/javascript" + src="http://maven-site.nuiton.org/public/js/maven-site-nuiton.org.js"> + </script> + </head> + + <breadcrumbs> + <item name="${project.name}" href="./index.html"/> + </breadcrumbs> + + <links> + <item name="[fr" href="index.html"/> + <item name="en]" href="../index.html"/> + </links> + + <!-- TC-20100117 : ne fonctionne pas sur une langue non principale --> + <!--<menu ref="parent"/>--> + <menu name="Parent Projet"> + <item name="Eugene" href="../../fr/index.html"/> + </menu> + + <menu name="Utilisateur"> + <item href="index.html" name="Accueil"/> + </menu> + + <menu ref="reports"/> + + <footer> + + <div id='projectMetas' locale='fr' + projectversion='${project.version}' + platform='${project.platform}' + projectid='${project.projectId}' + scm='${project.scm.developerConnection}' + scmwebeditorenabled='${project.scmwebeditorEnabled}' + scmwebeditorurl='${project.scmwebeditorUrl}' + siteSourcesType='${project.siteSourcesType}' + piwikEnabled='${project.piwikEnabled}' + piwikId='${project.piwikId}'> + </div> + </footer> + + </body> +</project> Property changes on: trunk/eugene-jpa-templates/src/site/site_fr.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java =================================================================== --- trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java (rev 0) +++ trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java 2013-03-28 11:13:11 UTC (rev 1234) @@ -0,0 +1,146 @@ +package org.nuiton.eugene.jpa; + +/* + * #%L + * EUGene :: JPA templates + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.eugene.ModelPropertiesUtil; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelClassifier; +import org.nuiton.eugene.models.object.ObjectModelEnumeration; +import org.nuiton.eugene.models.object.ObjectModelInterface; +import org.nuiton.eugene.models.object.ObjectModelOperation; + +/** + * To test stereotypes and tag values of this module. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.7 + */ +public class JPATemplatesModelPropertiesProviderTest { + + protected ModelPropertiesUtil.ModelPropertiesProvider provider; + + @Before + public void setUp() throws Exception { + provider = new JPATemplatesModelPropertiesProvider(); + provider.init(); + } + + @Test + public void getTagValueTarget() throws Exception { + getTagValueTarget(JPATemplatesTagValues.TAG_NO_PCS, ObjectModel.class, ObjectModelClassifier.class); + } + + @Test + public void containsTagValue() throws Exception { + containsTagValue(JPATemplatesTagValues.TAG_NO_PCS, true); + containsTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, true); + + long l = System.nanoTime(); + containsTagValue(JPATemplatesTagValues.TAG_NO_PCS + l, false); + containsTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS + l, false); + } + + @Test + public void acceptTagValue() throws Exception { + acceptTagValue(JPATemplatesTagValues.TAG_NO_PCS, true, ObjectModel.class, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class); + acceptTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, true, ObjectModel.class, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class); + + acceptTagValue(JPATemplatesTagValues.TAG_NO_PCS, false, ObjectModelOperation.class, ObjectModelAttribute.class); + acceptTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS, false, ObjectModelOperation.class, ObjectModelAttribute.class); + + long l = System.nanoTime(); + acceptTagValue(JPATemplatesTagValues.TAG_NO_PCS + l, false, ObjectModelOperation.class, ObjectModelAttribute.class); + acceptTagValue(JPATemplatesTagValues.TAG_ENTITY_SUPER_CLASS + l, false, ObjectModelOperation.class, ObjectModelAttribute.class); + } + + @Test + public void getStereotypeTarget() throws Exception { + + getStereotypeTarget(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, ObjectModelClassifier.class); + } + + @Test + public void containsStereotype() throws Exception { + containsStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, true); + + long l = System.nanoTime(); + containsStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY + l, false); + } + + @Test + public void acceptStereotype() throws Exception { + + acceptStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, true, ObjectModelClassifier.class, ObjectModelClass.class, ObjectModelEnumeration.class, ObjectModelInterface.class); + + acceptStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY, false, ObjectModel.class, ObjectModelOperation.class); + + long l = System.nanoTime(); + acceptStereotype(JPATemplatesStereoTypes.STEREOTYPE_ENTITY + l, false, ObjectModel.class, ObjectModelOperation.class); + + } + + protected void getTagValueTarget(String name, Class<?>... expected) { + Class<?>[] classes = provider.getTagValueTarget(name); + Assert.assertNotNull("Could not find target for " + name, classes); + Assert.assertEquals("Should have " + expected.length + " targets for " + name + " but had " + classes.length, classes.length, expected.length); + Assert.assertArrayEquals(expected, classes); + } + + protected void containsTagValue(String name, boolean expected) { + boolean classes = provider.containsTagValue(name); + Assert.assertEquals(expected, classes); + } + + protected void acceptTagValue(String name, boolean expected, Class<?>... types) { + for (Class<?> type : types) { + boolean actual = provider.acceptTagValue(name, type); + Assert.assertEquals(expected, actual); + } + } + + protected void getStereotypeTarget(String name, Class<?>... expected) { + Class<?>[] classes = provider.getStereotypeTarget(name); + Assert.assertNotNull("Could not find target for " + name, classes); + Assert.assertEquals("Should have " + expected.length + " targets for " + name + " but had " + classes.length, classes.length, expected.length); + Assert.assertArrayEquals(expected, classes); + } + + protected void containsStereotype(String name, boolean expected) { + boolean classes = provider.containsStereotype(name); + Assert.assertEquals(expected, classes); + } + + protected void acceptStereotype(String name, boolean expected, Class<?>... types) { + for (Class<?> type : types) { + boolean actual = provider.acceptStereotype(name, type); + Assert.assertEquals(expected, actual); + } + } +} Property changes on: trunk/eugene-jpa-templates/src/test/java/org/nuiton/eugene/jpa/JPATemplatesModelPropertiesProviderTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/eugene-maven-plugin/pom.xml =================================================================== --- trunk/eugene-maven-plugin/pom.xml 2013-01-11 16:08:07 UTC (rev 1233) +++ trunk/eugene-maven-plugin/pom.xml 2013-03-28 11:13:11 UTC (rev 1234) @@ -33,7 +33,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>eugene</artifactId> - <version>2.6.2-SNAPSHOT</version> + <version>2.7-SNAPSHOT</version> </parent> <groupId>org.nuiton.eugene</groupId> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-01-11 16:08:07 UTC (rev 1233) +++ trunk/pom.xml 2013-03-28 11:13:11 UTC (rev 1234) @@ -32,15 +32,16 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmineAndCentral</artifactId> - <version>3.4.7</version> + <version>3.4.8</version> </parent> <artifactId>eugene</artifactId> - <version>2.6.2-SNAPSHOT</version> + <version>2.7-SNAPSHOT</version> <modules> <module>eugene</module> <module>eugene-java-templates</module> + <module>eugene-jpa-templates</module> <module>eugene-maven-plugin</module> </modules> @@ -139,6 +140,12 @@ </dependency> <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + <version>1.0.1.Final</version> + </dependency> + + <dependency> <groupId>org.nuiton</groupId> <artifactId>helper-maven-plugin-api</artifactId> <version>${helperPluginVersion}</version> @@ -318,6 +325,7 @@ <!-- do not relativize links in generated site --> <relativizeDecorationLinks>false</relativizeDecorationLinks> + <plexusPluginVersion>1.3.8</plexusPluginVersion> </properties> <build>