CentraSite 10.7 | CentraSite Developer's Guide | Customizing CentraSite | Implementation of Computed Attributes and Profiles | Implementing Computed Attributes
 
Implementing Computed Attributes
A computed attribute is defined as an implementation of the ComputedAttribute interface.
The implementation of a Java-based computed attribute includes a set of predefined ComputedAttribute and ProfileAttribute interfaces. These implementation interfaces are bundled in the CentraSiteUtils.jar, which is available in the <CentraSiteInstall_Directory>/redist folder.
Interfaces
Description
ComputedAttribute
Declares the basic rendering methods for a computed attribute interface. It extends the ProfileAttribute interface.
boolean: isUsed(): returns true if this attribute is used in at least one asset instance of the corresponding type.
Collection: setValue(Collection): sets the attribute value.
ProfileAttribute
void: init(Collection<CentraSiteRegistryObject>, Locale)
The parameter Collection includes a single CentraSiteRegistryObject asset instance for which the attribute value is to be obtained. The parameter Locale provides the preferred locale of the logged in user.
Collection: getValue(): returns the actual set of values that are represented by this attribute for an asset instance.
If the data is of type String, the method returns a collection of Strings. If the data is of type Relationship, the method returns a collection of RegistryObjects. If the data is of type File, the method returns a collection of ExternalLinks.
String: getAttributeKey()
AttributeDescriptor: getAttributeDescriptor(): returns the definition of attribute.
String: getName(): returns the JAXR-based name of attribute.
AttributeDescriptor
Declares the standard properties (isReadOnly(), is Required()...) for an attribute.
String: getDataType(): returns the data type of attribute. It can be one of the supported standard types (xs:...). The constants are referred from the CentraSiteSlotType interface, which is available in the package com.centrasite.jaxr.type and bundled as a CentraSiteJAXR-API.jar in the CentraSite installation.
If the computed attribute is of association or relationship type and returns the RegistryObjects, then the attribute data type is Relationship. If the computed attribute is of classification type and returns the Concept objects, then the attribute data type is Classification. If the computed attribute is of file type, then the attribute data type is File.
Object: getDefaultValue(): returns the default attribute value.
String[]: getEnumValues()
int: getMaxLength(): returns the maximum length of attribute.
String: getMaxOccurs(): denotes if the attribute can have multiple occurrences. The options are: ProfileAttribute.MAXOCCURS_1 and ProfileAttribute.MAXOCCURS_UNBOUNDED.
String: getMinOccurs(): denotes whether the attribute is optional or mandatory. The options are: ProfileAttribute.MINOCCURS_0 and ProfileAttribute.MINOCCURS_1.
Object: getNativeAtribute(): returns the native attribute instance if it is not a primitive data type. Else, returns null.
int: getPrecision(): returns the precision for a number attribute.
String: getUnitLabel(): returns the slots' unit label.
boolean: hasDefaultValue(): returns if the attribute has a default value.
boolean: isPrefix(): returns true if the slots' unit label is a prefix, and false if the unit label is a suffix.
boolean: isReadOnly(): denotes if the attribute is read-only.
boolean: isRequired(): denotes if the attribute is required.
Structure of Archive File
The plug-in uses the policy engine infrastructure, so it uses the structure of a Java policy (archive file structure and classloader). The archive file must contain the following folders and files:
Zip folder
Description
META-INF
This folder contains the config.properties file, which is the build file for the plug-in. This properties file contains an entry of the following format:
com.softwareag.centrasite.computed.attr.impl.class=
com.sample.StringAttrImpl
lib
This folder contains the archive file with the source code examples, the plug-in's executor class and the external libraries.
Sample Code
The sample Java code for implementing a computed attribute in CentraSite is shipped in the <CentraSiteInstall_Directory>/​demos/ComputedAttribute/EndPointAttribute/src/com/​softwareag/centrasite/demo/computedattribute/EndPointAttribute.java folder.
A sample computed attribute is shipped in the <CentraSiteInstall_Directory>/demos/ComputedAttribute/EndPointAttribute folder.
Loading a Computed Attribute into an Asset Type Definition
After you have created an archive file that contains the attribute definition, you need to load the archive file into the asset type definition. You do this by starting the Edit Asset Type wizard for the appropriate existing asset type, or the Add Asset Type wizard for a new custom asset type and specifying in the wizard that you are defining a new computed attribute.
For procedures on how to load an archive file of a computed attribute into an asset type definition, see CentraSite User’s Guide.
When you have loaded the archive file, the new attribute is displayed in the list of attributes that can be assigned to an asset type profile.