public List<Resource> decodeResources() throws JsonException { JsonArray results = encoder.getResults(j); List<Resource> roots = new ArrayList<Resource>(); int len = results.size(); for (int i = 0; i < len; i++) { roots.add( decodeResource(results.get(i).getAsObject())); } return roots; }
private boolean isJsonArrayCompact(JsonArray jsonArray) { if ( jsonArray.size() > maxCompactArray ) return false ; for ( int i = 0 ; i < jsonArray.size() ; i++ ) { if ( ! jsonArray.get(i).isPrimitive() ) return false ; } return true ; }
protected RDFNode decodeList(JsonArray array) throws JsonException { if (array.size() == 0) { return RDF.nil; } else { RDFNode[] listContents = new RDFNode[ array.size() ]; for (int i = 0; i < array.size(); i++) { listContents[i] = decodeNode(array.get(i), null); } return model.createList(listContents); } }
private static boolean isCompactValue(JsonValue v) { if ( v.isPrimitive()) return true ; if ( v.isArray() ) { JsonArray a = v.getAsArray() ; if ( a.size() == 0 ) return true ; if ( a.size() > 1 ) return false ; return a.get(0).isPrimitive() ; } if ( v.isObject() ) { JsonObject obj = v.getAsObject() ; Set<String> x = obj.keySet() ; if ( x.size() == 0 ) return true ; if ( x.size() > 1 ) return false ; String k = obj.keys().iterator().next(); return obj.get(k).isPrimitive() ; } return false ; }
private static boolean isCompactValue(JsonValue v) { if ( v.isPrimitive()) return true ; if ( v.isArray() ) { JsonArray a = v.getAsArray() ; if ( a.size() == 0 ) return true ; if ( a.size() > 1 ) return false ; return a.get(0).isPrimitive() ; } if ( v.isObject() ) { JsonObject obj = v.getAsObject() ; Set<String> x = obj.keySet() ; if ( x.size() == 0 ) return true ; if ( x.size() > 1 ) return false ; String k = obj.keys().iterator().next(); return obj.get(k).isPrimitive() ; } return false ; }
private static String[] getStringArray(JsonObject json, String key) { if ( ! json.hasKey(key) ) throw new TDBException("StoreParamsCodec.getStringArray: no such key: "+key) ; JsonArray a = json.get(key).getAsArray() ; String[] x = new String[a.size()] ; for ( int i = 0 ; i < a.size() ; i++ ) { x[i] = a.get(i).getAsString().value() ; } return x ; }
public static JsonValue access(JsonValue obj, Object... path) { for ( Object p : path ) { if ( p instanceof String ) { if ( !obj.isObject() ) { throw new JsonException("Path traverses non-object") ; } obj = obj.getAsObject().get((String)p) ; } if ( p instanceof Integer ) { if ( !obj.isArray() ) { throw new JsonException("Path traverses non-array") ; } obj = obj.getAsArray().get((Integer)p) ; } } return obj ; }
private static String[] getStringArray(JsonObject json, String key) { if ( ! json.hasKey(key) ) throw new TDBException("StoreParamsCodec.getStringArray: no such key: "+key) ; JsonArray a = json.get(key).getAsArray() ; String[] x = new String[a.size()] ; for ( int i = 0 ; i < a.size() ; i++ ) { x[i] = a.get(i).getAsString().value() ; } return x ; }
public static JsonValue access(JsonValue obj, Object ... path) { for ( int i = 0 ; i < path.length ; i++ ) { Object p = path[i] ; if ( p instanceof String ) { if ( ! obj.isObject() ) throw new JsonException("Path traverses non-object") ; obj = obj.getAsObject().get((String)p) ; } if ( p instanceof Integer ) { if ( ! obj.isArray() ) throw new JsonException("Path traverses non-array") ; obj = obj.getAsArray().get((Integer)p) ; } } return obj ; }
} else { for (int i = 0; i < vala.size(); i++) { r.addProperty(p, decodeNode( vala.get(i), range ));
/** * Decode a JSON object from the reader into collection of named graphs * @throws EncodingException if there is a jsonrdf level error or JSON error */ public static Dataset decodeGraphs(Context context, Reader reader) { try { JsonObject jObj = ParseWrapper.readerToJsonObject(reader); // Context context = encoder.getContext(jObj); Model def = modelFromRoots( new Decoder(context, jObj).decodeResources() ); Dataset set = DatasetFactory.create(def); JsonArray graphs = encoder.getNamedGraphs(jObj); if (graphs != null) { for (int i = 0; i < graphs.size(); i++) { JsonObject graph = graphs.get(i).getAsObject(); String name = encoder.getGraphName(graph, context); Model model = modelFromRoots( new Decoder(context, graph).decodeResources() ); set.addNamedModel(name, model); } } return set; } catch (JsonException e) { throw new EncodingException(e.getMessage(), e); } }