protected SimpleMBean()

in jspwiki-main/src/main/java/org/apache/wiki/management/SimpleMBean.java [70:169]


    protected SimpleMBean() throws NotCompliantMBeanException
    {
        //
        //  Create attributes
        //
        final String[] attlist = getAttributeNames();
        MBeanAttributeInfo[] attributes = null;

        if( attlist != null )
        {
            attributes = new MBeanAttributeInfo[attlist.length];

            for( int i = 0; i < attlist.length; i++ )
            {
                String name = attlist[i];
                name = StringUtils.capitalize( name );
                Method getter = findGetterSetter( getClass(), "get"+name, null );

                if( getter == null ) getter = findGetterSetter( getClass(), "is"+name, null );

                Method setter = null;

                if( getter != null )
                {
                    setter = findGetterSetter( getClass(), "set"+name, getter.getReturnType() );
                }

                //
                //  Check, if there's a description available
                //
                final Method descriptor = findGetterSetter( getClass(), "get"+name+"Description", null );
                String description = "";

                if( descriptor != null )
                {
                    try
                    {
                        description = (String) descriptor.invoke( this, (Object[])null );
                    }
                    catch( final Exception e )
                    {
                        description="Exception: "+e.getMessage();
                    }
                }

                final MBeanAttributeInfo info;
                try
                {
                    info = new MBeanAttributeInfo( attlist[i], description, getter, setter );
                }
                catch (final IntrospectionException e)
                {
                    throw new NotCompliantMBeanException( e.getMessage() );
                }

                attributes[i] = info;
            }
        }

        //
        //  Create operations.
        //
        final String[] oplist = getMethodNames();
        final MBeanOperationInfo[] operations = new MBeanOperationInfo[oplist.length];

        final Method[] methods = getClass().getMethods();

        for( int i = 0; i < oplist.length; i++ )
        {
            Method method = null;

            for( final Method value : methods ) {
                if ( value.getName().equals( oplist[ i ] ) ) {
                    method = value;
                }
            }

            if( method == null )
            {
                throw new NotCompliantMBeanException("Class declares method "+oplist[i]+", yet does not implement it!");
            }

            final MBeanOperationInfo info = new MBeanOperationInfo( method.getName(), method );

            operations[i] = info;
        }

        //
        //  Create the actual BeanInfo instance.
        //
        final MBeanConstructorInfo[] constructors = null;
        final MBeanNotificationInfo[] notifications = null;

        m_beanInfo = new MBeanInfo( getClass().getName(),
                                    getDescription(),
                                    attributes,
                                    constructors,
                                    operations,
                                    notifications );
    }