# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: openide/util/apichanges.xml --- openide/util/apichanges.xml Base (1.27) +++ openide/util/apichanges.xml Locally Modified (Based On 1.27) @@ -49,6 +49,23 @@ Actions API + + + Mutex made pluggable + + + + + +

+ Added Mutex.Wrapper + that allows creators of some mutex to intercept and wrap posted actions + with custom code. +

+
+ + +
Obsolete method Utilities.isLargeFrameIcons deprecated. Index: openide/util/nbproject/project.properties --- openide/util/nbproject/project.properties Base (1.30) +++ openide/util/nbproject/project.properties Locally Modified (Based On 1.30) @@ -41,7 +41,7 @@ javac.source=1.5 module.jar.dir=lib -spec.version.base=7.11.0 +spec.version.base=7.12.0 # For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4: Index: openide/util/src/org/openide/util/Mutex.java --- openide/util/src/org/openide/util/Mutex.java Base (1.19) +++ openide/util/src/org/openide/util/Mutex.java Locally Modified (Based On 1.19) @@ -220,6 +220,19 @@ } } + /** @param privileged can enter privileged states of this Mutex + * @param wrapper a factory that allows Runnables from API to be wrapped into different onces + * @since 7.12 + */ + public Mutex(Privileged privileged, Wrapper wrapper) { + if (privileged == null) { + throw new IllegalArgumentException("privileged == null"); //NOI18N + } else { + init(new InternalLock()); + privileged.setParent(this); + } + } + /** Initiates this Mutex */ private void init(Object lock) { this.LOCK = lock; @@ -1485,6 +1498,22 @@ } } + /** Factory to wrap runnables into custom ones. This can be used + * to always do some action before and after a runnable passed to a + * mutex method is executed. + * + * @since 7.12 + */ + public static interface Wrapper { + /** Creates a custom runnable that is supposed to wrap those + * provided by mutex API methods. + * + * @param run runnable to wrap + * @return a custom runnable to execute custom pre and/or post action + */ + public Runnable wrap(Runnable run); + } + /** Provides access to Mutex's internal methods. * * This class can be used when one wants to avoid creating a Index: openide/util/test/unit/src/org/openide/util/MutexWrapTest.java --- openide/util/test/unit/src/org/openide/util/MutexWrapTest.java No Base Revision +++ openide/util/test/unit/src/org/openide/util/MutexWrapTest.java Locally New @@ -0,0 +1,172 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.openide.util; + +import junit.framework.Test; +import org.netbeans.junit.NbTestCase; +import org.netbeans.junit.NbTestSuite; + + +public class MutexWrapTest extends NbTestCase implements Mutex.Wrapper { + Mutex.Privileged p; + Mutex m; + ThreadLocal IN = new ThreadLocal(); + + public MutexWrapTest(java.lang.String testName) { + super(testName); + } + + public static Test suite() { + NbTestSuite suite = new NbTestSuite(MutexWrapTest.class); + + return suite; + } + + /** Sets up the test. + */ + @Override + protected void setUp () { + p = new Mutex.Privileged (); + m = new Mutex (p, this); + } + + public void testRead() throws Exception { + A arg = new A(); + Object ret = m.readAccess(arg); + assertEquals("Return type is ok", arg, ret); + } + public void testWrite() throws Exception { + A arg = new A(); + Object ret = m.writeAccess(arg); + assertEquals("Return type is ok", arg, ret); + } + public void testExRead() throws Exception { + E arg = new E(); + Object ret = m.readAccess(arg); + assertEquals("Return type is ok", arg, ret); + } + public void testExWrite() throws Exception { + E arg = new E(); + Object ret = m.writeAccess(arg); + assertEquals("Return type is ok", arg, ret); + } + public void testPostRead() throws Exception { + R arg = new R(); + m.postReadRequest(arg); + assertTrue("Executed", arg.exec); + } + public void testPostReadFromWrite() throws Exception { + R arg = new R(); + Del del = new Del(); + del.read = arg; + m.writeAccess(del); + assertTrue("Executed", arg.exec); + } + public void testPostWrite() throws Exception { + R arg = new R(); + m.postWriteRequest(arg); + assertTrue("Executed", arg.exec); + } + public void testPostWriteFromRead() throws Exception { + R arg = new R(); + Del del = new Del(); + del.write = arg; + m.readAccess(del); + assertTrue("Executed", arg.exec); + } + + + public Runnable wrap(final Runnable run) { + return new Runnable() { + public void run() { + Object prev = IN.get(); + IN.set(MutexWrapTest.this); + try { + run.run(); + } finally { + IN.set(prev); + } + assertFalse("No read", m.isReadAccess()); + assertFalse("No write", m.isWriteAccess()); + } + }; + } + private class A implements Mutex.Action { + boolean exec; + + public Object run() { + exec = true; + assertEquals("I am wrapped", MutexWrapTest.this, IN.get()); + return this; + } + } + private class E implements Mutex.ExceptionAction { + boolean exec; + + public Object run() { + exec = true; + assertEquals("I am wrapped", MutexWrapTest.this, IN.get()); + return this; + } + } + private class R implements Runnable { + boolean exec; + + public void run() { + exec = true; + assertEquals("I am wrapped", MutexWrapTest.this, IN.get()); + } + } + private class Del implements Runnable { + Runnable write; + Runnable read; + + public void run() { + if (write != null) { + m.writeAccess(write); + } + if (read != null) { + m.writeAccess(read); + } + } + } +}