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.serverimpl.query;
017:
018: import org.jbpm.taskmgmt.exe.TaskInstance;
019: import org.jbpm.graph.exe.ProcessInstance;
020: import org.jbpm.job.Timer;
021: import org.outerj.daisy.workflow.WfTaskDefinition;
022: import org.outerj.daisy.workflow.WfProcessDefinition;
023: import org.outerj.daisy.workflow.WorkflowException;
024: import org.outerj.daisy.workflow.serverimpl.IntWfContext;
025:
026: public class ValueGetterProvider implements ValueGetter.Provider {
027: private ProcessInstance processInstance;
028: private TaskInstance taskInstance;
029: private Timer timer;
030: private WfTaskDefinition taskDefinition;
031: private WfProcessDefinition processDefinition;
032: private IntWfContext context;
033:
034: public ValueGetterProvider(ProcessInstance processInstance,
035: TaskInstance taskInstance, Timer timer, IntWfContext context) {
036: this .processInstance = processInstance;
037: this .taskInstance = taskInstance;
038: this .timer = timer;
039: this .context = context;
040: }
041:
042: public TaskInstance getTaskInstance() throws WorkflowException {
043: if (taskInstance == null)
044: throw new WorkflowException(
045: "Trying to access task information in query while no task is available.");
046: return taskInstance;
047: }
048:
049: public WfTaskDefinition getTaskDefinition()
050: throws WorkflowException {
051: if (taskInstance == null) {
052: throw new WorkflowException(
053: "Trying to access task information in query while no task is available.");
054: } else {
055: if (taskDefinition == null) {
056: taskDefinition = context.getWfObjectBuilder()
057: .getTaskDefinition(taskInstance.getTask(),
058: context.getLocale());
059: }
060: return taskDefinition;
061: }
062: }
063:
064: public ProcessInstance getProcessInstance() {
065: return processInstance;
066: }
067:
068: public WfProcessDefinition getProcessDefinition()
069: throws WorkflowException {
070: if (processDefinition == null) {
071: processDefinition = context
072: .getWfObjectBuilder()
073: .getProcessDefinition(
074: getProcessInstance().getProcessDefinition(),
075: context.getLocale());
076: }
077: return processDefinition;
078: }
079:
080: public Timer getTimer() {
081: return timer;
082: }
083:
084: public IntWfContext getContext() {
085: return context;
086: }
087:
088: public static interface ValueGetterProviderBuilder {
089: ValueGetter.Provider getProvider(Object object);
090: }
091:
092: public static ValueGetterProviderBuilder getTaskValueProviderBuilder(
093: final IntWfContext context) {
094: return new ValueGetterProviderBuilder() {
095: public ValueGetter.Provider getProvider(Object object) {
096: TaskInstance task = (TaskInstance) object;
097: return new ValueGetterProvider(task.getToken()
098: .getProcessInstance(), task, null, context);
099: }
100: };
101: }
102:
103: public static ValueGetterProviderBuilder getProcessValueProviderBuilder(
104: final IntWfContext context) {
105: return new ValueGetterProviderBuilder() {
106: public ValueGetter.Provider getProvider(Object object) {
107: return new ValueGetterProvider(
108: (ProcessInstance) object, null, null, context);
109: }
110: };
111: }
112:
113: public static ValueGetterProviderBuilder getTimerValueProviderBuilder(
114: final IntWfContext context) {
115: return new ValueGetterProviderBuilder() {
116: public ValueGetter.Provider getProvider(Object object) {
117: Timer timer = (Timer) object;
118: return new ValueGetterProvider(timer
119: .getProcessInstance(), null, timer, context);
120: }
121: };
122: }
123: }
|