Skip to content

Commit

Permalink
First refactoring import.
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed May 30, 2011
1 parent 597dc7a commit 1cc180c
Show file tree
Hide file tree
Showing 63 changed files with 2,061 additions and 1,202 deletions.
6 changes: 6 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<project basedir="." default="compile" name="roma-core">

<import file="roma-build.xml" />

</project>
9 changes: 9 additions & 0 deletions ivy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="org.romaframework" module="roma-frontend" />
<configurations defaultconfmapping="*->*,!sources,!javadoc,!optional"></configurations>
<dependencies>
<dependency org="org.romaframework" name="roma-core" rev="latest.integration" />
<dependency org="commons-pool" name="commons-pool" rev="latest.integration" />
</dependencies>
</ivy-module>
8 changes: 8 additions & 0 deletions roma-module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties PUBLIC "JAVA PROPERTIES" "http://www.romaframework.org/schema/properties.dtd">
<properties>
<comment>Frontend basic module shared between all view aspects</comment>
<entry key="name">FRONTEND module</entry>
<entry key="version">2.2.0</entry>
<entry key="repository">romaframework</entry>
</properties>
74 changes: 16 additions & 58 deletions src/org/romaframework/aspect/data/DataBindingAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.romaframework.aspect.data.annotation.DataField;
import org.romaframework.aspect.data.feature.DataBindingFeatures;
import org.romaframework.aspect.data.feature.DataFieldFeatures;
import org.romaframework.core.Roma;
import org.romaframework.core.aspect.Aspect;
import org.romaframework.core.exception.ConfigurationNotFoundException;
Expand All @@ -43,7 +42,6 @@
import org.romaframework.core.schema.xmlannotations.XmlClassAnnotation;
import org.romaframework.core.schema.xmlannotations.XmlEventAnnotation;
import org.romaframework.core.schema.xmlannotations.XmlFieldAnnotation;
import org.romaframework.core.util.DynaBean;

