KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > doctaskrunner > serverimpl > DocumentTaskManagerImpl


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.serverimpl;
17
18 import org.outerj.daisy.doctaskrunner.*;
19 import org.outerj.daisy.doctaskrunner.commonimpl.TaskSpecificationImpl;
20 import org.outerj.daisy.doctaskrunner.commonimpl.QueryDocumentSelection;
21 import org.outerj.daisy.doctaskrunner.commonimpl.EnumerationDocumentSelection;
22 import org.outerj.daisy.doctaskrunner.commonimpl.SimpleActionsTaskSpecificationImpl;
23 import org.outerj.daisy.repository.Repository;
24 import org.outerj.daisy.repository.VariantKey;
25 import org.outerj.daisy.repository.user.Role;
26
27 public class DocumentTaskManagerImpl implements DocumentTaskManager {
28     private final CommonDocumentTaskManager delegate;
29     private final Repository repository;
30
31     public DocumentTaskManagerImpl(CommonDocumentTaskManager delegate, Repository repository) {
32         this.delegate = delegate;
33         this.repository = repository;
34     }
35
36     public long runTask(DocumentSelection documentSelection, TaskSpecification taskSpecification) throws TaskException {
37         if (!(taskSpecification instanceof SimpleActionsTaskSpecificationImpl) && !repository.isInRole(Role.ADMINISTRATOR))
38             throw new TaskException("Non-\"simple actions\" scripts can only be executed by Administrators.");
39
40         return delegate.runTask(documentSelection, taskSpecification, repository);
41     }
42
43     public Task getTask(long id) throws TaskException {
44         return delegate.getTask(id, repository);
45     }
46
47     public Tasks getTasks() throws TaskException {
48         return delegate.getTasks(repository);
49     }
50
51     public void deleteTask(long id) throws TaskException {
52         delegate.deleteTask(id, repository);
53     }
54
55     public void interruptTask(long id) throws TaskException {
56         delegate.interruptTask(id, repository);
57     }
58
59     public TaskDocDetails getTaskDocDetails(long taskId) throws TaskException {
60         return delegate.getTaskDocDetails(taskId, repository);
61     }
62
63     public TaskSpecification createTaskSpecification(String JavaDoc description, String JavaDoc script, String JavaDoc scriptLanguage, boolean stopOnFirstError) {
64         return new TaskSpecificationImpl(description, script, scriptLanguage, stopOnFirstError);
65     }
66
67     public SimpleActionsTaskSpecification createSimpleActionsTaskSpecification(String JavaDoc description, boolean stopOnFirstError) {
68         return new SimpleActionsTaskSpecificationImpl(description, stopOnFirstError, repository);
69     }
70
71     public DocumentSelection createQueryDocumentSelection(String JavaDoc query) {
72         return new QueryDocumentSelection(query);
73     }
74
75     public DocumentSelection createEnumerationDocumentSelection(VariantKey[] variantKeys) {
76         return new EnumerationDocumentSelection(variantKeys);
77     }
78 }
79
Popular Tags