Source Code Cross Referenced for XSAnnotationImpl.java in  » XML » xerces-2_9_1 » org » apache » xerces » impl » xs » 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 » XML » xerces 2_9_1 » org.apache.xerces.impl.xs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.xerces.impl.xs;
018:
019:        import org.apache.xerces.xs.XSAnnotation;
020:        import org.apache.xerces.xs.XSConstants;
021:        import org.apache.xerces.xs.XSNamespaceItem;
022:        import org.apache.xerces.dom.CoreDocumentImpl;
023:        import org.apache.xerces.parsers.SAXParser;
024:        import org.apache.xerces.parsers.DOMParser;
025:
026:        import org.xml.sax.ContentHandler;
027:        import org.xml.sax.SAXException;
028:        import org.xml.sax.InputSource;
029:        import org.w3c.dom.Node;
030:        import org.w3c.dom.Element;
031:        import org.w3c.dom.Document;
032:        import java.io.StringReader;
033:        import java.io.IOException;
034:
035:        /**
036:         * This is an implementation of the XSAnnotation schema component.
037:         * 
038:         * @xerces.internal 
039:         * 
040:         * @version $Id: XSAnnotationImpl.java 446734 2006-09-15 20:51:23Z mrglavas $
041:         */
042:        public class XSAnnotationImpl implements  XSAnnotation {
043:
044:            // Data
045:
046:            // the content of the annotation node, including all children, along
047:            // with any non-schema attributes from its parent
048:            private String fData = null;
049:
050:            // the grammar which owns this annotation; we get parsers
051:            // from here when we need them
052:            private SchemaGrammar fGrammar = null;
053:
054:            // constructors
055:            public XSAnnotationImpl(String contents, SchemaGrammar grammar) {
056:                fData = contents;
057:                fGrammar = grammar;
058:            }
059:
060:            /**
061:             *  Write contents of the annotation to the specified DOM object. If the 
062:             * specified <code>target</code> object is a DOM in-scope namespace 
063:             * declarations for <code>annotation</code> element are added as 
064:             * attributes nodes of the serialized <code>annotation</code>, otherwise 
065:             * the corresponding events for all in-scope namespace declaration are 
066:             * sent via specified document handler. 
067:             * @param target  A target pointer to the annotation target object, i.e. 
068:             *   <code>org.w3c.dom.Document</code>, 
069:             *   <code>org.xml.sax.ContentHandler</code>. 
070:             * @param targetType  A target type. 
071:             * @return If the <code>target</code> is recognized type and supported by 
072:             *   this implementation return true, otherwise return false. 
073:             */
074:            public boolean writeAnnotation(Object target, short targetType) {
075:                if (targetType == XSAnnotation.W3C_DOM_ELEMENT
076:                        || targetType == XSAnnotation.W3C_DOM_DOCUMENT) {
077:                    writeToDOM((Node) target, targetType);
078:                    return true;
079:                } else if (targetType == SAX_CONTENTHANDLER) {
080:                    writeToSAX((ContentHandler) target);
081:                    return true;
082:                }
083:                return false;
084:            }
085:
086:            /**
087:             * A text representation of annotation.
088:             */
089:            public String getAnnotationString() {
090:                return fData;
091:            }
092:
093:            // XSObject methods
094:
095:            /**
096:             *  The <code>type</code> of this object, i.e. 
097:             * <code>ELEMENT_DECLARATION</code>. 
098:             */
099:            public short getType() {
100:                return XSConstants.ANNOTATION;
101:            }
102:
103:            /**
104:             * The name of type <code>NCName</code> of this declaration as defined in 
105:             * XML Namespaces.
106:             */
107:            public String getName() {
108:                return null;
109:            }
110:
111:            /**
112:             *  The [target namespace] of this object, or <code>null</code> if it is 
113:             * unspecified. 
114:             */
115:            public String getNamespace() {
116:                return null;
117:            }
118:
119:            /**
120:             * A namespace schema information item corresponding to the target 
121:             * namespace of the component, if it's globally declared; or null 
122:             * otherwise.
123:             */
124:            public XSNamespaceItem getNamespaceItem() {
125:                return null;
126:            }
127:
128:            // private methods
129:            private synchronized void writeToSAX(ContentHandler handler) {
130:                // nothing must go wrong with this parse...
131:                SAXParser parser = fGrammar.getSAXParser();
132:                StringReader aReader = new StringReader(fData);
133:                InputSource aSource = new InputSource(aReader);
134:                parser.setContentHandler(handler);
135:                try {
136:                    parser.parse(aSource);
137:                } catch (SAXException e) {
138:                    // this should never happen!
139:                    // REVISIT:  what to do with this?; should really not
140:                    // eat it...
141:                } catch (IOException i) {
142:                    // ditto with above
143:                }
144:            }
145:
146:            // this creates the new Annotation element as the first child
147:            // of the Node
148:            private synchronized void writeToDOM(Node target, short type) {
149:                Document futureOwner = (type == XSAnnotation.W3C_DOM_ELEMENT) ? target
150:                        .getOwnerDocument()
151:                        : (Document) target;
152:                DOMParser parser = fGrammar.getDOMParser();
153:                StringReader aReader = new StringReader(fData);
154:                InputSource aSource = new InputSource(aReader);
155:                try {
156:                    parser.parse(aSource);
157:                } catch (SAXException e) {
158:                    // this should never happen!
159:                    // REVISIT:  what to do with this?; should really not
160:                    // eat it...
161:                } catch (IOException i) {
162:                    // ditto with above
163:                }
164:                Document aDocument = parser.getDocument();
165:                parser.dropDocumentReferences();
166:                Element annotation = aDocument.getDocumentElement();
167:                Node newElem = null;
168:                if (futureOwner instanceof  CoreDocumentImpl) {
169:                    newElem = futureOwner.adoptNode(annotation);
170:                    // adoptNode will return null when the DOM implementations are not compatible.
171:                    if (newElem == null) {
172:                        newElem = futureOwner.importNode(annotation, true);
173:                    }
174:                } else {
175:                    newElem = futureOwner.importNode(annotation, true);
176:                }
177:                target.insertBefore(newElem, target.getFirstChild());
178:            }
179:
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.