001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email ian.dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created 04-Dec-2003
009: * Filename $RCSfile: SimpleXMLPathDocument.java,v $
010: * Revision $Revision: 1.7 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:09:42 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: *****************************************************************************/package com.hp.hpl.jena.util.xml;
019:
020: // Imports
021: ///////////////
022: import java.util.*;
023:
024: import org.w3c.dom.*;
025:
026: import com.hp.hpl.jena.util.iterator.SingletonIterator;
027:
028: /**
029: * <p>
030: * An implementation of simple XML path that returns the document element for
031: * an xml document.
032: * </p>
033: *
034: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
035: * @version CVS $Id: SimpleXMLPathDocument.java,v 1.7 2008/01/02 12:09:42 andy_seaborne Exp $
036: */
037: public class SimpleXMLPathDocument implements SimpleXMLPathComponent {
038:
039: // Constants
040: //////////////////////////////////
041:
042: // Static variables
043: //////////////////////////////////
044:
045: // Instance variables
046: //////////////////////////////////
047:
048: // Constructors
049: //////////////////////////////////
050:
051: // External signature methods
052: //////////////////////////////////
053:
054: /**
055: * Answer an iterator containing only the document element of the given document
056: * @param node A document node
057: */
058: public Iterator getAll(Node node) {
059: if (!(node instanceof Document)) {
060: throw new IllegalArgumentException(
061: "Tried to evaluate a document path expression on a non document: "
062: + node.getClass().getName());
063: }
064:
065: return new SingletonIterator(((Document) node)
066: .getDocumentElement());
067: }
068:
069: /**
070: * Answer the document element of the given document
071: * @param node A document node
072: */
073: public Object getFirst(Node node) {
074: if (!(node instanceof Document)) {
075: throw new IllegalArgumentException(
076: "Tried to evaluate a document path expression on a non document: "
077: + node.getClass().getName());
078: }
079:
080: return ((Document) node).getDocumentElement();
081: }
082:
083: // Internal implementation methods
084: //////////////////////////////////
085:
086: //==============================================================================
087: // Inner class definitions
088: //==============================================================================
089:
090: }
091:
092: /*
093: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
094: * All rights reserved.
095: *
096: * Redistribution and use in source and binary forms, with or without
097: * modification, are permitted provided that the following conditions
098: * are met:
099: * 1. Redistributions of source code must retain the above copyright
100: * notice, this list of conditions and the following disclaimer.
101: * 2. Redistributions in binary form must reproduce the above copyright
102: * notice, this list of conditions and the following disclaimer in the
103: * documentation and/or other materials provided with the distribution.
104: * 3. The name of the author may not be used to endorse or promote products
105: * derived from this software without specific prior written permission.
106: *
107: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
108: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
109: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
110: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
111: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
112: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
113: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
114: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
115: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
116: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
117: */
|