001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package edu.sampleu.travel.workflow;
017:
018: import java.util.ArrayList;
019: import java.util.HashMap;
020: import java.util.List;
021: import java.util.Map;
022:
023: import edu.iu.uis.eden.lookupable.Field;
024: import edu.iu.uis.eden.lookupable.Row;
025: import edu.iu.uis.eden.routetemplate.GenericWorkflowAttribute;
026: import edu.iu.uis.eden.routetemplate.WorkflowAttributeValidationError;
027:
028: public class DestinationRuleAttribute extends GenericWorkflowAttribute {
029:
030: private static final String DEST_LABEL = "Destination";
031: private static final String DEST_FIELD_KEY = "destination";
032:
033: private static final List<Row> rows = new ArrayList<Row>();
034: static {
035: List<Field> fields = new ArrayList<Field>();
036: fields.add(new Field(DEST_LABEL, "", Field.TEXT, true,
037: DEST_FIELD_KEY, "", null, null, DEST_FIELD_KEY));
038: rows.add(new Row(fields));
039: }
040:
041: private String destination;
042:
043: public DestinationRuleAttribute() {
044: super ("destination");
045: }
046:
047: public DestinationRuleAttribute(String destination) {
048: super ("destination");
049: this .destination = destination;
050: }
051:
052: /*
053: public boolean isMatch(DocumentContent docContent, List<RuleExtension> ruleExtensions) {
054: try {
055: boolean foundDestRule = false;
056: for (Iterator extensionsIterator = ruleExtensions.iterator(); extensionsIterator.hasNext();) {
057: RuleExtension extension = (RuleExtension) extensionsIterator.next();
058: if (extension.getRuleTemplateAttribute().getRuleAttribute().getClassName().equals(getClass().getName())) {
059: for (Iterator valuesIterator = extension.getExtensionValues().iterator(); valuesIterator.hasNext();) {
060: RuleExtensionValue extensionValue = (RuleExtensionValue) valuesIterator.next();
061: String key = extensionValue.getKey();
062: String value = extensionValue.getValue();
063: if (key.equals(DEST_FIELD_KEY)) {
064: destination = value;
065: foundDestRule = true;
066: }
067: }
068: }
069: }
070: if (! foundDestRule) {
071: return false;
072: }
073:
074: Element element = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
075: new InputSource(new BufferedReader(new StringReader(docContent.getDocContent())))).getDocumentElement();
076: XPath xpath = XPathFactory.newInstance().newXPath();
077: String docContentDest = xpath.evaluate("//destination", element);
078: return destination.equals(docContentDest);
079: } catch (Exception e) {
080: throw new RuntimeException(e);
081: }
082: }*/
083:
084: public List<Row> getRuleRows() {
085: return getRows();
086: }
087:
088: public List<Row> getRoutingDataRows() {
089: return getRows();
090: }
091:
092: private List<Row> getRows() {
093: log.info("Returning rows: " + rows);
094: return rows;
095: }
096:
097: /* setter for edoclite field */
098: public void setDestination(String destination) {
099: this .destination = destination;
100: }
101:
102: public Map<String, String> getProperties() {
103: Map<String, String> props = new HashMap<String, String>();
104: props.put("destination", destination);
105: return props;
106: }
107:
108: public List validateRoutingData(Map paramMap) {
109: return validateInputMap(paramMap);
110: }
111:
112: public List validateRuleData(Map paramMap) {
113: return validateInputMap(paramMap);
114: }
115:
116: private List validateInputMap(Map paramMap) {
117: List errors = new ArrayList();
118: this .destination = (String) paramMap.get(DEST_FIELD_KEY);
119: if (this .destination == null && required) {
120: errors.add(new WorkflowAttributeValidationError(
121: DEST_FIELD_KEY, "Destination is required."));
122: }
123: return errors;
124: }
125: }
|