Author: tchemit Date: 2010-09-07 12:47:05 +0200 (Tue, 07 Sep 2010) New Revision: 2073 Url: http://nuiton.org/repositories/revision/jaxx/2073 Log: make real bean + introduce DemoDecoratorProvider Added: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java trunk/jaxx-demo/src/main/java/jaxx/demo/entities/DemoDecoratorProvider.java Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Movie.java trunk/jaxx-demo/src/main/java/jaxx/demo/entities/People.java Added: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java (rev 0) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java 2010-09-07 10:47:05 UTC (rev 2073) @@ -0,0 +1,82 @@ +package jaxx.demo.entities; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.Serializable; + +import static org.nuiton.i18n.I18n.n_; + +/** + * Abstract demo bean. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.2 + */ +public abstract class AbstractDemoBean implements Serializable { + + static { + n_("jaxxdemo.common.id"); + n_("jaxxdemo.common.image"); + } + + public static final String PROPERTY_ID = "id"; + + public static final String PROPERTY_IMAGE = "image"; + + protected String id; + + protected String image; + + protected final PropertyChangeSupport p; + + public AbstractDemoBean() { + p = new PropertyChangeSupport(this); + } + + protected AbstractDemoBean(String id, String image) { + this(); + this.id = id; + this.image = image; + } + + public String getId() { + return id; + } + + public String getImage() { + return image; + } + + public void setId(String id) { + String old = this.id; + this.id = id; + firePropertyChange(PROPERTY_ID, old, id); + } + + + public void setImage(String image) { + Object oldValue = this.image; + this.image = image; + firePropertyChange(PROPERTY_IMAGE, oldValue, image); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + p.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + p.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + p.removePropertyChangeListener(listener); + } + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + p.removePropertyChangeListener(propertyName, listener); + } + + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + p.firePropertyChange(propertyName, oldValue, newValue); + } +} Added: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/DemoDecoratorProvider.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/DemoDecoratorProvider.java (rev 0) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/DemoDecoratorProvider.java 2010-09-07 10:47:05 UTC (rev 2073) @@ -0,0 +1,27 @@ +package jaxx.demo.entities; + +import jaxx.runtime.decorator.DecoratorProvider; + +/** + * Demo decorator provider. + * + * @author tchemit <chemit@codelutin.com> + * @see DecoratorProvider + * @since 2.2 + */ +public class DemoDecoratorProvider extends DecoratorProvider { + @Override + protected void loadDecorators() { + + // load movie decorator + registerMultiJXPathDecorator(Movie.class, + "${title}$s#${year}$s", "#", " - "); + + // load people decorator + registerMultiJXPathDecorator(People.class, + "${firstName}$s#${lastName}$s#${age}$s", + "#", + " - " + ); + } +} Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java 2010-09-07 10:46:24 UTC (rev 2072) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java 2010-09-07 10:47:05 UTC (rev 2073) @@ -29,8 +29,10 @@ import java.beans.PropertyChangeSupport; import java.io.File; +import static org.nuiton.i18n.I18n.n_; + public class Identity { - + protected String firstName = ""; protected String lastName = ""; @@ -43,7 +45,7 @@ protected File dir = new File("/tmp"); - PropertyChangeSupport p; + protected final PropertyChangeSupport p; public Identity() { p = new PropertyChangeSupport(this); Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Movie.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Movie.java 2010-09-07 10:46:24 UTC (rev 2072) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Movie.java 2010-09-07 10:47:05 UTC (rev 2073) @@ -31,76 +31,82 @@ import java.util.ArrayList; import java.util.List; +import static org.nuiton.i18n.I18n.n_; + /** * @author tchemit <chemit@codelutin.com> * @since 1.7.2 */ -public class Movie { +public class Movie extends AbstractDemoBean { - protected String id; + static { + n_("jaxxdemo.common.movie"); + n_("jaxxdemo.common.title"); + n_("jaxxdemo.common.year"); + n_("jaxxdemo.common.actors"); + } protected String title; - protected String image; - protected int year; protected List<People> actors; + private static final long serialVersionUID = 1L; + + private static final String PROPERTY_ACTORS = "actors"; + + private static final String PROPERTY_TITLE = "title"; + + private static final String PROPERTY_YEAR = "year"; + + private static final String PROPERTY_IMAGE = "image"; + public Movie(String id, String title, int year, String image) { - this(); - this.id = id; + super(id, image); this.title = title; this.year = year; - this.image = image; + actors = new ArrayList<People>(); } public Movie() { actors = new ArrayList<People>(); } - public String getId() { - return id; + public List<People> getActors() { + return actors; } - public void setId(String id) { - this.id = id; + public String getTitle() { + return title; } - public List<People> getActors() { - return actors; + public int getYear() { + return year; } public void setActors(List<People> actors) { + Object oldValue = this.actors; this.actors = actors; + firePropertyChange(PROPERTY_ACTORS, null, actors); } - public String getTitle() { - return title; - } - public void setTitle(String title) { + Object oldValue = this.title; this.title = title; + firePropertyChange(PROPERTY_TITLE, oldValue, title); } - public int getYear() { - return year; - } - public void setYear(int year) { + Object oldValue = this.year; this.year = year; + firePropertyChange(PROPERTY_YEAR, oldValue, year); } - public String getImage() { - return image; - } - public void setImage(String image) { - this.image = image; - } - public void addActor(People actor) { actors.add(actor); + firePropertyChange(PROPERTY_ACTORS, null, actors); } @Override @@ -111,27 +117,25 @@ if (getClass() != obj.getClass()) { return false; } - final Movie other = (Movie) obj; - if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) { - return false; - } - return true; + Movie other = (Movie) obj; + return !(id == null ? other.id != null : !id.equals(other.id)); } @Override public int hashCode() { int hash = 5; - hash = 41 * hash + (this.id != null ? this.id.hashCode() : 0); + hash = 41 * hash + (id != null ? id.hashCode() : 0); return hash; } @Override public String toString() { ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); - b.append("id", id); - b.append("title", title); - b.append("year", year); - b.append("actors", actors); + b.append(PROPERTY_ID, id); + b.append(PROPERTY_TITLE, title); + b.append(PROPERTY_IMAGE, image); + b.append(PROPERTY_YEAR, year); + b.append(PROPERTY_ACTORS, actors); return b.toString(); } } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/People.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/People.java 2010-09-07 10:46:24 UTC (rev 2072) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/People.java 2010-09-07 10:47:05 UTC (rev 2073) @@ -28,70 +28,83 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import static org.nuiton.i18n.I18n.n_; + /** * @author tchemit <chemit@codelutin.com> * @since 1.7.2 */ -public class People { +public class People extends AbstractDemoBean { - protected String id; + static { + n_("jaxxdemo.common.people"); + n_("jaxxdemo.common.firstName"); + n_("jaxxdemo.common.lastName"); + n_("jaxxdemo.common.age"); + } - protected String image; + public static final String PROPERTY_FIRST_NAME = "firstName"; + public static final String PROPERTY_LAST_NAME = "lastName"; + + public static final String PROPERTY_AGE = "age"; + protected String firstName; protected String lastName; protected int age; - public People(String id, String firstName, String lastName, int age, String image) { - this.id = id; + private static final long serialVersionUID = 1L; + + public People() { + } + + public People(String id, + String firstName, + String lastName, + int age, + String image) { + super(id, image); this.firstName = firstName; this.lastName = lastName; this.age = age; - this.image = image; } public int getAge() { return age; } - public void setAge(int age) { - this.age = age; - } - public String getFirstName() { return firstName; } - public void setFirstName(String firstName) { - this.firstName = firstName; + public String getLastName() { + return lastName; } - public String getId() { - return id; + public String getImage() { + return image; } - public void setId(String id) { - this.id = id; + public void setAge(int age) { + int old = this.age; + this.age = age; + firePropertyChange(PROPERTY_AGE, old, age); } - public String getLastName() { - return lastName; + public void setFirstName(String firstName) { + String old = this.firstName; + this.firstName = firstName; + firePropertyChange(PROPERTY_FIRST_NAME, old, firstName); } public void setLastName(String lastName) { + String old = this.lastName; this.lastName = lastName; + firePropertyChange(PROPERTY_LAST_NAME, old, lastName); } - public String getImage() { - return image; - } - - public void setImage(String image) { - this.image = image; - } - @Override public boolean equals(Object obj) { if (obj == null) { @@ -100,27 +113,25 @@ if (getClass() != obj.getClass()) { return false; } - final People other = (People) obj; - if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) { - return false; - } - return true; + People other = (People) obj; + return !(id == null ? other.id != null : !id.equals(other.id)); } @Override public int hashCode() { int hash = 7; - hash = 97 * hash + (this.id != null ? this.id.hashCode() : 0); + hash = 97 * hash + (id != null ? id.hashCode() : 0); return hash; } @Override public String toString() { ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); - b.append("id", id); - b.append("firstName", firstName); - b.append("lastName", lastName); - b.append("age", age); + b.append(PROPERTY_ID, id); + b.append(PROPERTY_FIRST_NAME, firstName); + b.append(PROPERTY_LAST_NAME, lastName); + b.append(PROPERTY_IMAGE, image); + b.append(PROPERTY_AGE, age); return b.toString(); } }