Source Code Cross Referenced for MatchNSQuery.java in  » Search-Engine » Jofti » com » jofti » query » namespace » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » Jofti » com.jofti.query.namespace 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jofti.query.namespace;
002:
003:        import com.jofti.api.IndexQuery;
004:        import com.jofti.cache.adapter.NameSpaceWrapper;
005:        import com.jofti.core.INameSpace;
006:        import com.jofti.core.INameSpaceAware;
007:        import com.jofti.core.QueryId;
008:        import com.jofti.core.QueryType;
009:        import com.jofti.util.ReflectionUtil;
010:
011:        /**
012:         * 
013:         *
014:         * A utility class to enable simple queries to be done easily. The Query matches  
015:         * the value for particular field. This is equivalent to =.
016:         * <p>
017:         * All nameSpace queries must provide a correct namespace type for the implementation. Some nameSpaces 
018:         * are hierachical and so the search will use the nameSpace as starting point. Others are flat and so there is no 
019:         * traversal step.
020:         * <p>
021:         * This query cannot be combined with any other. iF you want to construct more complex queries use the @link com.jofti.query.Query class.
022:         *
023:         * @author steve Woodcock
024:         */
025:        public class MatchNSQuery implements  IndexQuery, INameSpaceAware,
026:                QueryId {
027:
028:            public final Object alias;
029:            private int hashCode = 0;
030:            Class className;
031:            Object nameSpace;
032:            String propertyName;
033:            Comparable value;
034:            static final QueryType QUERY_ID = QueryType.MATCH_NS_QUERY;
035:
036:            /**
037:             * Construct a query supplying the classname of the object type to be returned, the namespace 
038:             * under which to start the search. The field to be queried and the value to be used. 
039:             * <p>
040:             * The field type in the object and the value must be of the same type.
041:             * <p>
042:             * 
043:             * An example usage (for JBossCache) would be:
044:             * <p>
045:             * new MatchNSQuery("org.package.Myclass", "/test", "myProperty" ,"some value");
046:             * <p>
047:             * @param className - the class of object to be returned.
048:             * @param nameSpace - the name space to be searched.
049:             * @param propertyName - the field name to use
050:             * @param value - the value that is used as the search value.
051:             */
052:            public MatchNSQuery(Class className, Object nameSpace,
053:                    String propertyName, Comparable value) {
054:                this (className, nameSpace, propertyName, value, null);
055:            }
056:
057:            public MatchNSQuery(Class className, Object nameSpace,
058:                    String propertyName, Comparable value, Object alias) {
059:                this .className = className;
060:                this .propertyName = propertyName;
061:                this .value = value;
062:                this .nameSpace = nameSpace;
063:                this .alias = alias;
064:            }
065:
066:            public MatchNSQuery(String className, Object nameSpace,
067:                    String propertyName, Comparable value) {
068:                this (className, nameSpace, propertyName, value, null);
069:            }
070:
071:            public MatchNSQuery(String className, Object nameSpace,
072:                    String propertyName, Comparable value, Object alias) {
073:                Class clazz = null;
074:                try {
075:                    clazz = ReflectionUtil.classForName(className);
076:                } catch (Exception e) {
077:                    throw new RuntimeException(e);
078:                }
079:                this .className = clazz;
080:                this .propertyName = propertyName;
081:                this .value = value;
082:                this .nameSpace = nameSpace;
083:                this .alias = alias;
084:            }
085:
086:            /**
087:             * Construct a query supplying the value to be searched against and the namespace 
088:             * under which to start the search. This is a convenience method for classes (such as String,Integer etc)
089:             * that have no property value as such. Instead the value is the class type.
090:             * <p>
091:             * 
092:             * An example usage (for JBossCache) would be:
093:             * <p>
094:             * new MatchNSQuery("/test","some value");
095:             * <p>
096:             * This is so you do not have to use the methods above in the manner of
097:             * <p>
098:             * new MatchNSQuery("java.lang.String", "/test", null ,"some value"); 
099:             * <p>
100:
101:             * @param nameSpace - the name space to be searched.
102:             * @param value - the value that is used as the search value.
103:             */
104:
105:            public MatchNSQuery(Object nameSpace, Comparable value) {
106:                this (nameSpace, value, null);
107:            }
108:
109:            public MatchNSQuery(Object nameSpace, Comparable value, Object alias) {
110:                this .value = value;
111:                this .nameSpace = nameSpace;
112:                this .alias = alias;
113:
114:            }
115:
116:            public MatchNSQuery(Object nameSpace) {
117:                this (nameSpace, null);
118:            }
119:
120:            public MatchNSQuery(Object nameSpace, Object alias) {
121:                this .nameSpace = nameSpace;
122:                this .alias = alias;
123:
124:            }
125:
126:            /**
127:             * @return Returns the className.
128:             */
129:            public Class getClassName() {
130:                return className;
131:            }
132:
133:            /**
134:             * @return Returns the propertyName.
135:             */
136:            public String getPropertyName() {
137:                return propertyName;
138:            }
139:
140:            /**
141:             * @return Returns the value.
142:             */
143:            public Comparable getValue() {
144:                return value;
145:            }
146:
147:            /**
148:             * @return Returns the wrapper.
149:             */
150:            public synchronized INameSpace getNameSpaceWrapper() {
151:
152:                if (nameSpace instanceof  INameSpace) {
153:                    return (INameSpace) nameSpace;
154:                } else {
155:                    return new NameSpaceWrapper(nameSpace);
156:                }
157:            }
158:
159:            /**
160:             * @return Returns the nameSpace.
161:             */
162:            public synchronized Object getNameSpace() {
163:                return nameSpace;
164:            }
165:
166:            /**
167:             * @param nameSpace The nameSpace to set.
168:             */
169:            public synchronized void setNameSpace(Object nameSpace) {
170:                this .nameSpace = nameSpace;
171:            }
172:
173:            public boolean equals(Object o) {
174:                if (o instanceof  MatchNSQuery) {
175:                    MatchNSQuery temp = (MatchNSQuery) o;
176:                    boolean result = nameSpace.equals(temp.nameSpace);
177:                    if (!result) {
178:                        return result;
179:                    }
180:                    if (className != null && temp.className != null) {
181:                        result = className.equals(temp.className);
182:                        if (!result) {
183:                            return result;
184:                        }
185:                    } else {
186:                        result = className == null & temp.className == null;
187:                        if (!result) {
188:                            return result;
189:                        }
190:                    }
191:
192:                    if (propertyName != null && temp.propertyName != null) {
193:                        result = propertyName.equals(temp.propertyName);
194:                        if (!result) {
195:                            return result;
196:                        }
197:                    } else {
198:                        result = propertyName == null
199:                                & temp.propertyName == null;
200:                        if (!result) {
201:                            return result;
202:                        }
203:                    }
204:                    if (value != null && temp.value != null) {
205:                        result = value.equals(temp.value);
206:                        if (!result) {
207:                            return result;
208:                        }
209:                    } else {
210:                        result = value == null & temp.value == null;
211:                        if (!result) {
212:                            return result;
213:                        }
214:                    }
215:                    return result;
216:                }
217:                return false;
218:            }
219:
220:            public int hashCode() {
221:                if (hashCode == 0) {
222:                    int temp = nameSpace == null ? 0 : nameSpace.hashCode();
223:                    if (className != null) {
224:                        temp += className.hashCode();
225:                    }
226:                    if (propertyName != null) {
227:                        temp += propertyName.hashCode();
228:                    }
229:                    if (value != null) {
230:                        temp += value.hashCode();
231:                    }
232:                    hashCode = temp;
233:
234:                }
235:                return hashCode;
236:            }
237:
238:            public Object getAlias() {
239:                return alias;
240:            }
241:
242:            public QueryType getQueryType() {
243:
244:                return QUERY_ID;
245:            }
246:
247:            public IndexQuery setParameter(String name, Object value) {
248:                throw new UnsupportedOperationException(
249:                        "Parameters are not supported for convenience classes");
250:            }
251:
252:            /* (non-Javadoc)
253:             * @see com.jofti.api.IndexQuery#setParameter(int, java.lang.Object)
254:             */
255:            public IndexQuery setParameter(int position, Object value) {
256:                throw new UnsupportedOperationException(
257:                        "Parameters are not supported for convenience classes");
258:
259:            }
260:
261:            public IndexQuery setFirstResult(int firstResult) {
262:                throw new UnsupportedOperationException(
263:                        "Result limitation is not supported for convenience classes");
264:            }
265:
266:            public IndexQuery setMaxResults(int maxResults) {
267:                throw new UnsupportedOperationException(
268:                        "Result limitation is not supported for convenience classes");
269:            }
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.