KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > HttpListenerMBean


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * $Id: HttpListenerMBean.java,v 1.3 2005/12/25 03:42:21 tcfujii Exp $
26  */

27
28 package com.sun.enterprise.admin.mbeans;
29
30 import java.util.Map JavaDoc;
31 import java.util.logging.Level JavaDoc;
32
33 import javax.management.*;
34
35 import com.sun.enterprise.admin.util.jmx.AttributeListUtils;
36 import com.sun.enterprise.config.ConfigException;
37 import com.sun.enterprise.admin.config.BaseConfigMBean;
38
39 public class HttpListenerMBean extends BaseConfigMBean
40     implements MBeanRegistration
41 {
42     private ObjectName on;
43
44     static final String JavaDoc DEFAULT_VIRTUAL_SERVER = "default_virtual_server";
45
46     public void setAttribute(Attribute attribute)
47         throws AttributeNotFoundException, MBeanException, ReflectionException
48     {
49         String JavaDoc oldVs = null;
50         if (isDefaultVirtualServer(attribute))
51         {
52             oldVs = (String JavaDoc)super.getAttribute(DEFAULT_VIRTUAL_SERVER);
53         }
54
55         super.setAttribute(attribute);
56
57         if (isDefaultVirtualServer(attribute))
58         {
59             try
60             {
61                 changeHttpListenerRef(oldVs, (String JavaDoc)attribute.getValue());
62             }
63             catch (ConfigException ce)
64             {
65                 throw new MBeanException(ce);
66             }
67         }
68     }
69
70     public AttributeList setAttributes(AttributeList list)
71     {
72         String JavaDoc oldVs = null;
73         if (isDefaultVirtualServerExists(list))
74         {
75             try
76             {
77                 oldVs = (String JavaDoc)super.getAttribute(DEFAULT_VIRTUAL_SERVER);
78             }
79             catch (JMException e)
80             {
81                 //Ignoring. This should not occur.
82
}
83         }
84         AttributeList al = super.setAttributes(list);
85         if (isDefaultVirtualServerExists(list) &&
86             isDefaultVirtualServerExists(al))
87         {
88             try
89             {
90                 changeHttpListenerRef(oldVs, getDefaultVirtualServer(list));
91             }
92             catch (ConfigException ce)
93             {
94                 _sLogger.log(Level.WARNING,
95                     "httplistenerMBean.failed_to_add_http_listener_ref",ce);
96             }
97         }
98         return al;
99     }
100
101     public ObjectName preRegister(MBeanServer server, ObjectName name)
102         throws Exception JavaDoc
103     {
104         on = super.preRegister(server, name);
105         return on;
106     }
107
108     private void changeHttpListenerRef(String JavaDoc oldVs, String JavaDoc newVs)
109         throws ConfigException
110     {
111         HttpListenerVirtualServerAssociationMgr mgr =
112             new HttpListenerVirtualServerAssociationMgr(
113                 super.getConfigContext(), on.getKeyProperty("config"));
114         final String JavaDoc id = on.getKeyProperty("id");
115         mgr.changeHttpListenerRef(id, oldVs, newVs);
116     }
117
118     private boolean isDefaultVirtualServer(Attribute a)
119     {
120         return a.getName().equals(DEFAULT_VIRTUAL_SERVER);
121     }
122
123     private boolean isDefaultVirtualServerExists(AttributeList al)
124     {
125         return AttributeListUtils.containsNamedAttribute(al,
126                 DEFAULT_VIRTUAL_SERVER);
127     }
128
129     private String JavaDoc getDefaultVirtualServer(AttributeList al)
130     {
131         final Map JavaDoc map = AttributeListUtils.asNameMap(al);
132         final Attribute val = (Attribute)map.get(DEFAULT_VIRTUAL_SERVER);
133         return (String JavaDoc)val.getValue();
134     }
135 }
136
Popular Tags