mirror of git://gcc.gnu.org/git/gcc.git
2007-04-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
* javax/management/ObjectName.java:
(parse(String)): Catch multiple wildcards,
initialise with an empty string (so null isn't
appended), and emit comma even when wildcard
ends the list.
(checkComponents()): Catch newlines.
(quote(String)): Handle newlines and quotes
correctly.
From-SVN: r123873
This commit is contained in:
parent
9cb116cb55
commit
b3ea5d8ea6
|
|
@ -1,3 +1,14 @@
|
||||||
|
2007-04-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
|
||||||
|
|
||||||
|
* javax/management/ObjectName.java:
|
||||||
|
(parse(String)): Catch multiple wildcards,
|
||||||
|
initialise with an empty string (so null isn't
|
||||||
|
appended), and emit comma even when wildcard
|
||||||
|
ends the list.
|
||||||
|
(checkComponents()): Catch newlines.
|
||||||
|
(quote(String)): Handle newlines and quotes
|
||||||
|
correctly.
|
||||||
|
|
||||||
2007-04-16 Andrew Haley <aph@redhat.com>
|
2007-04-16 Andrew Haley <aph@redhat.com>
|
||||||
|
|
||||||
* org/omg/IOP/TaggedComponentHelper.java (read): Use
|
* org/omg/IOP/TaggedComponentHelper.java (read): Use
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,13 @@ public class ObjectName
|
||||||
|
|
||||||
private static final long serialVersionUID = 1081892073854801359L;
|
private static final long serialVersionUID = 1081892073854801359L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The wildcard {@link ObjectName} {@code "*:*"}
|
||||||
|
*
|
||||||
|
* @since 1.6
|
||||||
|
*/
|
||||||
|
public static final ObjectName WILDCARD;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The domain of the name.
|
* The domain of the name.
|
||||||
*/
|
*/
|
||||||
|
|
@ -129,6 +136,23 @@ public class ObjectName
|
||||||
*/
|
*/
|
||||||
private transient MBeanServer server;
|
private transient MBeanServer server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static initializer to set up the wildcard.
|
||||||
|
*/
|
||||||
|
static
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
WILDCARD = new ObjectName("");
|
||||||
|
}
|
||||||
|
catch (MalformedObjectNameException e)
|
||||||
|
{
|
||||||
|
throw (InternalError) (new InternalError("A problem occurred " +
|
||||||
|
"initializing the ObjectName " +
|
||||||
|
"wildcard.").initCause(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an {@link ObjectName} instance from the given string,
|
* Constructs an {@link ObjectName} instance from the given string,
|
||||||
* which should be of the form
|
* which should be of the form
|
||||||
|
|
@ -159,7 +183,6 @@ public class ObjectName
|
||||||
* Parse the name in the same form as the constructor. Used by
|
* Parse the name in the same form as the constructor. Used by
|
||||||
* readObject().
|
* readObject().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void parse(String name)
|
private void parse(String name)
|
||||||
throws MalformedObjectNameException
|
throws MalformedObjectNameException
|
||||||
{
|
{
|
||||||
|
|
@ -169,32 +192,37 @@ public class ObjectName
|
||||||
domain = name.substring(0, domainSep);
|
domain = name.substring(0, domainSep);
|
||||||
String rest = name.substring(domainSep + 1);
|
String rest = name.substring(domainSep + 1);
|
||||||
properties = new TreeMap<String,String>();
|
properties = new TreeMap<String,String>();
|
||||||
if (rest.equals("*"))
|
String[] pairs = rest.split(",");
|
||||||
propertyPattern = true;
|
if (pairs.length == 0 && !isPattern())
|
||||||
else
|
throw new MalformedObjectNameException("A name that is not a " +
|
||||||
|
"pattern must contain at " +
|
||||||
|
"least one key-value pair.");
|
||||||
|
propertyListString = "";
|
||||||
|
for (int a = 0; a < pairs.length; ++a)
|
||||||
{
|
{
|
||||||
if (rest.endsWith(",*"))
|
if (pairs[a].equals("*"))
|
||||||
{
|
{
|
||||||
|
if (propertyPattern)
|
||||||
|
throw new MalformedObjectNameException("Multiple wildcards " +
|
||||||
|
"in properties.");
|
||||||
propertyPattern = true;
|
propertyPattern = true;
|
||||||
propertyListString = rest.substring(0, rest.length() - 2);
|
continue;
|
||||||
}
|
}
|
||||||
else
|
int sep = pairs[a].indexOf('=');
|
||||||
propertyListString = rest;
|
if (sep == -1)
|
||||||
String[] pairs = propertyListString.split(",");
|
throw new MalformedObjectNameException("A key must be " +
|
||||||
if (pairs.length == 0 && !isPattern())
|
"followed by a value.");
|
||||||
throw new MalformedObjectNameException("A name that is not a " +
|
String key = pairs[a].substring(0, sep);
|
||||||
"pattern must contain at " +
|
if (properties.containsKey(key))
|
||||||
"least one key-value pair.");
|
throw new MalformedObjectNameException("The same key occurs " +
|
||||||
for (int a = 0; a < pairs.length; ++a)
|
"more than once.");
|
||||||
{
|
String value = pairs[a].substring(sep+1);
|
||||||
int sep = pairs[a].indexOf('=');
|
properties.put(key, value);
|
||||||
String key = pairs[a].substring(0, sep);
|
propertyListString += key + "=" + value + ",";
|
||||||
if (properties.containsKey(key))
|
|
||||||
throw new MalformedObjectNameException("The same key occurs " +
|
|
||||||
"more than once.");
|
|
||||||
properties.put(key, pairs[a].substring(sep + 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (propertyListString.length() > 0)
|
||||||
|
propertyListString =
|
||||||
|
propertyListString.substring(0, propertyListString.length() - 1);
|
||||||
checkComponents();
|
checkComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,7 +291,7 @@ public class ObjectName
|
||||||
if (domain.indexOf('\n') != -1)
|
if (domain.indexOf('\n') != -1)
|
||||||
throw new MalformedObjectNameException("The domain includes a newline " +
|
throw new MalformedObjectNameException("The domain includes a newline " +
|
||||||
"character.");
|
"character.");
|
||||||
char[] chars = new char[] { ':', ',', '*', '?', '=' };
|
char[] chars = new char[] { '\n', ':', ',', '*', '?', '=' };
|
||||||
Iterator i = properties.entrySet().iterator();
|
Iterator i = properties.entrySet().iterator();
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
{
|
{
|
||||||
|
|
@ -284,8 +312,9 @@ public class ObjectName
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e)
|
catch (IllegalArgumentException e)
|
||||||
{
|
{
|
||||||
throw new MalformedObjectNameException("The quoted value is " +
|
throw (MalformedObjectNameException)
|
||||||
"invalid.");
|
new MalformedObjectNameException("The quoted value is " +
|
||||||
|
"invalid.").initCause(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (quote != -1)
|
else if (quote != -1)
|
||||||
|
|
@ -763,10 +792,12 @@ public class ObjectName
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialization methods. The serialized form is the same as the
|
* Serialize this {@link ObjectName}. The serialized
|
||||||
* string parsed by the constructor.
|
* form is the same as the string parsed by the constructor.
|
||||||
|
*
|
||||||
|
* @param out the output stream to write to.
|
||||||
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void writeObject(ObjectOutputStream out)
|
private void writeObject(ObjectOutputStream out)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
|
@ -777,14 +808,21 @@ public class ObjectName
|
||||||
buffer.append(properties);
|
buffer.append(properties);
|
||||||
if (isPropertyPattern())
|
if (isPropertyPattern())
|
||||||
{
|
{
|
||||||
if (properties.length() == 0)
|
if (properties.length() == 0)
|
||||||
buffer.append("*");
|
buffer.append("*");
|
||||||
else
|
else
|
||||||
buffer.append(",*");
|
buffer.append(",*");
|
||||||
}
|
}
|
||||||
out.writeObject(buffer.toString());
|
out.writeObject(buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the serialized form, which is that used
|
||||||
|
* by the constructor.
|
||||||
|
*
|
||||||
|
* @param in the input stream to read from.
|
||||||
|
* @throws IOException if an I/O error occurs.
|
||||||
|
*/
|
||||||
private void readObject(ObjectInputStream in)
|
private void readObject(ObjectInputStream in)
|
||||||
throws IOException, ClassNotFoundException
|
throws IOException, ClassNotFoundException
|
||||||
{
|
{
|
||||||
|
|
@ -833,10 +871,12 @@ public class ObjectName
|
||||||
{
|
{
|
||||||
n = q.charAt(++a);
|
n = q.charAt(++a);
|
||||||
if (n != '"' && n != '?' && n != '*' &&
|
if (n != '"' && n != '?' && n != '*' &&
|
||||||
n != '\n' && n != '\\')
|
n != 'n' && n != '\\')
|
||||||
throw new IllegalArgumentException("Illegal escaped character: "
|
throw new IllegalArgumentException("Illegal escaped character: "
|
||||||
+ n);
|
+ n);
|
||||||
}
|
}
|
||||||
|
else if (n == '"' || n == '\n')
|
||||||
|
throw new IllegalArgumentException("Illegal character: " + n);
|
||||||
builder.append(n);
|
builder.append(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue