CentraSite 10.5 | CentraSite Developer's Guide | Application Framework | Mapping Beans to Registry Objects with Annotations
 
Mapping Beans to Registry Objects with Annotations
The beans are mapped to registry objects using Java5 Annotations.
Each bean from the application bean model has to extend or implement the RegistryBean (com.softwareag.centrasite.appl.framework.beans.RegistryBean) interface. If an interface extends the RegistryBean interface, an implementation must be provided and specified using the @Bean annotation:
@RegistryObject(objectTypeName="{http://namespaces.CentraSite.com/csaf}Item")
@Bean(implementationClass = "...")
public interface Item extends RegistryBean{
...
}
The following table describes the annotations currently supported by the CentraSite Application framework:
Annotations and Description
Scope
Properties
@RegistryObject
Maps a bean to a registry object with a specific object type.
Type
objectTypeName (optional) – the name of the object type of the registry object.
objectTypeKey (optional) – the key of the object type.
At least one of the properties must be specified.
@Property
Maps a bean property to a registry object property. The properties should have the same type. The mapper does not provide type conversion, except for JAXR InternationalString to/from String.
Method
target (optional) – the name of the target property in the registry object. The property must be a standard property of a predefined JAXR-based object type. If the target property is not specified, it is assumed that it matches the name of the bean property.
@Slot
Maps a bean property to a registry object slot. Multivalue slots are supported. Also provided are type conversion slot values which are string to integer, Boolean, date, timestamp, and Calendar.
Method
Name (mandatory) – the name of the slot to which this property is to be mapped. The JAXR-based property being mapped can be custom defined, or the JAXR-based object type that this property comes from can be custom.
targetType (optional) – specifies the type of the bean property. It is used when the property is a collection and thus the mapping cannot guess the underlying property.
type (optional) – the type of the bean property. Supported types are BOOLEAN, DATE, CALENDAR, TIMESTAMP, INTEGER, LONG, and AUTO. The latter allows the mapper to guess the property type.
@Slots
Maps all slots of a registry object to a bean property (Collection).
Method
targetType (mandatory) - the type of bean that is to be mapped to a single slot.
@SlotProperty
Used in conjunction with the @Slots property. Maps the properties of the bean of the type specified as target type with the @Slots annotation. A slot has a name, slot type and values. All these properties can be mapped using this annotation.
Method
target (mandatory) – can be one value from the enum SlotPropertyName – NAME, SLOT_TYPE, VALUES.
@TelephoneNumbers
Maps a bean property to the TelephoneNumber object from the JAXR-based infomodel. Such objects are used in the User JAXR Object.
Method
type (optional) – the type of the telephone numbers.
@ExternalLink
Maps a bean property to a ExternalLink JAXR-based object or a collection of them.
Method
slotName (optional) – the name of a slot inside the ExternalLink registry object to be mapped that is checked for having a specified value. This is used to pick the proper ExternalLink if the registry object has more than one.
slotValue (optional) – the value of the slot to be checked.
type (optional) – type of the bean used for the mapping
@Association
Maps a property to an association. It can be either the association object itself or the target of the association.
Method
key (optional) – the key of the association type to be used. Either type or key must be present.
type (optional) – the association type to be used. Either type or key must be present.
targetType (optional) – the type of the bean to be mapped. It is used when the bean property is a collection and the type cannot be guessed.
mappedTo (optional) – the property can be mapped to either the association registry object or the target of the association.
cascadeStyle (optional) – Supported cascade styles are ALL (Cascade on all operations), UPDATE (Cascade on update operations), DELETE (Cascade on delete operations), NONE (no cascading).
@AssociationTarget
Used in conjunction with the @Association annotation. Maps a bean to a target of an association. It is used when a bean is mapped to an association object using the @Association annotation. Then inside that bean a property must be mapped to the target.
Method
None
@Classification
Maps a bean property to a classification. Both the classification object and its concept can be used. The mapping can be simple – Bean property <-> Classification(Concept) or enumeration – Bean property <-> Classification (Concept) which concept is under a specified parent concept. The latter provides a set of predefined possible concepts, thus is similar to the notion of enumeration.
Method
classificationScheme (optional) – the name of the ClassificationScheme to be used.
parentConcept (optional) – the path of the parent concept. Used when mapping enumeration classifications.
parentConceptKey (optional) – the key of the parent concept. Either the path or the key can be used.
conceptPath (optional) – the path of the concept for this classification.
conceptKey (optional) – the key of the concept for this classification. Either the path or the key can be used.
targetType (optional) – the type of the bean used for the mapping. Required when the property is a collection and the type cannot be guessed.
mappedTo (optional) – the bean can be mapped either to the classification object or to its concept.
cascadeStyle (optional) – The supported cascade styles are ALL, UPDATE, DELETE, and NONE.
@ClassificationConcept
Used in conjunction with the @Classification annotation. Maps a bean to the Concept of the Classification specified in the @Classification annotation.
Method
None
@ClassifiedInstances
Maps class hierarchy to registry objects. Classifications are used to achieve this. Each registry object that corresponds to a bean from the hierarchy is classified with a concept. The latter belongs to a taxonomy mirroring the class hierarchy.
Type
instances (mandatory) – the array of the instances that this mapping will address.
@ClassifiedInstance Sets the information for a specific mapping between a bean from the hierarchy and a registry object.
Type
classificationScheme (mandatory) – the classification scheme to which the concept belongs. Either the scheme name or the key must be specified.
classificationSchemeKey (mandatory) – the key of the classification scheme. Either the scheme name or the key must be specified.
conceptKey (mandatory) – the key of the concept used to classify this instance.
conceptPath (mandatory) – the path of the concept used to classify this instance.
beanType (mandatory) – the type of the bean that corresponds to this instance.
@ClassificationAttribute
Annotation for mapping the return value of a (getter) method to the classification attribute specified at type level. The attribute name is mandatory and is used to identify the attribute. This annotation is very similar to the {@link Classification} annotation in terms of supported attributes and underlying representation. The difference is that the taxonomy is obtained from the attribute description. In order to use this annotation, a classification attribute must be defined at type level (the registry object type must have a classification attribute with the same attribute name as specified in the annotation).
Method
attributeName (mandatory) – The name of the attribute represented by this annotation.
cascadeStype (optional) – The cascading style for this mapping.
targetType (optional) – The type of the mapped bean. The bean itself must be of type Concept.
@FileAttribute
Annotation for mapping the return value of a (getter) method to the file attribute specified at type level. The attribute name is mandatory and is used to identify the attribute. This annotation is very similar to the {@link ExternalLink} annotation in terms of supported attributes and underlying representation. In order to use this annotation, a file attribute must be defined at type level (the registry object type must have a file attribute with the same attribute name as specified in the annotation).
Method
attributeName (mandatory) – The name of the attribute represented by this annotation.
cascadeStype (optional) – The cascading style for this mapping.
targetType (optional) – The type of the mapped bean. The bean itself must be of type ExternalLink.
@Relationship
Annotation for mapping the return value of a (getter) method to the attribute specified at type level. The attribute name is mandatory and is used to identify the attribute. This annotation is very similar to the {@link Association} annotation in terms of supported attributes and underlying representation. The difference is that the association and target types are not specified but are obtained from the attribute description. In order to use this annotation, a relationship attribute must be defined at type level (the registry object type must have a relationship attribute with the same attribute name as specified in the annotation).
Method
attributeName (mandatory) – The name of the attribute represented by this annotation.
cascadeStype (optional) – The cascading style for this mapping.
targetType (optional) – The type of the mapped bean. The bean itself must be of type Concept.
Example
/**
* Java bean interface representing JAXR-based registry objects
* of type ServiceInterfaceVersion.
*/
@RegistryObject(objectTypeName =
"{http://namespaces.CentraSite.com/csaf}ServiceInterfaceVersion")
@Bean(implementationClass =
"com.softwareag.centrasite.appl.framework.persistence.beanmodel.impl.ServiceIn
terfaceVersionImpl") public interface ServiceInterfaceVersion extends
RegistryBean{
 
@Property(target = "name")
public String getName();
public void setName(String name);
 
/**
* Returns the description
*/
@Property(target = "description")
public String getDescription();
 
/**
* Sets the description
*/
public void setDescription(String description);
 
/**
* Returns the attachments
*/
@ExternalLink(type = com.softwareag.centrasite.appl.framework.persistence.
beanmodel.ExternalLink.class) public List<com.softwareag.centrasite.appl.
framework.persistence.beanmodel.ExternalLink> getAttachments();
 
/**
* Sets the attachments
*/
public void setAttachments(List<com.softwareag.centrasite.appl.
framework.persistence.beanmodel.ExternalLink> attachments);
 
/**
* Returns the short name of the interface version.
* Maps to {http://namespaces.CentraSite.com/csaf}shortName slot.
*/
@Slot(name = "{http://namespaces.CentraSite.com/csaf}shortName")
String getShortName();
 
/**
* Sets the short name property of the interface version.
*/
void setShortName(String shortName);
 
/**
* Returns.
*/
@Association(type = "HasReviewRequest",
targetType = ReviewRequestOutcome.class,
cascadeStype = CascadeStyle.DELETE)
List<ReviewRequestOutcome> getReviewRequestOutcomes();
 
/**
* @param list
*/
public void setReviewRequestOutcomes(List<ReviewRequestOutcome> list);
 
/**
* Returns the findings, which are attached to the bean.
*/
@Classification(classificationScheme = "CSAF -Taxonomy",
conceptPath = "/ClassificationInstances/Finding",
targetType = Finding.class)
List<Finding> getFindings();
 
/**
*
* @param pFindings
*/
public void setFindings(List<Finding> pFindings);
 
 
@Slots(targetType = SlotBean.class)
public Collection<SlotBean> getSlots();
 
public void setSlots(Collection<SlotBean> slots);
}
 
/**
* Implementation of the {@link ServiceInterfaceVersion} bean interface.
*/public class ServiceInterfaceVersionImpl extends DynamicRegistryBean
implements ServiceInterfaceVersion {
 
private String _shortName;
private List<ReviewRequestOutcome> _reviewRequestOutcomes;
private Collection<SlotBean> slots;
private String _instanceSlotName;
private List<Finding> findings;
private List<ExternalLink> externalLinks;
 
/**
* {@inheritDoc}
*/
public String getShortName() {
return _shortName;
}
 
/**
* {@inheritDoc}
*
* The setter is annotated that modifies the object and it needs to be
* updated in the JAXR-based registry.
*/
public void setShortName(String shortName) {
_shortName = shortName;
}
 
public List<ReviewRequestOutcome> getReviewRequestOutcomes() {
return _reviewRequestOutcomes;
}
 
public
void setReviewRequestOutcomes(List<ReviewRequestOutcome> list) {
_reviewRequestOutcomes = list;
}
 
public Collection<SlotBean> getSlots() {
return slots;
}
 
public void setSlots(Collection<SlotBean> slots) {
this.slots = slots;
}
 
public String getInstanceSlotName() {
return _instanceSlotName;
}
 
public void setInstanceSlotName(String slotName) {
_instanceSlotName = slotName;
}
 
public List<Finding> getFindings() {
return findings;
}
 
public void setFindings(List<Finding> findings) {
this.findings = findings;
}
 
public List<ExternalLink> getAttachments() {
return externalLinks;
}
 
public void setAttachments(List<ExternalLink> attachments) {
externalLinks = attachments;
}
}
Standard Mappings
The Standard Mappings (com.softwareag.centrasite.appl.framework.beans.standard) are RegistryBeans that represent all supported JAXR-based Registry Objects under the package com.centrasite.jaxr.infomodel. They provide the functionality to operate and manage JAXR-based RegistryObjects through the Application Framework with ease.
There are other kinds of objects that are included in this package although they are not RegistryObjects (EmailAddress, PostalAddress, Slot … etc.). The Application Framework provides a mapping for them as well. Standard Mapping instances are created by the BeanPool's create(beanClass); standard non-registry object mappings (EmailAddress, PostalAddress, Slot … etc.) are managed using the following:
com.softwareag.centrasite.appl.framework.beans.standard.StandardMappingManager
Standard Mappings Usage Sample
//Create a com.softwareag.centrasite.appl.framework.beans.standard.Organization
com.softwareag.centrasite.appl.framework.beans.standard.Organization
organization = beanPool.create(com.softwareag.centrasite.appl.framework.beans.s
tandard.Organization.class);
organization.setName("MyOrganization");
 
// Create StandardMappingManager for managing Standard non RegistryObjects
// mappings
StandardMappingManager smm = new StandardMappingManager(registryProvider);
 
//Create a postal address
com.softwareag.centrasite.appl.framework.beans.standard.PostalAddress pa =
smm.createPostalAddress("streetNumber", "street", "city",
"stateOrProvince", "country", "postalCode","type");
organization.setPostalAddress(pa);
 
// Get existing user and add it to the organization
com.softwareag.centrasite.appl.framework.beans.standard.User user =
beanPool.read( com.softwareag.centrasite.appl.framework.beans.standard.
User.class,
USER_KEY);
Collection<User> users = new ArrayList<User>();
users.add(user);
organization.setUsers(users);
 
// save the changes
beanPool.flush();
Generating Beans Through the Command Line
Pre-requisites:
CentraSite provides a command tool named GenerateCSAFBeans for this purpose.
The syntax is of the format:
C:\SoftwareAG\CentraSite\utilities>GenerateCSAFBeans.cmd <USERNAME> <PASSWORD> <CENTRASITE-URL> <TYPENAME> <INTERFACEPACKAGE> <IMPLPACKAGE> <DESTINATION>
The input parameters are:
Parameter
Description
CENTRASITE-URL
(Optional). The URL of the CentraSite registry. For example, http://localhost:53307/CentraSite/CentraSite.
USER-ID
The user ID of a registered CentraSite user who has the CentraSite Administrator role. For example, Administrator.
PASSWORD
The password for the registered CentraSite user identified by the parameter USER-ID.
TYPENAME
The namespace or name of the type to be generated. Example: {http://test}TestService.
Or, the name of the virtual type to be generated. Example: "Virtual service" .
Note:
The quotation marks are necessary, in order that "Virtual service" is parsed as a single token.
INTERFACEPACKAGE
The name of the package in which the interfaces should be generated. For example: com.sag.generated
IMPLPACKAGE
The name of the package in which the implementation should be generated. For example: com.sag.generated.impl
DESTINATION
The location where the generated bean will be stored.
Example (all in one line):
C:\SoftwareAG\CentraSite\utilities>GenerateCSAFBeans.cmd Administrator manage http://localhost:53307 "Virtual service" com.sag.generated com.sag.generated.impl c:\tmp\