ここでは、マルチセキュリティー・ドメインにわたってプロパティー・スキーマを拡張するための、構成ステップ、コマンド、サンプル・コード、およびデータ・グラフを示します。
構成コマンドおよびサンプル・コード・スニペットでは、以下の手順を実行します。
「プログラミングの前提条件」トピック (propertySchema および extensionPropertySchema データ・オブジェクトについての情報が記載され、プロパティーのデータ型についての有効な構文がリストされている「プロパティー・スキーマの拡張」セクションを含む) で説明されている情報を参照済みであること、またトピックの手順を実行済みであることを確認してください。
アプリケーションでサンプル・コードを使用する前に、以下の構成ステップを完了する必要があります。wsadmin ツールを開始して、以下のコマンドを実行します。変数 を、実際に使用する値に置き換えます。
$AdminTask createApplicationServer nodeName {-name server2}
$AdminTask copySecurityDomainFromGlobalSecurity {-securityDomainName domain1}
$AdminTask mapResourceToSecurityDomain { -securityDomainName domain1 -resourceName Cell=:Node=nodeName:Server=server2}
グローバル・スキーマを使用する場合は、このステップを実行します。ドメイン固有のスキーマを使用する場合は、このステップをスキップします。
$AdminTask setIdMgrUseGlobalSchemaForModel { -useGlobalSchema true -securityDomainName domain1 }
$AdminApp install app_server_root/systemApps/wim.ear { -appname wim -server server1 -systemApp}
$AdminApp install app_server_root/installableApps/wimperdomain.ear {
-appname wimperdomain1
-BindJndiForEJBNonMessageBinding {{ wim.ejb WIMService wimejb.jar,
META-INF/ejb-jar.xml ejbd1/com/ibm/websphere/wim/ejb/WIMServiceHome}}
-MapModulesToServers {{ wim.ejb wimejb.jar,META-INF/ejb-jar.xml
WebSphere:cell=cellName,node=nodeName,server=server2 }}}
$AdminConfig save
以下の手順で説明するように、次のサンプル・コードをアプリケーション・コードに追加します。変数 を、実際に使用する値に置き換えます。
//The service object that holds the virtual member manager ejb service reference for server1.
private static Service service1 = null;
//The service object that holds the virtual member manager ejb service reference for server2.
private static Service service2 = null;
//A string constant for the new property name to be added for server1.
private static final String server1PropName = "postOfficeBox";
//A string constant for the new property name to be added for server2.
private static final String server2PropName = "age";
/**
* This method locates the virtual member manager services running on
* WebSphere Application Sever on the localhost
*/
private static void locateServices()
{
// Remote access WIM Service EJB
try
{
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(LocalServiceProvider.PROVIDER_URL, "corbaloc:iiop:localhost:2814");
service1 = new LocalServiceProvider(environment);
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(LocalServiceProvider.EJB_JNDI_NAME,
"ejbd1/com/ibm/websphere/wim/ejb/WIMServiceHome");
environment.put(LocalServiceProvider.PROVIDER_URL, "corbaloc:iiop:localhost:2815");
service2 = new LocalServiceProvider(environment);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* This method adds the "postOfficeBox" property to "PersonAccount" entity type.
*/
private static void createPropertyOnServer1()
{
try
{
System.out.println("¥nCreating new property type postOfficeBox
and add it to existing entity type PersonAccount");
DataObject root = service1.createRootDataObject();
DataObject dynaSchemaDO = root.createDataObject(SchemaConstants.DO_SCHEMA);
// Create new property schema data object
DataObject propSchemaDO = dynaSchemaDO.createDataObject(SchemaConstants.DO_PROPERTY_SCHEMA);
// Set the values for the property, such as, namespace URI, namespace prefix, property name
propSchemaDO.set(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
propSchemaDO.set(SchemaConstants.PROP_PROPERTY_NAME, server1PropName);
propSchemaDO.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
propSchemaDO.set(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_STRING);
List applicableEntityTypes = propSchemaDO.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES);
applicableEntityTypes.add(Service.DO_PERSON_ACCOUNT);
System.out.println("Input datagraph -> " + printDO(root));
// Invoke the create schema API
root = service1.createSchema(root);
System.out.println("Output datagraph -> " + printDO(root));
System.out.println("¥nCLIENT: new property type is created.");
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* This method adds the "age" property to "PersonAccount" entity type.
*/
private static void createPropertyOnServer2()
{
try
{
System.out.println("¥nCreating new property type age and
add it to existing entity type Person");
DataObject root = service2.createRootDataObject();
DataObject dynaSchemaDO = root.createDataObject(SchemaConstants.DO_SCHEMA);
// Create new property schema data object
DataObject propSchemaDO = dynaSchemaDO.createDataObject(SchemaConstants.DO_PROPERTY_SCHEMA);
// Set the values for the property, such as, namespace URI, namespace prefix, property name
propSchemaDO.set(SchemaConstants.PROP_NS_URI, SchemaConstants.WIM_NS_URI);
propSchemaDO.set(SchemaConstants.PROP_PROPERTY_NAME, server2PropName);
propSchemaDO.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
propSchemaDO.set(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_INT);
List applicableEntityTypes = propSchemaDO.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES);
applicableEntityTypes.add(Service.DO_PERSON_ACCOUNT);
SDOUtils.printDataGraph("Input datagraph", root);
System.out.println("Input datagraph -> " + printDO(root));
// Invoke the create Schema API
root = service2.createSchema(root);
System.out.println("Output datagraph -> " + printDO(root));
System.out.println("New property type is created.");
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Method that runs different searches on different servers.
*/
private static void testSearchProperties()
{
// Search using the server1 property but using service1
System.out.println("Searching property '" + server1PropName + "' on server1");
searchserver1PropName(service1);
// Utility stop to synchronize output
pause();
// Search using the server1 property but using service2
System.out.println("Searching property '" + server1PropName + "' on server2");
searchserver1PropName(service2);
// Utility stop to synchronize output
pause();
// Search using the server2 property but using service2
System.out.println("Searching property '" + server2PropName + "' on server2");
searchserver2PropName(service2);
// Utility stop to synchronize output
pause();
// Search using the server2 property but using service1
System.out.println("Searching property '" + server2PropName + "' on server1");
searchserver2PropName(service1);
}
/**
* A utility method added to ensure that the exception is flushed to the console
* before starting with the next operation.
*/
private static void pause()
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}
/**
* Method to search on 'age'
* @param service
*/
@SuppressWarnings("unchecked")
private static void searchserver2PropName(Service service)
{
try
{
//Search
DataObject root = SDOHelper.createRootDataObject();
DataObject searchCtrl = SDOHelper.createControlDataObject(root, null,
SchemaConstants.DO_SEARCH_CONTROL);
searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("uid");
searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("sn");
searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("cn");
searchCtrl.setString(SchemaConstants.PROP_SEARCH_EXPRESSION,
"@xsi:type='PersonAccount' and " + server2PropName + " > 4");
root = service.search(root);
System.out.println("Output datagraph -> " + printDO(root));
List searchResults = root.getList(SchemaConstants.DO_ENTITIES);
for (int i = 0; i < searchResults.size(); i++) {
DataObject ent = (DataObject) searchResults.get(i);
DataObject id = ent.getDataObject(SchemaConstants.DO_IDENTIFIER);
if (id != null) {
String uniqueName = id.getString(SchemaConstants.PROP_UNIQUE_NAME);
if (uniqueName != null) {
System.out.println("Found -> " + ent.getString("cn") + "(" + uniqueName + ")");
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Method to search on 'postOfficeBox'
* @param service
*/
@SuppressWarnings("unchecked")
private static void searchserver1PropName(Service service)
{
try
{
//Search
DataObject root = SDOHelper.createRootDataObject();
DataObject searchCtrl = SDOHelper.createControlDataObject(root, null,
SchemaConstants.DO_SEARCH_CONTROL);
searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("uid");
searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("sn");
searchCtrl.getList(SchemaConstants.PROP_PROPERTIES).add("cn");
searchCtrl.setString(SchemaConstants.PROP_SEARCH_EXPRESSION,
"@xsi:type='PersonAccount' and " + server1PropName + "='4-23'");
root = service.search(root);
System.out.println("Output datagraph -> " + printDO(root));
List searchResults = root.getList(SchemaConstants.DO_ENTITIES);
for (int i = 0; i < searchResults.size(); i++) {
DataObject ent = (DataObject) searchResults.get(i);
DataObject id = ent.getDataObject(SchemaConstants.DO_IDENTIFIER);
if (id != null) {
String uniqueName = id.getString(SchemaConstants.PROP_UNIQUE_NAME);
if (uniqueName != null) {
System.out.println("Found -> " + ent.getString("cn") + "(" + uniqueName + ")");
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
『前提条件』のセクションのステップ 5 で説明したように、グローバル・スキーマを使用するように useGlobalSchema プロパティーを設定した場合、複数ドメインにわたる検索操作の実行時に、すべてのインスタンスで拡張されたプロパティーのすべてを使用することができます。 useGlobalSchema を設定しない場合は、ドメイン固有のスキーマのみが拡張され、検索操作は、現行インスタンスで拡張されたプロパティーのみに基づいて実行されます。