1 29 30 package com.caucho.server.dispatch; 31 32 import com.caucho.config.BuilderProgram; 33 import com.caucho.config.BuilderProgramContainer; 34 import com.caucho.config.Config; 35 import com.caucho.config.ConfigException; 36 import com.caucho.soa.rest.RestProtocolServlet; 37 import com.caucho.soa.servlet.HessianProtocolServlet; 38 import com.caucho.soa.servlet.ProtocolServlet; 39 import com.caucho.soa.servlet.SoapProtocolServlet; 40 import com.caucho.util.L10N; 41 42 import javax.annotation.PostConstruct; 43 46 public class ServletProtocolConfig { 47 private static L10N L = new L10N(ServletProtocolConfig.class); 48 49 private Class _type; 50 51 private BuilderProgramContainer _program 52 = new BuilderProgramContainer(); 53 54 57 public ServletProtocolConfig() 58 { 59 } 60 61 public void setType(String type) 62 { 63 if ("soap".equals(type)) 64 _type = SoapProtocolServlet.class; 65 else if ("rest".equals(type)) 66 _type = RestProtocolServlet.class; 67 else if ("hessian".equals(type)) 68 _type = HessianProtocolServlet.class; 69 else { 70 try { 71 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 72 73 _type = Class.forName(type, false, loader); 74 75 Config.validate(_type, ProtocolServlet.class); 76 } catch (RuntimeException e) { 77 throw e; 78 } catch (Exception e) { 79 throw new ConfigException(e); 80 } 81 } 82 } 83 84 public Class getType() 85 { 86 return _type; 87 } 88 89 public void addBuilderProgram(BuilderProgram program) 90 { 91 _program.addProgram(program); 92 } 93 94 public BuilderProgram getProgram() 95 { 96 return _program; 97 } 98 99 @PostConstruct 100 public void init() 101 { 102 if (_type == null) 103 throw new ConfigException(L.l("'type' is a required attribute of <protocol>")); 104 } 105 } 106 | Popular Tags |