Express (Distributed operating systems), v8.0 > Secure applications and their environment > Authenticate users > Select a registry or repository > Manage realms in a federated repository > Virtual member manager > Develop with virtual member manager > Integrate virtual member manager into the application > Sample code


Sample code for extending the schema in the property extension repository

Use the sample code snippet and data graphs to extend the schema in the property extension repository.

The following sample code snippet and data graphs show how to add the property, age, to the PersonAccount entity type, and extend the schema in the property extension repository, by using the extensionPropertySchema data object. The property extension repository must be configured before you can use extensionPropertySchema. For more information, read about Configure a property extension repository in a federated repository in the WAS information center.


Prerequisites

Ensure that we have read the information and completed the steps described in the topic, Program prerequisites, including the section, Extend property schema, which has information about propertySchema and extensionPropertySchema data objects and lists the valid syntax for property data types.


Sample code

Add the following code snippet to the application code and replace the variables with the actual values to use.

// Get a root data object. The rest of the object tree would be built under it
DataObject root = SDOHelper.createRootDataObject();
// Create a new "schema" object under root
// This object will contain the details of the schema modifications that need to be made DataObject schema = root.createDataObject(SchemaConstants.DO_SCHEMA);
// Create a property schema data object under the schema object created earlier
// Note: To ensure that the property is also added into the extension repository // use the Extension Property Schema instead of the simple Property Schema
DataObject propertySchema = schema.createDataObject(SchemaConstants.DO_EXTENSION_PROPERTY_SCHEMA);
// Set the value for the property name propertySchema.setString(SchemaConstants.PROP_PROPERTY_NAME, "age");
// Set the namespace for the property // As here we are defining the property in the default namespace,
// we do not need to define the namespace prefix
// Note: Adding of property in default namespace is only possible when the VMM is using "dynamicModel"
propertySchema.setString(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
// Specify if the property is multi-valued (if it is multi-valued, its type must be List)
propertySchema.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
// Specify the data type of the property // Data types can be simple like boolean, int, float, double, String // or special like Address, Person, Group, etc.
propertySchema.setString(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_INT);
// Get the list of entity types to which this property needs to be added and // add the applicable entity type names (here "PersonAccount") to the list fetched above
propertySchema.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES).add(Service.DO_PERSON_ACCOUNT);
// Invoke the create schema
root = service.createSchema(root);

We can use the deleteIdMgrPropertyExtensionEntityData wsadmin command to delete property data from the property extension repository. For more information about using this command, see the topic IdMgrDBSetup command group in the WAS information center.


Input and output data graphs

Input data graph for adding property:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:extensionPropertySchema nsURI="//www.ibm.com/websphere/wim" dataType="Int"
          multiValued="false" propertyName="age">  
<wim:applicableEntityTypeNames>PersonAccount
</wim:applicableEntityTypeNames>
</wim:extensionPropertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph> 

Output data graph after adding property:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:extensionPropertySchema nsURI="//www.ibm.com/websphere/wim" dataType="Int"
          multiValued="false" propertyName="age">  
<wim:applicableEntityTypeNames>PersonAccount
</wim:applicableEntityTypeNames>
</wim:extensionPropertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph> 

Parent topic: Sample code



+

Search Tips   |   Advanced Search