Changeset 3584

Show
Ignore:
Timestamp:
04/02/08 14:49:12 (4 years ago)
Author:
michael
Message:

0.4.1 release - support restlet-jpa 0.2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build.properties

    r3013 r3584  
    11project.name=xtc 
    22project.rev=0.4.1 
    3 project.status=integration 
     3project.status=release 
  • trunk/ivy.xml

    r3011 r3584  
    1515  <dependencies> 
    1616    <dependency org="de.odysseus.juel" name="juel" rev="2.1.0" conf="default"/> 
    17     <dependency org="sarugo" name="restlet-jpa" rev="latest.${project.status}" conf="restlet,compile->default"/> 
    18     <dependency org="org.restlet" name="org.restlet" rev="1.0.4" conf="restlet,compile->default"/> 
    19     <dependency org="com.noelios.restlet" name="com.noelios.restlet.ext.simple" rev="1.0.4" conf="compile->default"/> 
     17    <dependency org="sarugo" name="restlet-jpa" rev="0.2" conf="restlet,compile->default"/> 
     18    <dependency org="org.restlet" name="org.restlet" rev="1.1-SNAPSHOT" conf="restlet,compile->default"/> 
     19    <dependency org="com.noelios.restlet" name="com.noelios.restlet.ext.simple" rev="1.1-SNAPSHOT" conf="compile->default"/> 
    2020    <dependency org="javax.servlet" name="servlet-api" rev="2.5" conf="compile->default" /> 
    21     <dependency org="com.noelios.restlet" name="com.noelios.restlet.ext.net" rev="1.0.4" conf="test->default"/> 
     21    <dependency org="com.noelios.restlet" name="com.noelios.restlet.ext.net" rev="1.1-SNAPSHOT" conf="test->default"/> 
    2222    <dependency org="junit" name="junit" rev="3.8.1" conf="test->default"/> 
    2323    <dependency org="xmlunit" name="xmlunit" rev="1.0" conf="test->default"/> 
  • trunk/src/main/java/org/sarugo/xtc/restlet/jpa/TemplateConverter.java

    r2958 r3584  
    1818 
    1919import java.io.IOException; 
     20import java.util.Collection; 
     21import java.util.Collections; 
    2022 
    2123import javax.el.ELException; 
     
    2426import org.restlet.resource.Representation; 
    2527import org.restlet.resource.Variant; 
    26 import org.sarugo.restlet.jpa.PersistenceConverter; 
    27 import org.sarugo.restlet.jpa.PersistenceResource; 
     28import org.sarugo.restlet.jpa.converter.OutputConverter; 
     29import org.sarugo.restlet.jpa.resource.EntityCollection; 
     30import org.sarugo.restlet.jpa.resource.EntityInstance; 
     31import org.sarugo.restlet.jpa.resource.EntityResource; 
    2832import org.sarugo.xtc.Template; 
    2933import org.sarugo.xtc.TemplateException; 
     
    3135import org.sarugo.xtc.restlet.TemplateRepresentation; 
    3236 
    33 public class TemplateConverter extends PersistenceConverter
     37public class TemplateConverter<E> implements OutputConverter<E>
    3438 
    35        private Template template; 
     39    private Template template; 
    3640 
    37        private MediaType mediaType; 
     41    private MediaType mediaType; 
    3842 
    39        private Template listTemplate; 
     43    private Template listTemplate; 
    4044 
    41        public TemplateConverter(String listTemplate) throws TemplateException, 
    42                        ELException, IOException { 
    43                this(listTemplate, MediaType.APPLICATION_XHTML_XML); 
    44        
     45    public TemplateConverter(String listTemplate) throws TemplateException, 
     46            ELException, IOException { 
     47        this(listTemplate, MediaType.APPLICATION_XHTML_XML); 
     48   
    4549 
    46        public TemplateConverter(String listTemplate, MediaType mediaType) 
    47                        throws TemplateException, ELException, IOException { 
    48                this(listTemplate, null, mediaType); 
    49        
     50    public TemplateConverter(String listTemplate, MediaType mediaType) 
     51            throws TemplateException, ELException, IOException { 
     52        this(listTemplate, null, mediaType); 
     53   
    5054 
    51        public TemplateConverter(String listTemplate, String template) 
    52                        throws TemplateException, ELException, IOException { 
    53                this(listTemplate, template, MediaType.APPLICATION_XHTML_XML); 
    54        
     55    public TemplateConverter(String listTemplate, String template) 
     56            throws TemplateException, ELException, IOException { 
     57        this(listTemplate, template, MediaType.APPLICATION_XHTML_XML); 
     58   
    5559 
    56        public TemplateConverter(String listTemplate, String template, 
    57                        MediaType mediaType) throws TemplateException, ELException, 
    58                        IOException { 
    59                setListTemplate(listTemplate); 
    60                setTemplate(template); 
    61                this.mediaType = mediaType; 
    62        
     60    public TemplateConverter(String listTemplate, String template, 
     61            MediaType mediaType) throws TemplateException, ELException, 
     62            IOException { 
     63        setListTemplate(listTemplate); 
     64        setTemplate(template); 
     65        this.mediaType = mediaType; 
     66   
    6367 
    64         @Override 
    65         public void initEntityVariants(PersistenceResource resource) { 
    66                 if (template != null) { 
    67                         resource.getVariants().add(new Variant(mediaType)); 
    68                 } 
    69         } 
     68    public Collection<Variant> getVariants() { 
     69        return Collections.singleton(new Variant(getMediaType())); 
     70    } 
    7071 
    71         @Override 
    72         public Representation getEntityRepresentation(Variant variant, 
    73                         PersistenceResource resource) { 
    74                 if (template != null && mediaType.equals(variant.getMediaType())) { 
    75                         TemplateRepresentation templateRepresentation = new TemplateRepresentation( 
    76                                         template, mediaType); 
    77                         templateRepresentation.setVariable("entity", resource.getEntity()); 
    78                         templateRepresentation.setVariable("resource", resource); 
    79                         return templateRepresentation; 
    80                 } 
    81                 return null; 
    82         } 
     72    public Representation represent(EntityResource<E> entityResource, 
     73            Variant variant) { 
     74        if (entityResource instanceof EntityCollection) { 
     75            return represent((EntityCollection<E>) entityResource, variant); 
     76        } else if (entityResource instanceof EntityInstance) { 
     77            return represent((EntityInstance<E>) entityResource, variant); 
     78        } else { 
     79            return null; 
     80        } 
     81    } 
    8382 
    84         @Override 
    85         public void initEntityListVariants(PersistenceResource resource) { 
    86                 if (listTemplate != null) { 
    87                         resource.getVariants().add(new Variant(mediaType)); 
    88                 } 
    89         } 
     83    public Representation represent(EntityInstance<E> resource, Variant variant) { 
     84        if (template != null && mediaType.equals(variant.getMediaType())) { 
     85            TemplateRepresentation templateRepresentation = new TemplateRepresentation( 
     86                    template, mediaType); 
     87            templateRepresentation.setVariable("entity", resource.getEntity()); 
     88            templateRepresentation.setVariable("resource", resource); 
     89            return templateRepresentation; 
     90        } 
     91        return null; 
     92    } 
    9093 
    91         @Override 
    92         public Representation getEntityListRepresentation(Variant variant, 
    93                         PersistenceResource resource) { 
    94                 if (listTemplate != null && mediaType.equals(variant.getMediaType())) { 
    95                         TemplateRepresentation templateRepresentation = new TemplateRepresentation( 
    96                                         listTemplate, mediaType); 
    97                         templateRepresentation.setVariable("entities", resource 
    98                                         .getEntities()); 
    99                         templateRepresentation.setVariable("resource", resource); 
    100                         return templateRepresentation; 
    101                 } 
    102                 return null; 
    103         } 
     94    public Representation represent(EntityCollection<E> resource, 
     95            Variant variant) { 
     96        if (listTemplate != null && mediaType.equals(variant.getMediaType())) { 
     97            TemplateRepresentation templateRepresentation = new TemplateRepresentation( 
     98                    listTemplate, mediaType); 
     99            templateRepresentation.setVariable("entities", resource 
     100                    .getEntityList()); 
     101            templateRepresentation.setVariable("resource", resource); 
     102            return templateRepresentation; 
     103        } 
     104        return null; 
     105    } 
    104106 
    105        public Template getListTemplate() { 
    106                return listTemplate; 
    107        
     107    public Template getListTemplate() { 
     108        return listTemplate; 
     109   
    108110 
    109        public void setListTemplate(String listTemplate) throws TemplateException, 
    110                        ELException, IOException { 
    111                if (listTemplate == null) { 
    112                        this.listTemplate = null; 
    113                } else { 
    114                        this.listTemplate = TemplateFactory.getInstance().getTemplate( 
    115                                        listTemplate); 
    116                
    117        
     111    public void setListTemplate(String listTemplate) throws TemplateException, 
     112            ELException, IOException { 
     113        if (listTemplate == null) { 
     114            this.listTemplate = null; 
     115        } else { 
     116            this.listTemplate = TemplateFactory.getInstance().getTemplate( 
     117                    listTemplate); 
     118       
     119   
    118120 
    119        public void setListTemplate(Template listTemplate) { 
    120                this.listTemplate = listTemplate; 
    121        
     121    public void setListTemplate(Template listTemplate) { 
     122        this.listTemplate = listTemplate; 
     123   
    122124 
    123        public MediaType getMediaType() { 
    124                return mediaType; 
    125        
     125    public MediaType getMediaType() { 
     126        return mediaType; 
     127   
    126128 
    127        public void setMediaType(MediaType mediaType) { 
    128                this.mediaType = mediaType; 
    129        
     129    public void setMediaType(MediaType mediaType) { 
     130        this.mediaType = mediaType; 
     131   
    130132 
    131        public Template getTemplate() { 
    132                return template; 
    133        
     133    public Template getTemplate() { 
     134        return template; 
     135   
    134136 
    135        public void setTemplate(String template) throws TemplateException, 
    136                        ELException, IOException { 
    137                if (template == null) { 
    138                        this.template = null; 
    139                } else { 
    140                        this.template = TemplateFactory.getInstance().getTemplate(template); 
    141                
    142        
     137    public void setTemplate(String template) throws TemplateException, 
     138            ELException, IOException { 
     139        if (template == null) { 
     140            this.template = null; 
     141        } else { 
     142            this.template = TemplateFactory.getInstance().getTemplate(template); 
     143       
     144   
    143145 
    144        public void setTemplate(Template template) { 
    145                this.template = template; 
    146        
     146    public void setTemplate(Template template) { 
     147        this.template = template; 
     148   
    147149 
    148150}