KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xfire > ScopeDeserializer


1 package jfun.yan.xfire;
2
3 import jfun.yan.util.deserializer.Deserializer;
4
5 /**
6  * The Deserializer implementation that converts String to ScopePolicy.
7  * <p>
8  * @author Ben Yu
9  * Feb 2, 2006 6:33:55 PM
10  */

11 public class ScopeDeserializer implements Deserializer {
12   public ScopeDeserializer(){}
13   public Object JavaDoc deserialize(String JavaDoc str){
14     final ScopePolicy policy = toScopePolicy(str.trim());
15     if(policy==null){
16       throw new IllegalArgumentException JavaDoc("invalid scope policy: "+policy);
17     }
18     return policy;
19   }
20   /**
21    * Convert a policy string to ScopePolicy object.
22    * @param policy the policy string.
23    * @return the ScopePolicy object. null if not recognized.
24    */

25   public static ScopePolicy toScopePolicy(String JavaDoc policy){
26     if("application".equals(policy) || "service".equals(policy)){
27       return ApplicationScopePolicy.instance();
28     }
29     else if("session".equals(policy)){
30       return SessionScopePolicy.instance();
31     }
32     else if("request".equals(policy)){
33       return RequestScopePolicy.instance();
34     }
35     else
36       return null;
37   }
38
39 }
40
Popular Tags