org.nuiton.topia.generator
Class ServiceTransformer

java.lang.Object
  extended by org.nuiton.eugene.Template<I>
      extended by org.nuiton.eugene.Transformer<org.nuiton.eugene.models.object.ObjectModel,O>
          extended by org.nuiton.eugene.models.object.ObjectModelTransformer<org.nuiton.eugene.models.object.ObjectModel>
              extended by org.nuiton.eugene.java.ObjectModelTransformerToJava
                  extended by org.nuiton.topia.generator.ServiceTransformer

public class ServiceTransformer
extends org.nuiton.eugene.java.ObjectModelTransformerToJava

This Template is used to create the skeleton of services for a final application which using Topia.

Generation from a model named 'App' :
Generation from interfaces with stereotype <<service>> :
Exemple of AppContextImpl :
   public class AppContextImpl implements AppContextImplementor {

      // properties for Topia configuration
      protected Properties properties;
      ...
 
      @Override
      public void doCatch(TopiaContext transaction, Exception eee, 
              String message, Object... args) throws AppException {

          // Note that the message from service doesn't directly use _() for
          // i18 messages but n_(). In this log, the _() is used to translate
          // correctly the message. But the message must be translate when
          // catching the AppException in UI.
          if (log.isErrorEnabled()) {
              log.error(_(message, args), eee);
          }

          // rollback of current transaction
          if (transaction != null) {
              try {
                  transaction.rollbackTransaction();
              } catch (TopiaException ex) {
                  if (log.isErrorEnabled()) {
                      log.error(_("app.error.context.rollback"), ex);
                  }
              }
          }
          // wrapping the exception in a AppException with message and
          // arguments for i18n translation
          throw new AppException(eee, message, args);
      }

      @Override
      public void doFinally(TopiaContext transaction) {
          if (transaction != null) {
              try {
                  transaction.closeContext();
              } catch (TopiaException eee) {
                  if (log.isErrorEnabled()) {
                      log.error(_("app.error.context.close"), eee);
                  }
              }
          }
      }

      @Override
      public TopiaContext beginTransaction() throws TopiaException {
          TopiaContext rootContext = null;
          try {
              // You have to manage the properties using ApplicationConfig
              // or other lib to have configuration for Topia
              rootContext = TopiaContextFactory.getContext(properties);

              return getTopiaRootContext().beginTransaction();

          // only catch exception for rootContext
          } catch (TopiaNotFoundException eee) {
              doCatch(eee, n_("app.error.context.getTopiaRootContext"));
          }
          return null;
      }
      ...
  }
 
Exemple of ServiceImpl :
 public class ServiceImpl extends ServiceAbstract {

      public ServiceImpl(AppContextImplementor context) {
          super(context);
      }

      // Implementation of abstract method, the interface method is
      // called 'createMyEntity(MyEntity entity)' in this case.
      @Override
      public void executeCreateMyEntity(TopiaContext transaction, 
                      MyEntity entity) throws TopiaException {

          MyEntityDAO dao = AppDAOHelper.getMyEntityDAO(transaction);
          dao.create(entity);
          // That's it, no need to manage errors or transaction, the abstract
          // service will do this job.
      }
 }
 

TAG_TRANSACTION

You can use the tagValue 'transaction=false' to specify that a method doesn't need any TopiaContext, so no need to instantiate a new one. This tagValue can only be put directly in the model and not in properties file (because of multiple methods with same name problem).

TAG_ERROR_ARGS

You can use the tagValue 'errorArgs=false' to specify that a method doesn't need any arguments for error message. This tagValue can only be put directly in the model and not in properties file.

It is smooth, isn't it :p ?

TODO : may be refactor to integrate JTA or webservice or may be not in this transformer.

TODO : find a good way to change log level

Created: 23 mars 2010

Version:
$Revision: 1862 $ Mise a jour: $Date: 2010-03-31 10:27:58 +0200 (mer. 31 mars 2010) $ par : $Author$
Author:
fdesbois

Field Summary
protected  String defaultPackageName
           
protected  String modelName
           
 
Fields inherited from class org.nuiton.eugene.java.ObjectModelTransformerToJava
builder
 
