01: /*
02: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: [See end of file]
04: $Id: TestObjectImpl.java,v 1.9 2008/01/02 12:06:34 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.enhanced.test;
08:
09: import com.hp.hpl.jena.enhanced.*;
10: import com.hp.hpl.jena.graph.*;
11:
12: /**
13: * See {@link TestObject} for more detailed documentation.
14: * @author jjc
15: */
16: public class TestObjectImpl extends TestCommonImpl implements
17: TestObject {
18:
19: /** The required field is the factory field, of
20: * class Implementation.
21: * This tells how to construct a new EnhNode of this typ
22: * from a Node. Note that caching has already happened, so
23: * there is no point in implementing another cache here.
24: */
25: public static final Implementation factory = new Implementation() {
26: /** This method should probably always just call a constructor.
27: * Note the constructor can/should be private.
28: */
29: public EnhNode wrap(Node n, EnhGraph eg) {
30: return new TestObjectImpl(n, eg);
31: }
32:
33: public boolean canWrap(Node n, EnhGraph eg) {
34: return true;
35: }
36: };
37:
38: /** Creates a new instance of TestAllImpl */
39: private TestObjectImpl(Node n, EnhGraph eg) {
40: super (n, eg);
41: }
42:
43: public boolean supports(Class t) {
44: return t.isInstance(this ) && isObject();
45: }
46:
47: public boolean isObject() {
48: return findObject() != null;
49: }
50:
51: /**
52: * The code first checks that the interface is appropriate at this point.
53: * This is not obligatory but should be considered.
54: * (If the underlying graph has changed for the worse will
55: * users prefer an early and unambiguous exception at this point).
56: *
57: * @see com.hp.hpl.jena.enhanced.test.TestObject#aSubject()
58: */
59: public TestSubject aSubject() {
60: if (!isObject())
61: throw new IllegalStateException(
62: "Node is not the object of a triple.");
63: return (TestSubject) enhGraph.getNodeAs(findObject()
64: .getSubject(), TestSubject.class);
65: }
66: }
67:
68: /*
69: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
70: All rights reserved.
71:
72: Redistribution and use in source and binary forms, with or without
73: modification, are permitted provided that the following conditions
74: are met:
75:
76: 1. Redistributions of source code must retain the above copyright
77: notice, this list of conditions and the following disclaimer.
78:
79: 2. Redistributions in binary form must reproduce the above copyright
80: notice, this list of conditions and the following disclaimer in the
81: documentation and/or other materials provided with the distribution.
82:
83: 3. The name of the author may not be used to endorse or promote products
84: derived from this software without specific prior written permission.
85:
86: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
87: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
88: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
89: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
90: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
91: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
92: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
93: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
94: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
95: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96: */
|