public abstract class ChangeableResource extends Resource
Resource
which adds the ability to change attribute values of a system resource.
Attribute changes are cached internally until they are committed
or canceled. This allows you to change many attribute values at
once. Every attribute is identified using an attribute ID. Any given
subclass of ChangeableResource will normally document the attribute IDs
that it supports.
One example of a concrete subclass of ChangeableResource is
RJob
, which represents
a server job. RJob supports many attribute IDs,
each of which can be used to access attribute values.
Here is an example which sets two attribute values for an RJob:
// Create an RJob object to refer to a specific job. AS400 system = new AS400("MYSYSTEM", "MYUSERID", "MYPASSWORD"); RJob job = new RJob(system, "AJOBNAME", "AUSERID", "AJOBNUMBER");
// Set the date format attribute value. job.setAttributeValue(RJob.DATE_FORMAT, RJob.DATE_FORMAT_JULIAN);
// Set the country ID attribute value. job.setAttributeValue(RJob.COUNTRY_ID, RJob.USER_PROFILE);
// Commit both attribute changes. job.commitAttributeChanges();
In addition to using concrete subclasses directly, you
can write generic code to work with any ChangeableResource
subclass. Such code may improve reusability and maintainability
and will work with future ChangeableResource subclasses without
modification. Every attribute has an associated attribute
meta data
object which describes various properties of the attribute.
These properties include whether or not the attribute is
read only and what the default and possible values are.
Here is an example of generic code which resets all attributes
of a ChangeableResource to their default values:
Subclass notes:void resetAttributeValues(ChangeableResource resource) throws ResourceException { // Get the attribute meta data. ResourceMetaData[] attributeMetaData = resource.getAttributeMetaData();
// Loop through all attributes. for(int i = 0; i < attributeMetaData.length; ++i) { // If the attribute is changeable (not read only), then // reset its value to the default. if (! attributeMetaData[i].isReadOnly()) { Object attributeID = attributeMetaData[i].getID(); Object defaultValue = attributeMetaData[i].getDefaultValue(); resource.setAttributeValue(attributeID, defaultValue); } }
// Commit all of the attribute changes. resource.commitAttributeChanges(); }
If you are extending this class to override the mechanism for getting
attribute values, you need to override either
getAttributeUnchangedValue(Object)
or getAttributeUnchangedValue(Object, int)
,
but not getAttributeValue(Object)
or getAttributeValue(Object, int)
.
This is because getAttributeValue() will automatically call getAttributeUnchangedValue()
only when needed.
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
getAttributeUnchangedValue(Object)
.
If you do plan to support bidirectional character conversion, then you need
to override isBidiEnabled()
to return true
and getAttributeUnchangedValue(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 getAttributeUnchangedValue(Object attributeID) throws ResourceException { // Call the superclass first. Object value = super.getAttributeUnchangedValue(attributeID); if (value == null) {
// Establish the connection if needed. if (! isConnectionEstablished()) establishConnection();
// Go get the attribute value. value = ...; } return value; }
If you are extending this class to override the mechanism for setting
attribute values, you need to override either
commitAttributeChanges(Object[], Object[])
or commitAttributeChanges(Object[], Object[], int[])
,
but not commitAttributeChanges()
,
setAttributeValue(Object, Object)
, or
setAttributeValue(Object, Object, int)
.
If you do not plan to support bidirectional character conversion, then you only need
to override commitAttributeChanges(Object[], Object[])
.
If you do plan to support bidirectional character conversion, then you need
to override isBidiEnabled()
to return true
and commitAttributeChanges(Object[], Object[], int[])
}.
In either case, the overriding method should call the superclass's method of the same name and then perform extra processing:
protected void commitAttributeChanges(Object[] attributeIDs, Object[] values) throws ResourceException { // Call the superclass first. super.commitAttributeChanges(attributeIDs, values);
// Establish the connection if needed. if (! isConnectionEstablished()) establishConnection();
// Commit the attribute changes. // ... }
Constructor and Description |
---|
ChangeableResource()
Deprecated.
Constructs a ChangeableResource object.
|
ChangeableResource(Presentation presentation,
java.lang.Object resourceKey,
ResourceMetaData[] attributeMetaData)
Deprecated.
Constructs a ChangeableResource object.
|
ChangeableResource(Presentation presentation,
java.lang.Object resourceKey,
ResourceMetaDataTable attributes)
Deprecated.
Constructs a ChangeableResource object.
|
Modifier and Type | Method and Description |
---|---|
void |
cancelAttributeChanges()
Deprecated.
Cancels all uncommitted attribute changes.
|
void |
commitAttributeChanges()
Deprecated.
Commits all attribute changes.
|
protected void |
commitAttributeChanges(java.lang.Object[] attributeIDs,
java.lang.Object[] values)
Deprecated.
Commits the specified attribute changes.
|
protected void |
commitAttributeChanges(java.lang.Object[] attributeIDs,
java.lang.Object[] values,
int[] bidiStringTypes)
Deprecated.
Commits the specified attribute changes.
|
protected void |
fireAttributeChangesCanceled()
Deprecated.
Fires an attributeChangesCanceled() ResourceEvent.
|
protected void |
fireAttributeChangesCommitted()
Deprecated.
Fires an attributeChangesCommitted() ResourceEvent.
|
protected void |
fireAttributeValueChanged(java.lang.Object attributeID,
java.lang.Object value)
Deprecated.
Fires an attributeValueChanged() ResourceEvent.
|
protected void |
fireResourceCreated()
Deprecated.
Fires an resourceCreated() ResourceEvent.
|
protected void |
fireResourceDeleted()
Deprecated.
Fires an resourceDeleted() ResourceEvent.
|
java.lang.Object |
getAttributeUnchangedValue(java.lang.Object attributeID)
Deprecated.
Returns the value of an attribute, disregarding any uncommitted
changes.
|
java.lang.Object |
getAttributeUnchangedValue(java.lang.Object attributeID,
int bidiStringType)
Deprecated.
Returns the value of an attribute, disregarding any uncommitted
changes.
|
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.
|
boolean |
hasUncommittedAttributeChanges(java.lang.Object attributeID)
Deprecated.
Indicates if an attribute has an uncommitted change.
|
protected void |
initializeAttributeValue(java.lang.Object attributeID,
java.lang.Object value)
Deprecated.
Initializes an attribute value.
|
void |
refreshAttributeValues()
Deprecated.
Refreshes the values for all attributes.
|
void |
setAttributeValue(java.lang.Object attributeID,
java.lang.Object value)
Deprecated.
Sets the current value of an attribute.
|
void |
setAttributeValue(java.lang.Object attributeID,
java.lang.Object value,
int bidiStringType)
Deprecated.
Sets the current value of an attribute.
|
addActiveStatusListener, addPropertyChangeListener, addResourceListener, addVetoableChangeListener, arePropertiesFrozen, equals, establishConnection, fireAttributeValuesRefreshed, fireBusy, fireIdle, firePropertyChange, fireVetoableChange, freezeProperties, getAttributeMetaData, getAttributeMetaData, getPresentation, getResourceKey, getSystem, isBidiEnabled, isConnectionEstablished, removeActiveStatusListener, removePropertyChangeListener, removeResourceListener, removeVetoableChangeListener, setPresentation, setResourceKey, setSystem, toString
public ChangeableResource()
public ChangeableResource(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 ChangeableResource(Presentation presentation, java.lang.Object resourceKey, ResourceMetaDataTable attributes)
presentation
- The presentation.resourceKey
- The resource key.attributes
- The attribute meta data, or null if not applicable.public void cancelAttributeChanges() throws ResourceException
ResourceException
- If an error occurs.public void commitAttributeChanges() throws ResourceException
This method gathers information about which attribute
changes need to be committed and calls commitAttributeChanges(Object[], Object[])
.
Subclasses should override
commitAttributeChanges(Object[], Object[]) to define how attribute
changes are physically committed.
ResourceException
- If an error occurs.protected void commitAttributeChanges(java.lang.Object[] attributeIDs, java.lang.Object[] values) throws ResourceException
Subclasses should override this method to define how attribute changes are physically committed.
attributeIDs
- The attribute IDs for the specified attribute changes.values
- The specified attribute changesResourceException
- If an error occurs.protected void commitAttributeChanges(java.lang.Object[] attributeIDs, java.lang.Object[] values, int[] bidiStringTypes) throws ResourceException
Subclasses should override this method to define how attribute changes are physically committed.
attributeIDs
- The attribute IDs for the specified attribute changes.values
- The specified attribute changesbidiStringTypes
- The bidi string types as defined by the CDRA (Character Data
Representation Architecture). See
BidiStringType
for more information and valid values.ResourceException
- If an error occurs.protected void fireAttributeChangesCanceled()
protected void fireAttributeChangesCommitted()
protected void fireAttributeValueChanged(java.lang.Object attributeID, java.lang.Object value)
attributeID
- Identifies the attribute.value
- The attribute value.protected void fireResourceCreated()
protected void fireResourceDeleted()
public java.lang.Object getAttributeUnchangedValue(java.lang.Object attributeID) throws ResourceException
Subclasses should override this method to implement how attribute values are physically retrieved.
attributeID
- Identifies the attribute.ResourceException
- If an error occurs.public java.lang.Object getAttributeUnchangedValue(java.lang.Object attributeID, int bidiStringType) throws ResourceException
Subclasses should override this method to implement how attribute values are physically retrieved.
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 java.lang.Object getAttributeValue(java.lang.Object attributeID) throws ResourceException
getAttributeValue
in class Resource
attributeID
- Identifies the attribute.ResourceException
- If an error occurs.public java.lang.Object getAttributeValue(java.lang.Object attributeID, int bidiStringType) throws ResourceException
getAttributeValue
in class Resource
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 boolean hasUncommittedAttributeChanges(java.lang.Object attributeID)
attributeID
- Identifies the attribute.protected void initializeAttributeValue(java.lang.Object attributeID, java.lang.Object value)
initializeAttributeValue
in class Resource
attributeID
- Identifies the attribute.value
- The attribute value. This cannot be null.public void refreshAttributeValues() throws ResourceException
refreshAttributeValues
in class Resource
ResourceException
- If an error occurs.public void setAttributeValue(java.lang.Object attributeID, java.lang.Object value) throws ResourceException
attributeID
- Identifies the attribute.value
- The attribute value. This cannot be null.ResourceException
- If an error occurs.public void setAttributeValue(java.lang.Object attributeID, java.lang.Object value, int bidiStringType) throws ResourceException
attributeID
- Identifies the attribute.value
- The attribute value. This cannot be null.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.