Source Code Cross Referenced for FieldFactory.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » base » 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 » Rule Engine » drolls Rule Engine » org.drools.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.base;
002:
003:        /*
004:         * Copyright 2005 JBoss Inc
005:         * 
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *      http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import java.math.BigDecimal;
020:        import java.math.BigInteger;
021:
022:        import org.drools.base.field.BooleanFieldImpl;
023:        import org.drools.base.field.DoubleFieldImpl;
024:        import org.drools.base.field.LongFieldImpl;
025:        import org.drools.base.field.ObjectFieldImpl;
026:        import org.drools.spi.FieldValue;
027:
028:        public class FieldFactory {
029:            private static final FieldFactory INSTANCE = new FieldFactory();
030:
031:            public static FieldFactory getInstance() {
032:                return FieldFactory.INSTANCE;
033:            }
034:
035:            private FieldFactory() {
036:
037:            }
038:
039:            public static FieldValue getFieldValue(final String value,
040:                    ValueType valueType) {
041:                FieldValue field = null;
042:                if (value == null) {
043:                    valueType = ValueType.NULL_TYPE;
044:                }
045:
046:                if (valueType == ValueType.NULL_TYPE) {
047:                    field = new ObjectFieldImpl(null);
048:                } else if (valueType == ValueType.PCHAR_TYPE) {
049:                    field = new LongFieldImpl(value.charAt(0));
050:                } else if (valueType == ValueType.PBYTE_TYPE) {
051:                    field = new LongFieldImpl(Long.parseLong(value));
052:                } else if (valueType == ValueType.PSHORT_TYPE) {
053:                    field = new LongFieldImpl(Long.parseLong(value));
054:                } else if (valueType == ValueType.PINTEGER_TYPE) {
055:                    field = new LongFieldImpl(Long
056:                            .parseLong(stripNumericType(value)));
057:                } else if (valueType == ValueType.PLONG_TYPE) {
058:                    field = new LongFieldImpl(Long
059:                            .parseLong(stripNumericType(value)));
060:                } else if (valueType == ValueType.PFLOAT_TYPE) {
061:                    field = new DoubleFieldImpl(Float
062:                            .parseFloat(stripNumericType(value)));
063:                } else if (valueType == ValueType.PDOUBLE_TYPE) {
064:                    field = new DoubleFieldImpl(Double
065:                            .parseDouble(stripNumericType(value)));
066:                } else if (valueType == ValueType.PBOOLEAN_TYPE) {
067:                    field = new BooleanFieldImpl(Boolean.valueOf(value)
068:                            .booleanValue());
069:                } else if (valueType == ValueType.CHAR_TYPE) {
070:                    field = new ObjectFieldImpl(new Character(value.charAt(0)));
071:                } else if (valueType == ValueType.BYTE_TYPE) {
072:                    field = new ObjectFieldImpl(new Byte(value));
073:                } else if (valueType == ValueType.SHORT_TYPE) {
074:                    field = new ObjectFieldImpl(new Short(value));
075:                } else if (valueType == ValueType.INTEGER_TYPE) {
076:                    field = new ObjectFieldImpl(new Integer(
077:                            stripNumericType(value)));
078:                } else if (valueType == ValueType.LONG_TYPE) {
079:                    field = new ObjectFieldImpl(new Long(
080:                            stripNumericType(value)));
081:                } else if (valueType == ValueType.FLOAT_TYPE) {
082:                    field = new ObjectFieldImpl(new Float(
083:                            stripNumericType(value)));
084:                } else if (valueType == ValueType.DOUBLE_TYPE) {
085:                    field = new ObjectFieldImpl(new Double(
086:                            stripNumericType(value)));
087:                } else if (valueType == ValueType.BOOLEAN_TYPE) {
088:                    field = new ObjectFieldImpl(Boolean.valueOf(value));
089:                } else if (valueType == ValueType.STRING_TYPE) {
090:                    field = new ObjectFieldImpl(value.intern());
091:                } else if (valueType == ValueType.DATE_TYPE) {
092:                    //MN: I think its fine like this, seems to work !
093:                    field = new ObjectFieldImpl(value);
094:                } else if (valueType == ValueType.ARRAY_TYPE) {
095:                    //MN: I think its fine like this.
096:                    field = new ObjectFieldImpl(value);
097:                } else if (valueType == ValueType.OBJECT_TYPE) {
098:                    field = new ObjectFieldImpl(value);
099:                } else if (valueType == ValueType.BIG_DECIMAL_TYPE) {
100:                    field = new ObjectFieldImpl(new BigDecimal(value));
101:                } else if (valueType == ValueType.BIG_INTEGER_TYPE) {
102:                    field = new ObjectFieldImpl(new BigInteger(value));
103:                }
104:
105:                return field;
106:            }
107:
108:            public static FieldValue getFieldValue(final Object value,
109:                    ValueType valueType) {
110:                FieldValue field = null;
111:                if (value == null) {
112:                    valueType = ValueType.NULL_TYPE;
113:                }
114:
115:                if (valueType == ValueType.NULL_TYPE) {
116:                    field = new ObjectFieldImpl(null);
117:                } else if (valueType == ValueType.PCHAR_TYPE) {
118:                    field = new LongFieldImpl(((Character) value).charValue());
119:                } else if (valueType == ValueType.PBYTE_TYPE) {
120:                    field = new LongFieldImpl(((Number) value).byteValue());
121:                } else if (valueType == ValueType.PSHORT_TYPE) {
122:                    field = new LongFieldImpl(((Number) value).shortValue());
123:                } else if (valueType == ValueType.PINTEGER_TYPE) {
124:                    field = new LongFieldImpl(((Number) value).intValue());
125:                } else if (valueType == ValueType.PLONG_TYPE) {
126:                    field = new LongFieldImpl(((Number) value).longValue());
127:                } else if (valueType == ValueType.PFLOAT_TYPE) {
128:                    field = new DoubleFieldImpl(((Number) value).floatValue());
129:                } else if (valueType == ValueType.PDOUBLE_TYPE) {
130:                    field = new DoubleFieldImpl(((Number) value).doubleValue());
131:                } else if (valueType == ValueType.PBOOLEAN_TYPE) {
132:                    field = new BooleanFieldImpl(((Boolean) value)
133:                            .booleanValue());
134:                } else if (valueType == ValueType.CHAR_TYPE) {
135:                    field = new ObjectFieldImpl(value);
136:                } else if (valueType == ValueType.BYTE_TYPE) {
137:                    field = new ObjectFieldImpl(value);
138:                } else if (valueType == ValueType.SHORT_TYPE) {
139:                    field = new ObjectFieldImpl(value);
140:                } else if (valueType == ValueType.INTEGER_TYPE) {
141:                    field = new ObjectFieldImpl(value);
142:                } else if (valueType == ValueType.LONG_TYPE) {
143:                    field = new ObjectFieldImpl(value);
144:                } else if (valueType == ValueType.FLOAT_TYPE) {
145:                    field = new ObjectFieldImpl(value);
146:                } else if (valueType == ValueType.DOUBLE_TYPE) {
147:                    field = new ObjectFieldImpl(value);
148:                } else if (valueType == ValueType.BOOLEAN_TYPE) {
149:                    field = new ObjectFieldImpl(value);
150:                } else if (valueType == ValueType.STRING_TYPE) {
151:                    field = new ObjectFieldImpl(value);
152:                } else if (valueType == ValueType.DATE_TYPE) {
153:                    //MN: I think its fine like this, seems to work !
154:                    field = new ObjectFieldImpl(value);
155:                } else if (valueType == ValueType.ARRAY_TYPE) {
156:                    //MN: I think its fine like this.
157:                    field = new ObjectFieldImpl(value);
158:                } else if (valueType == ValueType.OBJECT_TYPE) {
159:                    field = new ObjectFieldImpl(value);
160:                } else if (valueType == ValueType.BIG_DECIMAL_TYPE) {
161:                    field = new ObjectFieldImpl(value);
162:                } else if (valueType == ValueType.BIG_INTEGER_TYPE) {
163:                    field = new ObjectFieldImpl(value);
164:                }
165:
166:                return field;
167:            }
168:
169:            public static FieldValue getFieldValue(final Object value) {
170:                return new ObjectFieldImpl(value);
171:            }
172:
173:            public static FieldValue getFieldValue(final byte value) {
174:                return new LongFieldImpl(value);
175:            }
176:
177:            public static FieldValue getFieldValue(final short value) {
178:                return new LongFieldImpl(value);
179:            }
180:
181:            public static FieldValue getFieldValue(final char value) {
182:                return new LongFieldImpl(value);
183:            }
184:
185:            public static FieldValue getFieldValue(final int value) {
186:                return new LongFieldImpl(value);
187:            }
188:
189:            public static FieldValue getFieldValue(final long value) {
190:                return new LongFieldImpl(value);
191:            }
192:
193:            public static FieldValue getFieldValue(final boolean value) {
194:                return new BooleanFieldImpl(value);
195:            }
196:
197:            public static FieldValue getFieldValue(final float value) {
198:                return new DoubleFieldImpl(value);
199:            }
200:
201:            public static FieldValue getFieldValue(final double value) {
202:                return new DoubleFieldImpl(value);
203:            }
204:
205:            private static String stripNumericType(String value) {
206:                // incase a user adds a f or l, strip it as its not needed
207:                if (Character.getType(value.charAt(value.length() - 1)) != Character.DECIMAL_DIGIT_NUMBER) {
208:                    value = value.substring(0, value.length() - 1);
209:                }
210:
211:                return value;
212:            }
213:
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.