FileDocCategorySizeDatePackage
OfflineConfigMgr.javaAPI DocGlassfish v2 API11698Fri May 04 22:25:34 BST 2007com.sun.enterprise.admin.config

OfflineConfigMgr

public class OfflineConfigMgr extends Object implements MBeanMetaConstants

Base class for Config MBeans which implements basic config activity according to ModelMBeanInfo provided by MBeanRegistry

Fields Summary
MBeanRegistry
_registry
com.sun.enterprise.config.ConfigContext
_ctx
ArrayList
_allDottedNames
Constructors Summary
public OfflineConfigMgr(String domainFileName)

        _ctx = ConfigFactory.createConfigContext(domainFileName);
        _registry = MBeanRegistryFactory.getOfflineAdminMBeanRegistry();
        try{
             Class cl = Class.forName("com.sun.enterprise.config.serverbeans.validation.DomainMgr");
             Constructor ctr  = cl.getConstructor(
                  new Class[]{ConfigContext.class, Boolean.TYPE, MBeanRegistry.class});
             _ctx.addConfigContextEventListener((ConfigContextEventListener)
                      ctr.newInstance(new Object[]{_ctx, false, _registry}));
        } catch(Exception e)
        {
            e.printStackTrace();
            throw new MBeanConfigException("error registering validator");
        }
    
Methods Summary
public javax.management.AttributeListaddSubvaluesToArrayAttribute(java.lang.String dottedName, java.lang.String[] addValues)

        String[] splitted = DottedNameHelper.splitAttributeNameFromDottedName(dottedName);
        ManagedConfigBean mb = getManagedConfigBean(splitted[0]);
        MBeanAttributeInfo attrInfo = mb.getAttributeInfo(splitted[1]);
        if(attrInfo==null ||
           !attrInfo.getType().startsWith("[")) //array?
        {
            throw new MBeanConfigException("add subelement: attribute type is not array");
        }
        AttributeList list = getAttributes(dottedName);
        ArrayList values = new ArrayList();
        if(list.size()!=0)
        {
            DottedNameHelper.addArrayToList(values, (Object[])((Attribute)list.get(0)).getValue());
        }
        DottedNameHelper.addArrayToList(values, addValues);
        return setAttribute(dottedName, values.toArray(new String[]{}));
    
private MBeanRegistryEntryfindRegistryEntry(java.lang.String dottedName, int nameTarget)

        MBeanRegistryEntry[] entries =  _registry.findMBeanRegistryEntriesByDottedName(dottedName);
        if(entries==null || entries.length==0)
            return null;
        if(entries.length==1)
            return entries[0];
        for(int i=0; i<entries.length; i++)
        {
            int entryTarget = getRegistryEntryTargetType(entries[i]);
            if(nameTarget==entryTarget)
                return entries[i];
            if ((nameTarget==TARGET_TYPE_SERVER || nameTarget==TARGET_TYPE_CLUSTER) &&
                (   entryTarget==TARGET_TYPE_CONFIG || 
                    entryTarget==TARGET_TYPE_APPLICATION ||
                    entryTarget==TARGET_TYPE_RESOURCE ) )
                return entries[i];
            if ( nameTarget==TARGET_TYPE_DOMAIN  &&
                 entryTarget!=TARGET_TYPE_CONFIG && 
                 entryTarget!=TARGET_TYPE_SERVER &&
                 entryTarget!=TARGET_TYPE_CLUSTER )
                return entries[i];
        }
        return null;
    
public javax.management.AttributeListgetAttributes(java.lang.String dottedName)

        String[] splitted = DottedNameHelper.splitAttributeNameFromDottedName(dottedName);
        ManagedConfigBean mb = getManagedConfigBean(splitted[0]);
        AttributeList attrs = mb.getAttributes(new String[]{splitted[1]});
        return DottedNameHelper.addDottedPrefix(attrs, splitted[0]);
    
public java.util.ArrayListgetListDottedNames(java.lang.String mask)

        synchronized(this) {
            if(_allDottedNames==null) {
                _allDottedNames  = new ArrayList();
                DottedNameHelper.collectConfigMBeansDottedNames(_registry, _ctx.getRootConfigBean(), _allDottedNames);
            }
        }
        ArrayList list = DottedNameHelper.filterStringValues(_allDottedNames, mask);
        return DottedNameHelper.sortDottedNames(_ctx, list);
    
