package textbender.a.u.chromography; // Copyright 2006-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.beans.*; import java.rmi.*; import java.util.*; import org.w3c.dom.*; import textbender.a.r.desk.*; import textbender.a.r.page.*; import textbender.a.r.page.navdo.*; import textbender.a.u.transfer.*; import textbender.d.gene.*; import textbender.g.hold.*; import textbender.g.lang.*; import textbender.g.util.logging.*; import textbender.g.xml.dom.*; /** Reference series loader that responds to transfers loaded in a Web page, * as detected via a user-applet. In response, * it sets a new chromograph reference series * corresponding to the transferand. */ public @ThreadSafe final class InPageFactory implements PropertyChangeListener { /** Constructs an InPageFactory. * * @param vP page visit, context * * @throws RemoteException if the chromography service is unreachable */ public InPageFactory( PageVisit vP ) throws RemoteException { pageVisit = vP; uniqueID = PageDaemons.i().connections().hostServiceRegistry().nextUniqueID(); chromography = PageDaemons.i().connections().hostServiceRegistry() .getService( Chromography.class ); transfer.localOriginRegistry().addPropertyChangeListener( InPageFactory.this ); pageVisit.spool().add( new Hold() { public @ThreadSafe void release() { transfer.localOriginRegistry().removePropertyChangeListener( InPageFactory.this ); } }); } // ------------------------------------------------------------------------------------ /** The unique identifier of this referenceSeries origin. */ public HostServiceRegistry.UniqueID uniqueID() { return uniqueID; } private final HostServiceRegistry.UniqueID uniqueID; // - P r o p e r t y - C h a n g e - L i s t e n e r ---------------------------------- public @ThreadSafe void propertyChange( final PropertyChangeEvent e ) { final Transferand transferand = (Transferand)e.getNewValue(); try { if( transferand == null ) { chromography.setReferenceSeries( null ); return; } final ArrayList leafGeneList = new ArrayList( /*initial capacity, guess*/8 ); int gIndex = transferand.gIndex0(); Node node = pageVisit.geneList().get( gIndex ); final Node nodeBound = NodeX.nextNode // just past the end ( pageVisit.geneList().get(transferand.gIndex1()), /*deeply*/false ); for( ;; ) { if( Gene.gIndexIsGene(gIndex) && !Gene.hasChildGene(node) ) { leafGeneList.add( (Element)node ); } node = NodeX.nextNode( node ); if( NodeX.nullSame( node, nodeBound )) break; if( node == null ) { assert false: "transferand bounded"; chromography.setReferenceSeries( null ); return; } gIndex = Gene.gIndexOfNode( node ); } chromography.setReferenceSeries ( new ReferenceSeries ( /*origin*/uniqueID, leafGeneList.toArray( new Element[leafGeneList.size()] ), pageVisit.gList() ) ); } catch( RemoteException x ) { LoggerX.i(getClass()).warning( x.toString() ); } // final Transferand transferand = (Transferand)e.getNewValue(); // try // { // if( transferand == null ) chromography.setReferenceSeries( null ); // else // { // int[] gIndexArray = transferand.gIndexArray(); // Element[] leafGeneArray = new Element[gIndexArray.length]; // for( int i = gIndexArray.length - 1; i >= 0; --i ) // { // leafGeneArray[i] = pageVisit.geneList().get( gIndexArray[i] ); // } // chromography.setReferenceSeries // ( new ReferenceSeries( /*origin*/uniqueID, leafGeneArray, pageVisit.gList() )); // } // } // catch( RemoteException x ) { LoggerX.i(getClass()).warning( x.toString() ); } } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final Chromography chromography; private final PageVisit pageVisit; private final PRTransferCHub transfer = PageDaemons.i().connections().transferCHub(); }