KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > workflow > WorkItemContext


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.workflow;
14
15 import info.magnolia.context.Context;
16 import info.magnolia.context.ContextDecorator;
17
18 import java.util.Map JavaDoc;
19
20 import openwfe.org.engine.workitem.Attribute;
21 import openwfe.org.engine.workitem.AttributeException;
22 import openwfe.org.engine.workitem.AttributeUtils;
23 import openwfe.org.engine.workitem.WorkItem;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28
29 /**
30  * This context wrapps a workitem and delegates the most of the methods to the inner context.
31  * @author Philipp Bracher
32  * @version $Revision: 6432 $ ($Author: scharles $)
33  */

34 public class WorkItemContext extends ContextDecorator {
35
36     private static Logger log = LoggerFactory.getLogger(WorkItemContext.class);
37
38     /**
39      * The wrapped workitem
40      */

41     private WorkItem workItem;
42
43     /**
44      *
45      */

46     public WorkItemContext(Context ctx, WorkItem workItem) {
47         super(ctx);
48         this.workItem = workItem;
49     }
50
51     /**
52      * Use work item if request scope
53      */

54     public Object JavaDoc getAttribute(String JavaDoc name, int scope) {
55         if (scope == Context.LOCAL_SCOPE) {
56             Attribute attr = this.workItem.getAttribute(name);
57             if (attr != null) {
58                 Object JavaDoc obj = AttributeUtils.owfe2java(attr);
59                 if (obj != null) {
60                     return obj;
61                 }
62             }
63         }
64         return super.getAttribute(name, scope);
65     }
66
67     /**
68      * Use work item if request scope
69      */

70     public Map JavaDoc getAttributes(int scope) {
71         if (scope == Context.LOCAL_SCOPE) {
72             return AttributeUtils.map2java(this.workItem.getAttributes());
73         }
74         return super.getAttributes(scope);
75     }
76
77     /**
78      * Use work item if request scope
79      */

80     public void setAttribute(String JavaDoc name, Object JavaDoc value, int scope) {
81         if (scope == Context.LOCAL_SCOPE) {
82             Attribute attr = AttributeUtils.java2owfe(value);
83             try {
84                 this.workItem.addAttribute(name, attr);
85             }
86             catch (AttributeException e) {
87                 log.error("can't set value {}", name, e);
88             }
89         } else {
90             super.setAttribute(name, value, scope);
91         }
92     }
93
94     /**
95      * Use work item if request scope
96      */

97     public void removeAttribute(String JavaDoc name, int scope) {
98         if (scope == Context.LOCAL_SCOPE) {
99             this.workItem.removeAttribute(name);
100         } else {
101             super.removeAttribute(name, scope);
102         }
103     }
104
105     /**
106      * @return Returns the workItem.
107      */

108     public WorkItem getWorkItem() {
109         return this.workItem;
110     }
111
112     /**
113      * @param workItem The workItem to set.
114      */

115     public void setWorkItem(WorkItem workItem) {
116         this.workItem = workItem;
117     }
118
119 }
120
Popular Tags