001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mx.modelmbean;
023:
024: import javax.management.Attribute;
025: import javax.management.AttributeList;
026: import javax.management.AttributeNotFoundException;
027: import javax.management.DynamicMBean;
028: import javax.management.InvalidAttributeValueException;
029: import javax.management.MBeanException;
030: import javax.management.ReflectionException;
031: import javax.management.RuntimeMBeanException;
032: import javax.management.RuntimeOperationsException;
033: import javax.management.ServiceNotFoundException;
034: import javax.management.modelmbean.RequiredModelMBean;
035:
036: import org.jboss.mx.server.RawDynamicInvoker;
037:
038: /** An invoker that handles the 'ops' that are part of the RequiredModelMBean
039: * that must be handled at that level rather than its delegate.
040: *
041: * @author Scott.Stark@jboss.org
042: * @version $Revison:$
043: */
044: public class RequiredModelMBeanInvoker extends RawDynamicInvoker {
045: RequiredModelMBean mbean;
046:
047: public RequiredModelMBeanInvoker(DynamicMBean resource) {
048: super (resource);
049: mbean = (RequiredModelMBean) resource;
050: }
051:
052: public Object getAttribute(String name)
053: throws AttributeNotFoundException, MBeanException,
054: ReflectionException {
055: try {
056: return super .getAttribute(name);
057: } catch (ReflectionException e) {
058: // Another inconsistency
059: Exception ex = e.getTargetException();
060: if ((ex instanceof ClassNotFoundException) == false
061: && (ex instanceof NoSuchMethodException) == false) {
062: log.debug("Rewrapping reflection exception: ", e);
063: throw new MBeanException(new ServiceNotFoundException(
064: ex.getMessage()), e.getMessage());
065: } else
066: throw e;
067: }
068: }
069:
070: public void setAttribute(Attribute attribute)
071: throws AttributeNotFoundException,
072: InvalidAttributeValueException, MBeanException,
073: ReflectionException {
074: // Another inconsistency
075: if (attribute == null)
076: throw new RuntimeOperationsException(
077: new IllegalArgumentException("Null attribute"));
078: try {
079: super .setAttribute(attribute);
080: } catch (ReflectionException e) {
081: // Another inconsistency
082: Exception ex = e.getTargetException();
083: if ((ex instanceof ClassNotFoundException) == false
084: && (ex instanceof NoSuchMethodException) == false) {
085: log.debug("Rewrapping reflection exception: ", e);
086: throw new MBeanException(new ServiceNotFoundException(
087: ex.getMessage()), e.getMessage());
088: } else
089: throw e;
090: }
091: }
092:
093: public AttributeList getAttributes(String[] attributes) {
094: if (attributes == null)
095: throw new RuntimeOperationsException(
096: new IllegalArgumentException("Null attributes"));
097: return super .getAttributes(attributes);
098: }
099:
100: public AttributeList setAttributes(AttributeList attributes) {
101: if (attributes == null)
102: throw new RuntimeOperationsException(
103: new IllegalArgumentException("Null attributes"));
104: return super .setAttributes(attributes);
105: }
106:
107: public Object invoke(String name, Object[] args, String[] signature)
108: throws MBeanException, ReflectionException {
109: Object value;
110:
111: if (name == null)
112: throw new RuntimeOperationsException(
113: new IllegalArgumentException("Null operation"));
114: else if (name.equals("getNotificationInfo"))
115: value = mbean.getNotificationInfo();
116: else {
117: try {
118: value = super .invoke(name, args, signature);
119: } catch (RuntimeMBeanException e) {
120: // For some reason (not mentioned in the spec) these have to
121: // be wrapped in MBeanExceptions for RMM
122: throw new MBeanException(e.getTargetException(), e
123: .getMessage());
124: } catch (ReflectionException e) {
125: // Another inconsistency
126: Exception ex = e.getTargetException();
127: if ((ex instanceof ClassNotFoundException) == false
128: && (ex instanceof NoSuchMethodException) == false) {
129: log.debug("Rewrapping reflection exception: ", e);
130: throw new MBeanException(
131: new ServiceNotFoundException(ex
132: .getMessage()), e.getMessage());
133: } else
134: throw e;
135: }
136: }
137: return value;
138: }
139: }
|