使用样本代码片段和数据图在 LDAP 存储库中扩展模式。
以下样本代码片段和数据图显示如何使用 propertySchema 数据对象在 LDAP 存储库中扩展该模式。此样本代码片段中涵盖以下步骤:
确保您已阅读了“编程先决条件”主题(包括“扩展属性模式”部分,其中包含有关 propertySchema 和 extensionPropertySchema 数据对象的信息并列出了属性数据类型的有效语法)中的信息,并完成了其中描述的步骤。
您必须已在联合存储库配置中配置 LDAP 存储库。请参阅 WebSphere Application Server 信息中心中的“在联合存储库配置中配置轻量级目录访问协议”主题。在以下样本代码中,联合存储库配置中配置的 LDAP 存储库的标识为 LDAP1。
请将以下代码片段添加到您的应用程序代码,并将变量替换为您要使用的实际值。
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
DataObject propertySchema = schema.createDataObject(SchemaConstants.DO_PROPERTY_SCHEMA);
// Set the values for the property viz. namespace URI, namespace prefix, property name
propertySchema.setString(SchemaConstants.PROP_PROPERTY_NAME, "contactNumber");
propertySchema.setString(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
// Specify the property is not 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_STRING);
// Add entity types to the list of applicable entity types for this property
// This will add the property for all the entity types in the list
propertySchema.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES).add(Service.DO_PERSON_ACCOUNT);
// Map the new property to LDAP attribute, ‘primaryOwnerContact', for LDAP repository, "LDAP1", only.
// For other repositories it will be mapped to the same name.
DataObject metaDataDO = propertySchema.createDataObject(SchemaConstants.DO_META_DATA);
metaDataDO.set(SchemaConstants.PROP_REPOSITORY_ID, "LDAP1");
metaDataDO.set(SchemaConstants.PROP_NAME, SchemaConstants.META_REPOSITORY_PROPERTY_NAME);
metaDataDO.getList(SchemaConstants.PROP_VALUES).add("primaryOwnerContact");
// Invoke the create schema API to actually add the property definition to the schema model
DataObject outRoot = service.createSchema(root);
System.out.println("\nCLIENT: new property is created.");
用于添加属性的输入数据图:
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
xmlns:wim="http://www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:propertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="String"
multiValued="false" propertyName="contactNumber">
<wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
<wim:metaData name="repositoryPropertyName" repositoryId="LDAP1">
<wim:values>primaryOwnerContact</wim:values>
</wim:metaData>
</wim:propertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph>
添加属性之后的输出数据图:
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
xmlns:wim="http://www.ibm.com/websphere/wim">
<wim:Root>
<wim:schema>
<wim:propertySchema nsURI="http://www.ibm.com/websphere/wim" dataType="String"
multiValued="false" propertyName="contactNumber">
<wim:repositoryIds>LDAP1</wim:repositoryIds>
<wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
<wim:metaData name="repositoryPropertyName" repositoryId="LDAP1">
<wim:values>primaryOwnerContact</wim:values>
</wim:metaData>
</wim:propertySchema>
</wim:schema>
</wim:Root>
</sdo:datagraph>