Source Code Cross Referenced for Loader.java in  » Net » Terracotta » com » tc » config » 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 » Net » Terracotta » com.tc.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.config;
006:
007:        import org.apache.xmlbeans.SchemaType;
008:        import org.apache.xmlbeans.XmlException;
009:        import org.apache.xmlbeans.XmlOptions;
010:
011:        import com.tc.config.schema.migrate.ConfigUpdate;
012:        import com.tc.config.schema.migrate.V1toV2;
013:        import com.tc.config.schema.migrate.V2toV3;
014:
015:        import java.io.ByteArrayInputStream;
016:        import java.io.File;
017:        import java.io.FileInputStream;
018:        import java.io.IOException;
019:        import java.io.InputStream;
020:        import java.net.URL;
021:
022:        /**
023:         * Responsible for creating a TcConfigDocument of the current version from any published configuration schema version.
024:         */
025:        public final class Loader {
026:
027:            private final ConfigUpdate[] converters;
028:
029:            public Loader() {
030:                // order newest to oldest -- don't ever hotswap converters
031:                converters = new ConfigUpdate[] { new V2toV3(), new V1toV2() };
032:            }
033:
034:            private com.terracottatech.config.TcConfigDocument convert(
035:                    InputStream in, XmlOptions xmlOptions) throws IOException,
036:                    XmlException {
037:                byte[] data = new byte[in.available()];
038:                in.read(data);
039:                in.close();
040:                ByteArrayInputStream ain = new ByteArrayInputStream(data);
041:                SchemaType type = com.terracottatech.config.TcConfigDocument.type;
042:                if (xmlOptions == null)
043:                    xmlOptions = new XmlOptions();
044:                xmlOptions.setDocumentType(type);
045:                try {
046:                    return com.terracottatech.config.TcConfigDocument.Factory
047:                            .parse(ain, xmlOptions);
048:                } catch (XmlException e) {
049:                    ain.reset();
050:                    return com.terracottatech.config.TcConfigDocument.Factory
051:                            .parse(updateConfig(ain, 0, xmlOptions), xmlOptions);
052:                }
053:            }
054:
055:            private synchronized InputStream updateConfig(InputStream in,
056:                    int index, XmlOptions xmlOptions) throws IOException,
057:                    XmlException {
058:                byte[] data = new byte[in.available()];
059:                in.read(data);
060:                in.close();
061:                ByteArrayInputStream ain = new ByteArrayInputStream(data);
062:                try {
063:                    return converters[index].convert(ain, xmlOptions);
064:                } catch (XmlException e) {
065:                    if (index == converters.length - 1)
066:                        throw e;
067:                    ain.reset();
068:                    return converters[index].convert(updateConfig(ain,
069:                            index + 1, xmlOptions), xmlOptions);
070:                }
071:            }
072:
073:            public com.terracottatech.config.TcConfigDocument parse(File file)
074:                    throws IOException, XmlException {
075:                return convert(new FileInputStream(file), null);
076:            }
077:
078:            public com.terracottatech.config.TcConfigDocument parse(File file,
079:                    XmlOptions xmlOptions) throws IOException, XmlException {
080:                return convert(new FileInputStream(file), xmlOptions);
081:            }
082:
083:            public com.terracottatech.config.TcConfigDocument parse(
084:                    String xmlText) throws IOException, XmlException {
085:                return convert(new ByteArrayInputStream(xmlText.getBytes()),
086:                        null);
087:            }
088:
089:            public com.terracottatech.config.TcConfigDocument parse(
090:                    String xmlText, XmlOptions xmlOptions) throws IOException,
091:                    XmlException {
092:                return convert(new ByteArrayInputStream(xmlText.getBytes()),
093:                        xmlOptions);
094:            }
095:
096:            public com.terracottatech.config.TcConfigDocument parse(
097:                    InputStream stream) throws IOException, XmlException {
098:                return convert(stream, null);
099:            }
100:
101:            public com.terracottatech.config.TcConfigDocument parse(
102:                    InputStream stream, XmlOptions xmlOptions)
103:                    throws IOException, XmlException {
104:                return convert(stream, xmlOptions);
105:            }
106:
107:            public com.terracottatech.config.TcConfigDocument parse(URL url)
108:                    throws IOException, XmlException {
109:                return convert(url.openStream(), null);
110:            }
111:
112:            public com.terracottatech.config.TcConfigDocument parse(URL url,
113:                    XmlOptions xmlOptions) throws IOException, XmlException {
114:                return convert(url.openStream(), xmlOptions);
115:            }
116:
117:            public boolean testIsOld(File file) throws IOException,
118:                    XmlException {
119:                return !testIsCurrent(file);
120:            }
121:
122:            public boolean testIsCurrent(File file) throws IOException,
123:                    XmlException {
124:                com.terracottatech.config.TcConfigDocument.Factory
125:                        .parse(new FileInputStream(file));
126:                return true;
127:            }
128:
129:            public void updateToCurrent(File file) throws IOException,
130:                    XmlException {
131:                XmlOptions options = null;
132:                synchronized (converters) {
133:                    options = converters[0].createDefaultXmlOptions();
134:                }
135:                com.terracottatech.config.TcConfigDocument doc = convert(
136:                        new FileInputStream(file), options);
137:                doc.save(file);
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.