Source Code Cross Referenced for DefaultRule.java in  » XML-UI » xui32 » com » xoetrope » survey » 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 » XML UI » xui32 » com.xoetrope.survey 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.survey;
002:
003:        import java.awt.event.ActionListener;
004:        import java.util.Vector;
005:        import java.util.Enumeration;
006:
007:        /**
008:         * DefaultRule is a set of conditions being used by the DefaultRuleEngine.
009:         *
010:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
011:         * the GNU Public License (GPL), please see license.txt for more details. If
012:         * you make commercial use of this software you must purchase a commercial
013:         * license from Xoetrope.</p>
014:         * <p> $Revision: 1.5 $</p>
015:         */
016:        public class DefaultRule {
017:            protected int id;
018:            protected String name;
019:            protected QuestionGroup group;
020:            protected QuestionGroup target;
021:            protected Vector conditions;
022:
023:            /**
024:             * Creates a new instance of the DefaultRule
025:             * @param i the if of the rule
026:             * @param g question group that this rule belongs to
027:             * @param n the name of the rule
028:             */
029:            public DefaultRule(int i, QuestionGroup g, String n) {
030:                this (i, g, null, n);
031:            }
032:
033:            /**
034:             * Creates a new instance of the default rule.
035:             * @param i the id of this rule
036:             * @param g question group that this rule belongs to
037:             * @param t question group that this rule leads to
038:             */
039:            public DefaultRule(int i, QuestionGroup g, QuestionGroup t, String n) {
040:                id = i;
041:                group = g;
042:                target = t;
043:                name = (n != null ? n : "rule " + id);
044:                conditions = new Vector();
045:            }
046:
047:            /**
048:             * Gets the name of this rule
049:             * @rule the name
050:             */
051:            public String getName() {
052:                return name;
053:            }
054:
055:            /**
056:             * Sets the name of this rule
057:             * @param n the new name of this rule
058:             */
059:            public void setName(String n) {
060:                name = n;
061:            }
062:
063:            /**
064:             * Gets the id of this rule
065:             * @return the id
066:             */
067:            public int getId() {
068:                return id;
069:            }
070:
071:            /**
072:             * Gets the question group that this rule belongs to
073:             * @return the question group.
074:             */
075:            public QuestionGroup getGroup() {
076:                return group;
077:            }
078:
079:            /**
080:             * Gets the question group that this rule leads to
081:             * @reutrn the question group
082:             */
083:            public QuestionGroup getTarget() {
084:                return target;
085:            }
086:
087:            /**
088:             * Sets the new question group that this
089:             * rule will lead to.
090:             * @param the new question group.
091:             */
092:            public void setTarget(QuestionGroup at) {
093:                target = at;
094:            }
095:
096:            /**
097:             * Sets the new id of this rule
098:             * @param i the new id
099:             */
100:            public void setId(int i) {
101:                id = i;
102:            }
103:
104:            /**
105:             * Gets the conditions being contained by this rule
106:             * @return Vector containing conditions
107:             */
108:            public Vector getConditions() {
109:                return conditions;
110:            }
111:
112:            /**
113:             * Gets the condition for the specified question.
114:             * @param question question whose condition is to
115:             * be obtained
116:             * @return condition for the specified question.
117:             */
118:            public Condition getCondition(Question question) {
119:                Condition condition = null;
120:                Enumeration enumConditions = conditions.elements();
121:                while (enumConditions.hasMoreElements() && (condition == null)) {
122:                    Condition c = (Condition) enumConditions.nextElement();
123:                    if (c.getQuestion().equals(question))
124:                        condition = c;
125:                }
126:                return condition;
127:            }
128:
129:            /**
130:             * Creates and sdds the new condition to this rule
131:             * @param question the question of the condition
132:             * which is to be added
133:             * @param option the option, the answer for which
134:             * is specified
135:             * @param answer answer for the option
136:             * @return the new condition
137:             */
138:            public Condition addCondition(Question question, Option option,
139:                    String answer) {
140:                Condition condition = getCondition(question);
141:                if (condition == null) {
142:                    condition = new Condition(question);
143:                    conditions.add(condition);
144:                }
145:                condition.addAnswer(option, answer);
146:                return condition;
147:            }
148:
149:            /**
150:             * Removes the specified conditon from this rule
151:             * @param condition the condition to be removed
152:             */
153:            public void removeCondtion(Condition condition) {
154:                conditions.remove(condition);
155:            }
156:
157:            /**
158:             * Removes all conditions of the speicifed question
159:             * @param questionId the id of the question whose
160:             * conditions will be removed
161:             */
162:            public void removeCondition(int questionId) {
163:                Enumeration enumeration = conditions.elements();
164:                while (enumeration.hasMoreElements()) {
165:                    Condition condition = (Condition) enumeration.nextElement();
166:                    if (condition.getQuestion().getId() == questionId)
167:                        conditions.remove(condition);
168:                }
169:            }
170:
171:            /**
172:             * Check whether specified users responses match the conditions
173:             * contained in this rule.
174:             * @param userResponses responses given by the user
175:             * @return id of the target questions group if the responses match, 
176:             * -1 otherwise     
177:             */
178:            public int checkResponses(Vector userResponses) {
179:                if (target == null)
180:                    return -1;
181:
182:                boolean rf = true;
183:                Enumeration enumResponses = conditions.elements();
184:                while (enumResponses.hasMoreElements() && rf) {
185:                    Condition response = (Condition) enumResponses
186:                            .nextElement();
187:                    rf = false;
188:                    Enumeration enumUserResponses = userResponses.elements();
189:                    while (enumUserResponses.hasMoreElements() && !rf) {
190:                        Condition userResponse = (Condition) enumUserResponses
191:                                .nextElement();
192:                        rf |= response.equals(userResponse);
193:                    }
194:                }
195:
196:                return (rf ? target.getId() : -1);
197:            }
198:
199:            public boolean equals(Object o) {
200:                if (!(o instanceof  DefaultRule))
201:                    return false;
202:                DefaultRule rule = (DefaultRule) o;
203:                return (id == rule.getId());
204:            }
205:
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.