JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.datasource.beans
Class SerializedProperties

java.lang.Object
  |
  +--com.klg.jclass.datasource.beans.SerializedProperties
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
GridProperties, NodeProperties, TreeProperties

public class SerializedProperties
extends Object
implements Serializable

Serializes and deserializes a bean component to/from a file. Serialization file is a physical file that serialized a bean component. It is used at design-time. When the bean component is deployed, there is no guarantee that the serialization file saved at design-time is located at a directory that is accessible at run-time. Thus, a resource name relative to a class loader is used to specify where to get the serialized bean component.

A resource is identified by a String that is /-separated sequence of substrings. e.g. resource/jclass/datasource/mydb.ser

See Also:
ClassLoader, Serialized Form

Field Summary
protected  String defaultSerializationFileBase
          Default serialization file (base part) at design time.
protected  String resourceName
          resource name relative to a class loader.
protected  String serializationFile
          Serialization file for this bean component at design time.
 
Constructor Summary
SerializedProperties()
           
 
Method Summary
 void addJCDataListener(com.klg.jclass.datasource.beans.JCDataListener listener)
          Adds the specified listener to receive JCDataEvent objects.
 void fireJCDataEvent(com.klg.jclass.datasource.beans.JCDataEvent event)
          Inform registered listeners of a JCDataEvent.
static com.klg.jclass.datasource.beans.SerializedProperties fromFile(String file)
          Deserializes a serialization file to get a bean component.
static com.klg.jclass.datasource.beans.SerializedProperties fromResource(ClassLoader cl, String resource_name)
          Instantiates a SerializedProperties from a resource.
static com.klg.jclass.datasource.beans.SerializedProperties fromResource(Class caller_class, String resource_name)
          Instantiates a SerializedProperties from a resource.
protected static String getDefaultSerializationFile(String base, int counter)
          Gets a default serialization file name.
 String getDefaultSerializationFileToOpen()
          Gets a default serialization file name to open.
 String getResourceName()
          Gets resource name relative to a class loader.
 String getSerializationFile()
          Gets the bean component serialization file.
 boolean isResourceNameSpecified()
          Indicates if resource name has been specified.
protected  boolean isSameString(String s1, String s2)
          Returns if two strings are equal.
 boolean isSerializationRequired()
          Indicates if serialization is required.
 void removeJCDataListener(com.klg.jclass.datasource.beans.JCDataListener listener)
          Removes the specified listener so it no longer receives JCDataEvent objects.
protected  void setChanged()
          Override to set isSerializationRequired to true.
protected  void setDefaultSerializationFileBase(String base)
          Sets the default serialization file base part.
 void setResourceName(String s)
          Sets resource name relative to a class loader.
 void setSerializationFile(String s)
          Sets the bean component serialization file.
static void toFile(com.klg.jclass.datasource.beans.SerializedProperties comp, String file)
          Serializes the bean component to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serializationFile

protected String serializationFile
Serialization file for this bean component at design time.


resourceName

protected String resourceName
resource name relative to a class loader. It is used at run-time to get the bean component.


defaultSerializationFileBase

protected String defaultSerializationFileBase
Default serialization file (base part) at design time.

Constructor Detail

SerializedProperties

public SerializedProperties()
Method Detail

setSerializationFile

public void setSerializationFile(String s)
Sets the bean component serialization file.


getSerializationFile

public String getSerializationFile()
Gets the bean component serialization file.


setResourceName

public void setResourceName(String s)
Sets resource name relative to a class loader. It is used at run-time to get the bean component.


getResourceName

public String getResourceName()
Gets resource name relative to a class loader. It is used at run-time to get the bean component.


isResourceNameSpecified

public boolean isResourceNameSpecified()
Indicates if resource name has been specified.

Returns:
True if resource name is present.

isSerializationRequired

public boolean isSerializationRequired()
Indicates if serialization is required. Serialization is required when a change to the serialized bean component is made. isSerializationRequired is reset after the bean component is saved to a file.


fromResource

public static com.klg.jclass.datasource.beans.SerializedProperties fromResource(ClassLoader cl,
                                                                                String resource_name)
                                                                         throws ClassNotFoundException,
                                                                                IOException
Instantiates a SerializedProperties from a resource.

Parameters:
cl - class loader used to get the resource.
resource_name - resource name relative to a class loader to the bean component. It must have the right extension.
Throws:
ClassNotFoundException - If the class can't be loaded.
IOException - If an IO exception occurs.
See Also:
ClassLoader

fromResource

public static com.klg.jclass.datasource.beans.SerializedProperties fromResource(Class caller_class,
                                                                                String resource_name)
                                                                         throws ClassNotFoundException,
                                                                                IOException
Instantiates a SerializedProperties from a resource. First, the package name of the caller class is prepended to the resource name to locate the resource. If it fails, the resource name is used.

Parameters:
caller_class - class that uses the serialized bean component.
resource_name - resource name relative to a class loader to the bean component. It must have right extension.
Throws:
ClassNotFoundException - If the class can't be loaded.
IOException - If an IO exception occurs.
See Also:
ClassLoader

fromFile

public static com.klg.jclass.datasource.beans.SerializedProperties fromFile(String file)
                                                                     throws FileNotFoundException,
                                                                            ClassNotFoundException,
                                                                            IOException
Deserializes a serialization file to get a bean component.

Parameters:
file - serialization file. Itmust have the right extension.
Throws:
FileNotFoundException - If the file find operation fails.
ClassNotFoundException - If the class cannot be found.
IOException - If an IO exception occurs.

toFile

public static void toFile(com.klg.jclass.datasource.beans.SerializedProperties comp,
                          String file)
                   throws FileNotFoundException,
                          IOException
Serializes the bean component to a file.

Parameters:
comp - bean component to be serialized.
file - name of the file used to serialize the bean component.
FileNotFoundException
IOException

getDefaultSerializationFile

protected static String getDefaultSerializationFile(String base,
                                                    int counter)
Gets a default serialization file name. The file name is in the form of base + number + the serialization extension. If a file already exists, the passed in counter is incremented unless there is no file for the derived name.


setDefaultSerializationFileBase

protected void setDefaultSerializationFileBase(String base)
Sets the default serialization file base part.


getDefaultSerializationFileToOpen

public String getDefaultSerializationFileToOpen()
Gets a default serialization file name to open. The file name is in the form of base + number + the serialization extension. If a file does not exist, null is returned.


isSameString

protected boolean isSameString(String s1,
                               String s2)
Returns if two strings are equal. They are considered equal if both of them are null.


setChanged

protected void setChanged()
Override to set isSerializationRequired to true.


addJCDataListener

public void addJCDataListener(com.klg.jclass.datasource.beans.JCDataListener listener)
Adds the specified listener to receive JCDataEvent objects.

Parameters:
listener - A listener.

removeJCDataListener

public void removeJCDataListener(com.klg.jclass.datasource.beans.JCDataListener listener)
Removes the specified listener so it no longer receives JCDataEvent objects.

Parameters:
listener - A listener.

fireJCDataEvent

public void fireJCDataEvent(com.klg.jclass.datasource.beans.JCDataEvent event)
Inform registered listeners of a JCDataEvent.

Parameters:
event - The JCDataEvent.
Returns:
true if the event was accepted by all listeners, or false as soon as any listener cancels the change.

Copyright © 2004 Quest Software Inc..
All rights reserved.