Save This Page
Home » JBoss-5.1.0 » org.jboss.jpa » resolvers » strategy » [javadoc | source]
    1   /*
    2    * JBoss, Home of Professional Open Source.
    3    * Copyright 2008, Red Hat Middleware LLC, and individual contributors
    4    * as indicated by the @author tags. See the copyright.txt file in the
    5    * distribution for a full listing of individual contributors.
    6    *
    7    * This is free software; you can redistribute it and/or modify it
    8    * under the terms of the GNU Lesser General Public License as
    9    * published by the Free Software Foundation; either version 2.1 of
   10    * the License, or (at your option) any later version.
   11    *
   12    * This software is distributed in the hope that it will be useful,
   13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15    * Lesser General Public License for more details.
   16    *
   17    * You should have received a copy of the GNU Lesser General Public
   18    * License along with this software; if not, write to the Free
   19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21    */
   22   package org.jboss.jpa.resolvers.strategy;
   23   
   24   import java.util.Collection;
   25   
   26   import org.jboss.beans.metadata.api.annotations.Inject;
   27   import org.jboss.deployers.client.spi.Deployment;
   28   import org.jboss.deployers.client.spi.main.MainDeployer;
   29   import org.jboss.deployers.structure.spi.DeploymentUnit;
   30   import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
   31   import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
   32   
   33   /**
   34    * A search strategy which allows for persistence units in other (unrelated)
   35    * deployments.
   36    * 
   37    * Note that this violates spec EJB 3.0 6.2.2.
   38    * 
   39    * @author <a href="mailto:cdewolf@redhat.com">Carlo de Wolf</a>
   40    * @version $Revision: $
   41    */
   42   public class JBossSearchStrategy extends BaseSearchStrategy
   43   {
   44      private MainDeployer mainDeployer;
   45      
   46      private MainDeployerStructure mainDeployerStructure;
   47      
   48      @Override
   49      public String findPersistenceUnitSupplier(PersistenceUnitDependencyResolver resolver, DeploymentUnit deploymentUnit, String persistenceUnitName)
   50      {
   51         String name = super.findPersistenceUnitSupplier(resolver, deploymentUnit, persistenceUnitName);
   52         if(name != null)
   53            return name;
   54         return findWithinMainDeployer(resolver, persistenceUnitName);
   55      }
   56      
   57      protected String findWithinMainDeployer(PersistenceUnitDependencyResolver resolver, String persistenceUnitName)
   58      {
   59         Collection<Deployment> topLevelDeployments = mainDeployer.getTopLevel();
   60         if(topLevelDeployments == null)
   61            return null;
   62         
   63         for(Deployment deployment : topLevelDeployments)
   64         {
   65            String name = deployment.getName();
   66            DeploymentUnit deploymentUnit = mainDeployerStructure.getDeploymentUnit(name);
   67            if(deploymentUnit == null)
   68               continue;
   69            String beanName = findWithinApplication(resolver, deploymentUnit, persistenceUnitName);
   70            if(beanName != null)
   71               return beanName;
   72         }
   73         
   74         return null;
   75      }
   76      
   77      @Inject
   78      public void setMainDeployer(MainDeployer mainDeployer)
   79      {
   80         this.mainDeployer = mainDeployer;
   81      }
   82      
   83      @Inject
   84      public void setMainDeployerStructure(MainDeployerStructure mainDeployerStructure)
   85      {
   86         this.mainDeployerStructure = mainDeployerStructure;
   87      }
   88   }

Save This Page
Home » JBoss-5.1.0 » org.jboss.jpa » resolvers » strategy » [javadoc | source]