Package com.dd.plist
Class NSObject
- java.lang.Object
-
- com.dd.plist.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 intASCII_LINE_LENGTHThe maximum length of the text lines to be used when generating ASCII property lists.private static java.lang.StringINDENTThe indentation character used for generating the XML output.(package private) static java.lang.StringNEWLINEThe 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) voidassignIDs(BinaryPropertyListWriter out)Assigns IDs to all the objects in this NSObject subtree.abstract NSObjectclone()Creates and returns a deep copy of this instance.private java.lang.ObjectdeserializeArray(NSObject payload, java.lang.Class<?> clazz)private java.lang.ObjectdeserializeCollection(NSObject payload, java.lang.Class<?> clazz, java.lang.reflect.Type[] types)private static java.lang.ObjectdeserializeData(NSData payload, java.lang.Class<?> elementClass)private static java.util.DatedeserializeDate(NSDate date, java.lang.Class<?> clazz)private java.lang.ObjectdeserializeMap(java.lang.Class<?> clazz, java.lang.reflect.Type[] types, java.util.Map<java.lang.String,NSObject> map)private static java.lang.ObjectdeserializeNumber(NSNumber number, java.lang.Class<?> clazz)private java.lang.ObjectdeserializeObject(NSDictionary payload, java.lang.Class<?> clazz, java.lang.reflect.Type[] types)private static java.lang.ObjectdeserializeSimple(NSObject payload, java.lang.Class<?> clazz)private static NSObjectfromArray(java.lang.Object object, java.lang.Class<?> objClass)private static NSArrayfromCollection(java.util.Collection<?> collection)private static NSDatafromData(java.lang.Object object)static NSObjectfromJavaObject(java.lang.Object object)Serializes the specified object into an NSObject.private static NSDictionaryfromMap(java.util.Map<?,?> map)private static NSDictionaryfromPojo(java.lang.Object object, java.lang.Class<?> objClass)private static NSSetfromSet(java.util.Set<?> set)private static NSObjectfromSimple(java.lang.Object object, java.lang.Class<?> objClass)private static java.lang.Class<?>getClassForName(java.lang.String className)private static java.lang.ObjectgetInstance(java.lang.Class<?> clazz)protected voidindent(java.lang.StringBuilder xml, int level)Helper method that adds correct indentation to the xml output.private static booleanisSimple(java.lang.Class<?> clazz)private static java.lang.StringmakeFirstCharLowercase(java.lang.String input)(package private) abstract voidtoASCII(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object.(package private) abstract voidtoASCIIGnuStep(java.lang.StringBuilder ascii, int level)Generates the ASCII representation of this object in the GnuStep format.(package private) abstract voidtoBinary(BinaryPropertyListWriter out)Generates the binary representation of the object.abstract java.lang.ObjecttoJavaObject()Converts this NSObject into an equivalent object of the Java Runtime Environment.private java.lang.ObjecttoJavaObject(NSObject payload, java.lang.Class<?> clazz, java.lang.reflect.Type[] types)<T> TtoJavaObject(java.lang.Class<T> clazz)Converts this NSObject into an object of the specified class.(package private) abstract voidtoXML(java.lang.StringBuilder xml, int level)Generates the XML representation of the object (without XML headers or enclosing plist-tags).java.lang.StringtoXMLPropertyList()Generates a valid XML property list including headers using this object as root.
-
-
-
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
-
-
Method Detail
-
clone
public abstract NSObject clone()
Creates and returns a deep copy of this instance.- Overrides:
clonein classjava.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.NSArrayobjects are converted to arrays.NSDictionaryobjects are converted to objects extending theMapclass.NSSetobjects are converted to objects extending theSetclass.NSNumberobjects are converted to primitive number values (int, long, double or boolean).NSStringobjects are converted toStringobjects.NSDataobjects are converted to byte arrays.NSDateobjects are converted toDateobjects.UIDobjects 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- TheStringBuilderonto 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- TheStringBuilderonto 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- TheStringBuilderonto 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 addlevelnumber of tab characters to thexmlstring.- Parameters:
xml- TheStringBuilderonto 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 aNSDictionary. 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)
-
-