FileDocCategorySizeDatePackage
MBeanRegistryEntry.javaAPI DocGlassfish v2 API32961Mon Jul 02 10:49:54 BST 2007com.sun.enterprise.admin.meta

MBeanRegistryEntry

public class MBeanRegistryEntry extends Object implements MBeanMetaConstants

Fields Summary
com.sun.enterprise.admin.meta.naming.MBeanNamingDescriptor
namingDescriptor
private com.sun.org.apache.commons.modeler.ManagedBean
managedBean
private HashMap
fields
private boolean
_bIntrospectMBeanClass
static final String
filler
Constructors Summary
public MBeanRegistryEntry(com.sun.org.apache.commons.modeler.ManagedBean mb)

    

        
    
        this (mb,true);
    
public MBeanRegistryEntry(com.sun.org.apache.commons.modeler.ManagedBean mb, boolean bMergeWithMbean)

        _bIntrospectMBeanClass = bMergeWithMbean;
        managedBean = mb;
        fields = convertListOfFieldsToHashMap(mb.getFields());

        // convert dynamically changeable list to map
        String dynList  = (String)fields.get(DYNAMICALLY_RECONFIGURABLE_LIST_FIELD_NAME);
        if(dynList!=null)
        {
            //replace it by set
            fields.put(DYNAMICALLY_RECONFIGURABLE_LIST_FIELD_NAME, convertDelimListToSet(dynList));
        }

        //modify class info 
        String clazz = managedBean.getClassName();
        if(!_bIntrospectMBeanClass || clazz.startsWith("com.sun.org.apache"))
            clazz = null;
        String group = managedBean.getGroup();
        if("config".equals(group))
        {
            if(clazz==null)
            {
                clazz = "com.sun.enterprise.admin.config.BaseConfigMBean";
                managedBean.setClassName(clazz);
            }
            else
            {
                if(clazz.indexOf('.")<0)
                    clazz = "com.sun.enterprise.admin.config.mbeans."+clazz;
            }
            MBeanMetaHelper.mergeWithConfigBean(managedBean, 
                              MBeanMetaHelper.getConfigBeanClass((String)fields.get(XPATH_FIELD_NAME)), 
                              EXPOSE_ALL);
            MBeanMetaHelper.mergeWithDynamicMBean(managedBean, Class.forName(clazz));
        }
        else if("runtime".equals(group))
        {
            if(clazz==null)
            {
                clazz = "com.sun.enterprise.admin.runtime.BaseRuntimeMBean";
                managedBean.setClassName(clazz);
            }
            else
            {
                if(clazz.indexOf('.")<0)
                    clazz = "com.sun.enterprise.admin.runtime.mbeans"+clazz;
            }
            Class modelBeanClass = MBeanMetaHelper.getRuntimeModelBeanClass(mb.getName());
            if(modelBeanClass!=null)
               MBeanMetaHelper.mergeWithRuntimeModelBean(managedBean, modelBeanClass);
            Class configBeanClass = MBeanMetaHelper.getConfigBeanClass((String)fields.get(XPATH_FIELD_NAME));
            if(configBeanClass!=null)
            {
                int mode;
                if(modelBeanClass!=null)
                    mode = EXPOSE_RUNTIME_WITH_MODEL;
                else
                    mode = EXPOSE_RUNTIME_WITHOUT_MODEL;
                    
                MBeanMetaHelper.mergeWithConfigBean(managedBean, configBeanClass, mode);
            }
            MBeanMetaHelper.mergeWithDynamicMBean(managedBean, Class.forName(clazz));
        }
            
        namingDescriptor = new MBeanNamingDescriptor(  mb.getName(),
                new Integer(MBeansNaming.MODE_CONFIG), 
                (String)fields.get(CLINAME_FIELD_NAME), 
                (String)fields.get(OBJECTNAME_FIELD_NAME), 
                MBeanNamingDescriptor.XPATH_TO_MASK((String)fields.get(XPATH_FIELD_NAME)), 
                (String)clazz); // fields.get("Class")));*/

/*        AttributeInfo[] attrs = managedBean.getAttributes();
        if(attrs!=null && attrs.length>0 && "modelerType".equals(attrs[0].getName()))
        {
            AttributeInfo[] attrsNew = new AttributeInfo[attrs.length-1];
            for(int i=1; i<attrs.lenght; i++)
                attrsNew[i-1] = attrs[i];
            managedBean.setAttributes(attrsNew);
        }
*/
    
Methods Summary
private booleancheckItemsInReconfigurableSet(java.lang.String name1, java.lang.String name2)

        Set set = getDynamicallyReconfigurableAttributes();
        if(set==null || set.size()<1)
            return false;
        if(set.contains("**") ||
           set.contains(name1) || 
           (name2!=null && set.contains(name2)))
            return true;
        return false; 
    
private static java.util.SetconvertDelimListToSet(java.lang.String list)

        HashSet set = new HashSet();
        StringTokenizer tokenizer = new StringTokenizer(list, ", ");
        while(tokenizer.hasMoreTokens())
        {
            String token = tokenizer.nextToken();
            if(token.length()>0) //?
                set.add(token);
        }
        return set;
    
private static java.util.HashMapconvertListOfFieldsToHashMap(java.util.List fields)

        Iterator iter = fields.iterator();
        HashMap fldsMap = new HashMap();
        while(iter.hasNext())
        {
            FieldInfo field = (FieldInfo)iter.next();
            fldsMap.put(field.getName(), field.getValue());
        }
        return fldsMap;
    
public javax.management.modelmbean.ModelMBeanInfocreateMBeanInfo(com.sun.enterprise.admin.meta.naming.MBeanNamingInfo namingInfo, java.lang.String domainName)

        //force managedBean to reset MBeanInfo
        managedBean.setDescription(managedBean.getDescription());
        
        ModelMBeanInfo info = managedBean.createMBeanInfo();
        Descriptor descr = info.getMBeanDescriptor();
        if(domainName!=null)
            descr.setField(DOMAIN_FIELD_NAME, domainName);
        if(namingInfo!=null)
        {
            descr.setField(NMTYPE_FIELD_NAME, namingInfo.getType());
            descr.setField(NMLOCATION_FIELD_NAME, namingInfo.getLocationParams());
        }
        info.setMBeanDescriptor(descr);
        return info;
    
private java.lang.StringfillStr(java.lang.String name, int minSize)

         
    
        if(name.length()>=minSize)
            return name;
        return name+filler.substring(0, minSize-name.length());
    
private com.sun.org.apache.commons.modeler.AttributeInfofindAttributeInfo(java.lang.String attrName)

        return (AttributeInfo)findFeatureInfo(attrName, (FeatureInfo[]) managedBean.getAttributes());
    
private com.sun.org.apache.commons.modeler.FeatureInfofindFeatureInfo(java.lang.String attrName, com.sun.org.apache.commons.modeler.FeatureInfo[] features)

        if(attrName==null)
            return null;
        for(int i=0; i<features.length; i++)
        {
            if(attrName.equals(features[i].getName()))
                return features[i];
        }
        return null;
    
private java.lang.StringformatClassName(java.lang.String className, int minSize)

        if(className==null || className.length()==0)
            className = "void";
        else
        {
           int iLast = className.lastIndexOf('.");
           boolean bArray = className.startsWith("[");
           if(iLast>=0)
               className = className.substring(iLast+1);
           if(bArray)
               className =  className.substring(0, className.length()-1)+"[]";
        }
        return fillStr(className, minSize);
    
public java.lang.String[]getAttributeNames()

        AttributeInfo[] infos = managedBean.getAttributes();
        if(infos==null)
            return (new String[0]);
        String[] names = new String[infos.length];
        for(int i=0; i<infos.length; i++)
            names[i] = infos[i].getName();
        return names;
    
public java.util.SetgetDynamicallyReconfigurableAttributes()

        return (Set)this.fields.get(DYNAMICALLY_RECONFIGURABLE_LIST_FIELD_NAME);
    
public java.lang.StringgetElementChangeEventName()

        return (String)this.fields.get(ELEMENTCHANGEEVENT_FIELD_NAME);
    
public java.lang.StringgetElementPrintName()

       return (String)fields.get(PRINTNAME_FIELD_NAME);        
    
public java.lang.StringgetName()

        if(managedBean!=null)
            return managedBean.getName();
        return null;
    
public com.sun.enterprise.admin.meta.naming.MBeanNamingDescriptorgetNamingDescriptor()

        return namingDescriptor;
    
public com.sun.enterprise.admin.BaseAdminMBeaninstantiateMBean(javax.management.ObjectName objectName, java.lang.Object managedResource, com.sun.enterprise.config.ConfigContext ctx)

        String domainName = objectName.getDomain();
        return instantiateMBean(new MBeanNamingInfo(namingDescriptor, objectName), managedResource, domainName, ctx);
    
public com.sun.enterprise.admin.BaseAdminMBeaninstantiateMBean(java.lang.String type, java.lang.String[] location, java.lang.Object managedResource, java.lang.String domainName, com.sun.enterprise.config.ConfigContext ctx)

        return instantiateMBean(new MBeanNamingInfo(namingDescriptor, type, location), managedResource, domainName, ctx);
    
private com.sun.enterprise.admin.BaseAdminMBeaninstantiateMBean(com.sun.enterprise.admin.meta.naming.MBeanNamingInfo namingInfo, java.lang.Object managedResource, java.lang.String domainName, com.sun.enterprise.config.ConfigContext ctx)

        if(managedBean==null)
            return null;
        ModelMBeanInfo mbi = createMBeanInfo(namingInfo, domainName);
        //FIXME set fields xpath&object_name here
        String clazz = managedBean.getClassName();
        String group = managedBean.getGroup();
        
        Constructor constructor  = Class.forName(clazz).getConstructor();
        BaseAdminMBean mbean = (BaseAdminMBean)constructor.newInstance();
        mbean.setModelMBeanInfo(mbi);

        //BaseConfigMBean mbean = new BaseConfigMBean(mbi);
        String xpath = namingInfo.getXPath();
        if("config".equals(group))
        {
            if(xpath!=null && xpath.length()>0)
            {
                Object configBean = (Object)ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath);
                if(configBean!=null)
                    mbean.setManagedResource(configBean, CONFIG_BEAN_REF);
                else
                    throw new MBeanMetaException("instantiateMBean(): config mbean does not exist for xpath - " + xpath );
            }
            return mbean;
        }
        if( "runtime".equals(group))
        {
            //CONFIG BEAN
            if(xpath!=null && xpath.length()>0)
            {
                Object configBean = (Object)ConfigBeansFactory.getConfigBeanByXPath(ctx, xpath);
                if(configBean!=null)
                    mbean.setManagedResource(configBean, CONFIG_BEAN_REF);
            }

 
            //JSR77BEAN
            //construct JSR77Beanname
            String beanClassName = (String)fields.get(JSR77BEAN_FIELD_NAME);
            if(beanClassName==null || beanClassName.length()==0)
                beanClassName = "com.sun.enterprise.management.model."+namingInfo.getType()+"Mdl";
            
            if(managedResource==null)
            {
                Class    cl = Class.forName(beanClassName);
                if(cl!=null)
                {
                    String[] location = namingInfo.getLocationParams();
                    if(location!=null)
                    {
                        Constructor ctr  = cl.getConstructor(new Class[]{location.getClass()});
                        if(ctr!=null)
                           managedResource = ctr.newInstance(new Object[]{location});

                    }
                }
            }
            if(managedResource!=null)
                mbean.setManagedResource(managedResource, JSR77_MODEL_BEAN_REF);
            return mbean;

        }
        return null;
    
public booleanisAttributeDynamicReconfigNeeded(java.lang.String attrName)

        AttributeInfo ai = findAttributeInfo(attrName);
        if(ai==null)
            throw new MBeanMetaException("Attribute info is not founmd for attribute "+attrName);
        //get attribute's descriptor fields
        List fields = ai.getFields();
        if(fields!=null)
            for(int i=0; i<fields.size(); i++) //enum fields
            {
                if("dynamicReconfigNeeded".equals(((FieldInfo)fields.get(i)).getName()))
                {
                    //get "emptyValueAllowed" field value and compare it with "true"
                    Object value = ((FieldInfo)fields.get(i)).getValue();
                    if(value!=null && (value instanceof String) &&
                       ("false".equalsIgnoreCase((String)value)|| "no".equalsIgnoreCase((String)value)))
                        return false;
                }
            }
        return true;
    
public booleanisAttributeDynamicallyReconfigurable(java.lang.String attr)

        return checkItemsInReconfigurableSet(attr, "*");
    
public booleanisAttributeEmptyValueAllowed(java.lang.String attrName)

        AttributeInfo ai = findAttributeInfo(attrName);
        if(ai==null)
            throw new MBeanMetaException("Attribute info is not founmd for attribute "+attrName);
        //get attribute's descriptor fields
        List fields = ai.getFields();
        if(fields!=null)
            for(int i=0; i<fields.size(); i++) //enum fields
            {
                if(EMPTYVALUEALLOWED_FIELD_NAME.equals(((FieldInfo)fields.get(i)).getName()))
                {
                    //get "emptyValueAllowed" field value and compare it with "true"
                    Object value = ((FieldInfo)fields.get(i)).getValue();
                    if(value!=null && (value instanceof String) &&
                       ("true".equalsIgnoreCase((String)value)|| "yes".equalsIgnoreCase((String)value)))
                        return true; //empty value is allowed
                }
            }
        return false; //empty value is not allowed
    
public booleanisElementCreationDynamicallyReconfigurable()

        return checkItemsInReconfigurableSet("+", null);
    
public booleanisElementDeletionDynamicallyReconfigurable()

        return checkItemsInReconfigurableSet("-", null);
    
public booleanisElementDynamicallyReconfigurable()

        return checkItemsInReconfigurableSet("**", null);
    
public booleanisObjectNamePatternMatch(java.util.Hashtable ht)

        if(namingDescriptor!=null)
            return namingDescriptor.isObjectNamePatternMatch(ht);
        return false;
    
public booleanisObjectNamePatternMatch(javax.management.ObjectName objectName)

        if(namingDescriptor!=null)
            return namingDescriptor.isObjectNamePatternMatch(objectName);
        return false;
    
public booleanisPropertyDynamicallyReconfigurable(java.lang.String attr)

        return checkItemsInReconfigurableSet("property."+attr, "property.*");
    
public voidmergeAttribute(java.lang.String attrName, java.lang.String attrType, java.lang.String attrGetMethod, java.lang.String attrSetMethod, boolean attrReadable, boolean attrWriteable)

        AttributeInfo ai = findAttributeInfo(attrName);
        if(ai==null)
        {
            ai = new AttributeInfo();
            ai.setName(attrName);
            ai.setType(attrType);
            managedBean.addAttribute(ai);
        }
        if(ai.isReadable() && !attrReadable)
            ai.setReadable(false);
        if(ai.isWriteable() && !attrWriteable)
            ai.setWriteable(false);
        if(attrGetMethod!=null)
            ai.setGetMethod(attrGetMethod);
        if(attrSetMethod!=null)
            ai.setSetMethod(attrSetMethod);
    
public java.lang.StringtoFormatString()

        String str =  "\n\n*************** mbean type:"+managedBean.getName()+" ***************";
        String wrk;
        str += "\n--- ObjectName ="+ fields.get(OBJECTNAME_FIELD_NAME);
        str += "\n--- XPath ="+ fields.get(XPATH_FIELD_NAME);
        AttributeInfo[] attrs = managedBean.getAttributes();
        str =  str + "\n--- Attributes:";
        if(attrs!=null)
            for(int i=0; i<attrs.length; i++)
            {
                if("modelerType".equals(attrs[i].getName()))
                    continue;
                str = str + "\n " + formatClassName(attrs[i].getType(), 12)+" "+attrs[i].getName()+",";
                if(attrs[i].getDescription()!=null)
                   str = str + str + " // "+ attrs[i].getDescription();
            }

        OperationInfo[] opers = managedBean.getOperations();
        if(opers!=null && opers.length>0)
        {
            str =  str + "\n--- Operations:";
            for(int i=0; i<opers.length; i++)
            {
                wrk  = formatClassName(opers[i].getReturnType(), 14) + " " +  opers[i].getName() + "(";
                str = str + "\n"+wrk;
                //convert wrk to indent
                wrk = fillStr("\n", wrk.length()+1);
                ParameterInfo[] params = opers[i].getSignature();
                if(params!=null && params.length>0)
                {
                    for(int j=0; j<params.length; j++)
                    {
                        if(j!=0)
                            str += wrk;
                        str = str + formatClassName(params[j].getType(), 0) + " " +  params[j].getName();
                    }
//                    str = str + "[, Target target]";
                }
//                else
//                    str = str + "[Target target]";
                    
                str = str + ");";
                if(opers[i].getDescription()!=null)
                   str = str + str + " // "+ opers[i].getDescription();
            }
        }
        return str;
    
public java.lang.StringtoString()

        String str =  "\n--- MBeanRegistryEntry:\n   ";
        if(managedBean!=null)
        {
            str = str + managedBean.toString() + "\n   " +
            MBeanMetaHelper.descriptorToString(managedBean.getFields());
        }
        AttributeInfo[] attrs = managedBean.getAttributes();
        str =  str + "\n\n      --- Attributes:";
        if(attrs!=null)
            for(int i=0; i<attrs.length; i++)
            {
                if("modelerType".equals(attrs[i].getName()))
                    continue;
                str = str + "\n         " + attrs[i].toString();
                if(attrs[i].getFields().size()>0)
                   str = str + "\n            " + MBeanMetaHelper.descriptorToString(attrs[i].getFields());
            }

        OperationInfo[] opers = managedBean.getOperations();
        if(opers!=null && opers.length>0)
        {
            str =  str + "\n\n      --- Operations:";
            for(int i=0; i<opers.length; i++)
            {
                str = str + "\n         " + opers[i].toString();
                if(opers[i].getFields().size()>0)
                   str = str + "\n            " + MBeanMetaHelper.descriptorToString(opers[i].getFields());
                ParameterInfo[] params = opers[i].getSignature();
                if(params!=null && params.length>0)
                {
                    str =  str + "\n            --- Parameters:";
                    for(int j=0; j<params.length; j++)
                    {
                        str = str + "\n            " + params[j].toString();
                        if(params[j].getFields().size()>0)
                           str = str + "\n            " + MBeanMetaHelper.descriptorToString(params[j].getFields());
                    }
                }
            }
        }
        return str;