KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > value > AnyValue


1 package org.apache.slide.projector.value;
2
3 import org.apache.slide.projector.Context;
4 import org.apache.slide.projector.Store;
5 import org.apache.slide.projector.URI;
6 import org.apache.slide.projector.engine.ProcessorManager;
7 import org.apache.slide.projector.processor.process.Process;
8
9 public class AnyValue implements Value {
10     public String JavaDoc CONTENT_TYPE = "projector/stored-value";
11     
12     private URI processorUri;
13     private String JavaDoc result;
14     private int storeId;
15     private String JavaDoc key;
16     private String JavaDoc domain;
17     private Value input;
18
19     /**
20      * @param processor
21      * @param result
22      * @param store
23      * @param key
24      * @param domain
25      */

26     public AnyValue(String JavaDoc processor, Value input, String JavaDoc result, int storeId, String JavaDoc key, String JavaDoc domain) {
27         if ( processor != null ) {
28             this.processorUri = new URIValue(processor);
29             this.input = input;
30         }
31         this.result = result;
32         this.storeId = storeId;
33         this.key = key;
34         this.domain = domain;
35     }
36
37     public String JavaDoc getDomain() {
38         return domain;
39     }
40
41     public Value getInput() {
42         return input;
43     }
44
45     public String JavaDoc getKey() {
46         return key;
47     }
48     
49     public URI getProcessorUri() {
50         return processorUri;
51     }
52     
53     public String JavaDoc getResult() {
54         return result;
55     }
56     
57     public int getStoreId() {
58         return storeId;
59     }
60     
61     public Object JavaDoc load(Context context) throws Exception JavaDoc {
62         Object JavaDoc value = null;
63         if ( key != null ) {
64             if ( storeId == Store.NONE ) {
65                 storeId = Store.STEP;
66             }
67             String JavaDoc evaluatedKey = Process.evaluateKey(key, context);
68             Store store = context.getStore(storeId);
69             if ( store != null ) {
70                 if ( domain != null ) {
71                     MapValue mapResource = (MapValue)store.get(domain);
72                     if ( mapResource != null ) {
73                         value = mapResource.getMap().get(evaluatedKey);
74                     }
75                 } else {
76                     value = store.get(evaluatedKey);
77                 }
78             }
79         }
80         if ( processorUri != null ) {
81             if ( input != null ) {
82                 value = input;
83             }
84             value = ProcessorManager.getInstance().process(processorUri, value, result, context);
85         }
86         return value;
87     }
88
89     public String JavaDoc getContentType() {
90         return CONTENT_TYPE;
91     }
92
93 }
Popular Tags