Package com.dd.plist

Class NSObject

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

public abstract class NSObject extends Object implements Cloneable, 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 Details

    • NEWLINE

      static final 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:
    • INDENT

      private static final String INDENT
      The indentation character used for generating the XML output. This is the tabulator character.
      See Also:
  • Constructor Details

    • NSObject

      public NSObject()
  • Method Details

    • clone

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

      public abstract 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 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(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 IOException
      Generates the binary representation of the object.
      Parameters:
      out - The output stream to serialize the object to.
      Throws:
      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(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(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(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(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:
      IllegalArgumentException - If the specified class cannot be deserialized from this NSObject.
    • fromJavaObject

      public static NSObject fromJavaObject(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:
      IllegalArgumentException - If the specified object throws an exception while getting its properties.
    • isSimple

      private static boolean isSimple(Class<?> clazz)
    • getInstance

      private static Object getInstance(Class<?> clazz)
    • getClassForName

      private static Class<?> getClassForName(String className)
    • makeFirstCharLowercase

      private static String makeFirstCharLowercase(String input)
    • toJavaObject

      private Object toJavaObject(NSObject payload, Class<?> clazz, Type[] types)
    • deserializeObject

      private Object deserializeObject(NSDictionary payload, Class<?> clazz, Type[] types)
    • deserializeMap

      private Object deserializeMap(Class<?> clazz, Type[] types, Map<String,NSObject> map)
    • deserializeCollection

      private Object deserializeCollection(NSObject payload, Class<?> clazz, Type[] types)
    • deserializeArray

      private Object deserializeArray(NSObject payload, Class<?> clazz)
    • deserializeData

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

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

      private static Date deserializeDate(NSDate date, Class<?> clazz)
    • deserializeNumber

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

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

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

      private static NSDictionary fromMap(Map<?,?> map)
    • fromArray

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

      private static NSData fromData(Object object)
    • fromCollection

      private static NSArray fromCollection(Collection<?> collection)
    • fromSet

      private static NSSet fromSet(Set<?> set)