Source Code Cross Referenced for DeferredEntityReferenceImpl.java in  » Web-Server » Rimfaxe-Web-Server » org » apache » xerces » dom » 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 » Web Server » Rimfaxe Web Server » org.apache.xerces.dom 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         *
005:         * Copyright (c) 1999 The Apache Software Foundation.  All rights 
006:         * reserved.
007:         *
008:         * Redistribution and use in source and binary forms, with or without
009:         * modification, are permitted provided that the following conditions
010:         * are met:
011:         *
012:         * 1. Redistributions of source code must retain the above copyright
013:         *    notice, this list of conditions and the following disclaimer. 
014:         *
015:         * 2. Redistributions in binary form must reproduce the above copyright
016:         *    notice, this list of conditions and the following disclaimer in
017:         *    the documentation and/or other materials provided with the
018:         *    distribution.
019:         *
020:         * 3. The end-user documentation included with the redistribution,
021:         *    if any, must include the following acknowledgment:  
022:         *       "This product includes software developed by the
023:         *        Apache Software Foundation (http://www.apache.org/)."
024:         *    Alternately, this acknowledgment may appear in the software itself,
025:         *    if and wherever such third-party acknowledgments normally appear.
026:         *
027:         * 4. The names "Xerces" and "Apache Software Foundation" must
028:         *    not be used to endorse or promote products derived from this
029:         *    software without prior written permission. For written 
030:         *    permission, please contact apache@apache.org.
031:         *
032:         * 5. Products derived from this software may not be called "Apache",
033:         *    nor may "Apache" appear in their name, without prior written
034:         *    permission of the Apache Software Foundation.
035:         *
036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047:         * SUCH DAMAGE.
048:         * ====================================================================
049:         *
050:         * This software consists of voluntary contributions made by many
051:         * individuals on behalf of the Apache Software Foundation and was
052:         * originally based on software copyright (c) 1999, International
053:         * Business Machines, Inc., http://www.apache.org.  For more
054:         * information on the Apache Software Foundation, please see
055:         * <http://www.apache.org/>.
056:         */
057:
058:        package org.apache.xerces.dom;
059:
060:        import org.w3c.dom.DocumentType;
061:        import org.w3c.dom.Entity;
062:        import org.w3c.dom.NamedNodeMap;
063:        import org.w3c.dom.Node;
064:
065:        /**
066:         * EntityReference models the XML &entityname; syntax, when used for
067:         * entities defined by the DOM. Entities hardcoded into XML, such as
068:         * character entities, should instead have been translated into text
069:         * by the code which generated the DOM tree.
070:         * <P>
071:         * An XML processor has the alternative of fully expanding Entities
072:         * into the normal document tree. If it does so, no EntityReference nodes
073:         * will appear.
074:         * <P>
075:         * Similarly, non-validating XML processors are not required to read
076:         * or process entity declarations made in the external subset or
077:         * declared in external parameter entities. Hence, some applications
078:         * may not make the replacement value available for Parsed Entities 
079:         * of these types.
080:         * <P>
081:         * EntityReference behaves as a read-only node, and the children of 
082:         * the EntityReference (which reflect those of the Entity, and should
083:         * also be read-only) give its replacement value, if any. They are 
084:         * supposed to automagically stay in synch if the DocumentType is 
085:         * updated with new values for the Entity.
086:         * <P>
087:         * The defined behavior makes efficient storage difficult for the DOM
088:         * implementor. We can't just look aside to the Entity's definition
089:         * in the DocumentType since those nodes have the wrong parent (unless
090:         * we can come up with a clever "imaginary parent" mechanism). We
091:         * must at least appear to clone those children... which raises the
092:         * issue of keeping the reference synchronized with its parent.
093:         * This leads me back to the "cached image of centrally defined data"
094:         * solution, much as I dislike it.
095:         * <P>
096:         * For now I have decided, since REC-DOM-Level-1-19980818 doesn't
097:         * cover this in much detail, that synchronization doesn't have to be
098:         * considered while the user is deep in the tree. That is, if you're
099:         * looking within one of the EntityReferennce's children and the Entity
100:         * changes, you won't be informed; instead, you will continue to access
101:         * the same object -- which may or may not still be part of the tree.
102:         * This is the same behavior that obtains elsewhere in the DOM if the
103:         * subtree you're looking at is deleted from its parent, so it's
104:         * acceptable here. (If it really bothers folks, we could set things
105:         * up so deleted subtrees are walked and marked invalid, but that's
106:         * not part of the DOM's defined behavior.)
107:         * <P>
108:         * As a result, only the EntityReference itself has to be aware of
109:         * changes in the Entity. And it can take advantage of the same
110:         * structure-change-monitoring code I implemented to support
111:         * DeepNodeList.
112:         * 
113:         * @version
114:         * @since  PR-DOM-Level-1-19980818.
115:         */
116:        public class DeferredEntityReferenceImpl extends EntityReferenceImpl
117:                implements  DeferredNode {
118:
119:            //
120:            // Constants
121:            //
122:
123:            /** Serialization version. */
124:            static final long serialVersionUID = 390319091370032223L;
125:
126:            //
127:            // Data
128:            //
129:
130:            /** Node index. */
131:            protected transient int fNodeIndex;
132:
133:            //
134:            // Constructors
135:            //
136:
137:            /**
138:             * This is the deferred constructor. Only the fNodeIndex is given here. 
139:             * All other data, can be requested from the ownerDocument via the index.
140:             */
141:            DeferredEntityReferenceImpl(DeferredDocumentImpl ownerDocument,
142:                    int nodeIndex) {
143:                super (ownerDocument, null);
144:
145:                fNodeIndex = nodeIndex;
146:                needsSyncData(true);
147:                needsSyncChildren(true);
148:
149:            } // <init>(DeferredDocumentImpl,int)
150:
151:            //
152:            // DeferredNode methods
153:            //
154:
155:            /** Returns the node index. */
156:            public int getNodeIndex() {
157:                return fNodeIndex;
158:            }
159:
160:            //
161:            // Protected methods
162:            //
163:
164:            /** 
165:             * Synchronize the entity data. This is special because of the way
166:             * that the "fast" version stores the information.
167:             */
168:            protected void synchronizeData() {
169:
170:                // no need to sychronize again
171:                needsSyncData(false);
172:
173:                // get the node data
174:                DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) this .ownerDocument;
175:                name = ownerDocument.getNodeNameString(fNodeIndex);
176:
177:            } // synchronizeData()
178:
179:            /** Synchronize the children. */
180:            protected void synchronizeChildren() {
181:
182:                // no need to synchronize again
183:                needsSyncChildren(false);
184:
185:                // get children
186:                DocumentType doctype = ownerDocument.getDoctype();
187:                boolean found = false;
188:                if (doctype != null) {
189:
190:                    // we don't want to generate any event for this so turn them off
191:                    boolean orig = ownerDocument.getMutationEvents();
192:                    ownerDocument.setMutationEvents(false);
193:
194:                    NamedNodeMap entities = doctype.getEntities();
195:                    if (entities != null) {
196:                        Entity entity = (Entity) entities
197:                                .getNamedItem(getNodeName());
198:                        if (entity != null) {
199:
200:                            // we found the entity
201:                            found = true;
202:
203:                            // clone entity at this reference
204:                            boolean ro = isReadOnly();
205:                            isReadOnly(false);
206:                            Node child = entity.getFirstChild();
207:                            while (child != null) {
208:                                appendChild(child.cloneNode(true));
209:                                child = child.getNextSibling();
210:                            }
211:                            // set it back to readonly if what it was
212:                            if (ro) {
213:                                setReadOnly(true, true);
214:                            }
215:                        }
216:                    }
217:                    // set mutation events flag back to its original value
218:                    ownerDocument.setMutationEvents(orig);
219:                }
220:
221:                // if not found, create entity at this reference
222:                if (!found) {
223:                    isReadOnly(false);
224:                    DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) ownerDocument();
225:                    ownerDocument.synchronizeChildren(this , fNodeIndex);
226:                    setReadOnly(true, true);
227:                }
228:
229:            } // synchronizeChildren()
230:
231:            // inhibit the synchronize inherited from EntityReferenceImpl
232:            protected void synchronize() {
233:            }
234:
235:        } // class DeferredEntityReferenceImpl
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.