[jboss-cvs] JBossAS SVN: r77773 - in trunk/ejb3/src/main/org/jboss/ejb3: client/injection and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 2 04:12:22 EDT 2008


Author: wolfc
Date: 2008-09-02 04:12:22 -0400 (Tue, 02 Sep 2008)
New Revision: 77773

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/client/injection/
   trunk/ejb3/src/main/org/jboss/ejb3/client/injection/ClientPersistenceUnitHandler.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java
Log:
EJBTHREE-1050: inject persistence unit

Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2008-09-02 07:38:42 UTC (rev 77772)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2008-09-02 08:12:22 UTC (rev 77773)
@@ -49,13 +49,13 @@
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.DependencyPolicy;
 import org.jboss.ejb3.InitialContextFactory;
+import org.jboss.ejb3.client.injection.ClientPersistenceUnitHandler;
 import org.jboss.ejb3.entity.PersistenceUnitDeployment;
 import org.jboss.injection.DependsHandler;
 import org.jboss.injection.EncInjector;
 import org.jboss.injection.InjectionContainer;
 import org.jboss.injection.InjectionHandler;
 import org.jboss.injection.Injector;
-import org.jboss.injection.PersistenceUnitHandler;
 import org.jboss.injection.WebServiceRefHandler;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.client.jboss.JBossClientMetaData;
@@ -343,7 +343,7 @@
       // This currently has no use in the ClientContainer, maybe in the future when running an mc
       handlers.add(new DependsHandler<RemoteEnvironment>());
       //handlers.add(new JndiInjectHandler<RemoteEnvironment>());
-      handlers.add(new PersistenceUnitHandler<RemoteEnvironment>());
+      handlers.add(new ClientPersistenceUnitHandler<RemoteEnvironment>());
       handlers.add(new ClientResourceHandler<RemoteEnvironment>(this.mainClass));
       handlers.add(new WebServiceRefHandler<RemoteEnvironment>());
 

Added: trunk/ejb3/src/main/org/jboss/ejb3/client/injection/ClientPersistenceUnitHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/injection/ClientPersistenceUnitHandler.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/injection/ClientPersistenceUnitHandler.java	2008-09-02 08:12:22 UTC (rev 77773)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.client.injection;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.jboss.ejb3.client.Utils;
+import org.jboss.injection.InjectionContainer;
+import org.jboss.injection.InjectionHandler;
+import org.jboss.injection.Injector;
+import org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+
+/**
+ * Injection of persistence units into application clients.
+ * 
+ * Only setup injection of persistence units, the enc setup is done on the server.
+ * It's expected that the meta data is complete and no annotation handling should be performed.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ClientPersistenceUnitHandler<X extends RemoteEnvironment> implements InjectionHandler<X>
+{
+   public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
+   {
+      throw new IllegalStateException("Annotations are not handled");
+   }
+
+   public void handleFieldAnnotations(Field field, InjectionContainer container,
+         Map<AccessibleObject, Injector> injectors)
+   {
+      throw new IllegalStateException("Annotations are not handled");
+   }
+
+   public void handleMethodAnnotations(Method method, InjectionContainer container,
+         Map<AccessibleObject, Injector> injectors)
+   {
+      throw new IllegalStateException("Annotations are not handled");
+   }
+
+   public void loadXml(X xml, InjectionContainer container)
+   {
+      if (xml == null) return;
+      if (xml.getPersistenceUnitRefs() == null) return;
+
+      for (PersistenceUnitReferenceMetaData ref : xml.getPersistenceUnitRefs())
+      {
+         String encName = "env/" + ref.getPersistenceUnitRefName();
+         Utils.injectionTarget(encName, ref, container);
+      }
+   }
+}

Modified: trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java	2008-09-02 07:38:42 UTC (rev 77772)
+++ trunk/ejb3/src/main/org/jboss/ejb3/clientmodule/ClientENCInjectionContainer.java	2008-09-02 08:12:22 UTC (rev 77773)
@@ -38,6 +38,10 @@
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 
+import org.jboss.beans.metadata.api.annotations.Create;
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.beans.metadata.api.annotations.Start;
+import org.jboss.beans.metadata.api.annotations.Stop;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.DependencyPolicy;
@@ -54,11 +58,12 @@
 import org.jboss.ejb3.javaee.SimpleJavaEEModule;
 import org.jboss.injection.DependsHandler;
 import org.jboss.injection.EncInjector;
-import org.jboss.injection.InjectionContainer;
+import org.jboss.injection.ExtendedInjectionContainer;
 import org.jboss.injection.InjectionHandler;
 import org.jboss.injection.Injector;
 import org.jboss.injection.PersistenceUnitHandler;
 import org.jboss.injection.WebServiceRefHandler;
+import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.client.jboss.JBossClientMetaData;
 import org.jboss.metadata.javaee.spec.RemoteEnvironment;
@@ -77,10 +82,11 @@
  * @author adrian at jboss.org
  * @version $Revision$
  */
-public class ClientENCInjectionContainer extends AbstractJavaEEComponent implements InjectionContainer
+public class ClientENCInjectionContainer extends AbstractJavaEEComponent implements ExtendedInjectionContainer
 {
    private static final Logger log = Logger.getLogger(ClientENCInjectionContainer.class);
 
+   private VFSDeploymentUnit deploymentUnit;
    private DeploymentUnit ejb3Unit;
    private JBossClientMetaData clientMetaData;
    private Class<?> mainClass;
@@ -100,6 +106,8 @@
    private DependencyPolicy dependencyPolicy = new JBossASDepdencyPolicy(this);
 
    private MessageDestinationResolver messageDestinationResolver;
+   
+   private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
 
    public ClientENCInjectionContainer(VFSDeploymentUnit unit, JBossClientMetaData xml, Class<?> mainClass, String applicationClientName, ClassLoader classLoader,
          Context encCtx) throws NamingException
@@ -112,6 +120,7 @@
       if (classLoader == null)
          throw new NullPointerException("classLoader is mandatory");
 
+      this.deploymentUnit = unit;
       this.ejb3Unit = new JBoss5DeploymentUnit(unit);
       this.clientMetaData = xml;
       this.mainClass = mainClass;
@@ -160,10 +169,16 @@
          // should not happen
          throw new RuntimeException("Malformed object name " + on, e);
       }
+      
+      // Do not do any processing yet, because we need stuff to be injected by MC
+   }
 
+   @Create
+   public void create()
+   {
       processMetaData();
    }
-
+   
    private String createScopeKernelName(VFSDeploymentUnit unit, DeploymentScope ear)
    {
       String scopedKernelName = "";
@@ -273,6 +288,7 @@
       return objectName;
    }
 
+   @Deprecated
    public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
    {
       throw new RuntimeException("NYI");
@@ -408,6 +424,19 @@
       return messageDestinationResolver.resolveMessageDestination(link);
    }
 
+   public String resolvePersistenceUnitSupplier(String persistenceUnitName)
+   {
+      assert persistenceUnitDependencyResolver != null : "persistenceUnitDependencyResolver has not been injected";
+      return persistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
+   }
+   
+   @Inject
+   public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
+   {
+      this.persistenceUnitDependencyResolver = resolver;
+   }
+   
+   @Start
    public void start()
    {
       populateEnc();
@@ -417,6 +446,7 @@
       log.info("STARTED CLIENT ENC CONTAINER: " + applicationClientName);
    }
 
+   @Stop
    public void stop()
    {
       log.info("STOPPED CLIENT ENC CONTAINER: " + applicationClientName);




More information about the jboss-cvs-commits mailing list