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


001:        package org.drools.rule;
002:
003:        /*
004:         * $Id: Declaration.java,v 1.1 2005/07/26 01:06:31 mproctor Exp $
005:         *
006:         * Copyright 2001-2003 (C) The Werken Company. All Rights Reserved.
007:         *
008:         * Redistribution and use of this software and associated documentation
009:         * ("Software"), with or without modification, are permitted provided that the
010:         * following conditions are met:
011:         *
012:         * 1. Redistributions of source code must retain copyright statements and
013:         * notices. Redistributions must also contain a copy of this document.
014:         *
015:         * 2. Redistributions in binary form must reproduce the above copyright notice,
016:         * this list of conditions and the following disclaimer in the documentation
017:         * and/or other materials provided with the distribution.
018:         *
019:         * 3. The name "drools" must not be used to endorse or promote products derived
020:         * from this Software without prior written permission of The Werken Company.
021:         * For written permission, please contact bob@werken.com.
022:         *
023:         * 4. Products derived from this Software may not be called "drools" nor may
024:         * "drools" appear in their names without prior written permission of The Werken
025:         * Company. "drools" is a trademark of The Werken Company.
026:         *
027:         * 5. Due credit should be given to The Werken Company. (http://werken.com/)
028:         *
029:         * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
030:         * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
031:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
032:         * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
033:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
034:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
035:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
036:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
037:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
039:         * POSSIBILITY OF SUCH DAMAGE.
040:         *
041:         */
042:
043:        import java.io.Serializable;
044:        import java.lang.reflect.Method;
045:        import java.util.Collection;
046:        import java.util.Iterator;
047:
048:        import org.drools.RuntimeDroolsException;
049:        import org.drools.base.ShadowProxy;
050:        import org.drools.base.ValueType;
051:        import org.drools.common.InternalWorkingMemory;
052:        import org.drools.spi.Extractor;
053:
054:        /*
055:         * Copyright 2005 JBoss Inc
056:         * 
057:         * Licensed under the Apache License, Version 2.0 (the "License");
058:         * you may not use this file except in compliance with the License.
059:         * You may obtain a copy of the License at
060:         * 
061:         *      http://www.apache.org/licenses/LICENSE-2.0
062:         * 
063:         * Unless required by applicable law or agreed to in writing, software
064:         * distributed under the License is distributed on an "AS IS" BASIS,
065:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
066:         * See the License for the specific language governing permissions and
067:         * limitations under the License.
068:         */
069:
070:        /**
071:         * @author <a href="mailto:mark.proctor@jboss.com">Mark Proctor</a>
072:         * @author <a href="mailto:bob@werken.com">Bob McWhirter</a>
073:         * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris </a>
074:         *
075:         */
076:        public class Declaration implements  Serializable {
077:            // ------------------------------------------------------------
078:            // Instance members
079:            // ------------------------------------------------------------
080:
081:            /**
082:             * 
083:             */
084:            private static final long serialVersionUID = 400L;
085:
086:            /** The identifier for the variable. */
087:            private final String identifier;
088:
089:            private final Extractor extractor;
090:
091:            private Pattern pattern;
092:
093:            private final boolean internalFact;
094:
095:            // ------------------------------------------------------------
096:            // Constructors
097:            // ------------------------------------------------------------
098:
099:            /**
100:             * Construct.
101:             * 
102:             * @param identifier
103:             *            The name of the variable.
104:             * @param objectType
105:             *            The type of this variable declaration.
106:             * @param order
107:             *            The index within a rule.
108:             */
109:            public Declaration(final String identifier,
110:                    final Extractor extractor, final Pattern pattern) {
111:                this (identifier, extractor, pattern, false);
112:            }
113:
114:            /**
115:             * Construct.
116:             * 
117:             * @param identifier
118:             *            The name of the variable.
119:             * @param objectType
120:             *            The type of this variable declaration.
121:             * @param order
122:             *            The index within a rule.
123:             * @param internalFact
124:             *            True if this is an internal fact created by the engine, like a collection result
125:             *            of a collect CE
126:             */
127:            public Declaration(final String identifier,
128:                    final Extractor extractor, final Pattern pattern,
129:                    final boolean internalFact) {
130:                this .identifier = identifier;
131:                this .extractor = extractor;
132:                this .pattern = pattern;
133:                this .internalFact = internalFact;
134:            }
135:
136:            // ------------------------------------------------------------
137:            // Instance methods
138:            // ------------------------------------------------------------
139:
140:            /**
141:             * Retrieve the variable's identifier.
142:             * 
143:             * @return The variable's identifier.
144:             */
145:            public String getIdentifier() {
146:                return this .identifier;
147:            }
148:
149:            /**
150:             * Retrieve the <code>ValueType</code>.
151:             * 
152:             * @return The ValueType.
153:             */
154:            public ValueType getValueType() {
155:                return this .extractor.getValueType();
156:            }
157:
158:            /**
159:             * Returns the index of the pattern
160:             * 
161:             * @return the pattern
162:             */
163:            public Pattern getPattern() {
164:                return this .pattern;
165:            }
166:
167:            public void setPattern(final Pattern pattern) {
168:                this .pattern = pattern;
169:            }
170:
171:            /**
172:             * Returns true if this declaration is a pattern declaration
173:             * @return
174:             */
175:            public boolean isPatternDeclaration() {
176:                return this .pattern != null
177:                        && this .pattern.getDeclaration() == this ;
178:            }
179:
180:            /**
181:             * Returns the Extractor expression
182:             * 
183:             * @return
184:             */
185:            public Extractor getExtractor() {
186:                return this .extractor;
187:            }
188:
189:            public Object getValue(InternalWorkingMemory workingMemory,
190:                    final Object object) {
191:                return this .extractor.getValue(workingMemory, object);
192:            }
193:
194:            public Object getNonShadowedValue(
195:                    InternalWorkingMemory workingMemory, final Object object) {
196:                Object result = this .extractor.getValue(workingMemory, object);
197:                if (this .isInternalFact() && result instanceof  Collection) {
198:                    try {
199:                        Collection newCol = (Collection) result.getClass()
200:                                .newInstance();
201:                        for (Iterator it = ((Collection) result).iterator(); it
202:                                .hasNext();) {
203:                            Object element = it.next();
204:                            newCol
205:                                    .add((element instanceof  ShadowProxy) ? ((ShadowProxy) element)
206:                                            .getShadowedObject()
207:                                            : element);
208:                        }
209:                        return newCol;
210:                    } catch (InstantiationException e) {
211:                        // nothing we can do, so just return the resulting object
212:                    } catch (IllegalAccessException e) {
213:                        // TODO Auto-generated catch block
214:                    }
215:                }
216:                return result;
217:            }
218:
219:            public char getCharValue(InternalWorkingMemory workingMemory,
220:                    final Object object) {
221:                return this .extractor.getCharValue(workingMemory, object);
222:            }
223:
224:            public int getIntValue(InternalWorkingMemory workingMemory,
225:                    final Object object) {
226:                return this .extractor.getIntValue(workingMemory, object);
227:            }
228:
229:            public byte getByteValue(InternalWorkingMemory workingMemory,
230:                    final Object object) {
231:                return this .extractor.getByteValue(workingMemory, object);
232:            }
233:
234:            public short getShortValue(InternalWorkingMemory workingMemory,
235:                    final Object object) {
236:                return this .extractor.getShortValue(workingMemory, object);
237:            }
238:
239:            public long getLongValue(InternalWorkingMemory workingMemory,
240:                    final Object object) {
241:                return this .extractor.getLongValue(workingMemory, object);
242:            }
243:
244:            public float getFloatValue(InternalWorkingMemory workingMemory,
245:                    final Object object) {
246:                return this .extractor.getFloatValue(workingMemory, object);
247:            }
248:
249:            public double getDoubleValue(InternalWorkingMemory workingMemory,
250:                    final Object object) {
251:                return this .extractor.getDoubleValue(workingMemory, object);
252:            }
253:
254:            public boolean getBooleanValue(InternalWorkingMemory workingMemory,
255:                    final Object object) {
256:                return this .extractor.getBooleanValue(workingMemory, object);
257:            }
258:
259:            public int getHashCode(InternalWorkingMemory workingMemory,
260:                    final Object object) {
261:                return this .extractor.getHashCode(workingMemory, object);
262:            }
263:
264:            public boolean isGlobal() {
265:                return this .extractor.isGlobal();
266:            }
267:
268:            public Method getNativeReadMethod() {
269:                if (this .isPatternDeclaration() && this .isInternalFact()) {
270:                    try {
271:                        return this .getClass().getDeclaredMethod(
272:                                "getNonShadowedValue",
273:                                new Class[] { InternalWorkingMemory.class,
274:                                        Object.class });
275:                    } catch (final Exception e) {
276:                        throw new RuntimeDroolsException(
277:                                "This is a bug. Please report to development team: "
278:                                        + e.getMessage(), e);
279:                    }
280:                }
281:                return this .extractor.getNativeReadMethod();
282:            }
283:
284:            // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
285:
286:            public String toString() {
287:                return "[Declaration: type=" + this .extractor.getValueType()
288:                        + " identifier=" + this .identifier + "]";
289:            }
290:
291:            public int hashCode() {
292:                final int PRIME = 31;
293:                int result = 1;
294:                result = PRIME * this .pattern.getOffset();
295:                result = PRIME * this .extractor.hashCode();
296:                result = PRIME * this .identifier.hashCode();
297:                return result;
298:            }
299:
300:            public boolean equals(final Object object) {
301:                if (this  == object) {
302:                    return true;
303:                }
304:
305:                if (object == null || getClass() != object.getClass()) {
306:                    return false;
307:                }
308:
309:                final Declaration other = (Declaration) object;
310:
311:                return this .pattern.getOffset() == other.pattern.getOffset()
312:                        && this .identifier.equals(other.identifier)
313:                        && this .extractor.equals(other.extractor);
314:            }
315:
316:            protected boolean isInternalFact() {
317:                return internalFact;
318:            }
319:
320:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.