KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > enhanced > test > TestObjectImpl


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestObjectImpl.java,v 1.6 2005/02/21 12:03:42 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 {@link TestObject} for more detailed documentation.
13  * @author jjc
14  */

15 public class TestObjectImpl extends TestCommonImpl implements TestObject {
16
17     /** The required field is the factory field, of
18      * class Implementation.
19      * This tells how to construct a new EnhNode of this typ
20      * from a Node. Note that caching has already happened, so
21      * there is no point in implementing another cache here.
22      */

23     public static final Implementation factory = new Implementation() {
24     /** This method should probably always just call a constructor.
25      * Note the constructor can/should be private.
26      */

27     public EnhNode wrap(Node n,EnhGraph eg) {
28         return new TestObjectImpl(n,eg);
29     }
30     public boolean canWrap( Node n, EnhGraph eg )
31         { return true; }
32 };
33     
34     /** Creates a new instance of TestAllImpl */
35     private TestObjectImpl(Node n,EnhGraph eg) {
36         super( n, eg );
37     }
38     
39     public boolean supports( Class JavaDoc t )
40         { return t.isInstance( this) && isObject(); }
41         
42     public boolean isObject() {
43         return findObject() != null;
44     }
45     /**
46      * The code first checks that the interface is appropriate at this point.
47      * This is not obligatory but should be considered.
48      * (If the underlying graph has changed for the worse will
49      * users prefer an early and unambiguous exception at this point).
50      *
51      * @see com.hp.hpl.jena.enhanced.test.TestObject#aSubject()
52      */

53     public TestSubject aSubject() {
54         if (!isObject())
55             throw new IllegalStateException JavaDoc("Node is not the object of a triple.");
56         return (TestSubject)enhGraph.getNodeAs(findObject().getSubject(),TestSubject.class);
57     }
58 }
59
60 /*
61     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
62     All rights reserved.
63
64     Redistribution and use in source and binary forms, with or without
65     modification, are permitted provided that the following conditions
66     are met:
67
68     1. Redistributions of source code must retain the above copyright
69        notice, this list of conditions and the following disclaimer.
70
71     2. Redistributions in binary form must reproduce the above copyright
72        notice, this list of conditions and the following disclaimer in the
73        documentation and/or other materials provided with the distribution.
74
75     3. The name of the author may not be used to endorse or promote products
76        derived from this software without specific prior written permission.
77
78     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
79     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
80     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
81     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
82     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
83     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
87     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88 */

89
90
Popular Tags