|
||||||||||
| 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.
ServiceAbstract : abstract class which contains :
* treateError : abstract method used to catch all exception from a service method.
* closeTransaction : abstract method used to finally the try/catch of a service method
* beginTransaction : abstract method used to start the transaction using rootContext.
* 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 ServiceImpl implements ServiceAbstract {
// properties for Topia configuration
protected Properties properties;
...
@Override
public void treateError(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 closeTransaction(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) {
treateError(eee, n_("app.error.context.getTopiaRootContext"));
}
return null;
}
// 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.
}
}
Default value : true
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).
Default value : false
You can use the tagValue 'errorArgs=true' to specify that a method need arguments for error message. This tagValue can only be put directly in the model and not in properties file.
Default value : null
You can use the tagValue 'exceptionClass=my.exception.full.qualified.Name' to specify that all contract methods will throw this exception.
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
|
| Nested Class Summary | |
|---|---|
protected static class |
ServiceTransformer.Primitive
|
| Field Summary | |
|---|---|
protected String |
defaultPackageName
|
protected String |
exceptionName
|
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 |
|---|
configuration, excludeTemplates, generatedPackages, model |
| Fields inherited from interface org.nuiton.eugene.TemplateConfiguration |
|---|
PROP_CLASS_LOADER, PROP_DEFAULT_PACKAGE, PROP_ENCODING, PROP_EXCLUDE_TEMPLATES, PROP_GENERATED_PACKAGES, PROP_LAST_MODIFIED_SOURCE, PROP_OVERWRITE, PROP_VERBOSE, PROP_WRITER_REPORT |
| Constructor Summary | |
|---|---|
ServiceTransformer()
|
|
| Method Summary | |
|---|---|
protected org.nuiton.eugene.models.object.ObjectModelOperation |
createOperationExecuteAbstract(org.nuiton.eugene.models.object.ObjectModelClass serviceAbstract,
org.nuiton.eugene.models.object.ObjectModelOperation source)
Create an operation abstract to execute in contract implementation. |
protected void |
createOperationImplementation(org.nuiton.eugene.models.object.ObjectModelClass serviceAbstract,
org.nuiton.eugene.models.object.ObjectModelOperation abstOp,
org.nuiton.eugene.models.object.ObjectModelOperation source,
String serviceContractName)
Create an operation implementation. |
protected void |
createServiceAbstract(org.nuiton.eugene.models.object.ObjectModelInterface source,
org.nuiton.eugene.models.object.ObjectModelInterface serviceContract)
Create the service abstract for serviceContract
using source interface defined
in model. |
protected org.nuiton.eugene.models.object.ObjectModelInterface |
createServiceContract(org.nuiton.eugene.models.object.ObjectModelInterface source)
Create the service contract using source interface defined
in model. |
protected String |
getAbstractOperationKeyMap(org.nuiton.eugene.models.object.ObjectModelOperation op)
Create a key for the abstractOperations map from op. |
protected String |
getReturnValue(String returnType)
This method give the return string for an operation returnType. |
protected String |
getServiceAbstractClassName(String serviceName)
|
protected boolean |
isErrorArgsNeeded(org.nuiton.eugene.models.object.ObjectModelOperation op)
boolean to specify if the method need error arguments or not Default set to false but can be override using a tagvalue "errorArgs" on the method from model. |
protected boolean |
isTransactionNeeded(org.nuiton.eugene.models.object.ObjectModelOperation op)
boolean to specify if the method need a transaction or not. |
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, addConstantsFromDependency, addConstructor, addConstructor, addException, addException, addImport, addImport, addImport, addInnerClassifier, addInterface, addInterface, addLiteral, addOperation, addOperation, addParameter, addParameter, cloneOperationSignature, createAbstractClass, createClass, createEnumeration, createInterface, debugOutputModel, getConstantName, getConstantPrefix, getConstantPrefix, getFileInClassPath, initConstantPrefixFromModel, initOutputModel, initOutputTemplate, setConstantPrefix, 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, getOutputModel, getOutputProperties, getOutputTemplate, init, initPreviousTransformer, setProperties, transform |
| Methods inherited from class org.nuiton.eugene.Template |
|---|
getClassLoader, getConfiguration, getEncoding, getExcludeTemplates, getGeneratedPackages, getLastModifiedSource, getModel, getOverwrite, getProperties, getProperty, getProperty, getWriterReport, isOverwrite, isVerbose, setConfiguration, setProperty |
| 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
protected String exceptionName
| Constructor Detail |
|---|
public ServiceTransformer()
| Method Detail |
|---|
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>public void transformFromInterface(org.nuiton.eugene.models.object.ObjectModelInterface interfacez)
transformFromInterface in class org.nuiton.eugene.models.object.ObjectModelTransformer<org.nuiton.eugene.models.object.ObjectModel>protected org.nuiton.eugene.models.object.ObjectModelInterface createServiceContract(org.nuiton.eugene.models.object.ObjectModelInterface source)
source interface defined
in model.
source - interface from model
protected void createServiceAbstract(org.nuiton.eugene.models.object.ObjectModelInterface source,
org.nuiton.eugene.models.object.ObjectModelInterface serviceContract)
serviceContract
using source interface defined
in model.
source - interface from modelserviceContract - to implementprotected String getAbstractOperationKeyMap(org.nuiton.eugene.models.object.ObjectModelOperation op)
op. Concat
opName + params as String.
op - used as reference to construct the keyMap
protected org.nuiton.eugene.models.object.ObjectModelOperation createOperationExecuteAbstract(org.nuiton.eugene.models.object.ObjectModelClass serviceAbstract,
org.nuiton.eugene.models.object.ObjectModelOperation source)
serviceAbstract - where the operation will be createdsource - ObjectModelOperation from model
isErrorArgsNeeded(ObjectModelOperation),
isTransactionNeeded(ObjectModelOperation)
protected void createOperationImplementation(org.nuiton.eugene.models.object.ObjectModelClass serviceAbstract,
org.nuiton.eugene.models.object.ObjectModelOperation abstOp,
org.nuiton.eugene.models.object.ObjectModelOperation source,
String serviceContractName)
abstOp. You can use tagvalues "errorArgs" and
"transaction" for abstract method parameters to call. If the transaction
is needed, this will use the beginTransaction() and closeTransaction()
methods defined in serviceAbstract class.
serviceAbstract - where the operation will be createdabstOp - to execute into the implementation bodysource - ObjectModelOperation from modelserviceContractName - where the signature method is definedisErrorArgsNeeded(ObjectModelOperation),
isTransactionNeeded(ObjectModelOperation)protected boolean isTransactionNeeded(org.nuiton.eugene.models.object.ObjectModelOperation op)
op - where the tagvalue is set
protected boolean isErrorArgsNeeded(org.nuiton.eugene.models.object.ObjectModelOperation op)
op - where the tagvalue is set
protected String getReturnValue(String returnType)
returnType.
This use ServiceTransformer.Primitive enum to provide default values for primitive
type. For all other object type, this method will return null.
returnType -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||