/**
* @author luca.molino
Expand Down Expand Up @@ -74,21 +72,10 @@ public void beginConfigClass(SchemaClassDefinition iClass) {
public void configClass(SchemaClassDefinition iClass, Annotation iAnnotation, XmlClassAnnotation iNode) {
}

public void configField(SchemaField iField, Annotation iFieldAnnotation, Annotation iGenericAnnotation,
Annotation iGetterAnnotation, XmlFieldAnnotation iNode) {
DynaBean features = iField.getFeatures(ASPECT_NAME);
if (features == null) {
// CREATE EMPTY FEATURES
features = new DataBindingFeatures();
iField.setFeatures(ASPECT_NAME, features);
}
readFieldAnnotation(iGenericAnnotation, features, iField);
readFieldAnnotation(iFieldAnnotation, features, iField);
readFieldAnnotation(iGetterAnnotation, features, iField);
public void configField(SchemaField iField, Annotation iFieldAnnotation, Annotation iGenericAnnotation, Annotation iGetterAnnotation, XmlFieldAnnotation iNode) {
}

public void configAction(SchemaClassElement iAction, Annotation iActionAnnotation, Annotation iGenericAnnotation,
XmlActionAnnotation iNode) {
public void configAction(SchemaClassElement iAction, Annotation iActionAnnotation, Annotation iGenericAnnotation, XmlActionAnnotation iNode) {
}

public void configEvent(SchemaEvent iEvent, Annotation iEventAnnotation, Annotation iGenericAnnotation, XmlEventAnnotation iNode) {
Expand All @@ -100,15 +87,12 @@ public void endConfigClass(SchemaClassDefinition iClass) {
public void onCreate(SchemaObject iObject) {
if (iObject.getInstance() != null) {
for (SchemaField schemaField : iObject.getFields().values()) {
DynaBean features = schemaField.getFeatures(ASPECT_NAME);
if (features == null)
continue;
Class<?> repositoryClass = (Class<?>) features.getAttribute(DataBindingFeatures.REPOSITORY);
Class<?> repositoryClass = (Class<?>) schemaField.getFeature(DataFieldFeatures.REPOSITORY);
if (repositoryClass == null)
continue;
String methodName = (String) features.getAttribute(DataBindingFeatures.METHOD);
String[] searchFields = (String[]) features.getAttribute(DataBindingFeatures.SEARCH_FIELDS);
int limit = ((Integer) features.getAttribute(DataBindingFeatures.LIMIT)).intValue();
String methodName = schemaField.getFeature(DataFieldFeatures.METHOD);
String[] searchFields = schemaField.getFeature(DataFieldFeatures.SEARCH_FIELDS);
int limit = schemaField.getFeature(DataFieldFeatures.LIMIT).intValue();
Method methodToCall = getMethod(repositoryClass, methodName, searchFields);
try {
Object repository = repositoryClass.newInstance();
Expand All @@ -128,35 +112,12 @@ public Object getUnderlyingComponent() {
return null;
}

protected void readFieldAnnotation(Annotation iAnnotation, DynaBean iFeatures, SchemaField iField) {
DataField annotation = (DataField) iAnnotation;

if (annotation != null) {
if (annotation.repository() != Object.class) {
iFeatures.setAttribute(DataBindingFeatures.REPOSITORY, annotation.repository());
} else {
if (iField.getLanguageType() == null) {
throw new ConfigurationNotFoundException("Configuration for field " + iField.getName() + " not found");
} else {
String repositoryClassName = getRepositoryClassName(iField);
Class<?> repositoryClass = getRepositoryClass(repositoryClassName);
iFeatures.setAttribute(DataBindingFeatures.REPOSITORY, repositoryClass);
}
}
iFeatures.setAttribute(DataBindingFeatures.METHOD, annotation.method());
iFeatures.setAttribute(DataBindingFeatures.SEARCH_FIELDS, annotation.searchFields());
iFeatures.setAttribute(DataBindingFeatures.LIMIT, annotation.limit());
}
}

protected Class<?> getRepositoryClass(String repositoryClassName) {
Class<?> repositoryClass = Roma.repository(repositoryClassName) != null ? Roma.repository(repositoryClassName).getClass()
: null;
Class<?> repositoryClass = Roma.repository(repositoryClassName) != null ? Roma.repository(repositoryClassName).getClass() : null;
if (repositoryClass == null) {
repositoryClassName = configuration.get(repositoryClassName);
if (repositoryClassName == null || repositoryClassName.equals("")) {
throw new ConfigurationNotFoundException("Error loading repository class " + repositoryClassName
+ ": configuration not found.");
throw new ConfigurationNotFoundException("Error loading repository class " + repositoryClassName + ": configuration not found.");
} else {
try {
repositoryClass = Class.forName(repositoryClassName);
Expand Down Expand Up @@ -191,25 +152,22 @@ protected String getRepositoryClassName(SchemaField iField) {
return repositoryClassName;
}

protected List<?> setResult(SchemaObject iObject, SchemaField schemaField, Class<?> repositoryClass, String methodName,
int limit, Method methodToCall, Object repository, String[] searchFields) {
protected List<?> setResult(SchemaObject iObject, SchemaField schemaField, Class<?> repositoryClass, String methodName, int limit, Method methodToCall,
Object repository, String[] searchFields) {
Object[] args = new Object[searchFields.length];
for (int i = 0; i < searchFields.length; i++) {
String searchFieldName = searchFields[i];
if (iObject.getField(searchFieldName) == null)
throw new ConfigurationNotFoundException("Field '" + searchFieldName + "' in class " + iObject.getSchemaClass().getName()
+ " not found");
throw new ConfigurationNotFoundException("Field '" + searchFieldName + "' in class " + iObject.getSchemaClass().getName() + " not found");
args[i] = iObject.getField(searchFieldName).getValue(iObject.getInstance());
}
List<?> result = null;
try {
result = (List<?>) methodToCall.invoke(repository, args);
} catch (InvocationTargetException ite) {
throw new ConfigurationNotFoundException("Error invoking method " + methodName + " of instance " + repositoryClass.getName(),
ite);
throw new ConfigurationNotFoundException("Error invoking method " + methodName + " of instance " + repositoryClass.getName(), ite);
} catch (IllegalAccessException iae) {
throw new ConfigurationNotFoundException("Error invoking method " + methodName + " of instance " + repositoryClass.getName(),
iae);
throw new ConfigurationNotFoundException("Error invoking method " + methodName + " of instance " + repositoryClass.getName(), iae);
}
if (limit > 0 && result.size() > limit) {
schemaField.setValue(iObject.getInstance(), result.subList(0, limit));
Expand All @@ -228,8 +186,8 @@ protected Method getMethod(Class<?> repositoryClass, String methodName, String[]
}
}
if (methodToCall == null) {
throw new ConfigurationNotFoundException("Method '" + methodName + "' with " + searchFields.length
+ " parameters in repository '" + repositoryClass.getName() + "' not found.");
throw new ConfigurationNotFoundException("Method '" + methodName + "' with " + searchFields.length + " parameters in repository '"
+ repositoryClass.getName() + "' not found.");
}
return methodToCall;
}
Expand Down
30 changes: 30 additions & 0 deletions src/org/romaframework/aspect/data/feature/DataFieldFeatures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2006 Luca Garulli (luca.garulli--at--assetdata.it)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.romaframework.aspect.data.feature;

import org.romaframework.aspect.data.DataBindingAspect;
import org.romaframework.core.schema.Feature;
import org.romaframework.core.schema.FeatureType;

public class DataFieldFeatures {

public static final Feature<Class> REPOSITORY = new Feature<Class>(DataBindingAspect.ASPECT_NAME, "repository", FeatureType.FIELD, Class.class);
public static final Feature<String> METHOD = new Feature<String>(DataBindingAspect.ASPECT_NAME, "method", FeatureType.FIELD, String.class);
public static final Feature<String[]> SEARCH_FIELDS = new Feature<String[]>(DataBindingAspect.ASPECT_NAME, "searchFields", FeatureType.FIELD, String[].class);
public static final Feature<Long> LIMIT = new Feature<Long>(DataBindingAspect.ASPECT_NAME, "limit", FeatureType.FIELD, Long.class);

}
79 changes: 29 additions & 50 deletions src/org/romaframework/aspect/flow/FlowAspectAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.romaframework.aspect.flow.feature.FlowActionFeatures;
import org.romaframework.core.Roma;
import org.romaframework.core.flow.Controller;
import org.romaframework.core.flow.UserObjectEventListener;
import org.romaframework.core.flow.SchemaActionListener;
import org.romaframework.core.module.SelfRegistrantConfigurableModule;
import org.romaframework.core.schema.SchemaClass;
import org.romaframework.core.schema.SchemaClassDefinition;
Expand All @@ -32,19 +32,17 @@
import org.romaframework.core.schema.xmlannotations.XmlActionAnnotation;
import org.romaframework.core.schema.xmlannotations.XmlAspectAnnotation;
import org.romaframework.core.schema.xmlannotations.XmlEventAnnotation;
import org.romaframework.core.util.DynaBean;

/**
* Abstract implementation for Flow Aspect.
*
* @author Luca Garulli (luca.garulli--at--assetdata.it)
*/
public abstract class FlowAspectAbstract extends SelfRegistrantConfigurableModule<String> implements FlowAspect,
UserObjectEventListener {
public abstract class FlowAspectAbstract extends SelfRegistrantConfigurableModule<String> implements FlowAspect, SchemaActionListener {

@Override
public void startup() {
Controller.getInstance().registerListener(UserObjectEventListener.class, this);
Controller.getInstance().registerListener(SchemaActionListener.class, this);
}

public void beginConfigClass(SchemaClassDefinition iClass) {
Expand All @@ -53,39 +51,31 @@ public void beginConfigClass(SchemaClassDefinition iClass) {
public void endConfigClass(SchemaClassDefinition iClass) {
}

public void configAction(SchemaClassElement iAction, Annotation iActionAnnotation, Annotation iGenericAnnotation,
XmlActionAnnotation iXmlNode) {
DynaBean features = iAction.getFeatures(ASPECT_NAME);
if (features == null) {
// CREATE EMPTY FEATURES
features = new FlowActionFeatures();
iAction.setFeatures(ASPECT_NAME, features);
}

readActionAnnotation(iAction, iActionAnnotation, features);
public void configAction(SchemaClassElement iAction, Annotation iActionAnnotation, Annotation iGenericAnnotation, XmlActionAnnotation iXmlNode) {
readActionAnnotation(iAction, iActionAnnotation);
readActionXml(iAction, iXmlNode);
setActionDefaults(iAction);
}

private void readActionAnnotation(SchemaClassElement iAction, Annotation iAnnotation, DynaBean features) {
private void readActionAnnotation(SchemaClassElement iAction, Annotation iAnnotation) {
FlowAction annotation = (FlowAction) iAnnotation;

if (annotation != null) {
// PROCESS ANNOTATIONS
// ANNOTATION ATTRIBUTES (IF DEFINED) OVERWRITE DEFAULT VALUES
if (annotation != null) {
if (!annotation.next().equals(Object.class))
features.setAttribute(FlowActionFeatures.NEXT, Roma.schema().getSchemaClass(annotation.next()));
iAction.setFeature(FlowActionFeatures.NEXT, Roma.schema().getSchemaClass(annotation.next()));
if (!annotation.position().equals(AnnotationConstants.DEF_VALUE))
features.setAttribute(FlowActionFeatures.POSITION, annotation.position());
iAction.setFeature(FlowActionFeatures.POSITION, annotation.position());
if (!annotation.error().equals(AnnotationConstants.DEF_VALUE))
features.setAttribute(FlowActionFeatures.ERROR, annotation.error());
iAction.setFeature(FlowActionFeatures.ERROR, annotation.error());
if (annotation.back() != AnnotationConstants.UNSETTED)
features.setAttribute(FlowActionFeatures.BACK, annotation.back() == AnnotationConstants.TRUE);
iAction.setFeature(FlowActionFeatures.BACK, annotation.back() == AnnotationConstants.TRUE);
if (annotation.confirmRequired() != AnnotationConstants.UNSETTED)
features.setAttribute(FlowActionFeatures.CONFIRM_REQUIRED, annotation.confirmRequired() == AnnotationConstants.TRUE);
iAction.setFeature(FlowActionFeatures.CONFIRM_REQUIRED, annotation.confirmRequired() == AnnotationConstants.TRUE);
if (!annotation.confirmMessage().equals(AnnotationConstants.DEF_VALUE))
features.setAttribute(FlowActionFeatures.CONFIRM_MESSAGE, annotation.confirmMessage());
iAction.setFeature(FlowActionFeatures.CONFIRM_MESSAGE, annotation.confirmMessage());
}
}
}
Expand All @@ -97,51 +87,40 @@ private void readActionXml(SchemaClassElement iAction, XmlActionAnnotation iXmlN
if (iXmlNode == null || iXmlNode.aspect(ASPECT_NAME) == null)
return;

DynaBean features = iAction.getFeatures(ASPECT_NAME);

XmlAspectAnnotation descriptor = iXmlNode.aspect(ASPECT_NAME);

if (descriptor != null) {
String next = descriptor.getAttribute(FlowActionFeatures.NEXT);
String next = descriptor.getAttribute(FlowActionFeatures.NEXT.getName());
if (next != null) {
SchemaClass clazz = Roma.schema().getSchemaClass(next);
if (clazz != null && clazz.getSchemaClass() != null) {
features.setAttribute(FlowActionFeatures.NEXT, clazz);
iAction.setFeature(FlowActionFeatures.NEXT, clazz);
}
}
String position = descriptor.getAttribute(FlowActionFeatures.POSITION);
if (position != null) {
features.setAttribute(FlowActionFeatures.POSITION, position);
}
String error = descriptor.getAttribute(FlowActionFeatures.ERROR);
String position = descriptor.getAttribute(FlowActionFeatures.POSITION.getName());
if (position != null)
iAction.setFeature(FlowActionFeatures.POSITION, position);

String error = descriptor.getAttribute(FlowActionFeatures.ERROR.getName());
if (error != null)
features.setAttribute(FlowActionFeatures.ERROR, error);
iAction.setFeature(FlowActionFeatures.ERROR, error);

String back = descriptor.getAttribute(FlowActionFeatures.BACK);
String back = descriptor.getAttribute(FlowActionFeatures.BACK.getName());
if (back != null)
features.setAttribute(FlowActionFeatures.BACK, new Boolean(back));
iAction.setFeature(FlowActionFeatures.BACK, new Boolean(back));

String confirmRequired = descriptor.getAttribute(FlowActionFeatures.CONFIRM_REQUIRED);
if (confirmRequired != null) {
features.setAttribute(FlowActionFeatures.CONFIRM_REQUIRED, new Boolean(confirmRequired));
}
String confirmRequired = descriptor.getAttribute(FlowActionFeatures.CONFIRM_REQUIRED.getName());
if (confirmRequired != null)
iAction.setFeature(FlowActionFeatures.CONFIRM_REQUIRED, new Boolean(confirmRequired));

String confirmMessage = descriptor.getAttribute(FlowActionFeatures.CONFIRM_MESSAGE);
String confirmMessage = descriptor.getAttribute(FlowActionFeatures.CONFIRM_MESSAGE.getName());
if (confirmMessage != null)
features.setAttribute(FlowActionFeatures.CONFIRM_MESSAGE, confirmMessage);
iAction.setFeature(FlowActionFeatures.CONFIRM_MESSAGE, confirmMessage);
}
}

public void configEvent(SchemaEvent iEvent, Annotation iEventAnnotation, Annotation iGenericAnnotation,
XmlEventAnnotation iXmlNode) {
DynaBean features = iEvent.getFeatures(ASPECT_NAME);
if (features == null) {
// CREATE EMPTY FEATURES
features = new FlowActionFeatures();
iEvent.setFeatures(ASPECT_NAME, features);
}

readActionAnnotation(iEvent, iEventAnnotation, features);
public void configEvent(SchemaEvent iEvent, Annotation iEventAnnotation, Annotation iGenericAnnotation, XmlEventAnnotation iXmlNode) {
readActionAnnotation(iEvent, iEventAnnotation);
readActionXml(iEvent, iXmlNode);
setActionDefaults(iEvent);
}
Expand Down
34 changes: 17 additions & 17 deletions src/org/romaframework/aspect/flow/feature/FlowActionFeatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

package org.romaframework.aspect.flow.feature;

import org.romaframework.core.util.DynaBean;
import org.romaframework.aspect.flow.FlowAspectAbstract;
import org.romaframework.core.schema.Feature;
import org.romaframework.core.schema.FeatureType;
import org.romaframework.core.schema.SchemaClass;

public class FlowActionFeatures extends DynaBean {
public FlowActionFeatures() {
defineAttribute(NEXT, null);
defineAttribute(POSITION, null);
defineAttribute(ERROR, null);
defineAttribute(BACK, null);
defineAttribute(CONFIRM_REQUIRED, null);
defineAttribute(CONFIRM_MESSAGE, null);
}
public class FlowActionFeatures {

public static final Feature<SchemaClass> NEXT = new Feature<SchemaClass>(FlowAspectAbstract.ASPECT_NAME, "next", FeatureType.ACTION,
SchemaClass.class);
public static final Feature<String> POSITION = new Feature<String>(FlowAspectAbstract.ASPECT_NAME, "position", FeatureType.ACTION,
String.class);
public static final Feature<String> ERROR = new Feature<String>(FlowAspectAbstract.ASPECT_NAME, "error", FeatureType.ACTION, String.class);
public static final Feature<Boolean> BACK = new Feature<Boolean>(FlowAspectAbstract.ASPECT_NAME, "back", FeatureType.ACTION, Boolean.class);

public static final Feature<Boolean> CONFIRM_REQUIRED = new Feature<Boolean>(FlowAspectAbstract.ASPECT_NAME, "confirmRequired", FeatureType.ACTION,
Boolean.class);
public static final Feature<String> CONFIRM_MESSAGE = new Feature<String>(FlowAspectAbstract.ASPECT_NAME, "confirmMessage", FeatureType.ACTION,
String.class);

public static final String NEXT = "next";
public static final String POSITION = "position";
public static final String ERROR = "error";
public static final String BACK = "back";

public static final String CONFIRM_REQUIRED = "confirmRequired";
public static final String CONFIRM_MESSAGE = "confirmMessage";
}
Loading

0 comments on commit 1cc180c

Please sign in to comment.