info.sswap.api.input.io
Class JSONSerializer

java.lang.Object
  extended by info.sswap.api.input.io.JSONSerializer
All Implemented Interfaces:
InputVisitor, InputSerializer<org.json.JSONObject>

public class JSONSerializer
extends java.lang.Object
implements InputVisitor, InputSerializer<org.json.JSONObject>

Creates a JSON representation of the given Input object. Example output looks as follows:

{
  "type": "http://www.w3.org/2002/07/owl#intersectionOf",
  "inputs": [
    {    
      "type": "http://www.w3.org/2002/07/owl#unionOf",
      "inputs": [
        {        
          "type": "http://www.w3.org/2002/07/owl#Restriction",
          "property": "http://sswapmeet.sswap.info/OBO/id",
          "min": 1,
          "max": 1,
          "range": {"type": "http://www.w3.org/2001/XMLSchema#string"}
        },
        {
          "type": "http://www.w3.org/2002/07/owl#Restriction",          
          "property": "http://sswapmeet.sswap.info/OBO/name",
          "min": 1,
          "max": 1,
          "range": {"type": "http://www.w3.org/2001/XMLSchema#string"}
        }
      ]
    },
    {    
      "type": "http://www.w3.org/2002/07/owl#Restriction",
      "property": "http://plantontology.sswap.info/poAnnotations/ontologies/poAnnotation/ontology",
      "min": 0,
      "max": 1,
      "range": {      
        "type": "http://www.w3.org/2002/07/owl#oneOf",
        "values": [
          {
            "value": "plant_structure",
            "datatype": "http://www.w3.org/2001/XMLSchema#string",
            "type": "literal"
          },
          {
            "value": "plant_growth_and_development_stage",
            "datatype": "http://www.w3.org/2001/XMLSchema#string",
            "type": "literal"
          }
        ]
      }
    }
  ]
}

Author:
Evren Sirin

Field Summary
private  org.json.JSONObject out
           
 
Constructor Summary
JSONSerializer()
           
 
Method Summary
private  void addIfNotNull(org.json.JSONObject target, java.lang.String key, java.lang.Object value)
           
private  org.json.JSONObject newJSONObject(Input input)
           
 org.json.JSONObject serialize(Input input)
          Serializes the given input to an object.
private  org.json.JSONObject serialize(InputValue inputValue)
           
 void visit(AtomicInput input)
          
 void visit(BNodeValue value)
          
 void visit(EnumeratedInput input)
          
 void visit(IntersectionInput intersection)
          
 void visit(LiteralValue value)
          
 void visit(PropertyInput input)
          
 void visit(UnionInput union)
          
 void visit(URIValue value)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

private org.json.JSONObject out
Constructor Detail

JSONSerializer

public JSONSerializer()
Method Detail

serialize

public org.json.JSONObject serialize(Input input)
Description copied from interface: InputSerializer
Serializes the given input to an object.

Specified by:
serialize in interface InputSerializer<org.json.JSONObject>

serialize

private org.json.JSONObject serialize(InputValue inputValue)

newJSONObject

private org.json.JSONObject newJSONObject(Input input)
                                   throws org.json.JSONException
Throws:
org.json.JSONException

addIfNotNull

private void addIfNotNull(org.json.JSONObject target,
                          java.lang.String key,
                          java.lang.Object value)
                   throws org.json.JSONException
Throws:
org.json.JSONException

visit

public void visit(AtomicInput input)

Specified by:
visit in interface InputVisitor

visit

public void visit(IntersectionInput intersection)

Specified by:
visit in interface InputVisitor

visit

public void visit(UnionInput union)

Specified by:
visit in interface InputVisitor

visit

public void visit(EnumeratedInput input)

Specified by:
visit in interface InputVisitor

visit

public void visit(PropertyInput input)

Specified by:
visit in interface InputVisitor

visit

public void visit(URIValue value)

Specified by:
visit in interface InputVisitor

visit

public void visit(BNodeValue value)

Specified by:
visit in interface InputVisitor

visit

public void visit(LiteralValue value)

Specified by:
visit in interface InputVisitor


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.