Fields inherited from class org.nuiton.eugene.Transformer
outputModel, outputProperties, outputTemplate, previousTransformer
 
Fields inherited from class org.nuiton.eugene.Template
excludeTemplates, generatedPackages, model, PROP_DEFAULT_PACKAGE, PROP_ENCODING, PROP_EXCLUDE_TEMPLATES, PROP_GENERATED_PACKAGES, PROP_LAST_MODIFIED_SOURCE, PROP_OVERWRITE, properties
 
Constructor Summary
ServiceTransformer()
           
 
Method Summary
protected  void copyInterfaceOperations(org.nuiton.eugene.models.object.ObjectModelInterface source, org.nuiton.eugene.models.object.ObjectModelInterface dest)
          Used to simply copy the source interface signature to the dest interface.
protected  org.nuiton.eugene.models.object.ObjectModelClass createExceptionClass()
           
protected  String getContextImplementorInterfaceName()
           
protected  String getContextInterfaceName()
           
protected  String getExceptionClassName()
           
protected  String getServiceAbstractClassName(String serviceName)
           
 void transformFromInterface(org.nuiton.eugene.models.object.ObjectModelInterface interfacez)
           
 void transformFromModel(org.nuiton.eugene.models.object.ObjectModel model)
           
 
Methods inherited from class org.nuiton.eugene.java.ObjectModelTransformerToJava
addAnnotation, addAttribute, addAttribute, addAttribute, addAttribute, addBlock, addConstant, addConstant, addConstructor, addConstructor, addException, addException, addImport, addImport, addImport, addInnerClassifier, addInterface, addInterface, addLiteral, addOperation, addOperation, addParameter, addParameter, createAbstractClass, createClass, createEnumeration, createInterface, debugOutputModel, getConstantName, initOutputModel, initOutputTemplate, setDocumentation, setOperationBody, setSuperClass, setSuperClass
 
Methods inherited from class org.nuiton.eugene.models.object.ObjectModelTransformer
transform, transformFromClass, transformFromClassifier, transformFromElement, transformFromEnumeration
 
Methods inherited from class org.nuiton.eugene.Transformer
applyTemplate, generate, getOutputModel, getOutputProperties, getOutputTemplate, init, initPreviousTransformer, setProperties, transform
 
Methods inherited from class org.nuiton.eugene.Template
getEncoding, getExcludeTemplates, getGeneratedPackages, getLastModifiedSource, getModel, getOverwrite, getProperty, setEncoding, setExcludeTemplates, setGeneratedPackages, setLastModifiedSource, setOverwrite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modelName

protected String modelName

defaultPackageName

protected String defaultPackageName
Constructor Detail

ServiceTransformer

public ServiceTransformer()
Method Detail

getContextInterfaceName

protected String getContextInterfaceName()

getContextImplementorInterfaceName

protected String getContextImplementorInterfaceName()

getExceptionClassName

protected String getExceptionClassName()

getServiceAbstractClassName

protected String getServiceAbstractClassName(String serviceName)

transformFromModel

public void transformFromModel(org.nuiton.eugene.models.object.ObjectModel model)
Overrides:
transformFromModel in class org.nuiton.eugene.models.object.ObjectModelTransformer<org.nuiton.eugene.models.object.ObjectModel>

createExceptionClass

protected org.nuiton.eugene.models.object.ObjectModelClass createExceptionClass()

copyInterfaceOperations

protected void copyInterfaceOperations(org.nuiton.eugene.models.object.ObjectModelInterface source,
                                       org.nuiton.eugene.models.object.ObjectModelInterface dest)
Used to simply copy the source interface signature to the dest interface.

Parameters:
source - interface
dest - interface

transformFromInterface

public void transformFromInterface(org.nuiton.eugene.models.object.ObjectModelInterface interfacez)
Overrides:
transformFromInterface in class org.nuiton.eugene.models.object.ObjectModelTransformer<org.nuiton.eugene.models.object.ObjectModel>


Copyright © 2004-2010 CodeLutin. All Rights Reserved.