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 [12/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/exception/definition/DuplicateDefinitionException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/definition/DuplicateDefinitionException.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/definition/DuplicateDefinitionException.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/definition/DuplicateDefinitionException.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,47 @@
+/*
+ * 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.exception.definition;
+
+import org.apache.webbeans.exception.inject.DefinitionException;
+
+public class DuplicateDefinitionException extends DefinitionException
+{
+ private static final long serialVersionUID = 2312285271502063304L;
+
+ public DuplicateDefinitionException()
+ {
+ super();
+ }
+
+ public DuplicateDefinitionException(String message)
+ {
+ super(message);
+ }
+
+ public DuplicateDefinitionException(Throwable e)
+ {
+ super(e);
+ }
+
+ public DuplicateDefinitionException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/helper/ViolationMessageBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/helper/ViolationMessageBuilder.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/helper/ViolationMessageBuilder.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/helper/ViolationMessageBuilder.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.exception.helper;
+
+public class ViolationMessageBuilder
+{
+ private StringBuilder violationMessage;
+
+ private final String lineSeparator = System.getProperty("line.separator");
+
+ public static ViolationMessageBuilder newViolation()
+ {
+ return new ViolationMessageBuilder();
+ }
+
+ public static ViolationMessageBuilder newViolation(String... text)
+ {
+ return new ViolationMessageBuilder().append(text);
+ }
+
+ public ViolationMessageBuilder append(String... text)
+ {
+ appendText(text, false);
+ return this;
+ }
+
+ public ViolationMessageBuilder addLine(String... text)
+ {
+ if(text == null)
+ {
+ return this;
+ }
+
+ appendText(text, true);
+ return this;
+ }
+
+ private void appendText(String[] text, boolean appendLineSeparator)
+ {
+ if(violationMessage == null)
+ {
+ violationMessage = new StringBuilder();
+ }
+ else if(appendLineSeparator)
+ {
+ violationMessage.append(lineSeparator);
+ }
+
+ for(String t : text)
+ {
+ violationMessage.append(t);
+ }
+ }
+
+ public boolean containsViolation()
+ {
+ return violationMessage != null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return containsViolation() ? violationMessage.toString() : "no violation recorded";
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DefinitionException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DefinitionException.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DefinitionException.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DefinitionException.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.exception.inject;
+
+public class DefinitionException extends RuntimeException
+{
+ private static final long serialVersionUID = -6261526411795328050L;
+
+ public DefinitionException()
+ {
+ super();
+ }
+
+ public DefinitionException(String message)
+ {
+ super(message);
+ }
+
+ public DefinitionException(Throwable e)
+ {
+ super(e);
+ }
+
+ public DefinitionException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DeploymentException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DeploymentException.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DeploymentException.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/DeploymentException.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.exception.inject;
+
+public class DeploymentException extends RuntimeException
+{
+ private static final long serialVersionUID = -6635290650256485602L;
+
+ public DeploymentException()
+ {
+ super();
+ }
+
+ public DeploymentException(String message)
+ {
+ super(message);
+ }
+
+ public DeploymentException(Throwable e)
+ {
+ super(e);
+ }
+
+ public DeploymentException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/InconsistentSpecializationException.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.exception.inject;
+
+public class InconsistentSpecializationException extends DeploymentException
+{
+ private static final long serialVersionUID = 5398575103682514128L;
+
+ public InconsistentSpecializationException()
+ {
+ super();
+ }
+
+ public InconsistentSpecializationException(String message)
+ {
+ super(message);
+ }
+
+ public InconsistentSpecializationException(Throwable e)
+ {
+ super(e);
+ }
+
+ public InconsistentSpecializationException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/NullableDependencyException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/NullableDependencyException.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/NullableDependencyException.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/exception/inject/NullableDependencyException.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.exception.inject;
+
+public class NullableDependencyException extends DeploymentException
+{
+ private static final long serialVersionUID = -2226577224929251465L;
+
+ public NullableDependencyException()
+ {
+ super();
+ }
+
+ public NullableDependencyException(String message)
+ {
+ super(message);
+ }
+
+ public NullableDependencyException(Throwable e)
+ {
+ super(e);
+ }
+
+ public NullableDependencyException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,230 @@
+/*
+ * 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.inject;
+
+import java.io.Serializable;
+import java.lang.reflect.Member;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.IllegalProductException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Provider;
+
+import org.apache.webbeans.component.AbstractProducerBean;
+import org.apache.webbeans.component.EventBean;
+import org.apache.webbeans.component.InjectionPointBean;
+import org.apache.webbeans.component.InstanceBean;
+import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.context.creational.DependentCreationalContext;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * Abstract implementation of the {@link Injectable} contract.
+ *
+ * <p>
+ * Do actual injection via {@link AbstractInjectable#inject(InjectionPoint)}
+ * </p>
+ *
+ * @see InjectableField
+ * @see InjectableConstructor
+ * @see InjectableMethods
+ */
+public abstract class AbstractInjectable implements Injectable
+{
+ /** Owner bean of the injection point*/
+ protected OwbBean<?> injectionOwnerBean;
+
+ /**Creational context instance that is passed to bean's create*/
+ protected CreationalContext<?> injectionOwnerCreationalContext;
+
+ /**Field, method or constructor injection*/
+ protected Member injectionMember;
+
+ //X TODO refactor. public static variables are utterly ugly
+ public static ThreadLocal<Object> instanceUnderInjection = new ThreadLocal<Object>();
+
+ //X TODO this MUST NOT be public!
+ public static ThreadLocal<List<DependentCreationalContext<Object>>> dependentInstanceOfProducerMethods =
+ new ThreadLocal<List<DependentCreationalContext<Object>>>();
+
+ /**
+ * Creates a new injectable.
+ *
+ * @param injectionOwnerBean owner bean
+ * @param injectionOwnerCreationalContext creational context instance
+ */
+ protected AbstractInjectable(OwbBean<?> injectionOwnerBean, CreationalContext<?> injectionOwnerCreationalContext)
+ {
+ this.injectionOwnerBean = injectionOwnerBean;
+ this.injectionOwnerCreationalContext = injectionOwnerCreationalContext;
+ }
+
+ /**
+ * Gets the injected bean instance in its scoped context.
+ * @param injectionPoint injection point definition
+ * @return current bean instance in the resolved bean scope
+ */
+ public <T> Object inject(InjectionPoint injectionPoint)
+ {
+ Object injected;
+ BeanManagerImpl beanManager = injectionOwnerBean.getWebBeansContext().getBeanManagerImpl();
+
+ //Injected contextual beam
+ InjectionResolver instance = beanManager.getInjectionResolver();
+
+ Bean<?> injectedBean = instance.getInjectionPointBean(injectionPoint);
+ if(isInstanceProviderInjection(injectionPoint))
+ {
+ InstanceBean.local.set(injectionPoint);
+ }
+
+ else if(isEventProviderInjection(injectionPoint))
+ {
+ EventBean.local.set(injectionPoint);
+ }
+
+ boolean injectionPointBeanLocalSetOnStack = false;
+ try
+ {
+ //Injection for dependent instance InjectionPoint fields
+ boolean dependentProducer = false;
+ if(WebBeansUtil.isDependent(injectedBean))
+ {
+ if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
+ {
+ injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(injectionPoint);
+ }
+
+ if(!injectionPoint.isTransient())
+ {
+ if(injectedBean instanceof AbstractProducerBean)
+ {
+ if(injectionOwnerBean.isPassivationCapable())
+ {
+ dependentProducer = true;
+ }
+ }
+ }
+ }
+
+ //Gets injectable reference for injected bean
+ injected = beanManager.getInjectableReference(injectionPoint, injectionOwnerCreationalContext);
+
+ /*X TODO see spec issue CDI-140 */
+ if(dependentProducer)
+ {
+ if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
+ {
+ throw new IllegalProductException("If a producer method or field of scope @Dependent returns an serializable object for injection " +
+ "into an injection point "+ injectionPoint +" that requires a passivation capable dependency");
+ }
+ }
+
+ // add this dependent into bean dependent list
+ if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
+ {
+ if(instanceUnderInjection.get() != null)
+ {
+ ((CreationalContextImpl<?>) injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean, injected);
+ }
+ }
+ }
+ finally
+ {
+ if (injectionPointBeanLocalSetOnStack)
+ {
+ InjectionPointBean.unsetThreadLocal();
+ }
+ }
+
+
+ return injected;
+ }
+
+
+ /**
+ * Returns injection points related with given member type of the bean.
+ * @param member java member
+ * @return injection points related with given member type
+ */
+ protected List<InjectionPoint> getInjectedPoints(Member member)
+ {
+ List<InjectionPoint> injectedFields = injectionOwnerBean.getInjectionPoint(member);
+
+ return injectedFields;
+
+ }
+
+ private boolean isInstanceProviderInjection(InjectionPoint injectionPoint)
+ {
+ Type type = injectionPoint.getType();
+
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType pt = (ParameterizedType) type;
+ Class<?> clazz = (Class<?>) pt.getRawType();
+
+ if(Provider.class.isAssignableFrom(clazz))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ private boolean isEventProviderInjection(InjectionPoint injectionPoint)
+ {
+ Type type = injectionPoint.getType();
+
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType pt = (ParameterizedType) type;
+ Class<?> clazz = (Class<?>) pt.getRawType();
+
+ if(clazz.isAssignableFrom(Event.class))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Gets the component.
+ *
+ * @return the component
+ */
+ public OwbBean<?> getInjectionOwnerComponent()
+ {
+ return injectionOwnerBean;
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,142 @@
+/*
+ * 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.inject;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.spi.Bean;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.webbeans.util.AnnotationUtil;
+
+public class AlternativesManager
+{
+ private final Set<Class<?>> alternatives = new HashSet<Class<?>>();
+
+ private final Set<Class<? extends Annotation>> stereoAlternatives = new HashSet<Class<? extends Annotation>>();
+
+ private final WebBeansContext webBeansContext;
+
+ public AlternativesManager(WebBeansContext webBeansContext)
+ {
+
+ this.webBeansContext = webBeansContext;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void addStereoTypeAlternative(Class<?> alternative,String fileName,ScannerService scanner)
+ {
+ if(Annotation.class.isAssignableFrom(alternative))
+ {
+ Class<? extends Annotation> stereo = (Class<? extends Annotation>)alternative;
+ boolean ok = false;
+ if(webBeansContext.getAnnotationManager().isStereoTypeAnnotation(stereo))
+ {
+ if(AnnotationUtil.hasClassAnnotation(stereo, Alternative.class))
+ {
+ boolean isBDAScanningEnabled=(scanner!=null && scanner.isBDABeansXmlScanningEnabled());
+ if(isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addStereoType(stereo, fileName) ||
+ (!isBDAScanningEnabled && stereoAlternatives.contains(stereo)) )
+ {
+ throw new WebBeansConfigurationException("Given alternative class : " + alternative.getName() + " is already added as @Alternative" );
+ }
+
+ ok = true;
+
+ stereoAlternatives.add(stereo);
+ }
+ }
+
+ if(!ok)
+ {
+ throw new WebBeansConfigurationException("Given stereotype class : " + alternative.getName() + " is not annotated with @Alternative" );
+ }
+ }
+ else
+ {
+ throw new WebBeansConfigurationException("Given stereotype class : " + alternative.getName() + " is not an annotation" );
+ }
+ }
+
+ public void addClazzAlternative(Class<?> alternative,String fileName,ScannerService scanner)
+ {
+ if(AnnotationUtil.hasClassAnnotation(alternative, Alternative.class))
+ {
+ boolean isBDAScanningEnabled=(scanner!=null && scanner.isBDABeansXmlScanningEnabled());
+ if((isBDAScanningEnabled && !scanner.getBDABeansXmlScanner().addAlternative(alternative, fileName)) ||
+ (!isBDAScanningEnabled && alternatives.contains(alternative)))
+ {
+ throw new WebBeansConfigurationException("Given class : " + alternative.getName() + " is already added as @Alternative" );
+ }
+
+ alternatives.add(alternative);
+ }
+ else
+ {
+ throw new WebBeansConfigurationException("Given class : " + alternative.getName() + " is not annotated with @Alternative" );
+ }
+ }
+
+ public boolean isClassAlternative(Class<?> clazz)
+ {
+ if(alternatives.contains(clazz))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean isStereoAlternative(Class<? extends Annotation> stereo)
+ {
+ return stereoAlternatives.contains(stereo);
+ }
+
+ public boolean isBeanHasAlternative(Bean<?> bean)
+ {
+ Class<?> returnType = bean.getBeanClass();
+
+ if(alternatives.contains(returnType))
+ {
+ return true;
+ }
+
+ Set<Class<? extends Annotation>> set = bean.getStereotypes();
+ for(Class<? extends Annotation> ann : set)
+ {
+ if(stereoAlternatives.contains(ann))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public void clear()
+ {
+ alternatives.clear();
+ stereoAlternatives.clear();
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,54 @@
+/*
+ * 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.inject;
+
+/**
+ * Marker interface for all injectable elements of the web beans components.
+ * <p>
+ * There are several injectable elements in the web beans container;
+ * <ul>
+ * <li>Constructor,</li>
+ * <li>Methods,</li>
+ * <li>Fields</li>
+ * </ul>
+ * </p>
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ * @see InjectableConstructor
+ * @see InjectableField
+ * @see InjectableMethods
+ * @see AbstractInjectable
+ */
+public interface Injectable
+{
+ /**
+ * Responsible for injecting the owner required injected component
+ * instances. Maybe returning an component instance, for example,
+ * {@link InjectableConstructor#doInjection()} returns a new web bean
+ * component instance.
+ * <p>
+ * Each injetable elements parameters, web beans component instances, are
+ * resolved using the resolution type algorithm.
+ * </p>
+ *
+ * @return if the return instance if available
+ */
+ public Object doInjection();
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,99 @@
+/*
+ * 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.inject;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.exception.WebBeansException;
+
+/**
+ * Injects the parameters of the {@link org.apache.webbeans.component.ManagedBean} constructor and returns
+ * the created instance.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ * @see AbstractInjectable
+ */
+public class InjectableConstructor<T> extends AbstractInjectable
+{
+ /** Injectable constructor instance */
+ protected Constructor<T> con;
+
+ /**
+ * Sets the constructor.
+ *
+ * @param cons injectable constructor
+ */
+ public InjectableConstructor(Constructor<T> cons, AbstractOwbBean<?> owner,CreationalContext<?> creationalContext)
+ {
+ super(owner,creationalContext);
+ con = cons;
+ injectionMember = con;
+ }
+
+ /**
+ * Creates the instance from the constructor. Each constructor parameter
+ * instance is resolved using the resolution algorithm.
+ */
+ public T doInjection()
+ {
+ T instance = null;
+
+ List<InjectionPoint> injectedPoints = getInjectedPoints(con);
+ List<Object> list = new ArrayList<Object>();
+
+
+ for(int i=0;i<injectedPoints.size();i++)
+ {
+ for(InjectionPoint point : injectedPoints)
+ {
+ AnnotatedParameter<?> parameter = (AnnotatedParameter<?>)point.getAnnotated();
+ if(parameter.getPosition() == i)
+ {
+ list.add(inject(point));
+ break;
+ }
+ }
+ }
+
+ try
+ {
+ if(!con.isAccessible())
+ {
+ injectionOwnerBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(con, true);
+ }
+
+ instance = con.newInstance(list.toArray());
+
+ }
+ catch (Exception e)
+ {
+ throw new WebBeansException(e);
+ }
+
+ return instance;
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.inject;
+
+import java.lang.reflect.Field;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.exception.WebBeansException;
+
+/**
+ * Field type injection.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class InjectableField extends AbstractInjectable
+{
+ protected Field field;
+ protected Object instance;
+
+ public InjectableField(Field field, Object instance, AbstractOwbBean<?> owner,CreationalContext<?> creationalContext)
+ {
+ super(owner,creationalContext);
+ this.field = field;
+ this.instance = instance;
+ injectionMember = field;
+ }
+
+ public Object doInjection()
+ {
+ try
+ {
+ InjectionPoint injectedField = getInjectedPoints(field).get(0);
+
+ if (!field.isAccessible())
+ {
+ injectionOwnerBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(field, true);
+ }
+
+ Object object = inject(injectedField);
+
+ field.set(instance, object);
+
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new WebBeansException(e);
+ }
+
+ return null;
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,173 @@
+/*
+ * 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.inject;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.webbeans.annotation.DefaultLiteral;
+import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.component.ProducerMethodBean;
+import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.exception.WebBeansException;
+
+@SuppressWarnings("unchecked")
+public class InjectableMethods<T> extends AbstractInjectable
+{
+ /** Injectable method */
+ protected Method method;
+
+ /** Bean parent instance that owns the method */
+ protected Object instance;
+
+ /**If this method is dispose method*/
+ private boolean disposable;
+
+ /**Used in dispose method, represents produces method parameter instance*/
+ private Object producerMethodInstance = null;
+
+ private Map<Bean<?>,Object> dependentParameters = new HashMap<Bean<?>, Object>();
+
+ /**
+ * Constructs new instance.
+ *
+ * @param m injectable method
+ * @param instance component instance
+ */
+ public InjectableMethods(Method m, Object instance, OwbBean<?> owner,CreationalContext<?> creationalContext)
+ {
+ super(owner,creationalContext);
+ method = m;
+ this.instance = instance;
+ injectionMember = m;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.inject.Injectable#doInjection()
+ */
+ public T doInjection()
+ {
+ List<InjectionPoint> injectedPoints = getInjectedPoints(method);
+ List<Object> list = new ArrayList<Object>();
+
+
+ for(int i=0;i<injectedPoints.size();i++)
+ {
+ for(InjectionPoint point : injectedPoints)
+ {
+ AnnotatedParameter<?> parameter = (AnnotatedParameter<?>)point.getAnnotated();
+ if(parameter.getPosition() == i)
+ {
+ boolean injectionPoint = false;
+ if(injectionOwnerBean instanceof ProducerMethodBean)
+ {
+ if(parameter.getBaseType().equals(InjectionPoint.class))
+ {
+ BeanManager manager = injectionOwnerBean.getWebBeansContext().getBeanManagerImpl();
+ Bean<?> injectionPointBean = manager.getBeans(InjectionPoint.class, new DefaultLiteral()).iterator().next();
+ Object reference = manager.getReference(injectionPointBean, InjectionPoint.class, manager.createCreationalContext(injectionPointBean));
+
+ dependentParameters.put(injectionPointBean, reference);
+ list.add(reference);
+
+ injectionPoint = true;
+ }
+
+ }
+
+ if(!injectionPoint)
+ {
+ if(isDisposable() && parameter.getAnnotation(Disposes.class) != null)
+ {
+ list.add(producerMethodInstance);
+ }
+ else
+ {
+ Object instance = inject(point);
+ InjectionResolver injectionResolver = injectionOwnerBean.getWebBeansContext().getBeanManagerImpl().getInjectionResolver();
+
+ Bean<?> injectedBean = (Bean<?>) injectionResolver.getInjectionPointBean(point);
+ if(injectedBean.getScope() == Dependent.class)
+ {
+ dependentParameters.put(injectedBean, instance);
+ }
+
+ list.add(instance);
+ }
+ }
+
+ break;
+ }
+ }
+ }
+
+ try
+ {
+ if (!method.isAccessible())
+ {
+ injectionOwnerBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(method, true);
+ }
+
+ return (T) method.invoke(instance, list.toArray(new Object[list.size()]));
+
+ }
+ catch (Exception e)
+ {
+ throw new WebBeansException(e);
+ }
+ }
+
+ public Map<Bean<?>,Object> getDependentBeanParameters()
+ {
+ return dependentParameters;
+ }
+
+ /**
+ * @return the disposable
+ */
+ private boolean isDisposable()
+ {
+ return disposable;
+ }
+
+ /**
+ * @param disposable the disposable to set
+ */
+ public void setDisposable(boolean disposable)
+ {
+ this.disposable = disposable;
+ }
+
+ public void setProducerMethodInstance(Object instance)
+ {
+ producerMethodInstance = instance;
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,62 @@
+/*
+ * 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.inject;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Injects dependencies of the given Java EE component
+ * instance.
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+public final class OWBInjector
+{
+ private OWBInjector()
+ {
+ //No operation
+ }
+
+ /**
+ * Inject dependencies of given instance.
+ * @param beanManager the BeanManager to use
+ * @param instanceUnderInjection instance
+ * @param ownerCreationalContext CreationalContext of the owner
+ * @return this injector
+ * @throws Exception if exception occurs
+ */
+ @SuppressWarnings("unchecked")
+ public static void inject(BeanManager beanManager, Object instanceUnderInjection, CreationalContext<?> ownerCreationalContext)
+ throws Exception
+ {
+ CreationalContext<?> creationalContext = ownerCreationalContext;
+ if(creationalContext == null)
+ {
+ creationalContext = beanManager.createCreationalContext(null);
+ }
+
+ AnnotatedType annotatedType = beanManager.createAnnotatedType(instanceUnderInjection.getClass());
+ beanManager.createInjectionTarget(annotatedType).inject(instanceUnderInjection, creationalContext);
+ }
+
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,265 @@
+/*
+ * 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.inject.impl;
+
+import java.lang.annotation.Annotation;
+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 java.util.ArrayList;
+import java.util.List;
+
+import javax.decorator.Delegate;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Named;
+
+import org.apache.webbeans.annotation.NamedLiteral;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.Asserts;
+
+public class InjectionPointFactory
+{
+ private final WebBeansContext webBeansContext;
+
+ public InjectionPointFactory(WebBeansContext webBeansContext)
+ {
+ this.webBeansContext = webBeansContext;
+ }
+
+ public InjectionPoint getFieldInjectionPointData(Bean<?> owner, Field member)
+ {
+ Asserts.assertNotNull(owner, "owner parameter can not be null");
+ Asserts.assertNotNull(member, "member parameter can not be null");
+
+ Annotation[] annots = null;
+ annots = member.getAnnotations();
+
+ AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
+
+ AnnotatedType<?> annotated = annotatedElementFactory.newAnnotatedType(member.getDeclaringClass());
+ return getGenericInjectionPoint(owner, annots, member.getGenericType(), member, annotatedElementFactory.newAnnotatedField(member, annotated));
+ }
+
+ public <X> InjectionPoint getFieldInjectionPointData(Bean<?> owner, AnnotatedField<X> annotField)
+ {
+ Asserts.assertNotNull(owner, "owner parameter can not be null");
+ Asserts.assertNotNull(annotField, "annotField parameter can not be null");
+ Field member = annotField.getJavaMember();
+
+ Annotation[] annots = AnnotationUtil.getAnnotationsFromSet(annotField.getAnnotations());
+
+ return getGenericInjectionPoint(owner, annots, annotField.getBaseType(), member, annotField);
+ }
+
+ /**
+ * Gets injected point instance.
+ * @param owner owner of the injection point
+ * @param annots annotations of the injection point
+ * @param type type of the injection point
+ * @param member member of the injection point
+ * @param annotated annotated instance of injection point
+ * @return injection point instance
+ */
+ private InjectionPoint getGenericInjectionPoint(Bean<?> owner, Annotation[] annots, Type type, Member member,Annotated annotated)
+ {
+ InjectionPointImpl injectionPoint;
+
+ Annotation[] qualifierAnnots = webBeansContext.getAnnotationManager().getQualifierAnnotations(annots);
+
+ //@Named update for injection fields!
+ if(member instanceof Field)
+ {
+ for(int i=0; i < qualifierAnnots.length; i++)
+ {
+ Annotation qualifier = qualifierAnnots[i];
+ if(qualifier.annotationType().equals(Named.class))
+ {
+ Named named = (Named)qualifier;
+ String value = named.value();
+
+ if(value == null || value.equals(""))
+ {
+ NamedLiteral namedLiteral = new NamedLiteral();
+ namedLiteral.setValue(member.getName());
+ qualifierAnnots[i] = namedLiteral;
+ }
+
+ break;
+ }
+ }
+ }
+
+
+ injectionPoint = new InjectionPointImpl(owner, type, member, annotated);
+
+ if(AnnotationUtil.hasAnnotation(annots, Delegate.class))
+ {
+ injectionPoint.setDelegate(true);
+ }
+
+ if(Modifier.isTransient(member.getModifiers()))
+ {
+ injectionPoint.setTransient(true);
+ }
+
+ addAnnotation(injectionPoint, qualifierAnnots, true);
+
+ return injectionPoint;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<InjectionPoint> getMethodInjectionPointData(Bean<?> owner, Method member)
+ {
+ Asserts.assertNotNull(owner, "owner parameter can not be null");
+ Asserts.assertNotNull(member, "member parameter can not be null");
+
+ List<InjectionPoint> lists = new ArrayList<InjectionPoint>();
+
+ AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
+ AnnotatedType<?> annotated = annotatedElementFactory.newAnnotatedType(member.getDeclaringClass());
+ AnnotatedMethod method = annotatedElementFactory.newAnnotatedMethod(member, annotated);
+ List<AnnotatedParameter<?>> parameters = method.getParameters();
+
+ InjectionPoint point = null;
+
+ for(AnnotatedParameter<?> parameter : parameters)
+ {
+ //@Observes is not injection point type for method parameters
+ if(parameter.getAnnotation(Observes.class) == null)
+ {
+ point = getGenericInjectionPoint(owner, parameter.getAnnotations().toArray(new Annotation[parameter.getAnnotations().size()]),
+ parameter.getBaseType(), member , parameter);
+ lists.add(point);
+ }
+ }
+
+ return lists;
+ }
+
+ public <X> List<InjectionPoint> getMethodInjectionPointData(Bean<?> owner, AnnotatedMethod<X> method)
+ {
+ Asserts.assertNotNull(owner, "owner parameter can not be null");
+ Asserts.assertNotNull(method, "method parameter can not be null");
+
+ List<InjectionPoint> lists = new ArrayList<InjectionPoint>();
+
+ List<AnnotatedParameter<X>> parameters = method.getParameters();
+
+ InjectionPoint point = null;
+
+ for(AnnotatedParameter<?> parameter : parameters)
+ {
+ //@Observes is not injection point type for method parameters
+ if(parameter.getAnnotation(Observes.class) == null)
+ {
+ point = getGenericInjectionPoint(owner, parameter.getAnnotations().toArray(new Annotation[parameter.getAnnotations().size()]),
+ parameter.getBaseType(), method.getJavaMember() , parameter);
+ lists.add(point);
+ }
+ }
+
+ return lists;
+ }
+
+ public static InjectionPoint getPartialInjectionPoint(Bean<?> owner,Type type, Member member, Annotated annotated, Annotation...bindings)
+ {
+ InjectionPointImpl impl = new InjectionPointImpl(owner,type,member,annotated);
+
+
+ for(Annotation annot : bindings)
+ {
+ impl.addBindingAnnotation(annot);
+ }
+
+ return impl;
+
+ }
+
+ public <T> List<InjectionPoint> getConstructorInjectionPointData(Bean<T> owner, AnnotatedConstructor<T> constructor)
+ {
+ Asserts.assertNotNull(owner, "owner parameter can not be null");
+ Asserts.assertNotNull(constructor, "constructor parameter can not be null");
+
+ List<InjectionPoint> lists = new ArrayList<InjectionPoint>();
+
+ List<AnnotatedParameter<T>> parameters = constructor.getParameters();
+
+ InjectionPoint point = null;
+
+ for(AnnotatedParameter<?> parameter : parameters)
+ {
+ point = getGenericInjectionPoint(owner, parameter.getAnnotations().toArray(new Annotation[parameter.getAnnotations().size()]),
+ parameter.getBaseType(), constructor.getJavaMember() , parameter);
+ lists.add(point);
+ }
+
+ return lists;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public List<InjectionPoint> getConstructorInjectionPointData(Bean<?> owner, Constructor<?> member)
+ {
+ Asserts.assertNotNull(owner, "owner parameter can not be null");
+ Asserts.assertNotNull(member, "member parameter can not be null");
+
+ List<InjectionPoint> lists = new ArrayList<InjectionPoint>();
+
+ AnnotatedType<Object> annotated = (AnnotatedType<Object>) webBeansContext.getAnnotatedElementFactory().newAnnotatedType(member.getDeclaringClass());
+ AnnotatedConstructor constructor = webBeansContext.getAnnotatedElementFactory().newAnnotatedConstructor((Constructor<Object>)member,annotated);
+ List<AnnotatedParameter<?>> parameters = constructor.getParameters();
+
+ InjectionPoint point = null;
+
+ for(AnnotatedParameter<?> parameter : parameters)
+ {
+ point = getGenericInjectionPoint(owner, parameter.getAnnotations().toArray(new Annotation[parameter.getAnnotations().size()]),
+ parameter.getBaseType(), member , parameter);
+ lists.add(point);
+ }
+
+ return lists;
+ }
+
+ private static void addAnnotation(InjectionPointImpl impl, Annotation[] annots, boolean isBinding)
+ {
+ for (Annotation ann : annots)
+ {
+ if (isBinding)
+ {
+ impl.addBindingAnnotation(ann);
+ }
+ }
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,301 @@
+/*
+ * 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.inject.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
+import org.apache.webbeans.util.WebBeansUtil;
+
+class InjectionPointImpl implements InjectionPoint, Serializable
+{
+ private static final long serialVersionUID = 1047233127758068484L;
+
+ private Set<Annotation> qualifierAnnotations = new HashSet<Annotation>();
+
+ private Bean<?> ownerBean;
+
+ private Member injectionMember;
+
+ private Type injectionType;
+
+ private Annotated annotated;
+
+ private boolean transientt;
+
+ private boolean delegate;
+
+ InjectionPointImpl(Bean<?> ownerBean, Type type, Member member, Annotated annotated)
+ {
+ this.ownerBean = ownerBean;
+ injectionMember = member;
+ injectionType = type;
+ this.annotated = annotated;
+ }
+
+ void addBindingAnnotation(Annotation qualifierAnnotations)
+ {
+ this.qualifierAnnotations.add(qualifierAnnotations);
+ }
+
+ public Bean<?> getBean()
+ {
+
+ return ownerBean;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+
+ return qualifierAnnotations;
+ }
+
+ public Member getMember()
+ {
+ return injectionMember;
+ }
+
+ public Type getType()
+ {
+
+ return injectionType;
+ }
+
+
+ public Annotated getAnnotated()
+ {
+ return annotated;
+ }
+
+ public boolean isDelegate()
+ {
+ return delegate;
+ }
+
+ public boolean isTransient()
+ {
+ return transientt;
+ }
+
+ void setDelegate(boolean delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ void setTransient(boolean transientt)
+ {
+ this.transientt = transientt;
+ }
+
+ private void writeObject(java.io.ObjectOutputStream op) throws IOException
+ {
+ ObjectOutputStream out = new ObjectOutputStream(op);
+
+ //Write the owning bean class
+ out.writeObject(ownerBean.getBeanClass());
+
+ Set<Annotation> qualifiers = ownerBean.getQualifiers();
+ for(Annotation qualifier : qualifiers)
+ {
+ out.writeObject(Character.valueOf('-')); // throw-away delimiter so alternating annotations don't get swallowed in the read.
+ out.writeObject(qualifier);
+
+ }
+
+ out.writeObject(Character.valueOf('~'));
+
+ if(injectionMember instanceof Field)
+ {
+ out.writeByte(0);
+ out.writeUTF(injectionMember.getName());
+ }
+
+ if(injectionMember instanceof Method)
+ {
+ out.writeByte(1);
+ out.writeUTF(injectionMember.getName());
+ Method method = (Method) injectionMember;
+ Class<?>[] parameters = method.getParameterTypes();
+ out.writeObject(parameters);
+
+ AnnotatedParameter<?> ap = (AnnotatedParameter<?>) annotated;
+ out.writeByte(ap.getPosition());
+
+ }
+
+ if(injectionMember instanceof Constructor)
+ {
+ out.writeByte(2);
+ Constructor<?> constr = (Constructor<?>) injectionMember;
+ Class<?>[] parameters = constr.getParameterTypes();
+ out.writeObject(parameters);
+
+ AnnotatedParameter<?> ap = (AnnotatedParameter<?>) annotated;
+ out.writeByte(ap.getPosition());
+
+ }
+
+ out.writeBoolean(delegate);
+ out.writeBoolean(transientt);
+ out.flush();
+
+ }
+
+ public class CustomObjectInputStream extends ObjectInputStream
+ {
+ private ClassLoader classLoader;
+
+ public CustomObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException
+ {
+ super(in);
+ this.classLoader = classLoader;
+ }
+
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException
+ {
+ return Class.forName(desc.getName(), false, classLoader);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream inp) throws IOException, ClassNotFoundException
+ {
+
+ ObjectInputStream in = new CustomObjectInputStream(inp, WebBeansUtil.getCurrentClassLoader());
+
+ Class<?> beanClass = (Class<?>)in.readObject();
+ Set<Annotation> anns = new HashSet<Annotation>();
+ WebBeansContext webBeansContext = WebBeansContext.currentInstance();
+ AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
+
+ while(!in.readObject().equals('~')) // read throw-away '-' or '~' terminal delimiter.
+ {
+ Annotation ann = (Annotation) in.readObject(); // now read the annotation.
+ anns.add(ann);
+ }
+
+ //process annotations
+ ownerBean = webBeansContext.getBeanManagerImpl().getBeans(beanClass, anns.toArray(new Annotation[anns.size()])).iterator().next();
+ qualifierAnnotations = anns;
+
+ // determine type of injection point member (0=field, 1=method, 2=constructor) and read...
+ int c = in.readByte();
+ if(c == 0)
+ {
+ String fieldName = in.readUTF();
+ Field field = webBeansContext.getSecurityService().doPrivilegedGetDeclaredField(beanClass, fieldName);
+
+ injectionMember = field;
+
+ AnnotatedType<?> annotatedType = annotatedElementFactory.newAnnotatedType(beanClass);
+ annotated = annotatedElementFactory.newAnnotatedField(field, annotatedType);
+ injectionType = field.getGenericType();
+
+ }
+ else if(c == 1)
+ {
+ String methodName = in.readUTF();
+ Class<?>[] parameters = (Class<?>[])in.readObject();
+
+ Method method = webBeansContext.getSecurityService().doPrivilegedGetDeclaredMethod(beanClass, methodName, parameters);
+ injectionMember = method;
+
+ AnnotatedType<?> annotatedType = annotatedElementFactory.newAnnotatedType(beanClass);
+ AnnotatedMethod<Object> am = (AnnotatedMethod<Object>)annotatedElementFactory.
+ newAnnotatedMethod((Method) injectionMember,annotatedType);
+ List<AnnotatedParameter<Object>> annParameters = am.getParameters();
+
+ annotated = annParameters.get(in.readByte());
+ injectionType = annotated.getBaseType();
+
+ }
+ else if(c == 2)
+ {
+ Class<?>[] parameters = (Class<?>[])in.readObject();
+ try
+ {
+ injectionMember = beanClass.getConstructor(parameters);
+
+ }
+ catch(NoSuchMethodException e)
+ {
+ injectionMember = null;
+ }
+
+ AnnotatedType<Object> annotatedType = (AnnotatedType<Object>)annotatedElementFactory.newAnnotatedType(beanClass);
+ AnnotatedConstructor<Object> am = annotatedElementFactory
+ .newAnnotatedConstructor((Constructor<Object>) injectionMember,annotatedType);
+ List<AnnotatedParameter<Object>> annParameters = am.getParameters();
+
+ annotated = annParameters.get(in.readByte());
+ injectionType = annotated.getBaseType();
+ }
+
+ delegate = in.readBoolean();
+ transientt = in.readBoolean();
+
+ }
+
+
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ if(injectionMember instanceof Constructor)
+ {
+ Constructor<?> constructor = (Constructor<?>) injectionMember;
+ buffer.append("Constructor Injection Point, constructor name : " + constructor.getName() + ", Bean Owner : ["+ ownerBean.toString() + "]");
+ }
+ else if(injectionMember instanceof Method)
+ {
+ Method method = (Method) injectionMember;
+ buffer.append("Method Injection Point, method name : " + method.getName() + ", Bean Owner : ["+ ownerBean.toString() + "]");
+
+ }
+ else if(injectionMember instanceof Field)
+ {
+ Field field = (Field) injectionMember;
+ buffer.append("Field Injection Point, field name : " + field.getName() + ", Bean Owner : ["+ ownerBean.toString() + "]");
+ }
+
+ return buffer.toString();
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceFactory.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.inject.instance;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Instance;
+
+import org.apache.webbeans.config.WebBeansContext;
+
+public final class InstanceFactory
+{
+ private InstanceFactory()
+ {
+
+ }
+
+ /**
+ *
+ * @param injectedType injection class type
+ * @param injectionPointClass null or the class of the injection point
+ * @param webBeansContext
+ * @param creationalContext will get used for creating @Dependent beans
+ * @param ownerInstance the object the current Instance got injected into
+ * @param annotations qualifier annotations
+ * @return the {@link Instance<T>} for the given type.
+ */
+ public static <T> Instance<T> getInstance(Type injectedType, Class<?> injectionPointClass,
+ WebBeansContext webBeansContext, CreationalContext<?> creationalContext,
+ Object ownerInstance, Annotation... annotations)
+ {
+ InstanceImpl<T> instance = new InstanceImpl<T>(injectedType,injectionPointClass, webBeansContext,
+ creationalContext, ownerInstance, annotations);
+
+ return instance;
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,308 @@
+/*
+ * 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.inject.instance;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.TypeLiteral;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.OwbCustomObjectInputStream;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * Implements the {@link Instance} interface.
+ *
+ * @param <T> specific instance type
+ */
+class InstanceImpl<T> implements Instance<T>, Serializable
+{
+ private static final long serialVersionUID = -8401944412490389024L;
+
+ /** Injected class type */
+ private Type injectionClazz;
+
+ /**
+ * injection point class used to determine the BDA it was loaded from or null.
+ */
+ private Class<?> injectionPointClazz;
+
+ /** Qualifier annotations appeared on the injection point */
+ private Set<Annotation> qualifierAnnotations = new HashSet<Annotation>();
+
+ private WebBeansContext webBeansContext;
+
+ private CreationalContext<?> parentCreationalContext;
+
+ private Object ownerInstance;
+
+ /**
+ * Creates new instance.
+ *
+ * @param injectionClazz injection class type
+ * @param injectionPointClazz null or class of injection point
+ * @param webBeansContext
+ * @param creationalContext will get used for creating @Dependent beans
+ * @param ownerInstance the object the current Instance got injected into
+ * @param annotations qualifier annotations
+ */
+ InstanceImpl(Type injectionClazz, Class<?> injectionPointClazz, WebBeansContext webBeansContext,
+ CreationalContext<?> creationalContext, Object ownerInstance, Annotation... annotations)
+ {
+ this.injectionClazz = injectionClazz;
+ this.injectionPointClazz=injectionPointClazz;
+ this.parentCreationalContext = creationalContext;
+ this.ownerInstance = ownerInstance;
+
+ for (Annotation ann : annotations)
+ {
+ qualifierAnnotations.add(ann);
+ }
+ this.webBeansContext = webBeansContext;
+ }
+
+ /**
+ * Returns the bean instance with given qualifier annotations.
+ *
+ * @return bean instance
+ */
+ @SuppressWarnings("unchecked")
+ public T get()
+ {
+ T instance;
+
+ Annotation[] anns = new Annotation[qualifierAnnotations.size()];
+ anns = qualifierAnnotations.toArray(anns);
+
+ Set<Bean<?>> beans = resolveBeans();
+
+ webBeansContext.getResolutionUtil().checkResolvedBeans(beans, ClassUtil.getClazz(injectionClazz), anns, null);
+ BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
+
+ Bean<?> bean = beanManager.resolve(beans);
+
+ // since Instance<T> is Dependent, we we gonna use the parent CreationalContext by default
+ CreationalContext<?> creationalContext = parentCreationalContext;
+
+ boolean isDependentBean = WebBeansUtil.isDependent(bean);
+
+ if (!isDependentBean)
+ {
+ // but for all NormalScoped beans we will need to create a fresh CreationalContext
+ creationalContext = beanManager.createCreationalContext(bean);
+ }
+
+ instance = (T) beanManager.getReference(bean, null, creationalContext);
+
+ if (isDependentBean && ownerInstance != null && creationalContext instanceof CreationalContextImpl)
+ {
+ ((CreationalContextImpl<?>) creationalContext).addDependent(ownerInstance, bean, instance);
+ }
+
+ return instance;
+ }
+
+ /**
+ * Returns set of resolved beans.
+ *
+ * @return set of resolved beans
+ */
+ private Set<Bean<?>> resolveBeans()
+ {
+ Annotation[] anns = new Annotation[qualifierAnnotations.size()];
+ anns = qualifierAnnotations.toArray(anns);
+
+ InjectionResolver injectionResolver = webBeansContext.getBeanManagerImpl().getInjectionResolver();
+
+ InjectionResolver resolver = injectionResolver;
+ Set<Bean<?>> beans = resolver.implResolveByType(injectionClazz, injectionPointClazz, anns);
+ return beans;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isAmbiguous()
+ {
+ Set<Bean<?>> beans = resolveBeans();
+
+ return beans.size() > 1 ? true : false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isUnsatisfied()
+ {
+ Set<Bean<?>> beans = resolveBeans();
+
+ return beans.size() == 0 ? true : false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Instance<T> select(Annotation... qualifiers)
+ {
+ Annotation[] newQualifiersArray = getAdditionalQualifiers(qualifiers);
+ InstanceImpl<T> newInstance = new InstanceImpl<T>(injectionClazz, injectionPointClazz,
+ webBeansContext, parentCreationalContext,
+ ownerInstance, newQualifiersArray);
+
+ return newInstance;
+ }
+
+ /**
+ * Returns total qualifiers array
+ *
+ * @param qualifiers additional qualifiers
+ * @return total qualifiers array
+ */
+ private Annotation[] getAdditionalQualifiers(Annotation[] qualifiers)
+ {
+ webBeansContext.getAnnotationManager().checkQualifierConditions(qualifiers);
+ Set<Annotation> newQualifiers = new HashSet<Annotation>(qualifierAnnotations);
+
+ if (qualifiers != null && qualifiers.length > 0)
+ {
+ for (Annotation annot : qualifiers)
+ {
+ if (newQualifiers.contains(annot))
+ {
+ throw new IllegalArgumentException("Duplicate Qualifier Exception, " + toString());
+ }
+
+ newQualifiers.add(annot);
+ }
+ }
+
+ Annotation[] newQualifiersArray = new Annotation[newQualifiers.size()];
+ newQualifiersArray = newQualifiers.toArray(newQualifiersArray);
+
+ return newQualifiersArray;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <U extends T> Instance<U> select(Class<U> subtype, Annotation... qualifiers)
+ {
+ webBeansContext.getAnnotationManager().checkQualifierConditions(qualifiers);
+
+ Type sub = subtype;
+
+ if(sub == null)
+ {
+ sub = injectionClazz;
+ }
+
+ Annotation[] newQualifiers = getAdditionalQualifiers(qualifiers);
+
+ InstanceImpl<U> newInstance = new InstanceImpl(sub, injectionPointClazz, webBeansContext,
+ parentCreationalContext, ownerInstance,
+ newQualifiers);
+
+ return newInstance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <U extends T> Instance<U> select(TypeLiteral<U> subtype, Annotation... qualifiers)
+ {
+ return select(subtype.getRawType(), qualifiers);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public Iterator<T> iterator()
+ {
+ Set<Bean<?>> beans = resolveBeans();
+ Set<T> instances = new HashSet<T>();
+ for(Bean<?> bean : beans)
+ {
+ T instance = (T) webBeansContext.getBeanManagerImpl().getReference(bean,null, parentCreationalContext);
+ instances.add(instance);
+ }
+
+ return instances.iterator();
+ }
+
+ private void writeObject(java.io.ObjectOutputStream op) throws IOException
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(op);
+ oos.writeObject(injectionClazz);
+ oos.writeObject(qualifierAnnotations);
+ oos.writeObject(injectionPointClazz);
+
+ oos.flush();
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ webBeansContext = WebBeansContext.currentInstance();
+ final ObjectInputStream inputStream = new OwbCustomObjectInputStream(in, WebBeansUtil.getCurrentClassLoader());
+ injectionClazz = (Type)inputStream.readObject();
+ qualifierAnnotations = (Set<Annotation>)inputStream.readObject();
+ injectionPointClazz = (Class<?>) inputStream.readObject();
+ }
+
+
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Instance<");
+ builder.append(ClassUtil.getClazz(injectionClazz).getName());
+ builder.append("> injectionPointClazz=").append(injectionPointClazz);
+
+ builder.append(",with qualifier annotations {");
+ int i = 0;
+ for (Annotation qualifier : qualifierAnnotations)
+ {
+ if (i != 0)
+ {
+ builder.append(",");
+ }
+
+ builder.append(qualifier.toString());
+ }
+
+ builder.append("}");
+
+ return builder.toString();
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanInterceptorHandler.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.apache.webbeans.component.OwbBean;
+
+
+/**
+ * <p>This is a {@link org.apache.webbeans.proxy.MethodHandler} especially
+ * made for @ApplicationScoped beans.</p>
+ *
+ * <p>Since there is only one single contextual instance of an @ApplicationScoped bean,
+ * we can simply cache this instance inside our bean. We only need to reload this instance
+ * if it is null. This happens at the first usage and after the MethodHandler got deserialized</p>
+ */
+public class ApplicationScopedBeanInterceptorHandler extends NormalScopedBeanInterceptorHandler
+{
+ /**default serial id*/
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Cached bean instance. Please note that it is only allowed to
+ * use this special proxy if you don't use OpenWebBeans in an EAR
+ * scenario. In this case we must not cache @ApplicationScoped
+ * contextual instances because they could be injected into EJBs or other
+ * shared instances which span over multiple web-apps.
+ */
+ private transient Object cachedInstance = null;
+
+ /**
+ * We also cache the CreationalContext of the very bean.
+ */
+ private transient CreationalContext<Object> creationalContext = null;
+
+ /**
+ * Creates a new handler.
+ * @param bean bean
+ * @param creationalContext creaitonal context
+ */
+ public ApplicationScopedBeanInterceptorHandler(OwbBean<?> bean, CreationalContext<?> creationalContext)
+ {
+ super(bean, creationalContext);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Object getContextualInstance()
+ {
+ if (cachedInstance == null)
+ {
+ cachedInstance = super.getContextualInstance();
+ }
+
+ return cachedInstance;
+ }
+
+ @Override
+ protected CreationalContext<Object> getContextualCreationalContext()
+ {
+ if (creationalContext == null)
+ {
+ creationalContext = super.getContextualCreationalContext();
+ }
+
+ return creationalContext;
+ }
+}