FileDocCategorySizeDatePackage
MBeanNamingDescriptor.javaAPI DocGlassfish v2 API17024Fri May 04 22:25:38 BST 2007com.sun.enterprise.admin.meta.naming

MBeanNamingDescriptor

public class MBeanNamingDescriptor extends Object
Provides naming support for Mbeans

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
Object[]
m_xpathTokens
Constructors Summary
public MBeanNamingDescriptor(Object[] description)


//	// i18n StringManager
//	private static StringManager localStrings =
//		StringManager.getManager( MBeanNamingDescriptor.class );
    
        
    
        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
        {
            if(m_dottedPatterns!=null)
            {
                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_xpathTokens  = getXPathTokens(m_xpathPattern);
            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 MBeanNamingException( msg );
        }
    
Methods Summary
public static java.lang.StringXPATH_TO_MASK(java.lang.String xpath)

        if(xpath==null || xpath.length()==0)
            return xpath;
        
        char[] chrs =  xpath.toCharArray();
        char[] newchrs = new char[chrs.length*2];
        int j = 0;
        for(int i=0; i<chrs.length; i++)
        {
            newchrs[j++] = chrs[i];
            if(chrs[i]=='\'")
                newchrs[j++] = '\'";
        }
        return String.valueOf(newchrs, 0, j);
    
private voidcheckConsistency()

    
public java.lang.String[]createDottedNames(java.lang.Object[] params)

        if(m_dottedPatterns==null || m_dottedPatterns.length<1)
            return null;
        String[] names = new String[m_dottedPatterns.length];
        for(int i=0; i<m_dottedPatterns.length;i++)
           names[i] = formatPattern(m_dottedPatterns[i], params);
        return names;
    
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();
        ht.put(":",objectName.getDomain()); //add domain name pseudo pair
        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;
    
public java.lang.String[]extractParmListFromXPath(java.lang.String xpath)

        Object[] tokens = MBeanNamingDescriptor.getXPathTokens(xpath);
        if(m_xpathTokens==null || tokens==null || m_parmListSize<=0)
            return null;
        if(m_xpathTokens.length!= tokens.length)
            return null;
        String[] parmList = new String[m_parmListSize];
        for(int i=0; i<tokens.length; i++)
        {
            if(m_xpathTokens[i] instanceof Integer)
            {
                parmList[((Integer)m_xpathTokens[i]).intValue()] = (String)tokens[i];
            }        
        }
        return parmList;
    
private java.lang.Object[]findDottedPatternTokens(Name name)

        if(m_dottedTokens!=null)
        {
            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)

        if(pattern==null)
            return null;
        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 static 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();
            ht.put(":",objName.getDomain()); //add domain name pseudo pair
            Enumeration ee = ht.keys();
            Object[] tokens = new Object[ht.size()*2];
            int i = 0;
            while(ee.hasMoreElements())
            {
                String key = ((String)ee.nextElement());
                tokens[i++] = key; //key.trim(); jmx allows to have spaces in keys and values
                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 java.lang.Object[]getXPathTokens(java.lang.String xpathPattern)

        ArrayList list = new ArrayList();
        int       idx = 0, idx2 = 0;
        
        if(xpathPattern!=null)
        {
            while(idx<xpathPattern.length() && (idx2=xpathPattern.indexOf("'", idx))>=0)
            {
                if(idx != idx2)
                    list.add(xpathPattern.substring(idx,idx2));
                idx = idx2+1;
            }
            if(idx<xpathPattern.length())
                list.add(xpathPattern.substring(idx).trim());
            Object[] tokens = list.toArray();
            replacePlaceholdersToIntegers(tokens);
            return tokens;
        }
        return null;
    
private static booleanisDottedPatternMatch(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;
    
public booleanisDottedPatternMatch(Name name)

        if(findDottedPatternTokens(name)!=null)
            return true;
        return false;
    
public booleanisObjectNamePatternMatch(javax.management.ObjectName objectName)

       Hashtable ht = objectName.getKeyPropertyList();
       ht.put(":",objectName.getDomain()); //add domain name pseudo pair
       return isObjectNamePatternMatch(ht);
    
public 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);
    
public booleanisXpathTokensMatch(java.lang.Object[] tokens)

        if(m_xpathTokens==null || tokens==null)
            return false;
        if(m_xpathTokens.length!= tokens.length)
            return false;
        for(int i=0; i<tokens.length; i++)
        {
            if( (m_xpathTokens[i] instanceof String) &&
            !m_xpathTokens[i].equals(tokens[i]))
                return false;
        }
        return true;
    
private static 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)

        if(names==null)
            return null;
        ArrayList list = new ArrayList();
        int idx = 0, idx2 = 0;
        while(idx<names.length() && (idx2=names.indexOf(MBeansNaming.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()]);