001: /*
002: * Created on Jan 8, 2004
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package org.xdev.base.xssl.manage;
008:
009: import java.util.HashMap;
010: import java.util.Observable;
011: import java.util.Observer;
012:
013: import org.xdev.base.core.object.Configuration;
014: import org.xdev.base.core.object.ConfigurationObserver;
015: import org.xdev.base.xssl.XReference;
016: import org.xdev.base.xssl.XSSLAction;
017: import org.xdev.base.xssl.XSSLReturn;
018: import org.xdev.base.xssl.XPointer;
019:
020: /**
021: * @author AYegorov
022: *
023: * To change the template for this generated type comment go to
024: * Window>Preferences>Java>Code Generation>Code and Comments
025: */
026: public class TransactionTrigger extends XSSLReturn implements
027: ConfigurationObserver {
028: public static final String TRIGGER_TARGET = "target";
029: public static final String TRIGGER_SOURCE = "source";
030: public static final String TRIGGER_ON = "on";
031:
032: private Object returnedObject = null;
033:
034: private ITransactionTriggerable triggered = null;
035:
036: /**
037: * @param id
038: */
039: public TransactionTrigger(String id) {
040: super (id);
041: // XXX Auto-generated constructor stub
042: }
043:
044: /**
045: * @param id
046: * @param properties
047: */
048: public TransactionTrigger(String id, HashMap properties) {
049: super (id, properties);
050: // XXX Auto-generated constructor stub
051: }
052:
053: /* (non-Javadoc)
054: * @see org.xdev.base.xssl.XSSLReturn#getValue()
055: */
056: public Object getObjectValue() {
057: // XXX Auto-generated method stub
058: return this .returnedObject;
059: }
060:
061: /* (non-Javadoc)
062: * @see org.xdev.base.xssl.XSSLAction#set()
063: */
064: protected void set() throws Exception {
065: TransactionTrigger trigger = (TransactionTrigger) this
066: .getReference();
067:
068: this .logDebug("Triggering..." + trigger);
069:
070: if (trigger == null
071: || TransactionTrigger.TRIGGER_TARGET.equals(this
072: .getProperty(TransactionTrigger.TRIGGER_ON))) {
073:
074: if (trigger == null) {
075:
076: trigger = this ;
077:
078: this .setReference(this );
079:
080: }
081:
082: XSSLAction action = (XSSLAction) this .getElement(0);
083:
084: if (this .getBooleanProperty("passive")
085: || action.execute(this )) {
086:
087: this .logDebug("Action " + action.getClass()
088: + " is transaction triggerable: "
089: + (action instanceof ITransactionTriggerable));
090:
091: if (action instanceof XReference) {
092: action = (XSSLAction) ((XReference) action)
093: .getObjectValue();
094: }
095:
096: this .triggered = (ITransactionTriggerable) action;
097: }
098: } else if ((trigger != null || TransactionTrigger.TRIGGER_SOURCE
099: .equals(this .getProperty(TransactionTrigger.TRIGGER_ON))
100: && this .getCount() > 0)) {
101:
102: //trigger = this;
103:
104: this .setReference(this );
105:
106: XSSLAction ob = (XSSLAction) this .getElement(0);
107:
108: if (ob instanceof XReference) {
109: ob = (XSSLAction) ((XSSLReturn) ob).getObjectValue();
110: }
111:
112: ob.addObserver(trigger);
113:
114: ob.execute(this );
115: }
116: }
117:
118: /* (non-Javadoc)
119: * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
120: */
121: public void update(Configuration o, Object arg) throws Exception {
122:
123: if (this .eventList.contains(arg)) {
124:
125: try {
126: ((XSSLAction) this .triggered)
127: .issueTrigger(XSSLAction.TRIGGER_START_EVENT);
128:
129: if (((XSSLAction) this .triggered)
130: .getBooleanProperty("passive")) {
131: ((XSSLAction) this .triggered).execute(this );
132:
133: if (this .triggered instanceof XSSLReturn) {
134:
135: this .returnedObject = ((XSSLReturn) this .triggered)
136: .getObjectValue();
137:
138: }
139: }
140:
141: this .triggered.trigger(o, arg);
142:
143: ((XSSLAction) this .triggered)
144: .issueTrigger(XSSLAction.TRIGGER_END_EVENT);
145: } catch (Exception ex) {
146: ((XSSLAction) this .triggered)
147: .issueTrigger(XSSLAction.TRIGGER_ERROR_EVENT);
148: this .logDebug(ex);
149: }
150:
151: this .logDebug("Action " + this .triggered
152: + " triggered by: " + o + " with argument: " + arg);
153:
154: ((XSSLAction) this .triggered).issueTrigger(
155: XSSLAction.TRIGGER_BEFORE_REMOVE_EVENT, o);
156:
157: o.deleteObserver(this );
158:
159: ((XSSLAction) this .triggered)
160: .issueTrigger(XSSLAction.TRIGGER_AFTER_REMOVE_EVENT);
161: }
162: }
163:
164: /**
165: * @return Returns the returnedObject.
166: */
167: public Object getReturnedObject() {
168: return returnedObject;
169: }
170:
171: /**
172: * @return Returns the triggered.
173: */
174: public ITransactionTriggerable getTriggered() {
175: return triggered;
176: }
177: }
|