Attribute strings can in the Java Server Framework be manipulated similarly to the IFS Foundation1 CLIENT_SYS package.
In the
ifs.fnd.services.plsqlserver
package there is a class
AttributeString
which is a Java implementation of the attribute string concept widely used in
PL/SQL based components. In addition to adding and modifying name-value pairs,
this class can also convert between records/views and
attribute strings. This feature is quite handy since it makes the process much
easier. But it can only be used when the record's attribute names exactly match
the ones expected in the attribute string.
Attribute strings are pretty straight forward to use, here's an example on how to create and add values to an attribute string:
AttributeString attr = new AttributeString(); attr.add("GIVEN_NAME", "Homer"); attr.add("SURNAME", "Simpson"); attr.add("ADDRESS", "742 Evergreen Terrace");
Before an attribute string can be sent as input to a wrapper method, it must
first be converted to a String and placed in a FndText
(the parameters expecting
attribute strings are usually IN_OUT parameters) object:
FndText txtAttr = new FndText(); txtAttr.setValue(attr.toString());
Now the attribute string is ready to be used as input to a PL/SQL wrapper
method. Now, suppose you have called a wrapper method and it returned an
attribute string and you need to handle it. That is done by first creating the AttributeString
object with the constructor that takes a String argument and then
retrieve the values. This code snippet shows you how to create an AttributeString
from a returned result, access and modify values and iterate through all values.
// Create the attribute string from a FndText's value attr = new AttributeString(txtAttr.getValue()); // Get the value named 'ADDRESS'. getItemValue() returns null // if there is no value with the given name. String givenName = attr.getItemValue("ADDRESS"); // Update the value for 'GIVEN_NAME'. The setItemValue() // method is overloaded with versions taking Date, double and? // float data types. They are however always converted to String when added. attr.setItemValue("GIVEN_NAME", "Homer J"); // Iterate through all values and print them on System.out. // getNextItem() returns a FndText with a name and value. // If there is no more item, it returns null. FndText next = attr.getNextItem(); while(next != null) { System.out.println(next.getName() + ": " + next.getValue()); next = attr.getNextItem(); }
What about converting between records and attribute strings? How is that
done? To create an AttributeString
from a record there is a
constructor taking a FndAbstractRecord
as argument. By using this
constructor, an AttributeString
with the record's attributes as
values is created. There are two versions of this constructor. One that only takes a FndAbstractRecord
and one that also takes a boolean named includeAll
. If
the boolean parameter is true then all the record's attributes are
added to the attribute string. If it's false, only the dirty
attributes are added. The default value (for the version without the parameter)
is to include all attributes if the record's state is NEW_RECORD.
To go the other way around there are two methods, the first one
public FndRecord parseToRecord()
returns a new record with the attribute string's name-value pairs as attributes. The other one
public void parseToRecord(FndAbstractRecord record)
takes an existing record, or
view, clears its contents and then populates it with the values from the attribute string.
There is another version of the last method called updateRecord
. It
does not clear the contents of the record. It just populates it with the values
from the attribute string.