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.ConceptTagConstraint;
020: import org.jfolder.common.tagging.ConceptTagConstraintHolder;
021: import org.jfolder.common.tagging.DetermineClassConceptTagContext;
022: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagContext;
023: import org.jfolder.common.tagging.DetermineValueAndClassConceptTagException;
024: import org.jfolder.common.tagging.InitializeConceptTagContext;
025: import org.jfolder.common.tagging.ReturnableConceptTag;
026: import org.jfolder.common.tagging.StudioConceptTagInstanceInfoContext;
027: import org.jfolder.common.tagging.StudioConceptTagTypeInfoContext;
028: import org.jfolder.common.tagging.ValueAndClassForConceptTag;
029: import org.jfolder.common.utils.xml.XMLHelper;
030: import org.jfolder.workflow.model.template.*;
031: import org.jfolder.workflow.model.trigger.WorkflowTrigger;
032:
033: //other classes
034:
035: public class IsTriggerFromApplicationWorkflowTemplateTag implements
036: ReturnableConceptTag {
037:
038: public void initialize(InitializeConceptTagContext inIctc) {
039:
040: //
041: ConceptTagConstraintHolder rootCtconh = ConceptTagConstraintHolder
042: .newInstance(inIctc);
043:
044: inIctc.initialize();
045: }
046:
047: public void appraise(AppraiseConceptTagContext inCtic) {
048:
049: final String TITLE = "Is Trigger From Application";
050: final String DESCRIPTION = "Return true only if the trigger came"
051: + " from the same application as the script";
052:
053: if (inCtic instanceof StudioConceptTagInstanceInfoContext) {
054: StudioConceptTagInstanceInfoContext sctiic = (StudioConceptTagInstanceInfoContext) inCtic;
055:
056: sctiic.setInstanceTitle(TITLE);
057: sctiic.setInstanceDescription(DESCRIPTION);
058: } else if (inCtic instanceof StudioConceptTagTypeInfoContext) {
059: StudioConceptTagTypeInfoContext scttic = (StudioConceptTagTypeInfoContext) inCtic;
060:
061: scttic.setTypeTitle(TITLE);
062: scttic.setTypeDescription(DESCRIPTION);
063: }
064: }
065:
066: public void determineValueAndClass(
067: DetermineValueAndClassConceptTagContext inRvacc) {
068:
069: try {
070:
071: ValueAndClassForConceptTag outValue = null;
072:
073: final String APPLICATION_ATTRIBUTE = "application";
074:
075: ComponentsForReturnableWorkflowTemplateTag wcfrt = WorkflowTemplateTagHelper
076: .getComponentsForReturnableWorkflowTemplateTag(inRvacc);
077:
078: WorkflowTrigger t = wcfrt.getWorkflowTrigger();
079:
080: boolean result = false;
081:
082: Document doc = XMLHelper.loadDocument(t.getDataAsString());
083: Element e = doc.getDocumentElement();
084: if (e.hasAttribute(APPLICATION_ATTRIBUTE)) {
085: //DetermineValueAndClassConceptTagContextBean rvaccb =
086: // (DetermineValueAndClassConceptTagContextBean)inRvacc;
087: String currentApplication = wcfrt.getApplicationName();
088: result = (currentApplication != null && currentApplication
089: .equals(e.getAttribute(APPLICATION_ATTRIBUTE)));
090: }
091: outValue = ValueAndClassForConceptTag.newInstance(
092: new Boolean(result), Boolean.TYPE);
093:
094: inRvacc.setDetermineValueAndClass(outValue);
095: } catch (ParserConfigurationException pce) {
096: inRvacc.setDetermineException(pce);
097: } catch (SAXException saxe) {
098: inRvacc.setDetermineException(saxe);
099: } catch (IOException ioe) {
100: inRvacc.setDetermineException(ioe);
101: }
102: }
103:
104: public void determineClass(DetermineClassConceptTagContext inRcc) {
105: inRcc.setDetermineClass(Boolean.TYPE);
106: }
107: }
|