1 23 package com.sun.appserv.management.util.jmx; 24 25 import java.util.Set ; 26 import java.util.Map ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 30 import com.sun.appserv.management.util.misc.GSetUtil; 31 32 37 public class AttributeNameManglerImpl implements AttributeNameMangler 38 { 39 private final Map <String ,String > mOverrides; 40 private final boolean mCapitalizeFirstLetter; 41 42 46 public 47 AttributeNameManglerImpl( 48 final boolean capitalizeFirstLetter, 49 final Map <String ,String > overrides ) 50 { 51 mCapitalizeFirstLetter = capitalizeFirstLetter; 52 mOverrides = overrides; 53 } 54 55 56 private String 57 convertOverride( final String name ) 58 { 59 String result = name; 60 61 if ( mOverrides != null ) 62 { 63 if ( mOverrides.containsKey( name ) ) 64 { 65 result = (String )mOverrides.get( name ); 66 } 67 84 } 85 86 return( result ); 87 } 88 89 public String 90 mangleAttributeName( final String attributeName ) 91 { 92 String result = mangleIt( attributeName ); 93 94 return( result ); 95 } 96 97 private String 98 toUpperCase( final char c ) 99 { 100 return( ("" + c).toUpperCase() ); 101 } 102 103 109 private String 110 mangleIt( final String attributeName ) 111 { 112 final char[] chars = attributeName.toCharArray(); 113 final StringBuffer buf = new StringBuffer (); 114 115 final char firstChar = chars[ 0 ]; 117 if ( Character.isJavaIdentifierPart( firstChar ) ) 118 { 119 buf.append( mCapitalizeFirstLetter ? toUpperCase( firstChar ) : "" + firstChar ); 120 } 121 123 for( int i = 1; i < chars.length; ++i ) 124 { 125 final char c = chars[ i ]; 126 127 if ( ! Character.isJavaIdentifierPart( c ) ) 128 { 129 ++i; 131 final char nextChar = (i < chars.length) ? chars[ i ] : 0; 132 133 if ( nextChar >= 'a' && nextChar <= 'z' ) 134 { 135 buf.append( toUpperCase( chars[ i ] ) ); 136 } 137 else if ( nextChar >= 'A' && nextChar <= 'Z' ) 138 { 139 buf.append( "" + chars[ i ] ); 140 } 141 else 142 { 143 --i; 145 } 146 } 147 else 148 { 149 buf.append( c ); 150 } 151 } 152 153 final String before = buf.toString(); 154 final String result = convertOverride( before ); 155 156 return( result ); 157 } 158 } 159 | Popular Tags |