001: /*
002: * Created on Apr 1, 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.ArrayList;
010: import java.util.HashMap;
011:
012: import org.xdev.base.core.AbstractPersistance;
013: import org.xdev.base.core.BASE;
014: import org.xdev.base.core.IPage;
015: import org.xdev.base.core.compiler.AXCompiler;
016: import org.xdev.base.xssl.XObject;
017: import org.xdev.base.xssl.XParameter;
018: import org.xdev.base.xssl.XSSLAction;
019: import org.xdev.base.xssl.XSSLReturn;
020:
021: /**
022: * @author AYegorov
023: *
024: * To change the template for this generated type comment go to
025: * Window>Preferences>Java>Code Generation>Code and Comments
026: */
027: public class TransactionExecutor extends TransactionDefine {
028: private XSSLAction action = null;
029:
030: private Object returnObject = null;
031:
032: private ArrayList ruleParameters = new ArrayList();
033:
034: private ArrayList postParameters = new ArrayList();
035:
036: /**
037: * @param id
038: */
039: public TransactionExecutor(String id) {
040: super (id);
041: // XXX Auto-generated constructor stub
042: }
043:
044: /**
045: * @param id
046: * @param properties
047: */
048: public TransactionExecutor(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.XSSLActionIterator#invoke(org.xdev.base.xssl.XSSLAction)
055: */
056: protected void invoke(XSSLAction component) throws Exception {
057:
058: if (this .getBooleanProperty("define")) {
059: super .invoke(component);
060: }
061:
062: if (this .getBooleanProperty("post-parameter")) {
063: this .postParameters.add(component);
064: }
065:
066: this .addRuleParameter(component);
067: }
068:
069: protected void addRuleParameter(XSSLAction component) {
070: if (component instanceof XSSLReturn && component != null) {
071:
072: if (this .action != null) {
073: AbstractPersistance p = this .action.getPersistance();
074:
075: if (!component.getBooleanProperty("reference")) {
076: Object obj = component;
077:
078: while (obj instanceof XSSLReturn) {
079: obj = ((XSSLReturn) obj).getObjectValue();
080: }
081:
082: XParameter object = new XParameter(component
083: .getId(), component.getProperties());
084:
085: object.setParameter(obj);
086:
087: p.storeObject(component
088: .getProperty(XSSLReturn.OBJECT_ID), object);
089:
090: this .logDebug("Adding "
091: + object
092: + " as execution parameter "
093: + component
094: .getProperty(XSSLReturn.OBJECT_ID)
095: + ": " + obj);
096: } else {
097: p.storeObject(component
098: .getProperty(XSSLReturn.OBJECT_ID),
099: component);
100: }
101: }
102:
103: synchronized (this .ruleParameters) {
104:
105: if (!this .ruleParameters.contains(component)) {
106: this .logDebug("Adding execution component "
107: + component
108: .getProperty(XSSLReturn.OBJECT_ID)
109: + ": " + component);
110:
111: this .ruleParameters.add(component);
112: }
113: }
114: }
115: }
116:
117: protected void invoke() throws Exception {
118: String rulePath = this .getProperty("rule-path");
119:
120: this .action = AXCompiler.getInstance().compileRule(
121: (IPage) this .getTransactionAction(),
122: BASE.getFile(rulePath, this .getClass()), rulePath);
123:
124: Object obj = this .getReference();
125:
126: if (obj != null && obj instanceof TransactionExecutor) {
127: this .logDebug("Referencing a template invoker: " + obj);
128:
129: this .addRuleParameters(((TransactionExecutor) obj)
130: .getRuleParameters());
131: }
132:
133: int size = this .ruleParameters.size();
134:
135: for (int i = 0; i < size; i++) {
136: this .addRuleParameter((XSSLAction) this .ruleParameters
137: .get(i));
138: }
139:
140: super .invoke();
141:
142: if (!this .getBooleanProperty("prepare")) {
143:
144: this .action.start();
145:
146: boolean thread = this .getBooleanProperty("thread-rule");
147:
148: if (!thread) {
149:
150: while (this .action.isAlive()
151: && !this .action.isThreaded()) {
152: Thread.sleep(200);
153: }
154:
155: if (this .action instanceof XSSLReturn && !thread) {
156: this .returnObject = ((XSSLReturn) this .action)
157: .getObjectValue();
158: }
159:
160: //this.log("Transferred Persistance: "+this.action.getPersistance().toString());
161:
162: this .setPersistance(this .action.getPersistance());
163: }
164: }
165:
166: size = this .postParameters.size();
167:
168: for (int i = 0; i < size; i++) {
169: this .addRuleParameter((XSSLAction) this .postParameters
170: .remove(i));
171: }
172: }
173:
174: public Object getObjectValue() {
175: return this .returnObject;
176: }
177:
178: public ArrayList getRuleParameters() {
179: return this .ruleParameters;
180: }
181:
182: public void addRuleParameters(ArrayList list) {
183: synchronized (this .ruleParameters) {
184: int size = list.size();
185:
186: Object comp = null;
187:
188: for (int i = 0; i < size; i++) {
189:
190: comp = list.get(i);
191:
192: this
193: .logDebug("Adding component "
194: + ((comp instanceof XSSLAction) ? ((XSSLAction) comp)
195: .getProperty("object-id")
196: : "") + comp);
197:
198: this .ruleParameters.add(comp);
199:
200: comp = null;
201: }
202: }
203: }
204:
205: public void reset() {
206:
207: int size = this .ruleParameters.size();
208:
209: XSSLAction c = null;
210:
211: ArrayList list = new ArrayList();
212:
213: while (!this .ruleParameters.isEmpty()) {
214: c = (XSSLAction) this .ruleParameters.remove(0);
215:
216: if (c.getBooleanProperty("retain")) {
217: list.add(c);
218: }
219: }
220:
221: this.ruleParameters = list;
222:
223: super.reset();
224: }
225:
226: }
|