Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.core.internal » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *    http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.st.core.internal;
   19   
   20   import java.util.ArrayList;
   21   import java.util.Iterator;
   22   import java.util.List;
   23   import java.util.Set;
   24   
   25   import javax.xml.bind.JAXBElement;
   26   
   27   import org.apache.geronimo.jee.application.Application;
   28   import org.apache.geronimo.jee.applicationclient.ApplicationClient;
   29   import org.apache.geronimo.jee.connector.Connector;
   30   import org.apache.geronimo.jee.deployment.Artifact;
   31   import org.apache.geronimo.jee.deployment.Dependencies;
   32   import org.apache.geronimo.jee.deployment.Dependency;
   33   import org.apache.geronimo.jee.deployment.Environment;
   34   import org.apache.geronimo.jee.deployment.ObjectFactory;
   35   import org.apache.geronimo.jee.openejb.OpenejbJar;
   36   import org.apache.geronimo.jee.web.WebApp;
   37   import org.apache.geronimo.st.core.DeploymentUtils;
   38   import org.apache.geronimo.st.core.GeronimoUtils;
   39   import org.apache.geronimo.st.core.jaxb.JAXBUtils;
   40   import org.eclipse.core.resources.IFile;
   41   import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
   42   import org.eclipse.wst.server.core.IModule;
   43   import org.eclipse.wst.server.core.IServer;
   44   import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
   45   
   46   /**
   47    * <b>DependencyHelper</b> is a helper class with various methods to aid in the discovery of
   48    * inter-dependencies between modules being deployed from the GEP to the Geronimo server. It
   49    * performs the following capabilities:
   50    * <ol>
   51    *      <li>Discovery of dependencies between modules<p>
   52    *      <li>Provides the proper publishing ordering of the modules based on the discovered
   53    *          dependencies<p>
   54    *      <li><b>TODO:</b> Query the server searching for missing dependencies
   55    * </ol>
   56    * 
   57    * @version $Rev: 817996 $ $Date: 2009-09-23 16:04:12 +0800 (Wed, 23 Sep 2009) $
   58    */
   59   public class DependencyHelper {
   60   
   61       private DependencyManager dm = new DependencyManager();
   62       private ObjectFactory deploymentFactory = new ObjectFactory();
   63       private List inputModules = new ArrayList();
   64       private List inputDeltaKind = new ArrayList();
   65       private List reorderedModules = new ArrayList();
   66       private List reorderedKinds  = new ArrayList();
   67       private List<JAXBElement> inputJAXBElements = new ArrayList();
   68       private List<JAXBElement> reorderedJAXBElements = new ArrayList();
   69   
   70   
   71       /**
   72        * Reorder the publish order of the modules based on any discovered dependencies
   73        * 
   74        * @param modules   Modules to be published to the Geronimo server
   75        * @param deltaKind Publish kind constant for each module
   76        * 
   77        * @return List of reordered modules and deltaKind (or input if no change)
   78        */
   79       public List reorderModules(IServer server, List modules, List deltaKind ) {
   80           Trace.tracePoint("Entry", "DependencyHelper.reorderModules", modules, deltaKind);
   81   
   82           if (modules.size() == 0) {
   83               List reorderedLists = new ArrayList(2);
   84               reorderedLists.add(modules);
   85               reorderedLists.add(deltaKind);
   86               Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", reorderedLists);
   87               return reorderedLists;
   88           }
   89   
   90           inputModules = modules;
   91           inputDeltaKind = deltaKind;
   92   
   93           // 
   94           // Iterate through all the modules and register the dependencies
   95           // 
   96           for (int ii=0; ii<modules.size(); ii++) {
   97               IModule[] module = (IModule[]) modules.get(ii);
   98               int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
   99               if (moduleDeltaKind != ServerBehaviourDelegate.REMOVED) {
  100               	//GERONIMODEVTOOLS-361
  101               	for (IModule singleModule:module){
  102               		Environment environment = getEnvironment(singleModule);
  103   	                if (environment != null) {
  104   	                    Artifact child = environment.getModuleId();
  105   	                    Dependencies dependencies = environment.getDependencies();
  106   	                    if (dependencies != null) {
  107   	                        List<Dependency> depList = dependencies.getDependency();
  108   	                        for ( Dependency dep : depList) {
  109   	                            Artifact parent = deploymentFactory.createArtifact();
  110   	                            parent.setGroupId( dep.getGroupId() );
  111   	                            parent.setArtifactId( dep.getArtifactId() );
  112   	                            parent.setVersion( dep.getVersion() );
  113   	                            parent.setType( dep.getType() );
  114   	                            
  115   	                            StringBuilder configId = new StringBuilder();
  116   	                            if (dep.getGroupId()!=null)
  117   	                            	configId.append(dep.getGroupId());
  118   	                            configId.append("/");
  119   	                            if (dep.getArtifactId()!=null)
  120   	                            	configId.append(dep.getArtifactId());
  121   	                            configId.append("/");
  122   	                            if (dep.getVersion()!=null)
  123   	                            	configId.append(dep.getVersion());
  124   	                            configId.append("/");
  125   	                            if (dep.getType()!=null)
  126   	                            	configId.append(dep.getType());
  127   	                            
  128   	                            if (!DeploymentUtils.isInstalledModule(server,configId.toString()))
  129   	                               	dm.addDependency( child, parent );
  130   	                        }
  131   	                    }
  132   	                }
  133               	}
  134               }
  135           }
  136   
  137           // 
  138           // Iterate through all the modules again and reorder as necessary
  139           // 
  140           for (int ii=0; ii<modules.size(); ii++) {
  141               IModule[] module = (IModule[]) modules.get(ii);
  142               int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
  143               if (module!=null && !reorderedModules.contains(module)) {
  144                   // Not already moved 
  145                   if (moduleDeltaKind == ServerBehaviourDelegate.REMOVED) {
  146                       // Move module if going to be removed 
  147                       reorderedModules.add(module);
  148                       reorderedKinds.add(moduleDeltaKind);
  149                   }
  150                   else {
  151                       Environment environment = getEnvironment(module[0]);
  152                       if (environment != null) {
  153                           Artifact artifact = environment.getModuleId();
  154                           if (artifact == null) {
  155                               // Move if null (nothing can be done)
  156                               if (!reorderedModules.contains(module)) {
  157                                   reorderedModules.add(module);
  158                                   reorderedKinds.add(moduleDeltaKind);
  159                               }
  160                           }
  161                           else if (dm.getParents(artifact).contains(artifact) ||  
  162                                    dm.getChildren(artifact).contains(artifact)) {
  163                               // Move if a tight circular dependency (nothing can be done)
  164                               if (!reorderedModules.contains(module)) {
  165                                   reorderedModules.add(module);
  166                                   reorderedKinds.add(moduleDeltaKind);
  167                               }
  168                           }
  169                           else if (dm.getParents(artifact).size() == 0) {
  170                               // Move if no parents (nothing to do)
  171                               if (!reorderedModules.contains(module)) {
  172                                   reorderedModules.add(module);
  173                                   reorderedKinds.add(moduleDeltaKind);
  174                               }
  175                           }
  176                           else if (dm.getParents(artifact).size() > 0) {
  177                               // Move parents first
  178                               processParents(dm.getParents(artifact), artifact);
  179                               // Move self 
  180                               if (!reorderedModules.contains(module)) {
  181                                   reorderedModules.add(module);
  182                                   reorderedKinds.add(moduleDeltaKind);
  183                               }
  184                           }
  185                       }else {
  186                       	//no environment defined, do just as no parents
  187                           if (!reorderedModules.contains(module)) {
  188                               reorderedModules.add(module);
  189                               reorderedKinds.add(moduleDeltaKind);
  190                           }
  191                       }
  192                   }
  193               }
  194           }
  195   
  196           // 
  197           // Ensure return lists are exactly the same size as the input lists 
  198           // 
  199           assert reorderedModules.size() == modules.size();
  200           assert reorderedKinds.size() == deltaKind.size();
  201   
  202           // 
  203           // Return List of lists
  204           // 
  205           List reorderedLists = new ArrayList(2);
  206           reorderedLists.add(reorderedModules);
  207           reorderedLists.add(reorderedKinds);
  208   
  209           Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", reorderedLists);
  210           return reorderedLists;
  211       }
  212   
  213   
  214       /**
  215        * Reorder the list of JAXBElements based on any discovered dependencies
  216        * 
  217        * @param jaxbElements
  218        * 
  219        * @return List of JAXBElements (or input if no change)
  220        */
  221       public List<JAXBElement> reorderJAXBElements( List<JAXBElement> jaxbElements ) {
  222           Trace.tracePoint("Entry", "DependencyHelper.reorderModules", jaxbElements);
  223   
  224           if (jaxbElements.size() == 0) {
  225               Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", jaxbElements);
  226               return jaxbElements;
  227           }
  228   
  229           inputJAXBElements = jaxbElements;
  230   
  231           // 
  232           // Iterate through all the JAXBElements and register the dependencies
  233           // 
  234           for (JAXBElement jaxbElement : jaxbElements) {
  235               Environment environment = getEnvironment(jaxbElement);
  236               if (environment != null) {
  237                   Artifact child = environment.getModuleId();
  238                   if (child != null) {
  239                       Dependencies dependencies = environment.getDependencies();
  240                       if (dependencies != null) {
  241                           List<Dependency> depList = dependencies.getDependency();
  242                           if (depList != null) {
  243                               for ( Dependency dep : depList) {
  244                                   Artifact parent = deploymentFactory.createArtifact();
  245                                   parent.setGroupId( dep.getGroupId() );
  246                                   parent.setArtifactId( dep.getArtifactId() );
  247                                   parent.setVersion( dep.getVersion() );
  248                                   parent.setType( dep.getType() );
  249                                   dm.addDependency( child, parent );
  250                               }
  251                           }
  252                       }
  253                   }
  254               }
  255           }
  256   
  257           // 
  258           // Iterate through all the JAXBElements again and reorder as necessary
  259           // 
  260           for (JAXBElement jaxbElement : jaxbElements) {
  261               if (!reorderedJAXBElements.contains(jaxbElement)) {
  262                   // Not already moved
  263                   Environment environment = getEnvironment(jaxbElement);
  264                   if (environment != null) {
  265                       Artifact artifact = environment.getModuleId();
  266                       if (artifact == null) {
  267                           // Move if null (nothing can be done)
  268                           if (!reorderedJAXBElements.contains(jaxbElement)) {
  269                               reorderedJAXBElements.add(jaxbElement);
  270                           }
  271                       }
  272                       else if (dm.getParents(artifact).contains(artifact) ||  
  273                                dm.getChildren(artifact).contains(artifact)) {
  274                           // Move if a tight circular dependency (nothing can be done)
  275                           if (!reorderedJAXBElements.contains(jaxbElement)) {
  276                               reorderedJAXBElements.add(jaxbElement);
  277                           }
  278                       }
  279                       else if (dm.getParents(artifact).size() == 0) {
  280                           // Move if no parents (nothing to do)
  281                           if (!reorderedJAXBElements.contains(jaxbElement)) {
  282                               reorderedJAXBElements.add(jaxbElement);
  283                           }
  284                       }
  285                       else if (dm.getParents(artifact).size() > 0) {
  286                           // Move parents first
  287                           processJaxbParents(dm.getParents(artifact), artifact);
  288                           // Move self 
  289                           if (!reorderedJAXBElements.contains(jaxbElement)) {
  290                               reorderedJAXBElements.add(jaxbElement);
  291                           }
  292                       }
  293                   }
  294               }
  295           }
  296   
  297           // 
  298           // Ensure return list is exactly the same size as the input list 
  299           // 
  300           assert reorderedJAXBElements.size() == jaxbElements.size();
  301   
  302           // 
  303           // Return List of JAXBElements
  304           // 
  305           Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", reorderedJAXBElements);
  306           return reorderedJAXBElements;
  307       }
  308   
  309   
  310       /**
  311        *
  312        */
  313       public void close() {
  314           dm.close();
  315       }
  316   
  317   
  318       /*--------------------------------------------------------------------------------------------*\
  319       |                                                                                              |
  320       |  Private method(s)                                                                           | 
  321       |                                                                                              |
  322       \*--------------------------------------------------------------------------------------------*/
  323   
  324       /**
  325        * Process the parents for a given artifact. The terminatingArtifact parameter will be used as
  326        * the terminating condition to ensure there will not be an infinite loop (i.e., if
  327        * terminatingArtifact is encountered again there is a circular dependency).
  328        * 
  329        * @param parents
  330        * @param terminatingArtifact
  331        */
  332       private void processParents(Set parents, Artifact terminatingArtifact) {
  333           Trace.tracePoint("Enter", "DependencyHelper.processParents", parents, terminatingArtifact );
  334   
  335           if (parents == null) {
  336               Trace.tracePoint("Exit ", "DependencyHelper.processParents", null);
  337               return;
  338           }
  339           for (Iterator ii = parents.iterator(); ii.hasNext();) {
  340               Artifact artifact = (Artifact)ii.next();
  341               if (dm.getParents(artifact).size() > 0 && !artifact.equals(terminatingArtifact) &&
  342                   !dm.getParents(artifact).contains(artifact) && !dm.getChildren(artifact).contains(artifact)) {
  343                   // Keep processing parents (as long as no circular dependencies)
  344                   processParents(dm.getParents(artifact), terminatingArtifact);
  345                   // Move self 
  346                   IModule[] module = getModule(artifact);
  347                   int moduleDeltaKind = getDeltaKind(artifact);
  348                   if (module!=null && !reorderedModules.contains(module)) {
  349                       reorderedModules.add(module);
  350                       reorderedKinds.add(moduleDeltaKind);
  351                   }
  352               }
  353               else {
  354                   // Move parent
  355                   IModule[] module = getModule(artifact);
  356                   int moduleDeltaKind = getDeltaKind(artifact);
  357                   if (module!=null && !reorderedModules.contains(module)) {
  358                       reorderedModules.add(module);
  359                       reorderedKinds.add(moduleDeltaKind);
  360                   }
  361               }
  362           }
  363   
  364           Trace.tracePoint("Exit ", "DependencyHelper.processParents");
  365       }
  366   
  367   
  368       /**
  369        * Returns the Environment for the given IModule
  370        * 
  371        * @param module IModule to be published
  372        * 
  373        * @return Environment
  374        */
  375       private Environment getEnvironment(IModule module) {
  376           Trace.tracePoint("Enter", "DependencyHelper.getEnvironment", module);
  377   
  378           Environment environment = null;
  379           if (GeronimoUtils.isWebModule(module)) {
  380               if (getWebDeploymentPlan(module) != null) {
  381                   WebApp plan = getWebDeploymentPlan(module).getValue();
  382                   if (plan != null)
  383                       environment = plan.getEnvironment();
  384               }
  385           }
  386           else if (GeronimoUtils.isEjbJarModule(module)) {
  387               if (getOpenEjbDeploymentPlan(module) != null) {
  388                   OpenejbJar plan = getOpenEjbDeploymentPlan(module).getValue();
  389                   if (plan != null)
  390                       environment = plan.getEnvironment();
  391               }
  392           }
  393           else if (GeronimoUtils.isEarModule(module)) {
  394               if (getApplicationDeploymentPlan(module) != null) {
  395                   Application plan = getApplicationDeploymentPlan(module).getValue();
  396                   if (plan != null)
  397                       environment = plan.getEnvironment();
  398               }
  399           }
  400           else if (GeronimoUtils.isRARModule(module)) {
  401               if (getConnectorDeploymentPlan(module) != null) {
  402                   Connector plan = getConnectorDeploymentPlan(module).getValue();
  403                   if (plan != null)
  404                       environment = plan.getEnvironment();
  405               }
  406           }else if (GeronimoUtils.isAppClientModule(module)) {
  407               if (getAppClientDeploymentPlan(module) != null) {
  408                   ApplicationClient plan = getAppClientDeploymentPlan(module).getValue();
  409                   if (plan != null)
  410                       environment = plan.getServerEnvironment();
  411               }
  412           }
  413   
  414           Trace.tracePoint("Exit ", "DependencyHelper.getEnvironment", environment);
  415           return environment;
  416       }
  417   
  418   
  419       /**
  420        * Return the IModule[] for a given artifact
  421        * 
  422        * @param artifact
  423        * 
  424        * @return IModule[]
  425        */
  426       private IModule[] getModule(Artifact artifact) {
  427           Trace.tracePoint("Enter", "DependencyHelper.getModule", artifact);
  428   
  429           for (int ii=0; ii<inputModules.size(); ii++) {
  430               IModule[] module = (IModule[]) inputModules.get(ii);
  431               int moduleDeltaKind = ((Integer)inputDeltaKind.get(ii)).intValue();
  432               Environment environment = getEnvironment(module[0]);
  433               if (environment != null) {
  434                   Artifact moduleArtifact = environment.getModuleId();
  435                   if (artifact.equals(moduleArtifact)) {
  436                       Trace.tracePoint("Exit ", "DependencyHelper.getModule", module);
  437                       return module;
  438                   }
  439               }
  440           }
  441   
  442           Trace.tracePoint("Exit ", "DependencyHelper.getModule", null);
  443           return null;
  444       }
  445   
  446   
  447       /**
  448        * Return the deltaKind array index for a given artifact
  449        * 
  450        * @param artifact
  451        * 
  452        * @return int
  453        */
  454       private int getDeltaKind(Artifact artifact) {
  455           Trace.tracePoint("Enter", "DependencyHelper.getDeltaKind", artifact);
  456   
  457           for (int ii=0; ii<inputModules.size(); ii++) {
  458               IModule[] module = (IModule[]) inputModules.get(ii);
  459               int moduleDeltaKind = ((Integer)inputDeltaKind.get(ii)).intValue();
  460               Environment environment = getEnvironment(module[0]);
  461               if (environment != null) {
  462                   Artifact moduleArtifact = environment.getModuleId();
  463                   if (artifact.equals(moduleArtifact)) {
  464                       Trace.tracePoint("Exit ", "DependencyHelper.getDeltaKind", moduleDeltaKind);
  465                       return moduleDeltaKind;
  466                   }
  467               }
  468           }
  469           Trace.tracePoint("Exit ", "DependencyHelper.getDeltaKind", 0);
  470           return 0;
  471       }
  472   
  473   
  474       /**
  475        * Returns the WebApp for the given IModule
  476        * 
  477        * @param module IModule to be published
  478        * 
  479        * @return WebApp
  480        */
  481       private JAXBElement<WebApp> getWebDeploymentPlan(IModule module) {
  482           Trace.tracePoint("Enter", "DependencyHelper.getWebDeploymentPlan", module);
  483   
  484           IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
  485           IFile file = GeronimoUtils.getWebDeploymentPlanFile(comp);
  486           if (file.getName().equals(GeronimoUtils.WEB_PLAN_NAME) && file.exists()) {
  487               try {
  488   				Trace.tracePoint("Exit ", "DependencyHelper.getWebDeploymentPlan", JAXBUtils.unmarshalFilterDeploymentPlan(file));
  489   				 return JAXBUtils.unmarshalFilterDeploymentPlan(file);
  490   			} catch (Exception e) {
  491   				//ignore it, just indicate error by returning null
  492   			}
  493              
  494           }
  495   
  496           Trace.tracePoint("Exit ", "DependencyHelper.getWebDeploymentPlan", null);
  497           return null;
  498       }
  499   
  500   
  501       /**
  502        * Returns the OpenEjbJar for the given IModule
  503        * 
  504        * @param module IModule to be published
  505        * 
  506        * @return OpenEjbJar
  507        */
  508       private JAXBElement<OpenejbJar> getOpenEjbDeploymentPlan(IModule module) {
  509           Trace.tracePoint("Enter", "DependencyHelper.getOpenEjbDeploymentPlan", module);
  510   
  511           IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
  512           IFile file = GeronimoUtils.getOpenEjbDeploymentPlanFile(comp);
  513           if (file.getName().equals(GeronimoUtils.OPENEJB_PLAN_NAME) && file.exists()) {
  514               try {
  515   				Trace.tracePoint("Exit ", "DependencyHelper.getOpenEjbDeploymentPlan", JAXBUtils.unmarshalFilterDeploymentPlan(file));
  516   			} catch (Exception e) {
  517   				//ignore it, just indicate error by returning null
  518   			}
  519               try {
  520   				return JAXBUtils.unmarshalFilterDeploymentPlan(file);
  521   			} catch (Exception e) {
  522   				//ignore it, just indicate error by returning null
  523   			}
  524           }
  525   
  526           Trace.tracePoint("Exit ", "DependencyHelper.getOpenEjbDeploymentPlan", null);
  527           return null;
  528       }
  529   
  530       /**
  531        * Returns the ApplicationClient for the given IModule
  532        * 
  533        * @param module IModule to be published
  534        * 
  535        * @return ApplicationClient
  536        */
  537       private JAXBElement<ApplicationClient> getAppClientDeploymentPlan(IModule module) {
  538           Trace.tracePoint("Enter", "DependencyHelper.getWebDeploymentPlan", module);
  539   
  540           IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
  541           IFile file = GeronimoUtils.getApplicationClientDeploymentPlanFile(comp);
  542           if (file.getName().equals(GeronimoUtils.APP_CLIENT_PLAN_NAME) && file.exists()) {
  543               try {
  544   				Trace.tracePoint("Exit ", "DependencyHelper.getWebDeploymentPlan", JAXBUtils.unmarshalFilterDeploymentPlan(file));
  545   				 return JAXBUtils.unmarshalFilterDeploymentPlan(file);
  546   			} catch (Exception e) {
  547   				//ignore it, just indicate error by returning null
  548   			}
  549              
  550           }
  551   
  552           Trace.tracePoint("Exit ", "DependencyHelper.getWebDeploymentPlan", null);
  553           return null;
  554       }
  555       
  556       /**
  557        * Returns the Application for the given IModule
  558        * 
  559        * @param module IModule to be published
  560        * 
  561        * @return Application
  562        */
  563       private JAXBElement<Application> getApplicationDeploymentPlan(IModule module) {
  564           Trace.tracePoint("Enter", "DependencyHelper.getApplicationDeploymentPlan", module);
  565   
  566           IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
  567           IFile file = GeronimoUtils.getApplicationDeploymentPlanFile(comp);
  568           if (file.getName().equals(GeronimoUtils.APP_PLAN_NAME) && file.exists()) {
  569               try {
  570   				Trace.tracePoint("Exit ", "DependencyHelper.getApplicationDeploymentPlan", JAXBUtils.unmarshalFilterDeploymentPlan(file));
  571   				  return JAXBUtils.unmarshalFilterDeploymentPlan(file);
  572   			} catch (Exception e) {
  573   				//ignore it, just indicate error by returning null
  574   			}
  575             
  576           }
  577   
  578           Trace.tracePoint("Exit ", "DependencyHelper.getApplicationDeploymentPlan", null);
  579           return null;
  580       }
  581   
  582   
  583       /**
  584        * Returns the Connector for the given IModule
  585        * 
  586        * @param module IModule to be published
  587        * 
  588        * @return Application
  589        */
  590       private JAXBElement<Connector> getConnectorDeploymentPlan(IModule module) {
  591           Trace.tracePoint("Enter", "DependencyHelper.getConnectorDeploymentPlan", module);
  592   
  593           IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
  594           IFile file = GeronimoUtils.getConnectorDeploymentPlanFile(comp);
  595           if (file.getName().equals(GeronimoUtils.CONNECTOR_PLAN_NAME) && file.exists()) {
  596               try {
  597   				Trace.tracePoint("Exit ", "DependencyHelper.getConnectorDeploymentPlan", JAXBUtils.unmarshalFilterDeploymentPlan(file));
  598   				 return JAXBUtils.unmarshalFilterDeploymentPlan(file);
  599   			} catch (Exception e) {
  600   				//ignore it, just indicate error by returning null
  601   			}
  602              
  603           }
  604   
  605           Trace.tracePoint("Exit ", "DependencyHelper.getConnectorDeploymentPlan", null);
  606           return null;
  607       }
  608   
  609   
  610       /**
  611        * Process the parents for a given artifact. The terminatingArtifact parameter will be used as
  612        * the terminating condition to ensure there will not be an infinite loop (i.e., if
  613        * terminatingArtifact is encountered again there is a circular dependency).
  614        * 
  615        * @param parents
  616        * @param terminatingArtifact
  617        */
  618       private void processJaxbParents(Set parents, Artifact terminatingArtifact) {
  619           Trace.tracePoint("Enter", "DependencyHelper.processJaxbParents", parents, terminatingArtifact );
  620   
  621           if (parents == null) {
  622               Trace.tracePoint("Exit ", "DependencyHelper.processJaxbParents", null);
  623               return;
  624           }
  625           for (Iterator ii = parents.iterator(); ii.hasNext();) {
  626               Artifact artifact = (Artifact)ii.next();
  627               if (dm.getParents(artifact).size() > 0 && !artifact.equals(terminatingArtifact) &&
  628                   !dm.getParents(artifact).contains(artifact) && !dm.getChildren(artifact).contains(artifact)) {
  629                   // Keep processing parents (as long as no circular dependencies)
  630                   processJaxbParents(dm.getParents(artifact), terminatingArtifact);
  631                   // Move self 
  632                   JAXBElement jaxbElement = getJaxbElement(artifact);
  633                   if (jaxbElement != null) {
  634                       if (!reorderedJAXBElements.contains(jaxbElement)) {
  635                           reorderedJAXBElements.add(jaxbElement);
  636                       }
  637                   }
  638               }
  639               else {
  640                   // Move parent
  641                   JAXBElement jaxbElement = getJaxbElement(artifact);
  642                   if (jaxbElement != null) {
  643                       if (!reorderedJAXBElements.contains(jaxbElement)) {
  644                           reorderedJAXBElements.add(jaxbElement);
  645                       }
  646                   }
  647               }
  648           }
  649   
  650           Trace.tracePoint("Exit ", "DependencyHelper.processJaxbParents");
  651       }
  652   
  653   
  654       /**
  655        * Returns the Environment for the given JAXBElement plan
  656        * 
  657        * @param jaxbElement JAXBElement plan
  658        * 
  659        * @return Environment
  660        */
  661       private Environment getEnvironment(JAXBElement jaxbElement) {
  662           Trace.tracePoint("Enter", "DependencyHelper.getEnvironment", jaxbElement);
  663   
  664           Environment environment = null;
  665           Object plan = jaxbElement.getValue();
  666           if (plan != null) {
  667               if (WebApp.class.isInstance(plan)) {
  668                   environment = ((WebApp)plan).getEnvironment();
  669               }
  670               else if (OpenejbJar.class.isInstance(plan)) {
  671                   environment = ((OpenejbJar)plan).getEnvironment();
  672               }
  673               else if (Application.class.isInstance(plan)) {
  674                   environment = ((Application)plan).getEnvironment();
  675               }
  676               else if (Connector.class.isInstance(plan)) {
  677                   environment = ((Connector)plan).getEnvironment();
  678               }
  679           }
  680   
  681           Trace.tracePoint("Exit ", "DependencyHelper.getEnvironment", environment);
  682           return environment;
  683       }
  684   
  685   
  686       /**
  687        * Return the JAXBElement for a given artifact
  688        * 
  689        * @param artifact
  690        * 
  691        * @return JAXBElement
  692        */
  693       private JAXBElement getJaxbElement(Artifact artifact) {
  694           Trace.tracePoint("Enter", "DependencyHelper.getJaxbElement", artifact);
  695   
  696           for (JAXBElement jaxbElement : inputJAXBElements) {
  697               Environment environment = getEnvironment(jaxbElement);
  698               if (environment != null) {
  699                   Artifact jaxbArtifact = environment.getModuleId();
  700                   if (artifact.equals(jaxbArtifact)) {
  701                       Trace.tracePoint("Exit ", "DependencyHelper.getJaxbElement", jaxbElement);
  702                       return jaxbElement;
  703                   }
  704               }
  705           }
  706   
  707           // TODO: Query the server searching for missing dependencies
  708           Trace.tracePoint("Exit ", "DependencyHelper.getJaxbElement", null);
  709           return null;
  710       }
  711   }

Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.core.internal » [javadoc | source]