1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.Set ; 28 import java.io.File ; 29 30 import javax.management.ObjectName ; 31 import javax.management.AttributeList ; 32 33 import com.sun.appserv.management.config.TransformationRuleConfig; 34 import com.sun.appserv.management.config.TransformationRuleConfigKeys; 35 import com.sun.appserv.management.util.misc.GSetUtil; 36 import com.sun.appserv.management.base.Util; 37 import com.sun.enterprise.management.support.oldconfig.OldWebServiceEndpointConfigMBean; 38 import com.sun.enterprise.admin.wsmgmt.WebServiceMgrBackEnd; 39 40 import javax.xml.transform.stream.StreamSource ; 41 import javax.xml.transform.TransformerFactory ; 42 import javax.xml.transform.Transformer ; 43 44 final class TransformationRuleConfigFactory extends ConfigFactory 45 { 46 47 private final OldWebServiceEndpointConfigMBean 48 mOldWebServiceEndpointConfigMBean; 49 50 private TransformerFactory _tFactory; 51 52 public 53 TransformationRuleConfigFactory( 54 final ConfigFactoryCallback callbacks ) 55 { 56 super( callbacks ); 57 58 _tFactory = TransformerFactory.newInstance(); 59 60 mOldWebServiceEndpointConfigMBean = 61 getOldWebServiceEndpointConfigMBean(); 62 } 63 64 private final OldWebServiceEndpointConfigMBean 65 getOldWebServiceEndpointConfigMBean() 66 { 67 final String name = getFactoryContainer().getName(); 68 return getOldConfigProxies().getOldWebServiceEndpointConfigMBean( name ); 69 70 } 71 72 75 protected ObjectName 76 createOldChildConfig( 77 final AttributeList translatedAttrs ) 78 { 79 final ObjectName oldObjectName = (ObjectName ) 80 getCallbacks().getDelegate().invoke( 81 CREATE_TRANSFORMATION_RULE, new Object [] { translatedAttrs }, 82 CREATE_TRANSFORMATION_RULE_SIG ); 83 84 return oldObjectName; 85 86 } 87 88 public ObjectName 89 create( 90 final String name, 91 final String ruleFileLocation, 92 final boolean enabled, 93 final String applyTo, 94 final Map <String ,String > reserved ) 95 { 96 97 String appId = getFactoryContainer().getContainer().getName(); 98 99 String finalRuleFileLocation = null; 100 101 try { 102 StreamSource stylesource = 103 new StreamSource (new File (ruleFileLocation)); 104 Transformer transformer = _tFactory.newTransformer(stylesource); 105 106 finalRuleFileLocation = WebServiceMgrBackEnd.getManager(). 107 moveFileToRepository(ruleFileLocation, appId); 108 } catch (Throwable t) { 109 throw new RuntimeException (t); 110 } 111 112 Map <String ,String > optional = new HashMap <String ,String >(); 113 optional.put(TransformationRuleConfigKeys.ENABLED_KEY, 114 Boolean.toString(enabled)); 115 optional.put(TransformationRuleConfigKeys.APPLY_TO_KEY, applyTo); 116 final String [] requiredParams = new String [] { 117 TransformationRuleConfigKeys.RULE_FILE_LOCATION_KEY, 118 finalRuleFileLocation }; 119 120 if (reserved != null) { 121 optional.putAll(reserved); 122 } 123 124 final Map <String ,String > params = initParams(name, requiredParams, optional); 125 126 trace( "params as processed: " + stringify( params ) ); 127 128 final ObjectName amxName = createChild( params ); 129 130 return( amxName ); 131 } 132 133 protected final void 134 removeByName(String name) 135 { 136 String appId = getFactoryContainer().getContainer().getName(); 137 String epName = getFactoryContainer().getName(); 138 WebServiceMgrBackEnd.getManager(). 139 removeFileFromRepository(appId,epName,name); 140 mOldWebServiceEndpointConfigMBean.removeTransformationRuleByName(name); 141 } 142 143 144 private final Set <String > LEGAL_OPTIONAL_KEYS = 145 GSetUtil.newUnmodifiableStringSet( 146 TransformationRuleConfigKeys.ENABLED_KEY, 147 TransformationRuleConfigKeys.APPLY_TO_KEY); 148 149 protected Set <String > 150 getLegalOptionalCreateKeys() 151 { 152 return( LEGAL_OPTIONAL_KEYS ); 153 } 154 155 private static final String CREATE_TRANSFORMATION_RULE = 156 "createTransformationRule"; 157 private static final String [] CREATE_TRANSFORMATION_RULE_SIG = 158 new String [] { AttributeList .class.getName() }; 159 private static final String REMOVE_TRANSFORMATION_RULE = 160 "removeTransformationRuleByName"; 161 private static final String [] REMOVE_TRANSFORMATION_RULE_SIG = 162 new String [] { String .class.getName() }; 163 164 } 165 166 167 168 169 170 | Popular Tags |