Package org.openjena.atlas.json

Examples of org.openjena.atlas.json.JsonObject


    {}
   
    @Override
    public void startObject(long currLine, long currCol)
    {
        objects.push(new JsonObject()) ;
    }
View Full Code Here


    {
        if ( value == null )
            throw new InternalErrorException("null for 'value' (bad finishPair() allignment)") ;
       
        String k = keys.pop();
        JsonObject obj = objects.peek() ;
        if ( obj.hasKey(k) )
            Log.warn("JSON", "Duplicate key '"+k+"' for object ["+currLine+","+currCol+"]") ;
        obj.put(k, value) ;
        value = null ;
    }
View Full Code Here

        return this ;
    }
   
    private void parse(InputStream in)
    {
        JsonObject obj = JSON.parse(in) ;
       
        if ( obj.hasKey(kBoolean) )
        {
            checkContains(obj, kHead, kBoolean) ;
            // TODO check kHead is empty.
            booleanResult = obj.get(kBoolean).getAsBoolean().value() ;
            rows = null ;
            return ;
        }
       
        rows = new ArrayList<Binding>(1000) ;
       
        checkContains(obj, kHead, kResults) ;

        if ( ! obj.hasKey(kHead) )    throw new ResultSetException("No 'head' for results") ;
        if ( ! obj.hasKey(kResults) ) throw new ResultSetException("No 'results' for results") ;
       
        // process head
        if ( ! obj.get(kHead).isObject() )
            throw new ResultSetException("Key 'head' must have a JSON object as value: found: "+obj.get(kHead)) ;
        JsonObject head = obj.get(kHead).getAsObject() ;
       
        // ---- Head
        // -- Link - array.
        if ( head.hasKey(kLink) )
        {
            List<String> links = new ArrayList<String>() ;

            if ( head.get(kLink).isString() )
            {
                Log.warn(this, "Link field is a string, should be an array of strings") ;
                links.add(head.get(kLink).getAsString().value()) ;
            }
            else
            {
                if ( ! head.get(kLink).isArray() )
                    throw new ResultSetException("Key 'link' must have be an array: found: "+obj.get(kLink)) ;

                for ( JsonValue v : head.get(kLink).getAsArray() )
                {
                    if ( ! v.isString() )
                        throw new ResultSetException("Key 'link' must have be an array of strings: found: "+v) ;
                    links.add(v.getAsString().value()) ;
                }
            }
        }
        // -- Vars
        vars = parseVars(head) ;

        // ---- Results
        JsonObject results = obj.get(kResults).getAsObject() ;
        if ( ! results.get(kBindings).isArray() )
            throw new ResultSetException("'bindings' must be an array") ;
        JsonArray array = results.get(kBindings).getAsArray() ;
        Iterator<JsonValue> iter = array.iterator() ;
       
        for ( ; iter.hasNext() ; )
        {
            BindingMap b = BindingFactory.create() ;
            JsonValue v = iter.next() ;
            if ( ! v.isObject() )
                throw new ResultSetException("Entry in 'bindings' array must be an object {}";
            JsonObject x = v.getAsObject() ;
            Set<String> varNames = x.keys() ;
            for ( String vn : varNames )
            {
                if ( ! vars.contains(vn) )
                    ; // Warning
                JsonValue vt = x.get(vn) ;
                if ( ! vt.isObject() )
                    throw new ResultSetException("Binding for variable '"+vn+"' is not a JSON object: "+vt;
                Node n = parseOneTerm(vt.getAsObject()) ;
                b.add(Var.alloc(vn), n) ;
            }
View Full Code Here

TOP

Related Classes of org.openjena.atlas.json.JsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.