1 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 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 26 private TestAllImpl(Node n,EnhGraph eg) { 27 super( n, eg ); 28 } 29 30 public boolean supports( Class t ) 31 { 32 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 103 | Popular Tags |