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.InitializeConceptTagContext;
021: import org.jfolder.common.tagging.ReturnableConceptTag;
022: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
023: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
024: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
025: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
026: import org.jfolder.common.utils.misc.CommonExpressions;
027: import org.jfolder.common.utils.misc.MiscHelper;
028: import org.jfolder.workflow.model.attributes.AttributeSet;
029: import org.jfolder.workflow.model.template.*;
030:
031: //other classes
032:
033: public class GetApplicationAttributeWorkflowTemplateTag implements
034: ReturnableConceptTag {
035:
036: //characteristics
037: private ConceptTagCharacteristic nameCtchar = null;
038: private String attributeClass = null;
039:
040: //method details
041: private final static String NAME_CTCON = "name";
042: private final static String NAME_TITLE = "Application Attribute";
043: private final static String NAME_SHORT_DESCRIPTION = "Application attribute sought";
044:
045: public void initialize(InitializeConceptTagContext inIctc) {
046:
047: //
048: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
049: .newInstance(inIctc);
050:
051: //constrain "name"
052: ConceptTagConstraint nameCtcon = ConceptTagConstraint
053: .newInstance(NAME_CTCON, rootCtconh);
054: nameCtcon.setTitle(NAME_TITLE);
055: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
056: //
057: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
058: .newInstance(nameCtcon);
059: nameSctcc.setRegularExpression(CommonExpressions.JAVA_NAME);
060: //
061: nameSctcc.addDefaultValue("AttributeNameHere");
062: //((InitializeConceptTagContextBean)inItc).requireAttributeUse(
063: // this.nameTc);
064: //TO DO: check if attribute exists
065:
066: inIctc.initialize();
067:
068: //initialize characteristics
069: this .nameCtchar = nameCtcon.getCharacteristic();
070:
071: //TO DO: change this
072: this .attributeClass = Object.class.getName();
073: //post initialization
074: //if (this.nameTc.getValueLength() >= 1 && this.nameTc.isStatic(0)) {
075: // this.attributeClass =
076: // ((InitializeConceptTagContextBean)inItc).getAttributeClass(
077: // this.nameTc.getValueAsString(0));
078: //}
079: //else {
080: // this.attributeClass = Object.class.getName();
081: //}
082: }
083:
084: public void appraise(AppraiseConceptTagContext inCtic) {
085: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
086: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
087: String name = "(Unknown)";
088: if (this .nameCtchar.getValueLength() >= 1
089: && this .nameCtchar.isStatic(0, inCtic)) {
090:
091: name = this .nameCtchar.getValueAsString(0, inCtic);
092: }
093: sctiic.setInstanceTitle("GetAttribute(" + name + ")");
094: sctiic
095: .setInstanceDescription("Get the value of an application attribute '"
096: + name + "'");
097: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
098: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
099: scttic.setTypeTitle("Get Application Attribute");
100: scttic
101: .setTypeDescription("Gets the value of an application attribute");
102: }
103: }
104:
105: public void determineValueAndClass(
106: DetermineValueAndClassConceptTagContext inRvacc) {
107:
108: ValueAndClassForConceptTag outValue = null;
109:
110: ComponentsForReturnableWorkflowTemplateTag wcfrt = WorkflowTemplateTagHelper
111: .getComponentsForReturnableWorkflowTemplateTag(inRvacc);
112:
113: AttributeSet as = wcfrt.getAttributeSet();
114: String name = this .nameCtchar.getValueAsString(0, inRvacc);
115: //MiscHelper.println("GetAppAttrSt name = " + name);
116: //MiscHelper.println("GetAppAttrSt count = "
117: // + as.getPublicAppAttrCount());
118:
119: //java.util.Iterator iter = as.getPublicAppAttrNames();
120: //while (iter.hasNext()) {
121: // MiscHelper.println("GetAppAttrSt iter = " + iter.next());
122: //}
123:
124: if (!as.isAppAttrPresent(name)) {
125: inRvacc
126: .setDetermineException(new DetermineValueAndClassConceptTagException(
127: "Application attribute '" + name
128: + "' does not exist"));
129: } else {
130: outValue = as.getAppAttr(name);
131:
132: inRvacc.setDetermineValueAndClass(outValue);
133: }
134: }
135:
136: public void determineClass(DetermineClassConceptTagContext inRcc) {
137: try {
138: Class c = Class.forName(this .attributeClass);
139:
140: inRcc.setDetermineClass(c);
141: } catch (ClassNotFoundException cnfe) {
142: inRcc.setDetermineException(cnfe);
143: }
144: }
145: }
|