View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package org.apache.geronimo.naming.deployment;
20  
21  import java.net.URI;
22  import java.net.URL;
23  import java.util.HashMap;
24  import java.util.HashSet;
25  import java.util.Iterator;
26  import java.util.Map;
27  import java.util.Set;
28  
29  import org.apache.geronimo.common.DeploymentException;
30  import org.apache.geronimo.gbean.AbstractNameQuery;
31  import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
32  import org.apache.geronimo.kernel.repository.Artifact;
33  import org.apache.geronimo.xbeans.geronimo.naming.GerGbeanLocatorType;
34  import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
35  import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType;
36  import org.apache.geronimo.xbeans.j2ee.ResourceRefType;
37  
38  /**
39   * @version $Rev:385232 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
40   */
41  public class ENCConfigBuilder {
42  
43      public static AbstractNameQuery getGBeanQuery(String j2eeType, GerGbeanLocatorType gerGbeanLocator) {
44          AbstractNameQuery abstractNameQuery;
45          if (gerGbeanLocator.isSetGbeanLink()) {
46              //exact match
47              String linkName = gerGbeanLocator.getGbeanLink().trim();
48              abstractNameQuery = buildAbstractNameQuery(null, null, linkName, j2eeType, null);
49  
50          } else {
51              GerPatternType patternType = gerGbeanLocator.getPattern();
52              //construct name from components
53              abstractNameQuery = buildAbstractNameQuery(patternType, j2eeType, null, null);
54          }
55          //TODO check that the query is satisfied.
56          return abstractNameQuery;
57      }
58  
59      public static AbstractNameQuery buildAbstractNameQuery(GerPatternType pattern, String type, String moduleType, Set interfaceTypes) {
60          String groupId = pattern.isSetGroupId() ? pattern.getGroupId().trim() : null;
61          String artifactid = pattern.isSetArtifactId() ? pattern.getArtifactId().trim() : null;
62          String version = pattern.isSetVersion() ? pattern.getVersion().trim() : null;
63          String module = pattern.isSetModule() ? pattern.getModule().trim() : null;
64          String name = pattern.getName().trim();
65  
66          Artifact artifact = artifactid != null ? new Artifact(groupId, artifactid, version, "car") : null;
67          Map nameMap = new HashMap();
68          nameMap.put("name", name);
69          if (type != null) {
70              nameMap.put("j2eeType", type);
71          }
72          if (module != null && moduleType != null) {
73              nameMap.put(moduleType, module);
74          }
75          if(interfaceTypes != null) {
76              Set trimmed = new HashSet();
77              for (Iterator it = interfaceTypes.iterator(); it.hasNext();) {
78                  String intf = (String) it.next();
79                  trimmed.add(intf == null ? null : intf.trim());
80              }
81              interfaceTypes = trimmed;
82          }
83          return new AbstractNameQuery(artifact, nameMap, interfaceTypes);
84      }
85  
86      public static AbstractNameQuery buildAbstractNameQuery(Artifact configId, String module, String name, String type, String moduleType) {
87          Map nameMap = new HashMap();
88          nameMap.put("name", name);
89          if (type != null) {
90              nameMap.put("j2eeType", type);
91          }
92          if (module != null) {
93              nameMap.put(moduleType, module);
94          }
95          return new AbstractNameQuery(configId, nameMap);
96      }
97  
98  }