|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.nuiton.eugene.Template<I>
org.nuiton.eugene.Transformer<org.nuiton.eugene.models.object.ObjectModel,O>
org.nuiton.eugene.models.object.ObjectModelTransformer<org.nuiton.eugene.models.object.ObjectModel>
org.nuiton.eugene.java.ObjectModelTransformerToJava
org.nuiton.topia.generator.ServiceTransformer
public class ServiceTransformer
This Template is used to create the skeleton of services for a final application which using Topia.
AppContextImplementor : interface which extends AppContext to add technical methods for the application. Generation of methods :
* doCatch : used to catch all exception from a service method.
* doFinally : used to finally the try/catch of a service method
* beginTransaction : start the transaction using rootContext.
These three methods have to be implemented in a class which implements AppContextImplementor (ex : AppContextImpl). You can also add others methods to AppContextImplementor in the same way as AppContext.
ServiceAbstract : abstract class which contains :
* constructor with AppContextImplementor in argument
* for each method : the implementation of the method (skeleton with try/catch and beginTransaction call to open a new TopiaContext from AppContextImplementor). Usage of i18n keys for error messages in exception.
* for each method : an abstract method used to execute the business code of the method : need to be implemented in subclass.
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;
}
...
}
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.
}
}
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).
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
| 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 |
|---|
protected String modelName
protected String defaultPackageName
| Constructor Detail |
|---|
public ServiceTransformer()
| Method Detail |
|---|
protected String getContextInterfaceName()
protected String getContextImplementorInterfaceName()
protected String getExceptionClassName()
protected String getServiceAbstractClassName(String serviceName)
public void transformFromModel(org.nuiton.eugene.models.object.ObjectModel model)
transformFromModel in class org.nuiton.eugene.models.object.ObjectModelTransformer<org.nuiton.eugene.models.object.ObjectModel>protected org.nuiton.eugene.models.object.ObjectModelClass createExceptionClass()
protected void copyInterfaceOperations(org.nuiton.eugene.models.object.ObjectModelInterface source,
org.nuiton.eugene.models.object.ObjectModelInterface dest)
source interface signature to the
dest interface.
source - interfacedest - interfacepublic void transformFromInterface(org.nuiton.eugene.models.object.ObjectModelInterface interfacez)
transformFromInterface in class org.nuiton.eugene.models.object.ObjectModelTransformer<org.nuiton.eugene.models.object.ObjectModel>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||