FileDocCategorySizeDatePackage
MBeanNamingDescriptor.javaAPI DocGlassfish v2 API11906Fri May 04 22:34:08 BST 2007com.sun.enterprise.admin.server.core.mbean.config.naming

MBeanNamingDescriptor

public class MBeanNamingDescriptor extends Object
Provides naming support for ConfigMbeans

Fields Summary
String
m_type
String
m_className
String
m_objectPattern
String[]
m_dottedPatterns
String
m_xpathPattern
int
m_mode
int
m_parmListSize
Object[]
m_dottedTokens
Object[]
m_objectTokens
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public MBeanNamingDescriptor(Object[] description)

    
        
    
        this((String)description[0], (Integer)description[1], (String)description[2], (String)description[3], (String)description[4], (String)description[5]);
    
public MBeanNamingDescriptor(String type, Integer mode, String dottedPatterns, String objectPattern, String xpathPattern, String className)

        m_type     = type;
        m_className     = className;
        m_dottedPatterns = splitDottedPatternsString(dottedPatterns);
        m_xpathPattern  = xpathPattern;
        m_objectPattern = objectPattern;
        m_mode          = mode.intValue();
        
        try
        {
            m_dottedTokens = new Object[m_dottedPatterns.length][];
            for(int i=0; i<m_dottedPatterns.length; i++)
                m_dottedTokens[i] = getDottedNamePatternTokens(m_dottedPatterns[i]);
            m_objectTokens = getObjectNamePatternTokens(m_objectPattern);
            m_parmListSize = getMaxTokenIndex(m_objectTokens) + 1;
            
            checkConsistency();
        }
        catch(Exception e)
        {
			String msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeandescriptor_creation_failure_for_object_pattern", objectPattern, e.getMessage() );
            throw new MBeanConfigException( msg );
        }
    
Methods Summary
private voidcheckConsistency()

    
public java.lang.StringcreateDottedNameName(java.lang.Object[] params)

        if(m_dottedPatterns==null || m_dottedPatterns.length<1)
            return null;
        return formatPattern(m_dottedPatterns[0], params);
    
public javax.management.ObjectNamecreateObjectName(java.lang.Object[] params)

        return new ObjectName(formatPattern(m_objectPattern, params));
    
public java.lang.StringcreateXPath(java.lang.Object[] params)

        return formatPattern(m_xpathPattern, params);
    
public java.lang.String[]extractParmList(javax.management.ObjectName objectName)

        if(m_objectTokens==null)
            return null;
        Hashtable  ht = objectName.getKeyPropertyList();
        String[] parmList = new String[m_parmListSize];
        for(int i=0; i<m_objectTokens.length; i=i+2)
        {
            if( m_objectTokens[i+1] instanceof Integer )
            {
                parmList[((Integer)m_objectTokens[i+1]).intValue()] = (String)ht.get(m_objectTokens[i]);
            }
        }
        return parmList;
    
java.lang.String[]extractParmList(java.lang.String dottedName)

        if(m_dottedTokens==null)
            return null;
        Name name = new Name(dottedName);
        Object[] tokens = findDottedPatternTokens(name);
        if(tokens == null)
            return null;
        int  nTokens = name.getNumParts();
        if(name.getNumParts()!=tokens.length)
            return null;
        
        String[] parmList = new String[m_parmListSize];
        
        for(int i=0; i<nTokens; i++)
        {
            if( tokens[i] instanceof Integer )
            {
                parmList[((Integer)tokens[i]).intValue()] = name.getNamePart(i).toString();
            }
        }
        return parmList;
    
private java.lang.Object[]findDottedPatternTokens(com.sun.enterprise.admin.common.Name name)

        for(int i=0; i<m_dottedTokens.length; i++)
        {
            if(isDottedPatternMatch(name, m_dottedTokens[i], true))
                return m_dottedTokens[i];
        }
        return null;
    
private java.lang.StringformatPattern(java.lang.String pattern, java.lang.Object[] params)

        return MessageFormat.format(pattern, params);
    
