KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > doctaskrunner > commonimpl > TaskImpl


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.doctaskrunner.commonimpl;
17
18 import org.outerj.daisy.doctaskrunner.Task;
19 import org.outerj.daisy.doctaskrunner.TaskState;
20 import org.outerx.daisy.x10Doctaskrunner.TaskDocument;
21
22 import java.util.Date JavaDoc;
23 import java.util.GregorianCalendar JavaDoc;
24 import java.util.Calendar JavaDoc;
25
26 public class TaskImpl implements Task {
27     private final long id;
28     private final String JavaDoc description;
29     private final TaskState state;
30     private final long ownerId;
31     private final String JavaDoc progress;
32     private final String JavaDoc details;
33     private final String JavaDoc script;
34     private final String JavaDoc scriptLanguage;
35     private final Date JavaDoc startedAt;
36     private final Date JavaDoc finishedAt;
37
38     public TaskImpl(long id, String JavaDoc description, TaskState state, long ownerId, String JavaDoc progress, String JavaDoc details,
39             String JavaDoc script, String JavaDoc scriptLanguage, Date JavaDoc startedAt, Date JavaDoc finishedAt) {
40         this.id = id;
41         this.description = description;
42         this.state = state;
43         this.ownerId = ownerId;
44         this.progress = progress;
45         this.details = details;
46         this.script = script;
47         this.scriptLanguage = scriptLanguage;
48         this.startedAt = startedAt;
49         this.finishedAt = finishedAt;
50     }
51
52     public long getId() {
53         return id;
54     }
55
56     public String JavaDoc getDescription() {
57         return description;
58     }
59
60     public TaskState getState() {
61         return state;
62     }
63
64     public long getOwnerId() {
65         return ownerId;
66     }
67
68     public String JavaDoc getProgressIndication() {
69         return progress;
70     }
71
72     public String JavaDoc getDetails() {
73         return details;
74     }
75
76     public String JavaDoc getScript() {
77         return script;
78     }
79
80     public String JavaDoc getScriptLanguage() {
81         return scriptLanguage;
82     }
83
84     public Date JavaDoc getStartedAt() {
85         return (Date JavaDoc)startedAt.clone();
86     }
87
88     public Date JavaDoc getFinishedAt() {
89         return (Date JavaDoc)finishedAt.clone();
90     }
91
92     public TaskDocument getXml() {
93         TaskDocument taskDocument = TaskDocument.Factory.newInstance();
94         TaskDocument.Task taskXml = taskDocument.addNewTask();
95
96         taskXml.setId(id);
97         taskXml.setDescription(description);
98         taskXml.setOwnerId(ownerId);
99         taskXml.setProgress(progress);
100         TaskDocument.Task.Script scriptXml = taskXml.addNewScript();
101         scriptXml.setLanguage(scriptLanguage);
102         scriptXml.setStringValue(script);
103         taskXml.setStartedAt(getCalendar(startedAt));
104         if (finishedAt != null)
105             taskXml.setFinishedAt(getCalendar(finishedAt));
106         taskXml.setState(TaskDocument.Task.State.Enum.forString(state.toString()));
107         if (details != null)
108             taskXml.setDetails(details);
109
110         return taskDocument;
111     }
112
113     private Calendar JavaDoc getCalendar(Date JavaDoc date) {
114         GregorianCalendar JavaDoc calendar = new GregorianCalendar JavaDoc();
115         calendar.setTime(date);
116         return calendar;
117     }
118 }
119
Popular Tags