From e1bea0c0687c5f4551b3a6058ec37ce3705fa6cc Mon Sep 17 00:00:00 2001
From: Matthias Klose
Date: Sun, 3 Jun 2007 23:18:43 +0000
Subject: libjava/classpath/ChangeLog.gcj:
2007-05-31 Matthias Klose
* 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
* java/io/natFileWin32.cc (setFilePermissions): New (stub only).
_access: Handle EXEC query, stub only.
2007-06-03 Matthias Klose
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
* 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
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
---
libjava/classpath/java/awt/AWTEvent.java | 12 +-
libjava/classpath/java/awt/AWTKeyStroke.java | 6 +-
libjava/classpath/java/awt/AlphaComposite.java | 6 +-
libjava/classpath/java/awt/Canvas.java | 14 +-
libjava/classpath/java/awt/CardLayout.java | 2 +-
libjava/classpath/java/awt/Component.java | 60 +-
libjava/classpath/java/awt/Desktop.java | 268 +++
.../classpath/java/awt/EventDispatchThread.java | 3 +
libjava/classpath/java/awt/EventQueue.java | 6 +-
libjava/classpath/java/awt/Frame.java | 85 +-
.../classpath/java/awt/GraphicsConfiguration.java | 31 +-
libjava/classpath/java/awt/RenderingHints.java | 10 +-
libjava/classpath/java/awt/Toolkit.java | 24 +-
libjava/classpath/java/awt/Window.java | 32 +-
.../java/awt/datatransfer/SystemFlavorMap.java | 154 +-
libjava/classpath/java/awt/geom/GeneralPath.java | 11 +-
.../classpath/java/awt/image/BufferedImage.java | 327 ++--
.../java/awt/image/ComponentSampleModel.java | 448 ++---
.../classpath/java/awt/image/IndexColorModel.java | 17 +-
.../awt/image/SinglePixelPackedSampleModel.java | 150 +-
libjava/classpath/java/awt/peer/DesktopPeer.java | 64 +
libjava/classpath/java/awt/print/PrinterJob.java | 15 +-
.../java/beans/ConstructorProperties.java | 72 +
libjava/classpath/java/beans/XMLEncoder.java | 2 +-
libjava/classpath/java/io/File.java | 179 ++
libjava/classpath/java/io/ObjectInputStream.java | 175 +-
libjava/classpath/java/io/ObjectOutputStream.java | 88 +-
libjava/classpath/java/io/StreamTokenizer.java | 2 +
libjava/classpath/java/io/class-dependencies.conf | 100 -
libjava/classpath/java/lang/Character.java | 2 +-
libjava/classpath/java/lang/Class.java | 30 +-
libjava/classpath/java/lang/Enum.java | 13 +
libjava/classpath/java/lang/StrictMath.java | 5 +-
libjava/classpath/java/lang/String.java | 17 +-
libjava/classpath/java/lang/System.java | 25 +-
.../classpath/java/lang/class-dependencies.conf | 58 -
.../classpath/java/lang/management/LockInfo.java | 114 ++
.../java/lang/management/ManagementFactory.java | 265 +++
.../java/lang/management/MemoryUsage.java | 16 +-
.../java/lang/management/MonitorInfo.java | 179 ++
.../lang/management/OperatingSystemMXBean.java | 16 +
.../classpath/java/lang/management/ThreadInfo.java | 431 ++++-
.../java/lang/management/ThreadMXBean.java | 167 +-
libjava/classpath/java/math/BigInteger.java | 5 +-
.../classpath/java/math/class-dependencies.conf | 58 -
libjava/classpath/java/net/MimeTypeMapper.java | 13 +-
libjava/classpath/java/net/MulticastSocket.java | 6 +-
libjava/classpath/java/net/NetworkInterface.java | 7 +-
libjava/classpath/java/net/Proxy.java | 2 +-
libjava/classpath/java/net/ResolverCache.java | 4 +-
libjava/classpath/java/net/ServerSocket.java | 7 +-
libjava/classpath/java/net/Socket.java | 23 +-
libjava/classpath/java/net/URI.java | 2 +-
libjava/classpath/java/net/URL.java | 11 +-
libjava/classpath/java/net/URLClassLoader.java | 29 +-
libjava/classpath/java/net/class-dependencies.conf | 122 --
libjava/classpath/java/nio/ByteOrder.java | 4 +-
.../java/nio/channels/spi/SelectorProvider.java | 27 +
libjava/classpath/java/nio/class-dependencies.conf | 58 -
.../java/rmi/activation/ActivationID.java | 2 +-
.../java/rmi/server/UnicastRemoteObject.java | 5 +-
.../classpath/java/security/BasicPermission.java | 3 +-
libjava/classpath/java/security/Permission.java | 17 +-
.../classpath/java/security/SecureClassLoader.java | 2 +-
libjava/classpath/java/security/SignatureSpi.java | 13 +-
.../java/security/cert/X509CertSelector.java | 1419 ++++++++------
.../java/security/cert/X509Certificate.java | 4 +-
.../java/text/AttributedStringIterator.java | 8 +-
libjava/classpath/java/text/BreakIterator.java | 117 +-
libjava/classpath/java/text/Collator.java | 50 +-
libjava/classpath/java/text/DateFormat.java | 148 +-
libjava/classpath/java/text/DateFormatSymbols.java | 159 +-
libjava/classpath/java/text/DecimalFormat.java | 31 +-
.../classpath/java/text/DecimalFormatSymbols.java | 89 +-
libjava/classpath/java/text/MessageFormat.java | 128 +-
libjava/classpath/java/text/NumberFormat.java | 135 +-
libjava/classpath/java/text/SimpleDateFormat.java | 16 +-
.../classpath/java/text/class-dependencies.conf | 220 ---
.../java/text/spi/BreakIteratorProvider.java | 124 ++
.../classpath/java/text/spi/CollatorProvider.java | 79 +
.../java/text/spi/DateFormatProvider.java | 129 ++
.../java/text/spi/DateFormatSymbolsProvider.java | 79 +
.../text/spi/DecimalFormatSymbolsProvider.java | 79 +
.../java/text/spi/NumberFormatProvider.java | 129 ++
libjava/classpath/java/text/spi/package.html | 50 +
libjava/classpath/java/util/AbstractMap.java | 29 +-
libjava/classpath/java/util/Arrays.java | 998 +++++++++-
libjava/classpath/java/util/Calendar.java | 250 ++-
libjava/classpath/java/util/Collections.java | 217 ++-
libjava/classpath/java/util/Currency.java | 33 +-
libjava/classpath/java/util/Date.java | 2 +-
libjava/classpath/java/util/GregorianCalendar.java | 18 +-
libjava/classpath/java/util/HashMap.java | 16 +-
libjava/classpath/java/util/Hashtable.java | 18 +-
libjava/classpath/java/util/LinkedList.java | 271 ++-
libjava/classpath/java/util/Locale.java | 76 +-
libjava/classpath/java/util/PriorityQueue.java | 1 +
.../java/util/ServiceConfigurationError.java | 94 +
libjava/classpath/java/util/ServiceLoader.java | 274 +++
libjava/classpath/java/util/StringTokenizer.java | 8 +-
libjava/classpath/java/util/TreeMap.java | 1970 +++++++++++++++++---
libjava/classpath/java/util/TreeSet.java | 244 ++-
.../classpath/java/util/class-dependencies.conf | 78 -
.../java/util/concurrent/CopyOnWriteArrayList.java | 3 +-
.../classpath/java/util/logging/LogManager.java | 16 +-
libjava/classpath/java/util/logging/Logger.java | 18 +-
.../java/util/prefs/AbstractPreferences.java | 17 +-
libjava/classpath/java/util/prefs/Preferences.java | 6 +-
libjava/classpath/java/util/regex/Pattern.java | 14 +-
.../java/util/spi/CurrencyNameProvider.java | 100 +
.../java/util/spi/LocaleNameProvider.java | 135 ++
.../java/util/spi/LocaleServiceProvider.java | 125 ++
.../java/util/spi/TimeZoneNameProvider.java | 97 +
libjava/classpath/java/util/spi/package.html | 50 +
.../classpath/java/util/zip/DeflaterEngine.java | 3 +-
.../classpath/java/util/zip/ZipInputStream.java | 1 +
116 files changed, 9783 insertions(+), 2713 deletions(-)
create mode 100644 libjava/classpath/java/awt/Desktop.java
create mode 100644 libjava/classpath/java/awt/peer/DesktopPeer.java
create mode 100644 libjava/classpath/java/beans/ConstructorProperties.java
delete mode 100644 libjava/classpath/java/io/class-dependencies.conf
delete mode 100644 libjava/classpath/java/lang/class-dependencies.conf
create mode 100644 libjava/classpath/java/lang/management/LockInfo.java
create mode 100644 libjava/classpath/java/lang/management/MonitorInfo.java
delete mode 100644 libjava/classpath/java/math/class-dependencies.conf
delete mode 100644 libjava/classpath/java/net/class-dependencies.conf
delete mode 100644 libjava/classpath/java/nio/class-dependencies.conf
delete mode 100644 libjava/classpath/java/text/class-dependencies.conf
create mode 100644 libjava/classpath/java/text/spi/BreakIteratorProvider.java
create mode 100644 libjava/classpath/java/text/spi/CollatorProvider.java
create mode 100644 libjava/classpath/java/text/spi/DateFormatProvider.java
create mode 100644 libjava/classpath/java/text/spi/DateFormatSymbolsProvider.java
create mode 100644 libjava/classpath/java/text/spi/DecimalFormatSymbolsProvider.java
create mode 100644 libjava/classpath/java/text/spi/NumberFormatProvider.java
create mode 100644 libjava/classpath/java/text/spi/package.html
create mode 100644 libjava/classpath/java/util/ServiceConfigurationError.java
create mode 100644 libjava/classpath/java/util/ServiceLoader.java
delete mode 100644 libjava/classpath/java/util/class-dependencies.conf
create mode 100644 libjava/classpath/java/util/spi/CurrencyNameProvider.java
create mode 100644 libjava/classpath/java/util/spi/LocaleNameProvider.java
create mode 100644 libjava/classpath/java/util/spi/LocaleServiceProvider.java
create mode 100644 libjava/classpath/java/util/spi/TimeZoneNameProvider.java
create mode 100644 libjava/classpath/java/util/spi/package.html
(limited to 'libjava/classpath/java')
diff --git a/libjava/classpath/java/awt/AWTEvent.java b/libjava/classpath/java/awt/AWTEvent.java
index 3f4027c..102062c 100644
--- a/libjava/classpath/java/awt/AWTEvent.java
+++ b/libjava/classpath/java/awt/AWTEvent.java
@@ -262,9 +262,17 @@ public abstract class AWTEvent extends EventObject
*/
public String toString ()
{
+ String src;
+ if (source instanceof Component)
+ src = ((Component) source).getName();
+ else if (source instanceof MenuComponent)
+ src = ((MenuComponent) source).getName();
+ else if (source != null)
+ src = source.toString();
+ else
+ src = "null";
String string = getClass ().getName () + "[" + paramString () + "] on "
- + source;
-
+ + src;
return string;
}
diff --git a/libjava/classpath/java/awt/AWTKeyStroke.java b/libjava/classpath/java/awt/AWTKeyStroke.java
index 527e858..e0b34e9 100644
--- a/libjava/classpath/java/awt/AWTKeyStroke.java
+++ b/libjava/classpath/java/awt/AWTKeyStroke.java
@@ -1,5 +1,5 @@
/* AWTKeyStroke.java -- an immutable key stroke
- Copyright (C) 2002, 2004, 2005 Free Software Foundation
+ Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -93,9 +93,9 @@ public class AWTKeyStroke implements Serializable
private static final int MAX_CACHE_SIZE = 2048;
/** Prune stale entries. */
- protected boolean removeEldestEntry(Map.Entry
+ protected boolean removeEldestEntry(Entry
eldest)
- { // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround.
+ {
return size() > MAX_CACHE_SIZE;
}
};
diff --git a/libjava/classpath/java/awt/AlphaComposite.java b/libjava/classpath/java/awt/AlphaComposite.java
index 92b9e09..90df2e6 100644
--- a/libjava/classpath/java/awt/AlphaComposite.java
+++ b/libjava/classpath/java/awt/AlphaComposite.java
@@ -1,5 +1,5 @@
/* AlphaComposite.java -- provides a context for performing alpha compositing
- Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -61,8 +61,8 @@ public final class AlphaComposite implements Composite
private static final int MAX_CACHE_SIZE = 2048;
/** Prune stale entries. */
- protected boolean removeEldestEntry(Map.Entry eldest)
- { // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround.
+ protected boolean removeEldestEntry(Entry eldest)
+ {
return size() > MAX_CACHE_SIZE;
}
};
diff --git a/libjava/classpath/java/awt/Canvas.java b/libjava/classpath/java/awt/Canvas.java
index 843fded..95db1f5 100644
--- a/libjava/classpath/java/awt/Canvas.java
+++ b/libjava/classpath/java/awt/Canvas.java
@@ -75,11 +75,6 @@ public class Canvas
private static transient long next_canvas_number;
/**
- * The graphics configuration associated with the canvas.
- */
- transient GraphicsConfiguration graphicsConfiguration;
-
- /**
* The buffer strategy associated with this canvas.
*/
transient BufferStrategy bufferStrategy;
@@ -100,14 +95,7 @@ public class Canvas
*/
public Canvas(GraphicsConfiguration graphicsConfiguration)
{
- this.graphicsConfiguration = graphicsConfiguration;
- }
-
- GraphicsConfiguration getGraphicsConfigurationImpl()
- {
- if (graphicsConfiguration != null)
- return graphicsConfiguration;
- return super.getGraphicsConfigurationImpl();
+ this.graphicsConfig = graphicsConfiguration;
}
/**
diff --git a/libjava/classpath/java/awt/CardLayout.java b/libjava/classpath/java/awt/CardLayout.java
index 2e3feec..35380d2 100644
--- a/libjava/classpath/java/awt/CardLayout.java
+++ b/libjava/classpath/java/awt/CardLayout.java
@@ -225,7 +225,7 @@ public class CardLayout implements LayoutManager2, Serializable
*/
public Dimension maximumLayoutSize (Container target)
{
- if (target == null)
+ if (target == null || target.ncomponents == 0)
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
// The JCL says that this returns Integer.MAX_VALUE for both
// dimensions. But that just seems wrong to me.
diff --git a/libjava/classpath/java/awt/Component.java b/libjava/classpath/java/awt/Component.java
index b6eadab..f8bed17 100644
--- a/libjava/classpath/java/awt/Component.java
+++ b/libjava/classpath/java/awt/Component.java
@@ -726,7 +726,23 @@ public abstract class Component
*/
public GraphicsConfiguration getGraphicsConfiguration()
{
- return getGraphicsConfigurationImpl();
+ GraphicsConfiguration conf = null;
+ synchronized (getTreeLock())
+ {
+ if (graphicsConfig != null)
+ {
+ conf = graphicsConfig;
+ }
+ else
+ {
+ Component par = getParent();
+ if (par != null)
+ {
+ conf = parent.getGraphicsConfiguration();
+ }
+ }
+ }
+ return conf;
}
/**
@@ -823,7 +839,8 @@ public abstract class Component
*/
public boolean isShowing()
{
- return visible && peer != null && (parent == null || parent.isShowing());
+ Component par = parent;
+ return visible && peer != null && (par == null || par.isShowing());
}
/**
@@ -1179,19 +1196,12 @@ public abstract class Component
*/
public Font getFont()
{
- Font f;
- synchronized (getTreeLock())
- {
- f = getFontImpl();
- }
- return f;
+ return getFontImpl();
}
/**
* Implementation of getFont(). This is pulled out of getFont() to prevent
- * client programs from overriding this. This method is executed within
- * a tree lock, so we can assume that the hierarchy doesn't change in
- * between.
+ * client programs from overriding this.
*
* @return the font of this component
*/
@@ -1204,7 +1214,12 @@ public abstract class Component
if (p != null)
f = p.getFontImpl();
else
- f = new Font("Dialog", Font.PLAIN, 12);
+ {
+ // It is important to return null here and not some kind of default
+ // font, otherwise the Swing UI would not install its fonts because
+ // it keeps non-UIResource fonts.
+ f = null;
+ }
}
return f;
}
@@ -5435,27 +5450,6 @@ p *
the set of backward traversal keys
}
/**
- * Implementation method that allows classes such as Canvas and Window to
- * override the graphics configuration without violating the published API.
- *
- * @return the graphics configuration
- */
- GraphicsConfiguration getGraphicsConfigurationImpl()
- {
- if (peer != null)
- {
- GraphicsConfiguration config = peer.getGraphicsConfiguration();
- if (config != null)
- return config;
- }
-
- if (parent != null)
- return parent.getGraphicsConfiguration();
-
- return null;
- }
-
- /**
* Translate an AWT 1.1 event ({@link AWTEvent}) into an AWT 1.0
* event ({@link Event}).
*
diff --git a/libjava/classpath/java/awt/Desktop.java b/libjava/classpath/java/awt/Desktop.java
new file mode 100644
index 0000000..8010464
--- /dev/null
+++ b/libjava/classpath/java/awt/Desktop.java
@@ -0,0 +1,268 @@
+/* Desktop.java -- enable desktop integration between java programs and system
+ programs.
+ Copyright (C) 2006 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 java.awt;
+
+import java.awt.peer.DesktopPeer;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * This class enables Java application to access system commands to perform
+ * desktop oriented operations, like writing and sending emails, or surfing
+ * webpages with the system browser or editing/printing files with a default
+ * editor. Methods are provided to handle these common operations, plus an
+ * open command selects a default registered application for the
+ * specified file type. For example, opening an odf file results in launching
+ * OpenOffice. If an operation is not supported, or the application fails to
+ * launch, an exception is generated.
+ *
+ * Implementation note: As this class is used to manage Desktop
+ * integration, we provide some extension to configure the behaviour of this
+ * class depending on the type of dektop that is detected.
+ *
+ * First of all, we support 5 system properties that can be used to define
+ * the application to launch in any given case. These properties are:
+ *
+ * gnu.java.awt.peer.Desktop.html.command
+ * gnu.java.awt.peer.Desktop.mail.command
+ * gnu.java.awt.peer.Desktop.edit.command
+ * gnu.java.awt.peer.Desktop.print.command
+ * gnu.java.awt.peer.Desktop.open.command
+ *
+ *
+ * These can be specified from the command line and have priority on every
+ * other setting.
+ *
+ * The second method supported is defining a Java preference.
+ * The main preference node is a user node relative to the
+ * class gnu.java.awt.peer.ClasspathDesktopPeer. This node
+ * contains a child for each supported operation. The key for each type is
+ * always command:
+ *
+ * gnu.java.awt.peer.Desktop.html.command
+ * gnu.java.awt.peer.Desktop.mail.command
+ * gnu.java.awt.peer.Desktop.edit.command
+ * gnu.java.awt.peer.Desktop.print.command
+ * gnu.java.awt.peer.Desktop.open.command
+ *
+ *
+ * The access to these keys is done with the Preference API or, if outside
+ * of the java scope, is done in a backend dependent way. For example,
+ * with the GConf backend, you can access these properties
+ * with (may not be accurate on your system):
+ *
+ *
+ * gconftool-2 -g /apps/classpath/gnu/java/awt/peer/Desktop/html/command
+ *
+ *
+ * @author Mario Torre
+ * @since 1.6
+ */
+public class Desktop
+{
+ /**
+ * Represents an action type supported by a platform.
+ *
+ * To determine if a given action is supported by the platform,
+ * use the Desktop.isSupported(java.awt.Desktop.Action)
+ * method.
+ *
+ * @author Mario Torre
+ */
+ public enum Action
+ {
+ BROWSE, EDIT, MAIL, OPEN, PRINT
+ }
+
+ private DesktopPeer peer;
+
+ private Desktop()
+ {
+ /* nothing to be done */
+ }
+
+ /**
+ * Returns an istance of the Desktop Class.
+ *
+ * If this implementation does not support Desktop, an
+ * UnsupportedOperationException will be thrown.
+ * Also, an HeadlessException will be generated if
+ * GraphicsEnvironment.isHeadless() returns true.
+ *
+ * @throws UnsupportedOperationException
+ * @throws HeadlessException
+ */
+ public static Desktop getDesktop() throws UnsupportedOperationException,
+ HeadlessException
+ {
+ if (GraphicsEnvironment.isHeadless())
+ throw new HeadlessException();
+
+ if (!Desktop.isDesktopSupported())
+ throw new UnsupportedOperationException();
+
+ Desktop desktop = new Desktop();
+ desktop.peer = Toolkit.getDefaultToolkit().createDesktopPeer(desktop);
+
+ return desktop;
+ }
+
+ /**
+ * Check if this implementation supports Desktop.
+ * If true, use getDesktop to get an instance of this class.
+ *
+ * This implementation will return false when GraphicsEnvironment.isHeadless
+ * returns true.
+ *
+ * @return true if this class is supported on the current platform;
+ * false otherwise
+ */
+ private static boolean isDesktopSupported()
+ {
+ if (GraphicsEnvironment.isHeadless())
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Check if the given Action is supported by this implementation.
+ *
+ * @param action
+ * @return
+ */
+ public boolean isSupported(Desktop.Action action)
+ {
+ return peer.isSupported(action);
+ }
+
+ /**
+ * Launches the Desktop default browser to open the given uri.
+ *
+ * If a security manager exists and denies
+ * AWTPermission("showWindowWithoutWarningBanner"),a SecurityException will
+ * be generated.
+ *
+ * @param uri
+ * @throws IOException
+ */
+ public void browse(URI uri)
+ throws IOException
+ {
+ peer.browse(uri);
+ }
+
+ /**
+ * Launch the edit command to edit this file.
+ * File should already exist before the editing starts.
+ *
+ * If a security manager exists and
+ * SecurityManager.checkRead(java.lang.String) method denies read access to
+ * the file, or SecurityManager.checkPrintJobAccess() method denies the
+ * permission to print the file, a SecurityException will be generated.
+ *
+ * @param file
+ * @throws IOException
+ */
+ public void edit(File file)
+ throws IOException
+ {
+ peer.edit(file);
+ }
+
+ /**
+ * Launches the Desktop default mailer.
+ *
+ * If a security manager exists and denies
+ * AWTPermission("showWindowWithoutWarningBanner"), a SecurityException will
+ * be generated.
+ *
+ * @throws IOException
+ */
+ public void mail()
+ throws IOException
+ {
+ peer.mail();
+ }
+
+ /**
+ * Launches the Desktop default mailer, with the given mailtoURI
+ * as agrument. The mailtoURI must conform to the
+ * {@link http://www.ietf.org/rfc/rfc2368.txt The mailto URL scheme (RFC 2368)}
+ *
+ * If a security manager exists and denies
+ * AWTPermission("showWindowWithoutWarningBanner"), a SecurityException will
+ * be generated.
+ *
+ * @param mailtoURI
+ * @throws IOException
+ */
+ public void mail(URI mailtoURI)
+ throws IOException
+ {
+ peer.mail(mailtoURI);
+ }
+
+ /**
+ * Launches the Desktop default application to open the given File.
+ * If file is a directory, a file manager is launched.
+ *
+ * @param file
+ * @throws IOException
+ */
+ public void open(File file)
+ throws IOException
+ {
+ peer.open(file);
+ }
+
+ /**
+ * Launch the print program to print this file.
+ *
+ * @param file
+ * @throws IOException
+ */
+ public void print(File file)
+ throws IOException
+ {
+ peer.print(file);
+ }
+}
diff --git a/libjava/classpath/java/awt/EventDispatchThread.java b/libjava/classpath/java/awt/EventDispatchThread.java
index 074a849..9f81a79 100644
--- a/libjava/classpath/java/awt/EventDispatchThread.java
+++ b/libjava/classpath/java/awt/EventDispatchThread.java
@@ -73,6 +73,9 @@ class EventDispatchThread extends Thread
// Ignore and use default.
}
setPriority(priority);
+
+ // Make sure that an event dispatch thread is never a daemon thread.
+ setDaemon(false);
}
public void run()
diff --git a/libjava/classpath/java/awt/EventQueue.java b/libjava/classpath/java/awt/EventQueue.java
index 74dbd5f..eb17449 100644
--- a/libjava/classpath/java/awt/EventQueue.java
+++ b/libjava/classpath/java/awt/EventQueue.java
@@ -128,10 +128,8 @@ public class EventQueue
if (peekEvent() != null)
return false;
- Frame[] frames = Frame.getFrames();
- for (int i = 0; i < frames.length; ++i)
- if (frames[i].isDisplayable())
- return false;
+ if (Frame.hasDisplayableFrames())
+ return false;
return true;
}
diff --git a/libjava/classpath/java/awt/Frame.java b/libjava/classpath/java/awt/Frame.java
index d5cc7f5..3cc8738 100644
--- a/libjava/classpath/java/awt/Frame.java
+++ b/libjava/classpath/java/awt/Frame.java
@@ -40,9 +40,10 @@ exception statement from your version. */
package java.awt;
import java.awt.peer.FramePeer;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.Vector;
import javax.accessibility.AccessibleContext;
@@ -484,44 +485,72 @@ public class Frame extends Window implements MenuContainer
return super.paramString () + ",title=" + title + resizable + state;
}
- private static ArrayList weakFrames = new ArrayList();
+ /**
+ * The list of active frames. GC'ed frames get removed in noteFrame().
+ */
+ private static ArrayList> weakFrames =
+ new ArrayList>();
+
+ /**
+ * The death queue for all frames.
+ */
+ private static ReferenceQueue weakFramesQueue =
+ new ReferenceQueue();
private static void noteFrame(Frame f)
{
synchronized (weakFrames)
{
- weakFrames.add(new WeakReference(f));
+ // Remove GCed frames from the list.
+ Reference ref = weakFramesQueue.poll();
+ while (ref != null)
+ {
+ weakFrames.remove(ref);
+ ref = weakFramesQueue.poll();
+ }
+ // Add new frame.
+ weakFrames.add(new WeakReference(f));
}
}
+ /**
+ * Returns true when there are any displayable frames,
+ * false otherwise.
+ *
+ * @return true when there are any displayable frames,
+ * false otherwise
+ */
+ static boolean hasDisplayableFrames()
+ {
+ synchronized (weakFrames)
+ {
+ for (WeakReference r : Frame.weakFrames)
+ {
+ Frame f = (Frame) r.get();
+ if (f != null && f.isDisplayable())
+ return true;
+ }
+ }
+ return false;
+ }
+
public static Frame[] getFrames()
{
- int n = 0;
synchronized (weakFrames)
- {
- Iterator i = weakFrames.iterator();
- while (i.hasNext())
- {
- WeakReference wr = (WeakReference) i.next();
- if (wr.get() != null)
- ++n;
- }
- if (n == 0)
- return new Frame[0];
- else
- {
- Frame[] frames = new Frame[n];
- n = 0;
- i = weakFrames.iterator();
- while (i.hasNext())
- {
- WeakReference wr = (WeakReference) i.next();
- if (wr.get() != null)
- frames[n++] = (Frame) wr.get();
- }
- return frames;
- }
- }
+ {
+ ArrayList existingFrames = new ArrayList();
+ for (WeakReference ref : weakFrames)
+ {
+ Frame f = ref.get();
+ if (f != null)
+ {
+ existingFrames.add(f);
+ }
+ }
+ Frame[] frames = new Frame[existingFrames.size()];
+ frames = existingFrames.toArray(frames);
+ return frames;
+ }
}
public void setState(int state)
diff --git a/libjava/classpath/java/awt/GraphicsConfiguration.java b/libjava/classpath/java/awt/GraphicsConfiguration.java
index 792b2cc..3cf8b65 100644
--- a/libjava/classpath/java/awt/GraphicsConfiguration.java
+++ b/libjava/classpath/java/awt/GraphicsConfiguration.java
@@ -38,8 +38,6 @@ exception statement from your version. */
package java.awt;
-import gnu.classpath.NotImplementedException;
-
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
@@ -131,7 +129,8 @@ public abstract class GraphicsConfiguration
ImageCapabilities caps)
throws AWTException
{
- throw new AWTException("not implemented");
+ // Must be overridden by implementations to check caps.
+ return createCompatibleVolatileImage(w, h);
}
/**
@@ -150,6 +149,32 @@ public abstract class GraphicsConfiguration
int transparency);
/**
+ * Creates a volatile image with the specified capabilities and transparency.
+ * If the backend cannot meet the requested capabilities and transparency,
+ * an AWTException is thrown.
+ *
+ * @param width the width of the image
+ * @param height the height of the image
+ * @param caps the requested capabilities
+ * @param transparency the required transparency
+ *
+ * @return a volatile image with the specified capabilites and transparency
+ *
+ * @throws AWTException if the required capabilities and transparency cannot
+ * be met
+ *
+ * @since 1.5
+ */
+ public VolatileImage createCompatibleVolatileImage(int width, int height,
+ ImageCapabilities caps,
+ int transparency)
+ throws AWTException
+ {
+ // Must be overridden by implementations to check caps.
+ return createCompatibleVolatileImage(width, height, transparency);
+ }
+
+ /**
* Returns a buffered image optimized to this device, and with the specified
* transparency, so that blitting can be supported in the buffered image.
*
diff --git a/libjava/classpath/java/awt/RenderingHints.java b/libjava/classpath/java/awt/RenderingHints.java
index ce327e3..e98a00c 100644
--- a/libjava/classpath/java/awt/RenderingHints.java
+++ b/libjava/classpath/java/awt/RenderingHints.java
@@ -158,7 +158,7 @@ public class RenderingHints
}
} // class KeyImpl
- private HashMap hintMap = new HashMap();
+ private HashMap
*
The stack trace of the thread (if requested on creation
* of this object
+ *
The current locks held on object monitors by the thread.
+ *
The current locks held on ownable synchronizers by the thread.
*
*
Synchronization Statistics
*
@@ -165,11 +169,28 @@ public class ThreadInfo
private StackTraceElement[] trace;
/**
+ * The array of information on monitors locked by the thread.
+ */
+ private MonitorInfo[] lockedMonitors;
+
+ /**
+ * The array of information on ownable synchronizers locked
+ * by the thread.
+ */
+ private LockInfo[] lockedSynchronizers;
+
+ /**
* Cache a local reference to the thread management bean.
*/
private static ThreadMXBean bean = null;
/**
+ * Cache the {@link javax.management.openmbean.CompositeType}
+ * for the {@link StackTraceElement}.
+ */
+ private static CompositeType seType;
+
+ /**
* Constructs a new {@link ThreadInfo} corresponding
* to the thread specified.
*
@@ -200,13 +221,57 @@ public class ThreadInfo
long waitedTime, boolean isInNative, boolean isSuspended,
StackTraceElement[] trace)
{
+ this(thread, blockedCount, blockedTime, lock, lockOwner, waitedCount,
+ waitedTime, isInNative, isSuspended, trace, new MonitorInfo[]{},
+ new LockInfo[]{});
+ }
+
+ /**
+ * Constructs a new {@link ThreadInfo} corresponding
+ * to the thread specified.
+ *
+ * @param thread the thread on which the new instance
+ * will be based.
+ * @param blockedCount the number of times the thread
+ * has been blocked.
+ * @param blockedTime the accumulated number of milliseconds
+ * the specified thread has been blocked
+ * (only used with contention monitoring enabled)
+ * @param lock the monitor lock the thread is waiting for
+ * (only used if blocked)
+ * @param lockOwner the thread which owns the monitor lock, or
+ * null if it doesn't have an owner
+ * (only used if blocked)
+ * @param waitedCount the number of times the thread has been in a
+ * waiting state.
+ * @param waitedTime the accumulated number of milliseconds the
+ * specified thread has been waiting
+ * (only used with contention monitoring enabled)
+ * @param isInNative true if the thread is in a native method.
+ * @param isSuspended true if the thread is suspended.
+ * @param trace the stack trace of the thread to a pre-determined
+ * depth (see VMThreadMXBeanImpl)
+ * @param lockedMonitors an array of {@link MonitorInfo} objects
+ * representing locks held on object monitors
+ * by the thread.
+ * @param lockedSynchronizers an array of {@link LockInfo} objects
+ * representing locks held on ownable
+ * synchronizers by the thread.
+ * @since 1.6
+ */
+ private ThreadInfo(Thread thread, long blockedCount, long blockedTime,
+ Object lock, Thread lockOwner, long waitedCount,
+ long waitedTime, boolean isInNative, boolean isSuspended,
+ StackTraceElement[] trace, MonitorInfo[] lockedMonitors,
+ LockInfo[] lockedSynchronizers)
+ {
this(thread.getId(), thread.getName(), thread.getState(), blockedCount, blockedTime,
lock == null ? null : lock.getClass().getName() + "@" +
Integer.toHexString(System.identityHashCode(lock)),
lockOwner == null ? -1 : lockOwner.getId(),
lockOwner == null ? null : lockOwner.getName(),
waitedCount, waitedTime, isInNative, isSuspended,
- trace);
+ trace, lockedMonitors, lockedSynchronizers);
}
/**
@@ -248,6 +313,59 @@ public class ThreadInfo
long waitedTime, boolean isInNative, boolean isSuspended,
StackTraceElement[] trace)
{
+ this(threadId, threadName, threadState, blockedCount, blockedTime,
+ lockName, lockOwnerId, lockOwnerName, waitedCount, waitedTime,
+ isInNative, isSuspended, trace, new MonitorInfo[]{}, new LockInfo[]{});
+ }
+
+ /**
+ * Constructs a new {@link ThreadInfo} corresponding
+ * to the thread details specified.
+ *
+ * @param threadId the id of the thread on which this
+ * new instance will be based.
+ * @param threadName the name of the thread on which
+ * this new instance will be based.
+ * @param threadState the state of the thread on which
+ * this new instance will be based.
+ * @param blockedCount the number of times the thread
+ * has been blocked.
+ * @param blockedTime the accumulated number of milliseconds
+ * the specified thread has been blocked
+ * (only used with contention monitoring enabled)
+ * @param lockName the name of the monitor lock the thread is waiting for
+ * (only used if blocked)
+ * @param lockOwnerId the id of the thread which owns the monitor
+ * lock, or -1 if it doesn't have an owner
+ * (only used if blocked)
+ * @param lockOwnerName the name of the thread which owns the monitor
+ * lock, or null if it doesn't have an
+ * owner (only used if blocked)
+ * @param waitedCount the number of times the thread has been in a
+ * waiting state.
+ * @param waitedTime the accumulated number of milliseconds the
+ * specified thread has been waiting
+ * (only used with contention monitoring enabled)
+ * @param isInNative true if the thread is in a native method.
+ * @param isSuspended true if the thread is suspended.
+ * @param trace the stack trace of the thread to a pre-determined
+ * depth (see VMThreadMXBeanImpl)
+ * @param lockedMonitors an array of {@link MonitorInfo} objects
+ * representing locks held on object monitors
+ * by the thread.
+ * @param lockedSynchronizers an array of {@link LockInfo} objects
+ * representing locks held on ownable
+ * synchronizers by the thread.
+ *
+ * @since 1.6
+ */
+ private ThreadInfo(long threadId, String threadName, Thread.State threadState,
+ long blockedCount, long blockedTime, String lockName,
+ long lockOwnerId, String lockOwnerName, long waitedCount,
+ long waitedTime, boolean isInNative, boolean isSuspended,
+ StackTraceElement[] trace, MonitorInfo[] lockedMonitors,
+ LockInfo[] lockedSynchronizers)
+ {
this.threadId = threadId;
this.threadName = threadName;
this.threadState = threadState;
@@ -261,6 +379,8 @@ public class ThreadInfo
this.isInNative = isInNative;
this.isSuspended = isSuspended;
this.trace = trace;
+ this.lockedMonitors = lockedMonitors;
+ this.lockedSynchronizers = lockedSynchronizers;
}
/**
@@ -287,6 +407,44 @@ public class ThreadInfo
}
/**
+ * Returns the {@link javax.management.openmbean.CompositeType} for
+ * a {@link StackTraceElement}.
+ *
+ * @return the type for the stack trace element.
+ */
+ static CompositeType getStackTraceType()
+ {
+ if (seType == null)
+ try
+ {
+ seType = new CompositeType(StackTraceElement.class.getName(),
+ "An element of a stack trace",
+ new String[] { "className", "methodName",
+ "fileName", "lineNumber",
+ "nativeMethod"
+ },
+ new String[] { "Name of the class",
+ "Name of the method",
+ "Name of the source code file",
+ "Line number",
+ "True if this is a native method"
+ },
+ new OpenType[] {
+ SimpleType.STRING, SimpleType.STRING,
+ SimpleType.STRING, SimpleType.INTEGER,
+ SimpleType.BOOLEAN
+ });
+ }
+ catch (OpenDataException e)
+ {
+ throw new IllegalStateException("Something went wrong in creating " +
+ "the composite data type for the " +
+ "stack trace element.", e);
+ }
+ return seType;
+ }
+
+ /**
*
* Returns a {@link ThreadInfo} instance using the values
* given in the supplied
@@ -336,70 +494,133 @@ public class ThreadInfo
if (data == null)
return null;
CompositeType type = data.getCompositeType();
- checkAttribute(type, "threadId", SimpleType.LONG);
- checkAttribute(type, "threadName", SimpleType.STRING);
- checkAttribute(type, "threadState", SimpleType.STRING);
- checkAttribute(type, "suspended", SimpleType.BOOLEAN);
- checkAttribute(type, "inNative", SimpleType.BOOLEAN);
- checkAttribute(type, "blockedCount", SimpleType.LONG);
- checkAttribute(type, "blockedTime", SimpleType.LONG);
- checkAttribute(type, "waitedCount", SimpleType.LONG);
- checkAttribute(type, "waitedTime", SimpleType.LONG);
- checkAttribute(type, "lockName", SimpleType.STRING);
- checkAttribute(type, "lockOwnerId", SimpleType.LONG);
- checkAttribute(type, "lockOwnerName", SimpleType.STRING);
+ checkAttribute(type, "ThreadId", SimpleType.LONG);
+ checkAttribute(type, "ThreadName", SimpleType.STRING);
+ checkAttribute(type, "ThreadState", SimpleType.STRING);
+ checkAttribute(type, "Suspended", SimpleType.BOOLEAN);
+ checkAttribute(type, "InNative", SimpleType.BOOLEAN);
+ checkAttribute(type, "BlockedCount", SimpleType.LONG);
+ checkAttribute(type, "BlockedTime", SimpleType.LONG);
+ checkAttribute(type, "WaitedCount", SimpleType.LONG);
+ checkAttribute(type, "WaitedTime", SimpleType.LONG);
+ checkAttribute(type, "LockName", SimpleType.STRING);
+ checkAttribute(type, "LockOwnerId", SimpleType.LONG);
+ checkAttribute(type, "LockOwnerName", SimpleType.STRING);
try
{
- CompositeType seType =
- new CompositeType(StackTraceElement.class.getName(),
- "An element of a stack trace",
- new String[] { "className", "methodName",
- "fileName", "lineNumber",
- "nativeMethod"
- },
- new String[] { "Name of the class",
- "Name of the method",
- "Name of the source code file",
- "Line number",
- "True if this is a native method"
- },
- new OpenType[] {
- SimpleType.STRING, SimpleType.STRING,
- SimpleType.STRING, SimpleType.INTEGER,
- SimpleType.BOOLEAN
- });
- checkAttribute(type, "stackTrace", new ArrayType(1, seType));
+ checkAttribute(type, "StackTrace",
+ new ArrayType(1, getStackTraceType()));
+ }
+ catch (OpenDataException e)
+ {
+ throw new IllegalStateException("Something went wrong in creating " +
+ "the array for the stack trace element.",
+ e);
+ }
+ OpenType foundType = type.getType("LockedMonitors");
+ if (foundType != null)
+ try
+ {
+ CompositeType mType = new CompositeType(MonitorInfo.class.getName(),
+ "Information on a object monitor lock",
+ new String[] { "ClassName",
+ "IdentityHashCode",
+ "LockedStackDepth",
+ "LockedStackFrame"
+ },
+ new String[] { "Name of the class",
+ "Identity hash code " +
+ "of the class",
+ "Stack depth at time " +
+ "of lock",
+ "Stack frame at time " +
+ "of lock",
+ },
+ new OpenType[] {
+ SimpleType.STRING, SimpleType.INTEGER,
+ SimpleType.INTEGER, getStackTraceType()
+ });
+ if (!(foundType.equals(new ArrayType(1, mType))))
+ throw new IllegalArgumentException("Field LockedMonitors is not of " +
+ "type " + mType.getClassName());
+ }
+ catch (OpenDataException e)
+ {
+ throw new IllegalStateException("Something went wrong in creating " +
+ "the composite data type for the " +
+ "object monitor information array.", e);
}
+ foundType = type.getType("LockedSynchronizers");
+ if (foundType != null)
+ try
+ {
+ CompositeType lType = new CompositeType(LockInfo.class.getName(),
+ "Information on a lock",
+ new String[] { "ClassName",
+ "IdentityHashCode"
+ },
+ new String[] { "Name of the class",
+ "Identity hash code " +
+ "of the class"
+ },
+ new OpenType[] {
+ SimpleType.STRING, SimpleType.INTEGER
+ });
+ if (!(foundType.equals(new ArrayType(1, lType))))
+ throw new IllegalArgumentException("Field LockedSynchronizers is not of " +
+ "type " + lType.getClassName());
+ }
catch (OpenDataException e)
{
throw new IllegalStateException("Something went wrong in creating " +
"the composite data type for the " +
- "stack trace element.", e);
+ "ownable synchronizerinformation array.", e);
}
- CompositeData[] dTraces = (CompositeData[]) data.get("stackTrace");
+ CompositeData[] dTraces = (CompositeData[]) data.get("StackTrace");
StackTraceElement[] traces = new StackTraceElement[dTraces.length];
for (int a = 0; a < dTraces.length; ++a)
/* FIXME: We can't use the boolean as there is no available
constructor. */
traces[a] =
- new StackTraceElement((String) dTraces[a].get("className"),
- (String) dTraces[a].get("methodName"),
- (String) dTraces[a].get("fileName"),
+ new StackTraceElement((String) dTraces[a].get("ClassName"),
+ (String) dTraces[a].get("MethodName"),
+ (String) dTraces[a].get("FileName"),
((Integer)
- dTraces[a].get("lineNumber")).intValue());
- return new ThreadInfo(((Long) data.get("threadId")).longValue(),
- (String) data.get("threadName"),
- Thread.State.valueOf((String) data.get("threadState")),
- ((Long) data.get("blockedCount")).longValue(),
- ((Long) data.get("blockedTime")).longValue(),
- (String) data.get("lockName"),
- ((Long) data.get("lockOwnerId")).longValue(),
- (String) data.get("lockOwnerName"),
- ((Long) data.get("waitedCount")).longValue(),
- ((Long) data.get("waitedTime")).longValue(),
- ((Boolean) data.get("inNative")).booleanValue(),
- ((Boolean) data.get("suspended")).booleanValue(),
- traces);
+ dTraces[a].get("LineNumber")).intValue());
+ MonitorInfo[] mInfo;
+ if (data.containsKey("LockedMonitors"))
+ {
+ CompositeData[] dmInfos = (CompositeData[]) data.get("LockedMonitors");
+ mInfo = new MonitorInfo[dmInfos.length];
+ for (int a = 0; a < dmInfos.length; ++a)
+ mInfo[a] = MonitorInfo.from(dmInfos[a]);
+ }
+ else
+ mInfo = new MonitorInfo[]{};
+ LockInfo[] lInfo;
+ if (data.containsKey("LockedSynchronizers"))
+ {
+ CompositeData[] dlInfos = (CompositeData[]) data.get("LockedSynchronizers");
+ lInfo = new LockInfo[dlInfos.length];
+ for (int a = 0; a < dlInfos.length; ++a)
+ lInfo[a] = new LockInfo((String) dlInfos[a].get("ClassName"),
+ (Integer) dlInfos[a].get("IdentityHashCode"));
+ }
+ else
+ lInfo = new LockInfo[]{};
+ return new ThreadInfo(((Long) data.get("ThreadId")).longValue(),
+ (String) data.get("ThreadName"),
+ Thread.State.valueOf((String) data.get("ThreadState")),
+ ((Long) data.get("BlockedCount")).longValue(),
+ ((Long) data.get("BlockedTime")).longValue(),
+ (String) data.get("LockName"),
+ ((Long) data.get("LockOwnerId")).longValue(),
+ (String) data.get("LockOwnerName"),
+ ((Long) data.get("WaitedCount")).longValue(),
+ ((Long) data.get("WaitedTime")).longValue(),
+ ((Boolean) data.get("InNative")).booleanValue(),
+ ((Boolean) data.get("Suspended")).booleanValue(),
+ traces, mInfo, lInfo);
}
/**
@@ -459,9 +680,74 @@ public class ThreadInfo
}
/**
+ * Returns an array of {@link MonitorInfo} objects representing
+ * information on the locks on object monitors held by the thread.
+ * If no locks are held, or such information was not requested
+ * on creating this {@link ThreadInfo} object, a zero-length
+ * array will be returned.
+ *
+ * @return information on object monitors locked by this thread.
+ */
+ public MonitorInfo[] getLockedMonitors()
+ {
+ return lockedMonitors;
+ }
+
+ /**
+ * Returns an array of {@link LockInfo} objects representing
+ * information on the locks on ownable synchronizers held by the thread.
+ * If no locks are held, or such information was not requested
+ * on creating this {@link ThreadInfo} object, a zero-length
+ * array will be returned.
+ *
+ * @return information on ownable synchronizers locked by this thread.
+ */
+ public LockInfo[] getLockedSynchronizers()
+ {
+ return lockedSynchronizers;
+ }
+
+ /**
+ *
+ * Returns a {@link LockInfo} object representing the
+ * lock on which this thread is blocked. If the thread
+ * is not blocked, this method returns null.
+ *
+ *
+ * The thread may be blocked due to one of three reasons:
+ *
+ *
+ *
The thread is in the BLOCKED state
+ * waiting to acquire an object monitor in order to enter
+ * a synchronized method or block.
+ *
The thread is in the WAITING or
+ * TIMED_WAITING state due to a call to
+ * {@link java.lang.Object#wait()}.
+ *
The thread is in the WAITING or
+ * TIMED_WAITING state due to a call
+ * to {@link java.util.concurrent.locks.LockSupport#park()}.
+ * The lock is the return value of
+ * {@link java.util.concurrent.locks.LockSupport#getBlocker()}.
+ *
+ *
+ * @return a {@link LockInfo} object representing the lock on
+ * which the thread is blocked, or null if
+ * the thread isn't blocked.
+ * @since 1.6
+ * @see #getLockName()
+ */
+ public LockInfo getLockInfo()
+ {
+ String lockName = getLockName();
+ int at = lockName.indexOf('@');
+ return new LockInfo(lockName.substring(0, at),
+ Integer.decode(lockName.substring(at + 1)));
+ }
+
+ /**
*
* Returns a {@link java.lang.String} representation of
- * the monitor lock on which this thread is blocked. If
+ * the lock on which this thread is blocked. If
* the thread is not blocked, this method returns
* null.
*
@@ -477,7 +763,8 @@ public class ThreadInfo
* and
* Integer.toHexString(System.identityHashCode(l)).
* The value is only unique to the extent that the identity
- * hash code is also unique.
+ * hash code is also unique. The value is the same as would
+ * be returned by getLockInfo().toString()
*
*
* @return a string representing the lock on which this
@@ -486,7 +773,7 @@ public class ThreadInfo
*/
public String getLockName()
{
- if (threadState != Thread.State.BLOCKED)
+ if (!isThreadBlocked())
return null;
return lockName;
}
@@ -504,7 +791,7 @@ public class ThreadInfo
*/
public long getLockOwnerId()
{
- if (threadState != Thread.State.BLOCKED)
+ if (!isThreadBlocked())
return -1;
return lockOwnerId;
}
@@ -522,7 +809,7 @@ public class ThreadInfo
*/
public String getLockOwnerName()
{
- if (threadState != Thread.State.BLOCKED)
+ if (!isThreadBlocked())
return null;
return lockOwnerName;
}
@@ -697,10 +984,40 @@ public class ThreadInfo
", waitedCount=" + waitedCount +
", isInNative=" + isInNative +
", isSuspended=" + isSuspended +
- (threadState == Thread.State.BLOCKED ?
+ (isThreadBlocked() ?
", lockOwnerId=" + lockOwnerId +
", lockOwnerName=" + lockOwnerName : "") +
+ ", lockedMonitors=" + Arrays.toString(lockedMonitors) +
+ ", lockedSynchronizers=" + Arrays.toString(lockedSynchronizers) +
"]";
}
+ /**
+ *
+ * Returns true if the thread is in a blocked state.
+ * The thread is regarded as blocked if:
+ *
+ *
+ *
The thread is in the BLOCKED state
+ * waiting to acquire an object monitor in order to enter
+ * a synchronized method or block.
+ *
The thread is in the WAITING or
+ * TIMED_WAITING state due to a call to
+ * {@link java.lang.Object#wait()}.
+ *
The thread is in the WAITING or
+ * TIMED_WAITING state due to a call
+ * to {@link java.util.concurrent.locks.LockSupport#park()}.
+ * The lock is the return value of
+ * {@link java.util.concurrent.locks.LockSupport#getBlocker()}.
* This bean supports some optional behaviour, which all
* virtual machines may not choose to implement. Specifically,
- * this includes the monitoring of the CPU time used by a
- * thread, and the monitoring of thread contention. The former
- * is further subdivided into the monitoring of either just
- * the current thread or all threads. The methods
+ * this includes the monitoring of:
+ *
+ *
+ *
the CPU time used by a thread
+ *
thread contention
+ *
object monitor usage
+ *
ownable synchronizer usage
+ *
+ *
+ * The monitoring of CPU time is further subdivided into
+ * the monitoring of either just the current thread or all
+ * threads. The methods
* {@link #isThreadCpuTimeSupported()},
- * {@link #isCurrentThreadCpuTimeSupported()} and
- * {@link #isThreadContentionMonitoringSupported()} may be
+ * {@link #isCurrentThreadCpuTimeSupported()}
+ * {@link #isThreadContentionMonitoringSupported()},
+ * {@link #isObjectMonitorUsageSupported()} and
+ * {@link #isSynchronizerUsageSupported()} may be
* used to determine whether or not this functionality is
* supported.
*
*
- * Furthermore, both these facilities may be disabled.
- * In fact, thread contention monitoring is disabled by
- * default, and must be explictly turned on by calling
+ * Furthermore, both time and contention monitoring may be
+ * disabled. In fact, thread contention monitoring is disabled
+ * by default, and must be explictly turned on by calling
* the {@link #setThreadContentionMonitoringEnabled(boolean)}
* method.
*
@@ -82,6 +92,70 @@ public interface ThreadMXBean
{
/**
+ * This method returns information on all live threads at the
+ * time of execution (some threads may have terminated by the
+ * time the method completes). This method is simply a shorthand
+ * for calling {@link #getThreadInfo(long[], boolean,
+ * boolean)} with the return value of {@link #getAllThreadIds()}.
+ *
+ * @param lockedMonitors true if the returned {@link ThreadInfo}
+ * objects should contain information on
+ * locked monitors.
+ * @param lockedSynchronizers true if the returned {@link ThreadInfo}
+ * objects should contain information
+ * on locked ownable synchronizers.
+ * @return an array of {@link ThreadInfo} objects for all live threads.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ * @throws UnsupportedOperationException if lockedMonitors
+ * is true, but object monitor
+ * usage monitoring is not supported
+ * by the VM, or
+ * lockedSynchronizers
+ * is true, but ownable synchronizer
+ * usage monitoring is not supported
+ * by the VM.
+ * @since 1.6
+ * @see #getThreadInfo(long[], boolean, boolean)
+ * @see #getAllThreadIds()
+ * @see #isObjectMonitorUsageSupported()
+ * @see #isSynchronizerUsageSupported()
+ */
+ ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
+ boolean lockedSynchronizers);
+
+ /**
+ *
+ * This method obtains a list of threads which are deadlocked
+ * waiting to obtain monitor or ownable synchronizer ownership.
+ * This is similar to the behaviour described for
+ * {@link #getMonitorDeadlockedThreads()}, except this method also
+ * takes in to account deadlocks involving ownable synchronizers.
+ *
+ *
+ * Note that this method is not designed for controlling
+ * synchronization, but for troubleshooting problems which cause such
+ * deadlocks; it may be prohibitively expensive to use in normal
+ * operation. If only deadlocks involving monitors are of interest,
+ * then {@link #findMonitorDeadlockedThreads()} should be used in
+ * preference to this method.
+ *
+ *
+ * @return an array of thread identifiers, corresponding to threads
+ * which are currently in a deadlocked situation, or
+ * null if there are no deadlocks.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ * @throws UnsupportedOperationException if the VM does not support
+ * the monitoring of ownable
+ * synchronizer usage.
+ * @since 1.6
+ * @see #findMonitorDeadlockedThreads()
+ * @see #isSynchronizerUsageSupported()
+ */
+ long[] findDeadlockedThreads();
+
+ /**
*
* This method obtains a list of threads which are deadlocked
* waiting to obtain monitor ownership. On entering a synchronized
@@ -115,13 +189,17 @@ public interface ThreadMXBean
* of A and B. Note that this method is not designed for controlling
* synchronization, but for troubleshooting problems which cause such
* deadlocks; it may be prohibitively expensive to use in normal
- * operation.
+ * operation. This method only returns deadlocks involving monitors;
+ * to include deadlocks involving ownable synchronizers,
+ * {@link #findDeadlockedThreads()} should be used instead.
*
*
* @return an array of thread identifiers, corresponding to threads
- * which are currently in a deadlocked situation.
+ * which are currently in a deadlocked situation, or
+ * null if there are no deadlocks.
* @throws SecurityException if a security manager exists and
* denies ManagementPermission("monitor").
+ * @see #findDeadlockedThreads()
*/
long[] findMonitorDeadlockedThreads();
@@ -285,6 +363,53 @@ public interface ThreadMXBean
ThreadInfo[] getThreadInfo(long[] ids);
/**
+ * Returns information on the specified threads with full
+ * stack trace information and optional synchronization
+ * information. If lockedMonitors is false,
+ * or there are no locked monitors for a particular thread,
+ * then the corresponding {@link ThreadInfo} object will have
+ * an empty {@link MonitorInfo} array. Likewise, if
+ * lockedSynchronizers is false, or there are
+ * no locked ownable synchronizers for a particular thread,
+ * then the corresponding {@link ThreadInfo} object will have
+ * an empty {@link LockInfo} array. If both
+ * lockedMonitors and lockedSynchronizers
+ * are false, the return value is equivalent to that from
+ * {@link #getThreadInfo}(ids, Integer.MAX_VALUE).
+ * If an identifier specifies a thread which is either non-existant
+ * or not alive, then the corresponding element in the returned
+ * array is null.
+ *
+ * @param ids an array of thread identifiers to return information
+ * on.
+ * @param lockedMonitors true if information on locked monitors
+ * should be included.
+ * @param lockedSynchronizers true if information on locked
+ * ownable synchronizers should be included.
+ * @return an array of {@link ThreadInfo} objects matching the
+ * specified threads. The corresponding element is
+ * null if the identifier specifies
+ * a thread that doesn't exist or is not alive.
+ * @throws IllegalArgumentException if an identifier in the array is
+ * <= 0.
+ * @throws SecurityException if a security manager exists and
+ * denies ManagementPermission("monitor").
+ * @throws UnsupportedOperationException if lockedMonitors
+ * is true, but object monitor
+ * usage monitoring is not supported
+ * by the VM, or
+ * lockedSynchronizers
+ * is true, but ownable synchronizer
+ * usage monitoring is not supported
+ * by the VM.
+ * @since 1.6
+ * @see #isObjectMonitorUsageSupported()
+ * @see #isSynchronizerUsageSupported()
+ */
+ ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,
+ boolean lockedSynchronizers);
+
+ /**
* Returns information on the specified thread with
* stack trace information to the supplied depth. If the
* identifier specifies a thread which is either non-existant
@@ -390,6 +515,26 @@ public interface ThreadMXBean
boolean isCurrentThreadCpuTimeSupported();
/**
+ * Returns true if the virtual machine supports the monitoring
+ * of object monitor usage.
+ *
+ * @return true if the monitoring of object monitor usage
+ * is supported by the virtual machine.
+ * @since 1.6
+ */
+ boolean isObjectMonitorUsageSupported();
+
+ /**
+ * Returns true if the virtual machine supports the monitoring
+ * of ownable synchronizer usage.
+ *
+ * @return true if the monitoring of ownable synchronizer usage
+ * is supported by the virtual machine.
+ * @since 1.6
+ */
+ boolean isSynchronizerUsageSupported();
+
+ /**
* Returns true if thread contention monitoring is currently
* enabled.
*
diff --git a/libjava/classpath/java/math/BigInteger.java b/libjava/classpath/java/math/BigInteger.java
index c897d8b..8d174d0 100644
--- a/libjava/classpath/java/math/BigInteger.java
+++ b/libjava/classpath/java/math/BigInteger.java
@@ -573,7 +573,7 @@ public class BigInteger extends Number implements Comparable
long y_ext = y.words[i - 1] < 0 ? 0xffffffffL : 0;
for (; i < x.ival; i++)
{
- carry += ((long) x.words[i] & 0xffffffffL) + y_ext;;
+ carry += ((long) x.words[i] & 0xffffffffL) + y_ext;
result.words[i] = (int) carry;
carry >>>= 32;
}
@@ -1912,8 +1912,7 @@ public class BigInteger extends Number implements Comparable
private static void setBitOp(BigInteger result, int op,
BigInteger x, BigInteger y)
{
- if (y.words == null) ;
- else if (x.words == null || x.ival < y.ival)
+ if ((y.words != null) && (x.words == null || x.ival < y.ival))
{
BigInteger temp = x; x = y; y = temp;
op = swappedOp(op);
diff --git a/libjava/classpath/java/math/class-dependencies.conf b/libjava/classpath/java/math/class-dependencies.conf
deleted file mode 100644
index 4fbf75e..0000000
--- a/libjava/classpath/java/math/class-dependencies.conf
+++ /dev/null
@@ -1,58 +0,0 @@
-# This property file contains dependencies of classes, methods, and
-# field on other methods or classes.
-#
-# Syntax:
-#
-# : [... ]
-#
-# means that when is included, (... ) must
-# be included as well.
-#
-# and are of the form
-#
-#
-#
-# or just
-#
-#
-#
-# Within dependencies, variables can be used. A variable is defined as
-# follows:
-#
-# {variable}: value1 value2 ... value
-#
-# variables can be used on the right side of dependencies as follows:
-#
-# : com.bla.blu.{variable}.Class.m()V
-#
-# The use of the variable will expand to dependencies of the form
-#
-# : com.bla.blu.value1.Class.m()V
-# : com.bla.blu.value2.Class.m()V
-# ...
-# : com.bla.blu.value.Class.m()V
-#
-# Variables can be redefined when building a system to select the
-# required support for features like encodings, protocols, etc.
-#
-# Hints:
-#
-# - For methods and fields, the signature is mandatory. For
-# specification, please see the Java Virtual Machine Specification by
-# SUN. Unlike in the spec, field signatures (types) are in brackets.
-#
-# - Package names must be separated by '/' (and not '.'). E.g.,
-# java/lang/Class (this is necessary, because the '.' is used to
-# separate method or field names from classes)
-#
-# - In case refers to a class, only the class itself will be
-# included in the resulting binary, NOT necessarily all its methods
-# and fields. If you want to refer to all methods and fields, you can
-# write class.* as an abbreviation.
-#
-# - Abbreviations for packages are also possible: my/package/* means all
-# methods and fields of all classes in my/package.
-#
-# - A line with a trailing '\' continues in the next line.
-
-# end of file
diff --git a/libjava/classpath/java/net/MimeTypeMapper.java b/libjava/classpath/java/net/MimeTypeMapper.java
index 8153694..b0d400c 100644
--- a/libjava/classpath/java/net/MimeTypeMapper.java
+++ b/libjava/classpath/java/net/MimeTypeMapper.java
@@ -232,7 +232,8 @@ class MimeTypeMapper implements FileNameMap
/**
* The MIME types above are put into this Hashtable for faster lookup.
*/
- private Hashtable mime_types = new Hashtable(150);
+ private Hashtable mime_types
+ = new Hashtable(150);
/**
* Create a new MimeTypeMapper object.
@@ -257,7 +258,7 @@ class MimeTypeMapper implements FileNameMap
}
}
- public static void fillFromFile (Map table, String fname)
+ public static void fillFromFile (Map table, String fname)
throws IOException
{
LineNumberReader reader =
@@ -325,17 +326,17 @@ class MimeTypeMapper implements FileNameMap
*/
public static void main(String[] args) throws IOException
{
- TreeMap map = new TreeMap();
+ TreeMap map = new TreeMap();
// It is fine to hard-code the name here. This is only ever
// used by maintainers, who can hack it if they need to re-run
// it.
fillFromFile(map, "/etc/mime.types");
- Iterator it = map.keySet().iterator();
+ Iterator it = map.keySet().iterator();
boolean first = true;
while (it.hasNext())
{
- String key = (String) it.next();
- String value = (String) map.get(key);
+ String key = it.next();
+ String value = map.get(key);
// Put the "," first since it is easier to make correct syntax this way.
System.out.println(" " + (first ? " " : ", ")
+ "{ \"" + key + "\", \"" + value + "\" }");
diff --git a/libjava/classpath/java/net/MulticastSocket.java b/libjava/classpath/java/net/MulticastSocket.java
index 2841192..114d11f 100644
--- a/libjava/classpath/java/net/MulticastSocket.java
+++ b/libjava/classpath/java/net/MulticastSocket.java
@@ -1,5 +1,5 @@
/* MulticastSocket.java -- Class for using multicast sockets
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2007
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -337,7 +337,7 @@ public class MulticastSocket extends DatagramSocket
/**
* Sets the "Time to Live" value for a socket. The value must be between
- * 1 and 255.
+ * 0 and 255, inclusive.
*
* @param ttl The new TTL value
*
@@ -350,7 +350,7 @@ public class MulticastSocket extends DatagramSocket
if (isClosed())
throw new SocketException("socket is closed");
- if (ttl <= 0 || ttl > 255)
+ if (ttl < 0 || ttl > 255)
throw new IllegalArgumentException("Invalid ttl: " + ttl);
getImpl().setTimeToLive(ttl);
diff --git a/libjava/classpath/java/net/NetworkInterface.java b/libjava/classpath/java/net/NetworkInterface.java
index 6c78ead..a3a6058 100644
--- a/libjava/classpath/java/net/NetworkInterface.java
+++ b/libjava/classpath/java/net/NetworkInterface.java
@@ -40,12 +40,8 @@ package java.net;
import gnu.classpath.SystemProperties;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
import java.util.Vector;
/**
@@ -100,7 +96,8 @@ public final class NetworkInterface
public Enumeration getInetAddresses()
{
SecurityManager s = System.getSecurityManager();
- Vector inetAddresses = new Vector(netif.addresses);
+ Vector inetAddresses
+ = new Vector(netif.addresses);
if (s == null)
return inetAddresses.elements();
diff --git a/libjava/classpath/java/net/Proxy.java b/libjava/classpath/java/net/Proxy.java
index 6f9f1b6..3151774 100644
--- a/libjava/classpath/java/net/Proxy.java
+++ b/libjava/classpath/java/net/Proxy.java
@@ -57,7 +57,7 @@ public class Proxy
* For compatability with Sun's JDK
*/
private static final long serialVersionUID = -2231209257930100533L;
- };
+ }
public static final Proxy NO_PROXY = new Proxy(Type.DIRECT, null);
diff --git a/libjava/classpath/java/net/ResolverCache.java b/libjava/classpath/java/net/ResolverCache.java
index f879066..d57df49 100644
--- a/libjava/classpath/java/net/ResolverCache.java
+++ b/libjava/classpath/java/net/ResolverCache.java
@@ -97,12 +97,12 @@ class ResolverCache
/**
* The cache itself.
*/
- private static HashMap cache = new HashMap();
+ private static HashMap cache = new HashMap();
/**
* List of entries which may expire.
*/
- private static LinkedList killqueue = new LinkedList();
+ private static LinkedList killqueue = new LinkedList();
/**
* Return the hostname for the specified IP address.
diff --git a/libjava/classpath/java/net/ServerSocket.java b/libjava/classpath/java/net/ServerSocket.java
index d5f2a17..9cefd29 100644
--- a/libjava/classpath/java/net/ServerSocket.java
+++ b/libjava/classpath/java/net/ServerSocket.java
@@ -85,9 +85,7 @@ public class ServerSocket
* This constructor is only used by java.nio.
*/
- // FIXME: Workaround a bug in gcj.
- //ServerSocket (PlainSocketImpl impl) throws IOException
- ServerSocket(SocketImpl impl) throws IOException
+ ServerSocket(PlainSocketImpl impl) throws IOException
{
if (impl == null)
throw new NullPointerException("impl may not be null");
@@ -101,8 +99,6 @@ public class ServerSocket
* This method is only used by java.nio.
*/
- // FIXME: Workaround a bug in gcj.
- //PlainSocketImpl getImpl()
SocketImpl getImpl()
{
return impl;
@@ -390,6 +386,7 @@ public class ServerSocket
impl.accept(socket.impl);
socket.bound = true;
+ socket.implCreated = true;
SecurityManager sm = System.getSecurityManager();
if (sm != null)
diff --git a/libjava/classpath/java/net/Socket.java b/libjava/classpath/java/net/Socket.java
index f4f25fe..6480527 100644
--- a/libjava/classpath/java/net/Socket.java
+++ b/libjava/classpath/java/net/Socket.java
@@ -1,5 +1,5 @@
/* Socket.java -- Client socket implementation
- Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2006
+ Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2006, 2007
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -83,6 +83,12 @@ public class Socket
SocketImpl impl;
/**
+ * True if impl.create() has been called.
+ */
+ // package-private because ServerSocket.implAccept() needs to access it.
+ boolean implCreated;
+
+ /**
* True if the socket is bound.
* Package private so it can be set from ServerSocket when accept is called.
*/
@@ -326,11 +332,23 @@ public class Socket
private SocketImpl getImpl() throws SocketException
{
+ if (! implCreated)
+ {
+ try
+ {
+ impl.create(true);
+ }
+ catch (IOException x)
+ {
+ throw (SocketException) new SocketException().initCause(x);
+ }
+ implCreated = true;
+ }
return impl;
}
/**
- * Binds the socket to the givent local address/port
+ * Binds the socket to the given local address/port
*
* @param bindpoint The address/port to bind to
*
@@ -359,7 +377,6 @@ public class Socket
// bind to address/port
try
{
- getImpl().create(true);
getImpl().bind(tmp.getAddress(), tmp.getPort());
bound = true;
}
diff --git a/libjava/classpath/java/net/URI.java b/libjava/classpath/java/net/URI.java
index 689843c..43b10fc 100644
--- a/libjava/classpath/java/net/URI.java
+++ b/libjava/classpath/java/net/URI.java
@@ -693,7 +693,7 @@ public final class URI
String portStr = getURIGroup(matcher, AUTHORITY_PORT_GROUP);
- if (portStr != null)
+ if (portStr != null && ! portStr.isEmpty())
try
{
port = Integer.parseInt(portStr);
diff --git a/libjava/classpath/java/net/URL.java b/libjava/classpath/java/net/URL.java
index 8f72d06..16a606f 100644
--- a/libjava/classpath/java/net/URL.java
+++ b/libjava/classpath/java/net/URL.java
@@ -190,7 +190,8 @@ public final class URL implements Serializable
* This a table where we cache protocol handlers to avoid the overhead
* of looking them up each time.
*/
- private static HashMap ph_cache = new HashMap();
+ private static HashMap ph_cache
+ = new HashMap();
/**
* Whether or not to cache protocol handlers.
@@ -901,7 +902,7 @@ public final class URL implements Serializable
// First, see if a protocol handler is in our cache.
if (cache_handlers)
{
- if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null)
+ if ((ph = ph_cache.get(protocol)) != null)
return ph;
}
@@ -934,9 +935,9 @@ public final class URL implements Serializable
// Cache the systemClassLoader
if (systemClassLoader == null)
{
- systemClassLoader = (ClassLoader) AccessController.doPrivileged
- (new PrivilegedAction() {
- public Object run()
+ systemClassLoader = AccessController.doPrivileged
+ (new PrivilegedAction() {
+ public ClassLoader run()
{
return ClassLoader.getSystemClassLoader();
}
diff --git a/libjava/classpath/java/net/URLClassLoader.java b/libjava/classpath/java/net/URLClassLoader.java
index 7e2353a..6df2818 100644
--- a/libjava/classpath/java/net/URLClassLoader.java
+++ b/libjava/classpath/java/net/URLClassLoader.java
@@ -145,7 +145,7 @@ public class URLClassLoader extends SecureClassLoader
// Instance variables
/** Locations to load classes from */
- private final Vector urls = new Vector();
+ private final Vector urls = new Vector();
/**
* Store pre-parsed information for each url into this vector: each
@@ -153,7 +153,7 @@ public class URLClassLoader extends SecureClassLoader
* attribute which adds to the URLs that will be searched, but this
* does not add to the list of urls.
*/
- private final Vector urlinfos = new Vector();
+ private final Vector urlinfos = new Vector();
/** Factory used to get the protocol handlers of the URLs */
private final URLStreamHandlerFactory factory;
@@ -301,7 +301,6 @@ public class URLClassLoader extends SecureClassLoader
if ("file".equals (protocol))
{
File dir = new File(file);
- URL absUrl;
try
{
absoluteURL = dir.getCanonicalFile().toURL();
@@ -329,12 +328,12 @@ public class URLClassLoader extends SecureClassLoader
// First see if we can find a handler with the correct name.
try
{
- Class handler = Class.forName(URL_LOADER_PREFIX + protocol);
- Class[] argTypes = new Class[] { URLClassLoader.class,
- URLStreamHandlerCache.class,
- URLStreamHandlerFactory.class,
- URL.class,
- URL.class };
+ Class> handler = Class.forName(URL_LOADER_PREFIX + protocol);
+ Class>[] argTypes = new Class>[] { URLClassLoader.class,
+ URLStreamHandlerCache.class,
+ URLStreamHandlerFactory.class,
+ URL.class,
+ URL.class };
Constructor k = handler.getDeclaredConstructor(argTypes);
loader
= (URLLoader) k.newInstance(new Object[] { this,
@@ -395,7 +394,7 @@ public class URLClassLoader extends SecureClassLoader
}
urlinfos.add(loader);
- ArrayList extra = loader.getClassPath();
+ ArrayList extra = loader.getClassPath();
if (extra != null)
urlinfos.addAll(extra);
}
@@ -602,10 +601,10 @@ public class URLClassLoader extends SecureClassLoader
Class result = null;
if (sm != null && securityContext != null)
{
- result = (Class)AccessController.doPrivileged
- (new PrivilegedAction()
+ result = AccessController.doPrivileged
+ (new PrivilegedAction()
{
- public Object run()
+ public Class run()
{
return defineClass(className, classData,
0, classData.length,
@@ -848,9 +847,9 @@ public class URLClassLoader extends SecureClassLoader
+ securityContext);
URLClassLoader loader =
- (URLClassLoader) AccessController.doPrivileged(new PrivilegedAction()
+ AccessController.doPrivileged(new PrivilegedAction()
{
- public Object run()
+ public URLClassLoader run()
{
return new URLClassLoader(parent,
(AccessControlContext) securityContext);
diff --git a/libjava/classpath/java/net/class-dependencies.conf b/libjava/classpath/java/net/class-dependencies.conf
deleted file mode 100644
index 8b130f5..0000000
--- a/libjava/classpath/java/net/class-dependencies.conf
+++ /dev/null
@@ -1,122 +0,0 @@
-# This property file contains dependencies of classes, methods, and
-# field on other methods or classes.
-#
-# Syntax:
-#
-# : [... ]
-#
-# means that when is included, (... ) must
-# be included as well.
-#
-# and are of the form
-#
-#
-#
-# or just
-#
-#
-#
-# Within dependencies, variables can be used. A variable is defined as
-# follows:
-#
-# {variable}: value1 value2 ... value
-#
-# variables can be used on the right side of dependencies as follows:
-#
-# : com.bla.blu.{variable}.Class.m()V
-#
-# The use of the variable will expand to dependencies of the form
-#
-# : com.bla.blu.value1.Class.m()V
-# : com.bla.blu.value2.Class.m()V
-# ...
-# : com.bla.blu.value.Class.m()V
-#
-# Variables can be redefined when building a system to select the
-# required support for features like encodings, protocols, etc.
-#
-# Hints:
-#
-# - For methods and fields, the signature is mandatory. For
-# specification, please see the Java Virtual Machine Specification by
-# SUN. Unlike in the spec, field signatures (types) are in brackets.
-#
-# - Package names must be separated by '/' (and not '.'). E.g.,
-# java/lang/Class (this is necessary, because the '.' is used to
-# separate method or field names from classes)
-#
-# - In case refers to a class, only the class itself will be
-# included in the resulting binary, NOT necessarily all its methods
-# and fields. If you want to refer to all methods and fields, you can
-# write class.* as an abbreviation.
-#
-# - Abbreviations for packages are also possible: my/package/* means all
-# methods and fields of all classes in my/package.
-#
-# - A line with a trailing '\' continues in the next line.
-
-java/net/InetAddress: \
- java/lang/ClassNotFoundException.(Ljava/lang/String;)V \
- java/lang/InternalError.(Ljava/lang/String;)V \
- java/net/UnknownHostException.(Ljava/lang/String;)V
-
-java/net/DatagramSocketImpl: \
- java/net/DatagramSocketImpl.fd(Ljava/io/FileDescriptor;) \
- java/net/DatagramSocketImpl.localPort(I)
-
-java/net/PlainDatagramSocketImpl: \
- java/lang/ClassNotFoundException.(Ljava/lang/String;)V \
- java/lang/InternalError.(Ljava/lang/String;)V \
- java/io/IOException.(Ljava/lang/String;)V \
- java/io/FileDescriptor.()V \
- java/lang/Boolean.(Z)V \
- java/lang/Integer.(I)V \
- java/net/InetAddress.getByName(Ljava/lang/String;)Ljava/net/InetAddress; \
- java/net/InetAddress.getAddress()[B \
- java/lang/Boolean.booleanValue()Z \
- java/lang/Integer.intValue()I \
- java/net/SocketException.(Ljava/lang/String;)V \
- java/net/DatagramPacket.getData()[B \
- java/net/SocketImpl.address(Ljava/net/InetAddress;) \
- java/net/PlainSocketImpl.native_fd(I) \
- java/net/SocketImpl.fd(Ljava/io/FileDescriptor;) \
- java/net/SocketImpl.address(Ljava/net/InetAddress;) \
- java/net/PlainDatagramSocketImpl.native_fd(I) \
- java/net/SocketImpl.localport(I) \
- java/net/SocketImpl.port(I)
-
-java/net/PlainSocketImpl: \
- java/lang/ClassNotFoundException.(Ljava/lang/String;)V \
- java/lang/InternalError.(Ljava/lang/String;)V \
- java/io/IOException.(Ljava/lang/String;)V \
- java/io/FileDescriptor.()V \
- java/lang/Boolean.(Z)V \
- java/lang/Integer.(I)V \
- java/net/InetAddress.getByName(Ljava/lang/String;)Ljava/net/InetAddress; \
- java/net/InetAddress.getAddress()[B \
- java/lang/Boolean.booleanValue()Z \
- java/lang/Integer.intValue()I \
- java/net/SocketException.(Ljava/lang/String;)V \
- java/net/DatagramPacket.getData()[B \
- java/net/SocketImpl.address(Ljava/net/InetAddress;) \
- java/net/PlainSocketImpl.native_fd(I) \
- java/net/SocketImpl.fd(Ljava/io/FileDescriptor;) \
- java/net/SocketImpl.address(Ljava/net/InetAddress;) \
- java/net/PlainDatagramSocketImpl.native_fd(I) \
- java/net/SocketImpl.localport(I) \
- java/net/SocketImpl.port(I)
-
-# All protocols supported are loaded via URL.getURLStreamHandler from
-# class gnu.java.net.protocol..Handler.
-#
-# This introduces a dependency for all protocols. To allow an easy selection
-# and addition of protocols, the library variable {protocols} can be set to
-# the set of supported protocols.
-#
-{protocols}: http file jar
-
-java/net/URL.getURLStreamHandler(Ljava/lang/String;)Ljava/net/URLStreamHandler;: \
- gnu/java/net/protocol/{protocols}/Handler.* \
- com/aicas/java/net/protocol/rom/Handler.*
-
-# end of file
diff --git a/libjava/classpath/java/nio/ByteOrder.java b/libjava/classpath/java/nio/ByteOrder.java
index 39a3ff8..0e3b917 100644
--- a/libjava/classpath/java/nio/ByteOrder.java
+++ b/libjava/classpath/java/nio/ByteOrder.java
@@ -61,7 +61,9 @@ public final class ByteOrder
*/
public static ByteOrder nativeOrder()
{
- return (System.getProperty ("gnu.cpu.endian").equals("big")
+ // Let this fail with an NPE when the property is not set correctly.
+ // Otherwise we risk that NIO is silently working wrong.
+ return (System.getProperty("gnu.cpu.endian").equals("big")
? BIG_ENDIAN : LITTLE_ENDIAN);
}
diff --git a/libjava/classpath/java/nio/channels/spi/SelectorProvider.java b/libjava/classpath/java/nio/channels/spi/SelectorProvider.java
index db4e65f..b2fb7bb 100644
--- a/libjava/classpath/java/nio/channels/spi/SelectorProvider.java
+++ b/libjava/classpath/java/nio/channels/spi/SelectorProvider.java
@@ -40,6 +40,7 @@ package java.nio.channels.spi;
import gnu.java.nio.SelectorProviderImpl;
import java.io.IOException;
+import java.nio.channels.Channel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
import java.nio.channels.ServerSocketChannel;
@@ -115,6 +116,32 @@ public abstract class SelectorProvider
public abstract SocketChannel openSocketChannel() throws IOException;
/**
+ * Returns the inherited channel of the VM.
+ *
+ * @return the inherited channel of the VM
+ *
+ * @throws IOException If an I/O error occurs
+ * @throws SecurityException If an installed security manager denies access
+ * to RuntimePermission("inheritedChannel")
+ *
+ * @since 1.5
+ */
+ public Channel inheritedChannel()
+ throws IOException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ {
+ sm.checkPermission(new RuntimePermission("inheritedChannel"));
+ }
+ // Implementation note: The default implementation can't do much more
+ // than return null. If a VM can provide something more useful it should
+ // install its own SelectorProvider (maybe a subclass of this one) to
+ // return something more useful.
+ return null;
+ }
+
+ /**
* Returns the system-wide default selector provider for this invocation
* of the Java virtual machine.
*
diff --git a/libjava/classpath/java/nio/class-dependencies.conf b/libjava/classpath/java/nio/class-dependencies.conf
deleted file mode 100644
index 4fbf75e..0000000
--- a/libjava/classpath/java/nio/class-dependencies.conf
+++ /dev/null
@@ -1,58 +0,0 @@
-# This property file contains dependencies of classes, methods, and
-# field on other methods or classes.
-#
-# Syntax:
-#
-# : [... ]
-#
-# means that when is included, (... ) must
-# be included as well.
-#
-# and are of the form
-#
-#
-#
-# or just
-#
-#
-#
-# Within dependencies, variables can be used. A variable is defined as
-# follows:
-#
-# {variable}: value1 value2 ... value
-#
-# variables can be used on the right side of dependencies as follows:
-#
-# : com.bla.blu.{variable}.Class.m()V
-#
-# The use of the variable will expand to dependencies of the form
-#
-# : com.bla.blu.value1.Class.m()V
-# : com.bla.blu.value2.Class.m()V
-# ...
-# : com.bla.blu.value.Class.m()V
-#
-# Variables can be redefined when building a system to select the
-# required support for features like encodings, protocols, etc.
-#
-# Hints:
-#
-# - For methods and fields, the signature is mandatory. For
-# specification, please see the Java Virtual Machine Specification by
-# SUN. Unlike in the spec, field signatures (types) are in brackets.
-#
-# - Package names must be separated by '/' (and not '.'). E.g.,
-# java/lang/Class (this is necessary, because the '.' is used to
-# separate method or field names from classes)
-#
-# - In case refers to a class, only the class itself will be
-# included in the resulting binary, NOT necessarily all its methods
-# and fields. If you want to refer to all methods and fields, you can
-# write class.* as an abbreviation.
-#
-# - Abbreviations for packages are also possible: my/package/* means all
-# methods and fields of all classes in my/package.
-#
-# - A line with a trailing '\' continues in the next line.
-
-# end of file
diff --git a/libjava/classpath/java/rmi/activation/ActivationID.java b/libjava/classpath/java/rmi/activation/ActivationID.java
index c4bbcd2..e1cc8a7 100644
--- a/libjava/classpath/java/rmi/activation/ActivationID.java
+++ b/libjava/classpath/java/rmi/activation/ActivationID.java
@@ -174,7 +174,7 @@ public class ActivationID
{
out.writeObject(uid);
out.writeObject(activator);
- };
+ }
/**
* Compare by .equals if both a and b are not null, compare directly if at
diff --git a/libjava/classpath/java/rmi/server/UnicastRemoteObject.java b/libjava/classpath/java/rmi/server/UnicastRemoteObject.java
index 31bf880..6ef3432 100644
--- a/libjava/classpath/java/rmi/server/UnicastRemoteObject.java
+++ b/libjava/classpath/java/rmi/server/UnicastRemoteObject.java
@@ -239,11 +239,12 @@ public class UnicastRemoteObject extends RemoteServer
(UnicastServerRef) ((RemoteObject) obj).getRef();
return sref.unexportObject(obj, force);
}
- else
+ // FIXME
+ /* else
{
- // FIXME
;
}
+ */
return true;
}
diff --git a/libjava/classpath/java/security/BasicPermission.java b/libjava/classpath/java/security/BasicPermission.java
index ef2cc4d..6296cff 100644
--- a/libjava/classpath/java/security/BasicPermission.java
+++ b/libjava/classpath/java/security/BasicPermission.java
@@ -73,9 +73,8 @@ import java.util.Hashtable;
* @since 1.1
* @status updated to 1.4
*/
-public abstract class BasicPermission extends java.security.Permission
+public abstract class BasicPermission extends Permission
implements Serializable
- // FIXME extends with fully qualified classname as workaround for gcj 3.3.
{
/**
* Compatible with JDK 1.1+.
diff --git a/libjava/classpath/java/security/Permission.java b/libjava/classpath/java/security/Permission.java
index 48f4d52..9072d95 100644
--- a/libjava/classpath/java/security/Permission.java
+++ b/libjava/classpath/java/security/Permission.java
@@ -181,7 +181,20 @@ public abstract class Permission implements Guard, Serializable
*/
public String toString()
{
- return '(' + getClass().getName() + ' ' + getName() + ' '
- + getActions() + ')';
+ StringBuffer string = new StringBuffer();
+
+ string = string.append('(');
+ string = string.append(getClass().getName());
+ string = string.append(' ');
+ string = string.append(getName());
+
+ if (!(getActions().equals("")))
+ {
+ string = string.append(' ');
+ string = string.append(getActions());
+ }
+
+ string = string.append(')');
+ return string.toString();
}
} // class Permission
diff --git a/libjava/classpath/java/security/SecureClassLoader.java b/libjava/classpath/java/security/SecureClassLoader.java
index dfc1758..f683f9a 100644
--- a/libjava/classpath/java/security/SecureClassLoader.java
+++ b/libjava/classpath/java/security/SecureClassLoader.java
@@ -99,7 +99,7 @@ public class SecureClassLoader extends ClassLoader
*
* @since 1.5
*/
- protected final Class defineClass(String name, ByteBuffer b, CodeSource cs)
+ protected final Class> defineClass(String name, ByteBuffer b, CodeSource cs)
{
return super.defineClass(name, b, getProtectionDomain(cs));
}
diff --git a/libjava/classpath/java/security/SignatureSpi.java b/libjava/classpath/java/security/SignatureSpi.java
index 3b46815..80ecbfd 100644
--- a/libjava/classpath/java/security/SignatureSpi.java
+++ b/libjava/classpath/java/security/SignatureSpi.java
@@ -136,16 +136,23 @@ public abstract class SignatureSpi
* bytes of the given buffer.
*
* @param input The input buffer.
- * @throws SignatureException
+ * @throws IllegalStateException if the engine is not properly initialized.
*/
- protected void engineUpdate(ByteBuffer input) throws SignatureException
+ protected void engineUpdate(ByteBuffer input)
{
byte[] buf = new byte[4096];
while (input.hasRemaining())
{
int l = Math.min(input.remaining(), buf.length);
input.get(buf, 0, l);
- engineUpdate(buf, 0, l);
+ try
+ {
+ engineUpdate(buf, 0, l);
+ }
+ catch (SignatureException se)
+ {
+ throw new IllegalStateException(se);
+ }
}
}
diff --git a/libjava/classpath/java/security/cert/X509CertSelector.java b/libjava/classpath/java/security/cert/X509CertSelector.java
index 154ed2e..7a7db08 100644
--- a/libjava/classpath/java/security/cert/X509CertSelector.java
+++ b/libjava/classpath/java/security/cert/X509CertSelector.java
@@ -1,5 +1,5 @@
/* X509CertSelector.java -- selects X.509 certificates by criteria.
- Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,9 +40,17 @@ package java.security.cert;
import gnu.classpath.SystemProperties;
import gnu.java.security.OID;
+import gnu.java.security.x509.GnuPKIExtension;
+import gnu.java.security.x509.ext.CertificatePolicies;
+import gnu.java.security.x509.ext.Extension;
+import gnu.java.security.x509.ext.GeneralName;
+import gnu.java.security.x509.ext.GeneralSubtree;
+import gnu.java.security.x509.ext.NameConstraints;
+import gnu.java.security.x509.ext.GeneralName.Kind;
import java.io.IOException;
import java.math.BigInteger;
+import java.net.InetAddress;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
@@ -88,6 +96,48 @@ public class X509CertSelector implements CertSelector, Cloneable
private static final String SUBJECT_KEY_ID = "2.5.29.14";
private static final String NAME_CONSTRAINTS_ID = "2.5.29.30";
+ private static boolean checkOid(int[] oid)
+ {
+ return (oid != null && oid.length > 2 &&
+ (oid[0] >= 0 && oid[0] <= 2) && (oid[1] >= 0 && oid[1] <= 39));
+ }
+
+ private static GeneralName makeName(int id, String name) throws IOException
+ {
+ byte[] nameBytes = null;
+ GeneralName.Kind kind = GeneralName.Kind.forTag(id);
+ switch (Kind.forTag(id))
+ {
+ case dNSName:
+ case rfc822Name:
+ case uniformResourceIdentifier:
+ nameBytes = name.getBytes("ASCII");
+ break;
+
+ case iPAddress:
+ InetAddress addr = InetAddress.getByName(name);
+ nameBytes = addr.getAddress();
+ break;
+
+ case registeredId:
+ OID oid = new OID(name);
+ nameBytes = oid.getDER();
+ break;
+
+ case directoryName:
+ X500Principal xname = new X500Principal(name);
+ nameBytes = xname.getEncoded();
+ break;
+
+ case ediPartyName:
+ case x400Address:
+ case otherName:
+ throw new IOException("cannot decode string representation of "
+ + kind);
+ }
+ return new GeneralName(kind, nameBytes);
+ }
+
private int basicConstraints;
private X509Certificate cert;
private BigInteger serialNo;
@@ -100,14 +150,12 @@ public class X509CertSelector implements CertSelector, Cloneable
private OID sigId;
private PublicKey subjectKey;
private X509EncodedKeySpec subjectKeySpec;
- private Set keyPurposeSet;
- private List altNames;
+ private Set keyPurposeSet;
+ private List altNames;
private boolean matchAllNames;
private byte[] nameConstraints;
- private Set policy;
-
- // Constructors.
- // ------------------------------------------------------------------------
+ private Set policy;
+ private List pathToNames;
/**
* Creates a new X.509 certificate selector. The new selector will be
@@ -119,285 +167,280 @@ public class X509CertSelector implements CertSelector, Cloneable
basicConstraints = -1;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
- * Returns the certificate criterion, or null if this value
- * was not set.
+ * Add a name to match in the NameConstraints extension. The argument is
+ * the DER-encoded bytes of a GeneralName structure.
+ *
+ * See the method {@link #addSubjectAlternativeName(int, byte[])} for the
+ * format of the GeneralName structure.
*
- * @return The certificate.
+ * @param id The name identifier. Must be between 0 and 8.
+ * @param name The DER-encoded bytes of the name to match.
+ * @throws IOException If the name DER is malformed.
*/
- public X509Certificate getCertificate()
+ public void addPathToName(int id, byte[] name) throws IOException
{
- return cert;
+ GeneralName generalName = new GeneralName(GeneralName.Kind.forTag(id), name);
+ if (pathToNames == null)
+ pathToNames = new LinkedList();
+ pathToNames.add(generalName);
}
/**
- * Sets the certificate criterion. If set, only certificates that are
- * equal to the certificate passed here will be accepted.
+ * Add a name to match in the NameConstraints extension. This method will
+ * only recognize certain types of name that have convenient string
+ * encodings. For robustness, you should use the {@link
+ * #addPathToName(int, byte[])} method whenever possible.
*
- * @param cert The certificate.
+ * @param id The name identifier. Must be between 0 and 8.
+ * @param name The name.
+ * @throws IOException If the name cannot be decoded.
*/
- public void setCertificate(X509Certificate cert)
+ public void addPathToName(int id, String name) throws IOException
{
- this.cert = cert;
+ GeneralName generalName = makeName(id, name);
+ if (pathToNames == null)
+ pathToNames = new LinkedList();
+ pathToNames.add(generalName);
}
/**
- * Returns the serial number criterion, or null if this
- * value was not set.
+ * Add a name, as DER-encoded bytes, to the subject alternative names
+ * criterion.
+ *
+ * The name is a GeneralName structure, which has the ASN.1 format:
+ *
+ *
*
- * @return The serial number.
+ * @param id The type of name this is.
+ * @param name The DER-encoded name.
+ * @throws IOException If the name is not a valid DER sequence.
*/
- public BigInteger getSerialNumber()
+ public void addSubjectAlternativeName(int id, byte[] name)
+ throws IOException
{
- return serialNo;
+ GeneralName generalName = new GeneralName(GeneralName.Kind.forTag(id), name);
+ if (altNames == null)
+ altNames = new LinkedList();
+ altNames.add(generalName);
}
/**
- * Sets the serial number of the desired certificate. Only certificates that
- * contain this serial number are accepted.
+ * Add a name to the subject alternative names criterion. This method will
+ * only recognize certain types of name that have convenient string
+ * encodings. For robustness, you should use the {@link
+ * #addSubjectAlternativeName(int, byte[])} method whenever possible.
+ *
+ * This method can only decode certain name kinds of names as strings.
*
- * @param serialNo The serial number.
+ * @param id The type of name this is. Must be in the range [0,8].
+ * @param name The name.
+ * @throws IOException If the id is out of range, or if the name
+ * is null.
*/
- public void setSerialNumber(BigInteger serialNo)
+ public void addSubjectAlternativeName(int id, String name)
+ throws IOException
{
- this.serialNo = serialNo;
+ GeneralName generalName = makeName(id, name);
+ if (altNames == null)
+ altNames = new LinkedList();
+ altNames.add(generalName);
}
- /**
- * Returns the issuer criterion as a string, or null if this
- * value was not set.
- *
- * @return The issuer.
- */
- public String getIssuerAsString()
+ public Object clone()
{
- if (issuer != null)
- return issuer.getName();
- else
- return null;
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException shouldNotHappen)
+ {
+ throw new Error(shouldNotHappen);
+ }
}
/**
- * Returns the issuer criterion as a sequence of DER bytes, or
- * null if this value was not set.
+ * Returns the authority key identifier criterion, or null if
+ * this value was not set. Note that the byte array is cloned to prevent
+ * modification.
*
- * @return The issuer.
+ * @return The authority key identifier.
*/
- public byte[] getIssuerAsBytes() throws IOException
+ public byte[] getAuthorityKeyIdentifier()
{
- if (issuer != null)
- return issuer.getEncoded();
+ if (authKeyId != null)
+ return (byte[]) authKeyId.clone();
else
return null;
}
/**
- * Sets the issuer, specified as a string representation of the issuer's
- * distinguished name. Only certificates issued by this issuer will
- * be accepted.
+ * Returns the basic constraints criterion, or -1 if this value is not set.
*
- * @param name The string representation of the issuer's distinguished name.
- * @throws IOException If the given name is incorrectly formatted.
+ * @return The basic constraints.
*/
- public void setIssuer(String name) throws IOException
+ public int getBasicConstraints()
{
- if (name != null)
- {
- try
- {
- issuer = new X500Principal(name);
- }
- catch (IllegalArgumentException iae)
- {
- throw new IOException(iae.getMessage());
- }
- }
- else
- issuer = null;
+ return basicConstraints;
}
/**
- * Sets the issuer, specified as the DER encoding of the issuer's
- * distinguished name. Only certificates issued by this issuer will
- * be accepted.
+ * Returns the certificate criterion, or null if this value
+ * was not set.
*
- * @param name The DER encoding of the issuer's distinguished name.
- * @throws IOException If the given name is incorrectly formatted.
+ * @return The certificate.
*/
- public void setIssuer(byte[] name) throws IOException
+ public X509Certificate getCertificate()
{
- if (name != null)
- {
- try
- {
- issuer = new X500Principal(name);
- }
- catch (IllegalArgumentException iae)
- {
- throw new IOException(iae.getMessage());
- }
- }
- else
- issuer = null;
+ return cert;
}
/**
- * Returns the subject criterion as a string, of null if
- * this value was not set.
+ * Returns the date at which certificates must be valid, or null
+ * if this criterion was not set.
*
- * @return The subject.
+ * @return The target certificate valitity date.
*/
- public String getSubjectAsString()
+ public Date getCertificateValid()
{
- if (subject != null)
- return subject.getName();
+ if (certValid != null)
+ return (Date) certValid.clone();
else
return null;
}
/**
- * Returns the subject criterion as a sequence of DER bytes, or
- * null if this value is not set.
+ * Returns the set of extended key purpose IDs, as an unmodifiable set
+ * of OID strings. Returns null if this criterion is not
+ * set.
*
- * @return The subject.
+ * @return The set of key purpose OIDs (strings).
*/
- public byte[] getSubjectAsBytes() throws IOException
+ public Set getExtendedKeyUsage()
{
- if (subject != null)
- return subject.getEncoded();
+ if (keyPurposeSet != null)
+ return Collections.unmodifiableSet(keyPurposeSet);
else
return null;
}
/**
- * Sets the subject, specified as a string representation of the
- * subject's distinguished name. Only certificates with the given
- * subject will be accepted.
+ * Returns the issuer criterion as a sequence of DER bytes, or
+ * null if this value was not set.
*
- * @param name The string representation of the subject's distinguished name.
- * @throws IOException If the given name is incorrectly formatted.
+ * @return The issuer.
*/
- public void setSubject(String name) throws IOException
+ public byte[] getIssuerAsBytes() throws IOException
{
- if (name != null)
- {
- try
- {
- subject = new X500Principal(name);
- }
- catch (IllegalArgumentException iae)
- {
- throw new IOException(iae.getMessage());
- }
- }
+ if (issuer != null)
+ return issuer.getEncoded();
else
- subject = null;
+ return null;
}
/**
- * Sets the subject, specified as the DER encoding of the subject's
- * distinguished name. Only certificates with the given subject will
- * be accepted.
+ * Returns the issuer criterion as a string, or null if this
+ * value was not set.
*
- * @param name The DER encoding of the subject's distinguished name.
- * @throws IOException If the given name is incorrectly formatted.
+ * @return The issuer.
*/
- public void setSubject(byte[] name) throws IOException
+ public String getIssuerAsString()
{
- if (name != null)
- {
- try
- {
- subject = new X500Principal(name);
- }
- catch (IllegalArgumentException iae)
- {
- throw new IOException(iae.getMessage());
- }
- }
+ if (issuer != null)
+ return issuer.getName();
else
- subject = null;
+ return null;
}
/**
- * Returns the subject key identifier criterion, or null if
- * this value was not set. Note that the byte array is cloned to prevent
- * modification.
+ * Returns the public key usage criterion, or null if this
+ * value is not set. Note that the array is cloned to prevent modification.
*
- * @return The subject key identifier.
+ * @return The public key usage.
*/
- public byte[] getSubjectKeyIdentifier()
+ public boolean[] getKeyUsage()
{
- if (subjectKeyId != null)
- return (byte[]) subjectKeyId.clone();
+ if (keyUsage != null)
+ return (boolean[]) keyUsage.clone();
else
return null;
}
/**
- * Sets the subject key identifier criterion, or null to clear
- * this criterion. Note that the byte array is cloned to prevent modification.
+ * Returns whether or not all specified alternative names must match.
+ * If false, a certificate is considered a match if one of the
+ * specified alternative names matches.
*
- * @param subjectKeyId The subject key identifier.
+ * @return true if all names must match.
*/
- public void setSubjectKeyIdentifier(byte[] subjectKeyId)
+ public boolean getMatchAllSubjectAltNames()
{
- this.subjectKeyId = subjectKeyId != null ? (byte[]) subjectKeyId.clone() :
- null;
+ return matchAllNames;
}
/**
- * Returns the authority key identifier criterion, or null if
- * this value was not set. Note that the byte array is cloned to prevent
+ * Returns the name constraints criterion, or null if this
+ * value is not set. Note that the byte array is cloned to prevent
* modification.
*
- * @return The authority key identifier.
+ * @return The name constraints.
*/
- public byte[] getAuthorityKeyIdentifier()
+ public byte[] getNameConstraints()
{
- if (authKeyId != null)
- return (byte[]) authKeyId.clone();
+ if (nameConstraints != null)
+ return (byte[]) nameConstraints.clone();
else
return null;
}
- /**
- * Sets the authority key identifier criterion, or null to clear
- * this criterion. Note that the byte array is cloned to prevent modification.
- *
- * @param authKeyId The authority key identifier.
- */
- public void setAuthorityKeyIdentifier(byte[] authKeyId)
+ public Collection> getPathToNames()
{
- this.authKeyId = authKeyId != null ? (byte[]) authKeyId.clone() : null;
+ if (pathToNames != null)
+ {
+ List> names = new ArrayList>(pathToNames.size());
+ for (GeneralName name : pathToNames)
+ {
+ List n = new ArrayList(2);
+ n.add(name.kind().tag());
+ n.add(name.name());
+ names.add(n);
+ }
+
+ return names;
+ }
+ return null;
}
/**
- * Returns the date at which certificates must be valid, or null
- * if this criterion was not set.
+ * Returns the certificate policy extension that will be matched by this
+ * selector, or null if the certificate policy will not be matched.
*
- * @return The target certificate valitity date.
+ * @return The policy to be matched, or null.
*/
- public Date getCertificateValid()
+ public Set getPolicy()
{
- if (certValid != null)
- return (Date) certValid.clone();
- else
- return null;
- }
-
- /**
- * Sets the date at which certificates must be valid. Specify
- * null to clear this criterion.
- *
- * @param certValid The certificate validity date.
- */
- public void setCertificateValid(Date certValid)
- {
- this.certValid = certValid != null ? (Date) certValid.clone() : null;
+ Set p = this.policy;
+ if (p != null)
+ {
+ Set strings = new HashSet(p.size());
+ for (OID o : p)
+ {
+ strings.add(o.toString());
+ }
+ return strings;
+ }
+ return null;
}
/**
@@ -418,59 +461,83 @@ public class X509CertSelector implements CertSelector, Cloneable
}
/**
- * This method, and its related X.509 certificate extension — the
- * private key usage period — is not supported under the Internet
- * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this
- * method is not supported either.
+ * Returns the serial number criterion, or null if this
+ * value was not set.
*
- *
Do not use this method. It is not deprecated, as it is not deprecated
- * in the Java standard, but it is basically a no-operation.
+ * @return The serial number.
+ */
+ public BigInteger getSerialNumber()
+ {
+ return serialNo;
+ }
+
+ /**
+ * Get the subject alternative names criterion. The collection returned
+ * is a collection of pairs: the first element is an {@link Integer}
+ * containing the name type, and the second is a byte array containing
+ * the DER-encoded name bytes.
*
- * @param UNUSED Is silently ignored.
+ * @return The subject alternative names criterion. Returns null if this
+ * criterion is not set.
*/
- public void setPrivateKeyValid(Date UNUSED)
+ public Collection> getSubjectAlternativeNames()
{
+ if (altNames != null)
+ {
+ List> names = new ArrayList>(altNames.size());
+ for (GeneralName name : altNames)
+ {
+ List n = new ArrayList(2);
+ n.add(name.kind().tag());
+ n.add(name.name());
+ names.add(n);
+ }
+ return names;
+ }
+ return null;
}
/**
- * Returns the public key algorithm ID that matching certificates must have,
- * or null if this criterion was not set.
+ * Returns the subject criterion as a sequence of DER bytes, or
+ * null if this value is not set.
*
- * @return The public key algorithm ID.
+ * @return The subject.
*/
- public String getSubjectPublicKeyAlgID()
+ public byte[] getSubjectAsBytes() throws IOException
{
- return String.valueOf(sigId);
+ if (subject != null)
+ return subject.getEncoded();
+ else
+ return null;
}
/**
- * Sets the public key algorithm ID that matching certificates must have.
- * Specify null to clear this criterion.
+ * Returns the subject criterion as a string, of null if
+ * this value was not set.
*
- * @param sigId The public key ID.
- * @throws IOException If the specified ID is not a valid object identifier.
+ * @return The subject.
*/
- public void setSubjectPublicKeyAlgID(String sigId) throws IOException
+ public String getSubjectAsString()
{
- if (sigId != null)
- {
- try
- {
- OID oid = new OID(sigId);
- int[] comp = oid.getIDs();
- if (!checkOid(comp))
- throw new IOException("malformed OID: " + sigId);
- this.sigId = oid;
- }
- catch (IllegalArgumentException iae)
- {
- IOException ioe = new IOException("malformed OID: " + sigId);
- ioe.initCause(iae);
- throw ioe;
- }
- }
+ if (subject != null)
+ return subject.getName();
else
- this.sigId = null;
+ return null;
+ }
+
+ /**
+ * Returns the subject key identifier criterion, or null if
+ * this value was not set. Note that the byte array is cloned to prevent
+ * modification.
+ *
+ * @return The subject key identifier.
+ */
+ public byte[] getSubjectKeyIdentifier()
+ {
+ if (subjectKeyId != null)
+ return (byte[]) subjectKeyId.clone();
+ else
+ return null;
}
/**
@@ -485,101 +552,282 @@ public class X509CertSelector implements CertSelector, Cloneable
}
/**
- * Sets the subject public key criterion as an opaque representation.
- * Specify null to clear this criterion.
+ * Returns the public key algorithm ID that matching certificates must have,
+ * or null if this criterion was not set.
*
- * @param key The public key.
+ * @return The public key algorithm ID.
*/
- public void setSubjectPublicKey(PublicKey key)
+ public String getSubjectPublicKeyAlgID()
{
- this.subjectKey = key;
- if (key == null)
- {
- subjectKeySpec = null;
- return;
- }
- try
- {
- KeyFactory enc = KeyFactory.getInstance("X.509");
- subjectKeySpec = (X509EncodedKeySpec)
- enc.getKeySpec(key, X509EncodedKeySpec.class);
- }
- catch (Exception x)
- {
- subjectKey = null;
- subjectKeySpec = null;
- }
+ return String.valueOf(sigId);
}
/**
- * Sets the subject public key criterion as a DER-encoded key. Specify
- * null to clear this value.
+ * Match a certificate. This method will check the given certificate
+ * against all the enabled criteria of this selector, and will return
+ * true if the given certificate matches.
*
- * @param key The DER-encoded key bytes.
- * @throws IOException If the argument is not a valid DER-encoded key.
+ * @param certificate The certificate to check.
+ * @return true if the certificate matches all criteria.
*/
- public void setSubjectPublicKey(byte[] key) throws IOException
+ public boolean match(Certificate certificate)
{
- if (key == null)
+ if (!(certificate instanceof X509Certificate))
+ return false;
+ X509Certificate cert = (X509Certificate) certificate;
+ if (this.cert != null)
{
- subjectKey = null;
- subjectKeySpec = null;
- return;
+ try
+ {
+ byte[] e1 = this.cert.getEncoded();
+ byte[] e2 = cert.getEncoded();
+ if (!Arrays.equals(e1, e2))
+ return false;
+ }
+ catch (CertificateEncodingException cee)
+ {
+ return false;
+ }
}
- try
+ if (serialNo != null)
{
- subjectKeySpec = new X509EncodedKeySpec(key);
- KeyFactory enc = KeyFactory.getInstance("X.509");
- subjectKey = enc.generatePublic(subjectKeySpec);
+ if (!serialNo.equals(cert.getSerialNumber()))
+ return false;
}
- catch (Exception x)
+ if (certValid != null)
{
- subjectKey = null;
- subjectKeySpec = null;
- IOException ioe = new IOException(x.getMessage());
- ioe.initCause(x);
- throw ioe;
+ try
+ {
+ cert.checkValidity(certValid);
+ }
+ catch (CertificateException ce)
+ {
+ return false;
+ }
+ }
+ if (issuer != null)
+ {
+ if (!issuer.equals(cert.getIssuerX500Principal()))
+ return false;
+ }
+ if (subject != null)
+ {
+ if (!subject.equals(cert.getSubjectX500Principal()))
+ return false;
+ }
+ if (sigId != null)
+ {
+ if (!sigId.toString().equals(cert.getSigAlgOID()))
+ return false;
+ }
+ if (subjectKeyId != null)
+ {
+ byte[] b = cert.getExtensionValue(SUBJECT_KEY_ID);
+ if (!Arrays.equals(b, subjectKeyId))
+ return false;
}
+ if (authKeyId != null)
+ {
+ byte[] b = cert.getExtensionValue(AUTH_KEY_ID);
+ if (!Arrays.equals(b, authKeyId))
+ return false;
+ }
+ if (keyUsage != null)
+ {
+ boolean[] b = cert.getKeyUsage();
+ if (!Arrays.equals(b, keyUsage))
+ return false;
+ }
+ if (basicConstraints >= 0)
+ {
+ if (cert.getBasicConstraints() != basicConstraints)
+ return false;
+ }
+ if (keyPurposeSet != null)
+ {
+ List kp = null;
+ try
+ {
+ kp = cert.getExtendedKeyUsage();
+ }
+ catch (CertificateParsingException cpe)
+ {
+ return false;
+ }
+ if (kp == null)
+ return false;
+ for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); )
+ {
+ if (!kp.contains(it.next()))
+ return false;
+ }
+ }
+ if (altNames != null)
+ {
+ Collection> an = null;
+ try
+ {
+ an = cert.getSubjectAlternativeNames();
+ }
+ catch (CertificateParsingException cpe)
+ {
+ return false;
+ }
+ if (an == null)
+ return false;
+ int match = 0;
+ for (GeneralName name : altNames)
+ {
+ for (List> list : an)
+ {
+ try
+ {
+ Integer id = (Integer) list.get(0);
+ Object val = list.get(1);
+ GeneralName n = null;
+ if (val instanceof String)
+ n = makeName(id, (String) val);
+ else if (val instanceof byte[])
+ {
+ n = new GeneralName(GeneralName.Kind.forTag(id),
+ (byte[]) val);
+ }
+ else
+ continue;
+ if (name.equals(n))
+ match++;
+ }
+ catch (Exception e)
+ {
+ continue;
+ }
+ }
+ if (match == 0 || (matchAllNames && match < altNames.size()))
+ return false;
+ }
+ }
+ if (nameConstraints != null)
+ {
+ byte[] nc = cert.getExtensionValue(NAME_CONSTRAINTS_ID);
+ if (!Arrays.equals(nameConstraints, nc))
+ return false;
+ }
+
+ if (policy != null)
+ {
+ CertificatePolicies policies = null;
+ if (cert instanceof GnuPKIExtension)
+ {
+ policies = (CertificatePolicies)
+ ((GnuPKIExtension) cert).getExtension(CertificatePolicies.ID).getValue();
+ }
+ else
+ {
+ byte[] policiesDer =
+ cert.getExtensionValue(CertificatePolicies.ID.toString());
+ try
+ {
+ policies = new CertificatePolicies(policiesDer);
+ }
+ catch (IOException ioe)
+ {
+ // ignored
+ }
+ }
+
+ if (policies == null)
+ return false;
+ if (!policies.getPolicies().containsAll(policy))
+ return false;
+ }
+
+ if (pathToNames != null)
+ {
+ NameConstraints nc = null;
+ if (cert instanceof GnuPKIExtension)
+ {
+ Extension e =
+ ((GnuPKIExtension) cert).getExtension(NameConstraints.ID);
+ if (e != null)
+ nc = (NameConstraints) e.getValue();
+ }
+ else
+ {
+ byte[] b = cert.getExtensionValue(NameConstraints.ID.toString());
+ if (b != null)
+ {
+ try
+ {
+ nc = new NameConstraints(b);
+ }
+ catch (IOException ioe)
+ {
+ }
+ }
+ }
+
+ if (nc == null)
+ return false;
+
+ int match = 0;
+ for (GeneralName name : pathToNames)
+ {
+ for (GeneralSubtree subtree : nc.permittedSubtrees())
+ {
+ if (name.equals(subtree.base()))
+ match++;
+ }
+ }
+ if (match == 0 || (matchAllNames && match < pathToNames.size()))
+ return false;
+ }
+
+ return true;
}
/**
- * Returns the public key usage criterion, or null if this
- * value is not set. Note that the array is cloned to prevent modification.
+ * Sets the authority key identifier criterion, or null to clear
+ * this criterion. Note that the byte array is cloned to prevent modification.
*
- * @return The public key usage.
+ * @param authKeyId The authority key identifier.
*/
- public boolean[] getKeyUsage()
+ public void setAuthorityKeyIdentifier(byte[] authKeyId)
{
- if (keyUsage != null)
- return (boolean[]) keyUsage.clone();
- else
- return null;
+ this.authKeyId = authKeyId != null ? (byte[]) authKeyId.clone() : null;
}
/**
- * Sets the public key usage criterion. Specify null to clear
- * this value.
+ * Sets the basic constraints criterion. Specify -1 to clear this parameter.
*
- * @param keyUsage The public key usage.
+ * @param basicConstraints The new basic constraints value.
*/
- public void setKeyUsage(boolean[] keyUsage)
+ public void setBasicConstraints(int basicConstraints)
{
- this.keyUsage = keyUsage != null ? (boolean[]) keyUsage.clone() : null;
+ if (basicConstraints < -1)
+ basicConstraints = -1;
+ this.basicConstraints = basicConstraints;
}
/**
- * Returns the set of extended key purpose IDs, as an unmodifiable set
- * of OID strings. Returns null if this criterion is not
- * set.
+ * Sets the certificate criterion. If set, only certificates that are
+ * equal to the certificate passed here will be accepted.
*
- * @return The set of key purpose OIDs (strings).
+ * @param cert The certificate.
*/
- public Set getExtendedKeyUsage()
+ public void setCertificate(X509Certificate cert)
{
- if (keyPurposeSet != null)
- return Collections.unmodifiableSet(keyPurposeSet);
- else
- return null;
+ this.cert = cert;
+ }
+
+ /**
+ * Sets the date at which certificates must be valid. Specify
+ * null to clear this criterion.
+ *
+ * @param certValid The certificate validity date.
+ */
+ public void setCertificateValid(Date certValid)
+ {
+ this.certValid = certValid != null ? (Date) certValid.clone() : null;
}
/**
@@ -596,7 +844,7 @@ public class X509CertSelector implements CertSelector, Cloneable
this.keyPurposeSet = null;
return;
}
- Set s = new HashSet();
+ Set s = new HashSet();
for (Iterator it = keyPurposeSet.iterator(); it.hasNext(); )
{
Object o = it.next();
@@ -620,407 +868,387 @@ public class X509CertSelector implements CertSelector, Cloneable
}
/**
- * Returns whether or not all specified alternative names must match.
- * If false, a certificate is considered a match if one of the
- * specified alternative names matches.
+ * Sets the issuer, specified as the DER encoding of the issuer's
+ * distinguished name. Only certificates issued by this issuer will
+ * be accepted.
*
- * @return true if all names must match.
+ * @param name The DER encoding of the issuer's distinguished name.
+ * @throws IOException If the given name is incorrectly formatted.
*/
- public boolean getMatchAllSubjectAltNames()
+ public void setIssuer(byte[] name) throws IOException
{
- return matchAllNames;
+ if (name != null)
+ {
+ try
+ {
+ issuer = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new IOException(iae.getMessage());
+ }
+ }
+ else
+ issuer = null;
}
/**
- * Sets whether or not all subject alternative names must be matched.
- * If false, then a certificate will be considered a match if one
- * alternative name matches.
+ * Sets the issuer, specified as a string representation of the issuer's
+ * distinguished name. Only certificates issued by this issuer will
+ * be accepted.
*
- * @param matchAllNames Whether or not all alternative names must be
- * matched.
+ * @param name The string representation of the issuer's distinguished name.
+ * @throws IOException If the given name is incorrectly formatted.
*/
- public void setMatchAllSubjectAltNames(boolean matchAllNames)
+ public void setIssuer(String name) throws IOException
{
- this.matchAllNames = matchAllNames;
+ if (name != null)
+ {
+ try
+ {
+ issuer = new X500Principal(name);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new IOException(iae.getMessage());
+ }
+ }
+ else
+ issuer = null;
}
/**
- * Sets the subject alternative names critertion. Each element of the
- * argument must be a {@link java.util.List} that contains exactly two
- * elements: the first an {@link Integer}, representing the type of
- * name, and the second either a {@link String} or a byte array,
- * representing the name itself.
+ * Sets the public key usage criterion. Specify null to clear
+ * this value.
*
- * @param altNames The alternative names.
- * @throws IOException If any element of the argument is invalid.
+ * @param keyUsage The public key usage.
*/
- public void setSubjectAlternativeNames(Collection> altNames)
- throws IOException
+ public void setKeyUsage(boolean[] keyUsage)
{
- if (altNames == null)
- {
- this.altNames = null;
- return;
- }
- List l = new ArrayList(altNames.size());
- for (Iterator it = altNames.iterator(); it.hasNext(); )
- {
- Object o = it.next();
- if (!(o instanceof List) || ((List) o).size() != 2 ||
- !(((List) o).get(0) instanceof Integer) ||
- !(((List) o).get(1) instanceof String) ||
- !(((List) o).get(1) instanceof byte[]))
- throw new IOException("illegal alternative name: " + o);
- Integer i = (Integer) ((List) o).get(0);
- if (i.intValue() < 0 || i.intValue() > 8)
- throw new IOException("illegal alternative name: " + o +
- ", bad id: " + i);
- l.add(new ArrayList((List) o));
- }
- this.altNames = l;
+ this.keyUsage = keyUsage != null ? (boolean[]) keyUsage.clone() : null;
}
/**
- * Add a name to the subject alternative names criterion.
+ * Sets whether or not all subject alternative names must be matched.
+ * If false, then a certificate will be considered a match if one
+ * alternative name matches.
*
- * @param id The type of name this is. Must be in the range [0,8].
- * @param name The name.
- * @throws IOException If the id is out of range, or if the name
- * is null.
+ * @param matchAllNames Whether or not all alternative names must be
+ * matched.
*/
- public void addSubjectAlternativeName(int id, String name)
- throws IOException
+ public void setMatchAllSubjectAltNames(boolean matchAllNames)
{
- if (id < 0 || id > 8 || name == null)
- throw new IOException("illegal alternative name");
- if (altNames == null)
- altNames = new LinkedList();
- ArrayList l = new ArrayList(2);
- l.add(Integer.valueOf(id));
- l.add(name);
- altNames.add(l);
+ this.matchAllNames = matchAllNames;
}
/**
- * Add a name, as DER-encoded bytes, to the subject alternative names
- * criterion.
+ * Sets the name constraints criterion; specify null to
+ * clear this criterion. Note that if non-null, the argument will be
+ * cloned to prevent modification.
*
- * @param id The type of name this is.
+ * @param nameConstraints The new name constraints.
+ * @throws IOException If the argument is not a valid DER-encoded
+ * name constraints.
*/
- public void addSubjectAlternativeName(int id, byte[] name)
+ public void setNameConstraints(byte[] nameConstraints)
throws IOException
{
- if (id < 0 || id > 8 || name == null)
- throw new IOException("illegal alternative name");
- if (altNames == null)
- altNames = new LinkedList();
- ArrayList l = new ArrayList(2);
- l.add(Integer.valueOf(id));
- l.add(name);
- altNames.add(l);
+ // Check if the input is well-formed...
+ new NameConstraints(nameConstraints);
+
+ // But we just compare raw byte arrays.
+ this.nameConstraints = nameConstraints != null
+ ? (byte[]) nameConstraints.clone() : null;
}
-
+
/**
- * Returns the name constraints criterion, or null if this
- * value is not set. Note that the byte array is cloned to prevent
- * modification.
+ * Sets the pathToNames criterion. The argument is a collection of
+ * pairs, the first element of which is an {@link Integer} giving
+ * the ID of the name, and the second element is either a {@link String}
+ * or a byte array.
+ *
+ * See {@link #addPathToName(int, byte[])} and {@link #addPathToName(int, String)}
+ * for how these arguments are handled.
*
- * @return The name constraints.
+ * @param names The names.
+ * @throws IOException If any argument is malformed.
*/
- public byte[] getNameConstraints()
+ public void setPathToNames(Collection> names) throws IOException
{
- if (nameConstraints != null)
- return (byte[]) nameConstraints.clone();
+ if (names == null || names.size() == 0)
+ {
+ pathToNames = null;
+ }
else
- return null;
+ {
+ pathToNames = new ArrayList(names.size());
+ for (List> name : names)
+ {
+ Integer id = (Integer) name.get(0);
+ Object name2 = name.get(1);
+ if (name2 instanceof String)
+ addPathToName(id, (String) name2);
+ else if (name2 instanceof byte[])
+ addPathToName(id, (byte[]) name2);
+ else
+ throw new IOException("invalid name type: "
+ + name2.getClass().getName());
+ }
+ }
}
/**
- * Sets the name constraints criterion; specify null to
- * clear this criterion. Note that if non-null, the argument will be
- * cloned to prevent modification.
+ * Sets the certificate policy to match, or null if this criterion should
+ * not be checked. Each element if the set must be a dotted-decimal form
+ * of certificate policy object identifier.
*
- * @param nameConstraints The new name constraints.
- * @throws IOException If the argument is not a valid DER-encoded
- * name constraints.
+ * @param policy The policy to match.
+ * @throws IOException If some element of the policy is not a valid
+ * policy extenison OID.
*/
- public void setNameConstraints(byte[] nameConstraints)
- throws IOException
+ public void setPolicy(Set policy) throws IOException
{
- // FIXME check if the argument is valid.
- this.nameConstraints = nameConstraints != null
- ? (byte[]) nameConstraints.clone() : null;
+ if (policy != null)
+ {
+ HashSet p = new HashSet(policy.size());
+ for (String s : policy)
+ {
+ try
+ {
+ OID oid = new OID(s);
+ int[] i = oid.getIDs();
+ if (!checkOid(i))
+ throw new IOException("invalid OID");
+ p.add(oid);
+ }
+ catch (IOException ioe)
+ {
+ throw ioe;
+ }
+ catch (Exception x)
+ {
+ IOException ioe = new IOException("invalid OID");
+ ioe.initCause(x);
+ throw ioe;
+ }
+ }
+ this.policy = p;
+ }
+ else
+ this.policy = null;
}
/**
- * Returns the basic constraints criterion, or -1 if this value is not set.
+ * This method, and its related X.509 certificate extension — the
+ * private key usage period — is not supported under the Internet
+ * PKI for X.509 certificates (PKIX), described in RFC 3280. As such, this
+ * method is not supported either.
*
- * @return The basic constraints.
+ *