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 2010/03/09 21:27:33 UTC

svn commit: r921101 - in /openwebbeans/trunk/webbeans-ejb: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/webbeans/ src/main/java/org/apache/webbeans/ejb/ src/main/java/org/apache/webbeans/ejb/com...

Author: gerdogdu
Date: Tue Mar  9 20:27:32 2010
New Revision: 921101

URL: http://svn.apache.org/viewvc?rev=921101&view=rev
Log:
[OWB-322]Create new EJB project and separate common EJB classes from OpenEJB plugin

Added:
    openwebbeans/trunk/webbeans-ejb/   (with props)
    openwebbeans/trunk/webbeans-ejb/pom.xml   (with props)
    openwebbeans/trunk/webbeans-ejb/src/
    openwebbeans/trunk/webbeans-ejb/src/main/
    openwebbeans/trunk/webbeans-ejb/src/main/java/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreator.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreatorImpl.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbClassUtility.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbConstants.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java   (with props)
    openwebbeans/trunk/webbeans-ejb/src/main/resources/
    openwebbeans/trunk/webbeans-ejb/src/test/
    openwebbeans/trunk/webbeans-ejb/src/test/java/
    openwebbeans/trunk/webbeans-ejb/src/test/resources/

Propchange: openwebbeans/trunk/webbeans-ejb/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Mar  9 20:27:32 2010
@@ -0,0 +1,4 @@
+.settings
+target
+.classpath
+.project

Added: openwebbeans/trunk/webbeans-ejb/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/pom.xml?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/pom.xml (added)
+++ openwebbeans/trunk/webbeans-ejb/pom.xml Tue Mar  9 20:27:32 2010
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+	<!--
+
+		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.
+	-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.openwebbeans</groupId>
+		<artifactId>openwebbeans</artifactId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<artifactId>openwebbeans-ejb-common</artifactId>
+	<name>Apache OpenWebBeans :: EJB integration</name>
+	<packaging>jar</packaging>
+	<description>OpenWebBeans EJB Integration</description>
+	<dependencies>
+		
+	<dependency>
+	   <groupId>org.apache.openwebbeans</groupId>
+	   <artifactId>openwebbeans-impl</artifactId>
+	</dependency>
+		
+	<dependency>
+	   <groupId>org.apache.geronimo.specs</groupId>
+	   <artifactId>geronimo-el_2.2_spec</artifactId>
+           <scope>test</scope>
+	</dependency>
+		
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+            <optional>true</optional>
+        </dependency>
+        
+				
+	<dependency>
+	  <groupId>junit</groupId>
+	  <artifactId>junit</artifactId>
+	</dependency>
+		
+	</dependencies>
+</project>

