Source Code Cross Referenced for XSurvey.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.io.Reader;
004:        import java.util.Enumeration;
005:        import java.util.Vector;
006:
007:        import net.xoetrope.xml.XmlElement;
008:        import net.xoetrope.xml.XmlSource;
009:        import net.xoetrope.xui.XProject;
010:        import net.xoetrope.xui.XProjectManager;
011:        import net.xoetrope.xui.data.XDataBinding;
012:        import net.xoetrope.xui.data.XModel;
013:
014:        /**
015:         * An XSurvey contains the definition of a survey, the questions
016:         * and the responses. The definitions are read from file and passed on to the
017:         * question manager for rotation. The survey definition is largely independant
018:         * of how the surveys are presented or rendered</p>
019:         *
020:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
021:         * the GNU Public License (GPL), please see license.txt for more details. If
022:         * you make commercial use of this software you must purchase a commercial
023:         * license from Xoetrope.</p>
024:         * <p> $Revision: 1.9 $</p>
025:         */
026:        public class XSurvey {
027:            private String name;
028:
029:            private Vector questionGroups;
030:            private Vector bindings;
031:            private XResponseSet responseSet;
032:            private boolean hasQuestions = false;
033:
034:            /**
035:             * The owning project / the context for this object
036:             */
037:            XProject currentProject = XProjectManager.getCurrentProject();
038:
039:            /**
040:             * Creates a new survey
041:             * @param n the name of the survey
042:             */
043:            public XSurvey(String n) {
044:                name = n;
045:                questionGroups = new Vector();
046:                bindings = new Vector();
047:                responseSet = new XResponseSet(name);
048:            }
049:
050:            /**
051:             * Gets the survey name
052:             * @return the survey name
053:             */
054:            public String getName() {
055:                return name;
056:            }
057:
058:            /**
059:             * Reads the survey from the input stream
060:             * @param r the input stream reader
061:             */
062:            public void read(Reader r) {
063:                XmlElement ele = XmlSource.read(r);
064:                Vector v = ele.getChildren();
065:                if (v != null) {
066:                    int numGroups = v.size();
067:                    int scale = new Integer(ele.getAttribute("scale"))
068:                            .intValue();
069:                    XModel model = currentProject.getModel();
070:                    for (int i = 0; i < numGroups; i++) {
071:                        XmlElement xmlGroup = (XmlElement) v.elementAt(i);
072:                        char c = xmlGroup.getName().charAt(0);
073:                        if (c == 'G') {
074:                            //QuestionGroup currentGroup = new QuestionGroup( new Integer( xmlGroup.getAttribute( "id" )).intValue());
075:                            QuestionGroup currentGroup = new QuestionGroup(
076:                                    new Integer(xmlGroup.getAttribute("id "))
077:                                            .intValue(), "group");
078:                            Vector children = xmlGroup.getChildren();
079:                            int numQuestions = children.size();
080:                            for (int j = 0; j < numQuestions; j++) {
081:                                XmlElement xmlQuestion = (XmlElement) children
082:                                        .elementAt(j);
083:                                char cq = xmlQuestion.getName().charAt(0);
084:                                if (cq == 'Q') {
085:                                    Question currentQuestion = new Question(
086:                                            Integer.parseInt(xmlQuestion
087:                                                    .getAttribute("id")),
088:                                            currentGroup);
089:                                    Vector questionResponses = xmlQuestion
090:                                            .getChildren();
091:                                    int numResponses = questionResponses.size();
092:                                    currentQuestion.setSize(Math.max(
093:                                            numResponses, scale));
094:                                    for (int k = 0; k < numResponses; k++) {
095:                                        XmlElement xmlResponse = (XmlElement) questionResponses
096:                                                .elementAt(k);
097:                                        char cr = xmlResponse.getName().charAt(
098:                                                0);
099:                                        if (cr == 'R')
100:                                            currentQuestion
101:                                                    .addOption(
102:                                                            new Integer(
103:                                                                    xmlResponse
104:                                                                            .getAttribute("id"))
105:                                                                    .intValue(),
106:                                                            xmlResponse
107:                                                                    .getAttribute("A"));
108:                                    }
109:                                    currentGroup.addQuestion(currentQuestion);
110:                                }
111:                            }
112:                            questionGroups.add(currentGroup);
113:                        }
114:                    }
115:                }
116:            }
117:
118:            /**
119:             * Get the next question
120:             * @return the next question
121:             */
122:            /*
123:            public Question getNextQuestion()
124:            {
125:              try {
126:                
127:                return ((QuestionGroup)questionGroups.elementAt( 0 )).getNextQuestion();
128:              }
129:              catch ( ArrayIndexOutOfBoundsException aiobe ) {
130:                return null;
131:              }
132:            }
133:             */
134:
135:            public Question getNextQuestion() {
136:                return null;
137:            }
138:
139:            /**
140:             * Binding a question interface/representation to the survey
141:             * @param binding the survey data 
142:             */
143:            public void bindQuestion(XDataBinding binding) {
144:                bindings.addElement(binding);
145:            }
146:
147:            /**
148:             * Reset all questions
149:             */
150:            public void reset() {
151:                XModel csModel = ((XModel) currentProject.getModel().get(
152:                        "currentSurvey/question"));
153:
154:                // Push the bound data onto the model
155:                Enumeration enumeration = bindings.elements();
156:                while (enumeration.hasMoreElements())
157:                    ((XDataBinding) enumeration.nextElement()).set();
158:
159:                int numAnswers = csModel.getNumChildren();
160:                for (int i = 0; i < numAnswers; i++) {
161:                    XModel node = csModel.get(i);
162:                    int nv = new Integer(node.getId()).intValue();
163:                    if (!hasQuestions)
164:                        responseSet.addQuestion(nv);
165:                    responseSet.addResponse((String) node.get());
166:                    node.set("-1");
167:                }
168:
169:                hasQuestions = true;
170:                responseSet.closeSession();
171:
172:                // Pull the bound data from the model, they should all now be reset
173:                enumeration = bindings.elements();
174:                while (enumeration.hasMoreElements())
175:                    ((XDataBinding) enumeration.nextElement()).get();
176:            }
177:
178:            /**
179:             * Restart the session recording
180:             */
181:            public void restart() {
182:                hasQuestions = false;
183:                questionGroups = new Vector();
184:                responseSet = new XResponseSet(name);
185:            }
186:
187:            /**
188:             * Gets the current response set
189:             * @return the response set
190:             */
191:            public XResponseSet getResponses() {
192:                return responseSet;
193:            }
194:
195:            /**
196:             * Get the total number of questions in this survey
197:             * @return the number of questions in all groups
198:             */
199:            public int getNumQuestions() {
200:                int numQuestions = 0;
201:                int numGroups = questionGroups.size();
202:
203:                for (int i = 0; i < numGroups; i++) {
204:                    QuestionGroup currentGroup = (QuestionGroup) questionGroups
205:                            .elementAt(i);
206:                    numQuestions += currentGroup.getNumQuestions();
207:                }
208:
209:                return numQuestions;
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.