KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/processor/query/ResourceQuery.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.Map JavaDoc;
27
28 import org.apache.slide.projector.Context;
29 import org.apache.slide.projector.Processor;
30 import org.apache.slide.projector.Projector;
31 import org.apache.slide.projector.Result;
32 import org.apache.slide.projector.descriptor.ParameterDescriptor;
33 import org.apache.slide.projector.descriptor.ResultDescriptor;
34 import org.apache.slide.projector.descriptor.ResultEntryDescriptor;
35 import org.apache.slide.projector.descriptor.StateDescriptor;
36 import org.apache.slide.projector.descriptor.StringValueDescriptor;
37 import org.apache.slide.projector.i18n.DefaultMessage;
38 import org.apache.slide.projector.i18n.ParameterMessage;
39 import org.apache.slide.projector.processor.SimpleProcessor;
40 import org.apache.slide.projector.value.ArrayValue;
41 import org.apache.slide.projector.value.StringValue;
42 import org.apache.slide.projector.value.Value;
43
44 /**
45  * The Query class
46  *
47  */

48 public class ResourceQuery implements Processor {
49     private final static String JavaDoc EMPTY = "empty";
50     private final static String JavaDoc DASL_QUERY = "query";
51
52     private static ResultDescriptor resultDescriptor = new ResultDescriptor(
53             new StateDescriptor[] {
54                 StateDescriptor.OK_DESCRIPTOR,
55                 new StateDescriptor(EMPTY, new DefaultMessage("resourceQuery/state/empty"))},
56             new ResultEntryDescriptor[] {
57                 new ResultEntryDescriptor(SimpleProcessor.OUTPUT, new DefaultMessage("queryResult"), ArrayValue.CONTENT_TYPE, false)
58             });
59
60     private static ParameterDescriptor []parameterDescriptors = new ParameterDescriptor[] {
61         new ParameterDescriptor(DASL_QUERY, new ParameterMessage("daslQuery"), new StringValueDescriptor())
62     };
63
64     public Result process(Map JavaDoc parameter, Context context) throws Exception JavaDoc {
65         String JavaDoc query = ((StringValue)parameter.get(DASL_QUERY)).toString();
66         Value []values = Projector.getRepository().search(query, context.getCredentials());
67         if ( values.length == 0 ) return new Result(EMPTY);
68         return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, new ArrayValue(values));
69     }
70
71     public ParameterDescriptor[] getParameterDescriptors() {
72         return parameterDescriptors;
73     }
74
75     public ResultDescriptor getResultDescriptor() {
76         return resultDescriptor;
77     }
78 }
Popular Tags