public NotUniqueException( Resource root, Property property ) { super( makeMessage( root, property ) ); this.property = property; }
public static Resource getResourceValue(Resource r, Property p) { if ( !atmostOneProperty(r, p) ) throw new NotUniqueException(r, p) ; Statement s = r.getProperty(p) ; if ( s == null ) return null ; return s.getResource() ; }
private static boolean argBoolean(Resource r, Property p, boolean dftValue) { try { GraphUtils.atmostOneProperty(r, p); } catch (NotUniqueException ex) { throw new FusekiConfigException(ex.getMessage()); } Statement stmt = r.getProperty(p); if ( stmt == null ) return dftValue; try { return stmt.getBoolean(); } catch (JenaException ex) { throw new FusekiConfigException("Not a boolean for '"+p+"' : "+stmt.getObject()); } }
public static String getStringValue(Resource r, Property p) { if ( !atmostOneProperty(r, p) ) throw new NotUniqueException(r, p) ; Statement s = r.getProperty(p) ; if ( s == null ) return null ; return s.getString() ; }
private static boolean argBoolean(Resource r, Property p, boolean dftValue) { try { GraphUtils.atmostOneProperty(r, p); } catch (NotUniqueException ex) { throw new FusekiConfigException(ex.getMessage()); } Statement stmt = r.getProperty(p); if ( stmt == null ) return dftValue; try { return stmt.getBoolean(); } catch (JenaException ex) { throw new FusekiConfigException("Not a boolean for '"+p+"' : "+stmt.getObject()); } }
public static boolean atmostOneProperty(Resource r, Property p) { StmtIterator sIter = r.listProperties(p) ; try { if ( !sIter.hasNext() ) return true ; sIter.next() ; if ( sIter.hasNext() ) throw new NotUniqueException(r, p) ; } finally { sIter.close() ; } return true ; }
public static boolean exactlyOneProperty(Resource r, Property p) { StmtIterator sIter = r.listProperties(p) ; try { if ( !sIter.hasNext() ) throw new PropertyRequiredException(r, p) ; sIter.next() ; if ( sIter.hasNext() ) throw new NotUniqueException(r, p) ; } finally { sIter.close() ; } return true ; }
public static String getAsStringValue(Resource r, Property p) { if ( !atmostOneProperty(r, p) ) throw new NotUniqueException(r, p) ; Statement s = r.getProperty(p) ; if ( s == null ) return null ; if ( s.getObject().isResource() ) return s.getResource().getURI() ; return s.getString() ; }