Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- 4806 discussions
r1871 - in trunk: . topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesboisï¼ users.nuiton.org 02 Apr '10
by fdesboisï¼ users.nuiton.org 02 Apr '10
02 Apr '10
Author: fdesbois
Date: 2010-04-02 17:44:28 +0200 (Fri, 02 Apr 2010)
New Revision: 1871
Log:
Evo #439 : don't generate context and exception class + clean methods, abstract order and add javadoc
Modified:
trunk/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-04-02 09:19:54 UTC (rev 1870)
+++ trunk/pom.xml 2010-04-02 15:44:28 UTC (rev 1871)
@@ -190,7 +190,7 @@
<eugene.version>2.0</eugene.version>
<lutinutil.version>1.2</lutinutil.version>
<processor.version>1.0.3</processor.version>
- <i18n.version>1.2</i18n.version>
+ <i18n.version>1.2.1-SNAPSHOT</i18n.version>
<xmlrpc.version>3.1.2</xmlrpc.version>
<hibernate.version>3.3.2.GA</hibernate.version>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-02 09:19:54 UTC (rev 1870)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-02 15:44:28 UTC (rev 1871)
@@ -2,12 +2,13 @@
package org.nuiton.topia.generator;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.Template;
import org.nuiton.eugene.java.ObjectModelTransformerToJava;
import org.nuiton.eugene.models.object.ObjectModel;
import org.nuiton.eugene.models.object.ObjectModelClass;
@@ -27,33 +28,16 @@
* This Template is used to create the skeleton of services for a final
* application which using Topia.
* <div>
- * Generation from a model named 'App' :
- * <ul>
- * <li>AppContext : empty super interface to used in application UI. Can
- * be override in model if put in defaultPackage (ex : org.chorem.app) set
- * in maven-eugene-plugin configuration.
- * </li>
- * <li><p>AppContextImplementor : interface which extends AppContext to add
- * technical methods for the application. Generation of methods :</p>
- * <p>* doCatch : used to catch all exception from a service method.</p>
- * <p>* doFinally : used to finally the try/catch of a service method</p>
- * <p>* beginTransaction : start the transaction using rootContext.</p>
- * <p>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.</p>
- * </li>
- * <li>AppException : exception class which extends RuntimeException for all
- * technical exceptions which appears in service method. If you want to
- * manage some specific exceptions, you have to managed them in doCatch
- * implementation.
- * </li>
- * </ul>
- * </div>
- * <div>
* Generation from interfaces with stereotype <<service>> :
* <ul>
* <li>Service : interface of the service defined in model.</li>
* <li><p>ServiceAbstract : abstract class which contains :</p>
+ * <p>* treateError : abstract method used to catch all exception from a
+ * service method.</p>
+ * <p>* closeTransaction : abstract method used to finally the try/catch
+ * of a service method</p>
+ * <p>* beginTransaction : abstract method used to start the transaction
+ * using rootContext.</p>
* <p>* constructor with AppContextImplementor in argument</p>
* <p>* for each method : the implementation of the method (skeleton with
* try/catch and beginTransaction call to open a new TopiaContext from
@@ -65,9 +49,10 @@
* </ul>
* </div>
* <div>
- * Exemple of AppContextImpl :<br />
+ * Exemple of ServiceImpl utils method implementation. (The AppException
+ * is considered if defined in model tagvalue "exceptionClass") : <br />
* <pre>
- * public class AppContextImpl implements AppContextImplementor {
+ * public class ServiceImpl implements ServiceAbstract {
*
* // properties for Topia configuration
* protected Properties properties;
@@ -129,19 +114,7 @@
* }
* return null;
* }
- * ...
- * }
- * </pre>
- * </div>
- * <div>
- * Exemple of ServiceImpl :<br />
- * <pre>
- * 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
@@ -170,6 +143,12 @@
* need arguments for error message. This tagValue can only be put directly
* in the model and not in properties file.</p>
* </div>
+ * <div>
+ * <h2>TAG_EXCEPTION_CLASS</h2>
+ * <p>Default value : null</p>
+ * <p>You can use the tagValue 'exceptionClass=my.exception.full.qualified.Name'
+ * to specify that all contract methods will throw this exception.</p>
+ * </div>
* <p>It is smooth, isn't it :p ?</p>
* <p>TODO : may be refactor to integrate JTA or webservice or may be not in this
* transformer.</p>
@@ -189,149 +168,67 @@
protected String defaultPackageName;
- protected String getContextInterfaceName() {
- return StringUtils.capitalize(modelName) + "Context";
- }
+ protected String exceptionName;
- protected String getContextImplementorInterfaceName() {
- return getContextInterfaceName() + "Implementor";
- }
+ private static final String OP_NAME_BEGIN_TRANSACTION = "beginTransaction";
- protected String getExceptionClassName() {
- return StringUtils.capitalize(modelName) + "Exception";
- }
+ private static final String OP_NAME_CLOSE_TRANSACTION = "closeTransaction";
+ private static final String OP_NAME_TREATE_ERROR = "treateError";
+
+// protected String getContextInterfaceName() {
+// return StringUtils.capitalize(modelName) + "Context";
+// }
+//
+// protected String getContextImplementorInterfaceName() {
+// return getContextInterfaceName() + "Implementor";
+// }
+//
+// protected String getExceptionClassName() {
+// return StringUtils.capitalize(modelName) + "Exception";
+// }
+
protected String getServiceAbstractClassName(String serviceName) {
return serviceName + "Abstract";
}
@Override
public void transformFromModel(ObjectModel model) {
+ exceptionName =
+ model.getTagValue(TopiaGeneratorUtil.TAG_EXCEPTION_CLASS);
modelName = model.getName();
- defaultPackageName = getOutputProperties().
- getProperty(Template.PROP_DEFAULT_PACKAGE);
+ }
- ObjectModelInterface contextImplementor =
- model.getInterface(defaultPackageName + "." +
- getContextImplementorInterfaceName());
-
- ObjectModelInterface context =
- model.getInterface(defaultPackageName + "." +
- getContextInterfaceName());
-
- ObjectModelClass exception = createExceptionClass();
-
- ObjectModelInterface newContextImplementor =
- createInterface(getContextImplementorInterfaceName(),
- defaultPackageName);
- ObjectModelInterface newContext =
- createInterface(getContextInterfaceName(),
- defaultPackageName);
-
- addInterface(newContextImplementor,
- newContext.getQualifiedName());
-
- if (contextImplementor != null) {
- // Copy of defined operations
- // interfaces of contextImplementor are not copied
- copyInterfaceOperations(
- contextImplementor, newContextImplementor, false);
- }
-
- if (context != null) {
- // Copy of defined operations
- // interfaces of context are not copied
- copyInterfaceOperations(context, newContext, false);
+ @Override
+ public void transformFromInterface(ObjectModelInterface interfacez) {
+ if (!interfacez.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_SERVICE)) {
+ return;
}
- ObjectModelOperation beginTransaction =
- addOperation(newContextImplementor,
- "beginTransaction", TopiaContext.class);
- addException(beginTransaction, TopiaException.class);
+ ObjectModelInterface serviceContract =
+ createServiceContract(interfacez);
- ObjectModelOperation doCatch1 =
- addOperation(newContextImplementor, "treateError", "void");
- addParameter(doCatch1, Exception.class, "eee");
- addParameter(doCatch1, String.class, "message");
- addParameter(doCatch1, "Object...", "args");
- addException(doCatch1, exception.getQualifiedName());
-
- ObjectModelOperation doCatch2 =
- addOperation(newContextImplementor, "treateError", "void");
- addParameter(doCatch2, TopiaContext.class, "transaction");
- addParameter(doCatch2, Exception.class, "eee");
- addParameter(doCatch2, String.class, "message");
- addParameter(doCatch2, "Object...", "args");
- addException(doCatch2, exception.getQualifiedName());
-
- ObjectModelOperation doFinally =
- addOperation(newContextImplementor, "closeTransaction", "void");
- addParameter(doFinally, TopiaContext.class, "transaction");
+ createServiceAbstract(interfacez, serviceContract);
}
- protected ObjectModelClass createExceptionClass() {
-
- ObjectModelClass exception =
- createClass(getExceptionClassName(), defaultPackageName);
-
- setSuperClass(exception, RuntimeException.class);
- addAttribute(exception, "args", "Object[]", null,
- ObjectModelModifier.PROTECTED);
-
- ObjectModelOperation constructor =
- addConstructor(exception, ObjectModelModifier.PUBLIC);
-
- addParameter(constructor, Throwable.class, "eee");
- addParameter(constructor, String.class, "message");
- addParameter(constructor, "Object...", "args");
-
- setOperationBody(constructor, ""
- /*{
- super(message, eee);
- this.args = args;
- }*/
- );
-
- ObjectModelOperation getArgs =
- addOperation(exception, "getArgs", "Object[]",
- ObjectModelModifier.PUBLIC);
-
- setOperationBody(getArgs, ""
- /*{
- return args;
- }*/
- );
-
- ObjectModelOperation hasArgs =
- addOperation(exception, "hasArgs", "boolean",
- ObjectModelModifier.PUBLIC);
-
- setOperationBody(hasArgs, ""
- /*{
- return args.length > 0;
- }*/
- );
-
- return exception;
- }
-
/**
- * Used to simply copy the {@code source} interface signature to the
- * {@code dest} interface.
+ * Create the service contract using {@code source} interface defined
+ * in model.
*
- * @param source interface
- * @param dest interface
- * @param throwException if generated exception is thrown
+ * @param source interface from model
+ * @return the ObjectModelInterface created
*/
- protected void copyInterfaceOperations(ObjectModelInterface source,
- ObjectModelInterface dest, boolean throwException) {
- setDocumentation(dest, source.getDocumentation());
- if (throwException) {
- addImport(dest, defaultPackageName + "." + getExceptionClassName());
- }
+ protected ObjectModelInterface createServiceContract(
+ ObjectModelInterface source) {
+
+ ObjectModelInterface serviceContract =
+ createInterface(source.getName(),
+ source.getPackageName());
+
+ setDocumentation(serviceContract, source.getDocumentation());
for (ObjectModelOperation op : source.getOperations()) {
ObjectModelOperation newOp =
- addOperation(dest,
+ addOperation(serviceContract,
op.getName(), op.getReturnType());
setDocumentation(newOp.getReturnParameter(),
op.getReturnParameter().getDocumentation());
@@ -344,36 +241,33 @@
for (String ex : op.getExceptions()) {
addException(newOp, ex);
}
- if (throwException) {
- addException(newOp, getExceptionClassName());
+ if (exceptionName != null) {
+ addException(newOp, exceptionName);
}
setDocumentation(newOp, op.getDocumentation());
}
+ return serviceContract;
}
- @Override
- public void transformFromInterface(ObjectModelInterface interfacez) {
- // skip ContextImplementor and Context interfaces
- if (!interfacez.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_SERVICE)) {
- return;
- }
+ /**
+ * Create the service abstract for {@code serviceContract}
+ * using {@code source} interface defined
+ * in model.
+ *
+ * @param source interface from model
+ * @param serviceContract to implement
+ */
+ protected void createServiceAbstract(ObjectModelInterface source,
+ ObjectModelInterface serviceContract) {
- // Create INTERFACE
- ObjectModelInterface serviceInterface =
- createInterface(interfacez.getName(),
- interfacez.getPackageName());
+ ObjectModelClass serviceAbstract = createAbstractClass(
+ getServiceAbstractClassName(serviceContract.getName()),
+ serviceContract.getPackageName());
- copyInterfaceOperations(interfacez, serviceInterface, true);
+ // Implements contract interface
+ addInterface(serviceAbstract, serviceContract.getQualifiedName());
-
- // Create ABSTRACT CLASS
- ObjectModelClass service = createAbstractClass(
- getServiceAbstractClassName(interfacez.getName()),
- interfacez.getPackageName());
-
- addInterface(service, serviceInterface.getQualifiedName());
-
- // Add Logger
+ // Add Logger attribute
// FIXME in EUGene, we want the default value not to be managed
// for import.
// addAttribute(service, "log",
@@ -382,243 +276,352 @@
// ObjectModelModifier.PRIVATE,
// ObjectModelModifier.STATIC,
// ObjectModelModifier.FINAL);
- addAttribute(service, "log",
+ addAttribute(serviceAbstract, "log",
Log.class, null,
ObjectModelModifier.PRIVATE,
ObjectModelModifier.FINAL);
- addImport(service, Log.class);
- addImport(service, LogFactory.class);
+ addImport(serviceAbstract, Log.class);
+ addImport(serviceAbstract, LogFactory.class);
- String contextFqn = defaultPackageName + "." +
- getContextImplementorInterfaceName();
-
- // Add Context Attribute + constructor
- addAttribute(service, "context", contextFqn, null,
- ObjectModelModifier.PROTECTED);
-
// Constructor
ObjectModelOperation constructor =
- addConstructor(service, ObjectModelModifier.PUBLIC);
+ addConstructor(serviceAbstract, ObjectModelModifier.PUBLIC);
setOperationBody(constructor, ""
/*{
// FIXME : must be fixed attribute value in EUGene
- this.log = LogFactory.getLog(<%=interfacez.getName()%>.class);
+ this.log = LogFactory.getLog(<%=serviceAbstract.getName()%>.class);
}*/
);
- ObjectModelOperation setContext =
- addOperation(service, "setContext", "void",
- ObjectModelModifier.PUBLIC);
- addParameter(setContext, contextFqn, "context");
- setOperationBody(setContext, ""
- /*{
- this.context = context;
- }*/
- );
+ // Create abstract methods
+ ObjectModelOperation beginTransaction =
+ addOperation(serviceAbstract, OP_NAME_BEGIN_TRANSACTION,
+ TopiaContext.class,
+ ObjectModelModifier.ABSTRACT,
+ ObjectModelModifier.PROTECTED);
+ addException(beginTransaction, TopiaException.class);
- // Prepare operation generations
- String first = modelName.substring(0, 1);
- String serviceName =
- GeneratorUtil.toLowerCaseFirstLetter(interfacez.getName());
+ ObjectModelOperation treateError1 =
+ addOperation(serviceAbstract, OP_NAME_TREATE_ERROR, "void",
+ ObjectModelModifier.ABSTRACT,
+ ObjectModelModifier.PROTECTED);
+ addParameter(treateError1, Exception.class, "eee");
+ addParameter(treateError1, String.class, "message");
+ addParameter(treateError1, "Object...", "args");
+ if (exceptionName != null) {
+ addException(treateError1, exceptionName);
+ }
- addImport(service, TopiaContext.class);
- addImport(service, I18n.class);
- addImport(service, ArrayList.class);
- addImport(service, DurationFormatUtils.class);
+ ObjectModelOperation treateError2 =
+ addOperation(serviceAbstract, OP_NAME_TREATE_ERROR, "void",
+ ObjectModelModifier.ABSTRACT,
+ ObjectModelModifier.PROTECTED);
+ addParameter(treateError2, TopiaContext.class, "transaction");
+ addParameter(treateError2, Exception.class, "eee");
+ addParameter(treateError2, String.class, "message");
+ addParameter(treateError2, "Object...", "args");
+ if (exceptionName != null) {
+ addException(treateError2, exceptionName);
+ }
- for (ObjectModelOperation op : interfacez.getOperations()) {
+ ObjectModelOperation closeTransaction =
+ addOperation(serviceAbstract, OP_NAME_CLOSE_TRANSACTION, "void",
+ ObjectModelModifier.ABSTRACT,
+ ObjectModelModifier.PROTECTED);
+ addParameter(closeTransaction, TopiaContext.class, "transaction");
- // boolean to specify if the method need a transaction or not
- // Default set to true but can be override by a tagvalue on the
- // method
- boolean needTransaction = true;
+ // Create abstract execute methods
+ Map<String, ObjectModelOperation> abstOps =
+ new HashMap<String, ObjectModelOperation>();
- String transactionTag =
- op.getTagValue(TopiaGeneratorUtil.TAG_TRANSACTION);
+ // Use source interfacez to have tagvalues from model
+ for (ObjectModelOperation op : source.getOperations()) {
+ ObjectModelOperation abstOp =
+ createOperationExecuteAbstract(serviceAbstract, op);
+ // Keep abstract methods to use them in operationImplementation
+ // generation
+ abstOps.put(op.getName(), abstOp);
+ }
- if (transactionTag != null) {
- needTransaction = Boolean.parseBoolean(transactionTag);
- }
+ // Imports for implementations
+ addImport(serviceAbstract, TopiaContext.class);
+ addImport(serviceAbstract, I18n.class);
+ addImport(serviceAbstract, ArrayList.class);
+ addImport(serviceAbstract, DurationFormatUtils.class);
- // boolean to specify if the method need error arguments or not
- // Default set to true but can be override by a tagvalue on the
- // method
- boolean needErrorArgs = false;
+ // Create abstract execute methods
+ for (ObjectModelOperation op : source.getOperations()) {
+ createOperationImplementation(serviceAbstract,
+ abstOps.get(op.getName()), op, source.getName());
+ }
+ }
- String errorArgsTag =
- op.getTagValue(TopiaGeneratorUtil.TAG_ERROR_ARGS);
+ /**
+ * Create an operation abstract to execute in contract implementation.
+ * You can use tagvalues "errorArgs" (default = false) and "transaction"
+ * (default = true) to generate appropriate parameters. This abstract
+ * method will throw all exceptions (Exception.class). This is the method
+ * which will be implemented by the developper in service implementation
+ * class.
+ *
+ * @param serviceAbstract where the operation will be created
+ * @param source ObjectModelOperation from model
+ * @return the abstract operation created
+ * @see #isErrorArgsNeeded(org.nuiton.eugene.models.object.ObjectModelOperation)
+ * @see #isTransactionNeeded(org.nuiton.eugene.models.object.ObjectModelOperation)
+ */
+ protected ObjectModelOperation createOperationExecuteAbstract(
+ ObjectModelClass serviceAbstract, ObjectModelOperation source) {
+ String opName = StringUtils.capitalize(source.getName());
- if (errorArgsTag != null) {
- needErrorArgs = Boolean.parseBoolean(errorArgsTag);
- }
+ // Abstract operation to execute method content
+ ObjectModelOperation abstOp =
+ addOperation(serviceAbstract, "execute" + opName,
+ source.getReturnType(),
+ ObjectModelModifier.ABSTRACT,
+ ObjectModelModifier.PROTECTED);
- // Implementation of interface operation
- ObjectModelOperation implOp =
- addOperation(service,
- op.getName(), op.getReturnType(),
- ObjectModelModifier.PUBLIC);
- addAnnotation(service, implOp, Override.class.getSimpleName());
-
- String opName = StringUtils.capitalize(op.getName());
+ // Throw all exception from abstract method
+ // They will be catched by interface method to use treateError
+ addException(abstOp, Exception.class);
- // Abstract operation to execute method content
- ObjectModelOperation abstOp =
- addOperation(service, "execute" + opName,
- op.getReturnType(),
- ObjectModelModifier.ABSTRACT,
- ObjectModelModifier.PROTECTED);
+ if (isTransactionNeeded(source)) {
+ addParameter(abstOp, TopiaContext.class, "transaction");
+ }
- // Throw all exception from abstract method
- // They will be catched by interface method to use doCatch
- addException(abstOp, Exception.class);
+ if (isErrorArgsNeeded(source)) {
+ // Add errorArgs to abstract operation
+ addParameter(abstOp,
+ "java.util.List<Object>", "errorArgs");
+ }
- if (needTransaction) {
- addParameter(abstOp, TopiaContext.class, "transaction");
- //addException(abstOp, TopiaException.class);
- }
+ // Copy other operation parameters
+ for (ObjectModelParameter param : source.getParameters()) {
+ addParameter(abstOp, param.getType(), param.getName());
+ }
+ return abstOp;
+ }
- String toStringAppend = "";
- String separatorLog = " : ";
- // Prepare operation parameters
- String opParams = "";
- String separatorParams = "";
- if (needErrorArgs) {
- opParams += "errorArgs";
- separatorParams = ", ";
- // Add errorArgs to abstract operation
- addParameter(abstOp,
- "java.util.List<Object>", "errorArgs");
- }
+ /**
+ * Create an operation implementation. This is the skeleton of the operation
+ * defined from model. This will put a try/catch block over an abstract
+ * method {@code 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 {@code serviceAbstract} class.
+ *
+ * @param serviceAbstract where the operation will be created
+ * @param abstOp to execute into the implementation body
+ * @param source ObjectModelOperation from model
+ * @param serviceContractName where the signature method is defined
+ * @see #isErrorArgsNeeded(org.nuiton.eugene.models.object.ObjectModelOperation)
+ * @see #isTransactionNeeded(org.nuiton.eugene.models.object.ObjectModelOperation)
+ */
+ protected void createOperationImplementation(
+ ObjectModelClass serviceAbstract,
+ ObjectModelOperation abstOp, ObjectModelOperation source,
+ String serviceContractName) {
- // Copy other operation parameters
- for (ObjectModelParameter param : op.getParameters()) {
- String paramName = param.getName();
- addParameter(implOp, param.getType(), param.getName());
- addParameter(abstOp, param.getType(), param.getName());
+ // boolean to specify if the method need a transaction or not
+ // Default set to true but can be override by a tagvalue on the
+ // method
+ boolean needTransaction = isTransactionNeeded(source);
- // Prepare Log
- toStringAppend +=
- "\n\t\t\t.append(\"" + separatorLog + paramName + " = \")" +
- ".append(" + paramName + ")";
- separatorLog = " _ ";
+ // boolean to specify if the method need error arguments or not
+ // Default set to true but can be override by a tagvalue on the
+ // method
+ boolean needErrorArgs = isErrorArgsNeeded(source);
- // Prepare Abstract method params
- opParams += separatorParams + param.getName();
- separatorParams = ", ";
- }
+ // Implementation of interface operation
+ ObjectModelOperation implOp =
+ addOperation(serviceAbstract, source.getName(),
+ source.getReturnType(),
+ ObjectModelModifier.PUBLIC);
+ addAnnotation(serviceAbstract, implOp, Override.class.getSimpleName());
- // Use buffer for operation body
- StringBuilder buffer = new StringBuilder();
-
- // Error key for i18n
- String errorKey = StringUtils.lowerCase(modelName) + ".error." +
- serviceName + "." + op.getName();
+ String toStringAppend = "";
+ String separatorLog = " : ";
+ // Copy operation parameters
+ for (ObjectModelParameter param : source.getParameters()) {
+ String paramName = param.getName();
+ addParameter(implOp, param.getType(), paramName);
- String treateErrorParams = "eee, I18n.n_(\"" + errorKey + "\")";
- treateErrorParams += needErrorArgs ? ", errorArgs.toArray()" : "";
+ // Prepare Log
+ toStringAppend +=
+ "\n\t\t\t.append(\"" + separatorLog + paramName + " = \")" +
+ ".append(" + paramName + ")";
+ separatorLog = " _ ";
+ }
- // Return managment
- String opReturnType = "";
- String opReturn = "";
- String finalReturn = "";
- if (!op.getReturnType().equals("void")) {
- opReturnType = GeneratorUtil.getSimpleName(op.getReturnType()) +
- " result = ";
- opReturn = "return result;";
- finalReturn = "return " +
- getReturnValue(op.getReturnType()) + ";";
- }
+ // Use buffer for operation body
+ StringBuilder buffer = new StringBuilder();
- if (needErrorArgs) {
- // Init errorArgs
- buffer.append(""
+ // Abstract operation parameters
+ String abstName = abstOp.getName();
+ String abstParams = "";
+ String separator = "";
+ for (ObjectModelParameter param : abstOp.getParameters()) {
+ abstParams += separator + param.getName();
+ separator = ", ";
+ }
+
+ // Abstract operation return managment
+ String abstReturnType = "";
+ String abstReturn = "";
+ String finalReturn = "";
+ if (!abstOp.getReturnType().equals("void")) {
+ abstReturnType = GeneratorUtil.getSimpleName(abstOp.getReturnType())
+ + " result = ";
+ abstReturn = "return result;";
+ finalReturn = "return " +
+ getReturnValue(abstOp.getReturnType()) + ";";
+ }
+
+ // Error key for i18n
+ String contract =
+ GeneratorUtil.toLowerCaseFirstLetter(serviceContractName);
+ String errorKey = StringUtils.lowerCase(modelName) + ".error." +
+ contract + "." + source.getName();
+
+ String treateErrorParams = "eee, I18n.n_(\"" + errorKey + "\")";
+
+ if (needErrorArgs) {
+ // Init errorArgs
+ buffer.append(""
/*{
List<Object> errorArgs = new ArrayList<Object>();
}*/ );
- }
+ treateErrorParams += ", errorArgs.toArray()";
+ }
- if (needTransaction) {
- // Open the transaction
- buffer.append(""
+ if (needTransaction) {
+ // Open the transaction
+ buffer.append(""
/*{
TopiaContext transaction = null;
try {
- transaction = context.beginTransaction();
+ transaction = beginTransaction();
}*/
- );
- // Add transaction in the execute operation parameters
- // and doCatch parameters
- opParams = "transaction" + separatorParams + opParams;
- treateErrorParams = "transaction, " + treateErrorParams;
- } else {
- buffer.append(""
+ );
+ // Add transaction in treateError parameters
+ treateErrorParams = "transaction, " + treateErrorParams;
+ } else {
+ buffer.append(""
/*{
try {
}*/
- );
- }
+ );
+ }
- buffer.append(""
+ String implName = StringUtils.capitalize(implOp.getName());
+ String first = modelName.substring(0, 1);
+
+ buffer.append(""
/*{
long startTime = 0;
if (log.isDebugEnabled()) {
- log.debug("<%=first%>:[ begin <%=opName%> ]");
+ log.debug("<%=first%>:[ begin <%=implName%> ]");
startTime = System.currentTimeMillis();
}
if (log.isTraceEnabled()) {
String message = new StringBuilder("# ARGS >")<%=toStringAppend%>.
toString();
log.trace(message);
- }
+ }
- <%=opReturnType%>execute<%=opName%>(<%=opParams%>);
+ <%=abstReturnType%><%=abstName%>(<%=abstParams%>);
if (log.isDebugEnabled()) {
long stopTime = System.currentTimeMillis();
- log.debug("<%=first%>:[ end <%=opName%> ] Time = " +
+ log.debug("<%=first%>:[ end <%=implName%> ] Time = " +
DurationFormatUtils.formatDurationHMS(
stopTime - startTime));
}
- <%=opReturn%> }*/);
+ <%=abstReturn%> }*/);
- // Copy exceptions
- for (String ex : op.getExceptions()) {
- addException(implOp, ex);
- //addException(abstOp, ex);
- // Add catch block for known exceptions we want to throw
- String exName = GeneratorUtil.getSimpleName(ex);
- buffer.append(""
+ // Copy exceptions
+ for (String ex : source.getExceptions()) {
+ addException(implOp, ex);
+ // Add catch block for known exceptions we want to throw
+ String exName = GeneratorUtil.getSimpleName(ex);
+ buffer.append(""
/*{
} catch (<%=exName%> eee) {
throw eee; }*/);
- }
+ }
- buffer.append(""
+ buffer.append(""
/*{
} catch (Exception eee) {
- context.treateError(<%=treateErrorParams%>); }*/);
+ treateError(<%=treateErrorParams%>); }*/);
- if (needTransaction) {
- // Finally block to close transaction
- buffer.append(""
+ if (needTransaction) {
+ // Finally block to close transaction
+ buffer.append(""
/*{
} finally {
- context.closeTransaction(transaction); }*/);
- }
+ closeTransaction(transaction); }*/);
+ }
- buffer.append(""
+ buffer.append(""
/*{
}
- <%=finalReturn%>
+ <%=finalReturn%>
}*/
- );
+ );
- setOperationBody(implOp, buffer.toString());
+ setOperationBody(implOp, buffer.toString());
+ }
+
+ /**
+ * boolean to specify if the method need a transaction or not.
+ * Default set to true but can be override using a tagvalue "transaction"
+ * on the method from model.
+ *
+ * @param op where the tagvalue is set
+ * @return true if transaction is needed
+ */
+ protected boolean isTransactionNeeded(ObjectModelOperation op) {
+ boolean needTransaction = true;
+
+ String transactionTag =
+ op.getTagValue(TopiaGeneratorUtil.TAG_TRANSACTION);
+
+ if (transactionTag != null) {
+ needTransaction = Boolean.parseBoolean(transactionTag);
}
-
+ return needTransaction;
}
+ /**
+ * 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.
+ *
+ * @param op where the tagvalue is set
+ * @return true if errorArgs are needed
+ */
+ protected boolean isErrorArgsNeeded(ObjectModelOperation op) {
+ //
+ boolean needErrorArgs = false;
+ String errorArgsTag =
+ op.getTagValue(TopiaGeneratorUtil.TAG_ERROR_ARGS);
+
+ if (errorArgsTag != null) {
+ needErrorArgs = Boolean.parseBoolean(errorArgsTag);
+ }
+ return needErrorArgs;
+ }
+
+ /**
+ * This method give the return string for an operation {@code returnType}.
+ * This use {@link Primitive} enum to provide default values for primitive
+ * type. For all other object type, this method will return null.
+ *
+ * @param returnType
+ * @return the defaultValue of the returnType
+ */
protected String getReturnValue(String returnType) {
try {
Primitive prim =
@@ -630,7 +633,7 @@
}
}
- public enum Primitive {
+ protected enum Primitive {
BYTE("0"),
SHORT("0"),
INT("0"),
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-04-02 09:19:54 UTC (rev 1870)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-04-02 15:44:28 UTC (rev 1871)
@@ -148,6 +148,12 @@
*/
public static final String TAG_ERROR_ARGS = "errorArgs";
/**
+ * Tag pour specifier l'exception principale de l'application.
+ * Utiliser dans le ServiceTransformer pour etre automatiquement jeter
+ * depuis les methodes des services.
+ */
+ public static final String TAG_EXCEPTION_CLASS = "exceptionClass";
+ /**
* Tag pour permettre de choisir qui contrôle la relation N-N
* bidirectionnelle. A utiliser sur les deux extremités de l'association.
* Mettre inverse=false sur le rôle fils et inverse=true sur le rôle père.
1
0
r1870 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesboisï¼ users.nuiton.org 02 Apr '10
by fdesboisï¼ users.nuiton.org 02 Apr '10
02 Apr '10
Author: fdesbois
Date: 2010-04-02 11:19:54 +0200 (Fri, 02 Apr 2010)
New Revision: 1870
Log:
- Rename methods to manage transaction and error (treateError, closeTransaction)
- Change log level to debug
- remove addException for user exceptions in abstract method -> not needed, already add the Exception.class
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-01 18:35:15 UTC (rev 1869)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-02 09:19:54 UTC (rev 1870)
@@ -74,7 +74,7 @@
* ...
*
* @Override
- * public void doCatch(TopiaContext transaction, Exception eee,
+ * public void treateError(TopiaContext transaction, Exception eee,
* String message, Object... args) throws AppException {
*
* // Note that the message from service doesn't directly use _() for
@@ -101,7 +101,7 @@
* }
*
* @Override
- * public void doFinally(TopiaContext transaction) {
+ * public void closeTransaction(TopiaContext transaction) {
* if (transaction != null) {
* try {
* transaction.closeContext();
@@ -125,7 +125,7 @@
*
* // only catch exception for rootContext
* } catch (TopiaNotFoundException eee) {
- * doCatch(eee, n_("app.error.context.getTopiaRootContext"));
+ * treateError(eee, n_("app.error.context.getTopiaRootContext"));
* }
* return null;
* }
@@ -250,14 +250,14 @@
addException(beginTransaction, TopiaException.class);
ObjectModelOperation doCatch1 =
- addOperation(newContextImplementor, "doCatch", "void");
+ addOperation(newContextImplementor, "treateError", "void");
addParameter(doCatch1, Exception.class, "eee");
addParameter(doCatch1, String.class, "message");
addParameter(doCatch1, "Object...", "args");
addException(doCatch1, exception.getQualifiedName());
ObjectModelOperation doCatch2 =
- addOperation(newContextImplementor, "doCatch", "void");
+ addOperation(newContextImplementor, "treateError", "void");
addParameter(doCatch2, TopiaContext.class, "transaction");
addParameter(doCatch2, Exception.class, "eee");
addParameter(doCatch2, String.class, "message");
@@ -265,7 +265,7 @@
addException(doCatch2, exception.getQualifiedName());
ObjectModelOperation doFinally =
- addOperation(newContextImplementor, "doFinally", "void");
+ addOperation(newContextImplementor, "closeTransaction", "void");
addParameter(doFinally, TopiaContext.class, "transaction");
}
@@ -475,7 +475,7 @@
if (needTransaction) {
addParameter(abstOp, TopiaContext.class, "transaction");
- addException(abstOp, TopiaException.class);
+ //addException(abstOp, TopiaException.class);
}
String toStringAppend = "";
@@ -515,8 +515,8 @@
String errorKey = StringUtils.lowerCase(modelName) + ".error." +
serviceName + "." + op.getName();
- String doCatchParams = "eee, I18n.n_(\"" + errorKey + "\")";
- doCatchParams += needErrorArgs ? ", errorArgs.toArray()" : "";
+ String treateErrorParams = "eee, I18n.n_(\"" + errorKey + "\")";
+ treateErrorParams += needErrorArgs ? ", errorArgs.toArray()" : "";
// Return managment
String opReturnType = "";
@@ -550,7 +550,7 @@
// Add transaction in the execute operation parameters
// and doCatch parameters
opParams = "transaction" + separatorParams + opParams;
- doCatchParams = "transaction, " + doCatchParams;
+ treateErrorParams = "transaction, " + treateErrorParams;
} else {
buffer.append(""
/*{
@@ -561,23 +561,21 @@
buffer.append(""
/*{
- if (log.isInfoEnabled()) {
- log.info("<%=first%>:[ <%=opName%> ]");
+ long startTime = 0;
+ if (log.isDebugEnabled()) {
+ log.debug("<%=first%>:[ begin <%=opName%> ]");
+ startTime = System.currentTimeMillis();
}
if (log.isTraceEnabled()) {
String message = new StringBuilder("# ARGS >")<%=toStringAppend%>.
toString();
log.trace(message);
- }
- long startTime = 0;
- if (log.isDebugEnabled()) {
- startTime = System.currentTimeMillis();
- }
+ }
<%=opReturnType%>execute<%=opName%>(<%=opParams%>);
if (log.isDebugEnabled()) {
long stopTime = System.currentTimeMillis();
- log.debug("<%=first%>:[ <%=opName%> ] Time = " +
+ log.debug("<%=first%>:[ end <%=opName%> ] Time = " +
DurationFormatUtils.formatDurationHMS(
stopTime - startTime));
}
@@ -586,7 +584,7 @@
// Copy exceptions
for (String ex : op.getExceptions()) {
addException(implOp, ex);
- addException(abstOp, ex);
+ //addException(abstOp, ex);
// Add catch block for known exceptions we want to throw
String exName = GeneratorUtil.getSimpleName(ex);
buffer.append(""
@@ -598,14 +596,14 @@
buffer.append(""
/*{
} catch (Exception eee) {
- context.doCatch(<%=doCatchParams%>); }*/);
+ context.treateError(<%=treateErrorParams%>); }*/);
if (needTransaction) {
// Finally block to close transaction
buffer.append(""
/*{
} finally {
- context.doFinally(transaction); }*/);
+ context.closeTransaction(transaction); }*/);
}
buffer.append(""
1
0
r1869 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesboisï¼ users.nuiton.org 01 Apr '10
by fdesboisï¼ users.nuiton.org 01 Apr '10
01 Apr '10
Author: fdesbois
Date: 2010-04-01 20:35:15 +0200 (Thu, 01 Apr 2010)
New Revision: 1869
Log:
Change log level for method arguments
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-01 14:24:17 UTC (rev 1868)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-01 18:35:15 UTC (rev 1869)
@@ -562,9 +562,12 @@
buffer.append(""
/*{
if (log.isInfoEnabled()) {
- String message = new StringBuilder("<%=first%>:[ <%=opName%> ]")<%=toStringAppend%>.
+ log.info("<%=first%>:[ <%=opName%> ]");
+ }
+ if (log.isTraceEnabled()) {
+ String message = new StringBuilder("# ARGS >")<%=toStringAppend%>.
toString();
- log.info(message);
+ log.trace(message);
}
long startTime = 0;
if (log.isDebugEnabled()) {
1
0
r1868 - in trunk: . topia-persistence/src/main/java/org/nuiton/topia/generator topia-service-history topia-service-index topia-soa
by fdesboisï¼ users.nuiton.org 01 Apr '10
by fdesboisï¼ users.nuiton.org 01 Apr '10
01 Apr '10
Author: fdesbois
Date: 2010-04-01 16:24:17 +0200 (Thu, 01 Apr 2010)
New Revision: 1868
Log:
- ServiceTransformer : change default value for tag 'errorArgs'\n - Don't migrate old modules on snapshot
Modified:
trunk/pom.xml
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
trunk/topia-service-history/pom.xml
trunk/topia-service-index/pom.xml
trunk/topia-soa/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-04-01 13:30:48 UTC (rev 1867)
+++ trunk/pom.xml 2010-04-01 14:24:17 UTC (rev 1868)
@@ -17,12 +17,12 @@
<modules>
<module>topia-persistence</module>
- <module>topia-soa</module>
+ <!--module>topia-soa</module-->
<module>topia-service-replication</module>
<module>topia-service-migration</module>
- <module>topia-service-index</module>
+ <!--module>topia-service-index</module-->
<module>topia-service-security</module>
- <module>topia-service-history</module>
+ <!--module>topia-service-history</module-->
</modules>
<dependencyManagement>
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-01 13:30:48 UTC (rev 1867)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-01 14:24:17 UTC (rev 1868)
@@ -157,6 +157,7 @@
* </pre>
* <div>
* <h2>TAG_TRANSACTION</h2>
+ * <p>Default value : true</p>
* <p>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
@@ -164,8 +165,9 @@
* </div>
* <div>
* <h2>TAG_ERROR_ARGS</h2>
- * <p>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
+ * <p>Default value : false</p>
+ * <p>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.</p>
* </div>
* <p>It is smooth, isn't it :p ?</p>
@@ -442,7 +444,7 @@
// boolean to specify if the method need error arguments or not
// Default set to true but can be override by a tagvalue on the
// method
- boolean needErrorArgs = true;
+ boolean needErrorArgs = false;
String errorArgsTag =
op.getTagValue(TopiaGeneratorUtil.TAG_ERROR_ARGS);
Modified: trunk/topia-service-history/pom.xml
===================================================================
--- trunk/topia-service-history/pom.xml 2010-04-01 13:30:48 UTC (rev 1867)
+++ trunk/topia-service-history/pom.xml 2010-04-01 14:24:17 UTC (rev 1868)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-index/pom.xml
===================================================================
--- trunk/topia-service-index/pom.xml 2010-04-01 13:30:48 UTC (rev 1867)
+++ trunk/topia-service-index/pom.xml 2010-04-01 14:24:17 UTC (rev 1868)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-soa/pom.xml
===================================================================
--- trunk/topia-soa/pom.xml 2010-04-01 13:30:48 UTC (rev 1867)
+++ trunk/topia-soa/pom.xml 2010-04-01 14:24:17 UTC (rev 1868)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.2-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0
r1867 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesboisï¼ users.nuiton.org 01 Apr '10
by fdesboisï¼ users.nuiton.org 01 Apr '10
01 Apr '10
Author: fdesbois
Date: 2010-04-01 15:30:48 +0200 (Thu, 01 Apr 2010)
New Revision: 1867
Log:
[ServiceTransformer]
- Manage defaultValue for primitive returnType
- Resolve issue for methods with no parameter
- Add throw generated exception on interfaces
- Add time log
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-01 13:28:35 UTC (rev 1866)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-04-01 13:30:48 UTC (rev 1867)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DurationFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.eugene.GeneratorUtil;
@@ -187,7 +188,7 @@
protected String defaultPackageName;
protected String getContextInterfaceName() {
- return modelName + "Context";
+ return StringUtils.capitalize(modelName) + "Context";
}
protected String getContextImplementorInterfaceName() {
@@ -195,7 +196,7 @@
}
protected String getExceptionClassName() {
- return modelName + "Exception";
+ return StringUtils.capitalize(modelName) + "Exception";
}
protected String getServiceAbstractClassName(String serviceName) {
@@ -219,67 +220,68 @@
ObjectModelClass exception = createExceptionClass();
ObjectModelInterface newContextImplementor =
- this.createInterface(getContextImplementorInterfaceName(),
+ createInterface(getContextImplementorInterfaceName(),
defaultPackageName);
ObjectModelInterface newContext =
- this.createInterface(getContextInterfaceName(),
+ createInterface(getContextInterfaceName(),
defaultPackageName);
- this.addInterface(newContextImplementor,
+ addInterface(newContextImplementor,
newContext.getQualifiedName());
if (contextImplementor != null) {
// Copy of defined operations
// interfaces of contextImplementor are not copied
- copyInterfaceOperations(contextImplementor, newContextImplementor);
+ copyInterfaceOperations(
+ contextImplementor, newContextImplementor, false);
}
if (context != null) {
// Copy of defined operations
// interfaces of context are not copied
- copyInterfaceOperations(context, newContext);
+ copyInterfaceOperations(context, newContext, false);
}
ObjectModelOperation beginTransaction =
- this.addOperation(newContextImplementor,
+ addOperation(newContextImplementor,
"beginTransaction", TopiaContext.class);
- this.addException(beginTransaction, TopiaException.class);
+ addException(beginTransaction, TopiaException.class);
ObjectModelOperation doCatch1 =
- this.addOperation(newContextImplementor, "doCatch", "void");
- this.addParameter(doCatch1, Exception.class, "eee");
- this.addParameter(doCatch1, String.class, "message");
- this.addParameter(doCatch1, "Object...", "args");
- this.addException(doCatch1, exception.getQualifiedName());
+ addOperation(newContextImplementor, "doCatch", "void");
+ addParameter(doCatch1, Exception.class, "eee");
+ addParameter(doCatch1, String.class, "message");
+ addParameter(doCatch1, "Object...", "args");
+ addException(doCatch1, exception.getQualifiedName());
ObjectModelOperation doCatch2 =
- this.addOperation(newContextImplementor, "doCatch", "void");
- this.addParameter(doCatch2, TopiaContext.class, "transaction");
- this.addParameter(doCatch2, Exception.class, "eee");
- this.addParameter(doCatch2, String.class, "message");
- this.addParameter(doCatch2, "Object...", "args");
- this.addException(doCatch2, exception.getQualifiedName());
+ addOperation(newContextImplementor, "doCatch", "void");
+ addParameter(doCatch2, TopiaContext.class, "transaction");
+ addParameter(doCatch2, Exception.class, "eee");
+ addParameter(doCatch2, String.class, "message");
+ addParameter(doCatch2, "Object...", "args");
+ addException(doCatch2, exception.getQualifiedName());
ObjectModelOperation doFinally =
- this.addOperation(newContextImplementor, "doFinally", "void");
- this.addParameter(doFinally, TopiaContext.class, "transaction");
+ addOperation(newContextImplementor, "doFinally", "void");
+ addParameter(doFinally, TopiaContext.class, "transaction");
}
protected ObjectModelClass createExceptionClass() {
ObjectModelClass exception =
- this.createClass(getExceptionClassName(), defaultPackageName);
+ createClass(getExceptionClassName(), defaultPackageName);
- this.setSuperClass(exception, RuntimeException.class);
- this.addAttribute(exception, "args", "Object[]", null,
+ setSuperClass(exception, RuntimeException.class);
+ addAttribute(exception, "args", "Object[]", null,
ObjectModelModifier.PROTECTED);
ObjectModelOperation constructor =
- this.addConstructor(exception, ObjectModelModifier.PUBLIC);
+ addConstructor(exception, ObjectModelModifier.PUBLIC);
- this.addParameter(constructor, Throwable.class, "eee");
- this.addParameter(constructor, String.class, "message");
- this.addParameter(constructor, "Object...", "args");
+ addParameter(constructor, Throwable.class, "eee");
+ addParameter(constructor, String.class, "message");
+ addParameter(constructor, "Object...", "args");
setOperationBody(constructor, ""
/*{
@@ -289,7 +291,7 @@
);
ObjectModelOperation getArgs =
- this.addOperation(exception, "getArgs", "Object[]",
+ addOperation(exception, "getArgs", "Object[]",
ObjectModelModifier.PUBLIC);
setOperationBody(getArgs, ""
@@ -299,7 +301,7 @@
);
ObjectModelOperation hasArgs =
- this.addOperation(exception, "hasArgs", "boolean",
+ addOperation(exception, "hasArgs", "boolean",
ObjectModelModifier.PUBLIC);
setOperationBody(hasArgs, ""
@@ -317,25 +319,32 @@
*
* @param source interface
* @param dest interface
+ * @param throwException if generated exception is thrown
*/
protected void copyInterfaceOperations(ObjectModelInterface source,
- ObjectModelInterface dest) {
+ ObjectModelInterface dest, boolean throwException) {
setDocumentation(dest, source.getDocumentation());
+ if (throwException) {
+ addImport(dest, defaultPackageName + "." + getExceptionClassName());
+ }
for (ObjectModelOperation op : source.getOperations()) {
ObjectModelOperation newOp =
- this.addOperation(dest,
+ addOperation(dest,
op.getName(), op.getReturnType());
setDocumentation(newOp.getReturnParameter(),
op.getReturnParameter().getDocumentation());
for (ObjectModelParameter param : op.getParameters()) {
ObjectModelParameter newParam =
- this.addParameter(newOp, param.getType(),
+ addParameter(newOp, param.getType(),
param.getName());
setDocumentation(newParam, param.getDocumentation());
}
for (String ex : op.getExceptions()) {
- this.addException(newOp, ex);
+ addException(newOp, ex);
}
+ if (throwException) {
+ addException(newOp, getExceptionClassName());
+ }
setDocumentation(newOp, op.getDocumentation());
}
}
@@ -349,59 +358,57 @@
// Create INTERFACE
ObjectModelInterface serviceInterface =
- this.createInterface(interfacez.getName(),
+ createInterface(interfacez.getName(),
interfacez.getPackageName());
- copyInterfaceOperations(interfacez, serviceInterface);
+ copyInterfaceOperations(interfacez, serviceInterface, true);
// Create ABSTRACT CLASS
- ObjectModelClass service = this.createAbstractClass(
+ ObjectModelClass service = createAbstractClass(
getServiceAbstractClassName(interfacez.getName()),
interfacez.getPackageName());
- this.addInterface(service, serviceInterface.getQualifiedName());
+ addInterface(service, serviceInterface.getQualifiedName());
// Add Logger
// FIXME in EUGene, we want the default value not to be managed
// for import.
-// this.addAttribute(service, "log",
+// addAttribute(service, "log",
// Log.class,
// "LogFactory.getLog(" + interfacez.getName() + ".class)",
// ObjectModelModifier.PRIVATE,
// ObjectModelModifier.STATIC,
// ObjectModelModifier.FINAL);
- this.addAttribute(service, "log",
+ addAttribute(service, "log",
Log.class, null,
ObjectModelModifier.PRIVATE,
ObjectModelModifier.FINAL);
- this.addImport(service, Log.class);
- this.addImport(service, LogFactory.class);
+ addImport(service, Log.class);
+ addImport(service, LogFactory.class);
String contextFqn = defaultPackageName + "." +
getContextImplementorInterfaceName();
// Add Context Attribute + constructor
- this.addAttribute(service, "context", contextFqn, null,
+ addAttribute(service, "context", contextFqn, null,
ObjectModelModifier.PROTECTED);
// Constructor
ObjectModelOperation constructor =
- this.addConstructor(service, ObjectModelModifier.PUBLIC);
- //this.addParameter(constructor, contextFqn, "context");
+ addConstructor(service, ObjectModelModifier.PUBLIC);
setOperationBody(constructor, ""
/*{
- //this.context = context;
// FIXME : must be fixed attribute value in EUGene
this.log = LogFactory.getLog(<%=interfacez.getName()%>.class);
}*/
);
ObjectModelOperation setContext =
- this.addOperation(service, "setContext", "void",
+ addOperation(service, "setContext", "void",
ObjectModelModifier.PUBLIC);
- this.addParameter(setContext, contextFqn, "context");
+ addParameter(setContext, contextFqn, "context");
setOperationBody(setContext, ""
/*{
this.context = context;
@@ -413,9 +420,10 @@
String serviceName =
GeneratorUtil.toLowerCaseFirstLetter(interfacez.getName());
- this.addImport(service, TopiaContext.class);
- this.addImport(service, I18n.class);
- this.addImport(service, ArrayList.class);
+ addImport(service, TopiaContext.class);
+ addImport(service, I18n.class);
+ addImport(service, ArrayList.class);
+ addImport(service, DurationFormatUtils.class);
for (ObjectModelOperation op : interfacez.getOperations()) {
@@ -445,27 +453,27 @@
// Implementation of interface operation
ObjectModelOperation implOp =
- this.addOperation(service,
+ addOperation(service,
op.getName(), op.getReturnType(),
ObjectModelModifier.PUBLIC);
- this.addAnnotation(service, implOp, Override.class.getSimpleName());
+ addAnnotation(service, implOp, Override.class.getSimpleName());
String opName = StringUtils.capitalize(op.getName());
// Abstract operation to execute method content
ObjectModelOperation abstOp =
- this.addOperation(service, "execute" + opName,
+ addOperation(service, "execute" + opName,
op.getReturnType(),
ObjectModelModifier.ABSTRACT,
ObjectModelModifier.PROTECTED);
// Throw all exception from abstract method
// They will be catched by interface method to use doCatch
- this.addException(abstOp, Exception.class);
+ addException(abstOp, Exception.class);
if (needTransaction) {
- this.addParameter(abstOp, TopiaContext.class, "transaction");
- this.addException(abstOp, TopiaException.class);
+ addParameter(abstOp, TopiaContext.class, "transaction");
+ addException(abstOp, TopiaException.class);
}
String toStringAppend = "";
@@ -477,15 +485,15 @@
opParams += "errorArgs";
separatorParams = ", ";
// Add errorArgs to abstract operation
- this.addParameter(abstOp,
+ addParameter(abstOp,
"java.util.List<Object>", "errorArgs");
}
// Copy other operation parameters
for (ObjectModelParameter param : op.getParameters()) {
String paramName = param.getName();
- this.addParameter(implOp, param.getType(), param.getName());
- this.addParameter(abstOp, param.getType(), param.getName());
+ addParameter(implOp, param.getType(), param.getName());
+ addParameter(abstOp, param.getType(), param.getName());
// Prepare Log
toStringAppend +=
@@ -509,11 +517,15 @@
doCatchParams += needErrorArgs ? ", errorArgs.toArray()" : "";
// Return managment
+ String opReturnType = "";
String opReturn = "";
String finalReturn = "";
if (!op.getReturnType().equals("void")) {
- opReturn = "return ";
- finalReturn = "return null;";
+ opReturnType = GeneratorUtil.getSimpleName(op.getReturnType()) +
+ " result = ";
+ opReturn = "return result;";
+ finalReturn = "return " +
+ getReturnValue(op.getReturnType()) + ";";
}
if (needErrorArgs) {
@@ -535,7 +547,7 @@
);
// Add transaction in the execute operation parameters
// and doCatch parameters
- opParams = "transaction, " + opParams;
+ opParams = "transaction" + separatorParams + opParams;
doCatchParams = "transaction, " + doCatchParams;
} else {
buffer.append(""
@@ -547,18 +559,29 @@
buffer.append(""
/*{
- if (log.isDebugEnabled()) {
+ if (log.isInfoEnabled()) {
String message = new StringBuilder("<%=first%>:[ <%=opName%> ]")<%=toStringAppend%>.
toString();
- log.debug(message);
+ log.info(message);
}
+ long startTime = 0;
+ if (log.isDebugEnabled()) {
+ startTime = System.currentTimeMillis();
+ }
- <%=opReturn%>execute<%=opName%>(<%=opParams%>); }*/);
+ <%=opReturnType%>execute<%=opName%>(<%=opParams%>);
+ if (log.isDebugEnabled()) {
+ long stopTime = System.currentTimeMillis();
+ log.debug("<%=first%>:[ <%=opName%> ] Time = " +
+ DurationFormatUtils.formatDurationHMS(
+ stopTime - startTime));
+ }
+ <%=opReturn%> }*/);
// Copy exceptions
for (String ex : op.getExceptions()) {
- this.addException(implOp, ex);
- this.addException(abstOp, ex);
+ addException(implOp, ex);
+ addException(abstOp, ex);
// Add catch block for known exceptions we want to throw
String exName = GeneratorUtil.getSimpleName(ex);
buffer.append(""
@@ -587,8 +610,41 @@
}*/
);
- this.setOperationBody(implOp, buffer.toString());
+ setOperationBody(implOp, buffer.toString());
}
}
+
+
+ protected String getReturnValue(String returnType) {
+ try {
+ Primitive prim =
+ Primitive.valueOf(StringUtils.upperCase(returnType));
+ return prim.getValue();
+ // If not defined in Primitive enum, return null
+ } catch (IllegalArgumentException eee) {
+ return null;
+ }
+ }
+
+ public enum Primitive {
+ BYTE("0"),
+ SHORT("0"),
+ INT("0"),
+ LONG("0"),
+ FLOAT("0."),
+ DOUBLE("0."),
+ CHAR("''"),
+ BOOLEAN("false");
+
+ private String value;
+
+ Primitive(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+ }
}
1
0
r1866 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesboisï¼ users.nuiton.org 01 Apr '10
by fdesboisï¼ users.nuiton.org 01 Apr '10
01 Apr '10
Author: fdesbois
Date: 2010-04-01 15:28:35 +0200 (Thu, 01 Apr 2010)
New Revision: 1866
Log:
Evo #437 : Add tagvalue "inverse" on attributes used for a N-N association
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2010-03-31 08:41:27 UTC (rev 1865)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityHibernateMappingGenerator.java 2010-04-01 13:28:35 UTC (rev 1866)
@@ -500,7 +500,20 @@
boolean isInverse = attr.isNavigable() && attr.getReverseAttribute().isNavigable();
//isInverse |= !Util.isFirstAttribute(attr);
//isInverse = false; // 20070117 poussin: pour du many, jamais de inverse
- isInverse &= GeneratorUtil.isFirstAttribute(attr);
+
+ // Modification FD-2010-04-01 :
+ // Le tagvalue "inverse" permet de spécifier qui possède le
+ // inverse="true". Il est impératif de l'utiliser sur les deux
+ // extrémités pour ne pas avoir de surprise.
+ if (attr.hasTagValue(TopiaGeneratorUtil.TAG_INVERSE)) {
+ isInverse &= Boolean.parseBoolean(
+ attr.getTagValue(TopiaGeneratorUtil.TAG_INVERSE));
+ // Si aucun tagvalue n'est défini, le choix est arbitraire : le
+ // premier attribut dans l'ordre alphabétique sera choisi pour porter le
+ // inverse="true"
+ } else {
+ isInverse &= GeneratorUtil.isFirstAttribute(attr);
+ }
boolean needsIndex = attr.isIndexed();
String cascade = "";
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-03-31 08:41:27 UTC (rev 1865)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-04-01 13:28:35 UTC (rev 1866)
@@ -148,6 +148,14 @@
*/
public static final String TAG_ERROR_ARGS = "errorArgs";
/**
+ * Tag pour permettre de choisir qui contrôle la relation N-N
+ * bidirectionnelle. A utiliser sur les deux extremités de l'association.
+ * Mettre inverse=false sur le rôle fils et inverse=true sur le rôle père.
+ * Par défaut le inverse=true est placé sur le premier rôle trouvé dans
+ * l'ordre alphabétique.
+ */
+ public static final String TAG_INVERSE = "inverse";
+ /**
* Tag pour spécifier la caractère lazy d'une association multiple
*/
public static final String TAG_LAZY = "lazy";
1
0
r1865 - in trunk: . topia-persistence topia-service-history topia-service-index topia-service-migration topia-service-replication topia-service-security topia-soa
by fdesboisï¼ users.nuiton.org 31 Mar '10
by fdesboisï¼ users.nuiton.org 31 Mar '10
31 Mar '10
Author: fdesbois
Date: 2010-03-31 10:41:27 +0200 (Wed, 31 Mar 2010)
New Revision: 1865
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-service-history/pom.xml
trunk/topia-service-index/pom.xml
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/pom.xml
trunk/topia-service-security/pom.xml
trunk/topia-soa/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -13,7 +13,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
<modules>
<module>topia-persistence</module>
@@ -260,9 +260,9 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.3.1</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.3.1</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/topia/tags/topia-2.3.1</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/topia/trunk</url>
</scm>
</project>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/topia-persistence/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-history/pom.xml
===================================================================
--- trunk/topia-service-history/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/topia-service-history/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-index/pom.xml
===================================================================
--- trunk/topia-service-index/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/topia-service-index/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/topia-service-migration/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/topia-service-replication/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/topia-service-security/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-soa/pom.xml
===================================================================
--- trunk/topia-soa/pom.xml 2010-03-31 08:41:23 UTC (rev 1864)
+++ trunk/topia-soa/pom.xml 2010-03-31 08:41:27 UTC (rev 1865)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0
Author: fdesbois
Date: 2010-03-31 10:41:23 +0200 (Wed, 31 Mar 2010)
New Revision: 1864
Log:
[maven-release-plugin] copy for tag topia-2.3.1
Added:
tags/topia-2.3.1/
Property changes on: tags/topia-2.3.1
___________________________________________________________________
Added: svn:ignore
+ *.ipr
*.iws
.classpath
*.iml
.project
target
.settings
Added: svn:mergeinfo
+ /branches/from2.2.2-eugene2-beta:1662-1714
1
0
r1863 - in trunk: . topia-persistence topia-service-history topia-service-index topia-service-migration topia-service-replication topia-service-security topia-soa
by fdesboisï¼ users.nuiton.org 31 Mar '10
by fdesboisï¼ users.nuiton.org 31 Mar '10
31 Mar '10
Author: fdesbois
Date: 2010-03-31 10:41:20 +0200 (Wed, 31 Mar 2010)
New Revision: 1863
Log:
[maven-release-plugin] prepare release topia-2.3.1
Modified:
trunk/pom.xml
trunk/topia-persistence/pom.xml
trunk/topia-service-history/pom.xml
trunk/topia-service-index/pom.xml
trunk/topia-service-migration/pom.xml
trunk/topia-service-replication/pom.xml
trunk/topia-service-security/pom.xml
trunk/topia-soa/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -13,7 +13,7 @@
</parent>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
<modules>
<module>topia-persistence</module>
@@ -260,9 +260,9 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/trunk</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/topia/trunk</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.3.1</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/topia/tags/topia-2.3.1</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/topia/tags/topia-2.3.1</url>
</scm>
</project>
Modified: trunk/topia-persistence/pom.xml
===================================================================
--- trunk/topia-persistence/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/topia-persistence/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-history/pom.xml
===================================================================
--- trunk/topia-service-history/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/topia-service-history/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-index/pom.xml
===================================================================
--- trunk/topia-service-index/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/topia-service-index/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-migration/pom.xml
===================================================================
--- trunk/topia-service-migration/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/topia-service-migration/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-replication/pom.xml
===================================================================
--- trunk/topia-service-replication/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/topia-service-replication/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/topia-service-security/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/topia-soa/pom.xml
===================================================================
--- trunk/topia-soa/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
+++ trunk/topia-soa/pom.xml 2010-03-31 08:41:20 UTC (rev 1863)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>topia</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.topia</groupId>
1
0
r1862 - in trunk: . topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesboisï¼ users.nuiton.org 31 Mar '10
by fdesboisï¼ users.nuiton.org 31 Mar '10
31 Mar '10
Author: fdesbois
Date: 2010-03-31 10:27:58 +0200 (Wed, 31 Mar 2010)
New Revision: 1862
Log:
- Evo #412 : rename BusinessTransformer to ServiceTransformer + improve html javadoc
- Evo #430 : use 1.2 version of i18n
Added:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
Removed:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BusinessTransformer.java
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-03-30 20:51:55 UTC (rev 1861)
+++ trunk/pom.xml 2010-03-31 08:27:58 UTC (rev 1862)
@@ -190,7 +190,7 @@
<eugene.version>2.0</eugene.version>
<lutinutil.version>1.2</lutinutil.version>
<processor.version>1.0.3</processor.version>
- <i18n.version>1.1</i18n.version>
+ <i18n.version>1.2</i18n.version>
<xmlrpc.version>3.1.2</xmlrpc.version>
<hibernate.version>3.3.2.GA</hibernate.version>
Deleted: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BusinessTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BusinessTransformer.java 2010-03-30 20:51:55 UTC (rev 1861)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BusinessTransformer.java 2010-03-31 08:27:58 UTC (rev 1862)
@@ -1,592 +0,0 @@
-
-package org.nuiton.topia.generator;
-
-import java.util.ArrayList;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.GeneratorUtil;
-import org.nuiton.eugene.Template;
-import org.nuiton.eugene.java.ObjectModelTransformerToJava;
-import org.nuiton.eugene.models.object.ObjectModel;
-import org.nuiton.eugene.models.object.ObjectModelClass;
-import org.nuiton.eugene.models.object.ObjectModelInterface;
-import org.nuiton.eugene.models.object.ObjectModelModifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-import org.nuiton.eugene.models.object.ObjectModelParameter;
-import org.nuiton.i18n.I18n;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-
-/*{generator option: parentheses = false}*/
-
-/*{generator option: writeString = +}*/
-
-/**
- * This Template is used to create the skeleton of services for a final
- * application which using Topia.
- * <pre>
- * Generation from a model named 'App' :
- *
- * - AppContext : empty super interface to used in application UI. Can
- * be override in model if put in defaultPackage (ex : org.chorem.app) set
- * in maven-eugene-plugin configuration.
- *
- * - 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.
- *
- * - AppException : exception class which extends RuntimeException for all
- * technical exceptions which appears in service method. If you want to
- * manage some specific exceptions, you have to managed them in doCatch
- * implementation.
- *
- * Generation from interfaces with stereotype <<service>> :
- *
- * - Service : interface of the service defined in model.
- *
- * - 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.
- *
- * 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
- *
- * </pre>
- *
- * Created: 23 mars 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class BusinessTransformer extends ObjectModelTransformerToJava {
-
- protected String modelName;
-
- protected String defaultPackageName;
-
- protected String getContextInterfaceName() {
- return modelName + "Context";
- }
-
- protected String getContextImplementorInterfaceName() {
- return getContextInterfaceName() + "Implementor";
- }
-
- protected String getExceptionClassName() {
- return modelName + "Exception";
- }
-
- protected String getServiceAbstractClassName(String serviceName) {
- return serviceName + "Abstract";
- }
-
- @Override
- public void transformFromModel(ObjectModel model) {
- modelName = model.getName();
- defaultPackageName = getOutputProperties().
- getProperty(Template.PROP_DEFAULT_PACKAGE);
-
- ObjectModelInterface contextImplementor =
- model.getInterface(defaultPackageName + "." +
- getContextImplementorInterfaceName());
-
- ObjectModelInterface context =
- model.getInterface(defaultPackageName + "." +
- getContextInterfaceName());
-
- ObjectModelClass exception = createExceptionClass();
-
- ObjectModelInterface newContextImplementor =
- this.createInterface(getContextImplementorInterfaceName(),
- defaultPackageName);
- ObjectModelInterface newContext =
- this.createInterface(getContextInterfaceName(),
- defaultPackageName);
-
- this.addInterface(newContextImplementor,
- newContext.getQualifiedName());
-
- if (contextImplementor != null) {
- // Copy of defined operations
- // interfaces of contextImplementor are not copied
- copyInterfaceOperations(contextImplementor, newContextImplementor);
- }
-
- if (context != null) {
- // Copy of defined operations
- // interfaces of context are not copied
- copyInterfaceOperations(context, newContext);
- }
-
- ObjectModelOperation beginTransaction =
- this.addOperation(newContextImplementor,
- "beginTransaction", TopiaContext.class);
- this.addException(beginTransaction, TopiaException.class);
-
- ObjectModelOperation doCatch1 =
- this.addOperation(newContextImplementor, "doCatch", "void");
- this.addParameter(doCatch1, Exception.class, "eee");
- this.addParameter(doCatch1, String.class, "message");
- this.addParameter(doCatch1, "Object...", "args");
- this.addException(doCatch1, exception.getQualifiedName());
-
- ObjectModelOperation doCatch2 =
- this.addOperation(newContextImplementor, "doCatch", "void");
- this.addParameter(doCatch2, TopiaContext.class, "transaction");
- this.addParameter(doCatch2, Exception.class, "eee");
- this.addParameter(doCatch2, String.class, "message");
- this.addParameter(doCatch2, "Object...", "args");
- this.addException(doCatch2, exception.getQualifiedName());
-
- ObjectModelOperation doFinally =
- this.addOperation(newContextImplementor, "doFinally", "void");
- this.addParameter(doFinally, TopiaContext.class, "transaction");
- }
-
- protected ObjectModelClass createExceptionClass() {
-
- ObjectModelClass exception =
- this.createClass(getExceptionClassName(), defaultPackageName);
-
- this.setSuperClass(exception, RuntimeException.class);
- this.addAttribute(exception, "args", "Object[]", null,
- ObjectModelModifier.PROTECTED);
-
- ObjectModelOperation constructor =
- this.addConstructor(exception, ObjectModelModifier.PUBLIC);
-
- this.addParameter(constructor, Throwable.class, "eee");
- this.addParameter(constructor, String.class, "message");
- this.addParameter(constructor, "Object...", "args");
-
- setOperationBody(constructor, ""
- /*{
- super(message, eee);
- this.args = args;
- }*/
- );
-
- ObjectModelOperation getArgs =
- this.addOperation(exception, "getArgs", "Object[]",
- ObjectModelModifier.PUBLIC);
-
- setOperationBody(getArgs, ""
- /*{
- return args;
- }*/
- );
-
- ObjectModelOperation hasArgs =
- this.addOperation(exception, "hasArgs", "boolean",
- ObjectModelModifier.PUBLIC);
-
- setOperationBody(hasArgs, ""
- /*{
- return args.length > 0;
- }*/
- );
-
- return exception;
- }
-
- /**
- * Used to simply copy the {@code source} interface signature to the
- * {@code dest} interface.
- *
- * @param source interface
- * @param dest interface
- */
- protected void copyInterfaceOperations(ObjectModelInterface source,
- ObjectModelInterface dest) {
- for (ObjectModelOperation op : source.getOperations()) {
- ObjectModelOperation newOp =
- this.addOperation(dest,
- op.getName(), op.getReturnType());
- setDocumentation(newOp.getReturnParameter(),
- op.getReturnParameter().getDocumentation());
- for (ObjectModelParameter param : op.getParameters()) {
- ObjectModelParameter newParam =
- this.addParameter(newOp, param.getType(),
- param.getName());
- setDocumentation(newParam, param.getDocumentation());
- }
- for (String ex : op.getExceptions()) {
- this.addException(newOp, ex);
- }
- setDocumentation(newOp, op.getDocumentation());
- }
- }
-
- @Override
- public void transformFromInterface(ObjectModelInterface interfacez) {
- // skip ContextImplementor and Context interfaces
- if (!interfacez.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_SERVICE)) {
- return;
- }
-
- // Create INTERFACE
- ObjectModelInterface serviceInterface =
- this.createInterface(interfacez.getName(),
- interfacez.getPackageName());
-
- copyInterfaceOperations(interfacez, serviceInterface);
-
-
- // Create ABSTRACT CLASS
- ObjectModelClass service = this.createAbstractClass(
- getServiceAbstractClassName(interfacez.getName()),
- interfacez.getPackageName());
-
- this.addInterface(service, serviceInterface.getQualifiedName());
-
- // Add Logger
- // FIXME in EUGene, we want the default value not to be managed
- // for import.
-// this.addAttribute(service, "log",
-// Log.class,
-// "LogFactory.getLog(" + interfacez.getName() + ".class)",
-// ObjectModelModifier.PRIVATE,
-// ObjectModelModifier.STATIC,
-// ObjectModelModifier.FINAL);
- this.addAttribute(service, "log",
- Log.class, null,
- ObjectModelModifier.PRIVATE,
- ObjectModelModifier.FINAL);
-
- this.addImport(service, Log.class);
- this.addImport(service, LogFactory.class);
-
- String contextFqn = defaultPackageName + "." +
- getContextImplementorInterfaceName();
-
- // Add Context Attribute + constructor
- this.addAttribute(service, "context", contextFqn, null,
- ObjectModelModifier.PROTECTED);
-
- // Constructor
- ObjectModelOperation constructor =
- this.addConstructor(service, ObjectModelModifier.PUBLIC);
- //this.addParameter(constructor, contextFqn, "context");
- setOperationBody(constructor, ""
- /*{
- //this.context = context;
- // FIXME : must be fixed attribute value in EUGene
- this.log = LogFactory.getLog(<%=interfacez.getName()%>.class);
- }*/
- );
-
- ObjectModelOperation setContext =
- this.addOperation(service, "setContext", "void",
- ObjectModelModifier.PUBLIC);
- this.addParameter(setContext, contextFqn, "context");
- setOperationBody(setContext, ""
- /*{
- this.context = context;
- }*/
- );
-
- // Prepare operation generations
- String first = modelName.substring(0, 1);
- String serviceName =
- GeneratorUtil.toLowerCaseFirstLetter(interfacez.getName());
-
- this.addImport(service, TopiaContext.class);
- this.addImport(service, I18n.class);
- this.addImport(service, ArrayList.class);
-
- for (ObjectModelOperation op : interfacez.getOperations()) {
-
- // boolean to specify if the method need a transaction or not
- // Default set to true but can be override by a tagvalue on the
- // method
- boolean needTransaction = true;
-
- String transactionTag =
- op.getTagValue(TopiaGeneratorUtil.TAG_TRANSACTION);
-
- if (transactionTag != null) {
- needTransaction = Boolean.parseBoolean(transactionTag);
- }
-
- // boolean to specify if the method need error arguments or not
- // Default set to true but can be override by a tagvalue on the
- // method
- boolean needErrorArgs = true;
-
- String errorArgsTag =
- op.getTagValue(TopiaGeneratorUtil.TAG_ERROR_ARGS);
-
- if (errorArgsTag != null) {
- needErrorArgs = Boolean.parseBoolean(errorArgsTag);
- }
-
- // Implementation of interface operation
- ObjectModelOperation implOp =
- this.addOperation(service,
- op.getName(), op.getReturnType(),
- ObjectModelModifier.PUBLIC);
- this.addAnnotation(service, implOp, Override.class.getSimpleName());
-
- String opName = StringUtils.capitalize(op.getName());
-
- // Abstract operation to execute method content
- ObjectModelOperation abstOp =
- this.addOperation(service, "execute" + opName,
- op.getReturnType(),
- ObjectModelModifier.ABSTRACT,
- ObjectModelModifier.PROTECTED);
-
- // Throw all exception from abstract method
- // They will be catched by interface method to use doCatch
- this.addException(abstOp, Exception.class);
-
- if (needTransaction) {
- this.addParameter(abstOp, TopiaContext.class, "transaction");
- this.addException(abstOp, TopiaException.class);
- }
-
- String toStringAppend = "";
- String separatorLog = " : ";
- // Prepare operation parameters
- String opParams = "";
- String separatorParams = "";
- if (needErrorArgs) {
- opParams += "errorArgs";
- separatorParams = ", ";
- // Add errorArgs to abstract operation
- this.addParameter(abstOp,
- "java.util.List<Object>", "errorArgs");
- }
-
- // Copy other operation parameters
- for (ObjectModelParameter param : op.getParameters()) {
- String paramName = param.getName();
- this.addParameter(implOp, param.getType(), param.getName());
- this.addParameter(abstOp, param.getType(), param.getName());
-
- // Prepare Log
- toStringAppend +=
- "\n\t\t\t.append(\"" + separatorLog + paramName + " = \")" +
- ".append(" + paramName + ")";
- separatorLog = " _ ";
-
- // Prepare Abstract method params
- opParams += separatorParams + param.getName();
- separatorParams = ", ";
- }
-
- // Use buffer for operation body
- StringBuilder buffer = new StringBuilder();
-
- // Error key for i18n
- String errorKey = StringUtils.lowerCase(modelName) + ".error." +
- serviceName + "." + op.getName();
-
- String doCatchParams = "eee, I18n.n_(\"" + errorKey + "\")";
- doCatchParams += needErrorArgs ? ", errorArgs.toArray()" : "";
-
- // Return managment
- String opReturn = "";
- String finalReturn = "";
- if (!op.getReturnType().equals("void")) {
- opReturn = "return ";
- finalReturn = "return null;";
- }
-
- if (needErrorArgs) {
- // Init errorArgs
- buffer.append(""
- /*{
- List<Object> errorArgs = new ArrayList<Object>();
- }*/ );
- }
-
- if (needTransaction) {
- // Open the transaction
- buffer.append(""
- /*{
- TopiaContext transaction = null;
- try {
- transaction = context.beginTransaction();
- }*/
- );
- // Add transaction in the execute operation parameters
- // and doCatch parameters
- opParams = "transaction, " + opParams;
- doCatchParams = "transaction, " + doCatchParams;
- } else {
- buffer.append(""
- /*{
- try {
- }*/
- );
- }
-
- buffer.append(""
- /*{
- if (log.isDebugEnabled()) {
- String message = new StringBuilder("<%=first%>:[ <%=opName%> ]")<%=toStringAppend%>.
- toString();
- log.debug(message);
- }
-
- <%=opReturn%>execute<%=opName%>(<%=opParams%>); }*/);
-
- // Copy exceptions
- for (String ex : op.getExceptions()) {
- this.addException(implOp, ex);
- this.addException(abstOp, ex);
- // Add catch block for known exceptions we want to throw
- String exName = GeneratorUtil.getSimpleName(ex);
- buffer.append(""
- /*{
- } catch (<%=exName%> eee) {
- throw eee; }*/);
- }
-
- buffer.append(""
- /*{
- } catch (Exception eee) {
- context.doCatch(<%=doCatchParams%>); }*/);
-
- if (needTransaction) {
- // Finally block to close transaction
- buffer.append(""
- /*{
- } finally {
- context.doFinally(transaction); }*/);
- }
-
- buffer.append(""
- /*{
- }
- <%=finalReturn%>
- }*/
- );
-
- this.setOperationBody(implOp, buffer.toString());
- }
-
- }
-}
Copied: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java (from rev 1860, trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/BusinessTransformer.java)
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java (rev 0)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java 2010-03-31 08:27:58 UTC (rev 1862)
@@ -0,0 +1,594 @@
+
+package org.nuiton.topia.generator;
+
+import java.util.ArrayList;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.eugene.GeneratorUtil;
+import org.nuiton.eugene.Template;
+import org.nuiton.eugene.java.ObjectModelTransformerToJava;
+import org.nuiton.eugene.models.object.ObjectModel;
+import org.nuiton.eugene.models.object.ObjectModelClass;
+import org.nuiton.eugene.models.object.ObjectModelInterface;
+import org.nuiton.eugene.models.object.ObjectModelModifier;
+import org.nuiton.eugene.models.object.ObjectModelOperation;
+import org.nuiton.eugene.models.object.ObjectModelParameter;
+import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+
+/*{generator option: parentheses = false}*/
+
+/*{generator option: writeString = +}*/
+
+/**
+ * This Template is used to create the skeleton of services for a final
+ * application which using Topia.
+ * <div>
+ * Generation from a model named 'App' :
+ * <ul>
+ * <li>AppContext : empty super interface to used in application UI. Can
+ * be override in model if put in defaultPackage (ex : org.chorem.app) set
+ * in maven-eugene-plugin configuration.
+ * </li>
+ * <li><p>AppContextImplementor : interface which extends AppContext to add
+ * technical methods for the application. Generation of methods :</p>
+ * <p>* doCatch : used to catch all exception from a service method.</p>
+ * <p>* doFinally : used to finally the try/catch of a service method</p>
+ * <p>* beginTransaction : start the transaction using rootContext.</p>
+ * <p>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.</p>
+ * </li>
+ * <li>AppException : exception class which extends RuntimeException for all
+ * technical exceptions which appears in service method. If you want to
+ * manage some specific exceptions, you have to managed them in doCatch
+ * implementation.
+ * </li>
+ * </ul>
+ * </div>
+ * <div>
+ * Generation from interfaces with stereotype <<service>> :
+ * <ul>
+ * <li>Service : interface of the service defined in model.</li>
+ * <li><p>ServiceAbstract : abstract class which contains :</p>
+ * <p>* constructor with AppContextImplementor in argument</p>
+ * <p>* 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.</p>
+ * <p>* for each method : an abstract method used to execute the business
+ * code of the method : need to be implemented in subclass.</p>
+ * </li>
+ * </ul>
+ * </div>
+ * <div>
+ * Exemple of AppContextImpl :<br />
+ * <pre>
+ * 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;
+ * }
+ * ...
+ * }
+ * </pre>
+ * </div>
+ * <div>
+ * Exemple of ServiceImpl :<br />
+ * <pre>
+ * 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.
+ * }
+ * }
+ * </pre>
+ * <div>
+ * <h2>TAG_TRANSACTION</h2>
+ * <p>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).</p>
+ * </div>
+ * <div>
+ * <h2>TAG_ERROR_ARGS</h2>
+ * <p>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.</p>
+ * </div>
+ * <p>It is smooth, isn't it :p ?</p>
+ * <p>TODO : may be refactor to integrate JTA or webservice or may be not in this
+ * transformer.</p>
+ * <p>TODO : find a good way to change log level</p>
+ *
+ * Created: 23 mars 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ServiceTransformer extends ObjectModelTransformerToJava {
+
+ protected String modelName;
+
+ protected String defaultPackageName;
+
+ protected String getContextInterfaceName() {
+ return modelName + "Context";
+ }
+
+ protected String getContextImplementorInterfaceName() {
+ return getContextInterfaceName() + "Implementor";
+ }
+
+ protected String getExceptionClassName() {
+ return modelName + "Exception";
+ }
+
+ protected String getServiceAbstractClassName(String serviceName) {
+ return serviceName + "Abstract";
+ }
+
+ @Override
+ public void transformFromModel(ObjectModel model) {
+ modelName = model.getName();
+ defaultPackageName = getOutputProperties().
+ getProperty(Template.PROP_DEFAULT_PACKAGE);
+
+ ObjectModelInterface contextImplementor =
+ model.getInterface(defaultPackageName + "." +
+ getContextImplementorInterfaceName());
+
+ ObjectModelInterface context =
+ model.getInterface(defaultPackageName + "." +
+ getContextInterfaceName());
+
+ ObjectModelClass exception = createExceptionClass();
+
+ ObjectModelInterface newContextImplementor =
+ this.createInterface(getContextImplementorInterfaceName(),
+ defaultPackageName);
+ ObjectModelInterface newContext =
+ this.createInterface(getContextInterfaceName(),
+ defaultPackageName);
+
+ this.addInterface(newContextImplementor,
+ newContext.getQualifiedName());
+
+ if (contextImplementor != null) {
+ // Copy of defined operations
+ // interfaces of contextImplementor are not copied
+ copyInterfaceOperations(contextImplementor, newContextImplementor);
+ }
+
+ if (context != null) {
+ // Copy of defined operations
+ // interfaces of context are not copied
+ copyInterfaceOperations(context, newContext);
+ }
+
+ ObjectModelOperation beginTransaction =
+ this.addOperation(newContextImplementor,
+ "beginTransaction", TopiaContext.class);
+ this.addException(beginTransaction, TopiaException.class);
+
+ ObjectModelOperation doCatch1 =
+ this.addOperation(newContextImplementor, "doCatch", "void");
+ this.addParameter(doCatch1, Exception.class, "eee");
+ this.addParameter(doCatch1, String.class, "message");
+ this.addParameter(doCatch1, "Object...", "args");
+ this.addException(doCatch1, exception.getQualifiedName());
+
+ ObjectModelOperation doCatch2 =
+ this.addOperation(newContextImplementor, "doCatch", "void");
+ this.addParameter(doCatch2, TopiaContext.class, "transaction");
+ this.addParameter(doCatch2, Exception.class, "eee");
+ this.addParameter(doCatch2, String.class, "message");
+ this.addParameter(doCatch2, "Object...", "args");
+ this.addException(doCatch2, exception.getQualifiedName());
+
+ ObjectModelOperation doFinally =
+ this.addOperation(newContextImplementor, "doFinally", "void");
+ this.addParameter(doFinally, TopiaContext.class, "transaction");
+ }
+
+ protected ObjectModelClass createExceptionClass() {
+
+ ObjectModelClass exception =
+ this.createClass(getExceptionClassName(), defaultPackageName);
+
+ this.setSuperClass(exception, RuntimeException.class);
+ this.addAttribute(exception, "args", "Object[]", null,
+ ObjectModelModifier.PROTECTED);
+
+ ObjectModelOperation constructor =
+ this.addConstructor(exception, ObjectModelModifier.PUBLIC);
+
+ this.addParameter(constructor, Throwable.class, "eee");
+ this.addParameter(constructor, String.class, "message");
+ this.addParameter(constructor, "Object...", "args");
+
+ setOperationBody(constructor, ""
+ /*{
+ super(message, eee);
+ this.args = args;
+ }*/
+ );
+
+ ObjectModelOperation getArgs =
+ this.addOperation(exception, "getArgs", "Object[]",
+ ObjectModelModifier.PUBLIC);
+
+ setOperationBody(getArgs, ""
+ /*{
+ return args;
+ }*/
+ );
+
+ ObjectModelOperation hasArgs =
+ this.addOperation(exception, "hasArgs", "boolean",
+ ObjectModelModifier.PUBLIC);
+
+ setOperationBody(hasArgs, ""
+ /*{
+ return args.length > 0;
+ }*/
+ );
+
+ return exception;
+ }
+
+ /**
+ * Used to simply copy the {@code source} interface signature to the
+ * {@code dest} interface.
+ *
+ * @param source interface
+ * @param dest interface
+ */
+ protected void copyInterfaceOperations(ObjectModelInterface source,
+ ObjectModelInterface dest) {
+ setDocumentation(dest, source.getDocumentation());
+ for (ObjectModelOperation op : source.getOperations()) {
+ ObjectModelOperation newOp =
+ this.addOperation(dest,
+ op.getName(), op.getReturnType());
+ setDocumentation(newOp.getReturnParameter(),
+ op.getReturnParameter().getDocumentation());
+ for (ObjectModelParameter param : op.getParameters()) {
+ ObjectModelParameter newParam =
+ this.addParameter(newOp, param.getType(),
+ param.getName());
+ setDocumentation(newParam, param.getDocumentation());
+ }
+ for (String ex : op.getExceptions()) {
+ this.addException(newOp, ex);
+ }
+ setDocumentation(newOp, op.getDocumentation());
+ }
+ }
+
+ @Override
+ public void transformFromInterface(ObjectModelInterface interfacez) {
+ // skip ContextImplementor and Context interfaces
+ if (!interfacez.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_SERVICE)) {
+ return;
+ }
+
+ // Create INTERFACE
+ ObjectModelInterface serviceInterface =
+ this.createInterface(interfacez.getName(),
+ interfacez.getPackageName());
+
+ copyInterfaceOperations(interfacez, serviceInterface);
+
+
+ // Create ABSTRACT CLASS
+ ObjectModelClass service = this.createAbstractClass(
+ getServiceAbstractClassName(interfacez.getName()),
+ interfacez.getPackageName());
+
+ this.addInterface(service, serviceInterface.getQualifiedName());
+
+ // Add Logger
+ // FIXME in EUGene, we want the default value not to be managed
+ // for import.
+// this.addAttribute(service, "log",
+// Log.class,
+// "LogFactory.getLog(" + interfacez.getName() + ".class)",
+// ObjectModelModifier.PRIVATE,
+// ObjectModelModifier.STATIC,
+// ObjectModelModifier.FINAL);
+ this.addAttribute(service, "log",
+ Log.class, null,
+ ObjectModelModifier.PRIVATE,
+ ObjectModelModifier.FINAL);
+
+ this.addImport(service, Log.class);
+ this.addImport(service, LogFactory.class);
+
+ String contextFqn = defaultPackageName + "." +
+ getContextImplementorInterfaceName();
+
+ // Add Context Attribute + constructor
+ this.addAttribute(service, "context", contextFqn, null,
+ ObjectModelModifier.PROTECTED);
+
+ // Constructor
+ ObjectModelOperation constructor =
+ this.addConstructor(service, ObjectModelModifier.PUBLIC);
+ //this.addParameter(constructor, contextFqn, "context");
+ setOperationBody(constructor, ""
+ /*{
+ //this.context = context;
+ // FIXME : must be fixed attribute value in EUGene
+ this.log = LogFactory.getLog(<%=interfacez.getName()%>.class);
+ }*/
+ );
+
+ ObjectModelOperation setContext =
+ this.addOperation(service, "setContext", "void",
+ ObjectModelModifier.PUBLIC);
+ this.addParameter(setContext, contextFqn, "context");
+ setOperationBody(setContext, ""
+ /*{
+ this.context = context;
+ }*/
+ );
+
+ // Prepare operation generations
+ String first = modelName.substring(0, 1);
+ String serviceName =
+ GeneratorUtil.toLowerCaseFirstLetter(interfacez.getName());
+
+ this.addImport(service, TopiaContext.class);
+ this.addImport(service, I18n.class);
+ this.addImport(service, ArrayList.class);
+
+ for (ObjectModelOperation op : interfacez.getOperations()) {
+
+ // boolean to specify if the method need a transaction or not
+ // Default set to true but can be override by a tagvalue on the
+ // method
+ boolean needTransaction = true;
+
+ String transactionTag =
+ op.getTagValue(TopiaGeneratorUtil.TAG_TRANSACTION);
+
+ if (transactionTag != null) {
+ needTransaction = Boolean.parseBoolean(transactionTag);
+ }
+
+ // boolean to specify if the method need error arguments or not
+ // Default set to true but can be override by a tagvalue on the
+ // method
+ boolean needErrorArgs = true;
+
+ String errorArgsTag =
+ op.getTagValue(TopiaGeneratorUtil.TAG_ERROR_ARGS);
+
+ if (errorArgsTag != null) {
+ needErrorArgs = Boolean.parseBoolean(errorArgsTag);
+ }
+
+ // Implementation of interface operation
+ ObjectModelOperation implOp =
+ this.addOperation(service,
+ op.getName(), op.getReturnType(),
+ ObjectModelModifier.PUBLIC);
+ this.addAnnotation(service, implOp, Override.class.getSimpleName());
+
+ String opName = StringUtils.capitalize(op.getName());
+
+ // Abstract operation to execute method content
+ ObjectModelOperation abstOp =
+ this.addOperation(service, "execute" + opName,
+ op.getReturnType(),
+ ObjectModelModifier.ABSTRACT,
+ ObjectModelModifier.PROTECTED);
+
+ // Throw all exception from abstract method
+ // They will be catched by interface method to use doCatch
+ this.addException(abstOp, Exception.class);
+
+ if (needTransaction) {
+ this.addParameter(abstOp, TopiaContext.class, "transaction");
+ this.addException(abstOp, TopiaException.class);
+ }
+
+ String toStringAppend = "";
+ String separatorLog = " : ";
+ // Prepare operation parameters
+ String opParams = "";
+ String separatorParams = "";
+ if (needErrorArgs) {
+ opParams += "errorArgs";
+ separatorParams = ", ";
+ // Add errorArgs to abstract operation
+ this.addParameter(abstOp,
+ "java.util.List<Object>", "errorArgs");
+ }
+
+ // Copy other operation parameters
+ for (ObjectModelParameter param : op.getParameters()) {
+ String paramName = param.getName();
+ this.addParameter(implOp, param.getType(), param.getName());
+ this.addParameter(abstOp, param.getType(), param.getName());
+
+ // Prepare Log
+ toStringAppend +=
+ "\n\t\t\t.append(\"" + separatorLog + paramName + " = \")" +
+ ".append(" + paramName + ")";
+ separatorLog = " _ ";
+
+ // Prepare Abstract method params
+ opParams += separatorParams + param.getName();
+ separatorParams = ", ";
+ }
+
+ // Use buffer for operation body
+ StringBuilder buffer = new StringBuilder();
+
+ // Error key for i18n
+ String errorKey = StringUtils.lowerCase(modelName) + ".error." +
+ serviceName + "." + op.getName();
+
+ String doCatchParams = "eee, I18n.n_(\"" + errorKey + "\")";
+ doCatchParams += needErrorArgs ? ", errorArgs.toArray()" : "";
+
+ // Return managment
+ String opReturn = "";
+ String finalReturn = "";
+ if (!op.getReturnType().equals("void")) {
+ opReturn = "return ";
+ finalReturn = "return null;";
+ }
+
+ if (needErrorArgs) {
+ // Init errorArgs
+ buffer.append(""
+ /*{
+ List<Object> errorArgs = new ArrayList<Object>();
+ }*/ );
+ }
+
+ if (needTransaction) {
+ // Open the transaction
+ buffer.append(""
+ /*{
+ TopiaContext transaction = null;
+ try {
+ transaction = context.beginTransaction();
+ }*/
+ );
+ // Add transaction in the execute operation parameters
+ // and doCatch parameters
+ opParams = "transaction, " + opParams;
+ doCatchParams = "transaction, " + doCatchParams;
+ } else {
+ buffer.append(""
+ /*{
+ try {
+ }*/
+ );
+ }
+
+ buffer.append(""
+ /*{
+ if (log.isDebugEnabled()) {
+ String message = new StringBuilder("<%=first%>:[ <%=opName%> ]")<%=toStringAppend%>.
+ toString();
+ log.debug(message);
+ }
+
+ <%=opReturn%>execute<%=opName%>(<%=opParams%>); }*/);
+
+ // Copy exceptions
+ for (String ex : op.getExceptions()) {
+ this.addException(implOp, ex);
+ this.addException(abstOp, ex);
+ // Add catch block for known exceptions we want to throw
+ String exName = GeneratorUtil.getSimpleName(ex);
+ buffer.append(""
+ /*{
+ } catch (<%=exName%> eee) {
+ throw eee; }*/);
+ }
+
+ buffer.append(""
+ /*{
+ } catch (Exception eee) {
+ context.doCatch(<%=doCatchParams%>); }*/);
+
+ if (needTransaction) {
+ // Finally block to close transaction
+ buffer.append(""
+ /*{
+ } finally {
+ context.doFinally(transaction); }*/);
+ }
+
+ buffer.append(""
+ /*{
+ }
+ <%=finalReturn%>
+ }*/
+ );
+
+ this.setOperationBody(implOp, buffer.toString());
+ }
+
+ }
+}
Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/ServiceTransformer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
1
0