クラスの操作
以下の Java™ と C# のコード例は、クラス関連のオブジェクトを使用する操作を示しています。
ClassDescription オブジェクトの取得
オブジェクト・ストア内の特定の ClassDescription オブジェクトを検索するコード例を以下に示します。
Java の例
System.out.println("Type the symbolic name of the class description to retrieve:");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
String strSymbolicName = in.readLine();
// 選択したクラス記述をサーバーから取得する
ClassDescription objClassDesc = Factory.ClassDescription.fetchInstance(objObjectStore, strSymbolicName, null);
System.out.println("Class description selected: " + objClassDesc.get_SymbolicName());
System.out.println(objClassDesc);
C# の例
Console.WriteLine("Type the symbolic name of the class description to retrieve:");
String strSymbolicName = Console.ReadLine();
// 選択したクラス記述をサーバーから取得する
IClassDescription objClassDesc = Factory.ClassDescription.FetchInstance(objObjectStore, strSymbolicName, null);
Console.WriteLine("Class description selected: " + objClassDesc.SymbolicName);
Console.WriteLine(objClassDesc);
Console.WriteLine("Press any key to end");
Console.ReadLine();
ClassDefinition オブジェクトの取得
オブジェクト・ストア内の特定の ClassDefinition オブジェクトを検索するコード例を以下に示します。
Java の例
System.out.println("Type the symbolic name of the class definition to retrieve:");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
String strSymbolicName = in.readLine();
// 選択したクラス定義をサーバーから取得する
ClassDefinition objClassDef = Factory.ClassDefinition.fetchInstance(objObjectStore, strSymbolicName, null);
System.out.println("Class definition selected: " + objClassDef.get_SymbolicName());
System.out.println(objClassDef);
C# の例
Console.WriteLine("Type the symbolic name of the class definition to retrieve:");
String strSymbolicName = Console.ReadLine();
// 選択したクラス定義をサーバーから取得する
IClassDefinition objClassDef = Factory.ClassDefinition.FetchInstance(objObjectStore, strSymbolicName, null);
Console.WriteLine("Class definition selected: " + objClassDef.SymbolicName);
Console.WriteLine(objClassDef);
Console.WriteLine("Press any key to end");
Console.ReadLine();
サブクラスの作成、オブジェクト・インスタンスの作成、およびオブジェクトのクラスの変更
Folder サブクラスを作成し、そのクラスのオブジェクト・インスタンスを作成し、オブジェクトのクラスを変更するコード例を以下に示します。
Java の例
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
String strSymbolicName = "Folder";
// 選択したクラス定義をサーバーから取得する
ClassDefinition objClassDef = Factory.ClassDefinition.fetchInstance(objObjectStore, strSymbolicName, null);
System.out.println("Class definition selected: " + objClassDef.get_Name());
System.out.println("Type the name to assign to the new subclass:");
String strSubclassName = in.readLine();
//Folder クラスのサブクラスを作成
ClassDefinition objClassDefNew = objClassDef.createSubclass();
// ロケールを設定する
LocalizedString objLocStr = Factory.LocalizedString.createInstance();
objLocStr.set_LocalizedText(strSubclassName);
objLocStr.set_LocaleName(objObjectStore.get_LocaleName());
// LocalizedStringList コレクションを作成する
objClassDefNew.set_DisplayNames(Factory.LocalizedString.createList());
objClassDefNew.get_DisplayNames().add(objLocStr);
// 新規クラス定義をサーバーに保存する
objClassDefNew.save(RefreshMode.REFRESH);
System.out.println("New class definition created: " + objClassDefNew.get_Name());
System.out.println(objClassDefNew);
// 新しいオブジェクト・インスタンスを作成、必要なプロパティーを設定し、サーバーで保存
System.out.println("Type the FolderName property value to assign to the folder object instantiated from the new subclass:");
String strFolderName = in.readLine();
Folder objFolder = Factory.Folder.createInstance(objObjectStore, objClassDefNew.get_SymbolicName());
objFolder.set_FolderName(strFolderName);
objFolder.set_Parent(objObjectStore.get_RootFolder());
objFolder.save(RefreshMode.REFRESH);
System.out.println("Class of new object: " + objFolder.getClassName());
System.out.println("Name of new object: " + objFolder.get_Name());
System.out.println(objFolder);
// フォルダー・オブジェクトのクラスを Folder クラスに変更
objFolder.changeClass("Folder");
objFolder.save(RefreshMode.REFRESH);
System.out.println("Object's new class: " + objFolder.getClassName());
C# の例
String strSymbolicName = "Folder";
// 選択したクラス定義をサーバーから取得する
IClassDefinition objClassDef = Factory.ClassDefinition.FetchInstance(objObjectStore, strSymbolicName, null);
Console.WriteLine("Class definition selected: " + objClassDef.Name);
Console.WriteLine("Type the name to assign to the new subclass:");
String strSubclassName = Console.ReadLine();
//Folder クラスのサブクラスを作成
IClassDefinition objClassDefNew = objClassDef.CreateSubclass();
// ロケールを設定する
ILocalizedString objLocStr = Factory.LocalizedString.CreateInstance();
objLocStr.LocalizedText = strSubclassName;
objLocStr.LocaleName = objObjectStore.LocaleName;
// LocalizedStringList コレクションを作成する
objClassDefNew.DisplayNames = Factory.LocalizedString.CreateList();
objClassDefNew.DisplayNames.Add(objLocStr);
// 新規クラス定義をサーバーに保存する
objClassDefNew.Save(RefreshMode.REFRESH);
Console.WriteLine("New class definition created: " + objClassDefNew.Name);
Console.WriteLine(objClassDefNew);
// 新しいオブジェクト・インスタンスを作成、必要なプロパティーを設定し、サーバーで保存
Console.WriteLine("Type the FolderName property value to assign to a folder object instantiated from the new subclass:");
String strFolderName = Console.ReadLine();
IFolder objFolder = Factory.Folder.CreateInstance(objObjectStore, objClassDefNew.SymbolicName);
objFolder.FolderName = strFolderName;
objFolder.Parent = objObjectStore.RootFolder;
objFolder.Save(RefreshMode.REFRESH);
Console.WriteLine("Class of new object: " + objFolder.GetClassName());
Console.WriteLine("Name of new object: " + objFolder.Name);
Console.WriteLine(objFolder);
// フォルダー・オブジェクトのクラスを Folder クラスに変更
objFolder.ChangeClass("Folder");
objFolder.Save(RefreshMode.REFRESH);
Console.WriteLine("Object's new class: " + objFolder.GetClassName());
Console.WriteLine("Press any key to end");
Console.ReadLine();