From: Vance K. <va...@us...> - 2006-01-03 01:04:47
|
User: vancek Date: 06/01/02 17:04:40 Modified: andromda-ejb3/src/main/resources/templates/ejb3 SessionBean.vsl Log: fixed to include ejb3 annotations Revision Changes Path 1.2 +146 -363 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/SessionBean.vsl Index: SessionBean.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/resources/templates/ejb3/SessionBean.vsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- SessionBean.vsl 28 Dec 2005 00:32:55 -0000 1.1 +++ SessionBean.vsl 3 Jan 2006 01:04:39 -0000 1.2 @@ -5,422 +5,205 @@ #end /** - * Autogenerated EJB implementation class for the ${service.serviceName} session bean. -$service.getDocumentation(" * ") - * -#if ($service.abstract) - * @ejb.bean generate="false" -#else - * @ejb.bean generate="true" -#end - * name="$service.name" - * type="$service.type" - * view-type="$service.viewType" - * jndi-name = "${service.jndiName}/Remote" - * local-jndi-name = "${service.jndiName}/Local" - * - * @ejb.interface - * local-class="${service.fullyQualifiedName}Local" - * remote-class="${service.fullyQualifiedName}" - * @ejb.home - * local-class="${service.fullyQualifiedName}LocalHome" - * remote-class="${service.fullyQualifiedName}Home" - * @ejb.transaction type="$service.transactionType" + * Autogenerated EJB entity POJO class for the ${service.serviceName} session bean. * - * @ejb.util generate="physical" - * -#foreach($envEntry in $service.getEnvironmentEntries(true)) -#set ($value = $envEntry.defaultValue) -## Add string delimiters if they are not already present -#if (!$value.startsWith('"') || !$value.endsWith('"')) -#set ($value = "$value") -#end - * @ejb.env-entry - * name="$envEntry.name" - * type="$envEntry.type.fullyQualifiedName" - * value="$value" - * -#end -#foreach ( $dependency in $service.sourceDependencies ) -#if ($dependency.hasStereotype("EntityRef") || $dependency.hasStereotype("ServiceRef")) -#set ($reference = $dependency.targetElement) - * @ejb.ejb-ref - * ejb-name="${reference.name}" - * view-type="$reference.viewType" - * ref-name="ejb/${reference.name}BeanRef" - * -#end -#if ($dependency.hasStereotype("ResourceRef")) -#set ($reference = $dependency.targetElement) -#set ($jndiRef = $dependency.findTaggedValue("@andromda.ejb.resource-ref.jndi-name")) -#set ($resAuth = $dependency.findTaggedValue("@andromda.ejb.resource-ref.res-auth")) -#if (!$resAuth) -#set ($resAuth = "Container") -#end -#set ($resName = $dependency.name) -#if (!$resName) -#set ($resName = $reference.name) -#end - * @ejb.resource-ref - * res-ref-name="resource/$resName" - * res-type="${reference.fullyQualifiedName}" - * res-auth="$resAuth" - * -#if ($jndiRef) - * @jboss.resource-ref - * res-ref-name = "resource/$resName" - * jndi-name = "$jndiRef" +$service.getDocumentation(" * ") * - * @weblogic.resource-description - * res-ref-name= "resource/$resName" - * jndi-name= "$jndiRef" * - * @websphere.bean -#end -#end -#end */ +@javax.ejb.${service.type} +#if ($service.transactionType) +...@ja...ansactionAttribute(javax.ejb.TransactionAttributeType.${service.transactionType}) +#end +...@ja...llbackListener(${service.fullyQualifiedServiceListenerName}.class) +#if ($service.securityDomain) +#**##if ($service.persistenceContainerJboss) +...@or...curityDomain("${service.securityDomain}") +#**##end +#end +#if ($service.permitAll) +...@ja...rmitAll +#elseif ($service.rolesAllowed) +...@ja...lesAllowed({${service.rolesAllowed}}) +#end public abstract class ${service.serviceName} #if($service.generalization) extends ${service.generalization.fullyQualifiedName}BeanImpl #end - implements javax.ejb.SessionBean + implements ${service.fullyQualifiedServiceLocalInterfaceName}, ${service.fullyQualifiedServiceRemoteInterfaceName} { - // ----------- constant definitions ----------- -#foreach($constant in $service.getConstants(true)) - private static final $constant.type.fullyQualifiedName $constant.name = $constant.defaultValue; -#end + // ------ Session Context Injection ------ + @javax.annotation.Resource + javax.ejb.SessionContext context; - // -- accessors for environment entries -- -#foreach($envEntry in $service.getEnvironmentEntries(true)) - /** - * Get <em>${envEntry.name}</em> environment entry. -$envEntry.getDocumentation(" * ") - * -## Only expose the method to the component interface if it is public. -#set ($visibility = $envEntry.visibility) -#if($visibility == "public") - * @ejb.interface-method -#end - */ - $visibility $envEntry.type.fullyQualifiedName ${envEntry.getterName}() - { - javax.naming.InitialContext initialContext = null; - try - { - initialContext = new javax.naming.InitialContext(); - return (${envEntry.type.fullyQualifiedName}) initialContext.lookup("java:comp/env/$envEntry.name"); - } - catch (javax.naming.NamingException cause) - { - RuntimeException ex = new IllegalStateException( - "Cannot access environment entry \"$envEntry.name\"."); - // In order to set the exception cause on JDK 1.4 - // and stay JDK 1.3 compatible nonetheless, we need - // a bit of reflection magic here... - try - { - java.lang.reflect.Method initCause = - ex.getClass().getMethod("initCause", - new Class[] {Throwable.class}); - initCause.invoke(ex, new Object[] { cause }); - } - catch (Throwable t) - { - // Ignore any errors here - we simply make do without the cause - } - throw ex; - } - finally - { - try - { - if (initialContext != null) - { - initialContext.close(); - } - } - catch (javax.naming.NamingException ignore) - { - // Silently ignore naming exceptions at cleanup time - } - } - } -#end + // ------ Persistence Context Definitions -------- - // -- accessors for constants -- -#foreach($constant in $service.getConstants(true)) +#set ($argExists = false) /** - * Get the <code>$constant.name</code> constant -$constant.getDocumentation(" * ") -#if ($constant.visibility == "public") - * - * @ejb.interface-method -#end - $constant.visibility $constant.type.fullyQualifiedName ${constant.getterName}() - { - return $constant.name; - } - -## If the constant is public, expose it to the home interface as well -#if($constant.visibility == "public") + * Inject persistence context #if ($service.persistenceContextUnitName)${service.persistenceContextUnitName}#end - /** - * Home interface method for accessing {@link #${attribute.getterName}}. - * @ejb.home-method - * @see #${constant.getterName} */ - public $constant.type.fullyQualifiedName ejbHomeGet${constant.name}() - { - return ${constant.getterName}; - } -#end -#end + @javax.persistence.PersistenceContext#if ($service.persistenceContextUnitName || $service.persistenceContextType)(#end#if ($service.persistenceContextUnitName)unitName = "${service.persistenceContextUnitName}"#set ($argExists = true)#end#if ($service.persistenceContextType)#if ($argExists),#end type = javax.persistence.PersistenceContextType.${service.persistenceContextType}#end#if ($service.persistenceContextUnitName || $service.persistenceContextType))#end -#set ($instanceAttributes = $service.instanceAttributes) -#if(!$instanceAttributes.empty) - // --------------- attributes --------------------- -#foreach ( $attribute in $instanceAttributes) -#set ($visibility = $attribute.visibility) - /** The $attribute.name property */ - private $attribute.type.fullyQualifiedName $attribute.name; + protected javax.persistence.EntityManager emanager; +#foreach ($reference in $service.persistenceContextReferences) +#**##set ($persistenceContext = $reference.targetElement) +#**##set ($argExists = false) /** - * Get the ${attribute.name} property -$attribute.getDocumentation(" * ") - * -#if ($attribute.transactionType) - * @ejb.transaction type="$attribute.transactionType" -#end -#if($visibility == "public") - * @ejb.interface-method -#end - */ - $visibility $attribute.type.fullyQualifiedName ${attribute.getterName}() - { - return $attribute.name; - } + * Inject persistence context #if ($persistenceContext.persistenceContextUnitName)${persistenceContext.persistenceContextUnitName}#end -## Only generate a setter if the attribute is not read-only -## Note: It's no use to generate final fields for read-only attributes because -## the fields are likely to be initialized in ejbActivate() or a similiar -## method and not in the constructor. -#if (!$attribute.readOnly) - /** - * Set the $attribute.name property - * @param value the new value -#if($visibility == "public") - * @ejb.interface-method -#end -#if ($attribute.transactionType) - * @ejb.transaction type="$attribute.transactionType" -#end */ - $visibility void ${attribute.setterName}($attribute.type.fullyQualifiedName value) - { - this.$attribute.name = value; - } - -#end + @javax.persistence.PersistenceContext#if ($persistenceContext.persistenceContextUnitName || $persistenceContext.persistenceContextType)(#end#if ($persistenceContext.persistenceContextUnitName)unitName = "${persistenceContext.persistenceContextUnitName}"#set ($argExists = true)#end#if ($persistenceContext.persistenceContextType)#if ($argExists),#end type = javax.persistence.PersistenceContextType.${persistenceContext.persistenceContextType}#end#if ($persistenceContext.persistenceContextUnitName || $persistenceContext.persistenceContextType))#end + protected javax.persistence.EntityManager ${persistenceContext.name}; #end -#end - // ---------------- business methods ---------------------- +#set ($references = $service.serviceReferences) +#if (!$references.empty) +#**##foreach ($dependency in $references) +#* *##set ($reference = $dependency.targetElement) + + // ------ EJB Injection Definitions -------- -#foreach ( $operation in $service.businessOperations) -#set ($visibility = $operation.visibility) /** -$operation.getDocumentation(" * ") -## Only public methods have transactions and are exported to the interfaces -#if ($visibility == "public") - * @ejb.interface-method -#if ($operation.transactionType) - * @ejb.transaction type="$operation.transactionType" -#end -#end + * Inject session EJB ${reference.name}; */ -#set ($returnType = $operation.returnType.fullyQualifiedName) -#if ($operation.exceptionsPresent) - $visibility abstract $returnType $operation.signature throws $operation.exceptionList; -#else - $visibility abstract $returnType $operation.signature; + @javax.annotation.EJB + protected ${reference.fullyQualifiedServiceName} $stringUtils.uncapitalize(${reference.name}); +#**##end #end +#set ($constants = $service.getConstants(true)) +#if (!$constants.empty) + // ----------- Constant Definitions ----------- + +#**##foreach($constant in $constants) + private static final $constant.type.fullyQualifiedName $constant.name = $constant.defaultValue; +#**##end #end +#set ($instanceAttributes = $service.instanceAttributes) +#if(!$instanceAttributes.empty) - // ---------------- create methods -------------------- -## Handle explicitly defined create methods. Since we can't know -## what the user intended to do with the arbitrary parameters to these methods, -## we generate an abstract ejbCreate() and delegate the implementation to the user. -#foreach ( $operation in $service.getCreateMethods(false)) + // ------------ Attributes ------------------ - /** -$operation.getDocumentation(" * ") - * - * @ejb.create-method - */ - public abstract void ejbCreate($operation.typedArgumentList); - - public void ejbPostCreate($operation.typedArgumentList) - { - } +#**##foreach ($attribute in $instanceAttributes) + /** The $attribute.name property */ + private $attribute.type.fullyQualifiedName $attribute.name; +#**##end #end -## Default create method with no arguments. - /** -## Only expose the method to the interface for concrete EJBs -#if (!$service.abstract) - * @ejb.create-method -#end - */ - public void ejbCreate() throws javax.ejb.CreateException - { - } + // --------------- Constructors --------------- - public void ejbPostCreate() throws javax.ejb.CreateException +## Default create method with no arguments. + public ${service.serviceName}() { + super(); } - ## Autogenerated create method with all attributes. Only present for stateful beans. #set ($allAttributes = $service.allInstanceAttributes) #if (!$allAttributes.empty) + /** - * Create method with all attribute values. -#set ($inheritedAttributes = $service.inheritedInstanceAttributes) -#foreach($attribute in $allAttributes) + * Constructor with all attribute values. +#**##set ($inheritedAttributes = $service.inheritedInstanceAttributes) +#**##foreach($attribute in $allAttributes) * @param $attribute.name Value for the ${attribute.name} property -#end - * @ejb.create-method +#**##end */ - public void ejbCreate($transform.getAttributesAsList($allAttributes, true, true)) - throws javax.ejb.CreateException + public ${service.serviceName}($service.getAttributesAsList($allAttributes, true, true)) { -#if(!$inheritedAttributes.empty) - // Call ejbCreate method for the super type - super.ejbCreate($transform.getAttributesAsList($inheritedAttributes, false, true)); -#end -#foreach ( $attribute in $service.instanceAttributes) +#**##if(!$inheritedAttributes.empty) + super($service.getAttributesAsList($inheritedAttributes, false, true)); +#**##end +#**##foreach ($attribute in $service.instanceAttributes) ## Don't use a setter here - we may have none if the attribute is marked readonly this.$attribute.name = $attribute.name; -#end - } - - public void ejbPostCreate($transform.getAttributesAsList($allAttributes, true, true)) - throws javax.ejb.CreateException - { -#if(!$inheritedAttributes.empty) - // Call postCreate method for the super type - super.ejbPostCreate($transform.getAttributesAsList($inheritedAttributes, false, true)); -#end +#**##end } #end +#if (!$constants.empty) - // ---------------- accessor methods for bean references --------------- + // --------- Accessors for Constants ---------- -#foreach ( $dependency in $service.sourceDependencies ) -#if ($dependency.hasStereotype("EntityRef") || $dependency.hasStereotype("ServiceRef")) -#set ($reference = $dependency.targetElement) -#if ($reference.viewType == "local") -#set ($homeInterfaceName = "${reference.name}LocalHome") -#set ($fqHomeInterfaceName = "${reference.fullyQualifiedName}LocalHome") +#**##foreach($constant in $constants) +#* *##if ($constant.visibility == "public") /** - * Get the local home interface of the ${reference.name} bean. - * The home interface is obtained from the initial context - * by looking up the bean reference name. - * @return local home interface for ${reference.name}. + * Get the <code>$constant.name</code> constant +$constant.getDocumentation(" * ") */ - protected static ${fqHomeInterfaceName} get${homeInterfaceName}() - throws javax.naming.NamingException - { - javax.naming.InitialContext initialContext = new javax.naming.InitialContext(); - try - { - // Local homes shouldn't be narrowed, as there is no RMI involved. - ${fqHomeInterfaceName} home = - (${fqHomeInterfaceName}) initialContext.lookup("java:/comp/env/ejb/${reference.name}BeanRef"); - return home; - } - finally + $constant.visibility $constant.type.fullyQualifiedName ${constant.getterName}() { - initialContext.close(); - } + return $constant.name; } + +#* *##end +#**##end #end -#if ($reference.viewType == "remote") -#set ($homeInterfaceName = "${reference.name}Home") -#set ($fqHomeInterfaceName = "${reference.fullyQualifiedName}Home") +#if(!$instanceAttributes.empty) + + // ------- Accessors for Attributes ---------- + +#**##foreach ($attribute in $instanceAttributes) +#* *##set ($visibility = $attribute.visibility) +#* *##if ($visibility == "public") /** - * Get the remote home interface of the ${reference.name} bean. - * The home interface is obtained from the initial context - * by looking up the bean reference name. - * @return remote home interface for ${reference.name}. Lookup using bean ref name. + * Get the ${attribute.name} property +$attribute.getDocumentation(" * ") */ - protected static ${fqHomeInterfaceName} get${homeInterfaceName}() - throws javax.naming.NamingException { - javax.naming.InitialContext initialContext = new javax.naming.InitialContext(); - try - { - Object home = - initialContext.lookup("java:/comp/env/ejb/${reference.name}BeanRef"); - return ($fqHomeInterfaceName) - javax.rmi.PortableRemoteObject.narrow(home, - ${fqHomeInterfaceName}.class); - } - finally +#* *##if ($attribute.transactionType) + @javax.ejb.TransactionAttribute(javax.ejb.TransactionAttributeType.${attribute.transactionType}) +#* *##end + $visibility $attribute.type.fullyQualifiedName ${attribute.getterName}() { - initialContext.close(); - } + return $attribute.name; } -#end -#end -#if ($dependency.hasStereotype("ResourceRef")) -#set ($reference = $dependency.targetElement) -#set ($resClassName = "$referencedClass.fullyQualifiedName}") -#set ($resName = $dependency.name) -#if (!$resName) -#set ($resName = $reference.name) -#end +## Only generate a setter if the attribute is not read-only +#* *##if (!$attribute.readOnly) + /** - * Get the ${resName} resource. - * The resource is obtained by looking up - * <code>java:/comp/env/resource/$resName</code> in JNDI - * @return the ${resName} resource + * Set the $attribute.name property + * @param value the new value */ - protected static ${resClassName} get${stringUtils.capitalize($resName)}() - throws javax.naming.NamingException - { - javax.naming.InitialContext initialContext = - new javax.naming.InitialContext(); - try - { - Object resource = - initialContext.lookup("java:/comp/env/resource/$resName"); - return ($resClassName) resource; - } - finally - { - initialContext.close(); - } - } -#end -#end - - private javax.ejb.SessionContext context; - - public void setSessionContext(javax.ejb.SessionContext ctx) - { - context = ctx; - } - - public void ejbRemove() +#* *##if ($attribute.transactionType) + @javax.ejb.TransactionAttribute(javax.ejb.TransactionAttributeType.${attribute.transactionType}) +#* *##end + $visibility void ${attribute.setterName}($attribute.type.fullyQualifiedName value) { + this.$attribute.name = value; } - public void ejbPassivate() - { - } +#* *##end +#* *##end +#**##end +#end +#set ($operations = $service.businessOperations) +#if (!$operations.empty) + + // -------- Business Methods -------------- + +#**##foreach ($operation in $operations) +#* *##set ($visibility = $operation.visibility) +#* *##if ($visibility == "public") + /** +$operation.getDocumentation(" * ") +## Only public methods have transactions and are exported to the interfaces + */ +#* *##if ($operation.transactionType) + @javax.ejb.TransactionAttribute(javax.ejb.TransactionAttributeType.${operation.transactionType}) +#* *##end +#* *##if ($operation.permitAll) + @javax.annotation.security.PermitAll +#* *##elseif ($operation.rolesAllowed) + @javax.annotation.security.RolesAllowed({${operation.rolesAllowed}}) +#* *##end +#* *##set ($returnType = $operation.returnType.fullyQualifiedName) +#* *##if ($operation.exceptionsPresent) + $visibility abstract $returnType $operation.signature throws $operation.exceptionList; +#* *##else + $visibility abstract $returnType $operation.signature; +#* *##end - public void ejbActivate() - { - } +#* *##end +#**##end +#end } \ No newline at end of file |