/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package converter; import entity.Person; import java.net.URI; import java.util.Collection; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlAttribute; import java.util.ArrayList; /** * * @author lukas */ @XmlRootElement(name = "people") public class PeopleConverter { private Collection entities; private Collection items; private URI uri; private int expandLevel; /** Creates a new instance of PeopleConverter */ public PeopleConverter() { } /** * Creates a new instance of PeopleConverter. * * @param entities associated entities * @param uri associated uri * @param expandLevel indicates the number of levels the entity graph should be expanded */ public PeopleConverter(Collection entities, URI uri, int expandLevel) { this.entities = entities; this.uri = uri; this.expandLevel = expandLevel; } /** * Returns a collection of PersonConverter. * * @return a collection of PersonConverter */ @XmlElement public Collection getPerson() { if (items == null) { items = new ArrayList(); } if (entities != null) { for (Person entity : entities) { items.add(new PersonConverter(entity, uri, expandLevel, true)); } } return items; } /** * Sets a collection of PersonConverter. * * @param a collection of PersonConverter to set */ public void setPerson(Collection items) { this.items = items; } /** * Returns the URI associated with this converter. * * @return the uri */ @XmlAttribute public URI getUri() { return uri; } /** * Returns a collection Person entities. * * @return a collection of Person entities */ @XmlTransient public Collection getEntities() { entities = new ArrayList(); if (items != null) { for (PersonConverter item : items) { entities.add(item.getEntity()); } } return entities; } }