カスタム・オブジェクトの操作
CustomObject オブジェクトの作成
CustomObject オブジェクトを作成するには、以下の手順に従います。
- Factory.CustomObject.createInstance メソッドを呼び出します。
- 新しいカスタム・オブジェクトの save メソッドを呼び出します。
次のコード例に、CustomObject オブジェクトの作成方法を示します。
Java™ の例
// CustomObject オブジェクトを作成
CustomObject objCustomObject = Factory.CustomObject.createInstance(objObjectStore, "CustomObject");
objCustomObject.save(RefreshMode.REFRESH);
System.out.println("Custom object created: " + objCustomObject.get_Name());
System.out.println(objCustomObject);
C# の例
// CustomObject オブジェクトを作成
ICustomObject objCustomObject = Factory.CustomObject.CreateInstance(objObjectStore, "CustomObject");
objCustomObject.Save(RefreshMode.REFRESH);
Console.WriteLine("Custom object created: " + objCustomObject.Name);
Console.WriteLine(objCustomObject);
CustomObject オブジェクトの取得
次のコード例に、CustomObject オブジェクトの取得方法を示します。
Java の例
System.out.println("Type the path name of the CustomObject object to retrieve (/<folder name>/<containment name>):");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
String strPath = in.readLine();
// CustomObject オブジェクトを取得する
CustomObject objCustomObject = Factory.CustomObject.fetchInstance(objObjectStore, strPath, null);
objCustomObject.save(RefreshMode.REFRESH);
System.out.println("CustomObject object retrieved: " + objCustomObject.get_Name());
System.out.println(objCustomObject);
C# の例
Console.WriteLine("Type the path name of the CustomObject object to retrieve (/<folder name>/<containment name>):");
String strPath = Console.ReadLine();
// CustomObject オブジェクトを取得する
ICustomObject objCustomObject = Factory.CustomObject.FetchInstance(objObjectStore, strPath, null);
objCustomObject.Save(RefreshMode.REFRESH);
Console.WriteLine("CustomObject object retrieved: " + objCustomObject.Name);
Console.WriteLine(objCustomObject);
CustomObject サブクラスの作成およびカスタム名プロパティーの追加
CustomObject クラスのサブクラスを作成して、カスタム名プロパティーを追加するには、以下の手順に従います。
- Factory.ClassDefinition.fetchInstance メソッドを呼び出して、CustomObject クラスを定義する ClassDefinition オブジェクトをフェッチします。
- ClassDefinition オブジェクトの createSubclass メソッドを呼び出して、新しい ClassDefinition オブジェクトを CustomObject クラスのサブクラスとして作成します。
- Factory.LocalizedString.createInstance を呼び出して LocalizedString オブジェクトを作成し、その LocalizedText プロパティーと LocaleName プロパティーを設定します。
- Factory.LocalizedString.createList を呼び出して LocalizedStringList コレクション・オブジェクトを作成し、それを新しい ClassDefinition オブジェクトの DisplayNames プロパティーに設定します。
- 新しい ClassDefinition オブジェクトの save メソッドを呼び出して、オブジェクトを保存します。
- Factory.PropertyTemplateString.createInstance メソッドを呼び出して、PropertyTemplateString オブジェクトを作成します。
- 新しい PropertyTemplateString オブジェクトの Cardinality プロパティーを設定し、単一カーディナリティーを指定します。
- Factory.LocalizedString.createInstance メソッドを呼び出して LocalizedString オブジェクトを作成し、その LocalizedText プロパティーと LocaleName プロパティーを設定します。
- Factory.LocalizedString.createList メソッドを呼び出して、LocalizedStringList コレクション・オブジェクトを作成し、それを新しい PropertyTemplateString オブジェクトの DisplayNames プロパティーに設定します。
- 新しい PropertyTemplateString オブジェクトの save メソッドを呼び出して、オブジェクトを保存します。
- 新しい PropertyTemplateString オブジェクトの createClassProperty メソッドを呼び出して、新しい PropertyDefinitionString オブジェクトを作成します。
- 新しい PropertyDefinitionString オブジェクトの IsNameProperty を true に設定し、それを新しい CustomObject サブクラスの名前プロパティーとして指定します。
- 新しい ClassDefinition オブジェクトの PropertyDefinitions プロパティーから PropertyDefinitionList コレクション・オブジェクトを取得し、その add メソッドを呼び出して新しい PropertyDefinitionString オブジェクトをコレクションに追加します。
- 新しい ClassDefinition オブジェクトの save メソッドを呼び出して、プロパティー定義の変更内容を保存します。
次のコード例に、CustomObject クラスのサブクラスを作成して、カスタム名プロパティーを追加する方法を示します。
Java の例
System.out.println("Type the name of the new CustomObject subclass:");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
String strClassName = in.readLine();
// CustomObject クラス定義をフェッチする
ClassDefinition objClassDefCO = Factory.ClassDefinition.fetchInstance(objObjectStore, GuidConstants.Class_CustomObject, null);
// CustomObject クラスのサブクラスを作成する
ClassDefinition objClassDefCOSub = objClassDefCO.createSubclass();
// ロケールを設定する
LocalizedString objLocStrCD = Factory.LocalizedString.createInstance();
objLocStrCD.set_LocalizedText(strClassName);
objLocStrCD.set_LocaleName(objObjectStore.get_LocaleName());
// LocalizedStringList コレクションを作成する
objClassDefCOSub.set_DisplayNames(Factory.LocalizedString.createList());
objClassDefCOSub.get_DisplayNames().add(objLocStrCD);
// 新規クラス定義をサーバーに保存する
objClassDefCOSub.save(RefreshMode.REFRESH);
System.out.println("New CustomObject subclass: " + objClassDefCOSub.get_Name());
System.out.println(objClassDefCOSub);
// プロパティー・フィルターを作成して、クラス定義の PropertyDefinitions プロパティーが評価済みとして返されるようにする
PropertyFilter pf = new PropertyFilter();
pf.addIncludeType(0, null, Boolean.TRUE, FilteredPropertyType.ANY, null);
// 単一値ストリング・プロパティーのプロパティー・テンプレートを作成する
System.out.println("Type the name of the new custom name property:");
String strTemplateName = in.readLine();
PropertyTemplateString objPropTemplate = Factory.PropertyTemplateString.createInstance(objObjectStore);
// プロパティー・テンプレートから作成されるプロパティーのカーディナリティーを設定する
objPropTemplate.set_Cardinality(Cardinality.SINGLE);
// ロケールを設定する
LocalizedString objLocStrPT = Factory.LocalizedString.createInstance();
objLocStrPT.set_LocalizedText(strTemplateName);
objLocStrPT.set_LocaleName(objObjectStore.get_LocaleName());
// LocalizedStringList コレクションを作成する
objPropTemplate.set_DisplayNames(Factory.LocalizedString.createList());
objPropTemplate.get_DisplayNames().add(objLocStrPT);
// 新規プロパティー・テンプレートをサーバーに保存する
objPropTemplate.save(RefreshMode.REFRESH);
// プロパティー・テンプレートからプロパティー定義を作成する
PropertyDefinitionString objPropDef = (PropertyDefinitionString) objPropTemplate.createClassProperty();
// 指定の名前プロパティーとしてカスタム・プロパティーを設定する
objPropDef.set_IsNameProperty(true);
// PropertyDefinitions プロパティーをプロパティー・キャッシュから取得する
PropertyDefinitionList objPropDefs = objClassDefCOSub.get_PropertyDefinitions();
// 新規プロパティー定義をクラス定義に追加する
objPropDefs.add(objPropDef);
objClassDefCOSub.save(RefreshMode.REFRESH);
System.out.println("New property definition for custom name property: ");
System.out.println(objPropDef);
C# の例
Console.WriteLine("Type the name of the new CustomObject subclass:");
String strClassName = Console.ReadLine();
// CustomObject クラス定義を取得する
IClassDefinition objClassDefCO = Factory.ClassDefinition.FetchInstance(objObjectStore, GuidConstants.Class_CustomObject, null);
// CustomObject クラスのサブクラスを作成する
IClassDefinition objClassDefCOSub = objClassDefCO.CreateSubclass();
// ロケールを設定する
ILocalizedString objLocStrCD = Factory.LocalizedString.CreateInstance();
objLocStrCD.LocalizedText = strClassName;
objLocStrCD.LocaleName = objObjectStore.LocaleName;
// LocalizedStringList コレクションを作成する
objClassDefCOSub.DisplayNames = Factory.LocalizedString.CreateList();
objClassDefCOSub.DisplayNames.Add(objLocStrCD);
// 新規クラス定義をサーバーに保存する
objClassDefCOSub.Save(RefreshMode.REFRESH);
Console.WriteLine("New CustomObject subclass: " + objClassDefCOSub.Name);
Console.WriteLine(objClassDefCOSub);
// プロパティー・フィルターを作成して、クラス定義の PropertyDefinitions プロパティーが評価済みとして返されるようにする
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeType(0, null, true, FilteredPropertyType.ANY, null);
// 単一値ストリング・プロパティーのプロパティー・テンプレートを作成する
Console.WriteLine("Type the name of the new custom name property:");
String strTemplateName = Console.ReadLine();
IPropertyTemplateString objPropTemplate = Factory.PropertyTemplateString.CreateInstance(objObjectStore);
// プロパティー・テンプレートから作成されるプロパティーのカーディナリティーを設定する
objPropTemplate.Cardinality = Cardinality.SINGLE;
// ロケールを設定する
ILocalizedString objLocStrPT = Factory.LocalizedString.CreateInstance();
objLocStrPT.LocalizedText = strTemplateName;
objLocStrPT.LocaleName = objObjectStore.LocaleName;
// LocalizedStringList コレクションを作成する
objPropTemplate.DisplayNames = Factory.LocalizedString.CreateList();
objPropTemplate.DisplayNames.Add(objLocStrPT);
// 新規プロパティー・テンプレートをサーバーに保存する
objPropTemplate.Save(RefreshMode.REFRESH);
// プロパティー・テンプレートからプロパティー定義を作成する
IPropertyDefinitionString objPropDef = (IPropertyDefinitionString) objPropTemplate.CreateClassProperty();
// 指定の名前プロパティーとしてカスタム・プロパティーを設定する
objPropDef.IsNameProperty = true;
// PropertyDefinitions プロパティーをプロパティー・キャッシュから取得する
IPropertyDefinitionList objPropDefs = objClassDefCOSub.PropertyDefinitions;
// 新規プロパティー定義をクラス定義に追加する
objPropDefs.Add(objPropDef);
objClassDefCOSub.Save(RefreshMode.REFRESH);
Console.WriteLine("New property definition for custom name property: ");
Console.WriteLine(objPropDef);
Console.WriteLine("Press any key to end");
Console.ReadLine();