public abstract class Resource
extends java.lang.Object
implements java.io.Serializable
One example of a concrete subclass of Resource is
RUser
which represents a system user. RUser supports
many attribute IDs,
each of which can be used to get
attribute values. Here is an example which retrieves an attribute
value from an RUser:
// Create an RUser object to refer to a specific user. AS400 system = new AS400("MYSYSTEM", "MYUSERID", "MYPASSWORD"); RUser user = new RUser(system, "AUSERID");
// Get the text description attribute value. String textDescription = (String)user.getAttributeValue(RUser.TEXT_DESCRIPTION);
In addition to using concrete subclasses directly, you
can write generic code to work with any Resource subclass.
Such code may improve reusability and maintainability and will
work with future Resource subclasses without modification.
Every attribute has an associated attribute
meta data
object which describes various properties of the attribute.
The attribute meta data can come in handy when writing generic
code. Here is an example of generic code which prints the
value of every attribute supported by a Resource:
void printAllAttributeValues(Resource resource) throws ResourceException { // Get the attribute meta data. ResourceMetaData[] attributeMetaData = resource.getAttributeMetaData();
// Loop through all attributes and print the values. for(int i = 0; i < attributeMetaData.length; ++i) { Object attributeID = attributeMetaData[i].getID(); Object value = resource.getAttributeValue(attributeID); System.out.println("Attribute " + attributeID + " = " + value); } }
Every Resource and attribute meta data object has an associated
Presentation
object which provides translated information about the Resource
or attribute. You can use the Presentation information to
present Resources and attributes to end users. This example
prints a Resource and attribute using their Presentations:
void printSingleAttributeValue(Resource resource, Object attributeID) throws ResourceException { // Get the presentation for the Resource and print its full name. Presentation resourcePresentation = resource.getPresentation(); System.out.println(resourcePresentation.getFullName());
// Get the attribute meta data and the associated Presention. ResourceMetaData attributeMetaData = resource.getAttributeMetaData(attributeID); Presentation attributePresentation = attributeMetaData.getPresentation();
// Get the attribute value and print it. Object value = resource.getAttributeValue(attributeID); System.out.println(attributePresentation.getName() + " = " + value); }
The Resource abstract class only provides read access to the attribute
values. ChangeableResource
,
which is a subclass of Resource, adds methods which provide write access to
the attribute values.
Subclass notes:
If you are extending this class to override the mechanism for getting
attribute values, consider whether you need to support bidirectional
character conversion. If you do not plan to support bidirectional character
conversion, then you only need to override
getAttributeValue(Object)
.
If you do plan to support bidirectional character conversion, then you need
to override isBidiEnabled()
to return true
and getAttributeValue(Object, int)
.
In either case, the overriding method should call the superclass's method of the same name and perform extra processing only when null is returned:
public Object getAttributeValue(Object attributeID) throws ResourceException { // Call the superclass first. Object value = super.getAttributeValue(attributeID); if (value == null) {
// Establish the connection if needed. if (! isConnectionEstablished()) establishConnection();
// Go get the attribute value. value = ...; } return value; }
ResourceList
,
Serialized FormConstructor and Description |
---|
Resource()
Deprecated.
Constructs a Resource object.
|
Resource(Presentation presentation,
java.lang.Object resourceKey,
ResourceMetaData[] attributeMetaData)
Deprecated.
Constructs a Resource object.
|
Resource(Presentation presentation,
java.lang.Object resourceKey,
ResourceMetaData[] attributeMetaData,
java.util.Dictionary values)
Deprecated.
Constructs a Resource object.
|
Resource(Presentation presentation,
java.lang.Object resourceKey,
ResourceMetaDataTable attributes)
Deprecated.
Constructs a Resource object.
|
Modifier and Type | Method and Description |
---|---|
void |
addActiveStatusListener(ActiveStatusListener listener)
Deprecated.
Adds an ActiveStatusListener.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Deprecated.
Adds a PropertyChangeListener.
|
void |
addResourceListener(ResourceListener listener)
Deprecated.
Adds a ResourceListener.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Deprecated.
Adds a VetoableChangeListener.
|
protected boolean |
arePropertiesFrozen()
Deprecated.
Indicates if properties are frozen.
|
boolean |
equals(java.lang.Object other)
Deprecated.
Indicates if this resource is equal to an object.
|
protected void |
establishConnection()
Deprecated.
Establishes the connection to the system, if any.
|
protected void |
fireAttributeValuesRefreshed()
Deprecated.
Fires an attributeValuesRefreshed() ResourceEvent.
|
protected void |
fireBusy()
Deprecated.
Fires a busy active status event.
|
protected void |
fireIdle()
Deprecated.
Fires a idle active status event.
|
protected void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
Deprecated.
Fires a property change event.
|
protected void |
fireVetoableChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
Deprecated.
Fires a vetoable change event.
|
protected void |
freezeProperties()
Deprecated.
Freezes any property changes.
|
ResourceMetaData[] |
getAttributeMetaData()
Deprecated.
Returns the attribute meta data.
|
ResourceMetaData |
getAttributeMetaData(java.lang.Object attributeID)
Deprecated.
Returns the attribute meta data for a specific attribute.
|
java.lang.Object |
getAttributeValue(java.lang.Object attributeID)
Deprecated.
Returns the current value of an attribute.
|
java.lang.Object |
getAttributeValue(java.lang.Object attributeID,
int bidiStringType)
Deprecated.
Returns the current value of an attribute.
|
Presentation |
getPresentation()
Deprecated.
Returns the presentation information.
|
java.lang.Object |
getResourceKey()
Deprecated.
Returns the resource key.
|
AS400 |
getSystem()
Deprecated.
Returns the system.
|
protected void |
initializeAttributeValue(java.lang.Object attributeID,
java.lang.Object value)
Deprecated.
Initializes an attribute value.
|
protected boolean |
isBidiEnabled()
Deprecated.
Indicates if this resource is enabled for bidirectional character conversion.
|
protected boolean |
isConnectionEstablished()
Deprecated.
Indicates if a connection to the system is established, if any.
|
void |
refreshAttributeValues()
Deprecated.
Refreshes the values for all attributes.
|
void |
removeActiveStatusListener(ActiveStatusListener listener)
Deprecated.
Removes an ActiveStatusListener.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Deprecated.
Removes a PropertyChangeListener.
|
void |
removeResourceListener(ResourceListener listener)
Deprecated.
Removes a ResourceListener.
|
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Deprecated.
Removes a VetoableChangeListener.
|
protected void |
setPresentation(Presentation presentation)
Deprecated.
Sets the presentation.
|
protected void |
setResourceKey(java.lang.Object resourceKey)
Deprecated.
Sets the resource key.
|
void |
setSystem(AS400 system)
Deprecated.
Sets the system.
|
java.lang.String |
toString()
Deprecated.
Returns the presentation full name, if any.
|
public Resource()
public Resource(Presentation presentation, java.lang.Object resourceKey, ResourceMetaData[] attributeMetaData)
presentation
- The presentation.resourceKey
- The resource key.attributeMetaData
- The attribute meta data, or null if not applicable.public Resource(Presentation presentation, java.lang.Object resourceKey, ResourceMetaData[] attributeMetaData, java.util.Dictionary values)
presentation
- The presentation.resourceKey
- The resource key.attributeMetaData
- The attribute meta data, or null if not applicable.values
- The attribute values. The keys are attribute IDs and
the elements are attribute values. The attribute IDs
and values must be consistent according to the attribute
meta data.public Resource(Presentation presentation, java.lang.Object resourceKey, ResourceMetaDataTable attributes)
presentation
- The presentation.resourceKey
- The resource key, or null if it is not set.attributes
- The attribute meta data.public void addActiveStatusListener(ActiveStatusListener listener)
listener
- The listener.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener.public void addResourceListener(ResourceListener listener)
listener
- The listener.public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener.protected boolean arePropertiesFrozen()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- The object.protected void establishConnection() throws ResourceException
ResourceException
- If an error occurs.protected void fireAttributeValuesRefreshed()
protected void fireBusy()
protected void fireIdle()
protected void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
propertyName
- The property name.oldValue
- The old value.newValue
- The new value.protected void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue) throws java.beans.PropertyVetoException
propertyName
- The property name.oldValue
- The old value.newValue
- The new value.java.beans.PropertyVetoException
- If the property change is vetoed.protected void freezeProperties() throws ResourceException
Subclasses can override this method and put initialization code here that is dependent on properties being set. Any subclass that overrides this method should include a call to super.freezeProperties().
ResourceException
- If an error occurs.public ResourceMetaData getAttributeMetaData(java.lang.Object attributeID)
attributeID
- Identifies the attribute.public ResourceMetaData[] getAttributeMetaData()
public java.lang.Object getAttributeValue(java.lang.Object attributeID) throws ResourceException
attributeID
- Identifies the attribute.ResourceException
- If an error occurs.public java.lang.Object getAttributeValue(java.lang.Object attributeID, int bidiStringType) throws ResourceException
attributeID
- Identifies the attribute.bidiStringType
- The bidi string type as defined by the CDRA (Character Data
Representation Architecture). See
BidiStringType
for more information and valid values.ResourceException
- If an error occurs.public Presentation getPresentation()
public java.lang.Object getResourceKey()
public AS400 getSystem()
protected void initializeAttributeValue(java.lang.Object attributeID, java.lang.Object value)
attributeID
- Identifies the attribute.value
- The attribute value. This cannot be null.protected boolean isBidiEnabled()
protected boolean isConnectionEstablished()
public void refreshAttributeValues() throws ResourceException
ResourceException
- If an error occurs.public void removeActiveStatusListener(ActiveStatusListener listener)
listener
- The listener.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener.public void removeResourceListener(ResourceListener listener)
listener
- The listener.public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener.protected void setPresentation(Presentation presentation)
presentation
- The presentation.protected void setResourceKey(java.lang.Object resourceKey)
resourceKey
- The resource key.public void setSystem(AS400 system) throws java.beans.PropertyVetoException
system
- The system.java.beans.PropertyVetoException
- If the property change is vetoed.public java.lang.String toString()
toString
in class java.lang.Object