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.AnnotatedElement;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.romaframework.core.Utility;
025:
026: /**
027: * Represent a base element for an entity.
028: *
029: * @author Luca Garulli (luca.garulli@assetdata.it)
030: */
031: public abstract class SchemaElement extends SchemaFeatures implements
032: Comparable<SchemaElement> {
033: private static Log log = LogFactory.getLog(SchemaElement.class);
034:
035: protected static Annotation searchForAnnotation(
036: AnnotatedElement iElement, String annotationName,
037: String iAspectName) {
038: // CHECK FOR ANNOTATION PRESENCE
039: try {
040: Class annotationClass = Class.forName(Utility.ROMA_PACKAGE
041: + ".aspect." + iAspectName + ".annotation."
042: + annotationName);
043: Annotation ann = iElement.getAnnotation(annotationClass);
044: if (log.isDebugEnabled())
045: log
046: .debug("[SchemaElement.searchForAnnotation] Reading Java5 annotation "
047: + iElement + ":" + ann);
048: return ann;
049: } catch (ClassNotFoundException e) {
050: // ANNOTATION CLASS NOT EXIST FOR CURRENT ASPECT
051: }
052: return null;
053: }
054:
055: protected SchemaClassDefinition entity;
056: protected String name;
057: protected short order;
058:
059: public final static short DEF_ORDER = -1;
060:
061: public SchemaElement(SchemaClassDefinition iEntity) {
062: entity = iEntity;
063: order = DEF_ORDER;
064: }
065:
066: @Override
067: public Object clone() throws CloneNotSupportedException {
068: SchemaElement copy = (SchemaElement) super .clone();
069: copy.entity = entity;
070: copy.name = name;
071: copy.order = order;
072:
073: return copy;
074: }
075:
076: public int compareTo(SchemaElement iField) {
077: short otherOrder = iField.getOrder();
078:
079: if (otherOrder == -1)
080: return 1;
081:
082: if (order == -1)
083: return -1;
084:
085: return order > otherOrder ? 1 : -1;
086: }
087:
088: public SchemaClassDefinition getEntity() {
089: return entity;
090: }
091:
092: protected abstract void processConfiguration();
093:
094: public String getName() {
095: return name;
096: }
097:
098: public short getOrder() {
099: return order;
100: }
101:
102: public void setOrder(short order) {
103: this.order = order;
104: }
105: }
|