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.workflow.model.template.v1;
009:
010: //base classes
011:
012: //project specific classes
013: import org.jfolder.common.tagging.AppraiseConceptTagContext;
014: import org.jfolder.common.tagging.ConceptTagCharacteristic;
015: import org.jfolder.common.tagging.ConceptTagConstraint;
016: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
017: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
018: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
019: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
020: import org.jfolder.common.tagging.DynamicConceptTagConstraintContext;
021: import org.jfolder.common.tagging.InitializeConceptTagContext;
022: import org.jfolder.common.tagging.ReturnableConceptTag;
023: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
024: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
025: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
026: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
027: import org.jfolder.common.utils.misc.CommonExpressions;
028: import org.jfolder.common.utils.misc.MiscHelper;
029: import org.jfolder.workflow.model.attributes.AttributeSet;
030: import org.jfolder.workflow.model.template.*;
031:
032: //other classes
033:
034: public class SetApplicationAttributeWorkflowTemplateTag implements
035: ReturnableConceptTag {
036:
037: //characteristics
038: private ConceptTagCharacteristic nameCtchar = null;
039: private ConceptTagCharacteristic operandCtchar = null;
040: private String attributeClass = null;
041:
042: //name details
043: private final static String NAME_CTCON = "name";
044: private final static String NAME_TITLE = "Application Attribute";
045: private final static String NAME_SHORT_DESCRIPTION = "Application attribute to be set by operand";
046:
047: //operand details
048: private final static String OPERAND_CTCON = "operand";
049: private final static String OPERAND_TITLE = "Operand";
050: private final static String OPERAND_SHORT_DESCRIPTION = "Value that will be assigned to the application attribute";
051:
052: public void initialize(InitializeConceptTagContext inIctc) {
053:
054: //
055: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
056: .newInstance(inIctc);
057:
058: //constrain "name"
059: ConceptTagConstraint nameCtcon = ConceptTagConstraint
060: .newInstance(NAME_CTCON, rootCtconh);
061: nameCtcon.setTitle(NAME_TITLE);
062: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
063: //
064: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
065: .newInstance(nameCtcon);
066: nameSctcc.setRegularExpression(CommonExpressions.JAVA_NAME);
067: //
068: nameSctcc.addDefaultValue("AttributeNameHere");
069: //((InitializeConceptTagContextBean)inItc).requireAttributeUse(
070: // this.nameTc);
071: //TO DO: check if attribute exists
072:
073: //constrain "operand"
074: ConceptTagConstraint operandCtcon = ConceptTagConstraint
075: .newInstance(OPERAND_CTCON, rootCtconh);
076: operandCtcon.setTitle(OPERAND_TITLE);
077: operandCtcon.setShortDescription(OPERAND_SHORT_DESCRIPTION);
078: //dtc1.setClassRestrictions(ReturnableTag.class);
079: //dtc1.setReturnClassRestrictions(Object.class);
080: //
081: DynamicConceptTagConstraintContext operandDctcc = DynamicConceptTagConstraintContext
082: .newInstance(operandCtcon);
083: operandDctcc.getValidator()
084: .allowReturnOfAnythingExceptNothing();
085: //
086: operandDctcc
087: .addDefaultValue(GetApplicationAttributeWorkflowTemplateTag.class);
088: //TO DO: possibly constrain return type here instead of below?
089:
090: inIctc.initialize();
091:
092: //initialize characteristics
093: this .nameCtchar = nameCtcon.getCharacteristic();
094: this .operandCtchar = operandCtcon.getCharacteristic();
095:
096: //TO DO: change this
097: this .attributeClass = Object.class.getName();
098: //TO DO: check if casting is acceptable after initialization
099: //post initialization
100: //if (this.nameTc.getValueLength() >= 1 && this.nameTc.isStatic(0)) {
101: // this.attributeClass =
102: // ((InitializeConceptTagContextBean)inItc).getAttributeClass(
103: // this.nameTc.getValueAsString(0));
104: //}
105: //else {
106: // this.attributeClass = Object.class.getName();
107: //}
108: }
109:
110: public void appraise(AppraiseConceptTagContext inCtic) {
111: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
112: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
113: String name = "(Unknown)";
114: if (this .nameCtchar.getValueLength() >= 1
115: && this .nameCtchar.isStatic(0, inCtic)) {
116: name = this .nameCtchar.getValueAsString(0, inCtic);
117: }
118: String resultTitle = "(Unknown)";
119: String resultDesc = "(Unknown)";
120: if (this .operandCtchar.isHolderWithConceptTag(0, inCtic)) {
121: StudioConceptTagInstanceInfoContext nextStiic = this .operandCtchar
122: .getInstanceInformation(0);
123:
124: resultTitle = nextStiic.getInstanceTitle();
125: resultDesc = nextStiic.getInstanceDescription();
126: }
127: sctiic.setInstanceTitle("SetAttribute(" + name + " = "
128: + resultTitle + ")");
129: sctiic
130: .setInstanceDescription("Set the value of an application attribute '"
131: + name + "' equal to - " + resultDesc);
132: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
133: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
134: scttic.setTypeTitle("Set Application Attribute");
135: scttic
136: .setTypeDescription("Assigns a new value to an application attribute");
137: }
138: }
139:
140: public void determineValueAndClass(
141: DetermineValueAndClassConceptTagContext inRvacc) {
142:
143: try {
144: ValueAndClassForConceptTag outValue = null;
145:
146: ComponentsForReturnableWorkflowTemplateTag wcfrt = WorkflowTemplateTagHelper
147: .getComponentsForReturnableWorkflowTemplateTag(inRvacc);
148:
149: AttributeSet as = wcfrt.getAttributeSet();
150: String name = this .nameCtchar.getValueAsString(0, inRvacc);
151:
152: if (!as.isAppAttrPresent(name)) {
153: inRvacc
154: .setDetermineException(new DetermineValueAndClassConceptTagException(
155: "Application attribute '" + name
156: + "' does not exist"));
157: } else {
158: as.setAppAttr(name, this .operandCtchar
159: .getDetermineValueAndClass(0, inRvacc));
160:
161: outValue = as.getAppAttr(name);
162:
163: inRvacc.setDetermineValueAndClass(outValue);
164: }
165:
166: } catch (DetermineValueAndClassConceptTagException dvaccte) {
167: inRvacc.setDetermineException(dvaccte);
168: }
169: }
170:
171: public void determineClass(DetermineClassConceptTagContext inRcc) {
172:
173: try {
174: Class c = Class.forName(this .attributeClass);
175: inRcc.setDetermineClass(c);
176: } catch (ClassNotFoundException cnfe) {
177: inRcc.setDetermineException(cnfe);
178: }
179: }
180: /*
181: public void getTagSummary(TagSummaryDescriptor tsd) {
182: //TO DO: placeholder, put meaningful description
183: if (tsd.getMimeType().equals(TagSummaryMimeType.TEXT_HTML)) {
184: tsd.appendData("Set <i>" + this.nameAttr[0] + "</i> equal to ");
185: if (this.returnableTags.size() > 0) {
186: ((Tag)(this.returnableTags.get(0))).getTagSummary(tsd);
187: }
188: }
189: }
190: */
191: }
|