package textbender.a.r.page; // Copyright 2007, 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 java.util.concurrent.atomic.*; import javax.xml.transform.*; import textbender.g.lang.*; /** Common to page daemons, on the AWT event dispatch thread. * The single instance of PageDaemonsEDT is available via PageDaemonsEDT.i(). *

* Warning: though parts of this API are thread-safe, * that of the objects it dispenses are not. * The APIs of those objects are (at least partly) * restricted to the AWT event dispatch thread; * owing either to a specific restriction, or to general thread unsafety. *

*/ public @ThreadSafe final class PageDaemonsEDT { // Note: AWT constructs might not survive from page to page. // On Firefox 1.5, components that were persisted in static fields // have thrown AWT exceptions. They would probably do the same if persisted here. /** The single instance of PageDaemonsEDT. */ public static PageDaemonsEDT i() { return instanceA.get(); } private static final AtomicReference instanceA = new AtomicReference(); /** Creates the single instance of PageDaemonsEDT, * and makes it available via {@linkplain #i() i}(). */ PageDaemonsEDT() { if( !instanceA.compareAndSet( /*expect*/null, PageDaemonsEDT.this )) throw new IllegalStateException(); } // ------------------------------------------------------------------------------------ /** A shared transformer factory. * It has no features set (please do not set any). */ public TransformerFactory transformerFactory() { return transformerFactory; } // API unclear, but rumoured not thread-safe. private final TransformerFactory transformerFactory = TransformerFactory.newInstance(); }