1 23 24 package org.apache.slide.projector.processor.access; 25 26 import java.util.Map ; 27 28 import org.apache.slide.projector.Context; 29 import org.apache.slide.projector.Processor; 30 import org.apache.slide.projector.Result; 31 import org.apache.slide.projector.Store; 32 import org.apache.slide.projector.descriptor.AnyValueDescriptor; 33 import org.apache.slide.projector.descriptor.NumberValueDescriptor; 34 import org.apache.slide.projector.descriptor.ParameterDescriptor; 35 import org.apache.slide.projector.descriptor.ResultDescriptor; 36 import org.apache.slide.projector.descriptor.StateDescriptor; 37 import org.apache.slide.projector.descriptor.StringValueDescriptor; 38 import org.apache.slide.projector.i18n.ParameterMessage; 39 import org.apache.slide.projector.util.StoreHelper; 40 import org.apache.slide.projector.value.NullValue; 41 import org.apache.slide.projector.value.NumberValue; 42 import org.apache.slide.projector.value.Value; 43 44 48 public class Put implements Processor { 49 public final static String STORE = "store"; 50 public final static String KEY = "key"; 51 public final static String VALUE = "value"; 52 public final static String TIMEOUT = "timeout"; 53 54 private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] { 55 new ParameterDescriptor(STORE, new ParameterMessage("put/parameter/store"), new StringValueDescriptor(Store.stores)), 56 new ParameterDescriptor(KEY, new ParameterMessage("put/parameter/key"), new StringValueDescriptor()), 57 new ParameterDescriptor(VALUE, new ParameterMessage("put/parameter/value"), new AnyValueDescriptor()), 58 new ParameterDescriptor(TIMEOUT, new ParameterMessage("put/parameter/timeout"), new NumberValueDescriptor(), NullValue.NULL) 59 }; 60 private final static ResultDescriptor resultDescriptor = new ResultDescriptor(new StateDescriptor[] { StateDescriptor.OK_DESCRIPTOR }); 61 62 public Result process(Map parameter, Context context) throws Exception { 63 String storeName = parameter.get(STORE).toString(); 64 String key = parameter.get(KEY).toString(); 65 Value value = (Value)parameter.get(VALUE); 66 Value timeoutValue = (Value)parameter.get(TIMEOUT); 67 Store store = context.getStore(StoreHelper.getStoreByName(storeName)); 68 if ( timeoutValue == NullValue.NULL ) { 69 store.put(key, value); 70 } else { 71 long timeout = ((NumberValue)timeoutValue).getNumber().longValue(); 72 store.put(key, value, timeout); 73 } 74 return Result.OK; 75 } 76 77 public ParameterDescriptor[] getParameterDescriptors() { 78 return parameterDescriptors; 79 } 80 81 public ResultDescriptor getResultDescriptor() { 82 return resultDescriptor; 83 } 84 } 85 | Popular Tags |