StoredClass and StoredField interfaces

(IStoredClass and IStoredField in .NET)

Let's look closer at the class meta-information interfaces.

They look quite similar to reflection API, but unlike reflection there is no information about methods and constructors.

You can only use StoredClass to get the class's fields:

Java: StoredClass#getStoredFields()

returns all stored fields of this stored class.

Java: StoredClass#storedField(name, type)

returns an existing stored field of this stored class.

You can also use this interface to explore classes hierarchy.

Java: StoredClass#getParentStoredClass

returns the parent of the class.

StoredField interface gives you access to various meta-field information, such as field name, field type. It also provides some helpful methods for manipulating fields accepting their object as a variable (see db4o API for more information).

MetaInfExample.java: getMetaObjectsInfo
01public static void getMetaObjectsInfo(){ 02 ObjectContainer oc = Db4o.openFile(Util.YAPFILENAME); 03 try { 04 System.out.println("Retrieve meta information for field: "); 05 StoredClass sc = oc.ext().storedClass(Car.class.getName()); 06 StoredField sf = sc.storedField("pilot",Pilot.class); 07 System.out.println("Field info: "+ sf.getName()+"/"+sf.getStoredType()+"/isArray="+sf.isArray()); 08 09 System.out.println("Retrieve all fields: "); 10 StoredField sfields[] = sc.getStoredFields(); 11 for (int i=0; i< sfields.length; i++){ 12 System.out.println("Stored field: "+ sfields[i].getName()+"/"+sfields[i].getStoredType()); 13 } 14 } finally { 15 oc.close(); 16 } 17 }