KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > skin > converter > SkinConfigConverter


1 package org.exoplatform.services.portal.skin.converter;
2
3 import java.util.* ;
4 import org.exoplatform.services.portal.skin.model.*;
5
6 import com.thoughtworks.xstream.converters.Converter;
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 SkinConfigConverter implements Converter {
16
17     public boolean canConvert(Class JavaDoc type) {
18         return type.equals(SkinConfig.class) ;
19     }
20
21     public void marshal(Object JavaDoc source, HierarchicalStreamWriter w, MarshallingContext context) {
22         SkinConfig config = (SkinConfig) source ;
23         throw new Error JavaDoc("Not support marshall yet") ;
24     }
25
26     public Object JavaDoc unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
27       SkinConfig config = new SkinConfig() ;
28       while (reader.hasMoreChildren()) {
29             reader.moveDown();
30             String JavaDoc nodeName = reader.getNodeName() ;
31             if("portal-decorators".equals(nodeName)) {
32                 config.setPortalDecorators((List)context.convertAnother(config, List.class)) ;
33             } else if("page-decorators".equals(nodeName)) {
34               config.setPageDecorators((List)context.convertAnother(config, List.class)) ;
35             } else if("container-decorators".equals(nodeName)) {
36               config.setContainerDecorators((List)context.convertAnother(config, List.class)) ;
37             } else if("portlet-decorators".equals(nodeName)) {
38               config.setPortletDecorators((List)context.convertAnother(config, List.class)) ;
39             } else {
40                 Object JavaDoc o = context.convertAnother(config, PortletStyleConfig.class) ;
41                 config.getPortletStyleConfig().add(o) ;
42             }
43             reader.moveUp();
44         }
45         return config ;
46     }
47 }
Popular Tags