/** 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 ); }
/** 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 testAlreadyLinkedViewException() { Graph g = Factory.createGraphMem(); Personality<RDFNode> ours = BuiltinPersonalities.model.copy().add( Example.class, Example.factory ); EnhGraph eg = new EnhGraph( g, ours ); Node n = NodeCreateUtils.create( "spoo:bar" ); EnhNode eNode = new Example( n, eg ); EnhNode multiplexed = new Example( n, eg ); multiplexed.as( Property.class ); eNode.viewAs( Example.class ); try { eNode.addView( multiplexed ); fail( "should raise an AlreadyLinkedViewException " ); } catch (AlreadyLinkedViewException e) {} }
public void testAlreadyLinkedViewException() { Graph g = Factory.createGraphMem(); Personality<RDFNode> ours = BuiltinPersonalities.model.copy().add( Example.class, Example.factory ); EnhGraph eg = new EnhGraph( g, ours ); Node n = NodeCreateUtils.create( "spoo:bar" ); EnhNode eNode = new Example( n, eg ); EnhNode multiplexed = new Example( n, eg ); multiplexed.as( Property.class ); eNode.viewAs( Example.class ); try { eNode.addView( multiplexed ); fail( "should raise an AlreadyLinkedViewException " ); } catch (AlreadyLinkedViewException e) {} }