001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.core.schema;
018:
019: import java.lang.annotation.Annotation;
020: import java.lang.reflect.Method;
021: import java.util.Collection;
022:
023: import org.romaframework.core.aspect.Aspect;
024: import org.romaframework.core.aspect.AspectManager;
025: import org.romaframework.core.schema.config.SchemaConfiguration;
026: import org.romaframework.xml.config.XmlConfigActionType;
027:
028: /**
029: * Represent a method of a class.
030: *
031: * @author Luca Garulli (luca.garulli@assetdata.it)
032: */
033: public class SchemaAction extends SchemaElement {
034: protected Method method;
035:
036: public SchemaAction(SchemaClassDefinition iEntity) {
037: super (iEntity);
038: }
039:
040: @Override
041: public String toString() {
042: return name + " (action:" + method + ")";
043: }
044:
045: @Override
046: public Object clone() throws CloneNotSupportedException {
047: SchemaAction copy = (SchemaAction) super .clone();
048: copy.method = method;
049:
050: return copy;
051: }
052:
053: public void configure(Method iMethod) {
054: method = iMethod;
055: name = iMethod.getName();
056:
057: processConfiguration();
058: }
059:
060: @Override
061: protected void processConfiguration() {
062: // BROWSE ALL ASPECTS
063: Collection<Aspect> aspects = AspectManager.getInstance()
064: .getConfigurationValues();
065:
066: String annotationName;
067: Annotation annotationAction;
068: Annotation annotationGeneric;
069:
070: for (Aspect aspect : aspects) {
071: if (method != null) {
072: // COMPOSE ANNOTATION NAME BY ASPECT
073: annotationName = aspect.aspectName();
074: annotationName = Character.toUpperCase(annotationName
075: .charAt(0))
076: + annotationName.substring(1);
077:
078: annotationAction = searchForAnnotation(method,
079: annotationName + "Action", aspect.aspectName());
080: annotationGeneric = searchForAnnotation(method,
081: annotationName, aspect.aspectName());
082: } else {
083: annotationAction = null;
084: annotationGeneric = null;
085: }
086:
087: SchemaConfiguration classDescriptor = entity
088: .getSchemaClass().getDescriptor();
089:
090: XmlConfigActionType parentDescriptor = null;
091:
092: if (classDescriptor != null
093: && classDescriptor.getType() != null
094: && classDescriptor.getType().getActions() != null) {
095: // SEARCH FORM DEFINITION IN DESCRIPTOR
096: XmlConfigActionType[] allActions = classDescriptor
097: .getType().getActions().getActionArray();
098:
099: XmlConfigActionType tmpDescr = null;
100: for (short fieldNum = 0; fieldNum < allActions.length; ++fieldNum) {
101: tmpDescr = allActions[fieldNum];
102: if (tmpDescr.getName().equals(name)) {
103: // FOUND XML NODE
104: parentDescriptor = tmpDescr;
105: break;
106: }
107: }
108: }
109: // CONFIGURE THE SCHEMA OBJECT WITH CURRENT ASPECT
110: aspect.configAction(this , annotationAction,
111: annotationGeneric, parentDescriptor);
112: }
113: }
114:
115: public Method getMethod() {
116: return method;
117: }
118:
119: public static boolean ignoreMethod(String iItem, String iMethodName) {
120: if (iItem.endsWith("*")) {
121: if (iMethodName.startsWith(iItem.substring(0, iItem
122: .length() - 1)))
123: return true;
124: } else if (iItem.startsWith("*")) {
125: if (iMethodName.endsWith(iItem.substring(1)))
126: return true;
127: } else {
128: if (iMethodName.equals(iItem))
129: return true;
130: }
131:
132: return false;
133: }
134: }
|