Source Code Cross Referenced for FieldDefinition.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » search » fieldmodel » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.components.search.fieldmodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.cocoon.components.search.fieldmodel;
017:
018:        import org.apache.lucene.document.Field;
019:
020:        /**
021:         * Field Definition class
022:         * 
023:         * @author Nicolas Maisonneuve
024:         * 
025:         */
026:        public abstract class FieldDefinition {
027:            /**
028:             * Text type
029:             */
030:            public static final int TEXT = 0;
031:
032:            /**
033:             * Keyword type
034:             */
035:            public static final int KEYWORD = 1;
036:
037:            /**
038:             * Date type
039:             */
040:            public static final int DATE = 2;
041:
042:            public static final String[] STRING_TYPE = { "text", "keyword",
043:                    "date" };
044:
045:            /**
046:             * Name of the field
047:             */
048:            protected String name;
049:
050:            /**
051:             * type of the field (text, keyword, date)
052:             */
053:            protected int type;
054:
055:            /**
056:             * Lucene Field specification
057:             */
058:            protected boolean store;
059:
060:            protected boolean index;
061:
062:            // futur lucene 1.9: protected Field.Store store;
063:            // futur lucene 1.9: protected Field.Index index;
064:
065:            protected FieldDefinition(String name, String type)
066:                    throws IllegalArgumentException {
067:                this (name, stringTotype(type));
068:            }
069:
070:            protected FieldDefinition(String name, int type)
071:                    throws IllegalArgumentException {
072:                this (name, type, false);
073:            }
074:
075:            public static FieldDefinition create(String name, int type) {
076:                FieldDefinition field = null;
077:
078:                if (name == null || name.trim().equals("")) {
079:                    throw new IllegalArgumentException("name cannot be empty");
080:                }
081:                switch (type) {
082:                case TEXT:
083:                case KEYWORD:
084:                    field = new StringFieldDefinition(name, type);
085:                    break;
086:                case DATE:
087:                    field = new DateFieldDefinition(name);
088:                    break;
089:                default:
090:                    throw new IllegalArgumentException("type not allowed");
091:                }
092:                return field;
093:            }
094:
095:            /**
096:             * 
097:             * @param name
098:             *            String field's name
099:             * @param type
100:             *            int indexation type
101:             * @param store
102:             *            boolean store value in the index
103:             * @throws IllegalArgumentException
104:             */
105:            private FieldDefinition(String name, int type, boolean store)
106:                    throws IllegalArgumentException {
107:
108:                this .name = name.intern();
109:                setType(type);
110:                setStore(store);
111:            }
112:
113:            public int hashCode() {
114:                return name.hashCode() * this .type;
115:            }
116:
117:            public void setStore(boolean store) {
118:                // for futur lucene1.9
119:                // this.store=(store)?Field.Store.YES:Field.Store.NO;
120:                this .store = store;
121:            }
122:
123:            public boolean getStore() {
124:                // for futur lucene1.9 return this.store==Field.Store.YES;
125:                return store;
126:            }
127:
128:            public boolean equals(FieldDefinition fielddef) {
129:                if (name.equals(fielddef.name())
130:                        && getType() == fielddef.getType()) {
131:                    return true;
132:                } else {
133:                    return false;
134:                }
135:            }
136:
137:            public boolean equals(Object object) {
138:                if (object instanceof  FieldDefinition) {
139:                    return equals((FieldDefinition) object);
140:                } else {
141:                    return false;
142:                }
143:            }
144:
145:            public String name() {
146:                return name;
147:            }
148:
149:            /**
150:             * Create Lucene Field
151:             * 
152:             * @param value
153:             *            String value to store in the lucene field
154:             * @return Field
155:             */
156:            public abstract Field createLField(String value);
157:
158:            public int getType() {
159:                return type;
160:            }
161:
162:            /**
163:             * Set the type of the FieldDefinition (DATE,TEXT,KEYWORD)
164:             * 
165:             * @param type
166:             *            int
167:             * @throws IllegalArgumentException
168:             */
169:            private void setType(int type) throws IllegalArgumentException {
170:                switch (type) {
171:                case FieldDefinition.TEXT:
172:                    index = true;
173:                    break;
174:                case FieldDefinition.DATE:
175:                    index = true;
176:                    break;
177:                case FieldDefinition.KEYWORD:
178:                    index = false;
179:                    break;
180:                default:
181:                    throw new IllegalArgumentException("type not allowed");
182:                }
183:                this .type = type;
184:            }
185:
186:            public final String toString() {
187:                StringBuffer b = new StringBuffer();
188:                b.append("name: " + name);
189:                b.append(", type: " + FieldDefinition.STRING_TYPE[type]);
190:                b.append(", store: " + getStore());
191:                return b.toString();
192:            }
193:
194:            /**
195:             * Convert String to type
196:             * 
197:             * @param typename
198:             *            String
199:             * @return int
200:             */
201:            static final public int stringTotype(String typename)
202:                    throws IllegalArgumentException {
203:                for (int i = 0; i < STRING_TYPE.length; i++) {
204:                    if (typename.toLowerCase().equals(STRING_TYPE[i])) {
205:                        return i;
206:                    }
207:                }
208:                throw new IllegalArgumentException("type " + typename
209:                        + " is not allowed");
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.