001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.naming.deployment;
017:
018: import java.util.HashMap;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import org.apache.geronimo.gbean.AbstractNameQuery;
025: import org.apache.geronimo.kernel.repository.Artifact;
026: import org.apache.geronimo.xbeans.geronimo.naming.GerGbeanLocatorType;
027: import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
028:
029: /**
030: * @version $Rev:385232 $ $Date: 2008-01-03 11:35:04 -0800 (Thu, 03 Jan 2008) $
031: */
032: public class ENCConfigBuilder {
033:
034: public static AbstractNameQuery getGBeanQuery(String j2eeType,
035: GerGbeanLocatorType gerGbeanLocator) {
036: AbstractNameQuery abstractNameQuery;
037: if (gerGbeanLocator.isSetGbeanLink()) {
038: //exact match
039: String linkName = gerGbeanLocator.getGbeanLink().trim();
040: abstractNameQuery = buildAbstractNameQuery(null, null,
041: linkName, j2eeType, null);
042:
043: } else {
044: GerPatternType patternType = gerGbeanLocator.getPattern();
045: //construct name from components
046: abstractNameQuery = buildAbstractNameQuery(patternType,
047: j2eeType, null, null);
048: }
049: //TODO check that the query is satisfied.
050: return abstractNameQuery;
051: }
052:
053: public static AbstractNameQuery buildAbstractNameQuery(
054: GerPatternType pattern, String type, String moduleType,
055: Set interfaceTypes) {
056: return buildAbstractNameQueryFromPattern(pattern, "car", type,
057: moduleType, interfaceTypes);
058: }
059:
060: public static AbstractNameQuery buildAbstractNameQueryFromPattern(
061: GerPatternType pattern, String artifactType, String type,
062: String moduleType, Set interfaceTypes) {
063: String groupId = pattern.isSetGroupId() ? pattern.getGroupId()
064: .trim() : null;
065: String artifactid = pattern.isSetArtifactId() ? pattern
066: .getArtifactId().trim() : null;
067: String version = pattern.isSetVersion() ? pattern.getVersion()
068: .trim() : null;
069: String module = pattern.isSetModule() ? pattern.getModule()
070: .trim() : null;
071: String name = pattern.getName().trim();
072:
073: Artifact artifact = artifactid != null ? new Artifact(groupId,
074: artifactid, version, artifactType) : null;
075: Map nameMap = new HashMap();
076: nameMap.put("name", name);
077: if (type != null) {
078: nameMap.put("j2eeType", type);
079: }
080: if (module != null && moduleType != null) {
081: nameMap.put(moduleType, module);
082: }
083: if (interfaceTypes != null) {
084: Set trimmed = new HashSet();
085: for (Iterator it = interfaceTypes.iterator(); it.hasNext();) {
086: String intf = (String) it.next();
087: trimmed.add(intf == null ? null : intf.trim());
088: }
089: interfaceTypes = trimmed;
090: }
091: return new AbstractNameQuery(artifact, nameMap, interfaceTypes);
092: }
093:
094: public static AbstractNameQuery buildAbstractNameQuery(
095: Artifact configId, String module, String name, String type,
096: String moduleType) {
097: Map nameMap = new HashMap();
098: nameMap.put("name", name);
099: if (type != null) {
100: nameMap.put("j2eeType", type);
101: }
102: if (module != null && moduleType != null) {
103: nameMap.put(moduleType, module);
104: }
105: return new AbstractNameQuery(configId, nameMap);
106: }
107:
108: }
|