Source code: com/hp/hpl/jena/enhanced/test/TestAllImpl.java
1 /*
2 (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3 [See end of file]
4 $Id: TestAllImpl.java,v 1.6 2005/02/21 12:03:40 andy_seaborne Exp $
5 */
6
7 package com.hp.hpl.jena.enhanced.test;
8 import com.hp.hpl.jena.enhanced.*;
9 import com.hp.hpl.jena.graph.*;
10
11 /**
12 * @see TestObjectImpl
13 * @author jjc
14 */
15 public class TestAllImpl extends TestCommonImpl implements TestSubject, TestProperty, TestObject {
16
17 public static final Implementation factory = new Implementation() {
18 public boolean canWrap( Node n, EnhGraph eg )
19 { return true; }
20 public EnhNode wrap(Node n,EnhGraph eg) {
21 return new TestAllImpl(n,eg);
22 }
23 };
24
25 /** Creates a new instance of TestAllImpl */
26 private TestAllImpl(Node n,EnhGraph eg) {
27 super( n, eg );
28 }
29
30 public boolean supports( Class t )
31 {
32 // return convertTo( t ) != null;
33 return
34 t == TestProperty.class ? isProperty()
35 : t == TestSubject.class ? isSubject()
36 : t == TestObject.class ? isObject()
37 : false
38 ;
39 }
40
41 public boolean isObject() {
42 return findObject() != null;
43 }
44
45 public boolean isProperty() {
46 return findPredicate() != null;
47 }
48
49 public boolean isSubject() {
50 return findSubject() != null;
51 }
52
53 public TestObject anObject() {
54 if (!isProperty())
55
56 throw new IllegalStateException("Node is not the property of a triple.");
57 return (TestObject)enhGraph.getNodeAs(findPredicate().getObject(),TestObject.class);
58 }
59
60 public TestProperty aProperty() {
61 if (!isSubject())
62 throw new IllegalStateException("Node is not the subject of a triple.");
63 return (TestProperty)enhGraph.getNodeAs(findSubject().getPredicate(),TestProperty.class);
64 }
65
66 public TestSubject aSubject() {
67 if (!isObject())
68 throw new IllegalStateException("Node is not the object of a triple.");
69 return (TestSubject)enhGraph.getNodeAs(findObject().getSubject(),TestSubject.class);
70 }
71
72 }
73
74 /*
75 (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
76 All rights reserved.
77
78 Redistribution and use in source and binary forms, with or without
79 modification, are permitted provided that the following conditions
80 are met:
81
82 1. Redistributions of source code must retain the above copyright
83 notice, this list of conditions and the following disclaimer.
84
85 2. Redistributions in binary form must reproduce the above copyright
86 notice, this list of conditions and the following disclaimer in the
87 documentation and/or other materials provided with the distribution.
88
89 3. The name of the author may not be used to endorse or promote products
90 derived from this software without specific prior written permission.
91
92 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
93 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
94 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
95 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
96 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
97 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
98 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
99 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
100 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
101 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102 */