01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: OzoneXPathQuery.java,v 1.1 2001/12/18 11:03:24 per_nyfelt Exp $
08:
09: package org.ozoneDB.xml.util;
10:
11: import java.io.*;
12:
13: import org.w3c.dom.Document;
14: import org.w3c.dom.Node;
15:
16: import org.w3c.dom.traversal.NodeFilter;
17:
18: import org.infozone.tools.xml.queries.XObject;
19: import org.infozone.tools.xml.queries.XPathQuery;
20: import org.infozone.tools.xml.queries.XUpdateQuery;
21:
22: /**
23: * This class represents a XPath that can be used to query the document of
24: * a {@link XMLContainer}.
25: *
26: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
27: * @author <a href="http://www.softwarebuero.de">SMB</a>
28: * @see XMLContainer
29: */
30: public final class OzoneXPathQuery implements XPathQuery,
31: Externalizable {
32:
33: protected final static long serialVersionUID = 1L;
34:
35: protected String qstring;
36:
37: protected NodeFilter filter;
38:
39: protected Node namespace;
40:
41: protected Node rootNode;
42:
43: protected transient XMLContainer delegate;
44:
45: public OzoneXPathQuery() {
46: }
47:
48: protected OzoneXPathQuery(XMLContainer _delegate) {
49: delegate = _delegate;
50: }
51:
52: public void setQString(String _qstring) throws Exception {
53: qstring = _qstring;
54: }
55:
56: public void setNamespace(Node _namespace) throws Exception {
57: namespace = _namespace;
58: }
59:
60: public void setNodeFilter(NodeFilter _filter) throws Exception {
61: filter = _filter;
62: }
63:
64: /**
65: * Execute the xpath.
66: *
67: * @see #execute(Node)
68: */
69: public XObject execute() throws Exception {
70: return execute(null);
71: }
72:
73: /**
74: * Execute the xpath.
75: *
76: * @param rootNode The node from which the query should start. A value of
77: * null specifies that the entire document should be searched.
78: * @return The XObject insulating the query result.
79: */
80: public XObject execute(Node _rootNode) throws Exception {
81: rootNode = _rootNode;
82: return delegate.executeXPath(this );
83: }
84:
85: public void writeExternal(ObjectOutput out) throws IOException {
86: out.writeObject(rootNode);
87: out.writeObject(qstring);
88: out.writeObject(filter);
89: out.writeObject(namespace);
90: }
91:
92: public void readExternal(ObjectInput in) throws IOException,
93: ClassNotFoundException {
94: rootNode = (Node) in.readObject();
95: qstring = (String) in.readObject();
96: filter = (NodeFilter) in.readObject();
97: namespace = (Node) in.readObject();
98: }
99: }
|