KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > impl > converter > PageSetConverter


1 package org.exoplatform.services.portal.impl.converter;
2
3 import java.util.* ;
4 import org.exoplatform.services.portal.model.*;
5
6 import com.thoughtworks.xstream.converters.MarshallingContext;
7 import com.thoughtworks.xstream.converters.UnmarshallingContext;
8 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
9 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
10
11 /**
12  * @author Tuan Nguyen
13  */

14 public class PageSetConverter extends ComponentConverter {
15
16     public boolean canConvert(Class JavaDoc type) {
17         return type.equals(PageSet.class) ;
18     }
19
20     public void marshal(Object JavaDoc source, HierarchicalStreamWriter w,
21                             MarshallingContext context) {
22         PageSet pageSet = (PageSet) source ;
23         List pages = pageSet.getPages() ;
24         for(int i = 0; i < pages.size(); i++) {
25             Object JavaDoc o = pages.get(i) ;
26             context.convertAnother(o) ;
27         }
28     }
29
30     public Object JavaDoc unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
31         PageSet pageSet = new PageSet();
32         List pages = pageSet.getPages() ;
33         while (reader.hasMoreChildren()) {
34             reader.moveDown();
35             Object JavaDoc comp = context.convertAnother(pageSet, Page.class) ;
36             pages.add(comp) ;
37             reader.moveUp();
38         }
39         return pageSet ;
40     }
41 }
Popular Tags