1 16 package org.jmanage.core.management; 17 18 import org.jmanage.core.util.JManageProperties; 19 20 import javax.management.MalformedObjectNameException ; 21 import java.util.StringTokenizer ; 22 23 28 public class ObjectName implements java.io.Serializable { 29 30 private final String objectName; 31 private final String canonicalName; 32 33 public ObjectName(String objectName){ 34 this.objectName = objectName; 35 try { 36 this.canonicalName = 37 new javax.management.ObjectName (objectName).getCanonicalName(); 38 } catch (MalformedObjectNameException e) { 39 throw new RuntimeException (e); 40 } catch (NullPointerException e) { 41 throw new RuntimeException (e); 42 } 43 } 44 45 public ObjectName(String objectName, String canonicalName){ 46 this.objectName = objectName; 47 this.canonicalName = canonicalName; 48 } 49 50 public String getCanonicalName(){ 51 return canonicalName; 52 } 53 54 public String toString(){ 55 return objectName; 56 } 57 58 public String getDisplayName(){ 59 return JManageProperties.isDisplayCanonicalName()? 60 canonicalName : objectName; 61 } 62 63 public static String getShortName(String objectName){ 64 String shortName = objectName; 65 if(shortName.length() > 90){ 66 shortName = shortName.substring(0, 90) + "..."; 67 } 68 return shortName; 69 } 70 71 76 public String getShortName(){ 77 return getShortName(getDisplayName()); 78 } 79 80 85 public String getWrappedName(){ 86 String wrappedName = getDisplayName(); 87 if(wrappedName.length() > 80){ 88 StringTokenizer tokenizer = new StringTokenizer (wrappedName, ","); 89 StringBuffer buff = new StringBuffer (wrappedName.length()); 90 int multiplier = 1; 91 while(tokenizer.hasMoreTokens()){ 92 String nextToken = tokenizer.nextToken(); 93 if((buff.length() + nextToken.length()) > 80 * multiplier){ 94 buff.append("\n\t"); 95 multiplier ++; 96 } 97 buff.append(nextToken); 98 if(tokenizer.hasMoreTokens()){ 99 buff.append(","); 100 } 101 } 102 wrappedName = buff.toString(); 103 } 104 return wrappedName; 105 } 106 107 public boolean equals(Object obj){ 108 if(obj instanceof ObjectName){ 109 ObjectName on = (ObjectName)obj; 110 return on.objectName.equals(this.objectName); 111 } 112 return false; 113 } 114 } 115 | Popular Tags |