Class JSONElementWrapper

  • All Implemented Interfaces:
    EventListener, IGProp<GProp<?>[]>, IPropCnr, java.lang.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 Detail

      • 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 Detail

      • 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.
      • createJSONElementWrapper

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

        public JSONElementWrapper clone()
                                 throws java.lang.CloneNotSupportedException
        Clones the JSONElementWrapper.
        Overrides:
        clone in class PropCnr
        Returns:
        A new wrapper for a cloned JSON element.
        Throws:
        java.lang.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​(java.lang.String name,
                         int arrayIndex,
                         java.lang.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.
        java.lang.NullPointerException - If object is null.
      • isDocumentElement

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

        public java.lang.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 java.lang.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 java.lang.Object getJSONElement()
        Gets the wrapped JSON element.
        Returns:
        The wrapped element value, one of:
        • Boolean
        • Number
        • String
        • JSONObject
        • JSONArray
        • JSONObject.NULL