Source Code Cross Referenced for JAXB.java in  » EJB-Server-resin-3.1.5 » jaxb » javax » xml » bind » 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 » EJB Server resin 3.1.5 » jaxb » javax.xml.bind 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003:         *
004:         * This file is part of Resin(R) Open Source
005:         *
006:         * Each copy or derived work must preserve the copyright notice and this
007:         * notice unmodified.
008:         *
009:         * Resin Open Source is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License as published by
011:         * the Free Software Foundation; either version 2 of the License, or
012:         * (at your option) any later version.
013:         *
014:         * Resin Open Source is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
018:         * details.
019:         *
020:         * You should have received a copy of the GNU General Public License
021:         * along with Resin Open Source; if not, write to the
022:         *
023:         *   Free Software Foundation, Inc.
024:         *   59 Temple Place, Suite 330
025:         *   Boston, MA 02111-1307  USA
026:         *
027:         * @author Scott Ferguson
028:         */
029:
030:        package javax.xml.bind;
031:
032:        import java.util.*;
033:        import java.io.*;
034:        import java.net.*;
035:        import java.lang.ref.*;
036:
037:        import javax.xml.transform.*;
038:        import javax.xml.transform.stream.*;
039:
040:        public final class JAXB {
041:            private static WeakHashMap<Class, SoftReference<JAXBContext>> _contextMap = new WeakHashMap<Class, SoftReference<JAXBContext>>();
042:
043:            public static void marshal(Object obj, File xml) {
044:                try {
045:                    getContext(obj).createMarshaller().marshal(obj, xml);
046:                } catch (RuntimeException e) {
047:                    throw e;
048:                } catch (Exception e) {
049:                    throw new DataBindingException(e);
050:                }
051:            }
052:
053:            public static void marshal(Object obj, URL xml) {
054:                try {
055:                    URLConnection conn = xml.openConnection();
056:                    conn.setDoInput(false);
057:                    conn.setDoOutput(false);
058:                    conn.connect();
059:
060:                    OutputStream os = conn.getOutputStream();
061:                    try {
062:                        StreamResult result = new StreamResult(os);
063:
064:                        marshal(obj, result);
065:                    } finally {
066:                        os.close();
067:                    }
068:                } catch (RuntimeException e) {
069:                    throw e;
070:                } catch (Exception e) {
071:                    throw new DataBindingException(e);
072:                }
073:            }
074:
075:            public static void marshal(Object obj, URI xml) {
076:                try {
077:                    marshal(obj, xml.toURL());
078:                } catch (RuntimeException e) {
079:                    throw e;
080:                } catch (Exception e) {
081:                    throw new DataBindingException(e);
082:                }
083:            }
084:
085:            public static void marshal(Object obj, String xml) {
086:                try {
087:                    StreamResult result = new StreamResult(xml);
088:
089:                    getContext(obj).createMarshaller().marshal(obj, result);
090:                } catch (RuntimeException e) {
091:                    throw e;
092:                } catch (Exception e) {
093:                    throw new DataBindingException(e);
094:                }
095:            }
096:
097:            public static void marshal(Object obj, OutputStream xml) {
098:                try {
099:                    getContext(obj).createMarshaller().marshal(obj, xml);
100:                } catch (RuntimeException e) {
101:                    throw e;
102:                } catch (Exception e) {
103:                    throw new DataBindingException(e);
104:                }
105:            }
106:
107:            public static void marshal(Object obj, Writer xml) {
108:                try {
109:                    getContext(obj).createMarshaller().marshal(obj, xml);
110:                } catch (RuntimeException e) {
111:                    throw e;
112:                } catch (Exception e) {
113:                    throw new DataBindingException(e);
114:                }
115:            }
116:
117:            public static void marshal(Object obj, Result xml) {
118:                try {
119:                    getContext(obj).createMarshaller().marshal(obj, xml);
120:                } catch (RuntimeException e) {
121:                    throw e;
122:                } catch (Exception e) {
123:                    throw new DataBindingException(e);
124:                }
125:            }
126:
127:            public static <T> T unmarshal(File xml, Class<T> type) {
128:                try {
129:                    return (T) getContext(type).createUnmarshaller().unmarshal(
130:                            xml);
131:                } catch (RuntimeException e) {
132:                    throw e;
133:                } catch (Exception e) {
134:                    throw new DataBindingException(e);
135:                }
136:            }
137:
138:            public static <T> T unmarshal(URL url, Class<T> type) {
139:                try {
140:                    return (T) getContext(type).createUnmarshaller().unmarshal(
141:                            url);
142:                } catch (RuntimeException e) {
143:                    throw e;
144:                } catch (Exception e) {
145:                    throw new DataBindingException(e);
146:                }
147:            }
148:
149:            public static <T> T unmarshal(URI uri, Class<T> type) {
150:                try {
151:                    return unmarshal(uri.toURL(), type);
152:                } catch (RuntimeException e) {
153:                    throw e;
154:                } catch (Exception e) {
155:                    throw new DataBindingException(e);
156:                }
157:            }
158:
159:            public static <T> T unmarshal(String xml, Class<T> type) {
160:                try {
161:                    StreamSource source = new StreamSource(xml);
162:
163:                    return (T) getContext(type).createUnmarshaller().unmarshal(
164:                            source);
165:                } catch (RuntimeException e) {
166:                    throw e;
167:                } catch (Exception e) {
168:                    throw new DataBindingException(e);
169:                }
170:            }
171:
172:            public static <T> T unmarshal(InputStream xml, Class<T> type) {
173:                try {
174:                    return (T) getContext(type).createUnmarshaller().unmarshal(
175:                            xml);
176:                } catch (RuntimeException e) {
177:                    throw e;
178:                } catch (Exception e) {
179:                    throw new DataBindingException(e);
180:                }
181:            }
182:
183:            public static <T> T unmarshal(Reader xml, Class<T> type) {
184:                try {
185:                    return (T) getContext(type).createUnmarshaller().unmarshal(
186:                            xml);
187:                } catch (RuntimeException e) {
188:                    throw e;
189:                } catch (Exception e) {
190:                    throw new DataBindingException(e);
191:                }
192:            }
193:
194:            public static <T> T unmarshal(Source xml, Class<T> type) {
195:                try {
196:                    return (T) getContext(type).createUnmarshaller().unmarshal(
197:                            xml);
198:                } catch (RuntimeException e) {
199:                    throw e;
200:                } catch (Exception e) {
201:                    throw new DataBindingException(e);
202:                }
203:            }
204:
205:            private static JAXBContext getContext(Object obj)
206:                    throws JAXBException {
207:                if (obj instanceof  JAXBElement) {
208:                    JAXBElement elt = (JAXBElement) obj;
209:
210:                    return getContext(elt.getDeclaredType());
211:                } else
212:                    return getContext(obj.getClass());
213:            }
214:
215:            private static JAXBContext getContext(Class cl)
216:                    throws JAXBException {
217:                SoftReference<JAXBContext> ref = _contextMap.get(cl);
218:
219:                JAXBContext context = null;
220:
221:                if (ref != null)
222:                    context = ref.get();
223:
224:                if (context == null) {
225:                    context = JAXBContext.newInstance(cl);
226:
227:                    _contextMap
228:                            .put(cl, new SoftReference<JAXBContext>(context));
229:                }
230:
231:                return context;
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.