Author: tchemit Date: 2013-02-04 02:48:10 +0100 (Mon, 04 Feb 2013) New Revision: 324 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/324 Log: fix decorator Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-02-04 01:35:24 UTC (rev 323) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-02-04 01:48:10 UTC (rev 324) @@ -138,41 +138,9 @@ return bean == null ? "" : String.valueOf(bean); } }); - registerDecorator(new MultiJXPathDecorator<Vessel>(Vessel.class, "${name}$s#${internalRegistrationCode}$s", SEPARATOR, " - ") { + registerDecorator(new VesselMultiJXPathDecorator()); - private static final long serialVersionUID = 1L; - - @Override - protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { - Comparable result = super.getTokenValue(jxcontext, token); - if ("internalRegistrationCode".equals(token)) { - if (result == null || "null".equals(result)) { - result = _("tutti.propety.no.vessel.internalRegistrationCode"); - } - } else if ("name".equals(token)) { - if (result == null || "null".equals(result)) { - result = _("tutti.propety.no.vessel.name"); - } - } - return result; - } - }); - - registerDecorator(SPECIES_BY_CRUISE_CODE, new MultiJXPathDecorator<Species>(Species.class, "${cruiseCode}$s#${refTaxCode}$s#${name}$s", SEPARATOR, " - ") { - - private static final long serialVersionUID = 1L; - - @Override - protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { - Comparable result = super.getTokenValue(jxcontext, token); - if ("cruiseCode".equals(token)) { - if (result == null || "null".equals(result)) { - result = _("tutti.propety.no.species.cruiseCode"); - } - } - return result; - } - }); + registerDecorator(SPECIES_BY_CRUISE_CODE, new SpeciesMultiJXPathDecorator()); } }; } @@ -212,4 +180,57 @@ n_("tutti.property.caracteristic"); } + public static class SpeciesMultiJXPathDecorator extends MultiJXPathDecorator<Species> implements Cloneable { + + private static final long serialVersionUID = 1L; + + public SpeciesMultiJXPathDecorator() throws IllegalArgumentException, NullPointerException { + super(Species.class, "${cruiseCode}$s#${refTaxCode}$s#${name}$s", DecoratorService.SEPARATOR, " - "); + } + + @Override + protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { + Comparable result = super.getTokenValue(jxcontext, token); + if ("cruiseCode".equals(token)) { + if (result == null || "null".equals(result)) { + result = _("tutti.propety.no.species.cruiseCode"); + } + } + return result; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + } + + public static class VesselMultiJXPathDecorator extends MultiJXPathDecorator<Vessel> implements Cloneable { + + private static final long serialVersionUID = 1L; + + public VesselMultiJXPathDecorator() throws IllegalArgumentException, NullPointerException { + super(Vessel.class, "${name}$s#${internalRegistrationCode}$s", DecoratorService.SEPARATOR, " - "); + } + + @Override + protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) { + Comparable result = super.getTokenValue(jxcontext, token); + if ("internalRegistrationCode".equals(token)) { + if (result == null || "null".equals(result)) { + result = _("tutti.propety.no.vessel.internalRegistrationCode"); + } + } else if ("name".equals(token)) { + if (result == null || "null".equals(result)) { + result = _("tutti.propety.no.vessel.name"); + } + } + return result; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + } }