-
Notifications
You must be signed in to change notification settings - Fork 1
Inheritance
Bio Object can be extended in order to add new tags. But @BioObj
must exist in sub class also. In this case bio dictionary will contain different Bio Object but including tags of super class.
@BioObj
public class Car extends BioObject {
@BioTag(type="String", isInheritable=false)
public static final String PRODUCER = "producer" ;
@BioTag(type="Engine")
public static final String ENGINE = "engine" ;
@BioTag(type="Integer", initial="2007")
public static final String YEAR_OF_PRODUCTION = "year_of_production" ;
@BioTag(type="Boolean", expression="year_of_production > 2016")
public static final String IS_NEW_CAR = "is_new_car" ;
@BioTag(type="String", isExportable=false)
public static final String KEY_PASSWORD = "key_password" ;
@BioTag(type="Long", isEncodable=false)
public static final String MILEAGE = "mileage" ;
}
@BioObj
public class SportCar extends Car {
@BioTag(type="Integer")
public static final String MAX_SPEED = "max_speed" ;
}
Currently bio dictionary will contain two different Bio Objects Car
and SportCar
.
<?xml version="1.0" encoding="UTF-8"?>
<dictionary code="0">
<obj type="Car" name="car" code="28201" version="0" class="com.linkedlogics.bio.test.car.Car">
<tag name="key_password" code="838" type="String" is-xml-exportable="false"/>
<tag name="year_of_production" code="1031" type="Integer" initial="2007"/>
<tag name="engine" code="8335" type="Engine"/>
<tag name="producer" code="10263" type="String"/>
<tag name="mileage" code="24437" type="Long" is-encodable="false"/>
<tag name="is_new_car" code="32389" type="Boolean" expression="year_of_production > 2016"/>
</obj>
<obj type="SportCar" name="sport_car" code="31721" version="0" class="com.linkedlogics.bio.test.car.SportCar">
<tag name="key_password" code="838" type="String" is-xml-exportable="false"/>
<tag name="year_of_production" code="1031" type="Integer" initial="2007"/>
<tag name="engine" code="8335" type="Engine"/>
<tag name="max_speed" code="11847" type="Integer"/>
<tag name="mileage" code="24437" type="Long" is-encodable="false"/>
<tag name="is_new_car" code="32389" type="Boolean" expression="year_of_production > 2016"/>
</obj>
</dictionary>
Note that SportCar
doesn't contain producer because it is isInheritable=false
but contains additional max_speed.
If subclass also has same class name or has same value in type
property inside @BioObj
annotation then Bio Object definition is replaced with upcoming child class.
package com.linkedlogics.bio.test.car;
@BioObj
public class Car extends BioObject {
@BioTag(type="String", isInheritable=false)
public static final String PRODUCER = "producer" ;
@BioTag(type="Engine")
public static final String ENGINE = "engine" ;
@BioTag(type="Integer", initial="2007")
public static final String YEAR_OF_PRODUCTION = "year_of_production" ;
@BioTag(type="Boolean", expression="year_of_production > 2016")
public static final String IS_NEW_CAR = "is_new_car" ;
@BioTag(type="String", isExportable=false)
public static final String KEY_PASSWORD = "key_password" ;
@BioTag(type="Long", isEncodable=false)
public static final String MILEAGE = "mileage" ;
}
and
package com.linkedlogics.bio.test.car.ext;
@BioObj
public class Car extends com.linkedlogics.bio.test.car.Car {
@BioTag(type="Integer")
public static final String MAX_SPEED = "max_speed" ;
}
Here com.linkedlogics.bio.test.car.ext.Car
is more recent and contains inherited and additional tags. In this case dictionary will replace old Car
class with newer one.
<?xml version="1.0" encoding="UTF-8"?>
<dictionary code="0">
<obj type="Car" name="car" code="28201" version="0" class="com.linkedlogics.bio.test.car.ext.Car">
<tag name="key_password" code="838" type="String" is-xml-exportable="false"/>
<tag name="year_of_production" code="1031" type="Integer" initial="2007"/>
<tag name="engine" code="8335" type="Engine"/>
<tag name="max_speed" code="11847" type="Integer"/>
<tag name="mileage" code="24437" type="Long" is-encodable="false"/>
<tag name="is_new_car" code="32389" type="Boolean" expression="year_of_production > 2016"/>
</obj>
<obj type="SportCar" name="sport_car" code="31721" version="0" class="com.linkedlogics.bio.test.car.SportCar">
<tag name="key_password" code="838" type="String" is-xml-exportable="false"/>
<tag name="year_of_production" code="1031" type="Integer" initial="2007"/>
<tag name="engine" code="8335" type="Engine"/>
<tag name="max_speed" code="11847" type="Integer"/>
<tag name="mileage" code="24437" type="Long" is-encodable="false"/>
<tag name="is_new_car" code="32389" type="Boolean" expression="year_of_production > 2016"/>
</obj>
</dictionary>
And if factory methods will be used to create Bio Objects you will get instance of newer class.
Car c = BioDictionary.getDictionary().getFactory().newBioObject(Car.class) ;
System.out.println(c.getClass()) ;
class com.linkedlogics.bio.test.car.ext.Car