0001: /*
0002: * Created on Jul 14, 2003
0003: *
0004: * To change the template for this generated file go to
0005: * Window>Preferences>Java>Code Generation>Code and Comments
0006: */
0007: package org.xdev.base.xssl;
0008:
0009: import org.xdev.base.core.*;
0010:
0011: import org.xdev.base.log.LoggerWriter;
0012: import org.xdev.base.resource.*;
0013: import org.xdev.base.xssl.manage.ITransactionFinalizable;
0014: import org.xdev.base.core.compiler.AXCompiler;
0015:
0016: import java.util.*;
0017:
0018: import org.apache.log4j.Level;
0019: import org.jdom.*;
0020: import org.jaxen.jdom.*;
0021:
0022: /***
0023: *
0024: * @author AYegorov
0025: *
0026: *<p>
0027: *Abstract base class for all of the activeXml components, that defines all of the
0028: *core collaboration and component integration. Provides common exception handling,
0029: *transaction management abstraction, threading.
0030: *</p>
0031: *
0032: *
0033: * */
0034: public abstract class XSSLAction extends XSSLComponent implements
0035: Threaded {
0036:
0037: /***
0038: * <p>Name: catch-exception</p>
0039: *
0040: * <p>Defines whether the exception thrown by the executing action to be caught or propogated</p>
0041: *
0042: * <p>Values: true | false</p>
0043: *
0044: * <p>Default: false</p>
0045: */
0046: public static final String ACTION_CATCH_EX = "catch-exception";
0047:
0048: /***
0049: * <p>Name: do-commit</p>
0050: *
0051: * <p>Defines whether to execute commit logic after execution or not</p>
0052: *
0053: * <p>Values: true | false</p>
0054: *
0055: * <p>Default: false</p>
0056: */
0057: public static final String ACTION_DO_COMMIT = "do-commit";
0058:
0059: /***
0060: * <p>Name: do-rollback</p>
0061: *
0062: * <p>Defines whether to execute rollback logic after failed execution or not</p>
0063: *
0064: * <p>Values: true | false</p>
0065: *
0066: * <p>Default: true</p>
0067: */
0068: public static final String ACTION_DO_ROLLBACK = "do-rollback";
0069:
0070: /***
0071: * <p>Name: do-close</p>
0072: *
0073: * <p>Defines whether to execute close logic after execution or not</p>
0074: *
0075: * <p>Values: true | false</p>
0076: *
0077: * <p>Default: false</p>
0078: */
0079: public static final String ACTION_DO_CLOSE = "do-close";
0080:
0081: /***
0082: * <p>Name: reset</p>
0083: *
0084: * <p>Defines whether to reset the component on the repeated execution</p>
0085: *
0086: * <p>Values: true | false</p>
0087: *
0088: * <p>Default: true</p>
0089: */
0090: public static final String ACTION_DO_RESET = "reset";
0091:
0092: /***
0093: * <p>Name: object-id</p>
0094: *
0095: * <p>Defines the name of the persistance placeholder for a given component</p>
0096: *
0097: * <p>Values: any value</p>
0098: */
0099: public static final String OBJECT_ID = "object-id";
0100: public static final String DEFAULT = "default";
0101: /***
0102: * <p>Name: trigger</p>
0103: *
0104: * <p>Defines a comma delimited list of event triggers to process</p>
0105: *
0106: * <p>Values: any event trigger code value(s) delimited by a comma</p>
0107: */
0108: public static final String ACTION_EVENT_TRIGGER = "trigger";
0109:
0110: public static final int ACTION_COMMIT = 0;
0111: public static final int ACTION_ROLLBACK = 1;
0112: public static final int ACTION_CLOSE = 2;
0113:
0114: public static final int ACTION_STARTED_EVENT = 0;
0115: public static final int ACTION_SET_EVENT = 1;
0116: public static final int ACTION_ERROR_EVENT = 2;
0117: public static final int ACTION_RESET_EVENT = 3;
0118: public static final int ACTION_COPIED_EVENT = 4;
0119: public static final int ACTION_COMPLETED_EVENT = 5;
0120: public static final int ACTION_INITITIALIZED_EVENT = 6;
0121: public static final int ACTION_PROCESSED_EVENT = 7;
0122: public static final int ACTION_SUCCESS_EVENT = 8;
0123: public static final int ACTION_FAILURE_EVENT = 9;
0124: public static final int ACTION_VALUE_SET_EVENT = 10;
0125: public static final int ACTION_EXCEPTION_THROWN_EVENT = 11;
0126: public static final int ACTION_EXCEPTION_LOGGED_EVENT = 12;
0127: public static final int ACTION_COMMIT_EVENT = 13;
0128: public static final int ACTION_ROLLBACK_EVENT = 14;
0129: public static final int ACTION_CLOSE_EVENT = 15;
0130: public static final int ACTION_PREPROCESS_EVENT = 16;
0131: public static final int ACTION_PRESET_EVENT = 17;
0132: public static final int ACTION_STATUS_EVENT = 18;
0133: public static final int TRIGGER_START_EVENT = 43;
0134: public static final int TRIGGER_END_EVENT = 44;
0135: public static final int TRIGGER_ERROR_EVENT = 45;
0136: public static final int TRIGGER_BEFORE_REMOVE_EVENT = 46;
0137: public static final int TRIGGER_AFTER_REMOVE_EVENT = 47;
0138:
0139: private static HashMap onHold = new HashMap();
0140:
0141: protected static HashMap globalPersistances = new HashMap();
0142:
0143: private static String tag = "";
0144:
0145: protected AbstractPersistance persistance = null;
0146: protected XSSLAction template = null;
0147: protected XSSLAction actionParent = null;
0148: protected ArrayList eventList = new ArrayList();
0149:
0150: protected String type = "";
0151: protected String rulePath = null;
0152:
0153: protected String holdId = null;
0154:
0155: protected Element root = null;
0156:
0157: protected Exception exception = null;
0158:
0159: protected boolean executionStatus = false;
0160: protected boolean executionStatusSet = false;
0161: protected boolean wasExecuted = false;
0162: protected boolean wasSet = false;
0163: protected boolean wasStarted = false;
0164: protected boolean wasCloned = false;
0165: protected boolean resumed = true;
0166: protected boolean holding = false;
0167: protected boolean threaded = false;
0168: protected boolean reset = true;
0169:
0170: private int eventId = -1;
0171:
0172: protected Thread actionThread = null;
0173:
0174: protected XSSLAction originalRule = null;
0175: private String physicalPath;
0176: private boolean executionBroken = false;
0177:
0178: /**
0179: * @param id
0180: */
0181: public XSSLAction(String id) {
0182: this (id, null);
0183: }
0184:
0185: /**
0186: * @param id
0187: * @param properties
0188: */
0189: public XSSLAction(String id, HashMap properties) {
0190: super (id, properties);
0191: tag = this .setTagName();
0192: }
0193:
0194: public boolean execute() throws Exception {
0195: return this .execute(this );
0196: }
0197:
0198: protected abstract String setTagName();
0199:
0200: public synchronized void start() {
0201: //this.wasStarted = true;
0202: Thread th = null;
0203:
0204: if (this .getBooleanProperty("is-thread")) {
0205:
0206: XSSLAction action = (XSSLAction) this .newInstance(this
0207: .getRoot(), this .getParentComponent());
0208:
0209: action.setStarted(true);
0210:
0211: th = new Thread(action);
0212:
0213: this .log("Executing factored thread: " + th);
0214: } else {
0215: th = (this .actionThread = new Thread(this ));
0216: }
0217:
0218: th.setDaemon(true);
0219: th.start();
0220: }
0221:
0222: public void run() {
0223: try {
0224: this .executionStatus = this .execute();
0225: } catch (Exception ex) {
0226: this .executionStatus = false;
0227: }
0228: }
0229:
0230: public void setStarted(boolean flag) {
0231: this .wasStarted = flag;
0232: }
0233:
0234: public void setCloned(boolean flag) {
0235: this .wasCloned = flag;
0236: }
0237:
0238: public boolean isCloned() {
0239: return this .wasCloned;
0240: }
0241:
0242: public boolean isAlive() {
0243: return this .actionThread.isAlive();
0244: }
0245:
0246: public boolean execute(XSSLAction action) throws Exception {
0247: try {
0248:
0249: if (!this .isBroken() && this .hasProperOwner()) {
0250: if (this .getBooleanProperty("is-thread")
0251: && !this .wasStarted) {
0252: this .start();
0253: }
0254: /*else if (this.getBooleanProperty("clone") && !this.wasCloned) {
0255: XSSLAction cloned = (XSSLAction)this.newInstance(this.getRoot(), this.getParent());
0256:
0257: cloned.setCloned(true);
0258:
0259: cloned.execute(action);
0260: }*/
0261: else {
0262: this .issueTrigger(XSSLAction.ACTION_STARTED_EVENT);
0263:
0264: if (this
0265: .getBooleanProperty(XSSLAction.ACTION_DO_RESET)
0266: || !this
0267: .hasProperty(XSSLAction.ACTION_DO_RESET)) {
0268: this .reset();
0269: this
0270: .issueTrigger(XSSLAction.ACTION_RESET_EVENT);
0271: }
0272:
0273: String events = this
0274: .getProperty(XSSLAction.ACTION_EVENT_TRIGGER);
0275:
0276: this .logDebug("Processing events: " + events);
0277:
0278: if (!"".equals(events)) {
0279:
0280: StringTokenizer tokens = new StringTokenizer(
0281: events, ",");
0282:
0283: String eventCd = null;
0284:
0285: Object eventId = null;
0286:
0287: while (tokens.hasMoreElements()) {
0288:
0289: eventCd = tokens.nextToken();
0290: eventId = this .getFieldProperty(eventCd);
0291:
0292: if (!this .eventList.contains(eventId)
0293: && eventId != null) {
0294: //TODO: Store just a code and parse the code into a eventId at the observable level from the Observer
0295: this .eventList.add(eventId.toString());
0296:
0297: this .logDebug("Added event id: "
0298: + eventId.toString());
0299: }
0300:
0301: eventCd = null;
0302: }
0303: }
0304:
0305: this .wasExecuted = true;
0306: this .exception = null;
0307: this .template = (XSSLAction) action.getRoot();
0308:
0309: action = null;
0310:
0311: this
0312: .issueTrigger(XSSLAction.ACTION_INITITIALIZED_EVENT);
0313:
0314: this .logDebug("Processing action - START: " + this );
0315:
0316: List activeProps = this .getActiveProperties();
0317:
0318: int size = activeProps.size();
0319:
0320: Object activeProp = null;
0321:
0322: for (int i = 0; i < size; i++) {
0323: activeProp = activeProps.get(i);
0324:
0325: if (activeProp instanceof XSSLAction) {
0326: ((XSSLAction) activeProp).execute(this );
0327: }
0328: }
0329:
0330: this .process();
0331:
0332: this .logDebug("Processing action - END: " + this );
0333:
0334: this
0335: .issueTrigger(XSSLAction.ACTION_PROCESSED_EVENT);
0336: this .executionStatus = this
0337: .transaction(XSSLAction.ACTION_COMMIT);
0338:
0339: if (this .executionStatus) {
0340: this
0341: .issueTrigger(XSSLAction.ACTION_SUCCESS_EVENT);
0342: } else {
0343: this
0344: .issueTrigger(XSSLAction.ACTION_FAILURE_EVENT);
0345: }
0346: }
0347: }
0348: } catch (Exception ex) {
0349: this .issueTrigger(XSSLAction.ACTION_ERROR_EVENT);
0350: this .fail(ex);
0351: this .transaction(XSSLAction.ACTION_ROLLBACK);
0352: } finally {
0353: this .transaction(XSSLAction.ACTION_CLOSE);
0354: this .issueTrigger(XSSLAction.ACTION_COMPLETED_EVENT);
0355: }
0356:
0357: return this .executionStatus;
0358: }
0359:
0360: public void issueTrigger(int eventId) throws Exception {
0361: this .issueTrigger(eventId, String.valueOf(eventId));
0362: }
0363:
0364: public void issueTrigger(int eventId, Object param)
0365: throws Exception {
0366: this .setEventId(eventId);
0367:
0368: this .logDebug("Issuing trigger for event list: "
0369: + this .eventList);
0370:
0371: this .logDebug("Iterator finished looping: Observable "
0372: + this .getClass()
0373: + " state changed and has been recorded.");
0374:
0375: this .setChanged();
0376:
0377: this .logDebug("Notification of Observable " + this .getClass()
0378: + " state change sent to all registered("
0379: + this .countObservers() + ") observers.");
0380:
0381: this .notifyObservers(param);
0382: }
0383:
0384: public int getEventId() {
0385: return this .eventId;
0386: }
0387:
0388: public void setEventId(int eventId) {
0389: this .eventId = eventId;
0390: }
0391:
0392: private void fail(Exception ex) throws Exception {
0393: if (!((XSSLAction) this .getRoot()).hasException()) {
0394:
0395: ((XSSLAction) this .getRoot()).setException(ex);
0396:
0397: this .logError("Action " + type + " failed with exception: "
0398: + BASE.getValueFromObject(ex));
0399: }
0400:
0401: this .exception = ex;
0402: this .executionStatus = false;
0403: this .throwException();
0404: }
0405:
0406: public boolean getExecutionStatus() {
0407: return this .executionStatus;
0408: }
0409:
0410: public boolean hasExecuted() {
0411: return this .wasExecuted;
0412: }
0413:
0414: public Exception getException() {
0415: return this .exception;
0416: }
0417:
0418: public void setException(Exception ex) {
0419: this .exception = ex;
0420: }
0421:
0422: public boolean hasException() {
0423: return this .exception != null;
0424: }
0425:
0426: public void throwException() throws Exception {
0427: if (this .throwsException()) {
0428: this .issueTrigger(XSSLAction.ACTION_EXCEPTION_THROWN_EVENT);
0429: throw this .exception;
0430: } else if (!this .throwsException()) {
0431: this .issueTrigger(XSSLAction.ACTION_EXCEPTION_LOGGED_EVENT);
0432: this .log(this .exception);
0433: }
0434: }
0435:
0436: public boolean throwsException() {
0437: return !this .getBooleanProperty(XSSLAction.ACTION_CATCH_EX);
0438: }
0439:
0440: public boolean transaction(int choice) throws Exception {
0441: boolean flag = false;
0442: if (this .executionStatusSet) {
0443: flag = this .executionStatus;
0444: } else {
0445: try {
0446: switch (choice) {
0447: case XSSLAction.ACTION_COMMIT:
0448: if (this
0449: .getBooleanProperty(XSSLAction.ACTION_DO_COMMIT)) {
0450: this .commit();
0451: this
0452: .issueTrigger(XSSLAction.ACTION_COMMIT_EVENT);
0453: }
0454: break;
0455: case XSSLAction.ACTION_ROLLBACK:
0456: if (this
0457: .getBooleanProperty(XSSLAction.ACTION_DO_ROLLBACK)) {
0458: this .rollback();
0459: this
0460: .issueTrigger(XSSLAction.ACTION_ROLLBACK_EVENT);
0461: }
0462: break;
0463: case XSSLAction.ACTION_CLOSE:
0464: List list = this .getFinalizableList();
0465:
0466: int size = list.size();
0467:
0468: ITransactionFinalizable a = null;
0469:
0470: for (int i = 0; i < size; i++) {
0471: try {
0472: a = (ITransactionFinalizable) list.get(i);
0473:
0474: if (((XSSLAction) a)
0475: .getBooleanProperty("finalize")) {
0476: a.doFinalize();
0477: }
0478:
0479: a = null;
0480: } catch (Exception ex) {
0481: this .logDebug(ex);
0482: }
0483: }
0484:
0485: if (this
0486: .getBooleanProperty(XSSLAction.ACTION_DO_CLOSE)) {
0487: this .close();
0488: this
0489: .issueTrigger(XSSLAction.ACTION_CLOSE_EVENT);
0490: }
0491: break;
0492: }
0493: flag = true;
0494: } catch (Exception ex) {
0495: this .fail(ex);
0496: }
0497: }
0498:
0499: return flag;
0500: }
0501:
0502: /* (non-Javadoc)
0503: * @see org.xdev.base.templates.TemplateAbstractAction#process()
0504: */
0505: protected void process() throws Exception {
0506:
0507: this .logDebug("Initializing Action - START: " + this );
0508:
0509: this .init();
0510:
0511: this .logDebug("Initializing Action - END: " + this );
0512:
0513: this .issueTrigger(XSSLAction.ACTION_PREPROCESS_EVENT);
0514:
0515: this .logDebug("Invoking Action - START: " + this );
0516:
0517: this .invoke();
0518:
0519: this .logDebug("Invoking Action - END: " + this );
0520: }
0521:
0522: protected void init() throws Exception {
0523: if (!this .wasSet) {
0524: this .wasSet = true;
0525: this .issueTrigger(XSSLAction.ACTION_PRESET_EVENT);
0526: this .set();
0527: this .issueTrigger(XSSLAction.ACTION_SET_EVENT);
0528: }
0529: }
0530:
0531: abstract public void rollback() throws Exception;
0532:
0533: abstract public void commit() throws Exception;
0534:
0535: abstract protected void invoke() throws Exception;
0536:
0537: abstract protected void set() throws Exception;
0538:
0539: abstract protected void close() throws Exception;
0540:
0541: public Object get(String id) {
0542: return this .persistance.get(id);
0543: }
0544:
0545: public AbstractPersistance getPersistance() {
0546: if (this .persistance == null) {
0547:
0548: this .logDebug("Creating persistance...");
0549:
0550: this .setPersistance(new InMemoryStorage(XSSLAction.DEFAULT,
0551: new HashMap()));
0552: }
0553:
0554: return this .persistance;
0555: }
0556:
0557: public AbstractPersistance getPersistance(boolean global) {
0558: return global ? this .getGlobalPersistance() : this
0559: .getPersistance();
0560: }
0561:
0562: public AbstractPersistance getGlobalPersistance() {
0563: AbstractPersistance globalPersistance = null;
0564:
0565: if (globalPersistances.containsKey(this .getRulePath())) {
0566: globalPersistance = (AbstractPersistance) XSSLAction.globalPersistances
0567: .get(this .getRulePath());
0568: } else {
0569: globalPersistance = new InMemoryStorage(XSSLAction.DEFAULT,
0570: new HashMap());
0571:
0572: XSSLAction.globalPersistances.put(this .getRulePath(),
0573: globalPersistance);
0574: }
0575:
0576: globalPersistance.setOverwrite(false);
0577:
0578: return globalPersistance;
0579: }
0580:
0581: public XSSLAction getOriginalRule() {
0582: return this .originalRule;
0583: }
0584:
0585: public void setOriginalRule(XSSLAction originalRule) {
0586: this .originalRule = originalRule;
0587: }
0588:
0589: public void setPersistance(AbstractPersistance persistance) {
0590: this .persistance = persistance;
0591: }
0592:
0593: public IDataSource getDataSource(String id) {
0594: this .logDebug("Retrieving datasource: " + id);
0595:
0596: return AXCompiler.getInstance().getDataSource(id);
0597: }
0598:
0599: public Object getTransactionController() {
0600: return this .getTransactionComponent("xssl-controller");
0601: }
0602:
0603: public Object getTransactionSession() {
0604: return this .getTransactionComponent("xssl-session");
0605: }
0606:
0607: public void setTransactionController(Object controller) {
0608: this .logDebug("Transaction Controller set to: " + controller);
0609:
0610: this .setTransactionComponent("xssl-controller", controller);
0611: }
0612:
0613: public Object getTransactionAction() {
0614: return this .getTransactionComponent("xssl-mapping");
0615: }
0616:
0617: public Object getTransactionRequest() {
0618: return this .getTransactionComponent("xssl-request");
0619: }
0620:
0621: public Object getTransactionResponse() {
0622: return this .getTransactionComponent("xssl-response");
0623: }
0624:
0625: public Object getTransactionComponent(String id) {
0626: Object obj = null;
0627:
0628: XSSLAction root = (XSSLAction) this .getRoot();
0629:
0630: this .logDebug("Servlet component to retrieve: " + id);
0631:
0632: if (root != null) {
0633:
0634: this .logDebug("Getting servlet component from the root: "
0635: + root);
0636:
0637: obj = root.get(id);
0638: } else {
0639:
0640: this .logDebug("Getting servlet component from itself: "
0641: + this );
0642:
0643: obj = this .get(id);
0644: }
0645:
0646: this .logDebug("Servlet component received: " + obj);
0647:
0648: return obj;
0649: }
0650:
0651: public void setTransactionComponent(String id, Object comp) {
0652: this .getPersistance().storeObject(id, comp);
0653: }
0654:
0655: public Object getTransactionConfig() {
0656: return this .getTransactionComponent("xssl-config");
0657: }
0658:
0659: public String getWorkingDirectory() {
0660:
0661: Object obj = this .getTransactionComponent("working-dir");
0662:
0663: return obj == null ? System.getProperty("user.dir") : obj
0664: .toString();
0665: }
0666:
0667: public void setWorkingDirectory(String workingDirectory) {
0668:
0669: this .setTransactionComponent("working-dir", workingDirectory);
0670: }
0671:
0672: public void reset() {
0673: this .wasSet = false;
0674: this .executionStatusSet = false;
0675: this .executionBroken = false;
0676: this .wasStarted = false;
0677:
0678: try {
0679: this .issueTrigger(XSSLAction.ACTION_RESET_EVENT);
0680: } catch (Exception ex) {
0681: this .logError(ex);
0682: }
0683:
0684: this .eventList = new ArrayList();
0685: this .exception = null;
0686:
0687: ((XSSLAction) this .getRoot()).setException(null);
0688: }
0689:
0690: public XSSLAction copy() {
0691: return (XSSLAction) this .newInstance(this .getRoot(), this
0692: .getParentComponent());
0693: }
0694:
0695: /**
0696: * @param executionStatus The executionStatus to set.
0697: */
0698: public void setExecutionStatus(boolean executionStatus) {
0699: this .executionStatus = executionStatus;
0700: this .executionStatusSet = true;
0701:
0702: try {
0703: this .issueTrigger(XSSLAction.ACTION_STATUS_EVENT);
0704: } catch (Exception ex) {
0705: this .logError(ex);
0706: }
0707: }
0708:
0709: /**
0710: * @return Returns the aCTION_CATCH_EX.
0711: */
0712: public static String getACTION_CATCH_EX() {
0713: return ACTION_CATCH_EX;
0714: }
0715:
0716: /**
0717: * @return Returns the aCTION_CLOSE.
0718: */
0719: public static int getACTION_CLOSE() {
0720: return ACTION_CLOSE;
0721: }
0722:
0723: /**
0724: * @return Returns the aCTION_CLOSE_EVENT.
0725: */
0726: public static int getACTION_CLOSE_EVENT() {
0727: return ACTION_CLOSE_EVENT;
0728: }
0729:
0730: /**
0731: * @return Returns the aCTION_COMMIT.
0732: */
0733: public static int getACTION_COMMIT() {
0734: return ACTION_COMMIT;
0735: }
0736:
0737: /**
0738: * @return Returns the aCTION_COMMIT_EVENT.
0739: */
0740: public static int getACTION_COMMIT_EVENT() {
0741: return ACTION_COMMIT_EVENT;
0742: }
0743:
0744: /**
0745: * @return Returns the aCTION_COMPLETED_EVENT.
0746: */
0747: public static int getACTION_COMPLETED_EVENT() {
0748: return ACTION_COMPLETED_EVENT;
0749: }
0750:
0751: /**
0752: * @return Returns the aCTION_COPIED_EVENT.
0753: */
0754: public static int getACTION_COPIED_EVENT() {
0755: return ACTION_COPIED_EVENT;
0756: }
0757:
0758: /**
0759: * @return Returns the aCTION_DO_CLOSE.
0760: */
0761: public static String getACTION_DO_CLOSE() {
0762: return ACTION_DO_CLOSE;
0763: }
0764:
0765: /**
0766: * @return Returns the aCTION_DO_COMMIT.
0767: */
0768: public static String getACTION_DO_COMMIT() {
0769: return ACTION_DO_COMMIT;
0770: }
0771:
0772: /**
0773: * @return Returns the aCTION_DO_RESET.
0774: */
0775: public static String getACTION_DO_RESET() {
0776: return ACTION_DO_RESET;
0777: }
0778:
0779: /**
0780: * @return Returns the aCTION_DO_ROLLBACK.
0781: */
0782: public static String getACTION_DO_ROLLBACK() {
0783: return ACTION_DO_ROLLBACK;
0784: }
0785:
0786: /**
0787: * @return Returns the aCTION_ERROR_EVENT.
0788: */
0789: public static int getACTION_ERROR_EVENT() {
0790: return ACTION_ERROR_EVENT;
0791: }
0792:
0793: /**
0794: * @return Returns the aCTION_EVENT_TRIGGER.
0795: */
0796: public static String getACTION_EVENT_TRIGGER() {
0797: return ACTION_EVENT_TRIGGER;
0798: }
0799:
0800: /**
0801: * @return Returns the aCTION_EXCEPTION_LOGGED_EVENT.
0802: */
0803: public static int getACTION_EXCEPTION_LOGGED_EVENT() {
0804: return ACTION_EXCEPTION_LOGGED_EVENT;
0805: }
0806:
0807: /**
0808: * @return Returns the aCTION_EXCEPTION_THROWN_EVENT.
0809: */
0810: public static int getACTION_EXCEPTION_THROWN_EVENT() {
0811: return ACTION_EXCEPTION_THROWN_EVENT;
0812: }
0813:
0814: /**
0815: * @return Returns the aCTION_FAILURE_EVENT.
0816: */
0817: public static int getACTION_FAILURE_EVENT() {
0818: return ACTION_FAILURE_EVENT;
0819: }
0820:
0821: /**
0822: * @return Returns the aCTION_INITITIALIZED_EVENT.
0823: */
0824: public static int getACTION_INITITIALIZED_EVENT() {
0825: return ACTION_INITITIALIZED_EVENT;
0826: }
0827:
0828: /**
0829: * @return Returns the aCTION_PREPROCESS_EVENT.
0830: */
0831: public static int getACTION_PREPROCESS_EVENT() {
0832: return ACTION_PREPROCESS_EVENT;
0833: }
0834:
0835: /**
0836: * @return Returns the aCTION_PRESET_EVENT.
0837: */
0838: public static int getACTION_PRESET_EVENT() {
0839: return ACTION_PRESET_EVENT;
0840: }
0841:
0842: /**
0843: * @return Returns the aCTION_PROCESSED_EVENT.
0844: */
0845: public static int getACTION_PROCESSED_EVENT() {
0846: return ACTION_PROCESSED_EVENT;
0847: }
0848:
0849: /**
0850: * @return Returns the aCTION_RESET_EVENT.
0851: */
0852: public static int getACTION_RESET_EVENT() {
0853: return ACTION_RESET_EVENT;
0854: }
0855:
0856: /**
0857: * @return Returns the aCTION_ROLLBACK.
0858: */
0859: public static int getACTION_ROLLBACK() {
0860: return ACTION_ROLLBACK;
0861: }
0862:
0863: /**
0864: * @return Returns the aCTION_ROLLBACK_EVENT.
0865: */
0866: public static int getACTION_ROLLBACK_EVENT() {
0867: return ACTION_ROLLBACK_EVENT;
0868: }
0869:
0870: /**
0871: * @return Returns the aCTION_SET_EVENT.
0872: */
0873: public static int getACTION_SET_EVENT() {
0874: return ACTION_SET_EVENT;
0875: }
0876:
0877: /**
0878: * @return Returns the aCTION_STARTED_EVENT.
0879: */
0880: public static int getACTION_STARTED_EVENT() {
0881: return ACTION_STARTED_EVENT;
0882: }
0883:
0884: /**
0885: * @return Returns the aCTION_STATUS_EVENT.
0886: */
0887: public static int getACTION_STATUS_EVENT() {
0888: return ACTION_STATUS_EVENT;
0889: }
0890:
0891: /**
0892: * @return Returns the aCTION_SUCCESS_EVENT.
0893: */
0894: public static int getACTION_SUCCESS_EVENT() {
0895: return ACTION_SUCCESS_EVENT;
0896: }
0897:
0898: /**
0899: * @return Returns the aCTION_VALUE_SET_EVENT.
0900: */
0901: public static int getACTION_VALUE_SET_EVENT() {
0902: return ACTION_VALUE_SET_EVENT;
0903: }
0904:
0905: /**
0906: * @return Returns the tRIGGER_AFTER_REMOVE_EVENT.
0907: */
0908: public static int getTRIGGER_AFTER_REMOVE_EVENT() {
0909: return TRIGGER_AFTER_REMOVE_EVENT;
0910: }
0911:
0912: /**
0913: * @return Returns the tRIGGER_BEFORE_REMOVE_EVENT.
0914: */
0915: public static int getTRIGGER_BEFORE_REMOVE_EVENT() {
0916: return TRIGGER_BEFORE_REMOVE_EVENT;
0917: }
0918:
0919: /**
0920: * @return Returns the tRIGGER_END_EVENT.
0921: */
0922: public static int getTRIGGER_END_EVENT() {
0923: return TRIGGER_END_EVENT;
0924: }
0925:
0926: /**
0927: * @return Returns the tRIGGER_ERROR_EVENT.
0928: */
0929: public static int getTRIGGER_ERROR_EVENT() {
0930: return TRIGGER_ERROR_EVENT;
0931: }
0932:
0933: /**
0934: * @return Returns the tRIGGER_START_EVENT.
0935: */
0936: public static int getTRIGGER_START_EVENT() {
0937: return TRIGGER_START_EVENT;
0938: }
0939:
0940: /**
0941: * @return Returns the dEFAULT.
0942: */
0943: public static String getDEFAULT() {
0944: return DEFAULT;
0945: }
0946:
0947: /**
0948: * @return Returns the oBJECT_ID.
0949: */
0950: public static String getOBJECT_ID() {
0951: return OBJECT_ID;
0952: }
0953:
0954: /**
0955: * @return Returns the eventList.
0956: */
0957: public ArrayList getEventList() {
0958: return eventList;
0959: }
0960:
0961: public String hold(String holdId) throws Exception {
0962: if (this .resumed) {
0963: this .holdId = holdId;
0964:
0965: synchronized (onHold) {
0966: onHold.put(this .holdId, this );
0967:
0968: this .logDebug("Storing the transaction on hold: "
0969: + this .holdId);
0970: }
0971:
0972: this .resumed = false;
0973:
0974: ((XSSLAction) this .getRoot()).setHold(true);
0975:
0976: while (!this .resumed) {
0977: Thread.sleep(200);
0978:
0979: this
0980: .logDebug("Holding for response to an input request with id: "
0981: + this .holdId);
0982: }
0983: }
0984:
0985: return this .holdId;
0986: }
0987:
0988: public void resume(Object data) {
0989: if (!this .resumed) {
0990: synchronized (onHold) {
0991: onHold.remove(this .holdId);
0992: }
0993:
0994: this .setResumeData(data);
0995:
0996: this .resumed = true;
0997:
0998: ((XSSLAction) this .getRoot()).setHold(false);
0999: }
1000: }
1001:
1002: public void setResumeData(Object data) {
1003: this .logDebug("Data received after resume executed: " + data);
1004: }
1005:
1006: public static XSSLAction findOnHold(String id) {
1007: return (XSSLAction) onHold.get(id);
1008: }
1009:
1010: public void setRulePath(String rulePath) {
1011: this .rulePath = rulePath;
1012: }
1013:
1014: public String getRulePath() {
1015: return (this .getRoot() != null && !this .getRoot().equals(this )) ? ((XSSLAction) this
1016: .getRoot()).getRulePath()
1017: : this .rulePath;
1018: }
1019:
1020: public void setHold(boolean holding) {
1021: this .holding = holding;
1022: }
1023:
1024: public boolean isHolding() {
1025: return this .holding;
1026: }
1027:
1028: public void setThreaded(boolean flag) {
1029: this .threaded = flag;
1030: }
1031:
1032: public boolean isThreaded() {
1033: return this .threaded;
1034: }
1035:
1036: public boolean isStarted() {
1037: return this .wasStarted;
1038: }
1039:
1040: public static void removeGlobalPersistance(String ruleId) {
1041:
1042: synchronized (globalPersistances) {
1043:
1044: globalPersistances.remove(ruleId);
1045: }
1046: }
1047:
1048: protected Object resolveKeyword(Object key) {
1049: Object obj = null;
1050:
1051: if (key instanceof String && ((String) key).startsWith("!/")) {
1052: try {
1053: String keyword = (String) key;
1054:
1055: keyword = keyword.substring(2, keyword.length());
1056:
1057: Element root = null;
1058:
1059: String ds = keyword.substring(0, keyword.indexOf("/"));
1060:
1061: this .logDebug("Resolving datasource: " + ds
1062: + " for search property: " + keyword);
1063:
1064: IDataSource source = AXCompiler.getInstance()
1065: .getDataSource(ds);
1066:
1067: Document doc = (Document) source.getConnection();
1068:
1069: root = doc.getRootElement();
1070:
1071: if (root == null) {
1072: root = AXCompiler.BASE_ROOT;
1073: }
1074:
1075: JDOMXPath xpath = new JDOMXPath(keyword.substring(
1076: keyword.indexOf("/"), keyword.length()));
1077:
1078: obj = xpath.selectSingleNode(root);
1079:
1080: if (obj instanceof Element) {
1081: obj = ((Element) obj).getTextTrim();
1082: } else if (obj instanceof Attribute) {
1083: obj = ((Attribute) obj).getValue();
1084: } else if (obj instanceof Text) {
1085: obj = ((Text) obj).getTextTrim();
1086: }
1087: } catch (Exception ex) {
1088: this .log(ex);
1089: }
1090: } else {
1091: obj = super .resolveKeyword(key);
1092: }
1093:
1094: return obj;
1095:
1096: }
1097:
1098: /**
1099: * @param string
1100: */
1101: public void setPhysicalPath(String physicalPath) {
1102: this .physicalPath = physicalPath;
1103: }
1104:
1105: public String getPhysicalPath() {
1106: return this .physicalPath;
1107: }
1108:
1109: /**
1110: *
1111: */
1112: public void breakExecution() {
1113: this .executionBroken = true;
1114: }
1115:
1116: public boolean isBroken() {
1117: return this .executionBroken;
1118: }
1119:
1120: public void finalize() throws Throwable {
1121:
1122: super .finalize();
1123:
1124: LoggerWriter.log("Garbage Collecting component: " + this,
1125: Level.DEBUG_INT, this.getClass());
1126: }
1127: }
|