KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > query > namespace > MatchNSInQuery


1 package com.jofti.query.namespace;
2
3 import com.jofti.api.IndexQuery;
4 import com.jofti.core.QueryId;
5 import com.jofti.core.QueryType;
6 import com.jofti.util.ReflectionUtil;
7
8 /**
9  *
10  *
11  * A utility class to enable simple queries to be done easily. The Query matches everything equal to the
12  * value passed in for that particular field. This is equivalent to =.<p>
13  *
14  *
15  * This query cannot be combined with any other. iF you want to construct more complex queries use the @link com.jofti.query.Query class.
16   *<p>
17   *@author Steve Woodcock
18  */

19 public class MatchNSInQuery implements IndexQuery, QueryId {
20
21     Class JavaDoc className;
22     String JavaDoc propertyName;
23     Comparable JavaDoc[] values;
24     Object JavaDoc nameSpace;
25     public final Object JavaDoc alias;
26     
27     static final QueryType QUERY_ID=QueryType.IN_NS_QUERY;
28     
29     /**
30      * Construct a query supplying the classname of the object type to be returned,and the
31      * field to be queried and the value to be used. <p>
32      *
33      * The field type in the object and the value must be of the same type.
34      *
35      * <p>
36      * An example usage would be:
37      * <p>
38      * new MatchQuery("org.package.Myclass", "myProperty" ,"some value");
39      * <p>
40      * @param className - the class of object to be returned.
41      * @param propertyName - the field name to use
42      * @param value - the value that is used as the search value.
43      */

44     public MatchNSInQuery(Class JavaDoc className, Object JavaDoc nameSpace, String JavaDoc propertyName, Comparable JavaDoc[] values){
45         this(className,nameSpace, propertyName,values,null);
46     }
47     public MatchNSInQuery(Class JavaDoc className, Object JavaDoc nameSpace, String JavaDoc propertyName, Comparable JavaDoc[] values,Object JavaDoc alias){
48         this.className = className;
49         this.nameSpace = nameSpace;
50         this.propertyName = propertyName;
51         this.values = values;
52         this.alias = alias;
53     }
54     
55     public MatchNSInQuery(String JavaDoc className, Object JavaDoc nameSpace, String JavaDoc propertyName, Comparable JavaDoc[] values){
56         this(className,nameSpace,propertyName,values,null);
57     }
58     public MatchNSInQuery(String JavaDoc className, Object JavaDoc nameSpace,String JavaDoc propertyName, Comparable JavaDoc[] values,Object JavaDoc alias){
59         Class JavaDoc clazz = null;
60         try{
61             clazz = ReflectionUtil.classForName(className);
62         }catch (Exception JavaDoc e){
63             throw new RuntimeException JavaDoc(e);
64         }
65         this.nameSpace = nameSpace;
66         this.className = clazz;
67         this.propertyName = propertyName;
68         this.values = values;
69         this.alias = alias;
70     }
71     /**
72      * Construct a query supplying the value to be searched against.
73      * This is a convenience method for classes (such as String,Integer etc)
74      * that have no property value as such. Instead the value is the class type.
75      * <p>
76      *
77      * An example usage would be:
78      * <p>
79      * new MatchNotQuery("some value",true);
80      * <p>
81      * This is so you do not have to use the methods above in the manner of
82      * <p>
83      * new MatchQuery("java.lang.String", null ,"some value");
84      * <p>
85      * @param value - the value that is used as the search value.
86      */

87     public MatchNSInQuery(Comparable JavaDoc[] values){
88         this.values = values;
89         this.alias =null;
90     }
91     /**
92      * @return Returns the className.
93      */

94     public Class JavaDoc getClassName() {
95         return className;
96     }
97
98     /**
99      * @return Returns the propertyName.
100      */

101     public String JavaDoc getPropertyName() {
102         return propertyName;
103     }
104
105     /**
106      * @return Returns the value.
107      */

108     public Comparable JavaDoc[] getValues() {
109         return values;
110     }
111
112     public QueryType getQueryType()
113     {
114         return QUERY_ID;
115     }
116
117     
118     public Object JavaDoc getNameSpace() {
119         return nameSpace;
120     }
121     public void setNameSpace(Object JavaDoc nameSpace) {
122         this.nameSpace = nameSpace;
123     }
124     public Object JavaDoc getAlias() {
125         return alias;
126     }
127     /* (non-Javadoc)
128      * @see com.jofti.api.IndexQuery#setParameter(java.lang.String, java.lang.Object)
129      */

130     public IndexQuery setParameter(String JavaDoc name, Object JavaDoc value) {
131         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
132     }
133     /* (non-Javadoc)
134      * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
135      */

136     public IndexQuery setParameter(int position, Object JavaDoc value) {
137         throw new UnsupportedOperationException JavaDoc("Parameters are not supported for convenience classes");
138
139     }
140     public IndexQuery setFirstResult(int firstResult) {
141         throw new UnsupportedOperationException JavaDoc("Result limitation is not supported for convenience classes");
142     }
143     public IndexQuery setMaxResults(int maxResults) {
144         throw new UnsupportedOperationException JavaDoc("Result limitation is not supported for convenience classes");
145     }
146
147 }
148
Popular Tags