KickJava   Java API By Example, From Geeks To Geeks.

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


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

15 public class ExoPortletPreferencesConverter extends ComponentConverter {
16
17     public boolean canConvert(Class JavaDoc type) {
18         return type.equals(ExoPortletPreferences.class) ;
19     }
20
21     public void marshal(Object JavaDoc source, HierarchicalStreamWriter w,
22                             MarshallingContext context) {
23         ExoPortletPreferences prefs = (ExoPortletPreferences) source ;
24         Iterator i = prefs.values().iterator() ;
25         while(i.hasNext()) {
26             w.startNode("preference") ;
27             Preference pref = (Preference) i.next() ;
28             context.convertAnother(pref) ;
29             w.endNode() ;
30         }
31     }
32
33     public Object JavaDoc unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
34         ExoPortletPreferences prefs = new ExoPortletPreferences() ;
35         while (reader.hasMoreChildren()) {
36             reader.moveDown() ;
37             Preference pref = (Preference) context.convertAnother(prefs, Preference.class) ;
38             reader.moveUp();
39             prefs.put(pref.getName(), pref) ;
40         }
41         return prefs ;
42     }
43 }
Popular Tags