Class JSONElementWrapper

java.lang.Object
com.iizix.prop.GProp<GProp<?>[]>
com.iizix.prop.PropCnr
com.iizix.ws.prop.json.JSONElementWrapper
All Implemented Interfaces:
EventListener, IGProp<GProp<?>[]>, IPropCnr, Cloneable
Direct Known Subclasses:
EditorJSONElementWrapper

public class JSONElementWrapper extends PropCnr
A JSON element wrapper, used to process the output of a Web Service reply. The wrapper wraps Boolean, Number, String, JSONObject, JSONArray and JSONNull.NULL.
Author:
Christopher Mindus
  • Constructor Details

    • JSONElementWrapper

      public JSONElementWrapper()
      Creates the property container without a name.
    • JSONElementWrapper

      public JSONElementWrapper(Atom propertyAtom)
      Creates the property container.
      Parameters:
      propertyAtom - the name of the component, unique within it's parent.
  • Method Details

    • usesPropIndex

      public boolean usesPropIndex()
      JSON element wrappers are index based.
      Specified by:
      usesPropIndex in interface IPropCnr
      Overrides:
      usesPropIndex in class PropCnr
      Returns:
      true if index is used, false for non-index based container.
    • shouldSerializeToXML

      protected boolean shouldSerializeToXML(int programType)
      Method used to check for serialization to XML.
      Overrides:
      shouldSerializeToXML in class GProp<GProp<?>[]>
      Parameters:
      programType - From PropFactory.getProgramType(): 0=PropFactory.CLIENT, 1=PropFactory.SERVER or 2=PropFactory.EDITOR.
      Returns:
      false to avoid writing the property to XML.
    • createJSONElementWrapper

      protected JSONElementWrapper createJSONElementWrapper(Atom atom)
      Creates a new JSONElementWrapper instance.
    • clone

      Clones the JSONElementWrapper.
      Overrides:
      clone in class PropCnr
      Returns:
      A new wrapper for a cloned JSON element.
      Throws:
      CloneNotSupportedException - For property errors when cloning.
    • getOutputProps

      public OutputProps getOutputProps()
      Gets the Output properties.
      Returns:
      The Output properties, or null if this property is orphan.
    • wrap

      public void wrap(String name, int arrayIndex, Object object) throws PropException, JSONException
      Wraps the JSON "object". This method sets properties in this instance, and creates additional wrapped nested elements as required.
      Parameters:
      name - The name of the object, null for Root or Document element.
      arrayIndex - The index in the array, -1 for not inside an array.
      object - The Object to wrap. It must be one of:
      • Boolean
      • Number
      • String
      • JSONObject
      • JSONArray
      • JSONObject.NULL
      Throws:
      PropException - For property errors.
      JSONException - If it's not a valid object.
      NullPointerException - If object is null.
    • isDocumentElement

      protected boolean isDocumentElement()
      Checks if it's the document element.
    • getWrappedReference

      public String getWrappedReference(boolean attempIndex)
      Gets the reference of this wrapped element.
      Parameters:
      attempIndex - Flag indicating index is required if possible.
      Returns:
      A reference such as "json:/path" where an element that could be a row element is assigned the row index.
    • getName

      public String getName()
      Gets the wrapped JSON element name.
      Returns:
      The name, or null for JSON document element.
    • getIndex

      public int getIndex()
      Gets the wrapped element index if inside an array.
      Returns:
      The array index, or -1 if not inside an array.
    • getJSONElement

      public Object getJSONElement()
      Gets the wrapped JSON element.
      Returns:
      The wrapped element value, one of:
      • Boolean
      • Number
      • String
      • JSONObject
      • JSONArray
      • JSONObject.NULL