1 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 ; 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 34 public class WorkItemContext extends ContextDecorator { 35 36 private static Logger log = LoggerFactory.getLogger(WorkItemContext.class); 37 38 41 private WorkItem workItem; 42 43 46 public WorkItemContext(Context ctx, WorkItem workItem) { 47 super(ctx); 48 this.workItem = workItem; 49 } 50 51 54 public Object getAttribute(String name, int scope) { 55 if (scope == Context.LOCAL_SCOPE) { 56 Attribute attr = this.workItem.getAttribute(name); 57 if (attr != null) { 58 Object obj = AttributeUtils.owfe2java(attr); 59 if (obj != null) { 60 return obj; 61 } 62 } 63 } 64 return super.getAttribute(name, scope); 65 } 66 67 70 public Map 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 80 public void setAttribute(String name, Object 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 97 public void removeAttribute(String 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 108 public WorkItem getWorkItem() { 109 return this.workItem; 110 } 111 112 115 public void setWorkItem(WorkItem workItem) { 116 this.workItem = workItem; 117 } 118 119 } 120 | Popular Tags |