Source Code Cross Referenced for XMLChangeEventConverter.java in  » Testing » jacareto » jacareto » convert » xml » 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 » Testing » jacareto » jacareto.convert.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.convert.xml;
025:
026:        import jacareto.record.ChangeEventRecordable;
027:        import jacareto.struct.StructureElement;
028:        import jacareto.system.Environment;
029:        import jacareto.toolkit.UUIDGen;
030:
031:        import org.jdom.Element;
032:
033:        /**
034:         * A converter which is able to convert a {@link jacareto.record.ChangeEventRecordable} to a xml
035:         * element, and vice versa.
036:         *
037:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
038:         * @version 1.00
039:         */
040:        public class XMLChangeEventConverter extends XMLEventObjectConverter {
041:            /**
042:             * Creates a new converter.
043:             *
044:             * @param env the environment
045:             */
046:            public XMLChangeEventConverter(Environment env) {
047:                super (env);
048:            }
049:
050:            /**
051:             * Returns whether this converter is able to transform the specified structure element to an
052:             * other representation. This converter is responsible for the given structure element if it
053:             * is of type {@link jacareto.record.ChangeEventRecordable}.
054:             *
055:             * @param element the structure element
056:             *
057:             * @return <code>true</code> if this converter is responsible for this structure element;
058:             *         otherwise <code>false</code>.
059:             */
060:            public boolean handlesElement(StructureElement element) {
061:                return (element != null)
062:                        && (element instanceof  ChangeEventRecordable);
063:            }
064:
065:            /**
066:             * Converts the specified element to an other representation, if this converter is responsible
067:             * for it. For responsibility see {@link #handlesElement(StructureElement)}.
068:             *
069:             * @param element the structure element to convert
070:             *
071:             * @return the other representation
072:             */
073:            public Object convertElement(StructureElement element) {
074:                ChangeEventRecordable ceRecordable = (ChangeEventRecordable) element;
075:                Element result = (Element) super .convertElement(element);
076:
077:                result.setName("ChangeEvent");
078:                result.setAttribute("additionalInformation", ceRecordable
079:                        .getAdditionalInformation());
080:
081:                return result;
082:            }
083:
084:            /**
085:             * Returns whether this converter is able to transform the specified other representation to a
086:             * structure element. This converter is responsible if the other representation is of type
087:             * <code>jdom.org.Element</code> and the name of the xml element is &quot;ChangeEvent&quot;
088:             *
089:             * @param other the other representation
090:             *
091:             * @return <code>true</code> if this converter is responsible for this other representation;
092:             *         otherwise <code>false</code>.
093:             */
094:            public boolean handlesOther(Object other) {
095:                try {
096:                    Element e = (Element) other;
097:
098:                    return e.getName().equals("ChangeEvent");
099:                } catch (Throwable t) {
100:                    return false;
101:                }
102:            }
103:
104:            /**
105:             * Converts the specified other representation to a structure element, if this converter is
106:             * responsible for it (reverses {@link #convertElement(StructureElement)}). For responsibility
107:             * see {@link #handlesOther(Object)}.
108:             *
109:             * @param other the other representation to convert
110:             *
111:             * @return the key event element
112:             */
113:            public StructureElement convertOther(Object other) {
114:                Element element = (Element) other;
115:
116:                String sourceName = element.getAttributeValue("source");
117:                String sourceClass = element.getAttributeValue("class");
118:
119:                if (sourceClass == null) {
120:                    sourceClass = "";
121:                }
122:
123:                // workaround because of the changes relativeTime -> duration
124:                String duration;
125:
126:                if ((duration = element.getAttributeValue("duration")) == null) {
127:                    duration = element.getAttributeValue("relativeTime");
128:                }
129:
130:                String procTime = element.getAttributeValue("procTime");
131:
132:                long durationTime = Long.parseLong(duration);
133:                long procTimeTime = 0;
134:
135:                if (procTime != null) {
136:                    procTimeTime = Long.parseLong(procTime);
137:                }
138:
139:                String additionalInformation = element
140:                        .getAttributeValue("additionalInformation");
141:
142:                if (additionalInformation == null) {
143:                    additionalInformation = "";
144:                }
145:
146:                ChangeEventRecordable returnValue = new ChangeEventRecordable(
147:                        env, sourceName, sourceClass, durationTime,
148:                        procTimeTime, additionalInformation);
149:
150:                String uuidString = element.getAttributeValue("uuid");
151:
152:                if (uuidString == null) {
153:                    returnValue.setUUIDString(UUIDGen.getInstance()
154:                            .generateUUID());
155:                } else {
156:                    returnValue.setUUIDString(uuidString);
157:                }
158:
159:                return returnValue;
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.