01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.modeler.mbeans;
18:
19: import java.util.HashMap;
20:
21: import javax.management.Attribute;
22: import javax.management.AttributeNotFoundException;
23: import javax.management.MBeanException;
24: import javax.management.ReflectionException;
25:
26: import org.apache.commons.logging.Log;
27: import org.apache.commons.logging.LogFactory;
28: import org.apache.commons.modeler.BaseModelMBean;
29:
30: /** Use the same metadata, except that we replace the attribute
31: * get/set methods.
32: */
33: class MBeanProxy extends BaseModelMBean {
34: private static Log log = LogFactory.getLog(MBeanProxy.class);
35:
36: HashMap atts = new HashMap();
37:
38: SimpleRemoteConnector jkmx;
39:
40: public MBeanProxy(SimpleRemoteConnector jkmx, String code)
41: throws Exception {
42: this .jkmx = jkmx;
43: initModelInfo(code);
44: }
45:
46: /** Called by the connector - will update the value when a chunk of
47: * data is received
48: */
49: protected void update(String name, String val) {
50: if (log.isTraceEnabled())
51: log.trace("Updating " + oname + " " + name + " " + val);
52: // XXX Conversions !!!
53: atts.put(name, val);
54: }
55:
56: public Object getAttribute(String name)
57: throws AttributeNotFoundException, MBeanException,
58: ReflectionException {
59: // If we're stale - refresh values
60: jkmx.refresh();
61: return atts.get(name);
62: }
63:
64: public void setAttribute(Attribute attribute)
65: throws AttributeNotFoundException, MBeanException,
66: ReflectionException {
67: try {
68: jkmx.setAttribute(oname, attribute);
69: } catch (Exception ex) {
70: throw new MBeanException(ex);
71: }
72: }
73:
74: public Object invoke(String name, Object params[],
75: String signature[]) throws MBeanException,
76: ReflectionException {
77: try {
78: jkmx.invoke(oname, name, params, signature);
79: } catch (Exception ex) {
80: throw new MBeanException(ex);
81: }
82: return null;
83: }
84: }
|