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.Constructor;
012: import java.lang.reflect.InvocationTargetException;
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.DetermineValueAndClassConceptTagContext;
028: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
029: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
030: import org.jfolder.common.tagging.InitializeConceptTagContext;
031: import org.jfolder.common.tagging.ReturnableConceptTag;
032: import org.jfolder.common.tagging.SelectionCriteriaForReturnableConceptTag;
033: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
034: import org.jfolder.common.tagging.StudioConceptTagCreParInfoContext;
035: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
036: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
037: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
038:
039: //other classes
040:
041: public class CommonFunctionLangConstructorTag extends
042: BaseCommonFunctionCompatibilityTag implements
043: SelfArgumentlessConstructor {
044:
045: //characteristics
046: private ConceptTagCharacteristic typeCtchar = null;
047: private ConceptTagCharacteristic parameterCtchar = null;
048:
049: //type details
050: private final static String TYPE_CTCON = "type";
051: private final static String TYPE_TITLE = "Class";
052: private final static String TYPE_SHORT_DESCRIPTION = "Class whose constructor will be called";
053:
054: //parameter details
055: private final static String PARAMETER_CTCON = "parameter";
056: private final static String PARAMETER_TITLE = "Parameters";
057: private final static String PARAMETER_SHORT_DESCRIPTION = "Parameters to be passed to the constructor";
058:
059: public void initialize(InitializeConceptTagContext inIctc) {
060:
061: //
062: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
063: .newInstance(inIctc);
064:
065: //constrain "type"
066: ConceptTagConstraint typeCtcon = ConceptTagConstraint
067: .newInstance(TYPE_CTCON, rootCtconh);
068: typeCtcon.setTitle(TYPE_TITLE);
069: typeCtcon.setShortDescription(TYPE_SHORT_DESCRIPTION);
070: //
071: StaticConceptTagConstraintContext typeSctcc = StaticConceptTagConstraintContext
072: .newInstance(typeCtcon);
073: typeSctcc
074: .setRegularExpression("([a-zA-Z][a-zA-Z_0-9]+(\\.[a-zA-Z][a-zA-Z_0-9]+)*)");
075: //
076: typeSctcc.addDefaultValue("Put.Your.Class.Here");
077: //TO DO: check if class exists
078:
079: //constrain parameter
080: ConceptTagConstraint parameterCtcon = ConceptTagConstraint
081: .newInstance(PARAMETER_CTCON, rootCtconh);
082: parameterCtcon.setMinimumLength(0);
083: parameterCtcon.setLengthUnbounded(true);
084: parameterCtcon.setTitle(this .PARAMETER_TITLE);
085: parameterCtcon
086: .setShortDescription(this .PARAMETER_SHORT_DESCRIPTION);
087: //mdtc1.setClassRestrictions(ReturnableConceptTag.class);
088: //
089: DynamicConceptTagConstraintContext parameterDctcc = DynamicConceptTagConstraintContext
090: .newInstance(parameterCtcon);
091: parameterDctcc.getValidator()
092: .allowReturnOfAnythingExceptNothing();
093: parameterDctcc.getValidator().filterDirectChildOfRootAndHtml();
094: //
095: //parameterDctcc.addDefaultValue(
096: // GetApplicationAttributeWorkflowTemplateTag.class);
097:
098: //
099: ConceptTagFlagsHelper
100: .pushNonIterativeCommonFunctionDepth(inIctc);
101: inIctc.initialize();
102: ConceptTagFlagsHelper
103: .popNonIterativeCommonFunctionDepth(inIctc);
104:
105: //initialize characteristics
106: this .typeCtchar = typeCtcon.getCharacteristic();
107: this .parameterCtchar = parameterCtcon.getCharacteristic();
108:
109: }
110:
111: public void appraise(AppraiseConceptTagContext inActc) {
112:
113: if (inActc instanceof StudioConceptTagInstanceInfoContext) {
114:
115: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inActc;
116:
117: sctiic.setInstanceTitle("Constructor");
118: sctiic
119: .setInstanceDescription("Creates a new class instance by calling "
120: + "the constructor on a class");
121: } else if (inActc instanceof StudioConceptTagTypeInfoContext) {
122:
123: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inActc;
124:
125: scttic.setTypeTitle("Constructor");
126: scttic
127: .setTypeDescription("Creates a new class instance by calling "
128: + "the constructor on a class");
129: } else if (inActc instanceof WebPageTagInstanceViewContext) {
130:
131: WebPageTagInstanceViewContext wptivc = (WebPageTagInstanceViewContext) inActc;
132:
133: WebPageTagInstanceViewContextInfo info = wptivc
134: .getInfoAsNonHtml();
135: info.setNonHtmlContent("Constructor - Not Impl");
136: //wptivc.getInfo().setStartContent("");
137: //wptivc.getInfo().setEndContent("");
138: } else if (inActc instanceof SelectionCriteriaForReturnableConceptTag) {
139:
140: SelectionCriteriaForReturnableConceptTag scfrct = (SelectionCriteriaForReturnableConceptTag) inActc;
141:
142: scfrct.canReturnAnythingExceptNothing();
143: scfrct.declareFormatAsPlain();
144: } else if (inActc instanceof StudioConceptTagCreParInfoContext) {
145:
146: StudioConceptTagCreParInfoContext scpc = (StudioConceptTagCreParInfoContext) inActc;
147: }
148: }
149:
150: public void determineValueAndClass(
151: DetermineValueAndClassConceptTagContext inDvacctc) {
152:
153: try {
154: ValueAndClassForConceptTag vacfct = null;
155:
156: //initialize variables
157: Class conClass = Class.forName(this .typeCtchar
158: .getValueAsString(0, inDvacctc));
159: Class pClasses[] = new Class[this .parameterCtchar
160: .getValueLength()];
161: Object pValues[] = new Object[this .parameterCtchar
162: .getValueLength()];
163: for (int i = 0; i < this .parameterCtchar.getValueLength(); i++) {
164: ValueAndClassForConceptTag nextVac = this .parameterCtchar
165: .getDetermineValueAndClass(i, inDvacctc);
166: pClasses[i] = nextVac.getValueClass();
167: pValues[i] = nextVac.getValue();
168: }
169:
170: //create method
171: Constructor con = conClass.getConstructor(pClasses);
172:
173: //execute method
174: Object vacObject = con.newInstance(pValues);
175: vacfct = ValueAndClassForConceptTag.newInstance(vacObject,
176: conClass);
177:
178: inDvacctc.setDetermineValueAndClass(vacfct);
179: } catch (DetermineValueAndClassConceptTagException dvaccte) {
180: inDvacctc.setDetermineException(dvaccte);
181: } catch (ClassNotFoundException cnfe) {
182: inDvacctc.setDetermineException(cnfe);
183: } catch (NoSuchMethodException nsme) {
184: inDvacctc.setDetermineException(nsme);
185: } catch (InstantiationException ie) {
186: inDvacctc.setDetermineException(ie);
187: } catch (IllegalAccessException iae) {
188: inDvacctc.setDetermineException(iae);
189: } catch (InvocationTargetException ite) {
190: inDvacctc.setDetermineException(ite);
191: }
192: }
193:
194: public void determineClass(DetermineClassConceptTagContext inDcctc) {
195: try {
196: Class c = Class.forName(this .typeCtchar.getValueAsString(0,
197: inDcctc));
198: inDcctc.setDetermineClass(c);
199: } catch (ClassNotFoundException cnfe) {
200: inDcctc.setDetermineException(cnfe);
201: }
202: }
203:
204: public Object createUninitializedSelf() {
205: return new CommonFunctionLangConstructorTag();
206: }
207: }
|