/** Initialise this exception with the node that couldn't be polymorphed and the class it couldn't be polymorphed to. */ public UnsupportedPolymorphismException( Object node, boolean hasModel, Class<?> type ) { super( constructMessage( node, hasModel, type ) ); this.node = node; this.type = type; }
public void testAsThrowsPolymorphismExceptionIfNoModel() { Resource r = ResourceFactory.createResource(); try { r.as( Example.class ); fail( "should throw UnsupportedPolymorphismException" ); } catch (UnsupportedPolymorphismException e) { assertTrue( e.getBadNode() instanceof EnhNode ); assertEquals( null, ((EnhNode)e.getBadNode()).getGraph() ); assertEquals( Example.class, e.getBadClass() ); } }
/** Answer an new enhanced node object that presents <i>this</i> in a way which satisfies type <code>t</code>. The new object is linked into this object's sibling ring. If the node cannot be converted, throw an UnsupportedPolymorphismException. */ @Override protected <X extends RDFNode> X convertTo( Class<X> t ) { EnhGraph eg = getGraph(); if (eg == null) throw new UnsupportedPolymorphismException( this, false, t ); Implementation imp = getPersonality().getImplementation( t ); if (imp == null) throw new UnsupportedPolymorphismException( this, true, t ); EnhNode result = imp.wrap( asNode(), eg ); this.addView( result ); return t.cast( result ); }
public void testAsThrowsPolymorphismExceptionIfNoModel() { Resource r = ResourceFactory.createResource(); try { r.as( Example.class ); fail( "should throw UnsupportedPolymorphismException" ); } catch (UnsupportedPolymorphismException e) { assertTrue( e.getBadNode() instanceof EnhNode ); assertEquals( null, ((EnhNode)e.getBadNode()).getGraph() ); assertEquals( Example.class, e.getBadClass() ); } }
/** Answer an new enhanced node object that presents <i>this</i> in a way which satisfies type <code>t</code>. The new object is linked into this object's sibling ring. If the node cannot be converted, throw an UnsupportedPolymorphismException. */ @Override protected <X extends RDFNode> X convertTo( Class<X> t ) { EnhGraph eg = getGraph(); if (eg == null) throw new UnsupportedPolymorphismException( this, false, t ); Implementation imp = getPersonality().getImplementation( t ); if (imp == null) throw new UnsupportedPolymorphismException( this, true, t ); EnhNode result = imp.wrap( asNode(), eg ); this.addView( result ); return t.cast( result ); }
/** Test that an attempt to polymorph an enhanced node into a class that isn't supported by the enhanced graph generates an UnsupportedPolymorphism exception. */ public void testNullPointerTrap() { EnhGraph eg = new EnhGraph( Factory.createGraphMem(), new Personality<RDFNode>() ); Node n = NodeCreateUtils.create( "eh:something" ); EnhNode en = new EnhNode( n, eg ); try { en.as( Property.class ); fail( "oops" ); } catch (UnsupportedPolymorphismException e) { assertEquals( en, e.getBadNode() ); assertTrue( "exception should have cuplprit graph", eg == ((EnhNode)e.getBadNode()).getGraph() ); assertSame( "exception should have culprit class", Property.class, e.getBadClass() ); } }
/** Initialise this exception with the node that couldn't be polymorphed and the class it couldn't be polymorphed to. */ public UnsupportedPolymorphismException( Object node, boolean hasModel, Class<?> type ) { super( constructMessage( node, hasModel, type ) ); this.node = node; this.type = type; }
/** Test that an attempt to polymorph an enhanced node into a class that isn't supported by the enhanced graph generates an UnsupportedPolymorphism exception. */ public void testNullPointerTrap() { EnhGraph eg = new EnhGraph( Factory.createGraphMem(), new Personality<RDFNode>() ); Node n = NodeCreateUtils.create( "eh:something" ); EnhNode en = new EnhNode( n, eg ); try { en.as( Property.class ); fail( "oops" ); } catch (UnsupportedPolymorphismException e) { assertEquals( en, e.getBadNode() ); assertTrue( "exception should have cuplprit graph", eg == ((EnhNode)e.getBadNode()).getGraph() ); assertSame( "exception should have culprit class", Property.class, e.getBadClass() ); } }