0001: /**
0002: * EasyBeans
0003: * Copyright (C) 2006 Bull S.A.S.
0004: * Contact: easybeans@ow2.org
0005: *
0006: * This library is free software; you can redistribute it and/or
0007: * modify it under the terms of the GNU Lesser General Public
0008: * License as published by the Free Software Foundation; either
0009: * version 2.1 of the License, or any later version.
0010: *
0011: * This library is distributed in the hope that it will be useful,
0012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * Lesser General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU Lesser General Public
0017: * License along with this library; if not, write to the Free Software
0018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
0019: * USA
0020: *
0021: * --------------------------------------------------------------------------
0022: * $Id: ClassAnnotationMetadata.java 2059 2007-11-22 17:22:33Z benoitf $
0023: * --------------------------------------------------------------------------
0024: */package org.ow2.easybeans.deployment.annotations.metadata;
0025:
0026: import static javax.ejb.TransactionAttributeType.REQUIRED;
0027: import static javax.ejb.TransactionManagementType.CONTAINER;
0028:
0029: import java.util.ArrayList;
0030: import java.util.Collection;
0031: import java.util.HashMap;
0032: import java.util.LinkedList;
0033: import java.util.List;
0034: import java.util.Map;
0035:
0036: import javax.ejb.ApplicationException;
0037: import javax.ejb.TransactionAttributeType;
0038: import javax.ejb.TransactionManagementType;
0039:
0040: import org.ow2.easybeans.deployment.annotations.ClassType;
0041: import org.ow2.easybeans.deployment.annotations.InterceptorType;
0042: import org.ow2.easybeans.deployment.annotations.JClassInterceptor;
0043: import org.ow2.easybeans.deployment.annotations.JField;
0044: import org.ow2.easybeans.deployment.annotations.JMethod;
0045: import org.ow2.easybeans.deployment.annotations.exceptions.InterceptorsValidationException;
0046: import org.ow2.easybeans.deployment.annotations.impl.JAnnotationResource;
0047: import org.ow2.easybeans.deployment.annotations.impl.JCommonBean;
0048: import org.ow2.easybeans.deployment.annotations.impl.JEjbEJB;
0049: import org.ow2.easybeans.deployment.annotations.impl.JInterceptors;
0050: import org.ow2.easybeans.deployment.annotations.impl.JLocal;
0051: import org.ow2.easybeans.deployment.annotations.impl.JMessageDriven;
0052: import org.ow2.easybeans.deployment.annotations.impl.JRemote;
0053: import org.ow2.easybeans.deployment.annotations.impl.JStateful;
0054: import org.ow2.easybeans.deployment.annotations.impl.JStateless;
0055: import org.ow2.easybeans.deployment.annotations.impl.JavaxPersistenceContext;
0056: import org.ow2.easybeans.deployment.annotations.impl.JavaxPersistenceUnit;
0057: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityPermitAll;
0058: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IAnnotationSecurityRolesAllowed;
0059: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IEJBInterceptors;
0060: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.IInterceptorExcludeDefaultInterceptors;
0061: import org.ow2.easybeans.deployment.annotations.metadata.interfaces.ITransactionAttribute;
0062: import org.ow2.util.log.Log;
0063: import org.ow2.util.log.LogFactory;
0064:
0065: /**
0066: * This class represents the annotation metadata of a Bean.<br>
0067: * From this class, we can access to all methods of a bean with its associated information.
0068: * @author Florent Benoit
0069: */
0070: public class ClassAnnotationMetadata extends CommonAnnotationMetadata
0071: implements ITransactionAttribute, IEJBInterceptors,
0072: IAnnotationSecurityRolesAllowed, IAnnotationSecurityPermitAll,
0073: IInterceptorExcludeDefaultInterceptors {
0074:
0075: /**
0076: * Logger.
0077: */
0078: private static Log logger = LogFactory
0079: .getLog(ClassAnnotationMetadata.class);
0080:
0081: /**
0082: * List of method annotations metadata.
0083: */
0084: private Map<JMethod, MethodAnnotationMetadata> methodsAnnotationMetadata = null;
0085:
0086: /**
0087: * List of field annotations metadata.
0088: */
0089: private Map<JField, FieldAnnotationMetadata> fieldsAnnotationMetadata = null;
0090:
0091: /**
0092: * Parent meta data.
0093: */
0094: private EjbJarAnnotationMetadata ejbJarAnnotationMetadata = null;
0095:
0096: /**
0097: * List of local interfaces.
0098: */
0099: private JLocal jLocal = null;
0100:
0101: /**
0102: * List of remote interfaces.
0103: */
0104: private JRemote jRemote = null;
0105:
0106: /**
0107: * CommonBean description.
0108: */
0109: private JCommonBean jCommonBean = null;
0110:
0111: /**
0112: * Message Driven attribute.
0113: */
0114: private JMessageDriven jMessageDriven = null;
0115:
0116: /**
0117: * Stateless attribute.
0118: */
0119: private JStateless jStateless = null;
0120:
0121: /**
0122: * Stateful attribute.
0123: */
0124: private JStateful jStateful = null;
0125:
0126: /**
0127: * Ordered interceptors. If this flag is true it means that
0128: * interceptor-binding has been used in DD with an interceptor-order
0129: * element.<br/>
0130: * Also, this flag is used to check that the ordering is done only once.
0131: */
0132: private boolean orderedInterceptors = false;
0133:
0134: /**
0135: * Local Home.
0136: */
0137: private String localHome = null;
0138:
0139: /**
0140: * Remote Home.
0141: */
0142: private String remoteHome = null;
0143:
0144: /**
0145: * List of annotation interceptors.
0146: */
0147: private JInterceptors annotationInterceptors = null;
0148:
0149: /**
0150: * EasyBeans global interceptors.<br>
0151: * These interceptors correspond to a list of interceptors
0152: * that need to be present first on all methods.
0153: */
0154: private List<JClassInterceptor> globalEasyBeansInterceptors = null;
0155:
0156: /**
0157: * User interceptors. These interceptors correspond to a list of Interceptor that user has specified in its bean class.
0158: * It is the interceptors defined in interceptor classes, not the bean class itself.
0159: * Map<interceptor type <--> List of methods/class corresponding to the interceptor>
0160: */
0161: private Map<InterceptorType, List<JClassInterceptor>> externalUserInterceptors = null;
0162:
0163: /**
0164: * User interceptors. These interceptors correspond to a list of Interceptor that user has specified in the bean class.
0165: * It is not defined in separated classes.
0166: * Map<interceptor type <--> List of methods/class corresponding to the interceptor>
0167: */
0168: private Map<InterceptorType, List<JClassInterceptor>> internalUserInterceptors = null;
0169:
0170: /**
0171: * Transaction management type (default = container).
0172: */
0173: private TransactionManagementType transactionManagementType = CONTAINER;
0174:
0175: /**
0176: * Transaction attribute type (default = required).
0177: */
0178: private TransactionAttributeType transactionAttributeType = REQUIRED;
0179:
0180: /**
0181: * Application exception annotation.
0182: */
0183: private ApplicationException applicationException = null;
0184:
0185: /**
0186: * Superclass name.
0187: */
0188: private String super Name = null;
0189:
0190: /**
0191: * Interfaces of this clas.
0192: */
0193: private String[] interfaces = null;
0194:
0195: /**
0196: * The type of the class.
0197: * @see ClassType
0198: */
0199: private ClassType classType = null;
0200:
0201: /**
0202: * Name of the class associated to this metadata.
0203: */
0204: private String className = null;
0205:
0206: /**
0207: * List of @{@link javax.interceptor.AroundInvoke} methods on this
0208: * class (should be only one per class, validating occurs after).
0209: */
0210: private List<MethodAnnotationMetadata> aroundInvokeMethodsMetadata = null;
0211:
0212: /**
0213: * Object representing @{@link javax.ejb.EJBs} annotation.
0214: */
0215: private List<JEjbEJB> jEjbEJBs = null;
0216:
0217: /**
0218: * Object representing @{@link javax.annotation.Resources} annotation.
0219: */
0220: private List<JAnnotationResource> jAnnotationResources = null;
0221:
0222: /**
0223: * Object representing @{@link javax.persistence.PersistenceContext} annotation.
0224: */
0225: private List<JavaxPersistenceContext> javaxPersistencePersistenceContexts = null;
0226:
0227: /**
0228: * Object representing @{@link javax.persistence.PersistenceUnit} annotation.
0229: */
0230: private List<JavaxPersistenceUnit> javaxPersistencePersistenceUnits = null;
0231:
0232: /**
0233: * Methods used for @{@link javax.annotation.PostConstruct} on this
0234: * class (only one per class but may be defined in super classes).
0235: */
0236: private LinkedList<MethodAnnotationMetadata> postConstructMethodsMetadata = null;
0237:
0238: /**
0239: * Methods used for @{@link javax.annotation.PreDestroy} on this class
0240: * (only one per class but may be defined in super classes).
0241: */
0242: private LinkedList<MethodAnnotationMetadata> preDestroyMethodsMetadata = null;
0243:
0244: /**
0245: * Methods used for @{@link javax.ejb.PostActivate} on this class (only
0246: * one per class but may be defined in super classes).
0247: */
0248: private LinkedList<MethodAnnotationMetadata> postActivateMethodsMetadata = null;
0249:
0250: /**
0251: * Methods used for @{@link javax.ejb.PrePassivate} on this class (only
0252: * one per class but may be defined in super classes).
0253: */
0254: private LinkedList<MethodAnnotationMetadata> prePassivateMethodsMetadata = null;
0255:
0256: /**
0257: * Is that the class represented by this metadata has already been modified ?
0258: */
0259: private boolean modified = false;
0260:
0261: /**
0262: * List of roles that are declared on this class.
0263: */
0264: private List<String> declareRoles = null;
0265:
0266: /**
0267: * List of roles that are allowed on this class/bean.
0268: */
0269: private List<String> rolesAllowed = null;
0270:
0271: /**
0272: * This class/bean has the permitAll annotation.
0273: */
0274: private boolean permitAll = false;
0275:
0276: /**
0277: * The run-as security role (if any).
0278: */
0279: private String runAs = null;
0280:
0281: /**
0282: * @{@link javax.interceptor.ExcludeDefaultInterceptors} method ?
0283: */
0284: private boolean excludeDefaultInterceptors = false;
0285:
0286: /**
0287: * Name of the remote interface (used in EJB 2.1 DD).
0288: */
0289: private String remoteInterface = null;
0290:
0291: /**
0292: * Constructor.
0293: * @param className name of the class associated to these metadatas.
0294: * @param ejbJarAnnotationMetadata parent metadata object.
0295: */
0296: public ClassAnnotationMetadata(final String className,
0297: final EjbJarAnnotationMetadata ejbJarAnnotationMetadata) {
0298: this .className = className;
0299: this .methodsAnnotationMetadata = new HashMap<JMethod, MethodAnnotationMetadata>();
0300: this .fieldsAnnotationMetadata = new HashMap<JField, FieldAnnotationMetadata>();
0301: this .ejbJarAnnotationMetadata = ejbJarAnnotationMetadata;
0302: this .postConstructMethodsMetadata = new LinkedList<MethodAnnotationMetadata>();
0303: this .preDestroyMethodsMetadata = new LinkedList<MethodAnnotationMetadata>();
0304: this .postActivateMethodsMetadata = new LinkedList<MethodAnnotationMetadata>();
0305: this .prePassivateMethodsMetadata = new LinkedList<MethodAnnotationMetadata>();
0306: }
0307:
0308: /**
0309: * @return name of the bean (associated to this metadata).
0310: */
0311: public String getClassName() {
0312: return className;
0313: }
0314:
0315: /**
0316: * Add method annotation metadata for a given Bean.
0317: * @param methodAnnotationMetadata metadata of a method.
0318: */
0319: public void addMethodAnnotationMetadata(
0320: final MethodAnnotationMetadata methodAnnotationMetadata) {
0321: JMethod key = methodAnnotationMetadata.getJMethod();
0322: // No check: the same method can be added from the super class (ie : super = private, current = private)
0323: // So it means that there is no overriding
0324: methodsAnnotationMetadata.put(key, methodAnnotationMetadata);
0325: }
0326:
0327: /**
0328: * @param jMethod key of the map of methods annotations.
0329: * @return method annotation metadata of a given method.
0330: */
0331: public MethodAnnotationMetadata getMethodAnnotationMetadata(
0332: final JMethod jMethod) {
0333: return methodsAnnotationMetadata.get(jMethod);
0334: }
0335:
0336: /**
0337: * @param methodName the name of the method to search
0338: * @return list of method annotation metadata for the given method name
0339: */
0340: public List<MethodAnnotationMetadata> searchMethodAnnotationMetadata(
0341: final String methodName) {
0342: if (methodName == null) {
0343: throw new IllegalArgumentException(
0344: "Cannot search null methods");
0345: }
0346: List<MethodAnnotationMetadata> list = new ArrayList<MethodAnnotationMetadata>();
0347: for (MethodAnnotationMetadata method : methodsAnnotationMetadata
0348: .values()) {
0349: if (methodName.equals(method.getMethodName())) {
0350: list.add(method);
0351: }
0352: }
0353: return list;
0354: }
0355:
0356: /**
0357: * @param fieldName the name of the field to search
0358: * @return list of field annotation metadata for the given field name
0359: */
0360: public List<FieldAnnotationMetadata> searchFieldAnnotationMetadata(
0361: final String fieldName) {
0362: if (fieldName == null) {
0363: throw new IllegalArgumentException(
0364: "Cannot search null fields");
0365: }
0366: List<FieldAnnotationMetadata> list = new ArrayList<FieldAnnotationMetadata>();
0367: for (FieldAnnotationMetadata field : fieldsAnnotationMetadata
0368: .values()) {
0369: if (fieldName.equals(field.getFieldName())) {
0370: list.add(field);
0371: }
0372: }
0373: return list;
0374: }
0375:
0376: /**
0377: * Get collections of methods annotation metadata.
0378: * @return collections of methods annotation metadata.
0379: */
0380: public Collection<MethodAnnotationMetadata> getMethodAnnotationMetadataCollection() {
0381: return methodsAnnotationMetadata.values();
0382: }
0383:
0384: /**
0385: * Add field annotation metadata for a given Bean.
0386: * @param fieldAnnotationMetadata metadata of a field.
0387: */
0388: public void addFieldAnnotationMetadata(
0389: final FieldAnnotationMetadata fieldAnnotationMetadata) {
0390: JField key = fieldAnnotationMetadata.getJField();
0391: // already exists ?
0392: if (fieldsAnnotationMetadata.containsKey(key)) {
0393: String msg = logger
0394: .getI18n()
0395: .getMessage(
0396: "BeanAnnotationMetadata.addFieldAnnotationMetadata.alreadyPresent",
0397: key);
0398: logger.debug(msg);
0399: throw new IllegalStateException(msg);
0400: }
0401: fieldsAnnotationMetadata.put(key, fieldAnnotationMetadata);
0402: }
0403:
0404: /**
0405: * @param jField key of the map of fields annotations.
0406: * @return field annotation metadata of a given method.
0407: */
0408: public FieldAnnotationMetadata getFieldAnnotationMetadata(
0409: final JField jField) {
0410: return fieldsAnnotationMetadata.get(jField);
0411: }
0412:
0413: /**
0414: * Get collections of fields annotation metadata.
0415: * @return collections of fields annotation metadata.
0416: */
0417: public Collection<FieldAnnotationMetadata> getFieldAnnotationMetadataCollection() {
0418: return fieldsAnnotationMetadata.values();
0419: }
0420:
0421: /**
0422: * Sets the local interfaces of this class.
0423: * @param jLocal list of interfaces.
0424: */
0425: public void setLocalInterfaces(final JLocal jLocal) {
0426: this .jLocal = jLocal;
0427: }
0428:
0429: /**
0430: * Sets the remote interfaces of this class.
0431: * @param jRemote list of interfaces.
0432: */
0433: public void setRemoteInterfaces(final JRemote jRemote) {
0434: this .jRemote = jRemote;
0435: }
0436:
0437: /**
0438: * @return the local interfaces of this class.
0439: */
0440: public JLocal getLocalInterfaces() {
0441: return jLocal;
0442: }
0443:
0444: /**
0445: * @return the remote interfaces of this class.
0446: */
0447: public JRemote getRemoteInterfaces() {
0448: return jRemote;
0449: }
0450:
0451: /**
0452: * @return true if the class is a stateless class
0453: */
0454: public boolean isStateless() {
0455: return (classType != null && classType == ClassType.STATELESS);
0456: }
0457:
0458: /**
0459: * @return true if the class is a stateful class
0460: */
0461: public boolean isStateful() {
0462: return (classType != null && classType == ClassType.STATEFUL);
0463: }
0464:
0465: /**
0466: * @return true if the class is a session bean class
0467: */
0468: public boolean isSession() {
0469: return (classType != null && (classType == ClassType.STATELESS || classType == ClassType.STATEFUL));
0470: }
0471:
0472: /**
0473: * @return true if the class is an MDB class
0474: */
0475: public boolean isMdb() {
0476: return (classType != null && classType == ClassType.MDB);
0477: }
0478:
0479: /**
0480: * Sets the type of this class.
0481: * @param cType a type from enum class ClassType.
0482: * @see org.ow2.easybeans.deployment.annotations.ClassType
0483: */
0484: public void setClassType(final ClassType cType) {
0485: this .classType = cType;
0486: }
0487:
0488: /**
0489: * @return Message driven attribute.
0490: */
0491: public JMessageDriven getJMessageDriven() {
0492: return jMessageDriven;
0493: }
0494:
0495: /**
0496: * Sets the message driven bean object.
0497: * @param messageDriven attributes of message driven bean.
0498: */
0499: public void setJMessageDriven(final JMessageDriven messageDriven) {
0500: jMessageDriven = messageDriven;
0501: }
0502:
0503: /**
0504: * @return string representation.
0505: */
0506: @Override
0507: public String toString() {
0508: StringBuilder sb = new StringBuilder();
0509: // classname
0510: sb.append(this .getClass().getName().substring(
0511: this .getClass().getPackage().getName().length() + 1));
0512: sb.append("[\n");
0513:
0514: // Add super class toString()
0515: sb.append(super .toString());
0516:
0517: // Class name
0518: concatStringBuilder("className", className, sb);
0519:
0520: // superclass name
0521: concatStringBuilder("superName", super Name, sb);
0522:
0523: // interfaces
0524: concatStringBuilder("interfaces", interfaces, sb);
0525:
0526: // classType
0527: concatStringBuilder("classType", classType, sb);
0528:
0529: // jLocal
0530: concatStringBuilder("jLocal", jLocal, sb);
0531:
0532: // aroundInvokeMethodMetadatas
0533: concatStringBuilder("aroundInvokeMethodsMetadata",
0534: aroundInvokeMethodsMetadata, sb);
0535:
0536: // jRemote
0537: concatStringBuilder("jRemote", jRemote, sb);
0538:
0539: // jMessageDriven
0540: concatStringBuilder("jMessageDriven", jMessageDriven, sb);
0541:
0542: // remoteHome
0543: concatStringBuilder("remoteHome", remoteHome, sb);
0544:
0545: // localHome
0546: concatStringBuilder("localHome", localHome, sb);
0547:
0548: // transactionManagementType
0549: concatStringBuilder("transactionManagementType",
0550: transactionManagementType, sb);
0551:
0552: // transactionAttributeType
0553: concatStringBuilder("transactionAttributeType",
0554: transactionAttributeType, sb);
0555:
0556: // annotation Interceptors
0557: concatStringBuilder("annotationInterceptors",
0558: annotationInterceptors, sb);
0559:
0560: // jEjbEJBs
0561: concatStringBuilder("jAnnotationEJBs", jEjbEJBs, sb);
0562:
0563: // jAnnotationResources
0564: concatStringBuilder("jAnnotationResources",
0565: jAnnotationResources, sb);
0566:
0567: // javaxPersistencePersistenceContexts
0568: concatStringBuilder("javaxPersistencePersistenceContexts",
0569: javaxPersistencePersistenceContexts, sb);
0570:
0571: // javaxPersistencePersistenceUnits
0572: concatStringBuilder("javaxPersistencePersistenceUnits",
0573: javaxPersistencePersistenceUnits, sb);
0574:
0575: // Methods
0576: for (MethodAnnotationMetadata methodAnnotationMetadata : getMethodAnnotationMetadataCollection()) {
0577: concatStringBuilder("methods", methodAnnotationMetadata, sb);
0578: }
0579:
0580: // modified
0581: concatStringBuilder("modified", Boolean.valueOf(modified), sb);
0582:
0583: // excludeDefaultInterceptors
0584: concatStringBuilder("excludeDefaultInterceptors", Boolean
0585: .valueOf(excludeDefaultInterceptors), sb);
0586:
0587: // declareRoles
0588: concatStringBuilder("declareRoles", declareRoles, sb);
0589:
0590: // rolesAllowed
0591: concatStringBuilder("rolesAllowed", rolesAllowed, sb);
0592:
0593: // permitAll
0594: concatStringBuilder("permitAll", Boolean.valueOf(permitAll), sb);
0595:
0596: // runAs
0597: concatStringBuilder("runAs", runAs, sb);
0598:
0599: sb.append("]");
0600: return sb.toString();
0601: }
0602:
0603: /**
0604: * @return the @{@link javax.ejb.RemoteHome} class name.
0605: */
0606: public String getRemoteHome() {
0607: return remoteHome;
0608: }
0609:
0610: /**
0611: * Sets the @{@link javax.ejb.RemoteHome} class name.
0612: * @param remoteHome the class name.
0613: */
0614: public void setRemoteHome(final String remoteHome) {
0615: this .remoteHome = remoteHome;
0616: }
0617:
0618: /**
0619: * @return the @{@link javax.ejb.LocalHome} class name.
0620: */
0621: public String getLocalHome() {
0622: return localHome;
0623: }
0624:
0625: /**
0626: * Sets the @{@link javax.ejb.LocalHome} class name.
0627: * @param localHome the class name.
0628: */
0629: public void setLocalHome(final String localHome) {
0630: this .localHome = localHome;
0631: }
0632:
0633: /**
0634: * @return transaction management type from @see TransactionManagementType.
0635: */
0636: public TransactionManagementType getTransactionManagementType() {
0637: return transactionManagementType;
0638: }
0639:
0640: /**
0641: * Sets transaction management type.
0642: * @see javax.ejb.TransactionManagementType
0643: * @param transactionManagementType value.
0644: * (BEAN, CONTAINER)
0645: */
0646: public void setTransactionManagementType(
0647: final TransactionManagementType transactionManagementType) {
0648: this .transactionManagementType = transactionManagementType;
0649: }
0650:
0651: /**
0652: * @return transaction Attribute type.
0653: * @see javax.ejb.TransactionAttributeType
0654: */
0655: public TransactionAttributeType getTransactionAttributeType() {
0656: return transactionAttributeType;
0657: }
0658:
0659: /**
0660: * Set Transaction Attribute Type.
0661: * @see javax.ejb.TransactionAttributeType
0662: * @param transactionAttributeType the type of transaction.
0663: */
0664: public void setTransactionAttributeType(
0665: final TransactionAttributeType transactionAttributeType) {
0666: this .transactionAttributeType = transactionAttributeType;
0667: }
0668:
0669: /**
0670: * @return object representing list of @{@link javax.interceptor.Interceptors}.
0671: */
0672: public JInterceptors getAnnotationInterceptors() {
0673: return annotationInterceptors;
0674: }
0675:
0676: /**
0677: * Sets the object representing the @{@link javax.interceptor.Interceptors} annotation.
0678: * @param annotationInterceptors list of classes
0679: */
0680: public void setAnnotationsInterceptors(
0681: final JInterceptors annotationInterceptors) {
0682: this .annotationInterceptors = annotationInterceptors;
0683: }
0684:
0685: /**
0686: * @return the @{@link javax.ejb.ApplicationException} annotation.
0687: */
0688: public ApplicationException getApplicationException() {
0689: return applicationException;
0690: }
0691:
0692: /**
0693: * Sets the object representing the @{@link javax.ejb.ApplicationException} annotation.
0694: * @param applicationException object representation
0695: */
0696: public void setApplicationException(
0697: final ApplicationException applicationException) {
0698: this .applicationException = applicationException;
0699: }
0700:
0701: /**
0702: * @return true if the classs is a Bean
0703: */
0704: public boolean isBean() {
0705: return isStateless() || isStateful() || isMdb();
0706: }
0707:
0708: /**
0709: * @return array of interfaces name.
0710: */
0711: public String[] getInterfaces() {
0712: return interfaces;
0713: }
0714:
0715: /**
0716: * Sets the interfaces of this class.
0717: * @param interfaces name of interfaces.
0718: */
0719: public void setInterfaces(final String[] interfaces) {
0720: this .interfaces = interfaces;
0721: }
0722:
0723: /**
0724: * @return the super class name.
0725: */
0726: public String getSuperName() {
0727: return super Name;
0728: }
0729:
0730: /**
0731: * Sets the super class name.
0732: * @param superName name of the super class.
0733: */
0734: public void setSuperName(final String super Name) {
0735: this .super Name = super Name;
0736: }
0737:
0738: /**
0739: * @return parent metadata object.
0740: */
0741: public EjbJarAnnotationMetadata getEjbJarAnnotationMetadata() {
0742: return ejbJarAnnotationMetadata;
0743: }
0744:
0745: /**
0746: * @return Map<interceptor type <--> List of methods/class corresponding to the interceptor> (interceptor classes)
0747: * of user interceptors that enhancer will use.
0748: */
0749: public Map<InterceptorType, List<JClassInterceptor>> getExternalUserEasyBeansInterceptors() {
0750: return externalUserInterceptors;
0751: }
0752:
0753: /**
0754: * Sets the list of user interceptors that enhancers will use.<br>
0755: * These interceptors are defined outside the bean class (interceptor classes).
0756: * @param externalUserInterceptors list of interceptors that enhancer will use.
0757: */
0758: public void setExternalUserInterceptors(
0759: final Map<InterceptorType, List<JClassInterceptor>> externalUserInterceptors) {
0760: this .externalUserInterceptors = externalUserInterceptors;
0761: }
0762:
0763: /**
0764: * @return Map<interceptor type <--> List of methods/class corresponding to the interceptor> (bean classes)
0765: * of user interceptors that enhancer will use.
0766: */
0767: public Map<InterceptorType, List<JClassInterceptor>> getInternalUserEasyBeansInterceptors() {
0768: return internalUserInterceptors;
0769: }
0770:
0771: /**
0772: * Sets the list of user interceptors that enhancers will use.<br>
0773: * These interceptors are defined in bean class.
0774: * @param internalUserInterceptors list of interceptors that enhancer will use.
0775: */
0776: public void setInternalUserInterceptors(
0777: final Map<InterceptorType, List<JClassInterceptor>> internalUserInterceptors) {
0778: this .internalUserInterceptors = internalUserInterceptors;
0779: }
0780:
0781: /**
0782: * @return list of global interceptors that enhancer will use. (ie : ENC)
0783: */
0784: public List<JClassInterceptor> getGlobalEasyBeansInterceptors() {
0785: return globalEasyBeansInterceptors;
0786: }
0787:
0788: /**
0789: * Sets the list of global interceptors that enhancers will use.
0790: * @param globalEasyBeansInterceptors list of interceptors that enhancer will use.
0791: */
0792: public void setGlobalEasyBeansInterceptors(
0793: final List<JClassInterceptor> globalEasyBeansInterceptors) {
0794: this .globalEasyBeansInterceptors = globalEasyBeansInterceptors;
0795: }
0796:
0797: /**
0798: * @return the method metadata with annotation @{@link javax.interceptor.AroundInvoke}.
0799: */
0800: public boolean isAroundInvokeMethodMetadata() {
0801: return (aroundInvokeMethodsMetadata != null);
0802: }
0803:
0804: /**
0805: * @return the list of methods metadata with annotation @{@link javax.interceptor.AroundInvoke}.
0806: */
0807: public List<MethodAnnotationMetadata> getAroundInvokeMethodMetadatas() {
0808: return aroundInvokeMethodsMetadata;
0809: }
0810:
0811: /**
0812: * Add a @{@link javax.interceptor.AroundInvoke} method of this class.
0813: * @param aroundInvokeMethodMetadata the method.
0814: */
0815: public void addAroundInvokeMethodMetadata(
0816: final MethodAnnotationMetadata aroundInvokeMethodMetadata) {
0817: if (aroundInvokeMethodsMetadata == null) {
0818: this .aroundInvokeMethodsMetadata = new ArrayList<MethodAnnotationMetadata>();
0819: }
0820: aroundInvokeMethodsMetadata.add(aroundInvokeMethodMetadata);
0821: }
0822:
0823: /**
0824: * @return the methods metadata with annotation @{@link javax.annotation.PostConstruct}.
0825: */
0826: public LinkedList<MethodAnnotationMetadata> getPostConstructMethodsMetadata() {
0827: return postConstructMethodsMetadata;
0828: }
0829:
0830: /**
0831: * Adds a @{@link javax.annotation.PostConstruct} method of this class.
0832: * @param postConstructMethodMetadata the method.
0833: */
0834: public void addPostConstructMethodMetadata(
0835: final MethodAnnotationMetadata postConstructMethodMetadata) {
0836: checkLifeCycleDuplicate(postConstructMethodMetadata,
0837: InterceptorType.POST_CONSTRUCT,
0838: getPostConstructMethodsMetadata());
0839: this .postConstructMethodsMetadata
0840: .addFirst(postConstructMethodMetadata);
0841: }
0842:
0843: /**
0844: * Checks that only method at one level of a class is present.
0845: * @param postConstructMethodMetadata method to check
0846: * @param itcType the type of interceptor (used for the error)
0847: * @param existingList current list of methods
0848: */
0849: private void checkLifeCycleDuplicate(
0850: final MethodAnnotationMetadata postConstructMethodMetadata,
0851: final InterceptorType itcType,
0852: final List<MethodAnnotationMetadata> existingList) {
0853: // First case : not inherited
0854: ClassAnnotationMetadata wantToAddClassMetadata = postConstructMethodMetadata
0855: .getClassAnnotationMetadata();
0856: if (postConstructMethodMetadata.isInherited()) {
0857: wantToAddClassMetadata = postConstructMethodMetadata
0858: .getOriginalClassAnnotationMetadata();
0859: }
0860: for (MethodAnnotationMetadata method : existingList) {
0861: ClassAnnotationMetadata compareMetaData;
0862: if (method.isInherited()) {
0863: compareMetaData = method
0864: .getOriginalClassAnnotationMetadata();
0865: } else {
0866: compareMetaData = method.getClassAnnotationMetadata();
0867: }
0868: if (compareMetaData.equals(wantToAddClassMetadata)) {
0869: throw new InterceptorsValidationException("Class "
0870: + getClassName() + " has already a " + itcType
0871: + " method which is " + method.getMethodName()
0872: + ", cannot set new method "
0873: + postConstructMethodMetadata.getMethodName());
0874: }
0875: }
0876: }
0877:
0878: /**
0879: * @return the methods metadata with annotation @{@link javax.annotation.PreDestroy}.
0880: */
0881: public LinkedList<MethodAnnotationMetadata> getPreDestroyMethodsMetadata() {
0882: return preDestroyMethodsMetadata;
0883: }
0884:
0885: /**
0886: * Adds a @{@link javax.annotation.PreDestroy} method of this class.
0887: * @param preDestroyMethodMetadata the method.
0888: */
0889: public void addPreDestroyMethodMetadata(
0890: final MethodAnnotationMetadata preDestroyMethodMetadata) {
0891: checkLifeCycleDuplicate(preDestroyMethodMetadata,
0892: InterceptorType.PRE_DESTROY,
0893: getPreDestroyMethodsMetadata());
0894: this .preDestroyMethodsMetadata
0895: .addFirst(preDestroyMethodMetadata);
0896: }
0897:
0898: /**
0899: * @return the methods metadata with annotation @{@link javax.ejb.PostActivate}.
0900: */
0901: public LinkedList<MethodAnnotationMetadata> getPostActivateMethodsMetadata() {
0902: return postActivateMethodsMetadata;
0903: }
0904:
0905: /**
0906: * Adds a @{@link javax.ejb.PostActivate} method of this class.
0907: * @param postActivateMethodMetadata the method.
0908: */
0909: public void addPostActivateMethodMetadata(
0910: final MethodAnnotationMetadata postActivateMethodMetadata) {
0911: checkLifeCycleDuplicate(postActivateMethodMetadata,
0912: InterceptorType.POST_ACTIVATE,
0913: getPostActivateMethodsMetadata());
0914: this .postActivateMethodsMetadata
0915: .addFirst(postActivateMethodMetadata);
0916: }
0917:
0918: /**
0919: * @return the method metadata with annotation @{@link javax.ejb.PrePassivate}.
0920: */
0921: public LinkedList<MethodAnnotationMetadata> getPrePassivateMethodsMetadata() {
0922: return prePassivateMethodsMetadata;
0923: }
0924:
0925: /**
0926: * Adds a @{@link javax.ejb.PrePassivate} method of this class.
0927: * @param prePassivateMethodMetadata the method.
0928: */
0929: public void addPrePassivateMethodMetadata(
0930: final MethodAnnotationMetadata prePassivateMethodMetadata) {
0931: checkLifeCycleDuplicate(prePassivateMethodMetadata,
0932: InterceptorType.PRE_PASSIVATE,
0933: getPrePassivateMethodsMetadata());
0934: this .prePassivateMethodsMetadata
0935: .addFirst(prePassivateMethodMetadata);
0936: }
0937:
0938: /**
0939: * Is that this class is an interceptor class ?
0940: * @return true if it the case, else false.
0941: */
0942: public boolean isInterceptor() {
0943: return (aroundInvokeMethodsMetadata != null && aroundInvokeMethodsMetadata
0944: .size() > 0)
0945: || (postConstructMethodsMetadata != null && postConstructMethodsMetadata
0946: .size() > 0)
0947: || (preDestroyMethodsMetadata != null && preDestroyMethodsMetadata
0948: .size() > 0)
0949: || (prePassivateMethodsMetadata != null && prePassivateMethodsMetadata
0950: .size() > 0)
0951: || (postActivateMethodsMetadata != null && postActivateMethodsMetadata
0952: .size() > 0);
0953: }
0954:
0955: /**
0956: * @return jEjbEJBs list representing @{@link javax.ejb.EJBs} annotation.
0957: */
0958: public List<JEjbEJB> getJEjbEJBs() {
0959: return jEjbEJBs;
0960: }
0961:
0962: /**
0963: * Set JEjbEJBs object.
0964: * @param jEjbEJBs list representing javax.ejb.EJBs annotation.
0965: */
0966: public void setJEjbEJBs(final List<JEjbEJB> jEjbEJBs) {
0967: this .jEjbEJBs = jEjbEJBs;
0968: }
0969:
0970: /**
0971: * @return JAnnotationResources list representing @{@link javax.annotation.Resources} annotation.
0972: */
0973: public List<JAnnotationResource> getJAnnotationResources() {
0974: return jAnnotationResources;
0975: }
0976:
0977: /**
0978: * Sets JAnnotationResources object.
0979: * @param jAnnotationResources list representing javax.annotation.Resources annotation.
0980: */
0981: public void setJAnnotationResources(
0982: final List<JAnnotationResource> jAnnotationResources) {
0983: this .jAnnotationResources = jAnnotationResources;
0984: }
0985:
0986: /**
0987: * @return javaxPersistencePersistenceContexts list representing @{@link javax.persistence.PersistenceContexts}
0988: * annotation.
0989: */
0990: public List<JavaxPersistenceContext> getJavaxPersistencePersistenceContexts() {
0991: return javaxPersistencePersistenceContexts;
0992: }
0993:
0994: /**
0995: * Sets JavaxPersistencePersistenceContexts object.
0996: * @param javaxPersistencePersistenceContexts list representing @{@link javax.persistence.PersistenceContexts} annotation.
0997: */
0998: public void setJavaxPersistencePersistenceContexts(
0999: final List<JavaxPersistenceContext> javaxPersistencePersistenceContexts) {
1000: this .javaxPersistencePersistenceContexts = javaxPersistencePersistenceContexts;
1001: }
1002:
1003: /**
1004: * @return javaxPersistencePersistenceUnits list representing @{@link javax.persistence.PersistenceUnits} annotation.
1005: */
1006: public List<JavaxPersistenceUnit> getJavaxPersistencePersistenceUnits() {
1007: return javaxPersistencePersistenceUnits;
1008: }
1009:
1010: /**
1011: * Sets setJavaxPersistencePersistenceUnits object.
1012: * @param javaxPersistencePersistenceUnits list representing @{@link javax.persistence.PersistenceUnits} annotation.
1013: */
1014: public void setJavaxPersistencePersistenceUnits(
1015: final List<JavaxPersistenceUnit> javaxPersistencePersistenceUnits) {
1016: this .javaxPersistencePersistenceUnits = javaxPersistencePersistenceUnits;
1017: }
1018:
1019: /**
1020: * @return the attributes for a Stateless/Stateful/MDB
1021: */
1022: public JCommonBean getJCommonBean() {
1023: return jCommonBean;
1024: }
1025:
1026: /**
1027: * Sets the attributes for a Stateless/Stateful/MDB.
1028: * @param commonBean the attributes
1029: */
1030: public void setJCommonBean(final JCommonBean commonBean) {
1031: // ensure that there is a bean name
1032: String ejbName = commonBean.getName();
1033: if (ejbName == null || "".equals(ejbName)) {
1034: // if not set, it has to be the unqualified name of the bean class. (simplified spec : 10.1.1)
1035: commonBean.setName(className.substring(className
1036: .lastIndexOf("/") + 1));
1037: }
1038: jCommonBean = commonBean;
1039: }
1040:
1041: /**
1042: * @return the attributes for a Stateful
1043: */
1044: public JStateful getJStateful() {
1045: return jStateful;
1046: }
1047:
1048: /**
1049: * Sets the attributes for a Stateful.
1050: * @param jStateful the attributes
1051: */
1052: public void setJStateful(final JStateful jStateful) {
1053: this .jStateful = jStateful;
1054: }
1055:
1056: /**
1057: * @return the attributes for a Stateless
1058: */
1059: public JStateless getJStateless() {
1060: return jStateless;
1061: }
1062:
1063: /**
1064: * Sets the attributes for a Stateless.
1065: * @param jStateless the attributes
1066: */
1067: public void setJStateless(final JStateless jStateless) {
1068: this .jStateless = jStateless;
1069: }
1070:
1071: /**
1072: * @return true if the class has been modified.
1073: */
1074: public boolean wasModified() {
1075: return modified;
1076: }
1077:
1078: /**
1079: * Defines that this class has been modified.
1080: */
1081: public void setModified() {
1082: this .modified = true;
1083: }
1084:
1085: /**
1086: * Sets the list of roles declared on this class.
1087: * @param declareRoles the list of roles.
1088: */
1089: public void setDeclareRoles(final List<String> declareRoles) {
1090: this .declareRoles = declareRoles;
1091: }
1092:
1093: /**
1094: * @return the list of roles declared on this class.
1095: */
1096: public List<String> getDeclareRoles() {
1097: return declareRoles;
1098: }
1099:
1100: /**
1101: * Set the list of roles allowed on this class/method.
1102: * @param rolesAllowed the list of roles.
1103: */
1104: public void setRolesAllowed(final List<String> rolesAllowed) {
1105: this .rolesAllowed = rolesAllowed;
1106: }
1107:
1108: /**
1109: * @return the list of roles allowed on this class/method.
1110: */
1111: public List<String> getRolesAllowed() {
1112: return rolesAllowed;
1113: }
1114:
1115: /**
1116: * This class has PermitAll annotation.
1117: * @param permitAll the boolean value.
1118: */
1119: public void setPermitAll(final boolean permitAll) {
1120: this .permitAll = permitAll;
1121: }
1122:
1123: /**
1124: * @return true if PermitAll annotation.
1125: */
1126: public boolean hasPermitAll() {
1127: return permitAll;
1128: }
1129:
1130: /**
1131: * Set the value of the run-as property.
1132: * @param runAs the run-as property.
1133: */
1134: public void setRunAs(final String runAs) {
1135: this .runAs = runAs;
1136: }
1137:
1138: /**
1139: * @return the name of the security-role of the run-as element.
1140: */
1141: public String getRunAs() {
1142: return runAs;
1143: }
1144:
1145: /**
1146: * @return true if this class won't use default interceptors.
1147: */
1148: public boolean isExcludedDefaultInterceptors() {
1149: return excludeDefaultInterceptors;
1150: }
1151:
1152: /**
1153: * Flag this class as a class which exclude default interceptors.
1154: * @param excludeDefaultInterceptors true if this class is a class which exclude default interceptors.
1155: */
1156: public void setExcludeDefaultInterceptors(
1157: final boolean excludeDefaultInterceptors) {
1158: this .excludeDefaultInterceptors = excludeDefaultInterceptors;
1159: }
1160:
1161: /**
1162: * @return true if the interceptors have been ordered for this class.
1163: */
1164: public boolean isOrderedInterceptors() {
1165: return orderedInterceptors;
1166: }
1167:
1168: /**
1169: * Sets flag to true if interceptors are ordered.
1170: * @param orderedInterceptors boolean with true/false.
1171: */
1172: public void setOrderedInterceptors(final boolean orderedInterceptors) {
1173: this .orderedInterceptors = orderedInterceptors;
1174: }
1175:
1176: /**
1177: * Set the value of the remote Interface property.
1178: * @param remoteInterface the remote Interface property.
1179: */
1180: public void setRemoteInterface(final String remoteInterface) {
1181: this .remoteInterface = remoteInterface;
1182: }
1183:
1184: /**
1185: * @return the name of the remote interface.
1186: */
1187: public String getRemoteInterface() {
1188: return remoteInterface;
1189: }
1190:
1191: }
|