Initial import of OpenJdk files.
Create new libcore/ojluni directory with src/main/java and
src/main/native subdirectiories.
Build ojluni into core-oj jar.
Use openjdk classes from java.awt.font package.
Copy all files from jdk/src/share/classes and jdk/src/solaris/classes
directories in openjdk into libcore/ojluni/src/main/java.
Copy following native files from openjdk to
libcore/ojluni/src/main/native:
jdk/src/solaris/native/java/io/canonicalize_md.c
build/linux-amd64/include/classfile_constants.h
jdk/src/share/native/java/net/DatagramPacket.c
jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c
jdk/src/share/native/java/lang/Double.c
jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h
jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c
jdk/src/solaris/native/java/io/FileDescriptor_md.c
jdk/src/solaris/native/sun/nio/ch/FileDispatcherImpl.c
jdk/src/share/native/java/io/FileInputStream.c
jdk/src/solaris/native/sun/nio/ch/FileKey.c
jdk/src/solaris/native/java/io/FileOutputStream_md.c
jdk/src/solaris/native/java/io/FileSystem_md.c
jdk/src/share/native/java/lang/Float.c
jdk/src/share/native/java/net/Inet4Address.c
jdk/src/solaris/native/java/net/Inet4AddressImpl.c
jdk/src/share/native/java/net/Inet6Address.c
jdk/src/solaris/native/java/net/Inet6AddressImpl.c
jdk/src/share/native/java/net/InetAddress.c
jdk/src/solaris/native/java/net/InetAddressImplFactory.c
jdk/src/share/native/java/io/io_util.c
jdk/src/solaris/native/sun/nio/ch/IOUtil.c
jdk/src/share/native/java/io/io_util.h
jdk/src/solaris/native/java/io/io_util_md.c
jdk/src/solaris/native/java/io/io_util_md.h
build/linux-amd64/tmp/java/java.nio/nio/CClassHeaders/java_io_FileDescriptor.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_io_FileInputStream.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_io_FileOutputStream.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_io_FileSystem.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_io_ObjectStreamClass.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_io_UnixFileSystem.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Double.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Float.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Integer.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Long.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Runtime.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Shutdown.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_StrictMath.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_String.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_System.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Thread.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/java_lang_Throwable.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_DatagramPacket.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_Inet4Address.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_Inet4AddressImpl.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_Inet6Address.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_Inet6AddressImpl.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_InetAddress.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_InetAddressImplFactory.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_NetworkInterface.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_PlainDatagramSocketImpl.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_PlainSocketImpl.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_SocketInputStream.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_SocketOptions.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/java_net_SocketOutputStream.h
jdk/src/share/native/java/lang/java_props.h
jdk/src/solaris/native/java/lang/java_props_md.c
jdk/src/share/native/java/util/zip/Adler32.c as java_util_zip_Adler32.c
jdk/src/share/native/java/util/zip/CRC32.c as java_util_zip_CRC32.c
build/linux-amd64/tmp/sun/java.util.zip/zip/CClassHeaders/java_util_zip_CRC32.h
jdk/src/share/native/java/util/zip/Deflater.c as java_util_zip_Deflater.c
build/linux-amd64/tmp/sun/java.util.zip/zip/CClassHeaders/java_util_zip_Deflater.h
jdk/src/share/native/java/util/zip/Inflater.c as java_util_zip_Inflater.c
build/linux-amd64/tmp/sun/java.util.zip/zip/CClassHeaders/java_util_zip_Inflater.h
jdk/src/share/native/java/util/zip/ZipFile.c as java_util_zip_ZipFile.c
build/linux-amd64/tmp/sun/java.util.zip/zip/CClassHeaders/java_util_zip_ZipFile.h
jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h
jdk/src/share/native/common/jlong.h
jdk/src/solaris/native/common/jlong_md.h
jdk/src/share/native/common/jni_util.c
jdk/src/share/native/common/jni_util.h
jdk/src/solaris/native/common/jni_util_md.c
jdk/src/share/javavm/export/jvm.h
jdk/src/solaris/javavm/export/jvm_md.h
jdk/src/solaris/native/java/net/linux_close.c
jdk/src/share/native/sun/misc/NativeSignalHandler.c
jdk/src/solaris/native/sun/nio/ch/NativeThread.c
jdk/src/share/native/java/net/net_util.c
jdk/src/share/native/java/net/net_util.h
jdk/src/solaris/native/java/net/net_util_md.c
jdk/src/solaris/native/java/net/net_util_md.h
jdk/src/solaris/native/java/net/NetworkInterface.c
jdk/src/share/native/sun/nio/ch/nio.h
jdk/src/solaris/native/sun/nio/ch/nio_util.h
jdk/src/share/native/java/io/ObjectStreamClass.c
jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c
jdk/src/solaris/native/java/net/PlainSocketImpl.c
jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c
jdk/src/share/native/java/lang/Runtime.c
jdk/src/share/native/java/lang/Shutdown.c
jdk/src/share/native/sun/misc/Signal.c
jdk/src/solaris/native/java/net/SocketInputStream.c
jdk/src/solaris/native/java/net/SocketOutputStream.c
jdk/src/share/native/java/lang/StrictMath.c
jdk/src/share/native/java/lang/String.c
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/sun_misc_NativeSignalHandler.h
build/linux-amd64/tmp/java/java.lang/java/CClassHeaders/sun_misc_Signal.h
build/linux-amd64/tmp/sun/java.net/net/CClassHeaders/sun_net_spi_DefaultProxySelector.h
build/linux-amd64/tmp/java/java.nio/nio/CClassHeaders/sun_nio_ch_FileChannelImpl.h
build/linux-amd64/tmp/java/java.nio/nio/CClassHeaders/sun_nio_ch_FileDispatcherImpl.h
build/linux-amd64/tmp/java/java.nio/nio/CClassHeaders/sun_nio_ch_FileKey.h
build/linux-amd64/tmp/java/java.nio/nio/CClassHeaders/sun_nio_ch_IOStatus.h
build/linux-amd64/tmp/java/java.nio/nio/CClassHeaders/sun_nio_ch_IOUtil.h
build/linux-amd64/tmp/java/java.nio/nio/CClassHeaders/sun_nio_ch_NativeThread.h
jdk/src/share/native/java/lang/System.c
jdk/src/share/native/java/lang/Thread.c
jdk/src/share/native/java/lang/Throwable.c
jdk/src/solaris/native/java/io/UnixFileSystem_md.c
jdk/src/solaris/native/java/lang/UNIXProcess_md.c
jdk/src/share/native/java/util/zip/zip_util.c
jdk/src/share/native/java/util/zip/zip_util.h
Change-Id: Ib237df4e1b7b5b4d9f12e74d189e6ec9eed3c31d
diff --git a/JavaLibrary.mk b/JavaLibrary.mk
index 57a8f82..e49fa6e 100644
--- a/JavaLibrary.mk
+++ b/JavaLibrary.mk
@@ -37,8 +37,12 @@
#
# All subdirectories are optional (hence the "2> /dev/null"s below).
-define all-main-java-files-under
-$(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(dir)/src/main/java -name "*.java" 2> /dev/null)))
+define nonopenjdk-main-java-files-under
+$(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && (find $(dir)/src/main/java -name "*.java" 2> /dev/null) | grep -v -f openjdk_java_files)))
+endef
+
+define openjdk-main-java-files-under
+$(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && (find $(dir)/src/main/java -name "*.java" 2> /dev/null) | grep -f openjdk_java_files)))
endef
define all-test-java-files-under
@@ -50,19 +54,20 @@
endef
# The Java files and their associated resources.
-common_core_src_files := $(call all-main-java-files-under,dalvik dex dom json luni xml)
+nojcore_src_files := $(call nonopenjdk-main-java-files-under,dalvik dex dom json luni xml)
+ojcore_src_files := $(call openjdk-main-java-files-under,ojluni)
core_resource_dirs := $(call all-core-resource-dirs,main)
test_resource_dirs := $(call all-core-resource-dirs,test)
test_src_files := $(call all-test-java-files-under,dalvik dom harmony-tests json luni xml)
ifeq ($(EMMA_INSTRUMENT),true)
ifneq ($(EMMA_INSTRUMENT_STATIC),true)
- common_core_src_files += $(call all-java-files-under, ../external/emma/core ../external/emma/pregenerated)
+ nojcore_src_files += $(call all-java-files-under, ../external/emma/core ../external/emma/pregenerated)
core_resource_dirs += ../external/emma/core/res ../external/emma/pregenerated/res
endif
endif
-libart_core_src_files += $(common_core_src_files) $(call all-main-java-files-under,libart)
+libart_core_src_files := $(call nonopenjdk-main-java-files-under,libart)
local_javac_flags=-encoding UTF-8
#local_javac_flags+=-Xlint:all -Xlint:-serial,-deprecation,-unchecked
@@ -72,10 +77,34 @@
# Build for the target (device).
#
-# Definitions to make the core library.
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(ojcore_src_files) $(nojcore_src_files) $(libart_core_src_files)
+LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_DX_FLAGS := --core-library
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := core-all
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+LOCAL_REQUIRED_MODULES := tzdata
+include $(BUILD_JAVA_LIBRARY)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(libart_core_src_files)
+LOCAL_SRC_FILES := $(ojcore_src_files)
+LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_DX_FLAGS := --core-library
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := core-oj
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+LOCAL_JAVA_LIBRARIES := core-all
+LOCAL_REQUIRED_MODULES := tzdata
+include $(BUILD_JAVA_LIBRARY)
+
+# Definitions to make the core library.
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(libart_core_src_files) $(nojcore_src_files)
LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
LOCAL_JAVACFLAGS := $(local_javac_flags)
@@ -83,6 +112,7 @@
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := core-libart
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+LOCAL_JAVA_LIBRARIES := core-oj
LOCAL_REQUIRED_MODULES := tzdata
include $(BUILD_JAVA_LIBRARY)
@@ -92,7 +122,7 @@
LOCAL_SRC_FILES := $(test_src_files)
LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
-LOCAL_JAVA_LIBRARIES := core-libart okhttp core-junit bouncycastle
+LOCAL_JAVA_LIBRARIES := core-oj core-libart okhttp core-junit bouncycastle
LOCAL_STATIC_JAVA_LIBRARIES := core-tests-support sqlite-jdbc mockwebserver nist-pkix-tests
LOCAL_JAVACFLAGS := $(local_javac_flags)
LOCAL_MODULE := core-tests
@@ -106,7 +136,7 @@
LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
-LOCAL_JAVA_LIBRARIES := core-libart core-junit bouncycastle
+LOCAL_JAVA_LIBRARIES := core-oj core-libart core-junit bouncycastle
LOCAL_JAVACFLAGS := $(local_javac_flags)
LOCAL_MODULE := core-tests-support
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
@@ -119,7 +149,7 @@
LOCAL_SRC_FILES := $(call all-test-java-files-under, jsr166-tests)
LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
-LOCAL_JAVA_LIBRARIES := core-libart core-junit
+LOCAL_JAVA_LIBRARIES := core-oj core-libart core-junit
LOCAL_JAVACFLAGS := $(local_javac_flags)
LOCAL_MODULE := jsr166-tests
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
@@ -146,14 +176,39 @@
#
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(call all-main-java-files-under, dex)
+LOCAL_SRC_FILES := $(call nonopenjdk-main-java-files-under, dex)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := dex-host
include $(BUILD_HOST_JAVA_LIBRARY)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(ojcore_src_files) $(nojcore_src_files) $(libart_core_src_files)
+LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_DX_FLAGS := --core-library
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := core-all-hostdex
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+LOCAL_REQUIRED_MODULES := tzdata-host
+include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(ojcore_src_files)
+LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
+LOCAL_NO_STANDARD_LIBRARIES := true
+LOCAL_JAVACFLAGS := $(local_javac_flags)
+LOCAL_DX_FLAGS := --core-library
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := core-oj-hostdex
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+LOCAL_JAVA_LIBRARIES := core-all-hostdex
+LOCAL_REQUIRED_MODULES := tzdata-host
+include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
+
# Definitions to make the core library.
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(libart_core_src_files)
+LOCAL_SRC_FILES := $(nojcore_src_files) $(libart_core_src_files)
LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
LOCAL_JAVACFLAGS := $(local_javac_flags)
@@ -161,6 +216,7 @@
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := core-libart-hostdex
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/JavaLibrary.mk
+LOCAL_JAVA_LIBRARIES := core-oj-hostdex
LOCAL_REQUIRED_MODULES := tzdata-host
include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
@@ -170,7 +226,7 @@
LOCAL_SRC_FILES := $(test_src_files)
LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
- LOCAL_JAVA_LIBRARIES := core-libart-hostdex okhttp-hostdex bouncycastle-hostdex core-junit-hostdex core-tests-support-hostdex
+ LOCAL_JAVA_LIBRARIES := core-oj-hostdex core-libart-hostdex okhttp-hostdex bouncycastle-hostdex core-junit-hostdex core-tests-support-hostdex
LOCAL_STATIC_JAVA_LIBRARIES := sqlite-jdbc-host mockwebserver-host nist-pkix-tests-host
LOCAL_JAVACFLAGS := $(local_javac_flags)
LOCAL_MODULE_TAGS := optional
@@ -185,7 +241,7 @@
LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
LOCAL_NO_STANDARD_LIBRARIES := true
- LOCAL_JAVA_LIBRARIES := core-libart-hostdex core-junit-hostdex bouncycastle-hostdex
+ LOCAL_JAVA_LIBRARIES := core-oj-hostdex core-libart-hostdex core-junit-hostdex bouncycastle-hostdex
LOCAL_JAVACFLAGS := $(local_javac_flags)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := core-tests-support-hostdex
diff --git a/benchmarks/Android.mk b/benchmarks/Android.mk
index c0a38a0..93df5fb 100644
--- a/benchmarks/Android.mk
+++ b/benchmarks/Android.mk
@@ -23,7 +23,7 @@
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_JAVA_LIBRARIES := caliper-prebuilt core-tests
LOCAL_NO_STANDARD_LIBRARIES := true
-LOCAL_JAVA_LIBRARIES := core-libart conscrypt core-junit bouncycastle framework
+LOCAL_JAVA_LIBRARIES := core-oj core-libart conscrypt core-junit bouncycastle framework
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/data/caliperperf
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
diff --git a/ojluni/src/main/java/com/oracle/net/Sdp.java b/ojluni/src/main/java/com/oracle/net/Sdp.java
new file mode 100755
index 0000000..3231607
--- /dev/null
+++ b/ojluni/src/main/java/com/oracle/net/Sdp.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.net;
+
+import java.net.Socket;
+import java.net.ServerSocket;
+import java.net.SocketImpl;
+import java.net.SocketImplFactory;
+import java.net.SocketException;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.ServerSocketChannel;
+import java.io.IOException;
+import java.io.FileDescriptor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.InvocationTargetException;
+
+import sun.net.sdp.SdpSupport;
+
+/**
+ * This class consists exclusively of static methods that Sockets or Channels to
+ * sockets that support the InfiniBand Sockets Direct Protocol (SDP).
+ */
+
+public final class Sdp {
+ private Sdp() { }
+
+ /**
+ * The package-privage ServerSocket(SocketImpl) constructor
+ */
+ private static final Constructor<ServerSocket> serverSocketCtor;
+ static {
+ try {
+ serverSocketCtor = (Constructor<ServerSocket>)
+ ServerSocket.class.getDeclaredConstructor(SocketImpl.class);
+ setAccessible(serverSocketCtor);
+ } catch (NoSuchMethodException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ /**
+ * The package-private SdpSocketImpl() constructor
+ */
+ private static final Constructor<SocketImpl> socketImplCtor;
+ static {
+ try {
+ Class<?> cl = Class.forName("java.net.SdpSocketImpl", true, null);
+ socketImplCtor = (Constructor<SocketImpl>)cl.getDeclaredConstructor();
+ setAccessible(socketImplCtor);
+ } catch (ClassNotFoundException e) {
+ throw new AssertionError(e);
+ } catch (NoSuchMethodException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ private static void setAccessible(final AccessibleObject o) {
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ public Void run() {
+ o.setAccessible(true);
+ return null;
+ }
+ });
+ }
+
+ /**
+ * SDP enabled Socket.
+ */
+ private static class SdpSocket extends Socket {
+ SdpSocket(SocketImpl impl) throws SocketException {
+ super(impl);
+ }
+ }
+
+ /**
+ * Creates a SDP enabled SocketImpl
+ */
+ private static SocketImpl createSocketImpl() {
+ try {
+ return socketImplCtor.newInstance();
+ } catch (InstantiationException x) {
+ throw new AssertionError(x);
+ } catch (IllegalAccessException x) {
+ throw new AssertionError(x);
+ } catch (InvocationTargetException x) {
+ throw new AssertionError(x);
+ }
+ }
+
+ /**
+ * Creates an unconnected and unbound SDP socket. The {@code Socket} is
+ * associated with a {@link java.net.SocketImpl} of the system-default type.
+ *
+ * @return a new Socket
+ *
+ * @throws UnsupportedOperationException
+ * If SDP is not supported
+ * @throws IOException
+ * If an I/O error occurs
+ */
+ public static Socket openSocket() throws IOException {
+ SocketImpl impl = createSocketImpl();
+ return new SdpSocket(impl);
+ }
+
+ /**
+ * Creates an unbound SDP server socket. The {@code ServerSocket} is
+ * associated with a {@link java.net.SocketImpl} of the system-default type.
+ *
+ * @return a new ServerSocket
+ *
+ * @throws UnsupportedOperationException
+ * If SDP is not supported
+ * @throws IOException
+ * If an I/O error occurs
+ */
+ public static ServerSocket openServerSocket() throws IOException {
+ // create ServerSocket via package-private constructor
+ SocketImpl impl = createSocketImpl();
+ try {
+ return serverSocketCtor.newInstance(impl);
+ } catch (IllegalAccessException x) {
+ throw new AssertionError(x);
+ } catch (InstantiationException x) {
+ throw new AssertionError(x);
+ } catch (InvocationTargetException x) {
+ Throwable cause = x.getCause();
+ if (cause instanceof IOException)
+ throw (IOException)cause;
+ if (cause instanceof RuntimeException)
+ throw (RuntimeException)cause;
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * Opens a socket channel to a SDP socket.
+ *
+ * <p> The channel will be associated with the system-wide default
+ * {@link java.nio.channels.spi.SelectorProvider SelectorProvider}.
+ *
+ * @return a new SocketChannel
+ *
+ * @throws UnsupportedOperationException
+ * If SDP is not supported or not supported by the default selector
+ * provider
+ * @throws IOException
+ * If an I/O error occurs.
+ */
+ public static SocketChannel openSocketChannel() throws IOException {
+ FileDescriptor fd = SdpSupport.createSocket();
+ return sun.nio.ch.Secrets.newSocketChannel(fd);
+ }
+
+ /**
+ * Opens a socket channel to a SDP socket.
+ *
+ * <p> The channel will be associated with the system-wide default
+ * {@link java.nio.channels.spi.SelectorProvider SelectorProvider}.
+ *
+ * @return a new ServerSocketChannel
+ *
+ * @throws UnsupportedOperationException
+ * If SDP is not supported or not supported by the default selector
+ * provider
+ * @throws IOException
+ * If an I/O error occurs
+ */
+ public static ServerSocketChannel openServerSocketChannel()
+ throws IOException
+ {
+ FileDescriptor fd = SdpSupport.createSocket();
+ return sun.nio.ch.Secrets.newServerSocketChannel(fd);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility.properties
new file mode 100755
index 0000000..fd73143
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=alert
+awtcomponent=AWT component
+checkbox=check box
+colorchooser=color chooser
+columnheader=column header
+combobox=combo box
+canvas=canvas
+desktopicon=desktop icon
+desktoppane=desktop pane
+dialog=dialog
+directorypane=directory pane
+glasspane=glass pane
+filechooser=file chooser
+filler=filler
+frame=frame
+internalframe=internal frame
+label=label
+layeredpane=layered pane
+list=list
+listitem=list item
+menubar=menu bar
+menu=menu
+menuitem=menu item
+optionpane=option pane
+pagetab=page tab
+pagetablist=page tab list
+panel=panel
+passwordtext=password text
+popupmenu=popup menu
+progressbar=progress bar
+pushbutton=push button
+radiobutton=radio button
+rootpane=root pane
+rowheader=row header
+scrollbar=scroll bar
+scrollpane=scroll pane
+separator=separator
+slider=slider
+splitpane=split pane
+swingcomponent=swing component
+table=table
+text=text
+tree=tree
+togglebutton=toggle button
+toolbar=tool bar
+tooltip=tool tip
+unknown=unknown
+viewport=viewport
+window=window
+#
+# accessible relations
+#
+labelFor=label for
+labeledBy=labeled by
+memberOf=member of
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=active
+armed=armed
+busy=busy
+checked=checked
+collapsed=collapsed
+editable=editable
+expandable=expandable
+expanded=expanded
+enabled=enabled
+focusable=focusable
+focused=focused
+iconified=iconified
+modal=modal
+multiline=multiple line
+multiselectable=multiselectable
+opaque=opaque
+pressed=pressed
+resizable=resizable
+selectable=selectable
+selected=selected
+showing=showing
+singleline=single line
+transient=transient
+visible=visible
+vertical=vertical
+horizontal=horizontal
+#
+# accessible actions
+#
+toggleexpand=toggle expand
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=flows to
+flowsFrom=flows from
+subwindowOf=subwindow of
+parentWindowOf=parent window of
+embeds=embeds
+embeddedBy=embedded by
+childNodeOf=child node of
+
+#
+# accessible roles
+#
+header=header
+footer=footer
+paragraph=paragraph
+ruler=ruler
+editbar=editbar
+progressMonitor=progress monitor
+
+#
+# accessible states
+#
+managesDescendants=manages descendants
+indeterminate=indeterminate
+truncated=truncated
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML container
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_de.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_de.properties
new file mode 100755
index 0000000..fe0f918
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_de.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=Alert
+awtcomponent=AWT-Komponente
+checkbox=Kontrollk\u00E4stchen
+colorchooser=Farbauswahl
+columnheader=Spalten-Header
+combobox=Kombinationsfeld
+canvas=Leinwand
+desktopicon=Desktopsymbol
+desktoppane=Desktopbereich
+dialog=Dialogfeld
+directorypane=Verzeichnisbereich
+glasspane=Glass Pane
+filechooser=Dateiauswahl
+filler=F\u00FCllbereich
+frame=Rahmen
+internalframe=Innerer Rahmen
+label=Label
+layeredpane=Layered Pane
+list=Liste
+listitem=Listenelement
+menubar=Men\u00FCleiste
+menu=Men\u00FC
+menuitem=Men\u00FCpunkt
+optionpane=Optionsbereich
+pagetab=Registerkarte
+pagetablist=Registerkartenliste
+panel=Bereich
+passwordtext=Kennworttext
+popupmenu=Popup-Men\u00FC
+progressbar=Fortschrittsbalken
+pushbutton=Schaltfl\u00E4che
+radiobutton=Optionsfeld
+rootpane=Root-Bereich
+rowheader=Zeilen-Header
+scrollbar=Bildlaufleiste
+scrollpane=Bildlaufbereich
+separator=Trennzeichen
+slider=Schieberegler
+splitpane=Split Pane
+swingcomponent=Swing-Komponente
+table=Tabelle
+text=Text
+tree=Baumstruktur
+togglebutton=Umschaltfl\u00E4che
+toolbar=Symbolleiste
+tooltip=QuickInfo
+unknown=Unbekannt
+viewport=Viewport
+window=Fenster
+#
+# accessible relations
+#
+labelFor=Label f\u00FCr
+labeledBy=beschriftet von
+memberOf=Mitglied von
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=aktiv
+armed=aktiviert
+busy=ausgelastet
+checked=markiert
+collapsed=ausgeblendet
+editable=bearbeitbar
+expandable=erweiterbar
+expanded=eingeblendet
+enabled=aktiviert
+focusable=fokussierbar
+focused=fokussiert
+iconified=minimiert
+modal=modal
+multiline=mehrzeilig
+multiselectable=mehrfach ausw\u00E4hlbar
+opaque=nicht transparent
+pressed=gedr\u00FCckt
+resizable=skalierbar
+selectable=w\u00E4hlbar
+selected=ausgew\u00E4hlt
+showing=angezeigt
+singleline=einzeilig
+transient=transient
+visible=sichtbar
+vertical=vertikal
+horizontal=horizontal
+#
+# accessible actions
+#
+toggleexpand=ein-/ausblenden
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=flie\u00DFt zu
+flowsFrom=flie\u00DFt von
+subwindowOf=Unterfenster von
+parentWindowOf=\u00FCbergeordnetes Fenster von
+embeds=bettet ein
+embeddedBy=eingebettet in
+childNodeOf=untergeordneter Knoten von
+
+#
+# accessible roles
+#
+header=Header
+footer=Footer
+paragraph=Absatz
+ruler=Lineal
+editbar=Bearbeitungsleiste
+progressMonitor=Fortschrittsmonitor
+
+#
+# accessible states
+#
+managesDescendants=verwaltet untergeordnete Objekte
+indeterminate=unbestimmt
+truncated=abgeschnitten
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML-Container
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_en.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_en.properties
new file mode 100755
index 0000000..1281e49
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_en.properties
@@ -0,0 +1,142 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=alert
+awtcomponent=AWT component
+checkbox=check box
+colorchooser=color chooser
+columnheader=column header
+combobox=combo box
+canvas=canvas
+desktopicon=desktop icon
+desktoppane=desktop pane
+dialog=dialog
+directorypane=directory pane
+glasspane=glass pane
+filechooser=file chooser
+filler=filler
+frame=frame
+internalframe=internal frame
+label=label
+layeredpane=layered pane
+list=list
+listitem=list item
+menubar=menu bar
+menu=menu
+menuitem=menu item
+optionpane=option pane
+pagetab=page tab
+pagetablist=page tab list
+panel=panel
+passwordtext=password text
+popupmenu=popup menu
+progressbar=progress bar
+pushbutton=push button
+radiobutton=radio button
+rootpane=root pane
+rowheader=row header
+scrollbar=scroll bar
+scrollpane=scroll pane
+separator=separator
+slider=slider
+splitpane=split pane
+swingcomponent=swing component
+table=table
+text=text
+tree=tree
+togglebutton=toggle button
+toolbar=tool bar
+tooltip=tool tip
+unknown=unknown
+viewport=viewport
+window=window
+#
+# accessible relations
+#
+labelFor=label for
+labeledBy=labeled by
+memberOf=member of
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=active
+armed=armed
+busy=busy
+checked=checked
+collapsed=collapsed
+editable=editable
+expandable=expandable
+expanded=expanded
+enabled=enabled
+focusable=focusable
+focused=focused
+iconified=iconified
+modal=modal
+multiline=multiple line
+multiselectable=multiselectable
+opaque=opaque
+pressed=pressed
+resizable=resizable
+selectable=selectable
+selected=selected
+showing=showing
+singleline=single line
+transient=transient
+visible=visible
+vertical=vertical
+horizontal=horizontal
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=flows to
+flowsFrom=flows from
+subwindowOf=subwindow of
+parentWindowOf=parent window of
+embeds=embeds
+embeddedBy=embedded by
+childNodeOf=child node of
+
+#
+# accessible roles
+#
+header=header
+footer=footer
+paragraph=paragraph
+ruler=ruler
+editbar=editbar
+progressMonitor=progress monitor
+
+#
+# accessible states
+#
+managesDescendants=manages descendants
+indeterminate=indeterminate
+truncated=truncated
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML container
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_es.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_es.properties
new file mode 100755
index 0000000..c3f9041
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_es.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=alerta
+awtcomponent=componente AWT
+checkbox=casilla de control
+colorchooser=selector de color
+columnheader=cabecera de columna
+combobox=cuadro combinado
+canvas=lienzo
+desktopicon=icono de escritorio
+desktoppane=panel de escritorio
+dialog=cuadro de di\u00E1logo
+directorypane=panel de directorio
+glasspane=panel de cristal
+filechooser=selector de archivos
+filler=rellenador
+frame=marco
+internalframe=marco interno
+label=etiqueta
+layeredpane=panel en capas
+list=lista
+listitem=elemento de lista
+menubar=barra de men\u00FAs
+menu=men\u00FA
+menuitem=elemento de men\u00FA
+optionpane=panel de opciones
+pagetab=separador de p\u00E1gina
+pagetablist=lista de separadores de p\u00E1gina
+panel=panel
+passwordtext=texto de contrase\u00F1a
+popupmenu=men\u00FA emergente
+progressbar=barra de progreso
+pushbutton=bot\u00F3n
+radiobutton=bot\u00F3n de radio
+rootpane=panel ra\u00EDz
+rowheader=cabecera de filas
+scrollbar=barra de desplazamiento
+scrollpane=panel de desplazamiento
+separator=separador
+slider=deslizador
+splitpane=panel de divisi\u00F3n
+swingcomponent=componente swing
+table=tabla
+text=texto
+tree=\u00E1rbol
+togglebutton=bot\u00F3n conmutador
+toolbar=barra de herramientas
+tooltip=ayuda de burbuja
+unknown=desconocido
+viewport=viewport
+window=ventana
+#
+# accessible relations
+#
+labelFor=etiqueta para
+labeledBy=etiquetado por
+memberOf=miembro de
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=activo
+armed=armado
+busy=ocupado
+checked=activado
+collapsed=reducido
+editable=editable
+expandable=ampliable
+expanded=ampliado
+enabled=activado
+focusable=enfocable
+focused=enfocado
+iconified=convertido en icono
+modal=modal
+multiline=l\u00EDnea m\u00FAltiple
+multiselectable=multiseleccionable
+opaque=opaco
+pressed=pulsado
+resizable=redimensionable
+selectable=seleccionable
+selected=seleccionado
+showing=mostrando
+singleline=l\u00EDnea \u00FAnica
+transient=transitorio
+visible=visible
+vertical=vertical
+horizontal=horizontal
+#
+# accessible actions
+#
+toggleexpand=activar/desactivar ampliaci\u00F3n
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=llega a
+flowsFrom=procede de
+subwindowOf=ventana subordinada de
+parentWindowOf=ventana principal de
+embeds=embebe
+embeddedBy=embebido por
+childNodeOf=nodo secundario de
+
+#
+# accessible roles
+#
+header=cabecera
+footer=pie
+paragraph=p\u00E1rrafo
+ruler=regla
+editbar=barra de edici\u00F3n
+progressMonitor=monitor de progreso
+
+#
+# accessible states
+#
+managesDescendants=gestiona descendientes
+indeterminate=indeterminada
+truncated=truncado
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=Contenedor HTML
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_fr.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_fr.properties
new file mode 100755
index 0000000..c399d9a
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_fr.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=alerte
+awtcomponent=composant AWT
+checkbox=case \u00E0 cocher
+colorchooser=s\u00E9lecteur de couleurs
+columnheader=en-t\u00EAte de colonne
+combobox=liste d\u00E9roulante
+canvas=canevas
+desktopicon=ic\u00F4ne de bureau
+desktoppane=panneau de bureau
+dialog=bo\u00EEte de dialogue
+directorypane=panneau de r\u00E9pertoires
+glasspane=panneau de grossissement
+filechooser=s\u00E9lecteur de fichiers
+filler=\u00E9l\u00E9ment de remplissage
+frame=cadre
+internalframe=cadre interne
+label=libell\u00E9
+layeredpane=panneau superpos\u00E9
+list=liste
+listitem=\u00E9l\u00E9ment de liste
+menubar=barre de menus
+menu=menu
+menuitem=option de menu
+optionpane=panneau d'options
+pagetab=onglet de page
+pagetablist=liste d'onglets de page
+panel=panneau
+passwordtext=texte de mot de passe
+popupmenu=menu contextuel
+progressbar=barre de progression
+pushbutton=bouton
+radiobutton=bouton radio
+rootpane=panneau racine
+rowheader=en-t\u00EAte de ligne
+scrollbar=barre de d\u00E9filement
+scrollpane=panneau de d\u00E9filement
+separator=s\u00E9parateur
+slider=curseur
+splitpane=panneau divis\u00E9
+swingcomponent=composant Swing
+table=tableau
+text=texte
+tree=arborescence
+togglebutton=bouton de basculement
+toolbar=barre d'outils
+tooltip=info-bulle
+unknown=inconnu
+viewport=lucarne
+window=fen\u00EAtre
+#
+# accessible relations
+#
+labelFor=libell\u00E9 de
+labeledBy=libell\u00E9 par
+memberOf=membre de
+controlledBy=contr\u00F4l\u00E9 par
+controllerFor=contr\u00F4leur pour
+#
+# accessible states
+#
+active=actif
+armed=arm\u00E9
+busy=occup\u00E9
+checked=coch\u00E9
+collapsed=r\u00E9duit
+editable=modifiable
+expandable=extensible
+expanded=d\u00E9velopp\u00E9
+enabled=activ\u00E9
+focusable=zone d'entr\u00E9e possible
+focused=avec zone d'entr\u00E9e
+iconified=r\u00E9duit \u00E0 une ic\u00F4ne
+modal=modal
+multiline=ligne multiple
+multiselectable=multis\u00E9lectionnable
+opaque=opaque
+pressed=enfonc\u00E9
+resizable=redimensionnable
+selectable=s\u00E9lectionnable
+selected=s\u00E9lectionn\u00E9
+showing=montrant
+singleline=ligne unique
+transient=non persistant
+visible=visible
+vertical=vertical
+horizontal=horizontal
+#
+# accessible actions
+#
+toggleexpand=basculer le d\u00E9veloppement
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=flux vers
+flowsFrom=flux depuis
+subwindowOf=sous-fen\u00EAtre de
+parentWindowOf=fen\u00EAtre parente de
+embeds=incorpore
+embeddedBy=incorpor\u00E9 par
+childNodeOf=noeud enfant de
+
+#
+# accessible roles
+#
+header=en-t\u00EAte
+footer=pied de page
+paragraph=paragraphe
+ruler=r\u00E8gle
+editbar=barre d'\u00E9dition
+progressMonitor=contr\u00F4le de la progression
+
+#
+# accessible states
+#
+managesDescendants=g\u00E8re les descendants
+indeterminate=ind\u00E9termin\u00E9
+truncated=tronqu\u00E9
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=conteneur HTML
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_it.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_it.properties
new file mode 100755
index 0000000..94eefb0
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_it.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=avviso
+awtcomponent=componente AWT
+checkbox=casella di controllo
+colorchooser=selezione colori
+columnheader=intestazione colonna
+combobox=casella combinata
+canvas=sfondo
+desktopicon=icona desktop
+desktoppane=riquadro desktop
+dialog=finestra di dialogo
+directorypane=riquadro directory
+glasspane=riquadro trasparente
+filechooser=selezione file
+filler=utilit\u00E0 riempimento
+frame=cornice
+internalframe=cornice interna
+label=etichetta
+layeredpane=riquadro a livelli
+list=lista
+listitem=voce lista
+menubar=barra dei menu
+menu=menu
+menuitem=voce di menu
+optionpane=riquadro opzioni
+pagetab=scheda pagina
+pagetablist=lista schede pagina
+panel=pannello
+passwordtext=testo della password
+popupmenu=menu popup
+progressbar=barra di avanzamento
+pushbutton=pulsante
+radiobutton=pulsante di scelta
+rootpane=riquadro root
+rowheader=intestazione di riga
+scrollbar=barra di scorrimento
+scrollpane=riquadro scorrimento
+separator=separatore
+slider=dispositivo di scorrimento
+splitpane=riquadro doppio
+swingcomponent=componente swing
+table=tabella
+text=testo
+tree=albero
+togglebutton=interruttore
+toolbar=barra degli strumenti
+tooltip=descrizione comandi
+unknown=sconosciuto
+viewport=viewport
+window=finestra
+#
+# accessible relations
+#
+labelFor=etichetta per
+labeledBy=etichetta di
+memberOf=membro di
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=attivo
+armed=abilitato
+busy=occupato
+checked=verificato
+collapsed=compresso
+editable=modificabile
+expandable=espandibile
+expanded=espanso
+enabled=abilitato
+focusable=attivabile in primo piano
+focused=in primo piano
+iconified=ridotto a icona
+modal=modale
+multiline=a righe multiple
+multiselectable=multi-selezionabile
+opaque=nascosto
+pressed=premuto
+resizable=ridimensionabile
+selectable=selezionabile
+selected=selezionato
+showing=visualizzato
+singleline=a riga singola
+transient=transitorio
+visible=visibile
+vertical=verticale
+horizontal=orizzontale
+#
+# accessible actions
+#
+toggleexpand=abilita/disabilita espansione
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=va verso
+flowsFrom=proviene da
+subwindowOf=sottofinestra di
+parentWindowOf=finestra di livello superiore di
+embeds=incorpora
+embeddedBy=incorporato da
+childNodeOf=nodo figlio di
+
+#
+# accessible roles
+#
+header=intestazione
+footer=pi\u00E8 di pagina
+paragraph=paragrafo
+ruler=righello
+editbar=barra di modifica
+progressMonitor=stato avanzamento
+
+#
+# accessible states
+#
+managesDescendants=gestisce i discendenti
+indeterminate=indeterminato
+truncated=troncato
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=Contenitore HTML
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_ja.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_ja.properties
new file mode 100755
index 0000000..eefc178
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_ja.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=\u30A2\u30E9\u30FC\u30C8
+awtcomponent=AWT\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8
+checkbox=\u30C1\u30A7\u30C3\u30AF\u30FB\u30DC\u30C3\u30AF\u30B9
+colorchooser=\u30AB\u30E9\u30FC\u30FB\u30C1\u30E5\u30FC\u30B6
+columnheader=\u5217\u30D8\u30C3\u30C0\u30FC
+combobox=\u30B3\u30F3\u30DC\u30FB\u30DC\u30C3\u30AF\u30B9
+canvas=\u30AD\u30E3\u30F3\u30D0\u30B9
+desktopicon=\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u30FB\u30A2\u30A4\u30B3\u30F3
+desktoppane=\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u533A\u753B
+dialog=\u30C0\u30A4\u30A2\u30ED\u30B0
+directorypane=\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u533A\u753B
+glasspane=\u30AC\u30E9\u30B9\u533A\u753B
+filechooser=\u30D5\u30A1\u30A4\u30EB\u30FB\u30C1\u30E5\u30FC\u30B6
+filler=\u30D5\u30A3\u30E9\u30FC
+frame=\u30D5\u30EC\u30FC\u30E0
+internalframe=\u5185\u90E8\u30D5\u30EC\u30FC\u30E0
+label=\u30E9\u30D9\u30EB
+layeredpane=\u968E\u5C64\u5316\u3055\u308C\u305F\u533A\u753B
+list=\u30EA\u30B9\u30C8
+listitem=\u30EA\u30B9\u30C8\u9805\u76EE
+menubar=\u30E1\u30CB\u30E5\u30FC\u30FB\u30D0\u30FC
+menu=\u30E1\u30CB\u30E5\u30FC
+menuitem=\u30E1\u30CB\u30E5\u30FC\u9805\u76EE
+optionpane=\u30AA\u30D7\u30B7\u30E7\u30F3\u533A\u753B
+pagetab=\u30DA\u30FC\u30B8\u30FB\u30BF\u30D6
+pagetablist=\u30DA\u30FC\u30B8\u30FB\u30BF\u30D6\u30FB\u30EA\u30B9\u30C8
+panel=\u30D1\u30CD\u30EB
+passwordtext=\u30D1\u30B9\u30EF\u30FC\u30C9\u30FB\u30C6\u30AD\u30B9\u30C8
+popupmenu=\u30DD\u30C3\u30D7\u30A2\u30C3\u30D7\u30FB\u30E1\u30CB\u30E5\u30FC
+progressbar=\u9032\u6357\u30D0\u30FC
+pushbutton=\u30D7\u30C3\u30B7\u30E5\u30FB\u30DC\u30BF\u30F3
+radiobutton=\u30E9\u30B8\u30AA\u30FB\u30DC\u30BF\u30F3
+rootpane=\u30EB\u30FC\u30C8\u533A\u753B
+rowheader=\u884C\u30D8\u30C3\u30C0\u30FC
+scrollbar=\u30B9\u30AF\u30ED\u30FC\u30EB\u30FB\u30D0\u30FC
+scrollpane=\u30B9\u30AF\u30ED\u30FC\u30EB\u533A\u753B
+separator=\u30BB\u30D1\u30EC\u30FC\u30BF
+slider=\u30B9\u30E9\u30A4\u30C0
+splitpane=\u5206\u5272\u533A\u753B
+swingcomponent=Swing\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8
+table=\u8868
+text=\u30C6\u30AD\u30B9\u30C8
+tree=\u30C4\u30EA\u30FC
+togglebutton=\u30C8\u30B0\u30EB\u30FB\u30DC\u30BF\u30F3
+toolbar=\u30C4\u30FC\u30EB\u30D0\u30FC
+tooltip=\u30C4\u30FC\u30EB\u30C1\u30C3\u30D7
+unknown=\u4E0D\u660E
+viewport=\u30D3\u30E5\u30FC\u30DD\u30FC\u30C8
+window=\u30A6\u30A3\u30F3\u30C9\u30A6
+#
+# accessible relations
+#
+labelFor=label for
+labeledBy=labeled by
+memberOf=member of
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=\u30A2\u30AF\u30C6\u30A3\u30D6
+armed=\u4F5C\u52D5\u6E96\u5099\u5B8C\u4E86
+busy=\u30D3\u30B8\u30FC
+checked=\u30C1\u30A7\u30C3\u30AF
+collapsed=\u77ED\u7E2E
+editable=\u7DE8\u96C6\u53EF\u80FD
+expandable=\u5C55\u958B\u53EF\u80FD
+expanded=\u5C55\u958B
+enabled=\u6709\u52B9
+focusable=\u30D5\u30A9\u30FC\u30AB\u30B9\u53EF\u80FD
+focused=\u30D5\u30A9\u30FC\u30AB\u30B9
+iconified=\u30A2\u30A4\u30B3\u30F3\u5316
+modal=\u30E2\u30FC\u30C0\u30EB
+multiline=\u8907\u6570\u884C
+multiselectable=\u8907\u6570\u9078\u629E\u53EF\u80FD
+opaque=\u4E0D\u900F\u660E
+pressed=\u62BC\u4E0B
+resizable=\u30B5\u30A4\u30BA\u5909\u66F4\u53EF\u80FD
+selectable=\u9078\u629E\u53EF\u80FD
+selected=\u9078\u629E
+showing=\u8868\u793A
+singleline=\u5358\u4E00\u884C
+transient=\u4E00\u6642
+visible=\u53EF\u8996
+vertical=\u5782\u76F4
+horizontal=\u6C34\u5E73
+#
+# accessible actions
+#
+toggleexpand=\u5C55\u958B\u306E\u30C8\u30B0\u30EB
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=flows to
+flowsFrom=flows from
+subwindowOf=subwindow of
+parentWindowOf=parent window of
+embeds=\u57CB\u8FBC\u307F
+embeddedBy=embedded by
+childNodeOf=child node of
+
+#
+# accessible roles
+#
+header=\u30D8\u30C3\u30C0\u30FC
+footer=\u30D5\u30C3\u30BF\u30FC
+paragraph=\u6BB5\u843D
+ruler=\u30EB\u30FC\u30E9\u30FC
+editbar=\u7DE8\u96C6\u30D0\u30FC
+progressMonitor=\u9032\u6357\u30E2\u30CB\u30BF\u30FC
+
+#
+# accessible states
+#
+managesDescendants=\u5B50\u5B6B\u3092\u7BA1\u7406
+indeterminate=\u4E0D\u78BA\u5B9A
+truncated=\u4E0D\u5B8C\u5168
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML\u30B3\u30F3\u30C6\u30CA
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_ko.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_ko.properties
new file mode 100755
index 0000000..530caa6
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_ko.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=\uACBD\uBCF4
+awtcomponent=AWT \uAD6C\uC131 \uC694\uC18C
+checkbox=\uCCB4\uD06C \uBC15\uC2A4
+colorchooser=\uC0C9\uC0C1 \uC120\uD0DD\uAE30
+columnheader=\uC5F4 \uBA38\uB9AC\uAE00
+combobox=\uCF64\uBCF4 \uC0C1\uC790
+canvas=\uCE94\uBC84\uC2A4
+desktopicon=\uBC14\uD0D5 \uD654\uBA74 \uC544\uC774\uCF58
+desktoppane=\uBC14\uD0D5 \uD654\uBA74 \uCC3D
+dialog=\uB300\uD654\uC0C1\uC790
+directorypane=\uB514\uB809\uD1A0\uB9AC \uCC3D
+glasspane=\uAE00\uB798\uC2A4 \uCC3D
+filechooser=\uD30C\uC77C \uC120\uD0DD\uAE30
+filler=\uD544\uB7EC
+frame=\uD504\uB808\uC784
+internalframe=\uB0B4\uBD80 \uD504\uB808\uC784
+label=\uB808\uC774\uBE14
+layeredpane=\uACC4\uCE35\uC801 \uCC3D
+list=\uBAA9\uB85D
+listitem=\uBAA9\uB85D \uD56D\uBAA9
+menubar=\uBA54\uB274 \uD45C\uC2DC\uC904
+menu=\uBA54\uB274
+menuitem=\uBA54\uB274 \uD56D\uBAA9
+optionpane=\uC635\uC158 \uCC3D
+pagetab=\uD398\uC774\uC9C0 \uD0ED
+pagetablist=\uD398\uC774\uC9C0 \uD0ED \uBAA9\uB85D
+panel=\uD328\uB110
+passwordtext=\uBE44\uBC00\uBC88\uD638 \uD14D\uC2A4\uD2B8
+popupmenu=\uD31D\uC5C5 \uBA54\uB274
+progressbar=\uC9C4\uD589 \uB9C9\uB300
+pushbutton=\uB204\uB984 \uB2E8\uCD94
+radiobutton=\uB77C\uB514\uC624 \uB2E8\uCD94
+rootpane=\uB8E8\uD2B8 \uCC3D
+rowheader=\uD589 \uBA38\uB9AC\uAE00
+scrollbar=\uC2A4\uD06C\uB864 \uB9C9\uB300
+scrollpane=\uC2A4\uD06C\uB864 \uCC3D
+separator=\uAD6C\uBD84 \uAE30\uD638
+slider=\uC2AC\uB77C\uC774\uB354
+splitpane=\uBD84\uD560 \uCC3D
+swingcomponent=\uD68C\uC804 \uAD6C\uC131 \uC694\uC18C
+table=\uD14C\uC774\uBE14
+text=\uD14D\uC2A4\uD2B8
+tree=\uD2B8\uB9AC
+togglebutton=\uD1A0\uAE00 \uB2E8\uCD94
+toolbar=\uB3C4\uAD6C \uBAA8\uC74C
+tooltip=\uB3C4\uAD6C \uC124\uBA85
+unknown=\uC54C \uC218 \uC5C6\uC74C
+viewport=\uBDF0\uD3EC\uD2B8
+window=\uCC3D
+#
+# accessible relations
+#
+labelFor=\uB808\uC774\uBE14 \uB300\uC0C1
+labeledBy=\uB808\uC774\uBE14 \uC9C0\uC815\uC790
+memberOf=\uC18C\uC18D \uADF8\uB8F9
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=\uD65C\uC131
+armed=\uD06C\uAE30
+busy=\uC0AC\uC6A9 \uC911
+checked=\uC120\uD0DD\uB428
+collapsed=\uCD95\uC18C\uB428
+editable=\uD3B8\uC9D1 \uAC00\uB2A5
+expandable=\uD655\uC7A5 \uAC00\uB2A5
+expanded=\uD655\uC7A5\uB428
+enabled=\uC0AC\uC6A9
+focusable=\uD3EC\uCEE4\uC2A4 \uAC00\uB2A5
+focused=\uD3EC\uCEE4\uC2A4\uB428
+iconified=\uC544\uC774\uCF58\uD654\uB428
+modal=\uBAA8\uB2EC
+multiline=\uBCF5\uC218 \uD589
+multiselectable=\uB2E4\uC911 \uC120\uD0DD \uAC00\uB2A5
+opaque=\uBD88\uD22C\uBA85
+pressed=\uB204\uB984
+resizable=\uD06C\uAE30 \uC870\uC815 \uAC00\uB2A5
+selectable=\uC120\uD0DD \uAC00\uB2A5
+selected=\uC120\uD0DD\uB428
+showing=\uD45C\uC2DC
+singleline=\uD55C \uC904
+transient=\uC77C\uC2DC
+visible=\uD45C\uC2DC \uAC00\uB2A5
+vertical=\uC138\uB85C
+horizontal=\uAC00\uB85C
+#
+# accessible actions
+#
+toggleexpand=\uD1A0\uAE00 \uD655\uC7A5
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=\uD750\uB984 \uB300\uC0C1
+flowsFrom=\uD750\uB984 \uCD9C\uCC98
+subwindowOf=\uD558\uC704 \uCC3D
+parentWindowOf=\uC0C1\uC704 \uCC3D
+embeds=\uD3EC\uD568
+embeddedBy=\uD3EC\uD568 \uC8FC\uCCB4
+childNodeOf=\uD558\uC704 \uB178\uB4DC
+
+#
+# accessible roles
+#
+header=\uBA38\uB9AC\uAE00
+footer=\uBC14\uB2E5\uAE00
+paragraph=\uB2E8\uB77D
+ruler=\uB208\uAE08\uC790
+editbar=\uD3B8\uC9D1 \uB3C4\uAD6C
+progressMonitor=\uC9C4\uD589 \uBAA8\uB2C8\uD130
+
+#
+# accessible states
+#
+managesDescendants=\uC885\uC18D \uD56D\uBAA9 \uAD00\uB9AC
+indeterminate=\uD655\uC815\uB418\uC9C0 \uC54A\uC74C
+truncated=\uC798\uB9BC
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML \uCEE8\uD14C\uC774\uB108
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_pt_BR.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_pt_BR.properties
new file mode 100755
index 0000000..f8aaf35
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_pt_BR.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=alerta
+awtcomponent=componente AWT
+checkbox=caixa de sele\u00E7\u00E3o
+colorchooser=seletor de cores
+columnheader=cabe\u00E7alho da coluna
+combobox=caixa de combina\u00E7\u00E3o
+canvas=tela
+desktopicon=\u00EDcone da \u00E1rea de trabalho
+desktoppane=painel da \u00E1rea de trabalho
+dialog=caixa de di\u00E1logo
+directorypane=painel do diret\u00F3rio
+glasspane=painel transparente
+filechooser=seletor de arquivos
+filler=preenchedor
+frame=quadro
+internalframe=quadro interno
+label=r\u00F3tulo
+layeredpane=painel em camadas
+list=lista
+listitem=item da lista
+menubar=barra de menus
+menu=menu
+menuitem=item do menu
+optionpane=painel de op\u00E7\u00F5es
+pagetab=guia da p\u00E1gina
+pagetablist=lista de guias da p\u00E1gina
+panel=painel
+passwordtext=texto da senha
+popupmenu=menu pop-up
+progressbar=barra de progresso
+pushbutton=bot\u00E3o de a\u00E7\u00E3o
+radiobutton=bot\u00E3o de op\u00E7\u00E3o
+rootpane=painel base
+rowheader=cabe\u00E7alho da linha
+scrollbar=barra de rolagem
+scrollpane=painel de rolagem
+separator=separador
+slider=controle deslizante
+splitpane=painel dividido
+swingcomponent=componente swing
+table=tabela
+text=texto
+tree=\u00E1rvore
+togglebutton=bot\u00E3o de altern\u00E2ncia
+toolbar=barra de ferramentas
+tooltip=dica de ferramenta
+unknown=desconhecido
+viewport=janela de visualiza\u00E7\u00E3o
+window=janela
+#
+# accessible relations
+#
+labelFor=r\u00F3tulo de
+labeledBy=rotulado por
+memberOf=membro de
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=ativo
+armed=armado
+busy=ocupado
+checked=selecionado
+collapsed=contra\u00EDdo
+editable=edit\u00E1vel
+expandable=expans\u00EDvel
+expanded=expandido
+enabled=ativado
+focusable=focaliz\u00E1vel
+focused=focalizado
+iconified=iconizado
+modal=modal
+multiline=v\u00E1rias linhas
+multiselectable=m\u00FAltipla escolha
+opaque=opaco
+pressed=pressionado
+resizable=redimension\u00E1vel
+selectable=selecion\u00E1vel
+selected=selecionado
+showing=mostrando
+singleline=linha \u00FAnica
+transient=transit\u00F3rio
+visible=vis\u00EDvel
+vertical=vertical
+horizontal=horizontal
+#
+# accessible actions
+#
+toggleexpand=alternar expans\u00E3o
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=fluxos para
+flowsFrom=fluxos de
+subwindowOf=subjanela de
+parentWindowOf=janela pai de
+embeds=integra
+embeddedBy=integrado por
+childNodeOf=n\u00F3 filho de
+
+#
+# accessible roles
+#
+header=cabe\u00E7alho
+footer=rodap\u00E9
+paragraph=par\u00E1grafo
+ruler=r\u00E9gua
+editbar=barra de edi\u00E7\u00E3o
+progressMonitor=monitor de progresso
+
+#
+# accessible states
+#
+managesDescendants=gerencia descendentes
+indeterminate=indeterminado
+truncated=truncado
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=Container de HTML
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_sv.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_sv.properties
new file mode 100755
index 0000000..962b9d3
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_sv.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=avisering
+awtcomponent=AWT-komponent
+checkbox=kryssruta
+colorchooser=f\u00E4rgv\u00E4ljare
+columnheader=kolumnrubrik
+combobox=kombinationsruta
+canvas=rityta
+desktopicon=skrivbordsikon
+desktoppane=skrivbordsruta
+dialog=dialogruta
+directorypane=katalogruta
+glasspane=glasruta
+filechooser=filv\u00E4ljare
+filler=utfyllnad
+frame=ram
+internalframe=intern ram
+label=etikett
+layeredpane=staplad ruta
+list=lista
+listitem=listobjekt
+menubar=menyrad
+menu=meny
+menuitem=menyalternativ
+optionpane=alternativruta
+pagetab=sidflik
+pagetablist=sidflikslista
+panel=panel
+passwordtext=l\u00F6senordstext
+popupmenu=snabbmeny
+progressbar=statusrad
+pushbutton=knapp
+radiobutton=alternativknapp
+rootpane=grundruta
+rowheader=radrubrik
+scrollbar=rullningslist
+scrollpane=rullningsruta
+separator=avskiljare
+slider=skjutreglage
+splitpane=delad ruta
+swingcomponent=swing-komponent
+table=tabell
+text=text
+tree=tr\u00E4d
+togglebutton=v\u00E4xlingsknapp
+toolbar=verktygsrad
+tooltip=knappbeskrivning
+unknown=ok\u00E4nd
+viewport=vyport
+window=f\u00F6nster
+#
+# accessible relations
+#
+labelFor=etikett f\u00F6r
+labeledBy=etikett av
+memberOf=medlem i
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=aktiv
+armed=redo
+busy=upptagen
+checked=markerad
+collapsed=komprimerad
+editable=redigerbar
+expandable=ut\u00F6kningsbar
+expanded=ut\u00F6kad
+enabled=aktiverad
+focusable=fokuseringsbar
+focused=fokuserad
+iconified=minimerad
+modal=modal
+multiline=flera rader
+multiselectable=flerval
+opaque=t\u00E4ckande
+pressed=nedtryckt
+resizable=storleks\u00E4ndringsbar
+selectable=valbar
+selected=vald
+showing=visas
+singleline=en rad
+transient=tillf\u00E4llig
+visible=synlig
+vertical=vertikal
+horizontal=horisontell
+#
+# accessible actions
+#
+toggleexpand=v\u00E4xla ut\u00F6ka
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=fl\u00F6dar till
+flowsFrom=fl\u00F6dar fr\u00E5n
+subwindowOf=delf\u00F6nster av
+parentWindowOf=\u00F6verordnat f\u00F6nster f\u00F6r
+embeds=b\u00E4ddar in
+embeddedBy=b\u00E4ddas in av
+childNodeOf=underordnad nod f\u00F6r
+
+#
+# accessible roles
+#
+header=sidhuvud
+footer=sidfot
+paragraph=stycke
+ruler=linjal
+editbar=redigeringslist
+progressMonitor=f\u00F6rlopps\u00F6vervakare
+
+#
+# accessible states
+#
+managesDescendants=hanterar underordnade
+indeterminate=obest\u00E4mt
+truncated=kapad
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML-container
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_zh_CN.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_zh_CN.properties
new file mode 100755
index 0000000..da67e24
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_zh_CN.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=\u9884\u8B66
+awtcomponent=AWT \u7EC4\u4EF6
+checkbox=\u590D\u9009\u6846
+colorchooser=\u989C\u8272\u9009\u62E9\u5668
+columnheader=\u5217\u6807\u9898
+combobox=\u7EC4\u5408\u6846
+canvas=\u753B\u5E03
+desktopicon=\u684C\u9762\u56FE\u6807
+desktoppane=\u684C\u9762\u7A97\u683C
+dialog=\u5BF9\u8BDD
+directorypane=\u76EE\u5F55\u7A97\u683C
+glasspane=\u73BB\u7483\u7A97\u683C
+filechooser=\u6587\u4EF6\u9009\u62E9\u5668
+filler=\u6F0F\u6597
+frame=\u6846\u67B6
+internalframe=\u5185\u90E8\u6846\u67B6
+label=\u6807\u7B7E
+layeredpane=\u5206\u5C42\u7A97\u683C
+list=\u5217\u8868
+listitem=\u5217\u8868\u9879
+menubar=\u83DC\u5355\u680F
+menu=\u83DC\u5355
+menuitem=\u83DC\u5355\u9879
+optionpane=\u9009\u9879\u7A97\u683C
+pagetab=\u9875\u6807\u7B7E
+pagetablist=\u9875\u6807\u7B7E\u5217\u8868
+panel=\u9762\u677F
+passwordtext=\u53E3\u4EE4\u6587\u672C
+popupmenu=\u5F39\u51FA\u5F0F\u83DC\u5355
+progressbar=\u8FDB\u5EA6\u680F
+pushbutton=\u6309\u94AE
+radiobutton=\u5355\u9009\u6309\u94AE
+rootpane=\u6839\u7A97\u683C
+rowheader=\u884C\u6807\u9898
+scrollbar=\u6EDA\u52A8\u6761
+scrollpane=\u6EDA\u52A8\u7A97\u683C
+separator=\u5206\u9694\u6761
+slider=\u6ED1\u5757
+splitpane=\u62C6\u5206\u7A97\u683C
+swingcomponent=\u65CB\u8F6C\u7EC4\u4EF6
+table=\u8868
+text=\u6587\u672C
+tree=\u6811
+togglebutton=\u5207\u6362\u6309\u94AE
+toolbar=\u5DE5\u5177\u680F
+tooltip=\u5DE5\u5177\u63D0\u793A
+unknown=\u672A\u77E5
+viewport=\u89C6\u7A97
+window=\u7A97\u53E3
+#
+# accessible relations
+#
+labelFor=\u6807\u7B7E\u5C5E\u4E8E
+labeledBy=\u6807\u7B7E\u5236\u4F5C\u8005
+memberOf=\u5C5E\u4E8E
+controlledBy=controlledBy
+controllerFor=controllerFor
+#
+# accessible states
+#
+active=\u6D3B\u52A8
+armed=\u5F85\u547D
+busy=\u5FD9
+checked=\u5DF2\u9009\u4E2D
+collapsed=\u5DF2\u6536\u7F29
+editable=\u53EF\u7F16\u8F91
+expandable=\u53EF\u5C55\u5F00
+expanded=\u5DF2\u5C55\u5F00
+enabled=\u542F\u7528
+focusable=\u53EF\u96C6\u4E2D
+focused=\u5DF2\u96C6\u4E2D
+iconified=\u56FE\u6807\u5F0F
+modal=\u6A21\u6001
+multiline=\u591A\u884C
+multiselectable=\u591A\u9009\u62E9
+opaque=\u4E0D\u900F\u660E
+pressed=\u5DF2\u6309\u4E0B
+resizable=\u53EF\u8C03\u6574\u5927\u5C0F
+selectable=\u53EF\u9009\u62E9
+selected=\u6240\u9009
+showing=\u6B63\u5728\u663E\u793A
+singleline=\u5355\u884C
+transient=\u77AC\u65F6
+visible=\u53EF\u89C1
+vertical=\u5782\u76F4
+horizontal=\u6C34\u5E73
+#
+# accessible actions
+#
+toggleexpand=\u5207\u6362\u5C55\u5F00
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=\u6D41\u5411
+flowsFrom=\u6D41\u81EA
+subwindowOf=\u5B50\u7A97\u53E3
+parentWindowOf=\u7236\u7A97\u53E3
+embeds=\u5D4C\u5165\u9879
+embeddedBy=\u5D4C\u5165\u8005
+childNodeOf=\u5B50\u8282\u70B9
+
+#
+# accessible roles
+#
+header=\u9875\u7709
+footer=\u9875\u811A
+paragraph=\u6BB5\u843D
+ruler=\u6807\u5C3A
+editbar=\u7F16\u8F91\u680F
+progressMonitor=\u8FDB\u5EA6\u76D1\u89C6\u5668
+
+#
+# accessible states
+#
+managesDescendants=\u7BA1\u7406\u5B50\u9879
+indeterminate=\u4E0D\u786E\u5B9A
+truncated=\u5DF2\u622A\u65AD
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML \u5BB9\u5668
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_zh_TW.properties b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_zh_TW.properties
new file mode 100755
index 0000000..1de30c2
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/accessibility/internal/resources/accessibility_zh_TW.properties
@@ -0,0 +1,146 @@
+#
+# This properties file is used to create a PropertyResourceBundle
+# It contains Locale specific strings used be the Accessibility package.
+#
+# When this file is read in, the strings are put into the
+# defaults table. This is an implementation detail of the current
+# workings of Accessibility. DO NOT DEPEND ON THIS.
+# This may change in future versions of Accessibility as we improve
+# localization support.
+#
+# @author Lynn Monsanto
+
+#
+# accessible roles
+#
+alert=\u8B66\u793A
+awtcomponent=AWT \u5143\u4EF6
+checkbox=\u6838\u53D6\u65B9\u584A
+colorchooser=\u8272\u5F69\u9078\u64C7\u5668
+columnheader=\u76F4\u6B04\u6A19\u984C
+combobox=\u4E0B\u62C9\u5F0F\u6E05\u55AE\u65B9\u584A
+canvas=\u756B\u5E03
+desktopicon=\u684C\u9762\u5716\u793A
+desktoppane=\u684C\u9762\u7A97\u683C
+dialog=\u5C0D\u8A71\u65B9\u584A
+directorypane=\u76EE\u9304\u7A97\u683C
+glasspane=\u6AA2\u8996\u7A97\u683C
+filechooser=\u6A94\u6848\u9078\u64C7\u5668
+filler=\u586B\u5145\u7269
+frame=\u6846\u67B6
+internalframe=\u5167\u90E8\u6846\u67B6
+label=\u6A19\u7C64
+layeredpane=\u5206\u5C64\u7A97\u683C
+list=\u6E05\u55AE
+listitem=\u6E05\u55AE\u9805\u76EE
+menubar=\u529F\u80FD\u8868\u5217
+menu=\u529F\u80FD\u8868
+menuitem=\u529F\u80FD\u8868\u9805\u76EE
+optionpane=\u9078\u9805\u7A97\u683C
+pagetab=\u9801\u9762\u9801\u7C64
+pagetablist=\u9801\u9762\u9801\u7C64\u6E05\u55AE
+panel=\u9762\u677F
+passwordtext=\u5BC6\u78BC\u6587\u5B57
+popupmenu=\u5373\u73FE\u5F0F\u529F\u80FD\u8868
+progressbar=\u9032\u5EA6\u5217
+pushbutton=\u4E0B\u58D3\u6309\u9215
+radiobutton=\u55AE\u9078\u9215
+rootpane=root \u7A97\u683C
+rowheader=\u5217\u6A19\u984C
+scrollbar=\u6372\u8EF8
+scrollpane=\u6372\u52D5\u7A97\u683C
+separator=\u5206\u9694\u5143
+slider=\u6ED1\u52D5\u8EF8
+splitpane=\u5206\u5272\u7A97\u683C
+swingcomponent=Swing \u5143\u4EF6
+table=\u8868\u683C
+text=\u6587\u5B57
+tree=\u6A39\u72C0\u7D50\u69CB
+togglebutton=\u5207\u63DB\u6309\u9215
+toolbar=\u5DE5\u5177\u5217
+tooltip=\u5DE5\u5177\u63D0\u793A
+unknown=\u4E0D\u660E\u7684
+viewport=\u6AA2\u8996\u5340
+window=\u8996\u7A97
+#
+# accessible relations
+#
+labelFor=\u6A19\u793A\u5C0D\u8C61
+labeledBy=\u6A19\u793A\u8005
+memberOf=\u6240\u5C6C\u6210\u54E1
+controlledBy=\u63A7\u5236\u8005
+controllerFor=\u63A7\u5236\u5C0D\u8C61
+#
+# accessible states
+#
+active=\u4F5C\u7528\u4E2D
+armed=\u5DF2\u914D\u5099
+busy=\u5FD9\u788C\u4E2D
+checked=\u5DF2\u6838\u9078
+collapsed=\u5DF2\u6536\u7E2E
+editable=\u53EF\u7DE8\u8F2F
+expandable=\u53EF\u64F4\u5C55
+expanded=\u5DF2\u64F4\u5C55
+enabled=\u5DF2\u555F\u7528
+focusable=\u53EF\u805A\u7126
+focused=\u5DF2\u805A\u7126
+iconified=\u5DF2\u5716\u793A\u5316
+modal=\u6A21\u614B
+multiline=\u591A\u884C
+multiselectable=\u53EF\u591A\u91CD\u9078\u53D6
+opaque=\u4E0D\u900F\u660E
+pressed=\u5DF2\u6309\u4E0B
+resizable=\u53EF\u8ABF\u6574\u5927\u5C0F
+selectable=\u53EF\u9078\u53D6
+selected=\u5DF2\u9078\u53D6
+showing=\u986F\u793A
+singleline=\u55AE\u884C
+transient=\u66AB\u6642\u7684
+visible=\u53EF\u898B\u7684
+vertical=\u5782\u76F4
+horizontal=\u6C34\u5E73
+#
+# accessible actions
+#
+toggleexpand=\u5207\u63DB\u64F4\u5C55
+
+# new relations, roles and states for J2SE 1.5.0
+
+#
+# accessible relations
+#
+flowsTo=\u6D41\u52D5\u81F3
+flowsFrom=\u6D41\u52D5\u81EA
+subwindowOf=\u5B50\u8996\u7A97
+parentWindowOf=\u7236\u7CFB\u8996\u7A97
+embeds=\u5167\u5D4C
+embeddedBy=\u5167\u5D4C\u8005
+childNodeOf=\u5B50\u7BC0\u9EDE
+
+#
+# accessible roles
+#
+header=\u9801\u9996
+footer=\u9801\u5C3E
+paragraph=\u6BB5\u843D
+ruler=\u5C3A\u898F
+editbar=\u7DE8\u8F2F\u5217
+progressMonitor=\u9032\u5EA6\u76E3\u8996\u5668
+
+#
+# accessible states
+#
+managesDescendants=\u7BA1\u7406\u5B50\u4EE3
+indeterminate=\u4E0D\u78BA\u5B9A
+truncated=\u5DF2\u622A\u65B7
+
+# new for J2SE 1.6.0
+
+#
+# accessible roles
+#
+htmlcontainer=HTML \u5BB9\u5668
+
+#
+# END OF MATERIAL TO LOCALIZE
+#
diff --git a/ojluni/src/main/java/com/sun/awt/AWTUtilities.java b/ojluni/src/main/java/com/sun/awt/AWTUtilities.java
new file mode 100755
index 0000000..e6ba760
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/awt/AWTUtilities.java
@@ -0,0 +1,462 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.awt;
+
+import java.awt.*;
+
+import sun.awt.AWTAccessor;
+import sun.awt.SunToolkit;
+
+/**
+ * A collection of utility methods for AWT.
+ *
+ * The functionality provided by the static methods of the class includes:
+ * <ul>
+ * <li>Setting shapes on top-level windows
+ * <li>Setting a constant alpha value for each pixel of a top-level window
+ * <li>Making a window non-opaque, after that it paints only explicitly
+ * painted pixels on the screen, with arbitrary alpha values for every pixel.
+ * <li>Setting a 'mixing-cutout' shape for a component.
+ * </ul>
+ * <p>
+ * A "top-level window" is an instance of the {@code Window} class (or its
+ * descendant, such as {@code JFrame}).
+ * <p>
+ * Some of the mentioned features may not be supported by the native platform.
+ * To determine whether a particular feature is supported, the user must use
+ * the {@code isTranslucencySupported()} method of the class passing a desired
+ * translucency kind (a member of the {@code Translucency} enum) as an
+ * argument.
+ * <p>
+ * The per-pixel alpha feature also requires the user to create her/his
+ * windows using a translucency-capable graphics configuration.
+ * The {@code isTranslucencyCapable()} method must
+ * be used to verify whether any given GraphicsConfiguration supports
+ * the trasnlcency effects.
+ * <p>
+ * <b>WARNING</b>: This class is an implementation detail and only meant
+ * for limited use outside of the core platform. This API may change
+ * drastically between update release, and it may even be
+ * removed or be moved in some other package(s)/class(es).
+ */
+public final class AWTUtilities {
+
+ /**
+ * The AWTUtilities class should not be instantiated
+ */
+ private AWTUtilities() {
+ }
+
+ /** Kinds of translucency supported by the underlying system.
+ * @see #isTranslucencySupported
+ */
+ public static enum Translucency {
+ /**
+ * Represents support in the underlying system for windows each pixel
+ * of which is guaranteed to be either completely opaque, with
+ * an alpha value of 1.0, or completely transparent, with an alpha
+ * value of 0.0.
+ */
+ PERPIXEL_TRANSPARENT,
+
+ /**
+ * Represents support in the underlying system for windows all of
+ * the pixels of which have the same alpha value between or including
+ * 0.0 and 1.0.
+ */
+ TRANSLUCENT,
+
+ /**
+ * Represents support in the underlying system for windows that
+ * contain or might contain pixels with arbitrary alpha values
+ * between and including 0.0 and 1.0.
+ */
+ PERPIXEL_TRANSLUCENT;
+ }
+
+
+ /**
+ * Returns whether the given level of translucency is supported by
+ * the underlying system.
+ *
+ * Note that this method may sometimes return the value
+ * indicating that the particular level is supported, but
+ * the native windowing system may still not support the
+ * given level of translucency (due to the bugs in
+ * the windowing system).
+ *
+ * @param translucencyKind a kind of translucency support
+ * (either PERPIXEL_TRANSPARENT,
+ * TRANSLUCENT, or PERPIXEL_TRANSLUCENT)
+ * @return whether the given translucency kind is supported
+ */
+ public static boolean isTranslucencySupported(Translucency translucencyKind) {
+ switch (translucencyKind) {
+ case PERPIXEL_TRANSPARENT:
+ return isWindowShapingSupported();
+ case TRANSLUCENT:
+ return isWindowOpacitySupported();
+ case PERPIXEL_TRANSLUCENT:
+ return isWindowTranslucencySupported();
+ }
+ return false;
+ }
+
+
+ /**
+ * Returns whether the windowing system supports changing the opacity
+ * value of top-level windows.
+ * Note that this method may sometimes return true, but the native
+ * windowing system may still not support the concept of
+ * translucency (due to the bugs in the windowing system).
+ */
+ private static boolean isWindowOpacitySupported() {
+ Toolkit curToolkit = Toolkit.getDefaultToolkit();
+ if (!(curToolkit instanceof SunToolkit)) {
+ return false;
+ }
+ return ((SunToolkit)curToolkit).isWindowOpacitySupported();
+ }
+
+ /**
+ * Set the opacity of the window. The opacity is at the range [0..1].
+ * Note that setting the opacity level of 0 may or may not disable
+ * the mouse event handling on this window. This is
+ * a platform-dependent behavior.
+ *
+ * In order for this method to enable the translucency effect,
+ * the isTranslucencySupported() method should indicate that the
+ * TRANSLUCENT level of translucency is supported.
+ *
+ * <p>Also note that the window must not be in the full-screen mode
+ * when setting the opacity value < 1.0f. Otherwise
+ * the IllegalArgumentException is thrown.
+ *
+ * @param window the window to set the opacity level to
+ * @param opacity the opacity level to set to the window
+ * @throws NullPointerException if the window argument is null
+ * @throws IllegalArgumentException if the opacity is out of
+ * the range [0..1]
+ * @throws IllegalArgumentException if the window is in full screen mode,
+ * and the opacity is less than 1.0f
+ * @throws UnsupportedOperationException if the TRANSLUCENT translucency
+ * kind is not supported
+ */
+ public static void setWindowOpacity(Window window, float opacity) {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+
+ AWTAccessor.getWindowAccessor().setOpacity(window, opacity);
+ }
+
+ /**
+ * Get the opacity of the window. If the opacity has not
+ * yet being set, this method returns 1.0.
+ *
+ * @param window the window to get the opacity level from
+ * @throws NullPointerException if the window argument is null
+ */
+ public static float getWindowOpacity(Window window) {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+
+ return AWTAccessor.getWindowAccessor().getOpacity(window);
+ }
+
+ /**
+ * Returns whether the windowing system supports changing the shape
+ * of top-level windows.
+ * Note that this method may sometimes return true, but the native
+ * windowing system may still not support the concept of
+ * shaping (due to the bugs in the windowing system).
+ */
+ public static boolean isWindowShapingSupported() {
+ Toolkit curToolkit = Toolkit.getDefaultToolkit();
+ if (!(curToolkit instanceof SunToolkit)) {
+ return false;
+ }
+ return ((SunToolkit)curToolkit).isWindowShapingSupported();
+ }
+
+ /**
+ * Returns an object that implements the Shape interface and represents
+ * the shape previously set with the call to the setWindowShape() method.
+ * If no shape has been set yet, or the shape has been reset to null,
+ * this method returns null.
+ *
+ * @param window the window to get the shape from
+ * @return the current shape of the window
+ * @throws NullPointerException if the window argument is null
+ */
+ public static Shape getWindowShape(Window window) {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+ return AWTAccessor.getWindowAccessor().getShape(window);
+ }
+
+ /**
+ * Sets a shape for the given window.
+ * If the shape argument is null, this methods restores
+ * the default shape making the window rectangular.
+ * <p>Note that in order to set a shape, the window must be undecorated.
+ * If the window is decorated, this method ignores the {@code shape}
+ * argument and resets the shape to null.
+ * <p>Also note that the window must not be in the full-screen mode
+ * when setting a non-null shape. Otherwise the IllegalArgumentException
+ * is thrown.
+ * <p>Depending on the platform, the method may return without
+ * effecting the shape of the window if the window has a non-null warning
+ * string ({@link Window#getWarningString()}). In this case the passed
+ * shape object is ignored.
+ *
+ * @param window the window to set the shape to
+ * @param shape the shape to set to the window
+ * @throws NullPointerException if the window argument is null
+ * @throws IllegalArgumentException if the window is in full screen mode,
+ * and the shape is not null
+ * @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT
+ * translucency kind is not supported
+ */
+ public static void setWindowShape(Window window, Shape shape) {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+ AWTAccessor.getWindowAccessor().setShape(window, shape);
+ }
+
+ private static boolean isWindowTranslucencySupported() {
+ /*
+ * Per-pixel alpha is supported if all the conditions are TRUE:
+ * 1. The toolkit is a sort of SunToolkit
+ * 2. The toolkit supports translucency in general
+ * (isWindowTranslucencySupported())
+ * 3. There's at least one translucency-capable
+ * GraphicsConfiguration
+ */
+
+ Toolkit curToolkit = Toolkit.getDefaultToolkit();
+ if (!(curToolkit instanceof SunToolkit)) {
+ return false;
+ }
+
+ if (!((SunToolkit)curToolkit).isWindowTranslucencySupported()) {
+ return false;
+ }
+
+ GraphicsEnvironment env =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+
+ // If the default GC supports translucency return true.
+ // It is important to optimize the verification this way,
+ // see CR 6661196 for more details.
+ if (isTranslucencyCapable(env.getDefaultScreenDevice()
+ .getDefaultConfiguration()))
+ {
+ return true;
+ }
+
+ // ... otherwise iterate through all the GCs.
+ GraphicsDevice[] devices = env.getScreenDevices();
+
+ for (int i = 0; i < devices.length; i++) {
+ GraphicsConfiguration[] configs = devices[i].getConfigurations();
+ for (int j = 0; j < configs.length; j++) {
+ if (isTranslucencyCapable(configs[j])) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Enables the per-pixel alpha support for the given window.
+ * Once the window becomes non-opaque (the isOpaque is set to false),
+ * the drawing sub-system is starting to respect the alpha value of each
+ * separate pixel. If a pixel gets painted with alpha color component
+ * equal to zero, it becomes visually transparent, if the alpha of the
+ * pixel is equal to 255, the pixel is fully opaque. Interim values
+ * of the alpha color component make the pixel semi-transparent (i.e.
+ * translucent).
+ * <p>Note that in order for the window to support the per-pixel alpha
+ * mode, the window must be created using the GraphicsConfiguration
+ * for which the {@link #isTranslucencyCapable}
+ * method returns true.
+ * <p>Also note that some native systems enable the per-pixel translucency
+ * mode for any window created using the translucency-compatible
+ * graphics configuration. However, it is highly recommended to always
+ * invoke the setWindowOpaque() method for these windows, at least for
+ * the sake of cross-platform compatibility reasons.
+ * <p>Also note that the window must not be in the full-screen mode
+ * when making it non-opaque. Otherwise the IllegalArgumentException
+ * is thrown.
+ * <p>If the window is a {@code Frame} or a {@code Dialog}, the window must
+ * be undecorated prior to enabling the per-pixel translucency effect (see
+ * {@link Frame#setUndecorated()} and/or {@link Dialog#setUndecorated()}).
+ * If the window becomes decorated through a subsequent call to the
+ * corresponding {@code setUndecorated()} method, the per-pixel
+ * translucency effect will be disabled and the opaque property reset to
+ * {@code true}.
+ * <p>Depending on the platform, the method may return without
+ * effecting the opaque property of the window if the window has a non-null
+ * warning string ({@link Window#getWarningString()}). In this case
+ * the passed 'isOpaque' value is ignored.
+ *
+ * @param window the window to set the shape to
+ * @param isOpaque whether the window must be opaque (true),
+ * or translucent (false)
+ * @throws NullPointerException if the window argument is null
+ * @throws IllegalArgumentException if the window uses
+ * a GraphicsConfiguration for which the
+ * {@code isTranslucencyCapable()}
+ * method returns false
+ * @throws IllegalArgumentException if the window is in full screen mode,
+ * and the isOpaque is false
+ * @throws IllegalArgumentException if the window is decorated and the
+ * isOpaque argument is {@code false}.
+ * @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT
+ * translucency kind is not supported
+ */
+ public static void setWindowOpaque(Window window, boolean isOpaque) {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+ if (!isOpaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) {
+ throw new UnsupportedOperationException(
+ "The PERPIXEL_TRANSLUCENT translucency kind is not supported");
+ }
+ AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque);
+ }
+
+ /**
+ * Returns whether the window is opaque or translucent.
+ *
+ * @param window the window to set the shape to
+ * @return whether the window is currently opaque (true)
+ * or translucent (false)
+ * @throws NullPointerException if the window argument is null
+ */
+ public static boolean isWindowOpaque(Window window) {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+
+ return window.isOpaque();
+ }
+
+ /**
+ * Verifies whether a given GraphicsConfiguration supports
+ * the PERPIXEL_TRANSLUCENT kind of translucency.
+ * All windows that are intended to be used with the {@link #setWindowOpaque}
+ * method must be created using a GraphicsConfiguration for which this method
+ * returns true.
+ * <p>Note that some native systems enable the per-pixel translucency
+ * mode for any window created using a translucency-capable
+ * graphics configuration. However, it is highly recommended to always
+ * invoke the setWindowOpaque() method for these windows, at least
+ * for the sake of cross-platform compatibility reasons.
+ *
+ * @param gc GraphicsConfiguration
+ * @throws NullPointerException if the gc argument is null
+ * @return whether the given GraphicsConfiguration supports
+ * the translucency effects.
+ */
+ public static boolean isTranslucencyCapable(GraphicsConfiguration gc) {
+ if (gc == null) {
+ throw new NullPointerException("The gc argument should not be null");
+ }
+ /*
+ return gc.isTranslucencyCapable();
+ */
+ Toolkit curToolkit = Toolkit.getDefaultToolkit();
+ if (!(curToolkit instanceof SunToolkit)) {
+ return false;
+ }
+ return ((SunToolkit)curToolkit).isTranslucencyCapable(gc);
+ }
+
+ /**
+ * Sets a 'mixing-cutout' shape for the given component.
+ *
+ * By default a lightweight component is treated as an opaque rectangle for
+ * the purposes of the Heavyweight/Lightweight Components Mixing feature.
+ * This method enables developers to set an arbitrary shape to be cut out
+ * from heavyweight components positioned underneath the lightweight
+ * component in the z-order.
+ * <p>
+ * The {@code shape} argument may have the following values:
+ * <ul>
+ * <li>{@code null} - reverts the default cutout shape (the rectangle equal
+ * to the component's {@code getBounds()})
+ * <li><i>empty-shape</i> - does not cut out anything from heavyweight
+ * components. This makes the given lightweight component effectively
+ * transparent. Note that descendants of the lightweight component still
+ * affect the shapes of heavyweight components. An example of an
+ * <i>empty-shape</i> is {@code new Rectangle()}.
+ * <li><i>non-empty-shape</i> - the given shape will be cut out from
+ * heavyweight components.
+ * </ul>
+ * <p>
+ * The most common example when the 'mixing-cutout' shape is needed is a
+ * glass pane component. The {@link JRootPane#setGlassPane()} method
+ * automatically sets the <i>empty-shape</i> as the 'mixing-cutout' shape
+ * for the given glass pane component. If a developer needs some other
+ * 'mixing-cutout' shape for the glass pane (which is rare), this must be
+ * changed manually after installing the glass pane to the root pane.
+ * <p>
+ * Note that the 'mixing-cutout' shape neither affects painting, nor the
+ * mouse events handling for the given component. It is used exclusively
+ * for the purposes of the Heavyweight/Lightweight Components Mixing
+ * feature.
+ *
+ * @param component the component that needs non-default
+ * 'mixing-cutout' shape
+ * @param shape the new 'mixing-cutout' shape
+ * @throws NullPointerException if the component argument is {@code null}
+ */
+ public static void setComponentMixingCutoutShape(Component component,
+ Shape shape)
+ {
+ if (component == null) {
+ throw new NullPointerException(
+ "The component argument should not be null.");
+ }
+
+ AWTAccessor.getComponentAccessor().setMixingCutoutShape(component,
+ shape);
+ }
+}
+
diff --git a/ojluni/src/main/java/com/sun/awt/SecurityWarning.java b/ojluni/src/main/java/com/sun/awt/SecurityWarning.java
new file mode 100755
index 0000000..dd87ec1
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/awt/SecurityWarning.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.awt;
+
+import java.awt.*;
+import java.awt.geom.*;
+
+import sun.awt.AWTAccessor;
+
+
+/**
+ * Security Warning control interface.
+ *
+ * This class provides a couple of methods that help a developer relocate
+ * the AWT security warning to an appropriate position relative to the current
+ * window size. A "top-level window" is an instance of the {@code Window}
+ * class (or its descendant, such as {@code JFrame}). The security warning
+ * is applied to all windows created by an untrusted code. All such windows
+ * have a non-null "warning string" (see {@link Window#getWarningString()}).
+ * <p>
+ * <b>WARNING</b>: This class is an implementation detail and only meant
+ * for limited use outside of the core platform. This API may change
+ * drastically between update release, and it may even be
+ * removed or be moved to some other packages or classes.
+ */
+public final class SecurityWarning {
+
+ /**
+ * The SecurityWarning class should not be instantiated
+ */
+ private SecurityWarning() {
+ }
+
+ /**
+ * Gets the size of the security warning.
+ *
+ * The returned value is not valid until the peer has been created. Before
+ * invoking this method a developer must call the {@link Window#pack()},
+ * {@link Window#setVisible()}, or some other method that creates the peer.
+ *
+ * @param window the window to get the security warning size for
+ *
+ * @throws NullPointerException if the window argument is null
+ * @throws IllegalArgumentException if the window is trusted (i.e.
+ * the {@code getWarningString()} returns null)
+ */
+ public static Dimension getSize(Window window) {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+ if (window.getWarningString() == null) {
+ throw new IllegalArgumentException(
+ "The window must have a non-null warning string.");
+ }
+ // We don't check for a non-null peer since it may be destroyed
+ // after assigning a valid value to the security warning size.
+
+ return AWTAccessor.getWindowAccessor().getSecurityWarningSize(window);
+ }
+
+ /**
+ * Sets the position of the security warning.
+ * <p>
+ * The {@code alignmentX} and {@code alignmentY} arguments specify the
+ * origin of the coordinate system used to calculate the position of the
+ * security warning. The values must be in the range [0.0f...1.0f]. The
+ * {@code 0.0f} value represents the left (top) edge of the rectangular
+ * bounds of the window. The {@code 1.0f} value represents the right
+ * (bottom) edge of the bounds. Whenever the size of the window changes,
+ * the origin of the coordinate system gets relocated accordingly. For
+ * convenience a developer may use the {@code Component.*_ALIGNMENT}
+ * constants to pass predefined values for these arguments.
+ * <p>
+ * The {@code point} argument specifies the location of the security
+ * warning in the coordinate system described above. If both {@code x} and
+ * {@code y} coordinates of the point are equal to zero, the warning will
+ * be located right in the origin of the coordinate system. On the other
+ * hand, if both {@code alignmentX} and {@code alignmentY} are equal to
+ * zero (i.e. the origin of the coordinate system is placed at the top-left
+ * corner of the window), then the {@code point} argument represents the
+ * absolute location of the security warning relative to the location of
+ * the window. The "absolute" in this case means that the position of the
+ * security warning is not effected by resizing of the window.
+ * <p>
+ * Note that the security warning managment code guarantees that:
+ * <ul>
+ * <li>The security warning cannot be located farther than two pixels from
+ * the rectangular bounds of the window (see {@link Window#getBounds}), and
+ * <li>The security warning is always visible on the screen.
+ * </ul>
+ * If either of the conditions is violated, the calculated position of the
+ * security warning is adjusted by the system to meet both these
+ * conditions.
+ * <p>
+ * The default position of the security warning is in the upper-right
+ * corner of the window, two pixels to the right from the right edge. This
+ * corresponds to the following arguments passed to this method:
+ * <ul>
+ * <li>{@code alignmentX = Component.RIGHT_ALIGNMENT}
+ * <li>{@code alignmentY = Component.TOP_ALIGNMENT}
+ * <li>{@code point = (2, 0)}
+ * </ul>
+ *
+ * @param window the window to set the position of the security warning for
+ * @param alignmentX the horizontal origin of the coordinate system
+ * @param alignmentY the vertical origin of the coordinate system
+ * @param point the position of the security warning in the specified
+ * coordinate system
+ *
+ * @throws NullPointerException if the window argument is null
+ * @throws NullPointerException if the point argument is null
+ * @throws IllegalArgumentException if the window is trusted (i.e.
+ * the {@code getWarningString()} returns null
+ * @throws IllegalArgumentException if the alignmentX or alignmentY
+ * arguments are not within the range [0.0f ... 1.0f]
+ */
+ public static void setPosition(Window window, Point2D point,
+ float alignmentX, float alignmentY)
+ {
+ if (window == null) {
+ throw new NullPointerException(
+ "The window argument should not be null.");
+ }
+ if (window.getWarningString() == null) {
+ throw new IllegalArgumentException(
+ "The window must have a non-null warning string.");
+ }
+ if (point == null) {
+ throw new NullPointerException(
+ "The point argument must not be null");
+ }
+ if (alignmentX < 0.0f || alignmentX > 1.0f) {
+ throw new IllegalArgumentException(
+ "alignmentX must be in the range [0.0f ... 1.0f].");
+ }
+ if (alignmentY < 0.0f || alignmentY > 1.0f) {
+ throw new IllegalArgumentException(
+ "alignmentY must be in the range [0.0f ... 1.0f].");
+ }
+
+ AWTAccessor.getWindowAccessor().setSecurityWarningPosition(window,
+ point, alignmentX, alignmentY);
+ }
+}
+
diff --git a/ojluni/src/main/java/com/sun/beans/TypeResolver.java b/ojluni/src/main/java/com/sun/beans/TypeResolver.java
new file mode 100755
index 0000000..e4cb0f3
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/TypeResolver.java
@@ -0,0 +1,378 @@
+/*
+ * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.util.HashMap;
+import java.util.Map;
+
+import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl;
+import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
+
+/**
+ * This is utility class to resolve types.
+ *
+ * @since 1.7
+ *
+ * @author Eamonn McManus
+ * @author Sergey Malenkov
+ */
+public final class TypeResolver {
+
+ private static final WeakCache<Type, Map<Type, Type>> CACHE = new WeakCache<>();
+
+ /**
+ * Replaces the given {@code type} in an inherited method
+ * with the actual type it has in the given {@code inClass}.
+ *
+ * <p>Although type parameters are not inherited by subclasses in the Java
+ * language, they <em>are</em> effectively inherited when using reflection.
+ * For example, if you declare an interface like this...</p>
+ *
+ * <pre>
+ * public interface StringToIntMap extends Map<String,Integer> {}
+ * </pre>
+ *
+ * <p>...then StringToIntMap.class.getMethods() will show that it has methods
+ * like put(K,V) even though StringToIntMap has no type parameters. The K
+ * and V variables are the ones declared by Map, so
+ * {@link TypeVariable#getGenericDeclaration()} will return Map.class.</p>
+ *
+ * <p>The purpose of this method is to take a Type from a possibly-inherited
+ * method and replace it with the correct Type for the inheriting class.
+ * So given parameters of K and StringToIntMap.class in the above example,
+ * this method will return String.</p>
+ *
+ * @param inClass the base class used to resolve
+ * @param type the type to resolve
+ * @return a resolved type
+ *
+ * @see #getActualType(Class)
+ * @see #resolve(Type,Type)
+ */
+ public static Type resolveInClass(Class<?> inClass, Type type) {
+ return resolve(getActualType(inClass), type);
+ }
+
+ /**
+ * Replaces all {@code types} in the given array
+ * with the actual types they have in the given {@code inClass}.
+ *
+ * @param inClass the base class used to resolve
+ * @param types the array of types to resolve
+ * @return an array of resolved types
+ *
+ * @see #getActualType(Class)
+ * @see #resolve(Type,Type[])
+ */
+ public static Type[] resolveInClass(Class<?> inClass, Type[] types) {
+ return resolve(getActualType(inClass), types);
+ }
+
+ /**
+ * Replaces type variables of the given {@code formal} type
+ * with the types they stand for in the given {@code actual} type.
+ *
+ * <p>A ParameterizedType is a class with type parameters, and the values
+ * of those parameters. For example, Map<K,V> is a generic class, and
+ * a corresponding ParameterizedType might look like
+ * Map<K=String,V=Integer>. Given such a ParameterizedType, this method
+ * will replace K with String, or List<K> with List<String;, or
+ * List<? super K> with List<? super String>.</p>
+ *
+ * <p>The {@code actual} argument to this method can also be a Class.
+ * In this case, either it is equivalent to a ParameterizedType with
+ * no parameters (for example, Integer.class), or it is equivalent to
+ * a "raw" ParameterizedType (for example, Map.class). In the latter
+ * case, every type parameter declared or inherited by the class is replaced
+ * by its "erasure". For a type parameter declared as <T>, the erasure
+ * is Object. For a type parameter declared as <T extends Number>,
+ * the erasure is Number.</p>
+ *
+ * <p>Although type parameters are not inherited by subclasses in the Java
+ * language, they <em>are</em> effectively inherited when using reflection.
+ * For example, if you declare an interface like this...</p>
+ *
+ * <pre>
+ * public interface StringToIntMap extends Map<String,Integer> {}
+ * </pre>
+ *
+ * <p>...then StringToIntMap.class.getMethods() will show that it has methods
+ * like put(K,V) even though StringToIntMap has no type parameters. The K
+ * and V variables are the ones declared by Map, so
+ * {@link TypeVariable#getGenericDeclaration()} will return {@link Map Map.class}.</p>
+ *
+ * <p>For this reason, this method replaces inherited type parameters too.
+ * Therefore if this method is called with {@code actual} being
+ * StringToIntMap.class and {@code formal} being the K from Map,
+ * it will return {@link String String.class}.</p>
+ *
+ * <p>In the case where {@code actual} is a "raw" ParameterizedType, the
+ * inherited type parameters will also be replaced by their erasures.
+ * The erasure of a Class is the Class itself, so a "raw" subinterface of
+ * StringToIntMap will still show the K from Map as String.class. But
+ * in a case like this...
+ *
+ * <pre>
+ * public interface StringToIntListMap extends Map<String,List<Integer>> {}
+ * public interface RawStringToIntListMap extends StringToIntListMap {}
+ * </pre>
+ *
+ * <p>...the V inherited from Map will show up as List<Integer> in
+ * StringToIntListMap, but as plain List in RawStringToIntListMap.</p>
+ *
+ * @param actual the type that supplies bindings for type variables
+ * @param formal the type where occurrences of the variables
+ * in {@code actual} will be replaced by the corresponding bound values
+ * @return a resolved type
+ */
+ public static Type resolve(Type actual, Type formal) {
+ if (formal instanceof Class) {
+ return formal;
+ }
+ if (formal instanceof GenericArrayType) {
+ Type comp = ((GenericArrayType) formal).getGenericComponentType();
+ comp = resolve(actual, comp);
+ return (comp instanceof Class)
+ ? Array.newInstance((Class<?>) comp, 0).getClass()
+ : GenericArrayTypeImpl.make(comp);
+ }
+ if (formal instanceof ParameterizedType) {
+ ParameterizedType fpt = (ParameterizedType) formal;
+ Type[] actuals = resolve(actual, fpt.getActualTypeArguments());
+ return ParameterizedTypeImpl.make(
+ (Class<?>) fpt.getRawType(), actuals, fpt.getOwnerType());
+ }
+ if (formal instanceof WildcardType) {
+ WildcardType fwt = (WildcardType) formal;
+ Type[] upper = resolve(actual, fwt.getUpperBounds());
+ Type[] lower = resolve(actual, fwt.getLowerBounds());
+ return new WildcardTypeImpl(upper, lower);
+ }
+ if (formal instanceof TypeVariable) {
+ Map<Type, Type> map;
+ synchronized (CACHE) {
+ map = CACHE.get(actual);
+ if (map == null) {
+ map = new HashMap<>();
+ prepare(map, actual);
+ CACHE.put(actual, map);
+ }
+ }
+ Type result = map.get(formal);
+ if (result == null || result.equals(formal)) {
+ return formal;
+ }
+ result = fixGenericArray(result);
+ // A variable can be bound to another variable that is itself bound
+ // to something. For example, given:
+ // class Super<T> {...}
+ // class Mid<X> extends Super<T> {...}
+ // class Sub extends Mid<String>
+ // the variable T is bound to X, which is in turn bound to String.
+ // So if we have to resolve T, we need the tail recursion here.
+ return resolve(actual, result);
+ }
+ throw new IllegalArgumentException("Bad Type kind: " + formal.getClass());
+ }
+
+ /**
+ * Replaces type variables of all formal types in the given array
+ * with the types they stand for in the given {@code actual} type.
+ *
+ * @param actual the type that supplies bindings for type variables
+ * @param formals the array of types to resolve
+ * @return an array of resolved types
+ */
+ public static Type[] resolve(Type actual, Type[] formals) {
+ int length = formals.length;
+ Type[] actuals = new Type[length];
+ for (int i = 0; i < length; i++) {
+ actuals[i] = resolve(actual, formals[i]);
+ }
+ return actuals;
+ }
+
+ /**
+ * Converts the given {@code type} to the corresponding class.
+ * This method implements the concept of type erasure,
+ * that is described in section 4.6 of
+ * <cite>The Java™ Language Specification</cite>.
+ *
+ * @param type the array of types to convert
+ * @return a corresponding class
+ */
+ public static Class<?> erase(Type type) {
+ if (type instanceof Class) {
+ return (Class<?>) type;
+ }
+ if (type instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) type;
+ return (Class<?>) pt.getRawType();
+ }
+ if (type instanceof TypeVariable) {
+ TypeVariable tv = (TypeVariable)type;
+ Type[] bounds = tv.getBounds();
+ return (0 < bounds.length)
+ ? erase(bounds[0])
+ : Object.class;
+ }
+ if (type instanceof WildcardType) {
+ WildcardType wt = (WildcardType)type;
+ Type[] bounds = wt.getUpperBounds();
+ return (0 < bounds.length)
+ ? erase(bounds[0])
+ : Object.class;
+ }
+ if (type instanceof GenericArrayType) {
+ GenericArrayType gat = (GenericArrayType)type;
+ return Array.newInstance(erase(gat.getGenericComponentType()), 0).getClass();
+ }
+ throw new IllegalArgumentException("Unknown Type kind: " + type.getClass());
+ }
+
+ /**
+ * Converts all {@code types} in the given array
+ * to the corresponding classes.
+ *
+ * @param types the array of types to convert
+ * @return an array of corresponding classes
+ *
+ * @see #erase(Type)
+ */
+ public static Class[] erase(Type[] types) {
+ int length = types.length;
+ Class[] classes = new Class[length];
+ for (int i = 0; i < length; i++) {
+ classes[i] = TypeResolver.erase(types[i]);
+ }
+ return classes;
+ }
+
+ /**
+ * Fills the map from type parameters
+ * to types as seen by the given {@code type}.
+ * The method is recursive because the {@code type}
+ * inherits mappings from its parent classes and interfaces.
+ * The {@code type} can be either a {@link Class Class}
+ * or a {@link ParameterizedType ParameterizedType}.
+ * If it is a {@link Class Class}, it is either equivalent
+ * to a {@link ParameterizedType ParameterizedType} with no parameters,
+ * or it represents the erasure of a {@link ParameterizedType ParameterizedType}.
+ *
+ * @param map the mappings of all type variables
+ * @param type the next type in the hierarchy
+ */
+ private static void prepare(Map<Type, Type> map, Type type) {
+ Class<?> raw = (Class<?>)((type instanceof Class<?>)
+ ? type
+ : ((ParameterizedType)type).getRawType());
+
+ TypeVariable<?>[] formals = raw.getTypeParameters();
+
+ Type[] actuals = (type instanceof Class<?>)
+ ? formals
+ : ((ParameterizedType)type).getActualTypeArguments();
+
+ assert formals.length == actuals.length;
+ for (int i = 0; i < formals.length; i++) {
+ map.put(formals[i], actuals[i]);
+ }
+ Type gSuperclass = raw.getGenericSuperclass();
+ if (gSuperclass != null) {
+ prepare(map, gSuperclass);
+ }
+ for (Type gInterface : raw.getGenericInterfaces()) {
+ prepare(map, gInterface);
+ }
+ // If type is the raw version of a parameterized class, we type-erase
+ // all of its type variables, including inherited ones.
+ if (type instanceof Class<?> && formals.length > 0) {
+ for (Map.Entry<Type, Type> entry : map.entrySet()) {
+ entry.setValue(erase(entry.getValue()));
+ }
+ }
+ }
+
+ /**
+ * Replaces a {@link GenericArrayType GenericArrayType}
+ * with plain array class where it is possible.
+ * Bug <a href="http://bugs.sun.com/view_bug.do?bug_id=5041784">5041784</a>
+ * is that arrays of non-generic type sometimes show up
+ * as {@link GenericArrayType GenericArrayType} when using reflection.
+ * For example, a {@code String[]} might show up
+ * as a {@link GenericArrayType GenericArrayType}
+ * where {@link GenericArrayType#getGenericComponentType getGenericComponentType}
+ * is {@code String.class}. This violates the specification,
+ * which says that {@link GenericArrayType GenericArrayType}
+ * is used when the component type is a type variable or parameterized type.
+ * We fit the specification here.
+ *
+ * @param type the type to fix
+ * @return a corresponding type for the generic array type,
+ * or the same type as {@code type}
+ */
+ private static Type fixGenericArray(Type type) {
+ if (type instanceof GenericArrayType) {
+ Type comp = ((GenericArrayType)type).getGenericComponentType();
+ comp = fixGenericArray(comp);
+ if (comp instanceof Class) {
+ return Array.newInstance((Class<?>)comp, 0).getClass();
+ }
+ }
+ return type;
+ }
+
+ /**
+ * Replaces a {@link Class Class} with type parameters
+ * with a {@link ParameterizedType ParameterizedType}
+ * where every parameter is bound to itself.
+ * When calling {@link #resolveInClass} in the context of {@code inClass},
+ * we can't just pass {@code inClass} as the {@code actual} parameter,
+ * because if {@code inClass} has type parameters
+ * that would be interpreted as accessing the raw type,
+ * so we would get unwanted erasure.
+ * This is why we bind each parameter to itself.
+ * If {@code inClass} does have type parameters and has methods
+ * where those parameters appear in the return type or argument types,
+ * we will correctly leave those types alone.
+ *
+ * @param inClass the base class used to resolve
+ * @return a parameterized type for the class,
+ * or the same class as {@code inClass}
+ */
+ private static Type getActualType(Class<?> inClass) {
+ Type[] params = inClass.getTypeParameters();
+ return (params.length == 0)
+ ? inClass
+ : ParameterizedTypeImpl.make(
+ inClass, params, inClass.getEnclosingClass());
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/WeakCache.java b/ojluni/src/main/java/com/sun/beans/WeakCache.java
new file mode 100755
index 0000000..dbc22ea
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/WeakCache.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans;
+
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * A hashtable-based cache with weak keys and weak values.
+ * An entry in the map will be automatically removed
+ * when its key is no longer in the ordinary use.
+ * A value will be automatically removed as well
+ * when it is no longer in the ordinary use.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class WeakCache<K, V> {
+ private final Map<K, Reference<V>> map = new WeakHashMap<K, Reference<V>>();
+
+ /**
+ * Returns a value to which the specified {@code key} is mapped,
+ * or {@code null} if this map contains no mapping for the {@code key}.
+ *
+ * @param key the key whose associated value is returned
+ * @return a value to which the specified {@code key} is mapped
+ */
+ public V get(K key) {
+ Reference<V> reference = this.map.get(key);
+ if (reference == null) {
+ return null;
+ }
+ V value = reference.get();
+ if (value == null) {
+ this.map.remove(key);
+ }
+ return value;
+ }
+
+ /**
+ * Associates the specified {@code value} with the specified {@code key}.
+ * Removes the mapping for the specified {@code key} from this cache
+ * if it is present and the specified {@code value} is {@code null}.
+ * If the cache previously contained a mapping for the {@code key},
+ * the old value is replaced by the specified {@code value}.
+ *
+ * @param key the key with which the specified value is associated
+ * @param value the value to be associated with the specified key
+ */
+ public void put(K key, V value) {
+ if (value != null) {
+ this.map.put(key, new WeakReference<V>(value));
+ }
+ else {
+ this.map.remove(key);
+ }
+ }
+
+ /**
+ * Removes all of the mappings from this cache.
+ */
+ public void clear() {
+ this.map.clear();
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/WildcardTypeImpl.java b/ojluni/src/main/java/com/sun/beans/WildcardTypeImpl.java
new file mode 100755
index 0000000..28e316c
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/WildcardTypeImpl.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans;
+
+import java.lang.reflect.Type;
+import java.lang.reflect.WildcardType;
+import java.util.Arrays;
+
+/**
+ * This class implements {@link WildcardType WildcardType} compatibly with the JDK's
+ * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
+ * Unfortunately we can't use the JDK's
+ * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl} here as we do for
+ * {@link sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl ParameterizedTypeImpl} and
+ * {@link sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl GenericArrayTypeImpl},
+ * because {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}'s
+ * constructor takes parameters representing intermediate structures obtained during class-file parsing.
+ * We could reconstruct versions of those structures but it would be more trouble than it's worth.
+ *
+ * @since 1.7
+ *
+ * @author Eamonn McManus
+ * @author Sergey Malenkov
+ */
+final class WildcardTypeImpl implements WildcardType {
+ private final Type[] upperBounds;
+ private final Type[] lowerBounds;
+
+ /**
+ * Creates a wildcard type with the requested bounds.
+ * Note that the array arguments are not cloned
+ * because instances of this class are never constructed
+ * from outside the containing package.
+ *
+ * @param upperBounds the array of types representing
+ * the upper bound(s) of this type variable
+ * @param lowerBounds the array of types representing
+ * the lower bound(s) of this type variable
+ */
+ WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
+ this.upperBounds = upperBounds;
+ this.lowerBounds = lowerBounds;
+ }
+
+ /**
+ * Returns an array of {@link Type Type} objects
+ * representing the upper bound(s) of this type variable.
+ * Note that if no upper bound is explicitly declared,
+ * the upper bound is {@link Object Object}.
+ *
+ * @return an array of types representing
+ * the upper bound(s) of this type variable
+ */
+ public Type[] getUpperBounds() {
+ return this.upperBounds.clone();
+ }
+
+ /**
+ * Returns an array of {@link Type Type} objects
+ * representing the lower bound(s) of this type variable.
+ * Note that if no lower bound is explicitly declared,
+ * the lower bound is the type of {@code null}.
+ * In this case, a zero length array is returned.
+ *
+ * @return an array of types representing
+ * the lower bound(s) of this type variable
+ */
+ public Type[] getLowerBounds() {
+ return this.lowerBounds.clone();
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ * It is implemented compatibly with the JDK's
+ * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
+ *
+ * @param object the reference object with which to compare
+ * @return {@code true} if this object is the same as the object argument;
+ * {@code false} otherwise
+ * @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#equals
+ */
+ @Override
+ public boolean equals(Object object) {
+ if (object instanceof WildcardType) {
+ WildcardType type = (WildcardType) object;
+ return Arrays.equals(this.upperBounds, type.getUpperBounds())
+ && Arrays.equals(this.lowerBounds, type.getLowerBounds());
+ }
+ return false;
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ * It is implemented compatibly with the JDK's
+ * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
+ *
+ * @return a hash code value for this object
+ * @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#hashCode
+ */
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(this.upperBounds)
+ ^ Arrays.hashCode(this.lowerBounds);
+ }
+
+ /**
+ * Returns a string representation of the object.
+ * It is implemented compatibly with the JDK's
+ * {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
+ *
+ * @return a string representation of the object
+ * @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#toString
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb;
+ Type[] bounds;
+ if (this.lowerBounds.length == 0) {
+ if (this.upperBounds.length == 0 || Object.class == this.upperBounds[0]) {
+ return "?";
+ }
+ bounds = this.upperBounds;
+ sb = new StringBuilder("? extends ");
+ }
+ else {
+ bounds = this.lowerBounds;
+ sb = new StringBuilder("? super ");
+ }
+ for (int i = 0; i < bounds.length; i++) {
+ if (i > 0) {
+ sb.append(" & ");
+ }
+ sb.append((bounds[i] instanceof Class)
+ ? ((Class) bounds[i]).getName()
+ : bounds[i].toString());
+ }
+ return sb.toString();
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/AccessorElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/AccessorElementHandler.java
new file mode 100755
index 0000000..93511bc
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/AccessorElementHandler.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This is base class that simplifies access to entities (fields or properties).
+ * The {@code name} attribute specifies the name of the accessible entity.
+ * The element defines getter if it contains no argument
+ * or setter if it contains one argument.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+abstract class AccessorElementHandler extends ElementHandler {
+ private String name;
+ private ValueObject value;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>name
+ * <dd>the name of the accessible entity
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("name")) { // NON-NLS: the attribute name
+ this.name = value;
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Adds the argument that is used to set the value of this element.
+ *
+ * @param argument the value of the element that contained in this one
+ */
+ @Override
+ protected final void addArgument(Object argument) {
+ if (this.value != null) {
+ throw new IllegalStateException("Could not add argument to evaluated element");
+ }
+ setValue(this.name, argument);
+ this.value = ValueObjectImpl.VOID;
+ }
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ @Override
+ protected final ValueObject getValueObject() {
+ if (this.value == null) {
+ this.value = ValueObjectImpl.create(getValue(this.name));
+ }
+ return this.value;
+ }
+
+ /**
+ * Returns the value of the entity with specified {@code name}.
+ *
+ * @param name the name of the accessible entity
+ * @return the value of the specified entity
+ */
+ protected abstract Object getValue(String name);
+
+ /**
+ * Sets the new value for the entity with specified {@code name}.
+ *
+ * @param name the name of the accessible entity
+ * @param value the new value for the specified entity
+ */
+ protected abstract void setValue(String name, Object value);
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ArrayElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/ArrayElementHandler.java
new file mode 100755
index 0000000..5406891
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ArrayElementHandler.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import java.lang.reflect.Array;
+
+/**
+ * This class is intended to handle <array> element,
+ * that is used to array creation.
+ * The {@code length} attribute specifies the length of the array.
+ * The {@code class} attribute specifies the elements type.
+ * The {@link Object} type is used by default.
+ * For example:<pre>
+ * <array length="10"/></pre>
+ * is equivalent to {@code new Component[10]} in Java code.
+ * The {@code set} and {@code get} methods,
+ * as defined in the {@link java.util.List} interface,
+ * can be used as if they could be applied to array instances.
+ * The {@code index} attribute can thus be used with arrays.
+ * For example:<pre>
+ * <array length="3" class="java.lang.String">
+ * <void index="1">
+ * <string>Hello, world</string>
+ * </void>
+ * </array></pre>
+ * is equivalent to the following Java code:<pre>
+ * String[] s = new String[3];
+ * s[1] = "Hello, world";</pre>
+ * It is possible to omit the {@code length} attribute and
+ * specify the values directly, without using {@code void} tags.
+ * The length of the array is equal to the number of values specified.
+ * For example:<pre>
+ * <array id="array" class="int">
+ * <int>123</int>
+ * <int>456</int>
+ * </array></pre>
+ * is equivalent to {@code int[] array = {123, 456}} in Java code.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>length
+ * <dd>the array length
+ * <dt>class
+ * <dd>the type of object for instantiation
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ArrayElementHandler extends NewElementHandler {
+ private Integer length;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>length
+ * <dd>the array length
+ * <dt>class
+ * <dd>the type of object for instantiation
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("length")) { // NON-NLS: the attribute name
+ this.length = Integer.valueOf(value);
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Calculates the value of this element
+ * if the lentgh attribute is set.
+ */
+ @Override
+ public void startElement() {
+ if (this.length != null) {
+ getValueObject();
+ }
+ }
+
+ /**
+ * Creates an instance of the array.
+ *
+ * @param type the base class
+ * @param args the array of arguments
+ * @return the value of this element
+ */
+ @Override
+ protected ValueObject getValueObject(Class<?> type, Object[] args) {
+ if (type == null) {
+ type = Object.class;
+ }
+ if (this.length != null) {
+ return ValueObjectImpl.create(Array.newInstance(type, this.length));
+ }
+ Object array = Array.newInstance(type, args.length);
+ for (int i = 0; i < args.length; i++) {
+ Array.set(array, i, args[i]);
+ }
+ return ValueObjectImpl.create(array);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/BooleanElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/BooleanElementHandler.java
new file mode 100755
index 0000000..e00af8c
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/BooleanElementHandler.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <boolean> element.
+ * This element specifies {@code boolean} values.
+ * The class {@link Boolean} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <boolean>true</boolean></pre>
+ * is shortcut to<pre>
+ * <method name="valueOf" class="java.lang.Boolean">
+ * <string>true</string>
+ * </method></pre>
+ * which is equivalent to {@code Boolean.valueOf("true")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class BooleanElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code boolean} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code boolean} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ if (Boolean.TRUE.toString().equalsIgnoreCase(argument)) {
+ return Boolean.TRUE;
+ }
+ if (Boolean.FALSE.toString().equalsIgnoreCase(argument)) {
+ return Boolean.FALSE;
+ }
+ throw new IllegalArgumentException("Unsupported boolean argument: " + argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ByteElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/ByteElementHandler.java
new file mode 100755
index 0000000..a534759
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ByteElementHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <byte> element.
+ * This element specifies {@code byte} values.
+ * The class {@link Byte} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <byte>127</byte></pre>
+ * is shortcut to<pre>
+ * <method name="decode" class="java.lang.Byte">
+ * <string>127</string>
+ * </method></pre>
+ * which is equivalent to {@code Byte.decode("127")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ByteElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code byte} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code byte} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return Byte.decode(argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/CharElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/CharElementHandler.java
new file mode 100755
index 0000000..6e257d6
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/CharElementHandler.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <char> element.
+ * This element specifies {@code char} values.
+ * The class {@link Character} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <char>X</char></pre>
+ * which is equivalent to {@code Character.valueOf('X')} in Java code.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>code
+ * <dd>this attribute specifies character code
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ * The {@code code} attribute can be used for characters
+ * that are illegal in XML document, for example:<pre>
+ * <char code="0"/></pre>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class CharElementHandler extends StringElementHandler {
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>code
+ * <dd>this attribute specifies character code
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("code")) { // NON-NLS: the attribute name
+ int code = Integer.decode(value);
+ for (char ch : Character.toChars(code)) {
+ addCharacter(ch);
+ }
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Creates {@code char} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code char} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ if (argument.length() != 1) {
+ throw new IllegalArgumentException("Wrong characters count");
+ }
+ return Character.valueOf(argument.charAt(0));
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ClassElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/ClassElementHandler.java
new file mode 100755
index 0000000..9decb9f
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ClassElementHandler.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <class> element.
+ * This element specifies {@link Class} values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <class>java.lang.Class</class></pre>
+ * is shortcut to<pre>
+ * <method name="forName" class="java.lang.Class">
+ * <string>java.lang.Class</string>
+ * </method></pre>
+ * which is equivalent to {@code Class.forName("java.lang.Class")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ClassElementHandler extends StringElementHandler {
+
+ /**
+ * Creates class by the name from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code Class} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return getOwner().findClass(argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/DocumentHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/DocumentHandler.java
new file mode 100755
index 0000000..4bbb8f4
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/DocumentHandler.java
@@ -0,0 +1,402 @@
+/*
+ * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import com.sun.beans.finder.ClassFinder;
+
+import java.beans.ExceptionListener;
+
+import java.io.IOException;
+
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import sun.misc.SharedSecrets;
+
+/**
+ * The main class to parse JavaBeans XML archive.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ *
+ * @see ElementHandler
+ */
+public final class DocumentHandler extends DefaultHandler {
+ private final AccessControlContext acc = AccessController.getContext();
+ private final Map<String, Class<? extends ElementHandler>> handlers = new HashMap<>();
+ private final Map<String, Object> environment = new HashMap<>();
+ private final List<Object> objects = new ArrayList<>();
+
+ private Reference<ClassLoader> loader;
+ private ExceptionListener listener;
+ private Object owner;
+
+ private ElementHandler handler;
+
+ /**
+ * Creates new instance of document handler.
+ */
+ public DocumentHandler() {
+ setElementHandler("java", JavaElementHandler.class); // NON-NLS: the element name
+ setElementHandler("null", NullElementHandler.class); // NON-NLS: the element name
+ setElementHandler("array", ArrayElementHandler.class); // NON-NLS: the element name
+ setElementHandler("class", ClassElementHandler.class); // NON-NLS: the element name
+ setElementHandler("string", StringElementHandler.class); // NON-NLS: the element name
+ setElementHandler("object", ObjectElementHandler.class); // NON-NLS: the element name
+
+ setElementHandler("void", VoidElementHandler.class); // NON-NLS: the element name
+ setElementHandler("char", CharElementHandler.class); // NON-NLS: the element name
+ setElementHandler("byte", ByteElementHandler.class); // NON-NLS: the element name
+ setElementHandler("short", ShortElementHandler.class); // NON-NLS: the element name
+ setElementHandler("int", IntElementHandler.class); // NON-NLS: the element name
+ setElementHandler("long", LongElementHandler.class); // NON-NLS: the element name
+ setElementHandler("float", FloatElementHandler.class); // NON-NLS: the element name
+ setElementHandler("double", DoubleElementHandler.class); // NON-NLS: the element name
+ setElementHandler("boolean", BooleanElementHandler.class); // NON-NLS: the element name
+
+ // some handlers for new elements
+ setElementHandler("new", NewElementHandler.class); // NON-NLS: the element name
+ setElementHandler("var", VarElementHandler.class); // NON-NLS: the element name
+ setElementHandler("true", TrueElementHandler.class); // NON-NLS: the element name
+ setElementHandler("false", FalseElementHandler.class); // NON-NLS: the element name
+ setElementHandler("field", FieldElementHandler.class); // NON-NLS: the element name
+ setElementHandler("method", MethodElementHandler.class); // NON-NLS: the element name
+ setElementHandler("property", PropertyElementHandler.class); // NON-NLS: the element name
+ }
+
+ /**
+ * Returns the class loader used to instantiate objects.
+ * If the class loader has not been explicitly set
+ * then {@code null} is returned.
+ *
+ * @return the class loader used to instantiate objects
+ */
+ public ClassLoader getClassLoader() {
+ return (this.loader != null)
+ ? this.loader.get()
+ : null;
+ }
+
+ /**
+ * Sets the class loader used to instantiate objects.
+ * If the class loader is not set
+ * then default class loader will be used.
+ *
+ * @param loader a classloader to use
+ */
+ public void setClassLoader(ClassLoader loader) {
+ this.loader = new WeakReference<ClassLoader>(loader);
+ }
+
+ /**
+ * Returns the exception listener for parsing.
+ * The exception listener is notified
+ * when handler catches recoverable exceptions.
+ * If the exception listener has not been explicitly set
+ * then default exception listener is returned.
+ *
+ * @return the exception listener for parsing
+ */
+ public ExceptionListener getExceptionListener() {
+ return this.listener;
+ }
+
+ /**
+ * Sets the exception listener for parsing.
+ * The exception listener is notified
+ * when handler catches recoverable exceptions.
+ *
+ * @param listener the exception listener for parsing
+ */
+ public void setExceptionListener(ExceptionListener listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Returns the owner of this document handler.
+ *
+ * @return the owner of this document handler
+ */
+ public Object getOwner() {
+ return this.owner;
+ }
+
+ /**
+ * Sets the owner of this document handler.
+ *
+ * @param owner the owner of this document handler
+ */
+ public void setOwner(Object owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Returns the handler for the element with specified name.
+ *
+ * @param name the name of the element
+ * @return the corresponding element handler
+ */
+ public Class<? extends ElementHandler> getElementHandler(String name) {
+ Class<? extends ElementHandler> type = this.handlers.get(name);
+ if (type == null) {
+ throw new IllegalArgumentException("Unsupported element: " + name);
+ }
+ return type;
+ }
+
+ /**
+ * Sets the handler for the element with specified name.
+ *
+ * @param name the name of the element
+ * @param handler the corresponding element handler
+ */
+ public void setElementHandler(String name, Class<? extends ElementHandler> handler) {
+ this.handlers.put(name, handler);
+ }
+
+ /**
+ * Indicates whether the variable with specified identifier is defined.
+ *
+ * @param id the identifier
+ * @return @{code true} if the variable is defined;
+ * @{code false} otherwise
+ */
+ public boolean hasVariable(String id) {
+ return this.environment.containsKey(id);
+ }
+
+ /**
+ * Returns the value of the variable with specified identifier.
+ *
+ * @param id the identifier
+ * @return the value of the variable
+ */
+ public Object getVariable(String id) {
+ if (!this.environment.containsKey(id)) {
+ throw new IllegalArgumentException("Unbound variable: " + id);
+ }
+ return this.environment.get(id);
+ }
+
+ /**
+ * Sets new value of the variable with specified identifier.
+ *
+ * @param id the identifier
+ * @param value new value of the variable
+ */
+ public void setVariable(String id, Object value) {
+ this.environment.put(id, value);
+ }
+
+ /**
+ * Returns the array of readed objects.
+ *
+ * @return the array of readed objects
+ */
+ public Object[] getObjects() {
+ return this.objects.toArray();
+ }
+
+ /**
+ * Adds the object to the list of readed objects.
+ *
+ * @param object the object that is readed from XML document
+ */
+ void addObject(Object object) {
+ this.objects.add(object);
+ }
+
+ /**
+ * Prepares this handler to read objects from XML document.
+ */
+ @Override
+ public void startDocument() {
+ this.objects.clear();
+ this.handler = null;
+ }
+
+ /**
+ * Parses opening tag of XML element
+ * using corresponding element handler.
+ *
+ * @param uri the namespace URI, or the empty string
+ * if the element has no namespace URI or
+ * if namespace processing is not being performed
+ * @param localName the local name (without prefix), or the empty string
+ * if namespace processing is not being performed
+ * @param qName the qualified name (with prefix), or the empty string
+ * if qualified names are not available
+ * @param attributes the attributes attached to the element
+ */
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ ElementHandler parent = this.handler;
+ try {
+ this.handler = getElementHandler(qName).newInstance();
+ this.handler.setOwner(this);
+ this.handler.setParent(parent);
+ }
+ catch (Exception exception) {
+ throw new SAXException(exception);
+ }
+ for (int i = 0; i < attributes.getLength(); i++)
+ try {
+ String name = attributes.getQName(i);
+ String value = attributes.getValue(i);
+ this.handler.addAttribute(name, value);
+ }
+ catch (RuntimeException exception) {
+ handleException(exception);
+ }
+
+ this.handler.startElement();
+ }
+
+ /**
+ * Parses closing tag of XML element
+ * using corresponding element handler.
+ *
+ * @param uri the namespace URI, or the empty string
+ * if the element has no namespace URI or
+ * if namespace processing is not being performed
+ * @param localName the local name (without prefix), or the empty string
+ * if namespace processing is not being performed
+ * @param qName the qualified name (with prefix), or the empty string
+ * if qualified names are not available
+ */
+ @Override
+ public void endElement(String uri, String localName, String qName) {
+ try {
+ this.handler.endElement();
+ }
+ catch (RuntimeException exception) {
+ handleException(exception);
+ }
+ finally {
+ this.handler = this.handler.getParent();
+ }
+ }
+
+ /**
+ * Parses character data inside XML element.
+ *
+ * @param chars the array of characters
+ * @param start the start position in the character array
+ * @param length the number of characters to use
+ */
+ @Override
+ public void characters(char[] chars, int start, int length) {
+ if (this.handler != null) {
+ try {
+ while (0 < length--) {
+ this.handler.addCharacter(chars[start++]);
+ }
+ }
+ catch (RuntimeException exception) {
+ handleException(exception);
+ }
+ }
+ }
+
+ /**
+ * Handles an exception using current exception listener.
+ *
+ * @param exception an exception to handle
+ * @see #setExceptionListener
+ */
+ public void handleException(Exception exception) {
+ if (this.listener == null) {
+ throw new IllegalStateException(exception);
+ }
+ this.listener.exceptionThrown(exception);
+ }
+
+ /**
+ * Starts parsing of the specified input source.
+ *
+ * @param input the input source to parse
+ */
+ public void parse(final InputSource input) {
+ if ((this.acc == null) && (null != System.getSecurityManager())) {
+ throw new SecurityException("AccessControlContext is not set");
+ }
+ AccessControlContext stack = AccessController.getContext();
+ SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Void>() {
+ public Void run() {
+ try {
+ SAXParserFactory.newInstance().newSAXParser().parse(input, DocumentHandler.this);
+ }
+ catch (ParserConfigurationException exception) {
+ handleException(exception);
+ }
+ catch (SAXException wrapper) {
+ Exception exception = wrapper.getException();
+ if (exception == null) {
+ exception = wrapper;
+ }
+ handleException(exception);
+ }
+ catch (IOException exception) {
+ handleException(exception);
+ }
+ return null;
+ }
+ }, stack, this.acc);
+ }
+
+ /**
+ * Resolves class by name using current class loader.
+ * This method handles exception using current exception listener.
+ *
+ * @param name the name of the class
+ * @return the object that represents the class
+ */
+ public Class<?> findClass(String name) {
+ try {
+ return ClassFinder.resolveClass(name, getClassLoader());
+ }
+ catch (ClassNotFoundException exception) {
+ handleException(exception);
+ return null;
+ }
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/DoubleElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/DoubleElementHandler.java
new file mode 100755
index 0000000..f8292ae
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/DoubleElementHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <double> element.
+ * This element specifies {@code double} values.
+ * The class {@link Double} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <double>1.23e45</double></pre>
+ * is shortcut to<pre>
+ * <method name="valueOf" class="java.lang.Double">
+ * <string>1.23e45</string>
+ * </method></pre>
+ * which is equivalent to {@code Double.valueOf("1.23e45")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class DoubleElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code double} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code double} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return Double.valueOf(argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/ElementHandler.java
new file mode 100755
index 0000000..dc24b01
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ElementHandler.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * The base class for element handlers.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ *
+ * @see DocumentHandler
+ */
+public abstract class ElementHandler {
+ private DocumentHandler owner;
+ private ElementHandler parent;
+
+ private String id;
+
+ /**
+ * Returns the document handler that creates this element handler.
+ *
+ * @return the owner document handler
+ */
+ public final DocumentHandler getOwner() {
+ return this.owner;
+ }
+
+ /**
+ * Sets the document handler that creates this element handler.
+ * The owner document handler should be set after instantiation.
+ * Such approach is used to simplify the extensibility.
+ *
+ * @param owner the owner document handler
+ * @see DocumentHandler#startElement
+ */
+ final void setOwner(DocumentHandler owner) {
+ if (owner == null) {
+ throw new IllegalArgumentException("Every element should have owner");
+ }
+ this.owner = owner;
+ }
+
+ /**
+ * Returns the element handler that contains this one.
+ *
+ * @return the parent element handler
+ */
+ public final ElementHandler getParent() {
+ return this.parent;
+ }
+
+ /**
+ * Sets the element handler that contains this one.
+ * The parent element handler should be set after instantiation.
+ * Such approach is used to simplify the extensibility.
+ *
+ * @param parent the parent element handler
+ * @see DocumentHandler#startElement
+ */
+ final void setParent(ElementHandler parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * Returns the value of the variable with specified identifier.
+ *
+ * @param id the identifier
+ * @return the value of the variable
+ */
+ protected final Object getVariable(String id) {
+ if (id.equals(this.id)) {
+ ValueObject value = getValueObject();
+ if (value.isVoid()) {
+ throw new IllegalStateException("The element does not return value");
+ }
+ return value.getValue();
+ }
+ return (this.parent != null)
+ ? this.parent.getVariable(id)
+ : this.owner.getVariable(id);
+ }
+
+ /**
+ * Returns the value of the parent element.
+ *
+ * @return the value of the parent element
+ */
+ protected Object getContextBean() {
+ if (this.parent != null) {
+ ValueObject value = this.parent.getValueObject();
+ if (!value.isVoid()) {
+ return value.getValue();
+ }
+ throw new IllegalStateException("The outer element does not return value");
+ } else {
+ Object value = this.owner.getOwner();
+ if (value != null) {
+ return value;
+ }
+ throw new IllegalStateException("The topmost element does not have context");
+ }
+ }
+
+ /**
+ * Parses attributes of the element.
+ * By default, the following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ public void addAttribute(String name, String value) {
+ if (name.equals("id")) { // NON-NLS: the attribute name
+ this.id = value;
+ } else {
+ throw new IllegalArgumentException("Unsupported attribute: " + name);
+ }
+ }
+
+ /**
+ * This method is called before parsing of the element's body.
+ * All attributes are parsed at this point.
+ * By default, do nothing.
+ */
+ public void startElement() {
+ }
+
+ /**
+ * This method is called after parsing of the element's body.
+ * By default, it calculates the value of this element.
+ * The following tasks are executing for any non-void value:
+ * <ol>
+ * <li>If the {@code id} attribute is set
+ * the value of the variable with the specified identifier
+ * is set to the value of this element.</li>
+ * <li>This element is used as an argument of parent element if it is possible.</li>
+ * </ol>
+ *
+ * @see #isArgument
+ */
+ public void endElement() {
+ // do nothing if no value returned
+ ValueObject value = getValueObject();
+ if (!value.isVoid()) {
+ if (this.id != null) {
+ this.owner.setVariable(this.id, value.getValue());
+ }
+ if (isArgument()) {
+ if (this.parent != null) {
+ this.parent.addArgument(value.getValue());
+ } else {
+ this.owner.addObject(value.getValue());
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds the character that contained in this element.
+ * By default, only whitespaces are acceptable.
+ *
+ * @param ch the character
+ */
+ public void addCharacter(char ch) {
+ if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
+ throw new IllegalStateException("Illegal character with code " + (int) ch);
+ }
+ }
+
+ /**
+ * Adds the argument that is used to calculate the value of this element.
+ * By default, no arguments are acceptable.
+ *
+ * @param argument the value of the element that contained in this one
+ */
+ protected void addArgument(Object argument) {
+ throw new IllegalStateException("Could not add argument to simple element");
+ }
+
+ /**
+ * Tests whether the value of this element can be used
+ * as an argument of the element that contained in this one.
+ *
+ * @return {@code true} if the value of this element can be used
+ * as an argument of the element that contained in this one,
+ * {@code false} otherwise
+ */
+ protected boolean isArgument() {
+ return this.id == null;
+ }
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ protected abstract ValueObject getValueObject();
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/FalseElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/FalseElementHandler.java
new file mode 100755
index 0000000..608a827
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/FalseElementHandler.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <false> element.
+ * This element specifies {@code false} value.
+ * It should not contain body or inner elements.
+ * For example:<pre>
+ * <false/></pre>
+ * is equivalent to {@code false} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class FalseElementHandler extends NullElementHandler {
+
+ /**
+ * Returns {@code Boolean.FALSE}
+ * as a value of <false> element.
+ *
+ * @return {@code Boolean.FALSE} by default
+ */
+ @Override
+ public Object getValue() {
+ return Boolean.FALSE;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/FieldElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/FieldElementHandler.java
new file mode 100755
index 0000000..caa3a1d
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/FieldElementHandler.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import com.sun.beans.finder.FieldFinder;
+
+import java.lang.reflect.Field;
+
+/**
+ * This class is intended to handle <field> element.
+ * This element simplifies access to the fields.
+ * If the {@code class} attribute is specified
+ * this element accesses static field of specified class.
+ * This element defines getter if it contains no argument.
+ * It returns the value of the field in this case.
+ * For example:<pre>
+ * <field name="TYPE" class="java.lang.Long"/></pre>
+ * is equivalent to {@code Long.TYPE} in Java code.
+ * This element defines setter if it contains one argument.
+ * It does not return the value of the field in this case.
+ * For example:<pre>
+ * <field name="id"><int>0</int></field></pre>
+ * is equivalent to {@code id = 0} in Java code.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>name
+ * <dd>the field name
+ * <dt>class
+ * <dd>the type is used for static fields only
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class FieldElementHandler extends AccessorElementHandler {
+ private Class<?> type;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>name
+ * <dd>the field name
+ * <dt>class
+ * <dd>the type is used for static fields only
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("class")) { // NON-NLS: the attribute name
+ this.type = getOwner().findClass(value);
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Tests whether the value of this element can be used
+ * as an argument of the element that contained in this one.
+ *
+ * @return {@code true} if the value of this element should be used
+ * as an argument of the element that contained in this one,
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isArgument() {
+ return super.isArgument() && (this.type != null); // only static accessor can be used an argument
+ }
+
+ /**
+ * Returns the context of the field.
+ * The context of the static field is the class object.
+ * The context of the non-static field is the value of the parent element.
+ *
+ * @return the context of the field
+ */
+ @Override
+ protected Object getContextBean() {
+ return (this.type != null)
+ ? this.type
+ : super.getContextBean();
+ }
+
+ /**
+ * Returns the value of the field with specified {@code name}.
+ *
+ * @param name the name of the field
+ * @return the value of the specified field
+ */
+ @Override
+ protected Object getValue(String name) {
+ try {
+ return getFieldValue(getContextBean(), name);
+ }
+ catch (Exception exception) {
+ getOwner().handleException(exception);
+ }
+ return null;
+ }
+
+ /**
+ * Sets the new value for the field with specified {@code name}.
+ *
+ * @param name the name of the field
+ * @param value the new value for the specified field
+ */
+ @Override
+ protected void setValue(String name, Object value) {
+ try {
+ setFieldValue(getContextBean(), name, value);
+ }
+ catch (Exception exception) {
+ getOwner().handleException(exception);
+ }
+ }
+
+ /**
+ * Performs the search of the field with specified {@code name}
+ * in specified context and returns its value.
+ *
+ * @param bean the context bean that contains field
+ * @param name the name of the field
+ * @return the value of the field
+ * @throws IllegalAccessException if the field is not accesible
+ * @throws NoSuchFieldException if the field is not found
+ */
+ static Object getFieldValue(Object bean, String name) throws IllegalAccessException, NoSuchFieldException {
+ return findField(bean, name).get(bean);
+ }
+
+ /**
+ * Performs the search of the field with specified {@code name}
+ * in specified context and updates its value.
+ *
+ * @param bean the context bean that contains field
+ * @param name the name of the field
+ * @param value the new value for the field
+ * @throws IllegalAccessException if the field is not accesible
+ * @throws NoSuchFieldException if the field is not found
+ */
+ private static void setFieldValue(Object bean, String name, Object value) throws IllegalAccessException, NoSuchFieldException {
+ findField(bean, name).set(bean, value);
+ }
+
+ /**
+ * Performs the search of the field
+ * with specified {@code name} in specified context.
+ *
+ * @param bean the context bean that contains field
+ * @param name the name of the field
+ * @return field object that represents found field
+ * @throws NoSuchFieldException if the field is not found
+ */
+ private static Field findField(Object bean, String name) throws NoSuchFieldException {
+ return (bean instanceof Class<?>)
+ ? FieldFinder.findStaticField((Class<?>) bean, name)
+ : FieldFinder.findField(bean.getClass(), name);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/FloatElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/FloatElementHandler.java
new file mode 100755
index 0000000..0f934e6
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/FloatElementHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <float> element.
+ * This element specifies {@code float} values.
+ * The class {@link Float} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <float>-1.23</float></pre>
+ * is shortcut to<pre>
+ * <method name="valueOf" class="java.lang.Float">
+ * <string>-1.23</string>
+ * </method></pre>
+ * which is equivalent to {@code Float.valueOf("-1.23")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class FloatElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code float} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code float} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return Float.valueOf(argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/IntElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/IntElementHandler.java
new file mode 100755
index 0000000..0b9634a
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/IntElementHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <int> element.
+ * This element specifies {@code int} values.
+ * The class {@link Integer} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <int>-1</int></pre>
+ * is shortcut to<pre>
+ * <method name="decode" class="java.lang.Integer">
+ * <string>-1</string>
+ * </method></pre>
+ * which is equivalent to {@code Integer.decode("-1")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class IntElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code int} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code int} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return Integer.decode(argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/JavaElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/JavaElementHandler.java
new file mode 100755
index 0000000..53f3086
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/JavaElementHandler.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import java.beans.XMLDecoder;
+
+/**
+ * This class is intended to handle <java> element.
+ * Each element that appears in the body of this element
+ * is evaluated in the context of the decoder itself.
+ * Typically this outer context is used to retrieve the owner of the decoder,
+ * which can be set before reading the archive.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>version
+ * <dd>the Java version (not supported)
+ * <dt>class
+ * <dd>the type of preferable parser (not supported)
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @see DocumentHandler#getOwner
+ * @see DocumentHandler#setOwner
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class JavaElementHandler extends ElementHandler {
+ private Class<?> type;
+ private ValueObject value;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>version
+ * <dd>the Java version (not supported)
+ * <dt>class
+ * <dd>the type of preferable parser (not supported)
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("version")) { // NON-NLS: the attribute name
+ // unsupported attribute
+ } else if (name.equals("class")) { // NON-NLS: the attribute name
+ // check class for owner
+ this.type = getOwner().findClass(value);
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Adds the argument to the list of readed objects.
+ *
+ * @param argument the value of the element that contained in this one
+ */
+ @Override
+ protected void addArgument(Object argument) {
+ getOwner().addObject(argument);
+ }
+
+ /**
+ * Tests whether the value of this element can be used
+ * as an argument of the element that contained in this one.
+ *
+ * @return {@code true} if the value of this element should be used
+ * as an argument of the element that contained in this one,
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isArgument() {
+ return false; // do not use owner as object
+ }
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ @Override
+ protected ValueObject getValueObject() {
+ if (this.value == null) {
+ this.value = ValueObjectImpl.create(getValue());
+ }
+ return this.value;
+ }
+
+ /**
+ * Returns the owner of the owner document handler
+ * as a value of <java> element.
+ *
+ * @return the owner of the owner document handler
+ */
+ private Object getValue() {
+ Object owner = getOwner().getOwner();
+ if ((this.type == null) || isValid(owner)) {
+ return owner;
+ }
+ if (owner instanceof XMLDecoder) {
+ XMLDecoder decoder = (XMLDecoder) owner;
+ owner = decoder.getOwner();
+ if (isValid(owner)) {
+ return owner;
+ }
+ }
+ throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName());
+ }
+
+ /**
+ * Validates the owner of the <java> element.
+ * The owner is valid if it is {@code null} or an instance
+ * of the class specified by the {@code class} attribute.
+ *
+ * @param owner the owner of the <java> element
+ * @return {@code true} if the {@code owner} is valid;
+ * {@code false} otherwise
+ */
+ private boolean isValid(Object owner) {
+ return (owner == null) || this.type.isInstance(owner);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/LongElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/LongElementHandler.java
new file mode 100755
index 0000000..3147f47
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/LongElementHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <long> element.
+ * This element specifies {@code long} values.
+ * The class {@link Long} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <long>0xFFFF</long></pre>
+ * is shortcut to<pre>
+ * <method name="decode" class="java.lang.Long">
+ * <string>0xFFFF</string>
+ * </method></pre>
+ * which is equivalent to {@code Long.decode("0xFFFF")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class LongElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code long} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code long} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return Long.decode(argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/MethodElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/MethodElementHandler.java
new file mode 100755
index 0000000..73fcb67
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/MethodElementHandler.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import com.sun.beans.finder.MethodFinder;
+
+import java.lang.reflect.Method;
+
+import sun.reflect.misc.MethodUtil;
+
+/**
+ * This class is intended to handle <method> element.
+ * It describes invocation of the method.
+ * The {@code name} attribute denotes
+ * the name of the method to invoke.
+ * If the {@code class} attribute is specified
+ * this element invokes static method of specified class.
+ * The inner elements specifies the arguments of the method.
+ * For example:<pre>
+ * <method name="valueOf" class="java.lang.Long">
+ * <string>10</string>
+ * </method></pre>
+ * is equivalent to {@code Long.valueOf("10")} in Java code.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>name
+ * <dd>the method name
+ * <dt>class
+ * <dd>the type of object for instantiation
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class MethodElementHandler extends NewElementHandler {
+ private String name;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>name
+ * <dd>the method name
+ * <dt>class
+ * <dd>the type of object for instantiation
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("name")) { // NON-NLS: the attribute name
+ this.name = value;
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Returns the result of method execution.
+ *
+ * @param type the base class
+ * @param args the array of arguments
+ * @return the value of this element
+ * @throws Exception if calculation is failed
+ */
+ @Override
+ protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
+ Object bean = getContextBean();
+ Class<?>[] types = getArgumentTypes(args);
+ Method method = (type != null)
+ ? MethodFinder.findStaticMethod(type, this.name, types)
+ : MethodFinder.findMethod(bean.getClass(), this.name, types);
+
+ if (method.isVarArgs()) {
+ args = getArguments(args, method.getParameterTypes());
+ }
+ Object value = MethodUtil.invoke(method, bean, args);
+ return method.getReturnType().equals(void.class)
+ ? ValueObjectImpl.VOID
+ : ValueObjectImpl.create(value);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/NewElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/NewElementHandler.java
new file mode 100755
index 0000000..18998db
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/NewElementHandler.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import com.sun.beans.finder.ConstructorFinder;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class is intended to handle <new> element.
+ * It describes instantiation of the object.
+ * The {@code class} attribute denotes
+ * the name of the class to instantiate.
+ * The inner elements specifies the arguments of the constructor.
+ * For example:<pre>
+ * <new class="java.lang.Long">
+ * <string>10</string>
+ * </new></pre>
+ * is equivalent to {@code new Long("10")} in Java code.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>class
+ * <dd>the type of object for instantiation
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+class NewElementHandler extends ElementHandler {
+ private List<Object> arguments = new ArrayList<Object>();
+ private ValueObject value = ValueObjectImpl.VOID;
+
+ private Class<?> type;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>class
+ * <dd>the type of object for instantiation
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("class")) { // NON-NLS: the attribute name
+ this.type = getOwner().findClass(value);
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Adds the argument to the list of arguments
+ * that is used to calculate the value of this element.
+ *
+ * @param argument the value of the element that contained in this one
+ */
+ @Override
+ protected final void addArgument(Object argument) {
+ if (this.arguments == null) {
+ throw new IllegalStateException("Could not add argument to evaluated element");
+ }
+ this.arguments.add(argument);
+ }
+
+ /**
+ * Returns the context of the method.
+ * The context of the static method is the class object.
+ * The context of the non-static method is the value of the parent element.
+ *
+ * @return the context of the method
+ */
+ @Override
+ protected final Object getContextBean() {
+ return (this.type != null)
+ ? this.type
+ : super.getContextBean();
+ }
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ @Override
+ protected final ValueObject getValueObject() {
+ if (this.arguments != null) {
+ try {
+ this.value = getValueObject(this.type, this.arguments.toArray());
+ }
+ catch (Exception exception) {
+ getOwner().handleException(exception);
+ }
+ finally {
+ this.arguments = null;
+ }
+ }
+ return this.value;
+ }
+
+ /**
+ * Calculates the value of this element
+ * using the base class and the array of arguments.
+ * By default, it creates an instance of the base class.
+ * This method should be overridden in those handlers
+ * that extend behavior of this element.
+ *
+ * @param type the base class
+ * @param args the array of arguments
+ * @return the value of this element
+ * @throws Exception if calculation is failed
+ */
+ ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
+ if (type == null) {
+ throw new IllegalArgumentException("Class name is not set");
+ }
+ Class<?>[] types = getArgumentTypes(args);
+ Constructor<?> constructor = ConstructorFinder.findConstructor(type, types);
+ if (constructor.isVarArgs()) {
+ args = getArguments(args, constructor.getParameterTypes());
+ }
+ return ValueObjectImpl.create(constructor.newInstance(args));
+ }
+
+ /**
+ * Converts the array of arguments to the array of corresponding classes.
+ * If argument is {@code null} the class is {@code null} too.
+ *
+ * @param arguments the array of arguments
+ * @return the array of corresponding classes
+ */
+ static Class<?>[] getArgumentTypes(Object[] arguments) {
+ Class<?>[] types = new Class<?>[arguments.length];
+ for (int i = 0; i < arguments.length; i++) {
+ if (arguments[i] != null) {
+ types[i] = arguments[i].getClass();
+ }
+ }
+ return types;
+ }
+
+ /**
+ * Resolves variable arguments.
+ *
+ * @param arguments the array of arguments
+ * @param types the array of parameter types
+ * @return the resolved array of arguments
+ */
+ static Object[] getArguments(Object[] arguments, Class<?>[] types) {
+ int index = types.length - 1;
+ if (types.length == arguments.length) {
+ Object argument = arguments[index];
+ if (argument == null) {
+ return arguments;
+ }
+ Class<?> type = types[index];
+ if (type.isAssignableFrom(argument.getClass())) {
+ return arguments;
+ }
+ }
+ int length = arguments.length - index;
+ Class<?> type = types[index].getComponentType();
+ Object array = Array.newInstance(type, length);
+ System.arraycopy(arguments, index, array, 0, length);
+
+ Object[] args = new Object[types.length];
+ System.arraycopy(arguments, 0, args, 0, index);
+ args[index] = array;
+ return args;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/NullElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/NullElementHandler.java
new file mode 100755
index 0000000..59cb0e9
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/NullElementHandler.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <null> element.
+ * This element specifies {@code null} value.
+ * It should not contain body or inner elements.
+ * For example:<pre>
+ * <null/></pre>
+ * is equivalent to {@code null} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+class NullElementHandler extends ElementHandler implements ValueObject {
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ @Override
+ protected final ValueObject getValueObject() {
+ return this;
+ }
+
+ /**
+ * Returns {@code null}
+ * as a value of <null> element.
+ * This method should be overridden in those handlers
+ * that extend behavior of this element.
+ *
+ * @return {@code null} by default
+ */
+ public Object getValue() {
+ return null;
+ }
+
+ /**
+ * Returns {@code void} state of this value object.
+ *
+ * @return {@code false} always
+ */
+ public final boolean isVoid() {
+ return false;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ObjectElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/ObjectElementHandler.java
new file mode 100755
index 0000000..5669471
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ObjectElementHandler.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import java.beans.Expression;
+
+import static java.util.Locale.ENGLISH;
+
+/**
+ * This class is intended to handle <object> element.
+ * This element looks like <void> element,
+ * but its value is always used as an argument for element
+ * that contains this one.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>class
+ * <dd>the type is used for static methods and fields
+ * <dt>method
+ * <dd>the method name
+ * <dt>property
+ * <dd>the property name
+ * <dt>index
+ * <dd>the property index
+ * <dt>field
+ * <dd>the field name
+ * <dt>idref
+ * <dd>the identifier to refer to the variable
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+class ObjectElementHandler extends NewElementHandler {
+ private String idref;
+ private String field;
+ private Integer index;
+ private String property;
+ private String method;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>class
+ * <dd>the type is used for static methods and fields
+ * <dt>method
+ * <dd>the method name
+ * <dt>property
+ * <dd>the property name
+ * <dt>index
+ * <dd>the property index
+ * <dt>field
+ * <dd>the field name
+ * <dt>idref
+ * <dd>the identifier to refer to the variable
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public final void addAttribute(String name, String value) {
+ if (name.equals("idref")) { // NON-NLS: the attribute name
+ this.idref = value;
+ } else if (name.equals("field")) { // NON-NLS: the attribute name
+ this.field = value;
+ } else if (name.equals("index")) { // NON-NLS: the attribute name
+ this.index = Integer.valueOf(value);
+ addArgument(this.index); // hack for compatibility
+ } else if (name.equals("property")) { // NON-NLS: the attribute name
+ this.property = value;
+ } else if (name.equals("method")) { // NON-NLS: the attribute name
+ this.method = value;
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Calculates the value of this element
+ * if the field attribute or the idref attribute is set.
+ */
+ @Override
+ public final void startElement() {
+ if ((this.field != null) || (this.idref != null)) {
+ getValueObject();
+ }
+ }
+
+ /**
+ * Tests whether the value of this element can be used
+ * as an argument of the element that contained in this one.
+ *
+ * @return {@code true} if the value of this element can be used
+ * as an argument of the element that contained in this one,
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isArgument() {
+ return true; // hack for compatibility
+ }
+
+ /**
+ * Creates the value of this element.
+ *
+ * @param type the base class
+ * @param args the array of arguments
+ * @return the value of this element
+ * @throws Exception if calculation is failed
+ */
+ @Override
+ protected final ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
+ if (this.field != null) {
+ return ValueObjectImpl.create(FieldElementHandler.getFieldValue(getContextBean(), this.field));
+ }
+ if (this.idref != null) {
+ return ValueObjectImpl.create(getVariable(this.idref));
+ }
+ Object bean = getContextBean();
+ String name;
+ if (this.index != null) {
+ name = (args.length == 2)
+ ? PropertyElementHandler.SETTER
+ : PropertyElementHandler.GETTER;
+ } else if (this.property != null) {
+ name = (args.length == 1)
+ ? PropertyElementHandler.SETTER
+ : PropertyElementHandler.GETTER;
+
+ if (0 < this.property.length()) {
+ name += this.property.substring(0, 1).toUpperCase(ENGLISH) + this.property.substring(1);
+ }
+ } else {
+ name = (this.method != null) && (0 < this.method.length())
+ ? this.method
+ : "new"; // NON-NLS: the constructor marker
+ }
+ Expression expression = new Expression(bean, name, args);
+ return ValueObjectImpl.create(expression.getValue());
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/PropertyElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/PropertyElementHandler.java
new file mode 100755
index 0000000..8f4c40c
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/PropertyElementHandler.java
@@ -0,0 +1,289 @@
+/*
+ * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+import com.sun.beans.finder.MethodFinder;
+
+import java.beans.IndexedPropertyDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import sun.reflect.misc.MethodUtil;
+
+/**
+ * This class is intended to handle <property> element.
+ * This element simplifies access to the properties.
+ * If the {@code index} attribute is specified
+ * this element uses additional {@code int} parameter.
+ * If the {@code name} attribute is not specified
+ * this element uses method "get" as getter
+ * and method "set" as setter.
+ * This element defines getter if it contains no argument.
+ * It returns the value of the property in this case.
+ * For example:<pre>
+ * <property name="object" index="10"/></pre>
+ * is shortcut to<pre>
+ * <method name="getObject">
+ * <int>10</int>
+ * </method></pre>
+ * which is equivalent to {@code getObject(10)} in Java code.
+ * This element defines setter if it contains one argument.
+ * It does not return the value of the property in this case.
+ * For example:<pre>
+ * <property><int>0</int></property></pre>
+ * is shortcut to<pre>
+ * <method name="set">
+ * <int>0</int>
+ * </method></pre>
+ * which is equivalent to {@code set(0)} in Java code.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>name
+ * <dd>the property name
+ * <dt>index
+ * <dd>the property index
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class PropertyElementHandler extends AccessorElementHandler {
+ static final String GETTER = "get"; // NON-NLS: the getter prefix
+ static final String SETTER = "set"; // NON-NLS: the setter prefix
+
+ private Integer index;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>name
+ * <dd>the property name
+ * <dt>index
+ * <dd>the property index
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("index")) { // NON-NLS: the attribute name
+ this.index = Integer.valueOf(value);
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Tests whether the value of this element can be used
+ * as an argument of the element that contained in this one.
+ *
+ * @return {@code true} if the value of this element should be used
+ * as an argument of the element that contained in this one,
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isArgument() {
+ return false; // non-static accessor cannot be used an argument
+ }
+
+ /**
+ * Returns the value of the property with specified {@code name}.
+ *
+ * @param name the name of the property
+ * @return the value of the specified property
+ */
+ @Override
+ protected Object getValue(String name) {
+ try {
+ return getPropertyValue(getContextBean(), name, this.index);
+ }
+ catch (Exception exception) {
+ getOwner().handleException(exception);
+ }
+ return null;
+ }
+
+ /**
+ * Sets the new value for the property with specified {@code name}.
+ *
+ * @param name the name of the property
+ * @param value the new value for the specified property
+ */
+ @Override
+ protected void setValue(String name, Object value) {
+ try {
+ setPropertyValue(getContextBean(), name, this.index, value);
+ }
+ catch (Exception exception) {
+ getOwner().handleException(exception);
+ }
+ }
+
+ /**
+ * Performs the search of the getter for the property
+ * with specified {@code name} in specified class
+ * and returns value of the property.
+ *
+ * @param bean the context bean that contains property
+ * @param name the name of the property
+ * @param index the index of the indexed property
+ * @return the value of the property
+ * @throws IllegalAccessException if the property is not accesible
+ * @throws IntrospectionException if the bean introspection is failed
+ * @throws InvocationTargetException if the getter cannot be invoked
+ * @throws NoSuchMethodException if the getter is not found
+ */
+ private static Object getPropertyValue(Object bean, String name, Integer index) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
+ Class<?> type = bean.getClass();
+ if (index == null) {
+ return MethodUtil.invoke(findGetter(type, name), bean, new Object[] {});
+ } else if (type.isArray() && (name == null)) {
+ return Array.get(bean, index);
+ } else {
+ return MethodUtil.invoke(findGetter(type, name, int.class), bean, new Object[] {index});
+ }
+ }
+
+ /**
+ * Performs the search of the setter for the property
+ * with specified {@code name} in specified class
+ * and updates value of the property.
+ *
+ * @param bean the context bean that contains property
+ * @param name the name of the property
+ * @param index the index of the indexed property
+ * @param value the new value for the property
+ * @throws IllegalAccessException if the property is not accesible
+ * @throws IntrospectionException if the bean introspection is failed
+ * @throws InvocationTargetException if the setter cannot be invoked
+ * @throws NoSuchMethodException if the setter is not found
+ */
+ private static void setPropertyValue(Object bean, String name, Integer index, Object value) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
+ Class<?> type = bean.getClass();
+ Class<?> param = (value != null)
+ ? value.getClass()
+ : null;
+
+ if (index == null) {
+ MethodUtil.invoke(findSetter(type, name, param), bean, new Object[] {value});
+ } else if (type.isArray() && (name == null)) {
+ Array.set(bean, index, value);
+ } else {
+ MethodUtil.invoke(findSetter(type, name, int.class, param), bean, new Object[] {index, value});
+ }
+ }
+
+ /**
+ * Performs the search of the getter for the property
+ * with specified {@code name} in specified class.
+ *
+ * @param type the class that contains method
+ * @param name the name of the property
+ * @param args the method arguments
+ * @return method object that represents found getter
+ * @throws IntrospectionException if the bean introspection is failed
+ * @throws NoSuchMethodException if method is not found
+ */
+ private static Method findGetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
+ if (name == null) {
+ return MethodFinder.findInstanceMethod(type, GETTER, args);
+ }
+ PropertyDescriptor pd = getProperty(type, name);
+ if (args.length == 0) {
+ Method method = pd.getReadMethod();
+ if (method != null) {
+ return method;
+ }
+ } else if (pd instanceof IndexedPropertyDescriptor) {
+ IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
+ Method method = ipd.getIndexedReadMethod();
+ if (method != null) {
+ return method;
+ }
+ }
+ throw new IntrospectionException("Could not find getter for the " + name + " property");
+ }
+
+ /**
+ * Performs the search of the setter for the property
+ * with specified {@code name} in specified class.
+ *
+ * @param type the class that contains method
+ * @param name the name of the property
+ * @param args the method arguments
+ * @return method object that represents found setter
+ * @throws IntrospectionException if the bean introspection is failed
+ * @throws NoSuchMethodException if method is not found
+ */
+ private static Method findSetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
+ if (name == null) {
+ return MethodFinder.findInstanceMethod(type, SETTER, args);
+ }
+ PropertyDescriptor pd = getProperty(type, name);
+ if (args.length == 1) {
+ Method method = pd.getWriteMethod();
+ if (method != null) {
+ return method;
+ }
+ } else if (pd instanceof IndexedPropertyDescriptor) {
+ IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
+ Method method = ipd.getIndexedWriteMethod();
+ if (method != null) {
+ return method;
+ }
+ }
+ throw new IntrospectionException("Could not find setter for the " + name + " property");
+ }
+
+ /**
+ * Performs the search of the descriptor for the property
+ * with specified {@code name} in specified class.
+ *
+ * @param type the class to introspect
+ * @param name the property name
+ * @return descriptor for the named property
+ * @throws IntrospectionException if property descriptor is not found
+ */
+ private static PropertyDescriptor getProperty(Class<?> type, String name) throws IntrospectionException {
+ for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
+ if (name.equals(pd.getName())) {
+ return pd;
+ }
+ }
+ throw new IntrospectionException("Could not find the " + name + " property descriptor");
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ShortElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/ShortElementHandler.java
new file mode 100755
index 0000000..f86ad38
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ShortElementHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <short> element.
+ * This element specifies {@code short} values.
+ * The class {@link Short} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:<pre>
+ * <short>200</short></pre>
+ * is shortcut to<pre>
+ * <method name="decode" class="java.lang.Short">
+ * <string>200</string>
+ * </method></pre>
+ * which is equivalent to {@code Short.decode("200")} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ShortElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code short} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code short} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return Short.decode(argument);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/StringElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/StringElementHandler.java
new file mode 100755
index 0000000..bceb7ce
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/StringElementHandler.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <string> element.
+ * This element specifies {@link String} values.
+ * The result value is created from text of the body of this element.
+ * For example:<pre>
+ * <string>description</string></pre>
+ * is equivalent to {@code "description"} in Java code.
+ * The value of inner element is calculated
+ * before adding to the string using {@link String#valueOf(Object)}.
+ * Note that all characters are used including whitespaces (' ', '\t', '\n', '\r').
+ * So the value of the element<pre>
+ * <string><true></string></pre>
+ * is not equal to the value of the element<pre>
+ * <string>
+ * <true>
+ * </string></pre>
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public class StringElementHandler extends ElementHandler {
+ private StringBuilder sb = new StringBuilder();
+ private ValueObject value = ValueObjectImpl.NULL;
+
+ /**
+ * Adds the character that contained in this element.
+ *
+ * @param ch the character
+ */
+ @Override
+ public final void addCharacter(char ch) {
+ if (this.sb == null) {
+ throw new IllegalStateException("Could not add chararcter to evaluated string element");
+ }
+ this.sb.append(ch);
+ }
+
+ /**
+ * Adds the string value of the argument to the string value of this element.
+ *
+ * @param argument the value of the element that contained in this one
+ */
+ @Override
+ protected final void addArgument(Object argument) {
+ if (this.sb == null) {
+ throw new IllegalStateException("Could not add argument to evaluated string element");
+ }
+ this.sb.append(argument);
+ }
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ @Override
+ protected final ValueObject getValueObject() {
+ if (this.sb != null) {
+ try {
+ this.value = ValueObjectImpl.create(getValue(this.sb.toString()));
+ }
+ catch (RuntimeException exception) {
+ getOwner().handleException(exception);
+ }
+ finally {
+ this.sb = null;
+ }
+ }
+ return this.value;
+ }
+
+ /**
+ * Returns the text of the body of this element.
+ * This method evaluates value from text of the body,
+ * and should be overridden in those handlers
+ * that extend behavior of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated value
+ */
+ protected Object getValue(String argument) {
+ return argument;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/TrueElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/TrueElementHandler.java
new file mode 100755
index 0000000..f3bed67
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/TrueElementHandler.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <true> element.
+ * This element specifies {@code true} value.
+ * It should not contain body or inner elements.
+ * For example:<pre>
+ * <true/></pre>
+ * is equivalent to {@code true} in Java code.
+ * <p>The following atribute is supported:
+ * <dl>
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class TrueElementHandler extends NullElementHandler {
+
+ /**
+ * Returns {@code Boolean.TRUE}
+ * as a value of <true> element.
+ *
+ * @return {@code Boolean.TRUE} by default
+ */
+ @Override
+ public Object getValue() {
+ return Boolean.TRUE;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ValueObject.java b/ojluni/src/main/java/com/sun/beans/decoder/ValueObject.java
new file mode 100755
index 0000000..d602818
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ValueObject.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This interface represents the result of method execution.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public interface ValueObject {
+
+ /**
+ * Returns the result of method execution.
+ *
+ * @return the result of method execution
+ */
+ Object getValue();
+
+ /**
+ * Returns {@code void} state of this value object.
+ *
+ * @return {@code true} if value can be ignored,
+ * {@code false} otherwise
+ */
+ boolean isVoid();
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/ValueObjectImpl.java b/ojluni/src/main/java/com/sun/beans/decoder/ValueObjectImpl.java
new file mode 100755
index 0000000..6fa46c9
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/ValueObjectImpl.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This utility class provides {@code static} method
+ * to create the object that contains the result of method execution.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ValueObjectImpl implements ValueObject {
+ static final ValueObject NULL = new ValueObjectImpl(null);
+ static final ValueObject VOID = new ValueObjectImpl();
+
+ /**
+ * Returns the object that describes returning value.
+ *
+ * @param value the result of method execution
+ * @return the object that describes value
+ */
+ static ValueObject create(Object value) {
+ return (value != null)
+ ? new ValueObjectImpl(value)
+ : NULL;
+ }
+
+ private Object value;
+ private boolean isVoid;
+
+ /**
+ * Creates the object that describes returning void value.
+ */
+ private ValueObjectImpl() {
+ this.isVoid = true;
+ }
+
+ /**
+ * Creates the object that describes returning non-void value.
+ *
+ * @param value the result of method execution
+ */
+ private ValueObjectImpl(Object value) {
+ this.value = value;
+ }
+
+ /**
+ * Returns the result of method execution.
+ *
+ * @return the result of method execution
+ */
+ public Object getValue() {
+ return this.value;
+ }
+
+ /**
+ * Returns {@code void} state of this value object.
+ *
+ * @return {@code true} if value should be ignored,
+ * {@code false} otherwise
+ */
+ public boolean isVoid() {
+ return this.isVoid;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/VarElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/VarElementHandler.java
new file mode 100755
index 0000000..2d540fd
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/VarElementHandler.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <var> element.
+ * This element retrieves the value of specified variable.
+ * For example:<pre>
+ * <var id="id1" idref="id2"/></pre>
+ * is equivalent to {@code id1 = id2} in Java code.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>idref
+ * <dd>the identifier to refer to the variable
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class VarElementHandler extends ElementHandler {
+ private ValueObject value;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ * <dl>
+ * <dt>idref
+ * <dd>the identifier to refer to the variable
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("idref")) { // NON-NLS: the attribute name
+ this.value = ValueObjectImpl.create(getVariable(value));
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ @Override
+ protected ValueObject getValueObject() {
+ if (this.value == null) {
+ throw new IllegalArgumentException("Variable name is not set");
+ }
+ return this.value;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/decoder/VoidElementHandler.java b/ojluni/src/main/java/com/sun/beans/decoder/VoidElementHandler.java
new file mode 100755
index 0000000..63ce32c
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/decoder/VoidElementHandler.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <void> element.
+ * This element looks like <object> element,
+ * but its value is not used as an argument for element
+ * that contains this one.
+ * <p>The following atributes are supported:
+ * <dl>
+ * <dt>class
+ * <dd>the type is used for static methods and fields
+ * <dt>method
+ * <dd>the method name
+ * <dt>property
+ * <dd>the property name
+ * <dt>index
+ * <dd>the property index
+ * <dt>field
+ * <dd>the field name
+ * <dt>idref
+ * <dd>the identifier to refer to the variable
+ * <dt>id
+ * <dd>the identifier of the variable that is intended to store the result
+ * </dl>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class VoidElementHandler extends ObjectElementHandler {
+
+ /**
+ * Tests whether the value of this element can be used
+ * as an argument of the element that contained in this one.
+ *
+ * @return {@code true} if the value of this element should be used
+ * as an argument of the element that contained in this one,
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isArgument() {
+ return false; // hack for compatibility
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/BooleanEditor.java b/ojluni/src/main/java/com/sun/beans/editors/BooleanEditor.java
new file mode 100755
index 0000000..69aca32
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/BooleanEditor.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+/**
+ * Property editor for a java builtin "boolean" type.
+ */
+
+import java.beans.*;
+
+public class BooleanEditor extends PropertyEditorSupport {
+
+
+ public String getJavaInitializationString() {
+ Object value = getValue();
+ return (value != null)
+ ? value.toString()
+ : "null";
+ }
+
+ public String getAsText() {
+ Object value = getValue();
+ return (value instanceof Boolean)
+ ? getValidName((Boolean) value)
+ : null;
+ }
+
+ public void setAsText(String text) throws java.lang.IllegalArgumentException {
+ if (text == null) {
+ setValue(null);
+ } else if (isValidName(true, text)) {
+ setValue(Boolean.TRUE);
+ } else if (isValidName(false, text)) {
+ setValue(Boolean.FALSE);
+ } else {
+ throw new java.lang.IllegalArgumentException(text);
+ }
+ }
+
+ public String[] getTags() {
+ return new String[] {getValidName(true), getValidName(false)};
+ }
+
+ // the following method should be localized (4890258)
+
+ private String getValidName(boolean value) {
+ return value ? "True" : "False";
+ }
+
+ private boolean isValidName(boolean value, String name) {
+ return getValidName(value).equalsIgnoreCase(name);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/ByteEditor.java b/ojluni/src/main/java/com/sun/beans/editors/ByteEditor.java
new file mode 100755
index 0000000..2f4f342
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/ByteEditor.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+/**
+ * Property editor for a java builtin "byte" type.
+ *
+ */
+
+import java.beans.*;
+
+public class ByteEditor extends NumberEditor {
+
+ public String getJavaInitializationString() {
+ Object value = getValue();
+ return (value != null)
+ ? "((byte)" + value + ")"
+ : "null";
+ }
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue((text == null) ? null : Byte.decode(text));
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/ColorEditor.java b/ojluni/src/main/java/com/sun/beans/editors/ColorEditor.java
new file mode 100755
index 0000000..377af05
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/ColorEditor.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+import java.awt.*;
+import java.beans.*;
+
+public class ColorEditor extends Panel implements PropertyEditor {
+ private static final long serialVersionUID = 1781257185164716054L;
+
+ public ColorEditor() {
+ setLayout(null);
+
+ ourWidth = hPad;
+
+ // Create a sample color block bordered in black
+ Panel p = new Panel();
+ p.setLayout(null);
+ p.setBackground(Color.black);
+ sample = new Canvas();
+ p.add(sample);
+ sample.reshape(2, 2, sampleWidth, sampleHeight);
+ add(p);
+ p.reshape(ourWidth, 2, sampleWidth+4, sampleHeight+4);
+ ourWidth += sampleWidth + 4 + hPad;
+
+ text = new TextField("", 14);
+ add(text);
+ text.reshape(ourWidth,0,100,30);
+ ourWidth += 100 + hPad;
+
+ choser = new Choice();
+ int active = 0;
+ for (int i = 0; i < colorNames.length; i++) {
+ choser.addItem(colorNames[i]);
+ }
+ add(choser);
+ choser.reshape(ourWidth,0,100,30);
+ ourWidth += 100 + hPad;
+
+ resize(ourWidth,40);
+ }
+
+ public void setValue(Object o) {
+ Color c = (Color)o;
+ changeColor(c);
+ }
+
+ public Dimension preferredSize() {
+ return new Dimension(ourWidth, 40);
+ }
+
+ public boolean keyUp(Event e, int key) {
+ if (e.target == text) {
+ try {
+ setAsText(text.getText());
+ } catch (IllegalArgumentException ex) {
+ // Quietly ignore.
+ }
+ }
+ return (false);
+ }
+
+ public void setAsText(String s) throws java.lang.IllegalArgumentException {
+ if (s == null) {
+ changeColor(null);
+ return;
+ }
+ int c1 = s.indexOf(',');
+ int c2 = s.indexOf(',', c1+1);
+ if (c1 < 0 || c2 < 0) {
+ // Invalid string.
+ throw new IllegalArgumentException(s);
+ }
+ try {
+ int r = Integer.parseInt(s.substring(0,c1));
+ int g = Integer.parseInt(s.substring(c1+1, c2));
+ int b = Integer.parseInt(s.substring(c2+1));
+ Color c = new Color(r,g,b);
+ changeColor(c);
+ } catch (Exception ex) {
+ throw new IllegalArgumentException(s);
+ }
+
+ }
+
+ public boolean action(Event e, Object arg) {
+ if (e.target == choser) {
+ changeColor(colors[choser.getSelectedIndex()]);
+ }
+ return false;
+ }
+
+ public String getJavaInitializationString() {
+ return (this.color != null)
+ ? "new java.awt.Color(" + this.color.getRGB() + ",true)"
+ : "null";
+ }
+
+
+ private void changeColor(Color c) {
+
+ if (c == null) {
+ this.color = null;
+ this.text.setText("");
+ return;
+ }
+
+ color = c;
+
+ text.setText("" + c.getRed() + "," + c.getGreen() + "," + c.getBlue());
+
+ int active = 0;
+ for (int i = 0; i < colorNames.length; i++) {
+ if (color.equals(colors[i])) {
+ active = i;
+ }
+ }
+ choser.select(active);
+
+ sample.setBackground(color);
+ sample.repaint();
+
+ support.firePropertyChange("", null, null);
+ }
+
+ public Object getValue() {
+ return color;
+ }
+
+ public boolean isPaintable() {
+ return true;
+ }
+
+ public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) {
+ Color oldColor = gfx.getColor();
+ gfx.setColor(Color.black);
+ gfx.drawRect(box.x, box.y, box.width-3, box.height-3);
+ gfx.setColor(color);
+ gfx.fillRect(box.x+1, box.y+1, box.width-4, box.height-4);
+ gfx.setColor(oldColor);
+ }
+
+ public String getAsText() {
+ return (this.color != null)
+ ? this.color.getRed() + "," + this.color.getGreen() + "," + this.color.getBlue()
+ : null;
+ }
+
+ public String[] getTags() {
+ return null;
+ }
+
+ public java.awt.Component getCustomEditor() {
+ return this;
+ }
+
+ public boolean supportsCustomEditor() {
+ return true;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ support.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l) {
+ support.removePropertyChangeListener(l);
+ }
+
+
+ private String colorNames[] = { " ", "white", "lightGray", "gray", "darkGray",
+ "black", "red", "pink", "orange",
+ "yellow", "green", "magenta", "cyan",
+ "blue"};
+ private Color colors[] = { null, Color.white, Color.lightGray, Color.gray, Color.darkGray,
+ Color.black, Color.red, Color.pink, Color.orange,
+ Color.yellow, Color.green, Color.magenta, Color.cyan,
+ Color.blue};
+
+ private Canvas sample;
+ private int sampleHeight = 20;
+ private int sampleWidth = 40;
+ private int hPad = 5;
+ private int ourWidth;
+
+ private Color color;
+ private TextField text;
+ private Choice choser;
+
+ private PropertyChangeSupport support = new PropertyChangeSupport(this);
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/DoubleEditor.java b/ojluni/src/main/java/com/sun/beans/editors/DoubleEditor.java
new file mode 100755
index 0000000..55d5a05
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/DoubleEditor.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+/**
+ * Property editor for a java builtin "double" type.
+ *
+ */
+
+import java.beans.*;
+
+public class DoubleEditor extends NumberEditor {
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue((text == null) ? null : Double.valueOf(text));
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/EnumEditor.java b/ojluni/src/main/java/com/sun/beans/editors/EnumEditor.java
new file mode 100755
index 0000000..ee32685
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/EnumEditor.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.editors;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditor;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Property editor for java.lang.Enum subclasses.
+ *
+ * @see PropertyEditor
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public class EnumEditor implements PropertyEditor {
+ private final List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
+
+ private final Class type;
+ private final String[] tags;
+
+ private Object value;
+
+ public EnumEditor( Class type ) {
+ Object[] values = type.getEnumConstants();
+ if ( values == null ) {
+ throw new IllegalArgumentException( "Unsupported " + type );
+ }
+ this.type = type;
+ this.tags = new String[values.length];
+ for ( int i = 0; i < values.length; i++ ) {
+ this.tags[i] = ( ( Enum )values[i] ).name();
+ }
+ }
+
+ public Object getValue() {
+ return this.value;
+ }
+
+ public void setValue( Object value ) {
+ if ( ( value != null ) && !this.type.isInstance( value ) ) {
+ throw new IllegalArgumentException( "Unsupported value: " + value );
+ }
+ Object oldValue;
+ PropertyChangeListener[] listeners;
+ synchronized ( this.listeners ) {
+ oldValue = this.value;
+ this.value = value;
+
+ if ( ( value == null ) ? oldValue == null : value.equals( oldValue ) ) {
+ return; // do not fire event if value is not changed
+ }
+ int size = this.listeners.size();
+ if ( size == 0 ) {
+ return; // do not fire event if there are no any listener
+ }
+ listeners = this.listeners.toArray( new PropertyChangeListener[size] );
+ }
+ PropertyChangeEvent event = new PropertyChangeEvent( this, null, oldValue, value );
+ for ( PropertyChangeListener listener : listeners ) {
+ listener.propertyChange( event );
+ }
+ }
+
+ public String getAsText() {
+ return ( this.value != null )
+ ? ( ( Enum )this.value ).name()
+ : null;
+ }
+
+ public void setAsText( String text ) {
+ setValue( ( text != null )
+ ? Enum.valueOf( this.type, text )
+ : null );
+ }
+
+ public String[] getTags() {
+ return this.tags.clone();
+ }
+
+ public String getJavaInitializationString() {
+ String name = getAsText();
+ return ( name != null )
+ ? this.type.getName() + '.' + name
+ : "null";
+ }
+
+ public boolean isPaintable() {
+ return false;
+ }
+
+ public void paintValue( Graphics gfx, Rectangle box ) {
+ }
+
+ public boolean supportsCustomEditor() {
+ return false;
+ }
+
+ public Component getCustomEditor() {
+ return null;
+ }
+
+ public void addPropertyChangeListener( PropertyChangeListener listener ) {
+ synchronized ( this.listeners ) {
+ this.listeners.add( listener );
+ }
+ }
+
+ public void removePropertyChangeListener( PropertyChangeListener listener ) {
+ synchronized ( this.listeners ) {
+ this.listeners.remove( listener );
+ }
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/FloatEditor.java b/ojluni/src/main/java/com/sun/beans/editors/FloatEditor.java
new file mode 100755
index 0000000..4723c48
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/FloatEditor.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+/**
+ * Property editor for a java builtin "float" type.
+ *
+ */
+
+import java.beans.*;
+
+public class FloatEditor extends NumberEditor {
+
+ public String getJavaInitializationString() {
+ Object value = getValue();
+ return (value != null)
+ ? value + "F"
+ : "null";
+ }
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue((text == null) ? null : Float.valueOf(text));
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/FontEditor.java b/ojluni/src/main/java/com/sun/beans/editors/FontEditor.java
new file mode 100755
index 0000000..108ac5e
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/FontEditor.java
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+import java.awt.*;
+import java.beans.*;
+
+public class FontEditor extends Panel implements java.beans.PropertyEditor {
+ private static final long serialVersionUID = 6732704486002715933L;
+
+ public FontEditor() {
+ setLayout(null);
+
+ toolkit = Toolkit.getDefaultToolkit();
+ fonts = toolkit.getFontList();
+
+ familyChoser = new Choice();
+ for (int i = 0; i < fonts.length; i++) {
+ familyChoser.addItem(fonts[i]);
+ }
+ add(familyChoser);
+ familyChoser.reshape(20, 5, 100, 30);
+
+ styleChoser = new Choice();
+ for (int i = 0; i < styleNames.length; i++) {
+ styleChoser.addItem(styleNames[i]);
+ }
+ add(styleChoser);
+ styleChoser.reshape(145, 5, 70, 30);
+
+ sizeChoser = new Choice();
+ for (int i = 0; i < pointSizes.length; i++) {
+ sizeChoser.addItem("" + pointSizes[i]);
+ }
+ add(sizeChoser);
+ sizeChoser.reshape(220, 5, 70, 30);
+
+ resize(300,40);
+ }
+
+
+ public Dimension preferredSize() {
+ return new Dimension(300, 40);
+ }
+
+ public void setValue(Object o) {
+ font = (Font) o;
+ if (this.font == null)
+ return;
+
+ changeFont(font);
+ // Update the current GUI choices.
+ for (int i = 0; i < fonts.length; i++) {
+ if (fonts[i].equals(font.getFamily())) {
+ familyChoser.select(i);
+ break;
+ }
+ }
+ for (int i = 0; i < styleNames.length; i++) {
+ if (font.getStyle() == styles[i]) {
+ styleChoser.select(i);
+ break;
+ }
+ }
+ for (int i = 0; i < pointSizes.length; i++) {
+ if (font.getSize() <= pointSizes[i]) {
+ sizeChoser.select(i);
+ break;
+ }
+ }
+ }
+
+ private void changeFont(Font f) {
+ font = f;
+ if (sample != null) {
+ remove(sample);
+ }
+ sample = new Label(sampleText);
+ sample.setFont(font);
+ add(sample);
+ Component p = getParent();
+ if (p != null) {
+ p.invalidate();
+ p.layout();
+ }
+ invalidate();
+ layout();
+ repaint();
+ support.firePropertyChange("", null, null);
+ }
+
+ public Object getValue() {
+ return (font);
+ }
+
+ public String getJavaInitializationString() {
+ if (this.font == null)
+ return "null";
+
+ return "new java.awt.Font(\"" + font.getName() + "\", " +
+ font.getStyle() + ", " + font.getSize() + ")";
+ }
+
+ public boolean action(Event e, Object arg) {
+ String family = familyChoser.getSelectedItem();
+ int style = styles[styleChoser.getSelectedIndex()];
+ int size = pointSizes[sizeChoser.getSelectedIndex()];
+ try {
+ Font f = new Font(family, style, size);
+ changeFont(f);
+ } catch (Exception ex) {
+ System.err.println("Couldn't create font " + family + "-" +
+ styleNames[style] + "-" + size);
+ }
+ return (false);
+ }
+
+
+ public boolean isPaintable() {
+ return true;
+ }
+
+ public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) {
+ // Silent noop.
+ Font oldFont = gfx.getFont();
+ gfx.setFont(font);
+ FontMetrics fm = gfx.getFontMetrics();
+ int vpad = (box.height - fm.getAscent())/2;
+ gfx.drawString(sampleText, 0, box.height-vpad);
+ gfx.setFont(oldFont);
+ }
+
+ public String getAsText() {
+ if (this.font == null) {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(this.font.getName());
+ sb.append(' ');
+
+ boolean b = this.font.isBold();
+ if (b) {
+ sb.append("BOLD");
+ }
+ boolean i = this.font.isItalic();
+ if (i) {
+ sb.append("ITALIC");
+ }
+ if (b || i) {
+ sb.append(' ');
+ }
+ sb.append(this.font.getSize());
+ return sb.toString();
+ }
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue((text == null) ? null : Font.decode(text));
+ }
+
+ public String[] getTags() {
+ return null;
+ }
+
+ public java.awt.Component getCustomEditor() {
+ return this;
+ }
+
+ public boolean supportsCustomEditor() {
+ return true;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener l) {
+ support.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l) {
+ support.removePropertyChangeListener(l);
+ }
+
+ private Font font;
+ private Toolkit toolkit;
+ private String sampleText = "Abcde...";
+
+ private Label sample;
+ private Choice familyChoser;
+ private Choice styleChoser;
+ private Choice sizeChoser;
+
+ private String fonts[];
+ private String[] styleNames = { "plain", "bold", "italic" };
+ private int[] styles = { Font.PLAIN, Font.BOLD, Font.ITALIC };
+ private int[] pointSizes = { 3, 5, 8, 10, 12, 14, 18, 24, 36, 48 };
+
+ private PropertyChangeSupport support = new PropertyChangeSupport(this);
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/IntegerEditor.java b/ojluni/src/main/java/com/sun/beans/editors/IntegerEditor.java
new file mode 100755
index 0000000..066b714
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/IntegerEditor.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+/**
+ * Property editor for a java builtin "int" type.
+ *
+ */
+
+import java.beans.*;
+
+public class IntegerEditor extends NumberEditor {
+
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue((text == null) ? null : Integer.decode(text));
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/LongEditor.java b/ojluni/src/main/java/com/sun/beans/editors/LongEditor.java
new file mode 100755
index 0000000..3a8efbb
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/LongEditor.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+/**
+ * Property editor for a java builtin "long" type.
+ *
+ */
+
+import java.beans.*;
+
+public class LongEditor extends NumberEditor {
+
+ public String getJavaInitializationString() {
+ Object value = getValue();
+ return (value != null)
+ ? value + "L"
+ : "null";
+ }
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue((text == null) ? null : Long.decode(text));
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/NumberEditor.java b/ojluni/src/main/java/com/sun/beans/editors/NumberEditor.java
new file mode 100755
index 0000000..3941e2c
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/NumberEditor.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.editors;
+
+/**
+ * Abstract Property editor for a java builtin number types.
+ *
+ */
+
+import java.beans.*;
+
+abstract public class NumberEditor extends PropertyEditorSupport {
+
+ public String getJavaInitializationString() {
+ Object value = getValue();
+ return (value != null)
+ ? value.toString()
+ : "null";
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/ShortEditor.java b/ojluni/src/main/java/com/sun/beans/editors/ShortEditor.java
new file mode 100755
index 0000000..cf82eef
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/ShortEditor.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package com.sun.beans.editors;
+
+/**
+ * Property editor for a java builtin "short" type.
+ *
+ */
+
+import java.beans.*;
+
+public class ShortEditor extends NumberEditor {
+
+ public String getJavaInitializationString() {
+ Object value = getValue();
+ return (value != null)
+ ? "((short)" + value + ")"
+ : "null";
+ }
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ setValue((text == null) ? null : Short.decode(text));
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/editors/StringEditor.java b/ojluni/src/main/java/com/sun/beans/editors/StringEditor.java
new file mode 100755
index 0000000..2f1cde4
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/editors/StringEditor.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+package com.sun.beans.editors;
+
+import java.beans.*;
+
+public class StringEditor extends PropertyEditorSupport {
+
+ public String getJavaInitializationString() {
+ Object value = getValue();
+ if (value == null)
+ return "null";
+
+ String str = value.toString();
+ int length = str.length();
+ StringBuilder sb = new StringBuilder(length + 2);
+ sb.append('"');
+ for (int i = 0; i < length; i++) {
+ char ch = str.charAt(i);
+ switch (ch) {
+ case '\b': sb.append("\\b"); break;
+ case '\t': sb.append("\\t"); break;
+ case '\n': sb.append("\\n"); break;
+ case '\f': sb.append("\\f"); break;
+ case '\r': sb.append("\\r"); break;
+ case '\"': sb.append("\\\""); break;
+ case '\\': sb.append("\\\\"); break;
+ default:
+ if ((ch < ' ') || (ch > '~')) {
+ sb.append("\\u");
+ String hex = Integer.toHexString((int) ch);
+ for (int len = hex.length(); len < 4; len++) {
+ sb.append('0');
+ }
+ sb.append(hex);
+ } else {
+ sb.append(ch);
+ }
+ break;
+ }
+ }
+ sb.append('"');
+ return sb.toString();
+ }
+
+ public void setAsText(String text) {
+ setValue(text);
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/AbstractFinder.java b/ojluni/src/main/java/com/sun/beans/finder/AbstractFinder.java
new file mode 100755
index 0000000..c1868ba
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/AbstractFinder.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This abstract class provides functionality
+ * to find a public method or constructor
+ * with specified parameter types.
+ * It supports a variable number of parameters.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+abstract class AbstractFinder<T extends Member> {
+ private final Class<?>[] args;
+
+ /**
+ * Creates finder for array of classes of arguments.
+ * If a particular element of array equals {@code null},
+ * than the appropriate pair of classes
+ * does not take into consideration.
+ *
+ * @param args array of classes of arguments
+ */
+ protected AbstractFinder(Class<?>[] args) {
+ this.args = args;
+ }
+
+ /**
+ * Returns an array of {@code Class} objects
+ * that represent the formal parameter types of the method.
+ * Returns an empty array if the method takes no parameters.
+ *
+ * @param method the object that represents method
+ * @return the parameter types of the method
+ */
+ protected abstract Class<?>[] getParameters(T method);
+
+ /**
+ * Returns {@code true} if and only if the method
+ * was declared to take a variable number of arguments.
+ *
+ * @param method the object that represents method
+ * @return {@code true} if the method was declared
+ * to take a variable number of arguments;
+ * {@code false} otherwise
+ */
+ protected abstract boolean isVarArgs(T method);
+
+ /**
+ * Checks validness of the method.
+ * At least the valid method should be public.
+ *
+ * @param method the object that represents method
+ * @return {@code true} if the method is valid,
+ * {@code false} otherwise
+ */
+ protected boolean isValid(T method) {
+ return Modifier.isPublic(method.getModifiers());
+ }
+
+ /**
+ * Performs a search in the {@code methods} array.
+ * The one method is selected from the array of the valid methods.
+ * The list of parameters of the selected method shows
+ * the best correlation with the list of arguments
+ * specified at class initialization.
+ * If more than one method is both accessible and applicable
+ * to a method invocation, it is necessary to choose one
+ * to provide the descriptor for the run-time method dispatch.
+ * The most specific method should be chosen.
+ *
+ * @param methods the array of methods to search within
+ * @return the object that represents found method
+ * @throws NoSuchMethodException if no method was found or several
+ * methods meet the search criteria
+ * @see #isAssignable
+ */
+ final T find(T[] methods) throws NoSuchMethodException {
+ Map<T, Class<?>[]> map = new HashMap<T, Class<?>[]>();
+
+ T oldMethod = null;
+ Class<?>[] oldParams = null;
+ boolean ambiguous = false;
+
+ for (T newMethod : methods) {
+ if (isValid(newMethod)) {
+ Class<?>[] newParams = getParameters(newMethod);
+ if (newParams.length == this.args.length) {
+ PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams);
+ if (isAssignable(newParams, this.args)) {
+ if (oldMethod == null) {
+ oldMethod = newMethod;
+ oldParams = newParams;
+ } else {
+ boolean useNew = isAssignable(oldParams, newParams);
+ boolean useOld = isAssignable(newParams, oldParams);
+
+ if (useOld && useNew) {
+ // only if parameters are equal
+ useNew = !newMethod.isSynthetic();
+ useOld = !oldMethod.isSynthetic();
+ }
+ if (useOld == useNew) {
+ ambiguous = true;
+ } else if (useNew) {
+ oldMethod = newMethod;
+ oldParams = newParams;
+ ambiguous = false;
+ }
+ }
+ }
+ }
+ if (isVarArgs(newMethod)) {
+ int length = newParams.length - 1;
+ if (length <= this.args.length) {
+ Class<?>[] array = new Class<?>[this.args.length];
+ System.arraycopy(newParams, 0, array, 0, length);
+ if (length < this.args.length) {
+ Class<?> type = newParams[length].getComponentType();
+ if (type.isPrimitive()) {
+ type = PrimitiveWrapperMap.getType(type.getName());
+ }
+ for (int i = length; i < this.args.length; i++) {
+ array[i] = type;
+ }
+ }
+ map.put(newMethod, array);
+ }
+ }
+ }
+ }
+ for (T newMethod : methods) {
+ Class<?>[] newParams = map.get(newMethod);
+ if (newParams != null) {
+ if (isAssignable(newParams, this.args)) {
+ if (oldMethod == null) {
+ oldMethod = newMethod;
+ oldParams = newParams;
+ } else {
+ boolean useNew = isAssignable(oldParams, newParams);
+ boolean useOld = isAssignable(newParams, oldParams);
+
+ if (useOld && useNew) {
+ // only if parameters are equal
+ useNew = !newMethod.isSynthetic();
+ useOld = !oldMethod.isSynthetic();
+ }
+ if (useOld == useNew) {
+ if (oldParams == map.get(oldMethod)) {
+ ambiguous = true;
+ }
+ } else if (useNew) {
+ oldMethod = newMethod;
+ oldParams = newParams;
+ ambiguous = false;
+ }
+ }
+ }
+ }
+ }
+
+ if (ambiguous) {
+ throw new NoSuchMethodException("Ambiguous methods are found");
+ }
+ if (oldMethod == null) {
+ throw new NoSuchMethodException("Method is not found");
+ }
+ return oldMethod;
+ }
+
+ /**
+ * Determines if every class in {@code min} array is either the same as,
+ * or is a superclass of, the corresponding class in {@code max} array.
+ * The length of every array must equal the number of arguments.
+ * This comparison is performed in the {@link #find} method
+ * before the first call of the isAssignable method.
+ * If an argument equals {@code null}
+ * the appropriate pair of classes does not take into consideration.
+ *
+ * @param min the array of classes to be checked
+ * @param max the array of classes that is used to check
+ * @return {@code true} if all classes in {@code min} array
+ * are assignable from corresponding classes in {@code max} array,
+ * {@code false} otherwise
+ *
+ * @see Class#isAssignableFrom
+ */
+ private boolean isAssignable(Class<?>[] min, Class<?>[] max) {
+ for (int i = 0; i < this.args.length; i++) {
+ if (null != this.args[i]) {
+ if (!min[i].isAssignableFrom(max[i])) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/BeanInfoFinder.java b/ojluni/src/main/java/com/sun/beans/finder/BeanInfoFinder.java
new file mode 100755
index 0000000..28af1a4
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/BeanInfoFinder.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import java.beans.BeanDescriptor;
+import java.beans.BeanInfo;
+import java.beans.MethodDescriptor;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
+
+/**
+ * This is utility class that provides functionality
+ * to find a {@link BeanInfo} for a JavaBean specified by its type.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class BeanInfoFinder
+ extends InstanceFinder<BeanInfo> {
+
+ private static final String DEFAULT = "sun.beans.infos";
+ private static final String DEFAULT_NEW = "com.sun.beans.infos";
+
+ public BeanInfoFinder() {
+ super(BeanInfo.class, true, "BeanInfo", DEFAULT);
+ }
+
+ private static boolean isValid(Class<?> type, Method method) {
+ return (method != null) && method.getDeclaringClass().isAssignableFrom(type);
+ }
+
+ @Override
+ protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
+ if (DEFAULT.equals(prefix)) {
+ prefix = DEFAULT_NEW;
+ }
+ // this optimization will only use the BeanInfo search path
+ // if is has changed from the original
+ // or trying to get the ComponentBeanInfo
+ BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
+ ? super.instantiate(type, prefix, name)
+ : null;
+
+ if (info != null) {
+ // make sure that the returned BeanInfo matches the class
+ BeanDescriptor bd = info.getBeanDescriptor();
+ if (bd != null) {
+ if (type.equals(bd.getBeanClass())) {
+ return info;
+ }
+ }
+ else {
+ PropertyDescriptor[] pds = info.getPropertyDescriptors();
+ if (pds != null) {
+ for (PropertyDescriptor pd : pds) {
+ Method method = pd.getReadMethod();
+ if (method == null) {
+ method = pd.getWriteMethod();
+ }
+ if (isValid(type, method)) {
+ return info;
+ }
+ }
+ }
+ else {
+ MethodDescriptor[] mds = info.getMethodDescriptors();
+ if (mds != null) {
+ for (MethodDescriptor md : mds) {
+ if (isValid(type, md.getMethod())) {
+ return info;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/ClassFinder.java b/ojluni/src/main/java/com/sun/beans/finder/ClassFinder.java
new file mode 100755
index 0000000..9d53235
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/ClassFinder.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import static sun.reflect.misc.ReflectUtil.checkPackageAccess;
+
+/**
+ * This is utility class that provides {@code static} methods
+ * to find a class with the specified name using the specified class loader.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class ClassFinder {
+
+ /**
+ * Returns the {@code Class} object associated
+ * with the class or interface with the given string name,
+ * using the default class loader.
+ * <p>
+ * The {@code name} can denote an array class
+ * (see {@link Class#getName} for details).
+ *
+ * @param name fully qualified name of the desired class
+ * @return class object representing the desired class
+ *
+ * @throws ClassNotFoundException if the class cannot be located
+ * by the specified class loader
+ *
+ * @see Class#forName(String)
+ * @see Class#forName(String,boolean,ClassLoader)
+ * @see ClassLoader#getSystemClassLoader()
+ * @see Thread#getContextClassLoader()
+ */
+ public static Class<?> findClass(String name) throws ClassNotFoundException {
+ checkPackageAccess(name);
+ try {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ // can be null in IE (see 6204697)
+ loader = ClassLoader.getSystemClassLoader();
+ }
+ if (loader != null) {
+ return Class.forName(name, false, loader);
+ }
+
+ } catch (ClassNotFoundException exception) {
+ // use current class loader instead
+ } catch (SecurityException exception) {
+ // use current class loader instead
+ }
+ return Class.forName(name);
+ }
+
+ /**
+ * Returns the {@code Class} object associated with
+ * the class or interface with the given string name,
+ * using the given class loader.
+ * <p>
+ * The {@code name} can denote an array class
+ * (see {@link Class#getName} for details).
+ * <p>
+ * If the parameter {@code loader} is null,
+ * the class is loaded through the default class loader.
+ *
+ * @param name fully qualified name of the desired class
+ * @param loader class loader from which the class must be loaded
+ * @return class object representing the desired class
+ *
+ * @throws ClassNotFoundException if the class cannot be located
+ * by the specified class loader
+ *
+ * @see #findClass(String,ClassLoader)
+ * @see Class#forName(String,boolean,ClassLoader)
+ */
+ public static Class<?> findClass(String name, ClassLoader loader) throws ClassNotFoundException {
+ checkPackageAccess(name);
+ if (loader != null) {
+ try {
+ return Class.forName(name, false, loader);
+ } catch (ClassNotFoundException exception) {
+ // use default class loader instead
+ } catch (SecurityException exception) {
+ // use default class loader instead
+ }
+ }
+ return findClass(name);
+ }
+
+ /**
+ * Returns the {@code Class} object associated
+ * with the class or interface with the given string name,
+ * using the default class loader.
+ * <p>
+ * The {@code name} can denote an array class
+ * (see {@link Class#getName} for details).
+ * <p>
+ * This method can be used to obtain
+ * any of the {@code Class} objects
+ * representing {@code void} or primitive Java types:
+ * {@code char}, {@code byte}, {@code short},
+ * {@code int}, {@code long}, {@code float},
+ * {@code double} and {@code boolean}.
+ *
+ * @param name fully qualified name of the desired class
+ * @return class object representing the desired class
+ *
+ * @throws ClassNotFoundException if the class cannot be located
+ * by the specified class loader
+ *
+ * @see #resolveClass(String,ClassLoader)
+ */
+ public static Class<?> resolveClass(String name) throws ClassNotFoundException {
+ return resolveClass(name, null);
+ }
+
+ /**
+ * Returns the {@code Class} object associated with
+ * the class or interface with the given string name,
+ * using the given class loader.
+ * <p>
+ * The {@code name} can denote an array class
+ * (see {@link Class#getName} for details).
+ * <p>
+ * If the parameter {@code loader} is null,
+ * the class is loaded through the default class loader.
+ * <p>
+ * This method can be used to obtain
+ * any of the {@code Class} objects
+ * representing {@code void} or primitive Java types:
+ * {@code char}, {@code byte}, {@code short},
+ * {@code int}, {@code long}, {@code float},
+ * {@code double} and {@code boolean}.
+ *
+ * @param name fully qualified name of the desired class
+ * @param loader class loader from which the class must be loaded
+ * @return class object representing the desired class
+ *
+ * @throws ClassNotFoundException if the class cannot be located
+ * by the specified class loader
+ *
+ * @see #findClass(String,ClassLoader)
+ * @see PrimitiveTypeMap#getType(String)
+ */
+ public static Class<?> resolveClass(String name, ClassLoader loader) throws ClassNotFoundException {
+ Class<?> type = PrimitiveTypeMap.getType(name);
+ return (type == null)
+ ? findClass(name, loader)
+ : type;
+ }
+
+ /**
+ * Disable instantiation.
+ */
+ private ClassFinder() {
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/ConstructorFinder.java b/ojluni/src/main/java/com/sun/beans/finder/ConstructorFinder.java
new file mode 100755
index 0000000..9aed4c9
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/ConstructorFinder.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import com.sun.beans.WeakCache;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
+
+/**
+ * This utility class provides {@code static} methods
+ * to find a public constructor with specified parameter types
+ * in specified class.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
+ private static final WeakCache<Signature, Constructor<?>> CACHE = new WeakCache<Signature, Constructor<?>>();
+
+ /**
+ * Finds public constructor
+ * that is declared in public class.
+ *
+ * @param type the class that can have constructor
+ * @param args parameter types that is used to find constructor
+ * @return object that represents found constructor
+ * @throws NoSuchMethodException if constructor could not be found
+ * or some constructors are found
+ */
+ public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException {
+ if (type.isPrimitive()) {
+ throw new NoSuchMethodException("Primitive wrapper does not contain constructors");
+ }
+ if (type.isInterface()) {
+ throw new NoSuchMethodException("Interface does not contain constructors");
+ }
+ if (Modifier.isAbstract(type.getModifiers())) {
+ throw new NoSuchMethodException("Abstract class cannot be instantiated");
+ }
+ if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
+ throw new NoSuchMethodException("Class is not accessible");
+ }
+ PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
+ Signature signature = new Signature(type, args);
+
+ Constructor<?> constructor = CACHE.get(signature);
+ if (constructor != null) {
+ return constructor;
+ }
+ constructor = new ConstructorFinder(args).find(type.getConstructors());
+ CACHE.put(signature, constructor);
+ return constructor;
+ }
+
+ /**
+ * Creates constructor finder with specified array of parameter types.
+ *
+ * @param args the array of parameter types
+ */
+ private ConstructorFinder(Class<?>[] args) {
+ super(args);
+ }
+
+ /**
+ * Returns an array of {@code Class} objects
+ * that represent the formal parameter types of the constructor.
+ * Returns an empty array if the constructor takes no parameters.
+ *
+ * @param constructor the object that represents constructor
+ * @return the parameter types of the constructor
+ */
+ @Override
+ protected Class<?>[] getParameters(Constructor<?> constructor) {
+ return constructor.getParameterTypes();
+ }
+
+ /**
+ * Returns {@code true} if and only if the constructor
+ * was declared to take a variable number of arguments.
+ *
+ * @param constructor the object that represents constructor
+ * @return {@code true} if the constructor was declared
+ * to take a variable number of arguments;
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isVarArgs(Constructor<?> constructor) {
+ return constructor.isVarArgs();
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/FieldFinder.java b/ojluni/src/main/java/com/sun/beans/finder/FieldFinder.java
new file mode 100755
index 0000000..eb8b5bb
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/FieldFinder.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
+
+/**
+ * This utility class provides {@code static} methods
+ * to find a public field with specified name
+ * in specified class.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class FieldFinder {
+
+ /**
+ * Finds public field (static or non-static)
+ * that is declared in public class.
+ *
+ * @param type the class that can have field
+ * @param name the name of field to find
+ * @return object that represents found field
+ * @throws NoSuchFieldException if field is not found
+ * @see Class#getField
+ */
+ public static Field findField(Class<?> type, String name) throws NoSuchFieldException {
+ if (name == null) {
+ throw new IllegalArgumentException("Field name is not set");
+ }
+ Field field = type.getField(name);
+ if (!Modifier.isPublic(field.getModifiers())) {
+ throw new NoSuchFieldException("Field '" + name + "' is not public");
+ }
+ type = field.getDeclaringClass();
+ if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
+ throw new NoSuchFieldException("Field '" + name + "' is not accessible");
+ }
+ return field;
+ }
+
+ /**
+ * Finds public non-static field
+ * that is declared in public class.
+ *
+ * @param type the class that can have field
+ * @param name the name of field to find
+ * @return object that represents found field
+ * @throws NoSuchFieldException if field is not found
+ * @see Class#getField
+ */
+ public static Field findInstanceField(Class<?> type, String name) throws NoSuchFieldException {
+ Field field = findField(type, name);
+ if (Modifier.isStatic(field.getModifiers())) {
+ throw new NoSuchFieldException("Field '" + name + "' is static");
+ }
+ return field;
+ }
+
+ /**
+ * Finds public static field
+ * that is declared in public class.
+ *
+ * @param type the class that can have field
+ * @param name the name of field to find
+ * @return object that represents found field
+ * @throws NoSuchFieldException if field is not found
+ * @see Class#getField
+ */
+ public static Field findStaticField(Class<?> type, String name) throws NoSuchFieldException {
+ Field field = findField(type, name);
+ if (!Modifier.isStatic(field.getModifiers())) {
+ throw new NoSuchFieldException("Field '" + name + "' is not static");
+ }
+ return field;
+ }
+
+ /**
+ * Disable instantiation.
+ */
+ private FieldFinder() {
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/InstanceFinder.java b/ojluni/src/main/java/com/sun/beans/finder/InstanceFinder.java
new file mode 100755
index 0000000..5842af2
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/InstanceFinder.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+/**
+ * This is utility class that provides basic functionality
+ * to find an auxiliary class for a JavaBean specified by its type.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+class InstanceFinder<T> {
+
+ private static final String[] EMPTY = { };
+
+ private final Class<? extends T> type;
+ private final boolean allow;
+ private final String suffix;
+ private volatile String[] packages;
+
+ InstanceFinder(Class<? extends T> type, boolean allow, String suffix, String... packages) {
+ this.type = type;
+ this.allow = allow;
+ this.suffix = suffix;
+ this.packages = packages.clone();
+ }
+
+ public String[] getPackages() {
+ return this.packages.clone();
+ }
+
+ public void setPackages(String... packages) {
+ this.packages = (packages != null) && (packages.length > 0)
+ ? packages.clone()
+ : EMPTY;
+ }
+
+ public T find(Class<?> type) {
+ if (type == null) {
+ return null;
+ }
+ String name = type.getName() + this.suffix;
+ T object = instantiate(type, name);
+ if (object != null) {
+ return object;
+ }
+ if (this.allow) {
+ object = instantiate(type, null);
+ if (object != null) {
+ return object;
+ }
+ }
+ int index = name.lastIndexOf('.') + 1;
+ if (index > 0) {
+ name = name.substring(index);
+ }
+ for (String prefix : this.packages) {
+ object = instantiate(type, prefix, name);
+ if (object != null) {
+ return object;
+ }
+ }
+ return null;
+ }
+
+ protected T instantiate(Class<?> type, String name) {
+ if (type != null) {
+ try {
+ if (name != null) {
+ type = ClassFinder.findClass(name, type.getClassLoader());
+ }
+ if (this.type.isAssignableFrom(type)) {
+ return (T) type.newInstance();
+ }
+ }
+ catch (Exception exception) {
+ // ignore any exceptions
+ }
+ }
+ return null;
+ }
+
+ protected T instantiate(Class<?> type, String prefix, String name) {
+ return instantiate(type, prefix + '.' + name);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/MethodFinder.java b/ojluni/src/main/java/com/sun/beans/finder/MethodFinder.java
new file mode 100755
index 0000000..ec6b2b2
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/MethodFinder.java
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import com.sun.beans.TypeResolver;
+import com.sun.beans.WeakCache;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+
+import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
+
+/**
+ * This utility class provides {@code static} methods
+ * to find a public method with specified name and parameter types
+ * in specified class.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class MethodFinder extends AbstractFinder<Method> {
+ private static final WeakCache<Signature, Method> CACHE = new WeakCache<Signature, Method>();
+
+ /**
+ * Finds public method (static or non-static)
+ * that is accessible from public class.
+ *
+ * @param type the class that can have method
+ * @param name the name of method to find
+ * @param args parameter types that is used to find method
+ * @return object that represents found method
+ * @throws NoSuchMethodException if method could not be found
+ * or some methods are found
+ */
+ public static Method findMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
+ if (name == null) {
+ throw new IllegalArgumentException("Method name is not set");
+ }
+ PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
+ Signature signature = new Signature(type, name, args);
+
+ Method method = CACHE.get(signature);
+ boolean cached = method != null;
+ if (cached && isPackageAccessible(method.getDeclaringClass())) {
+ return method;
+ }
+ method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods()));
+ if (!cached) {
+ CACHE.put(signature, method);
+ }
+ return method;
+ }
+
+ /**
+ * Finds public non-static method
+ * that is accessible from public class.
+ *
+ * @param type the class that can have method
+ * @param name the name of method to find
+ * @param args parameter types that is used to find method
+ * @return object that represents found method
+ * @throws NoSuchMethodException if method could not be found
+ * or some methods are found
+ */
+ public static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) throws NoSuchMethodException {
+ Method method = findMethod(type, name, args);
+ if (Modifier.isStatic(method.getModifiers())) {
+ throw new NoSuchMethodException("Method '" + name + "' is static");
+ }
+ return method;
+ }
+
+ /**
+ * Finds public static method
+ * that is accessible from public class.
+ *
+ * @param type the class that can have method
+ * @param name the name of method to find
+ * @param args parameter types that is used to find method
+ * @return object that represents found method
+ * @throws NoSuchMethodException if method could not be found
+ * or some methods are found
+ */
+ public static Method findStaticMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
+ Method method = findMethod(type, name, args);
+ if (!Modifier.isStatic(method.getModifiers())) {
+ throw new NoSuchMethodException("Method '" + name + "' is not static");
+ }
+ return method;
+ }
+
+ /**
+ * Finds method that is accessible from public class or interface through class hierarchy.
+ *
+ * @param method object that represents found method
+ * @return object that represents accessible method
+ * @throws NoSuchMethodException if method is not accessible or is not found
+ * in specified superclass or interface
+ */
+ public static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
+ Class<?> type = method.getDeclaringClass();
+ if (Modifier.isPublic(type.getModifiers()) && isPackageAccessible(type)) {
+ return method;
+ }
+ if (Modifier.isStatic(method.getModifiers())) {
+ throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible");
+ }
+ for (Type generic : type.getGenericInterfaces()) {
+ try {
+ return findAccessibleMethod(method, generic);
+ }
+ catch (NoSuchMethodException exception) {
+ // try to find in superclass or another interface
+ }
+ }
+ return findAccessibleMethod(method, type.getGenericSuperclass());
+ }
+
+ /**
+ * Finds method that accessible from specified class.
+ *
+ * @param method object that represents found method
+ * @param generic generic type that is used to find accessible method
+ * @return object that represents accessible method
+ * @throws NoSuchMethodException if method is not accessible or is not found
+ * in specified superclass or interface
+ */
+ private static Method findAccessibleMethod(Method method, Type generic) throws NoSuchMethodException {
+ String name = method.getName();
+ Class<?>[] params = method.getParameterTypes();
+ if (generic instanceof Class) {
+ Class<?> type = (Class<?>) generic;
+ return findAccessibleMethod(type.getMethod(name, params));
+ }
+ if (generic instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) generic;
+ Class<?> type = (Class<?>) pt.getRawType();
+ for (Method m : type.getMethods()) {
+ if (m.getName().equals(name)) {
+ Class<?>[] pts = m.getParameterTypes();
+ if (pts.length == params.length) {
+ if (Arrays.equals(params, pts)) {
+ return findAccessibleMethod(m);
+ }
+ Type[] gpts = m.getGenericParameterTypes();
+ if (params.length == gpts.length) {
+ if (Arrays.equals(params, TypeResolver.erase(TypeResolver.resolve(pt, gpts)))) {
+ return findAccessibleMethod(m);
+ }
+ }
+ }
+ }
+ }
+ }
+ throw new NoSuchMethodException("Method '" + name + "' is not accessible");
+ }
+
+
+ private final String name;
+
+ /**
+ * Creates method finder with specified array of parameter types.
+ *
+ * @param name the name of method to find
+ * @param args the array of parameter types
+ */
+ private MethodFinder(String name, Class<?>[] args) {
+ super(args);
+ this.name = name;
+ }
+
+ /**
+ * Returns an array of {@code Class} objects
+ * that represent the formal parameter types of the method.
+ * Returns an empty array if the method takes no parameters.
+ *
+ * @param method the object that represents method
+ * @return the parameter types of the method
+ */
+ @Override
+ protected Class<?>[] getParameters(Method method) {
+ return method.getParameterTypes();
+ }
+
+ /**
+ * Returns {@code true} if and only if the method
+ * was declared to take a variable number of arguments.
+ *
+ * @param method the object that represents method
+ * @return {@code true} if the method was declared
+ * to take a variable number of arguments;
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isVarArgs(Method method) {
+ return method.isVarArgs();
+ }
+
+ /**
+ * Checks validness of the method.
+ * The valid method should be public and
+ * should have the specified name.
+ *
+ * @param method the object that represents method
+ * @return {@code true} if the method is valid,
+ * {@code false} otherwise
+ */
+ @Override
+ protected boolean isValid(Method method) {
+ return super.isValid(method) && method.getName().equals(this.name);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/PersistenceDelegateFinder.java b/ojluni/src/main/java/com/sun/beans/finder/PersistenceDelegateFinder.java
new file mode 100755
index 0000000..b29bbc9
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/PersistenceDelegateFinder.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import java.beans.PersistenceDelegate;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is utility class that provides functionality
+ * to find a {@link PersistenceDelegate} for a JavaBean specified by its type.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class PersistenceDelegateFinder
+ extends InstanceFinder<PersistenceDelegate> {
+
+ private final Map<Class<?>, PersistenceDelegate> registry;
+
+ public PersistenceDelegateFinder() {
+ super(PersistenceDelegate.class, true, "PersistenceDelegate");
+ this.registry = new HashMap<Class<?>, PersistenceDelegate>();
+ }
+
+ public void register(Class<?> type, PersistenceDelegate delegate) {
+ synchronized (this.registry) {
+ if (delegate != null) {
+ this.registry.put(type, delegate);
+ }
+ else {
+ this.registry.remove(type);
+ }
+ }
+ }
+
+ @Override
+ public PersistenceDelegate find(Class<?> type) {
+ PersistenceDelegate delegate;
+ synchronized (this.registry) {
+ delegate = this.registry.get(type);
+ }
+ return (delegate != null) ? delegate : super.find(type);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/PrimitiveTypeMap.java b/ojluni/src/main/java/com/sun/beans/finder/PrimitiveTypeMap.java
new file mode 100755
index 0000000..55f30d9
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/PrimitiveTypeMap.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This utility class associates
+ * name of primitive type with appropriate class.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class PrimitiveTypeMap {
+
+ /**
+ * Returns primitive type class by its name.
+ *
+ * @param name the name of primitive type
+ * @return found primitive type class,
+ * or {@code null} if not found
+ */
+ static Class<?> getType(String name) {
+ return map.get(name);
+ }
+
+ private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
+
+ static {
+ map.put(boolean.class.getName(), boolean.class);
+ map.put(char.class.getName(), char.class);
+ map.put(byte.class.getName(), byte.class);
+ map.put(short.class.getName(), short.class);
+ map.put(int.class.getName(), int.class);
+ map.put(long.class.getName(), long.class);
+ map.put(float.class.getName(), float.class);
+ map.put(double.class.getName(), double.class);
+ map.put(void.class.getName(), void.class);
+ }
+
+ /**
+ * Disable instantiation.
+ */
+ private PrimitiveTypeMap() {
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/PrimitiveWrapperMap.java b/ojluni/src/main/java/com/sun/beans/finder/PrimitiveWrapperMap.java
new file mode 100755
index 0000000..31b816c
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/PrimitiveWrapperMap.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This utility class associates
+ * name of primitive type with appropriate wrapper.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class PrimitiveWrapperMap {
+
+ /**
+ * Replaces all primitive types in specified array with wrappers.
+ *
+ * @param types array of classes where all primitive types
+ * will be replaced by appropriate wrappers
+ */
+ static void replacePrimitivesWithWrappers(Class<?>[] types) {
+ for (int i = 0; i < types.length; i++) {
+ if (types[i] != null) {
+ if (types[i].isPrimitive()) {
+ types[i] = getType(types[i].getName());
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns wrapper for primitive type by its name.
+ *
+ * @param name the name of primitive type
+ * @return found wrapper for primitive type,
+ * or {@code null} if not found
+ */
+ public static Class<?> getType(String name) {
+ return map.get(name);
+ }
+
+ private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
+
+ static {
+ map.put(Boolean.TYPE.getName(), Boolean.class);
+ map.put(Character.TYPE.getName(), Character.class);
+ map.put(Byte.TYPE.getName(), Byte.class);
+ map.put(Short.TYPE.getName(), Short.class);
+ map.put(Integer.TYPE.getName(), Integer.class);
+ map.put(Long.TYPE.getName(), Long.class);
+ map.put(Float.TYPE.getName(), Float.class);
+ map.put(Double.TYPE.getName(), Double.class);
+ map.put(Void.TYPE.getName(), Void.class);
+ }
+
+ /**
+ * Disable instantiation.
+ */
+ private PrimitiveWrapperMap() {
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/PropertyEditorFinder.java b/ojluni/src/main/java/com/sun/beans/finder/PropertyEditorFinder.java
new file mode 100755
index 0000000..c4097cc
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/PropertyEditorFinder.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+import com.sun.beans.WeakCache;
+
+import java.beans.PropertyEditor;
+
+import com.sun.beans.editors.BooleanEditor;
+import com.sun.beans.editors.ByteEditor;
+import com.sun.beans.editors.DoubleEditor;
+import com.sun.beans.editors.EnumEditor;
+import com.sun.beans.editors.FloatEditor;
+import com.sun.beans.editors.IntegerEditor;
+import com.sun.beans.editors.LongEditor;
+import com.sun.beans.editors.ShortEditor;
+
+/**
+ * This is utility class that provides functionality
+ * to find a {@link PropertyEditor} for a JavaBean specified by its type.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+public final class PropertyEditorFinder
+ extends InstanceFinder<PropertyEditor> {
+
+ private static final String DEFAULT = "sun.beans.editors";
+ private static final String DEFAULT_NEW = "com.sun.beans.editors";
+
+ private final WeakCache<Class<?>, Class<?>> registry;
+
+ public PropertyEditorFinder() {
+ super(PropertyEditor.class, false, "Editor", DEFAULT);
+
+ this.registry = new WeakCache<Class<?>, Class<?>>();
+ this.registry.put(Byte.TYPE, ByteEditor.class);
+ this.registry.put(Short.TYPE, ShortEditor.class);
+ this.registry.put(Integer.TYPE, IntegerEditor.class);
+ this.registry.put(Long.TYPE, LongEditor.class);
+ this.registry.put(Boolean.TYPE, BooleanEditor.class);
+ this.registry.put(Float.TYPE, FloatEditor.class);
+ this.registry.put(Double.TYPE, DoubleEditor.class);
+ }
+
+ public void register(Class<?> type, Class<?> editor) {
+ synchronized (this.registry) {
+ this.registry.put(type, editor);
+ }
+ }
+
+ @Override
+ public PropertyEditor find(Class<?> type) {
+ Class<?> predefined;
+ synchronized (this.registry) {
+ predefined = this.registry.get(type);
+ }
+ PropertyEditor editor = instantiate(predefined, null);
+ if (editor == null) {
+ editor = super.find(type);
+ if ((editor == null) && (null != type.getEnumConstants())) {
+ editor = new EnumEditor(type);
+ }
+ }
+ return editor;
+ }
+
+ @Override
+ protected PropertyEditor instantiate(Class<?> type, String prefix, String name) {
+ return super.instantiate(type, DEFAULT.equals(prefix) ? DEFAULT_NEW : prefix, name);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/finder/Signature.java b/ojluni/src/main/java/com/sun/beans/finder/Signature.java
new file mode 100755
index 0000000..9e169b6
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/finder/Signature.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.beans.finder;
+
+/**
+ * This class is designed to be a key of a cache
+ * of constructors or methods.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class Signature {
+ private final Class<?> type;
+ private final String name;
+ private final Class<?>[] args;
+
+ private volatile int code;
+
+ /**
+ * Constructs signature for constructor.
+ *
+ * @param type the class that contains constructor
+ * @param args the types of constructor's parameters
+ */
+ Signature(Class<?> type, Class<?>[] args) {
+ this(type, null, args);
+ }
+
+ /**
+ * Constructs signature for method.
+ *
+ * @param type the class that contains method
+ * @param name the name of the method
+ * @param args the types of method's parameters
+ */
+ Signature(Class<?> type, String name, Class<?>[] args) {
+ this.type = type;
+ this.name = name;
+ this.args = args;
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ *
+ * @param object the reference object with which to compare
+ * @return {@code true} if this object is the same as the
+ * {@code object} argument, {@code false} otherwise
+ * @see #hashCode()
+ */
+ @Override
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+ if (object instanceof Signature) {
+ Signature signature = (Signature) object;
+ return isEqual(signature.type, this.type)
+ && isEqual(signature.name, this.name)
+ && isEqual(signature.args, this.args);
+ }
+ return false;
+ }
+
+ /**
+ * Indicates whether some object is "equal to" another one.
+ * This method supports {@code null} values.
+ *
+ * @param obj1 the first reference object that will compared
+ * @param obj2 the second reference object that will compared
+ * @return {@code true} if first object is the same as the second object,
+ * {@code false} otherwise
+ */
+ private static boolean isEqual(Object obj1, Object obj2) {
+ return (obj1 == null)
+ ? obj2 == null
+ : obj1.equals(obj2);
+ }
+
+ /**
+ * Indicates whether some array is "equal to" another one.
+ * This method supports {@code null} values.
+ *
+ * @param args1 the first reference array that will compared
+ * @param args2 the second reference array that will compared
+ * @return {@code true} if first array is the same as the second array,
+ * {@code false} otherwise
+ */
+ private static boolean isEqual(Class<?>[] args1, Class<?>[] args2) {
+ if ((args1 == null) || (args2 == null)) {
+ return args1 == args2;
+ }
+ if (args1.length != args2.length) {
+ return false;
+ }
+ for (int i = 0; i < args1.length; i++) {
+ if (!isEqual(args1[i], args2[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ * This method is supported for the benefit of hashtables
+ * such as {@link java.util.HashMap} or {@link java.util.HashSet}.
+ * Hash code computed using algorithm
+ * suggested in Effective Java, Item 8.
+ *
+ * @return a hash code value for this object
+ * @see #equals(Object)
+ */
+ @Override
+ public int hashCode() {
+ if (this.code == 0) {
+ int code = 17;
+ code = addHashCode(code, this.type);
+ code = addHashCode(code, this.name);
+
+ if (this.args != null) {
+ for (Class<?> arg : this.args) {
+ code = addHashCode(code, arg);
+ }
+ }
+ this.code = code;
+ }
+ return this.code;
+ }
+
+ /**
+ * Adds hash code value if specified object.
+ * This is a part of the algorithm
+ * suggested in Effective Java, Item 8.
+ *
+ * @param code current hash code value
+ * @param object object that updates hash code value
+ * @return updated hash code value
+ * @see #hashCode()
+ */
+ private static int addHashCode(int code, Object object) {
+ code *= 37;
+ return (object != null)
+ ? code + object.hashCode()
+ : code;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/beans/infos/ComponentBeanInfo.java b/ojluni/src/main/java/com/sun/beans/infos/ComponentBeanInfo.java
new file mode 100755
index 0000000..9f1e2a7
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/beans/infos/ComponentBeanInfo.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.beans.infos;
+
+import java.beans.*;
+
+/**
+ * BeanInfo descriptor for a standard AWT component.
+ */
+
+public class ComponentBeanInfo extends SimpleBeanInfo {
+ private static final Class beanClass = java.awt.Component.class;
+
+ public PropertyDescriptor[] getPropertyDescriptors() {
+ try {
+ PropertyDescriptor
+ name = new PropertyDescriptor("name", beanClass),
+ background = new PropertyDescriptor("background", beanClass),
+ foreground = new PropertyDescriptor("foreground", beanClass),
+ font = new PropertyDescriptor("font", beanClass),
+ enabled = new PropertyDescriptor("enabled", beanClass),
+ visible = new PropertyDescriptor("visible", beanClass),
+ focusable = new PropertyDescriptor("focusable", beanClass);
+
+ enabled.setExpert(true);
+ visible.setHidden(true);
+
+ background.setBound(true);
+ foreground.setBound(true);
+ font.setBound(true);
+ focusable.setBound(true);
+
+ PropertyDescriptor[] rv = {name, background, foreground, font, enabled, visible, focusable };
+ return rv;
+ } catch (IntrospectionException e) {
+ throw new Error(e.toString());
+ }
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/AESCipher.java b/ojluni/src/main/java/com/sun/crypto/provider/AESCipher.java
new file mode 100755
index 0000000..3c3ef22
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/AESCipher.java
@@ -0,0 +1,427 @@
+/*
+ * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.*;
+import java.security.spec.*;
+import javax.crypto.*;
+import javax.crypto.spec.*;
+import javax.crypto.BadPaddingException;
+
+/**
+ * This class implements the AES algorithm in its various modes
+ * (<code>ECB</code>, <code>CFB</code>, <code>OFB</code>, <code>CBC</code>,
+ * <code>PCBC</code>) and padding schemes (<code>PKCS5Padding</code>,
+ * <code>NoPadding</code>, <code>ISO10126Padding</code>).
+ *
+ * @author Valerie Peng
+ *
+ *
+ * @see AESCrypt
+ * @see CipherBlockChaining
+ * @see ElectronicCodeBook
+ * @see CipherFeedback
+ * @see OutputFeedback
+ */
+
+public final class AESCipher extends CipherSpi {
+ /*
+ * internal CipherCore object which does the real work.
+ */
+ private CipherCore core = null;
+
+ /**
+ * Creates an instance of AES cipher with default ECB mode and
+ * PKCS5Padding.
+ */
+ public AESCipher() {
+ core = new CipherCore(new AESCrypt(), AESConstants.AES_BLOCK_SIZE);
+ }
+
+ /**
+ * Sets the mode of this cipher.
+ *
+ * @param mode the cipher mode
+ *
+ * @exception NoSuchAlgorithmException if the requested cipher mode does
+ * not exist
+ */
+ protected void engineSetMode(String mode)
+ throws NoSuchAlgorithmException {
+ core.setMode(mode);
+ }
+
+ /**
+ * Sets the padding mechanism of this cipher.
+ *
+ * @param padding the padding mechanism
+ *
+ * @exception NoSuchPaddingException if the requested padding mechanism
+ * does not exist
+ */
+ protected void engineSetPadding(String paddingScheme)
+ throws NoSuchPaddingException {
+ core.setPadding(paddingScheme);
+ }
+
+ /**
+ * Returns the block size (in bytes).
+ *
+ * @return the block size (in bytes), or 0 if the underlying algorithm is
+ * not a block cipher
+ */
+ protected int engineGetBlockSize() {
+ return AESConstants.AES_BLOCK_SIZE;
+ }
+
+ /**
+ * Returns the length in bytes that an output buffer would need to be in
+ * order to hold the result of the next <code>update</code> or
+ * <code>doFinal</code> operation, given the input length
+ * <code>inputLen</code> (in bytes).
+ *
+ * <p>This call takes into account any unprocessed (buffered) data from a
+ * previous <code>update</code> call, and padding.
+ *
+ * <p>The actual output length of the next <code>update</code> or
+ * <code>doFinal</code> call may be smaller than the length returned by
+ * this method.
+ *
+ * @param inputLen the input length (in bytes)
+ *
+ * @return the required output buffer size (in bytes)
+ */
+ protected int engineGetOutputSize(int inputLen) {
+ return core.getOutputSize(inputLen);
+ }
+
+ /**
+ * Returns the initialization vector (IV) in a new buffer.
+ *
+ * <p>This is useful in the case where a random IV has been created
+ * (see <a href = "#init">init</a>),
+ * or in the context of password-based encryption or
+ * decryption, where the IV is derived from a user-provided password.
+ *
+ * @return the initialization vector in a new buffer, or null if the
+ * underlying algorithm does not use an IV, or if the IV has not yet
+ * been set.
+ */
+ protected byte[] engineGetIV() {
+ return core.getIV();
+ }
+
+ /**
+ * Returns the parameters used with this cipher.
+ *
+ * <p>The returned parameters may be the same that were used to initialize
+ * this cipher, or may contain the default set of parameters or a set of
+ * randomly generated parameters used by the underlying cipher
+ * implementation (provided that the underlying cipher implementation
+ * uses a default set of parameters or creates new parameters if it needs
+ * parameters but was not initialized with any).
+ *
+ * @return the parameters used with this cipher, or null if this cipher
+ * does not use any parameters.
+ */
+ protected AlgorithmParameters engineGetParameters() {
+ return core.getParameters("AES");
+ }
+
+ /**
+ * Initializes this cipher with a key and a source of randomness.
+ *
+ * <p>The cipher is initialized for one of the following four operations:
+ * encryption, decryption, key wrapping or key unwrapping, depending on
+ * the value of <code>opmode</code>.
+ *
+ * <p>If this cipher requires an initialization vector (IV), it will get
+ * it from <code>random</code>.
+ * This behaviour should only be used in encryption or key wrapping
+ * mode, however.
+ * When initializing a cipher that requires an IV for decryption or
+ * key unwrapping, the IV
+ * (same IV that was used for encryption or key wrapping) must be provided
+ * explicitly as a
+ * parameter, in order to get the correct result.
+ *
+ * <p>This method also cleans existing buffer and other related state
+ * information.
+ *
+ * @param opmode the operation mode of this cipher (this is one of
+ * the following:
+ * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>,
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>)
+ * @param key the secret key
+ * @param random the source of randomness
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ */
+ protected void engineInit(int opmode, Key key, SecureRandom random)
+ throws InvalidKeyException {
+ core.init(opmode, key, random);
+ }
+
+ /**
+ * Initializes this cipher with a key, a set of
+ * algorithm parameters, and a source of randomness.
+ *
+ * <p>The cipher is initialized for one of the following four operations:
+ * encryption, decryption, key wrapping or key unwrapping, depending on
+ * the value of <code>opmode</code>.
+ *
+ * <p>If this cipher (including its underlying feedback or padding scheme)
+ * requires any random bytes, it will get them from <code>random</code>.
+ *
+ * @param opmode the operation mode of this cipher (this is one of
+ * the following:
+ * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>,
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>)
+ * @param key the encryption key
+ * @param params the algorithm parameters
+ * @param random the source of randomness
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ * @exception InvalidAlgorithmParameterException if the given algorithm
+ * parameters are inappropriate for this cipher
+ */
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameterSpec params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ core.init(opmode, key, params, random);
+ }
+
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameters params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ core.init(opmode, key, params, random);
+ }
+
+ /**
+ * Continues a multiple-part encryption or decryption operation
+ * (depending on how this cipher was initialized), processing another data
+ * part.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, are processed, and the
+ * result is stored in a new buffer.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ *
+ * @return the new buffer with the result
+ *
+ * @exception IllegalStateException if this cipher is in a wrong state
+ * (e.g., has not been initialized)
+ */
+ protected byte[] engineUpdate(byte[] input, int inputOffset,
+ int inputLen) {
+ return core.update(input, inputOffset, inputLen);
+ }
+
+ /**
+ * Continues a multiple-part encryption or decryption operation
+ * (depending on how this cipher was initialized), processing another data
+ * part.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, are processed, and the
+ * result is stored in the <code>output</code> buffer, starting at
+ * <code>outputOffset</code>.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ * @param output the buffer for the result
+ * @param outputOffset the offset in <code>output</code> where the result
+ * is stored
+ *
+ * @return the number of bytes stored in <code>output</code>
+ *
+ * @exception ShortBufferException if the given output buffer is too small
+ * to hold the result
+ */
+ protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
+ byte[] output, int outputOffset)
+ throws ShortBufferException {
+ return core.update(input, inputOffset, inputLen, output,
+ outputOffset);
+ }
+
+ /**
+ * Encrypts or decrypts data in a single-part operation,
+ * or finishes a multiple-part operation.
+ * The data is encrypted or decrypted, depending on how this cipher was
+ * initialized.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, and any input bytes that
+ * may have been buffered during a previous <code>update</code> operation,
+ * are processed, with padding (if requested) being applied.
+ * The result is stored in a new buffer.
+ *
+ * <p>The cipher is reset to its initial state (uninitialized) after this
+ * call.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ *
+ * @return the new buffer with the result
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block cipher,
+ * no padding has been requested (only in encryption mode), and the total
+ * input length of the data processed by this cipher is not a multiple of
+ * block size
+ * @exception BadPaddingException if this cipher is in decryption mode,
+ * and (un)padding has been requested, but the decrypted data is not
+ * bounded by the appropriate padding bytes
+ */
+ protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
+ throws IllegalBlockSizeException, BadPaddingException {
+ return core.doFinal(input, inputOffset, inputLen);
+ }
+
+ /**
+ * Encrypts or decrypts data in a single-part operation,
+ * or finishes a multiple-part operation.
+ * The data is encrypted or decrypted, depending on how this cipher was
+ * initialized.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, and any input bytes that
+ * may have been buffered during a previous <code>update</code> operation,
+ * are processed, with padding (if requested) being applied.
+ * The result is stored in the <code>output</code> buffer, starting at
+ * <code>outputOffset</code>.
+ *
+ * <p>The cipher is reset to its initial state (uninitialized) after this
+ * call.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ * @param output the buffer for the result
+ * @param outputOffset the offset in <code>output</code> where the result
+ * is stored
+ *
+ * @return the number of bytes stored in <code>output</code>
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block cipher,
+ * no padding has been requested (only in encryption mode), and the total
+ * input length of the data processed by this cipher is not a multiple of
+ * block size
+ * @exception ShortBufferException if the given output buffer is too small
+ * to hold the result
+ * @exception BadPaddingException if this cipher is in decryption mode,
+ * and (un)padding has been requested, but the decrypted data is not
+ * bounded by the appropriate padding bytes
+ */
+ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
+ byte[] output, int outputOffset)
+ throws IllegalBlockSizeException, ShortBufferException,
+ BadPaddingException {
+ return core.doFinal(input, inputOffset, inputLen, output,
+ outputOffset);
+ }
+
+ /**
+ * Returns the key size of the given key object.
+ *
+ * @param key the key object.
+ *
+ * @return the key size of the given key object.
+ *
+ * @exception InvalidKeyException if <code>key</code> is invalid.
+ */
+ protected int engineGetKeySize(Key key) throws InvalidKeyException {
+ byte[] encoded = key.getEncoded();
+ if (!AESCrypt.isKeySizeValid(encoded.length)) {
+ throw new InvalidKeyException("Invalid AES key length: " +
+ encoded.length + " bytes");
+ }
+ return encoded.length * 8;
+ }
+
+ /**
+ * Wrap a key.
+ *
+ * @param key the key to be wrapped.
+ *
+ * @return the wrapped key.
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block
+ * cipher, no padding has been requested, and the length of the
+ * encoding of the key to be wrapped is not a
+ * multiple of the block size.
+ *
+ * @exception InvalidKeyException if it is impossible or unsafe to
+ * wrap the key with this cipher (e.g., a hardware protected key is
+ * being passed to a software only cipher).
+ */
+ protected byte[] engineWrap(Key key)
+ throws IllegalBlockSizeException, InvalidKeyException {
+ return core.wrap(key);
+ }
+
+ /**
+ * Unwrap a previously wrapped key.
+ *
+ * @param wrappedKey the key to be unwrapped.
+ *
+ * @param wrappedKeyAlgorithm the algorithm the wrapped key is for.
+ *
+ * @param wrappedKeyType the type of the wrapped key.
+ * This is one of <code>Cipher.SECRET_KEY</code>,
+ * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>.
+ *
+ * @return the unwrapped key.
+ *
+ * @exception NoSuchAlgorithmException if no installed providers
+ * can create keys of type <code>wrappedKeyType</code> for the
+ * <code>wrappedKeyAlgorithm</code>.
+ *
+ * @exception InvalidKeyException if <code>wrappedKey</code> does not
+ * represent a wrapped key of type <code>wrappedKeyType</code> for
+ * the <code>wrappedKeyAlgorithm</code>.
+ */
+ protected Key engineUnwrap(byte[] wrappedKey,
+ String wrappedKeyAlgorithm,
+ int wrappedKeyType)
+ throws InvalidKeyException, NoSuchAlgorithmException {
+ return core.unwrap(wrappedKey, wrappedKeyAlgorithm,
+ wrappedKeyType);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/AESConstants.java b/ojluni/src/main/java/com/sun/crypto/provider/AESConstants.java
new file mode 100755
index 0000000..0b59311
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/AESConstants.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+/**
+ * This class defines the constants used by the AES implementation.
+ *
+ * @author Valerie Peng
+ *
+ *
+ * @see AESCipher
+ */
+
+interface AESConstants {
+
+ // AES block size in bytes.
+ int AES_BLOCK_SIZE = 16;
+
+ // Valid AES key sizes in bytes.
+ // NOTE: The values need to be listed in an *increasing* order
+ // since DHKeyAgreement depends on this fact.
+ int[] AES_KEYSIZES = { 16, 24, 32 };
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/AESCrypt.java b/ojluni/src/main/java/com/sun/crypto/provider/AESCrypt.java
new file mode 100755
index 0000000..0522ab8
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/AESCrypt.java
@@ -0,0 +1,677 @@
+/*
+ * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* $Id: Rijndael.java,v 1.6 2000/02/10 01:31:41 gelderen Exp $
+ *
+ * Copyright (C) 1995-2000 The Cryptix Foundation Limited.
+ * All rights reserved.
+ *
+ * Use, modification, copying and distribution of this softwareas is subject
+ * the terms and conditions of the Cryptix General Licence. You should have
+ * received a copy of the Cryptix General Licence along with this library;
+ * if not, you can download a copy from http://www.cryptix.org/ .
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.InvalidKeyException;
+import java.util.Arrays;
+
+/**
+ * Rijndael --pronounced Reindaal-- is a symmetric cipher with a 128-bit
+ * block size and variable key-size (128-, 192- and 256-bit).
+ * <p>
+ * Rijndael was designed by <a href="mailto:rijmen@esat.kuleuven.ac.be">Vincent
+ * Rijmen</a> and <a href="mailto:Joan.Daemen@village.uunet.be">Joan Daemen</a>.
+ */
+final class AESCrypt extends SymmetricCipher implements AESConstants
+{
+ private boolean ROUNDS_12 = false;
+ private boolean ROUNDS_14 = false;
+
+ /** Session and Sub keys */
+ private Object[] sessionK = null;
+ private int[] K = null;
+
+ /** Cipher encryption/decryption key */
+ // skip re-generating Session and Sub keys if the cipher key is
+ // the same
+ private byte[] lastKey = null;
+
+ /** ROUNDS * 4 */
+ private int limit = 0;
+
+ AESCrypt() {
+ // empty
+ }
+
+ /**
+ * Returns this cipher's block size.
+ *
+ * @return this cipher's block size
+ */
+ int getBlockSize() {
+ return AES_BLOCK_SIZE;
+ }
+
+ void init(boolean decrypting, String algorithm, byte[] key)
+ throws InvalidKeyException {
+ if (!algorithm.equalsIgnoreCase("AES")
+ && !algorithm.equalsIgnoreCase("Rijndael")) {
+ throw new InvalidKeyException
+ ("Wrong algorithm: AES or Rijndael required");
+ }
+ if (!isKeySizeValid(key.length)) {
+ throw new InvalidKeyException("Invalid AES key length: " +
+ key.length + " bytes");
+ }
+
+ if (!Arrays.equals(key, lastKey)) {
+ // re-generate session key 'sessionK' when cipher key changes
+ makeSessionKey(key);
+ lastKey = key.clone(); // save cipher key
+ }
+
+ // set sub key to the corresponding session Key
+ this.K = (int[]) sessionK[(decrypting? 1:0)];
+ }
+
+ /**
+ * Expand an int[(ROUNDS+1)][4] into int[(ROUNDS+1)*4].
+ * For decryption round keys, need to rotate right by 4 ints.
+ * @param kr The round keys for encryption or decryption.
+ * @param decrypting True if 'kr' is for decryption and false otherwise.
+ */
+ private static final int[] expandToSubKey(int[][] kr, boolean decrypting) {
+ int total = kr.length;
+ int[] expK = new int[total*4];
+ if (decrypting) {
+ // decrypting, rotate right by 4 ints
+ // i.e. i==0
+ for(int j=0; j<4; j++) {
+ expK[j] = kr[total-1][j];
+ }
+ for(int i=1; i<total; i++) {
+ for(int j=0; j<4; j++) {
+ expK[i*4 + j] = kr[i-1][j];
+ }
+ }
+ } else {
+ // encrypting, straight expansion
+ for(int i=0; i<total; i++) {
+ for(int j=0; j<4; j++) {
+ expK[i*4 + j] = kr[i][j];
+ }
+ }
+ }
+ return expK;
+ }
+
+ private static int[]
+ alog = new int[256],
+ log = new int[256];
+
+ private static final byte[]
+ S = new byte[256],
+ Si = new byte[256];
+
+ private static final int[]
+ T1 = new int[256],
+ T2 = new int[256],
+ T3 = new int[256],
+ T4 = new int[256],
+ T5 = new int[256],
+ T6 = new int[256],
+ T7 = new int[256],
+ T8 = new int[256];
+
+ private static final int[]
+ U1 = new int[256],
+ U2 = new int[256],
+ U3 = new int[256],
+ U4 = new int[256];
+
+ private static final byte[] rcon = new byte[30];
+
+
+ // Static code - to intialise S-boxes and T-boxes
+ static
+ {
+ int ROOT = 0x11B;
+ int i, j = 0;
+
+ //
+ // produce log and alog tables, needed for multiplying in the
+ // field GF(2^m) (generator = 3)
+ //
+ alog[0] = 1;
+ for (i = 1; i < 256; i++)
+ {
+ j = (alog[i-1] << 1) ^ alog[i-1];
+ if ((j & 0x100) != 0) {
+ j ^= ROOT;
+ }
+ alog[i] = j;
+ }
+ for (i = 1; i < 255; i++) {
+ log[alog[i]] = i;
+ }
+ byte[][] A = new byte[][]
+ {
+ {1, 1, 1, 1, 1, 0, 0, 0},
+ {0, 1, 1, 1, 1, 1, 0, 0},
+ {0, 0, 1, 1, 1, 1, 1, 0},
+ {0, 0, 0, 1, 1, 1, 1, 1},
+ {1, 0, 0, 0, 1, 1, 1, 1},
+ {1, 1, 0, 0, 0, 1, 1, 1},
+ {1, 1, 1, 0, 0, 0, 1, 1},
+ {1, 1, 1, 1, 0, 0, 0, 1}
+ };
+ byte[] B = new byte[] { 0, 1, 1, 0, 0, 0, 1, 1};
+
+ //
+ // substitution box based on F^{-1}(x)
+ //
+ int t;
+ byte[][] box = new byte[256][8];
+ box[1][7] = 1;
+ for (i = 2; i < 256; i++) {
+ j = alog[255 - log[i]];
+ for (t = 0; t < 8; t++) {
+ box[i][t] = (byte)((j >>> (7 - t)) & 0x01);
+ }
+ }
+ //
+ // affine transform: box[i] <- B + A*box[i]
+ //
+ byte[][] cox = new byte[256][8];
+ for (i = 0; i < 256; i++) {
+ for (t = 0; t < 8; t++) {
+ cox[i][t] = B[t];
+ for (j = 0; j < 8; j++) {
+ cox[i][t] ^= A[t][j] * box[i][j];
+ }
+ }
+ }
+ //
+ // S-boxes and inverse S-boxes
+ //
+ for (i = 0; i < 256; i++) {
+ S[i] = (byte)(cox[i][0] << 7);
+ for (t = 1; t < 8; t++) {
+ S[i] ^= cox[i][t] << (7-t);
+ }
+ Si[S[i] & 0xFF] = (byte) i;
+ }
+ //
+ // T-boxes
+ //
+ byte[][] G = new byte[][] {
+ {2, 1, 1, 3},
+ {3, 2, 1, 1},
+ {1, 3, 2, 1},
+ {1, 1, 3, 2}
+ };
+ byte[][] AA = new byte[4][8];
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) AA[i][j] = G[i][j];
+ AA[i][i+4] = 1;
+ }
+ byte pivot, tmp;
+ byte[][] iG = new byte[4][4];
+ for (i = 0; i < 4; i++) {
+ pivot = AA[i][i];
+ if (pivot == 0) {
+ t = i + 1;
+ while ((AA[t][i] == 0) && (t < 4)) {
+ t++;
+ }
+ if (t == 4) {
+ throw new RuntimeException("G matrix is not invertible");
+ }
+ else {
+ for (j = 0; j < 8; j++) {
+ tmp = AA[i][j];
+ AA[i][j] = AA[t][j];
+ AA[t][j] = (byte) tmp;
+ }
+ pivot = AA[i][i];
+ }
+ }
+ for (j = 0; j < 8; j++) {
+ if (AA[i][j] != 0) {
+ AA[i][j] = (byte)
+ alog[(255 + log[AA[i][j] & 0xFF] - log[pivot & 0xFF])
+ % 255];
+ }
+ }
+ for (t = 0; t < 4; t++) {
+ if (i != t) {
+ for (j = i+1; j < 8; j++) {
+ AA[t][j] ^= mul(AA[i][j], AA[t][i]);
+ }
+ AA[t][i] = 0;
+ }
+ }
+ }
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ iG[i][j] = AA[i][j + 4];
+ }
+ }
+
+ int s;
+ for (t = 0; t < 256; t++) {
+ s = S[t];
+ T1[t] = mul4(s, G[0]);
+ T2[t] = mul4(s, G[1]);
+ T3[t] = mul4(s, G[2]);
+ T4[t] = mul4(s, G[3]);
+
+ s = Si[t];
+ T5[t] = mul4(s, iG[0]);
+ T6[t] = mul4(s, iG[1]);
+ T7[t] = mul4(s, iG[2]);
+ T8[t] = mul4(s, iG[3]);
+
+ U1[t] = mul4(t, iG[0]);
+ U2[t] = mul4(t, iG[1]);
+ U3[t] = mul4(t, iG[2]);
+ U4[t] = mul4(t, iG[3]);
+ }
+ //
+ // round constants
+ //
+ rcon[0] = 1;
+ int r = 1;
+ for (t = 1; t < 30; t++) {
+ r = mul(2, r);
+ rcon[t] = (byte) r;
+ }
+ log = null;
+ alog = null;
+ }
+
+ // multiply two elements of GF(2^m)
+ private static final int mul (int a, int b) {
+ return (a != 0 && b != 0) ?
+ alog[(log[a & 0xFF] + log[b & 0xFF]) % 255] :
+ 0;
+ }
+
+ // convenience method used in generating Transposition boxes
+ private static final int mul4 (int a, byte[] b) {
+ if (a == 0) return 0;
+ a = log[a & 0xFF];
+ int a0 = (b[0] != 0) ? alog[(a + log[b[0] & 0xFF]) % 255] & 0xFF : 0;
+ int a1 = (b[1] != 0) ? alog[(a + log[b[1] & 0xFF]) % 255] & 0xFF : 0;
+ int a2 = (b[2] != 0) ? alog[(a + log[b[2] & 0xFF]) % 255] & 0xFF : 0;
+ int a3 = (b[3] != 0) ? alog[(a + log[b[3] & 0xFF]) % 255] & 0xFF : 0;
+ return a0 << 24 | a1 << 16 | a2 << 8 | a3;
+ }
+
+ // check if the specified length (in bytes) is a valid keysize for AES
+ static final boolean isKeySizeValid(int len) {
+ for (int i = 0; i < AES_KEYSIZES.length; i++) {
+ if (len == AES_KEYSIZES[i]) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Encrypt exactly one block of plaintext.
+ */
+ void encryptBlock(byte[] in, int inOffset,
+ byte[] out, int outOffset)
+ {
+ int keyOffset = 0;
+ int t0 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset++] & 0xFF) ) ^ K[keyOffset++];
+ int t1 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset++] & 0xFF) ) ^ K[keyOffset++];
+ int t2 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset++] & 0xFF) ) ^ K[keyOffset++];
+ int t3 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset++] & 0xFF) ) ^ K[keyOffset++];
+
+ // apply round transforms
+ while( keyOffset < limit )
+ {
+ int a0, a1, a2;
+ a0 = T1[(t0 >>> 24) ] ^
+ T2[(t1 >>> 16) & 0xFF] ^
+ T3[(t2 >>> 8) & 0xFF] ^
+ T4[(t3 ) & 0xFF] ^ K[keyOffset++];
+ a1 = T1[(t1 >>> 24) ] ^
+ T2[(t2 >>> 16) & 0xFF] ^
+ T3[(t3 >>> 8) & 0xFF] ^
+ T4[(t0 ) & 0xFF] ^ K[keyOffset++];
+ a2 = T1[(t2 >>> 24) ] ^
+ T2[(t3 >>> 16) & 0xFF] ^
+ T3[(t0 >>> 8) & 0xFF] ^
+ T4[(t1 ) & 0xFF] ^ K[keyOffset++];
+ t3 = T1[(t3 >>> 24) ] ^
+ T2[(t0 >>> 16) & 0xFF] ^
+ T3[(t1 >>> 8) & 0xFF] ^
+ T4[(t2 ) & 0xFF] ^ K[keyOffset++];
+ t0 = a0; t1 = a1; t2 = a2;
+ }
+
+ // last round is special
+ int tt = K[keyOffset++];
+ out[outOffset++] = (byte)(S[(t0 >>> 24) ] ^ (tt >>> 24));
+ out[outOffset++] = (byte)(S[(t1 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[outOffset++] = (byte)(S[(t2 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[outOffset++] = (byte)(S[(t3 ) & 0xFF] ^ (tt ));
+ tt = K[keyOffset++];
+ out[outOffset++] = (byte)(S[(t1 >>> 24) ] ^ (tt >>> 24));
+ out[outOffset++] = (byte)(S[(t2 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[outOffset++] = (byte)(S[(t3 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[outOffset++] = (byte)(S[(t0 ) & 0xFF] ^ (tt ));
+ tt = K[keyOffset++];
+ out[outOffset++] = (byte)(S[(t2 >>> 24) ] ^ (tt >>> 24));
+ out[outOffset++] = (byte)(S[(t3 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[outOffset++] = (byte)(S[(t0 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[outOffset++] = (byte)(S[(t1 ) & 0xFF] ^ (tt ));
+ tt = K[keyOffset++];
+ out[outOffset++] = (byte)(S[(t3 >>> 24) ] ^ (tt >>> 24));
+ out[outOffset++] = (byte)(S[(t0 >>> 16) & 0xFF] ^ (tt >>> 16));
+ out[outOffset++] = (byte)(S[(t1 >>> 8) & 0xFF] ^ (tt >>> 8));
+ out[outOffset ] = (byte)(S[(t2 ) & 0xFF] ^ (tt ));
+ }
+
+
+ /**
+ * Decrypt exactly one block of plaintext.
+ */
+ void decryptBlock(byte[] in, int inOffset,
+ byte[] out, int outOffset)
+ {
+ int keyOffset = 4;
+ int t0 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset++] & 0xFF) ) ^ K[keyOffset++];
+ int t1 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset++] & 0xFF) ) ^ K[keyOffset++];
+ int t2 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset++] & 0xFF) ) ^ K[keyOffset++];
+ int t3 = ((in[inOffset++] ) << 24 |
+ (in[inOffset++] & 0xFF) << 16 |
+ (in[inOffset++] & 0xFF) << 8 |
+ (in[inOffset ] & 0xFF) ) ^ K[keyOffset++];
+
+ int a0, a1, a2;
+ if(ROUNDS_12)
+ {
+ a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++];
+ a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++];
+ a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^
+ T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^
+ T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++];
+ t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++];
+ t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++];
+ t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^
+ T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^
+ T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++];
+
+ if(ROUNDS_14)
+ {
+ a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++];
+ a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++];
+ a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^
+ T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^
+ T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++];
+ t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++];
+ t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++];
+ t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^
+ T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^
+ T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++];
+ }
+ }
+ a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++];
+ a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++];
+ a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^
+ T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^
+ T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++];
+ t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++];
+ t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++];
+ t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^
+ T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^
+ T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++];
+ a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++];
+ a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++];
+ a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^
+ T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^
+ T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++];
+ t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++];
+ t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++];
+ t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^
+ T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^
+ T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++];
+ a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++];
+ a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++];
+ a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^
+ T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^
+ T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++];
+ t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++];
+ t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++];
+ t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^
+ T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^
+ T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++];
+ a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++];
+ a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++];
+ a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^
+ T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^
+ T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++];
+ t0 = T5[(a0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(a2>>> 8)&0xFF] ^ T8[(a1 )&0xFF] ^ K[keyOffset++];
+ t1 = T5[(a1>>>24) ] ^ T6[(a0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(a2 )&0xFF] ^ K[keyOffset++];
+ t2 = T5[(a2>>>24) ] ^ T6[(a1>>>16)&0xFF] ^
+ T7[(a0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(a2>>>16)&0xFF] ^
+ T7[(a1>>> 8)&0xFF] ^ T8[(a0 )&0xFF] ^ K[keyOffset++];
+ a0 = T5[(t0>>>24) ] ^ T6[(t3>>>16)&0xFF] ^
+ T7[(t2>>> 8)&0xFF] ^ T8[(t1 )&0xFF] ^ K[keyOffset++];
+ a1 = T5[(t1>>>24) ] ^ T6[(t0>>>16)&0xFF] ^
+ T7[(t3>>> 8)&0xFF] ^ T8[(t2 )&0xFF] ^ K[keyOffset++];
+ a2 = T5[(t2>>>24) ] ^ T6[(t1>>>16)&0xFF] ^
+ T7[(t0>>> 8)&0xFF] ^ T8[(t3 )&0xFF] ^ K[keyOffset++];
+ t3 = T5[(t3>>>24) ] ^ T6[(t2>>>16)&0xFF] ^
+ T7[(t1>>> 8)&0xFF] ^ T8[(t0 )&0xFF] ^ K[keyOffset++];
+
+ t1 = K[0];
+ out[outOffset++] = (byte)(Si[(a0 >>> 24) ] ^ (t1 >>> 24));
+ out[outOffset++] = (byte)(Si[(t3 >>> 16) & 0xFF] ^ (t1 >>> 16));
+ out[outOffset++] = (byte)(Si[(a2 >>> 8) & 0xFF] ^ (t1 >>> 8));
+ out[outOffset++] = (byte)(Si[(a1 ) & 0xFF] ^ (t1 ));
+ t1 = K[1];
+ out[outOffset++] = (byte)(Si[(a1 >>> 24) ] ^ (t1 >>> 24));
+ out[outOffset++] = (byte)(Si[(a0 >>> 16) & 0xFF] ^ (t1 >>> 16));
+ out[outOffset++] = (byte)(Si[(t3 >>> 8) & 0xFF] ^ (t1 >>> 8));
+ out[outOffset++] = (byte)(Si[(a2 ) & 0xFF] ^ (t1 ));
+ t1 = K[2];
+ out[outOffset++] = (byte)(Si[(a2 >>> 24) ] ^ (t1 >>> 24));
+ out[outOffset++] = (byte)(Si[(a1 >>> 16) & 0xFF] ^ (t1 >>> 16));
+ out[outOffset++] = (byte)(Si[(a0 >>> 8) & 0xFF] ^ (t1 >>> 8));
+ out[outOffset++] = (byte)(Si[(t3 ) & 0xFF] ^ (t1 ));
+ t1 = K[3];
+ out[outOffset++] = (byte)(Si[(t3 >>> 24) ] ^ (t1 >>> 24));
+ out[outOffset++] = (byte)(Si[(a2 >>> 16) & 0xFF] ^ (t1 >>> 16));
+ out[outOffset++] = (byte)(Si[(a1 >>> 8) & 0xFF] ^ (t1 >>> 8));
+ out[outOffset ] = (byte)(Si[(a0 ) & 0xFF] ^ (t1 ));
+ }
+
+
+ /**
+ * Expand a user-supplied key material into a session key.
+ *
+ * @param k The 128/192/256-bit cipher key to use.
+ * @exception InvalidKeyException If the key is invalid.
+ */
+ private void makeSessionKey(byte[] k) throws InvalidKeyException {
+ if (k == null) {
+ throw new InvalidKeyException("Empty key");
+ }
+ if (!isKeySizeValid(k.length)) {
+ throw new InvalidKeyException("Invalid AES key length: " +
+ k.length + " bytes");
+ }
+ int ROUNDS = getRounds(k.length);
+ int ROUND_KEY_COUNT = (ROUNDS + 1) * 4;
+
+ int BC = 4;
+ int[][] Ke = new int[ROUNDS + 1][4]; // encryption round keys
+ int[][] Kd = new int[ROUNDS + 1][4]; // decryption round keys
+
+ int KC = k.length/4; // keylen in 32-bit elements
+
+ int[] tk = new int[KC];
+ int i, j;
+
+ // copy user material bytes into temporary ints
+ for (i = 0, j = 0; i < KC; i++, j+=4) {
+ tk[i] = (k[j] ) << 24 |
+ (k[j+1] & 0xFF) << 16 |
+ (k[j+2] & 0xFF) << 8 |
+ (k[j+3] & 0xFF);
+ }
+
+ // copy values into round key arrays
+ int t = 0;
+ for (j = 0; (j < KC) && (t < ROUND_KEY_COUNT); j++, t++) {
+ Ke[t / 4][t % 4] = tk[j];
+ Kd[ROUNDS - (t / 4)][t % 4] = tk[j];
+ }
+ int tt, rconpointer = 0;
+ while (t < ROUND_KEY_COUNT) {
+ // extrapolate using phi (the round key evolution function)
+ tt = tk[KC - 1];
+ tk[0] ^= (S[(tt >>> 16) & 0xFF] ) << 24 ^
+ (S[(tt >>> 8) & 0xFF] & 0xFF) << 16 ^
+ (S[(tt ) & 0xFF] & 0xFF) << 8 ^
+ (S[(tt >>> 24) ] & 0xFF) ^
+ (rcon[rconpointer++] ) << 24;
+ if (KC != 8)
+ for (i = 1, j = 0; i < KC; i++, j++) tk[i] ^= tk[j];
+ else {
+ for (i = 1, j = 0; i < KC / 2; i++, j++) tk[i] ^= tk[j];
+ tt = tk[KC / 2 - 1];
+ tk[KC / 2] ^= (S[(tt ) & 0xFF] & 0xFF) ^
+ (S[(tt >>> 8) & 0xFF] & 0xFF) << 8 ^
+ (S[(tt >>> 16) & 0xFF] & 0xFF) << 16 ^
+ (S[(tt >>> 24) ] ) << 24;
+ for (j = KC / 2, i = j + 1; i < KC; i++, j++) tk[i] ^= tk[j];
+ }
+ // copy values into round key arrays
+ for (j = 0; (j < KC) && (t < ROUND_KEY_COUNT); j++, t++) {
+ Ke[t / 4][t % 4] = tk[j];
+ Kd[ROUNDS - (t / 4)][t % 4] = tk[j];
+ }
+ }
+ for (int r = 1; r < ROUNDS; r++) {
+ // inverse MixColumn where needed
+ for (j = 0; j < BC; j++) {
+ tt = Kd[r][j];
+ Kd[r][j] = U1[(tt >>> 24) & 0xFF] ^
+ U2[(tt >>> 16) & 0xFF] ^
+ U3[(tt >>> 8) & 0xFF] ^
+ U4[ tt & 0xFF];
+ }
+ }
+
+ // assemble the encryption (Ke) and decryption (Kd) round keys
+ // and expand them into arrays of ints.
+ int[] expandedKe = expandToSubKey(Ke, false); // decrypting==false
+ int[] expandedKd = expandToSubKey(Kd, true); // decrypting==true
+
+ ROUNDS_12 = (ROUNDS>=12);
+ ROUNDS_14 = (ROUNDS==14);
+ limit = ROUNDS*4;
+
+ // store the expanded sub keys into 'sessionK'
+ sessionK = new Object[] { expandedKe, expandedKd };
+ }
+
+
+ /**
+ * Return The number of rounds for a given Rijndael keysize.
+ *
+ * @param keySize The size of the user key material in bytes.
+ * MUST be one of (16, 24, 32).
+ * @return The number of rounds.
+ */
+ private static int getRounds(int keySize) {
+ return (keySize >> 2) + 6;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/AESKeyGenerator.java b/ojluni/src/main/java/com/sun/crypto/provider/AESKeyGenerator.java
new file mode 100755
index 0000000..8d8145c
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/AESKeyGenerator.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.SecureRandom;
+import java.security.InvalidParameterException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.spec.AlgorithmParameterSpec;
+import javax.crypto.KeyGeneratorSpi;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+
+/**
+ * This class generates a AES key.
+ *
+ * @author Valerie Peng
+ *
+ */
+
+public final class AESKeyGenerator extends KeyGeneratorSpi {
+
+ private SecureRandom random = null;
+ private int keySize = 16; // default keysize (in number of bytes)
+
+ /**
+ * Empty constructor.
+ */
+ public AESKeyGenerator() {
+ }
+
+ /**
+ * Initializes this key generator.
+ *
+ * @param random the source of randomness for this generator
+ */
+ protected void engineInit(SecureRandom random) {
+ this.random = random;
+ }
+
+ /**
+ * Initializes this key generator with the specified parameter
+ * set and a user-provided source of randomness.
+ *
+ * @param params the key generation parameters
+ * @param random the source of randomness for this key generator
+ *
+ * @exception InvalidAlgorithmParameterException if <code>params</code> is
+ * inappropriate for this key generator
+ */
+ protected void engineInit(AlgorithmParameterSpec params,
+ SecureRandom random)
+ throws InvalidAlgorithmParameterException {
+ throw new InvalidAlgorithmParameterException
+ ("AES key generation does not take any parameters");
+ }
+
+ /**
+ * Initializes this key generator for a certain keysize, using the given
+ * source of randomness.
+ *
+ * @param keysize the keysize. This is an algorithm-specific
+ * metric specified in number of bits.
+ * @param random the source of randomness for this key generator
+ */
+ protected void engineInit(int keysize, SecureRandom random) {
+ if (((keysize % 8) != 0) ||
+ (!AESCrypt.isKeySizeValid(keysize/8))) {
+ throw new InvalidParameterException
+ ("Wrong keysize: must be equal to 128, 192 or 256");
+ }
+ this.keySize = keysize/8;
+ this.engineInit(random);
+ }
+
+ /**
+ * Generates the AES key.
+ *
+ * @return the new AES key
+ */
+ protected SecretKey engineGenerateKey() {
+ SecretKeySpec aesKey = null;
+
+ if (this.random == null) {
+ this.random = SunJCE.RANDOM;
+ }
+
+ byte[] keyBytes = new byte[keySize];
+ this.random.nextBytes(keyBytes);
+ aesKey = new SecretKeySpec(keyBytes, "AES");
+ return aesKey;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/AESParameters.java b/ojluni/src/main/java/com/sun/crypto/provider/AESParameters.java
new file mode 100755
index 0000000..2faf31d
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/AESParameters.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.util.*;
+import java.io.*;
+import sun.security.util.*;
+import java.security.AlgorithmParametersSpi;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidParameterSpecException;
+import javax.crypto.spec.IvParameterSpec;
+
+/**
+ * This class implements the parameter (IV) used with the AES algorithm
+ * in feedback-mode. IV is defined in the standards as follows:
+ *
+ * <pre>
+ * IV ::= OCTET STRING -- 16 octets
+ * </pre>
+ *
+ * @author Valerie Peng
+ *
+ */
+public final class AESParameters extends AlgorithmParametersSpi {
+
+ private BlockCipherParamsCore core;
+
+ public AESParameters() {
+ core = new BlockCipherParamsCore(AESConstants.AES_BLOCK_SIZE);
+ }
+
+ protected void engineInit(AlgorithmParameterSpec paramSpec)
+ throws InvalidParameterSpecException {
+ core.init(paramSpec);
+ }
+
+ protected void engineInit(byte[] encoded)
+ throws IOException {
+ core.init(encoded);
+ }
+
+ protected void engineInit(byte[] encoded, String decodingMethod)
+ throws IOException {
+ core.init(encoded, decodingMethod);
+ }
+
+ protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
+ throws InvalidParameterSpecException {
+ return core.getParameterSpec(paramSpec);
+ }
+
+ protected byte[] engineGetEncoded() throws IOException {
+ return core.getEncoded();
+ }
+
+ protected byte[] engineGetEncoded(String encodingMethod)
+ throws IOException {
+ return core.getEncoded();
+ }
+
+ protected String engineToString() {
+ return core.toString();
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/AESWrapCipher.java b/ojluni/src/main/java/com/sun/crypto/provider/AESWrapCipher.java
new file mode 100755
index 0000000..21327dd
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/AESWrapCipher.java
@@ -0,0 +1,483 @@
+/*
+ * Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.util.Arrays;
+import java.security.*;
+import java.security.spec.*;
+import javax.crypto.*;
+import javax.crypto.spec.*;
+
+/**
+ * This class implements the AES KeyWrap algorithm as defined
+ * in <a href=http://www.w3.org/TR/xmlenc-core/#sec-Alg-SymmetricKeyWrap>
+ * "XML Encryption Syntax and Processing" section 5.6.3 "AES Key Wrap".
+ * Note: only <code>ECB</code> mode and <code>NoPadding</code> padding
+ * can be used for this algorithm.
+ *
+ * @author Valerie Peng
+ *
+ *
+ * @see AESCipher
+ */
+public final class AESWrapCipher extends CipherSpi {
+
+ private static final byte[] IV = {
+ (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6,
+ (byte) 0xA6, (byte) 0xA6, (byte) 0xA6, (byte) 0xA6
+ };
+
+ private static final int blksize = AESConstants.AES_BLOCK_SIZE;
+
+ /*
+ * internal cipher object which does the real work.
+ */
+ private AESCrypt cipher;
+
+ /*
+ * are we encrypting or decrypting?
+ */
+ private boolean decrypting = false;
+
+ /**
+ * Creates an instance of AES KeyWrap cipher with default
+ * mode, i.e. "ECB" and padding scheme, i.e. "NoPadding".
+ */
+ public AESWrapCipher() {
+ cipher = new AESCrypt();
+ }
+
+ /**
+ * Sets the mode of this cipher. Only "ECB" mode is accepted for this
+ * cipher.
+ *
+ * @param mode the cipher mode
+ *
+ * @exception NoSuchAlgorithmException if the requested cipher mode
+ * is not "ECB".
+ */
+ protected void engineSetMode(String mode)
+ throws NoSuchAlgorithmException {
+ if (!mode.equalsIgnoreCase("ECB")) {
+ throw new NoSuchAlgorithmException(mode + " cannot be used");
+ }
+ }
+
+ /**
+ * Sets the padding mechanism of this cipher. Only "NoPadding" schmem
+ * is accepted for this cipher.
+ *
+ * @param padding the padding mechanism
+ *
+ * @exception NoSuchPaddingException if the requested padding mechanism
+ * is not "NoPadding".
+ */
+ protected void engineSetPadding(String padding)
+ throws NoSuchPaddingException {
+ if (!padding.equalsIgnoreCase("NoPadding")) {
+ throw new NoSuchPaddingException(padding + " cannot be used");
+ }
+ }
+
+ /**
+ * Returns the block size (in bytes). i.e. 16 bytes.
+ *
+ * @return the block size (in bytes), i.e. 16 bytes.
+ */
+ protected int engineGetBlockSize() {
+ return blksize;
+ }
+
+ /**
+ * Returns the length in bytes that an output buffer would need to be
+ * given the input length <code>inputLen</code> (in bytes).
+ *
+ * <p>The actual output length of the next <code>update</code> or
+ * <code>doFinal</code> call may be smaller than the length returned
+ * by this method.
+ *
+ * @param inputLen the input length (in bytes)
+ *
+ * @return the required output buffer size (in bytes)
+ */
+ protected int engineGetOutputSize(int inputLen) {
+ // can only return an upper-limit if not initialized yet.
+ int result = 0;
+ if (decrypting) {
+ result = inputLen - 8;
+ } else {
+ result = inputLen + 8;
+ }
+ return (result < 0? 0:result);
+ }
+
+ /**
+ * Returns the initialization vector (IV) which is null for this cipher.
+ *
+ * @return null for this cipher.
+ */
+ protected byte[] engineGetIV() {
+ return null;
+ }
+
+ /**
+ * Initializes this cipher with a key and a source of randomness.
+ *
+ * <p>The cipher only supports the following two operation modes:<b>
+ * Cipher.WRAP_MODE, and <b>
+ * Cipher.UNWRAP_MODE.
+ * <p>For modes other than the above two, UnsupportedOperationException
+ * will be thrown.
+ *
+ * @param opmode the operation mode of this cipher. Only
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) are accepted.
+ * @param key the secret key.
+ * @param random the source of randomness.
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher.
+ */
+ protected void engineInit(int opmode, Key key, SecureRandom random)
+ throws InvalidKeyException {
+ if (opmode == Cipher.WRAP_MODE) {
+ decrypting = false;
+ } else if (opmode == Cipher.UNWRAP_MODE) {
+ decrypting = true;
+ } else {
+ throw new UnsupportedOperationException("This cipher can " +
+ "only be used for key wrapping and unwrapping");
+ }
+ cipher.init(decrypting, key.getAlgorithm(), key.getEncoded());
+ }
+
+ /**
+ * Initializes this cipher with a key, a set of algorithm parameters,
+ * and a source of randomness.
+ *
+ * <p>The cipher only supports the following two operation modes:<b>
+ * Cipher.WRAP_MODE, and <b>
+ * Cipher.UNWRAP_MODE.
+ * <p>For modes other than the above two, UnsupportedOperationException
+ * will be thrown.
+ *
+ * @param opmode the operation mode of this cipher. Only
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) are accepted.
+ * @param key the secret key.
+ * @param params the algorithm parameters; must be null for this cipher.
+ * @param random the source of randomness.
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ * @exception InvalidAlgorithmParameterException if the given algorithm
+ * parameters is not null.
+ */
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameterSpec params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ if (params != null) {
+ throw new InvalidAlgorithmParameterException("This cipher " +
+ "does not accept any parameters");
+ }
+ engineInit(opmode, key, random);
+ }
+
+ /**
+ * Initializes this cipher with a key, a set of algorithm parameters,
+ * and a source of randomness.
+ *
+ * <p>The cipher only supports the following two operation modes:<b>
+ * Cipher.WRAP_MODE, and <b>
+ * Cipher.UNWRAP_MODE.
+ * <p>For modes other than the above two, UnsupportedOperationException
+ * will be thrown.
+ *
+ * @param opmode the operation mode of this cipher. Only
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>) are accepted.
+ * @param key the secret key.
+ * @param params the algorithm parameters; must be null for this cipher.
+ * @param random the source of randomness.
+ *
+ * @exception InvalidKeyException if the given key is inappropriate.
+ * @exception InvalidAlgorithmParameterException if the given algorithm
+ * parameters is not null.
+ */
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameters params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ if (params != null) {
+ throw new InvalidAlgorithmParameterException("This cipher " +
+ "does not accept any parameters");
+ }
+ engineInit(opmode, key, random);
+ }
+
+ /**
+ * This operation is not supported by this cipher.
+ * Since it's impossible to initialize this cipher given the
+ * current Cipher.engineInit(...) implementation,
+ * IllegalStateException will always be thrown upon invocation.
+ *
+ * @param in the input buffer.
+ * @param inOffset the offset in <code>in</code> where the input
+ * starts.
+ * @param inLen the input length.
+ *
+ * @return n/a.
+ *
+ * @exception IllegalStateException upon invocation of this method.
+ */
+ protected byte[] engineUpdate(byte[] in, int inOffset, int inLen) {
+ throw new IllegalStateException("Cipher has not been initialized");
+ }
+
+ /**
+ * This operation is not supported by this cipher.
+ * Since it's impossible to initialize this cipher given the
+ * current Cipher.engineInit(...) implementation,
+ * IllegalStateException will always be thrown upon invocation.
+ *
+ * @param in the input buffer.
+ * @param inOffset the offset in <code>in</code> where the input
+ * starts.
+ * @param inLen the input length.
+ * @param out the buffer for the result.
+ * @param outOffset the offset in <code>out</code> where the result
+ * is stored.
+ *
+ * @return n/a.
+ *
+ * @exception IllegalStateException upon invocation of this method.
+ */
+ protected int engineUpdate(byte[] in, int inOffset, int inLen,
+ byte[] out, int outOffset)
+ throws ShortBufferException {
+ throw new IllegalStateException("Cipher has not been initialized");
+ }
+
+ /**
+ * This operation is not supported by this cipher.
+ * Since it's impossible to initialize this cipher given the
+ * current Cipher.engineInit(...) implementation,
+ * IllegalStateException will always be thrown upon invocation.
+ *
+ * @param in the input buffer
+ * @param inOffset the offset in <code>in</code> where the input
+ * starts
+ * @param inLen the input length.
+ *
+ * @return n/a.
+ *
+ * @exception IllegalStateException upon invocation of this method.
+ */
+ protected byte[] engineDoFinal(byte[] input, int inputOffset,
+ int inputLen)
+ throws IllegalBlockSizeException, BadPaddingException {
+ throw new IllegalStateException("Cipher has not been initialized");
+ }
+
+ /**
+ * This operation is not supported by this cipher.
+ * Since it's impossible to initialize this cipher given the
+ * current Cipher.engineInit(...) implementation,
+ * IllegalStateException will always be thrown upon invocation.
+ *
+ * @param in the input buffer.
+ * @param inOffset the offset in <code>in</code> where the input
+ * starts.
+ * @param inLen the input length.
+ * @param out the buffer for the result.
+ * @param outOffset the ofset in <code>out</code> where the result
+ * is stored.
+ *
+ * @return n/a.
+ *
+ * @exception IllegalStateException upon invocation of this method.
+ */
+ protected int engineDoFinal(byte[] in, int inOffset, int inLen,
+ byte[] out, int outOffset)
+ throws IllegalBlockSizeException, ShortBufferException,
+ BadPaddingException {
+ throw new IllegalStateException("Cipher has not been initialized");
+ }
+
+ /**
+ * Returns the parameters used with this cipher which is always null
+ * for this cipher.
+ *
+ * @return null since this cipher does not use any parameters.
+ */
+ protected AlgorithmParameters engineGetParameters() {
+ return null;
+ }
+
+ /**
+ * Returns the key size of the given key object in number of bits.
+ *
+ * @param key the key object.
+ *
+ * @return the "effective" key size of the given key object.
+ *
+ * @exception InvalidKeyException if <code>key</code> is invalid.
+ */
+ protected int engineGetKeySize(Key key) throws InvalidKeyException {
+ byte[] encoded = key.getEncoded();
+ if (!AESCrypt.isKeySizeValid(encoded.length)) {
+ throw new InvalidKeyException("Invalid key length: " +
+ encoded.length + " bytes");
+ }
+ return encoded.length * 8;
+ }
+
+ /**
+ * Wrap a key.
+ *
+ * @param key the key to be wrapped.
+ *
+ * @return the wrapped key.
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block
+ * cipher, no padding has been requested, and the length of the
+ * encoding of the key to be wrapped is not a
+ * multiple of the block size.
+ *
+ * @exception InvalidKeyException if it is impossible or unsafe to
+ * wrap the key with this cipher (e.g., a hardware protected key is
+ * being passed to a software only cipher).
+ */
+ protected byte[] engineWrap(Key key)
+ throws IllegalBlockSizeException, InvalidKeyException {
+ byte[] keyVal = key.getEncoded();
+ if ((keyVal == null) || (keyVal.length == 0)) {
+ throw new InvalidKeyException("Cannot get an encoding of " +
+ "the key to be wrapped");
+ }
+ byte[] out = new byte[keyVal.length + 8];
+
+ if (keyVal.length == 8) {
+ System.arraycopy(IV, 0, out, 0, IV.length);
+ System.arraycopy(keyVal, 0, out, IV.length, 8);
+ cipher.encryptBlock(out, 0, out, 0);
+ } else {
+ if (keyVal.length % 8 != 0) {
+ throw new IllegalBlockSizeException("length of the " +
+ "to be wrapped key should be multiples of 8 bytes");
+ }
+ System.arraycopy(IV, 0, out, 0, IV.length);
+ System.arraycopy(keyVal, 0, out, IV.length, keyVal.length);
+ int N = keyVal.length/8;
+ byte[] buffer = new byte[blksize];
+ for (int j = 0; j < 6; j++) {
+ for (int i = 1; i <= N; i++) {
+ int T = i + j*N;
+ System.arraycopy(out, 0, buffer, 0, IV.length);
+ System.arraycopy(out, i*8, buffer, IV.length, 8);
+ cipher.encryptBlock(buffer, 0, buffer, 0);
+ for (int k = 1; T != 0; k++) {
+ byte v = (byte) T;
+ buffer[IV.length - k] ^= v;
+ T >>>= 8;
+ }
+ System.arraycopy(buffer, 0, out, 0, IV.length);
+ System.arraycopy(buffer, 8, out, 8*i, 8);
+ }
+ }
+ }
+ return out;
+ }
+
+ /**
+ * Unwrap a previously wrapped key.
+ *
+ * @param wrappedKey the key to be unwrapped.
+ *
+ * @param wrappedKeyAlgorithm the algorithm the wrapped key is for.
+ *
+ * @param wrappedKeyType the type of the wrapped key.
+ * This is one of <code>Cipher.SECRET_KEY</code>,
+ * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>.
+ *
+ * @return the unwrapped key.
+ *
+ * @exception NoSuchAlgorithmException if no installed providers
+ * can create keys of type <code>wrappedKeyType</code> for the
+ * <code>wrappedKeyAlgorithm</code>.
+ *
+ * @exception InvalidKeyException if <code>wrappedKey</code> does not
+ * represent a wrapped key of type <code>wrappedKeyType</code> for
+ * the <code>wrappedKeyAlgorithm</code>.
+ */
+ protected Key engineUnwrap(byte[] wrappedKey,
+ String wrappedKeyAlgorithm,
+ int wrappedKeyType)
+ throws InvalidKeyException, NoSuchAlgorithmException {
+ int wrappedKeyLen = wrappedKey.length;
+ // ensure the wrappedKey length is multiples of 8 bytes and non-zero
+ if (wrappedKeyLen == 0) {
+ throw new InvalidKeyException("The wrapped key is empty");
+ }
+ if (wrappedKeyLen % 8 != 0) {
+ throw new InvalidKeyException
+ ("The wrapped key has invalid key length");
+ }
+ byte[] out = new byte[wrappedKeyLen - 8];
+ byte[] buffer = new byte[blksize];
+ if (wrappedKeyLen == 16) {
+ cipher.decryptBlock(wrappedKey, 0, buffer, 0);
+ for (int i = 0; i < IV.length; i++) {
+ if (IV[i] != buffer[i]) {
+ throw new InvalidKeyException("Integrity check failed");
+ }
+ }
+ System.arraycopy(buffer, IV.length, out, 0, out.length);
+ } else {
+ System.arraycopy(wrappedKey, 0, buffer, 0, IV.length);
+ System.arraycopy(wrappedKey, IV.length, out, 0, out.length);
+ int N = out.length/8;
+ for (int j = 5; j >= 0; j--) {
+ for (int i = N; i > 0; i--) {
+ int T = i + j*N;
+ System.arraycopy(out, 8*(i-1), buffer, IV.length, 8);
+ for (int k = 1; T != 0; k++) {
+ byte v = (byte) T;
+ buffer[IV.length - k] ^= v;
+ T >>>= 8;
+ }
+ cipher.decryptBlock(buffer, 0, buffer, 0);
+ System.arraycopy(buffer, IV.length, out, 8*(i-1), 8);
+ }
+ }
+ for (int i = 0; i < IV.length; i++) {
+ if (IV[i] != buffer[i]) {
+ throw new InvalidKeyException("Integrity check failed");
+ }
+ }
+ }
+ return ConstructKeys.constructKey(out, wrappedKeyAlgorithm,
+ wrappedKeyType);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/ARCFOURCipher.java b/ojluni/src/main/java/com/sun/crypto/provider/ARCFOURCipher.java
new file mode 100755
index 0000000..f5b99c1
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/ARCFOURCipher.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.*;
+import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.*;
+
+/**
+ * Implementation of the ARCFOUR cipher, an algorithm apparently compatible
+ * with RSA Security's RC4(tm) cipher. The description of this algorithm was
+ * taken from Bruce Schneier's book Applied Cryptography, 2nd ed.,
+ * section 17.1.
+ *
+ * We support keys from 40 to 1024 bits. ARCFOUR would allow for keys shorter
+ * than 40 bits, but that is too insecure for us to permit.
+ *
+ * Note that we subclass CipherSpi directly and do not use the CipherCore
+ * framework. That was designed to simplify implementation of block ciphers
+ * and does not offer any advantages for stream ciphers such as ARCFOUR.
+ *
+ * @since 1.5
+ * @author Andreas Sterbenz
+ */
+public final class ARCFOURCipher extends CipherSpi {
+
+ // state array S, 256 entries. The entries are 8-bit, but we use an int[]
+ // because int arithmetic is much faster than in Java than bytes.
+ private final int[] S;
+
+ // state indices i and j. Called is and js to avoid collision with
+ // local variables. 'is' is set to -1 after a call to doFinal()
+ private int is, js;
+
+ // the bytes of the last key used (if any)
+ // we need this to re-initialize after a call to doFinal()
+ private byte[] lastKey;
+
+ // called by the JCE framework
+ public ARCFOURCipher() {
+ S = new int[256];
+ }
+
+ // core key setup code. initializes S, is, and js
+ // assumes key is non-null and between 40 and 1024 bit
+ private void init(byte[] key) {
+ // initialize S[i] to i
+ for (int i = 0; i < 256; i++) {
+ S[i] = i;
+ }
+
+ // we avoid expanding key to 256 bytes and instead keep a separate
+ // counter ki = i mod key.length.
+ for (int i = 0, j = 0, ki = 0; i < 256; i++) {
+ int Si = S[i];
+ j = (j + Si + key[ki]) & 0xff;
+ S[i] = S[j];
+ S[j] = Si;
+ ki++;
+ if (ki == key.length) {
+ ki = 0;
+ }
+ }
+
+ // set indices to 0
+ is = 0;
+ js = 0;
+ }
+
+ // core crypt code. OFB style, so works for both encryption and decryption
+ private void crypt(byte[] in, int inOfs, int inLen, byte[] out,
+ int outOfs) {
+ if (is < 0) {
+ // doFinal() was called, need to reset the cipher to initial state
+ init(lastKey);
+ }
+ while (inLen-- > 0) {
+ is = (is + 1) & 0xff;
+ int Si = S[is];
+ js = (js + Si) & 0xff;
+ int Sj = S[js];
+ S[is] = Sj;
+ S[js] = Si;
+ out[outOfs++] = (byte)(in[inOfs++] ^ S[(Si + Sj) & 0xff]);
+ }
+ }
+
+ // Modes do not make sense with stream ciphers, but allow ECB
+ // see JCE spec.
+ protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
+ if (mode.equalsIgnoreCase("ECB") == false) {
+ throw new NoSuchAlgorithmException("Unsupported mode " + mode);
+ }
+ }
+
+ // Padding does not make sense with stream ciphers, but allow NoPadding
+ // see JCE spec.
+ protected void engineSetPadding(String padding)
+ throws NoSuchPaddingException {
+ if (padding.equalsIgnoreCase("NoPadding") == false) {
+ throw new NoSuchPaddingException("Padding must be NoPadding");
+ }
+ }
+
+ // Return 0 to indicate stream cipher
+ // see JCE spec.
+ protected int engineGetBlockSize() {
+ return 0;
+ }
+
+ // output length is always the same as input length
+ // see JCE spec
+ protected int engineGetOutputSize(int inputLen) {
+ return inputLen;
+ }
+
+ // no IV, return null
+ // see JCE spec
+ protected byte[] engineGetIV() {
+ return null;
+ }
+
+ // no parameters
+ // see JCE spec
+ protected AlgorithmParameters engineGetParameters() {
+ return null;
+ }
+
+ // see JCE spec
+ protected void engineInit(int opmode, Key key, SecureRandom random)
+ throws InvalidKeyException {
+ init(opmode, key);
+ }
+
+ // see JCE spec
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameterSpec params, SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ if (params != null) {
+ throw new InvalidAlgorithmParameterException
+ ("Parameters not supported");
+ }
+ init(opmode, key);
+ }
+
+ // see JCE spec
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameters params, SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ if (params != null) {
+ throw new InvalidAlgorithmParameterException
+ ("Parameters not supported");
+ }
+ init(opmode, key);
+ }
+
+ // init method. Check opmode and key, then call init(byte[]).
+ private void init(int opmode, Key key) throws InvalidKeyException {
+ if ((opmode < Cipher.ENCRYPT_MODE) || (opmode > Cipher.UNWRAP_MODE)) {
+ throw new InvalidKeyException("Unknown opmode: " + opmode);
+ }
+ lastKey = getEncodedKey(key);
+ init(lastKey);
+ }
+
+ // return the encoding of key if key is a valid ARCFOUR key.
+ // otherwise, throw an InvalidKeyException
+ private static byte[] getEncodedKey(Key key) throws InvalidKeyException {
+ String keyAlg = key.getAlgorithm();
+ if (!keyAlg.equals("RC4") && !keyAlg.equals("ARCFOUR")) {
+ throw new InvalidKeyException("Not an ARCFOUR key: " + keyAlg);
+ }
+ if ("RAW".equals(key.getFormat()) == false) {
+ throw new InvalidKeyException("Key encoding format must be RAW");
+ }
+ byte[] encodedKey = key.getEncoded();
+ if ((encodedKey.length < 5) || (encodedKey.length > 128)) {
+ throw new InvalidKeyException
+ ("Key length must be between 40 and 1024 bit");
+ }
+ return encodedKey;
+ }
+
+ // see JCE spec
+ protected byte[] engineUpdate(byte[] in, int inOfs, int inLen) {
+ byte[] out = new byte[inLen];
+ crypt(in, inOfs, inLen, out, 0);
+ return out;
+ }
+
+ // see JCE spec
+ protected int engineUpdate(byte[] in, int inOfs, int inLen,
+ byte[] out, int outOfs) throws ShortBufferException {
+ if (out.length - outOfs < inLen) {
+ throw new ShortBufferException("Output buffer too small");
+ }
+ crypt(in, inOfs, inLen, out, outOfs);
+ return inLen;
+ }
+
+ // see JCE spec
+ protected byte[] engineDoFinal(byte[] in, int inOfs, int inLen) {
+ byte[] out = engineUpdate(in, inOfs, inLen);
+ is = -1;
+ return out;
+ }
+
+ // see JCE spec
+ protected int engineDoFinal(byte[] in, int inOfs, int inLen,
+ byte[] out, int outOfs) throws ShortBufferException {
+ int outLen = engineUpdate(in, inOfs, inLen, out, outOfs);
+ is = -1;
+ return outLen;
+ }
+
+ // see JCE spec
+ protected byte[] engineWrap(Key key) throws IllegalBlockSizeException,
+ InvalidKeyException {
+ byte[] encoded = key.getEncoded();
+ if ((encoded == null) || (encoded.length == 0)) {
+ throw new InvalidKeyException("Could not obtain encoded key");
+ }
+ return engineDoFinal(encoded, 0, encoded.length);
+ }
+
+ // see JCE spec
+ protected Key engineUnwrap(byte[] wrappedKey, String algorithm,
+ int type) throws InvalidKeyException, NoSuchAlgorithmException {
+ byte[] encoded = engineDoFinal(wrappedKey, 0, wrappedKey.length);
+ return ConstructKeys.constructKey(encoded, algorithm, type);
+ }
+
+ // see JCE spec
+ protected int engineGetKeySize(Key key) throws InvalidKeyException {
+ byte[] encodedKey = getEncodedKey(key);
+ return encodedKey.length << 3;
+ }
+
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/BlockCipherParamsCore.java b/ojluni/src/main/java/com/sun/crypto/provider/BlockCipherParamsCore.java
new file mode 100755
index 0000000..7466d55
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/BlockCipherParamsCore.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.util.*;
+import java.io.*;
+import sun.security.util.*;
+import sun.misc.HexDumpEncoder;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidParameterSpecException;
+import javax.crypto.spec.IvParameterSpec;
+
+/**
+ * This class implements the parameter (IV) used with Block Ciphers
+ * in feedback-mode. IV is defined in the standards as follows:
+ *
+ * <pre>
+ * IV ::= OCTET STRING -- length depends on the block size of the
+ * block ciphers
+ * </pre>
+ *
+ * @author Valerie Peng
+ *
+ */
+final class BlockCipherParamsCore {
+ private int block_size = 0;
+ private byte[] iv = null;
+
+ BlockCipherParamsCore(int blksize) {
+ block_size = blksize;
+ }
+
+ void init(AlgorithmParameterSpec paramSpec)
+ throws InvalidParameterSpecException {
+ if (!(paramSpec instanceof IvParameterSpec)) {
+ throw new InvalidParameterSpecException
+ ("Inappropriate parameter specification");
+ }
+ byte[] tmpIv = ((IvParameterSpec)paramSpec).getIV();
+ if (tmpIv.length != block_size) {
+ throw new InvalidParameterSpecException("IV not " +
+ block_size + " bytes long");
+ }
+ iv = (byte[]) tmpIv.clone();
+ }
+
+ void init(byte[] encoded) throws IOException {
+ DerInputStream der = new DerInputStream(encoded);
+
+ byte[] tmpIv = der.getOctetString();
+ if (der.available() != 0) {
+ throw new IOException("IV parsing error: extra data");
+ }
+ if (tmpIv.length != block_size) {
+ throw new IOException("IV not " + block_size +
+ " bytes long");
+ }
+ iv = tmpIv;
+ }
+
+ void init(byte[] encoded, String decodingMethod)
+ throws IOException {
+ if ((decodingMethod != null) &&
+ (!decodingMethod.equalsIgnoreCase("ASN.1"))) {
+ throw new IllegalArgumentException("Only support ASN.1 format");
+ }
+ init(encoded);
+ }
+
+ AlgorithmParameterSpec getParameterSpec(Class paramSpec)
+ throws InvalidParameterSpecException
+ {
+ if (IvParameterSpec.class.isAssignableFrom(paramSpec)) {
+ return new IvParameterSpec(this.iv);
+ } else {
+ throw new InvalidParameterSpecException
+ ("Inappropriate parameter specification");
+ }
+ }
+
+ byte[] getEncoded() throws IOException {
+ DerOutputStream out = new DerOutputStream();
+ out.putOctetString(this.iv);
+ return out.toByteArray();
+ }
+
+ byte[] getEncoded(String encodingMethod)
+ throws IOException {
+ return getEncoded();
+ }
+
+ /*
+ * Returns a formatted string describing the parameters.
+ */
+ public String toString() {
+ String LINE_SEP = System.getProperty("line.separator");
+
+ String ivString = LINE_SEP + " iv:" + LINE_SEP + "[";
+ HexDumpEncoder encoder = new HexDumpEncoder();
+ ivString += encoder.encodeBuffer(this.iv);
+ ivString += "]" + LINE_SEP;
+ return ivString;
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/BlowfishCipher.java b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishCipher.java
new file mode 100755
index 0000000..29609ec
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishCipher.java
@@ -0,0 +1,428 @@
+/*
+ * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.*;
+import java.security.spec.*;
+import sun.security.util.*;
+import javax.crypto.*;
+import javax.crypto.spec.*;
+import javax.crypto.BadPaddingException;
+
+/**
+ * This class implements the Blowfish algorithm in its various modes
+ * (<code>ECB</code>, <code>CFB</code>, <code>OFB</code>, <code>CBC</code>,
+ * <code>PCBC</code>) and padding schemes (<code>PKCS5Padding</code>,
+ * <code>NoPadding</code>, <code>ISO10126Padding</code>).
+ *
+ * <p> Blowfish is a 64-bit block cipher with a variable-length key.
+ *
+ * @author Jan Luehe
+ *
+ *
+ * @see BlowfishCrypt
+ * @see CipherBlockChaining
+ * @see ElectronicCodeBook
+ * @see CipherFeedback
+ * @see OutputFeedback
+ */
+
+public final class BlowfishCipher extends CipherSpi {
+
+ /*
+ * internal CipherCore object which does the real work.
+ */
+ private CipherCore core = null;
+
+ /**
+ * Creates an instance of Blowfish cipher with default ECB mode and
+ * PKCS5Padding.
+ */
+ public BlowfishCipher() {
+ core = new CipherCore(new BlowfishCrypt(),
+ BlowfishConstants.BLOWFISH_BLOCK_SIZE);
+ }
+
+ /**
+ * Sets the mode of this cipher.
+ *
+ * @param mode the cipher mode
+ *
+ * @exception NoSuchAlgorithmException if the requested cipher mode does
+ * not exist
+ */
+ protected void engineSetMode(String mode)
+ throws NoSuchAlgorithmException {
+ core.setMode(mode);
+ }
+
+ /**
+ * Sets the padding mechanism of this cipher.
+ *
+ * @param padding the padding mechanism
+ *
+ * @exception NoSuchPaddingException if the requested padding mechanism
+ * does not exist
+ */
+ protected void engineSetPadding(String paddingScheme)
+ throws NoSuchPaddingException {
+ core.setPadding(paddingScheme);
+ }
+
+ /**
+ * Returns the block size (in bytes).
+ *
+ * @return the block size (in bytes), or 0 if the underlying algorithm is
+ * not a block cipher
+ */
+ protected int engineGetBlockSize() {
+ return BlowfishConstants.BLOWFISH_BLOCK_SIZE;
+ }
+
+ /**
+ * Returns the length in bytes that an output buffer would need to be in
+ * order to hold the result of the next <code>update</code> or
+ * <code>doFinal</code> operation, given the input length
+ * <code>inputLen</code> (in bytes).
+ *
+ * <p>This call takes into account any unprocessed (buffered) data from a
+ * previous <code>update</code> call, and padding.
+ *
+ * <p>The actual output length of the next <code>update</code> or
+ * <code>doFinal</code> call may be smaller than the length returned by
+ * this method.
+ *
+ * @param inputLen the input length (in bytes)
+ *
+ * @return the required output buffer size (in bytes)
+ */
+ protected int engineGetOutputSize(int inputLen) {
+ return core.getOutputSize(inputLen);
+ }
+
+ /**
+ * Returns the initialization vector (IV) in a new buffer.
+ *
+ * <p>This is useful in the case where a random IV has been created
+ * (see <a href = "#init">init</a>),
+ * or in the context of password-based encryption or
+ * decryption, where the IV is derived from a user-supplied password.
+ *
+ * @return the initialization vector in a new buffer, or null if the
+ * underlying algorithm does not use an IV, or if the IV has not yet
+ * been set.
+ */
+ protected byte[] engineGetIV() {
+ return core.getIV();
+ }
+
+ /**
+ * Returns the parameters used with this cipher.
+ *
+ * <p>The returned parameters may be the same that were used to initialize
+ * this cipher, or may contain the default set of parameters or a set of
+ * randomly generated parameters used by the underlying cipher
+ * implementation (provided that the underlying cipher implementation
+ * uses a default set of parameters or creates new parameters if it needs
+ * parameters but was not initialized with any).
+ *
+ * @return the parameters used with this cipher, or null if this cipher
+ * does not use any parameters.
+ */
+ protected AlgorithmParameters engineGetParameters() {
+ return core.getParameters("Blowfish");
+ }
+
+ /**
+ * Initializes this cipher with a key and a source of randomness.
+ *
+ * <p>The cipher is initialized for one of the following four operations:
+ * encryption, decryption, key wrapping or key unwrapping, depending on
+ * the value of <code>opmode</code>.
+ *
+ * <p>If this cipher requires an initialization vector (IV), it will get
+ * it from <code>random</code>.
+ * This behaviour should only be used in encryption or key wrapping
+ * mode, however.
+ * When initializing a cipher that requires an IV for decryption or
+ * key unwrapping, the IV
+ * (same IV that was used for encryption or key wrapping) must be provided
+ * explicitly as a
+ * parameter, in order to get the correct result.
+ *
+ * <p>This method also cleans existing buffer and other related state
+ * information.
+ *
+ * @param opmode the operation mode of this cipher (this is one of
+ * the following:
+ * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>,
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>)
+ * @param key the secret key
+ * @param random the source of randomness
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ */
+ protected void engineInit(int opmode, Key key, SecureRandom random)
+ throws InvalidKeyException {
+ core.init(opmode, key, random);
+ }
+
+ /**
+ * Initializes this cipher with a key, a set of
+ * algorithm parameters, and a source of randomness.
+ *
+ * <p>The cipher is initialized for one of the following four operations:
+ * encryption, decryption, key wrapping or key unwrapping, depending on
+ * the value of <code>opmode</code>.
+ *
+ * <p>If this cipher (including its underlying feedback or padding scheme)
+ * requires any random bytes, it will get them from <code>random</code>.
+ *
+ * @param opmode the operation mode of this cipher (this is one of
+ * the following:
+ * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>,
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>)
+ * @param key the encryption key
+ * @param params the algorithm parameters
+ * @param random the source of randomness
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ * @exception InvalidAlgorithmParameterException if the given algorithm
+ * parameters are inappropriate for this cipher
+ */
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameterSpec params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ core.init(opmode, key, params, random);
+ }
+
+ protected void engineInit(int opmode, Key key,
+ AlgorithmParameters params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ core.init(opmode, key, params, random);
+ }
+
+ /**
+ * Continues a multiple-part encryption or decryption operation
+ * (depending on how this cipher was initialized), processing another data
+ * part.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, are processed, and the
+ * result is stored in a new buffer.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ *
+ * @return the new buffer with the result
+ *
+ * @exception IllegalStateException if this cipher is in a wrong state
+ * (e.g., has not been initialized)
+ */
+ protected byte[] engineUpdate(byte[] input, int inputOffset,
+ int inputLen) {
+ return core.update(input, inputOffset, inputLen);
+ }
+
+ /**
+ * Continues a multiple-part encryption or decryption operation
+ * (depending on how this cipher was initialized), processing another data
+ * part.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, are processed, and the
+ * result is stored in the <code>output</code> buffer, starting at
+ * <code>outputOffset</code>.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ * @param output the buffer for the result
+ * @param outputOffset the offset in <code>output</code> where the result
+ * is stored
+ *
+ * @return the number of bytes stored in <code>output</code>
+ *
+ * @exception ShortBufferException if the given output buffer is too small
+ * to hold the result
+ */
+ protected int engineUpdate(byte[] input, int inputOffset, int inputLen,
+ byte[] output, int outputOffset)
+ throws ShortBufferException {
+ return core.update(input, inputOffset, inputLen, output,
+ outputOffset);
+ }
+
+ /**
+ * Encrypts or decrypts data in a single-part operation,
+ * or finishes a multiple-part operation.
+ * The data is encrypted or decrypted, depending on how this cipher was
+ * initialized.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, and any input bytes that
+ * may have been buffered during a previous <code>update</code> operation,
+ * are processed, with padding (if requested) being applied.
+ * The result is stored in a new buffer.
+ *
+ * <p>The cipher is reset to its initial state (uninitialized) after this
+ * call.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ *
+ * @return the new buffer with the result
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block cipher,
+ * no padding has been requested (only in encryption mode), and the total
+ * input length of the data processed by this cipher is not a multiple of
+ * block size
+ * @exception BadPaddingException if this cipher is in decryption mode,
+ * and (un)padding has been requested, but the decrypted data is not
+ * bounded by the appropriate padding bytes
+ */
+ protected byte[] engineDoFinal(byte[] input, int inputOffset,
+ int inputLen)
+ throws IllegalBlockSizeException, BadPaddingException {
+ return core.doFinal(input, inputOffset, inputLen);
+ }
+
+ /**
+ * Encrypts or decrypts data in a single-part operation,
+ * or finishes a multiple-part operation.
+ * The data is encrypted or decrypted, depending on how this cipher was
+ * initialized.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, and any input bytes that
+ * may have been buffered during a previous <code>update</code> operation,
+ * are processed, with padding (if requested) being applied.
+ * The result is stored in the <code>output</code> buffer, starting at
+ * <code>outputOffset</code>.
+ *
+ * <p>The cipher is reset to its initial state (uninitialized) after this
+ * call.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ * @param output the buffer for the result
+ * @param outputOffset the offset in <code>output</code> where the result
+ * is stored
+ *
+ * @return the number of bytes stored in <code>output</code>
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block cipher,
+ * no padding has been requested (only in encryption mode), and the total
+ * input length of the data processed by this cipher is not a multiple of
+ * block size
+ * @exception ShortBufferException if the given output buffer is too small
+ * to hold the result
+ * @exception BadPaddingException if this cipher is in decryption mode,
+ * and (un)padding has been requested, but the decrypted data is not
+ * bounded by the appropriate padding bytes
+ */
+ protected int engineDoFinal(byte[] input, int inputOffset, int inputLen,
+ byte[] output, int outputOffset)
+ throws IllegalBlockSizeException, ShortBufferException,
+ BadPaddingException {
+ return core.doFinal(input, inputOffset, inputLen, output,
+ outputOffset);
+ }
+
+ /**
+ * Returns the key size of the given key object.
+ *
+ * @param key the key object.
+ *
+ * @return the key size of the given key object.
+ *
+ * @exception InvalidKeyException if <code>key</code> is invalid.
+ */
+ protected int engineGetKeySize(Key key) throws InvalidKeyException {
+ return (key.getEncoded().length * 8);
+ }
+
+ /**
+ * Wrap a key.
+ *
+ * @param key the key to be wrapped.
+ *
+ * @return the wrapped key.
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block
+ * cipher, no padding has been requested, and the length of the
+ * encoding of the key to be wrapped is not a
+ * multiple of the block size.
+ *
+ * @exception InvalidKeyException if it is impossible or unsafe to
+ * wrap the key with this cipher (e.g., a hardware protected key is
+ * being passed to a software only cipher).
+ */
+ protected byte[] engineWrap(Key key)
+ throws IllegalBlockSizeException, InvalidKeyException {
+ return core.wrap(key);
+ }
+
+ /**
+ * Unwrap a previously wrapped key.
+ *
+ * @param wrappedKey the key to be unwrapped.
+ *
+ * @param wrappedKeyAlgorithm the algorithm the wrapped key is for.
+ *
+ * @param wrappedKeyType the type of the wrapped key.
+ * This is one of <code>Cipher.SECRET_KEY</code>,
+ * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>.
+ *
+ * @return the unwrapped key.
+ *
+ * @exception NoSuchAlgorithmException if no installed providers
+ * can create keys of type <code>wrappedKeyType</code> for the
+ * <code>wrappedKeyAlgorithm</code>.
+ *
+ * @exception InvalidKeyException if <code>wrappedKey</code> does not
+ * represent a wrapped key of type <code>wrappedKeyType</code> for
+ * the <code>wrappedKeyAlgorithm</code>.
+ */
+ protected Key engineUnwrap(byte[] wrappedKey,
+ String wrappedKeyAlgorithm,
+ int wrappedKeyType)
+ throws InvalidKeyException, NoSuchAlgorithmException {
+ return core.unwrap(wrappedKey, wrappedKeyAlgorithm,
+ wrappedKeyType);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/BlowfishConstants.java b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishConstants.java
new file mode 100755
index 0000000..560c4d2
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishConstants.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+/**
+ * This class defines the constants used by the Blowfish algorithm
+ * implementation.
+ *
+ * @author Jan Luehe
+ *
+ * @see BlowfishCipher
+ * @see BlowfishCrypt
+ */
+
+interface BlowfishConstants {
+ int BLOWFISH_BLOCK_SIZE = 8; // number of bytes
+ int BLOWFISH_MAX_KEYSIZE = 56; // number of bytes
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/BlowfishCrypt.java b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishCrypt.java
new file mode 100755
index 0000000..3632cb0
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishCrypt.java
@@ -0,0 +1,558 @@
+/*
+ * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.InvalidKeyException;
+
+/**
+ * This is the internal Blowfish class responsible for encryption and
+ * decryption of a byte array of size <code>BLOWFISH_BLOCK_SIZE</code>.
+ *
+ * @author Jan Luehe
+ * @author David Brownell
+ *
+ * @see BlowfishCipher
+ */
+
+final class BlowfishCrypt extends SymmetricCipher
+ implements BlowfishConstants {
+
+ /*
+ * Are we encrypting or decrypting?
+ */
+ private boolean decrypting = false;
+
+ /**
+ * Gets this cipher's block size.
+ *
+ * @return this cipher's block size
+ */
+ int getBlockSize() {
+ return BLOWFISH_BLOCK_SIZE;
+ }
+
+ void init(boolean decrypting, String algorithm, byte[] rawKey)
+ throws InvalidKeyException {
+ this.decrypting = decrypting;
+ if (!algorithm.equalsIgnoreCase("Blowfish")) {
+ throw new InvalidKeyException("Wrong algorithm: Blowfish required");
+ }
+ if (rawKey.length > BLOWFISH_MAX_KEYSIZE) {
+ throw new InvalidKeyException("Key too long (> 448 bits)");
+ }
+ // Step 1: Init P and then S arrays from pi bytes
+ int i, j, count;
+
+ System.arraycopy(pi, 0, p, 0, 18);
+ System.arraycopy(pi, 18, s0, 0, 256);
+ System.arraycopy(pi, 18 + 256, s1, 0, 256);
+ System.arraycopy(pi, 18 + 512, s2, 0, 256);
+ System.arraycopy(pi, 18 + 768, s3, 0, 256);
+
+ // Step 2: XOR all parts of P with key data
+ int tmp = 0;
+ int nLen = rawKey.length;
+ int nKeyPos = 0;
+ for (i = 0; i < 18; i++) {
+ for (j = 0; j < 4; j++) {
+ tmp <<= 8;
+ tmp |= 0x0ff & rawKey[nKeyPos];
+ if (++nKeyPos == nLen) nKeyPos = 0;
+ }
+ p[i] ^= tmp;
+ }
+
+ // Steps 3-7: Replace all P, S values with computed values
+ int[] data = new int[2];
+
+ for (i = 0; i < 18; i+=2) {
+ encryptBlock(data);
+ p[i] = data[0];
+ p[i+1] = data[1];
+ }
+
+ for (j = 0; j < 256; j+=2) {
+ encryptBlock(data);
+ s0[j] = data[0];
+ s0[j+1] = data[1];
+ }
+ for (j = 0; j < 256; j+=2) {
+ encryptBlock(data);
+ s1[j] = data[0];
+ s1[j+1] = data[1];
+ }
+ for (j = 0; j < 256; j+=2) {
+ encryptBlock(data);
+ s2[j] = data[0];
+ s2[j+1] = data[1];
+ }
+ for (j = 0; j < 256; j+=2) {
+ encryptBlock(data);
+ s3[j] = data[0];
+ s3[j+1] = data[1];
+ }
+ }
+
+ /**
+ * Performs encryption operation.
+ *
+ * <p>The input plain text <code>plain</code>, starting at
+ * <code>plainOffset</code> and ending at
+ * <code>(plainOffset + len - 1)</code>, is encrypted.
+ * The result is stored in <code>cipher</code>, starting at
+ * <code>cipherOffset</code>.
+ *
+ * <p>The subclass that implements Cipher should ensure that
+ * <code>init</code> has been called before this method is called.
+ *
+ * @param plain the buffer with the input data to be encrypted
+ * @param plainOffset the offset in <code>plain</code>
+ * @param plainLen the length of the input data
+ * @param cipher the buffer for the result
+ * @param cipherOffset the offset in <code>cipher</code>
+ */
+ void encryptBlock(byte[] plain, int plainOffset,
+ byte[] cipher, int cipherOffset)
+ {
+ cipherBlock(plain, plainOffset, cipher, cipherOffset);
+ }
+
+ /**
+ * Performs decryption operation.
+ *
+ * <p>The input cipher text <code>cipher</code>, starting at
+ * <code>cipherOffset</code> and ending at
+ * <code>(cipherOffset + len - 1)</code>, is decrypted.
+ * The result is stored in <code>plain</code>, starting at
+ * <code>plainOffset</code>.
+ *
+ * <p>The subclass that implements Cipher should ensure that
+ * <code>init</code> has been called before this method is called.
+ *
+ * @param cipher the buffer with the input data to be decrypted
+ * @param cipherOffset the offset in <code>cipherOffset</code>
+ * @param cipherLen the length of the input data
+ * @param plain the buffer for the result
+ * @param plainOffset the offset in <code>plain</code>
+ */
+ void decryptBlock(byte[] cipher, int cipherOffset,
+ byte[] plain, int plainOffset)
+ {
+ cipherBlock(cipher, cipherOffset, plain, plainOffset);
+ }
+
+ /**
+ * Encrypts, or decrypts, the blocks of data passed in.
+ */
+ private void cipherBlock(byte[] in, int inOffset,
+ byte[] out, int outOffset) {
+ temp[0] = ((in[inOffset ] ) << 24) |
+ ((in[inOffset + 1] & 0xff) << 16) |
+ ((in[inOffset + 2] & 0xff) << 8) |
+ ((in[inOffset + 3] & 0xff) );
+
+ temp[1] = ((in[inOffset + 4] ) << 24) |
+ ((in[inOffset + 5] & 0xff) << 16) |
+ ((in[inOffset + 6] & 0xff) << 8) |
+ ((in[inOffset + 7] & 0xff) );
+
+ if (decrypting) {
+ decryptBlock(temp);
+ } else {
+ encryptBlock(temp);
+ }
+
+ int t = temp[0];
+ out[outOffset ] = (byte)(t >> 24);
+ out[outOffset + 1] = (byte)(t >> 16);
+ out[outOffset + 2] = (byte)(t >> 8);
+ out[outOffset + 3] = (byte)(t );
+
+ t = temp[1];
+ out[outOffset + 4] = (byte)(t >> 24);
+ out[outOffset + 5] = (byte)(t >> 16);
+ out[outOffset + 6] = (byte)(t >> 8);
+ out[outOffset + 7] = (byte)(t );
+ }
+
+ /**
+ * Encrypts a single block, in place.
+ */
+ private void encryptBlock(int[] value) {
+ int left = value[0];
+ int right = value[1];
+
+ left ^= p[0];
+
+ right ^= F(left) ^ p[1];
+ left ^= F(right) ^ p[2];
+ right ^= F(left) ^ p[3];
+ left ^= F(right) ^ p[4];
+
+ right ^= F(left) ^ p[5];
+ left ^= F(right) ^ p[6];
+ right ^= F(left) ^ p[7];
+ left ^= F(right) ^ p[8];
+
+ right ^= F(left) ^ p[9];
+ left ^= F(right) ^ p[10];
+ right ^= F(left) ^ p[11];
+ left ^= F(right) ^ p[12];
+
+ right ^= F(left) ^ p[13];
+ left ^= F(right) ^ p[14];
+ right ^= F(left) ^ p[15];
+ left ^= F(right) ^ p[16];
+
+ right ^= p[17];
+
+ value[0] = right;
+ value[1] = left;
+ }
+
+ /**
+ * Decrypts a single block, in place.
+ */
+ private void decryptBlock(int[] value) {
+ int left = value[1];
+ int right = value[0];
+
+ right ^= p[17];
+
+ left ^= p[16] ^ F(right);
+ right ^= p[15] ^ F(left);
+ left ^= p[14] ^ F(right);
+ right ^= p[13] ^ F(left);
+
+ left ^= p[12] ^ F(right);
+ right ^= p[11] ^ F(left);
+ left ^= p[10] ^ F(right);
+ right ^= p[9] ^ F(left);
+
+ left ^= p[8] ^ F(right);
+ right ^= p[7] ^ F(left);
+ left ^= p[6] ^ F(right);
+ right ^= p[5] ^ F(left);
+
+ left ^= p[4] ^ F(right);
+ right ^= p[3] ^ F(left);
+ left ^= p[2] ^ F(right);
+ right ^= p[1] ^ F(left);
+
+ left ^= p[0];
+
+ value[0] = left;
+ value[1] = right;
+ }
+
+ /**
+ * Calculates the S-Box function F().
+ *
+ * This gets used "rounds" times on each encryption/decryption.
+ */
+ private int F(int v) {
+ return (( s0[ v >>> 24 ]
+ + s1[(v >> 16) & 0xff])
+ ^ s2[(v >> 8) & 0xff])
+ + s3[ v & 0xff];
+ }
+
+ private final int[] p = new int[18]; // subkeys
+ private final int[] s0 = new int[256]; // s-boxes
+ private final int[] s1 = new int[256];
+ private final int[] s2 = new int[256];
+ private final int[] s3 = new int[256];
+ private final int[] temp = new int[2]; // to avoid encrypt/decrypt mallocs
+
+ // many digits of pi, for initializing p and s
+ private static final int[] pi = {
+
+ // p [rounds + 2]
+ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
+ 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
+ 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+ 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
+ 0x9216d5d9, 0x8979fb1b,
+
+ // s [4][256]
+ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
+ 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
+ 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+ 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
+ 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
+ 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+ 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
+ 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
+ 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+ 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
+ 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
+ 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+ 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
+ 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
+ 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+ 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
+ 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
+ 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+ 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
+ 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
+ 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+ 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
+ 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
+ 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+ 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
+ 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
+ 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+ 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
+ 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
+ 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+ 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
+ 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
+ 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+ 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
+ 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
+ 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+ 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
+ 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
+ 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+ 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
+ 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
+ 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+ 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
+ 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
+ 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+ 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
+ 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
+ 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+ 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
+ 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
+ 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+ 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
+ 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
+ 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+ 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
+ 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
+ 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+ 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
+ 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
+ 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+ 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
+ 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
+ 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+ 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
+ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
+ 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
+ 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+ 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
+ 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
+ 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+ 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
+ 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
+ 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+ 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
+ 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
+ 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+ 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
+ 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
+ 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+ 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
+ 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
+ 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+ 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
+ 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
+ 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+ 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
+ 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
+ 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+ 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
+ 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
+ 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+ 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
+ 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
+ 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+ 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
+ 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
+ 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+ 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
+ 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
+ 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+ 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
+ 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
+ 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+ 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
+ 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
+ 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+ 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
+ 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
+ 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+ 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
+ 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
+ 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+ 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
+ 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
+ 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+ 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
+ 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
+ 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+ 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
+ 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
+ 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+ 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
+ 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
+ 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+ 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
+ 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
+ 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+ 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
+ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
+ 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
+ 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+ 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
+ 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
+ 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+ 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
+ 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
+ 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+ 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
+ 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
+ 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+ 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
+ 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
+ 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+ 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
+ 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
+ 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+ 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
+ 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
+ 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+ 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
+ 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
+ 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+ 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
+ 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
+ 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+ 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
+ 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
+ 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+ 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
+ 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
+ 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+ 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
+ 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
+ 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+ 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
+ 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
+ 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+ 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
+ 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
+ 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+ 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
+ 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
+ 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+ 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
+ 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
+ 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+ 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
+ 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
+ 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+ 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
+ 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
+ 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+ 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
+ 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
+ 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+ 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
+ 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
+ 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+ 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
+ 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
+ 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+ 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
+ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
+ 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
+ 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+ 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
+ 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
+ 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+ 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
+ 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
+ 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+ 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
+ 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
+ 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+ 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
+ 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
+ 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+ 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
+ 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
+ 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+ 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
+ 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
+ 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+ 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
+ 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
+ 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+ 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
+ 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
+ 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+ 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
+ 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
+ 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+ 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
+ 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
+ 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+ 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
+ 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
+ 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+ 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
+ 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
+ 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+ 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
+ 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
+ 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+ 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
+ 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
+ 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+ 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
+ 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
+ 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+ 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
+ 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
+ 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+ 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
+ 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
+ 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+ 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
+ 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
+ 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+ 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
+ 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
+ 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+ 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
+ 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
+ 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+ 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
+ };
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/BlowfishKeyGenerator.java b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishKeyGenerator.java
new file mode 100755
index 0000000..be747cb
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishKeyGenerator.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.SecureRandom;
+import java.security.InvalidParameterException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.spec.AlgorithmParameterSpec;
+import javax.crypto.KeyGeneratorSpi;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * This class generates a secret key for use with the Blowfish algorithm.
+ *
+ * @author Jan Luehe
+ *
+ */
+
+public final class BlowfishKeyGenerator extends KeyGeneratorSpi {
+
+ private SecureRandom random = null;
+ private int keysize = 16; // default keysize (in number of bytes)
+
+ /**
+ * Empty constructor
+ */
+ public BlowfishKeyGenerator() {
+ }
+
+ /**
+ * Initializes this key generator.
+ *
+ * @param random the source of randomness for this generator
+ */
+ protected void engineInit(SecureRandom random) {
+ this.random = random;
+ }
+
+ /**
+ * Initializes this key generator with the specified parameter
+ * set and a user-provided source of randomness.
+ *
+ * @param params the key generation parameters
+ * @param random the source of randomness for this key generator
+ *
+ * @exception InvalidAlgorithmParameterException if <code>params</code> is
+ * inappropriate for this key generator
+ */
+ protected void engineInit(AlgorithmParameterSpec params,
+ SecureRandom random)
+ throws InvalidAlgorithmParameterException
+ {
+ throw new InvalidAlgorithmParameterException
+ ("Blowfish key generation does not take any parameters");
+ }
+
+ /**
+ * Initializes this key generator for a certain keysize, using the given
+ * source of randomness.
+ *
+ * @param keysize the keysize. This is an algorithm-specific
+ * metric specified in number of bits.
+ * @param random the source of randomness for this key generator
+ */
+ protected void engineInit(int keysize, SecureRandom random) {
+ if (((keysize % 8) != 0) || (keysize < 32) || (keysize > 448)) {
+ throw new InvalidParameterException("Keysize must be "
+ + "multiple of 8, and can "
+ + "only range from 32 to 448 "
+ + "(inclusive)");
+ }
+ this.keysize = keysize / 8;
+ this.engineInit(random);
+ }
+
+ /**
+ * Generates a Blowfish key.
+ *
+ * @return the new Blowfish key
+ */
+ protected SecretKey engineGenerateKey() {
+ if (this.random == null) {
+ this.random = SunJCE.RANDOM;
+ }
+
+ byte[] keyBytes = new byte[this.keysize];
+ this.random.nextBytes(keyBytes);
+
+ return new SecretKeySpec(keyBytes, "Blowfish");
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/BlowfishParameters.java b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishParameters.java
new file mode 100755
index 0000000..995da5a
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/BlowfishParameters.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.util.*;
+import java.io.*;
+import sun.security.util.*;
+import java.security.AlgorithmParametersSpi;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidParameterSpecException;
+import javax.crypto.spec.IvParameterSpec;
+
+/**
+ * This class implements the parameter (IV) used with the Blowfish algorithm in
+ * feedback-mode. IV is defined in the standards as follows:
+ *
+ * <pre>
+ * IV ::= OCTET STRING -- 8 octets
+ * </pre>
+ *
+ * @author Jan Luehe
+ *
+ */
+
+public final class BlowfishParameters extends AlgorithmParametersSpi {
+
+ private BlockCipherParamsCore core;
+
+ public BlowfishParameters() {
+ core = new BlockCipherParamsCore
+ (BlowfishConstants.BLOWFISH_BLOCK_SIZE);
+ }
+ protected void engineInit(AlgorithmParameterSpec paramSpec)
+ throws InvalidParameterSpecException {
+ core.init(paramSpec);
+ }
+
+ protected void engineInit(byte[] encoded)
+ throws IOException {
+ core.init(encoded);
+ }
+
+ protected void engineInit(byte[] encoded, String decodingMethod)
+ throws IOException {
+ core.init(encoded, decodingMethod);
+ }
+
+ protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
+ throws InvalidParameterSpecException {
+ return core.getParameterSpec(paramSpec);
+ }
+
+ protected byte[] engineGetEncoded() throws IOException {
+ return core.getEncoded();
+ }
+
+ protected byte[] engineGetEncoded(String encodingMethod)
+ throws IOException {
+ return core.getEncoded();
+ }
+
+ protected String engineToString() {
+ return core.toString();
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/CipherBlockChaining.java b/ojluni/src/main/java/com/sun/crypto/provider/CipherBlockChaining.java
new file mode 100755
index 0000000..1291a6e
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/CipherBlockChaining.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.InvalidKeyException;
+
+/**
+ * This class represents ciphers in cipher block chaining (CBC) mode.
+ *
+ * <p>This mode is implemented independently of a particular cipher.
+ * Ciphers to which this mode should apply (e.g., DES) must be
+ * <i>plugged-in</i> using the constructor.
+ *
+ * <p>NOTE: This class does not deal with buffering or padding.
+ *
+ * @author Gigi Ankeny
+ */
+
+class CipherBlockChaining extends FeedbackCipher {
+
+ /*
+ * random bytes that are initialized with iv
+ */
+ protected byte[] r;
+
+ /*
+ * output buffer
+ */
+ private byte[] k;
+
+ // variables for save/restore calls
+ private byte[] rSave = null;
+
+ CipherBlockChaining(SymmetricCipher embeddedCipher) {
+ super(embeddedCipher);
+ k = new byte[blockSize];
+ r = new byte[blockSize];
+ }
+
+ /**
+ * Gets the name of this feedback mode.
+ *
+ * @return the string <code>CBC</code>
+ */
+ String getFeedback() {
+ return "CBC";
+ }
+
+ /**
+ * Initializes the cipher in the specified mode with the given key
+ * and iv.
+ *
+ * @param decrypting flag indicating encryption or decryption
+ * @param algorithm the algorithm name
+ * @param key the key
+ * @param iv the iv
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ */
+ void init(boolean decrypting, String algorithm, byte[] key, byte[] iv)
+ throws InvalidKeyException {
+ if ((key == null) || (iv == null) || (iv.length != blockSize)) {
+ throw new InvalidKeyException("Internal error");
+ }
+ this.iv = iv;
+ reset();
+ embeddedCipher.init(decrypting, algorithm, key);
+ }
+
+ /**
+ * Resets the iv to its original value.
+ * This is used when doFinal is called in the Cipher class, so that the
+ * cipher can be reused (with its original iv).
+ */
+ void reset() {
+ System.arraycopy(iv, 0, r, 0, blockSize);
+ }
+
+ /**
+ * Save the current content of this cipher.
+ */
+ void save() {
+ if (rSave == null) {
+ rSave = new byte[blockSize];
+ }
+ System.arraycopy(r, 0, rSave, 0, blockSize);
+ }
+
+ /**
+ * Restores the content of this cipher to the previous saved one.
+ */
+ void restore() {
+ System.arraycopy(rSave, 0, r, 0, blockSize);
+ }
+
+ /**
+ * Performs encryption operation.
+ *
+ * <p>The input plain text <code>plain</code>, starting at
+ * <code>plainOffset</code> and ending at
+ * <code>(plainOffset + len - 1)</code>, is encrypted.
+ * The result is stored in <code>cipher</code>, starting at
+ * <code>cipherOffset</code>.
+ *
+ * <p>It is the application's responsibility to make sure that
+ * <code>plainLen</code> is a multiple of the embedded cipher's block size,
+ * as any excess bytes are ignored.
+ *
+ * @param plain the buffer with the input data to be encrypted
+ * @param plainOffset the offset in <code>plain</code>
+ * @param plainLen the length of the input data
+ * @param cipher the buffer for the result
+ * @param cipherOffset the offset in <code>cipher</code>
+ */
+ void encrypt(byte[] plain, int plainOffset, int plainLen,
+ byte[] cipher, int cipherOffset)
+ {
+ int i;
+ int endIndex = plainOffset + plainLen;
+
+ for (; plainOffset < endIndex;
+ plainOffset+=blockSize, cipherOffset += blockSize) {
+ for (i=0; i<blockSize; i++) {
+ k[i] = (byte)(plain[i+plainOffset] ^ r[i]);
+ }
+ embeddedCipher.encryptBlock(k, 0, cipher, cipherOffset);
+ System.arraycopy(cipher, cipherOffset, r, 0, blockSize);
+ }
+ }
+
+ /**
+ * Performs decryption operation.
+ *
+ * <p>The input cipher text <code>cipher</code>, starting at
+ * <code>cipherOffset</code> and ending at
+ * <code>(cipherOffset + len - 1)</code>, is decrypted.
+ * The result is stored in <code>plain</code>, starting at
+ * <code>plainOffset</code>.
+ *
+ * <p>It is the application's responsibility to make sure that
+ * <code>cipherLen</code> is a multiple of the embedded cipher's block
+ * size, as any excess bytes are ignored.
+ *
+ * <p>It is also the application's responsibility to make sure that
+ * <code>init</code> has been called before this method is called.
+ * (This check is omitted here, to avoid double checking.)
+ *
+ * @param cipher the buffer with the input data to be decrypted
+ * @param cipherOffset the offset in <code>cipherOffset</code>
+ * @param cipherLen the length of the input data
+ * @param plain the buffer for the result
+ * @param plainOffset the offset in <code>plain</code>
+ *
+ * @exception IllegalBlockSizeException if input data whose length does
+ * not correspond to the embedded cipher's block size is passed to the
+ * embedded cipher
+ */
+ void decrypt(byte[] cipher, int cipherOffset, int cipherLen,
+ byte[] plain, int plainOffset)
+ {
+ int i;
+ byte[] cipherOrig=null;
+ int endIndex = cipherOffset + cipherLen;
+
+ if (cipher==plain && (cipherOffset >= plainOffset)
+ && ((cipherOffset - plainOffset) < blockSize)) {
+ // Save the original ciphertext blocks, so they can be
+ // stored in the feedback register "r".
+ // This is necessary because in this constellation, a
+ // ciphertext block (or parts of it) will be overridden by
+ // the plaintext result.
+ cipherOrig = (byte[])cipher.clone();
+ }
+
+ for (; cipherOffset < endIndex;
+ cipherOffset += blockSize, plainOffset += blockSize) {
+ embeddedCipher.decryptBlock(cipher, cipherOffset, k, 0);
+ for (i = 0; i < blockSize; i++) {
+ plain[i+plainOffset] = (byte)(k[i] ^ r[i]);
+ }
+ if (cipherOrig==null) {
+ System.arraycopy(cipher, cipherOffset, r, 0, blockSize);
+ } else {
+ System.arraycopy(cipherOrig, cipherOffset, r, 0, blockSize);
+ }
+ }
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/CipherCore.java b/ojluni/src/main/java/com/sun/crypto/provider/CipherCore.java
new file mode 100755
index 0000000..80070b7
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/CipherCore.java
@@ -0,0 +1,943 @@
+/*
+ * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.util.Locale;
+
+import java.security.*;
+import java.security.spec.*;
+import javax.crypto.*;
+import javax.crypto.spec.*;
+import javax.crypto.BadPaddingException;
+
+/**
+ * This class represents the symmetric algorithms in its various modes
+ * (<code>ECB</code>, <code>CFB</code>, <code>OFB</code>, <code>CBC</code>,
+ * <code>PCBC</code>, <code>CTR</code>, and <code>CTS</code>) and
+ * padding schemes (<code>PKCS5Padding</code>, <code>NoPadding</code>,
+ * <code>ISO10126Padding</code>).
+ *
+ * @author Gigi Ankeny
+ * @author Jan Luehe
+ * @see ElectronicCodeBook
+ * @see CipherFeedback
+ * @see OutputFeedback
+ * @see CipherBlockChaining
+ * @see PCBC
+ * @see CounterMode
+ * @see CipherTextStealing
+ */
+
+final class CipherCore {
+
+ /*
+ * internal buffer
+ */
+ private byte[] buffer = null;
+
+ /*
+ * internal buffer
+ */
+ private int blockSize = 0;
+
+ /*
+ * unit size (number of input bytes that can be processed at a time)
+ */
+ private int unitBytes = 0;
+
+ /*
+ * index of the content size left in the buffer
+ */
+ private int buffered = 0;
+
+ /*
+ * minimum number of bytes in the buffer required for
+ * FeedbackCipher.encryptFinal()/decryptFinal() call.
+ * update() must buffer this many bytes before before starting
+ * to encrypt/decrypt data.
+ * currently, only CTS mode has a non-zero value due to its special
+ * handling on the last two blocks (the last one may be incomplete).
+ */
+ private int minBytes = 0;
+
+ /*
+ * number of bytes needed to make the total input length a multiple
+ * of the blocksize (this is used in feedback mode, when the number of
+ * input bytes that are processed at a time is different from the block
+ * size)
+ */
+ private int diffBlocksize = 0;
+
+ /*
+ * padding class
+ */
+ private Padding padding = null;
+
+ /*
+ * internal cipher engine
+ */
+ private FeedbackCipher cipher = null;
+
+ /*
+ * the cipher mode
+ */
+ private int cipherMode = ECB_MODE;
+
+ /*
+ * are we encrypting or decrypting?
+ */
+ private boolean decrypting = false;
+
+ /*
+ * Block Mode constants
+ */
+ private static final int ECB_MODE = 0;
+ private static final int CBC_MODE = 1;
+ private static final int CFB_MODE = 2;
+ private static final int OFB_MODE = 3;
+ private static final int PCBC_MODE = 4;
+ private static final int CTR_MODE = 5;
+ private static final int CTS_MODE = 6;
+
+ /**
+ * Creates an instance of CipherCore with default ECB mode and
+ * PKCS5Padding.
+ */
+ CipherCore(SymmetricCipher impl, int blkSize) {
+ blockSize = blkSize;
+ unitBytes = blkSize;
+ diffBlocksize = blkSize;
+
+ /*
+ * The buffer should be usable for all cipher mode and padding
+ * schemes. Thus, it has to be at least (blockSize+1) for CTS.
+ * In decryption mode, it also hold the possible padding block.
+ */
+ buffer = new byte[blockSize*2];
+
+ // set mode and padding
+ cipher = new ElectronicCodeBook(impl);
+ padding = new PKCS5Padding(blockSize);
+ }
+
+ /**
+ * Sets the mode of this cipher.
+ *
+ * @param mode the cipher mode
+ *
+ * @exception NoSuchAlgorithmException if the requested cipher mode does
+ * not exist
+ */
+ void setMode(String mode) throws NoSuchAlgorithmException {
+ if (mode == null)
+ throw new NoSuchAlgorithmException("null mode");
+
+ String modeUpperCase = mode.toUpperCase(Locale.ENGLISH);
+
+ if (modeUpperCase.equals("ECB")) {
+ return;
+ }
+
+ SymmetricCipher rawImpl = cipher.getEmbeddedCipher();
+ if (modeUpperCase.equals("CBC")) {
+ cipherMode = CBC_MODE;
+ cipher = new CipherBlockChaining(rawImpl);
+ }
+ else if (modeUpperCase.equals("CTS")) {
+ cipherMode = CTS_MODE;
+ cipher = new CipherTextStealing(rawImpl);
+ minBytes = blockSize+1;
+ padding = null;
+ }
+ else if (modeUpperCase.equals("CTR")) {
+ cipherMode = CTR_MODE;
+ cipher = new CounterMode(rawImpl);
+ unitBytes = 1;
+ padding = null;
+ }
+ else if (modeUpperCase.startsWith("CFB")) {
+ cipherMode = CFB_MODE;
+ unitBytes = getNumOfUnit(mode, "CFB".length(), blockSize);
+ cipher = new CipherFeedback(rawImpl, unitBytes);
+ }
+ else if (modeUpperCase.startsWith("OFB")) {
+ cipherMode = OFB_MODE;
+ unitBytes = getNumOfUnit(mode, "OFB".length(), blockSize);
+ cipher = new OutputFeedback(rawImpl, unitBytes);
+ }
+ else if (modeUpperCase.equals("PCBC")) {
+ cipherMode = PCBC_MODE;
+ cipher = new PCBC(rawImpl);
+ }
+ else {
+ throw new NoSuchAlgorithmException("Cipher mode: " + mode
+ + " not found");
+ }
+ }
+
+ private static int getNumOfUnit(String mode, int offset, int blockSize)
+ throws NoSuchAlgorithmException {
+ int result = blockSize; // use blockSize as default value
+ if (mode.length() > offset) {
+ int numInt;
+ try {
+ Integer num = Integer.valueOf(mode.substring(offset));
+ numInt = num.intValue();
+ result = numInt >> 3;
+ } catch (NumberFormatException e) {
+ throw new NoSuchAlgorithmException
+ ("Algorithm mode: " + mode + " not implemented");
+ }
+ if ((numInt % 8 != 0) || (result > blockSize)) {
+ throw new NoSuchAlgorithmException
+ ("Invalid algorithm mode: " + mode);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Sets the padding mechanism of this cipher.
+ *
+ * @param padding the padding mechanism
+ *
+ * @exception NoSuchPaddingException if the requested padding mechanism
+ * does not exist
+ */
+ void setPadding(String paddingScheme)
+ throws NoSuchPaddingException
+ {
+ if (paddingScheme == null) {
+ throw new NoSuchPaddingException("null padding");
+ }
+ if (paddingScheme.equalsIgnoreCase("NoPadding")) {
+ padding = null;
+ } else if (paddingScheme.equalsIgnoreCase("ISO10126Padding")) {
+ padding = new ISO10126Padding(blockSize);
+ } else if (!paddingScheme.equalsIgnoreCase("PKCS5Padding")) {
+ throw new NoSuchPaddingException("Padding: " + paddingScheme
+ + " not implemented");
+ }
+ if ((padding != null) &&
+ ((cipherMode == CTR_MODE) || (cipherMode == CTS_MODE))) {
+ padding = null;
+ throw new NoSuchPaddingException
+ ((cipherMode == CTR_MODE? "CTR":"CTS") +
+ " mode must be used with NoPadding");
+ }
+ }
+
+ /**
+ * Returns the length in bytes that an output buffer would need to be in
+ * order to hold the result of the next <code>update</code> or
+ * <code>doFinal</code> operation, given the input length
+ * <code>inputLen</code> (in bytes).
+ *
+ * <p>This call takes into account any unprocessed (buffered) data from a
+ * previous <code>update</code> call, and padding.
+ *
+ * <p>The actual output length of the next <code>update</code> or
+ * <code>doFinal</code> call may be smaller than the length returned by
+ * this method.
+ *
+ * @param inputLen the input length (in bytes)
+ *
+ * @return the required output buffer size (in bytes)
+ */
+ int getOutputSize(int inputLen) {
+ int totalLen = buffered + inputLen;
+
+ if (padding == null)
+ return totalLen;
+
+ if (decrypting)
+ return totalLen;
+
+ if (unitBytes != blockSize) {
+ if (totalLen < diffBlocksize)
+ return diffBlocksize;
+ else
+ return (totalLen + blockSize -
+ ((totalLen - diffBlocksize) % blockSize));
+ } else {
+ return totalLen + padding.padLength(totalLen);
+ }
+ }
+
+ /**
+ * Returns the initialization vector (IV) in a new buffer.
+ *
+ * <p>This is useful in the case where a random IV has been created
+ * (see <a href = "#init">init</a>),
+ * or in the context of password-based encryption or
+ * decryption, where the IV is derived from a user-provided password.
+ *
+ * @return the initialization vector in a new buffer, or null if the
+ * underlying algorithm does not use an IV, or if the IV has not yet
+ * been set.
+ */
+ byte[] getIV() {
+ byte[] iv = cipher.getIV();
+ return (iv == null) ? null : (byte[])iv.clone();
+ }
+
+ /**
+ * Returns the parameters used with this cipher.
+ *
+ * <p>The returned parameters may be the same that were used to initialize
+ * this cipher, or may contain the default set of parameters or a set of
+ * randomly generated parameters used by the underlying cipher
+ * implementation (provided that the underlying cipher implementation
+ * uses a default set of parameters or creates new parameters if it needs
+ * parameters but was not initialized with any).
+ *
+ * @return the parameters used with this cipher, or null if this cipher
+ * does not use any parameters.
+ */
+ AlgorithmParameters getParameters(String algName) {
+ AlgorithmParameters params = null;
+ if (cipherMode == ECB_MODE) return null;
+ byte[] iv = getIV();
+ if (iv != null) {
+ AlgorithmParameterSpec ivSpec;
+ if (algName.equals("RC2")) {
+ RC2Crypt rawImpl = (RC2Crypt) cipher.getEmbeddedCipher();
+ ivSpec = new RC2ParameterSpec(rawImpl.getEffectiveKeyBits(),
+ iv);
+ } else {
+ ivSpec = new IvParameterSpec(iv);
+ }
+ try {
+ params = AlgorithmParameters.getInstance(algName, "SunJCE");
+ } catch (NoSuchAlgorithmException nsae) {
+ // should never happen
+ throw new RuntimeException("Cannot find " + algName +
+ " AlgorithmParameters implementation in SunJCE provider");
+ } catch (NoSuchProviderException nspe) {
+ // should never happen
+ throw new RuntimeException("Cannot find SunJCE provider");
+ }
+ try {
+ params.init(ivSpec);
+ } catch (InvalidParameterSpecException ipse) {
+ // should never happen
+ throw new RuntimeException("IvParameterSpec not supported");
+ }
+ }
+ return params;
+ }
+
+ /**
+ * Initializes this cipher with a key and a source of randomness.
+ *
+ * <p>The cipher is initialized for one of the following four operations:
+ * encryption, decryption, key wrapping or key unwrapping, depending on
+ * the value of <code>opmode</code>.
+ *
+ * <p>If this cipher requires an initialization vector (IV), it will get
+ * it from <code>random</code>.
+ * This behaviour should only be used in encryption or key wrapping
+ * mode, however.
+ * When initializing a cipher that requires an IV for decryption or
+ * key unwrapping, the IV
+ * (same IV that was used for encryption or key wrapping) must be provided
+ * explicitly as a
+ * parameter, in order to get the correct result.
+ *
+ * <p>This method also cleans existing buffer and other related state
+ * information.
+ *
+ * @param opmode the operation mode of this cipher (this is one of
+ * the following:
+ * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>,
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>)
+ * @param key the secret key
+ * @param random the source of randomness
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ */
+ void init(int opmode, Key key, SecureRandom random)
+ throws InvalidKeyException {
+ try {
+ init(opmode, key, (AlgorithmParameterSpec)null, random);
+ } catch (InvalidAlgorithmParameterException e) {
+ throw new InvalidKeyException(e.getMessage());
+ }
+ }
+
+ /**
+ * Initializes this cipher with a key, a set of
+ * algorithm parameters, and a source of randomness.
+ *
+ * <p>The cipher is initialized for one of the following four operations:
+ * encryption, decryption, key wrapping or key unwrapping, depending on
+ * the value of <code>opmode</code>.
+ *
+ * <p>If this cipher (including its underlying feedback or padding scheme)
+ * requires any random bytes, it will get them from <code>random</code>.
+ *
+ * @param opmode the operation mode of this cipher (this is one of
+ * the following:
+ * <code>ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>,
+ * <code>WRAP_MODE</code> or <code>UNWRAP_MODE</code>)
+ * @param key the encryption key
+ * @param params the algorithm parameters
+ * @param random the source of randomness
+ *
+ * @exception InvalidKeyException if the given key is inappropriate for
+ * initializing this cipher
+ * @exception InvalidAlgorithmParameterException if the given algorithm
+ * parameters are inappropriate for this cipher
+ */
+ void init(int opmode, Key key, AlgorithmParameterSpec params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ decrypting = (opmode == Cipher.DECRYPT_MODE)
+ || (opmode == Cipher.UNWRAP_MODE);
+
+ byte[] keyBytes = getKeyBytes(key);
+
+ byte[] ivBytes;
+ if (params == null) {
+ ivBytes = null;
+ } else if (params instanceof IvParameterSpec) {
+ ivBytes = ((IvParameterSpec)params).getIV();
+ if ((ivBytes == null) || (ivBytes.length != blockSize)) {
+ throw new InvalidAlgorithmParameterException
+ ("Wrong IV length: must be " + blockSize +
+ " bytes long");
+ }
+ } else if (params instanceof RC2ParameterSpec) {
+ ivBytes = ((RC2ParameterSpec)params).getIV();
+ if ((ivBytes != null) && (ivBytes.length != blockSize)) {
+ throw new InvalidAlgorithmParameterException
+ ("Wrong IV length: must be " + blockSize +
+ " bytes long");
+ }
+ } else {
+ throw new InvalidAlgorithmParameterException("Wrong parameter "
+ + "type: IV "
+ + "expected");
+ }
+
+ if (cipherMode == ECB_MODE) {
+ if (ivBytes != null) {
+ throw new InvalidAlgorithmParameterException
+ ("ECB mode cannot use IV");
+ }
+ } else if (ivBytes == null) {
+ if (decrypting) {
+ throw new InvalidAlgorithmParameterException("Parameters "
+ + "missing");
+ }
+ if (random == null) {
+ random = SunJCE.RANDOM;
+ }
+ ivBytes = new byte[blockSize];
+ random.nextBytes(ivBytes);
+ }
+
+ buffered = 0;
+ diffBlocksize = blockSize;
+
+ String algorithm = key.getAlgorithm();
+
+ cipher.init(decrypting, algorithm, keyBytes, ivBytes);
+ }
+
+ void init(int opmode, Key key, AlgorithmParameters params,
+ SecureRandom random)
+ throws InvalidKeyException, InvalidAlgorithmParameterException {
+ IvParameterSpec ivSpec = null;
+ if (params != null) {
+ try {
+ ivSpec = (IvParameterSpec)params.getParameterSpec
+ (IvParameterSpec.class);
+ } catch (InvalidParameterSpecException ipse) {
+ throw new InvalidAlgorithmParameterException("Wrong parameter "
+ + "type: IV "
+ + "expected");
+ }
+ }
+ init(opmode, key, ivSpec, random);
+ }
+
+ /**
+ * Return the key bytes of the specified key. Throw an InvalidKeyException
+ * if the key is not usable.
+ */
+ static byte[] getKeyBytes(Key key) throws InvalidKeyException {
+ if (key == null) {
+ throw new InvalidKeyException("No key given");
+ }
+ // note: key.getFormat() may return null
+ if (!"RAW".equalsIgnoreCase(key.getFormat())) {
+ throw new InvalidKeyException("Wrong format: RAW bytes needed");
+ }
+ byte[] keyBytes = key.getEncoded();
+ if (keyBytes == null) {
+ throw new InvalidKeyException("RAW key bytes missing");
+ }
+ return keyBytes;
+ }
+
+ /**
+ * Continues a multiple-part encryption or decryption operation
+ * (depending on how this cipher was initialized), processing another data
+ * part.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, are processed, and the
+ * result is stored in a new buffer.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ *
+ * @return the new buffer with the result
+ *
+ * @exception IllegalStateException if this cipher is in a wrong state
+ * (e.g., has not been initialized)
+ */
+ byte[] update(byte[] input, int inputOffset, int inputLen) {
+ byte[] output = null;
+ byte[] out = null;
+ try {
+ output = new byte[getOutputSize(inputLen)];
+ int len = update(input, inputOffset, inputLen, output,
+ 0);
+ if (len == output.length) {
+ out = output;
+ } else {
+ out = new byte[len];
+ System.arraycopy(output, 0, out, 0, len);
+ }
+ } catch (ShortBufferException e) {
+ // never thrown
+ }
+ return out;
+ }
+
+ /**
+ * Continues a multiple-part encryption or decryption operation
+ * (depending on how this cipher was initialized), processing another data
+ * part.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, are processed, and the
+ * result is stored in the <code>output</code> buffer, starting at
+ * <code>outputOffset</code>.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ * @param output the buffer for the result
+ * @param outputOffset the offset in <code>output</code> where the result
+ * is stored
+ *
+ * @return the number of bytes stored in <code>output</code>
+ *
+ * @exception ShortBufferException if the given output buffer is too small
+ * to hold the result
+ */
+ int update(byte[] input, int inputOffset, int inputLen, byte[] output,
+ int outputOffset) throws ShortBufferException {
+ // figure out how much can be sent to crypto function
+ int len = buffered + inputLen - minBytes;
+ if (padding != null && decrypting) {
+ // do not include the padding bytes when decrypting
+ len -= blockSize;
+ }
+ // do not count the trailing bytes which do not make up a unit
+ len = (len > 0 ? (len - (len%unitBytes)) : 0);
+
+ // check output buffer capacity
+ if ((output == null) || ((output.length - outputOffset) < len)) {
+ throw new ShortBufferException("Output buffer must be "
+ + "(at least) " + len
+ + " bytes long");
+ }
+ if (len != 0) {
+ // there is some work to do
+ byte[] in = new byte[len];
+
+ int inputConsumed = len - buffered;
+ int bufferedConsumed = buffered;
+ if (inputConsumed < 0) {
+ inputConsumed = 0;
+ bufferedConsumed = len;
+ }
+
+ if (buffered != 0) {
+ System.arraycopy(buffer, 0, in, 0, bufferedConsumed);
+ }
+ if (inputConsumed > 0) {
+ System.arraycopy(input, inputOffset, in,
+ bufferedConsumed, inputConsumed);
+ }
+
+ if (decrypting) {
+ cipher.decrypt(in, 0, len, output, outputOffset);
+ } else {
+ cipher.encrypt(in, 0, len, output, outputOffset);
+ }
+
+ // Let's keep track of how many bytes are needed to make
+ // the total input length a multiple of blocksize when
+ // padding is applied
+ if (unitBytes != blockSize) {
+ if (len < diffBlocksize)
+ diffBlocksize -= len;
+ else
+ diffBlocksize = blockSize -
+ ((len - diffBlocksize) % blockSize);
+ }
+
+ inputLen -= inputConsumed;
+ inputOffset += inputConsumed;
+ outputOffset += len;
+ buffered -= bufferedConsumed;
+ if (buffered > 0) {
+ System.arraycopy(buffer, bufferedConsumed, buffer, 0,
+ buffered);
+ }
+ }
+ // left over again
+ if (inputLen > 0) {
+ System.arraycopy(input, inputOffset, buffer, buffered,
+ inputLen);
+ }
+ buffered += inputLen;
+ return len;
+ }
+
+ /**
+ * Encrypts or decrypts data in a single-part operation,
+ * or finishes a multiple-part operation.
+ * The data is encrypted or decrypted, depending on how this cipher was
+ * initialized.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, and any input bytes that
+ * may have been buffered during a previous <code>update</code> operation,
+ * are processed, with padding (if requested) being applied.
+ * The result is stored in a new buffer.
+ *
+ * <p>The cipher is reset to its initial state (uninitialized) after this
+ * call.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ *
+ * @return the new buffer with the result
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block cipher,
+ * no padding has been requested (only in encryption mode), and the total
+ * input length of the data processed by this cipher is not a multiple of
+ * block size
+ * @exception BadPaddingException if this cipher is in decryption mode,
+ * and (un)padding has been requested, but the decrypted data is not
+ * bounded by the appropriate padding bytes
+ */
+ byte[] doFinal(byte[] input, int inputOffset, int inputLen)
+ throws IllegalBlockSizeException, BadPaddingException {
+ byte[] output = null;
+ byte[] out = null;
+ try {
+ output = new byte[getOutputSize(inputLen)];
+ int len = doFinal(input, inputOffset, inputLen, output, 0);
+ if (len < output.length) {
+ out = new byte[len];
+ if (len != 0)
+ System.arraycopy(output, 0, out, 0, len);
+ } else {
+ out = output;
+ }
+ } catch (ShortBufferException e) {
+ // never thrown
+ }
+ return out;
+ }
+
+ /**
+ * Encrypts or decrypts data in a single-part operation,
+ * or finishes a multiple-part operation.
+ * The data is encrypted or decrypted, depending on how this cipher was
+ * initialized.
+ *
+ * <p>The first <code>inputLen</code> bytes in the <code>input</code>
+ * buffer, starting at <code>inputOffset</code>, and any input bytes that
+ * may have been buffered during a previous <code>update</code> operation,
+ * are processed, with padding (if requested) being applied.
+ * The result is stored in the <code>output</code> buffer, starting at
+ * <code>outputOffset</code>.
+ *
+ * <p>The cipher is reset to its initial state (uninitialized) after this
+ * call.
+ *
+ * @param input the input buffer
+ * @param inputOffset the offset in <code>input</code> where the input
+ * starts
+ * @param inputLen the input length
+ * @param output the buffer for the result
+ * @param outputOffset the offset in <code>output</code> where the result
+ * is stored
+ *
+ * @return the number of bytes stored in <code>output</code>
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block cipher,
+ * no padding has been requested (only in encryption mode), and the total
+ * input length of the data processed by this cipher is not a multiple of
+ * block size
+ * @exception ShortBufferException if the given output buffer is too small
+ * to hold the result
+ * @exception BadPaddingException if this cipher is in decryption mode,
+ * and (un)padding has been requested, but the decrypted data is not
+ * bounded by the appropriate padding bytes
+ */
+ int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output,
+ int outputOffset)
+ throws IllegalBlockSizeException, ShortBufferException,
+ BadPaddingException {
+
+ // calculate the total input length
+ int totalLen = buffered + inputLen;
+ int paddedLen = totalLen;
+ int paddingLen = 0;
+
+ // will the total input length be a multiple of blockSize?
+ if (unitBytes != blockSize) {
+ if (totalLen < diffBlocksize) {
+ paddingLen = diffBlocksize - totalLen;
+ } else {
+ paddingLen = blockSize -
+ ((totalLen - diffBlocksize) % blockSize);
+ }
+ } else if (padding != null) {
+ paddingLen = padding.padLength(totalLen);
+ }
+
+ if ((paddingLen > 0) && (paddingLen != blockSize) &&
+ (padding != null) && decrypting) {
+ throw new IllegalBlockSizeException
+ ("Input length must be multiple of " + blockSize +
+ " when decrypting with padded cipher");
+ }
+
+ // if encrypting and padding not null, add padding
+ if (!decrypting && padding != null)
+ paddedLen += paddingLen;
+
+ // check output buffer capacity.
+ // if we are decrypting with padding applied, we can perform this
+ // check only after we have determined how many padding bytes there
+ // are.
+ if (output == null) {
+ throw new ShortBufferException("Output buffer is null");
+ }
+ int outputCapacity = output.length - outputOffset;
+ if (((!decrypting) || (padding == null)) &&
+ (outputCapacity < paddedLen) ||
+ (decrypting && (outputCapacity < (paddedLen - blockSize)))) {
+ throw new ShortBufferException("Output buffer too short: "
+ + outputCapacity + " bytes given, "
+ + paddedLen + " bytes needed");
+ }
+
+ // prepare the final input avoiding copying if possible
+ byte[] finalBuf = input;
+ int finalOffset = inputOffset;
+ if ((buffered != 0) || (!decrypting && padding != null)) {
+ finalOffset = 0;
+ finalBuf = new byte[paddedLen];
+ if (buffered != 0) {
+ System.arraycopy(buffer, 0, finalBuf, 0, buffered);
+ }
+ if (inputLen != 0) {
+ System.arraycopy(input, inputOffset, finalBuf,
+ buffered, inputLen);
+ }
+ if (!decrypting && padding != null) {
+ padding.padWithLen(finalBuf, totalLen, paddingLen);
+ }
+ }
+
+ if (decrypting) {
+ // if the size of specified output buffer is less than
+ // the length of the cipher text, then the current
+ // content of cipher has to be preserved in order for
+ // users to retry the call with a larger buffer in the
+ // case of ShortBufferException.
+ if (outputCapacity < paddedLen) {
+ cipher.save();
+ }
+ // create temporary output buffer so that only "real"
+ // data bytes are passed to user's output buffer.
+ byte[] outWithPadding = new byte[totalLen];
+ totalLen = finalNoPadding(finalBuf, finalOffset, outWithPadding,
+ 0, totalLen);
+
+ if (padding != null) {
+ int padStart = padding.unpad(outWithPadding, 0, totalLen);
+ if (padStart < 0) {
+ throw new BadPaddingException("Given final block not "
+ + "properly padded");
+ }
+ totalLen = padStart;
+ }
+ if ((output.length - outputOffset) < totalLen) {
+ // restore so users can retry with a larger buffer
+ cipher.restore();
+ throw new ShortBufferException("Output buffer too short: "
+ + (output.length-outputOffset)
+ + " bytes given, " + totalLen
+ + " bytes needed");
+ }
+ for (int i = 0; i < totalLen; i++) {
+ output[outputOffset + i] = outWithPadding[i];
+ }
+ } else { // encrypting
+ totalLen = finalNoPadding(finalBuf, finalOffset, output,
+ outputOffset, paddedLen);
+ }
+
+ buffered = 0;
+ diffBlocksize = blockSize;
+ if (cipherMode != ECB_MODE) {
+ ((FeedbackCipher)cipher).reset();
+ }
+ return totalLen;
+ }
+
+ private int finalNoPadding(byte[] in, int inOff, byte[] out, int outOff,
+ int len)
+ throws IllegalBlockSizeException
+ {
+ if (in == null || len == 0)
+ return 0;
+
+ if ((cipherMode != CFB_MODE) && (cipherMode != OFB_MODE)
+ && ((len % unitBytes) != 0) && (cipherMode != CTS_MODE)) {
+ if (padding != null) {
+ throw new IllegalBlockSizeException
+ ("Input length (with padding) not multiple of " +
+ unitBytes + " bytes");
+ } else {
+ throw new IllegalBlockSizeException
+ ("Input length not multiple of " + unitBytes
+ + " bytes");
+ }
+ }
+
+ if (decrypting) {
+ cipher.decryptFinal(in, inOff, len, out, outOff);
+ } else {
+ cipher.encryptFinal(in, inOff, len, out, outOff);
+ }
+
+ return len;
+ }
+
+ // Note: Wrap() and Unwrap() are the same in
+ // each of SunJCE CipherSpi implementation classes.
+ // They are duplicated due to export control requirements:
+ // All CipherSpi implementation must be final.
+ /**
+ * Wrap a key.
+ *
+ * @param key the key to be wrapped.
+ *
+ * @return the wrapped key.
+ *
+ * @exception IllegalBlockSizeException if this cipher is a block
+ * cipher, no padding has been requested, and the length of the
+ * encoding of the key to be wrapped is not a
+ * multiple of the block size.
+ *
+ * @exception InvalidKeyException if it is impossible or unsafe to
+ * wrap the key with this cipher (e.g., a hardware protected key is
+ * being passed to a software only cipher).
+ */
+ byte[] wrap(Key key)
+ throws IllegalBlockSizeException, InvalidKeyException {
+ byte[] result = null;
+
+ try {
+ byte[] encodedKey = key.getEncoded();
+ if ((encodedKey == null) || (encodedKey.length == 0)) {
+ throw new InvalidKeyException("Cannot get an encoding of " +
+ "the key to be wrapped");
+ }
+ result = doFinal(encodedKey, 0, encodedKey.length);
+ } catch (BadPaddingException e) {
+ // Should never happen
+ }
+ return result;
+ }
+
+ /**
+ * Unwrap a previously wrapped key.
+ *
+ * @param wrappedKey the key to be unwrapped.
+ *
+ * @param wrappedKeyAlgorithm the algorithm the wrapped key is for.
+ *
+ * @param wrappedKeyType the type of the wrapped key.
+ * This is one of <code>Cipher.SECRET_KEY</code>,
+ * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>.
+ *
+ * @return the unwrapped key.
+ *
+ * @exception NoSuchAlgorithmException if no installed providers
+ * can create keys of type <code>wrappedKeyType</code> for the
+ * <code>wrappedKeyAlgorithm</code>.
+ *
+ * @exception InvalidKeyException if <code>wrappedKey</code> does not
+ * represent a wrapped key of type <code>wrappedKeyType</code> for
+ * the <code>wrappedKeyAlgorithm</code>.
+ */
+ Key unwrap(byte[] wrappedKey, String wrappedKeyAlgorithm,
+ int wrappedKeyType)
+ throws InvalidKeyException, NoSuchAlgorithmException {
+ byte[] encodedKey;
+ try {
+ encodedKey = doFinal(wrappedKey, 0, wrappedKey.length);
+ } catch (BadPaddingException ePadding) {
+ throw new InvalidKeyException("The wrapped key is not padded " +
+ "correctly");
+ } catch (IllegalBlockSizeException eBlockSize) {
+ throw new InvalidKeyException("The wrapped key does not have " +
+ "the correct length");
+ }
+ return ConstructKeys.constructKey(encodedKey, wrappedKeyAlgorithm,
+ wrappedKeyType);
+ }
+}
diff --git a/ojluni/src/main/java/com/sun/crypto/provider/CipherFeedback.java b/ojluni/src/main/java/com/sun/crypto/provider/CipherFeedback.java
new file mode 100755
index 0000000..a5f74f6
--- /dev/null
+++ b/ojluni/src/main/java/com/sun/crypto/provider/CipherFeedback.java
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.crypto.provider;
+
+import java.security.InvalidKeyException;
+
+/**
+ * This class represents ciphers in cipher-feedback (CFB) mode.
+ *
+ * <p>This mode is implemented independently of a particular cipher.
+ * Ciphers to which this mode should apply (e.g., DES) must be
+ * <i>plugged-in</i> using the constructor.
+ *
+ * <p>NOTE: This class does not deal with buffering or padding.
+ *
+ * @author Gigi Ankeny
+ */
+
+final class CipherFeedback extends FeedbackCipher {
+
+ /*
+ * encrypt/decrypt output buffer
+ */
+ private final byte[] k;
+
+ /*
+ * register value, initialized with iv
+ */
+ private final byte[] register;
+
+ /*
+ * number of bytes for each stream unit, defaults to the blocksize
+ * of the embedded cipher
+ */
+ private int numBytes;
+
+ // variables for save/restore calls
+ private byte[] registerSave = null;
+
+ CipherFeedback(SymmetricCipher embeddedCipher, int numBytes) {
+ super(embeddedCipher);
+ if (numBytes > blockSize) {
+ numBytes = blockSize;
+ }
+ this.numBytes = numBytes;
+ k = new byte[blockSize];
+ register = new byte[blockSize];
+ }
+
+ /**
+ * Gets the name of this feedback mode.
+ *
+ * @return the string <code>CFB</code>
+ */
+ String getFeedback() {
+ return "CFB";
+ }
+
+ /**
+ * Initializes the cipher in the specified mode with the g