KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > access > Put


1 /*
2  * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/processor/access/Put.java,v 1.4 2004/08/03 14:30:02 dflorey Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/08/03 14:30:02 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.projector.processor.access;
25
26 import java.util.Map JavaDoc;
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 /**
45  * The Event class
46  *
47  */

48 public class Put implements Processor {
49     public final static String JavaDoc STORE = "store";
50     public final static String JavaDoc KEY = "key";
51     public final static String JavaDoc VALUE = "value";
52     public final static String JavaDoc 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 JavaDoc parameter, Context context) throws Exception JavaDoc {
63         String JavaDoc storeName = parameter.get(STORE).toString();
64         String JavaDoc 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