Source Code Cross Referenced for XMLContainerHelperImpl.java in  » Database-DBMS » Ozone-1.1 » org » ozoneDB » xml » util » 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 » Database DBMS » Ozone 1.1 » org.ozoneDB.xml.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Ozone Library License version 1 published by ozone-db.org.
003:        //
004:        // The original code and portions created by SMB are
005:        // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006:        //
007:        // $Id: XMLContainerHelperImpl.java,v 1.1 2001/12/18 11:03:24 per_nyfelt Exp $
008:
009:        package org.ozoneDB.xml.util;
010:
011:        import java.io.IOException;
012:
013:        import org.w3c.dom.Document;
014:        import org.w3c.dom.Node;
015:        import org.w3c.dom.NodeList;
016:
017:        import org.xml.sax.SAXException;
018:
019:        import org.ozoneDB.OzoneObject;
020:        import org.ozoneDB.xml.dom.DocumentProxy;
021:
022:        import org.infozone.tools.xml.queries.XObject;
023:        import org.infozone.tools.xml.queries.XPathQuery;
024:        import org.infozone.tools.xml.queries.XUpdateQuery;
025:        import org.infozone.tools.xml.queries.XPathQueryFactory;
026:        import org.infozone.tools.xml.queries.XUpdateQueryFactory;
027:
028:        /**
029:         * This class provides the server side part of the XMLContainer. It mainly
030:         * handles storing and retrieving of parts of the underlying XML document.
031:         * 
032:         * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
033:         * @author <a href="http://www.smb-tec.com">SMB</a>
034:         */
035:        public final class XMLContainerHelperImpl extends OzoneObject implements 
036:                XMLContainerHelper {
037:
038:            private final static long serialVersionUID = 4L;
039:
040:            private final static boolean debug = XMLContainer.debug;
041:
042:            private static XPathQueryFactory xpathQueryFactory;
043:
044:            private static XUpdateQueryFactory xupdateQueryFactory;
045:
046:            /** The underlying XML document. */
047:            private Document document;
048:
049:            static {
050:                // use Xt and Lexus for XPath and XUpdate
051:                if (System.getProperties().get(
052:                        "org.infozone.tools.xml.queries.XPathQueryFactory") == null) {
053:                    System
054:                            .getProperties()
055:                            .put(
056:                                    "org.infozone.tools.xml.queries.XPathQueryFactory",
057:                                    "org.infozone.tools.xml.queries.xt.XPathQueryFactoryImpl");
058:                }
059:
060:                if (System.getProperties().get(
061:                        "org.infozone.tools.xml.queries.XUpdateQueryFactory") == null) {
062:                    System
063:                            .getProperties()
064:                            .put(
065:                                    "org.infozone.tools.xml.queries.XUpdateQueryFactory",
066:                                    "org.infozone.lexus.XUpdateQueryFactoryImpl");
067:                }
068:
069:                xpathQueryFactory = XPathQueryFactory.newInstance();
070:                xupdateQueryFactory = XUpdateQueryFactory.newInstance();
071:            }
072:
073:            public XMLContainerHelperImpl() {
074:                if (debug) {
075:                    System.out.println("helper: ctor...");
076:                }
077:            }
078:
079:            public final void onCreate() throws Exception {
080:                if (debug) {
081:                    System.out.println("helper: onCreate()...");
082:                }
083:                document = (Document) database().createObject(
084:                        org.ozoneDB.xml.dom.DocumentImpl.class.getName());
085:                ((DocumentProxy) document).setContainer(this );
086:            }
087:
088:            public final void onDelete() throws Exception {
089:                if (debug) {
090:                    System.out.println("helper: onDelete()...");
091:                }
092:                if (document != null) {
093:                    database().deleteObject((DocumentProxy) document);
094:                }
095:            }
096:
097:            public final void setDocument(Document _pdoc) {
098:                if (debug) {
099:                    System.out.println("helper: setDocument...");
100:                }
101:
102:                if (document != null) {
103:                    throw new IllegalStateException(
104:                            "Container helper is already assigned to a document.");
105:                }
106:
107:                document = _pdoc;
108:                ((DocumentProxy) document).setContainer(this );
109:            }
110:
111:            public final Document getDocument() {
112:                if (debug) {
113:                    System.out.println("helper: getDocument...");
114:                }
115:
116:                return document;
117:            }
118:
119:            public final SAXChunkConsumer beginInputSequence(Node _pNode)
120:                    throws Exception {
121:                if (debug) {
122:                    System.out.println("helper: beginInputSequence...");
123:                }
124:
125:                if (_pNode == null) {
126:                    _pNode = getDocument();
127:                    ((DocumentProxy) _pNode).clearDocument();
128:                }
129:
130:                SAXChunkConsumer consumer = new SAXChunkConsumer(getDocument(),
131:                        _pNode);
132:                return consumer;
133:            }
134:
135:            public final SAXChunkConsumer putChunk(byte[] _chunkData,
136:                    SAXChunkConsumer _consumer) throws SAXException,
137:                    IOException {
138:                _consumer.processChunk(_chunkData);
139:                return _consumer;
140:            }
141:
142:            public final void endInputSequence() throws Exception {
143:                if (debug) {
144:                    System.out.println("helper: endInputSequence...");
145:                }
146:            }
147:
148:            /*    public final SAXChunkProducer beginOutputSequence( Node _pnode, int _depth ) throws Exception {
149:             if (_pnode == null) {
150:             _pnode = getDocument();
151:             } 
152:            
153:             ModifiableNodeList mnl = new ModifiableNodeList(1);
154:             mnl.addNode(_pnode);
155:            
156:             return new SAXChunkProducer( mnl, _depth );
157:             } 
158:             */
159:
160:            public final SAXChunkProducer beginOutputSequence(NodeList _pnodes,
161:                    int _depth) throws Exception {
162:                if (_pnodes == null) {
163:                    _pnodes = new ModifiableNodeList(1);
164:                    ((ModifiableNodeList) _pnodes).addNode(getDocument());
165:                }
166:                return new SAXChunkProducer(_pnodes, _depth);
167:            }
168:
169:            public final SAXChunkProducer createNextChunk(
170:                    SAXChunkProducer producer) throws SAXException {
171:                producer.createNextChunk();
172:                return producer;
173:            }
174:
175:            public final void endOutputSequence() throws Exception {
176:                if (debug) {
177:                    System.out.println("helper: endOutputSequence...");
178:                }
179:            }
180:
181:            public final XObject executeXPath(OzoneXPathQuery _query)
182:                    throws Exception {
183:                if (_query.rootNode == null) {
184:                    _query.rootNode = getDocument();
185:                }
186:                XPathQuery query = xpathQueryFactory.newXPathQuery();
187:                query.setQString(_query.qstring);
188:                if (_query.filter != null) {
189:                    query.setNodeFilter(_query.filter);
190:                }
191:                if (_query.namespace != null) {
192:                    query.setNamespace(_query.namespace);
193:                }
194:                return query.execute(_query.rootNode);
195:            }
196:
197:            public final void executeXUpdate(OzoneXUpdateQuery _query)
198:                    throws Exception {
199:                if (_query.rootNode == null) {
200:                    _query.rootNode = getDocument();
201:                }
202:                XUpdateQuery query = xupdateQueryFactory.newXUpdateQuery();
203:                query.setQString(_query.qstring);
204:                if (_query.filter != null) {
205:                    query.setNodeFilter(_query.filter);
206:                }
207:                if (_query.namespace != null) {
208:                    query.setNamespace(_query.namespace);
209:                }
210:                System.out.println(query.getClass().getName());
211:                System.out.println(_query.qstring);
212:                System.out.println(_query.rootNode);
213:                query.execute(_query.rootNode);
214:            }
215:
216:            /**
217:             * Determines the absolute XPath for the given node.
218:             * @param node The W3C DOM node whose XPath is to determine.
219:             * @return The string representing the absolute XPath for this node.
220:             */
221:            public final String xpathForNode(Node _pnode) {
222:                if (_pnode == null) {
223:                    throw new IllegalArgumentException("_pnode == null.");
224:                }
225:
226:                StringBuffer xpath = new StringBuffer();
227:                xpath = iterateBack(_pnode, xpath);
228:                return xpath.toString();
229:            }
230:
231:            // internal stuff
232:
233:            private final StringBuffer iterateBack(Node node,
234:                    StringBuffer buffer) {
235:                int nthChild = 1;
236:                String nodeName = node.getNodeName();
237:                Node prevNode = node;
238:                while ((prevNode = prevNode.getPreviousSibling()) != null) {
239:                    if (prevNode.getNodeName().equals(nodeName)
240:                            && prevNode.getNodeType() == node.getNodeType()) {
241:                        nthChild++;
242:                    }
243:                }
244:                if (node.getNodeType() == Node.TEXT_NODE) {
245:                    nodeName = "text()";
246:                } else if (node.getNodeType() == Node.COMMENT_NODE) {
247:                    nodeName = "comment()";
248:                } else {
249:                    if (node.getNodeType() == Node.DOCUMENT_NODE) {
250:                        nodeName = "";
251:                    }
252:                }
253:                buffer.insert(0, "/" + nodeName
254:                        + (nodeName.length() > 0 ? "[" + nthChild + "]" : ""));
255:                node = node.getParentNode();
256:                if (node != null && node.getNodeType() != Node.DOCUMENT_NODE) {
257:                    buffer = iterateBack(node, buffer);
258:                }
259:                return buffer;
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.