private ManagedConfigBeangetManagedConfigBean(java.lang.String dottedName)

        int cmdTargetType =  DottedNameHelper.getDottedNameTargetType(
                                                    _ctx, dottedName);
        MBeanRegistryEntry entry = findRegistryEntry(dottedName, cmdTargetType);
        ManagedConfigBean mbc = null;
        if(entry!=null)
        {
            int elementTargetType = getRegistryEntryTargetType(entry);
            String resolvedName  = DottedNameHelper.resolveDottedNameToTarget(
                               _ctx, dottedName, cmdTargetType, elementTargetType);
            if(resolvedName!=null)
            {
                try {
                    MBeanNamingInfo namingInfo = 
                       new MBeanNamingInfo(entry.getNamingDescriptor(), resolvedName);
                    String xpath = namingInfo.getXPath();
                    ConfigBean configBean = 
                       (ConfigBean)ConfigBeansFactory.getConfigBeanByXPath(_ctx, xpath);
                    if(configBean!=null)
                    {
                        ModelMBeanInfo mbi = entry.createMBeanInfo(namingInfo, "offline");
                        mbc =  new ManagedConfigBean((MBeanInfo)mbi, configBean, _registry);
                    }

                } catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
        if(mbc==null)
            throw new MBeanConfigException("config element is not found");
        return mbc;
    
private intgetRegistryEntryTargetType(MBeanRegistryEntry entry)

       MBeanNamingDescriptor descr = entry.getNamingDescriptor();
       return DottedNameHelper.getTargetTypeForXPath(descr.getXPathPattern());
    
public javax.management.AttributeListremoveSubvaluesFromArrayAttribute(java.lang.String dottedName, java.lang.String[] removeValues)

        String[] splitted = DottedNameHelper.splitAttributeNameFromDottedName(dottedName);
        ManagedConfigBean mb = getManagedConfigBean(splitted[0]);
        MBeanAttributeInfo attrInfo = mb.getAttributeInfo(splitted[1]);
        if(attrInfo==null ||
           !attrInfo.getType().startsWith("[")) //array?
        {
            throw new MBeanConfigException("add subelement: attribute type is not array");
        }
        AttributeList list = getAttributes(dottedName);
        ArrayList values = new ArrayList();
        if(list.size()!=0)
        {
            DottedNameHelper.addArrayToList(values, (Object[])((Attribute)list.get(0)).getValue());
            for(int i=0; i<removeValues.length; i++)
            {
                for(int j=0; j<values.size(); j++)
                {
                    if(removeValues[i].equals(values.get(j)))
                    {
                        values.remove(j);
                        break; // only first occasion will be removed
                    }
                }
            }
        }
        return setAttribute(dottedName, values.toArray(new String[]{}));
    
public voidresetDottedNames()

        synchronized(this) {
            _allDottedNames = null;
        }
    
public javax.management.AttributeListsetAttribute(java.lang.String dottedName, java.lang.Object value)

        String[] splitted = DottedNameHelper.splitAttributeNameFromDottedName(dottedName);
        ManagedConfigBean mb = getManagedConfigBean(splitted[0]);
        AttributeList attrsIn = new AttributeList();
        attrsIn.add(new Attribute(splitted[1], value));
        AttributeList attrsOut = mb.setAttributes(attrsIn);
        _ctx.flush();
        return DottedNameHelper.addDottedPrefix(attrsOut, splitted[0]);
    
public javax.management.AttributeListsetAttributes(javax.management.AttributeList attrsIn)

        AttributeList attrsOut = new AttributeList();
        for(int i=0; i< attrsIn.size(); i++)
        {
            Attribute attr = (Attribute)attrsIn.get(i);
            try {
               AttributeList attrs = setAttribute(attr.getName(), attr.getValue());
               if(attrs.size()>0)
                   attrsOut.addAll(attrs);
            } catch (Exception e) {}
        }
        return attrsOut;