Source Code Cross Referenced for StartElementEvent.java in  » 6.0-JDK-Modules » sjsxp » com » sun » xml » stream » events » 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 » 6.0 JDK Modules » sjsxp » com.sun.xml.stream.events 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: StartElementEvent.java,v 1.2 2006/04/01 06:01:35 jeffsuttor Exp $
003:         */
004:
005:        /*
006:         * The contents of this file are subject to the terms
007:         * of the Common Development and Distribution License
008:         * (the License).  You may not use this file except in
009:         * compliance with the License.
010:         * 
011:         * You can obtain a copy of the license at
012:         * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013:         * See the License for the specific language governing
014:         * permissions and limitations under the License.
015:         * 
016:         * When distributing Covered Code, include this CDDL
017:         * Header Notice in each file and include the License file
018:         * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019:         * If applicable, add the following below the CDDL Header,
020:         * with the fields enclosed by brackets [] replaced by
021:         * you own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         * 
024:         * [Name of File] [ver.__] [Date]
025:         * 
026:         * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027:         */
028:
029:        package com.sun.xml.stream.events;
030:
031:        import java.util.List;
032:        import java.util.Map;
033:        import java.util.HashMap;
034:        import java.util.Iterator;
035:        import java.util.ArrayList;
036:        import java.util.Collection;
037:
038:        import javax.xml.namespace.QName;
039:        import javax.xml.stream.events.StartElement;
040:        import javax.xml.stream.events.Attribute;
041:        import javax.xml.namespace.NamespaceContext;
042:        import java.io.Writer;
043:        import com.sun.xml.stream.util.ReadOnlyIterator;
044:        import javax.xml.stream.XMLStreamConstants;
045:        import javax.xml.stream.events.Namespace;
046:
047:        /** Implementation of StartElementEvent.
048:         *
049:         * @author Neeraj Bajaj Sun Microsystems,Inc.
050:         * @author K.Venugopal Sun Microsystems,Inc.
051:         */
052:
053:        public class StartElementEvent extends DummyEvent implements 
054:                StartElement {
055:
056:            private Map fAttributes;
057:            private List fNamespaces;
058:            private NamespaceContext fNamespaceContext = null;
059:            private QName fQName;
060:
061:            public StartElementEvent(String prefix, String uri, String localpart) {
062:                this (new QName(uri, localpart, prefix));
063:            }
064:
065:            public StartElementEvent(QName qname) {
066:                fQName = qname;
067:                init();
068:            }
069:
070:            public StartElementEvent(StartElement startelement) {
071:                this (startelement.getName());
072:                addAttributes(startelement.getAttributes());
073:                addNamespaceAttributes(startelement.getNamespaces());
074:            }
075:
076:            protected void init() {
077:                setEventType(XMLStreamConstants.START_ELEMENT);
078:                fAttributes = new HashMap();
079:                fNamespaces = new ArrayList();
080:            }
081:
082:            public QName getName() {
083:                return fQName;
084:            }
085:
086:            public void setName(QName qname) {
087:                this .fQName = qname;
088:            }
089:
090:            public Iterator getAttributes() {
091:                if (fAttributes != null) {
092:                    Collection coll = fAttributes.values();
093:                    return new ReadOnlyIterator(coll.iterator());
094:                }
095:                return new ReadOnlyIterator();
096:            }
097:
098:            public Iterator getNamespaces() {
099:                if (fNamespaces != null) {
100:                    return new ReadOnlyIterator(fNamespaces.iterator());
101:                }
102:                return new ReadOnlyIterator();
103:            }
104:
105:            public Attribute getAttributeByName(QName qname) {
106:                if (qname == null)
107:                    return null;
108:                return (Attribute) fAttributes.get(qname);
109:            }
110:
111:            public String getNamespace() {
112:                return fQName.getNamespaceURI();
113:            }
114:
115:            public String getNamespaceURI(String prefix) {
116:                //check that URI was supplied when creating this startElement event and prefix matches 
117:                if (getNamespace() != null && fQName.getPrefix().equals(prefix))
118:                    return getNamespace();
119:                //else check the namespace context
120:                if (fNamespaceContext != null)
121:                    return fNamespaceContext.getNamespaceURI(prefix);
122:                return null;
123:            }
124:
125:            public String toString() {
126:                String s = "<" + nameAsString();
127:
128:                if (fAttributes != null) {
129:                    Iterator it = this .getAttributes();
130:                    Attribute attr = null;
131:                    while (it.hasNext()) {
132:                        attr = (Attribute) it.next();
133:                        s = s + " " + attr.toString();
134:                    }
135:                }
136:
137:                if (fNamespaces != null) {
138:                    Iterator it = fNamespaces.iterator();
139:                    Namespace attr = null;
140:                    while (it.hasNext()) {
141:                        attr = (Namespace) it.next();
142:                        s = s + " " + attr.toString();
143:                    }
144:                }
145:                s = s + ">";
146:                return s;
147:            }
148:
149:            /** Return this event as String
150:             * @return String Event returned as string.
151:             */
152:            public String nameAsString() {
153:                if ("".equals(fQName.getNamespaceURI()))
154:                    return fQName.getLocalPart();
155:                if (fQName.getPrefix() != null)
156:                    return "['" + fQName.getNamespaceURI() + "']:"
157:                            + fQName.getPrefix() + ":" + fQName.getLocalPart();
158:                else
159:                    return "['" + fQName.getNamespaceURI() + "']:"
160:                            + fQName.getLocalPart();
161:            }
162:
163:            /** Gets a read-only namespace context. If no context is
164:             * available this method will return an empty namespace context.
165:             * The NamespaceContext contains information about all namespaces
166:             * in scope for this StartElement.
167:             *
168:             * @return the current namespace context
169:             */
170:            public NamespaceContext getNamespaceContext() {
171:                return fNamespaceContext;
172:            }
173:
174:            public void setNamespaceContext(NamespaceContext nc) {
175:                fNamespaceContext = nc;
176:            }
177:
178:            /** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
179:             * No indentation or whitespace should be outputted.
180:             *
181:             * Any user defined event type SHALL have this method
182:             * called when being written to on an output stream.
183:             * Built in Event types MUST implement this method,
184:             * but implementations MAY choose not call these methods
185:             * for optimizations reasons when writing out built in
186:             * Events to an output stream.
187:             * The output generated MUST be equivalent in terms of the
188:             * infoset expressed.
189:             *
190:             * @param writer The writer that will output the data
191:             * @throws XMLStreamException if there is a fatal error writing the event
192:             */
193:            public void writeAsEncodedUnicode(Writer writer)
194:                    throws javax.xml.stream.XMLStreamException {
195:            }
196:
197:            void addAttribute(Attribute attr) {
198:                if (attr.isNamespace()) {
199:                    fNamespaces.add(attr);
200:                } else {
201:                    fAttributes.put(attr.getName(), attr);
202:                }
203:            }
204:
205:            void addAttributes(Iterator attrs) {
206:                if (attrs == null)
207:                    return;
208:                while (attrs.hasNext()) {
209:                    Attribute attr = (Attribute) attrs.next();
210:                    fAttributes.put(attr.getName(), attr);
211:                }
212:            }
213:
214:            void addNamespaceAttribute(Namespace attr) {
215:                if (attr == null)
216:                    return;
217:                fNamespaces.add(attr);
218:            }
219:
220:            void addNamespaceAttributes(Iterator attrs) {
221:                if (attrs == null)
222:                    return;
223:                while (attrs.hasNext()) {
224:                    Namespace attr = (Namespace) attrs.next();
225:                    fNamespaces.add(attr);
226:                }
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.