Skip to content
Michael Guymon edited this page Nov 20, 2013 · 8 revisions

Constructor Callback

If the Model is unable to use the default constructor, the ConstructorCallback can be defined to be used by the ModelFactory to create the Model.

@Blueprint(Wheel.class)
public class WheelBlueprint {

  ConstructorCallback constructor = new ConstructorCallback() {

	@Override
	public Object createInstance() {
		Wheel wheel = new Wheel( "tire name" );
		return wheel;
	}
	
  };

  @Default
  public Integer size = 10;
}

Field Callbacks

Using the FieldCallback, a field can be uniquely created every time by the ModelFactory. Example below showing a @Blueprint to create a unique String username and a list of unique List of email addresses.

@Blueprint(User.class )
public class UserBlueprint {

  @Default
  public FieldCallback username = new FieldCallback() {

	@Override
	public String get( Object model) {
		return "username" + UUID.randomUUID();
	}
	
  };

  @Default
  public FieldCallback emails = new FieldCallBack() {

	@Override
	public List<String> get( Object model) {
		List<String> emails = new ArrayList();
		emails.add( "email" + UUID.randomUUID() + "@test.net" );
		emails.add( "email" + UUID.randomUUID() + "@test.net" );
		emails.add( "email" + UUID.randomUUID() + "@test.net" );
		
		return emails;
	}
	
  };
}
Clone this wiki locally