KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > wsgen > ddmodifier > WebJettyDDModifier


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial Developer: Matt Wringe
22  *
23  * --------------------------------------------------------------------------
24  * $Id: WebJettyDDModifier.java,v 1.1 2005/07/18 23:53:30 mwringe Exp $
25  * --------------------------------------------------------------------------
26  */

27
28 package org.objectweb.jonas_ws.wsgen.ddmodifier;
29
30 import org.w3c.dom.Document JavaDoc;
31 import org.w3c.dom.Element JavaDoc;
32
33 /**
34  * Modify the web-jetty.xml file. Wrapper around a web.xml DOM
35  *
36  * @author Matt Wringe
37  */

38 public class WebJettyDDModifier extends DeploymentDescModifier {
39
40     /** the name of the class that sets the realm for Jetty */
41     private static final String JavaDoc REALM_CLASS = "org.objectweb.jonas.security.realm.web.jetty50.Standard";
42
43     /** the name of the class that sets the context for Jetty */
44     private static final String JavaDoc CONTEXT_CLASS = "org.mortbay.jetty.servlet.WebApplicationContext";
45
46     /** Default Realm name is no name is specified */
47     private static final String JavaDoc DEFAULT_REALM_NAME = "Endpoint Authentication Area";
48
49     /**
50      * Create a new WebJettyDDModifier
51      *
52      * @param doc the context.xml Document
53      */

54     public WebJettyDDModifier(Document JavaDoc doc) {
55         super(doc.getDocumentElement(), doc);
56     }
57
58     /**
59      * Sets up the realm for Jetty to use
60      *
61      * @param realm the realm to use
62      */

63     public void configRealm (String JavaDoc realm) {
64         configRealm (DEFAULT_REALM_NAME, realm);
65     }
66
67     /**
68      * Sets up the realm for Jetty to use
69      *
70      * @param realmName the realm name for the realm
71      * @param realm the realm to use
72      */

73     public void configRealm(String JavaDoc realmName, String JavaDoc realm) {
74         Element JavaDoc configureElement = getElement();
75         configureElement.appendChild(setRealmName(realmName));
76         configureElement.appendChild(setRealm(realm, realmName));
77     }
78
79
80     /**
81      * Returns an element that defines the realm name to use
82      *
83      * @param realmName the name of the realm
84      * @return an element that defines the realm name
85      */

86     private Element JavaDoc setRealmName (String JavaDoc realmName) {
87         Element JavaDoc callElement = newElement("Call");
88         callElement.setAttribute("name", "setRealmName");
89
90         Element JavaDoc argElement = newElement("Arg", realmName);
91         callElement.appendChild(argElement);
92
93         return callElement;
94     }
95
96     /**
97      * Returns an element that defines which realm to use
98      *
99      * @param realm the realm
100      * @param realmName the name of the realm
101      * @return an element that defines which realm to use
102      */

103     private Element JavaDoc setRealm (String JavaDoc realm, String JavaDoc realmName) {
104         Element JavaDoc callElement = newElement ("Call");
105         callElement.setAttribute("name", "setRealm");
106
107         Element JavaDoc argElement = newElement ("Arg");
108
109         Element JavaDoc newElement = newElement ("New");
110         newElement.setAttribute("class", REALM_CLASS);
111
112         Element JavaDoc argRealmName = newElement ("Arg", realmName);
113         Element JavaDoc argRealm = newElement ("Arg", realm);
114
115         newElement.appendChild(argRealmName);
116         newElement.appendChild(argRealm);
117
118         argElement.appendChild(newElement);
119         callElement.appendChild(argElement);
120
121         return callElement;
122     }
123 }
124
Popular Tags