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.Utility;
024: import org.romaframework.core.aspect.Aspect;
025: import org.romaframework.core.aspect.AspectManager;
026: import org.romaframework.core.schema.config.SchemaConfiguration;
027: import org.romaframework.xml.config.XmlConfigActionType;
028:
029: /**
030: * Represent an event of a class.
031: *
032: * @author Luca Garulli (luca.garulli@assetdata.it)
033: */
034: public class SchemaEvent extends SchemaAction {
035: public SchemaEvent(SchemaClassDefinition iEntity, String iName) {
036: super (iEntity);
037: name = iName;
038: }
039:
040: @Override
041: public String toString() {
042: return name + " (event:" + method + ")";
043: }
044:
045: @Override
046: public void configure(Method iMethod) {
047: method = iMethod;
048: processConfiguration();
049: }
050:
051: @Override
052: protected void processConfiguration() {
053: // BROWSE ALL ASPECTS
054: Collection<Aspect> aspects = AspectManager.getInstance()
055: .getConfigurationValues();
056:
057: String annotationName;
058: Annotation annotationAction;
059: Annotation annotationGeneric;
060:
061: for (Aspect aspect : aspects) {
062: if (method != null) {
063: // COMPOSE ANNOTATION NAME BY ASPECT
064: annotationName = aspect.aspectName();
065: annotationName = Character.toUpperCase(annotationName
066: .charAt(0))
067: + annotationName.substring(1);
068:
069: annotationAction = searchForAnnotation(method,
070: annotationName + "Action", aspect.aspectName());
071: annotationGeneric = searchForAnnotation(method,
072: annotationName, aspect.aspectName());
073: } else {
074: annotationAction = null;
075: annotationGeneric = null;
076: }
077:
078: SchemaConfiguration classDescriptor = entity
079: .getSchemaClass().getDescriptor();
080:
081: if (classDescriptor != null
082: && classDescriptor.getType() != null
083: && classDescriptor.getType().getActions() != null) {
084: // SEARCH FORM DEFINITION IN DESCRIPTOR
085: XmlConfigActionType[] allActions = classDescriptor
086: .getType().getActions().getActionArray();
087:
088: XmlConfigActionType tmpDescr = null;
089: for (short fieldNum = 0; fieldNum < allActions.length; ++fieldNum) {
090: tmpDescr = allActions[fieldNum];
091: if (tmpDescr.getName().equals(name)) {
092: // FOUND XML NODE
093: break;
094: }
095: }
096: }
097: // CONFIGURE THE SCHEMA OBJECT WITH CURRENT ASPECT
098: aspect.configAction(this, annotationAction,
099: annotationGeneric, null);
100: }
101: }
102: }
|