1 23 24 package com.sun.enterprise.admin.event; 25 26 import java.lang.reflect.Constructor ; 27 import java.util.ArrayList ; 28 29 import com.sun.enterprise.admin.event.AdminEvent; 30 import com.sun.enterprise.config.ConfigContext; 31 import com.sun.enterprise.config.ConfigChange; 32 import com.sun.enterprise.config.ConfigSet; 33 import com.sun.enterprise.config.ConfigAdd; 34 import com.sun.enterprise.config.ConfigUpdate; 35 import com.sun.enterprise.config.ConfigDelete; 36 37 38 import com.sun.enterprise.util.i18n.StringManager; 40 41 48 public class ElementChangeEvent extends AdminEvent { 49 50 53 public static final int ACTION_ELEMENT_UNDEFINED = 0; 54 55 public static final int ACTION_ELEMENT_CREATE = 1; 56 public static final int ACTION_ELEMENT_DELETE = 2; 57 public static final int ACTION_ELEMENT_UPDATE = 3; 58 59 62 static final String eventType = ElementChangeEvent.class.getName(); 63 64 67 private int change_action = ACTION_ELEMENT_UNDEFINED; 68 private String element_id = null; 69 private String element_type = null; private String element_path = null; 71 72 private static StringManager localStrings = StringManager.getManager( ElementChangeEvent.class ); 74 75 82 public static ArrayList getEventInstances( 83 String event_type, String instanceName, String elementType, 84 ArrayList changeList, ConfigContext ctx) throws Exception 85 { 86 int action = ElementChangeHelper.getActionCodeForChanges(changeList); 87 if(action==ElementChangeEvent.ACTION_ELEMENT_UNDEFINED) 88 return null; String element_xpath = ElementChangeHelper.getElementXPath(changeList); 90 String element_id = ElementChangeHelper.getConfigElementPrimaryKey(element_xpath); 91 92 AdminEvent event = null; 93 if(event_type.equals(eventType)) 94 { 95 event = new ElementChangeEvent(instanceName, event_type, action, element_id); 97 } 98 else 99 { 100 try { 102 Class cl = Class.forName(event_type); 103 Constructor contr; 104 try { 105 contr = cl.getConstructor( 107 new Class []{String .class, Integer.TYPE}); 108 event = (AdminEvent)contr.newInstance( 109 new Object []{instanceName, new Integer (action)}); 110 } catch (Exception e) { 111 } 112 113 if(event==null) 114 { 115 contr = cl.getConstructor( 117 new Class []{String .class, Integer.TYPE, String .class}); 118 event = (AdminEvent)contr.newInstance( 119 new Object []{instanceName, new Integer (action), element_id}); 120 } 121 if(event!=null) 122 event.addConfigChange(changeList); 123 } catch (Exception e) { 124 return null; } 127 } 128 if(event!=null) 129 { 130 String targetName = ElementChangeHelper.getConfigElementTargetName(element_xpath, ctx); 131 event.setTargetDestination(targetName); 132 ArrayList events = new ArrayList (); 133 events.add(event); 134 return events; 135 } 136 return null; 137 } 138 139 154 public ElementChangeEvent(String instance, String evtType, int actionCode, String elementId) 158 { 159 super(evtType, instance); 160 161 element_id = elementId; 163 setAction(actionCode); 165 } 166 167 176 public void addConfigChange(ArrayList changeList) 177 { 178 if(getConfigChangeList()!=null) 180 { 181 String msg = localStrings.getString( "admin.event.wrong_configchange" ); 182 throw new IllegalArgumentException ( msg ); 183 } 184 190 super.addConfigChange(changeList); 191 } 192 193 197 200 public String getElementXPath() 201 { 202 return ElementChangeHelper.getElementXPath(this.getConfigChangeList()); 203 } 204 205 208 public String getElementId() 209 { 210 return this.element_id; 211 } 212 213 216 public int getActionType() 217 { 218 return change_action; 219 } 220 221 225 230 private void setAction(int action) 231 { 232 boolean valid = false; 233 if (action==ACTION_ELEMENT_CREATE || 234 action==ACTION_ELEMENT_DELETE || 235 action==ACTION_ELEMENT_UPDATE ) 236 valid = true; 237 if (!valid) { 238 String msg = localStrings.getString( "admin.event.invalid_action", ""+action ); 239 throw new IllegalArgumentException ( msg ); 240 } 241 this.change_action = action; 242 } 243 244 } 245 | Popular Tags |