public AmbiguousSpecificTypeException( Resource root, ArrayList<Resource> types ) { super( root, makeMessage( root, types ) ); this.types = types; }
public void testSpecificTypeFails() { try { testSpecificType( "xxx", "x rdf:type ja:Model; x rdf:type ja:PrefixMapping" ); fail( "should trap multiple types" ); } catch (AmbiguousSpecificTypeException e) { assertEquals( resource( "x" ), e.getRoot() ); assertEquals( resources( e.getRoot(), "ja:Model ja:PrefixMapping" ), new HashSet<>( e.getTypes() ) ); } }
/** Answer the most specific type of <code>root</code> that is a subclass of <code>givenType</code>. If there are no candidate types, answer <code>givenType</code>. If there is more than one type, throw a NoSpecificTypeException. */ public static Resource findSpecificType( Resource root, Resource baseType ) { Set<Resource> types = findSpecificTypes( root, baseType ); if (types.size() == 1) return types.iterator().next(); if (types.size() == 0) return baseType; throw new AmbiguousSpecificTypeException( root, new ArrayList<>( types ) ); }
public void testSpecificTypeFails() { try { testSpecificType( "xxx", "x rdf:type ja:Model; x rdf:type ja:PrefixMapping" ); fail( "should trap multiple types" ); } catch (AmbiguousSpecificTypeException e) { assertEquals( resource( "x" ), e.getRoot() ); assertEquals( resources( e.getRoot(), "ja:Model ja:PrefixMapping" ), new HashSet<>( e.getTypes() ) ); } }
/** Answer the most specific type of <code>root</code> that is a subclass of <code>givenType</code>. If there are no candidate types, answer <code>givenType</code>. If there is more than one type, throw a NoSpecificTypeException. */ public static Resource findSpecificType( Resource root, Resource baseType ) { Set<Resource> types = findSpecificTypes( root, baseType ); if (types.size() == 1) return types.iterator().next(); if (types.size() == 0) return baseType; throw new AmbiguousSpecificTypeException( root, new ArrayList<>( types ) ); }
@Override public Object open( Assembler a, Resource root, Mode mode ) { Set <Resource>types = AssemblerHelp.findSpecificTypes( root, JA.Object ); if (types.size() == 0) { // Does it exist as a subject in the model? Mistyped? boolean noSuchSubject = ! root.listProperties().hasNext() ; if ( noSuchSubject ) { String s ; if ( root.isURIResource() ) s = "<"+root.getURI()+">" ; else if ( root.isAnon() ) s = "_:"+root.getId() ; else s = String.valueOf(root) ; throw new AssemblerException(root, "Can't find "+s+" as a subject") ; } throw new NoSpecificTypeException( root ); } else if (types.size() > 1) throw new AmbiguousSpecificTypeException( root, new ArrayList<>( types ) ); else return openBySpecificType( a, root, mode, types.iterator().next() ); }
public AmbiguousSpecificTypeException( Resource root, ArrayList<Resource> types ) { super( root, makeMessage( root, types ) ); this.types = types; }
private static String nice( List<Resource> types ) { StringBuilder result = new StringBuilder(); for ( Resource type : types ) { result.append( " " ).append( nice( type ) ); } return result.toString(); }
@Override public Object open( Assembler a, Resource root, Mode mode ) { Set <Resource>types = AssemblerHelp.findSpecificTypes( root, JA.Object ); if (types.size() == 0) { // Does it exist as a subject in the model? Mistyped? boolean noSuchSubject = ! root.listProperties().hasNext() ; if ( noSuchSubject ) { String s ; if ( root.isURIResource() ) s = "<"+root.getURI()+">" ; else if ( root.isAnon() ) s = "_:"+root.getId() ; else s = String.valueOf(root) ; throw new AssemblerException(root, "Can't find "+s+" as a subject") ; } throw new NoSpecificTypeException( root ); } else if (types.size() > 1) throw new AmbiguousSpecificTypeException( root, new ArrayList<>( types ) ); else return openBySpecificType( a, root, mode, types.iterator().next() ); }
private static String nice( List<Resource> types ) { StringBuilder result = new StringBuilder(); for ( Resource type : types ) { result.append( " " ).append( nice( type ) ); } return result.toString(); }