
org.apache.webbeans.ejb.common.util.EjbUtility Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openwebbeans-ejb-common Show documentation
Show all versions of openwebbeans-ejb-common Show documentation
OpenWebBeans Java EE EJB Utility
The newest version!
/*
* 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.ejb.common.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.ObserverMethod;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import org.apache.webbeans.component.InjectionTargetWrapper;
import org.apache.webbeans.component.ProducerFieldBean;
import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.component.creation.BeanCreator.MetaDataProvider;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.ejb.common.component.BaseEjbBean;
import org.apache.webbeans.ejb.common.component.EjbBeanCreatorImpl;
import org.apache.webbeans.event.ObserverMethodImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.exception.definition.DuplicateDefinitionException;
import org.apache.webbeans.portable.AnnotatedElementFactory;
import org.apache.webbeans.portable.events.ProcessAnnotatedTypeImpl;
import org.apache.webbeans.portable.events.ProcessInjectionTargetImpl;
import org.apache.webbeans.portable.events.ProcessProducerImpl;
import org.apache.webbeans.portable.events.ProcessSessionBeanImpl;
import org.apache.webbeans.portable.events.generics.GProcessSessionBean;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
@SuppressWarnings("unchecked")
public final class EjbUtility
{
private EjbUtility()
{
}
public static void fireEvents(Class clazz, BaseEjbBean ejbBean,ProcessAnnotatedType event)
{
BeanManagerImpl manager = BeanManagerImpl.getManager();
AnnotatedElementFactory annotatedElementFactory = AnnotatedElementFactory.getInstance();
AnnotatedType annotatedType = annotatedElementFactory.newAnnotatedType(clazz);
//Fires ProcessAnnotatedType
ProcessAnnotatedTypeImpl processAnnotatedEvent = (ProcessAnnotatedTypeImpl)event;
EjbBeanCreatorImpl ejbBeanCreator = new EjbBeanCreatorImpl(ejbBean);
ejbBeanCreator.checkCreateConditions();
if(processAnnotatedEvent.isVeto())
{
return;
}
if(processAnnotatedEvent.isSet())
{
ejbBeanCreator.setMetaDataProvider(MetaDataProvider.THIRDPARTY);
}
//Define meta-data
ejbBeanCreator.defineSerializable();
ejbBeanCreator.defineStereoTypes();
ejbBeanCreator.defineApiType();
ejbBeanCreator.defineScopeType("Session Bean implementation class : " + clazz.getName() + " stereotypes must declare same @ScopeType annotations");
ejbBeanCreator.defineQualifier();
ejbBeanCreator.defineName(WebBeansUtil.getManagedBeanDefaultName(clazz.getSimpleName()));
Set> producerMethodBeans = ejbBeanCreator.defineProducerMethods();
checkProducerMethods(producerMethodBeans, ejbBean);
Set> producerFieldBeans = ejbBeanCreator.defineProducerFields();
ejbBeanCreator.defineInjectedFields();
ejbBeanCreator.defineInjectedMethods();
Set> observerMethods = ejbBeanCreator.defineObserverMethods();
//Fires ProcessInjectionTarget
ProcessInjectionTargetImpl processInjectionTargetEvent = WebBeansUtil.fireProcessInjectionTargetEvent(ejbBean);
WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessInjectionTarget event observers. Look at logs for further details");
//Put final InjectionTarget instance
manager.putInjectionTargetWrapper(ejbBean, new InjectionTargetWrapper(processInjectionTargetEvent.getInjectionTarget()));
Map,AnnotatedMethod>> annotatedMethods = new HashMap, AnnotatedMethod>>();
for(ProducerMethodBean> producerMethod : producerMethodBeans)
{
AnnotatedMethod> method = annotatedElementFactory.newAnnotatedMethod(producerMethod.getCreatorMethod(), annotatedType);
ProcessProducerImpl, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForMethod(producerMethod,method);
WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for ProducerMethods. Look at logs for further details");
annotatedMethods.put(producerMethod, method);
manager.putInjectionTargetWrapper(producerMethod, new InjectionTargetWrapper(producerEvent.getProducer()));
producerEvent.setProducerSet(false);
}
Map,AnnotatedField>> annotatedFields = new HashMap, AnnotatedField>>();
for(ProducerFieldBean> producerField : producerFieldBeans)
{
AnnotatedField> field = annotatedElementFactory.newAnnotatedField(producerField.getCreatorField(), annotatedType);
ProcessProducerImpl, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForField(producerField, field);
WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for ProducerFields. Look at logs for further details");
annotatedFields.put(producerField, field);
manager.putInjectionTargetWrapper(producerField, new InjectionTargetWrapper(producerEvent.getProducer()));
producerEvent.setProducerSet(false);
}
Map,AnnotatedMethod>> observerMethodsMap = new HashMap, AnnotatedMethod>>();
for(ObserverMethod> observerMethod : observerMethods)
{
ObserverMethodImpl> impl = (ObserverMethodImpl>)observerMethod;
AnnotatedMethod> method = annotatedElementFactory.newAnnotatedMethod(impl.getObserverMethod(), annotatedType);
observerMethodsMap.put(observerMethod, method);
}
//Fires ProcessManagedBean
ProcessSessionBeanImpl processBeanEvent = new GProcessSessionBean((Bean
© 2015 - 2025 Weber Informatics LLC | Privacy Policy