Propchange: openwebbeans/trunk/webbeans-ejb/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,203 @@
+/*
+ *  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.component;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.SessionBeanType;
+
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.component.EnterpriseBeanMarker;
+import org.apache.webbeans.component.WebBeansType;
+
+/**
+ * Defines bean contract for the session beans.
+ * 
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseEjbBean<T> extends AbstractInjectionTargetBean<T> implements EnterpriseBeanMarker
+{
+    /**Session bean type*/
+    protected SessionBeanType ejbType;
+    
+    /**Current bean instance*/
+    protected T instance = null;
+    
+    /**Injected reference local interface type*/
+    protected Class<?> iface = null;
+    
+    /**Remove stateful bean instance*/
+    protected boolean removeStatefulInstance = false;
+    
+    /**
+     * Creates a new instance of the session bean.
+     * @param ejbClassType ebj class type
+     */
+    public BaseEjbBean(Class<T> ejbClassType)
+    {
+        super(WebBeansType.ENTERPRISE,ejbClassType);
+
+        //Setting inherited meta data instance
+        setInheritedMetaData();
+    }
+
+    /**
+     * Sets local interface type.
+     * @param iface local interface type
+     */
+    public void setIface(Class<?> iface)
+    {
+        this.iface = iface;
+    }
+    
+    public Class<?> getIface()
+    {
+        return this.iface;
+    }
+    
+    /**
+     * Sets remove flag.
+     * @param remove flag
+     */
+    public void setRemoveStatefulInstance(boolean remove)
+    {
+        this.removeStatefulInstance = remove;
+    }
+    
+        
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void injectFields(T instance, CreationalContext<T> creationalContext)
+    {
+        //No-operations
+    }
+    
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.webbeans.component.AbstractBean#isPassivationCapable()
+     */
+    @Override
+    public boolean isPassivationCapable()
+    {
+        if(this.ejbType.equals(SessionBeanType.STATEFUL))
+        {
+            return true;
+        }
+        
+        return false;
+    }
+
+    /**
+     * Inject session bean injected fields. It is called from
+     * interceptor.
+     * @param instance bean instance
+     * @param creationalContext creational context instance
+     */
+    @SuppressWarnings("unchecked")
+    public void injectFieldInInterceptor(Object instance, CreationalContext<?> creationalContext)
+    {
+        super.injectFields((T)instance, (CreationalContext<T>)creationalContext);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected T createComponentInstance(CreationalContext<T> creationalContext)
+    {
+        if(this.instance == null)
+        {
+            //Create instance
+            this.instance = getInstance(creationalContext);
+        }
+
+        return instance;
+    }
+    
+    /**
+     * Sublclasses must return instance.
+     * @param creationalContext creational context
+     * @return instance
+     */
+    protected abstract T getInstance(CreationalContext<T> creationalContext);
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void destroyComponentInstance(T instance, CreationalContext<T> creational)
+    {
+        if(removeStatefulInstance && getEjbType().equals(SessionBeanType.STATEFUL))
+        {
+            //Call remove method
+        }
+        
+        this.instance = null;
+    }
+    
+    /**
+     * Sets session bean type.
+     * @param type session bean type
+     */
+    public void setEjbType(SessionBeanType type)
+    {
+        this.ejbType = type;
+        
+    }
+    
+    /**
+     * Subclasses can override this.
+     * @return remove methods
+     */
+    public List<Method> getRemoveMethods()
+    {
+        return null;
+    }
+    
+    /**
+     * Subclasses must override this to return local interfaces.
+     * @return local business interfaces.
+     */
+    public List<Class<?>> getBusinessLocalInterfaces()
+    {
+        return null;
+    }
+    
+    /**
+     * Subclasses must override this to return ejb name
+     * @return ejb name
+     */    
+    public String getEjbName()
+    {
+        return null;
+    }
+    
+    /**
+     * Gets ejb session type.
+     * @return type of the ejb
+     */
+    public SessionBeanType getEjbType()
+    {
+        return this.ejbType;
+    }
+
+}
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreator.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreator.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreator.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,21 @@
+/*
+ * 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.component;
+
+import org.apache.webbeans.component.creation.InjectedTargetBeanCreator;
+
+public interface EjbBeanCreator<T> extends InjectedTargetBeanCreator<T> 
+{
+
+}

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreatorImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreatorImpl.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreatorImpl.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreatorImpl.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,121 @@
+/*
+ * 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.component;
+
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.ObserverMethod;
+import javax.enterprise.inject.spi.SessionBeanType;
+
+import org.apache.webbeans.component.creation.AbstractInjectedTargetBeanCreator;
+import org.apache.webbeans.ejb.common.util.EjbValidator;
+import org.apache.webbeans.exception.WebBeansPassivationException;
+
+/**
+ * EjbBeanCreatorImpl.
+ * 
+ * @version $Rev$ $Date$
+ *
+ * @param <T> ejb class type
+ */
+public class EjbBeanCreatorImpl<T> extends AbstractInjectedTargetBeanCreator<T> implements EjbBeanCreator<T>
+{
+    public EjbBeanCreatorImpl(BaseEjbBean<T> ejbBean)
+    {
+        super(ejbBean);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void checkCreateConditions()
+    {        
+        EjbValidator.validateDecoratorOrInterceptor(getBean().getReturnType());
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void defineScopeType(String errorMessage) throws WebBeansPassivationException
+    {
+        try
+        {
+            super.defineScopeType(errorMessage);   
+        }
+        catch(WebBeansPassivationException e)
+        {
+            SessionBeanType type = getBean().getEjbType();
+            if(!type.equals(SessionBeanType.STATEFUL))
+            {
+                throw e;
+            }
+        }
+        
+        EjbValidator.validateEjbScopeType(getBean());
+        EjbValidator.validateGenericBeanType(getBean().getReturnType(), getBean().getScope());
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    public void defineApiType()
+    {
+        if(isDefaultMetaDataProvider())
+        {
+            List<Class<?>> businessLocals = getBean().getBusinessLocalInterfaces();
+            for(Class clazz : businessLocals)
+            {
+                getBean().addApiType(clazz);
+            }
+            
+            getBean().addApiType(Object.class);
+        }
+        else
+        {  
+            Set<Type> types = getAnnotatedType().getTypeClosure();
+            getBean().getTypes().addAll(types);
+        }
+    }
+    
+    
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.webbeans.component.creation.AbstractInjectedTargetBeanCreator#defineObserverMethods()
+     */
+    @Override
+    public Set<ObserverMethod<?>> defineObserverMethods()
+    {
+        Set<ObserverMethod<?>> observerMethods = super.defineObserverMethods();
+        EjbValidator.validateObserverMethods(getBean(), observerMethods);
+        
+        return observerMethods;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings("unchecked")
+    public BaseEjbBean<T> getBean()
+    {
+        return BaseEjbBean.class.cast(super.getBean());
+    }    
+}
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanCreatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,53 @@
+/*
+ *  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.interceptor;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.interceptor.InvocationContext;
+
+import org.apache.webbeans.ejb.common.component.BaseEjbBean;
+
+public class OpenWebBeansEjbInterceptor
+{
+    private static ThreadLocal<BaseEjbBean<?>> threadLocal = new ThreadLocal<BaseEjbBean<?>>();
+    
+    private static ThreadLocal<CreationalContext<?>> threadLocalCreationalContext = new ThreadLocal<CreationalContext<?>>();
+    
+    public static void setThreadLocal(BaseEjbBean<?> ejbBean, CreationalContext<?> creationalContext)
+    {
+        threadLocal.set(ejbBean);
+        threadLocalCreationalContext.set(creationalContext);
+    }
+    
+    public static void unsetThreadLocal()
+    {
+        threadLocal.remove();
+        threadLocalCreationalContext.remove();
+    }
+    
+    @PostConstruct
+    public void afterConstruct(InvocationContext context) throws Exception
+    {
+        Object instance = context.getTarget();
+
+        threadLocal.get().injectFieldInInterceptor(instance, threadLocalCreationalContext.get());
+        
+        
+    }
+    
+}

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/interceptor/OpenWebBeansEjbInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,115 @@
+/*
+ *  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.proxy;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.SessionBeanType;
+
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.ejb.common.component.BaseEjbBean;
+import org.apache.webbeans.ejb.common.interceptor.OpenWebBeansEjbInterceptor;
+
+import javassist.util.proxy.MethodHandler;
+
+/**
+ * EJB beans proxy handler.
+ * @version $Rev: 889852 $ $Date: 2009-12-12 01:11:53 +0200 (Sat, 12 Dec 2009) $
+ *
+ */
+@SuppressWarnings("unchecked")
+public class EjbBeanProxyHandler implements MethodHandler
+{
+    /**Proxy ejb bean instance*/
+    private BaseEjbBean<?> ejbBean;
+    
+    private CreationalContext<?> creationalContext;
+    
+    /**
+     * Creates a new instance.
+     * @param ejbBean ejb bean instance
+     */
+    public EjbBeanProxyHandler(BaseEjbBean<?> ejbBean, CreationalContext<?> creationalContext)
+    {
+        this.ejbBean = ejbBean;
+        this.creationalContext = creationalContext;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Object invoke(Object instance, Method method, Method proceed, Object[] arguments) throws Exception
+    {
+        //Check ejb remove method
+        if(this.ejbBean.getEjbType().equals(SessionBeanType.STATEFUL))
+        {
+            if(checkEjbRemoveMethod(method))
+            {
+                this.ejbBean.setRemoveStatefulInstance(true);
+            }
+        }
+        
+        Object result = null;
+        
+        try
+        {
+            OpenWebBeansEjbInterceptor.setThreadLocal(this.ejbBean, this.creationalContext);
+            
+            //Context of the bean
+            Context webbeansContext = BeanManagerImpl.getManager().getContext(ejbBean.getScope());
+            
+            //Get bean instance from context
+            Object webbeansInstance = webbeansContext.get((Contextual<Object>)this.ejbBean, (CreationalContext<Object>)this.creationalContext);            
+            result = method.invoke(webbeansInstance, arguments);            
+            
+        }finally
+        {
+            OpenWebBeansEjbInterceptor.unsetThreadLocal();   
+        }                
+        
+        return result;
+    }
+    
+    /**
+     * Check stateful bean remove method control.
+     * @param method called method
+     * @throws UnsupportedOperationException if not valid call
+     */
+    private boolean checkEjbRemoveMethod(Method method)
+    {
+        List<Method> removeMethods = this.ejbBean.getRemoveMethods();
+        if(removeMethods.contains(method))
+        {
+            if(this.ejbBean.getScope() != Dependent.class)
+            {
+                throw new UnsupportedOperationException("Can not call EJB Statefull Bean Remove Method without scoped @Dependent");
+            }
+            else
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+}

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/proxy/EjbBeanProxyHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbClassUtility.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbClassUtility.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbClassUtility.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbClassUtility.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,57 @@
+/*
+ *  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.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.ClassUtil;
+
+public final class EjbClassUtility
+{
+    private EjbClassUtility()
+    {
+        
+    }
+    
+    
+    public static Class<?> getLocalInterfaceClass(Type localInterfaceGenericType)
+    {
+        Asserts.assertNotNull(localInterfaceGenericType);
+        
+        Class<?> localInterface = null;
+        if(ClassUtil.isParametrizedType(localInterfaceGenericType))
+        {
+            ParameterizedType parametrizedType = (ParameterizedType)localInterfaceGenericType;
+            
+            if(ClassUtil.checkParametrizedType(parametrizedType))
+            {
+                Type rawType = parametrizedType.getRawType();
+                localInterface = (Class<?>)rawType;
+            }
+            
+        }
+        else if(localInterfaceGenericType instanceof Class)
+        {
+            localInterface = (Class<?>)localInterfaceGenericType;
+        }
+        
+        return localInterface;
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbClassUtility.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbConstants.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbConstants.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbConstants.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbConstants.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,32 @@
+/*
+ *  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;
+
+/**
+ * @version $Rev: 889852 $ $Date: 2009-12-12 01:11:53 +0200 (Sat, 12 Dec 2009) $
+ */
+public final class EjbConstants
+{
+    private EjbConstants()
+    {
+        
+    }
+
+    public static final String EJB_WEBBEANS_ERROR_PREFIX ="Ejb WebBeans Component ";
+    
+    public static final String EJB_WEBBEANS_ERROR_CLASS_PREFIX = EJB_WEBBEANS_ERROR_PREFIX + "with implementation class : ";
+}

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,66 @@
+/*
+ *  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 javax.enterprise.context.spi.CreationalContext;
+
+import javassist.util.proxy.ProxyFactory;
+
+import org.apache.webbeans.ejb.common.component.BaseEjbBean;
+import org.apache.webbeans.ejb.common.component.EjbBeanCreatorImpl;
+import org.apache.webbeans.ejb.common.proxy.EjbBeanProxyHandler;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
+
+/**
+ * @version $Rev: 917060 $ $Date: 2010-02-28 00:14:47 +0200 (Sun, 28 Feb 2010) $
+ */
+public final class EjbDefinitionUtility
+{
+    private EjbDefinitionUtility()
+    {
+        
+    }
+
+    @SuppressWarnings("unchecked")
+    public static void defineApiType(BaseEjbBean<?> ejbComponent)
+    {        
+        EjbBeanCreatorImpl<?> creator = new EjbBeanCreatorImpl(ejbComponent);
+        creator.defineApiType();
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static <T> T defineEjbBeanProxy(BaseEjbBean<T> bean, Class<?> iface, CreationalContext<?> creationalContext)
+    {
+        try
+        {
+            bean.setIface(iface);
+            ProxyFactory factory = new ProxyFactory();
+            
+            EjbBeanProxyHandler handler = new EjbBeanProxyHandler(bean,creationalContext);
+            
+            factory.setHandler(handler);
+            factory.setInterfaces(new Class[]{iface});
+         
+            return (T)(JavassistProxyFactory.getProxyClass(factory).newInstance());
+            
+        }catch(Exception e)
+        {
+            throw new WebBeansException(e);
+        }
+    }
+}

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbDefinitionUtility.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,213 @@
+/*
+ *  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.Producer;
+
+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.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 <T> void fireEvents(Class<T> clazz, BaseEjbBean<T> ejbBean)
+    {
+        AnnotatedType<T> annotatedType = AnnotatedElementFactory.newAnnotatedType(clazz);
+        
+        //Fires ProcessAnnotatedType
+        ProcessAnnotatedTypeImpl<T> processAnnotatedEvent = WebBeansUtil.fireProcessAnnotatedTypeEvent(annotatedType);             
+        EjbBeanCreatorImpl<T> ejbBeanCreator = new EjbBeanCreatorImpl<T>(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<ProducerMethodBean<?>> producerMethodBeans = ejbBeanCreator.defineProducerMethods();        
+        checkProducerMethods(producerMethodBeans, ejbBean);
+        Set<ProducerFieldBean<?>> producerFieldBeans = ejbBeanCreator.defineProducerFields();           
+        ejbBeanCreator.defineInjectedFields();
+        ejbBeanCreator.defineInjectedMethods();
+        Set<ObserverMethod<?>> observerMethods = ejbBeanCreator.defineObserverMethods();        
+        
+        //Fires ProcessInjectionTarget
+        ProcessInjectionTargetImpl<T> processInjectionTargetEvent = WebBeansUtil.fireProcessInjectionTargetEvent(ejbBean);     
+        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessInjectionTarget event observers. Look at logs for further details");
+        if(processInjectionTargetEvent.isSet())
+        {
+            ejbBeanCreator.setInjectedTarget(processInjectionTargetEvent.getInjectionTarget());
+        }
+        
+        Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods = new HashMap<ProducerMethodBean<?>, AnnotatedMethod<?>>(); 
+        for(ProducerMethodBean<?> producerMethod : producerMethodBeans)
+        {
+            AnnotatedMethod<?> method = AnnotatedElementFactory.newAnnotatedMethod(producerMethod.getCreatorMethod(), producerMethod.getParent().getReturnType());
+            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);
+            
+            if(producerEvent.isProducerSet())
+            {
+                producerMethod.setProducer((Producer) ejbBeanCreator);
+            }
+            
+            producerEvent.setProducerSet(false);
+        }
+        
+        Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields = new HashMap<ProducerFieldBean<?>, AnnotatedField<?>>();
+        for(ProducerFieldBean<?> producerField : producerFieldBeans)
+        {
+            AnnotatedField<?> field = AnnotatedElementFactory.newAnnotatedField(producerField.getCreatorField(), producerField.getParent().getReturnType());
+            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);
+            
+            if(producerEvent.isProducerSet())
+            {
+                producerField.setProducer((Producer) ejbBeanCreator);
+            }
+            
+            producerEvent.setProducerSet(false);
+        }
+        
+        Map<ObserverMethod<?>,AnnotatedMethod<?>> observerMethodsMap = new HashMap<ObserverMethod<?>, AnnotatedMethod<?>>(); 
+        for(ObserverMethod<?> observerMethod : observerMethods)
+        {
+            ObserverMethodImpl<?> impl = (ObserverMethodImpl<?>)observerMethod;
+            AnnotatedMethod<?> method = AnnotatedElementFactory.newAnnotatedMethod(impl.getObserverMethod(), impl.getBeanClass());
+            
+            observerMethodsMap.put(observerMethod, method);
+        }        
+
+        //Fires ProcessManagedBean
+        ProcessSessionBeanImpl<T> processBeanEvent = new GProcessSessionBean((Bean<Object>)ejbBean,annotatedType,ejbBean.getEjbName(),ejbBean.getEjbType());            
+        BeanManagerImpl.getManager().fireEvent(processBeanEvent, new Annotation[0]);
+        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessSessionBean event observers for managed beans. Look at logs for further details");
+        
+        
+        //Fires ProcessProducerMethod
+        WebBeansUtil.fireProcessProducerMethodBeanEvent(annotatedMethods);
+        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerMethod event observers for producer method beans. Look at logs for further details");
+        
+        //Fires ProcessProducerField
+        WebBeansUtil.fireProcessProducerFieldBeanEvent(annotatedFields);
+        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerField event observers for producer field beans. Look at logs for further details");
+        
+        //Fire ObservableMethods
+        WebBeansUtil.fireProcessObservableMethodBeanEvent(observerMethodsMap);
+        WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessObserverMethod event observers for observer methods. Look at logs for further details");
+
+                
+        //Set InjectionTarget that is used by the container to inject dependencies!
+        if(ejbBeanCreator.isInjectionTargetSet())
+        {
+            ejbBean.setInjectionTarget(ejbBeanCreator);   
+        }
+        
+        BeanManagerImpl.getManager().addBean(WebBeansUtil.createNewBean(ejbBean));                
+        BeanManagerImpl.getManager().addBean(ejbBean);
+        BeanManagerImpl.getManager().getBeans().addAll(producerMethodBeans);
+        ejbBeanCreator.defineDisposalMethods();
+        BeanManagerImpl.getManager().getBeans().addAll(producerFieldBeans);
+    }
+    
+    private static void checkProducerMethods(Set<ProducerMethodBean<?>> producerMethodBeans, BaseEjbBean<?> bean)
+    {
+        for(ProducerMethodBean<?> producerMethodBean : producerMethodBeans)
+        {
+            Method producerMethod = producerMethodBean.getCreatorMethod();
+            if(!ClassUtil.isStatic(producerMethod.getModifiers()))
+            {
+                if(!isBusinessMethod(producerMethod, bean))
+                {
+                    throw new WebBeansConfigurationException("Producer Method Bean must be business method of session bean : " + bean);
+                }
+            }
+        }        
+    }
+    
+    public static boolean isBusinessMethod(Method method, BaseEjbBean<?> bean)
+    {
+        List<Class<?>> businessLocals = bean.getBusinessLocalInterfaces();
+        for(Class<?> clz : businessLocals)
+        {
+            try
+            {
+                clz.getMethod(method.getName(), method.getParameterTypes());
+                
+                return true;
+            }
+            catch (SecurityException e)
+            {
+                throw new WebBeansException("Security exception",e);
+            }
+            catch (NoSuchMethodException e)
+            {
+                continue;
+            }
+        }
+        
+        return false;
+    }
+}
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java?rev=921101&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java (added)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java Tue Mar  9 20:27:32 2010
@@ -0,0 +1,163 @@
+/*
+ * 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.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.decorator.Decorator;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.ObserverMethod;
+import javax.enterprise.inject.spi.SessionBeanType;
+import javax.interceptor.Interceptor;
+
+import org.apache.webbeans.ejb.common.component.BaseEjbBean;
+import org.apache.webbeans.event.ObserverMethodImpl;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.ClassUtil;
+
+/**
+ * Validates session beans.
+ * 
+ * @version $Rev: 915746 $ $Date: 2010-02-24 12:43:43 +0200 (Wed, 24 Feb 2010) $
+ */
+public final class EjbValidator
+{
+    // No-instaniate
+    private EjbValidator()
+    {
+        // Empty
+    }
+
+    /**
+     * Validates session bean's scope.
+     * 
+     * @param ejbBean ejb bean
+     */
+    public static void validateEjbScopeType(BaseEjbBean<?> ejbBean)
+    {
+        Asserts.assertNotNull(ejbBean, "Session Bean can not be null");
+
+        if (ejbBean.getScope() == null)
+        {
+            throw new NullPointerException("Session Bean scope can not be null");
+        }
+
+        if (ejbBean.getEjbType() == null)
+        {
+            throw new NullPointerException("Session Bean type can not be null. It must be one of @Stateless, @Stateful, @Singleton");
+        }
+
+        if (ejbBean.getEjbType().equals(SessionBeanType.STATELESS))
+        {
+            if (!ejbBean.getScope().equals(Dependent.class))
+            {
+                throw new WebBeansConfigurationException("Stateless Session Bean class : " + ejbBean.getReturnType() + " " + "can not define scope other than @Dependent");
+            }
+        }
+        else if (ejbBean.getEjbType().equals(SessionBeanType.SINGLETON))
+        {
+            if (!ejbBean.getScope().equals(Dependent.class) && !ejbBean.getScope().equals(ApplicationScoped.class))
+            {
+                throw new WebBeansConfigurationException("Singleton Session Bean class : " + ejbBean.getReturnType() + " " + "can not define scope other than @Dependent or @ApplicationScoped");
+            }
+        }
+    }
+
+    /**
+     * Validates session bean decorator/interceptor conditions.
+     * 
+     * @param ejbClass ejb bean class
+     */
+    public static void validateDecoratorOrInterceptor(Class<?> ejbClass)
+    {
+        Asserts.assertNotNull(ejbClass, "ejbClass parameter can not be null");
+
+        if (AnnotationUtil.hasClassAnnotation(ejbClass, Decorator.class))
+        {
+            throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Decorator");
+
+        }
+
+        if (AnnotationUtil.hasClassAnnotation(ejbClass, Interceptor.class))
+        {
+            throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Interceptor");
+        }
+    }
+    
+    /**
+     * Check generic type conditions.
+     * @param ejbClass ebj class
+     * @param scopeType scope type
+     */
+    public static void validateGenericBeanType(Class<?> ejbClass, Class<? extends Annotation> scopeType)
+    {
+        Asserts.assertNotNull(ejbClass, "ejbClass parameter can not be null");
+        Asserts.assertNotNull(ejbClass, "scopeType parameter can not be null");
+        
+        if(ClassUtil.isDefinitionConstainsTypeVariables(ejbClass))
+        {
+            if(!scopeType.equals(Dependent.class))
+            {
+                throw new WebBeansConfigurationException("Ejb generic bean class : " + ejbClass.getName() + "scope must be @Dependent");
+            }
+        }
+    }
+    
+    public static void validateObserverMethods(BaseEjbBean<?> bean, Set<ObserverMethod<?>> observers)
+    {
+        for(ObserverMethod<?> observer : observers)
+        {
+            ObserverMethodImpl<?> obs = (ObserverMethodImpl<?>)observer;
+            Method method = obs.getObserverMethod();
+            List<?> locals =  bean.getBusinessLocalInterfaces();
+            if(locals != null)
+            {
+                Iterator<?> it = locals.iterator();
+                boolean found = false;
+                while(it.hasNext())
+                {
+                    Class<?> clazz = (Class<?>)it.next();
+                    List<Method> methods = ClassUtil.getClassMethodsWithTypes(clazz, method.getName(), Arrays.asList(method.getParameterTypes()));
+                    if(methods.isEmpty())
+                    {
+                        continue;
+                    }
+                    else
+                    {
+                        found = true;
+                        break;
+                    }
+                }
+                
+                if(!found)
+                {
+                    if(!ClassUtil.isStatic(method.getModifiers()))
+                    {
+                        throw new WebBeansConfigurationException("Observer method : " + method.getName() + " in session bean class : " + 
+                                bean.getBeanClass() + " must be business method");                                            
+                    }
+                }
+            }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native