KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > query > PropertyQuery


1 /*
2  * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/processor/query/PropertyQuery.java,v 1.3 2004/07/28 09:47:46 ib Exp $
3  * $Revision: 1.3 $
4  * $Date: 2004/07/28 09:47:46 $
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.query;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.apache.slide.projector.Context;
30 import org.apache.slide.projector.Processor;
31 import org.apache.slide.projector.Projector;
32 import org.apache.slide.projector.Result;
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.URIValueDescriptor;
38 import org.apache.slide.projector.i18n.DefaultMessage;
39 import org.apache.slide.projector.i18n.ParameterMessage;
40 import org.apache.slide.projector.value.ArrayValue;
41 import org.apache.slide.projector.value.MapValue;
42 import org.apache.slide.projector.value.URIValue;
43
44 /**
45  * The Query class
46  *
47  */

48 public class PropertyQuery implements Processor {
49     private final static String JavaDoc EMPTY = "empty";
50     private final static String JavaDoc URI = "uri";
51     private final static String JavaDoc ARRAY = "array";
52     private final static String JavaDoc MAP = "map";
53
54     private static ResultDescriptor resultDescriptor = new ResultDescriptor(
55             new StateDescriptor[] {
56                 StateDescriptor.OK_DESCRIPTOR,
57                 new StateDescriptor(EMPTY, new DefaultMessage("propertyQuery/state/empty"))},
58             new ResultEntryDescriptor[] {
59                 new ResultEntryDescriptor(ARRAY, new ParameterMessage("propertyQuery/array"), ArrayValue.CONTENT_TYPE, false),
60                 new ResultEntryDescriptor(MAP, new ParameterMessage("propertyQuery/map"), MapValue.CONTENT_TYPE, false)
61             });
62
63     private static ParameterDescriptor []parameterDescriptors = new ParameterDescriptor[] {
64         new ParameterDescriptor(URI, new DefaultMessage("propertyQuery/uri"), new URIValueDescriptor())
65     };
66
67     public Result process(Map JavaDoc parameter, Context context) throws Exception JavaDoc {
68         ArrayValue properties = Projector.getRepository().getProperties((URIValue)parameter.get(URI), context.getCredentials());
69         if ( properties.getArray().length == 0 ) return new Result(EMPTY);
70         Result result= new Result(StateDescriptor.OK, ARRAY, properties);
71         Map JavaDoc properyMap = new HashMap JavaDoc();
72         for ( int i = 0; i < properties.getArray().length; i++ ) {
73             properyMap.put(((MapValue)properties.getArray()[i]).getMap().get("name").toString(), ((MapValue)properties.getArray()[i]).getMap().get("value"));
74         }
75         result.addResultEntry(MAP, new MapValue(properyMap));
76         return result;
77     }
78
79     public ParameterDescriptor[] getParameterDescriptors() {
80         return parameterDescriptors;
81     }
82
83     public ResultDescriptor getResultDescriptor() {
84         return resultDescriptor;
85     }
86 }
Popular Tags