Skip to content
stemey edited this page Oct 20, 2012 · 7 revisions

A view offers an easy way to visit an object graph. A view is defined on an EntityType. It includes a subset of the type's attributes. If an included attribute is an association the view can cascade to the associated EntityType.

// create a viewBuilder for Person.class
EntityType personType=entityTypeRepository.getEntityType(Person.class);
// create a viewBuilder for Person.class
ViewBuilder builder = viewBuilderFactory.create(personType);
// include all attributes
builder.includePrimitives();
// remove attribute "firstName" from the attributes.
builder.exclude("firstName");
ViewBuilder paymentMethodBuilder = builder.include(PaymentMethod.class).cascade();
// include all attributes in PaymentMethod
paymentMethodBuilder.includePrimitives(false);
// create the view
View view = builder.create();

builder.visit(new ViewVisitor<Object>) {
	void visit(Object ctx, Attribute attribute, AttributeVisitor<?> attributeVisitor) {
		// do something with the attribute
		// visit the target view (e.g. PaymentMethod)
		attributeVisitor.visit(ctx);
	}
	void visit(Object ctx, Attribute attribute) {
		// do something with the attribute
	}
},null);

General usage

EntityType operation

###Configuration

  • classpath:/meta/utility/view.xml : classpath scanning
  • classpath:/meta/utility/view-example.xml : defines component "meta-utility-viewBuilderFactory"

###See test as example

ViewBuilderTest

Clone this wiki locally