Simple Example

mguymon edited this page Sep 4, 2012 · 5 revisions

Creating a model


ModelFactory modelFactory = new ModelFactory();
modelFactory.registerBlueprint( CarBlueprint.class );
Car car = modelFactory.createModel(Car.class);

Creating a model overriding defaults


Car car = new Car()
car.setMake( "Caddie" );
car = modelFactory.createModel(car);

Car Model


public class Car {
    private String make;
    private String manufacturer;
    private Integer mileage;
    private Map status;

    public String getMake() {
        return make;
    }

    public void setMake(String make) {
        this.make = make;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public Integer getMileage() {
        return mileage;
    }

    public void setMileage(Integer mileage) {
        this.milage = mileage;
    }

    public Map getStatus() {
        return status;
    }

    public void setStatus(Map status) {
        this.status = status;
    }
}

Car model’s Blueprint


@Blueprint(Car.class)
public class CarBlueprint {
    
    @Default
    String make = "car make";
        
    @Default
    String manufacturer = "car manufacturer";
        
    @Default
    Integer mileage = 100;
        
    @Default
    Map status = new HashMap();
}