BEA Systems, Inc.

BEA WebLogic Server 9.1 API Reference


weblogic.xml.xpath
Class XPathStreamFactory

java.lang.Object
  extended byweblogic.xml.xpath.XPathStreamFactory

public final class XPathStreamFactory
extends Object

Creates XMLInputStreams which perform xpath matching and notify XPathStreamObservers of the results. One or more observers may be registered with the factory along with a corresponding StreamXPaths which they wish to match against; the observers will receive event notifications from all streams subsequently created by the factory's createStream method.

The following code demonstrates how to create and use an XPathStreamFactory. It creates a factory, installs an observer, and then retrieves a stream from it:

  
  XMLInputStream sourceInputStream = ...
  StreamXPath xpath = new StreamXPath("foo/bar/baz");
  final List hits = new ArrayList();
  XPathStreamFactory f = new XPathStreamFactory();
  f.install(xpath,
            new XPathStreamObserver() {
              observe(XMLEvent e) { hits.add(e); }
              observeAttribute(XMLEvent e, Attribute a) {} // ignore
              observeNamespace(XMLEvent e, Attribute a) {} // ignore
            });
  XMLInputStream mystream = f.createStream(sourceInputStream);
                  
 

In this example, as events are pulled through mystream any events matching the xpath foo/bar/baz will be placed in hits. Note that this will include both start and end 'baz' elements.

Copyright © 2005 BEA Systems, Inc. All Rights Reserved.

Constructor Summary
XPathStreamFactory()
          Constructs an empty XPathStreamFactory.
XPathStreamFactory(StreamXPath xpath, XPathStreamObserver observer)
          Convenience constructor; equivalent to calling

(new XPathStreamFactory()).install(xpath,observer) .
 
Method Summary
 XMLInputStream createStream(XMLInputStream source)
          Returns an XMLInputStream which matches events in a given stream against the installed xpaths and notifies the corresponding installed observers.
 XMLOutputStream createStream(XMLOutputStream destination)
          Returns an XMLOutputStream which matches outbound events against the installed xpaths, notifies the appropriate installed observers, and then passes the events on to a given destination stream.
 void install(StreamXPath xpath, XPathStreamObserver observer)
          Installs an observer that receives notifications of all events in the stream which match the given xpath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathStreamFactory

public XPathStreamFactory()

Constructs an empty XPathStreamFactory. The factory will not be very useful until at least one xpath-observer pair is installed using the install method.


XPathStreamFactory

public XPathStreamFactory(StreamXPath xpath,
                          XPathStreamObserver observer)

Convenience constructor; equivalent to calling

(new XPathStreamFactory()).install(xpath,observer) .

Throws:
IllegalArgumentException - if either argument is null.
Method Detail

createStream

public XMLInputStream createStream(XMLInputStream source)

Returns an XMLInputStream which matches events in a given stream against the installed xpaths and notifies the corresponding installed observers. Each event from the source stream passes through the returned stream after being evaluated against the xpaths.

Throws:
IllegalArgumentException - if parent is null.

createStream

public XMLOutputStream createStream(XMLOutputStream destination)

Returns an XMLOutputStream which matches outbound events against the installed xpaths, notifies the appropriate installed observers, and then passes the events on to a given destination stream.

Parameters:
destination - The XMLOutputStream where events written to the returned stream are sent after matching is performed.
Throws:
IllegalArgumentException - if parent is null.

install

public void install(StreamXPath xpath,
                    XPathStreamObserver observer)

Installs an observer that receives notifications of all events in the stream which match the given xpath. Note that this includes end-elements which correspond to matching start-elements.

It is legal to install more than one xpath-observer pair; each observer will receive notifications of matches for the xpath with which it was installed. It is also legal to map a single xpath to multiple observers and vice-versa.

When a matching stream event is encountered, it is guaranteed that all of the appropriate notifications (if any) concerning that event will be processed before the event is passed on to the end consumer of the stream. If multiple xpath-observer pairs are installed, they will process each XMLEvent and send notifications in installation order.

Parameters:
observer - An observer to be notified of matches against the given xpath.
xpath - An xpath to be matched against streams created by this factory.
Throws:
IllegalArgumentException - if either argument is null.

Documentation is available at
http://download.oracle.com/docs/cd/E13222_01/wls/docs91
Copyright 2005 BEA Systems Inc.