SchemaEvent.java :  » Web-Framework » roma-webwizard » org » romaframework » core » schema » Java Open Source

Java Open Source » Web Framework » roma webwizard 
roma webwizard » org » romaframework » core » schema » SchemaEvent.java
/*
 * Copyright 2006 Luca Garulli (luca.garulli@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.core.schema;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;

import org.romaframework.core.Utility;
import org.romaframework.core.aspect.Aspect;
import org.romaframework.core.aspect.AspectManager;
import org.romaframework.core.schema.config.SchemaConfiguration;
import org.romaframework.xml.config.XmlConfigActionType;

/**
 * Represent an event of a class.
 * 
 * @author Luca Garulli (luca.garulli@assetdata.it)
 */
public class SchemaEvent extends SchemaAction {
  public SchemaEvent(SchemaClassDefinition iEntity, String iName) {
    super(iEntity);
    name = iName;
  }

  @Override
  public String toString() {
    return name + " (event:" + method + ")";
  }

  @Override
  public void configure(Method iMethod) {
    method = iMethod;
    processConfiguration();
  }

  @Override
  protected void processConfiguration() {
    // BROWSE ALL ASPECTS
    Collection<Aspect> aspects = AspectManager.getInstance().getConfigurationValues();

    String annotationName;
    Annotation annotationAction;
    Annotation annotationGeneric;

    for (Aspect aspect : aspects) {
      if (method != null) {
        // COMPOSE ANNOTATION NAME BY ASPECT
        annotationName = aspect.aspectName();
        annotationName = Character.toUpperCase(annotationName.charAt(0)) + annotationName.substring(1);

        annotationAction = searchForAnnotation(method, annotationName + "Action", aspect.aspectName());
        annotationGeneric = searchForAnnotation(method, annotationName, aspect.aspectName());
      } else {
        annotationAction = null;
        annotationGeneric = null;
      }

      SchemaConfiguration classDescriptor = entity.getSchemaClass().getDescriptor();

      if (classDescriptor != null && classDescriptor.getType() != null && classDescriptor.getType().getActions() != null) {
        // SEARCH FORM DEFINITION IN DESCRIPTOR
        XmlConfigActionType[] allActions = classDescriptor.getType().getActions().getActionArray();

        XmlConfigActionType tmpDescr = null;
        for (short fieldNum = 0; fieldNum < allActions.length; ++fieldNum) {
          tmpDescr = allActions[fieldNum];
          if (tmpDescr.getName().equals(name)) {
            // FOUND XML NODE
            break;
          }
        }
      }
      // CONFIGURE THE SCHEMA OBJECT WITH CURRENT ASPECT
      aspect.configAction(this, annotationAction, annotationGeneric, null);
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.