KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > naming > deployment > ENCConfigBuilder


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 JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
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: 2006-11-19 18:55:25 -0500 (Sun, 19 Nov 2006) $
33  */

34 public class ENCConfigBuilder {
35
36     public static AbstractNameQuery getGBeanQuery(String JavaDoc j2eeType, GerGbeanLocatorType gerGbeanLocator) {
37         AbstractNameQuery abstractNameQuery;
38         if (gerGbeanLocator.isSetGbeanLink()) {
39             //exact match
40
String JavaDoc 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 JavaDoc type, String JavaDoc moduleType, Set JavaDoc interfaceTypes) {
53         String JavaDoc groupId = pattern.isSetGroupId() ? pattern.getGroupId().trim() : null;
54         String JavaDoc artifactid = pattern.isSetArtifactId() ? pattern.getArtifactId().trim() : null;
55         String JavaDoc version = pattern.isSetVersion() ? pattern.getVersion().trim() : null;
56         String JavaDoc module = pattern.isSetModule() ? pattern.getModule().trim() : null;
57         String JavaDoc name = pattern.getName().trim();
58
59         Artifact artifact = artifactid != null ? new Artifact(groupId, artifactid, version, "car") : null;
60         Map JavaDoc nameMap = new HashMap JavaDoc();
61         nameMap.put("name", name);
62         if (type != null) {
63             nameMap.put("j2eeType", type);
64         }
65         if (module != null && moduleType != null) {
66             nameMap.put(moduleType, module);
67         }
68         if(interfaceTypes != null) {
69             Set JavaDoc trimmed = new HashSet JavaDoc();
70             for (Iterator JavaDoc it = interfaceTypes.iterator(); it.hasNext();) {
71                 String JavaDoc intf = (String JavaDoc) it.next();
72                 trimmed.add(intf == null ? null : intf.trim());
73             }
74             interfaceTypes = trimmed;
75         }
76         return new AbstractNameQuery(artifact, nameMap, interfaceTypes);
77     }
78
79     public static AbstractNameQuery buildAbstractNameQuery(Artifact configId, String JavaDoc module, String JavaDoc name, String JavaDoc type, String JavaDoc moduleType) {
80         Map JavaDoc nameMap = new HashMap JavaDoc();
81         nameMap.put("name", name);
82         if (type != null) {
83             nameMap.put("j2eeType", type);
84         }
85         if (module != null) {
86             nameMap.put(moduleType, module);
87         }
88         return new AbstractNameQuery(configId, nameMap);
89     }
90
91 }
92
Popular Tags