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: import java.io.IOException;
012: import javax.xml.parsers.ParserConfigurationException;
013: import org.w3c.dom.Document;
014: import org.w3c.dom.Element;
015: import org.xml.sax.SAXException;
016:
017: //project specific classes
018: import org.jfolder.common.tagging.AppraiseConceptTagContext;
019: import org.jfolder.common.tagging.ConceptTagCharacteristic;
020: import org.jfolder.common.tagging.ConceptTagConstraint;
021: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
022: import org.jfolder.common.tagging.ConceptTagHelper;
023: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
024: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
025: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
026: import org.jfolder.common.tagging.InitializeConceptTagContext;
027: import org.jfolder.common.tagging.ReturnableConceptTag;
028: import org.jfolder.common.tagging.StaticConceptTagConstraintContext;
029: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
030: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
031: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
032: import org.jfolder.common.utils.misc.CommonExpressions;
033: import org.jfolder.common.utils.misc.MiscHelper;
034: import org.jfolder.common.utils.xml.XMLHelper;
035:
036: //other classes
037:
038: public class GetTriggerAttributeWorkflowTemplateTag implements
039: ReturnableConceptTag {
040:
041: //ConceptTag characteristic
042: private ConceptTagCharacteristic pathCtchar = null;
043: private ConceptTagCharacteristic attributeCtchar = null;
044:
045: //path details
046: private final static String PATH_CTCON = "path";
047: private final static String PATH_TITLE = "Path";
048: private final static String PATH_SHORT_DESCRIPTION = "Path to the element in the trigger containing the attribute";
049: //TO DO: elaborate above
050:
051: //attribute details
052: private final static String ATTRIBUTE_CTCON = "attribute";
053: private final static String ATTRIBUTE_TITLE = "Attribute";
054: private final static String ATTRIBUTE_SHORT_DESCRIPTION = "Attribute, not workflow but XML, sought";
055:
056: //TO DO: elaborate above
057:
058: public void initialize(InitializeConceptTagContext inIctc) {
059:
060: //
061: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
062: .newInstance(inIctc);
063:
064: //constrain "path"
065: ConceptTagConstraint pathCtcon = ConceptTagConstraint
066: .newInstance(PATH_CTCON, rootCtconh);
067: pathCtcon.setTitle(PATH_TITLE);
068: pathCtcon.setShortDescription(PATH_SHORT_DESCRIPTION);
069: //
070: StaticConceptTagConstraintContext pathSctcc = StaticConceptTagConstraintContext
071: .newInstance(pathCtcon);
072: pathSctcc.setRegularExpression(CommonExpressions.ANY_STRING);
073: //
074: pathSctcc.addDefaultValue("XMLPATH");
075: //TO DO: provide better default
076: //TO DO: define regular expression
077:
078: //constrain "attribute"
079: ConceptTagConstraint attributeCtcon = ConceptTagConstraint
080: .newInstance(ATTRIBUTE_CTCON, rootCtconh);
081: attributeCtcon.setTitle(ATTRIBUTE_TITLE);
082: attributeCtcon.setShortDescription(ATTRIBUTE_SHORT_DESCRIPTION);
083: //
084: StaticConceptTagConstraintContext attributeSctcc = StaticConceptTagConstraintContext
085: .newInstance(attributeCtcon);
086: attributeSctcc
087: .setRegularExpression(CommonExpressions.ANY_STRING);
088: //
089: attributeSctcc.addDefaultValue("XMLAttribute");
090: //TO DO: provide better default
091: //TO DO: define regular expression
092:
093: inIctc.initialize();
094:
095: //initialize characteristics
096: this .pathCtchar = pathCtcon.getCharacteristic();
097: this .attributeCtchar = attributeCtcon.getCharacteristic();
098:
099: }
100:
101: public void appraise(AppraiseConceptTagContext inCtic) {
102: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
103: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
104: sctiic.setInstanceTitle("Get Trigger Attribute");
105: sctiic
106: .setInstanceDescription("Get an attribute value from a trigger element");
107: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
108: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
109: scttic.setTypeTitle("Get Trigger Attribute");
110: scttic
111: .setTypeDescription("Get an attribute value from a trigger element");
112: }
113: }
114:
115: public void determineValueAndClass(
116: DetermineValueAndClassConceptTagContext inRvacc) {
117:
118: inRvacc
119: .setDetermineException(new DetermineValueAndClassConceptTagException(
120: "Not Implemented"));
121: //ValueAndClassForConceptTag outValue = null;
122:
123: /*
124: ComponentsForReturnableConceptTag wcfrt =
125: ConceptTagHelper.getComponentsForReturnableScriptTag(
126: inRvacc);
127:
128: Trigger t = wcfrt.getTrigger();
129:
130: //X-Path creation and validation
131: String xpathData = null;
132:
133: if (this.pathTc.isStatic()) {
134: xpathData = this.pathTc.getValueAsString();
135: }
136: else if (this.pathTc.isDynamic()) {
137:
138: ValueAndClass outValue = this.pathTc.getDetermineValueAndClass(
139: inRvacc);
140: xpathData = (String)vac.getValue();
141: }
142:
143: String xpathErrors = XMLHelper.isXPathValid(xpathData);
144:
145: if (xpathErrors != null) {
146: throw new DetermineValueAndClassConceptTagException("X-Path '"
147: + xpathData
148: + "' is invalid for the following reasons - " + xpathErrors);
149: }
150:
151: //elementName creation and validation
152: String attrName = null;
153:
154: if (this.attributeTc.isStatic()) {
155: attrName = this.attributeTc.getValueAsString();
156: }
157: else if (this.attributeTc.isDynamic()) {
158:
159: ValueAndClass outValue =
160: this.attributeTc.getDetermineValueAndClass(inRvacc);
161: attrName = (String)vac.getValue();
162: }
163:
164: //trigger document creation and validation
165: Document doc = null;
166: try {
167: doc = XMLHelper.loadDocument(t.getDataAsString());
168: }
169: catch (ParserConfigurationException pce) {
170: throw new DetermineValueAndClassConceptTagException(pce);
171: }
172: catch (SAXException saxe) {
173: throw new DetermineValueAndClassConceptTagException(saxe);
174: }
175: catch (IOException ioe) {
176: throw new DetermineValueAndClassConceptTagException(ioe);
177: }
178:
179: Element element = XMLHelper.getXPathElement(doc, xpathData);
180:
181: return ValueAndClassFactory.newValueAndClass(
182: XMLHelper.getElementAttribute(doc, xpathData, attrName),
183: String.class);
184: */
185: //return outValue;
186: }
187:
188: public void determineClass(DetermineClassConceptTagContext inRcc) {
189: inRcc.setDetermineClass(String.class);
190: }
191:
192: }
|