You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(97) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(127) |
Feb
(34) |
Mar
(16) |
Apr
(26) |
May
(55) |
Jun
(107) |
Jul
(36) |
Aug
(72) |
Sep
(90) |
Oct
(41) |
Nov
(27) |
Dec
(13) |
2008 |
Jan
(37) |
Feb
(39) |
Mar
(98) |
Apr
(115) |
May
(134) |
Jun
(120) |
Jul
(86) |
Aug
(149) |
Sep
(68) |
Oct
(66) |
Nov
(104) |
Dec
(49) |
2009 |
Jan
(131) |
Feb
(132) |
Mar
(125) |
Apr
(172) |
May
(161) |
Jun
(43) |
Jul
(47) |
Aug
(38) |
Sep
(18) |
Oct
(6) |
Nov
(1) |
Dec
(15) |
2010 |
Jan
(21) |
Feb
(8) |
Mar
(10) |
Apr
(4) |
May
(9) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
(4) |
2011 |
Jan
(23) |
Feb
(10) |
Mar
(13) |
Apr
(3) |
May
|
Jun
(19) |
Jul
(11) |
Aug
(22) |
Sep
|
Oct
(4) |
Nov
(2) |
Dec
(12) |
2012 |
Jan
(3) |
Feb
(4) |
Mar
(7) |
Apr
(3) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(30) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
(8) |
2013 |
Jan
(3) |
Feb
(40) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(12) |
Dec
|
2021 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
From: <ls...@us...> - 2006-12-10 22:12:05
|
Revision: 2894 http://jnode.svn.sourceforge.net/jnode/?rev=2894&view=rev Author: lsantha Date: 2006-12-10 14:12:03 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Fixed usage of Address. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/memmgr/def/VmDefaultHeap.java Modified: trunk/core/src/core/org/jnode/vm/memmgr/def/VmDefaultHeap.java =================================================================== --- trunk/core/src/core/org/jnode/vm/memmgr/def/VmDefaultHeap.java 2006-12-10 22:02:58 UTC (rev 2893) +++ trunk/core/src/core/org/jnode/vm/memmgr/def/VmDefaultHeap.java 2006-12-10 22:12:03 UTC (rev 2894) @@ -186,7 +186,7 @@ */ protected Object alloc(VmClassType<?> vmClass, int alignedSize) { - if (nextFreePtr == null) { /* This heap is full */ + if (nextFreePtr.EQ(Address.zero())) { /* This heap is full */ return null; } final Offset tibOffset = this.tibOffset; @@ -201,7 +201,7 @@ throw new IllegalArgumentException("vmClass.TIB is null"); } //final int size = getSize(); - Address objectPtr = null; + Address objectPtr = Address.zero(); lock(); try { // Search for the first free block that is large enough @@ -218,7 +218,7 @@ // No large enough free space has been found // A collect may recover smaller free spaces in this // heap, but we leave that to a GC iteration. - nextFreePtr = null; + nextFreePtr = Address.zero(); //Screen.debug("B"); return null; } else { @@ -309,7 +309,7 @@ lock(); try { - Address firstFreePtr = null; + Address firstFreePtr = Address.zero(); while (offset.LT(size)) { final Address ptr = start.add(offset); final Word objSize = ptr.loadWord(sizeOffset); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-10 22:03:00
|
Revision: 2893 http://jnode.svn.sourceforge.net/jnode/?rev=2893&view=rev Author: lsantha Date: 2006-12-10 14:02:58 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Fixed usage of Address. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java Modified: trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java =================================================================== --- trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java 2006-12-10 21:56:39 UTC (rev 2892) +++ trunk/core/src/core/org/jnode/vm/compiler/NativeCodeCompiler.java 2006-12-10 22:02:58 UTC (rev 2893) @@ -173,7 +173,7 @@ .getOffset() - startOffset); } else { - defExHandler = null; + defExHandler = Address.zero(); } final VmCompiledExceptionHandler[] eTable; final VmAddressMap aTable = cm.getAddressTable(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-10 21:56:41
|
Revision: 2892 http://jnode.svn.sourceforge.net/jnode/?rev=2892&view=rev Author: lsantha Date: 2006-12-10 13:56:39 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Fixed usage of Address. Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java Modified: trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java =================================================================== --- trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2006-12-10 20:08:26 UTC (rev 2891) +++ trunk/core/src/core/org/jnode/vm/scheduler/VmProcessor.java 2006-12-10 21:56:39 UTC (rev 2892) @@ -507,7 +507,7 @@ * @return The address of the thread switch indicator */ protected final Address getTSIAddress() { - if (tsiAddress == null) { + if (tsiAddress.isZero()) { tsiAddress = ObjectReference.fromObject(this).toAddress(); } return tsiAddress; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-10 20:08:29
|
Revision: 2891 http://jnode.svn.sourceforge.net/jnode/?rev=2891&view=rev Author: lsantha Date: 2006-12-10 12:08:26 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Fixed missing dependency. gnu.classpath.ListenerData needs javax.management . Modified Paths: -------------- trunk/core/descriptors/org.classpath.core.xml trunk/core/descriptors/org.classpath.ext.management.xml Modified: trunk/core/descriptors/org.classpath.core.xml =================================================================== --- trunk/core/descriptors/org.classpath.core.xml 2006-12-10 19:36:16 UTC (rev 2890) +++ trunk/core/descriptors/org.classpath.core.xml 2006-12-10 20:08:26 UTC (rev 2891) @@ -133,6 +133,7 @@ <export name="javax.accessibility.*"/> <export name="javax.isolate.*"/> + <export name="javax.management.*"/> <export name="javax.naming.*"/> <export name="javax.naming.directory.*"/> <export name="javax.naming.event.*"/> Modified: trunk/core/descriptors/org.classpath.ext.management.xml =================================================================== --- trunk/core/descriptors/org.classpath.ext.management.xml 2006-12-10 19:36:16 UTC (rev 2890) +++ trunk/core/descriptors/org.classpath.ext.management.xml 2006-12-10 20:08:26 UTC (rev 2891) @@ -11,8 +11,7 @@ license-name="classpath"> <runtime> - <library name="jnode-core.jar"> - <export name="javax.management.*"/> + <library name="jnode-core.jar"> <export name="javax.management.openmbean.*"/> </library> </runtime> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-10 19:36:17
|
Revision: 2890 http://jnode.svn.sourceforge.net/jnode/?rev=2890&view=rev Author: lsantha Date: 2006-12-10 11:36:16 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/javax/javax/management/openmbean/OpenType.java Added Paths: ----------- trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java trunk/core/src/classpath/javax/javax/management/MBeanPermission.java trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java trunk/core/src/classpath/javax/javax/management/MBeanServer.java trunk/core/src/classpath/javax/javax/management/MBeanServerBuilder.java trunk/core/src/classpath/javax/javax/management/MBeanServerConnection.java trunk/core/src/classpath/javax/javax/management/MBeanServerDelegate.java trunk/core/src/classpath/javax/javax/management/MBeanServerDelegateMBean.java trunk/core/src/classpath/javax/javax/management/MBeanServerFactory.java trunk/core/src/classpath/javax/javax/management/MBeanServerNotification.java trunk/core/src/classpath/javax/javax/management/MBeanTrustPermission.java trunk/core/src/classpath/javax/javax/management/ObjectInstance.java trunk/core/src/classpath/javax/javax/management/ObjectName.java trunk/core/src/classpath/javax/javax/management/QueryExp.java trunk/core/src/classpath/javax/javax/management/ValueExp.java trunk/core/src/classpath/javax/javax/management/loading/ trunk/core/src/classpath/javax/javax/management/loading/ClassLoaderRepository.java Added: trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,102 @@ +/* BadBinaryOpValueExpException.java -- Thrown by invalid query expressions. + 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 javax.management; + +/** + * Thrown when the expression passed to a method for constructing a + * query proves to be invalid. This exception is only used internally + * by the Java management API and is not exposed to user code. + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public class BadBinaryOpValueExpException + extends Exception +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 5068475589449021227L; + + /** + * The value expression that caused the exception. + */ + private ValueExp exp; + + /** + * Constructs a new <code>BadBinaryOpValueExpException</code> + * using the specified expression to represent the invalid one. + * + * @param exp the inappropriate value expression. + */ + public BadBinaryOpValueExpException(ValueExp exp) + { + super(); + this.exp = exp; + } + + /** + * Returns the inappropriate value expression associated + * with this exception. + * + * @return the value expression. + */ + public ValueExp getExp() + { + return exp; + } + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.BadBinaryOpValueExpException</code>) + * and the invalid value expression. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + return getClass().getName() + + "[exp=" + exp + + "]"; + } + +} + Added: trunk/core/src/classpath/javax/javax/management/MBeanPermission.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/MBeanPermission.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/MBeanPermission.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,562 @@ +/* MBeanPermission.java -- Permissions controlling server access. + 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 javax.management; + +import java.security.Permission; + +import java.io.IOException; +import java.io.ObjectInputStream; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +/** + * <p> + * Represents the permissions required to perform + * operations using the {@link MBeanServer}. As with + * all {@link java.security.Permission} objects, an + * instance of this class either represents a permission + * already held or one that is required to access a + * particular service. In the case of {@link MBeanPermission}s, + * implication checks are made using an instance of this class + * when a user requests an operation from the server, and a + * {@link SecurityManager} is in place. + * </p> + * <p> + * An {@link MBeanPermission} consists of four elements, + * which all have to match for the permission to be implied. + * These are as follows: + * </p> + * <ol> + * <li><strong>The action</strong>. For a required permission, + * this is a single value. For a permission held by the user, + * this is a list of comma-separated actions (with spaces allowed), + * or <code>*</code> (representing all actions). {@link #getActions()} + * returns this value.</li> + * <li><strong>The class name</strong>. For a required permission, + * this is the class name of the bean being accessed, if any. If + * a bean isn't involved in this action, the value is <code>null</code>. + * For a permission held by the user, it has one of three values: + * <ol> + * <li>The empty string, implying any class.</li> + * <li><code>*</code>, also implying any class.</li> + * <li>A class name pattern, which may specify a single class + * (e.g. <code>java.lang.Object</code>) or a series of classes + * using the wildcard character <code>*</code> (e.g. + * <code>javax.swing.*</code>.)</li> + * </ol></li> + * <li><strong>The member</strong>. For a required permission, + * this is the member of the bean being accessed (an attribute + * or operation), if any. If a member of the bean isn't involved + * in this action, the value is <code>null</code>. + * For a permission held by the user, it has one of three values: + * <ol> + * <li>The empty string, implying any member.</li> + * <li><code>*</code>, also implying any member.</li> + * <li>The name of a member.</li> + * </ol></li> + * <li>The object name</strong>. For a required permission, + * this is the {@link ObjectName} of the bean being accessed, if + * any. If a bean isn't involved in this action, the value is + * <code>null</code>. The name may not be a pattern. + * For a permission held by the user, it may be the empty + * string (allowing everything) or an {@link ObjectName} + * pattern. + * </li></ol> + * {@link #getName()} returns the latter three of these as a + * single string: + * </p> + * <p><code>className#member[objectName]</code></p> + * <p> + * where <code>""</code> is disallowed, as, although any of + * the elements may be omitted, not all of them should be + * left out simultaneously. <code>"-"</code> is used to + * represent <code>null</code>. When this occurs in a + * required permission, anything may match it. When this + * forms part of a permission held by the user, it only + * matches another <code>null</code> value. + * </p> + * <p>The list of valid actions is as follows:</p> + * <ul> + * <li>addNotificationListener</li> + * <li>getAttribute</li> + * <li>getClassLoader</li> + * <li>getClassLoaderFor</li> + * <li>getClassLoaderRepository</li> + * <li>getDomains</li> + * <li>getMBeanInfo</li> + * <li>getObjectInstance</li> + * <li>instantiate</li> + * <li>invoke</li> + * <li>isInstanceOf</li> + * <li>queryMBeans</li> + * <li>queryNames</li> + * <li>registerMBean</li> + * <li>removeNotificationListener</li> + * <li>setAttribute</li> + * <li>unregisterMBean</li> + * </ul> + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public class MBeanPermission + extends Permission +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -2416928705275160661L; + + /** + * The list of actions associated with this permission. + */ + private String actions; + + /** + * The list of actions as an ordered set. + */ + private transient Set actionSet; + + /** + * The set of valid actions. + */ + private static final Set validSet; + + /** + * Initialise the set of valid actions. + */ + static + { + validSet = new HashSet(); + validSet.add("addNotificationListener"); + validSet.add("getAttribute"); + validSet.add("getClassLoader"); + validSet.add("getClassLoaderFor"); + validSet.add("getClassLoaderRepository"); + validSet.add("getDomains"); + validSet.add("getMBeanInfo"); + validSet.add("getObjectInstance"); + validSet.add("instantiate"); + validSet.add("invoke"); + validSet.add("isInstanceOf"); + validSet.add("queryMBeans"); + validSet.add("queryNames"); + validSet.add("registerMBean"); + validSet.add("removeNotificationListener"); + validSet.add("setAttribute"); + validSet.add("unregisterMBean"); + } + + /** + * Constructs a new {@link MBeanPermission} with the specified name + * and actions. The name is of the form <code>className#member[objectName]</code>, + * where each element is optional, but a completely empty or <code>null</code> + * name is disallowed. Actions are specified as a comma-separated list + * and may also not be empty or <code>null</code>. + * + * @param name the name of the permission. + * @param actions the actions associated with this permission. + * @throws IllegalArgumentException if the name or actions are invalid. + */ + public MBeanPermission(String name, String actions) + { + super(name); + if (name == null || name.length() == 0) + throw new IllegalArgumentException("The supplied name was null or empty."); + if (actions == null || actions.length() == 0) + throw new IllegalArgumentException("The supplied action list was null or empty."); + this.actions = actions; + updateActionSet(); + } + + /** + * Constructs a new {@link MBeanPermission} with the specified class name, + * member, object name and actions. The name of the permission is created + * using the form <code>className#member[objectName]</code>, + * where each element is optional, but an empty or <code>null</code> + * name is disallowed. Actions are specified as a comma-separated list + * and may also not be empty or <code>null</code>. + * + * @param className the name of the class to which this permission applies, + * or either <code>null</code> or <code>"-"</code> for a + * value which may be implied by any class name, but not + * imply any class name itself. + * @param member the member of the class to which this permission applies, + * or either <code>null</code> or <code>"-"</code> for a + * value which may be implied by any member, but not + * imply any member itself. + * @param objectName the {@link ObjectName} to which this permission applies, + * or <code>null</code> for a value which may be implied by + * any object name, but not imply any object name itself. + * @param actions the actions associated with this permission. + */ + public MBeanPermission(String className, String member, + ObjectName name, String actions) + { + this((className == null ? "-" : className) + "#" + + (member == null ? "-" : member) + "[" + + (name == null ? "-" : name.toString()) + "]", actions); + } + + /** + * Returns true if the given object is also an {@link MBeanPermission} + * with the same name and actions. + * + * @param obj the object to test. + * @return true if the object is an {@link MBeanPermission} with + * the same name and actions. + */ + public boolean equals(Object obj) + { + if (obj instanceof MBeanPermission) + { + MBeanPermission p = (MBeanPermission) obj; + return (p.getName().equals(getName()) && + p.getActions().equals(actions)); + } + return false; + } + + /** + * Returns the list of actions in alphabetical order. + * + * @return the list of actions. + */ + public String getActions() + { + Iterator it = actionSet.iterator(); + StringBuilder builder = new StringBuilder(); + while (it.hasNext()) + { + builder.append(it.next()); + if (it.hasNext()) + builder.append(","); + } + return builder.toString(); + } + + /** + * Returns the hashcode of the permission as the sum + * of the hashcodes of the name and actions. + * + * @return the hashcode of the permission. + */ + public int hashCode() + { + return getName().hashCode() + actions.hashCode(); + } + + /** + * <p> + * Returns true if this permission implies the supplied permission. + * This happens if the following holds: + * </p> + * <ul> + * <li>The supplied permission is an {@link MBeanPermission}</li> + * <li>The supplied permission has either a <code>null</code> classname + * or its classname matches the classname of this permission. A + * classname of <code>"*"</code> for this permission always matches + * the classname of the supplied permission. Generally, <code>'*'</code> + * acts as a wildcard, so <code>".*"</code> matches <code>'.'</code> + * followed by anything.</li> + * <li>The supplied permission has either a <code>null</code> member + * or its member matches the member of this permission. A member of + * <code>"*"</code> for this permission always matches the member + * of the supplied permission.</li> + * <li>The supplied permission has either a <code>null</code> object name + * or its object name matches the object name of this permission. If the + * object name of this permission is a pattern, {@link ObjectName#apply(ObjectName)} + * may be used as well.</li> + * <li>The supplied permission's actions are a subset of the actions + * of this permission. If the <code>queryMBeans</code> action is presented, + * the <code>queryNames</code> action is implied.</li> + * </ul> + * + * @param p the permission to check that this permission implies. + * @return true if this permission implies <code>p</code>. + */ + public boolean implies(Permission p) + { + if (p instanceof MBeanPermission) + { + MBeanPermission mp = (MBeanPermission) p; + NameHolder pName = new NameHolder(mp.getName()); + NameHolder name = new NameHolder(getName()); + if (!(name.equals(pName))) + return false; + Iterator i = mp.getActionSet().iterator(); + while (i.hasNext()) + { + String nextAction = (String) i.next(); + boolean found = actions.contains(nextAction); + if (!found) + if (nextAction.equals("queryNames")) + found = actions.contains("queryMBeans"); + if (!found) + return false; + } + return true; + } + return false; + } + + /** + * Small helper class to handle deconstruction of the name. + * + * @author Andrew John Hughes (gnu...@me...) + */ + private class NameHolder + { + + /** + * The class name. + */ + private String className; + + /** + * The member. + */ + private String member; + + /** + * The object name. + */ + private ObjectName objectName; + + /** + * Constructs a broken-down name from a given name. + * + * @param name the name to break down. + */ + public NameHolder(String name) + { + String objectName = null; + int memberIndex = name.indexOf("#"); + int onIndex = name.indexOf("["); + if (onIndex == -1) + { + if (memberIndex == -1) + className = name; + else + { + className = name.substring(0, memberIndex); + member = name.substring(memberIndex + 1); + } + } + else + { + if (memberIndex == -1) + { + className = name.substring(0, onIndex); + objectName = name.substring(onIndex + 1, + name.length() - 1); + } + else + { + className = name.substring(0, memberIndex); + member = name.substring(memberIndex + 1, onIndex); + objectName = name.substring(onIndex + 1, + name.length() - 1); + } + } + if (className.equals("-")) + className = null; + if (member.equals("-")) + member = null; + if (objectName == null || objectName.equals("-")) + this.objectName = null; + else + try + { + this.objectName = new ObjectName(objectName); + } + catch (MalformedObjectNameException e) + { + throw (Error) + (new InternalError("Invalid object name.").initCause(e)); + } + } + + /** + * <p> + * Returns true if the supplied object is also a + * {@link NameHolder} and the following holds: + * </p> + * <ul> + * <li>The supplied classname is <code>null</code> or the two match. A + * classname of <code>"*"</code> for this holder always matches + * the classname of the supplied holder. Generally, <code>'*'</code> + * acts as a wildcard, so <code>".*"</code> matches <code>'.'</code> + * followed by anything.</li> + * <li>The supplied name holder has either a <code>null</code> member + * or its member matches the member of this name holder. A member of + * <code>"*"</code> for this name holder always matches the member + * of the supplied name holder.</li> + * <li>The supplied name holder has either a <code>null</code> object name + * or its object name matches the object name of this name holder. If the + * object name of this name holder is a pattern, + * {@link ObjectName#apply(ObjectName)} may be used as well.</li> + * </ul> + * + * @param obj the object to compare with this. + * @return true if the above holds. + */ + public boolean equals(Object obj) + { + if (obj instanceof NameHolder) + { + NameHolder nh = (NameHolder) obj; + boolean cn = false; + String ocn = nh.getClassName(); + if (ocn == null || className.equals("*")) + cn = true; + else + { + int wcIndex = className.indexOf("*"); + if (wcIndex != -1) + cn = ocn.startsWith(className.substring(0, wcIndex)); + else + cn = ocn.equals(className); + } + boolean m = false; + String om = nh.getMember(); + if (om == null || member.equals("*")) + m = true; + else + m = om.equals(member); + boolean on = false; + ObjectName oon = nh.getObjectName(); + if (oon == null) + on = true; + else if (objectName.isPattern()) + on = objectName.apply(oon); + else + on = oon.equals(objectName); + return (cn && m && on); + } + return false; + } + + /** + * Returns the class name. + */ + public String getClassName() + { + return className; + } + + /** + * Returns the member. + */ + public String getMember() + { + return member; + } + + /** + * Returns the object name. + */ + public ObjectName getObjectName() + { + return objectName; + } + } + + /** + * Returns the set of actions. + * + * @return the actions as an ordered set. + */ + Set getActionSet() + { + return actionSet; + } + + /** + * Updates the action set from the current value of + * the actions string. + */ + private void updateActionSet() + { + String[] actionsArray = actions.split(","); + actionSet = new TreeSet(); + for (int a = 0; a < actionsArray.length; ++a) + actionSet.add(actionsArray[a].trim()); + } + + /** + * Reads the object from a stream and ensures the incoming + * data is valid. + * + * @param in the input stream. + * @throws IOException if an I/O error occurs. + * @throws ClassNotFoundException if a class used by the object + * can not be found. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + updateActionSet(); + checkActions(); + } + + /** + * Checks that the actions used in this permission + * are from the valid set. + * + * @throws IllegalArgumentException if the name or actions are invalid. + */ + private void checkActions() + { + Iterator it = actionSet.iterator(); + while (it.hasNext()) + { + String action = (String) it.next(); + if (!(validSet.contains(action))) + throw new IllegalArgumentException("Invalid action " + + action + " found."); + } + } + +} + Added: trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,95 @@ +/* MBeanRegistration.java -- Interface for beans to hook into registration. + 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 javax.management; + +/** + * Beans may implement this interface in order to perform + * operations immediately prior to or after their registration + * or deregistration. + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public interface MBeanRegistration +{ + + /** + * This method is called following deregistration of the bean + * by the server. + */ + void postDeregister(); + + /** + * This method is called following both successful and unsuccessful + * attempts to register the bean. The supplied boolean value indicates + * the result of the attempt relative to this call. + * + * @param successful true if the registration was successful. + */ + void postRegister(Boolean successful); + + /** + * This method is called prior to de-registration, and may throw + * an exception. + * + * @throws Exception if something goes wrong during the bean's pre-deregistration + * operation. The server will re-throw this exception + * as an {@link MBeanRegistrationException}. + */ + void preDeregister() + throws Exception; + + /** + * This method is called prior to registration, with a reference to the + * server and {@link ObjectName} supplied to the server for registration. + * This method may be used to replace this name by one chosen by the bean. + * Such behaviour is expected if the supplied name is <code>null</code>, + * but may occur in all cases. The method may throw an exception, which + * will cause registration to be aborted. + * + * @param server the server with which the bean is being registered. + * @param name the name the server was supplied with for registration, + * which may be <code>null</code>. + * @throws Exception if something goes wrong during the bean's pre-registration + * operation. The server will re-throw this exception + * as an {@link MBeanRegistrationException}. + */ + ObjectName preRegister(MBeanServer server, ObjectName name) + throws Exception; + +} Added: trunk/core/src/classpath/javax/javax/management/MBeanServer.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/MBeanServer.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/MBeanServer.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,1199 @@ +/* MBeanServer.java -- Represents a 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 javax.management; + +import java.io.ObjectInputStream; + +import java.util.Set; + +import javax.management.loading.ClassLoaderRepository; + +/** + * <p> + * This interface represents a server for management beans, + * providing facilities for the creation, registration and + * removal of such beans. This interface is central to the + * Java management architecture. Users do not usually implement + * this class. Instead, implementations of this class + * may be obtained using an {@link MBeanServerFactory}. + * </p> + * <p> + * Registering a bean with the server makes its attributes and + * operations accessible via the server. Only JMX compliant + * beans may be registered with the server. When a bean + * is registered or unregistered, an {@link MBeanServerNotification} + * is emitted by the server's {@link MBeanServerDelegate}. + * Listeners may be registered with this bean in order to + * obtain such notifications. It has the {@link ObjectName} + * <code>JMImplementation:type=MBeanServerDelegate</code>. + * </p> + * <p> + * Security checks are applied on the methods of the server, + * as detailed below, if it is obtained using the + * {@link MBeanServerFactory#createMBeanServer()} or + * {@link MBeanServerFactory#newMBeanServer()} methods and + * {@link System.getSecurityManager()} returns a non-<code>null</code> + * value. If a check fails, a {@link SecurityException} + * is thrown. Note than the class name used in the exception + * is that of the bean, and thus, as a result, an + * {@link InstanceNotFoundException} + * precludes these security checks, due to the class name + * that would be used in the exception being unavailable. + * </p> + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public interface MBeanServer + extends MBeanServerConnection +{ + + /** + * 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. + * + * @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) + */ + void addNotificationListener(ObjectName name, NotificationListener listener, + NotificationFilter filter, Object passback) + throws InstanceNotFoundException; + + /** + * <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) + */ + void addNotificationListener(ObjectName name, ObjectName listener, + NotificationFilter filter, Object passback) + throws InstanceNotFoundException; + + /** + * <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[]) + */ + ObjectInstance createMBean(String className, ObjectName name) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException; + + /** + * <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. + */ + ObjectInstance createMBean(String className, ObjectName name, + Object[] params, String[] sig) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException; + + /** + * <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[]) + */ + ObjectInstance createMBean(String className, ObjectName name, + ObjectName loaderName) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException, InstanceNotFoundException; + + /** + * <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. + */ + ObjectInstance createMBean(String className, ObjectName name, + ObjectName loaderName, Object[] params, + String[] sig) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException, InstanceNotFoundException; + + /** + * 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> + */ + ObjectInputStream deserialize(ObjectName name, byte[] data) + throws InstanceNotFoundException, OperationsException; + + /** + * 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> + */ + ObjectInputStream deserialize(String name, byte[] data) + throws OperationsException, ReflectionException; + + /** + * 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> + */ + ObjectInputStream deserialize(String name, ObjectName loader, byte[] data) + throws InstanceNotFoundException, ReflectionException, + OperationsException; + + /** + * 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) + */ + Object getAttribute(ObjectName bean, String name) + throws MBeanException, AttributeNotFoundException, + InstanceNotFoundException, ReflectionException; + + /** + * 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[]) + */ + AttributeList getAttributes(ObjectName bean, String[] names) + throws InstanceNotFoundException, ReflectionException; + + /** + * 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> + */ + ClassLoader getClassLoader(ObjectName name) + throws InstanceNotFoundException; + + /** + * 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> + */ + ClassLoader getClassLoaderFor(ObjectName name) + throws InstanceNotFoundException; + + /** + * 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> + */ + ClassLoaderRepository getClassLoaderRepository(); + + /** + * Returns the default domain this server applies to beans that have + * no specified domain. + * + * @return the default domain. + */ + String getDefaultDomain(); + + /** + * 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() + */ + String[] getDomains(); + + /** + * Returns the number of manag... [truncated message content] |
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: <Qa...@us...> - 2006-12-10 19:17:20
|
Revision: 2888 http://jnode.svn.sourceforge.net/jnode/?rev=2888&view=rev Author: QaDeS Date: 2006-12-10 11:17:19 -0800 (Sun, 10 Dec 2006) Log Message: ----------- tiny cleanup Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java Modified: trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java 2006-12-10 19:16:46 UTC (rev 2887) +++ trunk/shell/src/shell/org/jnode/shell/command/LocaleCommand.java 2006-12-10 19:17:19 UTC (rev 2888) @@ -21,8 +21,6 @@ package org.jnode.shell.command; -import gnu.java.net.GetLocalHostAction; - import java.io.InputStream; import java.io.PrintStream; import java.util.Locale; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Qa...@us...> - 2006-12-10 19:16:48
|
Revision: 2887 http://jnode.svn.sourceforge.net/jnode/?rev=2887&view=rev Author: QaDeS Date: 2006-12-10 11:16:46 -0800 (Sun, 10 Dec 2006) Log Message: ----------- optional "clean fallback" for localization, gulping possible errors and merely returning the given key on a miss Modified Paths: -------------- trunk/core/src/core/org/jnode/plugin/PluginUtils.java Modified: trunk/core/src/core/org/jnode/plugin/PluginUtils.java =================================================================== --- trunk/core/src/core/org/jnode/plugin/PluginUtils.java 2006-12-10 19:10:11 UTC (rev 2886) +++ trunk/core/src/core/org/jnode/plugin/PluginUtils.java 2006-12-10 19:16:46 UTC (rev 2887) @@ -49,9 +49,13 @@ } } - public static String getLocalizedMessage(Class parent, String bundleName, - String messageKey) - { + public static String getLocalizedMessage(Class parent, String bundleName, + String messageKey) { + return getLocalizedMessage(parent, bundleName, messageKey, false); + } + + public static String getLocalizedMessage(Class parent, String bundleName, + String messageKey, boolean cleanFallback) { String fullName; ClassLoader loader; if(parent == null) @@ -84,7 +88,8 @@ } catch (MissingResourceException mre) { - BootLog.error("can't get message", mre); + if( !cleanFallback ) + BootLog.error("can't get message", mre); } } @@ -98,16 +103,17 @@ } catch (MissingResourceException mre) { - mre.printStackTrace(); + if( !cleanFallback) + mre.printStackTrace(); } } - if(message == null) + if(message == null && !cleanFallback) { BootLog.error("can't get message from bundle "+bundleName+" with key "+messageKey); } - return (message == null) ? ('?' + messageKey + '?') : message; + return (message == null) ? (cleanFallback ? messageKey : ('?' + messageKey + '?')) : message; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-10 19:10:18
|
Revision: 2886 http://jnode.svn.sourceforge.net/jnode/?rev=2886&view=rev Author: lsantha Date: 2006-12-10 11:10:11 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Added tab handling and status line. Modified Paths: -------------- trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java Modified: trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2006-12-10 17:40:01 UTC (rev 2885) +++ trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2006-12-10 19:10:11 UTC (rev 2886) @@ -45,16 +45,16 @@ te.loadFile(f); } - public TextEditor(TextConsole first) { - this.console = first; - first.addKeyboardListener(this); - console.setCursorVisible(true); + public TextEditor(TextConsole console) { + this.console = console; + console.addKeyboardListener(this); + this.console.setCursorVisible(true); cx = 0; cy = 0; - sh = first.getHeight(); - sw = first.getWidth(); + sh = console.getHeight(); + sw = console.getWidth(); cxm = sw - 1; - cym = sh - 1; + cym = sh - 1 - 1; fx = 0; fy = 0; ls = new ArrayList<StringBuilder>(); @@ -107,19 +107,61 @@ }); } + private void updateScreen(){ - char[] data = new char[sw * sh]; + char[] data = new char[sw * (cym + 1 + 1)]; int k = 0; StringBuilder e = new StringBuilder(); - for(int i = 0; i < sh; i ++){ + List<StringBuilder> rl = new ArrayList<StringBuilder>(); + for(int i = 0; i < cym + 1; i ++){ StringBuilder l = (fy + i < ls.size()) ? ls.get(fy + i) : e; + StringBuilder sb = new StringBuilder(); + for(int j = 0; j < l.length(); j++){ + char c = l.charAt(j); + if(c == '\t'){ + sb.append(' '); + sb.append(' '); + sb.append(' '); + sb.append(' '); + } else if(c == '\n'){ + sb.append(' '); + } else{ + sb.append(c); + } + } + rl.add(sb); + } + + int tab_count = 0; + if(ls.size() > 0){ + CharSequence l = ls.get(oy()).subSequence(0, fx + cx); + for(int i = 0; i < l.length(); i ++ ){ + if(l.charAt(i) == '\t') tab_count ++; + } + } + + int tx = fx + cx + 3 * tab_count; + int cx2 = cx + 3 * tab_count; + int fx2 = fx; + if(tx >= sw){ + cx2 = sw -1; + fx2 = tx - cx2; + } + + for(int i = 0; i < cym + 1; i ++){ + StringBuilder l = rl.get(i); for(int j = 0; j < sw; j++){ - char c = (fx + j < l.length()) ? l.charAt(fx + j) : ' '; - data[k++] = (c == '\n' || c == '\t') ? ' ' : c; + char c = (fx2 + j < l.length()) ? l.charAt(fx2 + j) : ' '; + data[k++] = c; } } + + e.append(file.getName()).append(" [").append(fx2 + cx2 + 1).append(",").append(oy() + 1).append("]"); + for(int j = 0; j < sw; j++){ + data[k++] = (j < e.length()) ? e.charAt(j) : ' '; + } console.setChar(0, 0, data, 7); - console.setCursor(cx, cy); + console.setCursor(cx2, cy); } public void keyPressed(KeyboardEvent e) { @@ -131,8 +173,8 @@ case KeyEvent.VK_LEFT: {if(fx > 0) fx --; break;} case KeyEvent.VK_RIGHT: {if(fx < mx()) fx ++; break;} case KeyEvent.VK_HOME: {cx = fx = cy = fy = 0; break;} - case KeyEvent.VK_END: { if(my() < cym) cy = my(); else {cy = cym; fy = my() - cy;}; end(); break;} - case KeyEvent.VK_Y: { ls.remove(oy()); if(oy() > my()) cy --; break;} + case KeyEvent.VK_END: { if(my() < cym) cy = my(); else {cy = cym; fy = my() - cy;} end(); break;} + case KeyEvent.VK_Y: { if(oy() >= 0 && oy() <= my()) {ls.remove(oy()); if(cy > 0) cy --; else if(fy > 0) fy --;} break;} case KeyEvent.VK_S: { saveFile(); break;} case KeyEvent.VK_Q: { console.getManager().unregisterConsole(console); break;} @@ -170,6 +212,11 @@ cx = l2.length() - 1; l2.deleteCharAt(l2.length() - 1).append(ls.remove(oy())); cy --; + } else if(fy > 0){ + StringBuilder l2 = ls.get(oy() - 1); + cx = l2.length() - 1; + l2.deleteCharAt(l2.length() - 1).append(ls.remove(oy())); + fy --; } } else if(cx > 0){ cx --; @@ -201,6 +248,7 @@ } if(oy() > my()){ fy -= oy() - my(); + fy = fy < 0 ? 0 : fy ; } if(ox() > mx()) { if(mx() > cxm){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Qa...@us...> - 2006-12-10 17:40:07
|
Revision: 2885 http://jnode.svn.sourceforge.net/jnode/?rev=2885&view=rev Author: QaDeS Date: 2006-12-10 09:40:01 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Bug 911 quick fix Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/VmReflection.java trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java Modified: trunk/core/src/core/org/jnode/vm/VmReflection.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmReflection.java 2006-12-10 15:57:36 UTC (rev 2884) +++ trunk/core/src/core/org/jnode/vm/VmReflection.java 2006-12-10 17:40:01 UTC (rev 2885) @@ -318,6 +318,8 @@ } if (!method.isStatic()) { + if( o == null ) + throw new NullPointerException(); Unsafe.pushObject(o); } else { method.getDeclaringClass().initialize(); Modified: trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2006-12-10 15:57:36 UTC (rev 2884) +++ trunk/shell/src/shell/org/jnode/shell/ThreadCommandInvoker.java 2006-12-10 17:40:01 UTC (rev 2885) @@ -33,6 +33,7 @@ import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; @@ -287,8 +288,12 @@ // new // thread? try { - AccessController.doPrivileged(new InvokeAction(method, - null, args)); + Object obj = null; + if(!Modifier.isStatic(method.getModifiers())) { + obj = cx.newInstance(); + } + AccessController.doPrivileged(new InvokeAction(method, + obj, args)); } catch (PrivilegedActionException ex) { throw ex.getException(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2006-12-10 15:57:38
|
Revision: 2884 http://jnode.svn.sourceforge.net/jnode/?rev=2884&view=rev Author: fduminy Date: 2006-12-10 07:57:36 -0800 (Sun, 10 Dec 2006) Log Message: ----------- added more meaningfull message when escape char is not followed by a character Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/CommandLine.java Modified: trunk/shell/src/shell/org/jnode/shell/CommandLine.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2006-12-09 18:47:57 UTC (rev 2883) +++ trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2006-12-10 15:57:36 UTC (rev 2884) @@ -191,6 +191,11 @@ switch (currentChar) { case ESCAPE_CHAR: + if(pos >= s.length()) + { + throw new IllegalArgumentException("escape char ('\\') not followed by a character"); + } + token.append(CommandLine.unescape(s.charAt(pos++))); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-09 18:47:59
|
Revision: 2883 http://jnode.svn.sourceforge.net/jnode/?rev=2883&view=rev Author: lsantha Date: 2006-12-09 10:47:57 -0800 (Sat, 09 Dec 2006) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/javax/javax/swing/JEditorPane.java trunk/core/src/classpath/javax/javax/swing/JTextField.java trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicHTML.java trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicTextUI.java Modified: trunk/core/src/classpath/javax/javax/swing/JEditorPane.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/JEditorPane.java 2006-12-09 18:47:15 UTC (rev 2882) +++ trunk/core/src/classpath/javax/javax/swing/JEditorPane.java 2006-12-09 18:47:57 UTC (rev 2883) @@ -40,6 +40,8 @@ import java.awt.Container; import java.awt.Dimension; +import java.io.BufferedInputStream; +import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -47,6 +49,7 @@ import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.util.HashMap; import javax.accessibility.AccessibleContext; @@ -56,6 +59,8 @@ import javax.accessibility.AccessibleText; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; +import javax.swing.plaf.TextUI; +import javax.swing.text.AbstractDocument; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; @@ -482,6 +487,34 @@ } /** + * Used to store a mapping for content-type to editor kit class. + */ + private static class EditorKitMapping + { + /** + * The classname of the editor kit. + */ + String className; + + /** + * The classloader with which the kit is to be loaded. + */ + ClassLoader classLoader; + + /** + * Creates a new EditorKitMapping object. + * + * @param cn the classname + * @param cl the classloader + */ + EditorKitMapping(String cn, ClassLoader cl) + { + className = cn; + classLoader = cl; + } + } + + /** * An EditorKit used for plain text. This is the default editor kit for * JEditorPanes. * @@ -505,19 +538,159 @@ } } + /** + * A special stream that can be cancelled. + */ + private class PageStream + extends FilterInputStream + { + /** + * True when the stream has been cancelled, false otherwise. + */ + private boolean cancelled; + + protected PageStream(InputStream in) + { + super(in); + cancelled = false; + } + + private void checkCancelled() + throws IOException + { + if (cancelled) + throw new IOException("Stream has been cancelled"); + } + + void cancel() + { + cancelled = true; + } + + public int read() + throws IOException + { + checkCancelled(); + return super.read(); + } + + public int read(byte[] b, int off, int len) + throws IOException + { + checkCancelled(); + return super.read(b, off, len); + } + + public long skip(long n) + throws IOException + { + checkCancelled(); + return super.skip(n); + } + + public int available() + throws IOException + { + checkCancelled(); + return super.available(); + } + + public void reset() + throws IOException + { + checkCancelled(); + super.reset(); + } + } + + /** + * The thread that loads documents asynchronously. + */ + private class PageLoader + implements Runnable + { + private Document doc; + private PageStream in; + private URL old; + URL page; + PageLoader(Document doc, InputStream in, URL old, URL page) + { + this.doc = doc; + this.in = new PageStream(in); + this.old = old; + this.page = page; + } + + public void run() + { + try + { + read(in, doc); + } + catch (IOException ex) + { + UIManager.getLookAndFeel().provideErrorFeedback(JEditorPane.this); + } + finally + { + if (SwingUtilities.isEventDispatchThread()) + firePropertyChange("page", old, page); + else + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + firePropertyChange("page", old, page); + } + }); + } + } + } + + void cancel() + { + in.cancel(); + } + } + private static final long serialVersionUID = 3140472492599046285L; - private URL page; private EditorKit editorKit; boolean focus_root; + /** + * Maps content-types to editor kit instances. + */ + static HashMap editorKits; + // A mapping between content types and registered EditorKit types static HashMap registerMap; + static + { + registerMap = new HashMap(); + editorKits = new HashMap(); + registerEditorKitForContentType("application/rtf", + "javax.swing.text.rtf.RTFEditorKit"); + registerEditorKitForContentType("text/plain", + "javax.swing.JEditorPane$PlainEditorKit"); + registerEditorKitForContentType("text/html", + "javax.swing.text.html.HTMLEditorKit"); + registerEditorKitForContentType("text/rtf", + "javax.swing.text.rtf.RTFEditorKit"); + + } + // A mapping between content types and used EditorKits HashMap editorMap; + /** + * The currently loading stream, if any. + */ + private PageLoader loader; + public JEditorPane() { init(); @@ -550,15 +723,6 @@ void init() { editorMap = new HashMap(); - registerMap = new HashMap(); - registerEditorKitForContentType("application/rtf", - "javax.swing.text.rtf.RTFEditorKit"); - registerEditorKitForContentType("text/plain", - "javax.swing.JEditorPane$PlainEditorKit"); - registerEditorKitForContentType("text/html", - "javax.swing.text.html.HTMLEditorKit"); - registerEditorKitForContentType("text/rtf", - "javax.swing.text.rtf.RTFEditorKit"); } protected EditorKit createDefaultEditorKit() @@ -578,21 +742,29 @@ */ public static EditorKit createEditorKitForContentType(String type) { - // TODO: Have to handle the case where a ClassLoader was specified - // when the EditorKit was registered - EditorKit e = null; - String className = (String) registerMap.get(type); - if (className != null) + // Try cached instance. + EditorKit e = (EditorKit) editorKits.get(type); + if (e == null) { + EditorKitMapping m = (EditorKitMapping) registerMap.get(type); + if (m != null) + { + String className = m.className; + ClassLoader loader = m.classLoader; try { - e = (EditorKit) Class.forName(className).newInstance(); + e = (EditorKit) loader.loadClass(className).newInstance(); } catch (Exception e2) { - // TODO: Not sure what to do here. + // The reference implementation returns null when class is not + // loadable or instantiatable. } } + // Cache this for later retrieval. + if (e != null) + editorKits.put(type, e); + } return e; } @@ -652,7 +824,9 @@ */ public static String getEditorKitClassNameForContentType(String type) { - return (String) registerMap.get(type); + EditorKitMapping m = (EditorKitMapping) registerMap.get(type); + String kitName = m != null ? m.className : null; + return kitName; } /** @@ -675,10 +849,14 @@ EditorKit e = (EditorKit) editorMap.get(type); // Then check to see if we can create one. if (e == null) + { e = createEditorKitForContentType(type); + if (e != null) + setEditorKitForContentType(type, e); + } // Otherwise default to PlainEditorKit. if (e == null) - e = new PlainEditorKit(); + e = createDefaultEditorKit(); return e; } @@ -695,10 +873,28 @@ public Dimension getPreferredSize() { Dimension pref = super.getPreferredSize(); - if (getScrollableTracksViewportWidth()) - pref.width = getUI().getMinimumSize(this).width; - if (getScrollableTracksViewportHeight()) - pref.height = getUI().getMinimumSize(this).height; + Container parent = getParent(); + if (parent instanceof JViewport) + { + JViewport vp = (JViewport) getParent(); + TextUI ui = getUI(); + Dimension min = null; + if (! getScrollableTracksViewportWidth()) + { + min = ui.getMinimumSize(this); + int vpWidth = vp.getWidth(); + if (vpWidth != 0 && vpWidth < min.width) + pref.width = min.width; + } + if (! getScrollableTracksViewportHeight()) + { + if (min == null) + min = ui.getMinimumSize(this); + int vpHeight = vp.getHeight(); + if (vpHeight != 0 && vpHeight < min.height) + pref.height = min.height; + } + } return pref; } @@ -716,9 +912,11 @@ // Tests show that this returns true when the parent is a JViewport // and has a height > minimum UI height. Container parent = getParent(); + int height = parent.getHeight(); + TextUI ui = getUI(); return parent instanceof JViewport - && parent.getHeight() >= getUI().getMinimumSize(this).height - && parent.getHeight() <= getUI().getMaximumSize(this).height; + && height >= ui.getMinimumSize(this).height + && height <= ui.getMaximumSize(this).height; } /** @@ -741,13 +939,19 @@ public URL getPage() { - return page; + return loader != null ? loader.page : null; } protected InputStream getStream(URL page) throws IOException { - return page.openStream(); + URLConnection conn = page.openConnection(); + // Try to detect the content type of the stream data. + String type = conn.getContentType(); + if (type != null) + setContentType(type); + InputStream stream = conn.getInputStream(); + return new BufferedInputStream(stream); } public String getText() @@ -778,10 +982,12 @@ EditorKit kit = getEditorKit(); if (kit instanceof HTMLEditorKit && desc instanceof HTMLDocument) { - Document doc = (Document) desc; + HTMLDocument doc = (HTMLDocument) desc; + setDocument(doc); try { - kit.read(in, doc, 0); + InputStreamReader reader = new InputStreamReader(in); + kit.read(reader, doc, 0); } catch (BadLocationException ex) { @@ -806,7 +1012,8 @@ public static void registerEditorKitForContentType(String type, String classname) { - registerMap.put(type, classname); + registerEditorKitForContentType(type, classname, + Thread.currentThread().getContextClassLoader()); } /** @@ -816,7 +1023,7 @@ String classname, ClassLoader loader) { - // TODO: Implement this properly. + registerMap.put(type, new EditorKitMapping(classname, loader)); } /** @@ -840,6 +1047,13 @@ public final void setContentType(String type) { + // Strip off content type parameters. + int paramIndex = type.indexOf(';'); + if (paramIndex > -1) + { + // TODO: Handle character encoding. + type = type.substring(0, paramIndex).trim(); + } if (editorKit != null && editorKit.getContentType().equals(type)) return; @@ -900,14 +1114,45 @@ if (page == null) throw new IOException("invalid url"); - try + URL old = getPage(); + // Only reload if the URL doesn't point to the same file. + // This is not the same as equals because there might be different + // URLs on the same file with different anchors. + if (old == null || ! old.sameFile(page)) { - this.page = page; - getEditorKit().read(page.openStream(), getDocument(), 0); + InputStream in = getStream(page); + if (editorKit != null) + { + Document doc = editorKit.createDefaultDocument(); + doc.putProperty(Document.StreamDescriptionProperty, page); + + if (loader != null) + loader.cancel(); + loader = new PageLoader(doc, in, old, page); + + int prio = -1; + if (doc instanceof AbstractDocument) + { + AbstractDocument aDoc = (AbstractDocument) doc; + prio = aDoc.getAsynchronousLoadPriority(); + } + if (prio >= 0) + { + // Load asynchronously. + setDocument(doc); + Thread loadThread = new Thread(loader, + "JEditorPane.PageLoader"); + loadThread.setDaemon(true); + loadThread.setPriority(prio); + loadThread.start(); } - catch (BadLocationException e) + else { - // Ignored. '0' is always a valid offset. + // Load synchronously. + loader.run(); + setDocument(doc); + } + } } } Modified: trunk/core/src/classpath/javax/javax/swing/JTextField.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/JTextField.java 2006-12-09 18:47:15 UTC (rev 2882) +++ trunk/core/src/classpath/javax/javax/swing/JTextField.java 2006-12-09 18:47:57 UTC (rev 2883) @@ -270,7 +270,8 @@ */ protected void fireActionPerformed() { - ActionEvent event = new ActionEvent(this, 0, getText()); + ActionEvent event = new ActionEvent(this, 0, + actionCommand == null ? getText() : actionCommand); ActionListener[] listeners = getActionListeners(); for (int index = 0; index < listeners.length; ++index) Modified: trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicHTML.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicHTML.java 2006-12-09 18:47:15 UTC (rev 2882) +++ trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicHTML.java 2006-12-09 18:47:57 UTC (rev 2883) @@ -48,6 +48,7 @@ import javax.swing.JComponent; import javax.swing.SwingConstants; import javax.swing.event.DocumentEvent; +import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.EditorKit; @@ -355,6 +356,22 @@ { return document; } + + /** + * Overridden to return null, as a RootView has no attributes on its own. + */ + public AttributeSet getAttributes() + { + return null; + } + + /** + * Overridden to provide an element for the view. + */ + public Element getElement() + { + return view.getElement(); + } } /** Modified: trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicTextUI.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicTextUI.java 2006-12-09 18:47:15 UTC (rev 2882) +++ trunk/core/src/classpath/javax/javax/swing/plaf/basic/BasicTextUI.java 2006-12-09 18:47:57 UTC (rev 2883) @@ -38,6 +38,8 @@ package javax.swing.plaf.basic; +import gnu.classpath.SystemProperties; + import java.awt.Color; import java.awt.Container; import java.awt.Dimension; @@ -121,7 +123,141 @@ } } + private static class FocusHandler + implements FocusListener + { + public void focusGained(FocusEvent e) + { + // Nothing to do here. + } + public void focusLost(FocusEvent e) + { + JTextComponent textComponent = (JTextComponent) e.getComponent(); + // Integrates Swing text components with the system clipboard: + // The idea is that if one wants to copy text around X11-style + // (select text and middle-click in the target component) the focus + // will move to the new component which gives the old focus owner the + // possibility to paste its selection into the clipboard. + if (!e.isTemporary() + && textComponent.getSelectionStart() + != textComponent.getSelectionEnd()) + { + SecurityManager sm = System.getSecurityManager(); + try + { + if (sm != null) + sm.checkSystemClipboardAccess(); + + Clipboard cb = Toolkit.getDefaultToolkit().getSystemSelection(); + if (cb != null) + { + StringSelection selection = new StringSelection( + textComponent.getSelectedText()); + cb.setContents(selection, selection); + } + } + catch (SecurityException se) + { + // Not allowed to access the clipboard: Ignore and + // do not access it. + } + catch (HeadlessException he) + { + // There is no AWT: Ignore and do not access the + // clipboard. + } + catch (IllegalStateException ise) + { + // Clipboard is currently unavaible. + } + } + } + } + /** + * This FocusListener triggers repaints on focus shift. + */ + private static FocusListener focusListener; + + /** + * Receives notifications when properties of the text component change. + */ + private class Handler + implements PropertyChangeListener, DocumentListener + { + /** + * Notifies when a property of the text component changes. + * + * @param event the PropertyChangeEvent describing the change + */ + public void propertyChange(PropertyChangeEvent event) + { + if (event.getPropertyName().equals("document")) + { + // Document changed. + Object oldValue = event.getOldValue(); + if (oldValue != null) + { + Document oldDoc = (Document) oldValue; + oldDoc.removeDocumentListener(handler); + } + Object newValue = event.getNewValue(); + if (newValue != null) + { + Document newDoc = (Document) newValue; + newDoc.addDocumentListener(handler); + } + modelChanged(); + } + + BasicTextUI.this.propertyChange(event); + } + + /** + * Notification about a document change event. + * + * @param ev the DocumentEvent describing the change + */ + public void changedUpdate(DocumentEvent ev) + { + // Updates are forwarded to the View even if 'getVisibleEditorRect' + // method returns null. This means the View classes have to be + // aware of that possibility. + rootView.changedUpdate(ev, getVisibleEditorRect(), + rootView.getViewFactory()); + } + + /** + * Notification about a document insert event. + * + * @param ev the DocumentEvent describing the insertion + */ + public void insertUpdate(DocumentEvent ev) + { + // Updates are forwarded to the View even if 'getVisibleEditorRect' + // method returns null. This means the View classes have to be + // aware of that possibility. + rootView.insertUpdate(ev, getVisibleEditorRect(), + rootView.getViewFactory()); + } + + /** + * Notification about a document removal event. + * + * @param ev the DocumentEvent describing the removal + */ + public void removeUpdate(DocumentEvent ev) + { + // Updates are forwarded to the View even if 'getVisibleEditorRect' + // method returns null. This means the View classes have to be + // aware of that possibility. + rootView.removeUpdate(ev, getVisibleEditorRect(), + rootView.getViewFactory()); + } + + } + + /** * This view forms the root of the View hierarchy. However, it delegates * most calls to another View which is the real root of the hierarchy. * The purpose is to make sure that all Views in the hierarchy, including @@ -227,24 +363,13 @@ } /** - * Returns the preferred span along the specified <code>axis</code>. - * This is delegated to the real root view. - * - * @param axis the axis for which the preferred span is queried - * - * @return the preferred span along the axis + * Sets the size of the renderer. This is synchronized because that + * potentially triggers layout and we don't want more than one thread + * playing with the layout information. */ - public float getPreferredSpan(int axis) + public synchronized void setSize(float w, float h) { if (view != null) - return view.getPreferredSpan(axis); - - return Integer.MAX_VALUE; - } - - public void setSize(float w, float h) - { - if (view != null) view.setSize(w, h); } @@ -258,8 +383,8 @@ { if (view != null) { - Rectangle b = s.getBounds(); - view.setSize(b.width, b.height); + Rectangle b = s instanceof Rectangle ? (Rectangle) s : s.getBounds(); + setSize(b.width, b.height); view.paint(g, s); } } @@ -319,6 +444,7 @@ */ public void insertUpdate(DocumentEvent ev, Shape shape, ViewFactory vf) { + if (view != null) view.insertUpdate(ev, shape, vf); } @@ -332,6 +458,7 @@ */ public void removeUpdate(DocumentEvent ev, Shape shape, ViewFactory vf) { + if (view != null) view.removeUpdate(ev, shape, vf); } @@ -345,6 +472,7 @@ */ public void changedUpdate(DocumentEvent ev, Shape shape, ViewFactory vf) { + if (view != null) view.changedUpdate(ev, shape, vf); } @@ -415,103 +543,60 @@ { return null; } - } /** - * Receives notifications when properties of the text component change. - */ - private class PropertyChangeHandler implements PropertyChangeListener - { - /** - * Notifies when a property of the text component changes. - * - * @param event the PropertyChangeEvent describing the change + * Overridden to forward to the view. */ - public void propertyChange(PropertyChangeEvent event) - { - if (event.getPropertyName().equals("document")) - { - // Document changed. - Object oldValue = event.getOldValue(); - if (oldValue != null) + public float getPreferredSpan(int axis) { - Document oldDoc = (Document) oldValue; - oldDoc.removeDocumentListener(documentHandler); - } - Object newValue = event.getNewValue(); - if (newValue != null) - { - Document newDoc = (Document) newValue; - newDoc.addDocumentListener(documentHandler); - } - modelChanged(); - } - - BasicTextUI.this.propertyChange(event); - } + // The RI returns 10 in the degenerate case. + float span = 10; + if (view != null) + span = view.getPreferredSpan(axis); + return span; } /** - * Listens for changes on the underlying model and forwards notifications - * to the View. This also updates the caret position of the text component. - * - * TODO: Maybe this should somehow be handled through EditorKits + * Overridden to forward to the real view. */ - class DocumentHandler implements DocumentListener - { - /** - * Notification about a document change event. - * - * @param ev the DocumentEvent describing the change - */ - public void changedUpdate(DocumentEvent ev) + public float getMinimumSpan(int axis) { - // Updates are forwarded to the View even if 'getVisibleEditorRect' - // method returns null. This means the View classes have to be - // aware of that possibility. - rootView.changedUpdate(ev, getVisibleEditorRect(), - rootView.getViewFactory()); + // The RI returns 10 in the degenerate case. + float span = 10; + if (view != null) + span = view.getMinimumSpan(axis); + return span; } /** - * Notification about a document insert event. - * - * @param ev the DocumentEvent describing the insertion + * Overridden to return Integer.MAX_VALUE. */ - public void insertUpdate(DocumentEvent ev) + public float getMaximumSpan(int axis) { - // Updates are forwarded to the View even if 'getVisibleEditorRect' - // method returns null. This means the View classes have to be - // aware of that possibility. - rootView.insertUpdate(ev, getVisibleEditorRect(), - rootView.getViewFactory()); + // The RI returns Integer.MAX_VALUE here, regardless of the real view's + // maximum size. + return Integer.MAX_VALUE; } + } /** - * Notification about a document removal event. - * - * @param ev the DocumentEvent describing the removal + * The EditorKit used by this TextUI. */ - public void removeUpdate(DocumentEvent ev) - { - // Updates are forwarded to the View even if 'getVisibleEditorRect' - // method returns null. This means the View classes have to be - // aware of that possibility. - rootView.removeUpdate(ev, getVisibleEditorRect(), - rootView.getViewFactory()); - } - } + private static EditorKit kit; /** - * The EditorKit used by this TextUI. + * The combined event handler for text components. + * + * This is package private to avoid accessor methods. */ - // FIXME: should probably be non-static. - static EditorKit kit = new DefaultEditorKit(); + Handler handler; /** * The root view. + * + * This is package private to avoid accessor methods. */ - RootView rootView = new RootView(); + RootView rootView; /** * The text component that we handle. @@ -519,14 +604,6 @@ JTextComponent textComponent; /** - * Receives notification when the model changes. - */ - private PropertyChangeHandler updateHandler = new PropertyChangeHandler(); - - /** The DocumentEvent handler. */ - DocumentHandler documentHandler = new DocumentHandler(); - - /** * Creates a new <code>BasicTextUI</code> instance. */ public BasicTextUI() @@ -573,17 +650,31 @@ public void installUI(final JComponent c) { textComponent = (JTextComponent) c; + + if (rootView == null) + rootView = new RootView(); + installDefaults(); - textComponent.addPropertyChangeListener(updateHandler); + installFixedDefaults(); + + // These listeners must be installed outside of installListeners(), + // because overriding installListeners() doesn't prevent installing + // these in the RI, but overriding isntallUI() does. + if (handler == null) + handler = new Handler(); + textComponent.addPropertyChangeListener(handler); Document doc = textComponent.getDocument(); if (doc == null) { + // The Handler takes care of installing the necessary listeners + // on the document here. doc = getEditorKit(textComponent).createDefaultDocument(); textComponent.setDocument(doc); } else { - doc.addDocumentListener(documentHandler); + // Must install the document listener. + doc.addDocumentListener(handler); modelChanged(); } @@ -601,7 +692,6 @@ LookAndFeel.installColorsAndFont(textComponent, prefix + ".background", prefix + ".foreground", prefix + ".font"); LookAndFeel.installBorder(textComponent, prefix + ".border"); - textComponent.setMargin(UIManager.getInsets(prefix + ".margin")); // Some additional text component only properties. Color color = textComponent.getCaretColor(); @@ -615,7 +705,7 @@ color = textComponent.getDisabledTextColor(); if (color == null || color instanceof UIResource) { - color = UIManager.getColor(prefix + ".inactiveBackground"); + color = UIManager.getColor(prefix + ".inactiveForeground"); textComponent.setDisabledTextColor(color); } color = textComponent.getSelectedTextColor(); @@ -638,6 +728,15 @@ textComponent.setMargin(margin); } + } + + /** + * Installs defaults that can't be overridden by overriding + * installDefaults(). + */ + private void installFixedDefaults() + { + String prefix = getPropertyPrefix(); Caret caret = textComponent.getCaret(); if (caret == null || caret instanceof UIResource) { @@ -653,64 +752,18 @@ } /** - * This FocusListener triggers repaints on focus shift. - */ - private FocusListener focuslistener = new FocusListener() { - public void focusGained(FocusEvent e) - { - textComponent.repaint(); - } - public void focusLost(FocusEvent e) - { - textComponent.repaint(); - - // Integrates Swing text components with the system clipboard: - // The idea is that if one wants to copy text around X11-style - // (select text and middle-click in the target component) the focus - // will move to the new component which gives the old focus owner the - // possibility to paste its selection into the clipboard. - if (!e.isTemporary() - && textComponent.getSelectionStart() - != textComponent.getSelectionEnd()) - { - SecurityManager sm = System.getSecurityManager(); - try - { - if (sm != null) - sm.checkSystemClipboardAccess(); - - Clipboard cb = Toolkit.getDefaultToolkit().getSystemSelection(); - if (cb != null) - { - StringSelection selection = new StringSelection( - textComponent.getSelectedText()); - cb.setContents(selection, selection); - } - } - catch (SecurityException se) - { - // Not allowed to access the clipboard: Ignore and - // do not access it. - } - catch (HeadlessException he) - { - // There is no AWT: Ignore and do not access the - // clipboard. - } - catch (IllegalStateException ise) - { - // Clipboard is currently unavaible. - } - } - } - }; - - /** * Install all listeners on the text component. */ protected void installListeners() { - textComponent.addFocusListener(focuslistener); + // + if (SystemProperties.getProperty("gnu.swing.text.no-xlike-clipboard") + == null) + { + if (focusListener == null) + focusListener = new FocusHandler(); + textComponent.addFocusListener(focusListener); + } } /** @@ -849,10 +902,12 @@ */ public void uninstallUI(final JComponent component) { - super.uninstallUI(component); + textComponent.removePropertyChangeListener(handler); + textComponent.getDocument().removeDocumentListener(handler); rootView.setView(null); uninstallDefaults(); + uninstallFixedDefaults(); uninstallListeners(); uninstallKeyboardActions(); @@ -865,17 +920,41 @@ */ protected void uninstallDefaults() { - // Do nothing here. + if (textComponent.getCaretColor() instanceof UIResource) + textComponent.setCaretColor(null); + if (textComponent.getSelectionColor() instanceof UIResource) + textComponent.setSelectionColor(null); + if (textComponent.getDisabledTextColor() instanceof UIResource) + textComponent.setDisabledTextColor(null); + if (textComponent.getSelectedTextColor() instanceof UIResource) + textComponent.setSelectedTextColor(null); + LookAndFeel.uninstallBorder(textComponent); + if (textComponent.getMargin() instanceof UIResource) + textComponent.setMargin(null); } /** + * Uninstalls additional fixed defaults that were installed + * by installFixedDefaults(). + */ + private void uninstallFixedDefaults() + { + if (textComponent.getCaret() instanceof UIResource) + textComponent.setCaret(null); + if (textComponent.getHighlighter() instanceof UIResource) + textComponent.setHighlighter(null); + } + + /** * Uninstalls all listeners that have previously been installed by * this UI. */ protected void uninstallListeners() { - textComponent.removeFocusListener(focuslistener); - textComponent.getDocument().removeDocumentListener(documentHandler); + // Don't nullify the focusListener field, as it is static and shared + // between components. + if (focusListener != null) + textComponent.removeFocusListener(focusListener); } /** @@ -909,14 +988,33 @@ { Dimension d = c.getSize(); Insets i = c.getInsets(); + // We need to lock here, since we require the view hierarchy to _not_ + // change in between. + float w; + float h; + Document doc = textComponent.getDocument(); + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { if (d.width > (i.left + i.right) && d.height > (i.top + i.bottom)) { rootView.setSize(d.width - i.left - i.right, d.height - i.top - i.bottom); } - float w = rootView.getPreferredSpan(View.X_AXIS); - float h = rootView.getPreferredSpan(View.Y_AXIS); - + else + { + // Not laid out yet. Force some pseudo size. + rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE); + } + w = rootView.getPreferredSpan(View.X_AXIS); + h = rootView.getPreferredSpan(View.Y_AXIS); + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } Dimension size = new Dimension((int) w + i.left + i.right, (int) h + i.top + i.bottom); return size; @@ -933,8 +1031,27 @@ */ public Dimension getMaximumSize(JComponent c) { - // Sun's implementation returns Integer.MAX_VALUE here, so do we. - return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); + Dimension d = new Dimension(); + Insets i = c.getInsets(); + Document doc = textComponent.getDocument(); + // We need to lock here, since we require the view hierarchy to _not_ + // change in between. + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { + // Check for overflow here. + d.width = (int) Math.min((long) rootView.getMaximumSpan(View.X_AXIS) + + i.left + i.right, Integer.MAX_VALUE); + d.height = (int) Math.min((long) rootView.getMaximumSpan(View.Y_AXIS) + + i.top + i.bottom, Integer.MAX_VALUE); + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } + return d; } /** @@ -945,8 +1062,26 @@ */ public Dimension getMinimumSize(JComponent c) { + Dimension d = new Dimension(); + Document doc = textComponent.getDocument(); + // We need to lock here, since we require the view hierarchy to _not_ + // change in between. + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { + d.width = (int) rootView.getMinimumSpan(View.X_AXIS); + d.height = (int) rootView.getMinimumSpan(View.Y_AXIS); + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } Insets i = c.getInsets(); - return new Dimension(i.left + i.right, i.top + i.bottom); + d.width += i.left + i.right; + d.height += i.top + i.bottom; + return d; } /** @@ -967,7 +1102,6 @@ AbstractDocument aDoc = (AbstractDocument) doc; aDoc.readLock(); } - paintSafely(g); } finally @@ -1017,7 +1151,6 @@ g.setColor(oldColor); } - rootView.paint(g, getVisibleEditorRect()); if (caret != null && textComponent.hasFocus()) @@ -1125,6 +1258,8 @@ */ public EditorKit getEditorKit(JTextComponent t) { + if (kit == null) + kit = new DefaultEditorKit(); return kit; } @@ -1147,13 +1282,27 @@ Position.Bias[] biasRet) throws BadLocationException { - // A comment in the spec of NavigationFilter.getNextVisualPositionFrom() - // suggests that this method should be implemented by forwarding the call - // the root view. - return rootView.getNextVisualPositionFrom(pos, b, - getVisibleEditorRect(), + int offset = -1; + Document doc = textComponent.getDocument(); + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { + Rectangle alloc = getVisibleEditorRect(); + if (alloc != null) + { + rootView.setSize(alloc.width, alloc.height); + offset = rootView.getNextVisualPositionFrom(pos, b, alloc, direction, biasRet); } + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } + return offset; + } /** * Returns the root {@link View} of a text component. @@ -1262,7 +1411,25 @@ */ public int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn) { - return rootView.viewToModel(pt.x, pt.y, getVisibleEditorRect(), biasReturn); + int offset = -1; + Document doc = textComponent.getDocument(); + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); + try + { + Rectangle alloc = getVisibleEditorRect(); + if (alloc != null) + { + rootView.setSize(alloc.width, alloc.height); + offset = rootView.viewToModel(pt.x, pt.y, alloc, biasReturn); + } + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } + return offset; } /** @@ -1294,6 +1461,11 @@ } /** + * A cached Insets instance to be reused below. + */ + private Insets cachedInsets; + + /** * Returns the allocation to give the root view. * * @return the allocation to give the root view @@ -1311,7 +1483,7 @@ if (width <= 0 || height <= 0) return null; - Insets insets = textComponent.getInsets(); + Insets insets = textComponent.getInsets(cachedInsets); return new Rectangle(insets.left, insets.top, width - insets.left - insets.right, height - insets.top - insets.bottom); @@ -1362,4 +1534,5 @@ { // The default implementation does nothing. } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-09 18:47:16
|
Revision: 2882 http://jnode.svn.sourceforge.net/jnode/?rev=2882&view=rev Author: lsantha Date: 2006-12-09 10:47:15 -0800 (Sat, 09 Dec 2006) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/javax/javax/swing/text/AbstractDocument.java trunk/core/src/classpath/javax/javax/swing/text/BoxView.java trunk/core/src/classpath/javax/javax/swing/text/ComponentView.java trunk/core/src/classpath/javax/javax/swing/text/CompositeView.java trunk/core/src/classpath/javax/javax/swing/text/DefaultCaret.java trunk/core/src/classpath/javax/javax/swing/text/DefaultEditorKit.java trunk/core/src/classpath/javax/javax/swing/text/DefaultFormatter.java trunk/core/src/classpath/javax/javax/swing/text/DefaultStyledDocument.java trunk/core/src/classpath/javax/javax/swing/text/ElementIterator.java trunk/core/src/classpath/javax/javax/swing/text/FieldView.java trunk/core/src/classpath/javax/javax/swing/text/FlowView.java trunk/core/src/classpath/javax/javax/swing/text/GapContent.java trunk/core/src/classpath/javax/javax/swing/text/GlyphView.java trunk/core/src/classpath/javax/javax/swing/text/InternationalFormatter.java trunk/core/src/classpath/javax/javax/swing/text/MaskFormatter.java trunk/core/src/classpath/javax/javax/swing/text/ParagraphView.java trunk/core/src/classpath/javax/javax/swing/text/Position.java trunk/core/src/classpath/javax/javax/swing/text/StringContent.java trunk/core/src/classpath/javax/javax/swing/text/StyleConstants.java trunk/core/src/classpath/javax/javax/swing/text/StyleContext.java trunk/core/src/classpath/javax/javax/swing/text/TextAction.java trunk/core/src/classpath/javax/javax/swing/text/Utilities.java trunk/core/src/classpath/javax/javax/swing/text/View.java trunk/core/src/classpath/javax/javax/swing/text/WrappedPlainView.java Modified: trunk/core/src/classpath/javax/javax/swing/text/AbstractDocument.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/AbstractDocument.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/AbstractDocument.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -46,6 +46,7 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.EventListener; +import java.util.HashMap; import java.util.Hashtable; import java.util.Vector; @@ -158,15 +159,11 @@ private int numReaders = 0; /** - * Tells if there are one or more writers waiting. + * The number of current writers. If this is > 1 then the same thread entered + * the write lock more than once. */ - private int numWritersWaiting = 0; + private int numWriters = 0; - /** - * A condition variable that readers and writers wait on. - */ - private Object documentCV = new Object(); - /** An instance of a DocumentFilter.FilterBypass which allows calling * the insert, remove and replace method without checking for an installed * document filter. @@ -179,6 +176,12 @@ private BidiRootElement bidiRoot; /** + * True when we are currently notifying any listeners. This is used + * to detect illegal situations in writeLock(). + */ + private transient boolean notifyListeners; + + /** * Creates a new <code>AbstractDocument</code> with the specified * {@link Content} model. * @@ -315,7 +318,8 @@ * @throws BadLocationException if <code>offset</code> is not a valid * location in the documents content model */ - public Position createPosition(final int offset) throws BadLocationException + public synchronized Position createPosition(final int offset) + throws BadLocationException { return content.createPosition(offset); } @@ -327,11 +331,18 @@ */ protected void fireChangedUpdate(DocumentEvent event) { + notifyListeners = true; + try + { DocumentListener[] listeners = getDocumentListeners(); - for (int index = 0; index < listeners.length; ++index) listeners[index].changedUpdate(event); } + finally + { + notifyListeners = false; + } + } /** * Notifies all registered listeners when content is inserted in the document @@ -341,11 +352,18 @@ */ protected void fireInsertUpdate(DocumentEvent event) { + notifyListeners = true; + try + { DocumentListener[] listeners = getDocumentListeners(); - for (int index = 0; index < listeners.length; ++index) listeners[index].insertUpdate(event); } + finally + { + notifyListeners = false; + } + } /** * Notifies all registered listeners when content is removed from the @@ -355,11 +373,18 @@ */ protected void fireRemoveUpdate(DocumentEvent event) { + notifyListeners = true; + try + { DocumentListener[] listeners = getDocumentListeners(); - for (int index = 0; index < listeners.length; ++index) listeners[index].removeUpdate(event); } + finally + { + notifyListeners = false; + } + } /** * Notifies all registered listeners when an <code>UndoableEdit</code> has @@ -432,7 +457,7 @@ * @return the thread that currently modifies this <code>Document</code> * if there is one, otherwise <code>null</code> */ - protected final Thread getCurrentWriter() + protected final synchronized Thread getCurrentWriter() { return currentWriter; } @@ -1022,33 +1047,29 @@ * Blocks until a read lock can be obtained. Must block if there is * currently a writer modifying the <code>Document</code>. */ - public final void readLock() + public final synchronized void readLock() { - if (currentWriter != null && currentWriter.equals(Thread.currentThread())) - return; - synchronized (documentCV) - { - while (currentWriter != null || numWritersWaiting > 0) - { - try { - documentCV.wait(); - } - catch (InterruptedException ie) + while (currentWriter != null) { - throw new Error("interrupted trying to get a readLock"); - } + if (currentWriter == Thread.currentThread()) + return; + wait(); } numReaders++; } + catch (InterruptedException ex) + { + throw new Error("Interrupted during grab read lock"); + } } /** * Releases the read lock. If this was the only reader on this * <code>Document</code>, writing may begin now. */ - public final void readUnlock() + public final synchronized void readUnlock() { // Note we could have a problem here if readUnlock was called without a // prior call to readLock but the specs simply warn users to ensure that @@ -1075,21 +1096,14 @@ // FIXME: the reference implementation throws a // javax.swing.text.StateInvariantError here - if (numReaders == 0) + if (numReaders <= 0) throw new IllegalStateException("document lock failure"); - synchronized (documentCV) - { // If currentWriter is not null, the application code probably had a // writeLock and then tried to obtain a readLock, in which case // numReaders wasn't incremented - if (currentWriter == null) - { - numReaders --; - if (numReaders == 0 && numWritersWaiting != 0) - documentCV.notify(); - } - } + numReaders--; + notify(); } /** @@ -1113,10 +1127,19 @@ */ public void remove(int offset, int length) throws BadLocationException { - if (documentFilter == null) + writeLock(); + try + { + DocumentFilter f = getDocumentFilter(); + if (f == null) removeImpl(offset, length); else - documentFilter.remove(getBypass(), offset, length); + f.remove(getBypass(), offset, length); + } + finally + { + writeUnlock(); + } } void removeImpl(int offset, int length) throws BadLocationException @@ -1135,10 +1158,6 @@ new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.REMOVE); - try - { - writeLock(); - // The order of the operations below is critical! removeUpdate(event); UndoableEdit temp = content.remove(offset, length); @@ -1146,12 +1165,7 @@ postRemoveUpdate(event); fireRemoveUpdate(event); } - finally - { - writeUnlock(); - } } - } /** * Replaces a piece of content in this <code>Document</code> with @@ -1343,42 +1357,41 @@ * Blocks until a write lock can be obtained. Must wait if there are * readers currently reading or another thread is currently writing. */ - protected final void writeLock() - { - if (currentWriter != null && currentWriter.equals(Thread.currentThread())) - return; - synchronized (documentCV) - { - numWritersWaiting++; - while (numReaders > 0) + protected synchronized final void writeLock() { try { - documentCV.wait(); - } - catch (InterruptedException ie) + while (numReaders > 0 || currentWriter != null) + { + if (Thread.currentThread() == currentWriter) { - throw new Error("interruped while trying to obtain write lock"); + if (notifyListeners) + throw new IllegalStateException("Mutation during notify"); + numWriters++; + return; } + wait(); } - numWritersWaiting --; currentWriter = Thread.currentThread(); + numWriters = 1; } + catch (InterruptedException ex) + { + throw new Error("Interupted during grab write lock"); + } } /** * Releases the write lock. This allows waiting readers or writers to * obtain the lock. */ - protected final void writeUnlock() + protected final synchronized void writeUnlock() { - synchronized (documentCV) - { - if (Thread.currentThread().equals(currentWriter)) + if (--numWriters <= 0) { + numWriters = 0; currentWriter = null; - documentCV.notifyAll(); - } + notifyAll(); } } @@ -2384,6 +2397,11 @@ /** The serialization UID (compatible with JDK1.5). */ private static final long serialVersionUID = 5230037221564563284L; + /** + * The threshold that indicates when we switch to using a Hashtable. + */ + private static final int THRESHOLD = 10; + /** The starting offset of the change. */ private int offset; @@ -2394,15 +2412,18 @@ private DocumentEvent.EventType type; /** - * Maps <code>Element</code> to their change records. + * Maps <code>Element</code> to their change records. This is only + * used when the changes array gets too big. We can use an + * (unsync'ed) HashMap here, since changes to this are (should) always + * be performed inside a write lock. */ - Hashtable changes; + private HashMap changes; /** * Indicates if this event has been modified or not. This is used to * determine if this event is thrown. */ - boolean modified; + private boolean modified; /** * Creates a new <code>DefaultDocumentEvent</code>. @@ -2417,7 +2438,6 @@ this.offset = offset; this.length = length; this.type = type; - changes = new Hashtable(); modified = false; } @@ -2431,9 +2451,27 @@ public boolean addEdit(UndoableEdit edit) { // XXX - Fully qualify ElementChange to work around gcj bug #2499. - if (edit instanceof DocumentEvent.ElementChange) + + // Start using Hashtable when we pass a certain threshold. This + // gives a good memory/performance compromise. + if (changes == null && edits.size() > THRESHOLD) { - modified = true; + changes = new HashMap(); + int count = edits.size(); + for (int i = 0; i < count; i++) + { + Object o = edits.elementAt(i); + if (o instanceof DocumentEvent.ElementChange) + { + DocumentEvent.ElementChange ec = + (DocumentEvent.ElementChange) o; + changes.put(ec.getElement(), ec); + } + } + } + + if (changes != null && edit instanceof DocumentEvent.ElementChange) + { DocumentEvent.ElementChange elEdit = (DocumentEvent.ElementChange) edit; changes.put(elEdit.getElement(), elEdit); @@ -2492,7 +2530,27 @@ public DocumentEvent.ElementChange getChange(Element elem) { // XXX - Fully qualify ElementChange to work around gcj bug #2499. - return (DocumentEvent.ElementChange) changes.get(elem); + DocumentEvent.ElementChange change = null; + if (changes != null) + { + change = (DocumentEvent.ElementChange) changes.get(elem); + } + else + { + int count = edits.size(); + for (int i = 0; i < count && change == null; i++) + { + Object o = edits.get(i); + if (o instanceof DocumentEvent.ElementChange) + { + DocumentEvent.ElementChange ec = + (DocumentEvent.ElementChange) o; + if (elem.equals(ec.getElement())) + change = ec; + } + } + } + return change; } /** Modified: trunk/core/src/classpath/javax/javax/swing/text/BoxView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/BoxView.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/BoxView.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -38,6 +38,7 @@ package javax.swing.text; +import java.awt.Container; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; @@ -105,6 +106,8 @@ myAxis = axis; layoutValid[0] = false; layoutValid[1] = false; + requirementsValid[X_AXIS] = false; + requirementsValid[Y_AXIS] = false; span[0] = 0; span[1] = 0; requirements[0] = new SizeRequirements(); @@ -141,7 +144,10 @@ */ public void setAxis(int axis) { + boolean changed = axis != myAxis; myAxis = axis; + if (changed) + preferenceChanged(null, true, true); } /** @@ -222,55 +228,48 @@ */ public void replace(int offset, int length, View[] views) { - int numViews = 0; - if (views != null) - numViews = views.length; + // Actually perform the replace. + super.replace(offset, length, views); // Resize and copy data for cache arrays. - // The spansX cache. - int oldSize = getViewCount(); + int newItems = views != null ? views.length : 0; + int minor = 1 - myAxis; + offsets[myAxis] = replaceLayoutArray(offsets[myAxis], offset, newItems); + spans[myAxis] = replaceLayoutArray(spans[myAxis], offset, newItems); + layoutValid[myAxis] = false; + requirementsValid[myAxis] = false; + offsets[minor] = replaceLayoutArray(offsets[minor], offset, newItems); + spans[minor] = replaceLayoutArray(spans[minor], offset, newItems); + layoutValid[minor] = false; + requirementsValid[minor] = false; + } - int[] newSpansX = new int[oldSize - length + numViews]; - System.arraycopy(spans[X_AXIS], 0, newSpansX, 0, offset); - System.arraycopy(spans[X_AXIS], offset + length, newSpansX, - offset + numViews, - oldSize - (offset + length)); - spans[X_AXIS] = newSpansX; + /** + * Helper method. This updates the layout cache arrays in response + * to a call to {@link #replace(int, int, View[])}. + * + * @param oldArray the old array + * + * @return the replaced array + */ + private int[] replaceLayoutArray(int[] oldArray, int offset, int newItems) - // The spansY cache. - int[] newSpansY = new int[oldSize - length + numViews]; - System.arraycopy(spans[Y_AXIS], 0, newSpansY, 0, offset); - System.arraycopy(spans[Y_AXIS], offset + length, newSpansY, - offset + numViews, - oldSize - (offset + length)); - spans[Y_AXIS] = newSpansY; + { + int num = getViewCount(); + int[] newArray = new int[num]; + System.arraycopy(oldArray, 0, newArray, 0, offset); + System.arraycopy(oldArray, offset, newArray, offset + newItems, + num - newItems - offset); + return newArray; + } - // The offsetsX cache. - int[] newOffsetsX = new int[oldSize - length + numViews]; - System.arraycopy(offsets[X_AXIS], 0, newOffsetsX, 0, offset); - System.arraycopy(offsets[X_AXIS], offset + length, newOffsetsX, - offset + numViews, - oldSize - (offset + length)); - offsets[X_AXIS] = newOffsetsX; + /** + * A Rectangle instance to be reused in the paint() method below. + */ + private final Rectangle tmpRect = new Rectangle(); - // The offsetsY cache. - int[] newOffsetsY = new int[oldSize - length + numViews]; - System.arraycopy(offsets[Y_AXIS], 0, newOffsetsY, 0, offset); - System.arraycopy(offsets[Y_AXIS], offset + length, newOffsetsY, - offset + numViews, - oldSize - (offset + length)); - offsets[Y_AXIS] = newOffsetsY; + private Rectangle clipRect = new Rectangle(); - // Actually perform the replace. - super.replace(offset, length, views); - - // Invalidate layout information. - layoutValid[X_AXIS] = false; - requirementsValid[X_AXIS] = false; - layoutValid[Y_AXIS] = false; - requirementsValid[Y_AXIS] = false; - } - /** * Renders the <code>Element</code> that is associated with this * <code>View</code>. @@ -280,26 +279,20 @@ */ public void paint(Graphics g, Shape a) { - Rectangle alloc; - if (a instanceof Rectangle) - alloc = (Rectangle) a; - else - alloc = a.getBounds(); + // Try to avoid allocation if possible (almost all cases). + Rectangle alloc = a instanceof Rectangle ? (Rectangle) a : a.getBounds(); - int x = alloc.x + getLeftInset(); - int y = alloc.y + getTopInset(); + // This returns a cached instance. + alloc = getInsideAllocation(alloc); - Rectangle clip = g.getClipBounds(); - Rectangle tmp = new Rectangle(); int count = getViewCount(); - for (int i = 0; i < count; ++i) + for (int i = 0; i < count; i++) { - tmp.x = x + getOffset(X_AXIS, i); - tmp.y = y + getOffset(Y_AXIS, i); - tmp.width = getSpan(X_AXIS, i); - tmp.height = getSpan(Y_AXIS, i); - if (tmp.intersects(clip)) - paintChild(g, tmp, i); + View child = getView(i); + tmpRect.setBounds(alloc); + childAllocation(i, tmpRect); + if (g.hitClip(tmpRect.x, tmpRect.y, tmpRect.width, tmpRect.height)) + paintChild(g, tmpRect, i); } } @@ -571,7 +564,7 @@ res.minimum = 0; res.preferred = 0; - res.maximum = 0; + res.maximum = Integer.MAX_VALUE; res.alignment = 0.5F; int n = getViewCount(); for (int i = 0; i < n; i++) @@ -651,24 +644,54 @@ { View result = null; int count = getViewCount(); - Rectangle copy = new Rectangle(r); - - for (int i = 0; i < count; ++i) + if (myAxis == X_AXIS) { - copy.setBounds(r); - // The next call modifies copy. - childAllocation(i, copy); - if (copy.contains(x, y)) + // Border case. Requested point is left from the box. + if (x < r.x + offsets[X_AXIS][0]) { - // Modify r on success. - r.setBounds(copy); - result = getView(i); - break; + childAllocation(0, r); + result = getView(0); } + else + { + // Search views inside box. + for (int i = 0; i < count && result == null; i++) + { + if (x < r.x + offsets[X_AXIS][i]) + { + childAllocation(i - 1, r); + result = getView(i - 1); + } } - - if (result == null && count > 0) - return getView(count - 1); + } + } + else // Same algorithm for Y_AXIS. + { + // Border case. Requested point is above the box. + if (y < r.y + offsets[Y_AXIS][0]) + { + childAllocation(0, r); + result = getView(0); + } + else + { + // Search views inside box. + for (int i = 0; i < count && result == null; i++) + { + if (y < r.y + offsets[Y_AXIS][i]) + { + childAllocation(i - 1, r); + result = getView(i - 1); + } + } + } + } + // Not found, other border case: point is right from or below the box. + if (result == null) + { + childAllocation(count - 1, r); + result = getView(count - 1); + } return result; } @@ -702,49 +725,32 @@ */ protected void layout(int width, int height) { - int[] newSpan = new int[]{ width, height }; - int count = getViewCount(); - - // Update minor axis as appropriate. We need to first update the minor - // axis layout because that might affect the children's preferences along - // the major axis. - int minorAxis = myAxis == X_AXIS ? Y_AXIS : X_AXIS; - if ((! isLayoutValid(minorAxis)) || newSpan[minorAxis] != span[minorAxis]) - { - layoutValid[minorAxis] = false; - span[minorAxis] = newSpan[minorAxis]; - layoutMinorAxis(span[minorAxis], minorAxis, offsets[minorAxis], - spans[minorAxis]); - - // Update the child view's sizes. - for (int i = 0; i < count; ++i) - { - getView(i).setSize(spans[X_AXIS][i], spans[Y_AXIS][i]); + layoutAxis(X_AXIS, width); + layoutAxis(Y_AXIS, height); } - layoutValid[minorAxis] = true; - } - - // Update major axis as appropriate. - if ((! isLayoutValid(myAxis)) || newSpan[myAxis] != span[myAxis]) + private void layoutAxis(int axis, int s) { - layoutValid[myAxis] = false; - span[myAxis] = newSpan[myAxis]; - layoutMajorAxis(span[myAxis], myAxis, offsets[myAxis], - spans[myAxis]); + if (span[axis] != s) + layoutValid[axis] = false; + if (! layoutValid[axis]) + { + span[axis] = s; + updateRequirements(axis); + if (axis == myAxis) + layoutMajorAxis(span[axis], axis, offsets[axis], spans[axis]); + else + layoutMinorAxis(span[axis], axis, offsets[axis], spans[axis]); + layoutValid[axis] = true; - // Update the child view's sizes. - for (int i = 0; i < count; ++i) + // Push out child layout. + int viewCount = getViewCount(); + for (int i = 0; i < viewCount; i++) { - getView(i).setSize(spans[X_AXIS][i], spans[Y_AXIS][i]); + View v = getView(i); + v.setSize(spans[X_AXIS][i], spans[Y_AXIS][i]); } - layoutValid[myAxis] = true; } - - if (layoutValid[myAxis] == false) - System.err.println("WARNING: Major axis layout must be valid after layout"); - if (layoutValid[minorAxis] == false) - System.err.println("Minor axis layout must be valid after layout"); } /** @@ -767,7 +773,7 @@ { View child = getView(i); spans[i] = (int) child.getPreferredSpan(axis); - sumPref = spans[i]; + sumPref += spans[i]; } // Try to adjust the spans so that we fill the targetSpan. @@ -870,7 +876,9 @@ */ public int getWidth() { - return span[X_AXIS] + getLeftInset() - getRightInset(); + // The RI returns the following here, however, I'd think that is a bug. + // return span[X_AXIS] + getLeftInset() - getRightInset(); + return span[X_AXIS] + getLeftInset() + getRightInset(); } /** @@ -880,7 +888,9 @@ */ public int getHeight() { - return span[Y_AXIS] + getTopInset() - getBottomInset(); + // The RI returns the following here, however, I'd think that is a bug. + // return span[Y_AXIS] + getTopInset() - getBottomInset(); + return span[Y_AXIS] + getTopInset() + getBottomInset(); } /** @@ -1004,9 +1014,11 @@ { if (axis != X_AXIS && axis != Y_AXIS) throw new IllegalArgumentException("Illegal axis argument"); - int weight = 1; - if (axis == myAxis) - weight = 0; + updateRequirements(axis); + int weight = 0; + if ((requirements[axis].preferred != requirements[axis].minimum) + || (requirements[axis].preferred != requirements[axis].maximum)) + weight = 1; return weight; } @@ -1033,13 +1045,39 @@ protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory vf) { - // FIXME: What to do here? + boolean wasValid = isLayoutValid(myAxis); super.forwardUpdate(ec, e, a, vf); + // Trigger repaint when one of the children changed the major axis. + if (wasValid && ! isLayoutValid(myAxis)) + { + Container c = getContainer(); + if (a != null && c != null) + { + int pos = e.getOffset(); + int index = getViewIndexAtPosition(pos); + Rectangle r = getInsideAllocation(a); + if (myAxis == X_AXIS) + { + r.x += offsets[myAxis][index]; + r.width -= offsets[myAxis][index]; + } + else + { + r.y += offsets[myAxis][index]; + r.height -= offsets[myAxis][index]; + } + c.repaint(r.x, r.y, r.width, r.height); + } + } } public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) { - // FIXME: What to do here? + if (! isAllocationValid()) + { + Rectangle r = a instanceof Rectangle ? (Rectangle) a : a.getBounds(); + setSize(r.width, r.height); + } return super.viewToModel(x, y, a, bias); } Modified: trunk/core/src/classpath/javax/javax/swing/text/ComponentView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/ComponentView.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/ComponentView.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -397,7 +397,24 @@ { public void run() { + Document doc = getDocument(); + try + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readLock(); setParentImpl(); + Container host = getContainer(); + if (host != null) + { + preferenceChanged(null, true, true); + host.repaint(); + } + } + finally + { + if (doc instanceof AbstractDocument) + ((AbstractDocument) doc).readUnlock(); + } } }); } Modified: trunk/core/src/classpath/javax/javax/swing/text/CompositeView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/CompositeView.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/CompositeView.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -56,14 +56,19 @@ /** * The child views of this <code>CompositeView</code>. */ - View[] children; + private View[] children; /** + * The number of child views. + */ + private int numChildren; + + /** * The allocation of this <code>View</code> minus its insets. This is * initialized in {@link #getInsideAllocation} and reused and modified in * {@link #childAllocation(int, Rectangle)}. */ - Rectangle insideAllocation; + private final Rectangle insideAllocation = new Rectangle(); /** * The insets of this <code>CompositeView</code>. This is initialized @@ -101,6 +106,8 @@ */ protected void loadChildren(ViewFactory f) { + if (f != null) + { Element el = getElement(); int count = el.getElementCount(); View[] newChildren = new View[count]; @@ -115,6 +122,7 @@ // Harmony's tests this is not what the RI does. replace(0, 0, newChildren); } + } /** * Sets the parent of this <code>View</code>. @@ -126,7 +134,7 @@ public void setParent(View parent) { super.setParent(parent); - if (parent != null && ((children == null) || children.length == 0)) + if (parent != null && numChildren == 0) loadChildren(getViewFactory()); } @@ -137,7 +145,7 @@ */ public int getViewCount() { - return children.length; + return numChildren; } /** @@ -169,27 +177,37 @@ if (views == null) views = new View[0]; - // Check for null views to add. - for (int i = 0; i < views.length; ++i) - if (views[i] == null) - throw new NullPointerException("Added views must not be null"); - + // First we set the parent of the removed children to null. int endOffset = offset + length; - - // First we set the parent of the removed children to null. for (int i = offset; i < endOffset; ++i) { if (children[i].getParent() == this) children[i].setParent(null); + children[i] = null; } - View[] newChildren = new View[children.length - length + views.length]; + // Update the children array. + int delta = views.length - length; + int src = offset + length; + int numMove = numChildren - src; + int dst = src + delta; + if (numChildren + delta > children.length) + { + // Grow array. + int newLength = Math.max(2 * children.length, numChildren + delta); + View[] newChildren = new View[newLength]; System.arraycopy(children, 0, newChildren, 0, offset); System.arraycopy(views, 0, newChildren, offset, views.length); - System.arraycopy(children, offset + length, newChildren, - offset + views.length, - children.length - (offset + length)); + System.arraycopy(children, src, newChildren, dst, numMove); children = newChildren; + } + else + { + // Patch existing array. + System.arraycopy(children, src, children, dst, numMove); + System.arraycopy(views, 0, children, offset, views.length); + } + numChildren += delta; // Finally we set the parent of the added children to this. for (int i = 0; i < views.length; ++i) @@ -264,12 +282,12 @@ } } } - else - { + } + + if (ret == null) throw new BadLocationException("Position " + pos + " is not represented by view.", pos); - } - } + return ret; } @@ -509,24 +527,17 @@ if (a == null) return null; - Rectangle alloc = a.getBounds(); + // Try to avoid allocation of Rectangle here. + Rectangle alloc = a instanceof Rectangle ? (Rectangle) a : a.getBounds(); + // Initialize the inside allocation rectangle. This is done inside // a synchronized block in order to avoid multiple threads creating // this instance simultanously. - Rectangle inside; - synchronized(this) - { - inside = insideAllocation; - if (inside == null) - { - inside = new Rectangle(); - insideAllocation = inside; - } - } - inside.x = alloc.x + left; - inside.y = alloc.y + top; - inside.width = alloc.width - left - right; - inside.height = alloc.height - top - bottom; + Rectangle inside = insideAllocation; + inside.x = alloc.x + getLeftInset(); + inside.y = alloc.y + getTopInset(); + inside.width = alloc.width - getLeftInset() - getRightInset(); + inside.height = alloc.height - getTopInset() - getBottomInset(); return inside; } Modified: trunk/core/src/classpath/javax/javax/swing/text/DefaultCaret.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/DefaultCaret.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/DefaultCaret.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -1075,8 +1075,6 @@ handleHighlight(); appear(); - - adjustVisibility(this); } } @@ -1114,8 +1112,6 @@ clearHighlight(); appear(); - - adjustVisibility(this); } } @@ -1154,8 +1150,13 @@ // e.printStackTrace(); } if (area != null) + { + adjustVisibility(area); + if (getMagicCaretPosition() == null) + setMagicCaretPosition(new Point(area.x, area.y)); damage(area); } + } repaint(); } Modified: trunk/core/src/classpath/javax/javax/swing/text/DefaultEditorKit.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/DefaultEditorKit.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/DefaultEditorKit.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -311,11 +311,12 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { int offs = t.getDocument().getLength(); Caret c = t.getCaret(); c.setDot(0); c.moveDot(offs); - try { c.setMagicCaretPosition(t.modelToView(offs).getLocation()); @@ -326,6 +327,7 @@ } } } + } static class SelectionBeginAction extends TextAction @@ -338,6 +340,8 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { Caret c = t.getCaret(); c.moveDot(0); try @@ -350,6 +354,7 @@ } } } + } static class SelectionEndAction extends TextAction @@ -362,6 +367,8 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { int offs = t.getDocument().getLength(); Caret c = t.getCaret(); c.moveDot(offs); @@ -375,6 +382,7 @@ } } } + } static class SelectionBeginLineAction extends TextAction @@ -388,6 +396,8 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { Caret c = t.getCaret(); try { @@ -398,7 +408,7 @@ { // Can't happen. } - + } } } @@ -413,6 +423,8 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { Caret c = t.getCaret(); try { @@ -423,7 +435,7 @@ { // Can't happen. } - + } } } @@ -437,15 +449,15 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { Caret c = t.getCaret(); try { int offs1 = Utilities.getRowStart(t, c.getDot()); int offs2 = Utilities.getRowEnd(t, c.getDot()); - c.setDot(offs2); c.moveDot(offs1); - c.setMagicCaretPosition(t.modelToView(offs2).getLocation()); } catch(BadLocationException ble) @@ -454,6 +466,7 @@ } } } + } static class SelectWordAction extends TextAction { @@ -465,9 +478,10 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { Caret c = t.getCaret(); int dot = c.getDot(); - try { int wordStart = Utilities.getWordStart(t, dot); @@ -505,7 +519,6 @@ // as well. if (c.getDot() != dot) c.setMagicCaretPosition(t.modelToView(c.getDot()).getLocation()); - } catch(BadLocationException ble) { @@ -513,6 +526,7 @@ } } } + } static class SelectionDownAction extends TextAction.VerticalMovementAction @@ -714,10 +728,11 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { try { int offs = Utilities.getRowEnd(t, t.getCaretPosition()); - if (offs > -1) { Caret c = t.getCaret(); @@ -731,6 +746,7 @@ } } } + } static class BeginLineAction extends TextAction @@ -743,10 +759,11 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { try { int offs = Utilities.getRowStart(t, t.getCaretPosition()); - if (offs > -1) { Caret c = t.getCaret(); @@ -760,6 +777,7 @@ } } } + } static class BeginAction extends TextAction { @@ -772,6 +790,8 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { Caret c = t.getCaret(); c.setDot(0); try @@ -784,6 +804,7 @@ } } } + } static class EndAction extends TextAction { @@ -796,6 +817,8 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) + { int offs = t.getDocument().getLength(); Caret c = t.getCaret(); c.setDot(offs); @@ -809,6 +832,7 @@ } } } + } /** * Creates a beep on the PC speaker. @@ -861,7 +885,9 @@ */ public void actionPerformed(ActionEvent event) { - getTextComponent(event).copy(); + JTextComponent target = getTextComponent(event); + if (target != null) + target.copy(); } } @@ -892,7 +918,9 @@ */ public void actionPerformed(ActionEvent event) { - getTextComponent(event).cut(); + JTextComponent target = getTextComponent(event); + if (target != null) + target.cut(); } } @@ -921,7 +949,9 @@ */ public void actionPerformed(ActionEvent event) { - getTextComponent(event).paste(); + JTextComponent target = getTextComponent(event); + if (target != null) + target.paste(); } } @@ -1003,6 +1033,7 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) t.replaceSelection("\n"); } } @@ -1058,6 +1089,7 @@ public void actionPerformed(ActionEvent event) { JTextComponent t = getTextComponent(event); + if (t != null) t.replaceSelection("\t"); } } Modified: trunk/core/src/classpath/javax/javax/swing/text/DefaultFormatter.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/DefaultFormatter.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/DefaultFormatter.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -216,7 +216,7 @@ */ public DefaultFormatter() { - commitsOnValidEdit = true; + commitsOnValidEdit = false; overwriteMode = true; allowsInvalid = true; } Modified: trunk/core/src/classpath/javax/javax/swing/text/DefaultStyledDocument.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/DefaultStyledDocument.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/DefaultStyledDocument.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -683,6 +683,58 @@ return ret; } + /** + * Creates a document in response to a call to + * {@link DefaultStyledDocument#create(ElementSpec[])}. + * + * @param len the length of the inserted text + * @param data the specs for the elements + * @param ev the document event + */ + void create(int len, ElementSpec[] data, DefaultDocumentEvent ev) + { + prepareEdit(offset, len); + Element el = root; + int index = el.getElementIndex(0); + while (! el.isLeaf()) + { + Element child = el.getElement(index); + Edit edit = new Edit(el, index, false); + elementStack.push(edit); + el = child; + index = el.getElementIndex(0); + } + Edit ed = (Edit) elementStack.peek(); + Element child = ed.e.getElement(ed.index); + ed.added.add(createLeafElement(ed.e, child.getAttributes(), getLength(), + child.getEndOffset())); + ed.removed.add(child); + while (elementStack.size() > 1) + pop(); + int n = data.length; + + // Reset root element's attributes. + AttributeSet newAtts = null; + if (n > 0 && data[0].getType() == ElementSpec.StartTagType) + newAtts = data[0].getAttributes(); + if (newAtts == null) + newAtts = SimpleAttributeSet.EMPTY; + MutableAttributeSet mAtts = (MutableAttributeSet) root.getAttributes(); + ev.addEdit(new AttributeUndoableEdit(root, newAtts, true)); + mAtts.removeAttributes(mAtts); + mAtts.addAttributes(newAtts); + + // Insert the specified elements. + for (int i = 1; i < n; i++) + insertElement(data[i]); + + // Pop remaining stack. + while (elementStack.size() > 0) + pop(); + + finishEdit(ev); + } + private boolean canJoin(Element e0, Element e1) { boolean ret = false; @@ -987,6 +1039,8 @@ ElementEdit ee = new ElementEdit(parent, index, removed, added); ev.addEdit(ee); } + edits.clear(); + elementStack.clear(); } /** @@ -1069,16 +1123,15 @@ if (offset == 0 && fracturedParent != null && data[0].getType() == ElementSpec.EndTagType) { - for (int p = 0; + int p; + for (p = 0; p < data.length && data[p].getType() == ElementSpec.EndTagType; - p++) - { + p++); Edit edit = insertPath[insertPath.length - p - 1]; edit.index--; edit.removed.add(0, edit.e.getElement(edit.index)); } } - } private void pop() { @@ -2379,18 +2432,24 @@ if (length == 0) return; - UndoableEdit edit = content.insertString(offset, + Content c = getContent(); + UndoableEdit edit = c.insertString(offset, contentBuffer.toString()); // Create the DocumentEvent with the ElementEdit added DefaultDocumentEvent ev = new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.INSERT); + ev.addEdit(edit); // Finally we must update the document structure and fire the insert // update event. buffer.insert(offset, length, data, ev); + + super.insertUpdate(ev, null); + + ev.end(); fireInsertUpdate(ev); fireUndoableEditUpdate(new UndoableEditEvent(this, ev)); } @@ -2410,14 +2469,16 @@ */ protected void create(ElementSpec[] data) { - writeLock(); try { + // Clear content if there is some. int len = getLength(); if (len > 0) remove(0, len); + writeLock(); + // Now we insert the content. StringBuilder b = new StringBuilder(); for (int i = 0; i < data.length; ++i) @@ -2429,38 +2490,18 @@ Content content = getContent(); UndoableEdit cEdit = content.insertString(0, b.toString()); + len = b.length(); DefaultDocumentEvent ev = new DefaultDocumentEvent(0, b.length(), DocumentEvent.EventType.INSERT); ev.addEdit(cEdit); - // We do a little trick here to get the new structure: We instantiate - // a new ElementBuffer with a new root element, insert into that root - // and then reparent the newly created elements to the old root - // element. - BranchElement createRoot = - (BranchElement) createBranchElement(null, null); - Element dummyLeaf = createLeafElement(createRoot, null, 0, 1); - createRoot.replace(0, 0, new Element[]{ dummyLeaf }); - ElementBuffer createBuffer = new ElementBuffer(createRoot); - createBuffer.insert(0, b.length(), data, new DefaultDocumentEvent(0, b.length(), DocumentEvent.EventType.INSERT)); - // Now the new root is the first child of the createRoot. - Element newRoot = createRoot.getElement(0); - BranchElement root = (BranchElement) getDefaultRootElement(); - Element[] added = new Element[newRoot.getElementCount()]; - for (int i = 0; i < added.length; ++i) - { - added[i] = newRoot.getElement(i); - ((AbstractElement) added[i]).element_parent = root; - } - Element[] removed = new Element[root.getElementCount()]; - for (int i = 0; i < removed.length; ++i) - removed[i] = root.getElement(i); + buffer.create(len, data, ev); - // Replace the old elements in root with the new and update the event. - root.replace(0, removed.length, added); - ev.addEdit(new ElementEdit(root, 0, removed, added)); + // For the bidi update. + super.insertUpdate(ev, null); + ev.end(); fireInsertUpdate(ev); fireUndoableEditUpdate(new UndoableEditEvent(this, ev)); } Modified: trunk/core/src/classpath/javax/javax/swing/text/ElementIterator.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/ElementIterator.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/ElementIterator.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -37,6 +37,8 @@ package javax.swing.text; +import java.util.Stack; + /** * This class can be used to iterate over the {@link Element} tree of * a {@link Document} or an {@link Element}. This iterator performs @@ -46,30 +48,49 @@ */ public class ElementIterator implements Cloneable { + /** + * Uses to track the iteration on the stack. + */ + private class ElementRef + { + /** + * The element. + */ + Element element; + + /** + * The child index. -1 means the element itself. >= 0 values mean the + * n-th child of the element. + */ + int index; + + /** + * Creates a new ElementRef. + * + * @param el the element + */ + ElementRef(Element el) + { + element = el; + index = -1; + } + } + // The root element. private Element root; - // The current element. - private Element currentElement; - // The depth to which we have descended in the tree. - private int currentDepth; - // This is at least as big as the current depth, and at index N - // contains the index of the child element we're currently - // examining. - private int[] state; + /** + * Holds ElementRefs. + */ + private Stack stack; - // The previous item. - private Element previousItem; - /** * Create a new ElementIterator to iterate over the given document. * @param document the Document over which we iterate */ public ElementIterator(Document document) { - this.root = document.getDefaultRootElement(); - this.currentElement = root; - this.state = new int[5]; + root = document.getDefaultRootElement(); } /** @@ -79,8 +100,6 @@ public ElementIterator(Element root) { this.root = root; - this.currentElement = root; - this.state = new int[5]; } /** @@ -105,7 +124,24 @@ */ public Element current() { - return currentElement; + Element current; + if (stack == null) + current = first(); + else + { + current = null; + if (! stack.isEmpty()) + { + ElementRef ref = (ElementRef) stack.peek(); + Element el = ref.element; + int index = ref.index; + if (index == -1) + current = el; + else + current = el.getElement(index); + } + } + return current; } /** @@ -113,7 +149,10 @@ */ public int depth() { - return currentDepth; + int depth = 0; + if (stack != null) + depth = stack.size(); + return depth; } /** @@ -121,11 +160,15 @@ */ public Element first() { - // Reset the iterator. - currentElement = root; - currentDepth = 0; - previousItem = null; - return root; + Element first = null; + if (root != null) + { + stack = new Stack(); + if (root.getElementCount() > 0) + stack.push(new ElementRef(root)); + first = root; + } + return first; } /** @@ -134,39 +177,41 @@ */ public Element next() { - previousItem = currentElement; - if (currentElement == null) - return null; - if (! currentElement.isLeaf()) + Element next; + if (stack == null) + next = first(); + else { - ++currentDepth; - if (currentDepth > state.length) + next = null; + if (! stack.isEmpty()) { - int[] newState = new int[state.length * 2]; - System.arraycopy(state, 0, newState, 0, state.length); - state = newState; - } - state[currentDepth] = 0; - currentElement = currentElement.getElement(0); - return currentElement; + ElementRef ref = (ElementRef) stack.peek(); + Element el = ref.element; + int index = ref.index; + if (el.getElementCount() > index + 1) + { + Element child = el.getElement(index + 1); + if (child.isLeaf()) + ref.index++; + else + stack.push(new ElementRef(child)); + next = child; + next = child; } - - while (currentDepth > 0) + else { - // At a leaf, or done with a non-leaf's children, so go up a - // level. - --currentDepth; - currentElement = currentElement.getParentElement(); - ++state[currentDepth]; - if (state[currentDepth] < currentElement.getElementCount()) + stack.pop(); + if (! stack.isEmpty()) { - currentElement = currentElement.getElement(state[currentDepth]); - return currentElement; + ElementRef top = (ElementRef) stack.peek(); + top.index++; + next = next(); } } - - currentElement = null; - return currentElement; + } + // else return null. + } + return next; } /** @@ -174,8 +219,54 @@ */ public Element previous() { - if (currentElement == null || currentElement == root) - return null; - return previousItem; + Element previous = null; + int stackSize; + if (stack != null && (stackSize = stack.size()) > 0) + { + ElementRef ref = (ElementRef) stack.peek(); + Element el = ref.element; + int index = ref.index; + if (index > 0) + { + previous = deepestLeaf(el.getElement(--index)); + } + else if (index == 0) + { + previous = el; + } + else if (index == -1) + { + ElementRef top = (ElementRef) stack.pop(); + ElementRef item = (ElementRef) stack.peek(); + stack.push(top); + index = item.index; + el = item.element; + previous = index == -1 ? el : deepestLeaf(el.getElement(index)); + } + } + return previous; } + + /** + * Determines and returns the deepest leaf of the element <code>el</code>. + * + * @param el the base element + * + * @returnthe deepest leaf of the element <code>el</code> + */ + private Element deepestLeaf(Element el) + { + Element leaf; + if (el.isLeaf()) + leaf = el; + else + { + int count = el.getElementCount(); + if (count == 0) + leaf = el; + else + leaf = deepestLeaf(el.getElement(count - 1)); + } + return leaf; + } } Modified: trunk/core/src/classpath/javax/javax/swing/text/FieldView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/FieldView.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/FieldView.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -45,8 +45,6 @@ import java.awt.Insets; import java.awt.Rectangle; import java.awt.Shape; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.BoundedRangeModel; import javax.swing.JTextField; @@ -225,7 +223,7 @@ public int getResizeWeight(int axis) { - return axis = axis == X_AXIS ? 1 : 0; + return axis == X_AXIS ? 1 : 0; } public Shape modelToView(int pos, Shape a, Position.Bias bias) Modified: trunk/core/src/classpath/javax/javax/swing/text/FlowView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/FlowView.java 2006-12-09 18:44:58 UTC (rev 2881) +++ trunk/core/src/classpath/javax/javax/swing/text/FlowView.java 2006-12-09 18:47:15 UTC (rev 2882) @@ -38,6 +38,8 @@ package javax.swing.text; +import java.awt.Component; +import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; @@ -85,7 +87,17 @@ */ public void insertUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) { - // The default implementation does nothing. + if (alloc == null) + { + fv.layoutChanged(X_AXIS); + fv.layoutChanged(Y_AXIS); + } + else + { + Component host = fv.getContainer(); + if (host != null) + host.repaint(alloc.x, alloc.y, alloc.width, alloc.height); + } } /** @@ -101,7 +113,17 @@ */ public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) { - // The default implementation does nothing. + if (alloc == null) + { + fv.layoutChanged(X_AXIS); + fv.layoutChanged(Y_AXIS); + } + else + { + Component host = fv.getContainer(); + if (host != null) + host.repaint(alloc.x, alloc.y, alloc.width, alloc.height); + } } /** @@ -117,7 +139,17 @@ */ public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) { - // The default implementation does nothing. + if (alloc == null) + { + fv.layoutChanged(X_AXIS); + fv.layoutChanged(Y_AXIS); + } + else + { + Component host = fv.getContainer(); + if (host != null) + host.repaint(alloc.x, alloc.y, alloc.width, alloc.height); + } } /** @@ -143,18 +175,35 @@ */ public void layout(FlowView fv) { + int start = fv.getStartOffset(); + int end = fv.getEndOffset(); + + // Preserve the views from the logical view from beeing removed. + View lv = getLogicalView(fv); + int viewCount = lv.getViewCount(); + for (int i = 0; i < viewCount; i++) + { + View v = lv.getView(i); + v.setParent(lv); + } + + // Then remove all views from the flow view. fv.removeAll(); - Element el = fv.getElement(); - int rowStart = el.getStartOffset(); - int end = el.getEndOffset(); - int rowIndex = 0; - while (rowStart >= 0 && rowStart < end) + for (int rowIndex = 0; start < end; rowIndex++) { View row = fv.createRow(); fv.append(row); - rowStart = layoutRow(fv, rowIndex, rowStart); - rowIndex++; + int next = layoutRow(fv, rowIndex, start); + if (row.getViewCount() == 0) + { + row.append(createView(fv, start, Integer.MAX_VALUE, rowIndex)); + next = row.getEndOffset(); + } + if (start < next) + start = next; + else + assert false: "May not happen"; } } @@ -179,46 +228,69 @@ int axis = fv.getFlowAxis(); int span = fv.getFlowSpan(rowIndex); int x = fv.getFlowStart(rowIndex); - int offset = pos; - View logicalView = getLogicalView(fv); - // Special case when span == 0. We need to layout the row as if it had - // a span of Integer.MAX_VALUE. - if (span == 0) - span = Integer.MAX_VALUE; + int end = fv.getEndOffset(); - Row: while (span > 0) + // Needed for adjusting indentation in adjustRow(). + int preX = x; + int availableSpan = span; + + TabExpander tabExp = fv instanceof TabExpander ? (TabExpander) fv : null; + + boolean forcedBreak = false; + while (pos < end && span >= 0) { - if (logicalView.getViewIndex(offset, Position.Bias.Forward) == - 1) + View view = createView(fv, pos, span, rowIndex); + if (view == null + || (span == 0 && view.getPreferredSpan(axis) > 0)) break; - View view = createView(fv, offset, span, rowIndex); - if (view == null) - break; - int viewSpan = (int) view.getPreferredSpan(axis); - int breakWeight = view.getBreakWeight(axis, x, span); + int viewSpan; + if (axis == X_AXIS && view instanceof TabableView) + viewSpan = (int) ((TabableView) view).getTabbedSpan(x, tabExp); + else + viewSpan = (int) view.getPreferredSpan(axis); - row.append(view); - offset += (view.getEndOffset() - view.getStartOffset()); - x += viewSpan; - span -= viewSpan; - // Break if the line if the view does not fit in this row or the // line just must be broken. - if (span < 0 || breakWeight >= View.ForcedBreakWeight) + int breakWeight = view.getBreakWeight(axis, pos, span); + if (breakWeight >= ForcedBreakWeight) { - int flowStart = fv.getFlowStart(axis); - int flowSpan = fv.getFlowSpan(axis); - adjustRow(fv, rowIndex, flowSpan, flowStart); int rowViewCount = row.getViewCount(); if (rowViewCount > 0) - offset = row.getView(rowViewCount - 1).getEndOffset(); + { + view = view.breakView(axis, pos, x, span); + if (view != null) + { + if (axis == X_AXIS && view instanceof TabableView) + viewSpan = + (int) ((TabableView) view).getTabbedSpan(x, tabExp); else - offset = - 1; - break Row; + viewSpan = (int) view.getPreferredSpan(axis); } + else + ... [truncated message content] |
From: <ls...@us...> - 2006-12-09 18:44:59
|
Revision: 2881 http://jnode.svn.sourceforge.net/jnode/?rev=2881&view=rev Author: lsantha Date: 2006-12-09 10:44:58 -0800 (Sat, 09 Dec 2006) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/javax/javax/swing/text/html/BRView.java trunk/core/src/classpath/javax/javax/swing/text/html/BlockView.java trunk/core/src/classpath/javax/javax/swing/text/html/CSS.java trunk/core/src/classpath/javax/javax/swing/text/html/FormView.java trunk/core/src/classpath/javax/javax/swing/text/html/HTML.java trunk/core/src/classpath/javax/javax/swing/text/html/HTMLDocument.java trunk/core/src/classpath/javax/javax/swing/text/html/HTMLEditorKit.java trunk/core/src/classpath/javax/javax/swing/text/html/ImageView.java trunk/core/src/classpath/javax/javax/swing/text/html/InlineView.java trunk/core/src/classpath/javax/javax/swing/text/html/ListView.java trunk/core/src/classpath/javax/javax/swing/text/html/Option.java trunk/core/src/classpath/javax/javax/swing/text/html/ParagraphView.java trunk/core/src/classpath/javax/javax/swing/text/html/StyleSheet.java trunk/core/src/classpath/javax/javax/swing/text/html/TableView.java Added Paths: ----------- trunk/core/src/classpath/javax/javax/swing/text/html/CSSBorder.java trunk/core/src/classpath/javax/javax/swing/text/html/FormSubmitEvent.java trunk/core/src/classpath/javax/javax/swing/text/html/FrameSetView.java trunk/core/src/classpath/javax/javax/swing/text/html/FrameView.java trunk/core/src/classpath/javax/javax/swing/text/html/HTMLWriter.java trunk/core/src/classpath/javax/javax/swing/text/html/ResetableModel.java trunk/core/src/classpath/javax/javax/swing/text/html/ResetablePlainDocument.java trunk/core/src/classpath/javax/javax/swing/text/html/ResetableToggleButtonModel.java trunk/core/src/classpath/javax/javax/swing/text/html/SelectComboBoxModel.java trunk/core/src/classpath/javax/javax/swing/text/html/SelectListModel.java Modified: trunk/core/src/classpath/javax/javax/swing/text/html/BRView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/BRView.java 2006-12-09 18:43:40 UTC (rev 2880) +++ trunk/core/src/classpath/javax/javax/swing/text/html/BRView.java 2006-12-09 18:44:58 UTC (rev 2881) @@ -44,8 +44,7 @@ * Handled the HTML BR tag. */ class BRView - extends NullView - + extends InlineView { /** * Creates the new BR view. @@ -66,6 +65,6 @@ if (axis == X_AXIS) return ForcedBreakWeight; else - return BadBreakWeight; + return super.getBreakWeight(axis, pos, len); } } Modified: trunk/core/src/classpath/javax/javax/swing/text/html/BlockView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/BlockView.java 2006-12-09 18:43:40 UTC (rev 2880) +++ trunk/core/src/classpath/javax/javax/swing/text/html/BlockView.java 2006-12-09 18:44:58 UTC (rev 2881) @@ -38,9 +38,12 @@ package javax.swing.text.html; +import gnu.javax.swing.text.html.css.Length; + import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; +import java.util.HashMap; import javax.swing.SizeRequirements; import javax.swing.event.DocumentEvent; @@ -57,6 +60,105 @@ { /** + * Stores information about child positioning according to the + * CSS attributes position, left, right, top and bottom. + */ + private static class PositionInfo + { + // TODO: Use enums when available. + + /** + * Static positioning. This is the default and is thus rarely really + * used. + */ + static final int STATIC = 0; + + /** + * Relative positioning. The box is teaked relative to its static + * computed bounds. + */ + static final int RELATIVE = 1; + + /** + * Absolute positioning. The box is moved relative to the parent's box. + */ + static final int ABSOLUTE = 2; + + /** + * Like ABSOLUTE, with some fixation against the viewport (not yet + * implemented). + */ + static final int FIXED = 3; + + /** + * The type according to the constants of this class. + */ + int type; + + /** + * The left constraint, null if not set. + */ + Length left; + + /** + * The right constraint, null if not set. + */ + Length right; + + /** + * The top constraint, null if not set. + */ + Length top; + + /** + * The bottom constraint, null if not set. + */ + Length bottom; + + /** + * Creates a new PositionInfo object. + * + * @param typ the type to set + * @param l the left constraint + * @param r the right constraint + * @param t the top constraint + * @param b the bottom constraint + */ + PositionInfo(int typ, Length l, Length r, Length t, Length b) + { + type = typ; + left = l; + right = r; + top = t; + bottom = b; + } + } + + /** + * The attributes for this view. + */ + private AttributeSet attributes; + + /** + * The box painter for this view. + * + * This is package private because the TableView needs access to it. + */ + StyleSheet.BoxPainter painter; + + /** + * The width and height as specified in the stylesheet, null if not + * specified. The first value is the X_AXIS, the second the Y_AXIS. You + * can index this directly by the X_AXIS and Y_AXIS constants. + */ + private Length[] cssSpans; + + /** + * Stores additional CSS layout information. + */ + private HashMap positionInfo; + + /** * Creates a new view that represents an html box. * This can be used for a number of elements. * @@ -66,6 +168,8 @@ public BlockView(Element elem, int axis) { super(elem, axis); + cssSpans = new Length[2]; + positionInfo = new HashMap(); } /** @@ -99,10 +203,25 @@ protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) { - SizeRequirements sr = super.calculateMajorAxisRequirements(axis, r); - // FIXME: adjust it if the CSS width or height attribute is specified - // and applicable - return sr; + if (r == null) + r = new SizeRequirements(); + + if (setCSSSpan(r, axis)) + { + // If we have set the span from CSS, then we need to adjust + // the margins. + SizeRequirements parent = super.calculateMajorAxisRequirements(axis, + null); + int margin = axis == X_AXIS ? getLeftInset() + getRightInset() + : getTopInset() + getBottomInset(); + r.minimum -= margin; + r.preferred -= margin; + r.maximum -= margin; + constrainSize(axis, r, parent); + } + else + r = super.calculateMajorAxisRequirements(axis, r); + return r; } /** @@ -118,11 +237,88 @@ protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) { - SizeRequirements sr = super.calculateMinorAxisRequirements(axis, r); - // FIXME: adjust it if the CSS width or height attribute is specified - // and applicable. - return sr; + if (r == null) + r = new SizeRequirements(); + + if (setCSSSpan(r, axis)) + { + // If we have set the span from CSS, then we need to adjust + // the margins. + SizeRequirements parent = super.calculateMinorAxisRequirements(axis, + null); + int margin = axis == X_AXIS ? getLeftInset() + getRightInset() + : getTopInset() + getBottomInset(); + r.minimum -= margin; + r.preferred -= margin; + r.maximum -= margin; + constrainSize(axis, r, parent); + } + else + r = super.calculateMinorAxisRequirements(axis, r); + + // Apply text alignment if appropriate. + if (axis == X_AXIS) + { + Object o = getAttributes().getAttribute(CSS.Attribute.TEXT_ALIGN); + if (o != null) + { + String al = o.toString().trim(); + if (al.equals("center")) + r.alignment = 0.5f; + else if (al.equals("right")) + r.alignment = 1.0f; + else + r.alignment = 0.0f; + } + } + return r; } + + /** + * Sets the span on the SizeRequirements object according to the + * according CSS span value, when it is set. + * + * @param r the size requirements + * @param axis the axis + * + * @return <code>true</code> when the CSS span has been set, + * <code>false</code> otherwise + */ + private boolean setCSSSpan(SizeRequirements r, int axis) + { + boolean ret = false; + Length span = cssSpans[axis]; + // We can't set relative CSS spans here because we don't know + // yet about the allocated span. Instead we use the view's + // normal requirements. + if (span != null && ! span.isPercentage()) + { + r.minimum = (int) span.getValue(); + r.preferred = (int) span.getValue(); + r.maximum = (int) span.getValue(); + ret = true; + } + return ret; + } + + /** + * Constrains the <code>r</code> requirements according to + * <code>min</code>. + * + * @param axis the axis + * @param r the requirements to constrain + * @param min the constraining requirements + */ + private void constrainSize(int axis, SizeRequirements r, + SizeRequirements min) + { + if (min.minimum > r.minimum) + { + r.minimum = min.minimum; + r.preferred = min.minimum; + r.maximum = Math.max(r.maximum, min.maximum); + } + } /** * Lays out the box along the minor axis (the axis that is @@ -142,9 +338,132 @@ protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) { - // FIXME: Not implemented. - super.layoutMinorAxis(targetSpan, axis, offsets, spans); + int viewCount = getViewCount(); + for (int i = 0; i < viewCount; i++) + { + View view = getView(i); + int min = (int) view.getMinimumSpan(axis); + int max; + // Handle CSS span value of child. + Length length = cssSpans[axis]; + if (length != null) + { + min = Math.max((int) length.getValue(targetSpan), min); + max = min; + } + else + max = (int) view.getMaximumSpan(axis); + + if (max < targetSpan) + { + // Align child. + float align = view.getAlignment(axis); + offsets[i] = (int) ((targetSpan - max) * align); + spans[i] = max; + } + else + { + offsets[i] = 0; + spans[i] = Math.max(min, targetSpan); + } + + // Adjust according to CSS position info. + positionView(targetSpan, axis, i, offsets, spans); + } } + + /** + * Overridden to perform additional CSS layout (absolute/relative + * positioning). + */ + protected void layoutMajorAxis(int targetSpan, int axis, + int[] offsets, int[] spans) + { + super.layoutMajorAxis(targetSpan, axis, offsets, spans); + + // Adjust according to CSS position info. + int viewCount = getViewCount(); + for (int i = 0; i < viewCount; i++) + { + positionView(targetSpan, axis, i, offsets, spans); + } + } + + /** + * Positions a view according to any additional CSS constraints. + * + * @param targetSpan the target span + * @param axis the axis + * @param i the index of the view + * @param offsets the offsets get placed here + * @param spans the spans get placed here + */ + private void positionView(int targetSpan, int axis, int i, int[] offsets, + int[] spans) + { + View view = getView(i); + PositionInfo pos = (PositionInfo) positionInfo.get(view); + if (pos != null) + { + int p0 = -1; + int p1 = -1; + if (axis == X_AXIS) + { + Length l = pos.left; + if (l != null) + p0 = (int) l.getValue(targetSpan); + l = pos.right; + if (l != null) + p1 = (int) l.getValue(targetSpan); + } + else + { + Length l = pos.top; + if (l != null) + p0 = (int) l.getValue(targetSpan); + l = pos.bottom; + if (l != null) + p1 = (int) l.getValue(targetSpan); + } + if (pos.type == PositionInfo.ABSOLUTE + || pos.type == PositionInfo.FIXED) + { + if (p0 != -1) + { + offsets[i] = p0; + if (p1 != -1) + { + // Overrides computed width. (Possibly overconstrained + // when the width attribute was set too.) + spans[i] = targetSpan - p1 - offsets[i]; + } + } + else if (p1 != -1) + { + // Preserve any computed width. + offsets[i] = targetSpan - p1 - spans[i]; + } + } + else if (pos.type == PositionInfo.RELATIVE) + { + if (p0 != -1) + { + offsets[i] += p0; + if (p1 != -1) + { + // Overrides computed width. (Possibly overconstrained + // when the width attribute was set too.) + spans[i] = spans[i] - p0 - p1 - offsets[i]; + } + } + else if (p1 != -1) + { + // Preserve any computed width. + offsets[i] -= p1; + } + } + } + } /** * Paints using the given graphics configuration and shape. @@ -156,11 +475,13 @@ */ public void paint(Graphics g, Shape a) { - Rectangle rect = (Rectangle) a; - // FIXME: not fully implemented - getStyleSheet().getBoxPainter(getAttributes()).paint(g, rect.x, rect.y, - rect.width, - rect.height, this); + Rectangle rect = a instanceof Rectangle ? (Rectangle) a : a.getBounds(); + + // Debug output. Shows blocks in green rectangles. + // g.setColor(Color.GREEN); + // g.drawRect(rect.x, rect.y, rect.width, rect.height); + + painter.paint(g, rect.x, rect.y, rect.width, rect.height, this); super.paint(g, a); } @@ -171,7 +492,9 @@ */ public AttributeSet getAttributes() { - return getStyleSheet().getViewAttributes(this); + if (attributes == null) + attributes = getStyleSheet().getViewAttributes(this); + return attributes; } /** @@ -200,14 +523,17 @@ public float getAlignment(int axis) { if (axis == X_AXIS) - return 0.0F; + return super.getAlignment(axis); if (axis == Y_AXIS) { if (getViewCount() == 0) return 0.0F; float prefHeight = getPreferredSpan(Y_AXIS); - float firstRowHeight = getView(0).getPreferredSpan(Y_AXIS); - return (firstRowHeight / 2.F) / prefHeight; + View first = getView(0); + float firstRowHeight = first.getPreferredSpan(Y_AXIS); + return prefHeight != 0 ? (firstRowHeight * first.getAlignment(Y_AXIS)) + / prefHeight + : 0; } throw new IllegalArgumentException("Invalid Axis"); } @@ -227,7 +553,8 @@ // If more elements were added, then need to set the properties for them int currPos = ev.getOffset(); - if (currPos <= getStartOffset() && (currPos + ev.getLength()) >= getEndOffset()) + if (currPos <= getStartOffset() + && (currPos + ev.getLength()) >= getEndOffset()) setPropertiesFromAttributes(); } @@ -284,7 +611,31 @@ */ protected void setPropertiesFromAttributes() { - // FIXME: Not implemented (need to use StyleSheet). + // Fetch attributes. + StyleSheet ss = getStyleSheet(); + attributes = ss.getViewAttributes(this); + + // Fetch painter. + painter = ss.getBoxPainter(attributes); + + // Update insets. + if (attributes != null) + { + setInsets((short) painter.getInset(TOP, this), + (short) painter.getInset(LEFT, this), + (short) painter.getInset(BOTTOM, this), + (short) painter.getInset(RIGHT, this)); + } + + // Fetch width and height. + float emBase = ss.getEMBase(attributes); + float exBase = ss.getEXBase(attributes); + cssSpans[X_AXIS] = (Length) attributes.getAttribute(CSS.Attribute.WIDTH); + if (cssSpans[X_AXIS] != null) + cssSpans[X_AXIS].setFontBases(emBase, exBase); + cssSpans[Y_AXIS] = (Length) attributes.getAttribute(CSS.Attribute.HEIGHT); + if (cssSpans[Y_AXIS] != null) + cssSpans[Y_AXIS].setFontBases(emBase, exBase); } /** @@ -294,8 +645,77 @@ */ protected StyleSheet getStyleSheet() { - StyleSheet styleSheet = new StyleSheet(); - styleSheet.importStyleSheet(getClass().getResource(HTMLEditorKit.DEFAULT_CSS)); - return styleSheet; + HTMLDocument doc = (HTMLDocument) getDocument(); + return doc.getStyleSheet(); } + + /** + * Overridden to fetch additional CSS layout information. + */ + public void replace(int offset, int length, View[] views) + { + // First remove unneeded stuff. + for (int i = 0; i < length; i++) + { + View child = getView(i + offset); + positionInfo.remove(child); + } + + // Call super to actually replace the views. + super.replace(offset, length, views); + + // Now fetch the position infos for the new views. + for (int i = 0; i < views.length; i++) + { + fetchLayoutInfo(views[i]); + } + } + + /** + * Fetches and stores the layout info for the specified view. + * + * @param view the view for which the layout info is stored + */ + private void fetchLayoutInfo(View view) + { + AttributeSet atts = view.getAttributes(); + Object o = atts.getAttribute(CSS.Attribute.POSITION); + if (o != null && o instanceof String && ! o.equals("static")) + { + int type; + if (o.equals("relative")) + type = PositionInfo.RELATIVE; + else if (o.equals("absolute")) + type = PositionInfo.ABSOLUTE; + else if (o.equals("fixed")) + type = PositionInfo.FIXED; + else + type = PositionInfo.STATIC; + + if (type != PositionInfo.STATIC) + { + StyleSheet ss = getStyleSheet(); + float emBase = ss.getEMBase(atts); + float exBase = ss.getEXBase(atts); + Length left = (Length) atts.getAttribute(CSS.Attribute.LEFT); + if (left != null) + left.setFontBases(emBase, exBase); + Length right = (Length) atts.getAttribute(CSS.Attribute.RIGHT); + if (right != null) + right.setFontBases(emBase, exBase); + Length top = (Length) atts.getAttribute(CSS.Attribute.TOP); + if (top != null) + top.setFontBases(emBase, exBase); + Length bottom = (Length) atts.getAttribute(CSS.Attribute.BOTTOM); + if (bottom != null) + bottom.setFontBases(emBase, exBase); + if (left != null || right != null || top != null || bottom != null) + { + PositionInfo pos = new PositionInfo(type, left, right, top, + bottom); + positionInfo.put(view, pos); + } + } + } + } } Modified: trunk/core/src/classpath/javax/javax/swing/text/html/CSS.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/CSS.java 2006-12-09 18:43:40 UTC (rev 2880) +++ trunk/core/src/classpath/javax/javax/swing/text/html/CSS.java 2006-12-09 18:44:58 UTC (rev 2881) @@ -37,6 +37,8 @@ package javax.swing.text.html; +import gnu.javax.swing.text.html.css.BorderStyle; +import gnu.javax.swing.text.html.css.BorderWidth; import gnu.javax.swing.text.html.css.CSSColor; import gnu.javax.swing.text.html.css.FontSize; import gnu.javax.swing.text.html.css.FontStyle; @@ -45,7 +47,10 @@ import java.io.Serializable; import java.util.HashMap; +import java.util.StringTokenizer; +import javax.swing.text.MutableAttributeSet; + /** * Provides CSS attributes to be used by the HTML view classes. The constants * defined here are used as keys for text attributes for use in @@ -394,6 +399,36 @@ public static final Attribute WORD_SPACING = new Attribute("word-spacing", true, "normal"); + // Some GNU Classpath specific extensions. + static final Attribute BORDER_TOP_STYLE = + new Attribute("border-top-style", false, null); + static final Attribute BORDER_BOTTOM_STYLE = + new Attribute("border-bottom-style", false, null); + static final Attribute BORDER_LEFT_STYLE = + new Attribute("border-left-style", false, null); + static final Attribute BORDER_RIGHT_STYLE = + new Attribute("border-right-style", false, null); + static final Attribute BORDER_TOP_COLOR = + new Attribute("border-top-color", false, null); + static final Attribute BORDER_BOTTOM_COLOR = + new Attribute("border-bottom-color", false, null); + static final Attribute BORDER_LEFT_COLOR = + new Attribute("border-left-color", false, null); + static final Attribute BORDER_RIGHT_COLOR = + new Attribute("border-right-color", false, null); + static final Attribute BORDER_SPACING = + new Attribute("border-spacing", false, null); + static final Attribute POSITION = + new Attribute("position", false, null); + static final Attribute LEFT = + new Attribute("left", false, null); + static final Attribute RIGHT = + new Attribute("right", false, null); + static final Attribute TOP = + new Attribute("top", false, null); + static final Attribute BOTTOM = + new Attribute("bottom", false, null); + /** * The attribute string. */ @@ -484,14 +519,218 @@ o = new FontWeight(v); else if (att == Attribute.FONT_STYLE) o = new FontStyle(v); - else if (att == Attribute.COLOR || att == Attribute.BACKGROUND_COLOR) + else if (att == Attribute.COLOR || att == Attribute.BACKGROUND_COLOR + || att == Attribute.BORDER_COLOR + || att == Attribute.BORDER_TOP_COLOR + || att == Attribute.BORDER_BOTTOM_COLOR + || att == Attribute.BORDER_LEFT_COLOR + || att == Attribute.BORDER_RIGHT_COLOR) o = new CSSColor(v); else if (att == Attribute.MARGIN || att == Attribute.MARGIN_BOTTOM || att == Attribute.MARGIN_LEFT || att == Attribute.MARGIN_RIGHT - || att == Attribute.MARGIN_TOP) + || att == Attribute.MARGIN_TOP || att == Attribute.WIDTH + || att == Attribute.HEIGHT + || att == Attribute.PADDING || att == Attribute.PADDING_BOTTOM + || att == Attribute.PADDING_LEFT || att == Attribute.PADDING_RIGHT + || att == Attribute.PADDING_TOP + || att == Attribute.LEFT || att == Attribute.RIGHT + || att == Attribute.TOP || att == Attribute.BOTTOM) o = new Length(v); + else if (att == Attribute.BORDER_WIDTH || att == Attribute.BORDER_TOP_WIDTH + || att == Attribute.BORDER_LEFT_WIDTH + || att == Attribute.BORDER_RIGHT_WIDTH + || att == Attribute.BORDER_BOTTOM_WIDTH) + o = new BorderWidth(v); else o = v; return o; } + + static void addInternal(MutableAttributeSet atts, Attribute a, String v) + { + if (a == Attribute.BACKGROUND) + parseBackgroundShorthand(atts, v); + else if (a == Attribute.PADDING) + parsePaddingShorthand(atts, v); + else if (a == Attribute.MARGIN) + parseMarginShorthand(atts, v); + else if (a == Attribute.BORDER || a == Attribute.BORDER_LEFT + || a == Attribute.BORDER_RIGHT || a == Attribute.BORDER_TOP + || a == Attribute.BORDER_BOTTOM) + parseBorderShorthand(atts, v, a); + } + + /** + * Parses the background shorthand and translates it to more specific + * background attributes. + * + * @param atts the attributes + * @param v the value + */ + private static void parseBackgroundShorthand(MutableAttributeSet atts, + String v) + { + StringTokenizer tokens = new StringTokenizer(v, " "); + while (tokens.hasMoreElements()) + { + String token = tokens.nextToken(); + if (CSSColor.isValidColor(token)) + atts.addAttribute(Attribute.BACKGROUND_COLOR, + new CSSColor(token)); + } + } + + /** + * Parses the padding shorthand and translates to the specific padding + * values. + * + * @param atts the attributes + * @param v the actual value + */ + private static void parsePaddingShorthand(MutableAttributeSet atts, String v) + { + StringTokenizer tokens = new StringTokenizer(v, " "); + int numTokens = tokens.countTokens(); + if (numTokens == 1) + { + Length l = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.PADDING_BOTTOM, l); + atts.addAttribute(Attribute.PADDING_LEFT, l); + atts.addAttribute(Attribute.PADDING_RIGHT, l); + atts.addAttribute(Attribute.PADDING_TOP, l); + } + else if (numTokens == 2) + { + Length l1 = new Length(tokens.nextToken()); + Length l2 = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.PADDING_BOTTOM, l1); + atts.addAttribute(Attribute.PADDING_TOP, l1); + atts.addAttribute(Attribute.PADDING_LEFT, l2); + atts.addAttribute(Attribute.PADDING_RIGHT, l2); + } + else if (numTokens == 3) + { + Length l1 = new Length(tokens.nextToken()); + Length l2 = new Length(tokens.nextToken()); + Length l3 = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.PADDING_TOP, l1); + atts.addAttribute(Attribute.PADDING_LEFT, l2); + atts.addAttribute(Attribute.PADDING_RIGHT, l2); + atts.addAttribute(Attribute.PADDING_BOTTOM, l3); + } + else + { + Length l1 = new Length(tokens.nextToken()); + Length l2 = new Length(tokens.nextToken()); + Length l3 = new Length(tokens.nextToken()); + Length l4 = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.PADDING_TOP, l1); + atts.addAttribute(Attribute.PADDING_RIGHT, l2); + atts.addAttribute(Attribute.PADDING_BOTTOM, l3); + atts.addAttribute(Attribute.PADDING_LEFT, l4); + } + } + + /** + * Parses the margin shorthand and translates to the specific margin + * values. + * + * @param atts the attributes + * @param v the actual value + */ + private static void parseMarginShorthand(MutableAttributeSet atts, String v) + { + StringTokenizer tokens = new StringTokenizer(v, " "); + int numTokens = tokens.countTokens(); + if (numTokens == 1) + { + Length l = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.MARGIN_BOTTOM, l); + atts.addAttribute(Attribute.MARGIN_LEFT, l); + atts.addAttribute(Attribute.MARGIN_RIGHT, l); + atts.addAttribute(Attribute.MARGIN_TOP, l); + } + else if (numTokens == 2) + { + Length l1 = new Length(tokens.nextToken()); + Length l2 = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.MARGIN_BOTTOM, l1); + atts.addAttribute(Attribute.MARGIN_TOP, l1); + atts.addAttribute(Attribute.MARGIN_LEFT, l2); + atts.addAttribute(Attribute.MARGIN_RIGHT, l2); + } + else if (numTokens == 3) + { + Length l1 = new Length(tokens.nextToken()); + Length l2 = new Length(tokens.nextToken()); + Length l3 = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.MARGIN_TOP, l1); + atts.addAttribute(Attribute.MARGIN_LEFT, l2); + atts.addAttribute(Attribute.MARGIN_RIGHT, l2); + atts.addAttribute(Attribute.MARGIN_BOTTOM, l3); + } + else + { + Length l1 = new Length(tokens.nextToken()); + Length l2 = new Length(tokens.nextToken()); + Length l3 = new Length(tokens.nextToken()); + Length l4 = new Length(tokens.nextToken()); + atts.addAttribute(Attribute.MARGIN_TOP, l1); + atts.addAttribute(Attribute.MARGIN_RIGHT, l2); + atts.addAttribute(Attribute.MARGIN_BOTTOM, l3); + atts.addAttribute(Attribute.MARGIN_LEFT, l4); + } + } + + /** + * Parses the CSS border shorthand attribute and translates it to the + * more specific border attributes. + * + * @param atts the attribute + * @param value the value + */ + private static void parseBorderShorthand(MutableAttributeSet atts, + String value, Attribute cssAtt) + { + StringTokenizer tokens = new StringTokenizer(value, " "); + while (tokens.hasMoreTokens()) + { + String token = tokens.nextToken(); + if (BorderStyle.isValidStyle(token)) + { + if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_LEFT_STYLE, token); + if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_RIGHT_STYLE, token); + if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_BOTTOM_STYLE, token); + if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_TOP_STYLE, token); + } + else if (BorderWidth.isValid(token)) + { + BorderWidth w = new BorderWidth(token); + if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_LEFT_WIDTH, w); + if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_RIGHT_WIDTH, w); + if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_BOTTOM_WIDTH, w); + if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_TOP_WIDTH, w); + } + else if (CSSColor.isValidColor(token)) + { + CSSColor c = new CSSColor(token); + if (cssAtt == Attribute.BORDER_LEFT || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_LEFT_COLOR, c); + if (cssAtt == Attribute.BORDER_RIGHT || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_RIGHT_COLOR, c); + if (cssAtt == Attribute.BORDER_BOTTOM || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_BOTTOM_COLOR, c); + if (cssAtt == Attribute.BORDER_TOP || cssAtt == Attribute.BORDER) + atts.addAttribute(Attribute.BORDER_TOP_COLOR, c); + } + } + } } Added: trunk/core/src/classpath/javax/javax/swing/text/html/CSSBorder.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/CSSBorder.java (rev 0) +++ trunk/core/src/classpath/javax/javax/swing/text/html/CSSBorder.java 2006-12-09 18:44:58 UTC (rev 2881) @@ -0,0 +1,421 @@ +/* CSSBorder.java -- A border for rendering CSS border styles + 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 javax.swing.text.html; + +import gnu.javax.swing.text.html.css.BorderWidth; +import gnu.javax.swing.text.html.css.CSSColor; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Insets; + +import javax.swing.border.Border; +import javax.swing.text.AttributeSet; + +/** + * A border implementation to render CSS border styles. + */ +class CSSBorder + implements Border +{ + + /** + * The CSS border styles. + */ + + private static final int STYLE_NOT_SET = -1; + private static final int STYLE_NONE = 0; + private static final int STYLE_HIDDEN = 1; + private static final int STYLE_DOTTED = 2; + private static final int STYLE_DASHED = 3; + private static final int STYLE_SOLID = 4; + private static final int STYLE_DOUBLE = 5; + private static final int STYLE_GROOVE = 6; + private static final int STYLE_RIDGE = 7; + private static final int STYLE_INSET = 8; + private static final int STYLE_OUTSET = 9; + + /** + * The left insets. + */ + private int left; + + /** + * The right insets. + */ + private int right; + + /** + * The top insets. + */ + private int top; + + /** + * The bottom insets. + */ + private int bottom; + + /** + * The border style on the left. + */ + private int leftStyle; + + /** + * The border style on the right. + */ + private int rightStyle; + + /** + * The border style on the top. + */ + private int topStyle; + + /** + * The color for the top border. + */ + private Color topColor; + + /** + * The color for the bottom border. + */ + private Color bottomColor; + + /** + * The color for the left border. + */ + private Color leftColor; + + /** + * The color for the right border. + */ + private Color rightColor; + + /** + * The border style on the bottom. + */ + private int bottomStyle; + + /** + * Creates a new CSS border and fetches its attributes from the specified + * attribute set. + * + * @param atts the attribute set that contains the border spec + */ + CSSBorder(AttributeSet atts, StyleSheet ss) + { + // Determine the border styles. + int style = getBorderStyle(atts, CSS.Attribute.BORDER_STYLE); + if (style == STYLE_NOT_SET) + style = STYLE_NONE; // Default to none. + topStyle = bottomStyle = leftStyle = rightStyle = style; + style = getBorderStyle(atts, CSS.Attribute.BORDER_TOP_STYLE); + if (style != STYLE_NOT_SET) + topStyle = style; + style = getBorderStyle(atts, CSS.Attribute.BORDER_BOTTOM_STYLE); + if (style != STYLE_NOT_SET) + bottomStyle = style; + style = getBorderStyle(atts, CSS.Attribute.BORDER_LEFT_STYLE); + if (style != STYLE_NOT_SET) + leftStyle = style; + style = getBorderStyle(atts, CSS.Attribute.BORDER_RIGHT_STYLE); + if (style != STYLE_NOT_SET) + rightStyle = style; + + // Determine the border colors. + Color color = getBorderColor(atts, CSS.Attribute.BORDER_COLOR); + if (color == null) + color = Color.BLACK; + topColor = bottomColor = leftColor = rightColor = color; + color = getBorderColor(atts, CSS.Attribute.BORDER_TOP_COLOR); + if (color != null) + topColor = color; + color = getBorderColor(atts, CSS.Attribute.BORDER_BOTTOM_COLOR); + if (color != null) + bottomColor = color; + color = getBorderColor(atts, CSS.Attribute.BORDER_LEFT_COLOR); + if (color != null) + leftColor = color; + color = getBorderColor(atts, CSS.Attribute.BORDER_RIGHT_COLOR); + if (color != null) + rightColor = color; + + // Determine the border widths. + int width = getBorderWidth(atts, CSS.Attribute.BORDER_WIDTH, ss); + if (width == -1) + width = 0; + top = bottom = left = right = width; + width = getBorderWidth(atts, CSS.Attribute.BORDER_TOP_WIDTH, ss); + if (width >= 0) + top = width; + width = getBorderWidth(atts, CSS.Attribute.BORDER_BOTTOM_WIDTH, ss); + if (width >= 0) + bottom = width; + width = getBorderWidth(atts, CSS.Attribute.BORDER_LEFT_WIDTH, ss); + if (width >= 0) + left = width; + width = getBorderWidth(atts, CSS.Attribute.BORDER_RIGHT_WIDTH, ss); + if (width >= 0) + right = width; + } + + /** + * Determines the border style for a given CSS attribute. + * + * @param atts the attribute set + * @param key the CSS key + * + * @return the border style according to the constants defined in this class + */ + private int getBorderStyle(AttributeSet atts, CSS.Attribute key) + { + int style = STYLE_NOT_SET; + Object o = atts.getAttribute(key); + if (o != null) + { + String cssStyle = o.toString(); + if (cssStyle.equals("none")) + style = STYLE_NONE; + else if (cssStyle.equals("hidden")) + style = STYLE_HIDDEN; + else if (cssStyle.equals("dotted")) + style = STYLE_DOTTED; + else if (cssStyle.equals("dashed")) + style = STYLE_DASHED; + else if (cssStyle.equals("solid")) + style = STYLE_SOLID; + else if (cssStyle.equals("double")) + style = STYLE_DOUBLE; + else if (cssStyle.equals("groove")) + style = STYLE_GROOVE; + else if (cssStyle.equals("ridge")) + style = STYLE_RIDGE; + else if (cssStyle.equals("inset")) + style = STYLE_INSET; + else if (cssStyle.equals("outset")) + style = STYLE_OUTSET; + } + return style; + } + + /** + * Determines the border color for the specified key. + * + * @param atts the attribute set from which to fetch the color + * @param key the CSS key + * + * @return the border color + */ + private Color getBorderColor(AttributeSet atts, CSS.Attribute key) + { + Object o = atts.getAttribute(key); + Color color = null; + if (o instanceof CSSColor) + { + CSSColor cssColor = (CSSColor) o; + color = cssColor.getValue(); + } + return color; + } + + /** + * Returns the width for the specified key. + * + * @param atts the attributes to fetch the width from + * @param key the CSS key + * + * @return the width, or -1 of none has been set + */ + private int getBorderWidth(AttributeSet atts, CSS.Attribute key, + StyleSheet ss) + { + int width = -1; + Object o = atts.getAttribute(key); + if (o instanceof BorderWidth) + { + BorderWidth w = (BorderWidth) o; + w.setFontBases(ss.getEMBase(atts), ss.getEXBase(atts)); + width = (int) ((BorderWidth) o).getValue(); + } + return width; + } + + /** + * Returns the border insets. + */ + public Insets getBorderInsets(Component c) + { + return new Insets(top, left, bottom, right); + } + + /** + * CSS borders are generally opaque so return true here. + */ + public boolean isBorderOpaque() + { + return true; + } + + public void paintBorder(Component c, Graphics g, int x, int y, int width, + int height) + { + // Top border. + paintBorderLine(g, x, y + top / 2, x + width, y + top / 2, topStyle, top, + topColor, false); + // Left border. + paintBorderLine(g, x + left / 2, y, x + left / 2, y + height, leftStyle, + left, leftColor, true); + // Bottom border. + paintBorderLine(g, x, y + height - bottom / 2, x + width, + y + height - bottom / 2, topStyle, bottom, bottomColor, + false); + // Right border. + paintBorderLine(g, x + width - right / 2, y, x + width - right / 2, + y + height, topStyle, right, rightColor, true); + + } + + private void paintBorderLine(Graphics g, int x1, int y1, int x2, int y2, + int style, int width, Color color, + boolean vertical) + { + switch (style) + { + case STYLE_DOTTED: + paintDottedLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_DASHED: + paintDashedLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_SOLID: + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_DOUBLE: + paintDoubleLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_GROOVE: + paintGrooveLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_RIDGE: + paintRidgeLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_OUTSET: + paintOutsetLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_INSET: + paintInsetLine(g, x1, y1, x2, y2, width, color, vertical); + break; + case STYLE_NONE: + case STYLE_HIDDEN: + default: + // Nothing to do in these cases. + } + } + + private void paintDottedLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + // FIXME: Implement this. + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + } + + private void paintDashedLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + // FIXME: Implement this. + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + } + + private void paintSolidLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + int x = Math.min(x1, x2); + int y = Math.min(y1, y1); + int w = Math.abs(x2 - x1); + int h = Math.abs(y2 - y1); + if (vertical) + { + w = width; + x -= width / 2; + } + else + { + h = width; + y -= width / 2; + } + g.setColor(color); + g.fillRect(x, y, w, h); + } + + private void paintDoubleLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + // FIXME: Implement this. + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + } + + private void paintGrooveLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + // FIXME: Implement this. + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + } + + private void paintRidgeLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + // FIXME: Implement this. + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + } + + private void paintOutsetLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + // FIXME: Implement this. + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + } + + private void paintInsetLine(Graphics g, int x1, int y1, int x2, int y2, + int width, Color color, boolean vertical) + { + // FIXME: Implement this. + paintSolidLine(g, x1, y1, x2, y2, width, color, vertical); + } + +} Added: trunk/core/src/classpath/javax/javax/swing/text/html/FormSubmitEvent.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/FormSubmitEvent.java (rev 0) +++ trunk/core/src/classpath/javax/javax/swing/text/html/FormSubmitEvent.java 2006-12-09 18:44:58 UTC (rev 2881) @@ -0,0 +1,123 @@ +/* FormSubmitEvent.java -- Event fired on form submit + 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 javax.swing.text.html; + +import java.net.URL; + +import javax.swing.text.Element; + +/** + * The event fired on form submit. + * + * @since 1.5 + */ +public class FormSubmitEvent + extends HTMLFrameHyperlinkEvent +{ + + // FIXME: Use enums when available. + /** + * The submit method. + */ + public static class MethodType + { + /** + * Indicates a form submit with HTTP method POST. + */ + public static final MethodType POST = new MethodType(); + + /** + * Indicates a form submit with HTTP method GET. + */ + public static final MethodType GET = new MethodType(); + + private MethodType() + { + } + } + + /** + * The submit method. + */ + private MethodType method; + + /** + * The actual submit data. + */ + private String data; + + /** + * Creates a new FormSubmitEvent. + * + * @param source the source + * @param type the type of hyperlink update + * @param url the action url + * @param el the associated element + * @param target the target attribute + * @param m the submit method + * @param d the submit data + */ + FormSubmitEvent(Object source, EventType type, URL url, Element el, + String target, MethodType m, String d) + { + super(source, type, url, el, target); + method = m; + data = d; + } + + /** + * Returns the submit data. + * + * @return the submit data + */ + public String getData() + { + return data; + } + + /** + * Returns the HTTP submit method. + * + * @return the HTTP submit method + */ + public MethodType getMethod() + { + return method; + } +} Modified: trunk/core/src/classpath/javax/javax/swing/text/html/FormView.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/FormView.java 2006-12-09 18:43:40 UTC (rev 2880) +++ trunk/core/src/classpath/javax/javax/swing/text/html/FormView.java 2006-12-09 18:44:58 UTC (rev 2881) @@ -44,16 +44,36 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLEncoder; +import javax.swing.ButtonModel; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JEditorPane; +import javax.swing.JList; import javax.swing.JPasswordField; import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; import javax.swing.UIManager; +import javax.swing.event.HyperlinkEvent; import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; import javax.swing.text.ComponentView; +import javax.swing.text.Document; import javax.swing.text.Element; +import javax.swing.text.ElementIterator; import javax.swing.text.StyleConstants; /** @@ -105,6 +125,231 @@ } /** + * Actually submits the form data. + */ + private class SubmitThread + extends Thread + { + /** + * The submit data. + */ + private String data; + + /** + * Creates a new SubmitThread. + * + * @param d the submit data + */ + SubmitThread(String d) + { + data = d; + } + + /** + * Actually performs the submit. + */ + public void run() + { + if (data.length() > 0) + { + final String method = getMethod(); + final URL actionURL = getActionURL(); + final String target = getTarget(); + URLConnection conn; + final JEditorPane editor = (JEditorPane) getContainer(); + final HTMLDocument doc = (HTMLDocument) editor.getDocument(); + HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit(); + if (kit.isAutoFormSubmission()) + { + try + { + final URL url; + if (method != null && method.equals("post")) + { + // Perform POST. + url = actionURL; + conn = url.openConnection(); + postData(conn, data); + } + else + { + // Default to GET. + url = new URL(actionURL + "?" + data); + } + Runnable loadDoc = new Runnable() + { + public void run() + { + if (doc.isFrameDocument()) + { + editor.fireHyperlinkUpdate(createSubmitEvent(method, + actionURL, + target)); + } + else + { + try + { + editor.setPage(url); + } + catch (IOException ex) + { + // Oh well. + ex.printStackTrace(); + } + } + } + }; + SwingUtilities.invokeLater(loadDoc); + } + catch (MalformedURLException ex) + { + ex.printStackTrace(); + } + catch (IOException ex) + { + ex.printStackTrace(); + } + } + else + { + editor.fireHyperlinkUpdate(createSubmitEvent(method,actionURL, + target)); + } + } + } + + /** + * Determines the submit method. + * + * @return the submit method + */ + private String getMethod() + { + AttributeSet formAtts = getFormAttributes(); + String method = null; + if (formAtts != null) + { + method = (String) formAtts.getAttribute(HTML.Attribute.METHOD); + } + return method; + } + + /** + * Determines the action URL. + * + * @return the action URL + */ + private URL getActionURL() + { + AttributeSet formAtts = getFormAttributes(); + HTMLDocument doc = (HTMLDocument) getElement().getDocument(); + URL url = doc.getBase(); + if (formAtts != null) + { + String action = + (String) formAtts.getAttribute(HTML.Attribute.ACTION); + if (action != null) + { + try + { + url = new URL(url, action); + } + catch (MalformedURLException ex) + { + url = null; + } + } + } + return url; + } + + /** + * Fetches the target attribute. + * + * @return the target attribute or _self if none is present + */ + private String getTarget() + { + AttributeSet formAtts = getFormAttributes(); + String target = null; + if (formAtts != null) + { + target = (String) formAtts.getAttribute(HTML.Attribute.TARGET); + if (target != null) + target = target.toLowerCase(); + } + if (target == null) + target = "_self"; + return target; + } + + /** + * Posts the form data over the specified connection. + * + * @param conn the connection + */ + private void postData(URLConnection conn, String data) + { + conn.setDoOutput(true); + PrintWriter out = null; + try + { + out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream())); + out.print(data); + out.flush(); + } + catch (IOException ex) + { + // Deal with this! + ex.printStackTrace(); + } + finally + { + if (out != null) + out.close(); + } + } + + /** + * Determines the attributes from the relevant form tag. + * + * @return the attributes from the relevant form tag, <code>null</code> + * when there is no form tag + */ + private AttributeSet getFormAttributes() + { + AttributeSet atts = null; + Element form = getFormElement(); + if (form != null) + atts = form.getAttributes(); + return atts; + } + + /** + * Creates the submit event that should be fired. + * + * This is package private to avoid accessor methods. + * + * @param method the submit method + * @param actionURL the action URL + * @param target the target + * + * @return the submit event + */ + FormSubmitEvent createSubmitEvent(String method, URL actionURL, + String target) + { + FormSubmitEvent.MethodType m = "post".equals(method) + ? FormSubmitEvent.MethodType.POST + : FormSubmitEvent.MethodType.GET; + return new FormSubmitEvent(FormView.this, + HyperlinkEvent.EventType.ACTIVATED, + actionURL, getElement(), target, m, data); + } + } + + /** * If the value attribute of an <code><input type="submit">> * tag is not specified, then this string is used. * @@ -125,6 +370,11 @@ UIManager.getString("FormView.resetButtonText"); /** + * If this is true, the maximum size is set to the preferred size. + */ + private boolean maxIsPreferred; + + /** * Creates a new <code>FormView</code>. * * @param el the element that is displayed by this view. @@ -141,39 +391,161 @@ { Component comp = null; Element el = getElement(); - Object tag = el.getAttributes().getAttribute(StyleConstants.NameAttribute); + AttributeSet atts = el.getAttributes(); + Object tag = atts.getAttribute(StyleConstants.NameAttribute); + Object model = atts.getAttribute(StyleConstants.ModelAttribute); if (tag.equals(HTML.Tag.INPUT)) { - AttributeSet atts = el.getAttributes(); String type = (String) atts.getAttribute(HTML.Attribute.TYPE); - String value = (String) atts.getAttribute(HTML.Attribute.VALUE); if (type.equals("button")) - comp = new JButton(value); + { + String value = (String) atts.getAttribute(HTML.Attribute.VALUE); + JButton b = new JButton(value); + if (model != null) + { + b.setModel((ButtonModel) model); + b.addActionListener(this); + } + comp = b; + maxIsPreferred = true; + } else if (type.equals("checkbox")) - comp = new JCheckBox(value); + { + if (model instanceof ResetableToggleButtonModel) + { + ResetableToggleButtonModel m = + (ResetableToggleButtonModel) model; + JCheckBox c = new JCheckBox(); + c.setModel(m); + comp = c; + maxIsPreferred = true; + } + } else if (type.equals("image")) - comp = new JButton(value); // FIXME: Find out how to fetch the image. + { + String src = (String) atts.getAttribute(HTML.Attribute.SRC); + JButton b; + try + { + URL base = ((HTMLDocument) el.getDocument()).getBase(); + URL srcURL = new URL(base, src); + ImageIcon icon = new ImageIcon(srcURL); + b = new JButton(icon); + } + catch (MalformedURLException ex) + { + b = new JButton(src); + } + if (model != null) + { + b.setModel((ButtonModel) model); + b.addActionListener(this); + } + comp = b; + maxIsPreferred = true; + } else if (type.equals("password")) - comp = new JPasswordField(value); + { + int size = HTML.getIntegerAttributeValue(atts, HTML.Attribute.SIZE, + -1); + JTextField tf = new JPasswordField(); + if (size > 0) + tf.setColumns(size); + else + tf.setColumns(20); + if (model != null) + tf.setDocument((Document) model); + tf.addActionListener(this); + comp = tf; + maxIsPreferred = true; + } else if (type.equals("radio")) - comp = new JRadioButton(value); + ... [truncated message content] |
From: <ls...@us...> - 2006-12-09 18:43:42
|
Revision: 2880 http://jnode.svn.sourceforge.net/jnode/?rev=2880&view=rev Author: lsantha Date: 2006-12-09 10:43:40 -0800 (Sat, 09 Dec 2006) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/javax/javax/swing/text/html/parser/DocumentParser.java trunk/core/src/classpath/javax/javax/swing/text/html/parser/ParserDelegator.java Modified: trunk/core/src/classpath/javax/javax/swing/text/html/parser/DocumentParser.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/parser/DocumentParser.java 2006-12-09 11:09:36 UTC (rev 2879) +++ trunk/core/src/classpath/javax/javax/swing/text/html/parser/DocumentParser.java 2006-12-09 18:43:40 UTC (rev 2880) @@ -38,13 +38,13 @@ package javax.swing.text.html.parser; -import gnu.javax.swing.text.html.parser.htmlAttributeSet; import javax.swing.text.html.parser.Parser; import java.io.IOException; import java.io.Reader; import javax.swing.text.BadLocationException; +import javax.swing.text.SimpleAttributeSet; import javax.swing.text.html.HTMLEditorKit; /** @@ -117,7 +117,7 @@ protected final void handleStartTag(TagElement tag) { parser.handleStartTag(tag); - htmlAttributeSet attributes = gnu.getAttributes(); + SimpleAttributeSet attributes = gnu.getAttributes(); if (tag.fictional()) attributes.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED, Modified: trunk/core/src/classpath/javax/javax/swing/text/html/parser/ParserDelegator.java =================================================================== --- trunk/core/src/classpath/javax/javax/swing/text/html/parser/ParserDelegator.java 2006-12-09 11:09:36 UTC (rev 2879) +++ trunk/core/src/classpath/javax/javax/swing/text/html/parser/ParserDelegator.java 2006-12-09 18:43:40 UTC (rev 2880) @@ -38,13 +38,13 @@ package javax.swing.text.html.parser; import gnu.javax.swing.text.html.parser.HTML_401F; -import gnu.javax.swing.text.html.parser.htmlAttributeSet; import java.io.IOException; import java.io.Reader; import java.io.Serializable; import javax.swing.text.BadLocationException; +import javax.swing.text.SimpleAttributeSet; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.HTMLEditorKit.ParserCallback; @@ -93,7 +93,7 @@ protected final void handleStartTag(TagElement tag) { - htmlAttributeSet attributes = gnu.getAttributes(); + SimpleAttributeSet attributes = gnu.getAttributes(); if (tag.fictional()) attributes.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-09 11:09:38
|
Revision: 2879 http://jnode.svn.sourceforge.net/jnode/?rev=2879&view=rev Author: lsantha Date: 2006-12-09 03:09:36 -0800 (Sat, 09 Dec 2006) Log Message: ----------- Added javadoc. Modified Paths: -------------- trunk/gui/src/test/org/jnode/test/gui/HTMLTest.java Modified: trunk/gui/src/test/org/jnode/test/gui/HTMLTest.java =================================================================== --- trunk/gui/src/test/org/jnode/test/gui/HTMLTest.java 2006-12-09 10:29:22 UTC (rev 2878) +++ trunk/gui/src/test/org/jnode/test/gui/HTMLTest.java 2006-12-09 11:09:36 UTC (rev 2879) @@ -26,6 +26,8 @@ import javax.swing.JEditorPane; /** + * HTML rendering test. + * * @author Levente S\u00e1ntha */ public class HTMLTest { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-09 10:29:24
|
Revision: 2878 http://jnode.svn.sourceforge.net/jnode/?rev=2878&view=rev Author: lsantha Date: 2006-12-09 02:29:22 -0800 (Sat, 09 Dec 2006) Log Message: ----------- removed unused imports Modified Paths: -------------- trunk/gui/src/test/org/jnode/test/gui/HTMLTest.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2006-12-09 10:15:36
|
Revision: 2877 http://jnode.svn.sourceforge.net/jnode/?rev=2877&view=rev Author: lsantha Date: 2006-12-09 02:15:34 -0800 (Sat, 09 Dec 2006) Log Message: ----------- classpath patches Modified Paths: -------------- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSColor.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParser.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSParserCallback.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/CSSScanner.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/FontSize.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/Length.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/GnuParserDelegator.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/HTML_401F.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/parser/htmlValidator.java Added Paths: ----------- trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/BorderStyle.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/BorderWidth.java trunk/core/src/classpath/gnu/gnu/javax/swing/text/html/css/Selector.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |