1 23 package com.sun.enterprise.admin.wsmgmt.lifecycle.reconfig; 24 25 import com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEvent; 26 import com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEventListener; 27 28 import com.sun.enterprise.admin.event.AdminEventListenerException; 29 import com.sun.enterprise.config.ConfigBean; 30 import com.sun.enterprise.config.ConfigContext; 31 import com.sun.enterprise.config.ConfigException; 32 33 import com.sun.enterprise.config.serverbeans.WebServiceEndpoint; 34 import com.sun.enterprise.config.serverbeans.TransformationRule; 35 import com.sun.enterprise.config.serverbeans.J2eeApplication; 36 import com.sun.enterprise.config.serverbeans.WebModule; 37 import com.sun.enterprise.config.serverbeans.EjbModule; 38 39 import com.sun.enterprise.admin.wsmgmt.transform.TransformHandler; 40 import com.sun.enterprise.admin.wsmgmt.transform.TransformFilter; 41 import com.sun.enterprise.admin.wsmgmt.filter.spi.Filter; 42 import com.sun.enterprise.admin.wsmgmt.config.impl.WebServiceConfigImpl; 43 import com.sun.enterprise.admin.wsmgmt.config.spi.Constants; 44 45 49 public class TransformationRuleEventListenerImpl implements 50 TransformationRuleEventListener { 51 52 60 public void handleDelete(TransformationRuleEvent event) 61 throws AdminEventListenerException { 62 handleReconfiguration(event,true, true); 63 } 64 65 private void handleReconfiguration(TransformationRuleEvent event, boolean 66 takeOld, boolean isRemove) 67 throws AdminEventListenerException { 68 try { 69 ConfigBean bean = getTRBean(event, takeOld); 70 if ( bean instanceof TransformationRule ) { 71 TransformationRule tr = (TransformationRule) bean; 72 String appId = getApplicationId(tr); 73 WebServiceConfigImpl wsc = new WebServiceConfigImpl ( 74 (WebServiceEndpoint) tr.parent()); 75 TransformHandler trh = new TransformHandler( wsc , appId); 76 Filter f = trh.getFilter(appId, wsc); 77 TransformFilter tf = null; 78 if ( f != null) { 79 tf = (TransformFilter) f; 80 } 81 ConfigBean newBean = getTRBean(event, false); 82 WebServiceConfigImpl nwsc = null; 83 if ( newBean == null) { 84 if ( ! isRemove) { 85 throw new AdminEventListenerException(); 88 } else { 89 nwsc = wsc; 90 } 91 } else { 92 nwsc = new WebServiceConfigImpl( 93 (WebServiceEndpoint) newBean.parent()); 94 } 95 if ( tf == null) { 96 tf = (TransformFilter) trh.registerFilter(wsc); 98 } else { 99 if ( isRemove) { 100 String applyTo = tr.getApplyTo(); 101 if ( applyTo.equals(Constants.BOTH) || 102 applyTo.equals(Constants.REQUEST)) { 103 com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] rtrs = 104 nwsc.getRequestTransformationRule(); 105 tf.resetRequestChain( pruneList( rtrs, 106 tr.getName())); 107 } 108 if ( applyTo.equals(Constants.BOTH) || 109 applyTo.equals(Constants.RESPONSE)) { 110 com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] rtrs = 111 nwsc.getResponseTransformationRule(); 112 tf.resetResponseChain( pruneList( rtrs, 113 tr.getName())); 114 } 115 } else { 116 tf.resetRequestChain( 117 nwsc.getRequestTransformationRule()); 118 tf.resetResponseChain( 119 nwsc.getResponseTransformationRule()); 120 } 121 } 122 } 123 124 } catch (Exception e) { 125 throw new AdminEventListenerException(e); 126 } 127 } 128 129 130 private com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] 131 pruneList ( 132 com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] tRules, 133 String name) { 134 135 com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] 136 newRules = 137 new com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[ 138 tRules.length-1]; 139 140 int newIndex = 0; 141 for ( int index =0; index < tRules.length; index++) { 142 if ( tRules[index].getName().equals(name)) { 143 } else { 145 if ( newIndex >= tRules.length-1) { 146 throw new RuntimeException (); 149 } 150 newRules[newIndex++] = tRules[index]; 151 } 152 } 153 return newRules; 154 } 155 156 165 public void handleUpdate(TransformationRuleEvent event) 166 throws AdminEventListenerException { 167 168 handleReconfiguration(event,false,false); 169 } 170 171 179 public void handleCreate(TransformationRuleEvent event) 180 throws AdminEventListenerException { 181 182 handleReconfiguration(event,false, false); 183 } 184 185 private ConfigBean getTRBean(TransformationRuleEvent event, boolean old) 186 throws ConfigException { 187 188 if (event == null) { 189 throw new IllegalArgumentException (); 190 } 191 192 ConfigBean bean = null; 193 ConfigContext ctx = null; 194 String xpath = event.getElementXPath(); 195 if (old) { 196 ctx = event.getOldConfigContext(); 197 } else { 198 ctx = event.getConfigContext(); 199 } 200 if (ctx != null) { 201 bean = ctx.exactLookup(xpath); 202 } 203 204 return bean; 205 } 206 207 private String getApplicationId(TransformationRule trBean) { 208 String name = null; 209 210 ConfigBean bean = null; 211 if ( trBean != null) { 212 bean = (ConfigBean) trBean.parent(); 213 if (!( bean instanceof WebServiceEndpoint)) { 214 throw new RuntimeException (); 215 } 216 } 217 218 if (bean != null) { 219 ConfigBean parent = (ConfigBean) bean.parent(); 220 if (parent instanceof J2eeApplication) { 221 J2eeApplication app = (J2eeApplication) parent; 222 name = app.getName(); 223 } else if (parent instanceof WebModule) { 224 WebModule wm = (WebModule) parent; 225 name = wm.getName(); 226 } else if (parent instanceof EjbModule) { 227 EjbModule em = (EjbModule) parent; 228 name = em.getName(); 229 } 230 } 231 return name; 232 } 233 } 234 | Popular Tags |