/** * Answer the personality object bound to this enhanced node, which we obtain from * the associated enhanced graph. * * @return The personality object */ @Override protected Personality<RDFNode> getPersonality() { return getGraph().getPersonality(); }
/** answer true iff this enhanced node can support the class <code>t</code>, ie it is already a value <code>t</code> or it can be reimplemented as a <code>t</code> via the graph's personality's implementation. If this node has no graph, answer false. */ @Override protected <X extends RDFNode> boolean canSupport( Class<X> t ) { if (alreadyHasView( t )) return true; if (getGraph() == null) return false; Implementation imp = getPersonality().getImplementation( t ); return imp == null ? false : imp.canWrap( asNode(), getGraph() ); }
/** create a new Personality copying this one; the _types_ state is copied, not shared. */ public Personality<T> copy() { return new Personality<>( this ); }
/** initialise this personality with the bindings from _other_ */ public Personality( Personality<T> other ) { this(); this.add( other ); }
/** * Answer a polymorphic object that presents <i>this</i> in a way which satisfies type * t. * @param t A type * @return A polymorphic instance, possibly but not necessarily this, that conforms to t. */ protected final <X extends T> X asInternal( Class<X> t ) { X other = findExistingView( t ); return other == null ? this.convertTo( t ) : other; }
/** return _true_ iff this polymorphic object supports the specified interface. Synonymous with "does the argument class have this as an instance". Actually it shouldn't be. Review. */ public <X extends T> boolean supports( Class<X> t ) { X supporter = findExistingView( t ); return supporter != null || this.canSupport( t ); }
/** 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; }
/** Answer true iff this polymorphic object already has a valid view of type <code>t</code> in its ring (so .as()ing it doesn't need to construct a new object). */ protected <X extends T> boolean alreadyHasView( Class<X> t ) { return findExistingView( t ) != null; }
/** * Answer a facet of this node, where that facet is denoted by the * given type. * * @param t A type denoting the desired facet of the underlying node * @return An enhanced nodet that corresponds to t; this may be <i>this</i> * Java object, or a different object. */ public <X extends RDFNode> X viewAs( Class<X> t ) { return asInternal( t ); }
/** API-level method for polymorphic testing */ public <X extends RDFNode> boolean canAs( Class<X> t ) { return canSupport( t ); }
/** answer true iff this enhanced node can support the class <code>t</code>, ie it is already a value <code>t</code> or it can be reimplemented as a <code>t</code> via the graph's personality's implementation. If this node has no graph, answer false. */ @Override protected <X extends RDFNode> boolean canSupport( Class<X> t ) { if (alreadyHasView( t )) return true; if (getGraph() == null) return false; Implementation imp = getPersonality().getImplementation( t ); return imp == null ? false : imp.canWrap( asNode(), getGraph() ); }
/** initialise this personality with the bindings from _other_ */ public Personality( Personality<T> other ) { this(); this.add( other ); }
/** * Answer the personality object bound to this enhanced node, which we obtain from * the associated enhanced graph. * * @return The personality object */ @Override protected Personality<RDFNode> getPersonality() { return getGraph().getPersonality(); }
/** create a new Personality copying this one; the _types_ state is copied, not shared. */ public Personality<T> copy() { return new Personality<>( this ); }
/** * Answer a polymorphic object that presents <i>this</i> in a way which satisfies type * t. * @param t A type * @return A polymorphic instance, possibly but not necessarily this, that conforms to t. */ protected final <X extends T> X asInternal( Class<X> t ) { X other = findExistingView( t ); return other == null ? this.convertTo( t ) : other; }
/** return _true_ iff this polymorphic object supports the specified interface. Synonymous with "does the argument class have this as an instance". Actually it shouldn't be. Review. */ public <X extends T> boolean supports( Class<X> t ) { X supporter = findExistingView( t ); return supporter != null || this.canSupport( t ); }
/** 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; }
/** Answer true iff this polymorphic object already has a valid view of type <code>t</code> in its ring (so .as()ing it doesn't need to construct a new object). */ protected <X extends T> boolean alreadyHasView( Class<X> t ) { return findExistingView( t ) != null; }
/** * Answer a facet of this node, where that facet is denoted by the * given type. * * @param t A type denoting the desired facet of the underlying node * @return An enhanced nodet that corresponds to t; this may be <i>this</i> * Java object, or a different object. */ public <X extends RDFNode> X viewAs( Class<X> t ) { return asInternal( t ); }
/** API-level method for polymorphic testing */ public <X extends RDFNode> boolean canAs( Class<X> t ) { return canSupport( t ); }