[ http://jira.andromda.org/browse/EJB-23?page=history ]
Raj Subramani updated EJB-23: ----------------------------- Attachment: SessionBean.vsl This SessionBean.vsl attachment has all the modifications (3 in total) that I reported with regards to this issue. > EnvEntry does not work properly > ------------------------------- > > Key: EJB-23 > URL: http://jira.andromda.org/browse/EJB-23 > Project: EJB Cartridge > Type: Bug > Environment: All platforms > Reporter: Raj Subramani > Assignee: Chad Brandon > Attachments: SessionBean.vsl > > I have logged the bugs that need fixing (3 in total) and hope you or anyone > else maintaing this module will be able to incorporate my fixes. > The following entry in SessionBean.vsl in andromda-ejb-cartridge-3.*.jar > (line 94 to line 147) > Code: > line 94 // -- accessors for environment entries -- > line 95 #foreach($envEntry in $service.getEnvironmentEntries(true)) > line 96 /** > line 97 * Get <em>${envEntry.name}</em> environment entry. > line 98 $envEntry.getDocumentation(" * ") > line 99 * > line100 ## Only expose the method to the component interface if it is > public. > line101 #if($visibility == "public") > line102 * @ejb.interface-method > line103 #end > line104 */ > line105 $visibility $envEntry.type.fullyQualifiedName > ${attribute.getterName}() > line106 { > line107 javax.naming.InitialContext initialContext = null; > line108 try > line109 { > line110 initialContext = new javax.naming.InitialContext(); > line111 return (${envEntry.type.fullyQualifiedName}) line112 > initialContext.lookup("java:comp/env/$envEntry.name"); > line113 } > line114 catch (javax.naming.NamingException cause) > line115 { > line116 RuntimeException ex = new IllegalStateException( > line117 "Cannot access environment entry > \"$envEntry.name\"."); > line118 // In order to set the exception cause on JDK 1.4 > line119 // and stay JDK 1.3 compatible nonetheless, we need > line120 // a bit of reflection magic here... > line121 try > line122 { > line123 java.lang.reflect.Method initCause = > line124 ex.getClass().getMethod("initCause", > new Class[] {Throwable.class}); > line125 initCause.invoke(ex, new Object[] { cause }); > line126 } > line127 catch (Throwable t) > line128 { > line129 // Ignore any errors here - we simply make do > without the cause > line130 } > line131 throw ex; > line132 } > line133 finally > line134 { > line135 try > line136 { > line137 if (initialContext != null) > line138 { > line139 initialContext.close(); > line140 } > line141 } > line142 catch (javax.naming.NamingException ignore) > line143 { > line144 // Silently ignore naming exceptions at cleanup > time > line145 } > line146 } > line147 #end > has the following bugs: > 1. > Error > ----- > $visibility in line 101 is not set > Fix > --- > Add the line > Code: > #set ($visibility = $envEntry.visibility) > 2. > Error > ----- > $visibility $envEntry.type.fullyQualifiedName ${attribute.getterName}(), line > 105, is incorrect > Fix > --- > Replace with the line > Code: > $visibility $envEntry.type.fullyQualifiedName ${envEntry.getterName}() > 3. > Error > ----- > Closing brace before #end in line 147 is missing > Fix > --- > Replace line 146 and line 147 with the following 3 lines > Code: > } > } > #end > I have only one observation to make and wish some feedback. The ServiceBean > and the Local and Remote interfaces have getter methods for each of the env > entries but these methods do not exist in ServiceBeanImpl.java. Now either, > the ServiceBean.java must declare these methods as abstract and the > implementation moved to ServiceBeanImpl.java, or, the Remote and Local > interfaces should not generate the getter methods (I prefer the latter, which > would mean that the SessionRemote.vsl and SessionLocal.vsl also have to be > modified, someone please comment?). > The new SessionBean.vsl now looks as follows: > Code: > // license-header java merge-point > /* Autogenerated by AndroMDA (SessionBean.vsl) - do not edit */ > #if ($stringUtils.isNotBlank($service.packageName)) > package $service.packageName; > #end > /** > * Autogenerated EJB implementation class for the $service.name 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" > * > * @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" > * > * @weblogic.resource-description > * res-ref-name= "resource/$resName" > * jndi-name= "$jndiRef" > * > * @websphere.bean > #end > #end > #end > */ > public abstract class ${service.name}Bean > #if($service.generalization) > extends ${service.generalization.fullyQualifiedName}BeanImpl > #end > implements javax.ejb.SessionBean > { > // ----------- constant definitions ----------- > #foreach($constant in $service.getConstants(true)) > private static final $constant.type.fullyQualifiedName $constant.name = > $constant.defaultValue; > #end > // -- 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 > // -- accessors for constants -- > #foreach($constant in $service.getConstants(true)) > /** > * 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") > /** > * Home interface method for accessing [EMAIL PROTECTED] > #${attribute.getterName}}. > * @ejb.home-method > * @see #${constant.getterName} > */ > public $constant.type.fullyQualifiedName ejbHomeGet${constant.name}() > { > return ${constant.getterName}; > } > #end > #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; > /** > * 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; > } > ## 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 > #end > #end > // ---------------- business methods ---------------------- > #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 > */ > #set ($returnType = $operation.returnType.fullyQualifiedName) > #if ($operation.exceptionsPresent) > $visibility abstract $returnType $operation.signature throws > $operation.exceptionList; > #else > $visibility abstract $returnType $operation.signature; > #end > #end > // ---------------- 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)) > /** > $operation.getDocumentation(" * ") > * > * @ejb.create-method > */ > public abstract void ejbCreate($operation.typedArgumentList); > public void ejbPostCreate($operation.typedArgumentList) > { > } > #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 > { > } > public void ejbPostCreate() throws javax.ejb.CreateException > { > } > ## 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) > * @param $attribute.name Value for the ${attribute.name} property > #end > * @ejb.create-method > */ > public void ejbCreate($transform.getAttributesAsList($allAttributes, > true, true)) > throws javax.ejb.CreateException > { > #if(!$inheritedAttributes.empty) > // Call ejbCreate method for the super type > super.ejbCreate($transform.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 > // ---------------- accessor methods for bean references --------------- > #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") > /** > * 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}. > */ > 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 > { > initialContext.close(); > } > } > #end > #if ($reference.viewType == "remote") > #set ($homeInterfaceName = "${reference.name}Home") > #set ($fqHomeInterfaceName = "${reference.fullyQualifiedName}Home") > /** > * 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. > */ > 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 > { > initialContext.close(); > } > } > #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 > /** > * Get the ${resName} resource. > * The resource is obtained by looking up > * <code>java:/comp/env/resource/$resName</code> in JNDI > * @return the ${resName} resource > */ > 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() > { > } > public void ejbPassivate() > { > } > public void ejbActivate() > { > } > } > Cheers > -raj ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl