1 23 24 package com.sun.enterprise.admin.mbeans; 25 26 import com.sun.enterprise.admin.dottedname.*; 27 28 import javax.management.MBeanServerConnection ; 29 import javax.management.Attribute ; 30 import javax.management.ObjectName ; 31 import java.util.Arrays ; 32 33 41 44 public class DottedNameGetSetForConfig extends DottedNameGetSetMBeanBase 45 { 46 final DottedNameResolverForAliases mResolver; 47 final DottedNameQuery mQuery; 48 49 50 public DottedNameGetSetForConfig( 51 final MBeanServerConnection conn, 52 final DottedNameRegistry registry, 53 final DottedNameServerInfo serverInfo ) 54 { 55 super( conn, registry, serverInfo ); 56 57 mResolver = new DottedNameResolverForAliases( registry, serverInfo ); 59 60 mQuery = new DottedNameAliasedQuery( registry, serverInfo ); 61 } 62 63 64 65 protected DottedNameResolver 66 getResolver( ) 67 { 68 return( mResolver ); 69 } 70 71 public Object [] dottedNameSet( final String [] nameValuePairs ) 72 { 73 final int numItems = nameValuePairs.length; 74 75 final String [] sortedPairs = new String [ numItems ]; 79 for( int i = 0; i < numItems; ++i ) 80 { 81 sortedPairs[ i ] = nameValuePairs[ i ]; 82 } 83 Arrays.sort( sortedPairs ); 84 85 86 final Object [] results = new Object [ sortedPairs.length ]; 87 for( int i = 0; i < numItems; ++i ) 88 { 89 results[ i ] = dottedNameSet( sortedPairs[ i ] ); 90 } 91 92 return( results ); 93 } 94 95 98 protected Object dottedNameSet( final String nameValuePair ) 99 { 100 Object result = null; 101 102 try 103 { 104 result = doSet( nameValuePair ); 105 } 106 catch( Exception e ) 107 { 108 logException( e ); 110 result = e; 111 } 112 113 assert( result != null ); 114 return( result ); 115 } 116 117 public Attribute 118 doSet( String pair ) 119 throws Exception 120 { 121 final int delimIndex = pair.indexOf( ASSIGNMENT_DELIM ); 122 final boolean delete = delimIndex < 0; 123 124 final String dottedNameString = delete ? pair : pair.substring( 0, delimIndex ); 127 final String valueString = delete ? null : pair.substring( delimIndex + 1, pair.length() ); 128 129 final Attribute attr = doSet( dottedNameString, valueString ); 130 131 return( attr ); 132 } 133 134 135 public Attribute 136 doSet( String dottedNameString, String value ) 137 throws Exception 138 { 139 final DottedName dn = getDottedName( dottedNameString ); 141 142 if ( dn.isWildcardName() ) 143 { 144 final String msg = DottedNameStrings.getString( 145 DottedNameStrings.WILDCARD_DISALLOWED_FOR_SET_KEY, 146 dottedNameString ); 147 148 throw new IllegalArgumentException ( msg ); 149 } 150 151 ObjectName target = null; 152 final DottedNameForValue dnv = new DottedNameForValue( dn ); 153 if ( isDottedNameForServerName( dnv.getPrefix(), dnv.getValueName() ) ) 154 { 155 target = getRegistry().dottedNameToObjectName( dnv.getPrefix().toString() ); 158 } 159 else 160 { 161 target = getTarget( dnv, getResolver( ) ); 162 } 163 164 final Attribute inAttr = new Attribute ( dnv.getValueName(), value ); 165 166 Attribute resultAttr = mValueAccessor.setValue( target, inAttr ); 167 168 if ( resultAttr != null && resultAttr.getValue() != null ) 171 { 172 final String fullName = dnv.getPrefix() + "." + inAttr.getName(); 173 174 resultAttr = new Attribute ( fullName, resultAttr.getValue() ); 175 } 176 177 return( resultAttr ); 178 } 179 180 181 protected DottedNameQuery 182 createQuery( ) 183 { 184 return( mQuery ); 185 } 186 187 188 boolean 189 isServerName( String name ) 190 throws DottedNameServerInfo.UnavailableException 191 { 192 boolean isServerName = false; 193 194 isServerName = mServerInfo.getServerNames().contains( name ); 195 196 return( isServerName ); 197 } 198 199 protected boolean 200 isDottedNameForServerName( final DottedName prefix, final String valueName ) 201 throws DottedNameServerInfo.UnavailableException 202 { 203 return( valueName.equals( "name" ) && 204 isServerName( prefix.getScope() ) && prefix.getParts().size() == 0 ); 206 } 207 208 217 protected Attribute 218 formAttribute( final DottedName prefix, final String valueName, Object value ) 219 { 220 Attribute attr = super.formAttribute( prefix, valueName, value ); 222 223 try 224 { 225 if ( isDottedNameForServerName( prefix, valueName ) ) 227 { 228 final ObjectName objectName = getRegistry().dottedNameToObjectName( prefix.getScope() ); 231 232 final Attribute newAttr = mValueAccessor.getValue( objectName, valueName ); 233 assert( newAttr != null ); 234 attr = super.formAttribute( prefix, valueName, newAttr.getValue() ); 235 } 236 } 237 catch( Exception e) 238 { 239 logException( e ); 240 } 241 242 return( attr ); 243 } 244 } 245 | Popular Tags |