1 15 package org.apache.hivemind.management.impl; 16 17 import java.beans.PropertyEditorManager ; 18 19 import javax.management.MalformedObjectNameException ; 20 import javax.management.ObjectName ; 21 22 import org.apache.hivemind.ApplicationRuntimeException; 23 import org.apache.hivemind.internal.ServicePoint; 24 import org.apache.hivemind.management.ObjectNameBuilder; 25 import org.apache.hivemind.util.IdUtils; 26 27 37 public class ObjectNameBuilderImpl implements ObjectNameBuilder 38 { 39 private String _domain = "hivemind"; 40 41 static 42 { 43 PropertyEditorManager.registerEditor(ObjectName .class, ObjectNameEditor.class); 51 } 52 53 56 protected ObjectName createObjectNameInstance(String name) 57 { 58 ObjectName objectName; 59 try 60 { 61 objectName = new ObjectName (name); 62 } 63 catch (MalformedObjectNameException e) 64 { 65 throw new ApplicationRuntimeException(e); 67 } 68 return objectName; 69 70 } 71 72 78 public ObjectName createObjectName(String [] keys, String [] values) 79 { 80 if (keys.length != values.length) 81 throw new IllegalArgumentException ("Arrays keys and values must have same length"); 82 StringBuffer sb = new StringBuffer (); 83 sb.append(_domain + ':'); 84 for (int i = 0; i < values.length; i++) 85 { 86 if (i > 0) 87 sb.append(","); 88 sb.append(keys[i]); 89 sb.append("="); 90 sb.append(values[i]); 91 } 92 return createObjectNameInstance(sb.toString()); 93 } 94 95 99 public ObjectName createObjectName(String qualifiedId, String type) 100 { 101 String moduleId = IdUtils.extractModule(qualifiedId); 102 if (moduleId == null) 103 moduleId = "(default package)"; 104 String id = IdUtils.stripModule(qualifiedId); 105 return createObjectName(moduleId, id, type); 106 } 107 108 112 public ObjectName createObjectName(String moduleId, String id, String type) 113 { 114 return createObjectName(new String [] 115 { "module", "type", "id" }, new String [] 116 { moduleId, type, id }); 117 } 118 119 122 public ObjectName createServiceObjectName(ServicePoint servicePoint) 123 { 124 return createObjectName(servicePoint.getExtensionPointId(), "service"); 125 } 126 127 131 public ObjectName createServiceDecoratorName(ServicePoint servicePoint, String decoratorType) 132 { 133 return createObjectName(new String [] 134 { "module", "type", "id", "decorator" }, new String [] 135 { servicePoint.getModule().getModuleId(), "service", 136 IdUtils.stripModule(servicePoint.getExtensionPointId()), decoratorType }); 137 } 138 139 public String getDomain() 140 { 141 return _domain; 142 } 143 144 public void setDomain(String domain) 145 { 146 _domain = domain; 147 } 148 149 } | Popular Tags |