public static IlpDefaultAttribute EXISTS =
new IlpDefaultAttribute("exists",Boolean.class, true);
public static IlpDefaultAttribute NAME =
new IlpDefaultAttribute("name",String.class, true);
public static IlpDefaultAttribute PARENT =
new IlpDefaultAttribute("parent",String.class, true);
public static IlpDefaultAttribute PATH =
new IlpDefaultAttribute("path",String.class, true);
public static IlpDefaultAttribute DIRECTORY =
new IlpDefaultAttribute("directory",Boolean.class, true);
public static IlpDefaultAttribute HIDDEN =
new IlpDefaultAttribute("hidden",Boolean.class, true);
public static IlpDefaultAttribute LASTMODIFIED =
new IlpDefaultAttribute("lastModified", Long.class, true);
public static IlpDefaultAttribute LASTMODIFIEDDATE =
new IlpDefaultAttribute("lastModifiedDate", Date.class, true);
public static IlpDefaultAttribute LENGTH =
new IlpDefaultAttribute("length", Long.class, true);
public static IlpDefaultAttribute ROOT =
new IlpDefaultAttribute("root", Boolean.class, true);
protected static IlpDefaultClass ILPCLASS;
static {
ILPCLASS = new IlpDefaultClass("FileObject") {
/**
* This method is called when objects are loaded from XML.
*/
public IlpObject newInstance(IlpClass ilpClass, Object identifier,
boolean initializeAttributeValues) {
return new FileObject((File)identifier,ilpClass);
}
};
ILPCLASS.addAttribute(EXISTS);
ILPCLASS.addAttribute(NAME);
ILPCLASS.addAttribute(PARENT);
ILPCLASS.addAttribute(PATH);
ILPCLASS.addAttribute(DIRECTORY);
ILPCLASS.addAttribute(HIDDEN);
ILPCLASS.addAttribute(LASTMODIFIED);
ILPCLASS.addAttribute(LASTMODIFIEDDATE);
ILPCLASS.addAttribute(LENGTH);
ILPCLASS.addAttribute(ROOT);
}
In this sample code, you have created the
IlpClass as an
IlpDefaultClass with a specific
implementation of the
newInstance
method. This method is used to create objects read from an XML
file. Its implementation depends entirely on the case you have to
handle. Note that you do not need to implement the
newInstance
method if you do not intend to use XML with your
IlpClass
.
Here the
FileObject
class uses a
File
as its identifier with all its content. The
IlpClass
parameter allows you to subclass
IlpClass
. The parameter
initializeAttributeValues
has the same meaning as in the XML format. See
Elements in an XML data file . Here you do
not use that parameter because there are no default attribute
values.
The class manager is not aware of this new
IlpClass
. You have to define a static method called
GetIlpClass
in your implementation of
IlpObject
to have that class registered with the class manager
automatically.
If your Java classes include attributes, you can write an
implementation of
IlpObject that will act as a wrapper. This
wrapper will delegate methods to the underlying Java object to
access its attributes. This implementation of
IlpObject
is described by an
IlpClass.
The main methods to implement are the
following:
public static IlpClass GetIlpClass
—This method should return the corresponding
IlpClass
. This method tells the class manager how to retrieve the
IlpClass
corresponding to the Java class. When its
getClass
method is called with the Java class as its parameter, the
class manager loads the Java class from its name (
Class.forName
) and calls the
GetIlpClass
method that retrieves the
IlpClass
. This way, your
IlpClass
is automatically registered with all the class managers that
may use it.
Note
If you do not want a given Java class to be considered as a
JavaBean™ and cannot add the static method
GetIlpClass
to that class, you can register an
IlpClass
that has the same name as the Java class before the class
name is queried from the class manager.
public Object getIdentifier
—This method must return an identifier. This identifier can be
the underlying Java object, an attribute, or another
identifier stored in the implementation of
IlpObject
.
public IlpClass getIlpClass()
—This method returns the
IlpClass
. Usually, you have to store the
IlpClass
as a Java attribute of your
IlpObject
implementation to support subclasses. If you do not want to
support subclasses, you can return the result of the static
GetIlpClass()
method.
public Object getAttributeValue
(IlpAttribute attribute)
—This method returns the value of an attribute. Therefore, it
results in a call to a method of the delegate Java object.
public void setAttributeValue
(IlpAttribute attribute, Object value)
—This method sets the value of an attribute. It is not meant
to be supported for all attributes. If supported, it usually
results in a call to a method of the delegate Java object.
public Object getAttributeValue
(String attributeName)
—This method returns the value of an attribute, given the
attribute name. Therefore, it results in a call to a method of
the delegate Java object.
public void setAttributeValue
(String attributeName, Object value)
—This method sets the value of an attribute. It is not meant
to be supported for all attributes. If supported, it usually
results in a call to a method of the delegate Java object.