package textbender.o; // Copyright 2006, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import com.sun.java.browser.dom.*; import textbender.g.lang.*; /** Utilities for the Common DOM API of the Java Plug-in. * The single instance of CommonDOM is available via CommonDOM.i(). *

* Deprecated in favour of * Rhinohide. *

*/ public @Deprecated @ThreadSafe final class CommonDOM { /** Creates the single instance of CommonDOM, * and makes it available via i(). * * @param accessor not used, except to remind you * of the thread restriction, which cannot otherwise * be tested for compliance within this constructor */ public @ThreadRestricted("DOM access dispatch") CommonDOM( DOMAccessor accessor ) { synchronized( CommonDOM.class ) // for atomic test/set { // dispatchThreadGroup = Thread.currentThread().getThreadGroup(); // if( dispatchThreadGroup == null ) throw new IllegalStateException(); dispatchThreadName = Thread.currentThread().getName(); instance = this; } } /** The single instance of CommonDOM. */ public static CommonDOM i() { return instance; } private static CommonDOM instance; // ------------------------------------------------------------------------------------ /** Returns true if the calling thread * is probably the DOM access dispatch thread. * Use this call to ensure that a given task * is being executed (or not being) on the DOM access dispatch thread. *

* Note: The method used here is imperfect. * It is intended only for assertions, during development, * to catch coding errors. *

*/ public boolean isDispatchThread() { // return Thread.currentThread().getThreadGroup().equals( dispatchThreadGroup ); // assumes it will always have the same group (which seems reasonable), and isn't used for other threads (less certain) return Thread.currentThread().getName().equals( dispatchThreadName ); // assumes it won't change (let's see), and is unique (not guaranteed) } /** A version of invokeAndWait() that throws only unchecked exceptions. * * @param service to use * @param action to invoke * * @throws RuntimeException if a DOMAccessException occurs */ public static void tryInvokeAndWait( DOMService service, DOMAction action ) { try{ service.invokeAndWait( action ); } catch( RuntimeException xR ) { throw( xR ); } catch( DOMAccessException xDOMA ) { throw new RuntimeException( xDOMA ); } } //// P r i v a t e /////////////////////////////////////////////////////////////////////// // private final ThreadGroup dispatchThreadGroup; private final String dispatchThreadName; }