1 package com.db4odoc.f1.diagnostics; 2 3 import com.db4o.*; 4 import com.db4o.config.*; 5 6 public class CarTranslator 7 implements ObjectConstructor { 8 public Object onStore(ObjectContainer container, 9 Object applicationObject) { 10 Car car =(Car)applicationObject; 11 12 String fullModel; 13 if (hasYear(car.getModel())){ 14 fullModel = car.getModel(); 15 } else { 16 fullModel = car.getModel() + getYear(car.getModel()); 17 } 18 return new Object []{fullModel}; 19 } 20 21 private String getYear(String carModel){ 22 if (carModel.equals("BMW")){ 23 return " 2002"; 24 } else { 25 return " 1999"; 26 } 27 28 } 29 30 private boolean hasYear(String carModel){ 31 return false; 32 } 33 34 public Object onInstantiate(ObjectContainer container, Object storedObject) { 35 Object [] raw=(Object [])storedObject; 36 String model=(String )raw[0]; 37 return new Car(model); 38 } 39 40 public void onActivate(ObjectContainer container, 41 Object applicationObject, Object storedObject) { 42 } 43 44 public Class storedClass() { 45 return Object [].class; 46 } 47 } | Popular Tags |