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 java.math.BigDecimal;
013: import javax.xml.parsers.ParserConfigurationException;
014: import org.w3c.dom.Document;
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 GetTriggerElementCountWorkflowTemplateTag implements
039: ReturnableConceptTag {
040:
041: //characteristics
042: private ConceptTagCharacteristic pathCtchar = null;
043: private ConceptTagCharacteristic elementCtchar = 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 elements";
049: //TO DO: elaborate above
050:
051: //element details
052: //TO DO: is this needed, already have path
053: private final static String ELEMENT_CTCON = "element";
054: private final static String ELEMENT_TITLE = "Element";
055: private final static String ELEMENT_SHORT_DESCRIPTION = "XML element to be counted";
056:
057: //TO DO: elaborate above
058:
059: public void initialize(InitializeConceptTagContext inIctc) {
060:
061: //
062: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
063: .newInstance(inIctc);
064:
065: //constrain "path"
066: ConceptTagConstraint pathCtcon = ConceptTagConstraint
067: .newInstance(PATH_CTCON, rootCtconh);
068: pathCtcon.setTitle(PATH_TITLE);
069: pathCtcon.setShortDescription(PATH_SHORT_DESCRIPTION);
070: //
071: StaticConceptTagConstraintContext pathSctcc = StaticConceptTagConstraintContext
072: .newInstance(pathCtcon);
073: pathSctcc.setRegularExpression(CommonExpressions.ANY_STRING);
074: //
075: pathSctcc.addDefaultValue("XMLPATH");
076: //TO DO: provide better default
077: //TO DO: define regular expression
078:
079: //constrain "element"
080: ConceptTagConstraint elementCtcon = ConceptTagConstraint
081: .newInstance(ELEMENT_CTCON, rootCtconh);
082: elementCtcon.setTitle(ELEMENT_TITLE);
083: elementCtcon.setShortDescription(ELEMENT_SHORT_DESCRIPTION);
084: //
085: StaticConceptTagConstraintContext elementSctcc = StaticConceptTagConstraintContext
086: .newInstance(elementCtcon);
087: elementSctcc.setRegularExpression(CommonExpressions.ANY_STRING);
088: //
089: elementSctcc.addDefaultValue("XMLElementToCount");
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 .elementCtchar = elementCtcon.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 Element Count");
105: sctiic
106: .setInstanceDescription("Count the total number of elements of a certain type"
107: + " within an element of the trigger");
108: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
109: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
110: scttic.setTypeTitle("Get Trigger Element Count");
111: scttic
112: .setTypeDescription("Count the total number of elements of a certain type"
113: + " within an element of the trigger");
114: }
115: }
116:
117: public void determineValueAndClass(
118: DetermineValueAndClassConceptTagContext inRvacc) {
119:
120: inRvacc
121: .setDetermineException(new DetermineValueAndClassConceptTagException(
122: "Not Implemented"));
123: //ValueAndClassForConceptTag outValue = null;
124:
125: /*
126: ComponentsForReturnableConceptTag wcfrt =
127: ConceptTagHelper.getComponentsForReturnableScriptTag(
128: inRvacc);
129:
130: Trigger t = wcfrt.getTrigger();
131:
132: //X-Path creation and validation
133: String xpathData = null;
134:
135: if (this.pathTc.isStatic()) {
136: xpathData = this.pathTc.getValueAsString();
137: }
138: else if (this.pathTc.isDynamic()) {
139:
140: ValueAndClass outValue = this.pathTc.getDetermineValueAndClass(
141: inRvacc);
142: xpathData = (String)vac.getValue();
143: }
144:
145: String xpathErrors = XMLHelper.isXPathValid(xpathData);
146:
147: if (xpathErrors != null) {
148: throw new DetermineValueAndClassConceptTagException("X-Path '"
149: + xpathData
150: + "' is invalid for the following reasons - " + xpathErrors);
151: }
152:
153: //elementName creation and validation
154: String elementName = null;
155:
156: if (this.elementTc.isStatic()) {
157: elementName = this.elementTc.getValueAsString();
158: }
159: else if (this.elementTc.isDynamic()) {
160:
161: ValueAndClass outValue =
162: this.elementTc.getDetermineValueAndClass(inRvacc);
163: elementName = (String)vac.getValue();
164: }
165:
166: //trigger document creation and validation
167: Document doc = null;
168: try {
169: doc = XMLHelper.loadDocument(t.getDataAsString());
170: }
171: catch (ParserConfigurationException pce) {
172: throw new DetermineValueAndClassConceptTagException(pce);
173: }
174: catch (SAXException saxe) {
175: throw new DetermineValueAndClassConceptTagException(saxe);
176: }
177: catch (IOException ioe) {
178: throw new DetermineValueAndClassConceptTagException(ioe);
179: }
180:
181: return ValueAndClassFactory.newValueAndClass(
182: new BigDecimal(XMLHelper.getElementSubCount(
183: doc, xpathData, elementName)), BigDecimal.class);
184: */
185: //return outValue;
186: }
187:
188: public void determineClass(DetermineClassConceptTagContext inRcc) {
189: inRcc.setDetermineClass(BigDecimal.class);
190: }
191: }
|