001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jul 21, 2005
014: * @author James Dixon
015: *
016: */
017:
018: package org.pentaho.core.solution;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.commons.collections.map.ListOrderedMap;
025: import org.dom4j.Node;
026: import org.pentaho.core.component.IComponent;
027: import org.pentaho.core.util.XmlHelper;
028: import org.pentaho.util.logging.ILogger;
029: import org.pentaho.util.logging.Logger;
030:
031: public class ActionDefinition implements IActionDefinition {
032:
033: private int errorCode;
034:
035: private int loggingLevel;
036:
037: // private boolean audit;
038: private List preExecuteAuditList;
039:
040: private List postExecuteAuditList;
041:
042: // private ISequenceDefinition sequenceData;
043:
044: private String description;
045:
046: private String author;
047:
048: private String help;
049:
050: private String iconUrl;
051:
052: private Node componentNode;
053:
054: private Node actionRootNode;
055:
056: private IComponent component;
057:
058: private String componentName;
059:
060: private Map actionInputDefinitions;
061:
062: private Map actionInputMapping;
063:
064: private Map actionOutputDefinitions;
065:
066: private Map actionOutputMapping;
067:
068: private Map actionResourceMapping;
069:
070: private boolean hasActionResources = false;
071:
072: public ActionDefinition(Node actionRootNode, ILogger logger) {
073:
074: this .actionRootNode = actionRootNode;
075:
076: errorCode = ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
077: // this.sequenceData = sequenceData;
078:
079: // get the input parameter definitions
080: actionInputDefinitions = new ListOrderedMap();
081: actionInputMapping = new ListOrderedMap();
082: errorCode = SequenceDefinition
083: .parseParameters(
084: actionRootNode,
085: logger,
086: "action-inputs/*", actionInputDefinitions, actionInputMapping, true); //$NON-NLS-1$
087:
088: // get the ouput definitions
089: actionOutputDefinitions = new ListOrderedMap();
090: actionOutputMapping = new ListOrderedMap();
091: errorCode = SequenceDefinition
092: .parseParameters(
093: actionRootNode,
094: logger,
095: "action-outputs/*", actionOutputDefinitions, actionOutputMapping, false); //$NON-NLS-1$
096:
097: // get the resource definitions
098: actionResourceMapping = new ListOrderedMap();
099: if (actionRootNode.selectNodes("action-resources/*").size() > 0) { //$NON-NLS-1$
100: hasActionResources = true;
101: errorCode = SequenceDefinition
102: .parseActionResourceDefinitions(actionRootNode,
103: logger,
104: "action-resources/*", actionResourceMapping); //$NON-NLS-1$
105: }
106:
107: componentName = XmlHelper.getNodeText(
108: "component-name", actionRootNode); //$NON-NLS-1$
109: String loggingLevelString = XmlHelper.getNodeText(
110: "logging-level", actionRootNode); //$NON-NLS-1$
111: loggingLevel = Logger.getLogLevel(loggingLevelString);
112:
113: // get the component payload
114: componentNode = actionRootNode
115: .selectSingleNode("component-definition"); //$NON-NLS-1$
116: if (componentNode == null) {
117: // TODO log this / surface this error
118: errorCode = ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
119: }
120:
121: // TODO populate preExecuteAuditList and postExecuteAuditList
122: }
123:
124: public int getErrorCode() {
125: return errorCode;
126: }
127:
128: public String getMappedInputName(String name) {
129: return ((String) actionInputMapping.get(name));
130: }
131:
132: public Map getActionInputDefinitions() {
133: return actionInputDefinitions;
134: }
135:
136: public String getMappedOutputName(String name) {
137: return ((String) actionOutputMapping.get(name));
138: }
139:
140: public Map getActionOutputDefinitions() {
141: return actionOutputDefinitions;
142: }
143:
144: public String getMappedResourceName(String name) {
145: return ((String) actionResourceMapping.get(name));
146: }
147:
148: public List getActionResourceDefinitionNames() {
149: return (new ArrayList(actionResourceMapping.keySet()));
150: }
151:
152: public boolean hasActionResources() {
153: return (hasActionResources);
154: }
155:
156: public void setLoggingLevel(int loggingLevel) {
157: this .loggingLevel = loggingLevel;
158: }
159:
160: /*
161: * (non-Javadoc)
162: *
163: * @see org.pentaho.newcode.IActionDefinition#getComponentName()
164: */
165: public String getComponentName() {
166: // TODO Auto-generated method stub
167: return componentName;
168: }
169:
170: /*
171: * (non-Javadoc)
172: *
173: * @see org.pentaho.newcode.IActionDefinition#getComponentSection()
174: */
175: public Node getComponentSection() {
176: // TODO Auto-generated method stub
177: return componentNode;
178: }
179:
180: public Node getNode() {
181: return actionRootNode;
182: }
183:
184: /*
185: * (non-Javadoc)
186: *
187: * @see org.pentaho.newcode.IActionDefinition#getSyncPreference()
188: */
189: public boolean getSyncPreference() {
190: // TODO Auto-generated method stub
191: return false;
192: }
193:
194: public int getLoggingLevel() {
195: return loggingLevel;
196: }
197:
198: public List getPostExecuteAuditList() {
199: return preExecuteAuditList;
200: }
201:
202: public List getPreExecuteAuditList() {
203: return postExecuteAuditList;
204: }
205:
206: public IComponent getComponent() {
207: return component;
208: }
209:
210: public void setComponent(IComponent component) {
211: this .component = component;
212: }
213:
214: public String getIconUrl() {
215: return iconUrl;
216: }
217:
218: public String getAuthor() {
219: return author;
220: }
221:
222: public String getDescription() {
223: return description;
224: }
225:
226: public String getHelp() {
227: return help;
228: }
229:
230: }
|