From: Vance K. <va...@us...> - 2006-01-10 08:10:06
|
User: vancek Date: 06/01/10 00:09:59 Added: andromda-ejb3/src/main/resources/templates/ejb3 ServiceDelegate.vsl ServiceLocator.vsl Log: initial revision Revision Changes Path 1.1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/ServiceDelegate.vsl Index: ServiceDelegate.vsl =================================================================== // license-header java merge-point #if ($stringUtils.isNotBlank($service.packageName)) package $service.packageName; #end #set ($generatedFile = "${stringUtils.replace($service.fullyQualifiedServiceDelegateName,'.','/')}.java") /** * Web service delegator for {@link $service.fullyQualifiedServiceName}. * * @see $service.fullyQualifiedServiceName */ public class $service.serviceDelegateName { /** * Environment properties */ private java.util.Properties env = null; /** * Default constructor */ public ${service.serviceDelegateName}() { // Null implementation } /** * Constructor setting the envirinment properties. * * @param env */ public ${service.serviceDelegateName}(java.util.Properties env) { this.env = env; } /** * Gets an instance of {@link $service.fullyQualifiedServiceRemoteInterfaceName} */ private final ${service.fullyQualifiedServiceRemoteInterfaceName} get${service.name}() throws javax.naming.NamingException { return ${ejb3TypesPackage}.ServiceLocator.getInstance().get${service.name}(env); } #foreach ($operation in $service.businessOperations) /** * @see ${service.fullyQualifiedServiceName}#${operation.getSignature(false)} */ $operation.visibility $operation.returnType.fullyQualifiedName $operation.signature #**##if ($operation.exceptionsPresent) $operation.throwsClause #**##end { try { #**##if (!$operation.returnTypePresent) get${service.name}().${operation.name}(${operation.argumentNames}); #**##else return get${service.name}().${operation.name}(${operation.argumentNames}); #**##end } #**##if (!$operation.exceptionsPresent) catch (Exception ex) #**##else catch (javax.naming.NamingException ex) #**##end { #**##if ($operation.exceptionsPresent) #* *##foreach ($exception in $operation.exceptions) #* *##if ($velocityCount == 1) throw new ${exception.fullyQualifiedName}(ex); #* *##end #* *##end #**##else ex.printStackTrace(); #**##end } } #end /** * Close down service delegate resources */ public void close() { ${ejb3TypesPackage}.ServiceLocator.getInstance().shutdown(); } } 1.1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/ServiceLocator.vsl Index: ServiceLocator.vsl =================================================================== // license-header java merge-point #set ($generatedFile = "${serviceLocatorName}.java") #if($stringUtils.isNotEmpty($ejb3TypesPackage)) package $ejb3TypesPackage; #**##set ($generatedFile = "${stringUtils.replace($ejb3TypesPackage,'.','/')}/${generatedFile}") #end /** * Locates and provides all available application services. */ public class $serviceLocatorName { /** * The shared instance of this ${serviceLocatorName}. */ private static ${serviceLocatorName} instance; /** * The Context to lookup the service beans. */ protected javax.naming.InitialContext context = null; /** * Private constructor */ private ${serviceLocatorName}() { // shouldn't be instantiated } /** * Gets the instance of this Class. Create it if doesn't already exit, otherwise * return the current instance. * * @return the shared service locator instance. */ public final static $serviceLocatorName getInstance() { if (instance == null) { instance = new ${serviceLocatorName}(); } return instance; } /** * Gets the InitialContext. * * @param env the Context environment properties. * @return the javax.naming.InitialContext. * @throws javax.naming.NamingException failure to create InitialContext */ protected synchronized javax.naming.InitialContext getContext(java.util.Properties env) throws javax.naming.NamingException { if (this.context == null) { this.context = new javax.naming.InitialContext(env); } return this.context; } /** * Instantiate a new InitialContext using the properties table. * * @param env passed to the InitialContext constructor. * @return the javax.naming.InitialContext. * @throws javax.naming.NamingException failure to create InitialContext */ protected synchronized javax.naming.InitialContext newContext(java.util.Properties env) throws javax.naming.NamingException { this.context = new javax.naming.InitialContext(env); return this.context; } /** * Shuts down the ServiceLocator and releases any used resources. */ public synchronized void shutdown() { if (this.context != null) { try { this.context.close(); } catch (javax.naming.NamingException ne) { // ignore } finally { this.context = null; } } } #foreach ($service in $services) /** * Gets an instance of {@link $service.fullyQualifiedServiceRemoteName}. * * @param env the Context environment properties. Null represents no properties. * @throws javax.naming.NamingException failure to lookup remote service interface. */ public final $service.fullyQualifiedServiceRemoteInterfaceName get${service.name}(java.util.Properties env) throws javax.naming.NamingException { return (${service.fullyQualifiedServiceRemoteInterfaceName}) getContext(env).lookup(${service.fullyQualifiedServiceRemoteInterfaceName}.class.getName()); } #end /** * Gets an instance of the given service. * * @param serviceName lookup this service from the context. * @throws javax.naming.NamingException failure to lookup remote service interface. */ public final Object getService(String serviceName) throws javax.naming.NamingException { return getService(serviceName, null); } /** * Gets an instance of the given service. * * @param serviceName lookup this service from the context. * @param env the Context environment properties. Null represents no properties. * @throws javax.naming.NamingException failure to lookup remote service interface. */ public final Object getService(String serviceName, java.util.Properties env) throws javax.naming.NamingException { return getContext(env).lookup(serviceName); } } |