1 23 24 29 package com.sun.enterprise.management.config; 30 31 import java.util.Set ; 32 import java.util.HashSet ; 33 import java.util.Iterator ; 34 import java.util.Map ; 35 import java.util.HashMap ; 36 import java.util.Properties ; 37 import java.util.Collections ; 38 39 import javax.management.AttributeList ; 40 import javax.management.ObjectName ; 41 42 import com.sun.appserv.management.base.Util; 43 import com.sun.appserv.management.config.ConfigConfig; 44 import com.sun.appserv.management.util.misc.MapUtil; 45 import com.sun.appserv.management.util.jmx.JMXUtil; 46 47 import com.sun.enterprise.management.support.oldconfig.OldClustersMBean; 48 49 final class ClusterConfigFactory extends ConfigFactory 50 { 51 private final OldClustersMBean mOldClustersMBean; 52 53 public 54 ClusterConfigFactory( 55 final ConfigFactoryCallback callbacks ) 56 { 57 super( callbacks ); 58 59 mOldClustersMBean = getOldConfigProxies().getOldClustersMBean(); 60 } 61 62 protected ObjectName 63 createOldChildConfig( 64 final AttributeList translatedAttrs, 65 final Properties props ) 66 { 67 final Map <String ,String > m = JMXUtil.attributeListToStringMap( translatedAttrs ); 70 71 final String config = (String )m.get( "config-ref" ); 72 final String name = (String )m.get( "name" ); 73 74 return mOldClustersMBean.createCluster( name, config, props ); 75 } 76 77 private final static String REFERENCED_CONFIG_NAME = "ReferencedConfigName"; 78 79 protected Map <String ,String > 80 getParamNameOverrides() 81 { 82 return( MapUtil.newMap( REFERENCED_CONFIG_NAME, "config-ref" ) ); 83 } 84 85 private void 86 checkConfigExists( final String configName ) 87 { 88 final Map <String ,ConfigConfig> configs = getDomainConfig().getConfigConfigMap(); 89 90 if( ! configs.keySet().contains( configName ) ) 91 { 92 throw new IllegalArgumentException ( "No ConfigConfig exists with the name: " + configName ); 93 } 94 } 95 96 private boolean 97 clusterExists( final String name ) 98 { 99 return getDomainConfig().getClusterConfigMap().keySet().contains( name ); 100 } 101 102 public ObjectName 103 create( 104 final String name, 105 final String configName, 106 final Map <String ,String > optional ) 107 { 108 if ( configName != null ) 109 { 110 checkNonEmptyString( configName, "configName" ); 111 checkConfigExists( configName ); 112 113 if ( configName.equals( "server-config" ) || configName.equals( "default-config" ) ) 115 { 116 throw new IllegalArgumentException ( configName ); 117 } 118 } 119 120 if ( clusterExists( name ) ) 121 { 122 throw new IllegalArgumentException ( "Cluster already exists: " + quote( name ) ); 123 } 124 125 126 final String [] requiredParams = 127 { 128 "ReferencedConfigName", configName, 129 }; 130 131 final Map <String ,String > params = initParams( name, requiredParams, optional ); 132 133 return createNamedChild( name, params ); 134 } 135 136 public ObjectName 138 create( 139 final String name, 140 final Map <String ,String > optional ) 141 { 142 return create( name, null, optional ); 143 } 144 145 protected void internalRemove(final ObjectName objectName){ 146 final String name = Util.getName(objectName); 147 if ( ! clusterExists( name ) ) 148 { 149 throw new IllegalArgumentException ( "No such cluster: " + quote( name ) ); 150 } 151 mOldClustersMBean.deleteCluster(name); 152 } 153 } 154 155 156 157 158 159 | Popular Tags |