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 CONTENT_TYPE = "projector/stored-value"; 11 12 private URI processorUri; 13 private String result; 14 private int storeId; 15 private String key; 16 private String domain; 17 private Value input; 18 19 26 public AnyValue(String processor, Value input, String result, int storeId, String key, String 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 getDomain() { 38 return domain; 39 } 40 41 public Value getInput() { 42 return input; 43 } 44 45 public String getKey() { 46 return key; 47 } 48 49 public URI getProcessorUri() { 50 return processorUri; 51 } 52 53 public String getResult() { 54 return result; 55 } 56 57 public int getStoreId() { 58 return storeId; 59 } 60 61 public Object load(Context context) throws Exception { 62 Object value = null; 63 if ( key != null ) { 64 if ( storeId == Store.NONE ) { 65 storeId = Store.STEP; 66 } 67 String 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 getContentType() { 90 return CONTENT_TYPE; 91 } 92 93 } | Popular Tags |