001: /*
002: * Copyright 2007 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 org.outerj.daisy.workflow;
017:
018: import org.outerx.daisy.x10Workflow.*;
019:
020: import java.util.List;
021: import java.util.Map;
022: import java.util.ArrayList;
023:
024: public class WfListHelper {
025: /**
026: * Gets the XML representation of all the items in the list.
027: */
028: public static ProcessDefinitionsDocument getProcessDefinitionsAsXml(
029: List<WfProcessDefinition> processDefinitions) {
030: ProcessDefinitionsDocument doc = ProcessDefinitionsDocument.Factory
031: .newInstance();
032: ProcessDefinitionsDocument.ProcessDefinitions xml = doc
033: .addNewProcessDefinitions();
034:
035: ProcessDefinitionDocument.ProcessDefinition[] defsXml = new ProcessDefinitionDocument.ProcessDefinition[processDefinitions
036: .size()];
037: for (int i = 0; i < processDefinitions.size(); i++) {
038: defsXml[i] = processDefinitions.get(i).getXml()
039: .getProcessDefinition();
040: }
041:
042: xml.setProcessDefinitionArray(defsXml);
043:
044: return doc;
045: }
046:
047: /**
048: * Gets the XML representation of all the items in the list.
049: */
050: public static TasksDocument getTasksAsXml(List<WfTask> tasks) {
051: TaskDocument.Task[] tasksXml = new TaskDocument.Task[tasks
052: .size()];
053: for (int i = 0; i < tasks.size(); i++) {
054: tasksXml[i] = tasks.get(i).getXml().getTask();
055: }
056:
057: TasksDocument doc = TasksDocument.Factory.newInstance();
058: doc.addNewTasks().setTaskArray(tasksXml);
059: return doc;
060: }
061:
062: public static ProcessesDocument getProcessesAsXml(
063: List<WfProcessInstance> processes) {
064: ProcessDocument.Process[] processesXml = new ProcessDocument.Process[processes
065: .size()];
066: for (int i = 0; i < processes.size(); i++) {
067: processesXml[i] = processes.get(i).getXml().getProcess();
068: }
069:
070: ProcessesDocument doc = ProcessesDocument.Factory.newInstance();
071: doc.addNewProcesses().setProcessArray(processesXml);
072: return doc;
073: }
074:
075: public static TimersDocument getTimersAsXml(List<WfTimer> timers) {
076: TimerDocument.Timer[] timersXml = new TimerDocument.Timer[timers
077: .size()];
078: for (int i = 0; i < timers.size(); i++) {
079: timersXml[i] = timers.get(i).getXml().getTimer();
080: }
081:
082: TimersDocument doc = TimersDocument.Factory.newInstance();
083: doc.addNewTimers().setTimerArray(timersXml);
084: return doc;
085: }
086:
087: /**
088: * Gets the XML representation of all the items in the list.
089: */
090: public static PoolsDocument getPoolsAsXml(List<WfPool> pools) {
091: PoolDocument.Pool[] poolsXml = new PoolDocument.Pool[pools
092: .size()];
093: for (int i = 0; i < poolsXml.length; i++) {
094: poolsXml[i] = pools.get(i).getXml().getPool();
095: }
096:
097: PoolsDocument doc = PoolsDocument.Factory.newInstance();
098: doc.addNewPools().setPoolArray(poolsXml);
099: return doc;
100: }
101:
102: public static UsersDocument getUserIdsAsXml(List<Long> userIdsList) {
103: long[] userIds = new long[userIdsList.size()];
104: for (int i = 0; i < userIds.length; i++)
105: userIds[i] = userIdsList.get(i);
106:
107: UsersDocument document = UsersDocument.Factory.newInstance();
108: document.addNewUsers().setIdArray(userIds);
109: return document;
110: }
111:
112: public static ProcessInstanceCountsDocument getProcessInstanceCountsAsXml(
113: Map<String, Integer> counts) {
114: List<Map.Entry<String, Integer>> countEntries = new ArrayList<Map.Entry<String, Integer>>(
115: counts.entrySet());
116:
117: ProcessInstanceCountsDocument.ProcessInstanceCounts.ProcessInstanceCount[] countsXml = new ProcessInstanceCountsDocument.ProcessInstanceCounts.ProcessInstanceCount[countEntries
118: .size()];
119: for (int i = 0; i < countsXml.length; i++) {
120: countsXml[i] = ProcessInstanceCountsDocument.ProcessInstanceCounts.ProcessInstanceCount.Factory
121: .newInstance();
122: countsXml[i].setDefinitionId(countEntries.get(i).getKey());
123: countsXml[i].setCount(countEntries.get(i).getValue());
124: }
125:
126: ProcessInstanceCountsDocument document = ProcessInstanceCountsDocument.Factory
127: .newInstance();
128: document.addNewProcessInstanceCounts()
129: .setProcessInstanceCountArray(countsXml);
130: return document;
131: }
132: }
|