Skip to content

Commit

Permalink
Add getEJBMetaData() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Nov 15, 2011
1 parent 4e77385 commit 83606b5
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 19 deletions.
Expand Up @@ -19,23 +19,26 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.iiop;
package org.jboss.as.ejb3.component;

import java.io.Serializable;

import javax.ejb.EJBHome;
import javax.ejb.EJBMetaData;
import java.io.Serializable;

/**
* An implementation of the EJBMetaData interface which allows a
* client to obtain the enterprise Bean's meta-data information.
*
* TODO: remove this on next EJB client release
*
* @author Rickard ???berg (rickard.oberg@telkel.com)
* @author <a href="mailto:marc.fleury@telkel.com">Marc Fleury</a>
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
* @author <a href="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
* @author Stuart Douglas
*/
public class EJBMetaDataImplIIOP implements EJBMetaData, Serializable {
public class EJBMetaDataImp implements EJBMetaData, Serializable {
private final Class remoteClass;

private final Class homeClass;
Expand All @@ -48,8 +51,8 @@ public class EJBMetaDataImplIIOP implements EJBMetaData, Serializable {

private final EJBHome home;

public EJBMetaDataImplIIOP(Class remoteClass, Class homeClass, Class pkClass, boolean session,
boolean statelessSession, EJBHome home) {
public EJBMetaDataImp(final Class remoteClass, final Class homeClass, final Class pkClass, final boolean session,
final boolean statelessSession, final EJBHome home) {
this.remoteClass = remoteClass;
this.homeClass = homeClass;
this.pkClass = pkClass;
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.Collection;

import javax.ejb.Handle;

import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentStartService;
import org.jboss.as.ee.component.ComponentView;
Expand All @@ -33,7 +34,6 @@
import org.jboss.as.ee.component.ViewConfigurator;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.EjbHomeViewDescription;
import org.jboss.as.ejb3.component.MethodIntf;
Expand All @@ -42,11 +42,14 @@
import org.jboss.as.ejb3.component.entity.interceptors.EntityBeanHomeMethodInterceptorFactory;
import org.jboss.as.ejb3.component.entity.interceptors.EntityBeanHomeRemoveByHandleInterceptorFactory;
import org.jboss.as.ejb3.component.entity.interceptors.EntityBeanHomeRemoveInterceptorFactory;
import org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory;
import org.jboss.as.ejb3.component.interceptors.EjbMetadataInterceptorFactory;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentClassIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.metadata.ejb.spec.PersistenceType;
Expand All @@ -73,6 +76,8 @@ public void configure(final DeploymentPhaseContext context, final ComponentConfi
final EntityBeanComponentDescription componentDescription = (EntityBeanComponentDescription) componentConfiguration.getComponentDescription();
final EJBViewDescription createdView = localHome ? componentDescription.getEjbLocalView() : componentDescription.getEjbRemoteView();

final DeploymentClassIndex classIndex = deploymentUnit.getAttachment(Attachments.CLASS_INDEX);

for (final Method method : configuration.getProxyFactory().getCachedMethods()) {

configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
Expand Down Expand Up @@ -119,7 +124,27 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
} else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Handle.class) {
configuration.addViewInterceptor(method, EntityBeanHomeRemoveByHandleInterceptorFactory.INSTANCE, InterceptorOrder.View.COMPONENT_DISPATCHER);
} else if (method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0) {
// TODO: impl

final Class<?> ejbObjectClass;
final Class<?> pkClass;
try {
ejbObjectClass = classIndex.classIndex(createdView.getViewClassName()).getModuleClass();
pkClass = classIndex.classIndex(componentDescription.getPrimaryKeyType()).getModuleClass();
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException("Could not load view class for " + componentDescription.getComponentName(), e);
}
final EjbMetadataInterceptorFactory factory = new EjbMetadataInterceptorFactory(ejbObjectClass, configuration.getViewClass(), pkClass, false, false);

//add a dependency on the view to create
componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
}
});
//add the interceptor
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_CREATE_INTERCEPTOR);

} else if (method.getName().equals("getHomeHandle") && method.getParameterTypes().length == 0) {
// TODO: impl
} else {
Expand Down
@@ -0,0 +1,70 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.component.interceptors;

import javax.ejb.EJBHome;

import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ejb3.component.EJBMetaDataImp;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.invocation.InterceptorFactoryContext;
import org.jboss.msc.value.InjectedValue;

/**
* Interceptor that handles the EJB metadata
*
* @author Stuart Douglas
*/
public class EjbMetadataInterceptorFactory implements InterceptorFactory {

private final InjectedValue<ComponentView> homeView = new InjectedValue<ComponentView>();

private final Class<?> remoteClass;
private final Class<?> homeClass;
private final Class<?> pkClass;
private final boolean session;
private final boolean stateless;

public EjbMetadataInterceptorFactory(final Class<?> remoteClass, final Class<?> homeClass, final Class<?> pkClass, final boolean session, final boolean stateless) {
this.remoteClass = remoteClass;
this.homeClass = homeClass;
this.pkClass = pkClass;
this.session = session;
this.stateless = stateless;
}

@Override
public Interceptor create(final InterceptorFactoryContext context) {
return new Interceptor() {
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
return new EJBMetaDataImp(remoteClass, homeClass, pkClass, session, stateless, (EJBHome) homeView.getValue().createInstance().getInstance());
}
};
}

public InjectedValue<ComponentView> getHomeView() {
return homeView;
}
}
Expand Up @@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.component.session;
package org.jboss.as.ejb3.component.interceptors;

import java.lang.reflect.Method;

Expand Down
Expand Up @@ -22,7 +22,7 @@
package org.jboss.as.ejb3.component.stateful;

import org.jboss.as.ejb3.component.interceptors.AbstractEJBInterceptor;
import org.jboss.as.ejb3.component.session.SessionBeanHomeInterceptorFactory;
import org.jboss.as.ejb3.component.interceptors.SessionBeanHomeInterceptorFactory;
import org.jboss.invocation.Interceptor;
import org.jboss.invocation.InterceptorContext;
import org.jboss.invocation.InterceptorFactory;
Expand Down
Expand Up @@ -22,8 +22,8 @@

package org.jboss.as.ejb3.deployment.processors;

import static org.jboss.as.ejb3.deployment.EjbDeploymentMarker.isEjbDeployment;

import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
Expand All @@ -35,6 +35,8 @@
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoader;

import static org.jboss.as.ejb3.deployment.EjbDeploymentMarker.isEjbDeployment;

/**
* Responsible for adding appropriate Java EE {@link org.jboss.as.server.deployment.module.ModuleDependency module dependencies}
* <p/>
Expand Down Expand Up @@ -78,7 +80,8 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, EJB_CLIENT, false, false, false));

// fetch the EjbJarMetaData
if (!isEjbDeployment(deploymentUnit)) {
//TODO: remove the app client bit after the next EJB release
if (!isEjbDeployment(deploymentUnit) && !DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) {
// nothing to do
return;
}
Expand Down
Expand Up @@ -37,15 +37,18 @@
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.interceptors.EjbMetadataInterceptorFactory;
import org.jboss.as.ejb3.component.interceptors.SessionBeanHomeInterceptorFactory;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.ejb3.component.session.SessionBeanHomeInterceptorFactory;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.component.stateless.StatelessComponentDescription;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.as.server.deployment.reflect.ClassReflectionIndex;
import org.jboss.as.server.deployment.reflect.DeploymentClassIndex;
import org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex;
import org.jboss.msc.service.ServiceBuilder;

Expand Down Expand Up @@ -86,9 +89,11 @@ public void configure(final DeploymentPhaseContext context, final ComponentConfi
configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);

final DeploymentClassIndex classIndex = phaseContext.getDeploymentUnit().getAttachment(Attachments.CLASS_INDEX);

//loop over methods looking for create methods:
final ClassReflectionIndex<?> classIndex = reflectionIndex.getClassIndex(configuration.getViewClass());
for (Method method : classIndex.getMethods()) {
final ClassReflectionIndex<?> index = reflectionIndex.getClassIndex(configuration.getViewClass());
for (Method method : index.getMethods()) {
if (method.getName().startsWith("create")) {
//we have a create method
if(ejbObjectView == null) {
Expand All @@ -109,6 +114,27 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_CREATE_INTERCEPTOR);

} else if(method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0) {

final Class<?> ejbObjectClass;
try {
ejbObjectClass = classIndex.classIndex(ejbObjectView.getViewClassName()).getModuleClass();
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException("Could not load view class for " + componentDescription.getComponentName(), e);
}
final EjbMetadataInterceptorFactory factory = new EjbMetadataInterceptorFactory(ejbObjectClass, configuration.getViewClass(), null, true, componentDescription instanceof StatelessComponentDescription);

//add a dependency on the view to create
componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
}
});
//add the interceptor
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_CREATE_INTERCEPTOR);

}
}
}
Expand Down
9 changes: 5 additions & 4 deletions ejb3/src/main/java/org/jboss/as/ejb3/iiop/EjbIIOPService.java
Expand Up @@ -33,6 +33,7 @@
import org.jacorb.ssl.SSLPolicyValueHelper;
import org.jboss.as.ee.component.ComponentView;
import org.jboss.as.ejb3.component.EJBComponent;
import org.jboss.as.ejb3.component.EJBMetaDataImp;
import org.jboss.as.ejb3.component.entity.EntityBeanComponent;
import org.jboss.as.ejb3.component.stateless.StatelessSessionComponent;
import org.jboss.as.ejb3.deployment.DeploymentRepository;
Expand Down Expand Up @@ -143,7 +144,7 @@ public class EjbIIOPService implements Service<EjbIIOPService> {
/**
* <code>EJBMetaData</code> the enterprise bean in the container.
*/
private EJBMetaDataImplIIOP ejbMetaData;
private EJBMetaDataImp ejbMetaData;

/**
* Mapping from bean methods to <code>SkeletonStrategy</code> instances.
Expand Down Expand Up @@ -333,16 +334,16 @@ public synchronized void start(final StartContext startContext) throws StartExce
beanServantRegistry = poaRegistry.getValue().getRegistryWithPersistentPOAPerServant();
final EntityBeanComponent entityBeanComponent = (EntityBeanComponent) component;
final Class pkClass = entityBeanComponent.getPrimaryKeyClass();
ejbMetaData = new EJBMetaDataImplIIOP(entityBeanComponent.getRemoteClass(), entityBeanComponent.getHomeClass(), pkClass, false, false, ejbHome);
ejbMetaData = new EJBMetaDataImp(entityBeanComponent.getRemoteClass(), entityBeanComponent.getHomeClass(), pkClass, false, false, ejbHome);
} else {
// This is a session bean (lifespan: transient)
beanServantRegistry = poaRegistry.getValue().getRegistryWithTransientPOAPerServant();
if (component instanceof StatelessSessionComponent) {
// Stateless session bean
ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, true, ejbHome);
ejbMetaData = new EJBMetaDataImp(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, true, ejbHome);
} else {
// Stateful session bean
ejbMetaData = new EJBMetaDataImplIIOP(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, false, ejbHome);
ejbMetaData = new EJBMetaDataImp(remoteView.getValue().getViewClass(), homeView.getValue().getViewClass(), null, true, false, ejbHome);
}
}

Expand Down

0 comments on commit 83606b5

Please sign in to comment.