Package com.dd.plist

Class NSObject

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<NSObject>
    Direct Known Subclasses:
    NSArray, NSData, NSDate, NSDictionary, NSNull, NSNumber, NSSet, NSString, UID

    public abstract class NSObject
    extends java.lang.Object
    implements java.lang.Cloneable, java.lang.Comparable<NSObject>
    Abstract interface for an object contained in a property list. The names and functions of the various objects orient themselves towards Apple's Cocoa API.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int ASCII_LINE_LENGTH
      The maximum length of the text lines to be used when generating ASCII property lists.
      private static java.lang.String INDENT
      The indentation character used for generating the XML output.
      (package private) static java.lang.String NEWLINE
      The newline character used for generating the XML output.
    • Constructor Summary

      Constructors 
      Constructor Description
      NSObject()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void assignIDs​(BinaryPropertyListWriter out)
      Assigns IDs to all the objects in this NSObject subtree.
      abstract NSObject clone()
      Creates and returns a deep copy of this instance.
      private java.lang.Object deserializeArray​(NSObject payload, java.lang.Class<?> clazz)  
      private java.lang.Object deserializeCollection​(NSObject payload, java.lang.Class<?> clazz, java.lang.reflect.Type[] types)  
      private static java.lang.Object deserializeData​(NSData payload, java.lang.Class<?> elementClass)  
      private static java.util.Date deserializeDate​(NSDate date, java.lang.Class<?> clazz)  
      private java.lang.Object deserializeMap​(java.lang.Class<?> clazz, java.lang.reflect.Type[] types, java.util.Map<java.lang.String,​NSObject> map)  
      private static java.lang.Object deserializeNumber​(NSNumber number, java.lang.Class<?> clazz)  
      private java.lang.Object deserializeObject​(NSDictionary payload, java.lang.Class<?> clazz, java.lang.reflect.Type[] types)  
      private static java.lang.Object deserializeSimple​(NSObject payload, java.lang.Class<?> clazz)  
      private static NSObject fromArray​(java.lang.Object object, java.lang.Class<?> objClass)  
      private static NSArray fromCollection​(java.util.Collection<?> collection)  
      private static NSData fromData​(java.lang.Object object)  
      static NSObject fromJavaObject​(java.lang.Object object)
      Serializes the specified object into an NSObject.
      private static NSDictionary fromMap​(java.util.Map<?,​?> map)  
      private static NSDictionary fromPojo​(java.lang.Object object, java.lang.Class<?> objClass)  
      private static NSSet fromSet​(java.util.Set<?> set)  
      private static NSObject fromSimple​(java.lang.Object object, java.lang.Class<?> objClass)  
      private static java.lang.Class<?> getClassForName​(java.lang.String className)  
      private static java.lang.Object getInstance​(java.lang.Class<?> clazz)  
      protected void indent​(java.lang.StringBuilder xml, int level)
      Helper method that adds correct indentation to the xml output.
      private static boolean isSimple​(java.lang.Class<?> clazz)  
      private static java.lang.String makeFirstCharLowercase​(java.lang.String input)  
      (package private) abstract void toASCII​(java.lang.StringBuilder ascii, int level)
      Generates the ASCII representation of this object.
      (package private) abstract void toASCIIGnuStep​(java.lang.StringBuilder ascii, int level)
      Generates the ASCII representation of this object in the GnuStep format.
      (package private) abstract void toBinary​(BinaryPropertyListWriter out)
      Generates the binary representation of the object.
      abstract java.lang.Object toJavaObject()
      Converts this NSObject into an equivalent object of the Java Runtime Environment.
      private java.lang.Object toJavaObject​(NSObject payload, java.lang.Class<?> clazz, java.lang.reflect.Type[] types)  
      <T> T toJavaObject​(java.lang.Class<T> clazz)
      Converts this NSObject into an object of the specified class.
      (package private) abstract void toXML​(java.lang.StringBuilder xml, int level)
      Generates the XML representation of the object (without XML headers or enclosing plist-tags).
      java.lang.String toXMLPropertyList()
      Generates a valid XML property list including headers using this object as root.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Comparable

        compareTo
    • Field Detail

      • NEWLINE

        static final java.lang.String NEWLINE
        The newline character used for generating the XML output. This constant will be different depending on the operating system on which you use this library.
      • ASCII_LINE_LENGTH

        static final int ASCII_LINE_LENGTH
        The maximum length of the text lines to be used when generating ASCII property lists. But this number is only a guideline it is not guaranteed that it will not be overstepped.
        See Also:
        Constant Field Values
      • INDENT

        private static final java.lang.String INDENT
        The indentation character used for generating the XML output. This is the tabulator character.
        See Also:
        Constant Field Values
    • Constructor Detail

      • NSObject

        public NSObject()
    • Method Detail

      • clone

        public abstract NSObject clone()
        Creates and returns a deep copy of this instance.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone of this instance.
      • toJavaObject

        public abstract java.lang.Object toJavaObject()
        Converts this NSObject into an equivalent object of the Java Runtime Environment.
        • NSArray objects are converted to arrays.
        • NSDictionary objects are converted to objects extending the Map class.
        • NSSet objects are converted to objects extending the Set class.
        • NSNumber objects are converted to primitive number values (int, long, double or boolean).
        • NSString objects are converted to String objects.
        • NSData objects are converted to byte arrays.
        • NSDate objects are converted to Date objects.
        • UID objects are converted to byte arrays.
        Returns:
        A native java object representing this NSObject's value.
      • toXMLPropertyList

        public java.lang.String toXMLPropertyList()
        Generates a valid XML property list including headers using this object as root.
        Returns:
        The XML representation of the property list including XML header and doctype information.
      • toXML

        abstract void toXML​(java.lang.StringBuilder xml,
                            int level)
        Generates the XML representation of the object (without XML headers or enclosing plist-tags).
        Parameters:
        xml - The StringBuilder onto which the XML representation is appended.
        level - The indentation level of the object.
      • assignIDs

        void assignIDs​(BinaryPropertyListWriter out)
        Assigns IDs to all the objects in this NSObject subtree.
        Parameters:
        out - The writer object that handles the binary serialization.
      • toBinary

        abstract void toBinary​(BinaryPropertyListWriter out)
                        throws java.io.IOException
        Generates the binary representation of the object.
        Parameters:
        out - The output stream to serialize the object to.
        Throws:
        java.io.IOException - If an I/O error occurs while writing to the stream or the object structure contains data that cannot be saved.
      • toASCII

        abstract void toASCII​(java.lang.StringBuilder ascii,
                              int level)
        Generates the ASCII representation of this object. The generated ASCII representation does not end with a newline. Complies with the Old-Style ASCII Property Lists definition.
        Parameters:
        ascii - The StringBuilder onto which the ASCII representation is appended.
        level - The indentation level of the object.
      • toASCIIGnuStep

        abstract void toASCIIGnuStep​(java.lang.StringBuilder ascii,
                                     int level)
        Generates the ASCII representation of this object in the GnuStep format. The generated ASCII representation does not end with a newline.
        Parameters:
        ascii - The StringBuilder onto which the ASCII representation is appended.
        level - The indentation level of the object.
      • indent

        protected void indent​(java.lang.StringBuilder xml,
                              int level)
        Helper method that adds correct indentation to the xml output. Calling this method will add level number of tab characters to the xml string.
        Parameters:
        xml - The StringBuilder onto which the XML representation is appended.
        level - The level of indentation.
      • toJavaObject

        public <T> T toJavaObject​(java.lang.Class<T> clazz)
        Converts this NSObject into an object of the specified class.
        Type Parameters:
        T - The target object type.
        Parameters:
        clazz - The target class.
        Returns:
        A new instance of the specified class, deserialized from this NSObject.
        Throws:
        java.lang.IllegalArgumentException - If the specified class cannot be deserialized from this NSObject.
      • fromJavaObject

        public static NSObject fromJavaObject​(java.lang.Object object)
        Serializes the specified object into an NSObject. Objects which do not have a direct type correspondence to an NSObject type will be serialized as a NSDictionary. The dictionary will contain the values of all publicly accessible fields and properties.
        Parameters:
        object - The object to serialize.
        Returns:
        A NSObject instance.
        Throws:
        java.lang.IllegalArgumentException - If the specified object throws an exception while getting its properties.
      • isSimple

        private static boolean isSimple​(java.lang.Class<?> clazz)
      • getInstance

        private static java.lang.Object getInstance​(java.lang.Class<?> clazz)
      • getClassForName

        private static java.lang.Class<?> getClassForName​(java.lang.String className)
      • makeFirstCharLowercase

        private static java.lang.String makeFirstCharLowercase​(java.lang.String input)
      • toJavaObject

        private java.lang.Object toJavaObject​(NSObject payload,
                                              java.lang.Class<?> clazz,
                                              java.lang.reflect.Type[] types)
      • deserializeObject

        private java.lang.Object deserializeObject​(NSDictionary payload,
                                                   java.lang.Class<?> clazz,
                                                   java.lang.reflect.Type[] types)
      • deserializeMap

        private java.lang.Object deserializeMap​(java.lang.Class<?> clazz,
                                                java.lang.reflect.Type[] types,
                                                java.util.Map<java.lang.String,​NSObject> map)
      • deserializeCollection

        private java.lang.Object deserializeCollection​(NSObject payload,
                                                       java.lang.Class<?> clazz,
                                                       java.lang.reflect.Type[] types)
      • deserializeArray

        private java.lang.Object deserializeArray​(NSObject payload,
                                                  java.lang.Class<?> clazz)
      • deserializeData

        private static java.lang.Object deserializeData​(NSData payload,
                                                        java.lang.Class<?> elementClass)
      • deserializeSimple

        private static java.lang.Object deserializeSimple​(NSObject payload,
                                                          java.lang.Class<?> clazz)
      • deserializeDate

        private static java.util.Date deserializeDate​(NSDate date,
                                                      java.lang.Class<?> clazz)
      • deserializeNumber

        private static java.lang.Object deserializeNumber​(NSNumber number,
                                                          java.lang.Class<?> clazz)
      • fromSimple

        private static NSObject fromSimple​(java.lang.Object object,
                                           java.lang.Class<?> objClass)
      • fromPojo

        private static NSDictionary fromPojo​(java.lang.Object object,
                                             java.lang.Class<?> objClass)
      • fromMap

        private static NSDictionary fromMap​(java.util.Map<?,​?> map)
      • fromArray

        private static NSObject fromArray​(java.lang.Object object,
                                          java.lang.Class<?> objClass)
      • fromData

        private static NSData fromData​(java.lang.Object object)
      • fromCollection

        private static NSArray fromCollection​(java.util.Collection<?> collection)
      • fromSet

        private static NSSet fromSet​(java.util.Set<?> set)