1 17 package org.apache.geronimo.kernel; 18 19 import java.util.HashMap ; 20 import java.util.Hashtable ; 21 import java.util.Map ; 22 import java.util.Arrays ; 23 24 import javax.management.MalformedObjectNameException ; 25 import javax.management.ObjectName ; 26 27 import org.apache.geronimo.gbean.AbstractName; 28 import org.apache.geronimo.kernel.repository.Artifact; 29 30 33 public class Jsr77Naming extends Naming { 34 private static final String DEFAULT_DOMAIN_NAME = "geronimo"; 35 private static final String DEFAULT_SERVER_NAME = "geronimo"; 36 private static final String J2EE_TYPE = "j2eeType"; 37 private static final String J2EE_NAME = "name"; 38 private static final String INVALID_GENERIC_PARENT_TYPE = "GBean"; 39 40 public Jsr77Naming() { 41 } 42 43 public AbstractName createRootName(Artifact artifact, String name, String type) { 44 Map nameMap = new HashMap (); 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 name, String type) { 54 return createChildName(parentAbstractName, parentAbstractName.getArtifact(), name, type); 55 } 56 57 public AbstractName createSiblingName(AbstractName parentAbstractName, String name, String type) { 58 Map nameMap = new HashMap (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 name, String type) { 69 Map nameMap = new HashMap (parentAbstractName.getName()); 70 71 String parentType = (String ) nameMap.remove(J2EE_TYPE); 72 String parentName = (String ) nameMap.remove(J2EE_NAME); 73 if (INVALID_GENERIC_PARENT_TYPE.equals(parentType)) { 74 throw new IllegalArgumentException ("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 88 public static ObjectName createObjectName(Map nameMap) { 89 Hashtable objectNameMap = new Hashtable (nameMap); 90 String type = (String ) nameMap.get(J2EE_TYPE); 91 if ("JVM".equals(type)) { 92 objectNameMap.keySet().retainAll(Arrays.asList(new String [] {J2EE_TYPE, J2EE_NAME, "J2EEServer"})); 93 objectNameMap.put("J2EEServer", DEFAULT_SERVER_NAME); 94 } else if ("J2EEDomain".equals(type)) { 95 objectNameMap.clear(); 97 objectNameMap.put(J2EE_TYPE, "J2EEDomain"); 98 objectNameMap.put(J2EE_NAME, DEFAULT_DOMAIN_NAME); 99 } else if ("J2EEServer".equals(type)) { 100 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 moduleObjectName; 109 try { 110 moduleObjectName = ObjectName.getInstance(DEFAULT_DOMAIN_NAME, objectNameMap); 111 } catch (MalformedObjectNameException e) { 112 throw new AssertionError (e); 113 } 114 return moduleObjectName; 115 } 116 117 } 118 | Popular Tags |