Skip to content

Commit

Permalink
Add bean structures and lifecycle for enterprise resources
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2387 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Apr 10, 2009
1 parent 39c7384 commit 2da180c
Show file tree
Hide file tree
Showing 37 changed files with 1,149 additions and 34 deletions.
14 changes: 13 additions & 1 deletion impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Expand Up @@ -92,7 +92,7 @@ public static Class<? extends Annotation> getDeploymentType(List<Class<? extends
}

// Logger
private LogProvider log = Logging.getLogProvider(AbstractBean.class);
private final LogProvider log = Logging.getLogProvider(AbstractBean.class);
// The binding types
protected Set<Annotation> bindings;
// The name
Expand Down Expand Up @@ -139,6 +139,7 @@ public AbstractBean(ManagerImpl manager)
/**
* Initializes the bean and its metadata
*/
@Override
public void initialize(BeanDeployerEnvironment environment)
{
mergedStereotypes = new MergedStereotypes<T, E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class), manager);
Expand Down Expand Up @@ -372,6 +373,7 @@ protected void specialize(BeanDeployerEnvironment environment)
*
* @see javax.inject.manager.Bean#getBindings()
*/
@Override
public Set<Annotation> getBindings()
{
return bindings;
Expand All @@ -384,6 +386,7 @@ public Set<Annotation> getBindings()
*/
protected abstract String getDefaultName();

@Override
public abstract AbstractBean<?, ?> getSpecializedBean();

/**
Expand All @@ -393,11 +396,13 @@ public Set<Annotation> getBindings()
*
* @see javax.inject.manager.Bean#getDeploymentType()
*/
@Override
public Class<? extends Annotation> getDeploymentType()
{
return deploymentType;
}

@Override
public Set<AnnotatedInjectionPoint<?, ?>> getInjectionPoints()
{
return injectionPoints;
Expand All @@ -420,6 +425,7 @@ protected MergedStereotypes<T, E> getMergedStereotypes()
*
* @see javax.inject.manager.Bean#getName()
*/
@Override
public String getName()
{
return name;
Expand All @@ -432,6 +438,7 @@ public String getName()
*
* @see javax.inject.manager.Bean#getScopeType()
*/
@Override
public Class<? extends Annotation> getScopeType()
{
return scopeType;
Expand All @@ -442,6 +449,7 @@ public Class<? extends Annotation> getScopeType()
*
* @return The type
*/
@Override
public Class<T> getType()
{
return type;
Expand Down Expand Up @@ -490,6 +498,7 @@ public boolean isNullable()
*
* @return True if primitive, false otherwise
*/
@Override
public boolean isPrimitive()
{
return primitive;
Expand Down Expand Up @@ -517,16 +526,19 @@ public String toString()
return "AbstractBean " + getName();
}

@Override
public boolean isProxyable()
{
return proxyable;
}

@Override
public boolean isDependent()
{
return Dependent.class.equals(getScopeType());
}

@Override
public boolean isSpecializing()
{
return getAnnotatedItem().isAnnotationPresent(Specializes.class);
Expand Down
10 changes: 4 additions & 6 deletions impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
Expand Up @@ -17,7 +17,6 @@

package org.jboss.webbeans.bean;

import java.beans.BeanDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Arrays;
Expand All @@ -42,14 +41,13 @@
import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.DependentStorageRequest;
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.ejb.api.SessionObjectReference;
import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.Proxies;

Expand All @@ -62,7 +60,7 @@
*/
public class EnterpriseBean<T> extends AbstractClassBean<T>
{
private LogProvider log = Logging.getLogProvider(EnterpriseBean.class);
private final Log log = Logging.getLog(EnterpriseBean.class);

// The EJB descriptor
private InternalEjbDescriptor<T> ejbDescriptor;
Expand Down Expand Up @@ -131,6 +129,7 @@ public void initialize(BeanDeployerEnvironment environment)
}
}

@Override
protected void initTypes()
{
Set<Type> types = new HashSet<Type>();
Expand Down Expand Up @@ -232,8 +231,7 @@ public T create(CreationalContext<T> creationalContext)
T instance = proxyClass.newInstance();
creationalContext.push(instance);
((ProxyObject) instance).setHandler(new EnterpriseBeanProxyMethodHandler(this));
if (log.isTraceEnabled())
log.trace("Enterprise bean instance created for bean " + this);
log.trace("Enterprise bean instance created for bean {0}", this);
return instance;
}
catch (InstantiationException e)
Expand Down
@@ -0,0 +1,198 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.webbeans.bean.ee;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;

import javax.context.CreationalContext;
import javax.context.Dependent;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
import org.jboss.webbeans.util.Proxies;

/**
* Representation of a Java EE Resource bean
*
* @author Pete Muir
*
*/
public abstract class AbstractJavaEEResourceBean<T> extends RIBean<T>
{

private final Class<? extends Annotation> deploymentType;
private final Set<Annotation> bindings;
private final Class<T> type;
private final Set<Type> types;
private final Class<T> proxyClass;

/**
* @param manager the manager used to create this bean
* @param deploymentType the deployment type of the bean
* @param bindings the bindings of bean
* @param type the concrete type of the bean
*/
public AbstractJavaEEResourceBean(ManagerImpl manager, Class<? extends Annotation> deploymentType, Set<Annotation> bindings, Class<T> type)
{
super(manager);
this.deploymentType = deploymentType;
this.bindings = bindings;
this.type = type;
this.types = new HashSet<Type>();
types.add(type);

ProxyFactory proxyFactory = Proxies.getProxyFactory(types);

@SuppressWarnings("unchecked")
Class<T> proxyClass = proxyFactory.createClass();

this.proxyClass = proxyClass;
}

@Override
public Set<Annotation> getBindings()
{
return bindings;
}

@Override
public Class<? extends Annotation> getScopeType()
{
return Dependent.class;
}

@Override
public String getName()
{
return null;
}

@Override
public Class<? extends Annotation> getDeploymentType()
{
return deploymentType;
}

@Override
public Class<T> getType()
{
return type;
}

@Override
public Set<? extends Type> getTypes()
{
return types;
}

@Override
public boolean isSpecializing()
{
return false;
}

@Override
public RIBean<?> getSpecializedBean()
{
return null;
}

@Override
public boolean isDependent()
{
return true;
}

@Override
public Set<AnnotatedInjectionPoint<?, ?>> getInjectionPoints()
{
return Collections.emptySet();
}

@Override
public boolean isNullable()
{
return true;
}

@Override
public boolean isPrimitive()
{
return false;
}

@Override
public boolean isSerializable()
{
return true;
}

@Override
public boolean isProxyable()
{
return false;
}

protected Class<T> getProxyClass()
{
return proxyClass;
}

public T create(CreationalContext<T> creationalContext)
{
T instance;
try
{
instance = getProxyClass().newInstance();
}
catch (InstantiationException e)
{
throw new RuntimeException("Error creating proxy for " + this, e);
}
catch (IllegalAccessException e)
{
throw new RuntimeException("Error creating proxy for " + this, e);
}
((ProxyObject) instance).setHandler(newMethodHandler());
return instance;
}

protected abstract MethodHandler newMethodHandler();

@Override
public void initialize(BeanDeployerEnvironment environment)
{
// TODO Auto-generated method stub

}

public void destroy(T instance)
{

}

}

0 comments on commit 2da180c

Please sign in to comment.