KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > servlet > ConfigurationServlet


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2005 ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.servlet;
38
39 import java.io.IOException JavaDoc;
40 import java.util.Map JavaDoc;
41
42 import javax.management.AttributeNotFoundException JavaDoc;
43 import javax.management.InstanceNotFoundException JavaDoc;
44 import javax.management.InvalidAttributeValueException JavaDoc;
45 import javax.management.MBeanException JavaDoc;
46 import javax.management.MalformedObjectNameException JavaDoc;
47 import javax.management.ReflectionException JavaDoc;
48
49 import net.sourceforge.cruisecontrol.Configuration;
50 import net.sourceforge.cruisecontrol.interceptor.ConfigurationAware;
51
52 import org.jdom.JDOMException;
53
54 import com.opensymphony.xwork.ActionSupport;
55 import com.opensymphony.webwork.interceptor.SessionAware;
56
57 /**
58  * Understands how to edit the configuration via a web interface.
59  */

60 public class ConfigurationServlet extends ActionSupport implements ConfigurationAware, SessionAware {
61     private Configuration configuration;
62     private String JavaDoc project;
63
64     public String JavaDoc execute() {
65         return SUCCESS;
66     }
67
68     public String JavaDoc reload() throws AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc, MBeanException JavaDoc,
69             ReflectionException JavaDoc, IOException JavaDoc, JDOMException {
70         configuration.load();
71         addActionMessage("Reloaded configuration.");
72         return SUCCESS;
73     }
74
75     public String JavaDoc save() throws InstanceNotFoundException JavaDoc, AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc,
76             MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc {
77         configuration.save();
78         addActionMessage("Saved configuration.");
79         return SUCCESS;
80     }
81
82     public void setConfiguration(Configuration configuration) {
83         this.configuration = configuration;
84     }
85
86     public String JavaDoc getContents() throws AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc,
87             MalformedObjectNameException JavaDoc, NumberFormatException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc,
88             JDOMException {
89         return configuration.getConfiguration();
90     }
91
92     public void setContents(String JavaDoc contents) throws InstanceNotFoundException JavaDoc, AttributeNotFoundException JavaDoc,
93             InvalidAttributeValueException JavaDoc, MalformedObjectNameException JavaDoc, NumberFormatException JavaDoc, MBeanException JavaDoc,
94             ReflectionException JavaDoc, IOException JavaDoc {
95         this.configuration.setConfiguration(contents);
96     }
97
98     public void setSession(Map JavaDoc map) {
99         project = (String JavaDoc) map.get("project");
100     }
101
102     public String JavaDoc getProject() {
103         return project;
104     }
105 }
106
Popular Tags