You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/01/08 20:41:33 UTC
svn commit: r732803 [3/17] - in
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
./ annotation/ component/ component/ejb/ component/jms/ component/xml/
config/ container/ context/ context/type/ decorator/ decorator/xml/ de...
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Thu Jan 8 11:41:30 2009
@@ -1,18 +1,15 @@
/*
- * 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.
+ * 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.config;
@@ -67,494 +64,479 @@
*/
public final class DefinitionUtil
{
- private DefinitionUtil()
- {
-
- }
-
- public static <T> Class<? extends Annotation> defineDeploymentType(AbstractComponent<T> component, Annotation[] beanAnnotations, String errorMessage)
- {
- boolean found = false;
- for(Annotation annotation : beanAnnotations)
- {
- //Component Type annotation is not null, if Component
- Annotation ct = annotation.annotationType().getAnnotation(DeploymentType.class);
-
- if(ct != null)
- {
- //Already found component type, too many component type ,throw exception
- if(found == true)
- {
- throw new WebBeansConfigurationException(errorMessage);
- }
- else
- {
- component.setType(annotation);//component type
- found = true;
- }
- }
- }
-
- if(!found && (component instanceof ProducerComponentImpl))
- {
- ProducerComponentImpl<?> p = (ProducerComponentImpl<?>) component;
- component.setType(p.getParent().getType());
- }
- else
- {
-
- component.setType(WebBeansUtil.getMaxPrecedenceSteroTypeDeploymentType(component));
- }
-
- return component.getDeploymentType();
- }
-
- /**
- * Configures the web bean api types.
- *
- * @param <T> generic class type
- * @param component configuring web beans component
- * @param clazz bean implementation class
- */
- public static <T> void defineApiTypes(AbstractComponent<T> component, Class<T> clazz)
- {
- ClassUtil.setTypeHierarchy(component.getTypes(), clazz);
- }
-
-
- /**
- * Configures the producer method web bean api types.
- *
- * @param <T> generic class type
- * @param component configuring web beans component
- * @param clazz bean implementation class
- */
- public static <T> void defineProducerMethodApiTypes(AbstractComponent<T> component, Class<T> clazz)
- {
- if(clazz.isPrimitive() || clazz.isArray())
- {
- component.getTypes().add(clazz);
- component.getTypes().add(Object.class);
- }
- else
- {
- ClassUtil.setTypeHierarchy(component.getTypes(), clazz);
- }
- }
-
-
- /**
- * Configure web beans component binding type.
- *
- * @param component configuring web beans component
- * @param annotations annotations
- */
- public static <T> void defineBindingTypes(AbstractComponent<T> component,Annotation[] annotations)
- {
- boolean find = false;
- for(Annotation annotation : annotations)
- {
- Class<? extends Annotation> type = annotation.annotationType();
-
- if(AnnotationUtil.isBindingAnnotation(type))
- {
- Method[] methods =type.getDeclaredMethods();
-
- for(Method method : methods)
- {
- Class<?> clazz = method.getReturnType();
- if(clazz.isArray() || clazz.isAnnotation())
- {
- if(!AnnotationUtil.isAnnotationExist(method.getAnnotations(), NonBinding.class))
- {
- throw new WebBeansConfigurationException("WebBeans definition class : " + component.getReturnType().getName() +
- " @BindingType : " + annotation.annotationType().getName() + " must have @NonBinding valued members for its array-valued and annotation valued members");
- }
- }
- }
-
- if(find == false)
- {
- find = true;
- }
-
- component.addBindingType(annotation);
- }
- }
-
- //No-binding annotation
- if(!find)
- {
- component.addBindingType(new CurrentLiteral());
- }
- }
-
- /**
- * Configure web beans component scope type.
- *
- * @param <T> generic class type
- * @param component configuring web beans component
- * @param annotations annotations
- */
- public static <T> void defineScopeType(AbstractComponent<T> component, Annotation[] annotations,String exceptionMessage)
- {
- boolean found = false;
-
- for(Annotation annotation : annotations)
- {
- Annotation var = annotation.annotationType().getAnnotation(ScopeType.class);
- if(var != null)
- {
- if(found)
- {
- throw new WebBeansConfigurationException(exceptionMessage);
- }
- else
- {
- found = true;
- component.setImplScopeType(annotation);
- }
-
- }
- }
-
- if(!found)
- {
- defineDefaultScopeType(component, exceptionMessage);
- }
- }
-
- public static <T> void defineStereoTypes(Component<?> component, Class<T> clazz)
- {
- Annotation[] anns = clazz.getAnnotations();
-
- if(AnnotationUtil.isStereoTypeMetaAnnotationExist(anns))
- {
- Annotation[] steroAnns = AnnotationUtil.getStereotypeMetaAnnotations(anns);
-
- for(Annotation stereo : steroAnns)
- {
- component.addStereoType(stereo);
- }
- }
- }
-
- public static void defineDefaultScopeType(Component<?> component, String exceptionMessage)
- {
- Set<Annotation> stereos = component.getStereoTypes();
- if(stereos.size() == 0)
- {
- component.setImplScopeType(new DependentScopeLiteral());
- }
- else
- {
- Annotation defined = null;
- Set<Annotation> anns = component.getStereoTypes();
- for(Annotation stero : anns)
- {
- if(AnnotationUtil.isMetaAnnotationExist(stero.annotationType().getAnnotations(), ScopeType.class))
- {
- Annotation next = AnnotationUtil.getMetaAnnotations(stero.annotationType().getAnnotations(), ScopeType.class)[0];
-
- if(defined == null)
- {
- defined = next;
- }
- else
- {
- if(!defined.equals(next))
- {
- throw new WebBeansConfigurationException(exceptionMessage);
- }
- }
- }
- }
-
- if(defined != null)
- {
- component.setImplScopeType(defined);
- }
- else
- {
- component.setImplScopeType(new DependentScopeLiteral());
- }
- }
-
- }
-
- /**
- * Configure web beans component name.
- *
- * @param component configuring web beans component
- * @param defaultName default name of the web bean
- */
- public static <T> void defineName(AbstractComponent<T> component, Annotation[] anns, String defaultName)
- {
- Named nameAnnot = null;
- boolean isDefault = false;
- for(Annotation ann : anns)
- {
- if(ann.annotationType().equals(Named.class))
- {
- nameAnnot = (Named)ann;
- break;
- }
- }
-
- if(nameAnnot == null) //no @Named
- {
- //Check for stereottype
- if(WebBeansUtil.isNamedExistOnStereoTypes(component))
- {
- isDefault = true;
- }
-
- }
- else //yes @Named
- {
- if(nameAnnot.value().equals(""))
- {
- isDefault = true;
- }
- else
- {
- component.setName(nameAnnot.value());
- }
-
- }
-
- if(isDefault)
- {
- component.setName(defaultName);
- }
-
- }
-
- public static Set<ProducerComponentImpl<?>> defineProducerMethods(AbstractComponent<?> component)
- {
- Set<ProducerComponentImpl<?>> producerComponents = new HashSet<ProducerComponentImpl<?>>();
-
- Class<?> clazz = component.getReturnType();
-
- Method[] declaredMethods = clazz.getDeclaredMethods();
- for(Method declaredMethod : declaredMethods)
- {
- //Producer Method
- if(AnnotationUtil.isMethodHasAnnotation(declaredMethod, Produces.class))
- {
- WebBeansUtil.checkProducerMethodForDeployment(declaredMethod, clazz.getName());
-
- if(AnnotationUtil.isMethodHasAnnotation(declaredMethod, Specializes.class))
- {
- if(AnnotationUtil.isMethodHasAnnotation(declaredMethod, Override.class))
- {
- WebBeansUtil.configureProducerSpecialization(component, declaredMethod, clazz.getSuperclass());
- }
- else
- {
- throw new WebBeansConfigurationException("Producer method : " + declaredMethod.getName() + " in class : " + clazz.getName() + " must override its super class method");
- }
- }
-
- Type[] observableTypes = AnnotationUtil.getMethodParameterGenericTypesWithGivenAnnotation(declaredMethod, Fires.class);
- EventUtil.checkObservableMethodParameterConditions(observableTypes, "method parameter","method : " + declaredMethod.getName() + "in class : " + clazz.getName());
-
- ProducerComponentImpl<?> newComponent = createProducerComponent(declaredMethod.getReturnType(), declaredMethod ,component);
- if(newComponent != null)
- {
- producerComponents.add(newComponent);
- }
- }
- }
-
- return producerComponents;
-
- }
-
- private static <T> ProducerComponentImpl<T> createProducerComponent(Class<T> returnType, Method method, AbstractComponent<?> parent)
- {
- ProducerComponentImpl<T> component = new ProducerComponentImpl<T>(parent, returnType);
- component.setCreatorMethod(method);
-
- if(returnType.isPrimitive())
- {
- component.setNullable(false);
- }
-
- defineSerializable(component);
-
- Class<? extends Annotation> deploymentType = DefinitionUtil.defineDeploymentType(component, method.getAnnotations(), "There are more than one @DeploymentType annotation in the component class : " + component.getReturnType().getName());
-
- // Check if the deployment type is enabled.
- if (!DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(deploymentType))
- {
- return null;
- }
-
- Annotation[] methodAnns = method.getAnnotations();
-
- DefinitionUtil.defineProducerMethodApiTypes(component, returnType);
- DefinitionUtil.defineScopeType(component, methodAnns, "WebBeans producer method : " + method.getName() + " in class " + parent.getReturnType().getName() + " must declare default @ScopeType annotation");
- DefinitionUtil.defineBindingTypes(component, methodAnns);
- DefinitionUtil.defineName(component, methodAnns, WebBeansUtil.getProducerDefaultName(method.getName()));
-
- WebBeansUtil.checkSteroTypeRequirements(component, methodAnns , "WebBeans producer method : " + method.getName() + " in class : " + parent.getReturnType().getName());
-
-
- return component;
- }
-
-
- public static <T> void defineDisposalMethods(AbstractComponent<T> component)
- {
- Class<?> clazz = component.getReturnType();
-
- Method[] methods = AnnotationUtil.getMethodsWithParameterAnnotation(clazz, Disposes.class);
-
- ProducerComponentImpl<?> previous = null;
- for(Method declaredMethod : methods)
- {
- WebBeansUtil.checkProducerMethodDisposal(declaredMethod, clazz.getName());
-
- Type type = AnnotationUtil.getMethodFirstParameterWithAnnotation(declaredMethod, Disposes.class);
- Annotation[] annot = AnnotationUtil.getMethodFirstParameterBindingTypesWithGivenAnnotation(declaredMethod, Disposes.class);
-
- Set<Bean<T>> set = InjectionResolver.getInstance().implResolveByType(ClassUtil.getFirstRawType(type), ClassUtil.getActualTypeArguements(type), annot);
- ProducerComponentImpl<?> pr = (ProducerComponentImpl<?>) set.iterator().next();
-
- if(pr == null)
- {
- throw new UnsatisfiedDependencyException("Producer method component of the disposal method : " + declaredMethod.getName() + " in class : " + clazz.getName() + "is not found");
- }
-
- if(previous == null)
- {
- previous = pr;
- }
- else
- {
- //multiple same producer
- if(previous.equals(pr))
- {
- throw new WebBeansConfigurationException("There are multiple disposal method for the producer method : " + pr.getCreatorMethod().getName() + " in class : " + clazz.getName());
- }
- }
-
- pr.setDisposalMethod(declaredMethod);
- }
- }
-
- public static <T> void defineInjectedFields(ComponentImpl<T> component)
- {
- Class<T> clazz = component.getReturnType();
-
- WebBeansUtil.checkObservableFieldsConditions(clazz);
-
- Field[] fields = clazz.getDeclaredFields();
- if(fields.length != 0)
- {
- for(Field field : fields)
- {
- Annotation[] anns = field.getAnnotations();
- Annotation[] as = AnnotationUtil.getBindingAnnotations(anns);
-
- //injected fields must define binding types.
- if(as.length > 0)
- {
- WebBeansUtil.checkForNewBindingForDeployment(field.getGenericType(), clazz, field.getName(),anns);
-
- if(as.length > 0)
- {
- int mod = field.getModifiers();
- if(!Modifier.isStatic(mod) && !Modifier.isFinal(mod))
- {
- component.addInjectedField(field);
- }
- }
- }
-
- }
- }
-
- }
-
- public static <T> void defineInjectedMethods(ComponentImpl<T> component)
- {
- Asserts.assertNotNull(component, "component parameter can not be null");
-
- Class<T> clazz = component.getReturnType();
- Method[] methods = AnnotationUtil.getMethodsWithAnnotation(clazz, Initializer.class);
- if(methods.length != 0)
- {
- for(Method method : methods)
- {
- Annotation[][] anns = method.getParameterAnnotations();
- Type[] type = method.getGenericParameterTypes();
- for(int i=0; i< anns.length; i++)
- {
- Annotation [] a = anns[i];
- Type t = type[i];
- WebBeansUtil.checkForNewBindingForDeployment(t, clazz, method.getName(), a);
- }
-
- if(method.getAnnotation(Produces.class) == null && method.getAnnotation(Destructor.class) == null)
- {
- WebBeansUtil.checkInjectedMethodParameterConditions(method, clazz);
- if(!Modifier.isStatic(method.getModifiers()))
- {
- component.addInjectedMethod(method);
- }
-
- }else
- {
- throw new WebBeansConfigurationException("Initializer method : " + method.getName() + " in class : " + clazz.getName() +
- " can not be annotated with @Produces or @Destructor");
- }
- }
- }
- }
-
- public static void defineSimpleWebBeanInterceptorStack(AbstractComponent<?> component)
- {
- Asserts.assertNotNull(component, "component parameter can no be null");
-
- //@javax.interceptor.Interceptors
- EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
-
- //@javax.webbeans.Interceptor
- WebBeansInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
- }
-
- public static void defineWebBeanDecoratorStack(AbstractComponent<?> component, Object object)
- {
- WebBeansDecoratorConfig.configureDecarotors(component, object);
- }
-
- public static <T> void defineObserverMethods(ObservesMethodsOwner<T> component, Class<T> clazz)
- {
- Asserts.assertNotNull(component, "component parameter can not be null");
- Asserts.nullCheckForClass(clazz);
-
- NotificationManager manager = NotificationManager.getInstance();
-
- Method[] candidateMethods = AnnotationUtil.getMethodsWithParameterAnnotation(clazz, Observes.class);
-
- for(Method candidateMethod : candidateMethods)
- {
- EventUtil.checkObserverMethodConditions(candidateMethod, clazz);
- component.addObservableMethod(candidateMethod);
- }
-
- manager.addObservableComponentMethods(component);
-
- }
-
- public static <T> void defineSerializable(AbstractComponent<T> component)
- {
- Asserts.assertNotNull(component, "component parameter can not be null");
- if(ClassUtil.isAssignable(Serializable.class, component.getReturnType()))
- {
- component.setSerializable(true);
- }
- }
+ private DefinitionUtil()
+ {
+
+ }
+
+ public static <T> Class<? extends Annotation> defineDeploymentType(AbstractComponent<T> component, Annotation[] beanAnnotations, String errorMessage)
+ {
+ boolean found = false;
+ for (Annotation annotation : beanAnnotations)
+ {
+ // Component Type annotation is not null, if Component
+ Annotation ct = annotation.annotationType().getAnnotation(DeploymentType.class);
+
+ if (ct != null)
+ {
+ // Already found component type, too many component type ,throw
+ // exception
+ if (found == true)
+ {
+ throw new WebBeansConfigurationException(errorMessage);
+ } else
+ {
+ component.setType(annotation);// component type
+ found = true;
+ }
+ }
+ }
+
+ if (!found && (component instanceof ProducerComponentImpl))
+ {
+ ProducerComponentImpl<?> p = (ProducerComponentImpl<?>) component;
+ component.setType(p.getParent().getType());
+ } else
+ {
+
+ component.setType(WebBeansUtil.getMaxPrecedenceSteroTypeDeploymentType(component));
+ }
+
+ return component.getDeploymentType();
+ }
+
+ /**
+ * Configures the web bean api types.
+ *
+ * @param <T> generic class type
+ * @param component configuring web beans component
+ * @param clazz bean implementation class
+ */
+ public static <T> void defineApiTypes(AbstractComponent<T> component, Class<T> clazz)
+ {
+ ClassUtil.setTypeHierarchy(component.getTypes(), clazz);
+ }
+
+ /**
+ * Configures the producer method web bean api types.
+ *
+ * @param <T> generic class type
+ * @param component configuring web beans component
+ * @param clazz bean implementation class
+ */
+ public static <T> void defineProducerMethodApiTypes(AbstractComponent<T> component, Class<T> clazz)
+ {
+ if (clazz.isPrimitive() || clazz.isArray())
+ {
+ component.getTypes().add(clazz);
+ component.getTypes().add(Object.class);
+ } else
+ {
+ ClassUtil.setTypeHierarchy(component.getTypes(), clazz);
+ }
+ }
+
+ /**
+ * Configure web beans component binding type.
+ *
+ * @param component configuring web beans component
+ * @param annotations annotations
+ */
+ public static <T> void defineBindingTypes(AbstractComponent<T> component, Annotation[] annotations)
+ {
+ boolean find = false;
+ for (Annotation annotation : annotations)
+ {
+ Class<? extends Annotation> type = annotation.annotationType();
+
+ if (AnnotationUtil.isBindingAnnotation(type))
+ {
+ Method[] methods = type.getDeclaredMethods();
+
+ for (Method method : methods)
+ {
+ Class<?> clazz = method.getReturnType();
+ if (clazz.isArray() || clazz.isAnnotation())
+ {
+ if (!AnnotationUtil.isAnnotationExist(method.getAnnotations(), NonBinding.class))
+ {
+ throw new WebBeansConfigurationException("WebBeans definition class : " + component.getReturnType().getName() + " @BindingType : " + annotation.annotationType().getName() + " must have @NonBinding valued members for its array-valued and annotation valued members");
+ }
+ }
+ }
+
+ if (find == false)
+ {
+ find = true;
+ }
+
+ component.addBindingType(annotation);
+ }
+ }
+
+ // No-binding annotation
+ if (!find)
+ {
+ component.addBindingType(new CurrentLiteral());
+ }
+ }
+
+ /**
+ * Configure web beans component scope type.
+ *
+ * @param <T> generic class type
+ * @param component configuring web beans component
+ * @param annotations annotations
+ */
+ public static <T> void defineScopeType(AbstractComponent<T> component, Annotation[] annotations, String exceptionMessage)
+ {
+ boolean found = false;
+
+ for (Annotation annotation : annotations)
+ {
+ Annotation var = annotation.annotationType().getAnnotation(ScopeType.class);
+ if (var != null)
+ {
+ if (found)
+ {
+ throw new WebBeansConfigurationException(exceptionMessage);
+ } else
+ {
+ found = true;
+ component.setImplScopeType(annotation);
+ }
+
+ }
+ }
+
+ if (!found)
+ {
+ defineDefaultScopeType(component, exceptionMessage);
+ }
+ }
+
+ public static <T> void defineStereoTypes(Component<?> component, Class<T> clazz)
+ {
+ Annotation[] anns = clazz.getAnnotations();
+
+ if (AnnotationUtil.isStereoTypeMetaAnnotationExist(anns))
+ {
+ Annotation[] steroAnns = AnnotationUtil.getStereotypeMetaAnnotations(anns);
+
+ for (Annotation stereo : steroAnns)
+ {
+ component.addStereoType(stereo);
+ }
+ }
+ }
+
+ public static void defineDefaultScopeType(Component<?> component, String exceptionMessage)
+ {
+ Set<Annotation> stereos = component.getStereoTypes();
+ if (stereos.size() == 0)
+ {
+ component.setImplScopeType(new DependentScopeLiteral());
+ } else
+ {
+ Annotation defined = null;
+ Set<Annotation> anns = component.getStereoTypes();
+ for (Annotation stero : anns)
+ {
+ if (AnnotationUtil.isMetaAnnotationExist(stero.annotationType().getAnnotations(), ScopeType.class))
+ {
+ Annotation next = AnnotationUtil.getMetaAnnotations(stero.annotationType().getAnnotations(), ScopeType.class)[0];
+
+ if (defined == null)
+ {
+ defined = next;
+ } else
+ {
+ if (!defined.equals(next))
+ {
+ throw new WebBeansConfigurationException(exceptionMessage);
+ }
+ }
+ }
+ }
+
+ if (defined != null)
+ {
+ component.setImplScopeType(defined);
+ } else
+ {
+ component.setImplScopeType(new DependentScopeLiteral());
+ }
+ }
+
+ }
+
+ /**
+ * Configure web beans component name.
+ *
+ * @param component configuring web beans component
+ * @param defaultName default name of the web bean
+ */
+ public static <T> void defineName(AbstractComponent<T> component, Annotation[] anns, String defaultName)
+ {
+ Named nameAnnot = null;
+ boolean isDefault = false;
+ for (Annotation ann : anns)
+ {
+ if (ann.annotationType().equals(Named.class))
+ {
+ nameAnnot = (Named) ann;
+ break;
+ }
+ }
+
+ if (nameAnnot == null) // no @Named
+ {
+ // Check for stereottype
+ if (WebBeansUtil.isNamedExistOnStereoTypes(component))
+ {
+ isDefault = true;
+ }
+
+ } else
+ // yes @Named
+ {
+ if (nameAnnot.value().equals(""))
+ {
+ isDefault = true;
+ } else
+ {
+ component.setName(nameAnnot.value());
+ }
+
+ }
+
+ if (isDefault)
+ {
+ component.setName(defaultName);
+ }
+
+ }
+
+ public static Set<ProducerComponentImpl<?>> defineProducerMethods(AbstractComponent<?> component)
+ {
+ Set<ProducerComponentImpl<?>> producerComponents = new HashSet<ProducerComponentImpl<?>>();
+
+ Class<?> clazz = component.getReturnType();
+
+ Method[] declaredMethods = clazz.getDeclaredMethods();
+ for (Method declaredMethod : declaredMethods)
+ {
+ // Producer Method
+ if (AnnotationUtil.isMethodHasAnnotation(declaredMethod, Produces.class))
+ {
+ WebBeansUtil.checkProducerMethodForDeployment(declaredMethod, clazz.getName());
+
+ if (AnnotationUtil.isMethodHasAnnotation(declaredMethod, Specializes.class))
+ {
+ if (AnnotationUtil.isMethodHasAnnotation(declaredMethod, Override.class))
+ {
+ WebBeansUtil.configureProducerSpecialization(component, declaredMethod, clazz.getSuperclass());
+ } else
+ {
+ throw new WebBeansConfigurationException("Producer method : " + declaredMethod.getName() + " in class : " + clazz.getName() + " must override its super class method");
+ }
+ }
+
+ Type[] observableTypes = AnnotationUtil.getMethodParameterGenericTypesWithGivenAnnotation(declaredMethod, Fires.class);
+ EventUtil.checkObservableMethodParameterConditions(observableTypes, "method parameter", "method : " + declaredMethod.getName() + "in class : " + clazz.getName());
+
+ ProducerComponentImpl<?> newComponent = createProducerComponent(declaredMethod.getReturnType(), declaredMethod, component);
+ if (newComponent != null)
+ {
+ producerComponents.add(newComponent);
+ }
+ }
+ }
+
+ return producerComponents;
+
+ }
+
+ private static <T> ProducerComponentImpl<T> createProducerComponent(Class<T> returnType, Method method, AbstractComponent<?> parent)
+ {
+ ProducerComponentImpl<T> component = new ProducerComponentImpl<T>(parent, returnType);
+ component.setCreatorMethod(method);
+
+ if (returnType.isPrimitive())
+ {
+ component.setNullable(false);
+ }
+
+ defineSerializable(component);
+
+ Class<? extends Annotation> deploymentType = DefinitionUtil.defineDeploymentType(component, method.getAnnotations(), "There are more than one @DeploymentType annotation in the component class : " + component.getReturnType().getName());
+
+ // Check if the deployment type is enabled.
+ if (!DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(deploymentType))
+ {
+ return null;
+ }
+
+ Annotation[] methodAnns = method.getAnnotations();
+
+ DefinitionUtil.defineProducerMethodApiTypes(component, returnType);
+ DefinitionUtil.defineScopeType(component, methodAnns, "WebBeans producer method : " + method.getName() + " in class " + parent.getReturnType().getName() + " must declare default @ScopeType annotation");
+ DefinitionUtil.defineBindingTypes(component, methodAnns);
+ DefinitionUtil.defineName(component, methodAnns, WebBeansUtil.getProducerDefaultName(method.getName()));
+
+ WebBeansUtil.checkSteroTypeRequirements(component, methodAnns, "WebBeans producer method : " + method.getName() + " in class : " + parent.getReturnType().getName());
+
+ return component;
+ }
+
+ public static <T> void defineDisposalMethods(AbstractComponent<T> component)
+ {
+ Class<?> clazz = component.getReturnType();
+
+ Method[] methods = AnnotationUtil.getMethodsWithParameterAnnotation(clazz, Disposes.class);
+
+ ProducerComponentImpl<?> previous = null;
+ for (Method declaredMethod : methods)
+ {
+ WebBeansUtil.checkProducerMethodDisposal(declaredMethod, clazz.getName());
+
+ Type type = AnnotationUtil.getMethodFirstParameterWithAnnotation(declaredMethod, Disposes.class);
+ Annotation[] annot = AnnotationUtil.getMethodFirstParameterBindingTypesWithGivenAnnotation(declaredMethod, Disposes.class);
+
+ Set<Bean<T>> set = InjectionResolver.getInstance().implResolveByType(ClassUtil.getFirstRawType(type), ClassUtil.getActualTypeArguements(type), annot);
+ ProducerComponentImpl<?> pr = (ProducerComponentImpl<?>) set.iterator().next();
+
+ if (pr == null)
+ {
+ throw new UnsatisfiedDependencyException("Producer method component of the disposal method : " + declaredMethod.getName() + " in class : " + clazz.getName() + "is not found");
+ }
+
+ if (previous == null)
+ {
+ previous = pr;
+ } else
+ {
+ // multiple same producer
+ if (previous.equals(pr))
+ {
+ throw new WebBeansConfigurationException("There are multiple disposal method for the producer method : " + pr.getCreatorMethod().getName() + " in class : " + clazz.getName());
+ }
+ }
+
+ pr.setDisposalMethod(declaredMethod);
+ }
+ }
+
+ public static <T> void defineInjectedFields(ComponentImpl<T> component)
+ {
+ Class<T> clazz = component.getReturnType();
+
+ WebBeansUtil.checkObservableFieldsConditions(clazz);
+
+ Field[] fields = clazz.getDeclaredFields();
+ if (fields.length != 0)
+ {
+ for (Field field : fields)
+ {
+ Annotation[] anns = field.getAnnotations();
+ Annotation[] as = AnnotationUtil.getBindingAnnotations(anns);
+
+ // injected fields must define binding types.
+ if (as.length > 0)
+ {
+ WebBeansUtil.checkForNewBindingForDeployment(field.getGenericType(), clazz, field.getName(), anns);
+
+ if (as.length > 0)
+ {
+ int mod = field.getModifiers();
+ if (!Modifier.isStatic(mod) && !Modifier.isFinal(mod))
+ {
+ component.addInjectedField(field);
+ }
+ }
+ }
+
+ }
+ }
+
+ }
+
+ public static <T> void defineInjectedMethods(ComponentImpl<T> component)
+ {
+ Asserts.assertNotNull(component, "component parameter can not be null");
+
+ Class<T> clazz = component.getReturnType();
+ Method[] methods = AnnotationUtil.getMethodsWithAnnotation(clazz, Initializer.class);
+ if (methods.length != 0)
+ {
+ for (Method method : methods)
+ {
+ Annotation[][] anns = method.getParameterAnnotations();
+ Type[] type = method.getGenericParameterTypes();
+ for (int i = 0; i < anns.length; i++)
+ {
+ Annotation[] a = anns[i];
+ Type t = type[i];
+ WebBeansUtil.checkForNewBindingForDeployment(t, clazz, method.getName(), a);
+ }
+
+ if (method.getAnnotation(Produces.class) == null && method.getAnnotation(Destructor.class) == null)
+ {
+ WebBeansUtil.checkInjectedMethodParameterConditions(method, clazz);
+ if (!Modifier.isStatic(method.getModifiers()))
+ {
+ component.addInjectedMethod(method);
+ }
+
+ } else
+ {
+ throw new WebBeansConfigurationException("Initializer method : " + method.getName() + " in class : " + clazz.getName() + " can not be annotated with @Produces or @Destructor");
+ }
+ }
+ }
+ }
+
+ public static void defineSimpleWebBeanInterceptorStack(AbstractComponent<?> component)
+ {
+ Asserts.assertNotNull(component, "component parameter can no be null");
+
+ // @javax.interceptor.Interceptors
+ EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
+
+ // @javax.webbeans.Interceptor
+ WebBeansInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
+ }
+
+ public static void defineWebBeanDecoratorStack(AbstractComponent<?> component, Object object)
+ {
+ WebBeansDecoratorConfig.configureDecarotors(component, object);
+ }
+
+ public static <T> void defineObserverMethods(ObservesMethodsOwner<T> component, Class<T> clazz)
+ {
+ Asserts.assertNotNull(component, "component parameter can not be null");
+ Asserts.nullCheckForClass(clazz);
+
+ NotificationManager manager = NotificationManager.getInstance();
+
+ Method[] candidateMethods = AnnotationUtil.getMethodsWithParameterAnnotation(clazz, Observes.class);
+
+ for (Method candidateMethod : candidateMethods)
+ {
+ EventUtil.checkObserverMethodConditions(candidateMethod, clazz);
+ component.addObservableMethod(candidateMethod);
+ }
+
+ manager.addObservableComponentMethods(component);
+
+ }
+
+ public static <T> void defineSerializable(AbstractComponent<T> component)
+ {
+ Asserts.assertNotNull(component, "component parameter can not be null");
+ if (ClassUtil.isAssignable(Serializable.class, component.getReturnType()))
+ {
+ component.setSerializable(true);
+ }
+ }
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/EJBWebBeansConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/EJBWebBeansConfigurator.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/EJBWebBeansConfigurator.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/EJBWebBeansConfigurator.java Thu Jan 8 11:41:30 2009
@@ -1,18 +1,15 @@
/*
- * 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.
+ * 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.config;
@@ -20,16 +17,15 @@
public final class EJBWebBeansConfigurator
{
- private EJBWebBeansConfigurator()
- {
-
- }
-
- public static boolean isEJBWebBean(Class<?> clazz) throws WebBeansConfigurationException
- {
- return false;
-
- }
-
+ private EJBWebBeansConfigurator()
+ {
+
+ }
+
+ public static boolean isEJBWebBean(Class<?> clazz) throws WebBeansConfigurationException
+ {
+ return false;
+
+ }
}
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/SimpleWebBeansConfigurator.java Thu Jan 8 11:41:30 2009
@@ -1,18 +1,15 @@
/*
- * 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.
+ * 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.config;
@@ -23,7 +20,6 @@
import javax.webbeans.Interceptor;
import javax.webbeans.ScopeType;
-
import org.apache.webbeans.component.ComponentImpl;
import org.apache.webbeans.component.ProducerComponentImpl;
import org.apache.webbeans.component.WebBeansType;
@@ -37,115 +33,116 @@
/**
* Configures the simple web beans.
- *
* <p>
* Contains useful static methods for creating simple web beans.
* </p>
+ *
* @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
* @since 1.0
*/
public final class SimpleWebBeansConfigurator
{
- /**
- * Private constructor.
- */
- private SimpleWebBeansConfigurator()
- {
-
- }
-
- /**
- * Checks the implementation class for checking conditions.
- *
- * @param clazz implementation class
- * @throws WebBeansConfigurationException if any configuration exception occurs
- */
- public static void checkSimpleWebBeanCondition(Class<?> clazz) throws WebBeansConfigurationException
- {
- int modifier = clazz.getModifiers();
-
- if (AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class) && AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class))
- throw new WebBeansConfigurationException("WebBeans component implementation class : " + clazz.getName() + " can not annotated with both @Interceptor and @Decorator annotations");
-
- if(!AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class) && !AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class))
- InterceptorUtil.checkSimpleWebBeansInterceptorConditions(clazz);
-
- if (ClassUtil.isInterface(modifier))
- throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be interface");
-
- if (ClassUtil.isFinal(modifier) && (!AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class)
- || !AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class)))
- throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be final if not annotated with @Decorator or @Interceptor");
-
- }
-
- /**
- * Returns true if this class can be candidate for simple web bean,
- * false otherwise.
- *
- * @param clazz implementation class
- * @return true if this class can be candidate for simple web bean
- * @throws WebBeansConfigurationException if any configuration exception occurs
- */
- public static boolean isSimpleWebBean(Class<?> clazz) throws WebBeansConfigurationException
- {
- try
- {
- WebBeansUtil.isSimpleWebBeanClass(clazz);
-
- }catch(WebBeansConfigurationException e)
- {
- return false;
- }
-
- return true;
- }
-
-
- /**
- * Returns the newly created simlple web bean component.
- *
- * @param clazz simple web bean implementation class
- * @return the newly simple web bean component
- * @throws WebBeansConfigurationException if any configuration exception occurs
- */
- public static <T> ComponentImpl<T> define(Class<T> clazz, WebBeansType type) throws WebBeansConfigurationException
- {
- checkSimpleWebBeanCondition(clazz);
-
- ComponentImpl<T> component = new ComponentImpl<T>(clazz, type);
-
- DefinitionUtil.defineSerializable(component);
-
- Class<? extends Annotation> deploymentType = DefinitionUtil.defineDeploymentType(component, clazz.getAnnotations(), "There are more than one @DeploymentType annotation in the component class : " + component.getReturnType().getName());
-
- // Check if the deployment type is enabled.
- if (!DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(deploymentType))
- {
- return null;
- }
-
- Annotation[] clazzAnns = clazz.getAnnotations();
-
- DefinitionUtil.defineStereoTypes(component,clazz);
- DefinitionUtil.defineApiTypes(component, clazz);
- DefinitionUtil.defineScopeType(component, clazzAnns, "WebBeans component implementation class : " + clazz.getName() + " must declare default @ScopeType annotation");
- WebBeansUtil.checkPassivationScope(component, component.getScopeType().getAnnotation(ScopeType.class));
- DefinitionUtil.defineBindingTypes(component, clazzAnns);
- DefinitionUtil.defineName(component, clazzAnns, WebBeansUtil.getSimpleWebBeanDefaultName(clazz.getSimpleName()));
-
- component.setConstructor(WebBeansUtil.defineConstructor(clazz));
-
- WebBeansUtil.checkSteroTypeRequirements(component, clazz.getAnnotations(),"WebBeans component class : " + clazz.getName() );
-
- Set<ProducerComponentImpl<?>> producerComponents = DefinitionUtil.defineProducerMethods(component);
- ManagerImpl.getManager().getBeans().addAll(producerComponents);
-
- DefinitionUtil.defineDisposalMethods(component);
- DefinitionUtil.defineInjectedFields(component);
- DefinitionUtil.defineInjectedMethods(component);
- DefinitionUtil.defineObserverMethods(component, clazz);
-
- return component;
- }
+ /**
+ * Private constructor.
+ */
+ private SimpleWebBeansConfigurator()
+ {
+
+ }
+
+ /**
+ * Checks the implementation class for checking conditions.
+ *
+ * @param clazz implementation class
+ * @throws WebBeansConfigurationException if any configuration exception
+ * occurs
+ */
+ public static void checkSimpleWebBeanCondition(Class<?> clazz) throws WebBeansConfigurationException
+ {
+ int modifier = clazz.getModifiers();
+
+ if (AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class) && AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class))
+ throw new WebBeansConfigurationException("WebBeans component implementation class : " + clazz.getName() + " can not annotated with both @Interceptor and @Decorator annotations");
+
+ if (!AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class) && !AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class))
+ InterceptorUtil.checkSimpleWebBeansInterceptorConditions(clazz);
+
+ if (ClassUtil.isInterface(modifier))
+ throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be interface");
+
+ if (ClassUtil.isFinal(modifier) && (!AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class) || !AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class)))
+ throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be final if not annotated with @Decorator or @Interceptor");
+
+ }
+
+ /**
+ * Returns true if this class can be candidate for simple web bean, false
+ * otherwise.
+ *
+ * @param clazz implementation class
+ * @return true if this class can be candidate for simple web bean
+ * @throws WebBeansConfigurationException if any configuration exception
+ * occurs
+ */
+ public static boolean isSimpleWebBean(Class<?> clazz) throws WebBeansConfigurationException
+ {
+ try
+ {
+ WebBeansUtil.isSimpleWebBeanClass(clazz);
+
+ } catch (WebBeansConfigurationException e)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns the newly created simlple web bean component.
+ *
+ * @param clazz simple web bean implementation class
+ * @return the newly simple web bean component
+ * @throws WebBeansConfigurationException if any configuration exception
+ * occurs
+ */
+ public static <T> ComponentImpl<T> define(Class<T> clazz, WebBeansType type) throws WebBeansConfigurationException
+ {
+ checkSimpleWebBeanCondition(clazz);
+
+ ComponentImpl<T> component = new ComponentImpl<T>(clazz, type);
+
+ DefinitionUtil.defineSerializable(component);
+
+ Class<? extends Annotation> deploymentType = DefinitionUtil.defineDeploymentType(component, clazz.getAnnotations(), "There are more than one @DeploymentType annotation in the component class : " + component.getReturnType().getName());
+
+ // Check if the deployment type is enabled.
+ if (!DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(deploymentType))
+ {
+ return null;
+ }
+
+ Annotation[] clazzAnns = clazz.getAnnotations();
+
+ DefinitionUtil.defineStereoTypes(component, clazz);
+ DefinitionUtil.defineApiTypes(component, clazz);
+ DefinitionUtil.defineScopeType(component, clazzAnns, "WebBeans component implementation class : " + clazz.getName() + " must declare default @ScopeType annotation");
+ WebBeansUtil.checkPassivationScope(component, component.getScopeType().getAnnotation(ScopeType.class));
+ DefinitionUtil.defineBindingTypes(component, clazzAnns);
+ DefinitionUtil.defineName(component, clazzAnns, WebBeansUtil.getSimpleWebBeanDefaultName(clazz.getSimpleName()));
+
+ component.setConstructor(WebBeansUtil.defineConstructor(clazz));
+
+ WebBeansUtil.checkSteroTypeRequirements(component, clazz.getAnnotations(), "WebBeans component class : " + clazz.getName());
+
+ Set<ProducerComponentImpl<?>> producerComponents = DefinitionUtil.defineProducerMethods(component);
+ ManagerImpl.getManager().getBeans().addAll(producerComponents);
+
+ DefinitionUtil.defineDisposalMethods(component);
+ DefinitionUtil.defineInjectedFields(component);
+ DefinitionUtil.defineInjectedMethods(component);
+ DefinitionUtil.defineObserverMethods(component, clazz);
+
+ return component;
+ }
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java Thu Jan 8 11:41:30 2009
@@ -1,18 +1,15 @@
/*
- * 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.
+ * 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.config;
@@ -23,8 +20,6 @@
import java.util.Map;
import java.util.Set;
-
-
import javax.webbeans.Decorator;
import javax.webbeans.InconsistentSpecializationException;
import javax.webbeans.Interceptor;
@@ -51,9 +46,8 @@
import org.apache.webbeans.xml.XMLAnnotationTypeManager;
import org.apache.webbeans.xml.XMLSpecializesManager;
-
/**
- * Deploys the all components that are defined in the {@link WebBeansScanner} at
+ * Deploys the all components that are defined in the {@link WebBeansScanner} at
* the scanner phase.
*
* @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
@@ -62,326 +56,317 @@
@SuppressWarnings("unchecked")
public final class WebBeansContainerDeployer
{
- private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansContainerDeployer.class);
-
- private boolean deployed = false;
-
- private WebBeansXMLConfigurator xmlConfigurator = null;
-
- public WebBeansContainerDeployer(WebBeansXMLConfigurator xmlConfigurator)
- {
- this.xmlConfigurator = xmlConfigurator;
- }
-
- /**
- * Deploys all the defined web beans components in the container startup.
- * <p>
- * It deploys from the web-beans.xml files and from the class files. It uses the
- * {@link WebBeansScanner} class to get classes.
- * </p>
- * @throws WebBeansDeploymentException if any deployment exception occurs
- */
- public void deploy(WebBeansScanner scanner) throws WebBeansDeploymentException
- {
- try
- {
- if(!deployed)
- {
- //Register Manager built-in component
- ManagerImpl.getManager().addBean(WebBeansUtil.getManagerComponent());
-
- //Register Conversation built-in component
- ManagerImpl.getManager().addBean(WebBeansUtil.getConversationComponent());
-
- //JNDI bind
- JNDIUtil.bind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME, ManagerImpl.getManager());
-
-
-
- deployFromXML(scanner);
- checkStereoTypes(scanner);
- configureInterceptors(scanner);
- configureDecorators(scanner);
- deployFromClassPath(scanner);
- checkSpecializations(scanner);
-
- deployed = true;
- }
-
- }catch(Throwable e)
- {
- throw new WebBeansDeploymentException(e);
- }
- finally
- {
- Manager manager = ManagerImpl.getManager();
- manager.fireEvent(manager, new Annotation[]{new InitializedManagerLiteral()});
- }
- }
-
- private void deployFromClassPath(WebBeansScanner scanner) throws ClassNotFoundException
- {
- logger.info("Deploying configurations from class files is started");
-
- //Start from the class
- Map<String, Set<String>> classIndex = scanner.getANNOTATION_DB().getClassIndex();
- if(classIndex != null)
- {
- Set<String> pathClasses = classIndex.keySet();
- Iterator<String> itPathClasses = pathClasses.iterator();
-
- while(itPathClasses.hasNext())
- {
- String componentClassName = itPathClasses.next();
- Class<?> implClass = ClassUtil.getClassFromName(componentClassName);
-
- if(SimpleWebBeansConfigurator.isSimpleWebBean(implClass))
- {
- logger.info("Simple WebBeans Component with class name : " + componentClassName + " is found");
- defineSimpleWebBeans(implClass);
- }
- else if(EJBWebBeansConfigurator.isEJBWebBean(implClass))
- {
- logger.info("Enterprise WebBeans Component with class name : " + componentClassName + " is found");
- defineEnterpriseWebBeans();
- }
- }
- }
-
- logger.info("Deploying configurations from class files is ended");
-
- }
-
- private void deployFromXML(WebBeansScanner scanner)
- {
- logger.info("Deploying configurations from XML files is started");
-
- Map<String, InputStream> xmls = scanner.getWEBBEANS_XML_LOCATIONS();
- Set<String> keySet = xmls.keySet();
- Iterator<String> it = keySet.iterator();
-
- while(it.hasNext())
- {
- String fileName = it.next();
- this.xmlConfigurator.configure(xmls.get(fileName), fileName);
- }
-
- logger.info("Deploying configurations from XML is ended succesfully");
- }
-
- private void configureInterceptors(WebBeansScanner scanner) throws ClassNotFoundException
- {
- logger.info("Configuring the Interceptors is started");
-
- //Interceptors Set
- Map<String, Set<String>> annotIndex = scanner.getANNOTATION_DB().getAnnotationIndex();
- Set<String> classes = annotIndex.get(Interceptor.class.getName());
-
- if(classes != null)
- {
- for(String interceptorClazz : classes)
- {
- Class<?> implClass = ClassUtil.getClassFromName(interceptorClazz);
-
- logger.info("Simple WebBeans Interceptor Component with class name : " + interceptorClazz + " is found");
-
- defineSimpleWebBeansInterceptors(implClass);
- }
- }
-
- logger.info("Configuring the Interceptors is ended");
-
- }
-
- private void configureDecorators(WebBeansScanner scanner) throws ClassNotFoundException
- {
- logger.info("Configuring the Decorators is started");
-
- Map<String, Set<String>> annotIndex = scanner.getANNOTATION_DB().getAnnotationIndex();
- Set<String> classes = annotIndex.get(Decorator.class.getName());
-
- if(classes != null)
- {
- for(String decoratorClazz : classes)
- {
- Class<?> implClass = ClassUtil.getClassFromName(decoratorClazz);
- logger.info("Simple WebBeans Decorator Component with class name : " + decoratorClazz + " is found");
-
- defineSimpleWebBeansDecorators(implClass);
- }
- }
-
- logger.info("Configuring the Decorators is ended");
-
- }
-
- private void checkSpecializations(WebBeansScanner scanner)
- {
- logger.info("Checking Specialization constraints is started");
-
- Map<String, Set<String>> specialMap = scanner.getANNOTATION_DB().getAnnotationIndex();
- if(specialMap != null && specialMap.size() > 0)
- {
- if(specialMap.containsKey(Specializes.class.getName()))
- {
- Set<String> specialClassSet = specialMap.get(Specializes.class.getName());
- Iterator<String> specialIterator = specialClassSet.iterator();
-
- Class<?> superClass = null;
- while(specialIterator.hasNext())
- {
- String specialClassName = specialIterator.next();
- Class<?> specialClass = ClassUtil.getClassFromName(specialClassName);
-
- if(superClass == null)
- {
- superClass = specialClass.getSuperclass();
- }
- else
- {
- if(superClass.equals(specialClass.getSuperclass()))
- {
- throw new InconsistentSpecializationException("More than one class that specialized the same super class : " + superClass.getName());
- }
- }
-
- WebBeansUtil.configureSpecializations(specialClass);
- }
- }
- }
-
- //XML Defined Specializations
- checkXMLSpecializations();
-
- logger.info("Checking Specialization constraints is ended");
- }
-
- private void checkXMLSpecializations()
- {
- //Check XML specializations
- Set<Class<?>> clazzes = XMLSpecializesManager.getInstance().getXMLSpecializationClasses();
- Iterator<Class<?>> it = clazzes.iterator();
- Class<?> superClass = null;
- Class<?> specialClass = null;
- while(it.hasNext())
- {
- specialClass = it.next();
-
- if(superClass == null)
- {
- superClass = specialClass.getSuperclass();
- }
- else
- {
- if(superClass.equals(specialClass.getSuperclass()))
- {
- throw new InconsistentSpecializationException("XML Specialization Error : More than one class that specialized the same super class : " + superClass.getName());
- }
- }
-
- WebBeansUtil.configureSpecializations(specialClass);
-
- }
- }
-
- public void checkPassivationScopes()
- {
- Set<Bean<?>> beans = ManagerImpl.getManager().getBeans();
-
- if(beans != null && beans.size() > 0)
- {
- Iterator<Bean<?>> itBeans = beans.iterator();
- while(itBeans.hasNext())
- {
- Object beanObj = itBeans.next();
- if(beanObj instanceof ComponentImpl)
- {
- ComponentImpl<?> component = (ComponentImpl<?>)beanObj;
- ScopeType scope = component.getScopeType().getAnnotation(ScopeType.class);
- if(scope.passivating())
- {
- //Check constructor
-
- //Check non-transient fields
-
- //Check initializer methods
-
- //Check producer methods
- }
- }
- }
- }
- }
-
- public void checkStereoTypes(WebBeansScanner scanner)
- {
- logger.info("Checking StereoTypes constraints is started");
-
- Map<String, Set<String>> stereotypeMap = scanner.getANNOTATION_DB().getAnnotationIndex();
- if(stereotypeMap != null && stereotypeMap.size() > 0)
- {
- Set<String> stereoClassSet = stereotypeMap.keySet();
- Iterator<String> steIterator = stereoClassSet.iterator();
- while(steIterator.hasNext())
- {
- String steroClassName = steIterator.next();
-
- Class<? extends Annotation> stereoClass = (Class<? extends Annotation>)ClassUtil.getClassFromName(steroClassName);
-
- if(AnnotationUtil.isStereoTypeAnnotation(stereoClass))
- {
- if(!XMLAnnotationTypeManager.getInstance().isStereoTypeExist(stereoClass))
- {
- WebBeansUtil.checkStereoTypeClass(stereoClass);
- StereoTypeModel model = new StereoTypeModel(stereoClass);
- StereoTypeManager.getInstance().addStereoTypeModel(model);
- }
- }
- }
- }
-
- logger.info("Checking StereoTypes constraints is ended");
- }
-
-
- private <T> void defineSimpleWebBeans(Class<T> clazz)
- {
- ComponentImpl<T> component = null;
-
- if(!AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class)
- && !AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class))
- {
- component = SimpleWebBeansConfigurator.define(clazz, WebBeansType.SIMPLE);
- if(component != null)
- {
- DecoratorUtil.checkSimpleWebBeanDecoratorConditions(component);
-
- /*I have added this into the ComponentImpl.afterCreate();*/
- //DefinitionUtil.defineSimpleWebBeanInterceptorStack(component);
-
- ManagerImpl.getManager().addBean(component);
- }
- }
- }
-
- /**
- * Defines the new interceptor with given class.
- *
- * @param clazz interceptor class
- */
- private <T> void defineSimpleWebBeansInterceptors(Class<T> clazz)
- {
- WebBeansUtil.defineSimpleWebBeansInterceptors(clazz);
- }
-
- private <T> void defineSimpleWebBeansDecorators(Class<T> clazz)
- {
- WebBeansUtil.defineSimpleWebBeansDecorators(clazz);
- }
-
-
- private static void defineEnterpriseWebBeans()
- {
-
- }
+ private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansContainerDeployer.class);
+
+ private boolean deployed = false;
+
+ private WebBeansXMLConfigurator xmlConfigurator = null;
+
+ public WebBeansContainerDeployer(WebBeansXMLConfigurator xmlConfigurator)
+ {
+ this.xmlConfigurator = xmlConfigurator;
+ }
+
+ /**
+ * Deploys all the defined web beans components in the container startup.
+ * <p>
+ * It deploys from the web-beans.xml files and from the class files. It uses
+ * the {@link WebBeansScanner} class to get classes.
+ * </p>
+ *
+ * @throws WebBeansDeploymentException if any deployment exception occurs
+ */
+ public void deploy(WebBeansScanner scanner) throws WebBeansDeploymentException
+ {
+ try
+ {
+ if (!deployed)
+ {
+ // Register Manager built-in component
+ ManagerImpl.getManager().addBean(WebBeansUtil.getManagerComponent());
+
+ // Register Conversation built-in component
+ ManagerImpl.getManager().addBean(WebBeansUtil.getConversationComponent());
+
+ // JNDI bind
+ JNDIUtil.bind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME, ManagerImpl.getManager());
+
+ deployFromXML(scanner);
+ checkStereoTypes(scanner);
+ configureInterceptors(scanner);
+ configureDecorators(scanner);
+ deployFromClassPath(scanner);
+ checkSpecializations(scanner);
+
+ deployed = true;
+ }
+
+ } catch (Throwable e)
+ {
+ throw new WebBeansDeploymentException(e);
+ } finally
+ {
+ Manager manager = ManagerImpl.getManager();
+ manager.fireEvent(manager, new Annotation[] { new InitializedManagerLiteral() });
+ }
+ }
+
+ private void deployFromClassPath(WebBeansScanner scanner) throws ClassNotFoundException
+ {
+ logger.info("Deploying configurations from class files is started");
+
+ // Start from the class
+ Map<String, Set<String>> classIndex = scanner.getANNOTATION_DB().getClassIndex();
+ if (classIndex != null)
+ {
+ Set<String> pathClasses = classIndex.keySet();
+ Iterator<String> itPathClasses = pathClasses.iterator();
+
+ while (itPathClasses.hasNext())
+ {
+ String componentClassName = itPathClasses.next();
+ Class<?> implClass = ClassUtil.getClassFromName(componentClassName);
+
+ if (SimpleWebBeansConfigurator.isSimpleWebBean(implClass))
+ {
+ logger.info("Simple WebBeans Component with class name : " + componentClassName + " is found");
+ defineSimpleWebBeans(implClass);
+ } else if (EJBWebBeansConfigurator.isEJBWebBean(implClass))
+ {
+ logger.info("Enterprise WebBeans Component with class name : " + componentClassName + " is found");
+ defineEnterpriseWebBeans();
+ }
+ }
+ }
+
+ logger.info("Deploying configurations from class files is ended");
+
+ }
+
+ private void deployFromXML(WebBeansScanner scanner)
+ {
+ logger.info("Deploying configurations from XML files is started");
+
+ Map<String, InputStream> xmls = scanner.getWEBBEANS_XML_LOCATIONS();
+ Set<String> keySet = xmls.keySet();
+ Iterator<String> it = keySet.iterator();
+
+ while (it.hasNext())
+ {
+ String fileName = it.next();
+ this.xmlConfigurator.configure(xmls.get(fileName), fileName);
+ }
+
+ logger.info("Deploying configurations from XML is ended succesfully");
+ }
+
+ private void configureInterceptors(WebBeansScanner scanner) throws ClassNotFoundException
+ {
+ logger.info("Configuring the Interceptors is started");
+
+ // Interceptors Set
+ Map<String, Set<String>> annotIndex = scanner.getANNOTATION_DB().getAnnotationIndex();
+ Set<String> classes = annotIndex.get(Interceptor.class.getName());
+
+ if (classes != null)
+ {
+ for (String interceptorClazz : classes)
+ {
+ Class<?> implClass = ClassUtil.getClassFromName(interceptorClazz);
+
+ logger.info("Simple WebBeans Interceptor Component with class name : " + interceptorClazz + " is found");
+
+ defineSimpleWebBeansInterceptors(implClass);
+ }
+ }
+
+ logger.info("Configuring the Interceptors is ended");
+
+ }
+
+ private void configureDecorators(WebBeansScanner scanner) throws ClassNotFoundException
+ {
+ logger.info("Configuring the Decorators is started");
+
+ Map<String, Set<String>> annotIndex = scanner.getANNOTATION_DB().getAnnotationIndex();
+ Set<String> classes = annotIndex.get(Decorator.class.getName());
+
+ if (classes != null)
+ {
+ for (String decoratorClazz : classes)
+ {
+ Class<?> implClass = ClassUtil.getClassFromName(decoratorClazz);
+ logger.info("Simple WebBeans Decorator Component with class name : " + decoratorClazz + " is found");
+
+ defineSimpleWebBeansDecorators(implClass);
+ }
+ }
+
+ logger.info("Configuring the Decorators is ended");
+
+ }
+
+ private void checkSpecializations(WebBeansScanner scanner)
+ {
+ logger.info("Checking Specialization constraints is started");
+
+ Map<String, Set<String>> specialMap = scanner.getANNOTATION_DB().getAnnotationIndex();
+ if (specialMap != null && specialMap.size() > 0)
+ {
+ if (specialMap.containsKey(Specializes.class.getName()))
+ {
+ Set<String> specialClassSet = specialMap.get(Specializes.class.getName());
+ Iterator<String> specialIterator = specialClassSet.iterator();
+
+ Class<?> superClass = null;
+ while (specialIterator.hasNext())
+ {
+ String specialClassName = specialIterator.next();
+ Class<?> specialClass = ClassUtil.getClassFromName(specialClassName);
+
+ if (superClass == null)
+ {
+ superClass = specialClass.getSuperclass();
+ } else
+ {
+ if (superClass.equals(specialClass.getSuperclass()))
+ {
+ throw new InconsistentSpecializationException("More than one class that specialized the same super class : " + superClass.getName());
+ }
+ }
+
+ WebBeansUtil.configureSpecializations(specialClass);
+ }
+ }
+ }
+
+ // XML Defined Specializations
+ checkXMLSpecializations();
+
+ logger.info("Checking Specialization constraints is ended");
+ }
+
+ private void checkXMLSpecializations()
+ {
+ // Check XML specializations
+ Set<Class<?>> clazzes = XMLSpecializesManager.getInstance().getXMLSpecializationClasses();
+ Iterator<Class<?>> it = clazzes.iterator();
+ Class<?> superClass = null;
+ Class<?> specialClass = null;
+ while (it.hasNext())
+ {
+ specialClass = it.next();
+
+ if (superClass == null)
+ {
+ superClass = specialClass.getSuperclass();
+ } else
+ {
+ if (superClass.equals(specialClass.getSuperclass()))
+ {
+ throw new InconsistentSpecializationException("XML Specialization Error : More than one class that specialized the same super class : " + superClass.getName());
+ }
+ }
+
+ WebBeansUtil.configureSpecializations(specialClass);
+
+ }
+ }
+
+ public void checkPassivationScopes()
+ {
+ Set<Bean<?>> beans = ManagerImpl.getManager().getBeans();
+
+ if (beans != null && beans.size() > 0)
+ {
+ Iterator<Bean<?>> itBeans = beans.iterator();
+ while (itBeans.hasNext())
+ {
+ Object beanObj = itBeans.next();
+ if (beanObj instanceof ComponentImpl)
+ {
+ ComponentImpl<?> component = (ComponentImpl<?>) beanObj;
+ ScopeType scope = component.getScopeType().getAnnotation(ScopeType.class);
+ if (scope.passivating())
+ {
+ // Check constructor
+
+ // Check non-transient fields
+
+ // Check initializer methods
+
+ // Check producer methods
+ }
+ }
+ }
+ }
+ }
+
+ public void checkStereoTypes(WebBeansScanner scanner)
+ {
+ logger.info("Checking StereoTypes constraints is started");
+
+ Map<String, Set<String>> stereotypeMap = scanner.getANNOTATION_DB().getAnnotationIndex();
+ if (stereotypeMap != null && stereotypeMap.size() > 0)
+ {
+ Set<String> stereoClassSet = stereotypeMap.keySet();
+ Iterator<String> steIterator = stereoClassSet.iterator();
+ while (steIterator.hasNext())
+ {
+ String steroClassName = steIterator.next();
+
+ Class<? extends Annotation> stereoClass = (Class<? extends Annotation>) ClassUtil.getClassFromName(steroClassName);
+
+ if (AnnotationUtil.isStereoTypeAnnotation(stereoClass))
+ {
+ if (!XMLAnnotationTypeManager.getInstance().isStereoTypeExist(stereoClass))
+ {
+ WebBeansUtil.checkStereoTypeClass(stereoClass);
+ StereoTypeModel model = new StereoTypeModel(stereoClass);
+ StereoTypeManager.getInstance().addStereoTypeModel(model);
+ }
+ }
+ }
+ }
+
+ logger.info("Checking StereoTypes constraints is ended");
+ }
+
+ private <T> void defineSimpleWebBeans(Class<T> clazz)
+ {
+ ComponentImpl<T> component = null;
+
+ if (!AnnotationUtil.isAnnotationExistOnClass(clazz, Interceptor.class) && !AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class))
+ {
+ component = SimpleWebBeansConfigurator.define(clazz, WebBeansType.SIMPLE);
+ if (component != null)
+ {
+ DecoratorUtil.checkSimpleWebBeanDecoratorConditions(component);
+
+ /* I have added this into the ComponentImpl.afterCreate(); */
+ // DefinitionUtil.defineSimpleWebBeanInterceptorStack(component);
+ ManagerImpl.getManager().addBean(component);
+ }
+ }
+ }
+
+ /**
+ * Defines the new interceptor with given class.
+ *
+ * @param clazz interceptor class
+ */
+ private <T> void defineSimpleWebBeansInterceptors(Class<T> clazz)
+ {
+ WebBeansUtil.defineSimpleWebBeansInterceptors(clazz);
+ }
+
+ private <T> void defineSimpleWebBeansDecorators(Class<T> clazz)
+ {
+ WebBeansUtil.defineSimpleWebBeansDecorators(clazz);
+ }
+
+ private static void defineEnterpriseWebBeans()
+ {
+
+ }
}
\ No newline at end of file
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java?rev=732803&r1=732802&r2=732803&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java Thu Jan 8 11:41:30 2009
@@ -1,89 +1,85 @@
/*
- * 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.
+ * 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.config;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
public class WebBeansFinder
{
- public static final String SINGLETON_MANAGER = "org.apache.webbeans.container.ManagerImpl";
-
- public static final String SINGLETON_DECORATORS_MANAGER = "org.apache.webbeans.decorator.DecoratorsManager";
-
- public static final String SINGLETON_DEPLOYMENT_TYPE_MANAGER = "org.apache.webbeans.deployment.DeploymentTypeManager";
-
- public static final String SINGLETON_STEREOTYPE_MANAGER = "org.apache.webbeans.deployment.StereoTypeManager";
-
- public static final String SINGLETON_NOTIFICATION_MANAGER = "org.apache.webbeans.event.NotificationManager";
-
- public static final String SINGLETON_INTERCEPTORS_MANAGER = "org.apache.webbeans.intercept.InterceptorsManager";
-
- public static final String SINGLETON_CONVERSATION_MANAGER = "org.apache.webbeans.jsf.ConversationManager";
-
- public static final String SINGLETON_XML_ANNOTATION_TYPE_MANAGER = "org.apache.webbeans.xml.XMLAnnotationTypeManager";
-
- public static final String SINGLETON_XML_SPECIALIZES_MANAGER = "org.apache.webbeans.xml.XMLSpecializesManager";
-
- public static final String SINGLETON_INJECTION_RESOLVER = "org.apache.webbeans.container.InjectionResolver";
-
- private static Map<String, Map<ClassLoader, Object>> singletonMap = new HashMap<String, Map<ClassLoader,Object>>();
-
- public static Object getSingletonInstance(String singletonName)
- {
- Object object = null;
-
- synchronized (singletonMap)
- {
- ClassLoader classLoader = WebBeansUtil.getCurrentClassLoader();
- Map<ClassLoader, Object> managerMap = singletonMap.get(singletonName);
-
- if(managerMap == null)
- {
- managerMap = new HashMap<ClassLoader, Object>();
- singletonMap.put(singletonName, managerMap);
- }
- object = managerMap.get(classLoader);
- /*No singleton for this application, create one*/
- if(object == null)
- {
- Class<?> clazz = ClassUtil.getClassFromName(singletonName);
- try
- {
- object = clazz.newInstance();
- managerMap.put(classLoader, object);
-
- } catch (InstantiationException e)
- {
- throw new WebBeansException("Unable to instantiate class : " + singletonName,e);
-
- } catch (IllegalAccessException e)
- {
- throw new WebBeansException("Illegal access exception in creating instance with class : " + singletonName ,e);
- }
- }
- }
-
- return object;
-
- }
+ public static final String SINGLETON_MANAGER = "org.apache.webbeans.container.ManagerImpl";
+
+ public static final String SINGLETON_DECORATORS_MANAGER = "org.apache.webbeans.decorator.DecoratorsManager";
+
+ public static final String SINGLETON_DEPLOYMENT_TYPE_MANAGER = "org.apache.webbeans.deployment.DeploymentTypeManager";
+
+ public static final String SINGLETON_STEREOTYPE_MANAGER = "org.apache.webbeans.deployment.StereoTypeManager";
+
+ public static final String SINGLETON_NOTIFICATION_MANAGER = "org.apache.webbeans.event.NotificationManager";
+
+ public static final String SINGLETON_INTERCEPTORS_MANAGER = "org.apache.webbeans.intercept.InterceptorsManager";
+
+ public static final String SINGLETON_CONVERSATION_MANAGER = "org.apache.webbeans.jsf.ConversationManager";
+
+ public static final String SINGLETON_XML_ANNOTATION_TYPE_MANAGER = "org.apache.webbeans.xml.XMLAnnotationTypeManager";
+
+ public static final String SINGLETON_XML_SPECIALIZES_MANAGER = "org.apache.webbeans.xml.XMLSpecializesManager";
+
+ public static final String SINGLETON_INJECTION_RESOLVER = "org.apache.webbeans.container.InjectionResolver";
+
+ private static Map<String, Map<ClassLoader, Object>> singletonMap = new HashMap<String, Map<ClassLoader, Object>>();
+
+ public static Object getSingletonInstance(String singletonName)
+ {
+ Object object = null;
+
+ synchronized (singletonMap)
+ {
+ ClassLoader classLoader = WebBeansUtil.getCurrentClassLoader();
+ Map<ClassLoader, Object> managerMap = singletonMap.get(singletonName);
+
+ if (managerMap == null)
+ {
+ managerMap = new HashMap<ClassLoader, Object>();
+ singletonMap.put(singletonName, managerMap);
+ }
+ object = managerMap.get(classLoader);
+ /* No singleton for this application, create one */
+ if (object == null)
+ {
+ Class<?> clazz = ClassUtil.getClassFromName(singletonName);
+ try
+ {
+ object = clazz.newInstance();
+ managerMap.put(classLoader, object);
+
+ } catch (InstantiationException e)
+ {
+ throw new WebBeansException("Unable to instantiate class : " + singletonName, e);
+
+ } catch (IllegalAccessException e)
+ {
+ throw new WebBeansException("Illegal access exception in creating instance with class : " + singletonName, e);
+ }
+ }
+ }
+
+ return object;
+
+ }
}
\ No newline at end of file