001: /*
002: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.rdf.arp.states;
007:
008: import org.xml.sax.Attributes;
009: import org.xml.sax.SAXParseException;
010:
011: import com.hp.hpl.jena.rdf.arp.impl.ANode;
012: import com.hp.hpl.jena.rdf.arp.impl.ARPResource;
013: import com.hp.hpl.jena.rdf.arp.impl.AbsXMLContext;
014:
015: abstract class Collection extends WantDescription {
016: // TODO: not for 2.3. document this carefully.
017:
018: WantsObjectI nextSlot;
019:
020: public Collection(WantsObjectFrameI s, AbsXMLContext x) {
021: super (s, x);
022: nextSlot = s;
023: }
024:
025: ANode bnode;
026:
027: public FrameI startElement(String uri, String localName,
028: String rawName, Attributes atts) throws SAXParseException {
029: FrameI fi = super .startElement(uri, localName, rawName, atts);
030: ANode prevNode = bnode;
031: bnode = new ARPResource(arp);
032: try {
033: nextSlot.theObject(bnode);
034: } finally {
035: if (prevNode != null)
036: arp.endLocalScope(prevNode);
037: }
038: firstTriple(bnode, subject);
039: final ANode this Node = bnode;
040: nextSlot = new WantsObjectI() {
041: public void theObject(ANode a) {
042: restTriple(this Node, a);
043: }
044: };
045: return fi;
046:
047: }
048:
049: /** Must use second bnode in the first triple.
050: Can use either bnode in further triples.
051: */
052: abstract void restTriple(ANode subj, ANode obj);
053:
054: /** Must use both bnodes in the first triple.
055: Can use either bnode in further triples.
056: */
057: abstract void firstTriple(ANode subj, ANode obj);
058:
059: abstract ANode nil();
060:
061: final public void endElement() throws SAXParseException {
062: nextSlot.theObject(nil());
063: if (bnode != null) {
064: arp.endLocalScope(bnode);
065: bnode = null;
066: }
067: super .endElement();
068: }
069:
070: public void abort() {
071: if (bnode != null) {
072: arp.endLocalScope(bnode);
073: bnode = null;
074: }
075: super .abort();
076: }
077:
078: }
079:
080: /*
081: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
082: * All rights reserved.
083: *
084: * Redistribution and use in source and binary forms, with or without
085: * modification, are permitted provided that the following conditions
086: * are met:
087: * 1. Redistributions of source code must retain the above copyright
088: * notice, this list of conditions and the following disclaimer.
089: * 2. Redistributions in binary form must reproduce the above copyright
090: * notice, this list of conditions and the following disclaimer in the
091: * documentation and/or other materials provided with the distribution.
092: * 3. The name of the author may not be used to endorse or promote products
093: * derived from this software without specific prior written permission.
094: *
095: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
096: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
097: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
098: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
099: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
101: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
102: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
103: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
104: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105: */
|