001    /*
002     * Copyright 2005-2008 The Kuali Foundation
003     * 
004     * 
005     * Licensed under the Educational Community License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     * 
009     * http://www.opensource.org/licenses/ecl2.php
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.kuali.rice.kew.rule;
018    
019    import org.jdom.Document;
020    import org.jdom.Element;
021    import org.kuali.rice.core.api.util.xml.XmlHelper;
022    import org.kuali.rice.kew.routeheader.DocumentContent;
023    
024    import java.io.StringReader;
025    import java.util.ArrayList;
026    import java.util.Collection;
027    import java.util.List;
028    import java.util.Map;
029    
030    
031    /**
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     */
034    public class MockWorkflowAttribute implements WorkflowAttribute {
035        
036        private static final String MOCK_VALUE_ELEMENT = "mockValue";
037        //private static final String VALUE_KEY = "value";
038        
039        private String value;
040        
041        public MockWorkflowAttribute() {}
042        
043        public MockWorkflowAttribute(String value) {
044            setValue(value);
045        }
046    
047        public String getDocContent() {
048            if (value == null) return "";
049            return "<"+MOCK_VALUE_ELEMENT+">"+value+"</"+MOCK_VALUE_ELEMENT+">";
050        }
051        
052        public List parseDocContent(String docContent) {
053            try {
054                Document doc = XmlHelper.buildJDocument(new StringReader(docContent));
055                Collection<Element> elements = XmlHelper.findElements(doc.getRootElement(), MOCK_VALUE_ELEMENT);
056                Element mockValueElement = elements.iterator().next();
057                List attributes = new ArrayList();
058                if (mockValueElement != null) {
059                    attributes.add(new MockWorkflowAttribute(mockValueElement.getText()));
060                }
061                return attributes;
062            } catch (Exception e) {
063                throw new RuntimeException(e);
064            }
065        }
066        
067        public String getIdFieldName() {
068            return null;
069        }
070        public String getLockFieldName() {
071            return null;
072        }
073        public List getRoutingDataRows() {
074            return null;
075        }
076        public List getRuleExtensionValues() {
077            return null;
078        }
079        public List getRuleRows() {
080            return null;
081        }
082        public boolean isMatch(DocumentContent docContent, List ruleExtensions) {
083            return false;
084        }
085        public boolean isRequired() {
086            return false;
087        }
088        
089        public void setRequired(boolean required) {
090        }
091        public List validateRoutingData(Map paramMap) {
092            return null;
093        }
094        public List validateRuleData(Map paramMap) {
095            return null;
096        }
097        
098        public String getValue() {
099            return value;
100        }
101        
102        public void setValue(String value) {
103            this.value = value;
104        }
105        
106        
107    }