/// <summary> /// Write the specified object to the output stream. /// The serialized form will denote a series of /// expressions, the combined effect of which will create /// an equivalent object when the input stream is read. /// By default, the object is assumed to be a <em>JavaBean</em> /// with a nullary constructor, whose state is defined by /// the matching pairs of "setter" and "getter" methods /// returned by the Introspector. /// </summary> /// <param name="o"> The object to be written to the stream. /// </param> /// <seealso cref= XMLDecoder#readObject </seealso> protected internal virtual void WriteObject(Object o) { if (o == this) { return; } PersistenceDelegate info = GetPersistenceDelegate(o == null ? null : o.GetType()); info.WriteObject(o, this); }
/// <summary> /// Returns the persistence delegate for the given type. /// The persistence delegate is calculated by applying /// the following rules in order: /// <ol> /// <li> /// If a persistence delegate is associated with the given type /// by using the <seealso cref="#setPersistenceDelegate"/> method /// it is returned. /// <li> /// A persistence delegate is then looked up by the name /// composed of the the fully qualified name of the given type /// and the "PersistenceDelegate" postfix. /// For example, a persistence delegate for the {@code Bean} class /// should be named {@code BeanPersistenceDelegate} /// and located in the same package. /// <pre> /// public class Bean { ... } /// public class BeanPersistenceDelegate { ... }</pre> /// The instance of the {@code BeanPersistenceDelegate} class /// is returned for the {@code Bean} class. /// <li> /// If the type is {@code null}, /// a shared internal persistence delegate is returned /// that encodes {@code null} value. /// <li> /// If the type is a {@code enum} declaration, /// a shared internal persistence delegate is returned /// that encodes constants of this enumeration /// by their names. /// <li> /// If the type is a primitive type or the corresponding wrapper, /// a shared internal persistence delegate is returned /// that encodes values of the given type. /// <li> /// If the type is an array, /// a shared internal persistence delegate is returned /// that encodes an array of the appropriate type and length, /// and each of its elements as if they are properties. /// <li> /// If the type is a proxy, /// a shared internal persistence delegate is returned /// that encodes a proxy instance by using /// the <seealso cref="java.lang.reflect.Proxy#newProxyInstance"/> method. /// <li> /// If the <seealso cref="BeanInfo"/> for this type has a <seealso cref="BeanDescriptor"/> /// which defined a "persistenceDelegate" attribute, /// the value of this named attribute is returned. /// <li> /// In all other cases the default persistence delegate is returned. /// The default persistence delegate assumes the type is a <em>JavaBean</em>, /// implying that it has a default constructor and that its state /// may be characterized by the matching pairs of "setter" and "getter" /// methods returned by the <seealso cref="Introspector"/> class. /// The default constructor is the constructor with the greatest number /// of parameters that has the <seealso cref="ConstructorProperties"/> annotation. /// If none of the constructors has the {@code ConstructorProperties} annotation, /// then the nullary constructor (constructor with no parameters) will be used. /// For example, in the following code fragment, the nullary constructor /// for the {@code Foo} class will be used, /// while the two-parameter constructor /// for the {@code Bar} class will be used. /// <pre> /// public class Foo { /// public Foo() { ... } /// public Foo(int x) { ... } /// } /// public class Bar { /// public Bar() { ... } /// @ConstructorProperties({"x"}) /// public Bar(int x) { ... } /// @ConstructorProperties({"x", "y"}) /// public Bar(int x, int y) { ... } /// }</pre> /// </ol> /// </summary> /// <param name="type"> the class of the objects </param> /// <returns> the persistence delegate for the given type /// </returns> /// <seealso cref= #setPersistenceDelegate </seealso> /// <seealso cref= java.beans.Introspector#getBeanInfo </seealso> /// <seealso cref= java.beans.BeanInfo#getBeanDescriptor </seealso> public virtual PersistenceDelegate GetPersistenceDelegate(Class type) { PersistenceDelegate pd = this.Finder.find(type); if (pd == null) { pd = MetaData.GetPersistenceDelegate(type); if (pd != null) { this.Finder.register(type, pd); } } return(pd); }
/// <summary> /// Associates the specified persistence delegate with the given type. /// </summary> /// <param name="type"> the class of objects that the specified persistence delegate applies to </param> /// <param name="delegate"> the persistence delegate for instances of the given type /// </param> /// <seealso cref= #getPersistenceDelegate </seealso> /// <seealso cref= java.beans.Introspector#getBeanInfo </seealso> /// <seealso cref= java.beans.BeanInfo#getBeanDescriptor </seealso> public virtual void SetPersistenceDelegate(Class type, PersistenceDelegate @delegate) { this.Finder.register(type, @delegate); }