001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestAllImpl.java,v 1.9 2008/01/02 12:06:35 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.enhanced.test;
008:
009: import com.hp.hpl.jena.enhanced.*;
010: import com.hp.hpl.jena.graph.*;
011:
012: /**
013: * @see TestObjectImpl
014: * @author jjc
015: */
016: public class TestAllImpl extends TestCommonImpl implements TestSubject,
017: TestProperty, TestObject {
018:
019: public static final Implementation factory = new Implementation() {
020: public boolean canWrap(Node n, EnhGraph eg) {
021: return true;
022: }
023:
024: public EnhNode wrap(Node n, EnhGraph eg) {
025: return new TestAllImpl(n, eg);
026: }
027: };
028:
029: /** Creates a new instance of TestAllImpl */
030: private TestAllImpl(Node n, EnhGraph eg) {
031: super (n, eg);
032: }
033:
034: public boolean supports(Class t) {
035: // return convertTo( t ) != null;
036: return t == TestProperty.class ? isProperty()
037: : t == TestSubject.class ? isSubject()
038: : t == TestObject.class ? isObject() : false;
039: }
040:
041: public boolean isObject() {
042: return findObject() != null;
043: }
044:
045: public boolean isProperty() {
046: return findPredicate() != null;
047: }
048:
049: public boolean isSubject() {
050: return findSubject() != null;
051: }
052:
053: public TestObject anObject() {
054: if (!isProperty())
055:
056: throw new IllegalStateException(
057: "Node is not the property of a triple.");
058: return (TestObject) enhGraph.getNodeAs(findPredicate()
059: .getObject(), TestObject.class);
060: }
061:
062: public TestProperty aProperty() {
063: if (!isSubject())
064: throw new IllegalStateException(
065: "Node is not the subject of a triple.");
066: return (TestProperty) enhGraph.getNodeAs(findSubject()
067: .getPredicate(), TestProperty.class);
068: }
069:
070: public TestSubject aSubject() {
071: if (!isObject())
072: throw new IllegalStateException(
073: "Node is not the object of a triple.");
074: return (TestSubject) enhGraph.getNodeAs(findObject()
075: .getSubject(), TestSubject.class);
076: }
077:
078: }
079:
080: /*
081: (c) Copyright 2003, 2004, 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:
088: 1. Redistributions of source code must retain the above copyright
089: notice, this list of conditions and the following disclaimer.
090:
091: 2. Redistributions in binary form must reproduce the above copyright
092: notice, this list of conditions and the following disclaimer in the
093: documentation and/or other materials provided with the distribution.
094:
095: 3. The name of the author may not be used to endorse or promote products
096: derived from this software without specific prior written permission.
097:
098: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
099: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
100: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
101: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
102: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
103: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
104: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
105: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
106: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
107: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
108: */
|