FileDocCategorySizeDatePackage
TransformationRuleEventListenerImpl.javaAPI DocGlassfish v2 API10090Mon Jul 30 13:51:50 BST 2007com.sun.enterprise.admin.wsmgmt.lifecycle.reconfig

TransformationRuleEventListenerImpl

public class TransformationRuleEventListenerImpl extends Object implements com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEventListener
Listener impl to handle web-service-endpoint/transformation-rule element events.

Fields Summary
Constructors Summary
Methods Summary
private java.lang.StringgetApplicationId(com.sun.enterprise.config.serverbeans.TransformationRule trBean)

        String name = null;

        ConfigBean bean = null;
        if ( trBean != null) {
            bean = (ConfigBean) trBean.parent();
            if (!( bean instanceof WebServiceEndpoint)) {
                throw new RuntimeException();	
            }
        }

        if (bean != null) {
            ConfigBean parent = (ConfigBean) bean.parent();
            if (parent instanceof J2eeApplication) {
                J2eeApplication app = (J2eeApplication) parent;
                name = app.getName();
            } else if (parent instanceof WebModule) {
                WebModule wm = (WebModule) parent;
                name = wm.getName();
            } else if (parent instanceof EjbModule) {
                EjbModule em = (EjbModule) parent;
                name = em.getName();
            }
        }
        return name;
    
private com.sun.enterprise.config.ConfigBeangetTRBean(com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEvent event, boolean old)


        if (event == null) {
            throw new IllegalArgumentException();
        }

        ConfigBean bean = null;
        ConfigContext ctx = null;
        String xpath = event.getElementXPath();
        if (old) {
            ctx = event.getOldConfigContext();
        } else {
            ctx = event.getConfigContext();
        }
        if (ctx != null) {
            bean = ctx.exactLookup(xpath);
        }

        return bean;
    
public voidhandleCreate(com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEvent event)
Handles element additions.

param
event Event to be processed.
throws
AdminEventListenerException when the listener is unable to process the event.


        handleReconfiguration(event,false, false);
    
public voidhandleDelete(com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEvent event)
Handles web-service-endpoint/transformation-rule element removal.

param
event Event to be processed.
throws
AdminEventListenerException when the listener is unable to process the event.

        handleReconfiguration(event,true, true);
    
private voidhandleReconfiguration(com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEvent event, boolean takeOld, boolean isRemove)

       try { 
           ConfigBean bean = getTRBean(event, takeOld);
           if ( bean instanceof TransformationRule ) {
                TransformationRule tr = (TransformationRule) bean;
                String appId = getApplicationId(tr);
                WebServiceConfigImpl wsc = new WebServiceConfigImpl ( 
                    (WebServiceEndpoint) tr.parent());
                TransformHandler trh = new TransformHandler( wsc , appId);
                Filter f = trh.getFilter(appId, wsc);
                TransformFilter tf = null;
                if ( f != null) {
                    tf = (TransformFilter) f;
                }
                ConfigBean newBean = getTRBean(event, false);
                WebServiceConfigImpl nwsc = null;
                if ( newBean == null) {
                       if ( ! isRemove) {
                            // only remove operation can not have
                            // new element in the new config context
                            throw new AdminEventListenerException();
                       } else {
                            nwsc = wsc;
                       }
                } else {
                    nwsc = new WebServiceConfigImpl(
                        (WebServiceEndpoint) newBean.parent());
                }
                if ( tf == null) {
                    // create new filter to handle transformation
                    tf = (TransformFilter) trh.registerFilter(wsc);
                } else {
                    if ( isRemove) {
                        String applyTo = tr.getApplyTo();
                        if ( applyTo.equals(Constants.BOTH) ||
                            applyTo.equals(Constants.REQUEST)) {
                            com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] rtrs =
                            nwsc.getRequestTransformationRule();
                            tf.resetRequestChain( pruneList( rtrs,
                            tr.getName()));
                        }
                        if ( applyTo.equals(Constants.BOTH) ||
                            applyTo.equals(Constants.RESPONSE)) {
                            com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] rtrs =
                            nwsc.getResponseTransformationRule();
                            tf.resetResponseChain( pruneList( rtrs,
                            tr.getName()));
                        }
                    } else {
                        tf.resetRequestChain(
                            nwsc.getRequestTransformationRule());
                        tf.resetResponseChain(
                            nwsc.getResponseTransformationRule());
                    }
                }
           } 

        } catch (Exception e) {
            throw new AdminEventListenerException(e);
        }
    
public voidhandleUpdate(com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEvent event)
Handles web-service-endpoint/transformation-rule element modification (attributes/properties values changed).

param
event Event to be processed.
throws
AdminEventListenerException when the listener is unable to process the event.


        handleReconfiguration(event,false,false);
    
private com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[]pruneList(com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] tRules, java.lang.String name)

        // nothing to prune for a null or empty list
        if (tRules == null || tRules.length < 1) {
            return tRules;
        }

        com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[] 
        newRules =
        new com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule[
        tRules.length-1];

        int newIndex = 0;
        for ( int index =0; index < tRules.length; index++) {
            if ( tRules[index].getName().equals(name)) {
                 // found the match, do not add to the new list
            } else {
                 if ( newIndex >= tRules.length-1) {
                    // removed rule should exist and should not cause array
                    // overflow.
                    throw new RuntimeException();
                 }
                 newRules[newIndex++] = tRules[index];
            }
        }
        return newRules;