Source Code Cross Referenced for Constant.java in  » Rule-Engine » take » nz » org » take » 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 » take » nz.org.take 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2007 Jens Dietrich Licensed under the Apache License, Version 2.0 (the "License"); 
003:         * you may not use this file except in compliance with the License. 
004:         * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
005:         * Unless required by applicable law or agreed to in writing, software distributed under the 
006:         * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
007:         * either express or implied. See the License for the specific language governing permissions 
008:         * and limitations under the License.
009:         */package nz.org.take;
010:
011:        /**
012:         * Constant terms. Basically those are just arbitrary (wrapped) objects.
013:         * @author <a href="http://www-ist.massey.ac.nz/JBDietrich/">Jens Dietrich</a>
014:         */
015:
016:        public class Constant extends AbstractAnnotatable implements  Term {
017:
018:            private Object object = null;
019:            // the type can be overridden, by default the type of the object is used
020:            private Class type = null;
021:            // this is a string that is used to proxy the object
022:            private String ref = null;
023:
024:            public Object getObject() {
025:                return object;
026:            }
027:
028:            public void setObject(Object o) {
029:                checkTypeConsistency(o, type);
030:                this .object = o;
031:            }
032:
033:            public Class getType() {
034:                if (type == null) {
035:                    if (object == null)
036:                        return null;
037:                    else
038:                        return object.getClass();
039:                }
040:                return type;
041:            }
042:
043:            public void setType(Class t) {
044:                checkTypeConsistency(object, t);
045:                this .type = t;
046:            }
047:
048:            private void checkTypeConsistency(Object o, Class t) {
049:                if (o != null && t != null && !t.isAssignableFrom(o.getClass()))
050:                    throw new IllegalArgumentException(
051:                            "Object "
052:                                    + o
053:                                    + " and type "
054:                                    + t
055:                                    + " are inconsistent, the type must be a supertype of the object type");
056:            }
057:
058:            public String getRef() {
059:                return ref;
060:            }
061:
062:            public void setRef(String ref) {
063:                this .ref = ref;
064:            }
065:
066:            /**
067:             * Whether this is just a placeholder to access the object or a real object. 
068:             * @return
069:             */
070:            public boolean isProxy() {
071:                return this .object == null && this .ref != null;
072:            }
073:
074:            /**
075:             * Whether this is a literal, in particular a string.
076:             * @return
077:             */
078:            public boolean isLiteral() {
079:                Class type = getType();
080:                if (this .object == null)
081:                    return false; // proxy
082:                else
083:                    return (type == String.class) || type.isPrimitive()
084:                            || java.lang.Number.class.isAssignableFrom(type)
085:                            || type == Boolean.class;
086:            }
087:
088:            public String toString() {
089:                StringBuffer b = new StringBuffer();
090:                if (isProxy())
091:                    b.append('[');
092:                b.append(isProxy() ? ref : object);
093:                if (isProxy())
094:                    b.append(']');
095:                return b.toString();
096:            }
097:
098:            public void accept(KnowledgeBaseVisitor visitor) {
099:                visitor.visit(this );
100:                visitor.endVisit(this );
101:            }
102:
103:            // return a Java literal prepresenting this object, or null if this isn't possible
104:            public String getLiteral() {
105:                if (object != null) {
106:                    if (object instanceof  String)
107:                        return "\"" + object + "\"";
108:                    else if (object instanceof  Number
109:                            || object instanceof  Boolean
110:                            || object.getClass().isPrimitive())
111:                        return String.valueOf(object);
112:                }
113:                return null;
114:            }
115:
116:            @Override
117:            public int hashCode() {
118:                final int PRIME = 31;
119:                int result = 1;
120:                result = PRIME * result
121:                        + ((object == null) ? 0 : object.hashCode());
122:                result = PRIME * result + ((ref == null) ? 0 : ref.hashCode());
123:                result = PRIME * result
124:                        + ((type == null) ? 0 : type.hashCode());
125:                return result;
126:            }
127:
128:            @Override
129:            public boolean equals(Object obj) {
130:                if (this  == obj)
131:                    return true;
132:                if (obj == null)
133:                    return false;
134:                if (getClass() != obj.getClass())
135:                    return false;
136:                final Constant other = (Constant) obj;
137:                if (object == null) {
138:                    if (other.object != null)
139:                        return false;
140:                } else if (!object.equals(other.object))
141:                    return false;
142:                if (ref == null) {
143:                    if (other.ref != null)
144:                        return false;
145:                } else if (!ref.equals(other.ref))
146:                    return false;
147:                if (type == null) {
148:                    if (other.type != null)
149:                        return false;
150:                } else if (!type.equals(other.type))
151:                    return false;
152:                return true;
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.