You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/12/04 22:07:51 UTC
svn commit: r1417182 [15/22] - in /openejb/trunk/openejb:
container/openejb-core/ deps/ deps/webbeans-impl/ deps/webbeans-impl/src/
deps/webbeans-impl/src/main/ deps/webbeans-impl/src/main/java/
deps/webbeans-impl/src/main/java/org/ deps/webbeans-impl/...
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,436 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.intercept.webbeans;
+
+import org.apache.webbeans.annotation.AnnotationManager;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.component.ManagedBean;
+import org.apache.webbeans.component.WebBeansType;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.inject.InjectableField;
+import org.apache.webbeans.inject.InjectableMethods;
+import org.apache.webbeans.intercept.OwbInterceptor;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.util.Nonbinding;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.AroundTimeout;
+import javax.interceptor.InvocationContext;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+
+/**
+ * Defines the webbeans specific interceptors.
+ * <p>
+ * WebBeans interceotor classes has at least one {@link javax.interceptor.InterceptorBinding}
+ * annotation. It can be defined on the class or method level at the component.
+ * WebBeans interceptors are called after the EJB related interceptors are
+ * called in the chain. Semantics of the interceptors are specified by the EJB
+ * specificatin.
+ * </p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class WebBeansInterceptor<T> extends AbstractOwbBean<T> implements OwbInterceptor<T>
+{
+ /** InterceptorBindingTypes exist on the interceptor class */
+ private Map<Class<? extends Annotation>, Annotation> interceptorBindingSet = new HashMap<Class<? extends Annotation>, Annotation>();
+
+ /** Interceptor class */
+ private Class<?> clazz;
+
+ /**Delegate Bean*/
+ private AbstractInjectionTargetBean<T> delegateBean;
+ private final WebBeansContext webBeansContext;
+
+ public WebBeansInterceptor(AbstractInjectionTargetBean<T> delegateBean)
+ {
+ super(WebBeansType.INTERCEPTOR,delegateBean.getReturnType(), delegateBean.getWebBeansContext());
+
+ this.delegateBean = delegateBean;
+ clazz = getDelegate().getReturnType();
+
+ webBeansContext = delegateBean.getWebBeansContext();
+ }
+
+ public AbstractOwbBean<T> getDelegate()
+ {
+ return delegateBean;
+ }
+
+ public AnnotatedType<T> getAnnotatedType()
+ {
+ return delegateBean.getAnnotatedType();
+ }
+
+
+ /**
+ * Add new binding type to the interceptor.
+ *
+ * @param binding interceptor binding annotation. class
+ * @param annot binding type annotation
+ */
+ public void addInterceptorBinding(Class<? extends Annotation> binding, Annotation annot)
+ {
+ Method[] methods = webBeansContext.getSecurityService().doPrivilegedGetDeclaredMethods(binding);
+
+ for (Method method : methods)
+ {
+ Class<?> clazz = method.getReturnType();
+ if (clazz.isArray() || clazz.isAnnotation())
+ {
+ if (!AnnotationUtil.hasAnnotation(method.getAnnotations(), Nonbinding.class))
+ {
+ throw new WebBeansConfigurationException("Interceptor definition class : " + getClazz().getName() + " @InterceptorBinding : "
+ + binding.getName()
+ + " must have @NonBinding valued members for its array-valued and annotation valued members");
+ }
+ }
+ }
+
+ interceptorBindingSet.put(binding, annot);
+ }
+
+ /**
+ * Checks whether all of this interceptors binding types are present on the bean, with
+ * {@link Nonbinding} member values.
+ *
+ * @param bindingTypes binding types of bean
+ * @param annots binding types annots of bean
+ * @return true if all binding types of this interceptor exist ow false
+ */
+ public boolean hasBinding(List<Class<? extends Annotation>> bindingTypes, List<Annotation> annots)
+ {
+ if (bindingTypes == null || annots == null)
+ {
+ return false;
+ }
+ if (bindingTypes.size() != annots.size())
+ {
+ return false;
+ }
+ if (bindingTypes.size() == 0)
+ {
+ return false;
+ }
+
+ /* This interceptor is enabled if all of its interceptor bindings are present on the bean */
+ for (Annotation ann : getInterceptorBindings())
+ {
+ Class<? extends Annotation> bindingType = ann.annotationType();
+ int index = bindingTypes.indexOf(bindingType);
+ if (index < 0)
+ {
+ return false; /* at least one of this interceptors types is not in the beans bindingTypes */
+ }
+
+ if (!AnnotationUtil.isQualifierEqual(ann, annots.get(index)))
+
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Gets the interceptor class.
+ *
+ * @return interceptor class
+ */
+ public Class<?> getClazz()
+ {
+ return clazz;
+ }
+
+ public Set<Interceptor<?>> getMetaInceptors()
+ {
+ Set<Interceptor<?>> set = new HashSet<Interceptor<?>>();
+
+ Set<Annotation> keys = getInterceptorBindings();
+
+ AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
+
+ for (Annotation key : keys)
+ {
+ Class<? extends Annotation> clazzAnnot = key.annotationType();
+ Set<Annotation> declared = null;
+ Annotation[] anns = null;
+
+ if (webBeansContext.getBeanManagerImpl().hasInterceptorBindingType(clazzAnnot))
+ {
+ declared = webBeansContext.getBeanManagerImpl().getInterceptorBindingTypeMetaAnnotations(clazzAnnot);
+ anns = new Annotation[declared.size()];
+ anns = declared.toArray(anns);
+ }
+
+ else if (annotationManager.hasInterceptorBindingMetaAnnotation(clazzAnnot.getDeclaredAnnotations()))
+ {
+ anns = annotationManager.getInterceptorBindingMetaAnnotations(clazzAnnot.getDeclaredAnnotations());
+ }
+
+ /*
+ * For example: @InterceptorBinding @Transactional @Action
+ * public @interface ActionTransactional @ActionTransactional
+ * @Production { }
+ */
+
+ if (anns != null && anns.length > 0)
+ {
+ // For example : @Transactional @Action Interceptor
+ Set<Interceptor<?>> metas = webBeansContext.getWebBeansInterceptorConfig().findDeployedWebBeansInterceptor(anns, webBeansContext);
+ set.addAll(metas);
+
+ // For each @Transactional and @Action Interceptor
+ for (Annotation ann : anns)
+ {
+ Annotation[] simple = new Annotation[1];
+ simple[0] = ann;
+ metas = webBeansContext.getWebBeansInterceptorConfig().findDeployedWebBeansInterceptor(simple, webBeansContext);
+ set.addAll(metas);
+ }
+
+ }
+
+ }
+
+ return set;
+ }
+
+ public Set<Annotation> getInterceptorBindings()
+ {
+ Set<Annotation> set = new HashSet<Annotation>();
+ Set<Class<? extends Annotation>> keySet = interceptorBindingSet.keySet();
+ Iterator<Class<? extends Annotation>> itSet = keySet.iterator();
+
+ while (itSet.hasNext())
+ {
+ set.add(interceptorBindingSet.get(itSet.next()));
+ }
+
+ return set;
+ }
+
+ private Method getMethod(InterceptionType type)
+ {
+ Method method = null;
+
+ if(type.equals(InterceptionType.AROUND_INVOKE))
+ {
+ method = WebBeansUtil.checkAroundInvokeAnnotationCriterias(getClazz(),AroundInvoke.class);
+ }
+
+ else if(type.equals(InterceptionType.AROUND_TIMEOUT))
+ {
+ method = WebBeansUtil.checkAroundInvokeAnnotationCriterias(getClazz(),AroundTimeout.class);
+ }
+
+ else
+ {
+ Class<? extends Annotation> interceptorTypeAnnotationClazz =
+ webBeansContext.getInterceptorUtil().getInterceptorAnnotationClazz(type);
+ method = getWebBeansContext().getWebBeansUtil().checkCommonAnnotationCriterias(getClazz(),
+ interceptorTypeAnnotationClazz,
+ true);
+ }
+
+ return method;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ protected T createInstance(CreationalContext<T> creationalContext)
+ {
+ Context context = webBeansContext.getBeanManagerImpl().getContext(getScope());
+ Object actualInstance = context.get((Bean<Object>) delegateBean, (CreationalContext<Object>)creationalContext);
+ T proxy = (T) webBeansContext.getProxyFactory().createDependentScopedBeanProxy(delegateBean, actualInstance, creationalContext);
+
+ return proxy;
+ }
+
+ public void setInjections(Object proxy, CreationalContext<?> creationalContext)
+ {
+ // Set injected fields
+ ManagedBean<T> delegate = (ManagedBean<T>) delegateBean;
+
+ Set<Field> injectedFields = delegate.getInjectedFromSuperFields();
+ for (Field injectedField : injectedFields)
+ {
+ injectField(injectedField, proxy, creationalContext);
+ }
+
+ Set<Method> injectedMethods = delegate.getInjectedFromSuperMethods();
+ for (Method injectedMethod : injectedMethods)
+ {
+ injectMethod(injectedMethod, proxy, creationalContext);
+ }
+
+ injectedFields = delegate.getInjectedFields();
+ for (Field injectedField : injectedFields)
+ {
+ injectField(injectedField, proxy, creationalContext);
+ }
+
+
+ injectedMethods = delegate.getInjectedMethods();
+ for (Method injectedMethod : injectedMethods)
+ {
+ injectMethod(injectedMethod, proxy, creationalContext);
+ }
+ }
+
+ private void injectField(Field field, Object instance, CreationalContext<?> creationalContext)
+ {
+ InjectableField f = new InjectableField(field, instance, delegateBean, creationalContext);
+ f.doInjection();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void injectMethod(Method method, Object instance, CreationalContext<?> creationalContext)
+ {
+ InjectableMethods m = new InjectableMethods(method, instance, delegateBean, creationalContext);
+ m.doInjection();
+ }
+
+ @Override
+ public Set<Annotation> getQualifiers()
+ {
+ return delegateBean.getQualifiers();
+ }
+
+ @Override
+ public String getName()
+ {
+ return delegateBean.getName();
+ }
+
+ @Override
+ public Class<? extends Annotation> getScope()
+ {
+ return delegateBean.getScope();
+ }
+
+ public Set<Type> getTypes()
+ {
+ return delegateBean.getTypes();
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return delegateBean.getInjectionPoints();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return "WebBeans Interceptor with class : " + "[" + clazz.getName() + "]";
+ }
+
+ @Override
+ public boolean isNullable()
+ {
+ return delegateBean.isNullable();
+ }
+
+ @Override
+ public boolean isSerializable()
+ {
+ return delegateBean.isSerializable();
+ }
+
+ @Override
+ public Class<?> getBeanClass()
+ {
+ return delegateBean.getBeanClass();
+ }
+
+ @Override
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return delegateBean.getStereotypes();
+ }
+
+ public Object intercept(InterceptionType type, T instance,InvocationContext ctx)
+ {
+ Method method = getMethod(type);
+ try
+ {
+ method.invoke(instance, ctx);
+ }
+ catch (Exception e)
+ {
+ getLogger().log(Level.SEVERE, e.getMessage(), e);
+ throw new WebBeansException(e);
+ }
+
+ return null;
+ }
+
+ public boolean intercepts(InterceptionType type)
+ {
+ Method method = getMethod(type);
+
+ return method != null ? true : false;
+ }
+
+ @Override
+ public boolean isAlternative()
+ {
+ return delegateBean.isAlternative();
+ }
+
+ @Override
+ public boolean isPassivationCapable()
+ {
+ return delegateBean.isPassivationCapable();
+ }
+
+ @Override
+ public void validatePassivationDependencies()
+ {
+ delegateBean.validatePassivationDependencies();
+ }
+
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/jms/JMSModel.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/jms/JMSModel.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/jms/JMSModel.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/jms/JMSModel.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.jms;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+public class JMSModel
+{
+ public enum JMSType
+ {
+ QUEUE,
+ TOPIC
+ }
+
+ private final JMSType jmsType;
+ private String jndiName;
+ private final String mappedName;
+ private boolean isJndiNameDefined;
+ private final Set<Annotation> bindings = new HashSet<Annotation>();
+
+
+ public JMSModel(JMSType jmsType, String jndiName, String mappedName)
+ {
+ this.jmsType = jmsType;
+
+ if(jndiName != null)
+ {
+ this.jndiName = jndiName;
+ isJndiNameDefined = true;
+ }
+
+ this.mappedName = mappedName;
+ }
+
+ public void addBinding(Annotation annotation)
+ {
+ bindings.add(annotation);
+ }
+
+ public Annotation[] getBindings()
+ {
+ return bindings.toArray(new Annotation[bindings.size()]);
+ }
+
+ /**
+ * @return the jmsType
+ */
+ public JMSType getJmsType()
+ {
+ return jmsType;
+ }
+
+
+ /**
+ * @return the jndiName
+ */
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+
+ /**
+ * @return the mappedName
+ */
+ public String getMappedName()
+ {
+ return mappedName;
+ }
+
+
+ /**
+ * @return the isJndiNameDefined
+ */
+ public boolean isJndiNameDefined()
+ {
+ return isJndiNameDefined;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((bindings == null) ? 0 : bindings.hashCode());
+ result = prime * result + ((jmsType == null) ? 0 : jmsType.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ JMSModel other = (JMSModel) obj;
+ if (bindings == null)
+ {
+ if (other.bindings != null)
+ {
+ return false;
+ }
+ }
+ else if (!bindings.equals(other.bindings))
+ {
+ return false;
+ }
+ if (jmsType == null)
+ {
+ if (other.jmsType != null)
+ {
+ return false;
+ }
+ }
+ else if (!jmsType.equals(other.jmsType))
+ {
+ return false;
+ }
+ return true;
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.lifecycle;
+
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.webbeans.config.BeansDeployer;
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.config.WebBeansFinder;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
+import org.apache.webbeans.spi.ContainerLifecycle;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.spi.JNDIService;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.webbeans.util.WebBeansConstants;
+import org.apache.webbeans.util.WebBeansUtil;
+import org.apache.webbeans.xml.WebBeansXMLConfigurator;
+
+public abstract class AbstractLifeCycle implements ContainerLifecycle
+{
+ //Logger instance
+ protected Logger logger;
+
+ /**Discover bean classes*/
+ protected ScannerService scannerService;
+
+ protected final ContextsService contextsService;
+
+ /**Deploy discovered beans*/
+ private final BeansDeployer deployer;
+
+ /**XML discovery. */
+ //XML discovery is removed from the specification. It is here for next revisions of spec.
+ private final WebBeansXMLConfigurator xmlDeployer;
+
+ /**Using for lookup operations*/
+ private final JNDIService jndiService;
+
+ /**Root container.*/
+ private final BeanManagerImpl beanManager;
+ protected final WebBeansContext webBeansContext;
+
+ protected AbstractLifeCycle()
+ {
+ this(null);
+ }
+
+ protected AbstractLifeCycle(Properties properties)
+ {
+ this(properties, WebBeansContext.getInstance());
+ }
+
+ protected AbstractLifeCycle(Properties properties, WebBeansContext webBeansContext)
+ {
+ beforeInitApplication(properties);
+
+ this.webBeansContext = webBeansContext;
+ beanManager = this.webBeansContext.getBeanManagerImpl();
+ xmlDeployer = new WebBeansXMLConfigurator();
+ deployer = new BeansDeployer(xmlDeployer, this.webBeansContext);
+ jndiService = this.webBeansContext.getService(JNDIService.class);
+ beanManager.setXMLConfigurator(xmlDeployer);
+ scannerService = this.webBeansContext.getScannerService();
+ contextsService = this.webBeansContext.getService(ContextsService.class);
+ initApplication(properties);
+ }
+
+ public WebBeansContext getWebBeansContext()
+ {
+ return webBeansContext;
+ }
+
+ public BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+
+ public void startApplication(Object startupObject)
+ {
+ // Initalize Application Context
+ logger.info(OWBLogConst.INFO_0005);
+
+ long begin = System.currentTimeMillis();
+
+ //Before Start
+ beforeStartApplication(startupObject);
+
+ //Load all plugins
+ webBeansContext.getPluginLoader().startUp();
+
+ //Initialize contexts
+ contextsService.init(startupObject);
+
+ //Scanning process
+ logger.fine("Scanning classpaths for beans artifacts.");
+
+ //Scan
+ scannerService.scan();
+
+ //Deploy beans
+ logger.fine("Deploying scanned beans.");
+
+ //Deploy
+ deployer.deploy(scannerService);
+
+ //Start actual starting on sub-classes
+ afterStartApplication(startupObject);
+
+ if (logger.isLoggable(Level.INFO))
+ {
+ logger.log(Level.INFO, OWBLogConst.INFO_0001, Long.toString(System.currentTimeMillis() - begin));
+ }
+ }
+
+ public void stopApplication(Object endObject)
+ {
+ logger.fine("OpenWebBeans Container is stopping.");
+
+ try
+ {
+ //Sub-classes operations
+ beforeStopApplication(endObject);
+
+ //Set up the thread local for Application scoped as listeners will be App scoped.
+ contextsService.startContext(ApplicationScoped.class, endObject);
+
+ //Fire shut down
+ beanManager.fireEvent(new BeforeShutdownImpl());
+
+ //Destroys context
+ contextsService.destroy(endObject);
+
+ //Unbind BeanManager
+ jndiService.unbind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME);
+
+ //Free all plugin resources
+ webBeansContext.getPluginLoader().shutDown();
+
+ //Clear extensions
+ webBeansContext.getExtensionLoader().clear();
+
+ //Delete Resolutions Cache
+ InjectionResolver injectionResolver = webBeansContext.getBeanManagerImpl().getInjectionResolver();
+
+ injectionResolver.clearCaches();
+
+ //Delte proxies
+ webBeansContext.getProxyFactory().clear();
+
+ //Delete AnnotateTypeCache
+ webBeansContext.getAnnotatedElementFactory().clear();
+
+ //After Stop
+ afterStopApplication(endObject);
+
+ // Clear BeanManager
+ beanManager.clear();
+
+ // Clear singleton list
+ WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
+
+ }
+ catch (Exception e)
+ {
+ if (logger.isLoggable(Level.SEVERE))
+ {
+ logger.log(Level.SEVERE, OWBLogConst.ERROR_0021, e);
+ }
+ }
+
+ }
+
+ /**
+ * @return the logger
+ */
+ protected Logger getLogger()
+ {
+ return logger;
+ }
+
+ /**
+ * @return the contextsService
+ */
+ public ContextsService getContextService()
+ {
+ return contextsService;
+ }
+
+ public void initApplication(Properties properties)
+ {
+ afterInitApplication(properties);
+ }
+
+ protected void beforeInitApplication(Properties properties)
+ {
+ //Do nothing as default
+ }
+
+ protected void afterInitApplication(Properties properties)
+ {
+ //Do nothing as default
+ }
+
+ protected void afterStartApplication(Object startupObject)
+ {
+ //Do nothing as default
+ }
+
+ protected void afterStopApplication(Object stopObject)
+ {
+ //Do nothing as default
+ }
+
+ protected void beforeStartApplication(Object startupObject)
+ {
+ //Do nothing as default
+ }
+
+ protected void beforeStopApplication(Object stopObject)
+ {
+ //Do nothing as default
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.lifecycle;
+
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.apache.webbeans.config.WebBeansFinder;
+import org.apache.webbeans.el.ELContextStore;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * Default LifeCycle for a standalone application without a ServletContainer.
+ */
+public class StandaloneLifeCycle extends AbstractLifeCycle
+{
+ public StandaloneLifeCycle(Properties properties, Logger logger)
+ {
+ super(properties);
+ this.logger = logger;
+ }
+
+ public StandaloneLifeCycle()
+ {
+ this(null, WebBeansLoggerFacade.getLogger(StandaloneLifeCycle.class));
+ }
+
+ @Override
+ public void beforeStartApplication(Object object)
+ {
+ webBeansContext.getContextFactory().initRequestContext(null);
+ webBeansContext.getContextFactory().initSessionContext(null);
+ webBeansContext.getContextFactory().initConversationContext(null);
+ webBeansContext.getContextFactory().initApplicationContext(null);
+ webBeansContext.getContextFactory().initSingletonContext(null);
+ }
+
+ @Override
+ public void beforeStopApplication(Object endObject)
+ {
+ webBeansContext.getContextFactory().destroyRequestContext(null);
+ webBeansContext.getContextFactory().destroySessionContext(null);
+ webBeansContext.getContextFactory().destroyConversationContext();
+ webBeansContext.getContextFactory().destroyApplicationContext(null);
+ webBeansContext.getContextFactory().destroySingletonContext(null);
+
+ // clean up the EL caches after each request
+ ELContextStore elStore = ELContextStore.getInstance(false);
+ if (elStore != null)
+ {
+ elStore.destroyELContextStore();
+ }
+ }
+
+ @Override
+ protected void afterStopApplication(Object stopObject)
+ {
+ WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestLifeCycle.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestLifeCycle.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestLifeCycle.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestLifeCycle.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.lifecycle.test;
+
+import java.util.Properties;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.lifecycle.StandaloneLifeCycle;
+import org.apache.webbeans.spi.ScannerService;
+
+/**
+ * Ease the writing of the tests. Simulates container
+ * startup and stop functionality and allow injection of
+ * classes which should be scanned by using the
+ * {@link OpenWebBeansTestMetaDataDiscoveryService}.
+ * @version $Rev$ $Date$
+ *
+ */
+public class OpenWebBeansTestLifeCycle extends StandaloneLifeCycle
+{
+ public OpenWebBeansTestLifeCycle()
+ {
+ super();
+ }
+
+ @Override
+ public void beforeInitApplication(Properties properties)
+ {
+ WebBeansContext.getInstance().registerService(ScannerService.class, new OpenWebBeansTestMetaDataDiscoveryService());
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/test/OpenWebBeansTestMetaDataDiscoveryService.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.lifecycle.test;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javassist.ClassPool;
+
+import org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery;
+import org.apache.webbeans.exception.WebBeansDeploymentException;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.util.Asserts;
+
+/**
+ * Used by each test.
+ * @version $Rev$ $Date$
+ *
+ */
+public class OpenWebBeansTestMetaDataDiscoveryService extends AbstractMetaDataDiscovery
+{
+ private static final Logger logger = WebBeansLoggerFacade.getLogger(OpenWebBeansTestMetaDataDiscoveryService.class);
+
+ public OpenWebBeansTestMetaDataDiscoveryService()
+ {
+
+ }
+
+ @Override
+ protected void configure()
+ {
+ //Nothing we scan
+ }
+
+ /**
+ * Those classes will be scanned by container.
+ * @param classes deployed classes
+ */
+ public void deployClasses(Collection<Class<?>> classes)
+ {
+ if(classes != null)
+ {
+ for(Class<?> clazz : classes)
+ {
+ addBeanClass(clazz);
+ }
+ }
+ }
+
+ /**
+ * Those xmls will be scanned by container.
+ * @param xmls beans xmls
+ */
+ public void deployXMLs(Collection<String> xmls)
+ {
+ if(xmls != null)
+ {
+ for(String url : xmls)
+ {
+ try
+ {
+ addBeanXml(new URL(url));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new WebBeansDeploymentException("could not convert to URL: " + url, e);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Adds new class for scanning.
+ * @param clazz new scanned class
+ */
+ private void addBeanClass(Class<?> clazz)
+ {
+ Asserts.assertNotNull(clazz);
+
+ URL url = ClassPool.getDefault().find(clazz.getName());
+
+ try
+ {
+ getAnnotationDB().scanClass(url.openStream());
+ }
+ catch (IOException e)
+ {
+ logger.log(Level.WARNING, "Problems while scanning class " + clazz.getName());
+ }
+ }
+
+ /**
+ * Adds new beans.xml url for scanning.
+ * @param url new xml url
+ */
+ private void addBeanXml(URL url)
+ {
+ Asserts.assertNotNull(url);
+
+ addWebBeansXmlLocation(url);
+ }
+
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/JULLoggerFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/JULLoggerFactory.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/JULLoggerFactory.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/JULLoggerFactory.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.logger;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+public class JULLoggerFactory implements WebBeansLoggerFactory
+{
+ public Logger getLogger(Class<?> clazz, Locale desiredLocale)
+ {
+ return Logger.getLogger(clazz.getName(), ResourceBundle.getBundle("openwebbeans/Messages", desiredLocale).toString());
+ }
+
+ public Logger getLogger(Class<?> clazz)
+ {
+ return Logger.getLogger(clazz.getName(),"openwebbeans/Messages");
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFacade.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.logger;
+
+/*
+ * These are for use of JDK util logging.
+ */
+
+import org.apache.webbeans.config.OWBLogConst;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Wrapper class around the JUL logger class to include some checks before the
+ * logs are actually written.
+ * <p>
+ * Actually, it is a thin layer on the JUL {@link Logger} implementation.
+ * </p>
+ *
+ * @version $Rev$ $Date$
+ */
+public final class WebBeansLoggerFacade
+{
+ public static final String OPENWEBBEANS_LOGGING_FACTORY_PROP = "openwebbeans.logging.factory";
+
+ private static final WebBeansLoggerFactory FACTORY;
+
+ static final ResourceBundle WB_BUNDLE = ResourceBundle.getBundle("openwebbeans/Messages");
+
+ static {
+ final String factoryClassname = System.getProperty(OPENWEBBEANS_LOGGING_FACTORY_PROP);
+ WebBeansLoggerFactory factory = null;
+ Exception error = null;
+ if (factoryClassname != null)
+ {
+ try
+ {
+ // don't use the org.apache.webbeans.util.WebBeansUtil.getCurrentClassLoader()
+ // to avoid weird dependency and potential failing
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if(classloader == null)
+ {
+ classloader = WebBeansLoggerFacade.class.getClassLoader();
+ }
+ Class<?> factoryClazz = classloader.loadClass(factoryClassname);
+ factory = (WebBeansLoggerFactory) factoryClazz.newInstance();
+ }
+ catch (Exception e)
+ {
+ error = e;
+ }
+ }
+ if (factory != null)
+ {
+ FACTORY = factory;
+ }
+ else
+ {
+ FACTORY = new JULLoggerFactory();
+ }
+
+ final Logger logger = FACTORY.getLogger(WebBeansLoggerFacade.class);
+ if (error != null && logger.isLoggable(Level.SEVERE))
+ {
+ logger.log(Level.SEVERE, OWBLogConst.ERROR_0028, error);
+ }
+ }
+
+ /**
+ * Gets the new web beans logger instance.
+ *
+ * @param clazz own the return logger
+ * @return new logger
+ */
+ public static Logger getLogger(Class<?> clazz)
+ {
+ return FACTORY.getLogger(clazz);
+ }
+
+ /**
+ * Gets the new web beans logger instance.
+ *
+ * @param clazz own the return logger
+ * @param desiredLocale Locale used to select the Message resource bundle.
+ * @return new logger
+ */
+ public static Logger getLogger(Class<?> clazz, Locale desiredLocale)
+ {
+ return FACTORY.getLogger(clazz, desiredLocale);
+ }
+
+ public static String constructMessage(String messageKey, Object... args)
+ {
+ MessageFormat msgFrmt;
+ String formattedString;
+
+ msgFrmt = new MessageFormat(getTokenString(messageKey), Locale.getDefault());
+ formattedString = msgFrmt.format(args);
+
+ return formattedString;
+ }
+
+ public static String getTokenString(String messageKey)
+ {
+ String strVal;
+
+ if (WB_BUNDLE == null)
+ {
+ throw new NullPointerException("ResourceBundle can not be null");
+ }
+ try
+ {
+ strVal = WB_BUNDLE.getString(messageKey);
+ }
+ catch (MissingResourceException mre)
+ {
+ strVal = null;
+ }
+ if (strVal == null)
+ {
+ return messageKey;
+ }
+
+ return strVal;
+ }
+
+ // helper method
+ public static Object[] args(final Object... values)
+ {
+ return values;
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFactory.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFactory.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLoggerFactory.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.logger;
+
+import java.util.Locale;
+import java.util.logging.Logger;
+
+public interface WebBeansLoggerFactory
+{
+ Logger getLogger(Class<?> clazz, Locale desiredLocale);
+ Logger getLogger(Class<?> clazz);
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansEjbLCAPlugin.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansEjbLCAPlugin.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansEjbLCAPlugin.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansEjbLCAPlugin.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.plugins;
+
+import java.lang.annotation.Annotation;
+
+import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
+/**
+ * @version $Rev$ $Date$
+ */
+public interface OpenWebBeansEjbLCAPlugin extends OpenWebBeansPlugin
+{
+ public Class<? extends Annotation> getPrePassivateClass();
+
+ public Class<? extends Annotation> getPostActivateClass();
+
+ public Class<? extends Annotation> getAroundTimeoutClass();
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansJmsPlugin.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansJmsPlugin.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansJmsPlugin.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansJmsPlugin.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.plugins;
+
+import javax.enterprise.inject.spi.Bean;
+
+import org.apache.webbeans.jms.JMSModel;
+import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
+
+public interface OpenWebBeansJmsPlugin extends OpenWebBeansPlugin
+{
+ public Bean<?> getJmsBean(JMSModel jmsModel);
+
+ public Object getJmsBeanProxy(Bean<?> bean, Class<?> iface);
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.plugins;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
+import org.apache.webbeans.spi.plugins.OpenWebBeansJavaEEPlugin;
+import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
+import org.apache.webbeans.spi.plugins.OpenWebBeansWebPlugin;
+
+/**
+ * <p>OpenWebBeans plugins are used to extend 'core' functionality of the injection
+ * mechanism with functionality of other frameworks.</p>
+ *
+ * <p>Core functionality are all parts which are available in a standard
+ * JDK-1.5 SE runtime. Extended functionality are things like JPA, JSF, EJB etc.</p>
+ *
+ * <p>The plugin mechanism is based on the ServiceProvider functionality
+ * {@link http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider}.
+ * A jar containing an OWB plugin has to expose itself in the file
+ * <code>META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin</code></p>
+ */
+public class PluginLoader
+{
+ /**Logger instance*/
+ private static final Logger logger = WebBeansLoggerFacade.getLogger(PluginLoader.class);
+
+ /** unmodifiable list with all found OWB plugins */
+ private List<OpenWebBeansPlugin> plugins = null;
+
+ private AtomicBoolean started = new AtomicBoolean(false);
+
+ public PluginLoader()
+ {
+ }
+
+ /**
+ * load and startup all registered plugins.
+ * This must be called once the WebApplication is started.
+ * @throws WebBeansConfigurationException
+ */
+ public void startUp() throws WebBeansConfigurationException
+ {
+ if(started.compareAndSet(false, true))
+ {
+ logger.fine("PluginLoader startUp called.");
+ ArrayList<OpenWebBeansPlugin> ps = new ArrayList<OpenWebBeansPlugin>();
+
+ List<OpenWebBeansPlugin> pluginList = WebBeansContext.getInstance().getLoaderService().load(OpenWebBeansPlugin.class);
+ for (OpenWebBeansPlugin plugin : pluginList)
+ {
+ if (logger.isLoggable(Level.INFO))
+ {
+ logger.log(Level.INFO, OWBLogConst.INFO_0004, plugin.getClass().getSimpleName());
+ }
+ try
+ {
+ plugin.startUp();
+ }
+ catch (Exception e)
+ {
+ throwsException(e);
+ }
+ ps.add(plugin);
+ }
+
+ // just to make sure the plugins aren't modified afterwards
+ plugins = Collections.unmodifiableList(ps);
+ }
+ else
+ {
+ logger.fine("PluginLoader is already started.");
+ }
+ }
+
+ public static void throwsException(Exception e) throws WebBeansConfigurationException
+ {
+ if(e instanceof WebBeansConfigurationException)
+ {
+ throw (WebBeansConfigurationException)e;
+ }
+ else
+ {
+ throw new WebBeansConfigurationException(e);
+ }
+ }
+
+ /**
+ * Tell all the plugins to free up all locked resources.
+ * This must be called before the WebApplication gets undeployed or stopped.
+ * @throws WebBeansConfigurationException
+ */
+ public void shutDown() throws WebBeansConfigurationException
+ {
+ if(started.compareAndSet(true, false))
+ {
+ logger.fine("PluginLoader shutDown called.");
+
+ if (plugins == null)
+ {
+ logger.warning(OWBLogConst.WARN_0001);
+ return;
+ }
+
+ ArrayList<String> failedShutdown = new ArrayList<String>();
+
+ for (OpenWebBeansPlugin plugin : plugins)
+ {
+ try
+ {
+ plugin.shutDown();
+ }
+ catch (Exception e)
+ {
+ // we catch ALL exceptions, since we like to continue shutting down all other plugins!
+ String pluginName = plugin.getClass().getSimpleName();
+ logger.log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0009, pluginName), e);
+ failedShutdown.add(pluginName);
+ }
+ }
+
+ if (!failedShutdown.isEmpty())
+ {
+ throw new WebBeansConfigurationException(WebBeansLoggerFacade.getTokenString(OWBLogConst.EXCEPT_0006) + failedShutdown.toString());
+ }
+ }
+ else
+ {
+ logger.fine("PluginLoader is already shut down.");
+ }
+ }
+
+ /**
+ * @return an unmodifiable list of all registered {code OpenWebBeansPlugin}s
+ */
+ public List<OpenWebBeansPlugin> getPlugins()
+ {
+ return plugins;
+ }
+
+ /**
+ * Gets ejb plugin
+ *
+ * @return ejb plugin
+ */
+ public OpenWebBeansEjbPlugin getEjbPlugin()
+ {
+ if(!pluginsExist())
+ {
+ return null;
+ }
+
+ for(OpenWebBeansPlugin plugin : plugins)
+ {
+ if(plugin instanceof OpenWebBeansEjbPlugin)
+ {
+ return (OpenWebBeansEjbPlugin)plugin;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets ejb lifecycle annotations plugin
+ *
+ * @return ejb LCA plugin
+ */
+ public OpenWebBeansEjbLCAPlugin getEjbLCAPlugin()
+ {
+ if(!pluginsExist())
+ {
+ return null;
+ }
+
+ for(OpenWebBeansPlugin plugin : plugins)
+ {
+ if(plugin instanceof OpenWebBeansEjbLCAPlugin)
+ {
+ return (OpenWebBeansEjbLCAPlugin)plugin;
+ }
+ }
+
+ return null;
+ }
+ /**
+ * Gets the JMS plugin
+ *
+ * @return jms plugin
+ */
+ public OpenWebBeansJmsPlugin getJmsPlugin()
+ {
+ if(!pluginsExist())
+ {
+ return null;
+ }
+
+ for(OpenWebBeansPlugin plugin : plugins)
+ {
+ if(plugin instanceof OpenWebBeansJmsPlugin)
+ {
+ return (OpenWebBeansJmsPlugin)plugin;
+ }
+ }
+
+ return null;
+ }
+
+
+ public OpenWebBeansJavaEEPlugin getJavaEEPlugin()
+ {
+ if(!pluginsExist())
+ {
+ return null;
+ }
+
+ for(OpenWebBeansPlugin plugin : plugins)
+ {
+ if(plugin instanceof OpenWebBeansJavaEEPlugin)
+ {
+ return (OpenWebBeansJavaEEPlugin)plugin;
+ }
+ }
+
+ return null;
+ }
+
+ public OpenWebBeansWebPlugin getWebPlugin()
+ {
+ if(!pluginsExist())
+ {
+ return null;
+ }
+
+ for(OpenWebBeansPlugin plugin : plugins)
+ {
+ if(plugin instanceof OpenWebBeansWebPlugin)
+ {
+ return (OpenWebBeansWebPlugin)plugin;
+ }
+ }
+
+ return null;
+ }
+
+ private boolean pluginsExist()
+ {
+ if(plugins == null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.portable;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.Annotated;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.ClassUtil;
+
+/**
+ * Abstract implementation of the {@link Annotated} contract.
+ *
+ * @version $Rev: 1307021 $ $Date: 2012-03-29 19:59:55 +0200 (jeu., 29 mars 2012) $
+ */
+abstract class AbstractAnnotated implements Annotated
+{
+ /**Base type of an annotated element*/
+ private final Type baseType;
+
+ /**Type closures*/
+ private Set<Type> typeClosures = null;
+
+ /**Set of annotations*/
+ private Set<Annotation> annotations = new HashSet<Annotation>();
+
+ private final WebBeansContext webBeansContext;
+
+ /**
+ * Createa a new annotated element.
+ *
+ * @param webBeansContext our WebBeansContext
+ * @param baseType annotated element type
+ */
+ protected AbstractAnnotated(WebBeansContext webBeansContext, Type baseType)
+ {
+ if (webBeansContext == null)
+ {
+ throw new NullPointerException("no WebBeansContext");
+ }
+ if (baseType == null)
+ {
+ throw new NullPointerException("no base type");
+ }
+ this.baseType = baseType;
+ this.webBeansContext = webBeansContext;
+ }
+
+ /**
+ * Adds new annotation to set.
+ *
+ * @param annotation new annotation
+ */
+ protected void addAnnotation(Annotation annotation)
+ {
+ annotations.add(annotation);
+ }
+
+ protected WebBeansContext getWebBeansContext()
+ {
+ return webBeansContext;
+ }
+
+ /**
+ * Adds new annotation to set.
+ *
+ * @param annotations new annotations
+ */
+ protected void setAnnotations(Annotation[] annotations)
+ {
+ this.annotations.clear();
+ Collections.addAll(this.annotations, annotations);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType)
+ {
+ for(Annotation ann : annotations)
+ {
+ if(ann.annotationType().equals(annotationType))
+ {
+ return (T)ann;
+ }
+ }
+
+ return null;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Annotation> getAnnotations()
+ {
+ return annotations;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Type getBaseType()
+ {
+ return baseType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Type> getTypeClosure()
+ {
+ if (typeClosures == null)
+ {
+ initTypeClosures();
+ }
+ return typeClosures;
+ }
+
+ private synchronized void initTypeClosures()
+ {
+ if (typeClosures == null)
+ {
+ typeClosures = new HashSet<Type>();
+ typeClosures.add(Object.class);
+ ClassUtil.setTypeHierarchy(typeClosures, baseType);
+ Set<String> ignoredInterfaces = webBeansContext.getOpenWebBeansConfiguration().getIgnoredInterfaces();
+ for (Iterator<Type> i = typeClosures.iterator(); i.hasNext(); )
+ {
+ Type t = i.next();
+ if (t instanceof Class && ignoredInterfaces.contains(((Class<?>)t).getName()))
+ {
+ i.remove();
+ }
+ }
+
+ Annotation[] anns = annotations.toArray(new Annotation[annotations.size()]);
+ if(AnnotationUtil.hasAnnotation(anns, Typed.class))
+ {
+ Typed beanTypes = AnnotationUtil.getAnnotation(anns, Typed.class);
+ Class<?>[] types = beanTypes.value();
+
+ //New api types
+ Set<Type> newTypes = new HashSet<Type>();
+ for(Class<?> type : types)
+ {
+ Type foundType = null;
+
+ for(Type apiType : typeClosures)
+ {
+ if(ClassUtil.getClazz(apiType) == type)
+ {
+ foundType = apiType;
+ break;
+ }
+ }
+
+ if(foundType == null)
+ {
+ throw new WebBeansConfigurationException("@Type values must be in bean api types of class: " + baseType);
+ }
+
+ newTypes.add(foundType);
+ }
+
+ typeClosures.clear();
+ typeClosures.addAll(newTypes);
+
+ typeClosures.add(Object.class);
+ }
+
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
+ {
+ for(Annotation ann : annotations)
+ {
+ if(ann.annotationType().equals(annotationType))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("Base Type : " + baseType.toString() + ",");
+ builder.append("Type Closures : " + typeClosures + ",");
+ builder.append("Annotations : " + annotations.toString());
+
+ return builder.toString();
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedCallable.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedCallable.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedCallable.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedCallable.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.portable;
+
+import org.apache.webbeans.config.WebBeansContext;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * Implementation of {@link AnnotatedCallable} interface.
+ *
+ * @version $Rev: 1182847 $ $Date: 2011-10-13 15:31:37 +0200 (jeu., 13 oct. 2011) $
+ *
+ * @param <X> declaring class
+ */
+abstract class AbstractAnnotatedCallable<X> extends AbstractAnnotatedMember<X> implements AnnotatedCallable<X>
+{
+ /**Annotated parameters*/
+ private List<AnnotatedParameter<X>> annotatedParameters = new ArrayList<AnnotatedParameter<X>>();
+
+ AbstractAnnotatedCallable(WebBeansContext webBeansContext, Type baseType, Member javaMember, AnnotatedType<X> declaringType)
+ {
+ super(webBeansContext, baseType,javaMember,declaringType);
+ }
+
+ protected void setAnnotatedParameters(Type[] genericParameterTypes,Annotation[][] parameterAnnotations)
+ {
+ int i = 0;
+
+ for(Type genericParameter : genericParameterTypes)
+ {
+ AnnotatedParameterImpl<X> parameterImpl = new AnnotatedParameterImpl<X>(getWebBeansContext(), genericParameter,this,i);
+ parameterImpl.setAnnotations(parameterAnnotations[i]);
+
+ addAnnotatedParameter(parameterImpl);
+
+ i++;
+ }
+ }
+
+ /**
+ * Adds new annotated parameter.
+ *
+ * @param parameter new annotated parameter
+ */
+ void addAnnotatedParameter(AnnotatedParameter<X> parameter)
+ {
+ annotatedParameters.add(parameter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<AnnotatedParameter<X>> getParameters()
+ {
+ return annotatedParameters;
+ }
+
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder(super.toString());
+ builder.append(",");
+ builder.append("Annotated Parameters : [");
+ for(AnnotatedParameter<X> parameter : annotatedParameters)
+ {
+ builder.append(parameter.toString());
+ }
+ builder.append("]");
+
+ return builder.toString();
+ }
+ }
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedMember.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedMember.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedMember.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotatedMember.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.portable;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+import org.apache.webbeans.config.WebBeansContext;
+
+/**
+ * Implementation of {@link AnnotatedMember} interface.
+ *
+ * @version $Rev: 1182847 $ $Date: 2011-10-13 15:31:37 +0200 (jeu., 13 oct. 2011) $
+ *
+ * @param <X> declaring class
+ */
+abstract class AbstractAnnotatedMember<X> extends AbstractAnnotated implements AnnotatedMember<X>
+{
+ /**Annotated type that owns this member*/
+ private final AnnotatedType<X> declaringType;
+
+ /**Member type*/
+ protected final Member javaMember;
+
+ @SuppressWarnings("unchecked")
+ AbstractAnnotatedMember(WebBeansContext webBeansContext, Type baseType, Member javaMember, AnnotatedType<X> declaringType)
+ {
+ super(webBeansContext, baseType);
+
+ this.javaMember = javaMember;
+
+ if(declaringType == null)
+ {
+ this.declaringType = (AnnotatedType<X>) getWebBeansContext().getAnnotatedElementFactory().newAnnotatedType(this.javaMember.getDeclaringClass());
+
+ AnnotatedTypeImpl<X> impl = (AnnotatedTypeImpl<X>)this.declaringType;
+
+ if(this.javaMember instanceof Constructor)
+ {
+ impl.addAnnotatedConstructor((AnnotatedConstructor<X>)this);
+ }
+
+ else if(this.javaMember instanceof Method)
+ {
+ impl.addAnnotatedMethod((AnnotatedMethod<X>)this);
+ }
+
+ else if(this.javaMember instanceof Field)
+ {
+ impl.addAnnotatedField((AnnotatedField<X>)this);
+ }
+ }
+ else
+ {
+ this.declaringType = declaringType;
+ }
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public AnnotatedType<X> getDeclaringType()
+ {
+ return declaringType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Member getJavaMember()
+ {
+ return javaMember;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isStatic()
+ {
+ return Modifier.isStatic(javaMember.getModifiers());
+ }
+
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder(super.toString());
+ builder.append(",");
+ builder.append("Java Member Name : " + javaMember.getName());
+
+ return builder.toString();
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedConstructorImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedConstructorImpl.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedConstructorImpl.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedConstructorImpl.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.portable;
+
+import org.apache.webbeans.config.WebBeansContext;
+
+import java.lang.reflect.Constructor;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * Implementation of {@link AnnotatedConstructor} interface.
+ *
+ * @version $Rev: 1182780 $ $Date: 2011-10-13 13:11:03 +0200 (jeu., 13 oct. 2011) $
+ *
+ * @param <X> class info
+ */
+class AnnotatedConstructorImpl<X> extends AbstractAnnotatedCallable<X> implements AnnotatedConstructor<X>
+{
+ /**
+ * Create a ew instance.
+ *
+ * @param javaMember constructor
+ */
+ AnnotatedConstructorImpl(WebBeansContext webBeansContext, Constructor<X> javaMember, AnnotatedType<X> declaringType)
+ {
+ super(webBeansContext, javaMember.getDeclaringClass(), javaMember, declaringType);
+ setAnnotations(javaMember.getDeclaredAnnotations());
+ setAnnotatedParameters(javaMember.getGenericParameterTypes(), javaMember.getParameterAnnotations());
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public Constructor<X> getJavaMember()
+ {
+ return Constructor.class.cast(javaMember);
+ }
+
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Annotated Constructor,");
+ builder.append(super.toString());
+
+ return builder.toString();
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedElementFactory.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.portable;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.util.Asserts;
+
+/**
+ * Factory for {@link javax.enterprise.inject.spi.Annotated} elements.
+ *
+ * @version $Rev: 1366640 $ $Date: 2012-07-28 13:24:18 +0200 (sam., 28 juil. 2012) $
+ */
+public final class AnnotatedElementFactory
+{
+
+ // Logger instance
+ private final static Logger logger = WebBeansLoggerFacade.getLogger(AnnotatedElementFactory.class);
+
+ //Cache of the AnnotatedType
+ private ConcurrentMap<Class<?>, AnnotatedType<?>> annotatedTypeCache =
+ new ConcurrentHashMap<Class<?>, AnnotatedType<?>>();
+
+ //Cache of AnnotatedConstructor
+ private ConcurrentMap<Constructor<?>, AnnotatedConstructor<?>> annotatedConstructorCache =
+ new ConcurrentHashMap<Constructor<?>, AnnotatedConstructor<?>>();
+
+ //Cache of AnnotatedMethod
+ private ConcurrentMap<Method, AnnotatedMethod<?>> annotatedMethodCache =
+ new ConcurrentHashMap<Method, AnnotatedMethod<?>>();
+
+ //Cache of AnnotatedField
+ private ConcurrentMap<Field, AnnotatedField<?>> annotatedFieldCache =
+ new ConcurrentHashMap<Field, AnnotatedField<?>>();
+
+ private WebBeansContext webBeansContext;
+
+ /**
+ * No instantiate.
+ */
+ public AnnotatedElementFactory(WebBeansContext webBeansContext)
+ {
+ this.webBeansContext = webBeansContext;
+ }
+
+ /**
+ * Get an already registered AnnotatedType. This will NOT create a new one!
+ * @param annotatedClass
+ * @param <X>
+ * @return AnnotatedType
+ */
+ public <X> AnnotatedType<X> getAnnotatedType(Class<X> annotatedClass)
+ {
+ return (AnnotatedType<X>) annotatedTypeCache.get(annotatedClass);
+ }
+
+ /**
+ * This method will get used to manually add AnnoatedTypes to our storage.
+ * Those AnnotatedTypes are coming from Extensions and get registered e.g. via
+ * {@link javax.enterprise.inject.spi.BeforeBeanDiscovery#addAnnotatedType(AnnotatedType)}
+ *
+ * Sets the annotatedType and replace the given one.
+ * @param annotatedType
+ * @param <X>
+ * @return the previously registered AnnotatedType or null if not previously defined.
+ */
+ public <X> AnnotatedType<X> setAnnotatedType(AnnotatedType<X> annotatedType)
+ {
+ return (AnnotatedType<X>) annotatedTypeCache.put(annotatedType.getJavaClass(), annotatedType);
+ }
+
+
+ /**
+ * Creates and configures new annotated type.
+ *
+ * @param <X> class info
+ * @param annotatedClass annotated class
+ * @return new annotated type
+ */
+ @SuppressWarnings("unchecked")
+ public <X> AnnotatedType<X> newAnnotatedType(Class<X> annotatedClass)
+ {
+ Asserts.assertNotNull(annotatedClass, "annotatedClass is null");
+ AnnotatedType<X> annotatedType = (AnnotatedType<X>)annotatedTypeCache.get(annotatedClass);
+ if(annotatedType == null)
+ {
+ try
+ {
+ annotatedType = new AnnotatedTypeImpl<X>(webBeansContext, annotatedClass);
+
+ AnnotatedType<X> oldType = (AnnotatedType<X>)annotatedTypeCache.putIfAbsent(annotatedClass, annotatedType);
+ if(oldType != null)
+ {
+ annotatedType = oldType;
+ }
+ }
+ catch (Exception e)
+ {
+ if (e instanceof ClassNotFoundException || e instanceof ArrayStoreException)
+ {
+ if (logger.isLoggable(Level.SEVERE))
+ {
+ logger.log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0027, annotatedClass.getName(), e.getCause()), e);
+ }
+
+ annotatedType = null;
+ }
+ else
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ catch (NoClassDefFoundError ncdfe)
+ {
+ if (logger.isLoggable(Level.SEVERE))
+ {
+ logger.log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0027, annotatedClass.getName(), ncdfe.getCause()), ncdfe);
+ }
+
+ annotatedType = null;
+ }
+ }
+
+ return annotatedType;
+ }
+
+ /**
+ * Creates and configures new annotated constructor.
+ *
+ * @param <X> declaring class
+ * @param constructor constructor
+ * @return new annotated constructor
+ */
+ @SuppressWarnings("unchecked")
+ public <X> AnnotatedConstructor<X> newAnnotatedConstructor(Constructor<X> constructor, AnnotatedType<X> declaringClass)
+ {
+ Asserts.assertNotNull(constructor, "constructor is null");
+ Asserts.assertNotNull(declaringClass, "declaringClass is null");
+
+ AnnotatedConstructorImpl<X> annConstructor;
+ if(annotatedConstructorCache.containsKey(constructor))
+ {
+ annConstructor = (AnnotatedConstructorImpl<X>)annotatedConstructorCache.get(constructor);
+ }
+ else
+ {
+ annConstructor = new AnnotatedConstructorImpl<X>(webBeansContext, constructor, declaringClass);
+ AnnotatedConstructorImpl<X> old = (AnnotatedConstructorImpl<X>)annotatedConstructorCache.putIfAbsent(constructor, annConstructor);
+ if(old != null)
+ {
+ annConstructor = old;
+ }
+ }
+
+ return annConstructor;
+ }
+
+ /**
+ * Creates and configures new annotated field.
+ *
+ * @param <X> declaring class
+ * @param field field instance
+ * @param declaringClass declaring class
+ * @return new annotated field
+ */
+ @SuppressWarnings("unchecked")
+ public <X> AnnotatedField<X> newAnnotatedField(Field field, AnnotatedType<X> declaringClass)
+ {
+ Asserts.assertNotNull(field, "field is null");
+ Asserts.assertNotNull(declaringClass, "declaringClass is null");
+
+ AnnotatedFieldImpl<X> annotField;
+ if(annotatedFieldCache.containsKey(field))
+ {
+ annotField = (AnnotatedFieldImpl<X>)annotatedFieldCache.get(field);
+ }
+ else
+ {
+ annotField = new AnnotatedFieldImpl<X>(webBeansContext, field, declaringClass);
+ AnnotatedFieldImpl<X> old = (AnnotatedFieldImpl<X>) annotatedFieldCache.putIfAbsent(field, annotField);
+ if(old != null)
+ {
+ annotField = old;
+ }
+ }
+
+ return annotField;
+ }
+
+ /**
+ * Creates and configures new annotated method.
+ *
+ * @param <X> declaring class
+ * @param method annotated method
+ * @param declaringType declaring class info
+ * @return new annotated method
+ */
+ @SuppressWarnings("unchecked")
+ public <X> AnnotatedMethod<X> newAnnotatedMethod(Method method, AnnotatedType<X> declaringType)
+ {
+ Asserts.assertNotNull(method, "method is null");
+ Asserts.assertNotNull(declaringType, "declaringType is null");
+
+ AnnotatedMethodImpl<X> annotMethod;
+ if(annotatedMethodCache.containsKey(method))
+ {
+ annotMethod = (AnnotatedMethodImpl<X>)annotatedMethodCache.get(method);
+ }
+ else
+ {
+ annotMethod = new AnnotatedMethodImpl<X>(webBeansContext, method, declaringType);
+ AnnotatedMethodImpl<X> old = (AnnotatedMethodImpl<X>) annotatedMethodCache.putIfAbsent(method, annotMethod);
+ if(old != null)
+ {
+ annotMethod = old;
+ }
+ }
+
+ return annotMethod;
+ }
+
+ /**
+ * Clear caches.
+ */
+ public void clear()
+ {
+ annotatedTypeCache.clear();
+ annotatedConstructorCache.clear();
+ annotatedFieldCache.clear();
+ annotatedMethodCache.clear();
+ }
+}