From: <ls...@us...> - 2006-12-10 19:35:29
|
Revision: 2889 http://jnode.svn.sourceforge.net/jnode/?rev=2889&view=rev Author: lsantha Date: 2006-12-10 11:35:28 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Classpath patches. Added Paths: ----------- trunk/core/src/classpath/gnu/gnu/classpath/ListenerData.java trunk/core/src/classpath/gnu/gnu/javax/management/ trunk/core/src/classpath/gnu/gnu/javax/management/Server.java Added: trunk/core/src/classpath/gnu/gnu/classpath/ListenerData.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/classpath/ListenerData.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/classpath/ListenerData.java 2006-12-10 19:35:28 UTC (rev 2889) @@ -0,0 +1,136 @@ +/* ListenerData.java - Class to contain data about management bean listeners + Copyright (C) 2006 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath; + +import javax.management.NotificationFilter; +import javax.management.NotificationListener; + +/** + * Container for data on management listeners. Wraps + * a {@link javax.management.NotificationListener}, + * {@link javax.management.NotificationFilter} and + * passback object in one class. + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public class ListenerData +{ + /** + * The listener itself. + */ + private NotificationListener listener; + + /** + * A filter to apply to incoming events. + */ + private NotificationFilter filter; + + /** + * An object to pass back to the listener on an + * event occurring. + */ + private Object passback; + + /** + * Constructs a new {@link ListenerData} with the specified + * listener, filter and passback object. + * + * @param listener the listener itself. + * @param filter the filter for incoming events. + * @param passback the object to passback on an incoming event. + */ + public ListenerData(NotificationListener listener, + NotificationFilter filter, Object passback) + { + this.listener = listener; + this.filter = filter; + this.passback = passback; + } + + /** + * Returns the listener. + * + * @return the listener. + */ + public NotificationListener getListener() + { + return listener; + } + + /** + * Returns the filter. + * + * @return the filter. + */ + public NotificationFilter getFilter() + { + return filter; + } + + /** + * Returns the passback object. + * + * @return the passback object. + */ + public Object getPassback() + { + return passback; + } + + /** + * Returns true if the supplied object is an instance of + * {@link ListenerData} and has the same listener, filter + * and passback object. + * + * @param obj the object to check. + * @return true if <code>obj</code> is equal to this. + */ + public boolean equals(Object obj) + { + if (obj instanceof ListenerData) + { + ListenerData data = (ListenerData) obj; + return (data.getListener() == listener && + data.getFilter() == filter && + data.getPassback() == passback); + } + return false; + } + +} Added: trunk/core/src/classpath/gnu/gnu/javax/management/Server.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/management/Server.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/javax/management/Server.java 2006-12-10 19:35:28 UTC (rev 2889) @@ -0,0 +1,2200 @@ +/* Server.java -- A GNU Classpath management server. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.javax.management; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; +import java.io.StreamCorruptedException; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.AttributeNotFoundException; +import javax.management.BadAttributeValueExpException; +import javax.management.BadBinaryOpValueExpException; +import javax.management.BadStringOperationException; +import javax.management.DynamicMBean; +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.IntrospectionException; +import javax.management.InvalidApplicationException; +import javax.management.InvalidAttributeValueException; +import javax.management.ListenerNotFoundException; +import javax.management.MalformedObjectNameException; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.MBeanPermission; +import javax.management.MBeanRegistration; +import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.MBeanServerDelegate; +import javax.management.MBeanTrustPermission; +import javax.management.NotCompliantMBeanException; +import javax.management.Notification; +import javax.management.NotificationBroadcaster; +import javax.management.NotificationEmitter; +import javax.management.NotificationFilter; +import javax.management.NotificationListener; +import javax.management.ObjectInstance; +import javax.management.ObjectName; +import javax.management.OperationsException; +import javax.management.QueryExp; +import javax.management.ReflectionException; +import javax.management.RuntimeOperationsException; +import javax.management.StandardMBean; + +import javax.management.loading.ClassLoaderRepository; + +/** + * This class provides an {@link javax.management.MBeanServer} + * implementation for GNU Classpath. + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public class Server + implements MBeanServer +{ + + /** + * The name of the delegate bean. + */ + private static final ObjectName DELEGATE_NAME; + + /** + * The registered beans, represented as a map of + * {@link javax.management.ObjectName}s to + * {@link java.lang.Object}s. + */ + private final Map beans = new HashMap(); + + /** + * The default domain. + */ + private String defaultDomain; + + /** + * The outer server. + */ + private MBeanServer outer; + + /** + * The class loader repository. + */ + private ClassLoaderRepository repository; + + /** + * The map of listener delegates to the true + * listener. + */ + private Map listeners; + + /** + * Initialise the delegate name. + */ + static + { + try + { + DELEGATE_NAME = + new ObjectName("JMImplementation:type=MBeanServerDelegate"); + } + catch (MalformedObjectNameException e) + { + throw (Error) + (new InternalError("Failed to construct " + + "the delegate's object name.").initCause(e)); + } + } + + /** + * Constructs a new management server using the specified + * default domain, delegate bean and outer server. + * + * @param domain the default domain to use for beans constructed + * with no specified domain. + * @param outer an {@link javax.management.MBeanServer} to pass + * to beans implementing the {@link MBeanRegistration} + * interface, or <code>null</code> if <code>this</code> + * should be passed. + * @param delegate the delegate bean for this server. + */ + public Server(String defaultDomain, MBeanServer outer, + MBeanServerDelegate delegate) + { + this.defaultDomain = defaultDomain; + this.outer = outer; + try + { + registerMBean(delegate, DELEGATE_NAME); + } + catch (InstanceAlreadyExistsException e) + { + throw (Error) + (new InternalError("The delegate bean is " + + "already registered.").initCause(e)); + } + catch (MBeanRegistrationException e) + { + throw (Error) + (new InternalError("The delegate bean's preRegister " + + "methods threw an exception.").initCause(e)); + } + catch (NotCompliantMBeanException e) + { + throw (Error) + (new InternalError("The delegate bean is " + + "not compliant.").initCause(e)); + } + } + + /** + * Checks for the necessary security privileges to perform an + * operation. + * + * @param name the name of the bean being accessed. + * @param member the name of the operation or attribute being + * accessed, or <code>null</code> if one is not + * involved. + * @param action the action being performed. + * @throws SecurityException if the action is denied. + */ + private void checkSecurity(ObjectName name, String member, + String action) + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + try + { + MBeanInfo info = null; + if (name != null) + { + Object bean = getBean(name); + Method method = bean.getClass().getMethod("getMBeanInfo", null); + info = (MBeanInfo) method.invoke(bean, null); + } + sm.checkPermission(new MBeanPermission((info == null) ? + null : info.getClassName(), + member, name, action)); + } + catch (InstanceNotFoundException e) + { + throw (Error) + (new InternalError("Failed to get bean.").initCause(e)); + } + catch (NoSuchMethodException e) + { + throw (Error) + (new InternalError("Failed to get bean info.").initCause(e)); + } + catch (IllegalAccessException e) + { + throw (Error) + (new InternalError("Failed to get bean info.").initCause(e)); + } + catch (IllegalArgumentException e) + { + throw (Error) + (new InternalError("Failed to get bean info.").initCause(e)); + } + catch (InvocationTargetException e) + { + throw (Error) + (new InternalError("Failed to get bean info.").initCause(e)); + } + } + + /** + * Retrieves the specified bean. + * + * @param name the name of the bean. + * @return the bean. + * @throws InstanceNotFoundException if the name of the management bean + * could not be resolved. + */ + private Object getBean(ObjectName name) + throws InstanceNotFoundException + { + ServerInfo bean = (ServerInfo) beans.get(name); + if (bean == null) + throw new InstanceNotFoundException("The bean, " + name + + ", was not found."); + return bean.getObject(); + } + + /** + * Registers the supplied listener with the specified management + * bean. Notifications emitted by the management bean are forwarded + * to the listener via the server, which will convert an MBean + * references in the source to a portable {@link ObjectName} + * instance. The notification is otherwise unchanged. + * + * @param name the name of the management bean with which the listener + * should be registered. + * @param listener the listener which will handle notifications from + * the bean. + * @param filter the filter to apply to incoming notifications, or + * <code>null</code> if no filtering should be applied. + * @param passback an object to be passed to the listener when a + * notification is emitted. + * @throws InstanceNotFoundException if the name of the management bean + * could not be resolved. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "addNotificationListener")</code>}. + * @see #removeNotificationListener(ObjectName, NotificationListener) + * @see #removeNotificationListener(ObjectName, NotificationListener, + * NotificationFilter, Object) + * @see NotificationBroadcaster#addNotificationListener(NotificationListener, + * NotificationFilter, + * Object) + */ + public void addNotificationListener(ObjectName name, NotificationListener listener, + NotificationFilter filter, Object passback) + throws InstanceNotFoundException + { + Object bean = getBean(name); + checkSecurity(name, null, "addNotificationListener"); + if (bean instanceof NotificationBroadcaster) + { + NotificationBroadcaster bbean = (NotificationBroadcaster) bean; + if (listeners == null) + listeners = new HashMap(); + NotificationListener indirection = new ServerNotificationListener(bean, name, + listener); + bbean.addNotificationListener(indirection, filter, passback); + listeners.put(listener, indirection); + } + } + + /** + * <p> + * Registers the supplied listener with the specified management + * bean. Notifications emitted by the management bean are forwarded + * to the listener via the server, which will convert any MBean + * references in the source to portable {@link ObjectName} + * instances. The notification is otherwise unchanged. + * </p> + * <p> + * The listener that receives notifications will be the one that is + * registered with the given name at the time this method is called. + * Even if it later unregisters and ceases to use that name, it will + * still receive notifications. + * </p> + * + * @param name the name of the management bean with which the listener + * should be registered. + * @param listener the name of the listener which will handle + * notifications from the bean. + * @param filter the filter to apply to incoming notifications, or + * <code>null</code> if no filtering should be applied. + * @param passback an object to be passed to the listener when a + * notification is emitted. + * @throws InstanceNotFoundException if the name of the management bean + * could not be resolved. + * @throws RuntimeOperationsException if the bean associated with the given + * object name is not a + * {@link NotificationListener}. This + * exception wraps an + * {@link IllegalArgumentException}. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "addNotificationListener")</code>}. + * @see #removeNotificationListener(ObjectName, NotificationListener) + * @see #removeNotificationListener(ObjectName, NotificationListener, + * NotificationFilter, Object) + * @see NotificationBroadcaster#addNotificationListener(NotificationListener, + * NotificationFilter, + * Object) + */ + public void addNotificationListener(ObjectName name, ObjectName listener, + NotificationFilter filter, Object passback) + throws InstanceNotFoundException + { + Object lbean = getBean(listener); + if (!(lbean instanceof NotificationListener)) + { + RuntimeException e = + new IllegalArgumentException("The supplied listener name does not " + + "correspond to a notification listener."); + throw new RuntimeOperationsException(e); + } + addNotificationListener(name, ((NotificationListener) lbean), filter, passback); + } + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the default constructor and registers it with the server + * under the supplied name. The class is loaded using the + * {@link javax.management.loading.ClassLoaderRepository default + * loader repository} of the server. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * <p> + * This method is equivalent to calling {@link + * #createMBean(String, ObjectName, Object[], String[]) + * <code>createMBean(className, name, (Object[]) null, + * (String[]) null)</code>} with <code>null</code> parameters + * and signature. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + * @see #createMBean(String, ObjectName, Object[], String[]) + */ + public ObjectInstance createMBean(String className, ObjectName name) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException + { + return createMBean(className, name, (Object[]) null, (String[]) null); + } + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the given constructor and registers it with the server + * under the supplied name. The class is loaded using the + * {@link javax.management.loading.ClassLoaderRepository default + * loader repository} of the server. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @param params the parameters for the bean's constructor. + * @param sig the signature of the constructor to use. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + */ + public ObjectInstance createMBean(String className, ObjectName name, + Object[] params, String[] sig) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException + { + return registerMBean(instantiate(className, params, sig), name); + } + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the default constructor and registers it with the server + * under the supplied name. The class is loaded using the + * given class loader. If this argument is <code>null</code>, + * then the same class loader as was used to load the server + * is used. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * <p> + * This method is equivalent to calling {@link + * #createMBean(String, ObjectName, ObjectName, Object[], String) + * <code>createMBean(className, name, loaderName, (Object[]) null, + * (String) null)</code>} with <code>null</code> parameters + * and signature. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @param loaderName the name of the class loader. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws InstanceNotFoundException if the specified class loader is not + * registered with the server. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + * @see #createMBean(String, ObjectName, ObjectName, Object[], String[]) + */ + public ObjectInstance createMBean(String className, ObjectName name, + ObjectName loaderName) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException, InstanceNotFoundException + { + return createMBean(className, name, loaderName, (Object[]) null, + (String[]) null); + } + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the given constructor and registers it with the server + * under the supplied name. The class is loaded using the + * given class loader. If this argument is <code>null</code>, + * then the same class loader as was used to load the server + * is used. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @param loaderName the name of the class loader. + * @param params the parameters for the bean's constructor. + * @param sig the signature of the constructor to use. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws InstanceNotFoundException if the specified class loader is not + * registered with the server. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + */ + public ObjectInstance createMBean(String className, ObjectName name, + ObjectName loaderName, Object[] params, + String[] sig) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException, InstanceNotFoundException + { + return registerMBean(instantiate(className, loaderName, params, sig), + name); + } + + /** + * Deserializes a byte array using the class loader of the specified + * management bean as its context. + * + * @param name the name of the bean whose class loader should be used. + * @param data the byte array to be deserialized. + * @return the deserialized object stream. + * @deprecated {@link #getClassLoaderFor(ObjectName)} should be used + * to obtain the class loader of the bean, which can then + * be used to perform deserialization in the user's code. + * @throws InstanceNotFoundException if the specified bean is not + * registered with the server. + * @throws OperationsException if any I/O error is thrown by the + * deserialization process. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getClassLoaderFor")</code> + */ + public ObjectInputStream deserialize(ObjectName name, byte[] data) + throws InstanceNotFoundException, OperationsException + { + try + { + return new ServerInputStream(new ByteArrayInputStream(data), + getClassLoaderFor(name)); + } + catch (IOException e) + { + throw new OperationsException("An I/O error occurred: " + e); + } + } + + /** + * Deserializes a byte array using the same class loader for its context + * as was used to load the given class. This class loader is obtained by + * loading the specified class using the {@link + * javax.management.loading.ClassLoaderRepository Class Loader Repository} + * and then using the class loader of the resulting {@link Class} instance. + * + * @param name the name of the class which should be loaded to obtain the + * class loader. + * @param data the byte array to be deserialized. + * @return the deserialized object stream. + * @deprecated {@link #getClassLoaderRepository} should be used + * to obtain the class loading repository, which can then + * be used to obtain the {@link Class} instance and deserialize + * the array using its class loader. + * @throws OperationsException if any I/O error is thrown by the + * deserialization process. + * @throws ReflectionException if an error occurs in obtaining the + * {@link Class} instance. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, null, + * "getClassLoaderRepository")</code> + */ + public ObjectInputStream deserialize(String name, byte[] data) + throws OperationsException, ReflectionException + { + try + { + Class c = getClassLoaderRepository().loadClass(name); + return new ServerInputStream(new ByteArrayInputStream(data), + c.getClassLoader()); + } + catch (IOException e) + { + throw new OperationsException("An I/O error occurred: " + e); + } + catch (ClassNotFoundException e) + { + throw new ReflectionException(e, "The class could not be found."); + } + } + + /** + * Deserializes a byte array using the same class loader for its context + * as was used to load the given class. The name of the class loader to + * be used is supplied, and may be <code>null</code> if the server's + * class loader should be used instead. + * + * @param name the name of the class which should be loaded to obtain the + * class loader. + * @param loader the name of the class loader to use, or <code>null</code> + * if the class loader of the server should be used. + * @param data the byte array to be deserialized. + * @return the deserialized object stream. + * @deprecated {@link #getClassLoader(ObjectName} can be used to obtain + * the named class loader and deserialize the array. + * @throws InstanceNotFoundException if the specified class loader is not + * registered with the server. + * @throws OperationsException if any I/O error is thrown by the + * deserialization process. + * @throws ReflectionException if an error occurs in obtaining the + * {@link Class} instance. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, loader, + * "getClassLoader")</code> + */ + public ObjectInputStream deserialize(String name, ObjectName loader, byte[] data) + throws InstanceNotFoundException, ReflectionException, + OperationsException + { + try + { + Class c = getClassLoader(loader).loadClass(name); + return new ServerInputStream(new ByteArrayInputStream(data), + c.getClassLoader()); + } + catch (IOException e) + { + throw new OperationsException("An I/O error occurred: " + e); + } + catch (ClassNotFoundException e) + { + throw new ReflectionException(e, "The class could not be found."); + } + } + + /** + * Returns the value of the supplied attribute from the specified + * management bean. + * + * @param bean the bean to retrieve the value from. + * @param name the name of the attribute to retrieve. + * @return the value of the attribute. + * @throws AttributeNotFoundException if the attribute could not be + * accessed from the bean. + * @throws MBeanException if the management bean's accessor throws + * an exception. + * @throws InstanceNotFoundException if the bean can not be found. + * @throws ReflectionException if an exception was thrown in trying + * to invoke the bean's accessor. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> bean or attribute + * name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, name, bean, + * "getAttribute")</code>}. + * @see DynamicMBean#getAttribute(String) + */ + public Object getAttribute(ObjectName bean, String name) + throws MBeanException, AttributeNotFoundException, + InstanceNotFoundException, ReflectionException + { + if (bean == null || name == null) + { + RuntimeException e = + new IllegalArgumentException("One of the supplied arguments was null."); + throw new RuntimeOperationsException(e); + } + Object abean = getBean(bean); + checkSecurity(bean, name, "getAttribute"); + if (abean instanceof DynamicMBean) + return ((DynamicMBean) abean).getAttribute(name); + else + try + { + return new StandardMBean(abean, null).getAttribute(name); + } + catch (NotCompliantMBeanException e) + { + throw (Error) + (new InternalError("Failed to create dynamic bean.").initCause(e)); + } + } + + + /** + * Returns the values of the named attributes from the specified + * management bean. + * + * @param bean the bean to retrieve the value from. + * @param names the names of the attributes to retrieve. + * @return the values of the attributes. + * @throws InstanceNotFoundException if the bean can not be found. + * @throws ReflectionException if an exception was thrown in trying + * to invoke the bean's accessor. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> bean or attribute + * name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, bean, + * "getAttribute")</code>}. Additionally, + * for an attribute name, <code>n</code>, the + * caller's permission must imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, n, bean, + * "getAttribute")</code>} or that attribute will + * not be included. + * + * @see DynamicMBean#getAttributes(String[]) + */ + public AttributeList getAttributes(ObjectName bean, String[] names) + throws InstanceNotFoundException, ReflectionException + { + if (bean == null || names == null) + { + RuntimeException e = + new IllegalArgumentException("One of the supplied arguments was null."); + throw new RuntimeOperationsException(e); + } + Object abean = getBean(bean); + checkSecurity(bean, null, "getAttribute"); + AttributeList list = new AttributeList(names.length); + for (int a = 0; a < names.length; ++a) + { + if (names[a] == null) + { + RuntimeException e = + new IllegalArgumentException("Argument " + a + " was null."); + throw new RuntimeOperationsException(e); + } + checkSecurity(bean, names[a], "getAttribute"); + try + { + Object value; + if (abean instanceof DynamicMBean) + value = ((DynamicMBean) abean).getAttribute(names[a]); + else + try + { + value = new StandardMBean(abean, null).getAttribute(names[a]); + } + catch (NotCompliantMBeanException e) + { + throw (Error) + (new InternalError("Failed to create dynamic bean.").initCause(e)); + } + list.add(new Attribute(names[a], value)); + } + catch (AttributeNotFoundException e) + { + /* Ignored */ + } + catch (MBeanException e) + { + /* Ignored */ + } + } + return list; + } + + + /** + * Returns the specified class loader. If the specified value is + * <code>null</code>, then the class loader of the server will be + * returned. If <code>l</code> is the requested class loader, + * and <code>r</code> is the actual class loader returned, then + * either <code>l</code> and <code>r</code> will be identical, + * or they will at least return the same class from + * {@link ClassLoader#loadClass(String)} for any given string. + * They may not be identical due to one or the other + * being wrapped in another class loader (e.g. for security). + * + * @param name the name of the class loader to return. + * @return the class loader. + * @throws InstanceNotFoundException if the class loader can not + * be found. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getClassLoader")</code> + */ + public ClassLoader getClassLoader(ObjectName name) + throws InstanceNotFoundException + { + if (name == null) + { + checkSecurity(null, null, "getClassLoader"); + return getClass().getClassLoader(); + } + Object bean = getBean(name); + checkSecurity(name, null, "getClassLoader"); + return (ClassLoader) bean; + } + + /** + * Returns the class loader of the specified management bean. If + * <code>l</code> is the requested class loader, and <code>r</code> + * is the actual class loader returned, then either <code>l</code> + * and <code>r</code> will be identical, or they will at least + * return the same class from {@link ClassLoader#loadClass(String)} + * for any given string. They may not be identical due to one or + * the other being wrapped in another class loader (e.g. for + * security). + * + * @param name the name of the bean whose class loader should be + * returned. + * @return the class loader. + * @throws InstanceNotFoundException if the bean is not registered + * with the server. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getClassLoaderFor")</code> + */ + public ClassLoader getClassLoaderFor(ObjectName name) + throws InstanceNotFoundException + { + Object bean = getBean(name); + checkSecurity(name, null, "getClassLoaderFor"); + return bean.getClass().getClassLoader(); + } + + /** + * Returns the class loader repository used by this server. + * + * @return the class loader repository. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, null, + * "getClassLoaderRepository")</code> + */ + public ClassLoaderRepository getClassLoaderRepository() + { + return repository; + } + + /** + * Returns the default domain this server applies to beans that have + * no specified domain. + * + * @return the default domain. + */ + public String getDefaultDomain() + { + return defaultDomain; + } + + + /** + * Returns an array containing all the domains used by beans registered + * with this server. The ordering of the array is undefined. + * + * @return the list of domains. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, name, + * "getDomains")</code>}. Additionally, + * for an domain, <code>d</code>, the + * caller's permission must imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, + * new ObjectName("d:x=x"), "getDomains")</code>} + * or that domain will not be included. Note + * that "x=x" is an arbitrary key-value pair + * provided to satisfy the constructor. + * @see ObjectName#getDomain() + */ + public String[] getDomains() + { + checkSecurity(null, null, "getDomains"); + Set domains = new HashSet(); + Iterator iterator = beans.keySet().iterator(); + while (iterator.hasNext()) + { + String d = ((ObjectName) iterator.next()).getDomain(); + try + { + checkSecurity(new ObjectName(d + ":x=x"), null, "getDomains"); + domains.add(d); + } + catch (MalformedObjectNameException e) + { + /* Ignored */ + } + } + return (String[]) domains.toArray(new String[domains.size()]); + } + + /** + * Returns the number of management beans registered with this server. + * This may be less than the real number if the caller's access is + * restricted. + * + * @return the number of registered beans. + */ + public Integer getMBeanCount() + { + return Integer.valueOf(beans.size()); + } + + /** + * Returns information on the given management bean. + * + * @param name the name of the management bean. + * @return an instance of {@link MBeanInfo} for the bean. + * @throws IntrospectionException if an exception occurs in examining + * the bean. + * @throws InstanceNotFoundException if the bean can not be found. + * @throws ReflectionException if an exception occurs when trying + * to invoke {@link DynamicMBean#getMBeanInfo()} + * on the bean. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getMBeanInfo")</code>}. + * @see DynamicMBean#getMBeanInfo() + */ + public MBeanInfo getMBeanInfo(ObjectName name) + throws InstanceNotFoundException, IntrospectionException, + ReflectionException + { + Object bean = getBean(name); + checkSecurity(name, null, "getMBeanInfo"); + try + { + Method method = bean.getClass().getMethod("getMBeanInfo", null); + return (MBeanInfo) method.invoke(bean, null); + } + catch (NoSuchMethodException e) + { + throw new IntrospectionException("The getMBeanInfo method " + + "could not be found."); + } + catch (IllegalAccessException e) + { + throw new ReflectionException(e, "Failed to call getMBeanInfo"); + } + catch (IllegalArgumentException e) + { + throw new ReflectionException(e, "Failed to call getMBeanInfo"); + } + catch (InvocationTargetException e) + { + throw new ReflectionException(e, "The method threw an exception"); + } + } + + /** + * Returns the {@link ObjectInstance} created for the specified + * management bean on registration. + * + * @param name the name of the bean. + * @return the corresponding {@link ObjectInstance} instance. + * @throws InstanceNotFoundException if the bean can not be found. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getObjectInstance")</code> + * @see #createMBean(String, ObjectName) + */ + public ObjectInstance getObjectInstance(ObjectName name) + throws InstanceNotFoundException + { + ServerInfo bean = (ServerInfo) beans.get(name); + if (bean == null) + throw new InstanceNotFoundException("The bean, " + name + + ", was not found."); + return bean.getInstance(); + } + + /** + * <p> + * Creates an instance of the specified class using the list of + * class loaders from the {@link + * javax.management.loading.ClassLoaderRepository Class Loader + * Repository}. The class should have a public constructor + * with no arguments. A reference to the new instance is returned, + * but the instance is not yet registered with the server. + * </p> + * <p> + * This method is equivalent to calling {@link + * #instantiate(String, Object[], String[]) + * <code>instantiate(name, (Object[]) null, (String[]) null)</code>} + * with <code>null</code> parameters and signature. + * </p> + * + * @param name the name of the class of bean to be instantiated. + * @return an instance of the given class. + * @throws ReflectionException if an exception is thrown during + * loading the class or calling the + * constructor. + * @throws MBeanException if the constructor throws an exception. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, null, + * "instantiate")</code>}. + * @see #instantiate(String, Object[], String[]) + */ + public Object instantiate(String name) + throws ReflectionException, MBeanException + { + return instantiate(name, (Object[]) null, (String[]) null); + } + + /** + * Creates an instance of the specified class using the list of + * class loaders from the {@link + * javax.management.loading.ClassLoaderRepository Class Loader + * Repository}. The class should have a public constructor + * matching the supplied signature. A reference to the new + * instance is returned, but the instance is not yet + * registered with the server. + * + * @param name the name of the class of bean to be instantiated. + * @param params the parameters for the constructor. + * @param sig the signature of the constructor. + * @return an instance of the given class. + * @throws ReflectionException if an exception is thrown during + * loading the class or calling the + * constructor. + * @throws MBeanException if the constructor throws an exception. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, null, + * "instantiate")</code>}. + */ + public Object instantiate(String name, Object[] params, String[] sig) + throws ReflectionException, MBeanException + { + checkSecurity(null, null, "instantiate"); + if (name == null) + { + RuntimeException e = + new IllegalArgumentException("The name was null."); + throw new RuntimeOperationsException(e); + } + Class[] sigTypes = new Class[sig.length]; + for (int a = 0; a < sigTypes.length; ++a) + { + try + { + sigTypes[a] = repository.loadClass(sig[a]); + } + catch (ClassNotFoundException e) + { + throw new ReflectionException(e, "The class, " + sigTypes[a] + + ", in the method signature " + + "could not be loaded."); + } + } + try + { + Constructor cons = + repository.loadClass(name).getConstructor(sigTypes); + return cons.newInstance(params); + } + catch (ClassNotFoundException e) + { + throw new ReflectionException(e, "The class, " + name + + ", of the constructor " + + "could not be loaded."); + } + catch (NoSuchMethodException e) + { + throw new ReflectionException(e, "The method, " + name + + ", could not be found."); + } + catch (IllegalAccessException e) + { + throw new ReflectionException(e, "Failed to instantiate the object"); + } + catch (InstantiationException e) + { + throw new ReflectionException(e, "Failed to instantiate the object"); + } + catch (InvocationTargetException e) + { + throw new MBeanException((Exception) e.getCause(), "The constructor " + + name + " threw an exception"); + } + } + + /** + * <p> + * Creates an instance of the specified class using the supplied + * class loader. If the class loader given is <code>null</code>, + * then the class loader of the server will be used. The class + * should have a public constructor with no arguments. A reference + * to the new instance is returned, but the instance is not yet + * registered with the server. + * </p> + * <p> + * This method is equivalent to calling {@link + * #instantiate(String, ObjectName, Object[], String[]) + * <code>instantiate(name, loaderName, (Object[]) null, + * (String[]) null)</code>} with <code>null</code> parameters + * and signature. + * </p> + * + * @param name the name of the class of bean to be instantiated. + * @param loaderName the name of the class loader to use. + * @return an instance of the given class. + * @throws InstanceNotFoundException if the class loader is not + * registered with the server. + * @throws ReflectionException if an exception is thrown during + * loading the class or calling the + * constructor. + * @throws MBeanException if the constructor throws an exception. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, null, + * "instantiate")</code>}. + * @see #instantiate(String, Object[], String[]) + */ + public Object instantiate(String name, ObjectName loaderName) + throws InstanceNotFoundException, ReflectionException, + MBeanException + { + return instantiate(name, loaderName); + } + + /** + * Creates an instance of the specified class using the supplied + * class loader. If the class loader given is <code>null</code>, + * then the class loader of the server will be used. The class + * should have a public constructor matching the supplied + * signature. A reference to the new instance is returned, + * but the instance is not yet registered with the server. + * + * @param name the name of the class of bean to be instantiated. + * @param loaderName the name of the class loader to use. + * @param params the parameters for the constructor. + * @param sig the signature of the constructor. + * @return an instance of the given class. + * @throws InstanceNotFoundException if the class loader is not + * registered with the server. + * @throws ReflectionException if an exception is thrown during + * loading the class or calling the + * constructor. + * @throws MBeanException if the constructor throws an exception. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, null, + * "instantiate")</code>}. + */ + public Object instantiate(String name, ObjectName loaderName, + Object[] params, String[] sig) + throws InstanceNotFoundException, ReflectionException, + MBeanException + { + checkSecurity(null, null, "instantiate"); + if (name == null) + { + RuntimeException e = + new IllegalArgumentException("The name was null."); + throw new RuntimeOperationsException(e); + } + ClassLoader loader = getClassLoader(loaderName); + Class[] sigTypes = new Class[sig.length]; + for (int a = 0; a < sig.length; ++a) + { + try + { + sigTypes[a] = Class.forName(sig[a], true, loader); + } + catch (ClassNotFoundException e) + { + throw new ReflectionException(e, "The class, " + sig[a] + + ", in the method signature " + + "could not be loaded."); + } + } + try + { + Constructor cons = + Class.forName(name, true, loader).getConstructor(sigTypes); + return cons.newInstance(params); + } + catch (ClassNotFoundException e) + { + throw new ReflectionException(e, "The class, " + name + + ", of the constructor " + + "could not be loaded."); + } + catch (NoSuchMethodException e) + { + throw new ReflectionException(e, "The method, " + name + + ", could not be found."); + } + catch (IllegalAccessException e) + { + throw new ReflectionException(e, "Failed to instantiate the object"); + } + catch (InstantiationException e) + { + throw new ReflectionException(e, "Failed to in... [truncated message content] |
From: <ls...@us...> - 2007-01-07 08:33:14
|
Revision: 3012 http://jnode.svn.sourceforge.net/jnode/?rev=3012&view=rev Author: lsantha Date: 2007-01-07 00:33:13 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerImpl.java trunk/core/src/classpath/gnu/gnu/xml/transform/XSLURIResolver.java trunk/core/src/classpath/gnu/gnu/xml/util/XCat.java trunk/core/src/classpath/gnu/gnu/xml/xpath/Expr.java Added Paths: ----------- trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java Modified: trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/CORBA/DynAn/gnuDynValue.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -172,7 +172,6 @@ else return super.current_member_kind(); } - ; /** @inheritDoc */ public String current_member_name() throws TypeMismatch, InvalidValue @@ -182,7 +181,6 @@ else return super.current_member_name(); } - ; /** @inheritDoc */ public NameDynAnyPair[] get_members_as_dyn_any() throws InvalidValue @@ -191,7 +189,6 @@ throw new InvalidValue(ISNULL); return super.gnu_get_members_as_dyn_any(); } - ; /** @inheritDoc */ public NameValuePair[] get_members() throws InvalidValue @@ -201,7 +198,6 @@ else return super.gnu_get_members(); } - ; /** @inheritDoc */ public void set_members_as_dyn_any(NameDynAnyPair[] value) @@ -210,7 +206,6 @@ super.set_members_as_dyn_any(value); isNull = false; } - ; /** @inheritDoc */ public void set_members(NameValuePair[] value) @@ -219,7 +214,6 @@ super.set_members(value); isNull = false; } - ; /** @inheritDoc */ public boolean is_null() Modified: trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/CORBA/Poa/gnuPOA.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1348,7 +1348,6 @@ { return name; } - ; /** * Return the parent of this POA. Modified: trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/classpath/ServiceFactory.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -49,6 +49,7 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.ServiceConfigurationError; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -176,7 +177,6 @@ */ private static final Logger LOGGER = Logger.getLogger("gnu.classpath"); - /** * Declared private in order to prevent constructing instances of * this utility class. @@ -225,6 +225,51 @@ public static Iterator lookupProviders(Class spi, ClassLoader loader) { + return lookupProviders(spi, loader, false); + } + + /** + * Finds service providers that are implementing the specified + * Service Provider Interface. + * + * <p><b>On-demand loading:</b> Loading and initializing service + * providers is delayed as much as possible. The rationale is that + * typical clients will iterate through the set of installed service + * providers until one is found that matches some criteria (like + * supported formats, or quality of service). In such scenarios, it + * might make sense to install only the frequently needed service + * providers on the local machine. More exotic providers can be put + * onto a server; the server will only be contacted when no suitable + * service could be found locally. + * + * <p><b>Security considerations:</b> Any loaded service providers + * are loaded through the specified ClassLoader, or the system + * ClassLoader if <code>classLoader</code> is + * <code>null</code>. When <code>lookupProviders</code> is called, + * the current {@link AccessControlContext} gets recorded. This + * captured security context will determine the permissions when + * services get loaded via the <code>next()</code> method of the + * returned <code>Iterator</code>. + * + * @param spi the service provider interface which must be + * implemented by any loaded service providers. + * + * @param loader the class loader that will be used to load the + * service providers, or <code>null</code> for the system class + * loader. For using the context class loader, see {@link + * #lookupProviders(Class)}. + * @param error true if a {@link ServiceConfigurationError} + * should be thrown when an error occurs, rather + * than it merely being logged. + * @return an iterator over instances of <code>spi</code>. + * + * @throws IllegalArgumentException if <code>spi</code> is + * <code>null</code>. + */ + public static Iterator lookupProviders(Class spi, + ClassLoader loader, + boolean error) + { String resourceName; Enumeration urls; @@ -246,10 +291,14 @@ * does not return anything (no providers installed). */ log(Level.WARNING, "cannot access {0}", resourceName, ioex); + if (error) + throw new ServiceConfigurationError("Failed to access + " + + resourceName, ioex); + else return Collections.EMPTY_LIST.iterator(); } - return new ServiceIterator(spi, urls, loader, + return new ServiceIterator(spi, urls, loader, error, AccessController.getContext()); } @@ -342,6 +391,11 @@ */ private Object nextProvider; + /** + * True if a {@link ServiceConfigurationError} should be thrown + * when an error occurs, instead of it merely being logged. + */ + private boolean error; /** * Constructs an Iterator that loads and initializes services on @@ -359,16 +413,21 @@ * @param loader the ClassLoader that gets used for loading * service providers. * + * @param error true if a {@link ServiceConfigurationError} + * should be thrown when an error occurs, rather + * than it merely being logged. + * * @param securityContext the security context to use when loading * and initializing service providers. */ ServiceIterator(Class spi, Enumeration urls, ClassLoader loader, - AccessControlContext securityContext) + boolean error, AccessControlContext securityContext) { this.spi = spi; this.urls = urls; this.loader = loader; this.securityContext = securityContext; + this.error = error; this.nextProvider = loadNextServiceProvider(); } @@ -426,6 +485,9 @@ log(Level.WARNING, "IOException upon reading {0}", currentURL, readProblem); line = null; + if (error) + throw new ServiceConfigurationError("Error reading " + + currentURL, readProblem); } /* When we are at the end of one list of services, @@ -477,6 +539,13 @@ log(Level.WARNING, msg, new Object[] { line, spi.getName(), currentURL }, ex); + if (error) + throw new ServiceConfigurationError("Cannot load service "+ + "provider class " + + line + " specified by "+ + "\"META-INF/services/"+ + spi.getName() + "\" in "+ + currentURL, ex); continue; } } @@ -497,6 +566,9 @@ catch (Exception ex) { log(Level.WARNING, "cannot close {0}", currentURL, ex); + if (error) + throw new ServiceConfigurationError("Cannot close " + + currentURL, ex); } reader = null; currentURL = null; @@ -515,6 +587,9 @@ catch (Exception ex) { log(Level.WARNING, "cannot open {0}", currentURL, ex); + if (error) + throw new ServiceConfigurationError("Cannot open " + + currentURL, ex); } } while (reader == null); Modified: trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/classpath/debug/Component.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -98,8 +98,13 @@ */ public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2); - /* Indices 3 and 4 reserved for future use by SSL components. */ + /** + * Trace running of delegated tasks. + */ + public static final Component SSL_DELEGATED_TASK = new Component ("SSL DELEGATED TASK", 3); + /* Index 4 reserved for future use by SSL components. */ + /** * Trace the operation of cryptographic primitives. */ Modified: trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/classpath/debug/SystemLogger.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -42,11 +42,12 @@ import java.security.AccessController; import java.util.StringTokenizer; +import java.util.logging.Level; import java.util.logging.Logger; -public final class SystemLogger +public final class SystemLogger extends Logger { - public static final Logger SYSTEM = Logger.getLogger ("gnu.classpath"); + public static final SystemLogger SYSTEM = new SystemLogger(); static { @@ -62,12 +63,40 @@ Component c = Component.forName (tok.nextToken ()); if (c != null) PreciseFilter.GLOBAL.enable (c); - SYSTEM.log (java.util.logging.Level.INFO, "enabled: {0}", c); + SYSTEM.log (Level.INFO, "enabled: {0}", c); } } + } - java.util.logging.Handler[] h = SYSTEM.getHandlers (); - for (int i = 0; i < h.length; i++) - System.out.println (h[i]); + /** + * Fetch the system logger instance. The logger returned is meant for debug + * and diagnostic logging for Classpath internals. + * + * @return The system logger. + */ + public static SystemLogger getSystemLogger() + { + // XXX Check some permission here? + return SYSTEM; } + + /** + * Keep only one instance of the system logger. + */ + private SystemLogger() + { + super("gnu.classpath", null); + } + + /** + * Variable-arguments log method. + * + * @param level The level to log to. + * @param format The format string. + * @param args The arguments. + */ + public void logv(Level level, String format, Object... args) + { + log(level, format, args); + } } Modified: trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/awt/AWTUtilities.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1,5 +1,5 @@ /* AWTUtilities.java -- Common utility methods for AWT and Swing. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,6 +47,7 @@ import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.AbstractSequentialList; import java.util.List; @@ -694,4 +695,204 @@ { return java.awt.EventQueue.isDispatchThread(); } + + /** + * Returns whether the specified key code is valid. + */ + public static boolean isValidKey(int keyCode) + { + switch (keyCode) + { + case KeyEvent.VK_ENTER: + case KeyEvent.VK_BACK_SPACE: + case KeyEvent.VK_TAB: + case KeyEvent.VK_CANCEL: + case KeyEvent.VK_CLEAR: + case KeyEvent.VK_SHIFT: + case KeyEvent.VK_CONTROL: + case KeyEvent.VK_ALT: + case KeyEvent.VK_PAUSE: + case KeyEvent.VK_CAPS_LOCK: + case KeyEvent.VK_ESCAPE: + case KeyEvent.VK_SPACE: + case KeyEvent.VK_PAGE_UP: + case KeyEvent.VK_PAGE_DOWN: + case KeyEvent.VK_END: + case KeyEvent.VK_HOME: + case KeyEvent.VK_LEFT: + case KeyEvent.VK_UP: + case KeyEvent.VK_RIGHT: + case KeyEvent.VK_DOWN: + case KeyEvent.VK_COMMA: + case KeyEvent.VK_MINUS: + case KeyEvent.VK_PERIOD: + case KeyEvent.VK_SLASH: + case KeyEvent.VK_0: + case KeyEvent.VK_1: + case KeyEvent.VK_2: + case KeyEvent.VK_3: + case KeyEvent.VK_4: + case KeyEvent.VK_5: + case KeyEvent.VK_6: + case KeyEvent.VK_7: + case KeyEvent.VK_8: + case KeyEvent.VK_9: + case KeyEvent.VK_SEMICOLON: + case KeyEvent.VK_EQUALS: + case KeyEvent.VK_A: + case KeyEvent.VK_B: + case KeyEvent.VK_C: + case KeyEvent.VK_D: + case KeyEvent.VK_E: + case KeyEvent.VK_F: + case KeyEvent.VK_G: + case KeyEvent.VK_H: + case KeyEvent.VK_I: + case KeyEvent.VK_J: + case KeyEvent.VK_K: + case KeyEvent.VK_L: + case KeyEvent.VK_M: + case KeyEvent.VK_N: + case KeyEvent.VK_O: + case KeyEvent.VK_P: + case KeyEvent.VK_Q: + case KeyEvent.VK_R: + case KeyEvent.VK_S: + case KeyEvent.VK_T: + case KeyEvent.VK_U: + case KeyEvent.VK_V: + case KeyEvent.VK_W: + case KeyEvent.VK_X: + case KeyEvent.VK_Y: + case KeyEvent.VK_Z: + case KeyEvent.VK_OPEN_BRACKET: + case KeyEvent.VK_BACK_SLASH: + case KeyEvent.VK_CLOSE_BRACKET: + case KeyEvent.VK_NUMPAD0: + case KeyEvent.VK_NUMPAD1: + case KeyEvent.VK_NUMPAD2: + case KeyEvent.VK_NUMPAD3: + case KeyEvent.VK_NUMPAD4: + case KeyEvent.VK_NUMPAD5: + case KeyEvent.VK_NUMPAD6: + case KeyEvent.VK_NUMPAD7: + case KeyEvent.VK_NUMPAD8: + case KeyEvent.VK_NUMPAD9: + case KeyEvent.VK_MULTIPLY: + case KeyEvent.VK_ADD: + case KeyEvent.VK_SEPARATOR: + case KeyEvent.VK_SUBTRACT: + case KeyEvent.VK_DECIMAL: + case KeyEvent.VK_DIVIDE: + case KeyEvent.VK_DELETE: + case KeyEvent.VK_NUM_LOCK: + case KeyEvent.VK_SCROLL_LOCK: + case KeyEvent.VK_F1: + case KeyEvent.VK_F2: + case KeyEvent.VK_F3: + case KeyEvent.VK_F4: + case KeyEvent.VK_F5: + case KeyEvent.VK_F6: + case KeyEvent.VK_F7: + case KeyEvent.VK_F8: + case KeyEvent.VK_F9: + case KeyEvent.VK_F10: + case KeyEvent.VK_F11: + case KeyEvent.VK_F12: + case KeyEvent.VK_F13: + case KeyEvent.VK_F14: + case KeyEvent.VK_F15: + case KeyEvent.VK_F16: + case KeyEvent.VK_F17: + case KeyEvent.VK_F18: + case KeyEvent.VK_F19: + case KeyEvent.VK_F20: + case KeyEvent.VK_F21: + case KeyEvent.VK_F22: + case KeyEvent.VK_F23: + case KeyEvent.VK_F24: + case KeyEvent.VK_PRINTSCREEN: + case KeyEvent.VK_INSERT: + case KeyEvent.VK_HELP: + case KeyEvent.VK_META: + case KeyEvent.VK_BACK_QUOTE: + case KeyEvent.VK_QUOTE: + case KeyEvent.VK_KP_UP: + case KeyEvent.VK_KP_DOWN: + case KeyEvent.VK_KP_LEFT: + case KeyEvent.VK_KP_RIGHT: + case KeyEvent.VK_DEAD_GRAVE: + case KeyEvent.VK_DEAD_ACUTE: + case KeyEvent.VK_DEAD_CIRCUMFLEX: + case KeyEvent.VK_DEAD_TILDE: + case KeyEvent.VK_DEAD_MACRON: + case KeyEvent.VK_DEAD_BREVE: + case KeyEvent.VK_DEAD_ABOVEDOT: + case KeyEvent.VK_DEAD_DIAERESIS: + case KeyEvent.VK_DEAD_ABOVERING: + case KeyEvent.VK_DEAD_DOUBLEACUTE: + case KeyEvent.VK_DEAD_CARON: + case KeyEvent.VK_DEAD_CEDILLA: + case KeyEvent.VK_DEAD_OGONEK: + case KeyEvent.VK_DEAD_IOTA: + case KeyEvent.VK_DEAD_VOICED_SOUND: + case KeyEvent.VK_DEAD_SEMIVOICED_SOUND: + case KeyEvent.VK_AMPERSAND: + case KeyEvent.VK_ASTERISK: + case KeyEvent.VK_QUOTEDBL: + case KeyEvent.VK_LESS: + case KeyEvent.VK_GREATER: + case KeyEvent.VK_BRACELEFT: + case KeyEvent.VK_BRACERIGHT: + case KeyEvent.VK_AT: + case KeyEvent.VK_COLON: + case KeyEvent.VK_CIRCUMFLEX: + case KeyEvent.VK_DOLLAR: + case KeyEvent.VK_EURO_SIGN: + case KeyEvent.VK_EXCLAMATION_MARK: + case KeyEvent.VK_INVERTED_EXCLAMATION_MARK: + case KeyEvent.VK_LEFT_PARENTHESIS: + case KeyEvent.VK_NUMBER_SIGN: + case KeyEvent.VK_PLUS: + case KeyEvent.VK_RIGHT_PARENTHESIS: + case KeyEvent.VK_UNDERSCORE: + case KeyEvent.VK_FINAL: + case KeyEvent.VK_CONVERT: + case KeyEvent.VK_NONCONVERT: + case KeyEvent.VK_ACCEPT: + case KeyEvent.VK_MODECHANGE: + case KeyEvent.VK_KANA: + case KeyEvent.VK_KANJI: + case KeyEvent.VK_ALPHANUMERIC: + case KeyEvent.VK_KATAKANA: + case KeyEvent.VK_HIRAGANA: + case KeyEvent.VK_FULL_WIDTH: + case KeyEvent.VK_HALF_WIDTH: + case KeyEvent.VK_ROMAN_CHARACTERS: + case KeyEvent.VK_ALL_CANDIDATES: + case KeyEvent.VK_PREVIOUS_CANDIDATE: + case KeyEvent.VK_CODE_INPUT: + case KeyEvent.VK_JAPANESE_KATAKANA: + case KeyEvent.VK_JAPANESE_HIRAGANA: + case KeyEvent.VK_JAPANESE_ROMAN: + case KeyEvent.VK_KANA_LOCK: + case KeyEvent.VK_INPUT_METHOD_ON_OFF: + case KeyEvent.VK_CUT: + case KeyEvent.VK_COPY: + case KeyEvent.VK_PASTE: + case KeyEvent.VK_UNDO: + case KeyEvent.VK_AGAIN: + case KeyEvent.VK_FIND: + case KeyEvent.VK_PROPS: + case KeyEvent.VK_STOP: + case KeyEvent.VK_COMPOSE: + case KeyEvent.VK_ALT_GRAPH: + case KeyEvent.VK_BEGIN: + case KeyEvent.VK_CONTEXT_MENU: + case KeyEvent.VK_WINDOWS: + return true; + default: + return false; + } + } } Modified: trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/beans/encoder/ScanEngine.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -153,7 +153,7 @@ writer = new StAXWriter(os); root = new Root(); - final ScannerState start = current = new GenericScannerState(root);; + final ScannerState start = current = new GenericScannerState(root); ScannerState conf; // Use the ReportingScannerState to debug serialization issues. Modified: trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/locale/LocaleHelper.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -55,105 +55,44 @@ public class LocaleHelper { /** - * This method is used by the localized name lookup methods to retrieve - * the localized name of a particular piece of locale data. - * If the display name can not be localized to the supplied - * locale, it will fall back on other output in the following order: - * - * <ul> - * <li>the localized name in the default locale</li> - * <li>the localized name in English (optional)</li> - * <li>the localized name in the root locale bundle (optional)</li> - * <li>the localized input string</li> - * </ul> * <p> - * If the supplied key is merely the empty string, then the empty string is - * returned. + * This method is used by the localized name lookup methods to + * retrieve the next locale to try. The next locale is derived + * from the supplied locale by applying the first applicable + * rule from the following: * </p> + * <ol> + * <li>If the variant contains a <code>'_'</code>, then + * this and everything following it is trimmed.</li> + * <li>If the variant is non-empty, it is converted to + * an empty string.</li> + * <li>If the country is non-empty, it is converted to + * an empty string.</li> + * <li>If the language is non-empty, it is converted to + * an empty string (forming {@link java.util.Locale#ROOT})</li> + * </ol> + * <p> + * The base fallback locale is {@link java.util.Locale#ROOT}. + * </p> * - * @param inLocale the locale to use for formatting the display string. - * @param key the locale data used as a key to the localized lookup tables. - * @param name the name of the hashtable containing the localized data. - * @param checkEnglish true if the method should fall back on data - * from the English locale. - * @param checkRoot true if the method should fall back on data from the - * unlocalized root locale. - * @return a <code>String</code>, hopefully containing the localized - * variant of the input data. - * @throws NullPointerException if <code>inLocale</code> is null. + * @param locale the locale for which a localized piece of + * data could not be obtained. + * @return the next fallback locale to try. */ - public static String getLocalizedString(Locale inLocale, String key, - String name, boolean checkEnglish, - boolean checkRoot) - { - String localizedString; - String property; - - if (key.equals("")) - return ""; - property = name + "." + key; - /* Localize to inLocale */ - try + public static Locale getFallbackLocale(Locale locale) { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - inLocale).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - /* Localize to default locale */ - if (localizedString == null) - { - try - { - ResourceBundle bundle; - - bundle = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation"); - localizedString = bundle.getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Localize to English */ - if (localizedString == null && checkEnglish) - { - try - { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - Locale.ENGLISH).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Return unlocalized version */ - if (localizedString == null && checkRoot) - { - try - { - localizedString = - ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - new Locale("","","") - ).getString(property); - } - catch (MissingResourceException exception) - { - localizedString = null; - } - } - /* Return original input string */ - if (localizedString == null) - { - localizedString = key; - } - return localizedString; + String language = locale.getLanguage(); + String country = locale.getCountry(); + String variant = locale.getVariant(); + int uscore = variant.indexOf('_'); + if (uscore != -1) + return new Locale(language, country, + variant.substring(0, uscore)); + if (!variant.isEmpty()) + return new Locale(language, country, ""); + if (!country.isEmpty()) + return new Locale(language, "", ""); + return Locale.ROOT; } /** Modified: trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/util/DoubleEnumeration.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1,5 +1,5 @@ /* gnu.java.util.DoubleEnumeration - Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -63,7 +63,7 @@ * @author Jochen Hoenicke * @author Mark Wielaard (ma...@kl...) */ -public class DoubleEnumeration implements Enumeration +public class DoubleEnumeration<T> implements Enumeration<T> { /** * This is true as long as one of the enumerations has more @@ -82,17 +82,17 @@ /** * The first enumeration. */ - private Enumeration e1; + private Enumeration<T> e1; /** * The second enumeration. */ - private Enumeration e2; + private Enumeration<T> e2; /** * Creates a new Enumeration combining the given two enumerations. * The enumerations mustn't be accessed by other classes. */ - public DoubleEnumeration(Enumeration e1, Enumeration e2) + public DoubleEnumeration(Enumeration<T> e1, Enumeration<T> e2) { this.e1 = e1; this.e2 = e2; @@ -126,7 +126,7 @@ * element of the second enumeration. If both enumeration don't have * any elements it throws a <code>NoSuchElementException</code>. */ - public Object nextElement() + public T nextElement() { if (!hasMoreElements()) throw new NoSuchElementException(); Modified: trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/util/prefs/EventDispatcher.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -53,7 +53,7 @@ // This is a queue of events to dispatch. This thread waits on // the queue and when notified will remove events until the queue // is empty. - private static final ArrayList queue = new ArrayList(); + private static final ArrayList<Runnable> queue = new ArrayList<Runnable>(); // FIXME: this thread probably ought to go in some classpath-internal // ThreadGroup. But we don't have that yet. @@ -81,7 +81,7 @@ // Ignore. } } - r = (Runnable) queue.remove(0); + r = queue.remove(0); } // Invoke outside the synchronization, so that // we aren't blocking other threads from posting events. Modified: trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/java/util/prefs/MemoryBasedPreferences.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -52,7 +52,7 @@ private final boolean isUser; /** Contains all the preference entries of this node. */ - private HashMap entries = new HashMap(); + private HashMap<String, String> entries = new HashMap<String, String>(); /** * Creates a new preferences node with the given name and parent. @@ -98,7 +98,7 @@ * this node. */ protected String[] keysSpi() throws BackingStoreException { - return (String[]) entries.keySet().toArray(new String[entries.size()]); + return entries.keySet().toArray(new String[entries.size()]); } /** @@ -106,7 +106,7 @@ * null when the key has not been set. */ protected String getSpi(String key) { - return (String) entries.get(key); + return entries.get(key); } /** Modified: trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/imageio/png/PNGICCProfile.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -61,7 +61,9 @@ { super( type, data, crc ); int i = 0; - while( data[i++] != 0 ); + while( data[i++] != 0 ) + ; + try { name = new String(data, 0, i, "8859_1"); Modified: trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/rmi/CORBA/UtilDelegateImpl.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1,5 +1,5 @@ /* UtilDelegateImpl.java -- - Copyright (C) 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,6 +38,8 @@ package gnu.javax.rmi.CORBA; +import gnu.classpath.VMStackWalker; + import gnu.CORBA.Minor; import gnu.CORBA.ObjectCreator; import gnu.CORBA.Poa.ORB_1_4; @@ -70,6 +72,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.net.MalformedURLException; import java.rmi.AccessException; import java.rmi.MarshalException; import java.rmi.NoSuchObjectException; @@ -374,37 +377,24 @@ throws ClassNotFoundException { if (loader == null) - loader = Thread.currentThread().getContextClassLoader(); + loader = VMStackWalker.firstNonNullClassLoader(); String p_useCodebaseOnly = System.getProperty("java.rmi.server.useCodebaseOnly"); boolean useCodebaseOnly = p_useCodebaseOnly != null && p_useCodebaseOnly.trim().equalsIgnoreCase("true"); - try - { - if (remoteCodebase != null && !useCodebaseOnly) - return RMIClassLoader.loadClass(remoteCodebase, className); - } - catch (Exception e) - { - // This failed but try others. - } + if (useCodebaseOnly) + remoteCodebase = null; try { - if (remoteCodebase == null || useCodebaseOnly) - return RMIClassLoader.loadClass(remoteCodebase, className); + return RMIClassLoader.loadClass(remoteCodebase, className, loader); } - catch (Exception e) + catch (MalformedURLException x) { - // This failed but try others. + throw new ClassNotFoundException(className, x); } - - if (loader != null) - return Class.forName(className, true, loader); - - throw new ClassNotFoundException(className + " at " + remoteCodebase); } /** Modified: trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/security/auth/login/ConfigFileParser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -122,7 +122,9 @@ initParser(r); while (parseAppOrOtherEntry()) - ; // do nothing + { + /* do nothing */ + } } private void initParser(Reader r) throws IOException @@ -157,7 +159,9 @@ List lmis = new ArrayList(); while (parseACE(lmis)) - ; // do nothing + { + /* do nothing */ + } c = cft.nextToken(); if (c != '}') Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -308,7 +308,9 @@ { // FIXME: Handle block and ATKEYWORD. boolean success = parseAny(s); - while (parseAny(s)); + while (parseAny(s)) + ; + return success; } @@ -329,7 +331,8 @@ boolean ret = parseAny(sel); if (ret) { - while (parseAny(sel)); + while (parseAny(sel)) + ; } return ret; } Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/gnuDTD.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -390,7 +390,6 @@ allowed.add(allowed_values [ i ]); } } - ; AttributeList attr = new AttributeList(name, type, modifier, default_value, allowed, null); Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/Parser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -56,6 +56,7 @@ import java.util.Vector; import javax.swing.text.ChangedCharSetException; +import javax.swing.text.SimpleAttributeSet; import javax.swing.text.html.HTML; import javax.swing.text.html.parser.AttributeList; import javax.swing.text.html.parser.DTD; @@ -250,9 +251,9 @@ * Get the attributes of the current tag. * @return The attribute set, representing the attributes of the current tag. */ - public htmlAttributeSet getAttributes() + public SimpleAttributeSet getAttributes() { - return attributes; + return new SimpleAttributeSet(attributes); } /** @@ -497,6 +498,9 @@ mustBe(t.kind); } hTag = new Token(start, last); + + // Consume any whitespace immediately following a comment. + optional(WS); handleComment(); } @@ -579,6 +583,8 @@ ); } } + // Consume any whitespace that follows the Sgml insertion. + optional(WS); } /** @@ -658,7 +664,10 @@ else text = textProcessor.preprocess(buffer); - if (text != null && text.length > 0) + if (text != null && text.length > 0 + // According to the specs we need to discard whitespace immediately + // before a closing tag. + && (text.length > 1 || text[0] != ' ' || ! TAG_CLOSE.matches(this))) { TagElement pcdata = new TagElement(dtd.getElement("#pcdata")); attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; @@ -889,6 +898,8 @@ protected void parseDocument() throws ParseException { + // Read up any initial whitespace. + optional(WS); while (getTokenAhead().kind != EOF) { advanced = false; @@ -979,13 +990,15 @@ + next.getImage() + "'"); attrValue = value.getImage(); } - else if (next.kind == SLASH) - // The slash in this context is treated as the ordinary - // character, not as a token. The slash may be part of + else if (next.kind == SLASH || next.kind == OTHER) + // The slash and other characters (like %) in this context is + // treated as the ordinary + // character, not as a token. The character may be part of // the unquoted URL. { StringBuffer image = new StringBuffer(value.getImage()); - while (next.kind == NUMTOKEN || next.kind == SLASH) + while (next.kind == NUMTOKEN || next.kind == SLASH + || next.kind == OTHER) { image.append(getNextToken().getImage()); next = getTokenAhead(); @@ -1177,6 +1190,13 @@ { validator.validateTag(tag, attributes); handleEmptyTag(tag); + HTML.Tag h = tag.getHTMLTag(); + // When a block tag is closed, consume whitespace that follows after + // it. + // For some unknown reason a FRAME tag is not treated as block element. + // However in this case it should be treated as such. + if (isBlock(h)) + optional(WS); } catch (ChangedCharSetException ex) { @@ -1192,7 +1212,7 @@ */ private void _handleEndTag(TagElement tag) { - validator.closeTag(tag); + if (validator.closeTag(tag)) _handleEndTag_remaining(tag); } @@ -1213,6 +1233,11 @@ if (preformatted < 0) preformatted = 0; + // When a block tag is closed, consume whitespace that follows after + // it. + if (isBlock(h)) + optional(WS); + if (h == HTML.Tag.TITLE) { titleOpen = false; @@ -1239,6 +1264,9 @@ HTML.Tag h = tag.getHTMLTag(); + if (isBlock(h)) + optional(WS); + if (h.isPreformatted()) preformatted++; @@ -1354,7 +1382,7 @@ if (c == '\r') buffer.append(' '); // CR replaced by space else if (c == '\n') - ; // LF ignored + { /* LF ignored */ } else if (c == '\t') buffer.append(' '); // Tab replaced by space else @@ -1418,8 +1446,6 @@ hTag = new Token(start, next); - attributes.setResolveParent(defaulter.getDefaultParameters(name.getImage())); - if (!end) { // The tag body contains errors. If additionally the tag @@ -1457,9 +1483,14 @@ if (te.getElement().type == DTDConstants.EMPTY) _handleEmptyTag(te); else + { + // According to the specs we need to consume whitespace following + // immediately after a opening tag. + optional(WS); _handleStartTag(te); } } + } /** * This should fire additional actions in response to the @@ -1483,4 +1514,19 @@ { error("Whitespace here is not permitted"); } + + /** + * Returns true when the specified tag should be considered a block tag + * wrt whitespace handling. We need this special handling, since there + * are a couple of tags that we must treat as block tags but which aren't + * officially block tags. + * + * @param tag the tag to check + * @return true when the specified tag should be considered a block tag + * wrt whitespace handling + */ + private boolean isBlock(HTML.Tag tag) + { + return tag.isBlock() || tag == HTML.Tag.STYLE || tag == HTML.Tag.FRAME; + } } Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/low/Constants.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -209,6 +209,17 @@ } ); + /** + * Ordinary HTML tag closing pattern. + */ + public static final pattern TAG_CLOSE = + new pattern(new node[] + { + new node(BEGIN), new node(WS, true), new node(SLASH), + new node(WS, true), new node(NUMTOKEN) + } + ); + /* Special tokens */ /** Modified: trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/support/textPreProcessor.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -42,17 +42,17 @@ /** * Pre - processes text in text parts of the html document. - * Not thread - safe. + * * @author Audrius Meskauskas, Lithuania (Aud...@Bi...) */ public class textPreProcessor { /** - * Pre - process non-preformatted text. - * \t, \r and \n mutate into spaces, then multiple spaces mutate - * into single one, all whitespace around tags is consumed. - * The content of the passed buffer is destroyed. - * @param text A text to pre-process. + * Pre - process non-preformatted text. \t, \r and \n mutate into spaces, then + * multiple spaces mutate into single one, all whitespace around tags is + * consumed. The content of the passed buffer is destroyed. + * + * @param a_text A text to pre-process. */ public char[] preprocess(StringBuffer a_text) { @@ -64,18 +64,15 @@ int a = 0; int b = text.length - 1; - try - { - while (Constants.bWHITESPACE.get(text [ a ])) + // Remove leading/trailing whitespace, leaving at most one character + int len = text.length; + while (a + 1 < len && Constants.bWHITESPACE.get(text[a]) + && Constants.bWHITESPACE.get(text[a + 1])) a++; - while (Constants.bWHITESPACE.get(text [ b ])) + + while (b > a && Constants.bWHITESPACE.get(text[b]) + && Constants.bWHITESPACE.get(text[b - 1])) b--; - } - catch (ArrayIndexOutOfBoundsException sx) - { - // A text fragment, consisting from line breaks only. - return null; - } a_text.setLength(0); @@ -83,10 +80,9 @@ boolean spaceNow; char c; - chars: - for (int i = a; i <= b; i++) + chars: for (int i = a; i <= b; i++) { - c = text [ i ]; + c = text[i]; spaceNow = Constants.bWHITESPACE.get(c); if (spacesWere && spaceNow) continue chars; Modified: trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/dom/DomAttr.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -316,7 +316,7 @@ private void mutating(String oldValue, String newValue, short why) { - if (!reportMutations || parent == null) + if (!reportMutations || parent == null || equal(newValue, oldValue)) { return; } Modified: trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/dom/DomNode.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -668,6 +668,7 @@ { insertionEvent(null, child); } + length++; } return child; @@ -1561,7 +1562,7 @@ // Climb to the top of this subtree and handle capture, letting // each node (from the top down) capture until one stops it or // until we get to this one. - current = parent; + current = (parent == null) ? this : parent; if (current.depth >= ANCESTORS_INIT) { DomNode[] newants = new DomNode[current.depth + 1]; Modified: trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/dom/ls/SAXEventSink.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -43,6 +43,7 @@ import java.util.List; import javax.xml.XMLConstants; import org.w3c.dom.Attr; +import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; @@ -72,7 +73,7 @@ * * @author <a href='mailto:do...@gn...'>Chris Burdess</a> */ -class SAXEventSink +public class SAXEventSink implements ContentHandler, LexicalHandler, DTDHandler, DeclHandler { @@ -110,6 +111,11 @@ interrupted = true; } + protected Document getDocument() + { + return doc; + } + // -- ContentHandler2 -- public void setDocumentLocator(Locator locator) Modified: trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/pipeline/DomConsumer.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -365,7 +365,7 @@ throws SAXException { SAXParseException e; - ErrorHandler errHandler = consumer.getErrorHandler ();; + ErrorHandler errHandler = consumer.getErrorHandler (); if (locator == null) e = new SAXParseException (message, null, null, -1, -1, x); Modified: trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/stream/SAXParser.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -1021,9 +1021,18 @@ SAXParser parser = new SAXParser(validating, namespaceAware, xIncludeAware); InputSource input = new InputSource(args[pos]); + java.io.FileReader fr = new java.io.FileReader(args[pos]); + input.setCharacterStream(fr); + try + { XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.parse(input); + } + finally + { + fr.close(); + } pos++; } } Modified: trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/stream/XMLStreamWriterImpl.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -664,12 +664,10 @@ public void writeDTD(String dtd) throws XMLStreamException { - // Really thoroughly pointless method... try { - if (!isName(dtd)) - throw new IllegalArgumentException("illegal Name: " + dtd); - + // XXX: Should we parse the doctypedecl at this point to ensure + // wellformedness? writer.write("<!DOCTYPE "); writer.write(dtd); writer.write('>'); Added: trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTemplatesHandler.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -0,0 +1,97 @@ +/* SAXTemplatesHandler.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.transform; + +import javax.xml.transform.Templates; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.TemplatesHandler; +import org.w3c.dom.Document; +import gnu.xml.dom.ls.SAXEventSink; + +/** + * A content handler that acts as a sink for SAX parse events, + * constructing an XSL stylesheet. + * Internally, this class simply creates a DOM tree from the events, + * and then parses the DOM into a Templates object. + * + * @author Chris Burdess (do...@gn...) + */ +class SAXTemplatesHandler + extends SAXEventSink + implements TemplatesHandler +{ + + final TransformerFactoryImpl factory; + String systemId; + + SAXTemplatesHandler(TransformerFactoryImpl factory) + { + this.factory = factory; + } + + public String getSystemId() + { + return systemId; + } + + public void setSystemId(String systemId) + { + this.systemId = systemId; + } + + public Templates getTemplates() + { + Document doc = getDocument(); + if (doc == null) + throw new IllegalStateException("Parsing of stylesheet incomplete"); + DOMSource ds = new DOMSource(doc, systemId); + try + { + return factory.newTemplates(ds); + } + catch (TransformerConfigurationException e) + { + String msg = "Unable to construct templates from this event stream"; + IllegalStateException e2 = new IllegalStateException(msg); + e2.initCause(e); + throw e2; + } + } + +} Added: trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java (rev 0) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/SAXTransformerHandler.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -0,0 +1,111 @@ +/* SAXTransformerHandler.java -- + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.xml.transform; + +import javax.xml.transform.Result; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.TransformerHandler; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; +import gnu.xml.dom.ls.SAXEventSink; + +/** + * A SAX event sink that processes an XML source represented as a stream of + * SAX events into a result tree. + * This works by simply buffering all the events into a DOM tree and then + * using this DOM tree as the source of the transformation. + * + * @author Chris Burdess (do...@gn...) + */ +class SAXTransformerHandler + extends SAXEventSink + implements TransformerHandler +{ + + final TransformerFactoryImpl factory; + final Transformer transformer; + String systemId; + Result result; + + SAXTransformerHandler(TransformerFactoryImpl factory, Transformer transformer) + { + this.factory = factory; + this.transformer = transformer; + } + + public String getSystemId() + { + return systemId; + } + + public void setSystemId(String systemId) + { + this.systemId = systemId; + } + + public Transformer getTransformer() + { + return transformer; + } + + public void setResult(Result result) + { + this.result = result; + } + + public void endDocument() + throws SAXException + { + super.endDocument(); + try + { + Document doc = getDocument(); + DOMSource ds = new DOMSource(doc, systemId); + transformer.transform(ds, result); + } + catch (TransformerException e) + { + SAXException e2 = new SAXException(e.getMessage()); + e2.initCause(e); + throw e2; + } + } + +} Modified: trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/StreamSerializer.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -324,7 +324,8 @@ break; case Node.TEXT_NODE: value = node.getNodeValue(); - if (!"yes".equals(node.getUserData("disable-output-escaping"))) + if (!"yes".equals(node.getUserData("disable-output-escaping")) && + mode != Stylesheet.OUTPUT_TEXT) value = encode(value, false, false); out.write(encodeText(value)); break; Modified: trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java 2007-01-07 08:31:59 UTC (rev 3011) +++ trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerFactoryImpl.java 2007-01-07 08:33:13 UTC (rev 3012) @@ -60,11 +60,15 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TemplatesHandler; +import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.xml.sax.XMLFilter; import gnu.xml.dom.DomDocument; /** @@ -73,7 +77,7 @@ * @author <a href='mailto:do...@gn...'>Chris Burdess</a> */ public class TransformerFactoryImpl - extends TransformerFactory + extends SAXTransformerFactory { final XPathFactory xpathFactory; @@ -316,7 +320,8 @@ StreamSource.FEATURE.equals(name) || StreamResult.FEATURE.equals(name) || DOMSource.FEATURE.equals(name) || - DOMResult.FEATURE.equals(name)) + DOMResult.FEATURE.equals(name) || + SAXTransformerFactory.FEATURE.equals(name)) { return true; } @@ -346,6 +351,49 @@ return userListener; } + // -- SAXTransformerFactory -- + + public TemplatesHandler newTemplatesHandler() + throws TransformerConfigurationException + { + return new SAXTemplatesHandler(this); + } + + public TransformerHandler newTransformerHandler() + throws TransformerConfigurationException + { + Transformer transformer = newTransformer(); + return new SAXTransformerHandler(this, transformer); + } + + public TransformerHandler newTransformerHandler(Source source) + throws TransformerConfigurationException + { + Transformer transformer = newTransformer(source); + return new SAXTransformerHandler(this, transformer); + } + + public TransformerHandler newTransformerHandler(Templates templates) + throws TransformerConfigurationException + { + Transformer transformer = templates.newTransformer(); + return new SAXTransformerHandler(this, transformer); + } + + public XMLFilter newXMLFilter(Source source) + throws TransformerConfigurationException + { + throw new UnsupportedOperationException(); + } + + public XMLFilter newXMLFilter(Templates templates) + throws TransformerConfigurationException + { + throw new UnsupportedOperationException(); + } + + // -- SAXTransformerFactory end -- + /** * Syntax: TransformerFactoryImpl [<stylesheet> [<input> [<output>]]] */ Modified: trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/transform/TransformerImpl.java 2007-01-07 08:31:59 UT... [truncated message content] |
From: <ls...@us...> - 2007-06-25 11:20:38
|
Revision: 3311 http://jnode.svn.sourceforge.net/jnode/?rev=3311&view=rev Author: lsantha Date: 2007-06-25 04:20:36 -0700 (Mon, 25 Jun 2007) Log Message: ----------- Openjdk integration. Modified Paths: -------------- trunk/core/src/classpath/gnu/gnu/xml/stream/AttributeImpl.java trunk/core/src/classpath/gnu/gnu/xml/stream/NamespaceImpl.java Removed Paths: ------------- trunk/core/src/classpath/gnu/gnu/CORBA/ trunk/core/src/classpath/gnu/gnu/javax/naming/ trunk/core/src/classpath/gnu/gnu/javax/rmi/ Modified: trunk/core/src/classpath/gnu/gnu/xml/stream/AttributeImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/stream/AttributeImpl.java 2007-06-25 10:56:45 UTC (rev 3310) +++ trunk/core/src/classpath/gnu/gnu/xml/stream/AttributeImpl.java 2007-06-25 11:20:36 UTC (rev 3311) @@ -85,9 +85,10 @@ return value; } - public QName getDTDType() + //jnode openjdk + public String getDTDType() { - return type; + return type.toString(); } public boolean isSpecified() Modified: trunk/core/src/classpath/gnu/gnu/xml/stream/NamespaceImpl.java =================================================================== --- trunk/core/src/classpath/gnu/gnu/xml/stream/NamespaceImpl.java 2007-06-25 10:56:45 UTC (rev 3310) +++ trunk/core/src/classpath/gnu/gnu/xml/stream/NamespaceImpl.java 2007-06-25 11:20:36 UTC (rev 3311) @@ -42,6 +42,7 @@ import javax.xml.stream.Location; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Namespace; +import javax.xml.namespace.QName; /** * A namespace declaration event. @@ -106,6 +107,22 @@ throw e2; } } - + + //jnode openjdk + public QName getName() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public String getValue() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public String getDTDType() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean isSpecified() { + return false; //To change body of implemented methods use File | Settings | File Templates. + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |