0001: /**
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */package org.apache.openejb.config;
0017:
0018: import static java.util.Arrays.asList;
0019: import static java.lang.reflect.Modifier.isAbstract;
0020:
0021: import org.apache.openejb.DeploymentInfo;
0022: import org.apache.openejb.OpenEJBException;
0023: import org.apache.openejb.core.webservices.JaxWsUtils;
0024: import org.apache.openejb.jee.ActivationConfig;
0025: import org.apache.openejb.jee.ApplicationClient;
0026: import org.apache.openejb.jee.AroundInvoke;
0027: import org.apache.openejb.jee.AssemblyDescriptor;
0028: import org.apache.openejb.jee.ContainerTransaction;
0029: import org.apache.openejb.jee.EjbJar;
0030: import org.apache.openejb.jee.EjbLocalRef;
0031: import org.apache.openejb.jee.EjbRef;
0032: import org.apache.openejb.jee.EjbReference;
0033: import org.apache.openejb.jee.EnterpriseBean;
0034: import org.apache.openejb.jee.ExcludeList;
0035: import org.apache.openejb.jee.Filter;
0036: import org.apache.openejb.jee.Handler;
0037: import org.apache.openejb.jee.HandlerChains;
0038: import org.apache.openejb.jee.InitMethod;
0039: import org.apache.openejb.jee.InjectionTarget;
0040: import org.apache.openejb.jee.Interceptor;
0041: import org.apache.openejb.jee.InterceptorBinding;
0042: import org.apache.openejb.jee.JndiConsumer;
0043: import org.apache.openejb.jee.JndiReference;
0044: import org.apache.openejb.jee.Lifecycle;
0045: import org.apache.openejb.jee.LifecycleCallback;
0046: import org.apache.openejb.jee.Listener;
0047: import org.apache.openejb.jee.MessageDrivenBean;
0048: import org.apache.openejb.jee.MethodParams;
0049: import org.apache.openejb.jee.MethodPermission;
0050: import org.apache.openejb.jee.MethodTransaction;
0051: import org.apache.openejb.jee.NamedMethod;
0052: import org.apache.openejb.jee.PersistenceContextRef;
0053: import org.apache.openejb.jee.PersistenceContextType;
0054: import org.apache.openejb.jee.PersistenceUnitRef;
0055: import org.apache.openejb.jee.PortComponent;
0056: import org.apache.openejb.jee.Property;
0057: import org.apache.openejb.jee.RemoteBean;
0058: import org.apache.openejb.jee.RemoveMethod;
0059: import org.apache.openejb.jee.ResAuth;
0060: import org.apache.openejb.jee.ResSharingScope;
0061: import org.apache.openejb.jee.ResourceEnvRef;
0062: import org.apache.openejb.jee.ResourceRef;
0063: import org.apache.openejb.jee.SecurityIdentity;
0064: import org.apache.openejb.jee.SecurityRoleRef;
0065: import org.apache.openejb.jee.ServiceRef;
0066: import org.apache.openejb.jee.Servlet;
0067: import org.apache.openejb.jee.SessionBean;
0068: import org.apache.openejb.jee.SessionType;
0069: import org.apache.openejb.jee.StatefulBean;
0070: import org.apache.openejb.jee.StatelessBean;
0071: import org.apache.openejb.jee.Tag;
0072: import org.apache.openejb.jee.TimerConsumer;
0073: import org.apache.openejb.jee.TldTaglib;
0074: import org.apache.openejb.jee.TransAttribute;
0075: import org.apache.openejb.jee.TransactionType;
0076: import org.apache.openejb.jee.WebApp;
0077: import org.apache.openejb.jee.WebserviceDescription;
0078: import static org.apache.openejb.util.Join.join;
0079: import org.apache.openejb.util.LogCategory;
0080: import org.apache.openejb.util.Logger;
0081: import org.apache.xbean.finder.ClassFinder;
0082:
0083: import javax.annotation.PostConstruct;
0084: import javax.annotation.PreDestroy;
0085: import javax.annotation.Resource;
0086: import javax.annotation.Resources;
0087: import javax.annotation.security.DeclareRoles;
0088: import javax.annotation.security.DenyAll;
0089: import javax.annotation.security.PermitAll;
0090: import javax.annotation.security.RolesAllowed;
0091: import javax.annotation.security.RunAs;
0092: import javax.ejb.ApplicationException;
0093: import javax.ejb.EJB;
0094: import javax.ejb.EJBHome;
0095: import javax.ejb.EJBLocalHome;
0096: import javax.ejb.EJBLocalObject;
0097: import javax.ejb.EJBObject;
0098: import javax.ejb.EJBs;
0099: import javax.ejb.Init;
0100: import javax.ejb.Local;
0101: import javax.ejb.LocalHome;
0102: import javax.ejb.MessageDriven;
0103: import javax.ejb.PostActivate;
0104: import javax.ejb.PrePassivate;
0105: import javax.ejb.Remote;
0106: import javax.ejb.RemoteHome;
0107: import javax.ejb.Remove;
0108: import javax.ejb.Stateful;
0109: import javax.ejb.Stateless;
0110: import javax.ejb.TransactionAttribute;
0111: import javax.ejb.TransactionAttributeType;
0112: import javax.ejb.TransactionManagement;
0113: import javax.ejb.TransactionManagementType;
0114: import javax.interceptor.ExcludeClassInterceptors;
0115: import javax.interceptor.ExcludeDefaultInterceptors;
0116: import javax.interceptor.Interceptors;
0117: import javax.jws.HandlerChain;
0118: import javax.jws.WebService;
0119: import javax.persistence.EntityManager;
0120: import javax.persistence.EntityManagerFactory;
0121: import javax.persistence.PersistenceContext;
0122: import javax.persistence.PersistenceContexts;
0123: import javax.persistence.PersistenceUnit;
0124: import javax.persistence.PersistenceUnits;
0125: import javax.xml.ws.Service;
0126: import javax.xml.ws.WebServiceProvider;
0127: import javax.xml.ws.WebServiceRef;
0128: import javax.xml.ws.WebServiceRefs;
0129: import java.io.File;
0130: import java.lang.reflect.Field;
0131: import java.lang.reflect.Method;
0132: import java.lang.reflect.Modifier;
0133: import java.lang.annotation.Annotation;
0134: import java.net.MalformedURLException;
0135: import java.net.URL;
0136: import java.util.ArrayList;
0137: import java.util.HashMap;
0138: import java.util.HashSet;
0139: import java.util.List;
0140: import java.util.Map;
0141: import java.util.Properties;
0142: import java.util.Set;
0143: import java.util.TreeSet;
0144:
0145: /**
0146: * @version $Rev: 637726 $ $Date: 2008-03-16 22:34:37 -0700 $
0147: */
0148: public class AnnotationDeployer implements DynamicDeployer {
0149: public static final Logger logger = Logger.getInstance(
0150: LogCategory.OPENEJB_STARTUP, AnnotationDeployer.class
0151: .getPackage().getName());
0152:
0153: private static final ThreadLocal<ValidationContext> validationContext = new ThreadLocal<ValidationContext>();
0154:
0155: private final DiscoverAnnotatedBeans discoverAnnotatedBeans;
0156: private final ProcessAnnotatedBeans processAnnotatedBeans;
0157: private final EnvEntriesPropertiesDeployer envEntriesPropertiesDeployer;
0158:
0159: public AnnotationDeployer() {
0160: discoverAnnotatedBeans = new DiscoverAnnotatedBeans();
0161: processAnnotatedBeans = new ProcessAnnotatedBeans();
0162: envEntriesPropertiesDeployer = new EnvEntriesPropertiesDeployer();
0163: }
0164:
0165: public AppModule deploy(AppModule appModule)
0166: throws OpenEJBException {
0167: getValidationContext().set(appModule.getValidation());
0168: try {
0169: appModule = discoverAnnotatedBeans.deploy(appModule);
0170: appModule = envEntriesPropertiesDeployer.deploy(appModule);
0171: appModule = processAnnotatedBeans.deploy(appModule);
0172: return appModule;
0173: } finally {
0174: getValidationContext().remove();
0175: }
0176: }
0177:
0178: public WebModule deploy(WebModule webModule)
0179: throws OpenEJBException {
0180: getValidationContext().set(webModule.getValidation());
0181: try {
0182: webModule = discoverAnnotatedBeans.deploy(webModule);
0183: webModule = envEntriesPropertiesDeployer.deploy(webModule);
0184: webModule = processAnnotatedBeans.deploy(webModule);
0185: return webModule;
0186: } finally {
0187: getValidationContext().remove();
0188: }
0189: }
0190:
0191: public static ThreadLocal<ValidationContext> getValidationContext() {
0192: // Throwable throwable = new Throwable();
0193: // throwable.fillInStackTrace();
0194: // throwable.printStackTrace();
0195: return validationContext;
0196: }
0197:
0198: public static class DiscoverAnnotatedBeans implements
0199: DynamicDeployer {
0200: public static final Set<String> knownResourceEnvTypes = new TreeSet<String>(
0201: asList("javax.ejb.SessionContext",
0202: "javax.ejb.EntityContext",
0203: "javax.ejb.MessageDrivenContext",
0204: "javax.transaction.UserTransaction",
0205: "javax.jms.Queue", "javax.jms.Topic",
0206: "javax.xml.ws.WebServiceContext",
0207: "javax.ejb.TimerService"));
0208:
0209: public static final Set<String> knownEnvironmentEntries = new TreeSet<String>(
0210: asList("boolean", "java.lang.Boolean", "char",
0211: "java.lang.Character", "byte",
0212: "java.lang.Byte", "short", "java.lang.Short",
0213: "int", "java.lang.Integer", "long",
0214: "java.lang.Long", "float", "java.lang.Float",
0215: "double", "java.lang.Double",
0216: "java.lang.String"));
0217:
0218: public AppModule deploy(AppModule appModule)
0219: throws OpenEJBException {
0220: for (EjbModule ejbModule : appModule.getEjbModules()) {
0221: getValidationContext().set(ejbModule.getValidation());
0222: try {
0223: deploy(ejbModule);
0224: } finally {
0225: getValidationContext().remove();
0226: }
0227: }
0228: for (ClientModule clientModule : appModule
0229: .getClientModules()) {
0230: getValidationContext()
0231: .set(clientModule.getValidation());
0232: try {
0233: deploy(clientModule);
0234: } finally {
0235: getValidationContext().remove();
0236: }
0237: }
0238: for (ConnectorModule connectorModule : appModule
0239: .getResourceModules()) {
0240: getValidationContext().set(
0241: connectorModule.getValidation());
0242: try {
0243: deploy(connectorModule);
0244: } finally {
0245: getValidationContext().remove();
0246: }
0247: }
0248: for (WebModule webModule : appModule.getWebModules()) {
0249: getValidationContext().set(webModule.getValidation());
0250: try {
0251: deploy(webModule);
0252: } finally {
0253: getValidationContext().remove();
0254: }
0255: }
0256: return appModule;
0257: }
0258:
0259: public ClientModule deploy(ClientModule clientModule)
0260: throws OpenEJBException {
0261: return clientModule;
0262: }
0263:
0264: public ConnectorModule deploy(ConnectorModule connectorModule)
0265: throws OpenEJBException {
0266: return connectorModule;
0267: }
0268:
0269: public WebModule deploy(WebModule webModule)
0270: throws OpenEJBException {
0271: WebApp webApp = webModule.getWebApp();
0272: if (webApp != null
0273: && (webApp.isMetadataComplete() || !webApp
0274: .getServlet().isEmpty()))
0275: return webModule;
0276:
0277: ClassFinder finder;
0278: try {
0279: finder = new ClassFinder(webModule.getClassLoader());
0280: } catch (Exception e) {
0281: DeploymentLoader.logger
0282: .warning(
0283: "Unable to scrape for @WebService or @WebServiceProvider annotations. ClassFinder failed.",
0284: e);
0285: return webModule;
0286: }
0287:
0288: List<Class> classes = new ArrayList<Class>();
0289: classes.addAll(finder
0290: .findAnnotatedClasses(WebService.class));
0291: classes.addAll(finder
0292: .findAnnotatedClasses(WebServiceProvider.class));
0293: for (Class<?> webServiceClass : classes) {
0294: int modifiers = webServiceClass.getModifiers();
0295: if (!Modifier.isPublic(modifiers)
0296: || Modifier.isFinal(modifiers)
0297: || isAbstract(modifiers)) {
0298: continue;
0299: }
0300:
0301: // create webApp and webservices objects if they don't exist already
0302: if (webApp == null) {
0303: webApp = new WebApp();
0304: webModule.setWebApp(webApp);
0305: }
0306:
0307: // add new <servlet/> element
0308: Servlet servlet = new Servlet();
0309: servlet.setServletName(webServiceClass.getName());
0310: servlet.setServletClass(webServiceClass.getName());
0311: webApp.getServlet().add(servlet);
0312: }
0313:
0314: return webModule;
0315: }
0316:
0317: public EjbModule deploy(EjbModule ejbModule)
0318: throws OpenEJBException {
0319: if (ejbModule.getEjbJar() != null
0320: && ejbModule.getEjbJar().isMetadataComplete())
0321: return ejbModule;
0322:
0323: ClassFinder finder;
0324: if (ejbModule.getJarLocation() != null) {
0325: try {
0326: String location = ejbModule.getJarLocation();
0327: File file = new File(location);
0328:
0329: URL url;
0330: if (file.exists()) {
0331: url = file.toURL();
0332: } else {
0333: url = new URL(location);
0334: }
0335: finder = new ClassFinder(
0336: ejbModule.getClassLoader(), url);
0337: } catch (MalformedURLException e) {
0338: DeploymentLoader.logger.warning(
0339: "startup.scrapeFailedForModule", ejbModule
0340: .getJarLocation());
0341: return ejbModule;
0342: }
0343: } else {
0344: try {
0345: finder = new ClassFinder(ejbModule.getClassLoader());
0346: } catch (Exception e) {
0347: DeploymentLoader.logger
0348: .warning(
0349: "Unable to scrape for @Stateful, @Stateless or @MessageDriven annotations. ClassFinder failed.",
0350: e);
0351: return ejbModule;
0352: }
0353: }
0354:
0355: /* 19.2: ejb-name: Default is the unqualified name of the bean class */
0356:
0357: EjbJar ejbJar = ejbModule.getEjbJar();
0358: List<Class> classes = finder
0359: .findAnnotatedClasses(Stateless.class);
0360: for (Class<?> beanClass : classes) {
0361: Stateless stateless = beanClass
0362: .getAnnotation(Stateless.class);
0363: String ejbName = getEjbName(stateless, beanClass);
0364:
0365: if (!isValidAnnotationUsage(Stateless.class, beanClass,
0366: ejbName, ejbModule))
0367: continue;
0368:
0369: EnterpriseBean enterpriseBean = ejbJar
0370: .getEnterpriseBean(ejbName);
0371: if (enterpriseBean == null) {
0372: enterpriseBean = new StatelessBean(ejbName,
0373: beanClass.getName());
0374: ejbJar.addEnterpriseBean(enterpriseBean);
0375: }
0376: if (enterpriseBean.getEjbClass() == null) {
0377: enterpriseBean.setEjbClass(beanClass.getName());
0378: }
0379: if (enterpriseBean instanceof SessionBean) {
0380: SessionBean sessionBean = (SessionBean) enterpriseBean;
0381: sessionBean.setSessionType(SessionType.STATELESS);
0382: }
0383: }
0384:
0385: classes = finder.findAnnotatedClasses(Stateful.class);
0386: for (Class<?> beanClass : classes) {
0387: Stateful stateful = beanClass
0388: .getAnnotation(Stateful.class);
0389: String ejbName = getEjbName(stateful, beanClass);
0390:
0391: if (!isValidAnnotationUsage(Stateful.class, beanClass,
0392: ejbName, ejbModule))
0393: continue;
0394:
0395: EnterpriseBean enterpriseBean = ejbJar
0396: .getEnterpriseBean(ejbName);
0397: if (enterpriseBean == null) {
0398: enterpriseBean = new StatefulBean(ejbName,
0399: beanClass.getName());
0400: ejbJar.addEnterpriseBean(enterpriseBean);
0401: }
0402: if (enterpriseBean.getEjbClass() == null) {
0403: enterpriseBean.setEjbClass(beanClass.getName());
0404: }
0405: if (enterpriseBean instanceof SessionBean) {
0406: SessionBean sessionBean = (SessionBean) enterpriseBean;
0407: sessionBean.setSessionType(SessionType.STATEFUL);
0408: }
0409: }
0410:
0411: classes = finder.findAnnotatedClasses(MessageDriven.class);
0412: for (Class<?> beanClass : classes) {
0413: MessageDriven mdb = beanClass
0414: .getAnnotation(MessageDriven.class);
0415: String ejbName = getEjbName(mdb, beanClass);
0416:
0417: if (!isValidAnnotationUsage(MessageDriven.class,
0418: beanClass, ejbName, ejbModule))
0419: continue;
0420:
0421: MessageDrivenBean messageBean = (MessageDrivenBean) ejbJar
0422: .getEnterpriseBean(ejbName);
0423: if (messageBean == null) {
0424: messageBean = new MessageDrivenBean(ejbName);
0425: ejbJar.addEnterpriseBean(messageBean);
0426: }
0427: if (messageBean.getEjbClass() == null) {
0428: messageBean.setEjbClass(beanClass.getName());
0429: }
0430: }
0431:
0432: classes = finder
0433: .findAnnotatedClasses(ApplicationException.class);
0434: if (!classes.isEmpty()) {
0435: if (ejbJar.getAssemblyDescriptor() == null) {
0436: ejbJar
0437: .setAssemblyDescriptor(new AssemblyDescriptor());
0438: }
0439: }
0440: for (Class<?> exceptionClass : classes) {
0441: ApplicationException annotation = exceptionClass
0442: .getAnnotation(ApplicationException.class);
0443: org.apache.openejb.jee.ApplicationException exception = new org.apache.openejb.jee.ApplicationException(
0444: exceptionClass.getName(), annotation.rollback());
0445: ejbJar.getAssemblyDescriptor()
0446: .getApplicationException().add(exception);
0447: }
0448:
0449: return ejbModule;
0450: }
0451:
0452: private String getEjbName(MessageDriven mdb, Class<?> beanClass) {
0453: String ejbName = mdb.name().length() == 0 ? beanClass
0454: .getSimpleName() : mdb.name();
0455: return ejbName;
0456: }
0457:
0458: private String getEjbName(Stateful stateful, Class<?> beanClass) {
0459: String ejbName = stateful.name().length() == 0 ? beanClass
0460: .getSimpleName() : stateful.name();
0461: return ejbName;
0462: }
0463:
0464: private String getEjbName(Stateless stateless,
0465: Class<?> beanClass) {
0466: String ejbName = stateless.name().length() == 0 ? beanClass
0467: .getSimpleName() : stateless.name();
0468: return ejbName;
0469: }
0470:
0471: private boolean isValidAnnotationUsage(Class annotationClass,
0472: Class<?> beanClass, String ejbName, EjbModule ejbModule) {
0473: List<Class<? extends Annotation>> annotations = new ArrayList(
0474: asList(Stateless.class, Stateful.class,
0475: MessageDriven.class));
0476: annotations.remove(annotationClass);
0477:
0478: Map<String, Class<? extends Annotation>> names = new HashMap<String, Class<? extends Annotation>>();
0479:
0480: boolean b = true;
0481: for (Class<? extends Annotation> secondAnnotation : annotations) {
0482: Annotation annotation = beanClass
0483: .getAnnotation(secondAnnotation);
0484:
0485: if (annotation == null)
0486: continue;
0487:
0488: String secondEjbName = null;
0489: if (annotation instanceof Stateful) {
0490: secondEjbName = getEjbName((Stateful) annotation,
0491: beanClass);
0492: } else if (annotation instanceof Stateless) {
0493: secondEjbName = getEjbName((Stateless) annotation,
0494: beanClass);
0495: } else if (annotation instanceof MessageDriven) {
0496: secondEjbName = getEjbName(
0497: (MessageDriven) annotation, beanClass);
0498: }
0499:
0500: if (ejbName.equals(secondEjbName)) {
0501: ejbModule.getValidation().fail(ejbName,
0502: "multiplyAnnotatedAsBean",
0503: annotationClass.getSimpleName(),
0504: secondAnnotation.getSimpleName(), ejbName,
0505: beanClass.getName());
0506: }
0507: }
0508:
0509: if (beanClass.isInterface()) {
0510: ejbModule.getValidation().fail(ejbName,
0511: "interfaceAnnotatedAsBean",
0512: annotationClass.getSimpleName(),
0513: beanClass.getName());
0514: return false;
0515: }
0516:
0517: if (isAbstract(beanClass.getModifiers())) {
0518: ejbModule.getValidation().fail(ejbName,
0519: "abstractAnnotatedAsBean",
0520: annotationClass.getSimpleName(),
0521: beanClass.getName());
0522: return false;
0523: }
0524:
0525: return b;
0526: }
0527: }
0528:
0529: public static class ProcessAnnotatedBeans implements
0530: DynamicDeployer {
0531: public static final Set<String> knownResourceEnvTypes = new TreeSet<String>(
0532: asList("javax.ejb.SessionContext",
0533: "javax.ejb.EntityContext",
0534: "javax.ejb.MessageDrivenContext",
0535: "javax.transaction.UserTransaction",
0536: "javax.jms.Queue", "javax.jms.Topic",
0537: "javax.xml.ws.WebServiceContext",
0538: "javax.ejb.TimerService"));
0539:
0540: public static final Set<String> knownEnvironmentEntries = new TreeSet<String>(
0541: asList("boolean", "java.lang.Boolean", "char",
0542: "java.lang.Character", "byte",
0543: "java.lang.Byte", "short", "java.lang.Short",
0544: "int", "java.lang.Integer", "long",
0545: "java.lang.Long", "float", "java.lang.Float",
0546: "double", "java.lang.Double",
0547: "java.lang.String"));
0548:
0549: public AppModule deploy(AppModule appModule)
0550: throws OpenEJBException {
0551: for (EjbModule ejbModule : appModule.getEjbModules()) {
0552: getValidationContext().set(ejbModule.getValidation());
0553: try {
0554: deploy(ejbModule);
0555: } finally {
0556: getValidationContext().remove();
0557: }
0558: }
0559: for (ClientModule clientModule : appModule
0560: .getClientModules()) {
0561: getValidationContext()
0562: .set(clientModule.getValidation());
0563: try {
0564: deploy(clientModule);
0565: } finally {
0566: getValidationContext().remove();
0567: }
0568: }
0569: for (ConnectorModule connectorModule : appModule
0570: .getResourceModules()) {
0571: getValidationContext().set(
0572: connectorModule.getValidation());
0573: try {
0574: deploy(connectorModule);
0575: } finally {
0576: getValidationContext().remove();
0577: }
0578: }
0579: for (WebModule webModule : appModule.getWebModules()) {
0580: getValidationContext().set(webModule.getValidation());
0581: try {
0582: deploy(webModule);
0583: } finally {
0584: getValidationContext().remove();
0585: }
0586: }
0587: return appModule;
0588: }
0589:
0590: public ClientModule deploy(ClientModule clientModule)
0591: throws OpenEJBException {
0592: if (clientModule.getApplicationClient() != null
0593: && clientModule.getApplicationClient()
0594: .isMetadataComplete())
0595: return clientModule;
0596:
0597: ClassLoader classLoader = clientModule.getClassLoader();
0598: Class<?> clazz;
0599: try {
0600: clazz = classLoader.loadClass(clientModule
0601: .getMainClass());
0602: } catch (ClassNotFoundException e) {
0603: throw new OpenEJBException(
0604: "Unable to load Client main-class: "
0605: + clientModule.getMainClass(), e);
0606: }
0607: ApplicationClient client = clientModule
0608: .getApplicationClient();
0609: ClassFinder inheritedClassFinder = createInheritedClassFinder(clazz);
0610: buildAnnotatedRefs(client, inheritedClassFinder,
0611: classLoader);
0612: processWebServiceClientHandlers(client, classLoader);
0613:
0614: return clientModule;
0615: }
0616:
0617: public ConnectorModule deploy(ConnectorModule connectorModule)
0618: throws OpenEJBException {
0619: // resource modules currently don't have any annotations
0620: return connectorModule;
0621: }
0622:
0623: public WebModule deploy(WebModule webModule)
0624: throws OpenEJBException {
0625: WebApp webApp = webModule.getWebApp();
0626: if (webApp != null && webApp.isMetadataComplete())
0627: return webModule;
0628:
0629: Set<Class<?>> classes = new HashSet<Class<?>>();
0630: ClassLoader classLoader = webModule.getClassLoader();
0631: for (Servlet servlet : webApp.getServlet()) {
0632: String servletClass = servlet.getServletClass();
0633: if (servletClass != null) {
0634: try {
0635: Class clazz = classLoader
0636: .loadClass(servletClass);
0637: classes.add(clazz);
0638: } catch (ClassNotFoundException e) {
0639: throw new OpenEJBException(
0640: "Unable to load servlet class: "
0641: + servletClass, e);
0642: }
0643: }
0644: }
0645: for (Filter filter : webApp.getFilter()) {
0646: String filterClass = filter.getFilterClass();
0647: if (filterClass != null) {
0648: try {
0649: Class clazz = classLoader
0650: .loadClass(filterClass);
0651: classes.add(clazz);
0652: } catch (ClassNotFoundException e) {
0653: throw new OpenEJBException(
0654: "Unable to load servlet filter class: "
0655: + filterClass, e);
0656: }
0657: }
0658: }
0659: for (Listener listener : webApp.getListener()) {
0660: String listenerClass = listener.getListenerClass();
0661: if (listenerClass != null) {
0662: try {
0663: Class clazz = classLoader
0664: .loadClass(listenerClass);
0665: classes.add(clazz);
0666: } catch (ClassNotFoundException e) {
0667: throw new OpenEJBException(
0668: "Unable to load servlet listener class: "
0669: + listenerClass, e);
0670: }
0671: }
0672: }
0673: for (TldTaglib taglib : webModule.getTaglibs()) {
0674: for (Listener listener : taglib.getListener()) {
0675: String listenerClass = listener.getListenerClass();
0676: if (listenerClass != null) {
0677: try {
0678: Class clazz = classLoader
0679: .loadClass(listenerClass);
0680: classes.add(clazz);
0681: } catch (ClassNotFoundException e) {
0682: throw new OpenEJBException(
0683: "Unable to load tag library servlet listener class: "
0684: + listenerClass, e);
0685: }
0686: }
0687: }
0688: for (Tag tag : taglib.getTag()) {
0689: String tagClass = tag.getTagClass();
0690: if (tagClass != null) {
0691: try {
0692: Class clazz = classLoader
0693: .loadClass(tagClass);
0694: classes.add(clazz);
0695: } catch (ClassNotFoundException e) {
0696: throw new OpenEJBException(
0697: "Unable to load tag library tag class: "
0698: + tagClass, e);
0699: }
0700: }
0701: }
0702: }
0703: if (webModule.getWebservices() != null) {
0704: for (WebserviceDescription webservice : webModule
0705: .getWebservices().getWebserviceDescription()) {
0706: for (PortComponent port : webservice
0707: .getPortComponent()) {
0708: // skip ejb port defs
0709: if (port.getServiceImplBean().getEjbLink() != null)
0710: continue;
0711:
0712: if (port.getHandlerChains() == null)
0713: continue;
0714: for (org.apache.openejb.jee.HandlerChain handlerChain : port
0715: .getHandlerChains().getHandlerChain()) {
0716: for (Handler handler : handlerChain
0717: .getHandler()) {
0718: String handlerClass = handler
0719: .getHandlerClass();
0720: if (handlerClass != null) {
0721: try {
0722: Class clazz = classLoader
0723: .loadClass(handlerClass);
0724: classes.add(clazz);
0725: } catch (ClassNotFoundException e) {
0726: throw new OpenEJBException(
0727: "Unable to load webservice handler class: "
0728: + handlerClass,
0729: e);
0730: }
0731: }
0732: }
0733: }
0734: }
0735: }
0736: }
0737:
0738: ClassFinder inheritedClassFinder = createInheritedClassFinder(classes
0739: .toArray(new Class<?>[classes.size()]));
0740:
0741: // Currently we only process the JNDI annotations for web applications
0742: buildAnnotatedRefs(webApp, inheritedClassFinder,
0743: classLoader);
0744: processWebServiceClientHandlers(webApp, classLoader);
0745:
0746: return webModule;
0747: }
0748:
0749: public EjbModule deploy(EjbModule ejbModule)
0750: throws OpenEJBException {
0751: if (ejbModule.getEjbJar() != null
0752: && ejbModule.getEjbJar().isMetadataComplete())
0753: return ejbModule;
0754:
0755: ClassLoader classLoader = ejbModule.getClassLoader();
0756: EnterpriseBean[] enterpriseBeans = ejbModule.getEjbJar()
0757: .getEnterpriseBeans();
0758: for (EnterpriseBean bean : enterpriseBeans) {
0759: final String ejbName = bean.getEjbName();
0760:
0761: Class<?> clazz;
0762: try {
0763: clazz = classLoader.loadClass(bean.getEjbClass());
0764: } catch (ClassNotFoundException e) {
0765: throw new OpenEJBException(
0766: "Unable to load bean class: "
0767: + bean.getEjbClass(), e);
0768: }
0769: ClassFinder classFinder = new ClassFinder(clazz);
0770:
0771: ClassFinder inheritedClassFinder = createInheritedClassFinder(clazz);
0772:
0773: processCallbacks(bean, inheritedClassFinder);
0774:
0775: if (bean.getTransactionType() == null) {
0776: TransactionManagement tx = getInheritableAnnotation(
0777: clazz, TransactionManagement.class);
0778: TransactionManagementType transactionType = TransactionManagementType.CONTAINER;
0779: if (tx != null) {
0780: transactionType = tx.value();
0781: }
0782: switch (transactionType) {
0783: case BEAN:
0784: bean.setTransactionType(TransactionType.BEAN);
0785: break;
0786: case CONTAINER:
0787: bean
0788: .setTransactionType(TransactionType.CONTAINER);
0789: break;
0790: }
0791: }
0792:
0793: AssemblyDescriptor assemblyDescriptor = ejbModule
0794: .getEjbJar().getAssemblyDescriptor();
0795: if (assemblyDescriptor == null) {
0796: assemblyDescriptor = new AssemblyDescriptor();
0797: ejbModule.getEjbJar().setAssemblyDescriptor(
0798: assemblyDescriptor);
0799: }
0800:
0801: if (bean.getTransactionType() == TransactionType.CONTAINER) {
0802: processTransactionAttributes(clazz, ejbName,
0803: assemblyDescriptor, inheritedClassFinder);
0804: }
0805:
0806: processSecurityAnnotations(clazz, ejbName, ejbModule,
0807: inheritedClassFinder, bean);
0808:
0809: for (Class<?> interceptorsAnnotatedClass : inheritedClassFinder
0810: .findAnnotatedClasses(Interceptors.class)) {
0811: Interceptors interceptors = interceptorsAnnotatedClass
0812: .getAnnotation(Interceptors.class);
0813: EjbJar ejbJar = ejbModule.getEjbJar();
0814: for (Class interceptor : interceptors.value()) {
0815: if (ejbJar
0816: .getInterceptor(interceptor.getName()) == null) {
0817: ejbJar.addInterceptor(new Interceptor(
0818: interceptor.getName()));
0819: }
0820: }
0821:
0822: InterceptorBinding binding = new InterceptorBinding(
0823: bean);
0824: assemblyDescriptor.getInterceptorBinding().add(0,
0825: binding);
0826:
0827: for (Class interceptor : interceptors.value()) {
0828: binding.getInterceptorClass().add(
0829: interceptor.getName());
0830: }
0831: }
0832:
0833: for (Method method : inheritedClassFinder
0834: .findAnnotatedMethods(Interceptors.class)) {
0835: Interceptors interceptors = method
0836: .getAnnotation(Interceptors.class);
0837: if (interceptors != null) {
0838: EjbJar ejbJar = ejbModule.getEjbJar();
0839: for (Class interceptor : interceptors.value()) {
0840: if (ejbJar.getInterceptor(interceptor
0841: .getName()) == null) {
0842: ejbJar.addInterceptor(new Interceptor(
0843: interceptor.getName()));
0844: }
0845: }
0846:
0847: InterceptorBinding binding = new InterceptorBinding(
0848: bean);
0849: assemblyDescriptor.getInterceptorBinding().add(
0850: 0, binding);
0851:
0852: for (Class interceptor : interceptors.value()) {
0853: binding.getInterceptorClass().add(
0854: interceptor.getName());
0855: }
0856:
0857: binding.setMethod(new NamedMethod(method));
0858: }
0859: }
0860:
0861: ExcludeDefaultInterceptors excludeDefaultInterceptors = clazz
0862: .getAnnotation(ExcludeDefaultInterceptors.class);
0863: if (excludeDefaultInterceptors != null) {
0864: InterceptorBinding binding = assemblyDescriptor
0865: .addInterceptorBinding(new InterceptorBinding(
0866: bean));
0867: binding.setExcludeDefaultInterceptors(true);
0868: }
0869:
0870: for (Method method : classFinder
0871: .findAnnotatedMethods(ExcludeDefaultInterceptors.class)) {
0872: InterceptorBinding binding = assemblyDescriptor
0873: .addInterceptorBinding(new InterceptorBinding(
0874: bean));
0875: binding.setExcludeDefaultInterceptors(true);
0876: binding.setMethod(new NamedMethod(method));
0877: }
0878:
0879: ExcludeClassInterceptors excludeClassInterceptors = clazz
0880: .getAnnotation(ExcludeClassInterceptors.class);
0881: if (excludeClassInterceptors != null) {
0882: InterceptorBinding binding = assemblyDescriptor
0883: .addInterceptorBinding(new InterceptorBinding(
0884: bean));
0885: binding.setExcludeClassInterceptors(true);
0886: }
0887:
0888: for (Method method : classFinder
0889: .findAnnotatedMethods(ExcludeClassInterceptors.class)) {
0890: InterceptorBinding binding = assemblyDescriptor
0891: .addInterceptorBinding(new InterceptorBinding(
0892: bean));
0893: binding.setExcludeClassInterceptors(true);
0894: binding.setMethod(new NamedMethod(method));
0895: }
0896:
0897: if (bean instanceof RemoteBean) {
0898: RemoteBean remoteBean = (RemoteBean) bean;
0899:
0900: if (remoteBean.getHome() == null) {
0901: RemoteHome remoteHome = getInheritableAnnotation(
0902: clazz, RemoteHome.class);
0903: if (remoteHome != null) {
0904: Class<?> homeClass = remoteHome.value();
0905: try {
0906: Method create = null;
0907: for (Method method : homeClass
0908: .getMethods()) {
0909: if (method.getName().startsWith(
0910: "create")) {
0911: create = method;
0912: break;
0913: }
0914: }
0915: if (create == null)
0916: throw new NoSuchMethodException(
0917: "create");
0918:
0919: Class<?> remoteClass = create
0920: .getReturnType();
0921: remoteBean.setHome(homeClass.getName());
0922: remoteBean.setRemote(remoteClass
0923: .getName());
0924: } catch (NoSuchMethodException e) {
0925: logger
0926: .error("Class annotated as a RemoteHome has no 'create()' method. Unable to determine remote interface type. Bean class: "
0927: + clazz.getName()
0928: + ", Home class: "
0929: + homeClass.getName());
0930: }
0931: }
0932: }
0933:
0934: if (remoteBean.getLocalHome() == null) {
0935: LocalHome localHome = getInheritableAnnotation(
0936: clazz, LocalHome.class);
0937: if (localHome != null) {
0938: Class<?> homeClass = localHome.value();
0939: try {
0940: Method create = null;
0941: for (Method method : homeClass
0942: .getMethods()) {
0943: if (method.getName().startsWith(
0944: "create")) {
0945: create = method;
0946: break;
0947: }
0948: }
0949: if (create == null)
0950: throw new NoSuchMethodException(
0951: "create");
0952:
0953: Class<?> remoteClass = create
0954: .getReturnType();
0955: remoteBean.setLocalHome(homeClass
0956: .getName());
0957: remoteBean.setLocal(remoteClass
0958: .getName());
0959: } catch (NoSuchMethodException e) {
0960: logger
0961: .error("Class annotated as a LocalHome has no 'create()' method. Unable to determine remote interface type. Bean class: "
0962: + clazz.getName()
0963: + ", Home class: "
0964: + homeClass.getName());
0965: }
0966: }
0967: }
0968:
0969: if (remoteBean instanceof SessionBean) {
0970: SessionBean sessionBean = (SessionBean) remoteBean;
0971:
0972: processSessionInterfaces(sessionBean, clazz,
0973: ejbModule);
0974: }
0975: }
0976:
0977: if (bean instanceof MessageDrivenBean) {
0978: MessageDrivenBean mdb = (MessageDrivenBean) bean;
0979: MessageDriven messageDriven = clazz
0980: .getAnnotation(MessageDriven.class);
0981: if (messageDriven != null) {
0982: javax.ejb.ActivationConfigProperty[] configProperties = messageDriven
0983: .activationConfig();
0984: if (configProperties != null) {
0985: ActivationConfig activationConfig = mdb
0986: .getActivationConfig();
0987: if (activationConfig == null) {
0988: activationConfig = new ActivationConfig();
0989: mdb
0990: .setActivationConfig(activationConfig);
0991: }
0992: Properties properties = activationConfig
0993: .toProperties();
0994: for (javax.ejb.ActivationConfigProperty property : configProperties) {
0995: if (!properties.containsKey(property
0996: .propertyName())) {
0997: activationConfig.addProperty(
0998: property.propertyName(),
0999: property.propertyValue());
1000: }
1001: }
1002: }
1003:
1004: if (mdb.getMessagingType() == null) {
1005: Class<?> interfce = messageDriven
1006: .messageListenerInterface();
1007: if (interfce != null
1008: && !interfce.equals(Object.class)) {
1009: if (!interfce.isInterface()) {
1010: // TODO: Move this check to o.a.o.c.rules.CheckClasses and do it for all MDBs, annotated or not
1011: throw new OpenEJBException(
1012: "MessageListenerInterface property of @MessageDriven is not an interface");
1013: }
1014: mdb
1015: .setMessagingType(interfce
1016: .getName());
1017: }
1018: }
1019: }
1020:
1021: if (mdb.getMessagingType() == null) {
1022: List<Class<?>> interfaces = new ArrayList<Class<?>>();
1023: for (Class<?> intf : clazz.getInterfaces()) {
1024: String name = intf.getName();
1025: if (!name.equals("java.io.Serializable")
1026: && !name
1027: .equals("java.io.Externalizable")
1028: && !name.startsWith("javax.ejb.")) {
1029: interfaces.add(intf);
1030: }
1031: }
1032:
1033: if (interfaces.size() != 1) {
1034: String msg = "When annotating a bean class as @MessageDriven without declaring messageListenerInterface, the bean must implement exactly one interface, no more and no less. beanClass="
1035: + clazz.getName() + " interfaces=";
1036: for (Class<?> intf : interfaces) {
1037: msg += intf.getName() + ", ";
1038: }
1039: // TODO: Make this a validation failure, not an exception
1040: throw new IllegalStateException(msg);
1041: }
1042: mdb.setMessagingType(interfaces.get(0)
1043: .getName());
1044: }
1045: }
1046:
1047: // add webservice handler classes to the class finder used in annotation processing
1048: Set<Class<?>> classes = new HashSet<Class<?>>();
1049: classes.add(clazz);
1050: if (ejbModule.getWebservices() != null) {
1051: for (WebserviceDescription webservice : ejbModule
1052: .getWebservices()
1053: .getWebserviceDescription()) {
1054: for (PortComponent port : webservice
1055: .getPortComponent()) {
1056: // only process port definitions for this ejb
1057: if (!ejbName.equals(port
1058: .getServiceImplBean().getEjbLink()))
1059: continue;
1060:
1061: if (port.getHandlerChains() == null)
1062: continue;
1063: for (org.apache.openejb.jee.HandlerChain handlerChain : port
1064: .getHandlerChains()
1065: .getHandlerChain()) {
1066: for (Handler handler : handlerChain
1067: .getHandler()) {
1068: String handlerClass = handler
1069: .getHandlerClass();
1070: if (handlerClass != null) {
1071: try {
1072: Class handlerClazz = classLoader
1073: .loadClass(handlerClass);
1074: classes.add(handlerClazz);
1075: } catch (ClassNotFoundException e) {
1076: throw new OpenEJBException(
1077: "Unable to load webservice handler class: "
1078: + handlerClass,
1079: e);
1080: }
1081: }
1082: }
1083: }
1084: }
1085: }
1086: }
1087: inheritedClassFinder = createInheritedClassFinder(classes
1088: .toArray(new Class<?>[classes.size()]));
1089:
1090: buildAnnotatedRefs(bean, inheritedClassFinder,
1091: classLoader);
1092: processWebServiceClientHandlers(bean, classLoader);
1093: }
1094:
1095: for (Interceptor interceptor : ejbModule.getEjbJar()
1096: .getInterceptors()) {
1097: Class<?> clazz;
1098: try {
1099: clazz = classLoader.loadClass(interceptor
1100: .getInterceptorClass());
1101: } catch (ClassNotFoundException e) {
1102: throw new OpenEJBException(
1103: "Unable to load interceptor class: "
1104: + interceptor.getInterceptorClass(),
1105: e);
1106: }
1107:
1108: ClassFinder inheritedClassFinder = createInheritedClassFinder(clazz);
1109:
1110: processCallbacks(interceptor, inheritedClassFinder);
1111:
1112: buildAnnotatedRefs(interceptor, inheritedClassFinder,
1113: classLoader);
1114: processWebServiceClientHandlers(interceptor,
1115: classLoader);
1116:
1117: for (EnterpriseBean bean : enterpriseBeans) {
1118: // DMB: TODO, we should actually check to see if the ref exists in the bean's enc.
1119: bean.getEnvEntry()
1120: .addAll(interceptor.getEnvEntry());
1121: bean.getEjbRef().addAll(interceptor.getEjbRef());
1122: bean.getEjbLocalRef().addAll(
1123: interceptor.getEjbLocalRef());
1124: bean.getResourceRef().addAll(
1125: interceptor.getResourceRef());
1126: bean.getResourceEnvRef().addAll(
1127: interceptor.getResourceEnvRef());
1128: bean.getPersistenceContextRef().addAll(
1129: interceptor.getPersistenceContextRef());
1130: bean.getPersistenceUnitRef().addAll(
1131: interceptor.getPersistenceUnitRef());
1132: bean.getMessageDestinationRef().addAll(
1133: interceptor.getMessageDestinationRef());
1134: bean.getServiceRef().addAll(
1135: interceptor.getServiceRef());
1136: }
1137: }
1138:
1139: return ejbModule;
1140: }
1141:
1142: private void processSessionInterfaces(SessionBean sessionBean,
1143: Class<?> beanClass, EjbModule ejbModule) {
1144:
1145: ValidationContext validation = ejbModule.getValidation();
1146: String ejbName = sessionBean.getEjbName();
1147:
1148: for (Class<?> clazz : ancestors(beanClass)) {
1149: // Anything declared in the xml is also not eligable
1150: List<String> declared = new ArrayList<String>();
1151: declared.addAll(sessionBean.getBusinessLocal());
1152: declared.addAll(sessionBean.getBusinessRemote());
1153: declared.add(sessionBean.getHome());
1154: declared.add(sessionBean.getRemote());
1155: declared.add(sessionBean.getLocalHome());
1156: declared.add(sessionBean.getLocal());
1157: declared.add(sessionBean.getServiceEndpoint());
1158:
1159: List<Class<?>> interfaces = new ArrayList<Class<?>>();
1160: for (Class<?> interfce : clazz.getInterfaces()) {
1161: String name = interfce.getName();
1162: if (!name.equals("java.io.Serializable")
1163: && !name.equals("java.io.Externalizable")
1164: && !name.startsWith("javax.ejb.")
1165: && !declared.contains(interfce.getName())) {
1166: interfaces.add(interfce);
1167: }
1168: }
1169:
1170: List<Class> remotes = new ArrayList<Class>();
1171: Remote remote = clazz.getAnnotation(Remote.class);
1172: if (remote != null) {
1173: if (remote.value().length == 0) {
1174: if (interfaces.size() != 1) {
1175: validation.fail(ejbName,
1176: "ann.remote.noAttributes", join(
1177: ", ", interfaces));
1178: } else if (clazz.getAnnotation(Local.class) != null) {
1179: validation.fail(ejbName,
1180: "ann.remoteLocal.ambiguous", join(
1181: ", ", interfaces));
1182: } else if (interfaces.get(0).getAnnotation(
1183: Local.class) != null) {
1184: validation.fail(ejbName,
1185: "ann.remoteLocal.conflict", join(
1186: ", ", interfaces));
1187: } else {
1188: if (validateRemoteInterface(interfaces
1189: .get(0), validation, ejbName)) {
1190: remotes.add(interfaces.get(0));
1191: }
1192: interfaces.remove(0);
1193: }
1194: } else
1195: for (Class interfce : remote.value()) {
1196: if (validateRemoteInterface(interfce,
1197: validation, ejbName)) {
1198: remotes.add(interfce);
1199: }
1200: interfaces.remove(interfce);
1201: }
1202: }
1203:
1204: List<Class> locals = new ArrayList<Class>();
1205: Local local = clazz.getAnnotation(Local.class);
1206: if (local != null) {
1207: if (local.value().length == 0) {
1208: if (interfaces.size() != 1) {
1209: validation.fail(ejbName,
1210: "ann.local.noAttributes", join(
1211: ", ", interfaces));
1212: } else if (clazz.getAnnotation(Remote.class) != null) {
1213: validation.fail(ejbName,
1214: "ann.localRemote.ambiguous", join(
1215: ", ", interfaces));
1216: } else if (interfaces.get(0).getAnnotation(
1217: Remote.class) != null) {
1218: validation.fail(ejbName,
1219: "ann.localRemote.conflict", join(
1220: ", ", interfaces));
1221: } else {
1222: if (validateLocalInterface(interfaces
1223: .get(0), validation, ejbName)) {
1224: locals.add(interfaces.get(0));
1225: }
1226: interfaces.remove(0);
1227: }
1228: } else
1229: for (Class interfce : local.value()) {
1230: if (validateLocalInterface(interfce,
1231: validation, ejbName)) {
1232: locals.add(interfce);
1233: }
1234: interfaces.remove(interfce);
1235: }
1236: }
1237:
1238: if (sessionBean.getServiceEndpoint() == null) {
1239: WebService webService = clazz
1240: .getAnnotation(WebService.class);
1241: if (webService != null) {
1242: String endpointInterfaceName = webService
1243: .endpointInterface();
1244: if (!endpointInterfaceName.equals("")) {
1245: try {
1246: sessionBean
1247: .setServiceEndpoint(endpointInterfaceName);
1248: Class endpointInterface = Class
1249: .forName(
1250: endpointInterfaceName,
1251: false,
1252: ejbModule
1253: .getClassLoader());
1254: interfaces.remove(endpointInterface);
1255: } catch (ClassNotFoundException e) {
1256: throw new IllegalStateException(
1257: "Class not found @WebService.endpointInterface: "
1258: + endpointInterfaceName,
1259: e);
1260: }
1261: } else {
1262: sessionBean
1263: .setServiceEndpoint(DeploymentInfo.ServiceEndpoint.class
1264: .getName());
1265: }
1266: } else if (clazz
1267: .isAnnotationPresent(WebServiceProvider.class)) {
1268: sessionBean
1269: .setServiceEndpoint(DeploymentInfo.ServiceEndpoint.class
1270: .getName());
1271: }
1272: }
1273:
1274: for (Class interfce : copy(interfaces)) {
1275: if (interfce.isAnnotationPresent(WebService.class)) {
1276: if (sessionBean.getServiceEndpoint().equals(
1277: DeploymentInfo.ServiceEndpoint.class
1278: .getName())) {
1279: sessionBean.setServiceEndpoint(interfce
1280: .getName());
1281: }
1282: interfaces.remove(interfce);
1283: } else if (interfce
1284: .isAnnotationPresent(Remote.class)) {
1285: remotes.add(interfce);
1286: interfaces.remove(interfce);
1287: } else {
1288: locals.add(interfce);
1289: interfaces.remove(interfce);
1290: }
1291: }
1292:
1293: for (Class interfce : remotes) {
1294: sessionBean.addBusinessRemote(interfce.getName());
1295: }
1296:
1297: for (Class interfce : locals) {
1298: sessionBean.addBusinessLocal(interfce.getName());
1299: }
1300: }
1301: }
1302:
1303: private void processSecurityAnnotations(Class<?> beanClass,
1304: String ejbName, EjbModule ejbModule,
1305: ClassFinder classFinder, EnterpriseBean bean) {
1306: AssemblyDescriptor assemblyDescriptor = ejbModule
1307: .getEjbJar().getAssemblyDescriptor();
1308:
1309: List<String> classPermissions = getDeclaredClassPermissions(
1310: assemblyDescriptor, ejbName);
1311:
1312: for (Class<?> clazz : ancestors(beanClass)) {
1313:
1314: if (!classPermissions.contains("*")
1315: || !classPermissions.contains(clazz.getName())) {
1316:
1317: RolesAllowed rolesAllowed = clazz
1318: .getAnnotation(RolesAllowed.class);
1319: PermitAll permitAll = clazz
1320: .getAnnotation(PermitAll.class);
1321:
1322: if (rolesAllowed != null && permitAll != null) {
1323: ejbModule.getValidation().fail(ejbName,
1324: "permitAllAndRolesAllowedOnClass",
1325: clazz.getName());
1326: }
1327:
1328: if (rolesAllowed != null) {
1329: MethodPermission methodPermission = new MethodPermission();
1330: methodPermission.getRoleName().addAll(
1331: asList(rolesAllowed.value()));
1332: methodPermission.getMethod().add(
1333: new org.apache.openejb.jee.Method(
1334: ejbName, clazz.getName(), "*"));
1335: assemblyDescriptor.getMethodPermission().add(
1336: methodPermission);
1337: }
1338:
1339: if (permitAll != null) {
1340: MethodPermission methodPermission = new MethodPermission();
1341: methodPermission.setUnchecked(true);
1342: methodPermission.getMethod().add(
1343: new org.apache.openejb.jee.Method(
1344: ejbName, clazz.getName(), "*"));
1345: assemblyDescriptor.getMethodPermission().add(
1346: methodPermission);
1347: }
1348: }
1349:
1350: RunAs runAs = clazz.getAnnotation(RunAs.class);
1351: if (runAs != null && bean.getSecurityIdentity() == null) {
1352: SecurityIdentity securityIdentity = new SecurityIdentity();
1353: securityIdentity.setRunAs(runAs.value());
1354: bean.setSecurityIdentity(securityIdentity);
1355: }
1356:
1357: DeclareRoles declareRoles = clazz
1358: .getAnnotation(DeclareRoles.class);
1359: if (declareRoles != null && bean instanceof RemoteBean) {
1360: RemoteBean remoteBean = (RemoteBean) bean;
1361: List<SecurityRoleRef> securityRoleRefs = remoteBean
1362: .getSecurityRoleRef();
1363: for (String role : declareRoles.value()) {
1364: securityRoleRefs.add(new SecurityRoleRef(role));
1365: }
1366: }
1367: }
1368:
1369: List<Method> seen = new ArrayList<Method>();
1370:
1371: for (Method method : classFinder
1372: .findAnnotatedMethods(RolesAllowed.class)) {
1373: checkConflictingSecurityAnnotations(method, ejbName,
1374: ejbModule, seen);
1375: RolesAllowed rolesAllowed = method
1376: .getAnnotation(RolesAllowed.class);
1377: MethodPermission methodPermission = new MethodPermission();
1378: methodPermission.getRoleName().addAll(
1379: asList(rolesAllowed.value()));
1380: methodPermission.getMethod().add(
1381: new org.apache.openejb.jee.Method(ejbName,
1382: method));
1383: assemblyDescriptor.getMethodPermission().add(
1384: methodPermission);
1385: }
1386:
1387: for (Method method : classFinder
1388: .findAnnotatedMethods(PermitAll.class)) {
1389: checkConflictingSecurityAnnotations(method, ejbName,
1390: ejbModule, seen);
1391: MethodPermission methodPermission = new MethodPermission();
1392: methodPermission.setUnchecked(true);
1393: methodPermission.getMethod().add(
1394: new org.apache.openejb.jee.Method(ejbName,
1395: method));
1396: assemblyDescriptor.getMethodPermission().add(
1397: methodPermission);
1398: }
1399:
1400: for (Method method : classFinder
1401: .findAnnotatedMethods(DenyAll.class)) {
1402: checkConflictingSecurityAnnotations(method, ejbName,
1403: ejbModule, seen);
1404: ExcludeList excludeList = assemblyDescriptor
1405: .getExcludeList();
1406: excludeList
1407: .addMethod(new org.apache.openejb.jee.Method(
1408: ejbName, method));
1409: }
1410:
1411: }
1412:
1413: private void checkConflictingSecurityAnnotations(Method method,
1414: String ejbName, EjbModule ejbModule, List<Method> seen) {
1415: if (seen.contains(method))
1416: return;
1417: seen.add(method);
1418:
1419: List<String> annotations = new ArrayList<String>();
1420: for (Class<? extends Annotation> annotation : asList(
1421: RolesAllowed.class, PermitAll.class, DenyAll.class)) {
1422: if (method.getAnnotation(annotation) != null) {
1423: annotations.add("@" + annotation.getSimpleName());
1424: }
1425: }
1426:
1427: if (annotations.size() > 1) {
1428: ejbModule.getValidation().fail(ejbName,
1429: "conflictingSecurityAnnotations",
1430: method.getName(), join(" and ", annotations),
1431: method.getDeclaringClass());
1432: }
1433: }
1434:
1435: private List<String> getDeclaredClassPermissions(
1436: AssemblyDescriptor assemblyDescriptor, String ejbName) {
1437: List<MethodPermission> permissions = assemblyDescriptor
1438: .getMethodPermission();
1439: List<String> classPermissions = new ArrayList<String>();
1440: for (MethodPermission permission : permissions) {
1441: for (org.apache.openejb.jee.Method method : permission
1442: .getMethod()) {
1443: if (!method.getEjbName().equals(ejbName))
1444: continue;
1445: if (!"*".equals(method.getMethodName()))
1446: continue;
1447:
1448: String className = method.getClassName();
1449: if (className == null) {
1450: className = "*";
1451: }
1452: classPermissions.add(className);
1453: }
1454: }
1455: return classPermissions;
1456: }
1457:
1458: private void processTransactionAttributes(Class<?> clazz,
1459: String ejbName, AssemblyDescriptor assemblyDescriptor,
1460: ClassFinder classFinder) {
1461:
1462: Map<String, List<MethodTransaction>> methodTransactions = assemblyDescriptor
1463: .getMethodTransactions(ejbName);
1464:
1465: // SET THE DEFAULT
1466: if (!hasMethodTransaction("*", null, methodTransactions)) {
1467: for (Class<?> type : ancestors(clazz)) {
1468: if (!hasMethodTransaction("*", type,
1469: methodTransactions)) {
1470: TransactionAttribute attribute = type
1471: .getAnnotation(TransactionAttribute.class);
1472: if (attribute != null) {
1473: ContainerTransaction ctx = new ContainerTransaction(
1474: cast(attribute.value()), type
1475: .getName(), ejbName, "*");
1476: assemblyDescriptor
1477: .getContainerTransaction().add(ctx);
1478: }
1479: }
1480: }
1481:
1482: }
1483:
1484: List<Method> methods = classFinder
1485: .findAnnotatedMethods(TransactionAttribute.class);
1486: for (Method method : methods) {
1487: TransactionAttribute attribute = method
1488: .getAnnotation(TransactionAttribute.class);
1489: if (!methodTransactions.containsKey(method.getName())) {
1490: // no method with this name in descriptor
1491: addContainerTransaction(attribute, ejbName, method,
1492: assemblyDescriptor);
1493: } else {
1494: // method name already declared
1495: List<MethodTransaction> list = methodTransactions
1496: .get(method.getName());
1497: for (MethodTransaction mtx : list) {
1498: MethodParams methodParams = mtx
1499: .getMethodParams();
1500: if (methodParams == null) {
1501: // params not specified, so this is more specific
1502: addContainerTransaction(attribute, ejbName,
1503: method, assemblyDescriptor);
1504: } else {
1505: List<String> params1 = methodParams
1506: .getMethodParam();
1507: String[] params2 = asStrings(method
1508: .getParameterTypes());
1509: if (params1.size() != params2.length) {
1510: // params not the same
1511: addContainerTransaction(attribute,
1512: ejbName, method,
1513: assemblyDescriptor);
1514: } else {
1515: for (int i = 0; i < params1.size(); i++) {
1516: String a = params1.get(i);
1517: String b = params2[i];
1518: if (!a.equals(b)) {
1519: // params not the same
1520: addContainerTransaction(
1521: attribute, ejbName,
1522: method,
1523: assemblyDescriptor);
1524: break;
1525: }
1526: }
1527: }
1528: }
1529: }
1530: }
1531: }
1532: }
1533:
1534: public static void main(String[] args) {
1535: System.out.println(null + "");
1536: }
1537:
1538: private boolean hasMethodTransaction(String methodName,
1539: Class clazz, Map<String, List<MethodTransaction>> map) {
1540: return getMethodTransaction(methodName, clazz, map) != null;
1541: }
1542:
1543: private MethodTransaction getMethodTransaction(
1544: String methodName, Class clazz,
1545: Map<String, List<MethodTransaction>> map) {
1546: List<MethodTransaction> methodTransactions = map
1547: .get(methodName);
1548: if (methodTransactions == null)
1549: return null;
1550:
1551: for (MethodTransaction methodTransaction : methodTransactions) {
1552: String className = (clazz != null) ? clazz.getName()
1553: : null + "";
1554:
1555: if (className.equals(methodTransaction.getClassName()
1556: + "")) {
1557: return methodTransaction;
1558: }
1559: }
1560: return null;
1561: }
1562:
1563: private <A extends Annotation> A getInheritableAnnotation(
1564: Class clazz, Class<A> annotationClass) {
1565: if (clazz == null || clazz.equals(Object.class))
1566: return null;
1567:
1568: Annotation annotation = clazz
1569: .getAnnotation(annotationClass);
1570: if (annotation != null) {
1571: return (A) annotation;
1572: }
1573:
1574: return getInheritableAnnotation(clazz.getSuperclass(),
1575: annotationClass);
1576: }
1577:
1578: private List<Class<?>> ancestors(Class clazz) {
1579: ArrayList<Class<?>> ancestors = new ArrayList<Class<?>>();
1580:
1581: while (clazz != null && !clazz.equals(Object.class)) {
1582: ancestors.add(clazz);
1583: clazz = clazz.getSuperclass();
1584: }
1585:
1586: return ancestors;
1587: }
1588:
1589: private ClassFinder createInheritedClassFinder(
1590: Class<?>... classes) {
1591: List<Class> parents = new ArrayList<Class>();
1592: for (Class<?> clazz : classes) {
1593: parents.addAll(ancestors(clazz));
1594: }
1595:
1596: return new ClassFinder(parents);
1597: }
1598:
1599: private void processCallbacks(Lifecycle bean,
1600: ClassFinder classFinder) {
1601: LifecycleCallback postConstruct = getFirst(bean
1602: .getPostConstruct());
1603: if (postConstruct == null) {
1604: for (Method method : classFinder
1605: .findAnnotatedMethods(PostConstruct.class)) {
1606: bean.getPostConstruct().add(
1607: new LifecycleCallback(method));
1608: }
1609: }
1610:
1611: LifecycleCallback preDestroy = getFirst(bean
1612: .getPreDestroy());
1613: if (preDestroy == null) {
1614: for (Method method : classFinder
1615: .findAnnotatedMethods(PreDestroy.class)) {
1616: bean.getPreDestroy().add(
1617: new LifecycleCallback(method));
1618: }
1619: }
1620:
1621: AroundInvoke aroundInvoke = getFirst(bean.getAroundInvoke());
1622: if (aroundInvoke == null) {
1623: for (Method method : classFinder
1624: .findAnnotatedMethods(javax.interceptor.AroundInvoke.class)) {
1625: bean.getAroundInvoke()
1626: .add(new AroundInvoke(method));
1627: }
1628: }
1629:
1630: if (bean instanceof TimerConsumer) {
1631: TimerConsumer timerConsumer = (TimerConsumer) bean;
1632: if (timerConsumer.getTimeoutMethod() == null) {
1633: List<Method> timeoutMethods = classFinder
1634: .findAnnotatedMethods(javax.ejb.Timeout.class);
1635: for (Method method : timeoutMethods) {
1636: timerConsumer.setTimeoutMethod(new NamedMethod(
1637: method));
1638: }
1639: }
1640: }
1641:
1642: if (bean instanceof org.apache.openejb.jee.Session) {
1643: org.apache.openejb.jee.Session session = (org.apache.openejb.jee.Session) bean;
1644:
1645: LifecycleCallback postActivate = getFirst(session
1646: .getPostActivate());
1647: if (postActivate == null) {
1648: for (Method method : classFinder
1649: .findAnnotatedMethods(PostActivate.class)) {
1650: session.getPostActivate().add(
1651: new LifecycleCallback(method));
1652: }
1653: }
1654:
1655: LifecycleCallback prePassivate = getFirst(session
1656: .getPrePassivate());
1657: if (prePassivate == null) {
1658: for (Method method : classFinder
1659: .findAnnotatedMethods(PrePassivate.class)) {
1660: session.getPrePassivate().add(
1661: new LifecycleCallback(method));
1662: }
1663: }
1664:
1665: List<Method> initMethods = classFinder
1666: .findAnnotatedMethods(Init.class);
1667: for (Method method : initMethods) {
1668: InitMethod initMethod = new InitMethod(method);
1669:
1670: Init init = method.getAnnotation(Init.class);
1671: if (init.value() != null
1672: && !init.value().equals("")) {
1673: initMethod.setCreateMethod(init.value());
1674: }
1675:
1676: session.getInitMethod().add(initMethod);
1677: }
1678:
1679: List<Method> removeMethods = classFinder
1680: .findAnnotatedMethods(Remove.class);
1681: Map<NamedMethod, RemoveMethod> declaredRemoveMethods = new HashMap<NamedMethod, RemoveMethod>();
1682: for (RemoveMethod removeMethod : session
1683: .getRemoveMethod()) {
1684: declaredRemoveMethods.put(removeMethod
1685: .getBeanMethod(), removeMethod);
1686: }
1687: for (Method method : removeMethods) {
1688: Remove remove = method.getAnnotation(Remove.class);
1689: RemoveMethod removeMethod = new RemoveMethod(
1690: method, remove.retainIfException());
1691:
1692: RemoveMethod declaredRemoveMethod = declaredRemoveMethods
1693: .get(removeMethod.getBeanMethod());
1694:
1695: if (declaredRemoveMethod == null) {
1696: session.getRemoveMethod().add(removeMethod);
1697: } else if (!declaredRemoveMethod.isExplicitlySet()) {
1698: declaredRemoveMethod
1699: .setRetainIfException(remove
1700: .retainIfException());
1701: }
1702: }
1703: }
1704: }
1705:
1706: private void buildAnnotatedRefs(JndiConsumer consumer,
1707: ClassFinder classFinder, ClassLoader classLoader)
1708: throws OpenEJBException {
1709: //
1710: // @EJB
1711: //
1712:
1713: List<EJB> ejbList = new ArrayList<EJB>();
1714: for (Class<?> clazz : classFinder
1715: .findAnnotatedClasses(EJBs.class)) {
1716: EJBs ejbs = clazz.getAnnotation(EJBs.class);
1717: ejbList.addAll(asList(ejbs.value()));
1718: }
1719: for (Class<?> clazz : classFinder
1720: .findAnnotatedClasses(EJB.class)) {
1721: EJB e = clazz.getAnnotation(EJB.class);
1722: ejbList.add(e);
1723: }
1724:
1725: for (EJB ejb : ejbList) {
1726: buildEjbRef(consumer, ejb, null);
1727: }
1728:
1729: for (Field field : classFinder
1730: .findAnnotatedFields(EJB.class)) {
1731: EJB ejb = field.getAnnotation(EJB.class);
1732:
1733: Member member = new FieldMember(field);
1734:
1735: buildEjbRef(consumer, ejb, member);
1736: }
1737:
1738: for (Method method : classFinder
1739: .findAnnotatedMethods(EJB.class)) {
1740: EJB ejb = method.getAnnotation(EJB.class);
1741:
1742: Member member = new MethodMember(method);
1743:
1744: buildEjbRef(consumer, ejb, member);
1745: }
1746:
1747: //
1748: // @Resource
1749: //
1750:
1751: List<Resource> resourceList = new ArrayList<Resource>();
1752: for (Class<?> clazz : classFinder
1753: .findAnnotatedClasses(Resources.class)) {
1754: Resources resources = clazz
1755: .getAnnotation(Resources.class);
1756: resourceList.addAll(asList(resources.value()));
1757: }
1758: for (Class<?> clazz : classFinder
1759: .findAnnotatedClasses(Resource.class)) {
1760: Resource resource = clazz.getAnnotation(Resource.class);
1761: resourceList.add(resource);
1762: }
1763:
1764: for (Resource resource : resourceList) {
1765: buildResource(consumer, resource, null);
1766: }
1767:
1768: for (Field field : classFinder
1769: .findAnnotatedFields(Resource.class)) {
1770: Resource resource = field.getAnnotation(Resource.class);
1771:
1772: Member member = new FieldMember(field);
1773:
1774: buildResource(consumer, resource, member);
1775: }
1776:
1777: for (Method method : classFinder
1778: .findAnnotatedMethods(Resource.class)) {
1779: Resource resource = method
1780: .getAnnotation(Resource.class);
1781:
1782: Member member = new MethodMember(method);
1783:
1784: buildResource(consumer, resource, member);
1785: }
1786:
1787: //
1788: // @WebServiceRef
1789: //
1790:
1791: List<WebServiceRef> webservicerefList = new ArrayList<WebServiceRef>();
1792: for (Class<?> clazz : classFinder
1793: .findAnnotatedClasses(WebServiceRefs.class)) {
1794: WebServiceRefs webServiceRefs = clazz
1795: .getAnnotation(WebServiceRefs.class);
1796: webservicerefList
1797: .addAll(asList(webServiceRefs.value()));
1798: }
1799: for (Class<?> clazz : classFinder
1800: .findAnnotatedClasses(WebServiceRef.class)) {
1801: WebServiceRef webServiceRef = clazz
1802: .getAnnotation(WebServiceRef.class);
1803: webservicerefList.add(webServiceRef);
1804: }
1805:
1806: for (WebServiceRef webserviceref : webservicerefList) {
1807:
1808: buildWebServiceRef(consumer, webserviceref, null, null,
1809: classLoader);
1810: }
1811:
1812: for (Field field : classFinder
1813: .findAnnotatedFields(WebServiceRef.class)) {
1814: WebServiceRef webserviceref = field
1815: .getAnnotation(WebServiceRef.class);
1816: HandlerChain handlerChain = field
1817: .getAnnotation(HandlerChain.class);
1818:
1819: Member member = new FieldMember(field);
1820:
1821: buildWebServiceRef(consumer, webserviceref,
1822: handlerChain, member, classLoader);
1823: }
1824:
1825: for (Method method : classFinder
1826: .findAnnotatedMethods(WebServiceRef.class)) {
1827: WebServiceRef webserviceref = method
1828: .getAnnotation(WebServiceRef.class);
1829: HandlerChain handlerChain = method
1830: .getAnnotation(HandlerChain.class);
1831:
1832: Member member = new MethodMember(method);
1833:
1834: buildWebServiceRef(consumer, webserviceref,
1835: handlerChain, member, classLoader);
1836: }
1837:
1838: //
1839: // @PersistenceUnit
1840: //
1841:
1842: List<PersistenceUnit> persistenceUnitList = new ArrayList<PersistenceUnit>();
1843: for (Class<?> clazz : classFinder
1844: .findAnnotatedClasses(PersistenceUnits.class)) {
1845: PersistenceUnits persistenceUnits = clazz
1846: .getAnnotation(PersistenceUnits.class);
1847: persistenceUnitList.addAll(asList(persistenceUnits
1848: .value()));
1849: }
1850: for (Class<?> clazz : classFinder
1851: .findAnnotatedClasses(PersistenceUnit.class)) {
1852: PersistenceUnit persistenceUnit = clazz
1853: .getAnnotation(PersistenceUnit.class);
1854: persistenceUnitList.add(persistenceUnit);
1855: }
1856: for (PersistenceUnit pUnit : persistenceUnitList) {
1857: buildPersistenceUnit(consumer, pUnit, null);
1858: }
1859: for (Field field : classFinder
1860: .findAnnotatedFields(PersistenceUnit.class)) {
1861: PersistenceUnit pUnit = field
1862: .getAnnotation(PersistenceUnit.class);
1863: Member member = new FieldMember(field);
1864: buildPersistenceUnit(consumer, pUnit, member);
1865: }
1866: for (Method method : classFinder
1867: .findAnnotatedMethods(PersistenceUnit.class)) {
1868: PersistenceUnit pUnit = method
1869: .getAnnotation(PersistenceUnit.class);
1870: Member member = new MethodMember(method);
1871: buildPersistenceUnit(consumer, pUnit, member);
1872: }
1873:
1874: //
1875: // @PersistenceContext
1876: //
1877:
1878: PersistenceContextAnnFactory pcFactory = new PersistenceContextAnnFactory();
1879: List<PersistenceContext> persistenceContextList = new ArrayList<PersistenceContext>();
1880: for (Class<?> clazz : classFinder
1881: .findAnnotatedClasses(PersistenceContexts.class)) {
1882: PersistenceContexts persistenceContexts = clazz
1883: .getAnnotation(PersistenceContexts.class);
1884: persistenceContextList
1885: .addAll(asList(persistenceContexts.value()));
1886: pcFactory.addAnnotations(clazz);
1887: }
1888: for (Class<?> clazz : classFinder
1889: .findAnnotatedClasses(PersistenceContext.class)) {
1890: PersistenceContext persistenceContext = clazz
1891: .getAnnotation(PersistenceContext.class);
1892: persistenceContextList.add(persistenceContext);
1893: pcFactory.addAnnotations(clazz);
1894: }
1895: for (PersistenceContext pCtx : persistenceContextList) {
1896: buildPersistenceContext(consumer, pcFactory.create(
1897: pCtx, null), null);
1898: }
1899: for (Field field : classFinder
1900: .findAnnotatedFields(PersistenceContext.class)) {
1901: PersistenceContext pCtx = field
1902: .getAnnotation(PersistenceContext.class);
1903: Member member = new FieldMember(field);
1904: buildPersistenceContext(consumer, pcFactory.create(
1905: pCtx, member), member);
1906: }
1907: for (Method method : classFinder
1908: .findAnnotatedMethods(PersistenceContext.class)) {
1909: PersistenceContext pCtx = method
1910: .getAnnotation(PersistenceContext.class);
1911: Member member = new MethodMember(method);
1912: buildPersistenceContext(consumer, pcFactory.create(
1913: pCtx, member), member);
1914: }
1915:
1916: }
1917:
1918: private void processWebServiceClientHandlers(
1919: JndiConsumer consumer, ClassLoader classLoader)
1920: throws OpenEJBException {
1921: if (System.getProperty("duct tape") != null)
1922: return;
1923: Set<Class<?>> processedClasses = new HashSet<Class<?>>();
1924: Set<Class<?>> handlerClasses = new HashSet<Class<?>>();
1925: do {
1926: // get unprocessed handler classes
1927: handlerClasses.clear();
1928: for (ServiceRef serviceRef : consumer.getServiceRef()) {
1929: HandlerChains chains = serviceRef.getAllHandlers();
1930: if (chains == null)
1931: continue;
1932: for (org.apache.openejb.jee.HandlerChain handlerChain : chains
1933: .getHandlerChain()) {
1934: for (Handler handler : handlerChain
1935: .getHandler()) {
1936: if (handler.getHandlerClass() != null) {
1937: try {
1938: Class clazz = classLoader
1939: .loadClass(handler
1940: .getHandlerClass());
1941: handlerClasses.add(clazz);
1942: } catch (ClassNotFoundException e) {
1943: throw new OpenEJBException(
1944: "Unable to load webservice handler class: "
1945: + handler
1946: .getHandlerClass(),
1947: e);
1948: }
1949: }
1950: }
1951: }
1952: }
1953: handlerClasses.removeAll(processedClasses);
1954:
1955: // process handler classes
1956: ClassFinder handlerClassFinder = createInheritedClassFinder(handlerClasses
1957: .toArray(new Class<?>[handlerClasses.size()]));
1958: buildAnnotatedRefs(consumer, handlerClassFinder,
1959: classLoader);
1960: processedClasses.addAll(handlerClasses);
1961: } while (!handlerClasses.isEmpty());
1962: }
1963:
1964: private void buildPersistenceUnit(JndiConsumer consumer,
1965: PersistenceUnit persistenceUnit, Member member)
1966: throws OpenEJBException {
1967: // Get the ref-name
1968: String refName = persistenceUnit.name();
1969: if (refName.equals("")) {
1970: refName = (member == null) ? null : member
1971: .getDeclaringClass().getName()
1972: + "/" + member.getName();
1973: }
1974:
1975: if (refName == null && member == null) {
1976: getValidationContext().get().fail(
1977: consumer.getJndiConsumerName(),
1978: "presistenceUnitAnnotation.onClassWithNoName",
1979: persistenceUnit.unitName());
1980: return;
1981: }
1982:
1983: PersistenceUnitRef persistenceUnitRef = consumer
1984: .getPersistenceUnitRefMap().get(refName);
1985: if (persistenceUnitRef == null) {
1986: persistenceUnitRef = new PersistenceUnitRef();
1987: persistenceUnitRef
1988: .setPersistenceUnitName(persistenceUnit
1989: .unitName());
1990: persistenceUnitRef.setPersistenceUnitRefName(refName);
1991: consumer.getPersistenceUnitRef()
1992: .add(persistenceUnitRef);
1993: }
1994: if (member != null) {
1995: Class type = member.getType();
1996: if (EntityManager.class.isAssignableFrom(type)) {
1997: ValidationContext validationContext = AnnotationDeployer
1998: .getValidationContext().get();
1999: String jndiConsumerName = consumer
2000: .getJndiConsumerName();
2001: String name = persistenceUnitRef.getName();
2002: validationContext
2003: .fail(
2004: jndiConsumerName,
2005: "presistenceUnitAnnotation.onEntityManager",
2006: name);
2007: } else if (!EntityManagerFactory.class
2008: .isAssignableFrom(type)) {
2009: getValidationContext()
2010: .get()
2011: .fail(
2012: consumer.getJndiConsumerName(),
2013: "presistenceUnitAnnotation.onNonEntityManagerFactory",
2014: persistenceUnitRef.getName());
2015: } else {
2016: // Set the member name where this will be injected
2017: InjectionTarget target = new InjectionTarget();
2018: target.setInjectionTargetClass(member
2019: .getDeclaringClass().getName());
2020: target.setInjectionTargetName(member.getName());
2021: persistenceUnitRef.getInjectionTarget().add(target);
2022: }
2023: }
2024:
2025: if (persistenceUnitRef.getPersistenceUnitName() == null
2026: && !persistenceUnit.unitName().equals("")) {
2027: persistenceUnitRef
2028: .setPersistenceUnitName(persistenceUnit
2029: .unitName());
2030: }
2031: }
2032:
2033: private void buildResource(JndiConsumer consumer,
2034: Resource resource, Member member) {
2035: // Get the ref-name
2036: String refName = resource.name();
2037: if (refName.equals("")) {
2038: refName = (member == null) ? null : member
2039: .getDeclaringClass().getName()
2040: + "/" + member.getName();
2041: }
2042:
2043: if (member == null) {
2044: boolean shouldReturn = false;
2045: if (resource.name().equals("")) {
2046: getValidationContext().get().fail(
2047: consumer.getJndiConsumerName(),
2048: "resourceAnnotation.onClassWithNoName");
2049: shouldReturn = true;
2050: }
2051: if (resource.type().equals(Object.class)) {
2052: getValidationContext().get().fail(
2053: consumer.getJndiConsumerName(),
2054: "resourceAnnotation.onClassWithNoType");
2055: shouldReturn = true;
2056: }
2057: if (shouldReturn)
2058: return;
2059: }
2060:
2061: JndiReference reference = consumer.getEnvEntryMap().get(
2062: refName);
2063: if (reference == null) {
2064:
2065: if (member != null) { // Little quick validation for common mistake
2066: Class type = member.getType();
2067: boolean shouldReturn = false;
2068: if (EntityManager.class.isAssignableFrom(type)) {
2069: getValidationContext().get().fail(
2070: consumer.getJndiConsumerName(),
2071: "resourceRef.onEntityManager", refName);
2072: shouldReturn = true;
2073: } else if (EntityManagerFactory.class
2074: .isAssignableFrom(type)) {
2075: getValidationContext().get().fail(
2076: consumer.getJndiConsumerName(),
2077: "resourceRef.onEntityManagerFactory",
2078: refName);
2079: shouldReturn = true;
2080: }
2081: if (shouldReturn)
2082: return;
2083: }
2084: String type;
2085: if (resource.type() != java.lang.Object.class) {
2086: type = resource.type().getName();
2087: } else {
2088: type = member.getType().getName();
2089: }
2090:
2091: if (knownResourceEnvTypes.contains(type)) {
2092: ResourceEnvRef resourceEnvRef = consumer
2093: .getResourceEnvRefMap().get(refName);
2094: if (resourceEnvRef == null) {
2095: resourceEnvRef = new ResourceEnvRef();
2096: resourceEnvRef.setName(refName);
2097: consumer.getResourceEnvRef()
2098: .add(resourceEnvRef);
2099: }
2100:
2101: if (resourceEnvRef.getResourceEnvRefType() == null
2102: || ("").equals(resourceEnvRef
2103: .getResourceEnvRefType())) {
2104: if (resource.type() != java.lang.Object.class) {
2105: resourceEnvRef
2106: .setResourceEnvRefType(resource
2107: .type().getName());
2108: } else {
2109: resourceEnvRef.setResourceEnvRefType(member
2110: .getType().getName());
2111: }
2112: }
2113: reference = resourceEnvRef;
2114: } else if (!knownEnvironmentEntries.contains(type)) {
2115: ResourceRef resourceRef = consumer
2116: .getResourceRefMap().get(refName);
2117:
2118: if (resourceRef == null) {
2119: resourceRef = new ResourceRef();
2120: resourceRef.setName(refName);
2121: consumer.getResourceRef().add(resourceRef);
2122: }
2123:
2124: if (resourceRef.getResAuth() == null) {
2125: if (resource.authenticationType() == Resource.AuthenticationType.APPLICATION) {
2126: resourceRef.setResAuth(ResAuth.APPLICATION);
2127: } else {
2128: resourceRef.setResAuth(ResAuth.CONTAINER);
2129: }
2130: }
2131:
2132: if (resourceRef.getResType() == null
2133: || ("").equals(resourceRef.getResType())) {
2134: if (resource.type() != java.lang.Object.class) {
2135: resourceRef.setResType(resource.type()
2136: .getName());
2137: } else {
2138: resourceRef.setResType(member.getType()
2139: .getName());
2140: }
2141: }
2142:
2143: if (resourceRef.getResSharingScope() == null) {
2144: if (resource.shareable()) {
2145: resourceRef
2146: .setResSharingScope(ResSharingScope.SHAREABLE);
2147: } else {
2148: resourceRef
2149: .setResSharingScope(ResSharingScope.UNSHAREABLE);
2150: }
2151: }
2152: reference = resourceRef;
2153: }
2154: }
2155: if (reference == null) {
2156: return;
2157: }
2158:
2159: // reference.setName(refName);
2160:
2161: if (member != null) {
2162: // Set the member name where this will be injected
2163: InjectionTarget target = new InjectionTarget();
2164: target.setInjectionTargetClass(member
2165: .getDeclaringClass().getName());
2166: target.setInjectionTargetName(member.getName());
2167: reference.getInjectionTarget().add(target);
2168: }
2169:
2170: // Override the mapped name if not set
2171: if (reference.getMappedName() == null
2172: && !resource.mappedName().equals("")) {
2173: reference.setMappedName(resource.mappedName());
2174: }
2175:
2176: }
2177:
2178: private void buildWebServiceRef(JndiConsumer consumer,
2179: WebServiceRef webService, HandlerChain handlerChain,
2180: Member member, ClassLoader classLoader)
2181: throws OpenEJBException {
2182:
2183: ServiceRef serviceRef;
2184:
2185: String refName = webService.name();
2186: if (refName.equals("")) {
2187: refName = (member == null) ? null : member
2188: .getDeclaringClass().getName()
2189: + "/" + member.getName();
2190: }
2191:
2192: serviceRef = consumer.getServiceRefMap().get(refName);
2193:
2194: if (serviceRef == null) {
2195: serviceRef = new ServiceRef();
2196: serviceRef.setServiceRefName(refName);
2197:
2198: consumer.getServiceRef().add(serviceRef);
2199: }
2200:
2201: if (member != null) {
2202: // Set the member name where this will be injected
2203: InjectionTarget target = new InjectionTarget();
2204: target.setInjectionTargetClass(member
2205: .getDeclaringClass().getName());
2206: target.setInjectionTargetName(member.getName());
2207: serviceRef.getInjectionTarget().add(target);
2208: }
2209:
2210: // Set service interface
2211: Class<?> serviceInterface = null;
2212: if (serviceRef.getServiceInterface() == null) {
2213: serviceInterface = webService.type();
2214: if (serviceInterface.equals(Object.class)) {
2215: if (member != null) {
2216: serviceInterface = member.getType();
2217: } else {
2218: serviceInterface = webService.value();
2219: }
2220: }
2221: }
2222: if (serviceInterface == null
2223: || !serviceInterface
2224: .isAssignableFrom(Service.class)) {
2225: serviceInterface = Service.class;
2226: }
2227: serviceRef.setServiceInterface(serviceInterface.getName());
2228:
2229: // reference type
2230: if (serviceRef.getServiceRefType() == null
2231: || ("").equals(serviceRef.getServiceRefType())) {
2232: if (webService.type() != java.lang.Object.class) {
2233: serviceRef.setServiceRefType(webService.type()
2234: .getName());
2235: } else {
2236: serviceRef.setServiceRefType(member.getType()
2237: .getName());
2238: }
2239: }
2240: Class<?> refType = null;
2241: try {
2242: refType = classLoader.loadClass(serviceRef.getType());
2243: } catch (ClassNotFoundException e) {
2244: }
2245:
2246: // Set the mappedName
2247: if (serviceRef.getMappedName() == null) {
2248: String mappedName = webService.mappedName();
2249: if (mappedName.equals("")) {
2250: mappedName = null;
2251: }
2252: serviceRef.setMappedName(mappedName);
2253: }
2254:
2255: // wsdl file
2256: if (serviceRef.getWsdlFile() == null) {
2257: String wsdlLocation = webService.wsdlLocation();
2258: if (!wsdlLocation.equals("")) {
2259: serviceRef.setWsdlFile(wsdlLocation);
2260: }
2261: }
2262:
2263: if (System.getProperty("duct tape") != null)
2264: return;
2265:
2266: if (serviceRef.getWsdlFile() == null && refType != null) {
2267: serviceRef.setWsdlFile(JaxWsUtils
2268: .getServiceWsdlLocation(refType, classLoader));
2269: }
2270: if (serviceRef.getWsdlFile() == null
2271: && serviceInterface != null) {
2272: serviceRef.setWsdlFile(JaxWsUtils
2273: .getServiceWsdlLocation(serviceInterface,
2274: classLoader));
2275: }
2276:
2277: // service qname
2278: if (serviceRef.getServiceQname() == null && refType != null) {
2279: serviceRef.setServiceQname(JaxWsUtils
2280: .getServiceQName(refType));
2281: }
2282: if (serviceRef.getServiceQname() == null
2283: && serviceInterface != null) {
2284: serviceRef.setServiceQname(JaxWsUtils
2285: .getServiceQName(serviceInterface));
2286: }
2287:
2288: // handlers
2289: if (serviceRef.getHandlerChains() == null
2290: && handlerChain != null) {
2291: try {
2292: URL handlerFileURL = member.getDeclaringClass()
2293: .getResource(handlerChain.file());
2294: HandlerChains handlerChains = ReadDescriptors
2295: .readHandlerChains(handlerFileURL);
2296: serviceRef.setHandlerChains(handlerChains);
2297: } catch (Throwable e) {
2298: throw new OpenEJBException(
2299: "Unable to load handler chain file: "
2300: + handlerChain.file(), e);
2301: }
2302: }
2303: }
2304:
2305: /**
2306: * Refer 16.11.2.1 Overriding Rules of EJB Core Spec for overriding rules
2307: *
2308: * @param consumer
2309: * @param persistenceContext
2310: * @param member
2311: * @throws OpenEJBException
2312: */
2313: private void buildPersistenceContext(JndiConsumer consumer,
2314: PersistenceContextAnn persistenceContext, Member member)
2315: throws OpenEJBException {
2316: String refName = persistenceContext.name();
2317:
2318: if (refName.equals("")) {
2319: refName = (member == null) ? null : member
2320: .getDeclaringClass().getName()
2321: + "/" + member.getName();
2322: }
2323:
2324: if (refName == null && member == null) {
2325: getValidationContext()
2326: .get()
2327: .fail(
2328: consumer.getJndiConsumerName(),
2329: "presistenceContextAnnotation.onClassWithNoName",
2330: persistenceContext.unitName());
2331: return;
2332: }
2333:
2334: PersistenceContextRef persistenceContextRef = consumer
2335: .getPersistenceContextRefMap().get(refName);
2336: if (persistenceContextRef == null) {
2337: persistenceContextRef = new PersistenceContextRef();
2338: persistenceContextRef
2339: .setPersistenceUnitName(persistenceContext
2340: .unitName());
2341: persistenceContextRef
2342: .setPersistenceContextRefName(refName);
2343: if ("EXTENDED".equalsIgnoreCase(persistenceContext
2344: .type())) {
2345: persistenceContextRef
2346: .setPersistenceContextType(PersistenceContextType.EXTENDED);
2347: } else {
2348: persistenceContextRef
2349: .setPersistenceContextType(PersistenceContextType.TRANSACTION);
2350: }
2351: consumer.getPersistenceContextRef().add(
2352: persistenceContextRef);
2353: } else {
2354: if (persistenceContextRef.getPersistenceUnitName() == null
2355: || ("").equals(persistenceContextRef
2356: .getPersistenceUnitName())) {
2357: persistenceContextRef
2358: .setPersistenceUnitName(persistenceContext
2359: .unitName());
2360: }
2361: if (persistenceContextRef.getPersistenceContextType() == null
2362: || ("").equals(persistenceContextRef
2363: .getPersistenceContextType())) {
2364: if ("EXTENDED".equalsIgnoreCase(persistenceContext
2365: .type())) {
2366: persistenceContextRef
2367: .setPersistenceContextType(PersistenceContextType.EXTENDED);
2368: } else {
2369: persistenceContextRef
2370: .setPersistenceContextType(PersistenceContextType.TRANSACTION);
2371: }
2372: }
2373: }
2374:
2375: List<Property> persistenceProperties = persistenceContextRef
2376: .getPersistenceProperty();
2377: if (persistenceProperties == null) {
2378: persistenceProperties = new ArrayList<Property>();
2379: persistenceContextRef
2380: .setPersistenceProperty(persistenceProperties);
2381: }
2382:
2383: for (Map.Entry<String, String> persistenceProperty : persistenceContext
2384: .properties().entrySet()) {
2385: boolean flag = true;
2386: for (Property prpty : persistenceProperties) {
2387: if (prpty.getName().equals(
2388: persistenceProperty.getKey())) {
2389: flag = false;
2390: break;
2391: }
2392: }
2393: if (flag) {
2394: Property property = new Property();
2395: property.setName(persistenceProperty.getKey());
2396: property.setValue(persistenceProperty.getValue());
2397: persistenceProperties.add(property);
2398: }
2399: }
2400:
2401: if (member != null) {
2402: Class type = member.getType();
2403: if (EntityManagerFactory.class.isAssignableFrom(type)) {
2404: getValidationContext()
2405: .get()
2406: .fail(
2407: consumer.getJndiConsumerName(),
2408: "presistenceContextAnnotation.onEntityManagerFactory",
2409: persistenceContextRef.getName());
2410: } else if (!EntityManager.class.isAssignableFrom(type)) {
2411: getValidationContext()
2412: .get()
2413: .fail(
2414: consumer.getJndiConsumerName(),
2415: "presistenceContextAnnotation.onNonEntityManager",
2416: persistenceContextRef.getName());
2417: } else {
2418: // Set the member name where this will be injected
2419: InjectionTarget target = new InjectionTarget();
2420: target.setInjectionTargetClass(member
2421: .getDeclaringClass().getName());
2422: target.setInjectionTargetName(member.getName());
2423: persistenceContextRef.getInjectionTarget().add(
2424: target);
2425: }
2426: }
2427: }
2428:
2429: private void buildEjbRef(JndiConsumer consumer, EJB ejb,
2430: Member member) {
2431:
2432: if (member == null) {
2433: boolean shouldReturn = false;
2434: if (ejb.name().equals("")) {
2435: getValidationContext().get().fail(
2436: consumer.getJndiConsumerName(),
2437: "ejbAnnotation.onClassWithNoName");
2438: shouldReturn = true;
2439: }
2440: if (ejb.beanInterface().equals(Object.class)) {
2441: getValidationContext().get().fail(
2442: consumer.getJndiConsumerName(),
2443: "ejbAnnotation.onClassWithNoBeanInterface");
2444: shouldReturn = true;
2445: }
2446: if (shouldReturn)
2447: return;
2448: }
2449:
2450: EjbRef ejbRef = new EjbRef();
2451:
2452: // This is how we deal with the fact that we don't know
2453: // whether to use an EjbLocalRef or EjbRef (remote).
2454: // We flag it uknown and let the linking code take care of
2455: // figuring out what to do with it.
2456: ejbRef.setRefType(EjbReference.Type.UNKNOWN);
2457:
2458: if (member != null) {
2459: // Set the member name where this will be injected
2460: InjectionTarget target = new InjectionTarget();
2461: target.setInjectionTargetClass(member
2462: .getDeclaringClass().getName());
2463: target.setInjectionTargetName(member.getName());
2464: ejbRef.getInjectionTarget().add(target);
2465: }
2466:
2467: Class<?> interfce = ejb.beanInterface();
2468: if (interfce.equals(Object.class)) {
2469: interfce = (member == null) ? null : member.getType();
2470: }
2471:
2472: if (interfce != null && !interfce.equals(Object.class)) {
2473: if (EJBHome.class.isAssignableFrom(interfce)) {
2474: ejbRef.setHome(interfce.getName());
2475: Method[] methods = interfce.getMethods();
2476: for (Method method : methods) {
2477: if (method.getName().startsWith("create")) {
2478: ejbRef.setRemote(method.getReturnType()
2479: .getName());
2480: break;
2481: }
2482: }
2483: ejbRef.setRefType(EjbReference.Type.REMOTE);
2484: } else if (EJBLocalHome.class
2485: .isAssignableFrom(interfce)) {
2486: ejbRef.setHome(interfce.getName());
2487: Method[] methods = interfce.getMethods();
2488: for (Method method : methods) {
2489: if (method.getName().startsWith("create")) {
2490: ejbRef.setRemote(method.getReturnType()
2491: .getName());
2492: break;
2493: }
2494: }
2495: ejbRef.setRefType(EjbReference.Type.LOCAL);
2496: } else {
2497: ejbRef.setRemote(interfce.getName());
2498: if (interfce.getAnnotation(Local.class) != null) {
2499: ejbRef.setRefType(EjbReference.Type.LOCAL);
2500: } else if (interfce.getAnnotation(Remote.class) != null) {
2501: ejbRef.setRefType(EjbReference.Type.REMOTE);
2502: }
2503: }
2504: }
2505:
2506: // Get the ejb-ref-name
2507: String refName = ejb.name();
2508: if (refName.equals("")) {
2509: refName = (member == null) ? null : member
2510: .getDeclaringClass().getName()
2511: + "/" + member.getName();
2512: }
2513: ejbRef.setEjbRefName(refName);
2514:
2515: // Set the ejb-link, if any
2516: String ejbName = ejb.beanName();
2517: if (ejbName.equals("")) {
2518: ejbName = null;
2519: }
2520: ejbRef.setEjbLink(ejbName);
2521:
2522: // Set the mappedName, if any
2523: String mappedName = ejb.mappedName();
2524: if (mappedName.equals("")) {
2525: mappedName = null;
2526: }
2527: ejbRef.setMappedName(mappedName);
2528:
2529: Map<String, EjbRef> remoteRefs = consumer.getEjbRefMap();
2530: if (remoteRefs.containsKey(ejbRef.getName())) {
2531: EjbRef ref = remoteRefs.get(ejbRef.getName());
2532: if (ref.getRemote() == null)
2533: ref.setRemote(ejbRef.getRemote());
2534: if (ref.getHome() == null)
2535: ref.setHome(ejbRef.getHome());
2536: if (ref.getMappedName() == null)
2537: ref.setMappedName(ejbRef.getMappedName());
2538: ref.getInjectionTarget().addAll(
2539: ejbRef.getInjectionTarget());
2540: return;
2541: }
2542:
2543: Map<String, EjbLocalRef> localRefs = consumer
2544: .getEjbLocalRefMap();
2545: if (localRefs.containsKey(ejbRef.getName())) {
2546: EjbLocalRef ejbLocalRef = new EjbLocalRef(ejbRef);
2547: EjbLocalRef ref = localRefs.get(ejbLocalRef.getName());
2548: if (ref.getLocal() == null)
2549: ref.setLocal(ejbLocalRef.getLocal());
2550: if (ref.getLocalHome() == null)
2551: ref.setLocalHome(ejbLocalRef.getLocalHome());
2552: if (ref.getMappedName() == null)
2553: ref.setMappedName(ejbLocalRef.getMappedName());
2554: ref.getInjectionTarget().addAll(
2555: ejbLocalRef.getInjectionTarget());
2556: return;
2557: }
2558:
2559: switch (ejbRef.getRefType()) {
2560: case UNKNOWN:
2561: case REMOTE:
2562: consumer.getEjbRef().add(ejbRef);
2563: break;
2564: case LOCAL:
2565: consumer.getEjbLocalRef().add(new EjbLocalRef(ejbRef));
2566: break;
2567: }
2568: }
2569:
2570: private List<Class<?>> copy(List<Class<?>> classes) {
2571: return new ArrayList<Class<?>>(classes);
2572: }
2573:
2574: private void addContainerTransaction(
2575: TransactionAttribute attribute, String ejbName,
2576: Method method, AssemblyDescriptor assemblyDescriptor) {
2577: ContainerTransaction ctx = new ContainerTransaction(
2578: cast(attribute.value()), ejbName, method);
2579: assemblyDescriptor.getContainerTransaction().add(ctx);
2580: }
2581:
2582: private String[] asStrings(Class[] types) {
2583: List<String> names = new ArrayList<String>();
2584: for (Class clazz : types) {
2585: names.add(clazz.getName());
2586: }
2587: return names.toArray(new String[names.size()]);
2588: }
2589:
2590: private TransAttribute cast(
2591: TransactionAttributeType transactionAttributeType) {
2592: return TransAttribute.valueOf(transactionAttributeType
2593: .toString());
2594: }
2595:
2596: private <T> T getFirst(List<T> list) {
2597: if (list.size() > 0) {
2598: return list.get(0);
2599: }
2600: return null;
2601: }
2602:
2603: private boolean validateRemoteInterface(Class interfce,
2604: ValidationContext validation, String ejbName) {
2605: return isValidInterface(interfce, validation, ejbName,
2606: "Remote");
2607: }
2608:
2609: private boolean validateLocalInterface(Class interfce,
2610: ValidationContext validation, String ejbName) {
2611: return isValidInterface(interfce, validation, ejbName,
2612: "Local");
2613: }
2614:
2615: private boolean isValidInterface(Class interfce,
2616: ValidationContext validation, String ejbName,
2617: String annotationName) {
2618: if (!interfce.isInterface()) {
2619: validation.fail(ejbName, "ann.notAnInterface",
2620: annotationName, interfce.getName());
2621: return false;
2622: } else if (EJBHome.class.isAssignableFrom(interfce)) {
2623: validation.fail(ejbName, "ann.remoteOrLocal.ejbHome",
2624: annotationName, interfce.getName());
2625: return false;
2626: } else if (EJBObject.class.isAssignableFrom(interfce)) {
2627: validation.fail(ejbName, "ann.remoteOrLocal.ejbObject",
2628: annotationName, interfce.getName());
2629: return false;
2630: } else if (EJBLocalHome.class.isAssignableFrom(interfce)) {
2631: validation.fail(ejbName,
2632: "ann.remoteOrLocal.ejbLocalHome",
2633: annotationName, interfce.getName());
2634: return false;
2635: } else if (EJBLocalObject.class.isAssignableFrom(interfce)) {
2636: validation.fail(ejbName,
2637: "ann.remoteOrLocal.ejbLocalObject",
2638: annotationName, interfce.getName());
2639: return false;
2640: }
2641: return true;
2642: }
2643: }
2644:
2645: public static interface Member {
2646: Class getDeclaringClass();
2647:
2648: String getName();
2649:
2650: Class getType();
2651: }
2652:
2653: public static class MethodMember implements Member {
2654: private final Method setter;
2655:
2656: public MethodMember(Method method) {
2657: this .setter = method;
2658: }
2659:
2660: public Class getType() {
2661: return setter.getParameterTypes()[0];
2662: }
2663:
2664: public Class getDeclaringClass() {
2665: return setter.getDeclaringClass();
2666: }
2667:
2668: public String getName() {
2669: StringBuilder name = new StringBuilder(setter.getName());
2670:
2671: // remove 'set'
2672: name.delete(0, 3);
2673:
2674: // lowercase first char
2675: name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
2676:
2677: return name.toString();
2678: }
2679:
2680: public String toString() {
2681: return setter.toString();
2682: }
2683: }
2684:
2685: public static class FieldMember implements Member {
2686: private final Field field;
2687:
2688: public FieldMember(Field field) {
2689: this .field = field;
2690: }
2691:
2692: public Class getType() {
2693: return field.getType();
2694: }
2695:
2696: public String toString() {
2697: return field.toString();
2698: }
2699:
2700: public Class getDeclaringClass() {
2701: return field.getDeclaringClass();
2702: }
2703:
2704: public String getName() {
2705: return field.getName();
2706: }
2707: }
2708:
2709: }
|