このサンプル・コード・スニペットおよびデータ・グラフは、LDAP リポジトリーでスキーマを拡張するために使用します。
以下のサンプル・コード・スニペットおよびデータ・グラフは、propertySchema データ・オブジェクトを使用して、LDAP リポジトリーでスキーマを拡張する方法を示します。 このサンプル・コード・スニペットでは、以下の手順を実行します。
「プログラミングの前提条件」トピック (propertySchema および extensionPropertySchema データ・オブジェクトについての情報が記載され、プロパティーのデータ型についての有効な構文がリストされている「プロパティー・スキーマの拡張」セクションを含む) で説明されている情報を参照済みであること、またトピックの手順を実行済みであることを確認してください。
統合リポジトリー構成で LDAP リポジトリーを構成しておく必要があります。WebSphere Application Server インフォメーション・センターの「フェデレーテッド・リポジトリー構成における Lightweight Directory Access Protocol の構成」トピックを参照してください。以下のサンプル・コードでは、統合リポジトリー構成で構成された LDAP リポジトリーの ID は 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>