Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.naming.deployment » [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.naming.deployment;
   19   
   20   import java.util.HashMap;
   21   import java.util.HashSet;
   22   import java.util.Iterator;
   23   import java.util.Map;
   24   import java.util.Set;
   25   
   26   import org.apache.geronimo.gbean.AbstractNameQuery;
   27   import org.apache.geronimo.kernel.repository.Artifact;
   28   import org.apache.geronimo.xbeans.geronimo.naming.GerGbeanLocatorType;
   29   import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
   30   
   31   /**
   32    * @version $Rev:385232 $ $Date: 2008-01-03 11:35:04 -0800 (Thu, 03 Jan 2008) $
   33    */
   34   public class ENCConfigBuilder {
   35   
   36       public static AbstractNameQuery getGBeanQuery(String j2eeType, GerGbeanLocatorType gerGbeanLocator) {
   37           AbstractNameQuery abstractNameQuery;
   38           if (gerGbeanLocator.isSetGbeanLink()) {
   39               //exact match
   40               String linkName = gerGbeanLocator.getGbeanLink().trim();
   41               abstractNameQuery = buildAbstractNameQuery(null, null, linkName, j2eeType, null);
   42   
   43           } else {
   44               GerPatternType patternType = gerGbeanLocator.getPattern();
   45               //construct name from components
   46               abstractNameQuery = buildAbstractNameQuery(patternType, j2eeType, null, null);
   47           }
   48           //TODO check that the query is satisfied.
   49           return abstractNameQuery;
   50       }
   51   
   52       public static AbstractNameQuery buildAbstractNameQuery(GerPatternType pattern, String type, String moduleType, Set interfaceTypes) {
   53           return buildAbstractNameQueryFromPattern(pattern, "car", type, moduleType, interfaceTypes);
   54       }
   55       
   56       public static AbstractNameQuery buildAbstractNameQueryFromPattern(GerPatternType pattern, String artifactType, String type, String moduleType, Set interfaceTypes)  {
   57           String groupId = pattern.isSetGroupId() ? pattern.getGroupId().trim() : null;
   58           String artifactid = pattern.isSetArtifactId() ? pattern.getArtifactId().trim() : null;
   59           String version = pattern.isSetVersion() ? pattern.getVersion().trim() : null;
   60           String module = pattern.isSetModule() ? pattern.getModule().trim() : null;
   61           String name = pattern.getName().trim();
   62   
   63           Artifact artifact = artifactid != null ? new Artifact(groupId, artifactid, version, artifactType) : null;
   64           Map nameMap = new HashMap();
   65           nameMap.put("name", name);
   66           if (type != null) {
   67               nameMap.put("j2eeType", type);
   68           }
   69           if (module != null && moduleType != null) {
   70               nameMap.put(moduleType, module);
   71           }
   72           if (interfaceTypes != null) {
   73               Set trimmed = new HashSet();
   74               for (Iterator it = interfaceTypes.iterator(); it.hasNext();) {
   75                   String intf = (String) it.next();
   76                   trimmed.add(intf == null ? null : intf.trim());
   77               }
   78               interfaceTypes = trimmed;
   79           }
   80           return new AbstractNameQuery(artifact, nameMap, interfaceTypes);
   81       }
   82   
   83       public static AbstractNameQuery buildAbstractNameQuery(Artifact configId, String module, String name, String type, String moduleType) {
   84           Map nameMap = new HashMap();
   85           nameMap.put("name", name);
   86           if (type != null) {
   87               nameMap.put("j2eeType", type);
   88           }
   89           if (module != null && moduleType != null) {        
   90               nameMap.put(moduleType, module);
   91           }
   92           return new AbstractNameQuery(configId, nameMap);
   93       }
   94   
   95   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.naming.deployment » [javadoc | source]