Source Code Cross Referenced for JAXBResult.java in  » 6.0-JDK-Core » xml » javax » xml » bind » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » xml » javax.xml.bind.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025        package javax.xml.bind.util;
026
027        import javax.xml.bind.JAXBContext;
028        import javax.xml.bind.JAXBException;
029        import javax.xml.bind.Unmarshaller;
030        import javax.xml.bind.UnmarshallerHandler;
031        import javax.xml.transform.sax.SAXResult;
032
033        /**
034         * JAXP {@link javax.xml.transform.Result} implementation
035         * that unmarshals a JAXB object.
036         * 
037         * <p>
038         * This utility class is useful to combine JAXB with
039         * other Java/XML technologies.
040         * 
041         * <p>
042         * The following example shows how to use JAXB to unmarshal a document
043         * resulting from an XSLT transformation.
044         * 
045         * <blockquote>
046         *    <pre>
047         *       JAXBResult result = new JAXBResult(
048         *         JAXBContext.newInstance("org.acme.foo") );
049         *       
050         *       // set up XSLT transformation
051         *       TransformerFactory tf = TransformerFactory.newInstance();
052         *       Transformer t = tf.newTransformer(new StreamSource("test.xsl"));
053         *       
054         *       // run transformation
055         *       t.transform(new StreamSource("document.xml"),result);
056         * 
057         *       // obtain the unmarshalled content tree
058         *       Object o = result.getResult();
059         *    </pre>
060         * </blockquote>
061         * 
062         * <p>
063         * The fact that JAXBResult derives from SAXResult is an implementation
064         * detail. Thus in general applications are strongly discouraged from
065         * accessing methods defined on SAXResult.
066         * 
067         * <p>
068         * In particular it shall never attempt to call the setHandler, 
069         * setLexicalHandler, and setSystemId methods.
070         * 
071         * @author
072         * 	Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
073         */
074        public class JAXBResult extends SAXResult {
075
076            /**
077             * Creates a new instance that uses the specified
078             * JAXBContext to unmarshal.
079             * 
080             * @param context The JAXBContext that will be used to create the
081             * necessary Unmarshaller.  This parameter must not be null.
082             * @exception JAXBException if an error is encountered while creating the
083             * JAXBResult or if the context parameter is null.
084             */
085            public JAXBResult(JAXBContext context) throws JAXBException {
086                this ((context == null) ? assertionFailed() : context
087                        .createUnmarshaller());
088            }
089
090            /**
091             * Creates a new instance that uses the specified
092             * Unmarshaller to unmarshal an object.
093             * 
094             * <p>
095             * This JAXBResult object will use the specified Unmarshaller
096             * instance. It is the caller's responsibility not to use the
097             * same Unmarshaller for other purposes while it is being
098             * used by this object.
099             * 
100             * <p>
101             * The primary purpose of this method is to allow the client
102             * to configure Unmarshaller. Unless you know what you are doing,
103             * it's easier and safer to pass a JAXBContext.
104             * 
105             * @param _unmarshaller the unmarshaller.  This parameter must not be null.
106             * @throws JAXBException if an error is encountered while creating the
107             * JAXBResult or the Unmarshaller parameter is null.
108             */
109            public JAXBResult(Unmarshaller _unmarshaller) throws JAXBException {
110                if (_unmarshaller == null)
111                    throw new JAXBException(Messages
112                            .format(Messages.RESULT_NULL_UNMARSHALLER));
113
114                this .unmarshallerHandler = _unmarshaller
115                        .getUnmarshallerHandler();
116
117                super .setHandler(unmarshallerHandler);
118            }
119
120            /**
121             * Unmarshaller that will be used to unmarshal
122             * the input documents.
123             */
124            private final UnmarshallerHandler unmarshallerHandler;
125
126            /**
127             * Gets the unmarshalled object created by the transformation.
128             * 
129             * @return
130             *      Always return a non-null object.
131             * 
132             * @exception IllegalStateException
133             * 	if this method is called before an object is unmarshalled.
134             * 
135             * @exception JAXBException
136             *      if there is any unmarshalling error.
137             *      Note that the implementation is allowed to throw SAXException
138             *      during the parsing when it finds an error.
139             */
140            public Object getResult() throws JAXBException {
141                return unmarshallerHandler.getResult();
142            }
143
144            /**
145             * Hook to throw exception from the middle of a contructor chained call
146             * to this
147             */
148            private static Unmarshaller assertionFailed() throws JAXBException {
149                throw new JAXBException(Messages
150                        .format(Messages.RESULT_NULL_CONTEXT));
151            }
152        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.