KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > dispatch > ServletProtocolConfig


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

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 /**
44  * Configuration for a servlet web-service protocol.
45  */

46 public class ServletProtocolConfig {
47   private static L10N L = new L10N(ServletProtocolConfig.class);
48
49   private Class JavaDoc _type;
50
51   private BuilderProgramContainer _program
52     = new BuilderProgramContainer();
53
54   /**
55    * Creates a new protocol configuration object.
56    */

57   public ServletProtocolConfig()
58   {
59   }
60
61   public void setType(String JavaDoc 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 JavaDoc loader = Thread.currentThread().getContextClassLoader();
72     
73     _type = Class.forName(type, false, loader);
74
75     Config.validate(_type, ProtocolServlet.class);
76       } catch (RuntimeException JavaDoc e) {
77     throw e;
78       } catch (Exception JavaDoc e) {
79     throw new ConfigException(e);
80       }
81     }
82   }
83
84   public Class JavaDoc 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