KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > util > OzoneXPathQuery


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: OzoneXPathQuery.java,v 1.1 2003/11/02 17:26:15 per_nyfelt Exp $
8

9 package org.ozoneDB.xml.util;
10
11 import java.io.*;
12
13 import org.w3c.dom.Node JavaDoc;
14 import org.w3c.dom.traversal.NodeFilter;
15 import org.infozone.tools.xml.queries.XObject;
16 import org.infozone.tools.xml.queries.XPathQuery;
17
18 /**
19  * This class represents a XPath that can be used to query the document of
20  * a {@link XMLContainer}.
21  *
22  * @version $Revision: 1.1 $ $Date: 2003/11/02 17:26:15 $
23  * @author <a HREF="http://www.softwarebuero.de">SMB</a>
24  * @see XMLContainer
25  */

26 public final class OzoneXPathQuery implements XPathQuery, Externalizable {
27
28     protected final static long serialVersionUID = 1L;
29
30     protected String JavaDoc qstring;
31
32     protected NodeFilter filter;
33
34     protected Node JavaDoc namespace;
35
36     protected Node JavaDoc rootNode;
37
38     protected transient XMLContainer delegate;
39
40     public OzoneXPathQuery() {
41     }
42
43     protected OzoneXPathQuery(XMLContainer _delegate) {
44         delegate = _delegate;
45     }
46
47     public void setQString(String JavaDoc _qstring) throws Exception JavaDoc {
48         qstring = _qstring;
49     }
50
51     public void setNamespace(Node JavaDoc _namespace) throws Exception JavaDoc {
52         namespace = _namespace;
53     }
54
55     public void setNodeFilter(NodeFilter _filter) throws Exception JavaDoc {
56         filter = _filter;
57     }
58
59     /**
60      * Execute the xpath.
61      *
62      * @see #execute(Node)
63      */

64     public XObject execute() throws Exception JavaDoc {
65         return execute(null);
66     }
67
68     /**
69      * Execute the xpath.
70      *
71      * @param _rootNode The node from which the query should start. A value of
72      * null specifies that the entire document should be searched.
73      * @return The XObject insulating the query result.
74      */

75     public XObject execute(Node JavaDoc _rootNode) throws Exception JavaDoc {
76         rootNode = _rootNode;
77         return delegate.executeXPath(this);
78     }
79
80     public void writeExternal(ObjectOutput out) throws IOException {
81         out.writeObject(rootNode);
82         out.writeObject(qstring);
83         out.writeObject(filter);
84         out.writeObject(namespace);
85     }
86
87     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException JavaDoc {
88         rootNode = (Node JavaDoc) in.readObject();
89         qstring = (String JavaDoc) in.readObject();
90         filter = (NodeFilter) in.readObject();
91         namespace = (Node JavaDoc) in.readObject();
92     }
93 }
Popular Tags