private java.lang.Object[]getDottedNamePatternTokens(java.lang.String dottedPattern)

        ArrayList list = new ArrayList();
        int       idx = 0, idx2 = 0;
        
        if(dottedPattern!=null)
        {
            while(idx<dottedPattern.length() && (idx2=dottedPattern.indexOf('.", idx))>=0)
            {
                if(idx == idx2)
                    list.add("");
                else
                    list.add(dottedPattern.substring(idx,idx2).trim());
                idx = idx2+1;
            }
            if(idx<dottedPattern.length())
                list.add(dottedPattern.substring(idx).trim());
            Object[] tokens = list.toArray();
            replacePlaceholdersToIntegers(tokens);
            return tokens;
        }
        return null;
    
public java.lang.String[]getDottedPatterns()

        return m_dottedPatterns;
    
public java.lang.Object[][]getDottedTokens()

        return m_dottedTokens;
    
private java.lang.IntegergetIndexForPlaceholder(java.lang.String str)

        int len = str.length();
        if(len<3 || str.charAt(0)!='{" || str.charAt(len-1)!='}")
            return null;
        try
        {
            return Integer.valueOf(str.substring(1,len-1));
        }
        catch(Throwable e)
        {
        }
        return null;
    
public java.lang.StringgetMBeanClassName()

        return m_className;
    
private intgetMaxTokenIndex(java.lang.Object[] tokens)

        int res = -1;
        int current;
        for(int i=0; i<tokens.length; i++)
        {
            if(tokens[i] instanceof Integer &&
            res < (current=((Integer)tokens[i]).intValue()))
                res  = current;
        }
        return res;
    
public intgetMode()

        return m_mode;
    
private java.lang.Object[]getObjectNamePatternTokens(java.lang.String objectPattern)

        if(objectPattern!=null)
        {
            ObjectName objName = new ObjectName(objectPattern);
            Hashtable  ht = objName.getKeyPropertyList();
            Enumeration e = ht.keys();
            Object[] tokens = new Object[ht.size()*2];
            int i = 0;
            while(e.hasMoreElements())
            {
                String key = (String)e.nextElement();
                tokens[i++] = key;
                tokens[i++] = ht.get(key);
            }
            replacePlaceholdersToIntegers(tokens);
            return tokens;
        }
        return null;
    
public intgetParmListSize()

        return m_parmListSize;
    
public java.lang.StringgetType()

        return m_type;
    
public java.lang.StringgetXPathPattern()

        return m_xpathPattern;
    
public static booleanisDottedPatternMatch(com.sun.enterprise.admin.common.Name name, java.lang.Object[] tokens, boolean bExactMatch)

        if(tokens==null)
            return false;
        int  nTokens = name.getNumParts();
        if(bExactMatch)
        {
            if(nTokens!=tokens.length)
                return false;
        }
        else
        {
            if(nTokens>tokens.length)
                return false;
        }
        for(int i=0; i<nTokens; i++)
        {
            if( (tokens[i] instanceof String) &&
            !name.getNamePart(i).toString().equals((String)tokens[i]))
                return false;
        }
        return true;
    
booleanisDottedPatternMatch(com.sun.enterprise.admin.common.Name name)

        if(findDottedPatternTokens(name)!=null)
            return true;
        return false;
    
booleanisObjectNamePatternMatch(java.util.Hashtable sample)

        if(m_objectTokens.length!=(sample.size()*2))
            return false;
        for(int i=0; i<m_objectTokens.length; i = i+2)
        {
            String sampleVal = (String)sample.get(m_objectTokens[i]);
            if(sampleVal==null || 
               ((m_objectTokens[i+1] instanceof String) && !sampleVal.equals((String)m_objectTokens[i+1])) )
                return false;
        }
        return (true);
    
private voidreplacePlaceholdersToIntegers(java.lang.Object[] tokens)

        for(int i=0; i<tokens.length; i++)
        {
            Object idx = getIndexForPlaceholder((String)tokens[i]);
            if(idx!=null)
                tokens[i] = idx;
        }
    
private java.lang.String[]splitDottedPatternsString(java.lang.String names)

        ArrayList list = new ArrayList();
        int idx = 0, idx2 = 0;
        while(idx<names.length() && (idx2=names.indexOf(MBeansDescriptions.PATTERNS_SEPARATOR, idx))>=0)
        {
            if(idx2!=idx)
                list.add(names.substring(idx, idx2));
            idx = idx2+1;
        }
        if(idx2<0)
            list.add(names.substring(idx));
        return (String[])list.toArray(new String[list.size()]);