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.CoreConceptTag;
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.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:
029: //other classes
030:
031: public class AttributeWorkflowTemplateTag implements CoreConceptTag {
032:
033: //characteristics
034: private ConceptTagCharacteristic nameCtchar = null;
035: private ConceptTagCharacteristic accessCtchar = null;
036: private ConceptTagCharacteristic typeCtchar = null;
037: private ConceptTagCharacteristic valueCtchar = null;
038:
039: //name details
040: private final static String NAME_CTCON = "name";
041: private final static String NAME_TITLE = "Name";
042: private final static String NAME_SHORT_DESCRIPTION = "Name of this attribute";
043:
044: //access details
045: private final static String ACCESS_CTCON = "access";
046: private final static String ACCESS_TITLE = "Access";
047: private final static String ACCESS_SHORT_DESCRIPTION = "Access to attribute - public or private";
048:
049: //class details
050: private final static String TYPE_CTCON = "type";
051: private final static String TYPE_TITLE = "Type";
052: private final static String TYPE_SHORT_DESCRIPTION = "Type of this attribute";
053:
054: //value details
055: private final static String VALUE_CTCON = "value";
056: private final static String VALUE_TITLE = "Value";
057: private final static String VALUE_SHORT_DESCRIPTION = "Initial value of this attribute (Must implement serializable)";
058:
059: //TO DO: add array capability
060:
061: public void initialize(InitializeConceptTagContext inIctc) {
062:
063: //
064: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
065: .newInstance(inIctc);
066:
067: //constrain "name"
068: ConceptTagConstraint nameCtcon = ConceptTagConstraint
069: .newInstance(NAME_CTCON, rootCtconh);
070: nameCtcon.setTitle(NAME_TITLE);
071: nameCtcon.setShortDescription(NAME_SHORT_DESCRIPTION);
072: //
073: StaticConceptTagConstraintContext nameSctcc = StaticConceptTagConstraintContext
074: .newInstance(nameCtcon);
075: nameSctcc.setRegularExpression(CommonExpressions.JAVA_NAME);
076: //
077: nameSctcc.addDefaultValue("AttributeName");
078: //((InitializeConceptTagContextBean)inItc).registerAttribute(
079: // this.nameTc, this.classTc);
080:
081: //constrain "access"
082: ConceptTagConstraint accessCtcon = ConceptTagConstraint
083: .newInstance(ACCESS_CTCON, rootCtconh);
084: accessCtcon.setTitle(ACCESS_TITLE);
085: accessCtcon.setShortDescription(ACCESS_SHORT_DESCRIPTION);
086: //
087: StaticConceptTagConstraintContext accessSctcc = StaticConceptTagConstraintContext
088: .newInstance(accessCtcon);
089: accessSctcc.registerEntry("Can Query", "Public");
090: accessSctcc.registerEntry("Cannot Query", "Private");
091: accessSctcc.setEntrySetExclusive(true);
092: //
093: accessSctcc.addDefaultValue("Public");
094:
095: //constrain "type"
096: ConceptTagConstraint typeCtcon = ConceptTagConstraint
097: .newInstance(TYPE_CTCON, rootCtconh);
098: typeCtcon.setTitle(TYPE_TITLE);
099: typeCtcon.setShortDescription(TYPE_SHORT_DESCRIPTION);
100: //
101: StaticConceptTagConstraintContext typeSctcc = StaticConceptTagConstraintContext
102: .newInstance(typeCtcon);
103: typeSctcc.setRegularExpression("[a-zA-Z\\.]+");//TO DO: verify this
104: typeSctcc.registerEntry("String", "java.lang.String");
105: typeSctcc.registerEntry("Decimal", "java.math.BigDecimal");
106: typeSctcc.registerEntry("Boolean", "boolean");
107: typeSctcc.addDefaultValue("java.lang.String");
108:
109: //constrain "value"
110: ConceptTagConstraint valueCtcon = ConceptTagConstraint
111: .newInstance(VALUE_CTCON, rootCtconh);
112: valueCtcon.setTitle(VALUE_TITLE);
113: valueCtcon.setShortDescription(VALUE_SHORT_DESCRIPTION);
114: //
115: DynamicConceptTagConstraintContext valueDctcc = DynamicConceptTagConstraintContext
116: .newInstance(valueCtcon);
117: //valueDctcc.addDefaultValue(StringWorkflowTemplateTag.class);
118: valueDctcc.getValidator().allowReturnOfAnythingExceptNothing();
119:
120: //((InitializeConceptTagContextBean)inItc).forbidAttributeUse(
121: // this.valueTc);
122:
123: inIctc.initialize();
124: //
125: //initialize characteristics
126: this .nameCtchar = nameCtcon.getCharacteristic();
127: this .accessCtchar = accessCtcon.getCharacteristic();
128: this .typeCtchar = typeCtcon.getCharacteristic();
129: this .valueCtchar = valueCtcon.getCharacteristic();
130: //
131:
132: }
133:
134: public void appraise(AppraiseConceptTagContext inCtic) {
135: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
136: StudioConceptTagInstanceInfoContext stiic = (StudioConceptTagInstanceInfoContext) inCtic;
137: stiic.setInstanceTitle(this .nameCtchar.getValueAsString(0,
138: inCtic));
139: stiic
140: .setInstanceDescription("Contains attributes for the workflow-instance");
141: stiic.setLocalInstanceIcon("public-attribute");
142: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
143: StudioConceptTagTypeInfoContext sttic = (StudioConceptTagTypeInfoContext) inCtic;
144: sttic.setTypeTitle("Attribute");
145: sttic
146: .setTypeDescription("Contains attributes for the workflow-instance");
147: }
148: }
149:
150: public ValueAndClassForConceptTag getInitialValue(
151: DetermineValueAndClassConceptTagContext inRvacc)
152: throws DetermineValueAndClassConceptTagException {
153:
154: return this .valueCtchar.getDetermineValueAndClass(0, inRvacc);
155: }
156:
157: public String getAttributeName() {
158: return this .nameCtchar.getValueAsString(0, null);
159: }
160:
161: public Class getAttributeClass() {
162: return MiscHelper.getClassByName(this .typeCtchar
163: .getValueAsString(0, null));
164: }
165:
166: public boolean isAttributePublic() {
167:
168: boolean outValue = false;
169:
170: String access = this .accessCtchar.getValueAsString(0, null);
171: outValue = access.trim().equalsIgnoreCase("PUBLIC");
172:
173: return outValue;
174: }
175:
176: /*
177: public void getTagSummary(TagSummaryDescriptor tsd) {
178: //TO DO: placeholder, put meaningful description
179: if (tsd.getMimeType().equals(TagSummaryMimeType.TEXT_HTML)) {
180: tsd.appendData("<table width=\"100%\">");
181: tsd.appendData("<tr><td style=\"font-size: 20; font-family:
182: // Arial; color: #000000;\">");
183: tsd.appendData("Attributes");
184: tsd.appendData("</td></tr>");
185: for (int i = 0; i < this.attributeTags.size(); i++) {
186: tsd.appendData("<tr><td>");
187: ((Tag)this.attributeTags.get(i)).getTagSummary(tsd);
188: tsd.appendData("</td></tr>");
189: }
190: //tsd.appendData("<tr><td>");
191: //tsd.appendData("</td></tr>");
192: tsd.appendData("</table>");
193: }
194: }
195:
196: */
197: }
|