From: Vance K. <va...@us...> - 2006-10-06 02:06:32
|
User: vancek Date: 06/10/05 19:06:31 Modified: andromda-ejb3/src/site/axdoc howto.xml howto5.xml andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades EJB3EnumerationFacadeLogicImpl.java andromda-ejb3/src/main/resources/templates/ejb3 Enumeration.vsl andromda-ejb3/src/changes changes.xml andromda-ejb3/src/main/uml EJB3MetafacadeModel.xml.zip Log: Added support for enum member variables Add EJB3EnumerationFacade.memberVariablesAsList operation Update Enumeration.vsl to support member variables and data on literals Updated docs Revision Changes Path 1.2 +2 -0 cartridges/andromda-ejb3/src/site/axdoc/howto.xml Index: howto.xml =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/site/axdoc/howto.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- howto.xml 14 Sep 2006 14:31:28 -0000 1.1 +++ howto.xml 6 Oct 2006 02:06:31 -0000 1.2 @@ -100,6 +100,8 @@ <ul> <li><a href="howto5.html#Literals">Literal</a></li> <li><a href="howto5.html#Enumeration_Types">Enumeration Types</a></li> + <li><a href="howto5.html#Add_Data">Adding Data to Enumerations</a></li> + <li><a href="howto5.html#Further_Reading">Further Reading</a></li> </ul> </li> <li> 1.2 +30 -0 cartridges/andromda-ejb3/src/site/axdoc/howto5.xml Index: howto5.xml =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/site/axdoc/howto5.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- howto5.xml 14 Sep 2006 14:31:27 -0000 1.1 +++ howto5.xml 6 Oct 2006 02:06:31 -0000 1.2 @@ -106,6 +106,36 @@ values of the enumeration literals are used. </p> </subsection> + <a name="Add_Data"/> + <subsection name="Adding Data to Enumerations"> + <p> + You can now add data to eumeration literals. This is achieved by adding member variables to + the enumeration class. + </p> + <p> + You simply model the enumeration as you would normally, but add a member variable as an + attribute of the class. You have to model the + <code>@andromda.persistence.enumeration.member.variable</code> tagged value on this attribute to + indicate that this is NOT a literal. + </p> + <p> + Once you have all your literals and member variables, you can model the + <code>@andromda.persistence.enumeration.literal.parameters</code> tagged value on + enumeration literal attributes. This tagged value takes a comma separated list containing + the data/values assigned to your member variables. + </p> + <p class="highlight"> + Remember to order this comma separated list according to the order you added the member variables. + This is used in the enum class constructor to initialise the member variables. + </p> + </subsection> + <a name="Further_Reading"/> + <subsection name="Further Reading"> + <p> + To get a better understanding of Java5 enumerations, have a look at + <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html">Java5 Enums</a>. + </p> + </subsection> </section> <section name="Next"> <p> 1.2 +39 -0 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3EnumerationFacadeLogicImpl.java Index: EJB3EnumerationFacadeLogicImpl.java =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3EnumerationFacadeLogicImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- EJB3EnumerationFacadeLogicImpl.java 25 Jan 2006 03:01:00 -0000 1.1 +++ EJB3EnumerationFacadeLogicImpl.java 6 Oct 2006 02:06:31 -0000 1.2 @@ -1,5 +1,9 @@ package org.andromda.cartridges.ejb3.metafacades; +import java.util.Collection; +import java.util.Iterator; + +import org.andromda.metafacades.uml.AttributeFacade; /** * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3EnumerationFacade. @@ -14,4 +18,39 @@ { super (metaObject, context); } + + /** + * @see org.andromda.cartridges.ejb3.metafacades.EJB3EnumerationFacadeLogic# + * handleGetMemberVariablesAsList(java.util.Collection, boolean, boolean) + */ + protected String handleGetMemberVariablesAsList( + final Collection variables, + final boolean includeTypes, + final boolean includeNames) + { + if (!includeNames && !includeTypes || variables == null) + { + return ""; + } + + StringBuffer sb = new StringBuffer(); + String separator = ""; + + for (final Iterator it = variables.iterator(); it.hasNext();) + { + final AttributeFacade attr = (AttributeFacade)it.next(); + sb.append(separator); + separator = ", "; + if (includeTypes) + { + sb.append(attr.getType().getFullyQualifiedName()); + sb.append(" "); + } + if (includeNames) + { + sb.append(attr.getName()); + } + } + return sb.toString(); + } } \ No newline at end of file 1.5 +37 -1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/Enumeration.vsl Index: Enumeration.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/resources/templates/ejb3/Enumeration.vsl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- Enumeration.vsl 14 Jun 2006 14:37:25 -0000 1.4 +++ Enumeration.vsl 6 Oct 2006 02:06:31 -0000 1.5 @@ -16,10 +16,46 @@ /** $literal.getDocumentation(" * ") */ - ${literal.name}#if ($velocityCount != $enum.literals.size()),#else#**#;#end + ${literal.name}#if ($literal.enumerationLiteralParametersExist)(${literal.enumerationLiteralParameters})#end#if ($velocityCount != $enum.literals.size()),#else#**#;#end #end +#foreach ($memberVariable in $enum.memberVariables) + /** +$memberVariable.getDocumentation(" * ") + */ + $memberVariable.visibility $memberVariable.type.fullyQualifiedName ${memberVariable.name}; + +#end + /** + * $enum.name constructor + */ + private ${enum.name}($enum.getMemberVariablesAsList($enum.memberVariables, true, true)) + { +#foreach ($memberVariable in $enum.memberVariables) + ${memberVariable.setterName}(${memberVariable.name}); +#end + } + +#foreach ($memberVariable in $enum.memberVariables) + /** + * Get the $memberVariable.name property + * @return ${memberVariable.type.fullyQualifiedName} + */ + public ${memberVariable.type.fullyQualifiedName} ${memberVariable.getterName}() + { + return $memberVariable.name; + } + + /** + * Set the $memberVariable.name property. + * @param value the new value + */ + public void ${memberVariable.setterName}(${memberVariable.type.fullyQualifiedName} value) + { + this.${memberVariable.name} = value; + } +#end /** * Return the ${enum.name} from a string value * @return ${enum.name} enum object 1.33 +3 -0 cartridges/andromda-ejb3/src/changes/changes.xml Index: changes.xml =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/changes/changes.xml,v retrieving revision 1.32 retrieving revision 1.33 diff -u -w -r1.32 -r1.33 --- changes.xml 29 Sep 2006 08:01:27 -0000 1.32 +++ changes.xml 6 Oct 2006 02:06:31 -0000 1.33 @@ -297,6 +297,9 @@ EJB3MessageDrivenFacade.getDestinationType requires search and replace for destination type retrieved from TV. i.e. replace all '_' with '.'. </section> + <section dev="vancek" type="add"> + Add support for member variables within type safe enumerations. + </section> </release> </body> </document> \ No newline at end of file 1.45 +239 -229 cartridges/andromda-ejb3/src/main/uml/EJB3MetafacadeModel.xml.zip <<Binary file>> |