Source Code Cross Referenced for DOMUtilities.java in  » ESB » open-esb » com » sun » jbi » wsdl2 » impl » 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 » ESB » open esb » com.sun.jbi.wsdl2.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)DOMUtilities.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.wsdl2.impl;
030:
031:        import com.sun.jbi.wsdl2.WsdlException;
032:
033:        import javax.xml.namespace.QName;
034:        import javax.xml.parsers.DocumentBuilder;
035:        import javax.xml.parsers.DocumentBuilderFactory;
036:
037:        import org.w3c.dom.Attr;
038:        import org.w3c.dom.Document;
039:        import org.w3c.dom.Element;
040:        import org.w3c.dom.Node;
041:
042:        import org.xml.sax.InputSource;
043:
044:        /**
045:         * This class contains a set of utilities for dealing with DOM trees.
046:         * 
047:         * @author Sun Microsystems, Inc.
048:         */
049:        class DOMUtilities {
050:            /**
051:             * Resolve the given attribute value, which is assumed to contain a prefixed 
052:             * name value into a proper QName.
053:             * 
054:             * @param attr        Attribute containing the prefixed name value
055:             *                    (e.g., "foo:bar") to be resolved.
056:             * @param documentURI The URI of the containing document.
057:             * @return The qualified name for the attribute value; null if it cannot be 
058:             *         resolved.
059:             * @exception WsdlException ILLEGAL_QNAME_ATTR_VALUE when the QName value in 
060:             *                          the attribute is illegal.
061:             */
062:            public static QName resolveNamespace(Attr attr, String documentURI)
063:                    throws WsdlException {
064:                QName result = null;
065:
066:                if (attr != null) {
067:                    Element element = attr.getOwnerElement();
068:                    String value = attr.getValue();
069:
070:                    try {
071:                        result = resolveNamespace(value, element, documentURI);
072:                    } catch (WsdlException ex) {
073:                        throw new WsdlException(
074:                                "Illegal qualified name {0} in value of attribute {2} in "
075:                                        + "document {1}", new Object[] { value,
076:                                        documentURI, attr.getName() });
077:                    }
078:                }
079:
080:                return result;
081:            }
082:
083:            /**
084:             * Resolve the given attribute value, which is assumed to contain a prefixed 
085:             * name value into a proper QName. The context for the namespace is the
086:             * parent element given.
087:             * 
088:             * @param value       The attribute value to resolve to a QName.
089:             * @param element     The parent element to the attribute value given.
090:             * @param documentURI The URI of the containing document.
091:             * @return The qualified name for the attribute value; null if it cannot be 
092:             *         resolved.
093:             * @exception WsdlException ILLEGAL_QNAME_VALUE when the QName value in 
094:             *                          the attribute is illegal.
095:             */
096:            public static QName resolveNamespace(String value, Element element,
097:                    String documentURI) throws WsdlException {
098:                QName result = null;
099:
100:                if (value != null) {
101:                    int valueLength = value.length();
102:                    int colonIndex = value.indexOf(':');
103:                    String targetNsDecl;
104:
105:                    if (colonIndex > 0 && colonIndex < valueLength - 1) {
106:                        targetNsDecl = "xmlns:"
107:                                + value.substring(0, colonIndex);
108:                    } else if (colonIndex < 0 && valueLength > 0) {
109:                        targetNsDecl = "xmlns";
110:                    } else {
111:                        throw new WsdlException(
112:                                "Illegal qualified name {0} in element {2} in document {1}",
113:                                new Object[] { value, documentURI,
114:                                        element.getNodeName() });
115:                    }
116:
117:                    Attr nsDeclAttr = findAttribute(element, targetNsDecl);
118:
119:                    if (nsDeclAttr != null) {
120:                        result = new QName(nsDeclAttr.getValue(), value
121:                                .substring(colonIndex + 1));
122:                    }
123:                }
124:
125:                return result;
126:            }
127:
128:            /**
129:             * Starting at the given element, search for the named attribute. The 
130:             * attribute is searched for from child to parent, up to (and including the 
131:             * root document element. <p>This search order conforms to the XML
132:             * name space scoping rules.<p>Note: this function uses recursion to search
133:             * up the parent edges of the node graph.
134:             * 
135:             * @param element The element to search from.
136:             * @param targetName The name of the attribute to search for.
137:             * @return The target attribute; null if not found.
138:             */
139:            private static Attr findAttribute(Element element, String targetName) {
140:                Attr result = null;
141:
142:                if (element != null) {
143:                    result = element.getAttributeNode(targetName);
144:
145:                    if (result == null) {
146:                        Node parent = element.getParentNode();
147:
148:                        if (parent != null
149:                                && parent.getNodeType() == Node.ELEMENT_NODE) {
150:                            result = findAttribute((Element) parent, targetName);
151:                        }
152:                    }
153:                }
154:
155:                return result;
156:            }
157:
158:            /**
159:             * Get the document from the given input source.
160:             * 
161:             * @param documentBaseURI The base URI for the document to be read.
162:             * @param inputSource     The input source for the document.
163:             * @return A DOM document representation of the well-formed XML document
164:             *         from the input stream.
165:             * @exception WsdlException if an XML parsing error occurs.
166:             */
167:            public static Document getDocument(String documentBaseURI,
168:                    InputSource inputSource) throws WsdlException {
169:                Document result;
170:                DocumentBuilderFactory factory = DocumentBuilderFactory
171:                        .newInstance();
172:
173:                factory.setNamespaceAware(true);
174:                factory.setValidating(false);
175:
176:                try {
177:                    DocumentBuilder builder = factory.newDocumentBuilder();
178:                    result = builder.parse(inputSource);
179:                } catch (Exception ex) {
180:                    throw new WsdlException("Problem parsing '{0}.\n"
181:                            + "\tReason = {0}\n", new Object[] {
182:                            documentBaseURI, ex.getMessage() });
183:                }
184:
185:                return result;
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.