KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > kernel > Jsr77Naming


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 package org.apache.geronimo.kernel;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Arrays JavaDoc;
23
24 import javax.management.MalformedObjectNameException JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import org.apache.geronimo.gbean.AbstractName;
28 import org.apache.geronimo.kernel.repository.Artifact;
29
30 /**
31  * @version $Rev: 476457 $ $Date: 2006-11-18 01:49:20 -0500 (Sat, 18 Nov 2006) $
32  */

33 public class Jsr77Naming extends Naming {
34     private static final String JavaDoc DEFAULT_DOMAIN_NAME = "geronimo";
35     private static final String JavaDoc DEFAULT_SERVER_NAME = "geronimo";
36     private static final String JavaDoc J2EE_TYPE = "j2eeType";
37     private static final String JavaDoc J2EE_NAME = "name";
38     private static final String JavaDoc INVALID_GENERIC_PARENT_TYPE = "GBean";
39
40     public Jsr77Naming() {
41     }
42
43     public AbstractName createRootName(Artifact artifact, String JavaDoc name, String JavaDoc type) {
44         Map JavaDoc nameMap = new HashMap JavaDoc();
45         nameMap.put(J2EE_TYPE, type);
46         nameMap.put(J2EE_NAME, name);
47
48         return new AbstractName(artifact,
49                 nameMap,
50                 createObjectName(nameMap));
51     }
52
53     public AbstractName createChildName(AbstractName parentAbstractName, String JavaDoc name, String JavaDoc type) {
54         return createChildName(parentAbstractName, parentAbstractName.getArtifact(), name, type);
55     }
56
57     public AbstractName createSiblingName(AbstractName parentAbstractName, String JavaDoc name, String JavaDoc type) {
58         Map JavaDoc nameMap = new HashMap JavaDoc(parentAbstractName.getName());
59
60         nameMap.put(J2EE_TYPE, type);
61         nameMap.put(J2EE_NAME, name);
62
63         return new AbstractName(parentAbstractName.getArtifact(),
64                 nameMap,
65                 createObjectName(nameMap));
66     }
67
68     public AbstractName createChildName(AbstractName parentAbstractName, Artifact artifact, String JavaDoc name, String JavaDoc type) {
69         Map JavaDoc nameMap = new HashMap JavaDoc(parentAbstractName.getName());
70
71         String JavaDoc parentType = (String JavaDoc) nameMap.remove(J2EE_TYPE);
72         String JavaDoc parentName = (String JavaDoc) nameMap.remove(J2EE_NAME);
73         if (INVALID_GENERIC_PARENT_TYPE.equals(parentType)) {
74             throw new IllegalArgumentException JavaDoc("You can't create a child of a generic typed gbean");
75         }
76         nameMap.put(parentType, parentName);
77         nameMap.put(J2EE_TYPE, type);
78         nameMap.put(J2EE_NAME, name);
79
80         return new AbstractName(artifact,
81                 nameMap,
82                 createObjectName(nameMap));
83     }
84
85     /**
86      * @deprecated objectnames are being removed
87      */

88     public static ObjectName JavaDoc createObjectName(Map JavaDoc nameMap) {
89         Hashtable JavaDoc objectNameMap = new Hashtable JavaDoc(nameMap);
90         String JavaDoc type = (String JavaDoc) nameMap.get(J2EE_TYPE);
91         if ("JVM".equals(type)) {
92             objectNameMap.keySet().retainAll(Arrays.asList(new String JavaDoc[] {J2EE_TYPE, J2EE_NAME, "J2EEServer"}));
93             objectNameMap.put("J2EEServer", DEFAULT_SERVER_NAME);
94         } else if ("J2EEDomain".equals(type)) {
95             //special case J2EEDomain gbean
96
objectNameMap.clear();
97             objectNameMap.put(J2EE_TYPE, "J2EEDomain");
98             objectNameMap.put(J2EE_NAME, DEFAULT_DOMAIN_NAME);
99         } else if ("J2EEServer".equals(type)) {
100             //special case J2EEServer gbean
101
objectNameMap.clear();
102             objectNameMap.put(J2EE_TYPE, "J2EEServer");
103             objectNameMap.put(J2EE_NAME, DEFAULT_SERVER_NAME);
104         } else {
105             objectNameMap.put("J2EEServer", DEFAULT_SERVER_NAME);
106         }
107
108         ObjectName JavaDoc moduleObjectName;
109         try {
110             moduleObjectName = ObjectName.getInstance(DEFAULT_DOMAIN_NAME, objectNameMap);
111         } catch (MalformedObjectNameException JavaDoc e) {
112             throw new AssertionError JavaDoc(e);
113         }
114         return moduleObjectName;
115     }
116
117 }
118
Popular Tags