FileDocCategorySizeDatePackage
MBeanHelper.javaAPI DocGlassfish v2 API18807Fri May 04 22:25:34 BST 2007com.sun.enterprise.admin

MBeanHelper

public class MBeanHelper extends Object implements com.sun.enterprise.admin.meta.MBeanMetaConstants

Fields Summary
protected static final Logger
_sLogger
protected static final com.sun.enterprise.util.i18n.StringManager
_localStrings
public static final Object
INVOKE_ERROR_SIGNAL_OBJECT
Constructors Summary
Methods Summary
public static javax.management.MBeanExceptionextractAndWrapTargetException(java.lang.Exception e, java.lang.String wrapMsg)

         while(e instanceof InvocationTargetException ||
               e instanceof MBeanException)
         {
             if(e instanceof InvocationTargetException)
                {
                    Throwable t = ((InvocationTargetException)e).getTargetException();
                    if (t instanceof Exception)
                        e = (Exception)t;
                    else
                        e = new Exception(t.getMessage());
                }
             else
                 if(e instanceof MBeanException)
                    {
                        e = ((MBeanException)e).getTargetException();
                    }
         }
        String msg  = e.getMessage();
        String targetMsgPref = _localStrings.getString( "admin.server.core.mbean.target_exception_prefix");
        if(msg!=null)
            return new MBeanException(e, wrapMsg + "\n"+ targetMsgPref + ": "  + e.getMessage());
        else
            return new MBeanException(e, wrapMsg);
    
public static javax.management.MBeanAttributeInfofindMatchingAttributeInfo(javax.management.MBeanInfo mbeanInfo, java.lang.String name)

        MBeanAttributeInfo[] attrInfos = mbeanInfo.getAttributes();
        if(attrInfos==null)
            return null;
        boolean bMatch;
        for(int i=0; i<attrInfos.length; i++)
        {
            if(name.equals(attrInfos[i].getName()))
            {
                return attrInfos[i];
            }
        }
        return null;
    
public static javax.management.MBeanOperationInfofindMatchingOperationInfo(javax.management.MBeanInfo mbeanInfo, java.lang.String name, java.lang.String[] signature)

        MBeanOperationInfo[] opInfos = mbeanInfo.getOperations();
        if(opInfos==null)
            return null;
        boolean bMatch;
        for(int i=0; i<opInfos.length; i++)
        {
            if(name.equals(opInfos[i].getName()))
            {
                String sign[] = getParamTypesFromOperationInfo(opInfos[i]);
                if(isSignaturesEqual(sign, signature))
                    return opInfos[i];
            }
        }
        return null;
    
public static java.lang.reflect.MethodfindMatchingOperationMethod(java.lang.String opName, javax.management.MBeanOperationInfo opInfo, java.lang.Object bean)

//        try
        {
           Class  signature[] = getSignatureFromOperationInfo(opInfo);
           return bean.getClass().getMethod(opName, signature);
        }
/*        catch (NoSuchMethodException nsme)
        {
        }
        catch (SecurityException nsme)
        {
        }
        return null;
 */
    
private static java.lang.ClassgetAttributeClass(java.lang.String signature)

        if (signature.equals(Boolean.TYPE.getName()))
            return Boolean.TYPE;
        else if (signature.equals(Byte.TYPE.getName()))
            return Byte.TYPE;
        else if (signature.equals(Character.TYPE.getName()))
            return Character.TYPE;
        else if (signature.equals(Double.TYPE.getName()))
            return Double.TYPE;
        else if (signature.equals(Float.TYPE.getName()))
            return Float.TYPE;
        else if (signature.equals(Integer.TYPE.getName()))
            return Integer.TYPE;
        else if (signature.equals(Long.TYPE.getName()))
            return Long.TYPE;
        else if (signature.equals(Short.TYPE.getName()))
            return Short.TYPE;
        else {
            try {
                ClassLoader cl=Thread.currentThread().getContextClassLoader();
                if( cl!=null )
                    return cl.loadClass(signature); 
            } catch( ClassNotFoundException e ) {
            }
//            try {
                return Class.forName(signature);
//            } catch (ClassNotFoundException e) {
//                throw new ReflectionException
//                    (e, "Cannot find Class for " + signature);
//            }
        }
    
public static java.lang.ObjectgetDescriptorFieldValue(javax.management.modelmbean.ModelMBeanInfo info, java.lang.String name)

    
    //********************************************************************************************************************
    // get Descriptor's field value by its name 
            
    
        Descriptor descr = info.getMBeanDescriptor();
        return descr.getFieldValue(name);
        
    
public static java.lang.String[]getLocation(javax.management.modelmbean.ModelMBeanInfo info)

        return (String[])getDescriptorFieldValue(info, NMLOCATION_FIELD_NAME);
        
    
public static java.lang.String[]getParamTypesFromOperationInfo(javax.management.MBeanOperationInfo opInfo)

        MBeanParameterInfo[] params = opInfo.getSignature();
        if(params==null)
            return new String[0];
        ArrayList signature = new ArrayList();
        for(int i=0; i<params.length; i++)
            signature.add(params[i].getType());
        return (String[])signature.toArray(new String[signature.size()]);
    
public static java.lang.Class[]getSignatureFromOperationInfo(javax.management.MBeanOperationInfo opInfo)

        MBeanParameterInfo[] params = opInfo.getSignature();
        if(params==null)
            return new Class[0];
        ArrayList signature = new ArrayList();
        for(int i=0; i<params.length; i++)
            signature.add(getAttributeClass(params[i].getType()));
        return (Class[])signature.toArray(new Class[signature.size()]);
    
public static java.lang.StringgetXPathPattern(javax.management.modelmbean.ModelMBeanInfo info)

        return (String)getDescriptorFieldValue(info, XPATH_FIELD_NAME);
    
public static java.lang.ObjectinvokeOperationInBean(java.lang.String opName, javax.management.MBeanOperationInfo opInfo, java.lang.Object bean, java.lang.Object[] params)

        Method method = null;
        try 
        {
            method = findMatchingOperationMethod(opName, opInfo, bean);
        }
        catch (Exception e)
        {
            if(e instanceof SecurityException)
                _sLogger.log(Level.FINEST, "invokeOperationInBean() failed", e);
        }
        if(method==null)
           return INVOKE_ERROR_SIGNAL_OBJECT;
        return method.invoke(bean,  params);
    
public static java.lang.ObjectinvokeOperationInBean(javax.management.MBeanOperationInfo opInfo, java.lang.Object bean, java.lang.Object[] params)

        return invokeOperationInBean(opInfo.getName(), opInfo, bean, params);
    
private static booleanisSignaturesEqual(java.lang.String[] sign, java.lang.String[] signature)

        //signature test
        if ((signature==null||signature.length==0) &&
            (sign==null||sign.length==0) )
            return true;
        if((signature==null && sign!=null) ||
           (signature!=null && sign==null) )
           return false;
        if(signature.length != sign.length)
            return false;
        boolean bMatch = true;
        for(int j=0; j<sign.length; j++)
        {
            if(!sign[j].equals(signature[j]))
            {
                bMatch = false;
                break;
            }
        }
        return bMatch;