libjava/classpath/ChangeLog.gcj:

2007-05-31  Matthias Klose  <doko@ubuntu.com>

        * javax/management/NotificationBroadcasterSupport.java
        (getNotificationInfo): Add cast.
        * native/jni/qt-peer/Makefile.am (AM_CXXFLAGS): Add libstdc++ include
        directories.
        * native/jni/qt-peer/Makefile.in: Regenerate.

libjava/ChangeLog:

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        * java/io/natFileWin32.cc (setFilePermissions): New (stub only).
        _access: Handle EXEC query, stub only.

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        Merged from classpath:
        * gnu/java/nio/SelectorProviderImpl.java: Whitespace merge.
        * java/lang/System.java(inheritedChannel): New.
        * java/lang/Character.java: Remove stray`;'.
        * java/net/MulticastSocket.java: Merged.
        * java/text/DateFormatSymbols.java(getInstance): New, comment updates.
        * java/text/Collator.java(getInstance): Merged.
        * java/util/Calendar.java: New attributes ALL_STYLES, SHORT, LONG.
        getDisplayName, getDisplayNames: New.
        * java/util/logging/Logger.java: Merged.
        * Regenerate .class and .h files.

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        * java/io/File.java: Merge with classpath-0.95, new method
        setFilePermissions, new attribute EXEC.
        * java/io/natFilePosix.cc (setFilePermissions): New.
        _access: Handle EXEC query.
        * classpath/lib/java/io/File.class, java/io/File.h: Regenerate.

2007-06-03  Matthias Klose  <doko@ubuntu.com>

        Imported GNU Classpath 0.95.

        * classpath/Makefile.in,
        classpath/native/jni/midi-dssi/Makefile.in,
        classpath/native/jni/classpath/Makefile.in,
        classpath/native/jni/Makefile.in,
        classpath/native/jni/gconf-peer/Makefile.in,
        classpath/native/jni/java-io/Makefile.in,
        classpath/native/jni/native-lib/Makefile.in,
        classpath/native/jni/java-util/Makefile.in,
        classpath/native/jni/midi-alsa/Makefile.in,
        classpath/native/jni/java-lang/Makefile.in,
        classpath/native/jni/java-nio/Makefile.in,
        classpath/native/jni/java-net/Makefile.in,
        classpath/native/jni/xmlj/Makefile.in,
        classpath/native/jni/qt-peer/Makefile.in,
        classpath/native/jni/gtk-peer/Makefile.in,
        classpath/native/Makefile.in, classpath/native/jawt/Makefile.in,
        classpath/native/fdlibm/Makefile.in,
        classpath/native/plugin/Makefile.in,
        classpath/resource/Makefile.in, classpath/scripts/Makefile.in,
        classpath/tools/Makefile.in, classpath/doc/Makefile.in,
        classpath/doc/api/Makefile.in, classpath/lib/Makefile.in,
        classpath/external/Makefile.in, classpath/external/jsr166/Makefile.in,
        classpath/external/sax/Makefile.in,
        classpath/external/w3c_dom/Makefile.in,
        classpath/external/relaxngDatatype/Makefile.in,
        classpath/include/Makefile.in,
        classpath/examples/Makefile.in: Regenerate.
        * classpath/config.guess, classpath/config.sub,
        classpath/ltmain.sh : Update.
        * classpath/configure, classpath/depcomp, classpath/missing,
        classpath/aclocal.m4, classpath/install-sh: Regenerate.

        * gnu/classpath/Configuration.java (CLASSPATH_VERSION): Now 0.95.
        * sources.am: Regenerate.
        * Makefile.in: Regenerate.

        * Update the .class files and generated CNI header files, add new
        .class and generated CNI header files.
        * Remove generated files for removed java source files:
        classpath/gnu/java/net/BASE64.java,
        classpath/gnu/java/security/util/Base64.java,
        classpath/gnu/java/awt/peer/gtk/GThreadMutex.java,
        classpath/gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java,
        classpath/gnu/java/awt/font/autofit/Scaler.java,
        classpath/gnu/classpath/jdwp/util/Value.java,
        classpath/gnu/javax/net/ssl/Base64.java.
        * Remove empty directories.

        * Makefile.am(nat_source_files): Add natVMOperatingSystemMXBeanImpl.cc.
        * java/lang/Class.java(setAccessible): Merge from classpath.
        * java/util/Locale.java: Remove.
        * gnu/java/lang/management/VMOperatingSystemMXBeanImpl.java,
        gnu/java/lang/management/natVMOperatingSystemMXBeanImpl.cc: New.
        * gcj/javaprims.h: Update class declarations.
        * scripts/classes.pl: Update usage.
        * HACKING: Mention to build all peers.

From-SVN: r125302
This commit is contained in:
Matthias Klose 2007-06-03 23:18:43 +00:00
parent af333b9a7f
commit e1bea0c068
2951 changed files with 80982 additions and 68583 deletions

View file

@ -0,0 +1,90 @@
/* ActivityCompletedException.java -- Wrapper for CORBA.ACTIVITY_COMPLETED.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.activity;
import java.rmi.RemoteException;
/**
* Exception wrapper for CORBA.ACTIVITY_COMPLETED.
*
* @see org.omg.CORBA.ACTIVITY_COMPLETED
*/
public class ActivityCompletedException extends RemoteException
{
/**
* Creates an exception with a null message, and cause initialized
* to null.
*/
public ActivityCompletedException()
{
this(null, null);
}
/**
* Creates an exception with the given message, and cause
* initialized to null.
*
* @param s the message
*/
public ActivityCompletedException(String s)
{
this(s, null);
}
/**
* Creates an exception with the given cause, and a null message.
*
* @param e the cause
*/
public ActivityCompletedException(Throwable e)
{
this(null, e);
}
/**
* Creates an exception with the given message and cause.
*
* @param s the message
* @param e the cause
*/
public ActivityCompletedException(String s, Throwable e)
{
super(s, e);
}
}

View file

@ -0,0 +1,90 @@
/* ActivityRequiredException.java -- Wrapper for CORBA.ACTIVITY_REQUIRED
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.activity;
import java.rmi.RemoteException;
/**
* Exception wrapper for CORBA.ACTIVITY_REQUIRED
*
* @see org.omg.CORBA.ACTIVITY_REQUIRED
*/
public class ActivityRequiredException extends RemoteException
{
/**
* Creates an exception with a null message, and cause initialized
* to null.
*/
public ActivityRequiredException()
{
this(null, null);
}
/**
* Creates an exception with the given message, and cause
* initialized to null.
*
* @param s the message
*/
public ActivityRequiredException(String s)
{
this(s, null);
}
/**
* Creates an exception with the given cause, and a null message.
*
* @param e the cause
*/
public ActivityRequiredException(Throwable e)
{
this(null, e);
}
/**
* Creates an exception with the given message and cause.
*
* @param s the message
* @param e the cause
*/
public ActivityRequiredException(String s, Throwable e)
{
super(s, e);
}
}

View file

@ -0,0 +1,90 @@
/* InvalidActivityException.java -- Wrapper for CORBA.INVALID_ACTIVITY
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.activity;
import java.rmi.RemoteException;
/**
* Exception wrapper for CORBA.INVALID_ACTIVITY.
*
* @see org.omg.CORBA.INVALID_ACTIVITY
*/
public class InvalidActivityException extends RemoteException
{
/**
* Creates an exception with a null message, and cause initialized
* to null.
*/
public InvalidActivityException()
{
this(null, null);
}
/**
* Creates an exception with the given message, and cause
* initialized to null.
*
* @param s the message
*/
public InvalidActivityException(String s)
{
this(s, null);
}
/**
* Creates an exception with the given cause, and a null message.
*
* @param e the cause
*/
public InvalidActivityException(Throwable e)
{
this(null, e);
}
/**
* Creates an exception with the given message and cause.
*
* @param s the message
* @param e the cause
*/
public InvalidActivityException(String s, Throwable e)
{
super(s, e);
}
}

View file

@ -0,0 +1,45 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- package.html - describes classes in the javax.activity package.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. -->
<html>
<head><title>GNU Classpath - javax.activity</title></head>
<body>
<p>Exception wrappers for org.omg.CORBA activity status system exceptions.</p>
</body>
</html>

View file

@ -147,6 +147,8 @@ public class CipherOutputStream extends FilterOutputStream
*/
public void write(byte[] buf, int off, int len) throws IOException
{
out.write(cipher.update(buf, off, len));
byte[] b = cipher.update(buf, off, len);
if (b != null)
out.write(b);
}
}

View file

@ -278,7 +278,7 @@ public class ImageWriteParam extends IIOParam
public String[] getCompressionQualityDescriptions()
{
checkNotExplicitCompression();
checkCompressionTypesSet();;
checkCompressionTypesSet();
return null;
}
@ -286,7 +286,7 @@ public class ImageWriteParam extends IIOParam
public float[] getCompressionQualityValues()
{
checkNotExplicitCompression();
checkCompressionTypesSet();;
checkCompressionTypesSet();
return null;
}

View file

@ -45,6 +45,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import gnu.java.awt.ClasspathToolkit;
import gnu.javax.imageio.bmp.BMPImageReaderSpi;
import gnu.javax.imageio.bmp.BMPImageWriterSpi;
import gnu.javax.imageio.gif.GIFImageReaderSpi;
@ -91,6 +92,8 @@ public final class IIORegistry extends ServiceRegistry
registerServiceProvider(new BMPImageWriterSpi());
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof ClasspathToolkit)
((ClasspathToolkit)toolkit).registerImageIOSpis(this);
registerApplicationClasspathSpis();
}

View file

@ -957,6 +957,6 @@ public class ServiceRegistry
* criteria; <code>false</code> if it does not match.
*/
boolean filter(Object provider);
};
}
}

View file

@ -38,11 +38,10 @@ exception statement from your version. */
package javax.imageio.stream;
import gnu.classpath.NotImplementedException;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
/**
* @author Michael Koch (konqueror@gmx.de)
@ -50,32 +49,30 @@ import java.io.OutputStream;
public class FileCacheImageOutputStream extends ImageOutputStreamImpl
{
private OutputStream stream;
private File cacheDir;
public FileCacheImageOutputStream(OutputStream stream, File cacheDir)
private File cacheFile;
private RandomAccessFile cache;
private long maxPos;
public FileCacheImageOutputStream(OutputStream s, File cacheDir)
throws IOException
{
super();
this.stream = stream;
// FIXME: We do not support caching yet.
this.cacheDir = cacheDir;
stream = s;
cacheFile = File.createTempFile("imageio", ".tmp", cacheDir);
cache = new RandomAccessFile(cacheFile, "rw");
maxPos = 0;
}
public void close()
throws IOException
{
if (stream != null)
{
stream.close();
stream = null;
}
}
private void checkStreamClosed()
throws IOException
{
if (stream == null)
throw new IOException("stream closed");
maxPos = cache.length();
seek(maxPos);
flushBefore(maxPos);
super.close();
cache.close();
cacheFile.delete();
stream.flush();
stream = null;
}
public boolean isCached()
@ -94,32 +91,88 @@ public class FileCacheImageOutputStream extends ImageOutputStreamImpl
}
public int read()
throws IOException, NotImplementedException
throws IOException
{
// FIXME: Implement me.
throw new Error("not implemented");
bitOffset = 0;
int val = cache.read();
if (val != -1)
streamPos++;
return val;
}
public int read(byte[] data, int offset, int len)
throws IOException, NotImplementedException
throws IOException
{
// FIXME: Implement me.
throw new Error("not implemented");
bitOffset = 0;
int num = cache.read(data, offset, len);
if (num != -1)
streamPos += num;
return num;
}
public void write(byte[] data, int offset, int len)
throws IOException
{
checkStreamClosed();
// FIXME: Flush pending bits.
stream.write(data, offset, len);
flushBits();
cache.write(data, offset, len);
streamPos += len;
maxPos = Math.max(streamPos, maxPos);
}
public void write(int value)
throws IOException
{
checkStreamClosed();
// FIXME: Flush pending bits.
stream.write(value);
flushBits();
cache.write(value);
streamPos++;
maxPos = Math.max(streamPos, maxPos);
}
public long length()
{
long l;
try
{
l = cache.length();
}
catch (IOException ex)
{
l = -1;
}
return l;
}
public void seek(long pos)
throws IOException
{
checkClosed();
if (pos < flushedPos)
throw new IndexOutOfBoundsException();
cache.seek(pos);
streamPos = cache.getFilePointer();
maxPos = Math.max(streamPos, maxPos);
bitOffset = 0;
}
public void flushBefore(long pos)
throws IOException
{
long oldPos = flushedPos;
super.flushBefore(pos);
long flushed = flushedPos - oldPos;
if (flushed > 0)
{
int len = 512;
byte[] buf = new byte[len];
cache.seek(oldPos);
while (flushed > 0)
{
int l = (int) Math.min(flushed, len);
cache.readFully(buf, 0, l);
stream.write(buf, 0, l);
flushed -= l;
}
stream.flush();
}
}
}

View file

@ -38,8 +38,6 @@ exception statement from your version. */
package javax.imageio.stream;
import gnu.classpath.NotImplementedException;
import java.io.IOException;
import java.io.UTFDataFormatException;
import java.nio.ByteOrder;
@ -56,10 +54,25 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl
}
protected final void flushBits()
throws IOException, NotImplementedException
throws IOException
{
// FIXME: Implement me.
throw new Error("not implemented");
checkClosed();
if (bitOffset != 0)
{
int offset = bitOffset;
int partial = read();
if (partial < 0)
{
partial = 0;
bitOffset = 0;
}
else
{
seek(getStreamPosition() - 1);
partial &= -1 << (8 - offset);
}
write(partial);
}
}
public void write(byte[] data)
@ -75,17 +88,82 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl
throws IOException;
public void writeBit(int bit)
throws IOException, NotImplementedException
throws IOException
{
// FIXME: Implement me.
throw new Error("not implemented");
writeBits(1L & bit, 1);
}
public void writeBits(long bits, int numBits)
throws IOException, NotImplementedException
throws IOException
{
// FIXME: Implement me.
throw new Error("not implemented");
checkClosed();
// Append chunk of bits to any preexisting bits, if any.
if (getStreamPosition() > 0 || bitOffset > 0)
{
int offs = bitOffset;
int partial = read();
if (partial != -1)
seek(getStreamPosition() - 1);
else
partial = 0;
if (numBits + offs < 8)
{
// Append complete bits to partial byte.
int shift = 8 - (offs + numBits);
int mask = -1 >>> (32 - numBits);
partial &= ~(mask << shift);
partial |= (bits & mask) << shift;
write(partial);
seek(getStreamPosition() - 1);
bitOffset = offs + numBits;
numBits = 0;
}
else
{
// Append bits and decrease numBits accordingly.
int num = 8 - offs;
int mask = -1 >>> (32 - num);
partial &= ~mask;
partial |= (bits >> (numBits - num)) & mask;
write(partial);
numBits -= num;
}
}
// Write out whole chunks, if any.
if (numBits > 7)
{
int remaining = numBits % 8;
for (int numBytes = numBits / 8; numBytes > 0; numBytes--)
{
int shift = (numBytes - 1) * 8 + remaining;
int value = (int) ((shift == 0) ? bits & 0xff
: (bits >> shift) & 0xff);
write(value);
}
numBits = remaining;
}
// Write remaing partial bytes.
if (numBits != 0)
{
int partial = read();
if (partial == -1)
{
seek(getStreamPosition() - 1);
}
else
{
partial = 0;
}
int shift = 8 - numBits;
int mask = -1 >>> (32 - numBits);
partial &= ~(mask << shift);
partial |= (bits & mask) << shift;
write(partial);
seek(getStreamPosition() - 1);
bitOffset = numBits;
}
}
public void writeBoolean(boolean value)

View file

@ -0,0 +1,166 @@
/* AttributeChangeNotification.java -- Notification for attribute changes
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
/**
* Defines the notification used to let listeners know of
* an attribute change. The bean itself is responsible
* for creating and transmitting the notification when the
* attribute changes, by implementing
* {@link NotificationBroadcaster}. For example, if a
* bean increments the integer, <code>count</code>, it
* should send a notification with the
* <code>attributeName</code>, <code>"count"</code>,
* the <code>attributeType</code>, <code>"Integer"</code>
* and the old and new values of the attribute.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class AttributeChangeNotification
extends Notification
{
/**
* Compatible with JDK 1.5
*/
private static final long serialVersionUID = 535176054565814134L;
/**
* The attribute type for attribute change
* notifications.
*/
public static final String ATTRIBUTE_CHANGE = "jmx.attribute.change";
/**
* The name of the attribute that changed.
*/
private String attributeName;
/**
* The type of the attribute that changed.
*/
private String attributeType;
/**
* The old value of the attribute.
*/
private Object oldValue;
/**
* The new value of the attribute.
*/
private Object newValue;
/**
* Constructs a new {@link AttributeChangeNotification}
* with the specified source, sequence number, timestamp,
* message, and the attribute name, type, old value and
* new value.
*
* @param source the producer of the notification, which
* is usually the bean that changed the
* attribute.
* @param sequenceNumber the sequence number of the
* notification.
* @param timeStamp the date and time of the notification.
* @param msg the message content of the notification.
* @param name the name of the attribute.
* @param type the type of the attribute.
* @param oldVal the old value of the attribute.
* @param newVal the new value of the attribute.
*/
public AttributeChangeNotification(Object source,
long sequenceNumber,
long timeStamp,
String msg, String name,
String type, Object oldVal,
Object newVal)
{
super(ATTRIBUTE_CHANGE, source, sequenceNumber,
timeStamp, msg);
attributeName = name;
attributeType = type;
oldValue = oldVal;
newValue = newVal;
}
/**
* Returns the name of the attribute that changed.
*
* @return the name of the attribute.
*/
public String getAttributeName()
{
return attributeName;
}
/**
* Returns the type of the attribute that changed.
*
* @return the type of the attribute.
*/
public String getAttributeType()
{
return attributeType;
}
/**
* Returns the old value of the attribute.
*
* @return the old value.
*/
public Object getOldValue()
{
return oldValue;
}
/**
* Returns the new value of the attribute.
*
* @return the new value.
*/
public Object getNewValue()
{
return newValue;
}
}

View file

@ -0,0 +1,137 @@
/* AttributeChangeNotificationFilter.java -- Filter on attribute name
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import java.io.Serializable;
import java.util.Vector;
/**
* Performs filtering of {@link AttributeChangeNotification}s
* based on a list of attribute names.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class AttributeChangeNotificationFilter
implements NotificationFilter, Serializable
{
/**
* Compatible with JDK 1.5
*/
private static final long serialVersionUID = -6347317584796410029L;
/**
* Lists the names of the attributes that may pass
* through the filter.
*/
private final Vector<String> enabledAttributes = new Vector<String>();
/**
* Blocks all {@link AttributeChangeNotification}s
* by emptying the list of enabled attributes.
*/
public void disableAllAttributes()
{
enabledAttributes.clear();
}
/**
* Removes the specified attribute name from the list
* of enabled attributes, thus preventing
* {@link AttributeChangeNotification}s for this attribute
* from passing through the filter. If the attribute is
* not enabled, this has no effect.
*
* @param name the name of the attribute to disable.
*/
public void disableAttribute(String name)
{
enabledAttributes.remove(name);
}
/**
* Adds the specified attribute name to the list
* of enabled attributes, thus allowing
* {@link AttributeChangeNotification}s for this attribute
* to pass through the filter. If the attribute is
* enabled, this has no effect.
*
* @param name the name of the attribute to enable.
*/
public void enableAttribute(String name)
{
if (!enabledAttributes.contains(name))
enabledAttributes.add(name);
}
/**
* Returns the list of enabled attributes for this
* filter.
*
* @return the list of enabled attributes.
*/
public Vector<String> getEnabledAttributes()
{
return enabledAttributes;
}
/**
* Returns true if the specified notification is an
* {@link AttributeChangeNotification} and the name of the
* attribute concerned is in the list of enabled attributes
* for this filter.
*
* @param notif the notification being filtered.
* @return true if the notification is an
* {@link AttributeChangeNotification} for an
* enabled attribute.
*/
public boolean isNotificationEnabled(Notification notif)
{
if (notif instanceof AttributeChangeNotification)
{
AttributeChangeNotification n =
(AttributeChangeNotification) notif;
return enabledAttributes.contains(n.getAttributeName());
}
return false;
}
}

View file

@ -0,0 +1,181 @@
/* AttributeValueExp.java -- Represents attributes to be passed to queries.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
/**
* Represents an attribute value being used as an argument
* to a relational constraint.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class AttributeValueExp
implements ValueExp
{
/**
* Compatible with JDK 1.5
*/
private static final long serialVersionUID = -7768025046539163385L;
/**
* The name of the attribute.
*/
private String attr;
/**
* Constructs a new {@link AttributeValueExp}.
*
* @deprecated An instance created with a <code>null</code>
* attribute name can not be used in a query.
*/
@Deprecated public AttributeValueExp()
{
}
/**
* Constructs a new {@link AttributeValueExp} using the
* specified attribute.
*
* @param attr the name of the attribute whose value
* will be used for this expression.
*/
public AttributeValueExp(String attr)
{
this.attr = attr;
}
/**
* Applies the {@link AttributeValueExp} to the specified
* management bean by obtaining the attribute value from
* the {@link MBeanServer} and using it to create a
* {@link StringValueExp}.
*
* @param name the {@link ObjectName} of the bean to obtain
* the value from.
* @return a {@link StringValueExp} containing the result.
* @throws BadStringOperationException if an invalid string
* operation is used by
* the value expression.
* @throws BadBinaryOpValueExpException if an invalid expression
* is used by the value expression.
* @throws BadAttributeValueExpException if an invalid attribute
* is used by the value expression.
* @throws InvalidApplicationException if the value expression is applied
* to the wrong type of bean.
*/
public ValueExp apply(ObjectName name)
throws BadStringOperationException, BadBinaryOpValueExpException,
BadAttributeValueExpException, InvalidApplicationException
{
Object val = getAttribute(name);
if (val == null || !(val instanceof String))
throw new BadAttributeValueExpException(val);
return new StringValueExp((String) val);
}
/**
* Returns the value of the attribute by calling the
* {@link MBeanServer#getAttribute(ObjectName)} method of
* the server returned by {@link QueryEval#getMBeanServer()}.
* If an exception occurs, <code>null</code> is returned.
*
* @param name the {@link ObjectName} of the bean to obtain
* the value from.
* @return a {@link StringValueExp} containing the result.
*/
protected Object getAttribute(ObjectName name)
{
try
{
return QueryEval.getMBeanServer().getAttribute(name, attr);
}
catch (NullPointerException e)
{
return null;
}
catch (MBeanException e)
{
return null;
}
catch (AttributeNotFoundException e)
{
return null;
}
catch (InstanceNotFoundException e)
{
return null;
}
catch (ReflectionException e)
{
return null;
}
}
/**
* Returns the attribute name.
*
* @return the attribute name.
*/
public String getAttributeName()
{
return attr;
}
/**
* Sets the {@link MBeanServer} on which the query
* will be performed.
*
* @param server the new server.
*/
public void setMBeanServer(MBeanServer server)
{
/* This seems to do nothing any more */
}
/**
* Returns the attribute name, quoted.
*
* @return the quoted attribute name.
*/
public String toString()
{
return "'" + attr + "'";
}
}

View file

@ -0,0 +1,148 @@
/* DefaultLoaderRepository.java -- Manages class loaders for the servers.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import java.util.List;
/**
* Maintains a list of the {@link ClassLoader} instances
* registered with the management servers, allowing it
* to be used to load classes. In early versions of the
* JMX API, this class represented a shared repository for
* the classloaders of all management servers. The management
* of classloaders is now decentralised and this class is
* deprecated. The old behaviour is emulated by consulting
* the {@link MBeanServer#getClassLoaderRepository()} method
* of all the servers obtained from
* {@link MBeanServerFactory#findMBeanServer(String)}. Use of
* this class should be avoided in new code.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
* @deprecated Use {@link MBeanServer#getClassLoaderRepository()}
* instead.
*/
@Deprecated public class DefaultLoaderRepository
{
/**
* Attempts to load the given class using class loaders
* supplied by the repository of each {@link MBeanServer}.
* The {@link ClassLoader#loadClass(String)}
* method of each class loader is called. If the method
* returns successfully, then the returned {@link Class} instance
* is returned. If a {@link ClassNotFoundException} is thrown,
* then the next loader is tried. Any other exception thrown
* by the method is passed back to the caller. This method
* throws a {@link ClassNotFoundException} itself if all the
* class loaders listed prove fruitless.
*
* @param name the name of the class to load.
* @return the loaded class.
* @throws ClassNotFoundException if all the class loaders fail
* to load the class.
*/
public static Class loadClass(String name)
throws ClassNotFoundException
{
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
for (MBeanServer server : servers)
{
try
{
return server.getClassLoaderRepository().loadClass(name);
}
catch (ClassNotFoundException e)
{
/* Ignored; try the next server. */
}
}
throw new ClassNotFoundException("The class loaders of all registered " +
"servers failed to load the class, " +
name);
}
/**
* <p>
* Attempts to load the given class using class loaders
* supplied by the repository of each {@link MBeanServer}.
* The {@link ClassLoader#loadClass(String)}
* method of each class loader is called. If the method
* returns successfully, then the returned {@link Class} instance
* is returned. If a {@link ClassNotFoundException} is thrown,
* then the next loader is tried. Any other exception thrown
* by the method is passed back to the caller. This method
* throws a {@link ClassNotFoundException} itself if all the
* class loaders listed prove fruitless.
* </p>
* <p>
* Note that this method may deadlock if called simultaneously
* by two class loaders in the list.
* {@link loadClassBefore(ClassLoader, String)} should be used
* in preference to this method to avoid this.
* </p>
*
* @param exclude the class loader to exclude, or <code>null</code>
* to obtain the same behaviour as {@link #loadClass(String)}.
* @param name the name of the class to load.
* @return the loaded class.
* @throws ClassNotFoundException if all the class loaders fail
* to load the class.
*/
public static Class loadClassWithout(ClassLoader exclude, String name)
throws ClassNotFoundException
{
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
for (MBeanServer server : servers)
{
try
{
return server.getClassLoaderRepository().loadClassWithout(exclude,
name);
}
catch (ClassNotFoundException e)
{
/* Ignored; try the next server. */
}
}
throw new ClassNotFoundException("The class loaders of all registered " +
"servers failed to load the class, " +
name);
}
}

View file

@ -0,0 +1,392 @@
/* Descriptor.java -- Metadata container.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import java.io.Serializable;
/**
* <p>
* Provides metadata for a management element as a series
* of fields, formed from name-value pairs. Descriptors
* are usually attached to one of the <code>Info</code>
* classes, such as {@link MBeanAttributeInfo}.
* </p>
* <p>
* Field names are not case-sensitive, but are case-preserving
* (in that the same use of case will be returned by
* {@link #getFields()} and {@link #getFieldNames()}).
* The type of the value should match the type returned
* by the <code>getType()</code> method of the associated
* <code>Info</code> object. In the case of {@link MXBean}s,
* this should be the mapped type returned by the mapping rules.
* </p>
* <p>
* The contents of a descriptor may be immutable, in which
* case, attempts to change the contents of the descriptor
* will cause an exception to be thrown. Immutable descriptors
* are usually instances or subclasses of {@link ImmutableDescriptor},
* while mutable descriptors are usually instances or subclasses
* of {@link javax.management.modelmbean.DescriptorSupport}.
* </p>
* <p>
* A series of field names are predefined, but additional
* ones can be added as needed. Predefined names never include
* a period ('.'), and so additional names may safely avoid
* conflicts by including this character. It is recommended that
* additional names make use of the same syntax as Java package
* names e.g. <code>gnu.classpath.ImportantMetadata</code>.
* </p>
* <p>
* The predefined names are as follows:
* </p>
* <table>
* <th>
* <td>Name</td><td>Type</td><td>Used In</td><td>Meaning</td>
* </th>
* <tr>
* <td>defaultValue</td><td>Object</td><td>{@link MBeanAttributeInfo},
* {@link MBeanParameterInfo}</td><td>Default value for an attribute
* or parameter.</td>
* </tr>
* <tr>
* <td>deprecated</td><td>String</td><td>Any</td><td>The annotated element
* has been deprecated. Conventially, the field's value takes the form
* of the version in which the element was deprecated, followed by an
* explaination.</td>
* </tr>
* <tr>
* <td>descriptionResourceBundleBaseName</td><td>String</td><td>Any</td>
* <td>The base name for the bundle in which the <code>descriptionResourceKey</code>
* can be found.</td>
* </tr>
* <tr>
* <td>descriptionResourceKey</td><td>String</td><td>Any</td>
* <td>The name of the resource key which contains a localized description of
* this element.</td>
* </tr>
* <tr>
* <td>enabled</td><td>String</td><td>{@link MBeanAttributeInfo},
* {@link MBeanNotificationInfo}, {@link MBeanOperationInfo}</td>
* <td>Specifies whether the annotated element is currently enabled or
* not, via a value of either <code>"true"</code> or <code>"false"</code>.
* </tr>
* <tr>
* <td>immutableInfo</td><td>String</td><td>{@link MBeanInfo}</td>
* <td>If the value of this field is <code>"true"</code>, this means that
* the annotated element will not change and thus may be cached.</td>
* </tr>
* <tr>
* <td>infoTimeout</td><td>String or Long</td><td>{@link MBeanInfo}</td>
* <td>If this field is present, and non-zero, it will contain a value
* in milliseconds for which the value of the annotated element will
* remain unchanged, allowing it to be safely cached for that period.</td>
* </tr>
* <tr>
* <td>interfaceClassName</td><td>String</td><td>{@link MBeanInfo}</td>
* <td>The Java interface name associated with the bean, as returned
* by {@link Class#getName()}.</td>
* </tr>
* <tr>
* <td>legalValues</td><td>Set<?></td><td>{@link MBeanAttributeInfo},
* {@link MBeanParameterInfo}</td><td>Legal values for an attribute
* or parameter.</td>
* </tr>
* <tr>
* <td>maxValue</td><td>Object</td><td><td>{@link MBeanAttributeInfo},
* {@link MBeanParameterInfo}</td><td>Maximum legal value for an attribute
* or parameter.</td>
* </tr>
* <tr>
* <td>metricType</td><td>String</td><td>{@link MBeanAttributeInfo},
* {@link MBeanOperationInfo}</td><td>Specifies the type of metric represented
* by the annotated element. This will be either <code>"counter"</code>
* (an increasing value, which will only be reset and never decrease)
* or <code>"gauge"</code> (an increasing and decreasing value).</td>
* </tr>
* <tr>
* <td>minValue</td><td>Object</td><td>{@link MBeanAttributeInfo},
* {@link MBeanParameterInfo}</td><td>Minimum legal value for an attribute
* or parameter.</td>
* </tr>
* <tr>
* <td>mxbean</td><td>String</td><td>{@link MBeanInfo}</td>
* <td>Specifies whether the annotated element is an {@link MXBean} or
* not, via a value of either <code>"true"</code> or <code>"false"</code>.
* </tr>
* <tr>
* <td>openType</td><td>{@link javax.management.openmbean.OpenType}</td>
* <td>{@link MBeanAttributeInfo}, {@link MBeanOperationInfo}</td>,
* {@link MBeanNotificationInfo}, {@link MBeanParameterInfo}</td>
* <td>Specifies the open type of the attribute or parameter, the return
* value of the operation or the user data of the notification respectively.
* This is present on <code>Open*Info</code> instances and for {@link MXBean}s.</td>
* <tr>
* <td>originalType</td><td>String</td><td>{@link MBeanAttributeInfo},
* {@link MBeanOperationInfo}, {@link MBeanParameterInfo}</td>
* <td>The original Java type of an element which has been converted
* to another type according to the {@link MXBean} typing rules.
* For example, {@link java.lang.management.MemoryType} becomes a
* String after conversion. This field would contain
* <code>"java.lang.management.MemoryType"</code> to represent the
* earlier type of an element with the converted type.</td>
* </tr>
* <tr>
* <td>severity</td><td>Integer or String</td>
* <td>{@link MBeanNotificationInfo}</td><td>Represents the severity
* of the notification, ranging from 1 (most severe) to 6 (least
* severe), with 0 representing unknown severity.</td>
* </tr>
* <tr>
* <td>since</td><td>String</td><td>Any</td>
* <td>The version in which this field was introduced.</td>
* </tr>
* <tr>
* <td>units</td><td>String</td><td>{@link MBeanAttributeInfo},
* {@link MBeanOperationInfo}, {@link MBeanParameterInfo}</td>
* <td>The units used by the value of an attribute or parameter,
* or the return value of an operation, such as <code>"bytes"</code>,
* <code>"milliseconds"</code> or <code>"kilogrammes"</code>.
* </tr>
* </table>
* <p>Some names are also defined as part of the Model MBeans package.
* See {@link javax.management.modelmbean.ModelMBeanInfo}.</p>
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public interface Descriptor
extends Serializable, Cloneable
{
/**
* Returns a clone of this descriptor, which can then be modified
* independently of this descriptor. If the descriptor is
* immutable, it is sufficient to return this instance.
*
* @return a clone of this descriptor.
* @throws RuntimeOperationsException if creation of the new
* descriptor fails for any
* reason.
*/
Object clone()
throws RuntimeOperationsException;
/**
* <p>
* Returns true if this descriptor is equivalent to the
* supplied object. This is true if the following holds:
* </p>
* <ul>
* <li>The given object is also a {@link Descriptor}.</li>
* <li>Has the same field names, independent of case.</li>
* <li>Has the same values, based on the following:
* <ul>
* <li>If one value is <code>null</code>, the other must be.</li>
* <li>If one value is a primitive array, the other must be a
* primitive array of the same type with the same elements.</li>
* <li>If one value is an {@link Object} array, the other
* must be and {@link java.util.Arrays#deepEquals(Object[],Object[])}
* must return true.</li>
* <li>Otherwise, {@link Object#equals(Object)} must return true.</li>
* </ul>
*
* @param obj the object to compare according to the above.
* @return true if the above holds.
* @see Object#equals(Object)
* @see Object#hashCode()
* @since 1.6
*/
boolean equals(Object obj);
/**
* Returns the field names of the descriptor. If the
* descriptor is empty, an empty array is returned.
*
* @return the field names as an array of Strings.
*/
String[] getFieldNames();
/**
* <p>
* Returns all the field name and value pairs, in the
* form <code>name=value</code>. The value is converted
* to a String as follows:
* </p>
* <ul>
* <li>If the value is a String, it is used as is.</li>
* <li>If the value is <code>null</code>, the printed
* value will be empty.</li>
* <li>Otherwise, the value will be converted to a
* String using its {@link Object#toString()} method,
* and included as <code>"(" + string + ")"</code>.</li>
* </ul>
* <p>If the descriptor is empty, an empty array is returned.</p>
*
* @return the field names and values as an array of Strings.
* @see #setFields(String[],Object[])
*/
String[] getFields();
/**
* Returns the value of the specified field, or <code>null</code>
* if no value is present for the given field name.
*
* @param name the field name.
* @return the value of the field, or <code>null</code> if there
* is no value present.
* @throws RuntimeOperationsException if the field name is illegal.
*/
Object getFieldValue(String name);
/**
* Returns the values corresponding to the fields named in
* the specified array, in the same order. If an empty
* array is supplied, an empty array is returned. A value
* of <code>null</code> leads to behaviour equivalent to
* {@link #getFields()}. Field values are obtained as specified
* in {@link #getFieldValue(String)}, with <code>null</code>
* being returned if the field is not present. This applies
* even if the given field name is <code>null</code> or
* the empty string.
*
* @param names an array of field names whose values should
* be returned.
* @return the values of the specified fields.
* @see #getFields()
* @see #getFieldValue(String)
*/
Object[] getFieldValues(String... names);
/**
* <p>
* Returns the hash code of the descriptor. The hashcode
* is computed as the sum of the hashcodes for each field,
* which in turn is calculated as the sum of
* the hashcode of the name, <code>n</code>, computed
* using <code>n.toLowerCase().hashCode()</code>, and the
* hashcode of the value, <code>v</code>, computed
* using:
* </p>
* <ul>
* <li>If <code>v</code> is <code>null</code>, then the
* hash code is 0.</li>
* <li>If <code>v</code> is a primitive array, then the
* hash code is computed using the appropriate method
* from {@link java.util.Arrays}.</li>
* <li>If <code>v</code> is an {@link java.lang.Object}
* array, then the hash code is computed using the
* {@link java.util.Arrays#deepHashCode(Object[])} method.</li>
* <li>Otherwise, the hashcode is equal to
* <code>v.hashCode()</code>.
* </ul>
*
* @return a hashcode for this descriptor.
* @since 1.6
* @see Object#equals(Object)
* @see Object#hashCode()
*/
int hashCode();
/**
* Returns true if all the fields have legal values, given
* their names. Validity is determined by the implementation.
*
* @return true if the values are legal.
* @throws RuntimeOperationsException if the validity check
* fails for some reason.
*/
boolean isValid()
throws RuntimeOperationsException;
/**
* Removes a field from the descriptor. If the field name
* is illegal or not found, this method fails silently.
*
* @param name the name of the field to remove.
* @throws RuntimeOperationsException if the field exists
* and the descriptor is
* immutable. This wraps
* an {@link UnsupportedOperationException}.
*/
void removeField(String name);
/**
* Attempts to set the specified field to the supplied
* value. If the field does not exist, it will be created.
* If the field value given is invalid, then an exception will
* be thrown. Validity is determined by the implementation
* of the descriptor.
*
* @param name the field to set. Can not be <code>null</code>
* or empty.
* @param value the value to use, the validity of which is
* determined by the implementation.
* @throws RuntimeOperationsException if the name or value is
* illegal (wrapping a
* {@link IllegalArgumentException})
* or if the descriptor is
* immutable (wrapping a
* {@link UnsupportedOperationException}.
*/
void setField(String name, Object value)
throws RuntimeOperationsException;
/**
* Sets the field named in the first array to the corresponding
* value specified in the second. The array sizes must match.
* Empty arrays have no effect. An invalid value will cause
* an exception to be thrown.
*
* @param names the names of the fields to change. Neither
* the array or its elements may be <code>null</code>.
* @param values the values to use. The array must not be
* <code>null</code>. The value of the elements
* depends on the validity constraints of the
* implementation.
* @throws RuntimeOperationsException if the arrays differ in
* length, or a name or value is
* illegal (wrapping a
* {@link IllegalArgumentException})
* or if the descriptor is
* immutable (wrapping a
* {@link UnsupportedOperationException}.
* @see #setField(String,Object)
*/
void setFields(String[] names, Object[] values);
}

View file

@ -0,0 +1,65 @@
/* DescriptorAccess.java -- Allows a descriptor to be changed.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
/**
* Allows the descriptor of a management element
* to be changed.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public interface DescriptorAccess
extends DescriptorRead
{
/**
* Replaces the descriptor of this management element
* with the one specified. If the specified descriptor
* is <code>null</code>, the descriptor of the element
* will be returned to its default, which must at least
* contain a name and type. If the specified descriptor
* is invalid for this management element, an exception
* is thrown.
*
* @param descriptor the new descriptor to use.
* @see DescriptorRead#getDescriptor()
*/
void setDescriptor(Descriptor descriptor);
}

View file

@ -0,0 +1,59 @@
/* DescriptorRead.java -- Allows a descriptor to be read.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
/**
* Provides read access to the descriptor of
* a management element.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.6
*/
public interface DescriptorRead
{
/**
* Returns a copy of the descriptor for this management
* element. The return value is never <code>null</code>,
* but the returned descriptor may be empty.
*
* @return the descriptor for this management element.
*/
Descriptor getDescriptor();
}

View file

@ -0,0 +1,342 @@
/* JMX.java -- Static methods pertaining to the management API.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import java.lang.reflect.Proxy;
/**
* Common static methods pertaining to the management
* API. There are no instances of this class.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.6
*/
public class JMX
{
/**
* The name of the defaultValue field.
*/
public static final String DEFAULT_VALUE_FIELD = "defaultValue";
/**
* The name of the immutableInfo field.
*/
public static final String IMMUTABLE_INFO_FIELD = "immutableInfo";
/**
* The name of the interfaceClassName field.
*/
public static final String INTERFACE_CLASS_NAME_FIELD = "interfaceClassName";
/**
* The name of the legalValues field.
*/
public static final String LEGAL_VALUES_FIELD = "legalValues";
/**
* The name of the maxValue field.
*/
public static final String MAX_VALUE_FIELD = "maxValue";
/**
* The name of the minValue field.
*/
public static final String MIN_VALUE_FIELD = "minValue";
/**
* The name of the mxbean field.
*/
public static final String MXBEAN_FIELD = "mxbean";
/**
* The name of the openType field.
*/
public static final String OPEN_TYPE_FIELD = "openType";
/**
* The name of the originalType field.
*/
public static final String ORIGINAL_TYPE_FIELD = "originalType";
/**
* Prevent instance creation.
*/
private JMX()
{
}
/**
* <p>
* Returns true if the given class represents an {@link MXBean}
* interface. An interface is an {@link MXBean interface} if:
* </p>
* <ul>
* <li>It is annotated with {@code @MXBean} or
* {@code @MXBean(true)}</li>.
* <li>Its name ends in {@code "MXBean"} and it does not
* have an {@link MXBean} annotation.</li>
* </ul>
*
* @param iface the interface class that is to be checked
* for {@link MXBean} status.
* @return true if the interface represents an {@link MXBean}.
* @throws NullPointerException if {@code iface} is {@code null}.
*/
public static boolean isMXBeanInterface(Class<?> iface)
{
MXBean annotation = iface.getAnnotation(MXBean.class);
if (annotation != null)
return annotation.value();
return iface.getName().endsWith("MXBean");
}
/**
* <p>
* Returns a proxy for a standard management bean, using
* the specified connection to access the named implementation.
* To create a proxy for the bean, {@code SomethingMBean}, a call to
* {@code JMX.newMBeanProxy(server, name, SomethingMBean.class)}
* is made, where {@code server} is a local or remote management
* server, and {@code name} is the registered {@link ObjectName}
* of the implementation of {@code SomethingMBean} to use.
* </p>
* <p>
* The proxy redirects calls to the methods of the interface,
* {@link SomethingMBean}, to the appropriate methods of the
* management server. If {@link SomethingMBean} is specified
* as follows:
* </p>
* <pre>
* public interface SomethingMBean
* {
* String getName();
* void setName(String name);
* void doStuff();
* }
* </pre>
* <p>
* The proxy created above will provide these three methods
* using an instance of {@link MBeanServerInvocationHandler}.
* The two methods, {@code getName} and {@code setName} define
* an attribute, {@code Name}, so a call to {@code getName()}
* will return the value of {@code server.getAttribute(name,
* "Name")}, while {@code setName(newName)} will result in a
* call to {@code server.setAttribute(name, new Attribute("Name",
* newName))}. Finally, {@code doStuff()}, as an operation,
* will cause the proxy to call {@link MBeanServer#invoke(ObjectName,
* String, Object[], String[])} as
* {@code server.invoke(name, "doStuff", null, null)}.
* </p>
* <p>
* Calling this method is equivalent to calling
* {@link #newMBeanProxy(MBeanServerConnection, ObjectName, Class,
* boolean)}.
* </p>
*
* @param conn the server connection over which to forward calls to
* the bean.
* @param name the registered name of the bean to use to implement
* the given interface.
* @param iface the interface to provide a proxy for.
* @return a proxy implementing the specified interface using calls
* to the methods of the bean registered with the supplied
* server using the given name.
* @see #newMBeanProxy(MBeanServerConnection, ObjectName, Class,
* boolean)
*/
public static <T> T newMBeanProxy(MBeanServerConnection conn,
ObjectName name, Class<T> iface)
{
return newMBeanProxy(conn, name, iface, false);
}
/**
* Returns a proxy for a standard management bean, using
* the specified connection to access the named implementation,
* as with {@link #newMBeanProxy(MBeanServerConnection, ObjectName,
* Class)}. In addition, the proxy returned by this method will
* also implement {@link NotificationEmitter} if {@code bcast} is
* true, under the assumption that the implementation referenced by
* {@code name} implements this interface. Calls to the methods of
* {@link NotificationEmitter} will be forwarded to the bean
* implementation via the appropriate server methods.
*
* @param conn the server connection over which to forward calls to
* the bean.
* @param name the registered name of the bean to use to implement
* the given interface.
* @param iface the interface to provide a proxy for.
* @param bcast true if the proxy should implement
* {@link NotificationEmitter}.
* @return a proxy implementing the specified interface using calls
* to the methods of the bean registered with the supplied
* server using the given name.
* @see #newMBeanProxy(MBeanServerConnection, ObjectName, Class)
*/
public static <T> T newMBeanProxy(MBeanServerConnection conn,
ObjectName name, Class<T> iface,
boolean bcast)
{
return MBeanServerInvocationHandler.newProxyInstance(conn, name,
iface, bcast);
}
/**
* <p>
* Returns a proxy for a {@link MXBean}, using the specified
* connection to access the named implementation.
* To create a proxy for the bean, {@code SomethingMXBean}, a call to
* {@code JMX.newMXBeanProxy(server, name, SomethingMXBean.class)}
* is made, where {@code server} is a local or remote management
* server, and {@code name} is the registered {@link ObjectName}
* of the implementation of {@code SomethingMBean} to use.
* </p>
* <p>
* The proxy redirects calls to the methods of the interface,
* {@link SomethingMXBean}, to the appropriate methods of the
* management server with appropriate conversion between
* Java and open types, according to the MXBean rules. If
* {@link SomethingMXBean} is specified as follows:
* </p>
* <pre>
* public interface SomethingMXBean
* {
* String getName();
* void setName(String name);
* List<Double> getStatistics();
* void setStatistics(List<Double> statistics);
* List<Double> getNamedStatistics(String, Map<String,Integer>);
* }
* </pre>
* <p>
* The proxy created above will provide these five methods
* using an instance of {@link MBeanServerInvocationHandler}.
* The two methods, {@code getName} and {@code setName} define
* an attribute, {@code Name}, so a call to {@code getName()}
* will return the value of {@code server.getAttribute(name,
* "Name")}, while {@code setName(newName)} will result in a
* call to {@code server.setAttribute(name, new Attribute("Name",
* newName))}. As this uses a simple type, {@link String}, no
* conversion is necessary.
* </p>
* <p>
* The two methods, {@code getStatistics} and {@code setStatistics}
* similarly define another attribute, {@code Statistics}. Calling
* {@code getStatistics()} will cause a call to the server to be
* made as before, {@code server.getAttribute(name, "Statistics")}.
* However, the type of the return value from this call will be
* an array of {@link Double} objects, as per the {@link MXBean}
* rules. The proxy converts this back in to a {@link java.util.List}
* of {@link Double} objects before returning it.
* </p>
* <p>
* The same process is applied in reverse for
* {@code setStatistics(newStats)}. The list is converted into
* an appropriate array before the call to
* {@link MBeanServerConnection#setAttribute(ObjectName, Attribute)}
* is made. Finally, a call to {@code getNamedStatistics} will require
* both a Java to open type conversion on the arguments, and then
* an open type to Java conversion of the return value. Thus, a proxy
* enables an {@link MXBean} to be used in cases where the appropriate
* Java types are available and the user wishes to access the bean
* using the types directly defined in its interface, just as with
* standard management beans.
* </p>
* <p>
* Calling this method is equivalent to calling
* {@link #newMXBeanProxy(MBeanServerConnection, ObjectName, Class,
* boolean)}.
* </p>
*
* @param conn the server connection over which to forward calls to
* the bean.
* @param name the registered name of the bean to use to implement
* the given interface.
* @param iface the interface to provide a proxy for.
* @return a proxy implementing the specified interface using calls
* to the methods of the bean registered with the supplied
* server using the given name.
* @see #newMXBeanProxy(MBeanServerConnection, ObjectName, Class,
* boolean)
*/
public static <T> T newMXBeanProxy(MBeanServerConnection conn,
ObjectName name, Class<T> iface)
{
return newMXBeanProxy(conn, name, iface, false);
}
/**
* Returns a proxy for a {@link MXBean}, using
* the specified connection to access the named implementation,
* as with {@link #newMXBeanProxy(MBeanServerConnection, ObjectName,
* Class)}. In addition, the proxy returned by this method will
* also implement {@link NotificationEmitter} if {@code bcast} is
* true, under the assumption that the implementation referenced by
* {@code name} implements this interface. Calls to the methods of
* {@link NotificationEmitter} will be forwarded to the bean
* implementation via the appropriate server methods.
*
* @param conn the server connection over which to forward calls to
* the bean.
* @param name the registered name of the bean to use to implement
* the given interface.
* @param iface the interface to provide a proxy for.
* @param bcast true if the proxy should implement
* {@link NotificationEmitter}.
* @return a proxy implementing the specified interface using calls
* to the methods of the bean registered with the supplied
* server using the given name.
* @see #newMXBeanProxy(MBeanServerConnection, ObjectName, Class)
*/
public static <T> T newMXBeanProxy(MBeanServerConnection conn,
ObjectName name, Class<T> iface,
boolean bcast)
{
if (bcast)
return (T) Proxy.newProxyInstance(iface.getClassLoader(),
new Class[] { iface,
NotificationEmitter.class },
new MBeanServerInvocationHandler(conn,name,true));
else
return (T) Proxy.newProxyInstance(iface.getClassLoader(),
new Class[] { iface },
new MBeanServerInvocationHandler(conn,name,true));
}
}

View file

@ -54,6 +54,11 @@ public class MBeanAttributeInfo
implements Cloneable
{
/**
* Compatible with JDK 1.6
*/
private static final long serialVersionUID = 8644704819898565848L;
/**
* The type of the attribute.
*

View file

@ -37,6 +37,8 @@ exception statement from your version. */
package javax.management;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
@ -183,4 +185,17 @@ public class MBeanFeatureInfo
return string;
}
/**
* Serialize the {@link MBeanFeatureInfo}.
*
* @param out the output stream to write to.
* @throws IOException if an I/O error occurs.
*/
private void writeObject(ObjectOutputStream out)
throws IOException
{
out.defaultWriteObject();
/* FIXME: Handle extra 1.6 descriptor stuff */
}
}

View file

@ -0,0 +1,400 @@
/* MBeanServerInvocationHandler.java -- Provides a proxy for a bean.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import gnu.javax.management.Translator;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* <p>
* Provides a proxy for a management bean. The methods
* of the given interface are fulfilled by redirecting the
* calls over an {@link MBeanServerConnection} to the bean
* specified by the supplied {@link ObjectName}.
* </p>
* <p>
* The {@link java.lang.reflect.InvocationHandler} also makes
* provision for {@link MXBean}s by providing type conversion
* according to the rules defined for these beans. The input
* parameters are converted to their equivalent open type before
* calling the method, and then the return value is converted
* back from its open type to the appropriate Java type. For
* example, a method that takes an {@link Enum} as input and
* returns a {@link java.util.List} will have the input value
* converted from an {@link Enum} to a {@link String}, while
* the return value will be converted from its return type
* (an appropriately typed array) to a {@link java.util.List}.
* </p>
* <p>
* The proxy has special cases for the {@link Object#equals(Object)},
* {@link Object#hashCode()} and {@link Object#toString()} methods.
* Unless they are specified explictly by the interface, the
* following behaviour is provided for these methods by the proxy:
* </p>
* <ul>
* <li><code>equals(Object)</code> returns true if the other object
* is an {@link MBeanServerInvocationHandler} with the same
* {@link MBeanServerConnection} and {@link ObjectName}. If an
* interface class was specified on construction for one of the
* proxies, then the same class must have also been specified
* for the other.</li>
* <li><code>hashCode()</code> returns the same value for
* equivalent proxies.</li>
* <li><code>toString()</code> returns a textual representation
* of the proxy.</li>
* </ul>
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class MBeanServerInvocationHandler
implements InvocationHandler
{
/**
* The connection used to make the calls.
*/
private MBeanServerConnection conn;
/**
* The name of the bean to perform operations on.
*/
private ObjectName name;
/**
* True if this proxy is for an {@link MXBean}.
*/
private boolean mxBean;
/**
* The interface class associated with the bean.
*/
private Class<?> iface;
/**
* Constructs a new {@link MBeanServerInvocationHandler}
* which forwards methods to the supplied bean via the
* given {@link MBeanServerConnection}. This constructor
* is used in preference to
* {@link JMX#newMBeanProxy(MBeanServerConnection, ObjectName,
* Class<T>)} if you wish to make your own call to
* {@link java.lang.reflect.Proxy#newInstance(ClassLoader,
* Class[], java.lang.reflect.InvocationHandler)} with
* a different {@link ClassLoader}. Calling this constructor
* is equivalent to <code>MBeanServerInvocationHandler(conn,
* name, false)</code>. The other constructor should be used
* instead if the bean being proxied is an {@link MXBean}.
*
* @param conn the connection through which methods will
* be forwarded to the bean.
* @param name the name of the bean to use to provide the
* actual calls.
*/
public MBeanServerInvocationHandler(MBeanServerConnection conn,
ObjectName name)
{
this(conn, name, false);
}
/**
* Constructs a new {@link MBeanServerInvocationHandler}
* which forwards methods to the supplied bean via the
* given {@link MBeanServerConnection}. This constructor
* is used in preference to
* {@link JMX#newMBeanProxy(MBeanServerConnection, ObjectName,
* Class<T>)} if you wish to make your own call to
* {@link java.lang.reflect.Proxy#newInstance(ClassLoader,
* Class[], java.lang.reflect.InvocationHandler)} with
* a different {@link ClassLoader}.
*
* @param conn the connection through which methods will
* be forwarded to the bean.
* @param name the name of the bean to use to provide the
* actual calls.
* @param mxBean true if the bean being proxied is an
* {@link MXBean}.
* @since 1.6
*/
public MBeanServerInvocationHandler(MBeanServerConnection conn,
ObjectName name, boolean mxBean)
{
this.conn = conn;
this.name = name;
this.mxBean = mxBean;
}
/**
* Returns the connection through which the calls to the bean
* will be made.
*
* @return the connection being used to forward the calls to
* the bean.
* @since 1.6
*/
public MBeanServerConnection getMBeanServerConnection()
{
return conn;
}
/**
* Returns the name of the bean to which method calls are made.
*
* @return the bean which provides the actual method calls.
* @since 1.6
*/
public ObjectName getObjectName()
{
return name;
}
/**
* Called by the proxy class whenever a method is called. The method
* is emulated by retrieving an attribute from, setting an attribute on
* or invoking a method on the server connection as required. Translation
* between the Java data types supplied as arguments to the open types used
* by the bean is provided, as well as translation of the return value back
* in to the appropriate Java type if the bean is an {@link MXBean}.
*
* @param proxy the proxy on which the method was called.
* @param method the method which was called.
* @param args the arguments supplied to the method.
* @return the return value from the method.
* @throws Throwable if an exception is thrown in performing the
* method emulation.
*/
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
String mName = method.getName();
Class proxyClass = proxy.getClass();
if (mName.equals("toString"))
{
if (inInterface(mName, proxyClass))
return conn.invoke(name,mName,null,null);
else
return proxyClass.getName() + "[name=" + name
+ ", conn=" + conn + "]";
}
if (mName.equals("hashCode"))
{
if (inInterface(mName, proxyClass))
return conn.invoke(name,mName,null,null);
else
return conn.hashCode() + name.hashCode()
+ (iface == null ? 0 : iface.hashCode());
}
if (mName.equals("equals"))
{
if (inInterface(mName, proxyClass, Object.class))
return conn.invoke(name,mName,new Object[]{args[0]},
new String[]{"java.lang.Object"});
else
{
if (args[0].getClass() != proxy.getClass())
return false;
InvocationHandler ih = Proxy.getInvocationHandler(args[0]);
if (ih instanceof MBeanServerInvocationHandler)
{
MBeanServerInvocationHandler h =
(MBeanServerInvocationHandler) ih;
return conn.equals(h.getMBeanServerConnection())
&& name.equals(h.getObjectName())
&& (iface == null ? h.iface == null
: iface.equals(h.iface));
}
return false;
}
}
if (NotificationEmitter.class.isAssignableFrom(proxyClass))
{
if (mName.equals("addNotificationListener"))
{
conn.addNotificationListener(name,
(NotificationListener) args[0],
(NotificationFilter) args[1],
args[2]);
return null;
}
if (mName.equals("getNotificationInfo"))
return conn.getMBeanInfo(name).getNotifications();
if (mName.equals("removeNotificationListener"))
{
if (args.length == 1)
conn.removeNotificationListener(name,
(NotificationListener)
args[0]);
else
conn.removeNotificationListener(name,
(NotificationListener)
args[0],
(NotificationFilter)
args[1], args[2]);
return null;
}
}
String[] sigs;
if (args == null)
sigs = null;
else
{
sigs = new String[args.length];
for (int a = 0; a < args.length; ++a)
sigs[a] = args[a].getClass().getName();
}
String attrib = null;
if (mName.startsWith("get"))
attrib = mName.substring(3);
else if (mName.startsWith("is"))
attrib = mName.substring(2);
if (attrib != null)
{
Object val = conn.getAttribute(name, attrib);
if (mxBean)
return Translator.toJava(val, method);
else
return val;
}
else if (mName.startsWith("set"))
{
Object arg;
if (mxBean)
arg = Translator.fromJava(args, method)[0];
else
arg = args[0];
conn.setAttribute(name, new Attribute(mName.substring(3), arg));
return null;
}
if (mxBean)
return Translator.toJava(conn.invoke(name, mName,
Translator.fromJava(args,method),
sigs), method);
else
return conn.invoke(name, mName, args, sigs);
}
/**
* Returns true if this is a proxy for an {@link MXBean}
* and conversions must be applied to input parameters
* and return types, according to the rules for such beans.
*
* @return true if this is a proxy for an {@link MXBean}.
* @since 1.6
*/
public boolean isMXBean()
{
return mxBean;
}
/**
* <p>
* Returns a proxy for the specified bean. A proxy object is created
* using <code>Proxy.newProxyInstance(iface.getClassLoader(),
* new Class[] { iface }, handler)</code>. The
* {@link javax.management.NotificationEmitter} class is included as the
* second element of the array if <code>broadcaster</code> is true.
* <code>handler</code> refers to the invocation handler which forwards
* calls to the connection, which is created by a call to
* <code>new MBeanServerInvocationHandler(conn, name)</code>.
* </p>
* <p>
* <strong>Note</strong>: use of the proxy may result in
* {@link java.io.IOException}s from the underlying
* {@link MBeanServerConnection}.
* As of 1.6, the use of {@link JMX#newMBeanProxy(MBeanServerConnection,
* ObjectName,Class)} and {@link JMX#newMBeanProxy(MBeanServerConnection,
* ObjectName,Class,boolean)} is preferred.
* </p>
*
* @param conn the server connection to use to access the bean.
* @param name the {@link javax.management.ObjectName} of the
* bean to provide a proxy for.
* @param iface the interface for the bean being proxied.
* @param broadcaster true if the proxy should implement
* {@link NotificationEmitter}.
* @return a proxy for the specified bean.
* @see JMX#newMBeanProxy(MBeanServerConnection,ObjectName,Class)
*/
public static <T> T newProxyInstance(MBeanServerConnection conn,
ObjectName name, Class<T> iface,
boolean broadcaster)
{
if (broadcaster)
return (T) Proxy.newProxyInstance(iface.getClassLoader(),
new Class[] { iface,
NotificationEmitter.class },
new MBeanServerInvocationHandler(conn,name));
else
return (T) Proxy.newProxyInstance(iface.getClassLoader(),
new Class[] { iface },
new MBeanServerInvocationHandler(conn,name));
}
/**
* Returns true if the specified method is specified
* by one of the proxy's interfaces.
*
* @param name the name of the method to search for.
* @param proxyClass the class of the proxy.
* @param args the arguments to the method.
* @return true if one of the interfaces specifies the
* given method.
*/
private boolean inInterface(String name, Class<?> proxyClass,
Class<?>... args)
{
for (Class<?> iface : proxyClass.getInterfaces())
{
try
{
iface.getMethod(name, args);
return true;
}
catch (NoSuchMethodException e)
{
/* Ignored; this interface doesn't specify
the method. */
}
}
return false;
}
}

View file

@ -0,0 +1,82 @@
/* MXBean.java - Marks a management bean interface as an MXBean.
Copyright (C) 2007 Free Software Foundation
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static java.lang.annotation.ElementType.TYPE;
/**
* <p>
* An annotation used to explictly mark an interface
* as defining (or not defining) an {@link MXBean}. By
* default, such beans are taken to be those whose interface
* has the suffix {@code "MXBean"}. The presence of this
* annotation overrides this intuition. The following
* interfaces would be classed as {@link MXBean}s:
* </p>
* <ul>
* <li>{@code public interface SomethingMXBean{}}</li>
* <li>{@code @MXBean public interface Someat{}}</li>
* <li>{@code @MXBean(true) public interface SomeatElse{}}</li>
* </ul>
* <p>The following would not:</p>
* <ul>
* <li>{@code public interface RandomInterface{}}</li>
* <li>{@code @MXBean(false) public interface SomethingMXBean{}}</li>
* </ul>
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.6
*/
@Documented @Retention(RUNTIME) @Target(TYPE)
public @interface MXBean
{
/**
* Returns true if the annotated interface
* is an {@link MXBean}.
*
* @return true if the interface is an {@link MXBean}.
*/
boolean value();
}

View file

@ -37,6 +37,9 @@ exception statement from your version. */
package javax.management;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;
import java.util.EventObject;
@ -65,6 +68,11 @@ public class Notification
extends EventObject
{
/**
* Compatible with JDK 1.6
*/
private static final long serialVersionUID = -7516092053498031989L;
/**
* The notification message.
*
@ -141,7 +149,7 @@ public class Notification
public Notification(String type, Object source, long sequenceNumber,
long timeStamp)
{
this(type, source, sequenceNumber, timeStamp, null);
this(type, source, sequenceNumber, timeStamp, "");
}
/**
@ -159,6 +167,7 @@ public class Notification
{
super(source);
this.type = type;
this.source = source;
this.sequenceNumber = sequenceNumber;
this.timeStamp = timeStamp;
this.message = message;
@ -310,5 +319,17 @@ public class Notification
+ "]";
}
/**
* Serialize the {@link Notification}.
*
* @param out the output stream to write to.
* @throws IOException if an I/O error occurs.
*/
private void writeObject(ObjectOutputStream out)
throws IOException
{
out.defaultWriteObject();
}
}

View file

@ -0,0 +1,390 @@
/* NotificationBroadcasterSupport.java -- Supporting implementation.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import gnu.javax.management.ListenerData;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
/**
* <p>
* Provides an implementation of the {@link NotificationEmitter}
* interface, which beans may utilise by extension. By default,
* a synchronous dispatch system is provided, whereby the
* {@link #handleNotification(NotificationListener, Notification,
* Object)} is called once per listener by
* {*@link #sendNotification(Notification)} before returning.
* Thus, unless the listener is remote, it will have received
* the notification before the method returns.
* This may be changed by overriding the <code>handleNotification</code>
* method, or by providing an {@link java.util.concurrent.Executor} to
* use. With the latter, the dispatch of a notification to a particular
* listener will form one task performed by the executor.
* </p>
* <p>
* Any exceptions thrown by the dispatch process will be caught, allowing
* other listeners to still receive the notification. However, any
* {@link Error}s that are thrown will be propogated to the caller of
* {@link #sendNotification(Notification)}.
* </p>
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class NotificationBroadcasterSupport
implements NotificationEmitter
{
/**
* The executor for dispatch, or
* <code>null</code> if this thread should
* handle dispatch itself.
*/
private Executor executor;
/**
* An array containing information on each
* notification, or <code>null</code> if an
* empty array should be returned by
* {@link #getNotificationInfo()}.
*/
private MBeanNotificationInfo[] info;
/**
* The list of listeners registered with
* this broadcaster.
*/
private final List<ListenerData> listeners =
new ArrayList<ListenerData>();
/**
* Constructs a {@link NotificationBroadcasterSupport} using
* the default synchronous dispatch model, where a single
* thread sends the notification to all listeners. This
* is equivalent to calling
* <code>NotificationBroadcasterSupport(null, null)</code>.
*/
public NotificationBroadcasterSupport()
{
this(null, null);
}
/**
* Constructs a {@link NotificationBroadcasterSupport} where
* the specified (@link java.util.concurrent.Executor} is used
* to perform each invocation of the
* {@link #handleNotification(NotificationListener, Notification,
* Object)} method. Filtering is performed beforehand, by this
* thread; only calls which have successfully passed through the
* filter are sent to the executor. This is equivalent to calling
* <code>NotificationBroadcasterSupport(executor, null)</code>.
*
* @param executor the executor to use for each call to
* <code>handleNotification()</code>.
* @since 1.6
*/
public NotificationBroadcasterSupport(Executor executor)
{
this(executor, null);
}
/**
* Constructs a {@link NotificationBroadcasterSupport} using
* the default synchronous dispatch model, where a single
* thread sends the notification to all listeners. The specified
* {@link MBeanNotificationInfo} array is used to provide
* information about the notifications on calls to
* {@link #getNotificationInfo()}, where a clone will be
* returned if the array is non-empty. This is equivalent to
* calling <code>NotificationBroadcasterSupport(null, info)</code>.
*
* @param info an array of {@link MBeanNotificationInfo} objects
* describing the notifications delivered by this
* broadcaster. This may be <code>null</code>, which
* is taken as being equivalent to an empty array.
*/
public NotificationBroadcasterSupport(MBeanNotificationInfo... info)
{
this(null, info);
}
/**
* Constructs a {@link NotificationBroadcasterSupport} where
* the specified (@link java.util.concurrent.Executor} is used
* to perform each invocation of the
* {@link #handleNotification(NotificationListener, Notification,
* Object)} method. Filtering is performed beforehand, by this
* thread; only calls which have successfully passed through the
* filter are sent to the executor. The specified
* {@link MBeanNotificationInfo} array is used to provide
* information about the notifications on calls to
* {@link #getNotificationInfo()}, where a clone will be
* returned if the array is non-empty.
*
* @param executor the executor to use for each call to
* <code>handleNotification()</code>.
* @param info an array of {@link MBeanNotificationInfo} objects
* describing the notifications delivered by this
* broadcaster. This may be <code>null</code>, which
* is taken as being equivalent to an empty array.
* @since 1.6
*/
public NotificationBroadcasterSupport(Executor executor,
MBeanNotificationInfo... info)
{
this.executor = executor;
this.info = info;
}
/**
* Registers the specified listener as a new recipient of
* notifications from this bean. If non-null, the filter
* argument will be used to select which notifications are
* delivered. The supplied object will also be passed to
* the recipient with each notification. This should not
* be modified by the broadcaster, but instead should be
* passed unmodified to the listener.
*
* @param listener the new listener, who will receive
* notifications from this broadcasting bean.
* @param filter a filter to determine which notifications are
* delivered to the listener, or <code>null</code>
* if no filtering is required.
* @param passback an object to be passed to the listener with
* each notification.
* @throws IllegalArgumentException if <code>listener</code> is
* <code>null</code>.
* @see #removeNotificationListener(NotificationListener)
*/
public void addNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object passback)
throws IllegalArgumentException
{
if (listener == null)
throw new IllegalArgumentException("Null listener added to bean.");
listeners.add(new ListenerData(listener, filter, passback));
}
/**
* Returns an array describing the notifications this
* bean may send to its registered listeners. Ideally, this
* array should be complete, but in some cases, this may
* not be possible. However, be aware that some listeners
* may expect this to be so.
*
* @return the array of possible notifications.
*/
public MBeanNotificationInfo[] getNotificationInfo()
{
if (info == null || info.length == 0)
return new MBeanNotificationInfo[0];
return (MBeanNotificationInfo[]) info.clone();
}
/**
* This method is called on a per-listener basis, either
* from this thread or the supplied executor, and may be
* overridden by subclasses which wish to change how
* notifications are delivered. The default
* implementation simply calls
* <code>listener.handleNotification(notif, passback)</code>.
*
* @param listener the listener to send the notification to.
* @param notif the notification to dispatch.
* @param passback the passback object of the listener.
*/
protected void handleNotification(NotificationListener listener,
Notification notif,
Object passback)
{
listener.handleNotification(notif, passback);
}
/**
* Removes the specified listener from the list of recipients
* of notifications from this bean. This includes all combinations
* of filters and passback objects registered for this listener.
* For more specific removal of listeners, see the subinterface
* {@link NotificationEmitter}.
*
* @param listener the listener to remove.
* @throws ListenerNotFoundException if the specified listener
* is not registered with this bean.
* @see #addNotificationListener(NotificationListener, NotificationFilter,
* java.lang.Object)
*/
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException
{
Iterator<ListenerData> it = listeners.iterator();
boolean foundOne = false;
while (it.hasNext())
{
if (it.next().getListener() == listener)
{
it.remove();
foundOne = true;
}
}
if (!foundOne)
throw new ListenerNotFoundException("The specified listener, " + listener +
"is not registered with this bean.");
}
/**
* Removes the specified listener from the list of recipients
* of notifications from this bean. Only the first instance with
* the supplied filter and passback object is removed.
* <code>null</code> is used as a valid value for these parameters,
* rather than as a way to remove all registration instances for
* the specified listener; for this behaviour instead, see the details
* of the same method in {@link NotificationBroadcaster}.
*
* @param listener the listener to remove.
* @param filter the filter of the listener to remove.
* @param passback the passback object of the listener to remove.
* @throws ListenerNotFoundException if the specified listener
* is not registered with this bean.
* @see #addNotificationListener(NotificationListener, NotificationFilter,
* java.lang.Object)
*/
public void removeNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object passback)
throws ListenerNotFoundException
{
if (!(listeners.remove(new ListenerData(listener, filter, passback))))
{
throw new ListenerNotFoundException("The specified listener, " + listener +
" with filter " + filter +
"and passback " + passback +
", is not registered with this bean.");
}
}
/**
* <p>
* Performs delivery of the notification. If an executor
* was specified on construction, this will be used to call
* {@link #handleNotification(NotificationListener, Notification,
* Object)}. If the executor is <code>null</code>, however,
* this thread calls the method itself in order to perform a
* synchronous dispatch of the notification to all eligible
* listeners.
* </p>
* <p>
* Prior to either process taking place, the listeners are filtered.
* Notifications are only delivered if the filter is either
* <code>null</code> or returns true from the
* {@link NotificationFilter#isNotificationEnabled(Notification)}
* method.
* </p>
*
* @param notif the notification to send.
*/
public void sendNotification(Notification notif)
{
for (ListenerData ldata : listeners)
{
NotificationFilter filter = ldata.getFilter();
if (filter == null || filter.isNotificationEnabled(notif))
{
if (executor == null)
try
{
handleNotification(ldata.getListener(), notif,
ldata.getPassback());
}
catch (Exception e) { /* Ignore */ }
else
executor.execute(new DispatchTask(ldata, notif));
}
}
}
/**
* The dispatch task to be performed by an executor.
*/
private final class DispatchTask
implements Runnable
{
/**
* The data on the listener being called.
*/
private ListenerData ldata;
/**
* The notification to send.
*/
private Notification notif;
/**
* Construct a new {@link DispatchTask}.
*
* @param ldata the listener data.
* @param notif the notification to send.
*/
public DispatchTask(ListenerData ldata,
Notification notif)
{
this.ldata = ldata;
this.notif = notif;
}
/**
* Dispatch the notification.
*/
public void run()
{
try
{
handleNotification(ldata.getListener(), notif,
ldata.getPassback());
}
catch (Exception e) { /* Ignore */ }
}
}
}

View file

@ -0,0 +1,139 @@
/* NotificationFilterSupport.java -- Filter on notification type.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import java.util.Vector;
/**
* Performs filtering of {@link Notification}s
* based on a list of type prefixes. The type of a notification
* is compared with each member of the list using
* {@link String#startsWith(String)} and, if one matches,
* the notification is allowed to pass through the filter.
* Matching on the beginning of the string is used in
* preference to wildcards, so <code>type.*</code> will
* match only notifications with a type beginning with
* code>type.*</code>, not <code>type.</code> as
* expected.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class NotificationFilterSupport
implements NotificationFilter
{
/**
* Compatible with JDK 1.5
*/
private static final long serialVersionUID = 6579080007561786969L;
/**
* Lists the types that may pass through the filter.
*/
private final Vector<String> enabledTypes = new Vector<String>();
/**
* Blocks all types by emptying the list of enabled attributes.
*/
public void disableAllTypes()
{
enabledTypes.clear();
}
/**
* Removes the specified type prefix from the list
* of enabled types, thus preventing matching types
* from passing through the filter. If the specified
* type prefix is not enabled, this operation has no
* effect.
*
* @param prefix the prefix to disable.
*/
public void disableType(String prefix)
{
enabledTypes.remove(prefix);
}
/**
* Adds the specified type prefix to the list
* of enabled types, thus allowing
* types starting with this string to pass through
* the filter. If the type prefix is already
* enabled, this has no effect.
*
* @param prefix the prefix to enable.
* @throws IllegalArgumentException if <code>prefix</code>
* is <code>null</code>.
*/
public void enableType(String prefix)
{
if (prefix == null)
throw new IllegalArgumentException("A null prefix was supplied.");
if (!enabledTypes.contains(prefix))
enabledTypes.add(prefix);
}
/**
* Returns the list of enabled types for this
* filter.
*
* @return the list of enabled types.
*/
public Vector<String> getEnabledTypes()
{
return enabledTypes;
}
/**
* Returns true if the type of the specified notification
* begins with one of the enabled type prefixes.
*
* @param notif the notification being filtered.
* @return true if the notification's type is enabled.
*/
public boolean isNotificationEnabled(Notification notif)
{
String nType = notif.getType();
for (String type : enabledTypes)
if (nType.startsWith(type))
return true;
return false;
}
}

View file

@ -0,0 +1,126 @@
/* PersistentMBean.java -- Interface for beans that should persist.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
/**
* Beans may implement this interface in order to become
* persistent. The {@link #load()} method should be
* called on construction in order to reload the stored
* state. The {@link #store()} method should be called
* sometime during the bean's lifetime in order to create
* a persistent copy of the bean's instance data. This
* method may also be called by the {@link MBeanServer}
* as a result of the {@link Descriptor} of an
* {@link javax.management.modelmbean.ModelMBean}.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public interface PersistentMBean
{
/**
* Instantiates the bean with the data previously stored
* using a call to {@link #store()}. The data stored can
* include values held by attributes as well as those returned
* by operations. This method should be called during
* construction or initialisation of the bean, before
* it becomes registered with an {@link MBeanServer}.
*
* @throws MBeanException if persistence is not supported,
* or another exception is thrown
* (which this then wraps).
* @throws RuntimeOperationsException if the persistence
* mechanism throws an
* exception.
* @throws InstanceNotFoundException if the bean can not
* be found in the
* persistent store.
*/
void load()
throws MBeanException, RuntimeOperationsException,
InstanceNotFoundException;
/**
* <p>
* Captures the current state of the bean and stores it
* for future retrieval by the {@link #load()} method.
* The data stored can include values held by attributes
* as well as those returned by operations.
* </p>
* <p>
* Whether the state is stored or not depends on the
* <code>persistPolicy</code> field of the MBean/attribute
* descriptor. The state should be stored if the policy
* is set to any of the following:
* </p>
* <ul>
* <li><code>always</code></li>
* <li><code>onTimer</code> and <code>now</code> is
* greater than or equal to <code>lastPersistTime +
* persistPeriod</code>.</li>
* <li><code>noMoreOftenThan</code> and <code>now</code> is
* greater than or equal to <code>lastPersistTime +
* persistPeriod</code>.</li>
* <li>onUnregister</li>
* </ul>
* <p>If the policy is set to any of the following, the state
* should not be stored:</p>
* <ul>
* <li><code>never</code></li>
* <li><code>onUpdate</code></li>
* <li><code>onTimer</code> and <code>now</code> is
* less than <code>lastPersistTime + persistPeriod</code>.
* </li>
* </ul>
*
* @throws MBeanException if persistence is not supported,
* or another exception is thrown
* (which this then wraps).
* @throws RuntimeOperationsException if the persistence
* mechanism throws an
* exception.
* @throws InstanceNotFoundException if the persistent
* store can not be found
* or accessed.
*/
void store()
throws MBeanException, RuntimeOperationsException,
InstanceNotFoundException;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,95 @@
/* QueryEval.java -- An evaluation context for a MBean server query.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
import java.io.Serializable;
/**
* Represents the evaluation context of a {@link MBeanServer}
* query by retaining the server used on a thread-by-thread
* basis.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class QueryEval
implements Serializable
{
/**
* Compatible with JDK 1.5
*/
private static final long serialVersionUID = 2675899265640874796L;
/**
* Stores the server used, on a
* thread-by-thread basis.
*/
private static InheritableThreadLocal<MBeanServer> server =
new InheritableThreadLocal<MBeanServer>();
/**
* Returns the {@link MBeanServer} last supplied to the
* {@link #setMBeanServer(MBeanServer)} method. If this method
* has not been called for this thread, then the value will be
* inherited from any parent thread on which the method has
* been called. If the method has never been called, then
* <code>null</code> is returned.
*
* @return the server.
* @see #setMBeanServer(MBeanServer)
*/
public static MBeanServer getMBeanServer()
{
return server.get();
}
/**
* Sets the {@link MBeanServer} on which the query will be
* performed. This value is inherited automatically by
* child threads. This method is only non-static for historical
* reasons; it makes no use of instance-related values.
*
* @param svr the server to use.
*/
public void setMBeanServer(MBeanServer svr)
{
server.set(svr);
}
}

View file

@ -106,10 +106,19 @@ public class StandardMBean
}
catch (ClassNotFoundException e)
{
throw (NotCompliantMBeanException)
(new NotCompliantMBeanException("An interface, " + className +
"MBean, for the class " + className +
" was not found.").initCause(e));
for (Class<?> nextIface : getClass().getInterfaces())
{
if (JMX.isMXBeanInterface(nextIface))
{
iface = nextIface;
break;
}
}
if (iface == null)
throw (NotCompliantMBeanException)
(new NotCompliantMBeanException("An interface for the class "
+ className +
" was not found.").initCause(e));
}
}
if (!(iface.isInstance(this)))
@ -140,18 +149,28 @@ public class StandardMBean
throw new IllegalArgumentException("The specified implementation is null.");
if (iface == null)
{
String className = impl.getClass().getName();
Class<?> implClass = impl.getClass();
String className = implClass.getName();
try
{
this.iface = Class.forName(className + "MBean", true,
impl.getClass().getClassLoader());
implClass.getClassLoader());
}
catch (ClassNotFoundException e)
{
throw (NotCompliantMBeanException)
(new NotCompliantMBeanException("An interface, " + className +
"MBean, for the class " + className +
" was not found.").initCause(e));
for (Class<?> nextIface : implClass.getInterfaces())
{
if (JMX.isMXBeanInterface(nextIface))
{
this.iface = nextIface;
break;
}
}
if (this.iface == null)
throw (NotCompliantMBeanException)
(new NotCompliantMBeanException("An interface for the class " +
className +
" was not found.").initCause(e));
}
}
else
@ -753,19 +772,30 @@ public class StandardMBean
public Object invoke(String name, Object[] params, String[] signature)
throws MBeanException, ReflectionException
{
Class[] sigTypes = new Class[signature.length];
if (name.startsWith("get") || name.startsWith("is") ||
name.startsWith("set"))
throw new ReflectionException(new NoSuchMethodException(),
"Invocation of an attribute " +
"method is disallowed.");
ClassLoader loader = getClass().getClassLoader();
for (int a = 0; a < signature.length; ++a)
try
{
sigTypes[a] = Class.forName(signature[a], true, loader);
}
catch (ClassNotFoundException e)
{
throw new ReflectionException(e, "The class, " + signature[a] +
", in the method signature " +
"could not be loaded.");
}
Class[] sigTypes;
if (signature != null)
{
sigTypes = new Class[signature.length];
for (int a = 0; a < signature.length; ++a)
try
{
sigTypes[a] = Class.forName(signature[a], true, loader);
}
catch (ClassNotFoundException e)
{
throw new ReflectionException(e, "The class, " + signature[a] +
", in the method signature " +
"could not be loaded.");
}
}
else
sigTypes = null;
Method method;
try
{
@ -824,23 +854,12 @@ public class StandardMBean
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException
{
Method setter;
String name = attribute.getName();
try
{
setter = iface.getMethod("set" +
name.substring(0, 1).toUpperCase() +
name.substring(1), null);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
String attName = name.substring(0, 1).toUpperCase() + name.substring(1);
Object val = attribute.getValue();
try
{
setter.invoke(impl, new Object[] { attribute.getValue() });
getMutator(attName, val.getClass()).invoke(impl, new Object[] { val });
}
catch (IllegalAccessException e)
{
@ -855,8 +874,8 @@ public class StandardMBean
}
catch (InvocationTargetException e)
{
throw new MBeanException((Exception) e.getCause(), "The getter of "
+ name + " threw an exception");
throw new MBeanException(e, "The getter of " + name +
" threw an exception");
}
}
@ -925,4 +944,142 @@ public class StandardMBean
this.impl = impl;
}
/**
* Returns the mutator method for a particular attribute name
* with a parameter type matching that of the given value.
*
* @param name the name of the attribute.
* @param type the type of the parameter.
* @return the appropriate mutator method.
* @throws AttributeNotFoundException if a method can't be found.
*/
private Method getMutator(String name, Class<?> type)
throws AttributeNotFoundException
{
String mutator = "set" + name;
Exception ex = null;
try
{
return iface.getMethod(mutator, type);
}
catch (NoSuchMethodException e)
{
/* Ignored; we'll try harder instead */
ex = e;
}
/* Special cases */
if (type == Boolean.class)
try
{
return iface.getMethod(mutator, Boolean.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
if (type == Byte.class)
try
{
return iface.getMethod(mutator, Byte.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
if (type == Character.class)
try
{
return iface.getMethod(mutator, Character.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
if (type == Double.class)
try
{
return iface.getMethod(mutator, Double.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
if (type == Float.class)
try
{
return iface.getMethod(mutator, Float.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
if (type == Integer.class)
try
{
return iface.getMethod(mutator, Integer.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
if (type == Long.class)
try
{
return iface.getMethod(mutator, Long.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
if (type == Short.class)
try
{
return iface.getMethod(mutator, Short.TYPE);
}
catch (NoSuchMethodException e)
{
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(e));
}
/* Superclasses and interfaces */
for (Class<?> i : type.getInterfaces())
try
{
return getMutator(name, i);
}
catch (AttributeNotFoundException e)
{
ex = e;
}
Class<?> sclass = type.getSuperclass();
if (sclass != null && sclass != Object.class)
try
{
return getMutator(name, sclass);
}
catch (AttributeNotFoundException e)
{
ex = e;
}
/* If we get this far, give up */
throw ((AttributeNotFoundException)
new AttributeNotFoundException("The attribute, " + name +
", was not found.").initCause(ex));
}
}

View file

@ -0,0 +1,133 @@
/* StringValueExp.java -- Represents strings to be passed to queries.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management;
/**
* Represents a string being used as an argument
* to a relational constraint.
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class StringValueExp
implements ValueExp
{
/**
* Compatible with JDK 1.5
*/
private static final long serialVersionUID = -3256390509806284044L;
/**
* The string value.
*/
private String val;
/**
* Constructs a new {@link StringValueExp}.
*/
public StringValueExp()
{
}
/**
* Constructs a new {@link StringValueExp} using the
* specified value.
*
* @param val the string value used for this expression.
*/
public StringValueExp(String val)
{
this.val = val;
}
/**
* Applies the {@link StringValueExp} to the specified
* management bean by simply returning the value.
*
* @param name the {@link ObjectName} of the bean.
* @return the {@link StringValueExp} itself.
* @throws BadStringOperationException if an invalid string
* operation is used by
* the value expression.
* @throws BadBinaryOpValueExpException if an invalid expression
* is used by the value expression.
* @throws BadAttributeValueExpException if an invalid attribute
* is used by the value expression.
* @throws InvalidApplicationException if the value expression is applied
* to the wrong type of bean.
*/
public ValueExp apply(ObjectName name)
throws BadStringOperationException, BadBinaryOpValueExpException,
BadAttributeValueExpException, InvalidApplicationException
{
return this;
}
/**
* Returns the value.
*
* @return the value.
*/
public String getValue()
{
return val;
}
/**
* Sets the {@link MBeanServer} on which the query
* will be performed.
*
* @param server the new server.
*/
public void setMBeanServer(MBeanServer server)
{
/* This seems to do nothing any more */
}
/**
* Returns the value in quotes.
*
* @return the value (quoted).
*/
public String toString()
{
return "'" + val + "'";
}
}

View file

@ -71,7 +71,7 @@ public interface ClassLoaderRepository
* @throws ClassNotFoundException if all the class loaders fail
* to load the class.
*/
Class loadClass(String name)
Class<?> loadClass(String name)
throws ClassNotFoundException;
/**
@ -102,7 +102,7 @@ public interface ClassLoaderRepository
* @throws ClassNotFoundException if all the class loaders fail
* to load the class.
*/
Class loadClassBefore(ClassLoader stop, String name)
Class<?> loadClassBefore(ClassLoader stop, String name)
throws ClassNotFoundException;
/**
@ -132,7 +132,7 @@ public interface ClassLoaderRepository
* @throws ClassNotFoundException if all the class loaders fail
* to load the class.
*/
Class loadClassWithout(ClassLoader exclude, String name)
Class<?> loadClassWithout(ClassLoader exclude, String name)
throws ClassNotFoundException;
}

View file

@ -1,5 +1,5 @@
/* ArrayType.java -- Open type descriptor for an array.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -40,6 +40,8 @@ package javax.management.openmbean;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* The open type descriptor for arrays of open data values.
@ -47,8 +49,8 @@ import java.util.Arrays;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public class ArrayType
extends OpenType
public class ArrayType<T>
extends OpenType<T>
{
/**
@ -64,7 +66,12 @@ public class ArrayType
/**
* The element type of arrays of this type.
*/
private OpenType elementType;
private OpenType<?> elementType;
/**
* True if this type represents a primitive array.
*/
private boolean primitiveArray;
/**
* The hash code of this instance.
@ -76,20 +83,184 @@ public class ArrayType
*/
private transient String string;
/**
* A cache of {@link ArrayType} instances created
* by {@link #getArrayType(OpenType)}.
*/
private static final Map<OpenType<?>,ArrayType<?>> cache =
new HashMap<OpenType<?>,ArrayType<?>>();
/**
* A cache of {@link ArrayType} instances created
* by {@link #getPrimitiveArrayType(Class)}.
*/
private static final Map<Class<?>,ArrayType<?>> primCache =
new HashMap<Class<?>,ArrayType<?>>();
/**
* Returns the class name of the array, given the element
* class name and its dimensions.
*
* @param className the name of the class used by the
* array's elements.
* @param elementType the type of the array's elements.
* @param dim the dimensions of the array.
* @param primitive true if this should be a primitive array.
* @return the array's class name.
* @throws OpenDataException if the class name does not reference
* a loadable class.
*/
private static String getArrayClassName(String className, int dim)
private static final String getArrayClassName(OpenType<?> elementType,
int dim,
boolean primitive)
throws OpenDataException
{
char[] brackets = new char[dim];
Arrays.fill(brackets, '[');
return String.valueOf(brackets) + "L" + className;
Class<?> type;
if (primitive)
type = getPrimitiveTypeClass((SimpleType<?>) elementType);
else
{
String className = elementType.getClassName();
try
{
type = Class.forName(className);
}
catch (ClassNotFoundException e)
{
throw new OpenDataException("The class name, " + className +
", is unavailable.");
}
}
while (type.isArray())
type = type.getComponentType();
return
Array.newInstance(type,
new int[getDimensions(elementType, dim)]).getClass().getName();
}
/**
* Returns the dimensions of the new {@link ArrayType},
* based on whether the given element type is already an
* {@link ArrayType} or not.
*
* @param elementType the type of the array.
* @param dim the proposed dimensions.
* @return the resultant dimensions.
* @throws IllegalArgumentException if <code>dim</code> is less than 1.
*/
private static final int getDimensions(OpenType<?> elementType,
int dim)
{
if (dim < 1)
throw new IllegalArgumentException("Dimensions must be greater " +
"than or equal to 1.");
if (elementType instanceof ArrayType)
return dim + ((ArrayType) elementType).getDimension();
return dim;
}
/**
* Returns the appropriate primitive type name, given the
* corresponding wrapper class.
*
* @param type the type to convert.
* @return the corresponding primitive type.
* @throws OpenDataException if {@code type} is not a valid
* {@link Class} for a primitive type.
*
*/
private static final SimpleType<?> getPrimitiveType(Class<?> type)
throws OpenDataException
{
if (type.equals(Boolean.TYPE))
return SimpleType.BOOLEAN;
if (type.equals(Byte.TYPE))
return SimpleType.BYTE;
if (type.equals(Character.TYPE))
return SimpleType.CHARACTER;
if (type.equals(Double.TYPE))
return SimpleType.DOUBLE;
if (type.equals(Float.TYPE))
return SimpleType.FLOAT;
if (type.equals(Integer.TYPE))
return SimpleType.INTEGER;
if (type.equals(Long.TYPE))
return SimpleType.LONG;
if (type.equals(Short.TYPE))
return SimpleType.SHORT;
if (type.equals(Void.TYPE))
return SimpleType.VOID;
throw new OpenDataException(type + " is not a primitive type.");
}
/**
* Returns the appropriate primitive type name, given the
* corresponding wrapper class.
*
* @param type the type to convert.
* @return the corresponding primitive type.
* @throws OpenDataException if {@code type} is not a valid
* {@link SimpleType} for a primitive type.
*
*/
private static final Class<?> getPrimitiveTypeClass(SimpleType<?> type)
throws OpenDataException
{
if (type.equals(SimpleType.BOOLEAN))
return Boolean.TYPE;
if (type.equals(SimpleType.BYTE))
return Byte.TYPE;
if (type.equals(SimpleType.CHARACTER))
return Character.TYPE;
if (type.equals(SimpleType.DOUBLE))
return Double.TYPE;
if (type.equals(SimpleType.FLOAT))
return Float.TYPE;
if (type.equals(SimpleType.INTEGER))
return Integer.TYPE;
if (type.equals(SimpleType.LONG))
return Long.TYPE;
if (type.equals(SimpleType.SHORT))
return Short.TYPE;
if (type.equals(SimpleType.VOID))
return Void.TYPE;
throw new OpenDataException(type + " is not a primitive type.");
}
/**
* Returns the element type that will actually be used, if the
* specified element type is passed to a constructor. This is
* necessary to ensure that a non-array type is still returned when
* an {@link ArrayType} is constructed from an {@link ArrayType}.
*
* @param elemType the element type that was supplied.
* @return the element type that will be used.
*/
private static final OpenType<?> getElementType(OpenType<?> elemType)
{
if (elemType instanceof ArrayType)
return ((ArrayType) elemType).getElementOpenType();
return elemType;
}
/**
* Returns the element type name that will actually be used, if the
* specified element type is passed to a constructor. This is
* necessary to ensure that a non-array type is still returned when
* an {@link ArrayType} is constructed from an {@link ArrayType},
* and that primitive arrays are described correctly.
*
* @param elemType the element type that was supplied.
* @return the element type name that will be used.
* @throws OpenDataException if the element type is not a valid
* {@link SimpleType} for a primitive type.
*/
private static final String getElementTypeName(OpenType<?> elemType)
throws OpenDataException
{
OpenType<?> trueElemType = getElementType(elemType);
if (elemType instanceof ArrayType &&
((ArrayType) elemType).isPrimitiveArray())
return getPrimitiveTypeClass((SimpleType<?>) trueElemType).getName();
return trueElemType.getClassName();
}
/**
@ -136,23 +307,84 @@ public class ArrayType
* {@link SimpleType}, {@link CompositeType}
* or {@link TabularType}.
*/
public ArrayType(int dim, OpenType elementType)
public ArrayType(int dim, OpenType<?> elementType)
throws OpenDataException
{
super(getArrayClassName(elementType.getClassName(), dim),
getArrayClassName(elementType.getClassName(), dim),
dim + "-dimension array of " + elementType.getClassName());
if (dim < 1)
throw new IllegalArgumentException("Dimensions must be greater " +
"than or equal to 1.");
super(getArrayClassName(elementType, dim, false),
getArrayClassName(elementType, dim, false),
getDimensions(elementType, dim) + "-dimension array of "
+ getElementTypeName(elementType));
if (!(elementType instanceof SimpleType ||
elementType instanceof CompositeType ||
elementType instanceof TabularType))
elementType instanceof TabularType ||
elementType instanceof ArrayType))
throw new OpenDataException("The element type must be a simple " +
"type, a composite type or a tabular " +
"type.");
dimension = dim;
"type, an array type, a composite type " +
"or a tabular type.");
dimension = getDimensions(elementType, dim);
this.elementType = getElementType(elementType);
primitiveArray = (elementType instanceof ArrayType &&
((ArrayType) elementType).isPrimitiveArray());
}
/**
* <p>
* Constructs a new {@link ArrayType} instance for a unidimensional
* array of the specified {@link SimpleType}. The attributes
* used by the superclass, {@link OpenType}, are automatically defined,
* based on these values. Both the class name and type name are set
* to the value returned by the {@link java.lang.Class#getName()} of
* the array's class. If the array is of a primitive type (indicated
* by giving {@code primitiveArray} the value {@code true}), the
* name will be '[' followed by the appropriate letter for the
* primitive type (see {@link java.lang.Class#getName()}). If the
* array is not of a primitive type, then the name is formed from
* the element type, preceded by '[' and an 'L', in the same way
* as when the multi-dimensional constructor is used.
* </p>
* <p>
* The description is based upon the template <code>1-dimension array
* of e</code>, where e is either the primitive type or a class name,
* depending on whether the array itself is of a primitive type or not.
* The class name of the actual elements is obtainable by calling
* {@link OpenType#getClassName()} on the result of
* {@link #getElementOpenType()}. This will be the appropriate wrapper
* class for a primitive type.
* </p>
* <p>
* As an example, the array type returned by
* <code>new ArrayType(SimpleType.INTEGER, true)</code> has the following
* values:
* </p>
* <table>
* <th><td>Attribute</td><td>Value</td></th>
* <tr><td>Class Name</td><td><code>[I</code>
* </td></tr>
* <tr><td>Type Name</td><td><code>[I</code>
* </td></tr>
* <tr><td>Description</td><td><code>1-dimension array of int</code></td></tr>
* <tr><td>Element Type Class Name</td><td><code>java.lang.Integer</code>
* </td></tr>
* </table>
*
* @param elementType the type of the elements of the array.
* @param primitiveArray true if the array should be of a primitive type.
* @throws OpenDataException if {@code primitiveArray} is {@code true},
* and {@link elementType} is not a valid
* {@link SimpleType} for a primitive type.
* @since 1.6
*/
public ArrayType(SimpleType<?> elementType, boolean primitiveArray)
throws OpenDataException
{
super(getArrayClassName(elementType, 1, primitiveArray),
getArrayClassName(elementType, 1, primitiveArray),
"1-dimension array of " +
(primitiveArray ? getPrimitiveTypeClass(elementType).getName()
: elementType.getClassName()));
dimension = 1;
this.elementType = elementType;
this.primitiveArray = primitiveArray;
}
/**
@ -166,6 +398,8 @@ public class ArrayType
* {@link ArrayType}.</li>
* <li>The dimensions are equal.</li>
* <li>The element types are equal.</li>
* <li>The primitive array flag is set the same in both
* instances.</li>
* </ul>
*
* @param obj the object to compare with.
@ -177,7 +411,118 @@ public class ArrayType
return false;
ArrayType atype = (ArrayType) obj;
return (atype.getDimension() == dimension &&
atype.getElementOpenType().equals(elementType));
atype.getElementOpenType().equals(elementType) &&
atype.isPrimitiveArray() == primitiveArray);
}
/**
* <p>
* Returns a new {@link ArrayType} instance in a type-safe
* manner, by ensuring that the type of the given {@link OpenType}
* matches the component type used in the type of the
* returned instance. If the given {@link OpenType} is a
* {@link SimpleType}, {@link CompositeType} or
* {@link TabularType}, then a 1-dimensional array of that
* type is returned. Otherwise, if the type is
* an {@link ArrayType} of n dimensions, the returned
* type is also an {@link ArrayType} but of n+1 dimensions.
* For example,
* {@code ArrayType.getArrayType(ArrayType.getArrayType(SimpleType.STRING))}
* returns a 2-dimensional array of {@link SimpleType#String}.
* </p>
* <p>
* This method caches its results, so that the same instance
* is returned from subsequent calls with the same parameters.
* </p>
*
* @param elementType the element type of the new array type.
* @throws OpenDataException if the class name of {@code elementType}
* is not in {@link OpenType#ALLOWED_CLASSNAMES_LIST}.
* @since 1.6
*/
public static <E> ArrayType<E[]> getArrayType(OpenType<E> elementType)
throws OpenDataException
{
ArrayType<E[]> arr = (ArrayType<E[]>) cache.get(elementType);
if (arr != null)
return arr;
arr = new ArrayType(1, elementType);
cache.put(elementType, arr);
return arr;
}
/**
* <p>
* Returns a new {@link ArrayType} instance for the given
* primitive type in a type-safe* manner, by ensuring that
* the type of the given {@link OpenType} matches the type
* used in the returned instance. If the type is
* an array of n dimensions, the returned
* type is also an {@link ArrayType} of n dimensions.
* </p>
* <p>
* As an example, the array type returned by
* <code>getPrimitiveArrayType(Integer.TYPE)</code> has the
* following values:
* </p>
* <table>
* <th><td>Attribute</td><td>Value</td></th>
* <tr><td>Class Name</td><td><code>[I</code>
* </td></tr>
* <tr><td>Type Name</td><td><code>[I</code>
* </td></tr>
* <tr><td>Description</td><td><code>1-dimension array of int</code></td></tr>
* <tr><td>Element Type Class Name</td><td><code>java.lang.Integer</code>
* </td></tr>
* </table>
* <p>
* This method caches its results, so that the same instance
* is returned from subsequent calls with the same parameters.
* </p>
*
* @param type the type of the new {@link ArrayType}.
* @throws IllegalArgumentException if the type is not a primitive
* array.
* @since 1.6
*/
public static <T> ArrayType<T> getPrimitiveArrayType(Class<T> type)
{
ArrayType<T> arr = (ArrayType<T>) primCache.get(type);
if (arr != null)
return arr;
Class<?> comType = type;
int dim = 0;
do
{
comType = comType.getComponentType();
++dim;
if (comType == null)
throw new IllegalArgumentException("The given class is " +
"not an array.");
} while (comType.isArray());
String className = type.getName();
try
{
arr = new ArrayType(getPrimitiveType(comType), true);
}
catch (OpenDataException e)
{
throw new IllegalArgumentException("The array is not of a primitive " +
"type", e);
}
while (dim > 1)
try
{
arr = new ArrayType(1, arr);
--dim;
}
catch (OpenDataException e)
{
throw (Error)
new InternalError("Couldn't generate extra dimensions").initCause(e);
}
primCache.put(type, arr);
return arr;
}
/**
@ -197,7 +542,7 @@ public class ArrayType
*
* @return the type of the elements.
*/
public OpenType getElementOpenType()
public OpenType<?> getElementOpenType()
{
return elementType;
}
@ -207,11 +552,11 @@ public class ArrayType
* Returns the hash code of the array type.
* This is computed as the sum of the hash code of the
* element type together with the number of dimensions
* the array has. These are the same elements
* of the type that are compared as part of the
* {@link #equals(java.lang.Object)} method, thus ensuring
* that the hashcode is compatible with the equality
* test.
* the array has and the primitive array flag. These
* are the same elements of the type that are compared as
* part of the {@link #equals(java.lang.Object)} method,
* thus ensuring that the hashcode is compatible with the
* equality test.
* </p>
* <p>
* As instances of this class are immutable, the hash code
@ -224,10 +569,23 @@ public class ArrayType
public int hashCode()
{
if (hashCode == null)
hashCode = Integer.valueOf(dimension + elementType.hashCode());
hashCode = Integer.valueOf(dimension +
elementType.hashCode() +
Boolean.valueOf(primitiveArray).hashCode());
return hashCode.intValue();
}
/**
* Returns true if this instance represents an array of
* a primitive type.
*
* @return true if the array is of a primitive type.
*/
public boolean isPrimitiveArray()
{
return primitiveArray;
}
/**
* <p>
* Returns true if the specified object is a member of this
@ -306,6 +664,7 @@ public class ArrayType
+ "[name=" + getTypeName()
+ ", dimension=" + dimension
+ ", elementType=" + elementType
+ ", primitiveArray=" + primitiveArray
+ "]";
return string;
}

View file

@ -1,5 +1,5 @@
/* CompositeData.java -- A composite data structure.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -148,7 +148,7 @@ public interface CompositeData
*
* @return the values of this instance.
*/
Collection values();
Collection<?> values();
}

View file

@ -0,0 +1,190 @@
/* CompositeDataInvocationHandler.java - Pseudo-accessors for CompositeData.
Copyright (C) 2007 Free Software Foundation
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.management.openmbean;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* <p>
* Provides an {@link java.lang.reflect.InvocationHandler} which
* implements a series of accessor methods (those beginning with
* {@code "get"} or {@code "is"}) using the content of a
* {@link CompositeData} object. An instance of {@link CompositeData}
* consists of a series of key-value mappings. This handler assumes
* these keys to be the names of attributes, and thus provides
* accessor methods by returning the associated value.
* </p>
* <p>
* As an example, consider the following interface:
* </p>
* <pre>
* public interface Person
* {
* public String getName();
* public Date getBirthday();
* }
* </pre>
* <p>
* This specifies two accessor methods for retrieving the attributes,
* {@code name} and {@code birthday}. An implementation of this interface
* can be provided by creating an instance of this class, using a
* {@link CompositeData} object with appropriate key-value mappings
* (e.g. "name" => "Fred", "birthday" => 30/06/1974), and then passing
* that to {@link java.lang.reflect.Proxy#newProxyInstance} along with
* the interface itself. The invocation handler implements the methods
* by calling {@link CompositeData#get(String)} with the appropriate key.
* </p>
* <p>
* The attribute name is derived by taking the remainder of the method
* name following {@code "get"}. If the first letter of this substring
* is uppercase, then two attempts are made to retrieve the attribute
* from the {@link CompositeData} instance: one using the original substring,
* and one with the first letter changed to its lower-case equivalent.
* If the first letter is lowercase, only the exact substring is used.
* </p>
* <p>
* An {@link Object#equals(Object)} implementation is provided. This returns
* true if the argument is a proxy with a {@link CompositeDataInvocationHandler}
* using an equivalent {@link CompositeData} instance. {@link Object#hashCode()}
* is also defined so as to match this implementation and give equivalent instances
* the same hashcode.
* </p>
*
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.6
*/
public class CompositeDataInvocationHandler
implements InvocationHandler
{
/**
* The {@link CompositeData} providing the key-value mappings.
*/
private CompositeData data;
/**
* Constructs a new {@link CompositeDataInvocationHandler}
* with the specified {@link CompositeData} instance.
*
* @param data the {@link CompositeData} instance to use.
* @throws IllegalArgumentException if {@code data} is {@code null}.
*/
public CompositeDataInvocationHandler(CompositeData data)
{
if (data == null)
throw new IllegalArgumentException("The CompositeData instance " +
"must be non-null.");
this.data = data;
}
/**
* Returns the {@link CompositeData} instance which provides
* the key-value mappings for this instance. This is never
* {@code null}.
*
* @return the {@link CompositeData} instance.
*/
public CompositeData getCompositeData()
{
return data;
}
/**
* Called by the proxy class whenever a method is called. The
* handler only deals with accessor methods (beginning with
* {@code "get"} or {@code "is"}), {@code equals}, and
* {@code "hashCode"}. Accessor methods are implemented by
* returning the appropriate value from the {@link CompositeData}
* instance, while {@code equals} and {@code hashCode} allow
* two proxies with a {@link CompositeDataInvocationHandler} using
* the same {@link CompositeData} instance to be classified
* as equivalent.
*
* @param proxy the proxy on which the method was called.
* @param method the method which was called.
* @param args the arguments supplied to the method.
* @return the return value from the method.
* @throws Throwable if an exception is thrown in the process.
*/
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
String mName = method.getName();
if (mName.equals("equals"))
{
if (args[0] instanceof Proxy)
{
InvocationHandler h = Proxy.getInvocationHandler(args[0]);
if (h instanceof CompositeDataInvocationHandler)
return data.equals(((CompositeDataInvocationHandler)
h).getCompositeData());
}
return false;
}
if (mName.equals("hashCode"))
{
return data.hashCode();
}
String attrib = null;
if (mName.startsWith("get"))
attrib = mName.substring(3);
else if (mName.startsWith("is"))
attrib = mName.substring(2);
if (attrib == null)
throw new NoSuchMethodException(mName + " is not an accessor.");
if (!data.containsKey(attrib))
{
if (Character.isLowerCase(attrib.charAt(0)))
throw new NoSuchMethodException("The attribute " +
attrib + " is not available " +
"in the given CompositeData " +
"object");
attrib = Character.toLowerCase(attrib.charAt(0))
+ attrib.substring(1);
if (!data.containsKey(attrib))
throw new NoSuchMethodException("The attribute " +
attrib + " is not available " +
"in the given CompositeData " +
"object");
}
return data.get(attrib);
}
}

View file

@ -1,5 +1,5 @@
/* CompositeData.java -- A composite data structure implementation.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -68,7 +68,7 @@ public class CompositeDataSupport
*
* @serial the map of field names to values.
*/
private SortedMap contents;
private SortedMap<String, Object> contents;
/**
* The composite type which represents this composite data instance.
@ -106,11 +106,11 @@ public class CompositeDataSupport
* {@link java.lang.String} (thus calling a failure
* in converting the keys to an array of strings).
*/
public CompositeDataSupport(CompositeType type, Map items)
public CompositeDataSupport(CompositeType type, Map<String, ?> items)
throws OpenDataException
{
this(type,
(String[]) items.keySet().toArray(new String[items.size()]),
items.keySet().toArray(new String[items.size()]),
items.values().toArray());
}
@ -158,7 +158,7 @@ public class CompositeDataSupport
if (typeKeys.size() != names.length)
throw new OpenDataException("The number of field names does not match " +
"the type description.");
contents = new TreeMap();
contents = new TreeMap<String, Object>();
for (int a = 0; a < names.length; ++a)
{
if (names[a] == null)
@ -340,7 +340,7 @@ public class CompositeDataSupport
*
* @return the values of this instance.
*/
public Collection values()
public Collection<?> values()
{
return Collections.unmodifiableCollection(contents.values());
}

View file

@ -1,5 +1,5 @@
/* CompositeType.java -- Type descriptor for CompositeData instances.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -51,7 +51,7 @@ import java.util.TreeMap;
* @since 1.5
*/
public class CompositeType
extends OpenType
extends OpenType<CompositeData>
{
/**
@ -62,12 +62,12 @@ public class CompositeType
/**
* A map of item names to their descriptions.
*/
private TreeMap nameToDescription;
private TreeMap<String,String> nameToDescription;
/**
* A map of item names to their types.
*/
private TreeMap nameToType;
private TreeMap<String,OpenType<?>> nameToType;
/**
* The hash code of this instance.
@ -109,7 +109,7 @@ public class CompositeType
* before comparison.
*/
public CompositeType(String name, String desc, String[] names,
String[] descs, OpenType[] types)
String[] descs, OpenType<?>[] types)
throws OpenDataException
{
super(CompositeData.class.getName(), name, desc);
@ -138,7 +138,7 @@ public class CompositeType
"than once.");
nameToDescription.put(fieldName, descs[a]);
}
nameToType = new TreeMap();
nameToType = new TreeMap<String,OpenType<?>>();
for (int a = 0; a < names.length; ++a)
nameToType.put(names[a].trim(), types[a]);
}
@ -178,16 +178,14 @@ public class CompositeType
CompositeType ctype = (CompositeType) obj;
if (!(ctype.getTypeName().equals(getTypeName())))
return false;
Set keys = keySet();
Set<String> keys = keySet();
if (!(ctype.keySet().equals(keys)))
return false;
Iterator it = keys.iterator();
while (it.hasNext())
{
String key = (String) it.next();
if (!(ctype.getType(key).equals(getType(key))))
return false;
}
for (String key : keys)
{
if (!(ctype.getType(key).equals(getType(key))))
return false;
}
return true;
}
@ -203,7 +201,7 @@ public class CompositeType
*/
public String getDescription(String name)
{
return (String) nameToDescription.get(name);
return nameToDescription.get(name);
}
/**
@ -216,9 +214,9 @@ public class CompositeType
* @return the type, or <code>null</code> if the
* field doesn't exist.
*/
public OpenType getType(String name)
public OpenType<?> getType(String name)
{
return (OpenType) nameToType.get(name);
return nameToType.get(name);
}
/**
@ -287,7 +285,7 @@ public class CompositeType
* @return a unmodifiable set containing the field
* name {@link java.lang.String}s.
*/
public Set keySet()
public Set<String> keySet()
{
return Collections.unmodifiableSet(nameToDescription.keySet());
}

View file

@ -1,5 +1,5 @@
/* OpenMBeanAttributeInfoSupport.java -- Open typed info about an attribute.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -62,7 +62,7 @@ public class OpenMBeanAttributeInfoSupport
/**
* The open type of the attribute.
*/
private OpenType openType;
private OpenType<?> openType;
/**
* The default value of the attribute (may be <code>null</code>).
@ -72,17 +72,17 @@ public class OpenMBeanAttributeInfoSupport
/**
* The possible legal values of the attribute (may be <code>null</code>).
*/
private Set legalValues;
private Set<?> legalValues;
/**
* The minimum value of the attribute (may be <code>null</code>).
*/
private Comparable minValue;
private Comparable<Object> minValue;
/**
* The maximum value of the attribute (may be <code>null</code>).
*/
private Comparable maxValue;
private Comparable<Object> maxValue;
/**
* The hash code of this instance.
@ -112,7 +112,7 @@ public class OpenMBeanAttributeInfoSupport
* or the name or description are
* the empty string.
*/
public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type,
public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType<?> type,
boolean isReadable, boolean isWritable,
boolean isIs)
{
@ -157,9 +157,9 @@ public class OpenMBeanAttributeInfoSupport
* open type or the open type is an instance
* of {@link ArrayType} or {@link TabularType}.
*/
public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type,
boolean isReadable, boolean isWritable,
boolean isIs, Object defaultValue)
public <T> OpenMBeanAttributeInfoSupport(String name, String desc, OpenType<T> type,
boolean isReadable, boolean isWritable,
boolean isIs, T defaultValue)
throws OpenDataException
{
this(name, desc, type, isReadable, isWritable, isIs, defaultValue, null);
@ -203,11 +203,11 @@ public class OpenMBeanAttributeInfoSupport
* the empty string.
* @throws OpenDataException if any condition in the list above is broken.
*/
public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type,
boolean isReadable, boolean isWritable,
boolean isIs, Object defaultValue,
Comparable minimumValue,
Comparable maximumValue)
public <T> OpenMBeanAttributeInfoSupport(String name, String desc, OpenType<T> type,
boolean isReadable, boolean isWritable,
boolean isIs, T defaultValue,
Comparable<T> minimumValue,
Comparable<T> maximumValue)
throws OpenDataException
{
this(name, desc, type, isReadable, isWritable, isIs);
@ -239,8 +239,8 @@ public class OpenMBeanAttributeInfoSupport
openType = type;
this.defaultValue = defaultValue;
minValue = minimumValue;
maxValue = maximumValue;
minValue = (Comparable<Object>) minimumValue;
maxValue = (Comparable<Object>) maximumValue;
}
/**
@ -280,10 +280,10 @@ public class OpenMBeanAttributeInfoSupport
* the empty string.
* @throws OpenDataException if any condition in the list above is broken.
*/
public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type,
boolean isReadable, boolean isWritable,
boolean isIs, Object defaultValue,
Object[] legalValues)
public <T> OpenMBeanAttributeInfoSupport(String name, String desc, OpenType<T> type,
boolean isReadable, boolean isWritable,
boolean isIs, T defaultValue,
T[] legalValues)
throws OpenDataException
{
this(name, desc, type, isReadable, isWritable, isIs);
@ -379,7 +379,7 @@ public class OpenMBeanAttributeInfoSupport
* @return a set of legal values, or <code>null</code> if no such
* set exists.
*/
public Set getLegalValues()
public Set<?> getLegalValues()
{
return legalValues;
}
@ -390,7 +390,7 @@ public class OpenMBeanAttributeInfoSupport
*
* @return the maximum value, or <code>null</code> if none exists.
*/
public Comparable getMaxValue()
public Comparable<?> getMaxValue()
{
return maxValue;
}
@ -401,7 +401,7 @@ public class OpenMBeanAttributeInfoSupport
*
* @return the minimum value, or <code>null</code> if none exists.
*/
public Comparable getMinValue()
public Comparable<?> getMinValue()
{
return minValue;
}
@ -412,7 +412,7 @@ public class OpenMBeanAttributeInfoSupport
*
* @return the open type of this attribute.
*/
public OpenType getOpenType()
public OpenType<?> getOpenType()
{
return openType;
}

View file

@ -109,7 +109,7 @@ public interface OpenMBeanOperationInfo
*
* @return the open type of the return value.
*/
OpenType getReturnOpenType();
OpenType<?> getReturnOpenType();
/**
* Returns the return type of the operation, as the class

View file

@ -1,5 +1,5 @@
/* OpenMBeanOperationInfoSupport.java -- Open typed info about an operation.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -61,7 +61,7 @@ public class OpenMBeanOperationInfoSupport
/**
* The open type representing the return value.
*/
private OpenType returnOpenType;
private OpenType<?> returnOpenType;
/**
* The hash code of this instance.
@ -108,7 +108,7 @@ public class OpenMBeanOperationInfoSupport
*/
public OpenMBeanOperationInfoSupport(String name, String desc,
OpenMBeanParameterInfo[] sig,
OpenType type, int impact)
OpenType<?> type, int impact)
{
super(name, desc, (MBeanParameterInfo[]) sig,
type == null ? null : type.getClassName(), impact);
@ -159,7 +159,7 @@ public class OpenMBeanOperationInfoSupport
*
* @return the open type of the return value.
*/
public OpenType getReturnOpenType()
public OpenType<?> getReturnOpenType()
{
return returnOpenType;
}

View file

@ -93,7 +93,7 @@ public interface OpenMBeanParameterInfo
* @return a set of legal values, or <code>null</code> if no such
* set exists.
*/
Set getLegalValues();
Set<?> getLegalValues();
/**
* Returns the maximum value of this parameter, or <code>null</code>
@ -101,7 +101,7 @@ public interface OpenMBeanParameterInfo
*
* @return the maximum value, or <code>null</code> if none exists.
*/
Comparable getMaxValue();
Comparable<?> getMaxValue();
/**
* Returns the minimum value of this parameter, or <code>null</code>
@ -109,7 +109,7 @@ public interface OpenMBeanParameterInfo
*
* @return the minimum value, or <code>null</code> if none exists.
*/
Comparable getMinValue();
Comparable<?> getMinValue();
/**
* Returns the name of this parameter.
@ -124,7 +124,7 @@ public interface OpenMBeanParameterInfo
*
* @return the open type of this parameter.
*/
OpenType getOpenType();
OpenType<?> getOpenType();
/**
* Returns true if this parameter has a default value.

View file

@ -1,5 +1,5 @@
/* OpenMBeanParameterInfoSupport.java -- Open typed info about a parameter.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -63,7 +63,7 @@ public class OpenMBeanParameterInfoSupport
/**
* The open type of the parameter.
*/
private OpenType openType;
private OpenType<?> openType;
/**
* The default value of the parameter (may be <code>null</code>).
@ -73,17 +73,17 @@ public class OpenMBeanParameterInfoSupport
/**
* The possible legal values of the parameter (may be <code>null</code>).
*/
private Set legalValues;
private Set<?> legalValues;
/**
* The minimum value of the parameter (may be <code>null</code>).
*/
private Comparable minValue;
private Comparable<Object> minValue;
/**
* The maximum value of the parameter (may be <code>null</code>).
*/
private Comparable maxValue;
private Comparable<Object> maxValue;
/**
* The hash code of this instance.
@ -109,7 +109,7 @@ public class OpenMBeanParameterInfoSupport
* or the name or description are
* the empty string.
*/
public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type)
public OpenMBeanParameterInfoSupport(String name, String desc, OpenType<?> type)
{
super(name, type == null ? null : type.getClassName(), desc);
if (name == null)
@ -149,8 +149,8 @@ public class OpenMBeanParameterInfoSupport
* open type or the open type is an instance
* of {@link ArrayType} or {@link TabularType}.
*/
public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type,
Object defaultValue)
public <T> OpenMBeanParameterInfoSupport(String name, String desc, OpenType<T> type,
T defaultValue)
throws OpenDataException
{
this(name, desc, type, defaultValue, null);
@ -190,9 +190,9 @@ public class OpenMBeanParameterInfoSupport
* the empty string.
* @throws OpenDataException if any condition in the list above is broken.
*/
public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type,
Object defaultValue, Comparable minimumValue,
Comparable maximumValue)
public <T> OpenMBeanParameterInfoSupport(String name, String desc, OpenType<T> type,
T defaultValue, Comparable<T> minimumValue,
Comparable<T> maximumValue)
throws OpenDataException
{
this(name, desc, type);
@ -223,8 +223,8 @@ public class OpenMBeanParameterInfoSupport
"maximum.");
this.defaultValue = defaultValue;
minValue = minimumValue;
maxValue = maximumValue;
minValue = (Comparable<Object>) minimumValue;
maxValue = (Comparable<Object>) maximumValue;
}
/**
@ -261,8 +261,8 @@ public class OpenMBeanParameterInfoSupport
* the empty string.
* @throws OpenDataException if any condition in the list above is broken.
*/
public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type,
Object defaultValue, Object[] legalValues)
public <T> OpenMBeanParameterInfoSupport(String name, String desc, OpenType<T> type,
T defaultValue, T[] legalValues)
throws OpenDataException
{
this(name, desc, type);
@ -351,7 +351,7 @@ public class OpenMBeanParameterInfoSupport
* @return a set of legal values, or <code>null</code> if no such
* set exists.
*/
public Set getLegalValues()
public Set<?> getLegalValues()
{
return legalValues;
}
@ -362,7 +362,7 @@ public class OpenMBeanParameterInfoSupport
*
* @return the maximum value, or <code>null</code> if none exists.
*/
public Comparable getMaxValue()
public Comparable<?> getMaxValue()
{
return maxValue;
}
@ -373,7 +373,7 @@ public class OpenMBeanParameterInfoSupport
*
* @return the minimum value, or <code>null</code> if none exists.
*/
public Comparable getMinValue()
public Comparable<?> getMinValue()
{
return minValue;
}
@ -384,7 +384,7 @@ public class OpenMBeanParameterInfoSupport
*
* @return the open type of this parameter.
*/
public OpenType getOpenType()
public OpenType<?> getOpenType()
{
return openType;
}

View file

@ -1,5 +1,5 @@
/* OpenType.java -- Superclass of all open types.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -39,6 +39,9 @@ package javax.management.openmbean;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
/**
* The superclass of all open types, which describe the
* applicable data values for open MBeans. An open type
@ -48,7 +51,7 @@ import java.io.Serializable;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public abstract class OpenType
public abstract class OpenType<T>
implements Serializable
{
@ -76,7 +79,10 @@ public abstract class OpenType
* An array which defines the set of Java types which can be
* used as open types. Note that each type is also available
* in array form, possibly with multiple dimensions.
*
* @deprecated Use {@link ALLOWED_CLASSNAMES_LIST} instead.
*/
@Deprecated
public static final String[] ALLOWED_CLASSNAMES = {
"java.lang.Void",
"java.lang.Boolean",
@ -96,6 +102,14 @@ public abstract class OpenType
TabularData.class.getName()
};
/**
* A list which defines the set of Java types that may be
* used as open types. Note that each type is also available
* in array form, possibly with multiple dimensions.
*/
public static final List<String> ALLOWED_CLASSNAMES_LIST =
Arrays.asList(ALLOWED_CLASSNAMES);
/**
* Constructs a new {@link OpenType} for the specified class
* with the given name and description. The name of the class
@ -126,17 +140,20 @@ public abstract class OpenType
if (desc == null || desc.equals(""))
throw new IllegalArgumentException("The description can not " +
"be null or the empty string.");
String testString;
if (className.startsWith("["))
testString = className.substring(className.indexOf("L") + 1);
else
testString = className;
boolean openTypeFound = false;
for (int a = 0; a < ALLOWED_CLASSNAMES.length; ++a)
if (ALLOWED_CLASSNAMES[a].equals(testString))
openTypeFound = true;
if (!openTypeFound)
throw new OpenDataException("The class name, " + testString +
Class<?> type;
try
{
type = Class.forName(className);
}
catch (ClassNotFoundException e)
{
throw (OpenDataException) new OpenDataException("The class name, " + className +
", is unavailable.").initCause(e);
}
while (type.isArray())
type = type.getComponentType();
if (!(type.isPrimitive() || ALLOWED_CLASSNAMES_LIST.contains(type.getName())))
throw new OpenDataException("The class name, " + className +
", does not specify a valid open type.");
this.className = className;
typeName = name;

View file

@ -1,5 +1,5 @@
/* SimpleType.java -- Open type descriptor for the base types.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -40,6 +40,13 @@ package javax.management.openmbean;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import javax.management.ObjectName;
/**
* The open type descriptor for data values that are members
* of one of the simple types (such as an integer or a string).
@ -53,94 +60,94 @@ import java.io.ObjectStreamException;
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
* @since 1.5
*/
public final class SimpleType
extends OpenType
public final class SimpleType<T>
extends OpenType<T>
{
/**
* The {@link SimpleType} representation of
* <code>java.math.BigDecimal</code>.
*/
public static final SimpleType BIGDECIMAL;
public static final SimpleType<BigDecimal> BIGDECIMAL;
/**
* The {@link SimpleType} representation of
* <code>java.math.BigInteger</code>.
*/
public static final SimpleType BIGINTEGER;
public static final SimpleType<BigInteger> BIGINTEGER;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Boolean</code>.
*/
public static final SimpleType BOOLEAN;
public static final SimpleType<Boolean> BOOLEAN;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Byte</code>.
*/
public static final SimpleType BYTE;
public static final SimpleType<Byte> BYTE;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Character</code>.
*/
public static final SimpleType CHARACTER;
public static final SimpleType<Character> CHARACTER;
/**
* The {@link SimpleType} representation of
* <code>java.util.Date</code>.
*/
public static final SimpleType DATE;
public static final SimpleType<Date> DATE;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Double</code>.
*/
public static final SimpleType DOUBLE;
public static final SimpleType<Double> DOUBLE;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Float</code>.
*/
public static final SimpleType FLOAT;
public static final SimpleType<Float> FLOAT;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Integer</code>.
*/
public static final SimpleType INTEGER;
public static final SimpleType<Integer> INTEGER;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Long</code>.
*/
public static final SimpleType LONG;
public static final SimpleType<Long> LONG;
/**
* The {@link SimpleType} representation of
* <code>javax.management.ObjectName</code>.
*/
public static final SimpleType OBJECTNAME;
public static final SimpleType<ObjectName> OBJECTNAME;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Short</code>.
*/
public static final SimpleType SHORT;
public static final SimpleType<Short> SHORT;
/**
* The {@link SimpleType} representation of
* <code>java.lang.String</code>.
*/
public static final SimpleType STRING;
public static final SimpleType<String> STRING;
/**
* The {@link SimpleType} representation of
* <code>java.lang.Void</code>.
*/
public static final SimpleType VOID;
public static final SimpleType<Void> VOID;
/**
* Compatible with JDK 1.5
@ -164,27 +171,28 @@ public final class SimpleType
{
try
{
BIGDECIMAL = new SimpleType("java.math.BigDecimal");
BIGINTEGER = new SimpleType("java.math.BigInteger");
BOOLEAN = new SimpleType("java.lang.Boolean");
BYTE = new SimpleType("java.lang.Byte");
CHARACTER = new SimpleType("java.lang.Character");
DATE = new SimpleType("java.util.Date");
DOUBLE = new SimpleType("java.lang.Double");
FLOAT = new SimpleType("java.lang.Float");
INTEGER = new SimpleType("java.lang.Integer");
LONG = new SimpleType("java.lang.Long");
OBJECTNAME = new SimpleType("javax.management.ObjectName");
SHORT = new SimpleType("java.lang.Short");
STRING = new SimpleType("java.lang.String");
VOID = new SimpleType("java.lang.Void");
BIGDECIMAL = new SimpleType<BigDecimal>("java.math.BigDecimal");
BIGINTEGER = new SimpleType<BigInteger>("java.math.BigInteger");
BOOLEAN = new SimpleType<Boolean>("java.lang.Boolean");
BYTE = new SimpleType<Byte>("java.lang.Byte");
CHARACTER = new SimpleType<Character>("java.lang.Character");
DATE = new SimpleType<Date>("java.util.Date");
DOUBLE = new SimpleType<Double>("java.lang.Double");
FLOAT = new SimpleType<Float>("java.lang.Float");
INTEGER = new SimpleType<Integer>("java.lang.Integer");
LONG = new SimpleType<Long>("java.lang.Long");
OBJECTNAME =
new SimpleType<ObjectName>("javax.management.ObjectName");
SHORT = new SimpleType<Short>("java.lang.Short");
STRING = new SimpleType<String>("java.lang.String");
VOID = new SimpleType<Void>("java.lang.Void");
}
catch (OpenDataException e)
{
/* In normal circumstances, this shouldn't be possible. */
throw new IllegalStateException("A invalid class name " +
"was passed to the SimpleType " +
"constructor.");
"constructor.", e);
}
}

View file

@ -1,5 +1,5 @@
/* TabularData.java -- Tables of composite data structures.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -165,7 +165,7 @@ public interface TabularData
*
* @return a set containing the keys of this instance.
*/
Set keySet();
Set<?> keySet();
/**
* Adds the specified {@link CompositeData} value to the
@ -253,7 +253,7 @@ public interface TabularData
*
* @return the values of this instance.
*/
Collection values();
Collection<?> values();
}

View file

@ -1,5 +1,5 @@
/* TabularDataSupport.java -- Tables of composite data structures.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -55,7 +55,7 @@ import java.util.Set;
* @since 1.5
*/
public class TabularDataSupport
implements TabularData, Serializable, Cloneable, Map
implements TabularData, Serializable, Cloneable, Map<Object,Object>
{
/**
@ -68,7 +68,7 @@ public class TabularDataSupport
*
* @serial the map of rows to column values.
*/
private Map dataMap;
private Map<Object,Object> dataMap;
/**
* The tabular type which represents this tabular data instance.
@ -113,7 +113,7 @@ public class TabularDataSupport
if (type == null)
throw new IllegalArgumentException("The type may not be null.");
tabularType = type;
dataMap = new HashMap(cap, lf);
dataMap = new HashMap<Object,Object>(cap, lf);
}
/**
@ -279,7 +279,7 @@ public class TabularDataSupport
* @return the set view of all mapping entries
* @see java.util.Map.Entry
*/
public Set entrySet()
public Set<Map.Entry<Object,Object>> entrySet()
{
return dataMap.entrySet();
}
@ -413,7 +413,7 @@ public class TabularDataSupport
*
* @return the set view of all keys
*/
public Set keySet()
public Set<Object> keySet()
{
return dataMap.keySet();
}
@ -535,7 +535,7 @@ public class TabularDataSupport
* of one of the other
* specified values.
*/
public void putAll(Map m)
public void putAll(Map<?,?> m)
{
if (m == null || m.size() == 0)
return;
@ -643,7 +643,7 @@ public class TabularDataSupport
*
* @return the collection view of all values
*/
public Collection values()
public Collection<Object> values()
{
return dataMap.values();
}

View file

@ -1,5 +1,5 @@
/* TabularType.java -- Type descriptor for TabularData instances.
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -50,7 +50,7 @@ import java.util.List;
* @since 1.5
*/
public class TabularType
extends OpenType
extends OpenType<TabularData>
{
/**
@ -68,7 +68,7 @@ public class TabularType
* They are retained in the order given by the user, and is
* unmodifiable.
*/
private List indexNames;
private List<String> indexNames;
/**
* The hash code of this instance.
@ -167,7 +167,7 @@ public class TabularType
* @return an unmodifiable list of the index names used by this
* tabular data structure.
*/
public List getIndexNames()
public List<String> getIndexNames()
{
return indexNames;
}

View file

@ -58,16 +58,16 @@ public class CompositeName implements Name, Cloneable, Serializable
{
private static final long serialVersionUID = 1667768148915813118L;
private transient Vector elts;
private transient Vector<String> elts;
public CompositeName ()
{
elts = new Vector ();
elts = new Vector<String> ();
}
protected CompositeName (Enumeration<String> comps)
{
elts = new Vector ();
elts = new Vector<String> ();
try
{
while (comps.hasMoreElements ())
@ -80,7 +80,7 @@ public class CompositeName implements Name, Cloneable, Serializable
public CompositeName (String n) throws InvalidNameException
{
elts = new Vector ();
elts = new Vector<String> ();
// Parse the string into its components.
final char no_quote = 'x'; // Use 'x' to mean no quoting.
char quote = no_quote;
@ -151,7 +151,7 @@ public class CompositeName implements Name, Cloneable, Serializable
public Name addAll (int posn, Name n) throws InvalidNameException
{
Enumeration e = n.getAll ();
Enumeration<String> e = n.getAll ();
try
{
while (e.hasMoreElements ())
@ -168,7 +168,7 @@ public class CompositeName implements Name, Cloneable, Serializable
public Name addAll (Name suffix) throws InvalidNameException
{
Enumeration e = suffix.getAll ();
Enumeration<String> e = suffix.getAll ();
try
{
while (e.hasMoreElements ())
@ -193,8 +193,8 @@ public class CompositeName implements Name, Cloneable, Serializable
int last = Math.min (cn.elts.size (), elts.size ());
for (int i = 0; i < last; ++i)
{
String f = (String) elts.get (i);
int comp = f.compareTo ((String) cn.elts.get (i));
String f = elts.get (i);
int comp = f.compareTo (cn.elts.get (i));
if (comp != 0)
return comp;
}
@ -227,7 +227,7 @@ public class CompositeName implements Name, Cloneable, Serializable
public String get (int posn)
{
return (String) elts.get (posn);
return elts.get (posn);
}
public Enumeration<String> getAll ()
@ -239,7 +239,7 @@ public class CompositeName implements Name, Cloneable, Serializable
{
CompositeName cn = new CompositeName ();
for (int i = 0; i < posn; ++i)
cn.elts.add ((String) elts.get (i));
cn.elts.add (elts.get (i));
return cn;
}
@ -249,7 +249,7 @@ public class CompositeName implements Name, Cloneable, Serializable
throw new ArrayIndexOutOfBoundsException (posn);
CompositeName cn = new CompositeName ();
for (int i = posn; i < elts.size (); ++i)
cn.elts.add ((String) elts.get (i));
cn.elts.add (elts.get (i));
return cn;
}
@ -299,7 +299,7 @@ public class CompositeName implements Name, Cloneable, Serializable
{
// For simplicity we choose to always quote using escapes and
// never quotes.
String elt = (String) elts.get (i);
String elt = elts.get (i);
if (i > 0
|| (i == elts.size () - 1 && elt.equals ("")))
result.append ('/');
@ -327,9 +327,9 @@ public class CompositeName implements Name, Cloneable, Serializable
throws IOException, ClassNotFoundException
{
int size = s.readInt();
elts = new Vector(size);
elts = new Vector<String>(size);
for (int i = 0; i < size; i++)
elts.add(s.readObject());
elts.add((String) s.readObject());
}
private void writeObject(ObjectOutputStream s) throws IOException

View file

@ -68,14 +68,14 @@ public class CompoundName implements Name, Cloneable, Serializable
private CompoundName (Properties syntax)
{
elts = new Vector ();
elts = new Vector<String> ();
mySyntax = syntax;
initializeSyntax ();
}
protected CompoundName (Enumeration<String> comps, Properties syntax)
{
elts = new Vector ();
elts = new Vector<String> ();
mySyntax = syntax;
initializeSyntax ();
try
@ -91,7 +91,7 @@ public class CompoundName implements Name, Cloneable, Serializable
public CompoundName (String n, Properties syntax)
throws InvalidNameException
{
elts = new Vector ();
elts = new Vector<String> ();
mySyntax = syntax;
initializeSyntax ();
@ -186,7 +186,7 @@ public class CompoundName implements Name, Cloneable, Serializable
int len = elts.size ();
for (i = 0; i < len / 2; ++i)
{
Object t = elts.set (i, elts.get (len - i - 1));
String t = elts.set (i, elts.get (len - i - 1));
elts.set (len - i - 1, t);
}
}
@ -210,7 +210,7 @@ public class CompoundName implements Name, Cloneable, Serializable
public Name addAll (int posn, Name n) throws InvalidNameException
{
Enumeration e = n.getAll ();
Enumeration<String> e = n.getAll ();
try
{
while (e.hasMoreElements ())
@ -227,7 +227,7 @@ public class CompoundName implements Name, Cloneable, Serializable
public Name addAll (Name suffix) throws InvalidNameException
{
Enumeration e = suffix.getAll ();
Enumeration<String> e = suffix.getAll ();
try
{
while (e.hasMoreElements ())
@ -252,8 +252,8 @@ public class CompoundName implements Name, Cloneable, Serializable
int last = Math.min (cn.elts.size (), elts.size ());
for (int i = 0; i < last; ++i)
{
String f = canonicalize ((String) elts.get (i));
int comp = f.compareTo (canonicalize ((String) cn.elts.get (i)));
String f = canonicalize (elts.get (i));
int comp = f.compareTo (canonicalize (cn.elts.get (i)));
if (comp != 0)
return comp;
}
@ -270,8 +270,8 @@ public class CompoundName implements Name, Cloneable, Serializable
int delta = elts.size () - cn.elts.size ();
for (int i = 0; i < cn.elts.size (); ++i)
{
String f = canonicalize ((String) elts.get (delta + i));
if (! f.equals (canonicalize ((String) cn.elts.get (i))))
String f = canonicalize (elts.get (delta + i));
if (! f.equals (canonicalize (cn.elts.get (i))))
return false;
}
return true;
@ -286,7 +286,7 @@ public class CompoundName implements Name, Cloneable, Serializable
public String get (int posn)
{
return (String) elts.get (posn);
return elts.get (posn);
}
public Enumeration<String> getAll ()
@ -316,7 +316,7 @@ public class CompoundName implements Name, Cloneable, Serializable
{
int h = 0;
for (int i = 0; i < elts.size (); ++i)
h += canonicalize ((String) elts.get (i)).hashCode ();
h += canonicalize (elts.get (i)).hashCode ();
return h;
}
@ -344,8 +344,8 @@ public class CompoundName implements Name, Cloneable, Serializable
return false;
for (int i = 0; i < cn.elts.size (); ++i)
{
String f = canonicalize ((String) elts.get (i));
if (! f.equals (canonicalize ((String) cn.elts.get (i))))
String f = canonicalize (elts.get (i));
if (! f.equals (canonicalize (cn.elts.get (i))))
return false;
}
return true;
@ -383,7 +383,7 @@ public class CompoundName implements Name, Cloneable, Serializable
// Find the appropriate element. FIXME: not clear what FLAT
// means.
int offset = (direction == RIGHT_TO_LEFT) ? (size - i - 1) : i;
String element = (String) elts.get (offset);
String element = elts.get (offset);
if (i > 0
|| (i == size - 1 && element.equals ("")))
result.append (separator);
@ -478,7 +478,7 @@ public class CompoundName implements Name, Cloneable, Serializable
{
mySyntax = (Properties) s.readObject();
int count = s.readInt();
elts = new Vector(count);
elts = new Vector<String>(count);
for (int i = 0; i < count; i++)
elts.addElement((String) s.readObject());
}
@ -499,7 +499,7 @@ public class CompoundName implements Name, Cloneable, Serializable
protected transient Properties mySyntax;
// The actual elements.
private transient Vector elts;
private transient Vector<String> elts;
// The following are all used for syntax.
private transient int direction;

View file

@ -80,14 +80,14 @@ public class InitialContext implements Context
* be appended after the colon to the first possible value. Used in
* {@link #merge(Hashtable, Hashtable)}
*/
static final HashSet colon_list;
static final HashSet<String> colon_list;
static
{
colon_list = new HashSet();
colon_list = new HashSet<String>();
colon_list.add(Context.OBJECT_FACTORIES);
colon_list.add(Context.URL_PKG_PREFIXES);
colon_list.add(Context.STATE_FACTORIES);
};
}
/**
* The properties that are searched in the agreed places in the
@ -262,7 +262,8 @@ public class InitialContext implements Context
* in this table.
* @param additional the second table, from where additional values are taken
*/
static void merge (Hashtable primary, Hashtable additional)
static void merge (Hashtable<Object, Object> primary,
Hashtable<Object, Object> additional)
{
Enumeration en = additional.keys();

View file

@ -83,7 +83,7 @@ public class Reference implements Cloneable, Serializable
public Reference (String className)
{
this.className = className;
addrs = new Vector ();
addrs = new Vector<RefAddr> ();
}
/**
@ -93,7 +93,7 @@ public class Reference implements Cloneable, Serializable
public Reference (String className, RefAddr addr)
{
this.className = className;
addrs = new Vector ();
addrs = new Vector<RefAddr> ();
addrs.add (addr);
}
@ -112,7 +112,7 @@ public class Reference implements Cloneable, Serializable
this.className = className;
this.classFactory = factoryClassName;
this.classFactoryLocation = factoryLocation;
addrs = new Vector ();
addrs = new Vector<RefAddr> ();
}
/**
@ -131,7 +131,7 @@ public class Reference implements Cloneable, Serializable
this.className = className;
this.classFactory = factoryClassName;
this.classFactoryLocation = factoryLocation;
addrs = new Vector ();
addrs = new Vector<RefAddr> ();
addrs.add (addr);
}
@ -164,7 +164,7 @@ public class Reference implements Cloneable, Serializable
{
Reference r = new Reference (className, classFactory,
classFactoryLocation);
r.addrs = (Vector) addrs.clone ();
r.addrs = (Vector<RefAddr>) addrs.clone ();
return r;
}
@ -193,7 +193,7 @@ public class Reference implements Cloneable, Serializable
*/
public RefAddr get (int posn)
{
return (RefAddr) addrs.get (posn);
return addrs.get (posn);
}
/**
@ -208,7 +208,7 @@ public class Reference implements Cloneable, Serializable
{
for (int i = 0; i < addrs.size (); ++i)
{
RefAddr r = (RefAddr) addrs.get (i);
RefAddr r = addrs.get (i);
if (addrType.equals (r.getType ()))
return r;
}

View file

@ -78,7 +78,7 @@ public class BasicAttribute implements Attribute
{
attrID = id;
this.ordered = ordered;
values = new Vector ();
values = new Vector<Object> ();
}
public BasicAttribute (String id, Object value)
@ -90,7 +90,7 @@ public class BasicAttribute implements Attribute
{
attrID = id;
this.ordered = ordered;
values = new Vector ();
values = new Vector<Object> ();
values.add (value);
}
@ -118,7 +118,7 @@ public class BasicAttribute implements Attribute
BasicAttribute c = new BasicAttribute ();
c.attrID = attrID;
c.ordered = ordered;
c.values = (Vector) values.clone ();
c.values = (Vector<Object>) values.clone ();
return c;
}
@ -307,7 +307,7 @@ public class BasicAttribute implements Attribute
{
s.defaultReadObject();
int size = s.readInt();
values = new Vector(size);
values = new Vector<Object>(size);
for (int i=0; i < size; i++)
values.add(s.readObject());
}

View file

@ -63,7 +63,7 @@ public class BasicAttributes implements Attributes
public BasicAttributes (boolean ignoreCase)
{
this.ignoreCase = ignoreCase;
this.attributes = new Vector ();
this.attributes = new Vector<Attribute>();
}
public BasicAttributes (String attrID, Object val)
@ -74,7 +74,7 @@ public class BasicAttributes implements Attributes
public BasicAttributes (String attrID, Object val, boolean ignoreCase)
{
this.ignoreCase = ignoreCase;
attributes = new Vector ();
attributes = new Vector<Attribute>();
attributes.add (new BasicAttribute (attrID, val));
}
@ -82,7 +82,7 @@ public class BasicAttributes implements Attributes
{
// Slightly inefficient as we make a garbage Vector here.
BasicAttributes ba = new BasicAttributes (ignoreCase);
ba.attributes = (Vector) attributes.clone ();
ba.attributes = (Vector<Attribute>) attributes.clone ();
return ba;
}
@ -117,7 +117,7 @@ public class BasicAttributes implements Attributes
{
for (int i = 0; i < attributes.size (); ++i)
{
Attribute at = (Attribute) attributes.get (i);
Attribute at = attributes.get (i);
if ((ignoreCase && attrID.equalsIgnoreCase (at.getID ()))
|| (! ignoreCase && attrID.equals (at.getID ())))
return at;
@ -128,12 +128,38 @@ public class BasicAttributes implements Attributes
public NamingEnumeration<Attribute> getAll ()
{
return new BasicAttributesEnumeration (false);
return new BasicAttributesEnumeration();
}
public NamingEnumeration<String> getIDs ()
{
return new BasicAttributesEnumeration (true);
final NamingEnumeration<Attribute> attrs = getAll();
return new NamingEnumeration<String>() {
public boolean hasMore() throws NamingException
{
return attrs.hasMore();
}
public boolean hasMoreElements()
{
return attrs.hasMoreElements();
}
public String next() throws NamingException
{
return attrs.next().getID();
}
public String nextElement()
{
return attrs.nextElement().getID();
}
public void close() throws NamingException
{
attrs.close();
}
};
}
public int hashCode ()
@ -197,16 +223,16 @@ public class BasicAttributes implements Attributes
// This is set by the serialization spec.
private boolean ignoreCase;
// Package-private to avoid a trampoline.
transient Vector attributes;
transient Vector<Attribute> attributes;
private void readObject(ObjectInputStream s) throws IOException,
ClassNotFoundException
{
s.defaultReadObject();
int size = s.readInt();
attributes = new Vector(size);
attributes = new Vector<Attribute>(size);
for (int i = 0; i < size; i++)
attributes.add(s.readObject());
attributes.add((Attribute) s.readObject());
}
private void writeObject(ObjectOutputStream s) throws IOException
@ -218,14 +244,13 @@ public class BasicAttributes implements Attributes
}
// Used when enumerating.
private class BasicAttributesEnumeration implements NamingEnumeration
private class BasicAttributesEnumeration
implements NamingEnumeration<Attribute>
{
int where = 0;
boolean id;
public BasicAttributesEnumeration (boolean id)
public BasicAttributesEnumeration ()
{
this.id = id;
}
public void close () throws NamingException
@ -237,7 +262,7 @@ public class BasicAttributes implements Attributes
return hasMoreElements ();
}
public Object next () throws NamingException
public Attribute next () throws NamingException
{
return nextElement ();
}
@ -247,13 +272,13 @@ public class BasicAttributes implements Attributes
return where < attributes.size ();
}
public Object nextElement () throws NoSuchElementException
public Attribute nextElement () throws NoSuchElementException
{
if (where >= attributes.size ())
throw new NoSuchElementException ("no more elements");
Attribute at = (Attribute) attributes.get (where);
Attribute at = attributes.get (where);
++where;
return id ? (Object) at.getID () : (Object) at;
return at;
}
}
}

View file

@ -66,13 +66,13 @@ public class InitialLdapContext
{
super (false);
Hashtable myenv = null;
Hashtable<Object, Object> myenv = null;
if (connControls != null)
{
if (environment == null)
myenv = new Hashtable ();
myenv = new Hashtable<Object, Object> ();
else
myenv = (Hashtable) environment.clone ();
myenv = (Hashtable<Object, Object>) environment.clone ();
myenv.put ("java.naming.ldap.control.connect",
connControls);
}

View file

@ -41,15 +41,14 @@ package javax.naming.spi;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.NotContextException;
/**
+ * <p>Represents the object, capable for the at least partial name resolution.
+ * The object is not necessay capable for the complete name resolution and
+ * need not implement the {@link Context}.</p>
+ * <p>
+ * Both passed parameters and returned results are owned by the caller.</p>
+ *
* <p>Represents the object, capable for the at least partial name resolution.
* The object is not necessay capable for the complete name resolution and
* need not implement the {@link Context}.</p>
* <p>
* Both passed parameters and returned results are owned by the caller.</p>
*
* @author Warren Levy (warrenl@redhat.com)
*/
public interface Resolver

View file

@ -38,6 +38,9 @@ exception statement from your version. */
package javax.net.ssl;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.security.KeyStore;
import java.security.Security;
@ -138,8 +141,9 @@ public abstract class SSLServerSocketFactory extends ServerSocketFactory
}
catch (Exception ex)
{
throw new RuntimeException("error instantiating default server socket factory: "
+ ex.toString());
return new ErrorServerSocketFactory(new RuntimeException(
"error instantiating default server socket factory: "
+ ex.toString(), ex));
}
}
try
@ -149,7 +153,52 @@ public abstract class SSLServerSocketFactory extends ServerSocketFactory
catch (Exception e)
{
}
throw new RuntimeException("no SSLSocketFactory implementation available");
return new ErrorServerSocketFactory(new RuntimeException(
"no SSLSocketFactory implementation available"));
}
private static final class ErrorServerSocketFactory
extends SSLServerSocketFactory
{
private RuntimeException x;
ErrorServerSocketFactory(RuntimeException x)
{
this.x = x;
}
public ServerSocket createServerSocket() throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public ServerSocket createServerSocket(int port) throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public ServerSocket createServerSocket(int port, int backlog)
throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public ServerSocket createServerSocket(int port, int backlog,
InetAddress ifAddress)
throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public String[] getDefaultCipherSuites()
{
throw new RuntimeException(x);
}
public String[] getSupportedCipherSuites()
{
throw new RuntimeException(x);
}
}
// Abstract methods.

View file

@ -39,6 +39,7 @@ exception statement from your version. */
package javax.net.ssl;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.KeyStore;
import java.security.Security;
@ -141,8 +142,9 @@ public abstract class SSLSocketFactory extends SocketFactory
}
catch (Exception ex)
{
throw new RuntimeException("error instantiating default socket factory: "
+ ex.toString(), ex);
return new ErrorSocketFactory(new RuntimeException(
"error instantiating default socket factory: " + ex.toString(),
ex));
}
}
try
@ -152,7 +154,65 @@ public abstract class SSLSocketFactory extends SocketFactory
catch (Exception e)
{
}
throw new RuntimeException("no SSLSocketFactory implementation available");
return new ErrorSocketFactory(new RuntimeException(
"no SSLSocketFactory implementation available"));
}
private static final class ErrorSocketFactory extends SSLSocketFactory
{
private RuntimeException x;
ErrorSocketFactory(RuntimeException x)
{
this.x = x;
}
public Socket createSocket() throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public Socket createSocket(String host, int port)
throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public Socket createSocket(String host, int port, InetAddress localHost,
int localPort)
throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public Socket createSocket(InetAddress host, int port) throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public Socket createSocket(InetAddress hast, int port, InetAddress localHost,
int localPort)
throws IOException
{
throw (IOException) new IOException().initCause(x);
}
public String[] getDefaultCipherSuites()
{
throw new RuntimeException(x);
}
public String[] getSupportedCipherSuites()
{
throw new RuntimeException(x);
}
public Socket createSocket(Socket s, String host, int port,
boolean autoClose)
throws IOException
{
throw new RuntimeException(x);
}
}
// Abstract methods.

View file

@ -122,7 +122,7 @@ public class AudioFileFormat
private AudioFormat format;
private Type type;
private int frameLength;
private Map properties;
private Map<String, Object> properties;
/**
* Create a new AudioFileFormat given the type, the format, and the
@ -138,7 +138,7 @@ public class AudioFileFormat
this.format = fmt;
this.type = type;
this.frameLength = frameLen;
this.properties = Collections.EMPTY_MAP;
this.properties = Collections.<String, Object> emptyMap();
}
/**
@ -159,7 +159,7 @@ public class AudioFileFormat
this.format = fmt;
this.type = type;
this.frameLength = frameLen;
this.properties = Collections.unmodifiableMap(new HashMap(properties));
this.properties = Collections.unmodifiableMap(new HashMap<String, Object>(properties));
}
/**
@ -177,7 +177,7 @@ public class AudioFileFormat
this.format = fmt;
this.type = type;
this.frameLength = frameLen;
this.properties = Collections.EMPTY_MAP;
this.properties = Collections.<String, Object> emptyMap();
}
/**

View file

@ -133,7 +133,7 @@ public class AudioFormat
*/
protected int sampleSizeInBits;
private Map properties;
private Map<String, Object> properties;
/**
* Create a new audio format, given various attributes of it.
@ -158,7 +158,7 @@ public class AudioFormat
this.frameSize = frameSize;
this.frameRate = frameRate;
this.bigEndian = bigEndian;
this.properties = Collections.EMPTY_MAP;
this.properties = Collections.<String, Object> emptyMap();
}
/**
@ -186,7 +186,7 @@ public class AudioFormat
this.frameSize = frameSize;
this.frameRate = frameRate;
this.bigEndian = bigEndian;
this.properties = Collections.unmodifiableMap(new HashMap(properties));
this.properties = Collections.unmodifiableMap(new HashMap<String, Object>(properties));
}
/**
@ -218,7 +218,7 @@ public class AudioFormat
this.frameSize = (sampleSizeInBits + 7) / 8 * channels;
this.frameRate = sampleRate;
this.bigEndian = bigEndian;
this.properties = Collections.EMPTY_MAP;
this.properties = Collections.<String, Object> emptyMap();
}
/**

View file

@ -160,7 +160,8 @@ public class AudioSystem
*/
public static AudioFileFormat.Type[] getAudioFileTypes()
{
HashSet result = new HashSet();
HashSet<AudioFileFormat.Type> result
= new HashSet<AudioFileFormat.Type>();
Iterator i = ServiceFactory.lookupProviders(AudioFileWriter.class);
while (i.hasNext())
{
@ -169,7 +170,7 @@ public class AudioSystem
for (int j = 0; j < types.length; ++j)
result.add(types[j]);
}
return (AudioFileFormat.Type[]) result.toArray(new AudioFileFormat.Type[result.size()]);
return result.toArray(new AudioFileFormat.Type[result.size()]);
}
/**
@ -180,7 +181,8 @@ public class AudioSystem
*/
public static AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream ais)
{
HashSet result = new HashSet();
HashSet<AudioFileFormat.Type> result
= new HashSet<AudioFileFormat.Type>();
Iterator i = ServiceFactory.lookupProviders(AudioFileWriter.class);
while (i.hasNext())
{
@ -189,7 +191,7 @@ public class AudioSystem
for (int j = 0; j < types.length; ++j)
result.add(types[j]);
}
return (AudioFileFormat.Type[]) result.toArray(new AudioFileFormat.Type[result.size()]);
return result.toArray(new AudioFileFormat.Type[result.size()]);
}
/**
@ -204,7 +206,6 @@ public class AudioSystem
public static AudioInputStream getAudioInputStream(AudioFormat.Encoding targ,
AudioInputStream ais)
{
HashSet result = new HashSet();
Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);
while (i.hasNext())
{
@ -228,7 +229,6 @@ public class AudioSystem
public static AudioInputStream getAudioInputStream(AudioFormat targ,
AudioInputStream ais)
{
HashSet result = new HashSet();
Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);
while (i.hasNext())
{
@ -416,7 +416,7 @@ public class AudioSystem
*/
public static Mixer.Info[] getMixerInfo()
{
HashSet result = new HashSet();
HashSet<Mixer.Info> result = new HashSet<Mixer.Info>();
Iterator i = ServiceFactory.lookupProviders(MixerProvider.class);
while (i.hasNext())
{
@ -425,7 +425,7 @@ public class AudioSystem
for (int j = 0; j < is.length; ++j)
result.add(is[j]);
}
return (Mixer.Info[]) result.toArray(new Mixer.Info[result.size()]);
return result.toArray(new Mixer.Info[result.size()]);
}
/**
@ -474,7 +474,7 @@ public class AudioSystem
*/
public static Line.Info[] getSourceLineInfo(Line.Info info)
{
HashSet result = new HashSet();
HashSet<Line.Info> result = new HashSet<Line.Info>();
Mixer.Info[] infos = getMixerInfo();
for (int i = 0; i < infos.length; ++i)
{
@ -483,7 +483,7 @@ public class AudioSystem
for (int j = 0; j < srcs.length; ++j)
result.add(srcs[j]);
}
return (Line.Info[]) result.toArray(new Line.Info[result.size()]);
return result.toArray(new Line.Info[result.size()]);
}
/**
@ -534,7 +534,8 @@ public class AudioSystem
*/
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding source)
{
HashSet result = new HashSet();
HashSet<AudioFormat.Encoding> result
= new HashSet<AudioFormat.Encoding>();
Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);
while (i.hasNext())
{
@ -545,7 +546,7 @@ public class AudioSystem
for (int j = 0; j < es.length; ++j)
result.add(es[j]);
}
return (AudioFormat.Encoding[]) result.toArray(new AudioFormat.Encoding[result.size()]);
return result.toArray(new AudioFormat.Encoding[result.size()]);
}
/**
@ -555,7 +556,8 @@ public class AudioSystem
*/
public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat source)
{
HashSet result = new HashSet();
HashSet<AudioFormat.Encoding> result
= new HashSet<AudioFormat.Encoding>();
Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);
while (i.hasNext())
{
@ -564,7 +566,7 @@ public class AudioSystem
for (int j = 0; j < es.length; ++j)
result.add(es[j]);
}
return (AudioFormat.Encoding[]) result.toArray(new AudioFormat.Encoding[result.size()]);
return result.toArray(new AudioFormat.Encoding[result.size()]);
}
/**
@ -576,7 +578,7 @@ public class AudioSystem
public static AudioFormat[] getTargetFormats(AudioFormat.Encoding encoding,
AudioFormat sourceFmt)
{
HashSet result = new HashSet();
HashSet<AudioFormat> result = new HashSet<AudioFormat>();
Iterator i = ServiceFactory.lookupProviders(FormatConversionProvider.class);
while (i.hasNext())
{
@ -585,7 +587,7 @@ public class AudioSystem
for (int j = 0; j < es.length; ++j)
result.add(es[j]);
}
return (AudioFormat[]) result.toArray(new AudioFormat[result.size()]);
return result.toArray(new AudioFormat[result.size()]);
}
/**
@ -595,7 +597,7 @@ public class AudioSystem
*/
public static Line.Info[] getTargetLineInfo(Line.Info info)
{
HashSet result = new HashSet();
HashSet<Line.Info> result = new HashSet<Line.Info>();
Mixer.Info[] infos = getMixerInfo();
for (int i = 0; i < infos.length; ++i)
{
@ -604,7 +606,7 @@ public class AudioSystem
for (int j = 0; j < targs.length; ++j)
result.add(targs[j]);
}
return (Line.Info[]) result.toArray(new Line.Info[result.size()]);
return result.toArray(new Line.Info[result.size()]);
}
/**

View file

@ -72,7 +72,6 @@ public abstract class BooleanControl extends Control
}
}
private Type type;
private boolean value;
private String trueLabel;
private String falseLabel;

View file

@ -293,21 +293,35 @@ public class DefaultDesktopManager implements DesktopManager, Serializable
public void activateFrame(JInternalFrame frame)
{
JDesktopPane p = frame.getDesktopPane();
JInternalFrame active = null;
if (p != null)
p.setSelectedFrame(frame);
else
active = p.getSelectedFrame();
if (active == null)
{
try
if (p != null)
{
frame.setSelected(true);
}
catch (PropertyVetoException e)
{
// Do nothing if attempt is vetoed.
p.setSelectedFrame(frame);
}
}
else if (active != frame)
{
if (active.isSelected())
{
try
{
active.setSelected(false);
}
catch (PropertyVetoException ex)
{
// Not allowed.
}
}
if (p != null)
{
p.setSelectedFrame(frame);
}
}
frame.toFront();
}

View file

@ -1021,21 +1021,6 @@ public abstract class JComponent extends Container implements Serializable
super.firePropertyChange(property, oldValue, newValue);
}
/**
* Fires a property change for a primitive character property.
*
* @param property the name of the property
* @param oldValue the old value of the property
* @param newValue the new value of the property
*/
public void firePropertyChange(String property, char oldValue,
char newValue)
{
// FIXME - This method is already public in awt Component, but
// is included here to work around a compilation bug in gcj 4.1.
super.firePropertyChange(property, oldValue, newValue);
}
/**
* Get the value of the accessibleContext property for this component.
*
@ -1942,7 +1927,8 @@ public abstract class JComponent extends Container implements Serializable
int i = getComponentCount() - 1;
if (paintChild != null && paintChild.isOpaque())
{
for (; i >= 0 && getComponent(i) != paintChild; i--);
for (; i >= 0 && getComponent(i) != paintChild; i--)
;
}
for (; i >= 0; i--)
{
@ -2203,7 +2189,8 @@ public abstract class JComponent extends Container implements Serializable
{
int count = c.getComponentCount();
int i = 0;
for (; i < count && c.getComponent(i) != child; i++);
for (; i < count && c.getComponent(i) != child; i++)
;
if (jc.isCompletelyObscured(i, paintX, paintY, paintW,
paintH))

View file

@ -712,7 +712,7 @@ public class JEditorPane extends JTextComponent
public JEditorPane(URL url) throws IOException
{
init();
setEditorKit(createEditorKitForContentType("text/html"));;
setEditorKit(createEditorKitForContentType("text/html"));
setPage(url);
}

View file

@ -415,7 +415,7 @@ public class JFormattedTextField extends JTextField
// to create a new formatter.
Object oldValue = this.value;
this.value = formatter.stringToValue(getText());;
this.value = formatter.stringToValue(getText());
editValid = true;
firePropertyChange("value", oldValue, this.value);

View file

@ -371,7 +371,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/
public int getUnitIncrement(int direction)
{
return direction * unitIncrement;
return unitIncrement;
}
/**
@ -401,7 +401,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/
public int getBlockIncrement(int direction)
{
return direction * blockIncrement;
return blockIncrement;
}
/**

View file

@ -181,7 +181,7 @@ public class JToolTip extends JComponent implements Accessible
{
StringBuffer sb = new StringBuffer(super.paramString());
sb.append(",tiptext=");
if (text != null);
if (text != null)
sb.append(text);
return sb.toString();
}

View file

@ -574,8 +574,12 @@ public class JViewport extends JComponent implements Accessible
Component view = getView();
if (view == null)
return;
Point pos = getViewPosition();
// We get the contentRect in the viewport coordinates. But we want to
// calculate with view coordinates.
int contentX = contentRect.x + pos.x;
int contentY = contentRect.y + pos.y;
Rectangle viewBounds = getView().getBounds();
Rectangle portBounds = getBounds();
@ -584,20 +588,20 @@ public class JViewport extends JComponent implements Accessible
// If the bottom boundary of contentRect is below the port
// boundaries, scroll up as necessary.
if (contentRect.y + contentRect.height + viewBounds.y > portBounds.height)
pos.y = contentRect.y + contentRect.height - portBounds.height;
// If contentRect.y is above the port boundaries, scroll down to
// contentRect.y.
if (contentRect.y + viewBounds.y < 0)
pos.y = contentRect.y;
if (contentY + contentRect.height + viewBounds.y > portBounds.height)
pos.y = contentY + contentRect.height - portBounds.height;
// If contentY is above the port boundaries, scroll down to
// contentY.
if (contentY + viewBounds.y < 0)
pos.y = contentY;
// If the right boundary of contentRect is right from the port
// boundaries, scroll left as necessary.
if (contentRect.x + contentRect.width + viewBounds.x > portBounds.width)
pos.x = contentRect.x + contentRect.width - portBounds.width;
// If contentRect.x is left from the port boundaries, scroll right to
if (contentX + contentRect.width + viewBounds.x > portBounds.width)
pos.x = contentX + contentRect.width - portBounds.width;
// If contentX is left from the port boundaries, scroll right to
// contentRect.x.
if (contentRect.x + viewBounds.x < 0)
pos.x = contentRect.x;
if (contentX + viewBounds.x < 0)
pos.x = contentX;
setViewPosition(pos);
}
@ -834,7 +838,7 @@ public class JViewport extends JComponent implements Accessible
int dy = viewPosition.y - lastPaintPosition.y;
boolean canBlit = computeBlit(dx, dy, cachedBlitFrom, cachedBlitTo,
cachedBlitSize, cachedBlitPaint);
if (canBlit)
if (canBlit && isPaintRoot)
{
// Copy the part that remains visible during scrolling.
if (cachedBlitSize.width > 0 && cachedBlitSize.height > 0)

View file

@ -38,15 +38,23 @@ exception statement from your version. */
package javax.swing;
import gnu.classpath.NotImplementedException;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceContext;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@ -210,7 +218,101 @@ public class TransferHandler implements Serializable
}
}
}
private static class SwingDragGestureRecognizer extends DragGestureRecognizer
{
protected SwingDragGestureRecognizer(DragGestureListener dgl)
{
super(DragSource.getDefaultDragSource(), null, NONE, dgl);
}
void gesture(JComponent c, MouseEvent e, int src, int drag)
{
setComponent(c);
setSourceActions(src);
appendEvent(e);
fireDragGestureRecognized(drag, e.getPoint());
}
protected void registerListeners()
{
// Nothing to do here.
}
protected void unregisterListeners()
{
// Nothing to do here.
}
}
private static class SwingDragHandler
implements DragGestureListener, DragSourceListener
{
private boolean autoscrolls;
public void dragGestureRecognized(DragGestureEvent e)
{
JComponent c = (JComponent) e.getComponent();
TransferHandler th = c.getTransferHandler();
Transferable t = th.createTransferable(c);
if (t != null)
{
autoscrolls = c.getAutoscrolls();
c.setAutoscrolls(false);
try
{
e.startDrag(null, t, this);
return;
}
finally
{
c.setAutoscrolls(autoscrolls);
}
}
th.exportDone(c, t, NONE);
}
public void dragDropEnd(DragSourceDropEvent e)
{
DragSourceContext ctx = e.getDragSourceContext();
JComponent c = (JComponent) ctx.getComponent();
TransferHandler th = c.getTransferHandler();
if (e.getDropSuccess())
{
th.exportDone(c, ctx.getTransferable(), e.getDropAction());
}
else
{
th.exportDone(c, ctx.getTransferable(), e.getDropAction());
}
c.setAutoscrolls(autoscrolls);
}
public void dragEnter(DragSourceDragEvent e)
{
// Nothing to do here.
}
public void dragExit(DragSourceEvent e)
{
// Nothing to do here.
}
public void dragOver(DragSourceDragEvent e)
{
// Nothing to do here.
}
public void dropActionChanged(DragSourceDragEvent e)
{
// Nothing to do here.
}
}
private static final long serialVersionUID = -967749805571669910L;
private static final String COMMAND_COPY = "copy";
@ -235,6 +337,11 @@ public class TransferHandler implements Serializable
*/
private String propertyName;
/**
* The DragGestureRecognizer for Swing.
*/
private SwingDragGestureRecognizer recognizer;
public static Action getCopyAction()
{
return copyAction;
@ -331,10 +438,27 @@ public class TransferHandler implements Serializable
return transferable;
}
public void exportAsDrag(JComponent c, InputEvent e, int action)
throws NotImplementedException
public void exportAsDrag(JComponent c, InputEvent e, int action)
{
// TODO: Implement this properly
int src = getSourceActions(c);
int drag = src & action;
if (! (e instanceof MouseEvent))
{
drag = NONE;
}
if (drag != NONE)
{
if (recognizer == null)
{
SwingDragHandler ds = new SwingDragHandler();
recognizer = new SwingDragGestureRecognizer(ds);
}
recognizer.gesture(c, (MouseEvent) e, src, drag);
}
else
{
exportDone(c, null, NONE);
}
}
/**

View file

@ -778,7 +778,6 @@ class DefaultHSBChooserPanel extends AbstractColorChooserPanel
if (locked == HLOCKED)
{
slider.setMaximum(359);
;
slider.setValue(((Number) hSpinner.getValue()).intValue());
slider.setInverted(true);
}

View file

@ -215,6 +215,8 @@ public class BasicComboBoxUI extends ComboBoxUI
isMinimumSizeDirty = true;
comboBox = (JComboBox) c;
installDefaults();
popup = createPopup();
listBox = popup.getList();
// Set editor and renderer for the combo box. Editor is used
// only if combo box becomes editable, otherwise renderer is used
@ -229,14 +231,9 @@ public class BasicComboBoxUI extends ComboBoxUI
currentEditor = createEditor();
comboBox.setEditor(currentEditor);
}
editor = currentEditor.getEditorComponent();
installComponents();
installListeners();
if (arrowButton != null)
configureArrowButton();
if (editor != null)
configureEditor();
comboBox.setLayout(createLayoutManager());
comboBox.setFocusable(true);
installKeyboardActions();
@ -473,13 +470,11 @@ public class BasicComboBoxUI extends ComboBoxUI
*/
protected void installComponents()
{
// create drop down list of items
popup = createPopup();
listBox = popup.getList();
// create and install arrow button
arrowButton = createArrowButton();
comboBox.add(arrowButton);
if (arrowButton != null)
configureArrowButton();
if (comboBox.isEditable())
addEditor();
@ -494,24 +489,20 @@ public class BasicComboBoxUI extends ComboBoxUI
*/
protected void uninstallComponents()
{
// uninstall arrow button
unconfigureArrowButton();
comboBox.remove(arrowButton);
arrowButton = null;
popup = null;
if (comboBox.getRenderer() instanceof UIResource)
comboBox.setRenderer(null);
// if the editor is not an instanceof UIResource, it was not set by the
// UI delegate, so don't clear it...
ComboBoxEditor currentEditor = comboBox.getEditor();
if (currentEditor instanceof UIResource)
// Unconfigure arrow button.
if (arrowButton != null)
{
comboBox.setEditor(null);
editor = null;
unconfigureArrowButton();
}
// Unconfigure editor.
if (editor != null)
{
unconfigureEditor();
}
comboBox.removeAll();
arrowButton = null;
}
/**
@ -521,7 +512,11 @@ public class BasicComboBoxUI extends ComboBoxUI
{
removeEditor();
editor = comboBox.getEditor().getEditorComponent();
comboBox.add(editor);
if (editor != null)
{
configureEditor();
comboBox.add(editor);
}
}
/**
@ -572,10 +567,8 @@ public class BasicComboBoxUI extends ComboBoxUI
{
arrowButton.setEnabled(comboBox.isEnabled());
arrowButton.setFocusable(false);
if (popupMouseListener != null)
arrowButton.addMouseListener(popupMouseListener);
if (popupMouseMotionListener != null)
arrowButton.addMouseMotionListener(popupMouseMotionListener);
arrowButton.addMouseListener(popup.getMouseListener());
arrowButton.addMouseMotionListener(popup.getMouseMotionListener());
// Mark the button as not closing the popup, we handle this ourselves.
arrowButton.putClientProperty(BasicLookAndFeel.DONT_CANCEL_POPUP,
@ -855,9 +848,6 @@ public class BasicComboBoxUI extends ComboBoxUI
*/
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
{
Object currentValue = comboBox.getSelectedItem();
boolean isPressed = arrowButton.getModel().isPressed();
/* Gets the component to be drawn for the current value.
* If there is currently no selected item we will take an empty
* String as replacement.
@ -1109,7 +1099,6 @@ public class BasicComboBoxUI extends ComboBoxUI
// editable
Insets i = getInsets();
int arrowSize = comboBox.getHeight() - (i.top + i.bottom);
int editorWidth = comboBox.getBounds().width - arrowSize;
if (arrowButton != null)
arrowButton.setBounds(comboBox.getWidth() - (i.right + arrowSize),
@ -1345,52 +1334,76 @@ public class BasicComboBoxUI extends ComboBoxUI
public void propertyChange(PropertyChangeEvent e)
{
// Lets assume every change invalidates the minimumsize.
isMinimumSizeDirty = true;
if (e.getPropertyName().equals("enabled"))
String propName = e.getPropertyName();
if (propName.equals("enabled"))
{
arrowButton.setEnabled(comboBox.isEnabled());
boolean enabled = comboBox.isEnabled();
if (editor != null)
editor.setEnabled(enabled);
if (arrowButton != null)
arrowButton.setEnabled(enabled);
if (comboBox.isEditable())
comboBox.getEditor().getEditorComponent().setEnabled(
comboBox.isEnabled());
comboBox.repaint();
}
else if (propName.equals("editor") && comboBox.isEditable())
{
addEditor();
comboBox.revalidate();
}
else if (e.getPropertyName().equals("editable"))
{
if (comboBox.isEditable())
{
configureEditor();
addEditor();
}
else
{
unconfigureEditor();
removeEditor();
}
comboBox.revalidate();
comboBox.repaint();
}
else if (e.getPropertyName().equals("dataModel"))
else if (propName.equals("model"))
{
// remove ListDataListener from old model and add it to new model
ComboBoxModel oldModel = (ComboBoxModel) e.getOldValue();
if (oldModel != null)
if (oldModel != null && listDataListener != null)
oldModel.removeListDataListener(listDataListener);
if ((ComboBoxModel) e.getNewValue() != null)
ComboBoxModel newModel = (ComboBoxModel) e.getNewValue();
if (newModel != null && listDataListener != null)
comboBox.getModel().addListDataListener(listDataListener);
}
else if (e.getPropertyName().equals("font"))
{
Font font = (Font) e.getNewValue();
editor.setFont(font);
listBox.setFont(font);
arrowButton.setFont(font);
if (editor != null)
{
comboBox.configureEditor(comboBox.getEditor(),
comboBox.getSelectedItem());
}
isMinimumSizeDirty = true;
comboBox.revalidate();
comboBox.repaint();
}
else if (propName.equals("font"))
{
Font font = (Font) e.getNewValue();
if (editor != null)
{
editor.setFont(font);
}
listBox.setFont(font);
isMinimumSizeDirty = true;
comboBox.revalidate();
}
else if (propName.equals("prototypeDisplayValue"))
{
isMinimumSizeDirty = true;
comboBox.revalidate();
}
else if (propName.equals("renderer"))
{
isMinimumSizeDirty = true;
comboBox.revalidate();
}
// FIXME: Need to handle changes in other bound properties.
}
}

View file

@ -271,9 +271,17 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
*/
public void uninstallingUI()
{
if (propertyChangeListener != null)
{
comboBox.removePropertyChangeListener(propertyChangeListener);
}
if (itemListener != null)
{
comboBox.removeItemListener(itemListener);
}
uninstallComboBoxModelListeners(comboBox.getModel());
uninstallListeners();
uninstallKeyboardActions();
uninstallListListeners();
}
/**
@ -466,7 +474,6 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
list.setBorder(null);
list.setCellRenderer(comboBox.getRenderer());
list.setFocusable(false);
syncListSelection();
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
installListListeners();
}
@ -1009,15 +1016,6 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
// ------ private helper methods --------------------
/**
* This method uninstalls listeners installed by the UI
*/
private void uninstallListeners()
{
uninstallComboBoxListeners();
uninstallComboBoxModelListeners(comboBox.getModel());
}
/**
* This method uninstalls Listeners registered with combo boxes list of
* items
@ -1031,19 +1029,6 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup
listMouseMotionListener = null;
}
/**
* This method uninstalls listeners listening to combo box associated with
* this popup menu
*/
private void uninstallComboBoxListeners()
{
comboBox.removeItemListener(itemListener);
itemListener = null;
comboBox.removePropertyChangeListener(propertyChangeListener);
propertyChangeListener = null;
}
void syncListSelection()
{
int index = comboBox.getSelectedIndex();

View file

@ -37,13 +37,14 @@
package javax.swing.plaf.basic;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
@ -58,6 +59,7 @@ import javax.swing.JLabel;
import javax.swing.KeyStroke;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.LabelUI;
import javax.swing.text.View;
@ -79,6 +81,11 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
private Rectangle ir;
private Rectangle tr;
/**
* A cached Insets object for reuse in the label layout methods.
*/
private Insets cachedInsets;
/**
* Creates a new BasicLabelUI object.
*/
@ -131,7 +138,7 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
icon.getIconHeight() + insetsY);
else
{
FontMetrics fm = lab.getFontMetrics(lab.getFont());
FontMetrics fm = getFontMetrics(lab);
ir.x = 0;
ir.y = 0;
ir.width = 0;
@ -189,43 +196,46 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
public void paint(Graphics g, JComponent c)
{
JLabel b = (JLabel) c;
FontMetrics fm = g.getFontMetrics();
Insets i = c.getInsets();
vr.x = i.left;
vr.y = i.right;
vr.width = c.getWidth() - i.left + i.right;
vr.height = c.getHeight() - i.top + i.bottom;
ir.x = 0;
ir.y = 0;
ir.width = 0;
ir.height = 0;
tr.x = 0;
tr.y = 0;
tr.width = 0;
tr.height = 0;
Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();
String text = layoutCL(b, fm, b.getText(), icon, vr, ir, tr);
if (icon != null)
icon.paintIcon(b, g, ir.x, ir.y);
Object htmlRenderer = b.getClientProperty(BasicHTML.propertyKey);
if (htmlRenderer == null)
String text = b.getText();
if (icon != null || (text != null && ! text.equals("")))
{
if (text != null && !text.equals(""))
FontMetrics fm = getFontMetrics(b);
Insets i = c.getInsets(cachedInsets);
vr.x = i.left;
vr.y = i.right;
vr.width = c.getWidth() - i.left - i.right;
vr.height = c.getHeight() - i.top - i.bottom;
ir.x = 0;
ir.y = 0;
ir.width = 0;
ir.height = 0;
tr.x = 0;
tr.y = 0;
tr.width = 0;
tr.height = 0;
text = layoutCL(b, fm, text, icon, vr, ir, tr);
if (icon != null)
icon.paintIcon(b, g, ir.x, ir.y);
if (text != null && ! text.equals(""))
{
if (b.isEnabled())
paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
Object htmlRenderer = b.getClientProperty(BasicHTML.propertyKey);
if (htmlRenderer == null)
{
if (b.isEnabled())
paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
else
paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
}
else
paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
{
((View) htmlRenderer).paint(g, tr);
}
}
}
else
{
((View) htmlRenderer).paint(g, tr);
}
}
/**
@ -265,8 +275,6 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX,
int textY)
{
Color saved_color = g.getColor();
g.setColor(l.getBackground().brighter());
int mnemIndex = l.getDisplayedMnemonicIndex();
@ -283,8 +291,6 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
textY + 1);
else
g.drawString(s, textX + 1, textY + 1);
g.setColor(saved_color);
}
/**
@ -298,9 +304,8 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
* @param textY The y coordinate of the start of the baseline.
*/
protected void paintEnabledText(JLabel l, Graphics g, String s, int textX,
int textY)
int textY)
{
Color saved_color = g.getColor();
g.setColor(l.getForeground());
int mnemIndex = l.getDisplayedMnemonicIndex();
@ -310,8 +315,6 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
textY);
else
g.drawString(s, textX, textY);
g.setColor(saved_color);
}
/**
@ -514,4 +517,27 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
"press");
}
}
/**
* Fetches a font metrics object for the specified label. This first
* tries to get it from the label object itself by calling
* {@link Component#getFontMetrics(Font)}, and if that does not work
* (for instance, when we are in the initialization and have no parent yet),
* it asks the Toolkit for a font metrics object.
*
* @param l the label
*
* @return a suitable font metrics object
*/
private FontMetrics getFontMetrics(JLabel l)
{
Font font = l.getFont();
FontMetrics fm = l.getFontMetrics(font);
if (fm == null)
{
Toolkit tk = Toolkit.getDefaultToolkit();
fm = tk.getFontMetrics(font);
}
return fm;
}
}

View file

@ -149,57 +149,24 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
g.setFont(f);
ButtonModel m = b.getModel();
// This is the icon that we use for layout.
Icon icon = b.getIcon();
if (icon == null)
icon = getDefaultIcon();
// Figure out the correct icon.
Icon currentIcon = getCurrentIcon(b);
// Do the layout.
String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f),
b.getText(), icon,
b.getText(), currentIcon == null ? getDefaultIcon() : currentIcon,
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
viewR, iconR, textR, b.getIconTextGap());
// Figure out the correct icon.
icon = b.getIcon();
if (icon == null)
icon = getDefaultIcon();
else
{
if (! m.isEnabled())
{
if (m.isSelected())
icon = b.getDisabledSelectedIcon();
else
icon = b.getDisabledIcon();
}
else if (m.isArmed() && m.isPressed())
{
icon = b.getPressedIcon();
if (icon == null)
icon = b.getSelectedIcon();
}
else if (m.isSelected())
{
if (b.isRolloverEnabled() && m.isRollover())
{
icon = b.getRolloverSelectedIcon();
if (icon == null)
icon = b.getSelectedIcon();
}
else
icon = b.getSelectedIcon();
}
else if (b.isRolloverEnabled() && m.isRollover())
icon = b.getRolloverIcon();
if (icon == null)
icon = b.getIcon();
}
// .. and paint it.
icon.paintIcon(c, g, iconR.x, iconR.y);
if (currentIcon != null)
currentIcon.paintIcon(c, g, iconR.x, iconR.y);
// Paint text and focus indicator.
if (text != null)
@ -218,6 +185,58 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
}
}
/**
* Determines the icon to be displayed for the specified radio button.
*
* @param b the radio button
*
* @return the icon
*/
private Icon getCurrentIcon(AbstractButton b)
{
ButtonModel m = b.getModel();
Icon currentIcon = b.getIcon();
if (currentIcon == null)
{
currentIcon = getDefaultIcon();
}
else
{
if (! m.isEnabled())
{
if (m.isSelected())
currentIcon = b.getDisabledSelectedIcon();
else
currentIcon = b.getDisabledIcon();
}
else if (m.isPressed() && m.isArmed())
{
currentIcon = b.getPressedIcon();
if (currentIcon == null)
currentIcon = b.getSelectedIcon();
}
else if (m.isSelected())
{
if (b.isRolloverEnabled() && m.isRollover())
{
currentIcon = b.getRolloverSelectedIcon();
if (currentIcon == null)
currentIcon = b.getSelectedIcon();
}
else
currentIcon = b.getSelectedIcon();
}
else if (b.isRolloverEnabled() && m.isRollover())
{
currentIcon = b.getRolloverIcon();
}
if (currentIcon == null)
currentIcon = b.getIcon();
}
return currentIcon;
}
public Dimension getPreferredSize(JComponent c)
{
// This is basically the same code as in

View file

@ -1364,7 +1364,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants
calcRect.height -= tabAreaInsets.top + tabAreaInsets.bottom;
int height = 0;
int runHeight = tabAreaInsets.top + insets.top;;
int runHeight = tabAreaInsets.top + insets.top;
int fontHeight = fm.getHeight();
int left = insets.left + tabAreaInsets.left;
for (int i = 0; i < tabCount; i++)

View file

@ -116,7 +116,7 @@ import javax.swing.tree.VariableHeightLayoutCache;
* @author Audrius Meskauskas (audriusa@bioinformatics.org)
*/
public class BasicTreeUI
extends TreeUI
extends TreeUI
{
/**
* The tree cell editing may be started by the single mouse click on the
@ -656,7 +656,18 @@ public class BasicTreeUI
*/
public Rectangle getPathBounds(JTree tree, TreePath path)
{
return treeState.getBounds(path, new Rectangle());
Rectangle bounds = null;
if (tree != null && treeState != null)
{
bounds = treeState.getBounds(path, null);
Insets i = tree.getInsets();
if (bounds != null && i != null)
{
bounds.x += i.left;
bounds.y += i.top;
}
}
return bounds;
}
/**
@ -1561,7 +1572,6 @@ public class BasicTreeUI
int startIndex = tree.getClosestRowForLocation(clip.x, clip.y);
int endIndex = tree.getClosestRowForLocation(clip.x + clip.width,
clip.y + clip.height);
// Also paint dashes to the invisible nodes below.
// These should be painted first, otherwise they may cover
// the control icons.

View file

@ -174,9 +174,8 @@ public class MetalButtonUI
{
if (b.isContentAreaFilled())
{
Rectangle area = b.getVisibleRect();
g.setColor(getSelectColor());
g.fillRect(area.x, area.y, area.width, area.height);
g.fillRect(0, 0, b.getWidth(), b.getHeight());
}
}

View file

@ -48,7 +48,6 @@ import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.CellRendererPane;
import javax.swing.ComboBoxEditor;
import javax.swing.Icon;
import javax.swing.JButton;
@ -217,7 +216,7 @@ public class MetalComboBoxUI extends BasicComboBoxUI
*/
protected ComboPopup createPopup()
{
return new MetalComboPopup(comboBox);
return super.createPopup();
}
/**
@ -228,7 +227,7 @@ public class MetalComboBoxUI extends BasicComboBoxUI
protected JButton createArrowButton()
{
JButton button = new MetalComboBoxButton(comboBox, new MetalComboBoxIcon(),
new CellRendererPane(), listBox);
currentValuePane, listBox);
button.setMargin(new Insets(0, 1, 1, 3));
return button;
}
@ -305,7 +304,6 @@ public class MetalComboBoxUI extends BasicComboBoxUI
{
MetalComboBoxButton b = (MetalComboBoxButton) arrowButton;
d = getDisplaySize();
Insets insets = b.getInsets();
Insets arrowInsets = b.getInsets();
Insets comboInsets = comboBox.getInsets();
Icon icon = b.getComboIcon();

View file

@ -56,9 +56,9 @@ import java.awt.event.MouseListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.sql.Date;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.List;
import javax.swing.AbstractAction;
@ -441,7 +441,7 @@ public class MetalFileChooserUI
filechooser.revalidate();
filechooser.repaint();
}
};
}
/**
* A combo box model containing the selected directory and all its parent

View file

@ -75,9 +75,6 @@ public class MetalLookAndFeel extends BasicLookAndFeel
/** The current theme. */
private static MetalTheme theme;
/** The look and feel defaults. */
private UIDefaults LAF_defaults;
/**
* Creates a new instance of the Metal look and feel.
*/
@ -151,17 +148,10 @@ public class MetalLookAndFeel extends BasicLookAndFeel
public UIDefaults getDefaults()
{
createDefaultTheme();
if (LAF_defaults == null)
{
LAF_defaults = super.getDefaults();
UIDefaults def = super.getDefaults();
// add custom theme entries to the table
if (theme != null)
theme.addCustomEntriesToTable(LAF_defaults);
}
// Returns the default values for this look and feel.
return LAF_defaults;
theme.addCustomEntriesToTable(def);
return def;
}
/**

View file

@ -82,7 +82,7 @@ public class MetalMenuBarUI extends BasicMenuBarUI
&& c.getBackground() instanceof UIResource
&& height > 2)
{
MetalUtils.paintGradient(g, 0, 0, c.getWidth(), height - 2,
MetalUtils.paintGradient(g, 0, 0, c.getWidth(), height,
SwingConstants.VERTICAL, "MenuBar.gradient");
paint(g, c);

View file

@ -570,7 +570,7 @@ public class JTableHeader extends JComponent
if (comp != null)
comp.setVisible(b);
}
};
}
public AccessibleRole getAccessibleRole()
{

View file

@ -1,5 +1,5 @@
/* AbstractDocument.java --
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -2093,7 +2093,7 @@ public abstract class AbstractDocument implements Document, Serializable
/**
* The child elements of this BranchElement.
*/
private Element[] children;;
private Element[] children;
/**
* The number of children in the branch element.
@ -2450,8 +2450,6 @@ public abstract class AbstractDocument implements Document, Serializable
*/
public boolean addEdit(UndoableEdit edit)
{
// XXX - Fully qualify ElementChange to work around gcj bug #2499.
// Start using Hashtable when we pass a certain threshold. This
// gives a good memory/performance compromise.
if (changes == null && edits.size() > THRESHOLD)
@ -2461,19 +2459,17 @@ public abstract class AbstractDocument implements Document, Serializable
for (int i = 0; i < count; i++)
{
Object o = edits.elementAt(i);
if (o instanceof DocumentEvent.ElementChange)
if (o instanceof ElementChange)
{
DocumentEvent.ElementChange ec =
(DocumentEvent.ElementChange) o;
ElementChange ec = (ElementChange) o;
changes.put(ec.getElement(), ec);
}
}
}
if (changes != null && edit instanceof DocumentEvent.ElementChange)
if (changes != null && edit instanceof ElementChange)
{
DocumentEvent.ElementChange elEdit =
(DocumentEvent.ElementChange) edit;
ElementChange elEdit = (ElementChange) edit;
changes.put(elEdit.getElement(), elEdit);
}
return super.addEdit(edit);
@ -2527,13 +2523,12 @@ public abstract class AbstractDocument implements Document, Serializable
* @return the changes for <code>elem</code> or <code>null</code> if
* <code>elem</code> has not been changed
*/
public DocumentEvent.ElementChange getChange(Element elem)
public ElementChange getChange(Element elem)
{
// XXX - Fully qualify ElementChange to work around gcj bug #2499.
DocumentEvent.ElementChange change = null;
ElementChange change = null;
if (changes != null)
{
change = (DocumentEvent.ElementChange) changes.get(elem);
change = (ElementChange) changes.get(elem);
}
else
{
@ -2541,10 +2536,9 @@ public abstract class AbstractDocument implements Document, Serializable
for (int i = 0; i < count && change == null; i++)
{
Object o = edits.get(i);
if (o instanceof DocumentEvent.ElementChange)
if (o instanceof ElementChange)
{
DocumentEvent.ElementChange ec =
(DocumentEvent.ElementChange) o;
ElementChange ec = (ElementChange) o;
if (elem.equals(ec.getElement()))
change = ec;
}

View file

@ -307,7 +307,7 @@ public class AsyncBoxView
private int updateChildOffsets(float targetOffset)
{
int n = getViewCount();
int targetIndex = n - 1;;
int targetIndex = n - 1;
int pos = lastValidOffset.getChildView().getStartOffset();
int startIndex = getViewIndexAtPosition(pos, Position.Bias.Forward);
float start = lastValidOffset.getMajorOffset();

View file

@ -1126,7 +1126,9 @@ public class DefaultStyledDocument extends AbstractDocument implements
int p;
for (p = 0;
p < data.length && data[p].getType() == ElementSpec.EndTagType;
p++);
p++)
;
Edit edit = insertPath[insertPath.length - p - 1];
edit.index--;
edit.removed.add(0, edit.e.getElement(edit.index));

View file

@ -91,7 +91,7 @@ public class FieldView extends PlainView
horizontalVisibility.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent event) {
getContainer().repaint();
};
}
});
// It turned out that the span calculated at this point is wrong

View file

@ -1,5 +1,5 @@
/* InternationalFormatter.java --
Copyright (C) 2005 Free Software Foundation, Inc.
Copyright (C) 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -329,7 +329,7 @@ public class InternationalFormatter
*
* @throws CloneNotSupportedException not thrown here, since cloning is
* supported
* XXX - FIXME - Whole method disabled as workaround for gcj bug #22060.
*/
public Object clone()
throws CloneNotSupportedException
{
@ -338,7 +338,6 @@ public class InternationalFormatter
Object clone = super.clone();
return clone;
}
*/
/**
* Returns the Actions that are supported by this Formatter.

View file

@ -1821,7 +1821,7 @@ public abstract class JTextComponent extends JComponent
public boolean getScrollableTracksViewportWidth()
{
boolean res = false;;
boolean res = false;
Container c = getParent();
if (c instanceof JViewport)
res = ((JViewport) c).getExtentSize().width > getPreferredSize().width;

View file

@ -315,7 +315,8 @@ class CSSParser
try
{
if (!parsingDeclaration)
while(getNextStatement());
while(getNextStatement())
;
else
parseDeclarationBlock();
}
@ -565,4 +566,4 @@ class CSSParser
}
}