KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > core > MapEntry


1 /*
2  * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/processor/core/MapEntry.java,v 1.5 2004/08/04 15:22:49 dflorey Exp $
3  * $Revision: 1.5 $
4  * $Date: 2004/08/04 15:22:49 $
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.core;
25
26 import java.util.Map JavaDoc;
27
28 import org.apache.slide.projector.ContentType;
29 import org.apache.slide.projector.Context;
30 import org.apache.slide.projector.Processor;
31 import org.apache.slide.projector.Result;
32 import org.apache.slide.projector.descriptor.MapValueDescriptor;
33 import org.apache.slide.projector.descriptor.ParameterDescriptor;
34 import org.apache.slide.projector.descriptor.ResultDescriptor;
35 import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
36 import org.apache.slide.projector.descriptor.StateDescriptor;
37 import org.apache.slide.projector.descriptor.StringValueDescriptor;
38 import org.apache.slide.projector.i18n.DefaultMessage;
39 import org.apache.slide.projector.i18n.ParameterMessage;
40 import org.apache.slide.projector.processor.SimpleProcessor;
41 import org.apache.slide.projector.value.MapValue;
42 import org.apache.slide.projector.value.StringValue;
43 import org.apache.slide.projector.value.Value;
44
45 /**
46  * The MapEntry class
47  *
48  */

49 public class MapEntry implements Processor {
50     private final static String JavaDoc MAP = "map";
51     private final static String JavaDoc KEY = "key";
52
53     private final static String JavaDoc KEY_NOT_FOUND = "keyNotFound";
54
55     private final static ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[] {
56         new ParameterDescriptor(MAP, new ParameterMessage("mapEntry/map"), MapValueDescriptor.ANY),
57         new ParameterDescriptor(KEY, new ParameterMessage("mapEntry/key"), new StringValueDescriptor())
58     };
59
60     private final static ResultDescriptor resultDescriptor = new ResultDescriptor(
61             new StateDescriptor[] {
62                 StateDescriptor.OK_DESCRIPTOR,
63                 new StateDescriptor(KEY_NOT_FOUND, new DefaultMessage("mapEntry/state/keyNotFound"))},
64             new ResultEntryDescriptor[] {
65                 new ResultEntryDescriptor(SimpleProcessor.OUTPUT, new DefaultMessage("mapEntry/output"), ContentType.DYNAMIC, false)
66             });
67
68     public Result process(Map JavaDoc parameter, Context context) throws Exception JavaDoc {
69         Map JavaDoc map = ((MapValue)parameter.get(MAP)).getMap();
70         String JavaDoc key = ((StringValue)parameter.get(KEY)).toString();
71         Value entry = (Value)map.get(key);
72         if ( entry == null ) return new Result(KEY_NOT_FOUND);
73         return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, entry);
74     }
75
76     public ParameterDescriptor[] getParameterDescriptors() {
77         return parameterDescriptors;
78     }
79
80     public ResultDescriptor getResultDescriptor() {
81         return resultDescriptor;
82     }
83 }
84
Popular Tags