2111 lines · 81.6 KB · Java
RawDownload
        final int len = val.length();        if (len == 0)            return false;         final char[] s = val.toCharArray();        final int[] result = parseValue(s,0);        final int endValue = result[0];        final boolean value_pattern = result[1] == 1;        if (endValue < len) throw new            MalformedObjectNameException("Invalid character in value: `" +                                         s[endValue] + "'");        return value_pattern;    }     /**     * Check if the supplied key is a valid key.     */    private static void checkKey(String key)        throws MalformedObjectNameException {         if (key == null) throw new            NullPointerException("Invalid key (null)");         final int len = key.length();        if (len == 0) throw new            MalformedObjectNameException("Invalid key (empty)");        final char[] k=key.toCharArray();        final int endKey = parseKey(k,0);        if (endKey < len) throw new            MalformedObjectNameException("Invalid character in value: `" +                                         k[endKey] + "'");    }      // Category : Internal utilities <==============================     // Category : Internal accessors ------------------------------>     /**     * Check if domain is a valid domain.  Set _domain_pattern if appropriate.     */    private boolean isDomain(String domain) {        if (domain == null) return true;        final int len = domain.length();        int next = 0;        while (next < len) {            final char c = domain.charAt(next++);            switch (c) {                case ':' :                case '\n' :                    return false;                case '*' :                case '?' :                    _domain_pattern = true;                    break;            }        }        return true;    }     // Category : Internal accessors <==============================     // Category : Serialization ----------------------------------->     /**     * Deserializes an {@link ObjectName} from an {@link ObjectInputStream}.     * @serialData <ul>     *               <li>In the current serial form (value of property     *                   <code>jmx.serial.form</code> differs from     *                   <code>1.0</code>): the string     *                   &quot;&lt;domain&gt;:&lt;properties&gt;&lt;wild&gt;&quot;,     *                   where: <ul>     *                            <li>&lt;domain&gt; represents the domain part     *                                of the {@link ObjectName}</li>     *                            <li>&lt;properties&gt; represents the list of     *                                properties, as returned by     *                                {@link #getKeyPropertyListString}     *                            <li>&lt;wild&gt; is empty if not     *                                <code>isPropertyPattern</code>, or     *                                is the character "<code>*</code>" if     *                                <code>isPropertyPattern</code>     *                                and &lt;properties&gt; is empty, or     *                                is "<code>,*</code>" if     *                                <code>isPropertyPattern</code> and     *                                &lt;properties&gt; is not empty.     *                            </li>     *                          </ul>     *                   The intent is that this string could be supplied     *                   to the {@link #ObjectName(String)} constructor to     *                   produce an equivalent {@link ObjectName}.     *               </li>     *               <li>In the old serial form (value of property     *                   <code>jmx.serial.form</code> is     *                   <code>1.0</code>): &lt;domain&gt; &lt;propertyList&gt;     *                   &lt;propertyListString&gt; &lt;canonicalName&gt;     *                   &lt;pattern&gt; &lt;propertyPattern&gt;,     *                   where: <ul>     *                            <li>&lt;domain&gt; represents the domain part     *                                of the {@link ObjectName}</li>     *                            <li>&lt;propertyList&gt; is the     *                                {@link Hashtable} that contains all the     *                                pairs (key,value) for this     *                                {@link ObjectName}</li>     *                            <li>&lt;propertyListString&gt; is the     *                                {@link String} representation of the     *                                list of properties in any order (not     *                                mandatorily a canonical representation)     *                                </li>     *                            <li>&lt;canonicalName&gt; is the     *                                {@link String} containing this     *                                {@link ObjectName}'s canonical name</li>     *                            <li>&lt;pattern&gt; is a boolean which is     *                                <code>true</code> if this     *                                {@link ObjectName} contains a pattern</li>     *                            <li>&lt;propertyPattern&gt; is a boolean which     *                                is <code>true</code> if this     *                                {@link ObjectName} contains a pattern in     *                                the list of properties</li>     *                          </ul>     *               </li>     *             </ul>     */    private void readObject(ObjectInputStream in)        throws IOException, ClassNotFoundException {         String cn;        if (compat) {            // Read an object serialized in the old serial form            //            //in.defaultReadObject();            final ObjectInputStream.GetField fields = in.readFields();            String propListString =                    (String)fields.get("propertyListString", "");             // 6616825: take care of property patterns            final boolean propPattern =                    fields.get("propertyPattern" , false);            if (propPattern) {                propListString =                        (propListString.length()==0?"*":(propListString+",*"));            }             cn = (String)fields.get("domain", "default")+                ":"+ propListString;        } else {            // Read an object serialized in the new serial form            //            in.defaultReadObject();            cn = (String)in.readObject();        }         try {            construct(cn);        } catch (NullPointerException e) {            throw new InvalidObjectException(e.toString());        } catch (MalformedObjectNameException e) {            throw new InvalidObjectException(e.toString());        }    }      /**     * Serializes an {@link ObjectName} to an {@link ObjectOutputStream}.     * @serialData <ul>     *               <li>In the current serial form (value of property     *                   <code>jmx.serial.form</code> differs from     *                   <code>1.0</code>): the string     *                   &quot;&lt;domain&gt;:&lt;properties&gt;&lt;wild&gt;&quot;,     *                   where: <ul>     *                            <li>&lt;domain&gt; represents the domain part     *                                of the {@link ObjectName}</li>     *                            <li>&lt;properties&gt; represents the list of     *                                properties, as returned by     *                                {@link #getKeyPropertyListString}     *                            <li>&lt;wild&gt; is empty if not     *                                <code>isPropertyPattern</code>, or     *                                is the character "<code>*</code>" if     *                                this <code>isPropertyPattern</code>     *                                and &lt;properties&gt; is empty, or     *                                is "<code>,*</code>" if     *                                <code>isPropertyPattern</code> and     *                                &lt;properties&gt; is not empty.     *                            </li>     *                          </ul>     *                   The intent is that this string could be supplied     *                   to the {@link #ObjectName(String)} constructor to     *                   produce an equivalent {@link ObjectName}.     *               </li>     *               <li>In the old serial form (value of property     *                   <code>jmx.serial.form</code> is     *                   <code>1.0</code>): &lt;domain&gt; &lt;propertyList&gt;     *                   &lt;propertyListString&gt; &lt;canonicalName&gt;     *                   &lt;pattern&gt; &lt;propertyPattern&gt;,     *                   where: <ul>     *                            <li>&lt;domain&gt; represents the domain part     *                                of the {@link ObjectName}</li>     *                            <li>&lt;propertyList&gt; is the     *                                {@link Hashtable} that contains all the     *                                pairs (key,value) for this     *                                {@link ObjectName}</li>     *                            <li>&lt;propertyListString&gt; is the     *                                {@link String} representation of the     *                                list of properties in any order (not     *                                mandatorily a canonical representation)     *                                </li>     *                            <li>&lt;canonicalName&gt; is the     *                                {@link String} containing this     *                                {@link ObjectName}'s canonical name</li>     *                            <li>&lt;pattern&gt; is a boolean which is     *                                <code>true</code> if this     *                                {@link ObjectName} contains a pattern</li>     *                            <li>&lt;propertyPattern&gt; is a boolean which     *                                is <code>true</code> if this     *                                {@link ObjectName} contains a pattern in     *                                the list of properties</li>     *                          </ul>     *               </li>     *             </ul>     */    private void writeObject(ObjectOutputStream out)            throws IOException {       if (compat)      {        // Serializes this instance in the old serial form        // Read CR 6441274 before making any changes to this code        ObjectOutputStream.PutField fields = out.putFields();        fields.put("domain", _canonicalName.substring(0, _domain_length));        fields.put("propertyList", getKeyPropertyList());        fields.put("propertyListString", getKeyPropertyListString());        fields.put("canonicalName", _canonicalName);        fields.put("pattern", (_domain_pattern || _property_list_pattern));        fields.put("propertyPattern", _property_list_pattern);        out.writeFields();      }      else      {        // Serializes this instance in the new serial form        //        out.defaultWriteObject();        out.writeObject(getSerializedNameString());      }    }     //  Category : Serialization <===================================     // Private methods <========================================     // Public methods ---------------------------------------->     // Category : ObjectName Construction ------------------------------>     /**     * <p>Return an instance of ObjectName that can be used anywhere     * an object obtained with {@link #ObjectName(String) new     * ObjectName(name)} can be used.  The returned object may be of     * a subclass of ObjectName.  Calling this method twice with the     * same parameters may return the same object or two equal but     * not identical objects.</p>     *     * @param name  A string representation of the object name.     *     * @return an ObjectName corresponding to the given String.     *     * @exception MalformedObjectNameException The string passed as a     * parameter does not have the right format.     * @exception NullPointerException The <code>name</code> parameter     * is null.     *     */    public static ObjectName getInstance(String name)            throws MalformedObjectNameException, NullPointerException {        return new ObjectName(name);    }     /**     * <p>Return an instance of ObjectName that can be used anywhere     * an object obtained with {@link #ObjectName(String, String,     * String) new ObjectName(domain, key, value)} can be used.  The     * returned object may be of a subclass of ObjectName.  Calling     * this method twice with the same parameters may return the same     * object or two equal but not identical objects.</p>     *     * @param domain  The domain part of the object name.     * @param key  The attribute in the key property of the object name.     * @param value The value in the key property of the object name.     *     * @return an ObjectName corresponding to the given domain,     * key, and value.     *     * @exception MalformedObjectNameException The     * <code>domain</code>, <code>key</code>, or <code>value</code>     * contains an illegal character, or <code>value</code> does not     * follow the rules for quoting.     * @exception NullPointerException One of the parameters is null.     *     */    public static ObjectName getInstance(String domain, String key,                                         String value)            throws MalformedObjectNameException {        return new ObjectName(domain, key, value);    }     /**     * <p>Return an instance of ObjectName that can be used anywhere     * an object obtained with {@link #ObjectName(String, Hashtable)     * new ObjectName(domain, table)} can be used.  The returned     * object may be of a subclass of ObjectName.  Calling this method     * twice with the same parameters may return the same object or     * two equal but not identical objects.</p>     *     * @param domain  The domain part of the object name.     * @param table A hash table containing one or more key     * properties.  The key of each entry in the table is the key of a     * key property in the object name.  The associated value in the     * table is the associated value in the object name.     *     * @return an ObjectName corresponding to the given domain and     * key mappings.     *     * @exception MalformedObjectNameException The <code>domain</code>     * contains an illegal character, or one of the keys or values in     * <code>table</code> contains an illegal character, or one of the     * values in <code>table</code> does not follow the rules for     * quoting.     * @exception NullPointerException One of the parameters is null.     *     */    public static ObjectName getInstance(String domain,                                         Hashtable<String,String> table)        throws MalformedObjectNameException {        return new ObjectName(domain, table);    }     /**     * <p>Return an instance of ObjectName that can be used anywhere     * the given object can be used.  The returned object may be of a     * subclass of ObjectName.  If <code>name</code> is of a subclass     * of ObjectName, it is not guaranteed that the returned object     * will be of the same class.</p>     *     * <p>The returned value may or may not be identical to     * <code>name</code>.  Calling this method twice with the same     * parameters may return the same object or two equal but not     * identical objects.</p>     *     * <p>Since ObjectName is immutable, it is not usually useful to     * make a copy of an ObjectName.  The principal use of this method     * is to guard against a malicious caller who might pass an     * instance of a subclass with surprising behavior to sensitive     * code.  Such code can call this method to obtain an ObjectName     * that is known not to have surprising behavior.</p>     *     * @param name an instance of the ObjectName class or of a subclass     *     * @return an instance of ObjectName or a subclass that is known to     * have the same semantics.  If <code>name</code> respects the     * semantics of ObjectName, then the returned object is equal     * (though not necessarily identical) to <code>name</code>.     *     * @exception NullPointerException The <code>name</code> is null.     *     */    public static ObjectName getInstance(ObjectName name) {        if (name.getClass().equals(ObjectName.class))            return name;        return Util.newObjectName(name.getSerializedNameString());    }     /**     * Construct an object name from the given string.     *     * @param name  A string representation of the object name.     *     * @exception MalformedObjectNameException The string passed as a     * parameter does not have the right format.     * @exception NullPointerException The <code>name</code> parameter     * is null.     */    public ObjectName(String name)        throws MalformedObjectNameException {        construct(name);    }     /**     * Construct an object name with exactly one key property.     *     * @param domain  The domain part of the object name.     * @param key  The attribute in the key property of the object name.     * @param value The value in the key property of the object name.     *     * @exception MalformedObjectNameException The     * <code>domain</code>, <code>key</code>, or <code>value</code>     * contains an illegal character, or <code>value</code> does not     * follow the rules for quoting.     * @exception NullPointerException One of the parameters is null.     */    public ObjectName(String domain, String key, String value)        throws MalformedObjectNameException {        // If key or value are null a NullPointerException        // will be thrown by the put method in Hashtable.        //        Map<String,String> table = Collections.singletonMap(key, value);        construct(domain, table);    }     /**     * Construct an object name with several key properties from a Hashtable.     *     * @param domain  The domain part of the object name.     * @param table A hash table containing one or more key     * properties.  The key of each entry in the table is the key of a     * key property in the object name.  The associated value in the     * table is the associated value in the object name.     *     * @exception MalformedObjectNameException The <code>domain</code>     * contains an illegal character, or one of the keys or values in     * <code>table</code> contains an illegal character, or one of the     * values in <code>table</code> does not follow the rules for     * quoting.     * @exception NullPointerException One of the parameters is null.     */    public ObjectName(String domain, Hashtable<String,String> table)            throws MalformedObjectNameException {        construct(domain, table);        /* The exception for when a key or value in the table is not a           String is now ClassCastException rather than           MalformedObjectNameException.  This was not previously           specified.  */    }     // Category : ObjectName Construction <==============================      // Category : Getter methods ------------------------------>     /**     * Checks whether the object name is a pattern.     * <p>     * An object name is a pattern if its domain contains a     * wildcard or if the object name is a property pattern.     *     * @return  True if the name is a pattern, otherwise false.     */    public boolean isPattern() {        return (_domain_pattern ||                _property_list_pattern ||                _property_value_pattern);    }     /**     * Checks whether the object name is a pattern on the domain part.     *     * @return  True if the name is a domain pattern, otherwise false.     *     */    public boolean isDomainPattern() {        return _domain_pattern;    }     /**     * Checks whether the object name is a pattern on the key properties.     * <p>     * An object name is a pattern on the key properties if it is a     * pattern on the key property list (e.g. "d:k=v,*") or on the     * property values (e.g. "d:k=*") or on both (e.g. "d:k=*,*").     *     * @return  True if the name is a property pattern, otherwise false.     */    public boolean isPropertyPattern() {        return _property_list_pattern || _property_value_pattern;    }     /**     * Checks whether the object name is a pattern on the key property list.     * <p>     * For example, "d:k=v,*" and "d:k=*,*" are key property list patterns     * whereas "d:k=*" is not.     *     * @return  True if the name is a property list pattern, otherwise false.     *     * @since 1.6     */    public boolean isPropertyListPattern() {        return _property_list_pattern;    }     /**     * Checks whether the object name is a pattern on the value part     * of at least one of the key properties.     * <p>     * For example, "d:k=*" and "d:k=*,*" are property value patterns     * whereas "d:k=v,*" is not.     *     * @return  True if the name is a property value pattern, otherwise false.     *     * @since 1.6     */    public boolean isPropertyValuePattern() {        return _property_value_pattern;

Lines 1001–1500 of 2111. Previous lines