001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.function.v1;
009:
010: //base classes
011: import java.lang.reflect.InvocationTargetException;
012: import java.lang.reflect.Method;
013:
014: //project specific classes
015: import org.jfolder.common.SelfArgumentlessConstructor;
016: import org.jfolder.common.StandardDataTypes;
017: import org.jfolder.common.function.BaseCommonFunctionCompatibilityTag;
018: import org.jfolder.common.function.WebPageTagInstanceViewContext;
019: import org.jfolder.common.function.WebPageTagInstanceViewContextInfo;
020: import org.jfolder.common.tagging.AppraiseConceptTagContext;
021: import org.jfolder.common.tagging.ConceptTagCharacteristic;
022: import org.jfolder.common.tagging.ConceptTagConstraint;
023: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
024: import org.jfolder.common.tagging.ConceptTagFlagsHelper;
025: import org.jfolder.common.tagging.ConceptTagHelper;
026: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
027: import org.jfolder.common.tagging.DetermineClassConceptTagException;
028: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
029: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
030: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
031: import org.jfolder.common.tagging.InitializeConceptTagContext;
032: import org.jfolder.common.tagging.ReturnableConceptTag;
033: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
034: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
035: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
037: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
038: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
039:
040: //other classes
041:
042: public class CommonFunctionLangCallTag extends
043: BaseCommonFunctionCompatibilityTag implements
044: SelfArgumentlessConstructor {
045:
046: //characteristics
047: private ConceptTagCharacteristic callerCtchar = null;
048: private ConceptTagCharacteristic methodCtchar = null;
049: private ConceptTagCharacteristic parameterCtchar = null;
050:
051: //caller details
052: private final static String CALLER_CTCON = "caller";
053: private final static String CALLER_TITLE = "Caller";
054: private final static String CALLER_SHORT_DESCRIPTION = "Object calling the method";
055:
056: //method details
057: private final static String METHOD_CTCON = "method";
058: private final static String METHOD_TITLE = "Method";
059: private final static String METHOD_SHORT_DESCRIPTION = "Method to be called";
060:
061: //parameter details
062: private final static String PARAMETER_CTCON = "parameter";
063: private final static String PARAMETER_TITLE = "Parameters";
064: private final static String PARAMETER_SHORT_DESCRIPTION = "Parameters to be passed to the method";
065:
066: public void initialize(InitializeConceptTagContext inIctc) {
067:
068: //
069: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
070: .newInstance(inIctc);
071:
072: //constrain "caller"
073: ConceptTagConstraint callerCtcon = ConceptTagConstraint
074: .newInstance(CALLER_CTCON, rootCtconh);
075: callerCtcon.setTitle(CALLER_TITLE);
076: callerCtcon.setShortDescription(CALLER_SHORT_DESCRIPTION);
077: //dtc1.setClassRestrictions(ReturnableConceptTag.class);
078: //
079: //
080: DynamicConceptTagConstraintContext callerDctcc = DynamicConceptTagConstraintContext
081: .newInstance(callerCtcon);
082: callerDctcc.getValidator().filterDirectChildOfRootAndHtml();
083: //
084: //callerDctcc.addDefaultValue(
085: // GetApplicationAttributeWorkflowTemplateTag.class);
086:
087: //constrain "method"
088: ConceptTagConstraint methodCtcon = ConceptTagConstraint
089: .newInstance(METHOD_CTCON, rootCtconh);
090: methodCtcon.setTitle(METHOD_TITLE);
091: methodCtcon.setShortDescription(METHOD_SHORT_DESCRIPTION);
092: //
093: StaticConceptTagConstraintContext methodSctcc = StaticConceptTagConstraintContext
094: .newInstance(methodCtcon);
095: methodSctcc.setRegularExpression("([a-zA-Z][a-zA-Z_0-9]+)");
096: //
097: methodSctcc.addDefaultValue("MethodNameHere");
098: //stc1.setReturnClassExclusions(Void.TYPE);
099: //TO DO: check if method name goes with object
100:
101: //constrain "parameter"
102: ConceptTagConstraint parameterCtcon = ConceptTagConstraint
103: .newInstance(PARAMETER_CTCON, rootCtconh);
104: parameterCtcon.setMinimumLength(0);
105: parameterCtcon.setLengthUnbounded(true);
106: parameterCtcon.setTitle(PARAMETER_TITLE);
107: parameterCtcon.setShortDescription(PARAMETER_SHORT_DESCRIPTION);
108: //
109: DynamicConceptTagConstraintContext parameterDctcc = DynamicConceptTagConstraintContext
110: .newInstance(parameterCtcon);
111: parameterDctcc.getValidator()
112: .allowReturnOfAnythingExceptNothing();
113: parameterDctcc.getValidator().filterDirectChildOfRootAndHtml();
114:
115: //TO DO: check correctness of parameters with method, caller
116:
117: //
118: ConceptTagFlagsHelper
119: .pushNonIterativeCommonFunctionDepth(inIctc);
120: inIctc.initialize();
121: ConceptTagFlagsHelper
122: .popNonIterativeCommonFunctionDepth(inIctc);
123:
124: //initialize characteristic
125: this .callerCtchar = callerCtcon.getCharacteristic();
126: this .methodCtchar = methodCtcon.getCharacteristic();
127: this .parameterCtchar = parameterCtcon.getCharacteristic();
128:
129: }
130:
131: public void appraise(AppraiseConceptTagContext inActc) {
132:
133: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
134:
135: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
136:
137: sctiic.setInstanceTitle("Call");
138: sctiic.setInstanceDescription("Calls a funtion");
139: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
140:
141: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
142:
143: scttic.setTypeTitle("Call");
144: scttic.setTypeDescription("Calls a function");
145: } else if (inActc instanceof WebPageTagInstanceViewContext) {
146:
147: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
148:
149: WebPageTagInstanceViewContextInfo info = wptivc
150: .getInfoAsNonHtml();
151: info.setNonHtmlContent("Call - Not Impl");
152: //wptivc.getInfo().setStartContent("");
153: //wptivc.getInfo().setEndContent("");
154: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
155:
156: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
157:
158: scfrct.canReturnAnythingIncludingNothing();
159: scfrct.declareFormatAsPlain();
160: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
161:
162: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
163: }
164: }
165:
166: public void determineValueAndClass(
167: DetermineValueAndClassConceptTagContext inDvacctc) {
168:
169: try {
170:
171: ValueAndClassForConceptTag vacfct = null;
172:
173: //initialize variables
174: ValueAndClassForConceptTag objectVac = this .callerCtchar
175: .getDetermineValueAndClass(0, inDvacctc);
176: Class rClass = objectVac.getValueClass();
177: Object rValue = objectVac.getValue();
178: String methodName = this .methodCtchar.getValueAsString(0,
179: inDvacctc);
180: Class pClasses[] = new Class[this .parameterCtchar
181: .getValueLength()];
182: Object pValues[] = new Object[this .parameterCtchar
183: .getValueLength()];
184: for (int i = 0; i < this .parameterCtchar.getValueLength(); i++) {
185: ValueAndClassForConceptTag nextVac = this .parameterCtchar
186: .getDetermineValueAndClass(i, inDvacctc);
187: pClasses[i] = nextVac.getValueClass();
188: pValues[i] = nextVac.getValue();
189: }
190:
191: //create method
192: Method method = rClass.getMethod(methodName, pClasses);
193:
194: //execute method
195: Class vacClass = method.getReturnType();
196: Object vacObject = method.invoke(rValue, pValues);
197: vacfct = ValueAndClassForConceptTag.newInstance(vacObject,
198: vacClass);
199:
200: inDvacctc.setDetermineValueAndClass(vacfct);
201: } catch (DetermineValueAndClassConceptTagException dvaccte) {
202: inDvacctc.setDetermineException(dvaccte);
203: } catch (NoSuchMethodException nsme) {
204: inDvacctc.setDetermineException(nsme);
205: } catch (IllegalAccessException iae) {
206: inDvacctc.setDetermineException(iae);
207: } catch (InvocationTargetException ite) {
208: inDvacctc.setDetermineException(ite);
209: }
210: }
211:
212: public void determineClass(DetermineClassConceptTagContext inDcctc) {
213:
214: try {
215: //initialize variables
216: Class rClass = this .callerCtchar.getDetermineClass(0,
217: inDcctc);
218: String methodName = this .methodCtchar.getValueAsString(0,
219: inDcctc);
220: Class pClasses[] = new Class[this .parameterCtchar
221: .getValueLength()];
222: for (int i = 0; i < this .parameterCtchar.getValueLength(); i++) {
223: pClasses[i] = this .parameterCtchar.getDetermineClass(i,
224: inDcctc);
225: }
226:
227: //create method
228: Method method = rClass.getMethod(methodName, pClasses);
229:
230: //execute method
231: inDcctc.setDetermineClass(method.getReturnType());
232: } catch (DetermineClassConceptTagException dccte) {
233: inDcctc.setDetermineException(dccte);
234: } catch (NoSuchMethodException nsme) {
235: inDcctc.setDetermineException(nsme);
236: }
237:
238: }
239:
240: public Object createUninitializedSelf() {
241: return new CommonFunctionLangCallTag();
242: }
243: }
|