Input: Called by a thread that is not the WorkerQueue thread this method queues the job and if necessary wakes up this worker queue that is waiting in { [CODESPLIT] public synchronized void putJob ( Executable job ) { // Preconditions if ( m_queueThread == null || ! m_queueThread . isAlive ( ) ) { throw new IllegalStateException ( "Can't put job, thread is not alive or not present" ) ; } if ( isInterrupted ( ) ) { throw new IllegalStateException ( "Can't put job, thread was interrupted" ) ; } putJobImpl ( job ) ; }


Input: Never call this method only override in subclasses to perform job getting in a specific way normally tied to the data structure holding the jobs . [CODESPLIT] protected Executable getJobImpl ( ) throws InterruptedException { // While the queue is empty, wait(); // when notified take an event from the queue and return it. while ( m_currentJob == null ) { wait ( ) ; } // This one is the job to return JobItem item = m_currentJob ; // Go on to the next object for the next call.  m_currentJob = m_currentJob . m_next ; return item . m_job ; }


Input: Never call this method only override in subclasses to perform job adding in a specific way normally tied to the data structure holding the jobs . [CODESPLIT] protected void putJobImpl ( Executable job ) { JobItem posted = new JobItem ( job ) ; if ( m_currentJob == null ) { // The queue is empty, set the current job to process and // wake up the thread waiting in method getJob m_currentJob = posted ; notifyAll ( ) ; } else { JobItem item = m_currentJob ; // The queue is not empty, find the end of the queue ad add the // posted job at the end while ( item . m_next != null ) { item = item . m_next ; } item . m_next = posted ; } }


Input: A utility method to convert a string name to a BlockingMode [CODESPLIT] public static final BlockingMode toBlockingMode ( String name ) { BlockingMode mode = null ; if ( name == null ) { mode = null ; } else if ( name . equalsIgnoreCase ( "run" ) ) { mode = RUN ; } else if ( name . equalsIgnoreCase ( "wait" ) ) { mode = WAIT ; } else if ( name . equalsIgnoreCase ( "discard" ) ) { mode = DISCARD ; } else if ( name . equalsIgnoreCase ( "discardOldest" ) ) { mode = DISCARD_OLDEST ; } else if ( name . equalsIgnoreCase ( "abort" ) ) { mode = ABORT ; } return mode ; }


Input: Overriden to return the indentity instance of BlockingMode based on the stream type int value . This ensures that BlockingMode enums can be compared using == . [CODESPLIT] Object readResolve ( ) throws ObjectStreamException { // Replace the marshalled instance type with the local instance BlockingMode mode = ABORT ; switch ( type ) { case RUN_TYPE : mode = RUN ; break ; case WAIT_TYPE : mode = RUN ; break ; case DISCARD_TYPE : mode = RUN ; break ; case DISCARD_OLDEST_TYPE : mode = RUN ; break ; case ABORT_TYPE : mode = RUN ; break ; } return mode ; }


Input: Create a <tt > WeakObject< / tt > for the given object . [CODESPLIT] public static WeakObject create ( final Object obj , final ReferenceQueue queue ) { if ( obj == null ) return null ; else return new WeakObject ( obj , queue ) ; }


Input: Public -------------------------------------------------------- [CODESPLIT] public Collection listMembers ( URL baseUrl , URLFilter filter ) throws IOException { return listMembers ( baseUrl , filter , false ) ; }


Input: Starting from baseUrl that should point to a directory populate the resultList with the contents that pass the filter ( in the form of URLs ) and possibly recurse into subdris not containing a . in their name . [CODESPLIT] private void listFiles ( final URL baseUrl , final URLFilter filter , boolean scanNonDottedSubDirs , ArrayList < URL > resultList ) throws IOException { // List the files at the current dir level, using the provided filter final File baseDir = new File ( baseUrl . getPath ( ) ) ; String [ ] filenames = baseDir . list ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { try { return filter . accept ( baseUrl , name ) ; } catch ( Exception e ) { log . debug ( "Unexpected exception filtering entry '" + name + "' in directory '" + baseDir + "'" , e ) ; return true ; } } } ) ; if ( filenames == null ) { // This happens only when baseDir not a directory (but this is already // checked by the caller) or some unknown IOException happens internally // (e.g. run out of file descriptors?). Unfortunately the File API // doesn't provide a way to know. throw new IOException ( "Could not list directory '" + baseDir + "', reason unknown" ) ; } else { String baseUrlString = baseUrl . toString ( ) ; for ( int i = 0 ; i < filenames . length ; i ++ ) { String filename = filenames [ i ] ; // Find out if this is a directory File file = new File ( baseDir , filename ) ; boolean isDir = file . isDirectory ( ) ; // The subUrl URL subUrl = createURL ( baseUrlString , filename , isDir ) ; // If scanning subdirs and we have a directory, not containing a '.' in // the name, recurse into it. This is to allow recursing into grouping // dirs like ./deploy/jms, ./deploy/management, etc., avoiding // at the same time exploded packages, like .sar, .war, etc. if ( scanNonDottedSubDirs && isDir && ( filename . indexOf ( ' ' ) == - 1 ) ) { // recurse into it listFiles ( subUrl , filter , scanNonDottedSubDirs , resultList ) ; } else { // just add to the list resultList . add ( subUrl ) ; } } } }


Input: Create a URL by concatenating the baseUrlString that should end at / the filename and a trailing slash if it points to a directory [CODESPLIT] private URL createURL ( String baseUrlString , String filename , boolean isDirectory ) { try { return new URL ( baseUrlString + filename + ( isDirectory ? "/" : "" ) ) ; } catch ( MalformedURLException e ) { // shouldn't happen throw new IllegalStateException ( ) ; } }


Input: Setup readers . [CODESPLIT] public void setupReaders ( ) { SAXParserFactory spf = SAXParserFactory . newInstance ( ) ; spf . setNamespaceAware ( true ) ; spf . setValidating ( false ) ; SAXCatalogReader saxReader = new SAXCatalogReader ( spf ) ; saxReader . setCatalogParser ( null , "XMLCatalog" , "org.apache.xml.resolver.readers.XCatalogReader" ) ; saxReader . setCatalogParser ( OASISXMLCatalogReader . namespaceName , "catalog" , "org.apache.xml.resolver.readers.OASISXMLCatalogReader" ) ; addReader ( "application/xml" , saxReader ) ; TR9401CatalogReader textReader = new TR9401CatalogReader ( ) ; addReader ( "text/plain" , textReader ) ; }


Input: Add a new CatalogReader to the Catalog . [CODESPLIT] public void addReader ( String mimeType , CatalogReader reader ) { if ( readerMap . containsKey ( mimeType ) ) { Integer pos = ( Integer ) readerMap . get ( mimeType ) ; readerArr . set ( pos . intValue ( ) , reader ) ; } else { readerArr . add ( reader ) ; Integer pos = new Integer ( readerArr . size ( ) - 1 ) ; readerMap . put ( mimeType , pos ) ; } }


Input: Copies the reader list from the current Catalog to a new Catalog . [CODESPLIT] protected void copyReaders ( Catalog newCatalog ) { // Have to copy the readers in the right order...convert hash to arr Vector mapArr = new Vector ( readerMap . size ( ) ) ; // Pad the mapArr out to the right length for ( int count = 0 ; count < readerMap . size ( ) ; count ++ ) { mapArr . add ( null ) ; } Enumeration enumt = readerMap . keys ( ) ; while ( enumt . hasMoreElements ( ) ) { String mimeType = ( String ) enumt . nextElement ( ) ; Integer pos = ( Integer ) readerMap . get ( mimeType ) ; mapArr . set ( pos . intValue ( ) , mimeType ) ; } for ( int count = 0 ; count < mapArr . size ( ) ; count ++ ) { String mimeType = ( String ) mapArr . get ( count ) ; Integer pos = ( Integer ) readerMap . get ( mimeType ) ; newCatalog . addReader ( mimeType , ( CatalogReader ) readerArr . get ( pos . intValue ( ) ) ) ; } }


Input: Create a new Catalog object . [CODESPLIT] protected Catalog newCatalog ( ) { String catalogClass = this . getClass ( ) . getName ( ) ; try { Catalog c = ( Catalog ) ( Class . forName ( catalogClass ) . newInstance ( ) ) ; c . setCatalogManager ( catalogManager ) ; copyReaders ( c ) ; return c ; } catch ( ClassNotFoundException cnfe ) { catalogManager . debug . message ( 1 , "Class Not Found Exception: " + catalogClass ) ; } catch ( IllegalAccessException iae ) { catalogManager . debug . message ( 1 , "Illegal Access Exception: " + catalogClass ) ; } catch ( InstantiationException ie ) { catalogManager . debug . message ( 1 , "Instantiation Exception: " + catalogClass ) ; } catch ( ClassCastException cce ) { catalogManager . debug . message ( 1 , "Class Cast Exception: " + catalogClass ) ; } catch ( Exception e ) { catalogManager . debug . message ( 1 , "Other Exception: " + catalogClass ) ; } Catalog c = new Catalog ( ) ; c . setCatalogManager ( catalogManager ) ; copyReaders ( c ) ; return c ; }


Input: Load the system catalog files . [CODESPLIT] public void loadSystemCatalogs ( ) throws MalformedURLException , IOException { Vector catalogs = catalogManager . getCatalogFiles ( ) ; if ( catalogs != null ) { for ( int count = 0 ; count < catalogs . size ( ) ; count ++ ) { catalogFiles . addElement ( catalogs . elementAt ( count ) ) ; } } if ( catalogFiles . size ( ) > 0 ) { // This is a little odd. The parseCatalog() method expects // a filename, but it adds that name to the end of the // catalogFiles vector, and then processes that vector. // This allows the system to handle CATALOG entries // correctly. // // In this init case, we take the last element off the // catalogFiles vector and pass it to parseCatalog. This // will "do the right thing" in the init case, and allow // parseCatalog() to do the right thing in the non-init // case. Honest. // String catfile = ( String ) catalogFiles . lastElement ( ) ; catalogFiles . removeElement ( catfile ) ; parseCatalog ( catfile ) ; } }


Input: Parse a catalog file augmenting internal data structures . [CODESPLIT] public synchronized void parseCatalog ( String fileName ) throws MalformedURLException , IOException { default_override = catalogManager . getPreferPublic ( ) ; catalogManager . debug . message ( 4 , "Parse catalog: " + fileName ) ; // Put the file into the list of catalogs to process... // In all cases except the case when initCatalog() is the // caller, this will be the only catalog initially in the list... catalogFiles . addElement ( fileName ) ; // Now process all the pending catalogs... parsePendingCatalogs ( ) ; }


Input: Parse a catalog file augmenting internal data structures . [CODESPLIT] public synchronized void parseCatalog ( String mimeType , InputStream is ) throws IOException , CatalogException { default_override = catalogManager . getPreferPublic ( ) ; catalogManager . debug . message ( 4 , "Parse " + mimeType + " catalog on input stream" ) ; CatalogReader reader = null ; if ( readerMap . containsKey ( mimeType ) ) { int arrayPos = ( ( Integer ) readerMap . get ( mimeType ) ) . intValue ( ) ; reader = ( CatalogReader ) readerArr . get ( arrayPos ) ; } if ( reader == null ) { String msg = "No CatalogReader for MIME type: " + mimeType ; catalogManager . debug . message ( 2 , msg ) ; throw new CatalogException ( CatalogException . UNPARSEABLE , msg ) ; } reader . readCatalog ( this , is ) ; // Now process all the pending catalogs... parsePendingCatalogs ( ) ; }


Input: Parse a catalog document augmenting internal data structures . [CODESPLIT] public synchronized void parseCatalog ( URL aUrl ) throws IOException { catalogCwd = aUrl ; base = aUrl ; default_override = catalogManager . getPreferPublic ( ) ; catalogManager . debug . message ( 4 , "Parse catalog: " + aUrl . toString ( ) ) ; DataInputStream inStream = null ; boolean parsed = false ; for ( int count = 0 ; ! parsed && count < readerArr . size ( ) ; count ++ ) { CatalogReader reader = ( CatalogReader ) readerArr . get ( count ) ; try { inStream = new DataInputStream ( aUrl . openStream ( ) ) ; } catch ( FileNotFoundException fnfe ) { // No catalog; give up! break ; } try { reader . readCatalog ( this , inStream ) ; parsed = true ; } catch ( CatalogException ce ) { if ( ce . getExceptionType ( ) == CatalogException . PARSE_FAILED ) { // give up! break ; } else { // try again! } } try { inStream . close ( ) ; } catch ( IOException e ) { //nop } } if ( parsed ) parsePendingCatalogs ( ) ; }


Input: Parse all of the pending catalogs . [CODESPLIT] protected synchronized void parsePendingCatalogs ( ) throws MalformedURLException , IOException { if ( ! localCatalogFiles . isEmpty ( ) ) { // Move all the localCatalogFiles into the front of // the catalogFiles queue Vector newQueue = new Vector ( ) ; Enumeration q = localCatalogFiles . elements ( ) ; while ( q . hasMoreElements ( ) ) { newQueue . addElement ( q . nextElement ( ) ) ; } // Put the rest of the catalogs on the end of the new list for ( int curCat = 0 ; curCat < catalogFiles . size ( ) ; curCat ++ ) { String catfile = ( String ) catalogFiles . elementAt ( curCat ) ; newQueue . addElement ( catfile ) ; } catalogFiles = newQueue ; localCatalogFiles . clear ( ) ; } // Suppose there are no catalog files to process, but the // single catalog already parsed included some delegate // entries? Make sure they don't get lost. if ( catalogFiles . isEmpty ( ) && ! localDelegate . isEmpty ( ) ) { Enumeration e = localDelegate . elements ( ) ; while ( e . hasMoreElements ( ) ) { catalogEntries . addElement ( e . nextElement ( ) ) ; } localDelegate . clear ( ) ; } // Now process all the files on the catalogFiles vector. This // vector can grow during processing if CATALOG entries are // encountered in the catalog while ( ! catalogFiles . isEmpty ( ) ) { String catfile = ( String ) catalogFiles . elementAt ( 0 ) ; try { catalogFiles . remove ( 0 ) ; } catch ( ArrayIndexOutOfBoundsException e ) { // can't happen } if ( catalogEntries . size ( ) == 0 && catalogs . size ( ) == 0 ) { // We haven't parsed any catalogs yet, let this // catalog be the first... try { parseCatalogFile ( catfile ) ; } catch ( CatalogException ce ) { System . out . println ( "FIXME: " + ce . toString ( ) ) ; } } else { // This is a subordinate catalog. We save its name, // but don't bother to load it unless it's necessary. catalogs . addElement ( catfile ) ; } if ( ! localCatalogFiles . isEmpty ( ) ) { // Move all the localCatalogFiles into the front of // the catalogFiles queue Vector newQueue = new Vector ( ) ; Enumeration q = localCatalogFiles . elements ( ) ; while ( q . hasMoreElements ( ) ) { newQueue . addElement ( q . nextElement ( ) ) ; } // Put the rest of the catalogs on the end of the new list for ( int curCat = 0 ; curCat < catalogFiles . size ( ) ; curCat ++ ) { catfile = ( String ) catalogFiles . elementAt ( curCat ) ; newQueue . addElement ( catfile ) ; } catalogFiles = newQueue ; localCatalogFiles . clear ( ) ; } if ( ! localDelegate . isEmpty ( ) ) { Enumeration e = localDelegate . elements ( ) ; while ( e . hasMoreElements ( ) ) { catalogEntries . addElement ( e . nextElement ( ) ) ; } localDelegate . clear ( ) ; } } // We've parsed them all, reinit the vector... catalogFiles . clear ( ) ; }


Input: Parse a single catalog file augmenting internal data structures . [CODESPLIT] protected synchronized void parseCatalogFile ( String fileName ) throws MalformedURLException , IOException , CatalogException { // The base-base is the cwd. If the catalog file is specified // with a relative path, this assures that it gets resolved // properly... try { // tack on a basename because URLs point to files not dirs String userdir = fixSlashes ( System . getProperty ( "user.dir" ) ) ; catalogCwd = new URL ( "file:" + userdir + "/basename" ) ; } catch ( MalformedURLException e ) { String userdir = fixSlashes ( System . getProperty ( "user.dir" ) ) ; catalogManager . debug . message ( 1 , "Malformed URL on cwd" , userdir ) ; catalogCwd = null ; } // The initial base URI is the location of the catalog file try { base = new URL ( catalogCwd , fixSlashes ( fileName ) ) ; } catch ( MalformedURLException e ) { try { base = new URL ( "file:" + fixSlashes ( fileName ) ) ; } catch ( MalformedURLException e2 ) { catalogManager . debug . message ( 1 , "Malformed URL on catalog filename" , fixSlashes ( fileName ) ) ; base = null ; } } catalogManager . debug . message ( 2 , "Loading catalog" , fileName ) ; catalogManager . debug . message ( 4 , "Default BASE" , base . toString ( ) ) ; fileName = base . toString ( ) ; DataInputStream inStream = null ; boolean parsed = false ; boolean notFound = false ; for ( int count = 0 ; ! parsed && count < readerArr . size ( ) ; count ++ ) { CatalogReader reader = ( CatalogReader ) readerArr . get ( count ) ; try { notFound = false ; inStream = new DataInputStream ( base . openStream ( ) ) ; } catch ( FileNotFoundException fnfe ) { // No catalog; give up! notFound = true ; break ; } try { reader . readCatalog ( this , inStream ) ; parsed = true ; } catch ( CatalogException ce ) { if ( ce . getExceptionType ( ) == CatalogException . PARSE_FAILED ) { // give up! break ; } else { // try again! } } try { inStream . close ( ) ; } catch ( IOException e ) { //nop } } if ( ! parsed ) { if ( notFound ) { catalogManager . debug . message ( 3 , "Catalog does not exist" , fileName ) ; } else { catalogManager . debug . message ( 1 , "Failed to parse catalog" , fileName ) ; } } }


Input: Cleanup and process a Catalog entry . [CODESPLIT] public void addEntry ( CatalogEntry entry ) { int type = entry . getEntryType ( ) ; if ( type == BASE ) { String value = entry . getEntryArg ( 0 ) ; URL newbase = null ; catalogManager . debug . message ( 5 , "BASE CUR" , base . toString ( ) ) ; catalogManager . debug . message ( 4 , "BASE STR" , value ) ; try { value = fixSlashes ( value ) ; newbase = new URL ( base , value ) ; } catch ( MalformedURLException e ) { try { newbase = new URL ( "file:" + value ) ; } catch ( MalformedURLException e2 ) { catalogManager . debug . message ( 1 , "Malformed URL on base" , value ) ; newbase = null ; } } if ( newbase != null ) { base = newbase ; } catalogManager . debug . message ( 5 , "BASE NEW" , base . toString ( ) ) ; } else if ( type == CATALOG ) { String fsi = makeAbsolute ( entry . getEntryArg ( 0 ) ) ; catalogManager . debug . message ( 4 , "CATALOG" , fsi ) ; localCatalogFiles . addElement ( fsi ) ; } else if ( type == PUBLIC ) { String publicid = PublicId . normalize ( entry . getEntryArg ( 0 ) ) ; String systemid = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 0 , publicid ) ; entry . setEntryArg ( 1 , systemid ) ; catalogManager . debug . message ( 4 , "PUBLIC" , publicid , systemid ) ; catalogEntries . addElement ( entry ) ; } else if ( type == SYSTEM ) { String systemid = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "SYSTEM" , systemid , fsi ) ; catalogEntries . addElement ( entry ) ; } else if ( type == URI ) { String uri = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String altURI = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , altURI ) ; catalogManager . debug . message ( 4 , "URI" , uri , altURI ) ; catalogEntries . addElement ( entry ) ; } else if ( type == DOCUMENT ) { String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 0 ) ) ) ; entry . setEntryArg ( 0 , fsi ) ; catalogManager . debug . message ( 4 , "DOCUMENT" , fsi ) ; catalogEntries . addElement ( entry ) ; } else if ( type == OVERRIDE ) { catalogManager . debug . message ( 4 , "OVERRIDE" , entry . getEntryArg ( 0 ) ) ; catalogEntries . addElement ( entry ) ; } else if ( type == SGMLDECL ) { // meaningless in XML String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 0 ) ) ) ; entry . setEntryArg ( 0 , fsi ) ; catalogManager . debug . message ( 4 , "SGMLDECL" , fsi ) ; catalogEntries . addElement ( entry ) ; } else if ( type == DELEGATE_PUBLIC ) { String ppi = PublicId . normalize ( entry . getEntryArg ( 0 ) ) ; String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 0 , ppi ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "DELEGATE_PUBLIC" , ppi , fsi ) ; addDelegate ( entry ) ; } else if ( type == DELEGATE_SYSTEM ) { String psi = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 0 , psi ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "DELEGATE_SYSTEM" , psi , fsi ) ; addDelegate ( entry ) ; } else if ( type == DELEGATE_URI ) { String pui = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 0 , pui ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "DELEGATE_URI" , pui , fsi ) ; addDelegate ( entry ) ; } else if ( type == REWRITE_SYSTEM ) { String psi = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String rpx = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 0 , psi ) ; entry . setEntryArg ( 1 , rpx ) ; catalogManager . debug . message ( 4 , "REWRITE_SYSTEM" , psi , rpx ) ; catalogEntries . addElement ( entry ) ; } else if ( type == REWRITE_URI ) { String pui = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String upx = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 0 , pui ) ; entry . setEntryArg ( 1 , upx ) ; catalogManager . debug . message ( 4 , "REWRITE_URI" , pui , upx ) ; catalogEntries . addElement ( entry ) ; } else if ( type == DOCTYPE ) { String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "DOCTYPE" , entry . getEntryArg ( 0 ) , fsi ) ; catalogEntries . addElement ( entry ) ; } else if ( type == DTDDECL ) { // meaningless in XML String fpi = PublicId . normalize ( entry . getEntryArg ( 0 ) ) ; entry . setEntryArg ( 0 , fpi ) ; String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "DTDDECL" , fpi , fsi ) ; catalogEntries . addElement ( entry ) ; } else if ( type == ENTITY ) { String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "ENTITY" , entry . getEntryArg ( 0 ) , fsi ) ; catalogEntries . addElement ( entry ) ; } else if ( type == LINKTYPE ) { // meaningless in XML String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "LINKTYPE" , entry . getEntryArg ( 0 ) , fsi ) ; catalogEntries . addElement ( entry ) ; } else if ( type == NOTATION ) { String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "NOTATION" , entry . getEntryArg ( 0 ) , fsi ) ; catalogEntries . addElement ( entry ) ; } else { catalogEntries . addElement ( entry ) ; } }


Input: Handle unknown CatalogEntry types . [CODESPLIT] public void unknownEntry ( Vector strings ) { if ( strings != null && strings . size ( ) > 0 ) { String keyword = ( String ) strings . elementAt ( 0 ) ; catalogManager . debug . message ( 2 , "Unrecognized token parsing catalog" , keyword ) ; } }


Input: Parse all subordinate catalogs . [CODESPLIT] public void parseAllCatalogs ( ) throws MalformedURLException , IOException { // Parse all the subordinate catalogs for ( int catPos = 0 ; catPos < catalogs . size ( ) ; catPos ++ ) { Catalog c = null ; try { c = ( Catalog ) catalogs . elementAt ( catPos ) ; } catch ( ClassCastException e ) { String catfile = ( String ) catalogs . elementAt ( catPos ) ; c = newCatalog ( ) ; c . parseCatalog ( catfile ) ; catalogs . setElementAt ( c , catPos ) ; c . parseAllCatalogs ( ) ; } } // Parse all the DELEGATE catalogs Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == DELEGATE_PUBLIC || e . getEntryType ( ) == DELEGATE_SYSTEM || e . getEntryType ( ) == DELEGATE_URI ) { Catalog dcat = newCatalog ( ) ; dcat . parseCatalog ( e . getEntryArg ( 1 ) ) ; } } }


Input: Return the applicable DOCTYPE system identifier . [CODESPLIT] public String resolveDoctype ( String entityName , String publicId , String systemId ) throws MalformedURLException , IOException { String resolved = null ; catalogManager . debug . message ( 3 , "resolveDoctype(" + entityName + "," + publicId + "," + systemId + ")" ) ; systemId = normalizeURI ( systemId ) ; if ( publicId != null && publicId . startsWith ( "urn:publicid:" ) ) { publicId = PublicId . decodeURN ( publicId ) ; } if ( systemId != null && systemId . startsWith ( "urn:publicid:" ) ) { systemId = PublicId . decodeURN ( systemId ) ; if ( publicId != null && ! publicId . equals ( systemId ) ) { catalogManager . debug . message ( 1 , "urn:publicid: system identifier differs from public identifier; using public identifier" ) ; systemId = null ; } else { publicId = systemId ; systemId = null ; } } if ( systemId != null ) { // If there's a SYSTEM entry in this catalog, use it resolved = resolveLocalSystem ( systemId ) ; if ( resolved != null ) { return resolved ; } } if ( publicId != null ) { // If there's a PUBLIC entry in this catalog, use it resolved = resolveLocalPublic ( DOCTYPE , entityName , publicId , systemId ) ; if ( resolved != null ) { return resolved ; } } // If there's a DOCTYPE entry in this catalog, use it boolean over = default_override ; Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == OVERRIDE ) { over = e . getEntryArg ( 0 ) . equalsIgnoreCase ( "YES" ) ; continue ; } if ( e . getEntryType ( ) == DOCTYPE && e . getEntryArg ( 0 ) . equals ( entityName ) ) { if ( over || systemId == null ) { return e . getEntryArg ( 1 ) ; } } } // Otherwise, look in the subordinate catalogs return resolveSubordinateCatalogs ( DOCTYPE , entityName , publicId , systemId ) ; }


Input: Return the applicable DOCUMENT entry . [CODESPLIT] public String resolveDocument ( ) throws MalformedURLException , IOException { // If there's a DOCUMENT entry, return it catalogManager . debug . message ( 3 , "resolveDocument" ) ; Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == DOCUMENT ) { return e . getEntryArg ( 1 ) ; //FIXME check this } } return resolveSubordinateCatalogs ( DOCUMENT , null , null , null ) ; }


Input: Return the applicable PUBLIC or SYSTEM identifier . [CODESPLIT] public String resolvePublic ( String publicId , String systemId ) throws MalformedURLException , IOException { catalogManager . debug . message ( 3 , "resolvePublic(" + publicId + "," + systemId + ")" ) ; systemId = normalizeURI ( systemId ) ; if ( publicId != null && publicId . startsWith ( "urn:publicid:" ) ) { publicId = PublicId . decodeURN ( publicId ) ; } if ( systemId != null && systemId . startsWith ( "urn:publicid:" ) ) { systemId = PublicId . decodeURN ( systemId ) ; if ( publicId != null && ! publicId . equals ( systemId ) ) { catalogManager . debug . message ( 1 , "urn:publicid: system identifier differs from public identifier; using public identifier" ) ; systemId = null ; } else { publicId = systemId ; systemId = null ; } } // If there's a SYSTEM entry in this catalog, use it if ( systemId != null ) { String resolved = resolveLocalSystem ( systemId ) ; if ( resolved != null ) { return resolved ; } } // If there's a PUBLIC entry in this catalog, use it String resolved = resolveLocalPublic ( PUBLIC , null , publicId , systemId ) ; if ( resolved != null ) { return resolved ; } // Otherwise, look in the subordinate catalogs return resolveSubordinateCatalogs ( PUBLIC , null , publicId , systemId ) ; }


Input: Return the applicable PUBLIC or SYSTEM identifier . [CODESPLIT] protected synchronized String resolveLocalPublic ( int entityType , String entityName , String publicId , String systemId ) throws MalformedURLException , IOException { // Always normalize the public identifier before attempting a match publicId = PublicId . normalize ( publicId ) ; // If there's a SYSTEM entry in this catalog, use it if ( systemId != null ) { String resolved = resolveLocalSystem ( systemId ) ; if ( resolved != null ) { return resolved ; } } // If there's a PUBLIC entry in this catalog, use it boolean over = default_override ; Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == OVERRIDE ) { over = e . getEntryArg ( 0 ) . equalsIgnoreCase ( "YES" ) ; continue ; } if ( e . getEntryType ( ) == PUBLIC && e . getEntryArg ( 0 ) . equals ( publicId ) ) { if ( over || systemId == null ) { return e . getEntryArg ( 1 ) ; } } } // If there's a DELEGATE_PUBLIC entry in this catalog, use it over = default_override ; enumt = catalogEntries . elements ( ) ; Vector delCats = new Vector ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == OVERRIDE ) { over = e . getEntryArg ( 0 ) . equalsIgnoreCase ( "YES" ) ; continue ; } if ( e . getEntryType ( ) == DELEGATE_PUBLIC && ( over || systemId == null ) ) { String p = e . getEntryArg ( 0 ) ; if ( p . length ( ) <= publicId . length ( ) && p . equals ( publicId . substring ( 0 , p . length ( ) ) ) ) { // delegate this match to the other catalog delCats . addElement ( e . getEntryArg ( 1 ) ) ; } } } if ( delCats . size ( ) > 0 ) { Enumeration enumCats = delCats . elements ( ) ; if ( catalogManager . debug . getDebug ( ) > 1 ) { catalogManager . debug . message ( 2 , "Switching to delegated catalog(s):" ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; catalogManager . debug . message ( 2 , "\t" + delegatedCatalog ) ; } } Catalog dcat = newCatalog ( ) ; enumCats = delCats . elements ( ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; dcat . parseCatalog ( delegatedCatalog ) ; } return dcat . resolvePublic ( publicId , null ) ; } // Nada! return null ; }


Input: Return the applicable SYSTEM system identifier . [CODESPLIT] public String resolveSystem ( String systemId ) throws MalformedURLException , IOException { catalogManager . debug . message ( 3 , "resolveSystem(" + systemId + ")" ) ; systemId = normalizeURI ( systemId ) ; if ( systemId != null && systemId . startsWith ( "urn:publicid:" ) ) { systemId = PublicId . decodeURN ( systemId ) ; return resolvePublic ( systemId , null ) ; } // If there's a SYSTEM entry in this catalog, use it if ( systemId != null ) { String resolved = resolveLocalSystem ( systemId ) ; if ( resolved != null ) { return resolved ; } } // Otherwise, look in the subordinate catalogs return resolveSubordinateCatalogs ( SYSTEM , null , null , systemId ) ; }


Input: Return the applicable SYSTEM system identifier in this catalog . [CODESPLIT] protected String resolveLocalSystem ( String systemId ) throws MalformedURLException , IOException { String osname = System . getProperty ( "os.name" ) ; boolean windows = ( osname . indexOf ( "Windows" ) >= 0 ) ; Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == SYSTEM && ( e . getEntryArg ( 0 ) . equals ( systemId ) || ( windows && e . getEntryArg ( 0 ) . equalsIgnoreCase ( systemId ) ) ) ) { return e . getEntryArg ( 1 ) ; } } // If there's a REWRITE_SYSTEM entry in this catalog, use it enumt = catalogEntries . elements ( ) ; String startString = null ; String prefix = null ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == REWRITE_SYSTEM ) { String p = e . getEntryArg ( 0 ) ; if ( p . length ( ) <= systemId . length ( ) && p . equals ( systemId . substring ( 0 , p . length ( ) ) ) ) { // Is this the longest prefix? if ( startString == null || p . length ( ) > startString . length ( ) ) { startString = p ; prefix = e . getEntryArg ( 1 ) ; } } } if ( prefix != null ) { // return the systemId with the new prefix return prefix + systemId . substring ( startString . length ( ) ) ; } } // If there's a DELEGATE_SYSTEM entry in this catalog, use it enumt = catalogEntries . elements ( ) ; Vector delCats = new Vector ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == DELEGATE_SYSTEM ) { String p = e . getEntryArg ( 0 ) ; if ( p . length ( ) <= systemId . length ( ) && p . equals ( systemId . substring ( 0 , p . length ( ) ) ) ) { // delegate this match to the other catalog delCats . addElement ( e . getEntryArg ( 1 ) ) ; } } } if ( delCats . size ( ) > 0 ) { Enumeration enumCats = delCats . elements ( ) ; if ( catalogManager . debug . getDebug ( ) > 1 ) { catalogManager . debug . message ( 2 , "Switching to delegated catalog(s):" ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; catalogManager . debug . message ( 2 , "\t" + delegatedCatalog ) ; } } Catalog dcat = newCatalog ( ) ; enumCats = delCats . elements ( ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; dcat . parseCatalog ( delegatedCatalog ) ; } return dcat . resolveSystem ( systemId ) ; } return null ; }


Input: Return the applicable URI . [CODESPLIT] public String resolveURI ( String uri ) throws MalformedURLException , IOException { catalogManager . debug . message ( 3 , "resolveURI(" + uri + ")" ) ; uri = normalizeURI ( uri ) ; if ( uri != null && uri . startsWith ( "urn:publicid:" ) ) { uri = PublicId . decodeURN ( uri ) ; return resolvePublic ( uri , null ) ; } // If there's a URI entry in this catalog, use it if ( uri != null ) { String resolved = resolveLocalURI ( uri ) ; if ( resolved != null ) { return resolved ; } } // Otherwise, look in the subordinate catalogs return resolveSubordinateCatalogs ( URI , null , null , uri ) ; }


Input: Return the applicable URI in this catalog . [CODESPLIT] protected String resolveLocalURI ( String uri ) throws MalformedURLException , IOException { Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == URI && ( e . getEntryArg ( 0 ) . equals ( uri ) ) ) { return e . getEntryArg ( 1 ) ; } } // If there's a REWRITE_URI entry in this catalog, use it enumt = catalogEntries . elements ( ) ; String startString = null ; String prefix = null ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == REWRITE_URI ) { String p = e . getEntryArg ( 0 ) ; if ( p . length ( ) <= uri . length ( ) && p . equals ( uri . substring ( 0 , p . length ( ) ) ) ) { // Is this the longest prefix? if ( startString == null || p . length ( ) > startString . length ( ) ) { startString = p ; prefix = e . getEntryArg ( 1 ) ; } } } if ( prefix != null ) { // return the systemId with the new prefix return prefix + uri . substring ( startString . length ( ) ) ; } } // If there's a DELEGATE_URI entry in this catalog, use it enumt = catalogEntries . elements ( ) ; Vector delCats = new Vector ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == DELEGATE_URI ) { String p = e . getEntryArg ( 0 ) ; if ( p . length ( ) <= uri . length ( ) && p . equals ( uri . substring ( 0 , p . length ( ) ) ) ) { // delegate this match to the other catalog delCats . addElement ( e . getEntryArg ( 1 ) ) ; } } } if ( delCats . size ( ) > 0 ) { Enumeration enumCats = delCats . elements ( ) ; if ( catalogManager . debug . getDebug ( ) > 1 ) { catalogManager . debug . message ( 2 , "Switching to delegated catalog(s):" ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; catalogManager . debug . message ( 2 , "\t" + delegatedCatalog ) ; } } Catalog dcat = newCatalog ( ) ; enumCats = delCats . elements ( ) ; while ( enumCats . hasMoreElements ( ) ) { String delegatedCatalog = ( String ) enumCats . nextElement ( ) ; dcat . parseCatalog ( delegatedCatalog ) ; } return dcat . resolveURI ( uri ) ; } return null ; }


Input: Search the subordinate catalogs in order looking for a match . [CODESPLIT] protected synchronized String resolveSubordinateCatalogs ( int entityType , String entityName , String publicId , String systemId ) throws MalformedURLException , IOException { for ( int catPos = 0 ; catPos < catalogs . size ( ) ; catPos ++ ) { Catalog c = null ; try { c = ( Catalog ) catalogs . elementAt ( catPos ) ; } catch ( ClassCastException e ) { String catfile = ( String ) catalogs . elementAt ( catPos ) ; c = newCatalog ( ) ; try { c . parseCatalog ( catfile ) ; } catch ( MalformedURLException mue ) { catalogManager . debug . message ( 1 , "Malformed Catalog URL" , catfile ) ; } catch ( FileNotFoundException fnfe ) { catalogManager . debug . message ( 1 , "Failed to load catalog, file not found" , catfile ) ; } catch ( IOException ioe ) { catalogManager . debug . message ( 1 , "Failed to load catalog, I/O error" , catfile ) ; } catalogs . setElementAt ( c , catPos ) ; } String resolved = null ; // Ok, now what are we supposed to call here? if ( entityType == DOCTYPE ) { resolved = c . resolveDoctype ( entityName , publicId , systemId ) ; } else if ( entityType == DOCUMENT ) { resolved = c . resolveDocument ( ) ; } else if ( entityType == ENTITY ) { resolved = c . resolveEntity ( entityName , publicId , systemId ) ; } else if ( entityType == NOTATION ) { resolved = c . resolveNotation ( entityName , publicId , systemId ) ; } else if ( entityType == PUBLIC ) { resolved = c . resolvePublic ( publicId , systemId ) ; } else if ( entityType == SYSTEM ) { resolved = c . resolveSystem ( systemId ) ; } else if ( entityType == URI ) { resolved = c . resolveURI ( systemId ) ; } if ( resolved != null ) { return resolved ; } } return null ; }


Input: Construct an absolute URI from a relative one using the current base URI . [CODESPLIT] protected String makeAbsolute ( String sysid ) { URL local = null ; sysid = fixSlashes ( sysid ) ; try { local = new URL ( base , sysid ) ; } catch ( MalformedURLException e ) { catalogManager . debug . message ( 1 , "Malformed URL on system identifier" , sysid ) ; } if ( local != null ) { return local . toString ( ) ; } else { return sysid ; } }


Input: Perform character normalization on a URI reference . [CODESPLIT] protected String normalizeURI ( String uriref ) { String newRef = "" ; byte [ ] bytes ; if ( uriref == null ) { return null ; } try { bytes = uriref . getBytes ( "UTF-8" ) ; } catch ( UnsupportedEncodingException uee ) { // this can't happen catalogManager . debug . message ( 1 , "UTF-8 is an unsupported encoding!?" ) ; return uriref ; } for ( int count = 0 ; count < bytes . length ; count ++ ) { int ch = bytes [ count ] & 0xFF ; if ( ( ch <= 0x20 ) // ctrl || ( ch > 0x7F ) // high ascii || ( ch == 0x22 ) // " || ( ch == 0x3C ) // < || ( ch == 0x3E ) // > || ( ch == 0x5C ) // \ || ( ch == 0x5E ) // ^ || ( ch == 0x60 ) // ` || ( ch == 0x7B ) // { || ( ch == 0x7C ) // | || ( ch == 0x7D ) // } || ( ch == 0x7F ) ) { newRef += encodedByte ( ch ) ; } else { newRef += ( char ) bytes [ count ] ; } } return newRef ; }


Input: Perform % - encoding on a single byte . [CODESPLIT] protected String encodedByte ( int b ) { String hex = Integer . toHexString ( b ) . toUpperCase ( ) ; if ( hex . length ( ) < 2 ) { return "%0" + hex ; } else { return "%" + hex ; } }


Input: Add to the current list of delegated catalogs . [CODESPLIT] protected void addDelegate ( CatalogEntry entry ) { int pos = 0 ; String partial = entry . getEntryArg ( 0 ) ; Enumeration local = localDelegate . elements ( ) ; while ( local . hasMoreElements ( ) ) { CatalogEntry dpe = ( CatalogEntry ) local . nextElement ( ) ; String dp = dpe . getEntryArg ( 0 ) ; if ( dp . equals ( partial ) ) { // we already have this prefix return ; } if ( dp . length ( ) > partial . length ( ) ) { pos ++ ; } if ( dp . length ( ) < partial . length ( ) ) { break ; } } // now insert partial into the vector at [pos] if ( localDelegate . size ( ) == 0 ) { localDelegate . addElement ( entry ) ; } else { localDelegate . insertElementAt ( entry , pos ) ; } }


Input: Create a server socket on the specified port ( port 0 indicates an anonymous port ) . [CODESPLIT] public Socket createSocket ( String host , int port ) throws IOException { Socket s = new Socket ( host , port ) ; s . setSoTimeout ( 1000 ) ; TimeoutSocket ts = new TimeoutSocket ( s ) ; return ts ; }


Input: Build a int [] from comma or eol seperated elements [CODESPLIT] public void setAsText ( final String text ) { StringTokenizer stok = new StringTokenizer ( text , ",\r\n" ) ; int [ ] theValue = new int [ stok . countTokens ( ) ] ; int i = 0 ; while ( stok . hasMoreTokens ( ) ) { theValue [ i ++ ] = Integer . decode ( stok . nextToken ( ) ) . intValue ( ) ; } setValue ( theValue ) ; }


Input: Safely create a new SoftValueRef [CODESPLIT] static < K , V > SoftValueRef < K , V > create ( K key , V val , ReferenceQueue < V > q ) { if ( val == null ) return null ; else return new SoftValueRef < K , V > ( key , val , q ) ; }


Input: Returns a Properties object initialized with current getAsText value interpretted as a . properties file contents . This replaces any references of the form $ { x } with the corresponding system property . [CODESPLIT] public Object getValue ( ) { try { // Load the current key=value properties into a Properties object String propsText = getAsText ( ) ; Properties rawProps = new Properties ( System . getProperties ( ) ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( propsText . getBytes ( ) ) ; rawProps . load ( bais ) ; // Now go through the rawProps and replace any ${x} refs Properties props = new Properties ( ) ; Iterator keys = rawProps . keySet ( ) . iterator ( ) ; while ( keys . hasNext ( ) ) { String key = ( String ) keys . next ( ) ; String value = rawProps . getProperty ( key ) ; String value2 = StringPropertyReplacer . replaceProperties ( value , rawProps ) ; props . setProperty ( key , value2 ) ; } rawProps . clear ( ) ; return props ; } catch ( IOException e ) { throw new NestedRuntimeException ( e ) ; } }


Input: Fire onThrowable to all registered listeners . [CODESPLIT] protected static void fireOnThrowable ( int type , Throwable t ) { Object [ ] list = listeners . toArray ( ) ; for ( int i = 0 ; i < list . length ; i ++ ) { ( ( ThrowableListener ) list [ i ] ) . onThrowable ( type , t ) ; } }


Input: Add a throwable that is to be handled . [CODESPLIT] public static void add ( int type , Throwable t ) { // don't add null throwables if ( t == null ) return ; try { fireOnThrowable ( type , t ) ; } catch ( Throwable bad ) { // don't let these propagate, that could introduce unwanted side-effects System . err . println ( "Unable to handle throwable: " + t + " because of:" ) ; bad . printStackTrace ( ) ; } }


Input: Create the list implementation [CODESPLIT] private List < T > createImplementation ( ) { if ( delegate instanceof ArrayList == false ) return new ArrayList < T > ( delegate ) ; return delegate ; }


Input: Add an element to the set . [CODESPLIT] public boolean add ( final Object obj ) { boolean added = false ; if ( ! list . contains ( obj ) ) { added = list . add ( obj ) ; } return added ; }


Input: Create a server socket on the specified port ( port 0 indicates an anonymous port ) . [CODESPLIT] public Socket createSocket ( String host , int port ) throws IOException { try { permits . acquire ( ) ; return new Socket ( host , port ) ; } catch ( InterruptedException ex ) { throw new IOException ( "Failed to acquire FIFOSemaphore for ClientSocketFactory" ) ; } finally { permits . release ( ) ; } }


Input: Create a server socket on the specified port ( port 0 indicates an anonymous port ) . [CODESPLIT] public Socket createSocket ( String host , int port ) throws IOException { InetAddress addr = null ; if ( bindAddress != null ) addr = bindAddress ; else addr = InetAddress . getByName ( host ) ; Socket s = new Socket ( addr , port ) ; return s ; }


Input: A TimerTask is less than another if it will be scheduled before . [CODESPLIT] public int compareTo ( Object other ) { if ( other == this ) return 0 ; TimerTask t = ( TimerTask ) other ; long diff = getNextExecutionTime ( ) - t . getNextExecutionTime ( ) ; return ( int ) diff ; }


Input: Returns a InetAddress for the input object converted to a string . [CODESPLIT] public Object getValue ( ) { try { String text = getAsText ( ) ; if ( text == null ) { return null ; } if ( text . startsWith ( "/" ) ) { // seems like localhost sometimes will look like: // /127.0.0.1 and the getByNames barfs on the slash - JGH text = text . substring ( 1 ) ; } return InetAddress . getByName ( StringPropertyReplacer . replaceProperties ( text ) ) ; } catch ( UnknownHostException e ) { throw new NestedRuntimeException ( e ) ; } }


Input: Check if a file is acceptible . [CODESPLIT] public boolean accept ( final File file ) { boolean success = false ; for ( int i = 0 ; i < suffixes . length && ! success ; i ++ ) { if ( ignoreCase ) success = file . getName ( ) . toLowerCase ( ) . endsWith ( suffixes [ i ] ) ; else success = file . getName ( ) . endsWith ( suffixes [ i ] ) ; } return success ; }


Input: Dereference the object at the given index . [CODESPLIT] private Object getObject ( final int index ) { Object obj = list . get ( index ) ; return Objects . deref ( obj ) ; }


Input: Replaces the element at the specified position in this list with the specified element . [CODESPLIT] public Object set ( final int index , final Object obj ) { maintain ( ) ; SoftObject soft = SoftObject . create ( obj , queue ) ; soft = ( SoftObject ) list . set ( index , soft ) ; return Objects . deref ( soft ) ; }


Input: Inserts the specified element at the specified position in this list ( optional operation ) . Shifts the element currently at that position ( if any ) and any subsequent elements to the right ( adds one to their indices ) . [CODESPLIT] public void add ( final int index , final Object obj ) { maintain ( ) ; SoftObject soft = SoftObject . create ( obj , queue ) ; list . add ( index , soft ) ; }


Input: Removes the element at the specified position in this list ( optional operation ) . Shifts any subsequent elements to the left ( subtracts one from their indices ) . Returns the element that was removed from the list . [CODESPLIT] public Object remove ( final int index ) { maintain ( ) ; Object obj = list . remove ( index ) ; return Objects . deref ( obj ) ; }


Input: Maintains the collection by removing garbage collected objects . [CODESPLIT] private void maintain ( ) { SoftObject obj ; int count = 0 ; while ( ( obj = ( SoftObject ) queue . poll ( ) ) != null ) { count ++ ; list . remove ( obj ) ; } if ( count != 0 ) { // some temporary debugging fluff System . err . println ( "vm reclaimed " + count + " objects" ) ; } }


Input: Adds a new catalog entry type . [CODESPLIT] public static int addEntryType ( String name , int numArgs ) { entryTypes . put ( name , new Integer ( nextEntry ) ) ; entryArgs . add ( nextEntry , new Integer ( numArgs ) ) ; nextEntry ++ ; return nextEntry - 1 ; }


Input: Lookup an entry type [CODESPLIT] public static int getEntryType ( String name ) throws CatalogException { if ( ! entryTypes . containsKey ( name ) ) { throw new CatalogException ( CatalogException . INVALID_ENTRY_TYPE ) ; } Integer iType = ( Integer ) entryTypes . get ( name ) ; if ( iType == null ) { throw new CatalogException ( CatalogException . INVALID_ENTRY_TYPE ) ; } return iType . intValue ( ) ; }


Input: Find out how many arguments an entry is required to have . [CODESPLIT] public static int getEntryArgCount ( int type ) throws CatalogException { try { Integer iArgs = ( Integer ) entryArgs . get ( type ) ; return iArgs . intValue ( ) ; } catch ( ArrayIndexOutOfBoundsException e ) { throw new CatalogException ( CatalogException . INVALID_ENTRY_TYPE ) ; } }


Input: Get an entry argument . [CODESPLIT] public String getEntryArg ( int argNum ) { try { String arg = ( String ) args . get ( argNum ) ; return arg ; } catch ( ArrayIndexOutOfBoundsException e ) { return null ; } }


Input: Inserts the given element in this heap . @param obj [CODESPLIT] public void insert ( Object obj ) { int length = m_nodes . length ; // Expand if necessary if ( m_count == length ) { Object [ ] newNodes = new Object [ length + length ] ; System . arraycopy ( m_nodes , 0 , newNodes , 0 , length ) ; m_nodes = newNodes ; } // Be cur_slot the first unused slot index; be par_slot its parent index. // Start from cur_slot and walk up the tree comparing the object to  // insert with the object at par_slot; if it's smaller move down the object at par_slot, // otherwise cur_slot is the index where insert the object. If not done,  // shift up the tree so that now cur_slot is the old par_slot and  // par_slot is the parent index of the new cur_slot (so the grand-parent // index of the old cur_slot) and compare again. int k = m_count ; while ( k > 0 ) { int par = parent ( k ) ; if ( compare ( obj , m_nodes [ par ] ) < 0 ) { m_nodes [ k ] = m_nodes [ par ] ; k = par ; } else break ; } m_nodes [ k ] = obj ; ++ m_count ; }


Input: Removes and returns the least element of this heap . @return the extracted object [CODESPLIT] public Object extract ( ) { if ( m_count < 1 ) { return null ; } else { int length = m_nodes . length >> 1 ; // Shrink if necessary if ( length > 5 && m_count < ( length >> 1 ) ) { Object [ ] newNodes = new Object [ length ] ; System . arraycopy ( m_nodes , 0 , newNodes , 0 , length ) ; m_nodes = newNodes ; } // int k = 0 ; Object ret = m_nodes [ k ] ; -- m_count ; Object last = m_nodes [ m_count ] ; for ( ; ; ) { int l = left ( k ) ; if ( l >= m_count ) { break ; } else { int r = right ( k ) ; int child = ( r >= m_count || compare ( m_nodes [ l ] , m_nodes [ r ] ) < 0 ) ? l : r ; if ( compare ( last , m_nodes [ child ] ) > 0 ) { m_nodes [ k ] = m_nodes [ child ] ; k = child ; } else { break ; } } } m_nodes [ k ] = last ; m_nodes [ m_count ] = null ; return ret ; } }


Input: Map the argument text into and Byte using Byte . decode . [CODESPLIT] public void setAsText ( final String text ) { if ( PropertyEditors . isNull ( text , false , false ) ) { setValue ( null ) ; return ; } Object newValue = text . getBytes ( ) ; setValue ( newValue ) ; }


Input: Set the context classloader for the given thread [CODESPLIT] public void setContextClassLoader ( final Thread thread , final ClassLoader cl ) { AccessController . doPrivileged ( new PrivilegedAction ( ) { public Object run ( ) { thread . setContextClassLoader ( cl ) ; return null ; } } ) ; }


Input: A new node has been added at index <code > index< / code > . Normalize the tree by moving the new node up the tree . [CODESPLIT] private boolean normalizeUp ( int index ) { // INV: assertExpr(index > 0); // INV: assertExpr(index <= size); // INV: assertExpr(queue[index] != null); if ( index == 1 ) return false ; // at root boolean ret = false ; long t = queue [ index ] . time ; int p = index >> 1 ; while ( queue [ p ] . time > t ) { // INV: assertExpr(queue[index].time == t); swap ( p , index ) ; ret = true ; if ( p == 1 ) break ; // at root index = p ; p >>= 1 ; } return ret ; }


Input: Swap two nodes in the tree . [CODESPLIT] private void swap ( int a , int b ) { // INV: assertExpr(a > 0); // INV: assertExpr(a <= size); // INV: assertExpr(b > 0); // INV: assertExpr(b <= size); // INV: assertExpr(queue[a] != null); // INV: assertExpr(queue[b] != null); // INV: assertExpr(queue[a].index == a); // INV: assertExpr(queue[b].index == b); TimeoutExtImpl temp = queue [ a ] ; queue [ a ] = queue [ b ] ; queue [ a ] . index = a ; queue [ b ] = temp ; queue [ b ] . index = b ; }


Input: Remove a node from the tree and normalize . [CODESPLIT] private TimeoutExtImpl removeNode ( int index ) { // INV: assertExpr(index > 0); // INV: assertExpr(index <= size); TimeoutExtImpl res = queue [ index ] ; // INV: assertExpr(res != null); // INV: assertExpr(res.index == index); if ( index == size ) { -- size ; queue [ index ] = null ; return res ; } swap ( index , size ) ; // Exchange removed node with last leaf node -- size ; // INV: assertExpr(res.index == size + 1); queue [ res . index ] = null ; if ( normalizeUp ( index ) ) return res ; // Node moved up, so it shouldn't move down long t = queue [ index ] . time ; int c = index << 1 ; while ( c <= size ) { // INV: assertExpr(q[index].time == t); TimeoutExtImpl l = queue [ c ] ; // INV: assertExpr(l != null); // INV: assertExpr(l.index == c); if ( c + 1 <= size ) { // two children, swap with smallest TimeoutExtImpl r = queue [ c + 1 ] ; // INV: assertExpr(r != null); // INV: assertExpr(r.index == c+1); if ( l . time <= r . time ) { if ( t <= l . time ) break ; // done swap ( index , c ) ; index = c ; } else { if ( t <= r . time ) break ; // done swap ( index , c + 1 ) ; index = c + 1 ; } } else { // one child if ( t <= l . time ) break ; // done swap ( index , c ) ; index = c ; } c = index << 1 ; } return res ; }


Input: Recursive cleanup of a TimeoutImpl [CODESPLIT] private TimeoutExtImpl cleanupTimeoutExtImpl ( TimeoutExtImpl timeout ) { if ( timeout != null ) timeout . target = null ; return null ; }


Input:
Check invariants of the queue . [CODESPLIT] void checkTree ( ) { assertExpr ( size >= 0 ) ; assertExpr ( size < queue . length ) ; assertExpr ( queue [ 0 ] == null ) ; if ( size > 0 ) { assertExpr ( queue [ 1 ] != null ) ; assertExpr ( queue [ 1 ] . index == 1 ) ; for ( int i = 2 ; i <= size ; ++ i ) { assertExpr ( queue [ i ] != null ) ; assertExpr ( queue [ i ] . index == i ) ; assertExpr ( queue [ i >> 1 ] . time <= queue [ i ] . time ) ; // parent fires first } for ( int i = size + 1 ; i < queue . length ; ++ i ) assertExpr ( queue [ i ] == null ) ; } } /**
    * Debugging helper.
    */ private void assertExpr ( boolean expr ) { if ( ! expr ) throw new IllegalStateException ( "***** assert failed *****" ) ; } /**
    *  Our private Timeout implementation.
    */ private class TimeoutExtImpl implements TimeoutExt { /** Done */ static final int DONE = - 1 ; /** In timeout */ static final int TIMEOUT = - 2 ; /** Index in the queue */ int index ; /** Time of the timeout */ long time ; /** The timeout target */ TimeoutTarget target ; public long getTime ( ) { return time ; } public TimeoutTarget getTimeoutTarget ( ) { return target ; } public void done ( ) { index = DONE ; } public boolean cancel ( ) { return remove ( this ) ; } } }


Input: Load a class by asking the parent [CODESPLIT] protected Class < ? > loadClass ( String className , boolean resolve ) throws ClassNotFoundException { // Revert to standard rules if ( standard ) return super . loadClass ( className , resolve ) ; // Ask the parent Class < ? > clazz = null ; try { clazz = parent . loadClass ( className ) ; } catch ( ClassNotFoundException e ) { // Not found in parent, // maybe it is a proxy registered against this classloader? clazz = findLoadedClass ( className ) ; if ( clazz == null ) throw e ; } // Link the class if ( resolve ) resolveClass ( clazz ) ; return clazz ; }


Input: Preload the JBoss specific protocol handlers so that URL knows about them even if the handler factory is changed . [CODESPLIT] @ SuppressWarnings ( "unused" ) public static void preload ( ) { for ( int i = 0 ; i < PROTOCOLS . length ; i ++ ) { try { URL url = new URL ( PROTOCOLS [ i ] , "" , - 1 , "" ) ; log . trace ( "Loaded protocol: " + PROTOCOLS [ i ] ) ; } catch ( Exception e ) { log . warn ( "Failed to load protocol: " + PROTOCOLS [ i ] , e ) ; } } }


Input: Search the handlerPkgs for URLStreamHandler classes matching the pkg + protocol + . Handler naming convention . [CODESPLIT] public URLStreamHandler createURLStreamHandler ( final String protocol ) { // Check the handler map URLStreamHandler handler = ( URLStreamHandler ) handlerMap . get ( protocol ) ; if ( handler != null ) return handler ; // Validate that createURLStreamHandler is not recursing String prevProtocol = ( String ) createURLStreamHandlerProtocol . get ( ) ; if ( prevProtocol != null && prevProtocol . equals ( protocol ) ) return null ; createURLStreamHandlerProtocol . set ( protocol ) ; // See if the handler pkgs definition has changed checkHandlerPkgs ( ) ; // Search the handlerPkgs for a matching protocol handler ClassLoader ctxLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; for ( int p = 0 ; p < handlerPkgs . length ; p ++ ) { try { // Form the standard protocol handler class name String classname = handlerPkgs [ p ] + "." + protocol + ".Handler" ; Class < ? > type = null ; try { type = ctxLoader . loadClass ( classname ) ; } catch ( ClassNotFoundException e ) { // Try our class loader type = Class . forName ( classname ) ; } if ( type != null ) { handler = ( URLStreamHandler ) type . newInstance ( ) ; handlerMap . put ( protocol , handler ) ; log . trace ( "Found protocol:" + protocol + " handler:" + handler ) ; } } catch ( Throwable ignore ) { } } createURLStreamHandlerProtocol . set ( null ) ; return handler ; }


Input: See if the java . protocol . handler . pkgs system property has changed and if it has parse it to update the handlerPkgs array . [CODESPLIT] private synchronized void checkHandlerPkgs ( ) { String handlerPkgsProp = System . getProperty ( "java.protocol.handler.pkgs" ) ; if ( handlerPkgsProp != null && handlerPkgsProp . equals ( lastHandlerPkgs ) == false ) { // Update the handlerPkgs[] from the handlerPkgsProp StringTokenizer tokeninzer = new StringTokenizer ( handlerPkgsProp , "|" ) ; ArrayList < String > tmp = new ArrayList < String > ( ) ; while ( tokeninzer . hasMoreTokens ( ) ) { String pkg = tokeninzer . nextToken ( ) . intern ( ) ; if ( tmp . contains ( pkg ) == false ) tmp . add ( pkg ) ; } // Include the JBoss default protocol handler pkg if ( tmp . contains ( PACKAGE_PREFIX ) == false ) tmp . add ( PACKAGE_PREFIX ) ; handlerPkgs = new String [ tmp . size ( ) ] ; tmp . toArray ( handlerPkgs ) ; lastHandlerPkgs = handlerPkgsProp ; } }


Input: Returns a Class for the input object converted to a string . [CODESPLIT] public Object getValue ( ) { try { ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; String classname = getAsText ( ) ; Class < ? > type = loader . loadClass ( classname ) ; return type ; } catch ( Exception e ) { throw new NestedRuntimeException ( e ) ; } }


Input: Create the set implementation [CODESPLIT] private Set < T > createImplementation ( ) { if ( delegate instanceof HashSet == false ) return new HashSet < T > ( delegate ) ; return delegate ; }


Input: Attempt to close an array of <tt > InputStream< / tt > s . [CODESPLIT] public static boolean close ( final InputStream [ ] streams ) { boolean success = true ; for ( int i = 0 ; i < streams . length ; i ++ ) { boolean rv = close ( streams [ i ] ) ; if ( ! rv ) success = false ; } return success ; }


Input: Return a synchronized counter . [CODESPLIT] public static LongCounter makeSynchronized ( final LongCounter counter ) { return new Wrapper ( counter ) { /** The serialVersionUID */ private static final long serialVersionUID = 8903330696503363758L ; public synchronized long increment ( ) { return this . counter . increment ( ) ; } public synchronized long decrement ( ) { return this . counter . decrement ( ) ; } public synchronized long getCount ( ) { return this . counter . getCount ( ) ; } public synchronized void reset ( ) { this . counter . reset ( ) ; } public synchronized int hashCode ( ) { return this . counter . hashCode ( ) ; } public synchronized boolean equals ( final Object obj ) { return this . counter . equals ( obj ) ; } public synchronized String toString ( ) { return this . counter . toString ( ) ; } public synchronized Object clone ( ) { return this . counter . clone ( ) ; } } ; }


Input: Returns a directional counter . [CODESPLIT] public static LongCounter makeDirectional ( final LongCounter counter , final boolean increasing ) { LongCounter temp ; if ( increasing ) { temp = new Wrapper ( counter ) { /** The serialVersionUID */ private static final long serialVersionUID = - 8902748795144754375L ; public long decrement ( ) { throw new UnsupportedOperationException ( ) ; } public void reset ( ) { throw new UnsupportedOperationException ( ) ; } } ; } else { temp = new Wrapper ( counter ) { /** The serialVersionUID */ private static final long serialVersionUID = 2584758778978644599L ; public long increment ( ) { throw new UnsupportedOperationException ( ) ; } } ; } return temp ; }


Input: Are we in an extension namespace? [CODESPLIT] protected boolean inExtensionNamespace ( ) { boolean inExtension = false ; Enumeration elements = namespaceStack . elements ( ) ; while ( ! inExtension && elements . hasMoreElements ( ) ) { String ns = ( String ) elements . nextElement ( ) ; if ( ns == null ) { inExtension = true ; } else { inExtension = ( ! ns . equals ( tr9401NamespaceName ) && ! ns . equals ( namespaceName ) ) ; } } return inExtension ; }


Input: The SAX <code > startDocument< / code > method does nothing . [CODESPLIT] public void startDocument ( ) throws SAXException { baseURIStack . push ( catalog . getCurrentBase ( ) ) ; overrideStack . push ( catalog . getDefaultOverride ( ) ) ; return ; }


Input: The SAX <code > startElement< / code > method recognizes elements from the plain catalog format and instantiates CatalogEntry objects for them . [CODESPLIT] public void startElement ( String namespaceURI , String localName , String qName , Attributes atts ) throws SAXException { int entryType = - 1 ; Vector entryArgs = new Vector ( ) ; namespaceStack . push ( namespaceURI ) ; boolean inExtension = inExtensionNamespace ( ) ; if ( namespaceURI != null && namespaceName . equals ( namespaceURI ) && ! inExtension ) { // This is an XML Catalog entry if ( atts . getValue ( "xml:base" ) != null ) { String baseURI = atts . getValue ( "xml:base" ) ; entryType = Catalog . BASE ; entryArgs . add ( baseURI ) ; baseURIStack . push ( baseURI ) ; debug . message ( 4 , "xml:base" , baseURI ) ; try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { debug . message ( 1 , "Invalid catalog entry (base)" , localName ) ; } } entryType = - 1 ; entryArgs = new Vector ( ) ; } else { baseURIStack . push ( baseURIStack . peek ( ) ) ; } if ( ( localName . equals ( "catalog" ) || localName . equals ( "group" ) ) && atts . getValue ( "prefer" ) != null ) { String override = atts . getValue ( "prefer" ) ; if ( override . equals ( "public" ) ) { override = "yes" ; } else if ( override . equals ( "system" ) ) { override = "no" ; } else { debug . message ( 1 , "Invalid prefer: must be 'system' or 'public'" , localName ) ; override = catalog . getDefaultOverride ( ) ; } entryType = Catalog . OVERRIDE ; entryArgs . add ( override ) ; overrideStack . push ( override ) ; debug . message ( 4 , "override" , override ) ; try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { debug . message ( 1 , "Invalid catalog entry (override)" , localName ) ; } } entryType = - 1 ; entryArgs = new Vector ( ) ; } else { overrideStack . push ( overrideStack . peek ( ) ) ; } if ( localName . equals ( "delegatePublic" ) ) { if ( checkAttributes ( atts , "publicIdStartString" , "catalog" ) ) { entryType = Catalog . DELEGATE_PUBLIC ; entryArgs . add ( atts . getValue ( "publicIdStartString" ) ) ; entryArgs . add ( atts . getValue ( "catalog" ) ) ; debug . message ( 4 , "delegatePublic" , PublicId . normalize ( atts . getValue ( "publicIdStartString" ) ) , atts . getValue ( "catalog" ) ) ; } } else if ( localName . equals ( "delegateSystem" ) ) { if ( checkAttributes ( atts , "systemIdStartString" , "catalog" ) ) { entryType = Catalog . DELEGATE_SYSTEM ; entryArgs . add ( atts . getValue ( "systemIdStartString" ) ) ; entryArgs . add ( atts . getValue ( "catalog" ) ) ; debug . message ( 4 , "delegateSystem" , atts . getValue ( "systemIdStartString" ) , atts . getValue ( "catalog" ) ) ; } } else if ( localName . equals ( "delegateURI" ) ) { if ( checkAttributes ( atts , "uriStartString" , "catalog" ) ) { entryType = Catalog . DELEGATE_URI ; entryArgs . add ( atts . getValue ( "uriStartString" ) ) ; entryArgs . add ( atts . getValue ( "catalog" ) ) ; debug . message ( 4 , "delegateURI" , atts . getValue ( "uriStartString" ) , atts . getValue ( "catalog" ) ) ; } } else if ( localName . equals ( "rewriteSystem" ) ) { if ( checkAttributes ( atts , "systemIdStartString" , "rewritePrefix" ) ) { entryType = Catalog . REWRITE_SYSTEM ; entryArgs . add ( atts . getValue ( "systemIdStartString" ) ) ; entryArgs . add ( atts . getValue ( "rewritePrefix" ) ) ; debug . message ( 4 , "rewriteSystem" , atts . getValue ( "systemIdStartString" ) , atts . getValue ( "rewritePrefix" ) ) ; } } else if ( localName . equals ( "rewriteURI" ) ) { if ( checkAttributes ( atts , "uriStartString" , "rewritePrefix" ) ) { entryType = Catalog . REWRITE_URI ; entryArgs . add ( atts . getValue ( "uriStartString" ) ) ; entryArgs . add ( atts . getValue ( "rewritePrefix" ) ) ; debug . message ( 4 , "rewriteURI" , atts . getValue ( "uriStartString" ) , atts . getValue ( "rewritePrefix" ) ) ; } } else if ( localName . equals ( "nextCatalog" ) ) { if ( checkAttributes ( atts , "catalog" ) ) { entryType = Catalog . CATALOG ; entryArgs . add ( atts . getValue ( "catalog" ) ) ; debug . message ( 4 , "nextCatalog" , atts . getValue ( "catalog" ) ) ; } } else if ( localName . equals ( "public" ) ) { if ( checkAttributes ( atts , "publicId" , "uri" ) ) { entryType = Catalog . PUBLIC ; entryArgs . add ( atts . getValue ( "publicId" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; debug . message ( 4 , "public" , PublicId . normalize ( atts . getValue ( "publicId" ) ) , atts . getValue ( "uri" ) ) ; } } else if ( localName . equals ( "system" ) ) { if ( checkAttributes ( atts , "systemId" , "uri" ) ) { entryType = Catalog . SYSTEM ; entryArgs . add ( atts . getValue ( "systemId" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; debug . message ( 4 , "system" , atts . getValue ( "systemId" ) , atts . getValue ( "uri" ) ) ; } } else if ( localName . equals ( "uri" ) ) { if ( checkAttributes ( atts , "name" , "uri" ) ) { entryType = Catalog . URI ; entryArgs . add ( atts . getValue ( "name" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; debug . message ( 4 , "uri" , atts . getValue ( "name" ) , atts . getValue ( "uri" ) ) ; } } else if ( localName . equals ( "catalog" ) ) { // nop, start of catalog } else if ( localName . equals ( "group" ) ) { // nop, a group } else { // This is equivalent to an invalid catalog entry type debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } if ( entryType >= 0 ) { try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { debug . message ( 1 , "Invalid catalog entry" , localName ) ; } } } } if ( namespaceURI != null && tr9401NamespaceName . equals ( namespaceURI ) && ! inExtension ) { // This is a TR9401 Catalog entry if ( atts . getValue ( "xml:base" ) != null ) { String baseURI = atts . getValue ( "xml:base" ) ; entryType = Catalog . BASE ; entryArgs . add ( baseURI ) ; baseURIStack . push ( baseURI ) ; debug . message ( 4 , "xml:base" , baseURI ) ; try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { debug . message ( 1 , "Invalid catalog entry (base)" , localName ) ; } } entryType = - 1 ; entryArgs = new Vector ( ) ; } else { baseURIStack . push ( baseURIStack . peek ( ) ) ; } if ( localName . equals ( "doctype" ) ) { entryType = catalog . DOCTYPE ; entryArgs . add ( atts . getValue ( "name" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; } else if ( localName . equals ( "document" ) ) { entryType = catalog . DOCUMENT ; entryArgs . add ( atts . getValue ( "uri" ) ) ; } else if ( localName . equals ( "dtddecl" ) ) { entryType = catalog . DTDDECL ; entryArgs . add ( atts . getValue ( "publicId" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; } else if ( localName . equals ( "entity" ) ) { entryType = Catalog . ENTITY ; entryArgs . add ( atts . getValue ( "name" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; } else if ( localName . equals ( "linktype" ) ) { entryType = Catalog . LINKTYPE ; entryArgs . add ( atts . getValue ( "name" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; } else if ( localName . equals ( "notation" ) ) { entryType = Catalog . NOTATION ; entryArgs . add ( atts . getValue ( "name" ) ) ; entryArgs . add ( atts . getValue ( "uri" ) ) ; } else if ( localName . equals ( "sgmldecl" ) ) { entryType = Catalog . SGMLDECL ; entryArgs . add ( atts . getValue ( "uri" ) ) ; } else { // This is equivalent to an invalid catalog entry type debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } if ( entryType >= 0 ) { try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { debug . message ( 1 , "Invalid catalog entry" , localName ) ; } } } } }


Input: The SAX <code > endElement< / code > method does nothing . [CODESPLIT] public void endElement ( String namespaceURI , String localName , String qName ) throws SAXException { int entryType = - 1 ; Vector entryArgs = new Vector ( ) ; boolean inExtension = inExtensionNamespace ( ) ; if ( namespaceURI != null && ! inExtension && ( namespaceName . equals ( namespaceURI ) || tr9401NamespaceName . equals ( namespaceURI ) ) ) { String popURI = ( String ) baseURIStack . pop ( ) ; String baseURI = ( String ) baseURIStack . peek ( ) ; if ( ! baseURI . equals ( popURI ) ) { entryType = catalog . BASE ; entryArgs . add ( baseURI ) ; debug . message ( 4 , "(reset) xml:base" , baseURI ) ; try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { debug . message ( 1 , "Invalid catalog entry (rbase)" , localName ) ; } } } } if ( namespaceURI != null && namespaceName . equals ( namespaceURI ) && ! inExtension ) { if ( localName . equals ( "catalog" ) || localName . equals ( "group" ) ) { String popOverride = ( String ) overrideStack . pop ( ) ; String override = ( String ) overrideStack . peek ( ) ; if ( ! override . equals ( popOverride ) ) { entryType = catalog . OVERRIDE ; entryArgs . add ( override ) ; overrideStack . push ( override ) ; debug . message ( 4 , "(reset) override" , override ) ; try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { debug . message ( 1 , "Invalid catalog entry (roverride)" , localName ) ; } } } } } namespaceStack . pop ( ) ; return ; }


Input: Checks whether a notification is required and notifies as appropriate [CODESPLIT] public void checkNotification ( int result ) { // Is a notification required? chunk += result ; if ( chunk >= chunkSize ) { if ( listener != null ) listener . onStreamNotification ( this , chunk ) ; // Start a new chunk chunk = 0 ; } }


Input: Lookup a value from the NonSerializableFactory map . [CODESPLIT] public static Object lookup ( String key ) { Object value = wrapperMap . get ( key ) ; return value ; }


Input: Lookup a value from the NonSerializableFactory map . [CODESPLIT] public static Object lookup ( Name name ) { String key = name . toString ( ) ; Object value = wrapperMap . get ( key ) ; return value ; }


Input: A convenience method that simplifies the process of rebinding a non - serializable object into a JNDI context . [CODESPLIT] public static synchronized void rebind ( Context ctx , String key , Object target ) throws NamingException { NonSerializableFactory . rebind ( key , target ) ; // Bind a reference to target using NonSerializableFactory as the ObjectFactory String className = target . getClass ( ) . getName ( ) ; String factory = NonSerializableFactory . class . getName ( ) ; StringRefAddr addr = new StringRefAddr ( "nns" , key ) ; Reference memoryRef = new Reference ( className , addr , factory , null ) ; ctx . rebind ( key , memoryRef ) ; }


Input: A convenience method that simplifies the process of rebinding a non - serializable object into a JNDI context . [CODESPLIT] public static synchronized void rebind ( Context ctx , String key , Object target , boolean createSubcontexts ) throws NamingException { Name name = ctx . getNameParser ( "" ) . parse ( key ) ; if ( createSubcontexts == true && name . size ( ) > 1 ) { int size = name . size ( ) - 1 ; Util . createSubcontext ( ctx , name . getPrefix ( size ) ) ; } rebind ( ctx , key , target ) ; }


Input: A convenience method that simplifies the process of rebinding a non - serializable object into a JNDI context . This version binds the target object into the default IntitialContext using name path . [CODESPLIT] public static synchronized void rebind ( Name name , Object target , boolean createSubcontexts ) throws NamingException { String key = name . toString ( ) ; InitialContext ctx = new InitialContext ( ) ; if ( createSubcontexts == true && name . size ( ) > 1 ) { int size = name . size ( ) - 1 ; Util . createSubcontext ( ctx , name . getPrefix ( size ) ) ; } rebind ( ctx , key , target ) ; }


Input: Transform the obj Reference bound into the JNDI namespace into the actual non - Serializable object . [CODESPLIT] public Object getObjectInstance ( Object obj , Name name , Context nameCtx , Hashtable env ) throws Exception { // Get the nns value from the Reference obj and use it as the map key Reference ref = ( Reference ) obj ; RefAddr addr = ref . get ( "nns" ) ; String key = ( String ) addr . getContent ( ) ; Object target = wrapperMap . get ( key ) ; return target ; }


Input: Substitute sub - strings in side of a string . [CODESPLIT] public static String subst ( final StringBuffer buff , final String string , final Map map , final String beginToken , final String endToken ) { int begin = 0 , rangeEnd = 0 ; Range range ; while ( ( range = rangeOf ( beginToken , endToken , string , rangeEnd ) ) != null ) { // append the first part of the string buff . append ( string . substring ( begin , range . begin ) ) ; // Get the string to replace from the map String key = string . substring ( range . begin + beginToken . length ( ) , range . end ) ; Object value = map . get ( key ) ; // if mapping does not exist then use empty; if ( value == null ) value = EMPTY ; // append the replaced string buff . append ( value ) ; // update positions begin = range . end + endToken . length ( ) ; rangeEnd = begin ; } // append the rest of the string buff . append ( string . substring ( begin , string . length ( ) ) ) ; return buff . toString ( ) ; }


Input: Split up a string into multiple strings based on a delimiter . [CODESPLIT] public static String [ ] split ( final String string , final String delim , final int limit ) { // get the count of delim in string, if count is > limit  // then use limit for count.  The number of delimiters is less by one // than the number of elements, so add one to count. int count = count ( string , delim ) + 1 ; if ( limit > 0 && count > limit ) { count = limit ; } String strings [ ] = new String [ count ] ; int begin = 0 ; for ( int i = 0 ; i < count ; i ++ ) { // get the next index of delim int end = string . indexOf ( delim , begin ) ; // if the end index is -1 or if this is the last element // then use the string's length for the end index if ( end == - 1 || i + 1 == count ) end = string . length ( ) ; // if end is 0, then the first element is empty if ( end == 0 ) strings [ i ] = EMPTY ; else strings [ i ] = string . substring ( begin , end ) ; // update the begining index begin = end + 1 ; } return strings ; }


Input: Convert and join an array of bytes into one string . [CODESPLIT] public static String join ( final byte array [ ] ) { Byte bytes [ ] = new Byte [ array . length ] ; for ( int i = 0 ; i < bytes . length ; i ++ ) { bytes [ i ] = new Byte ( array [ i ] ) ; } return join ( bytes , null ) ; }


Input: The default toString implementation of an object [CODESPLIT] public static final void defaultToString ( JBossStringBuilder buffer , Object object ) { if ( object == null ) buffer . append ( "null" ) ; else { buffer . append ( object . getClass ( ) . getName ( ) ) ; buffer . append ( ' ' ) ; buffer . append ( Integer . toHexString ( System . identityHashCode ( object ) ) ) ; } }


Input: Trim all occurences of the supplied leading character from the given String . [CODESPLIT] public static String trimLeadingCharacter ( String str , final char leadingCharacter ) { return trimLeadingCharacter ( str , new CharacterChecker ( ) { public boolean isCharacterLegal ( char character ) { return character == leadingCharacter ; } } ) ; }


Input: Trim all occurences of the supplied leading character from the given String . [CODESPLIT] public static String trimLeadingCharacter ( String str , CharacterChecker checker ) { if ( hasLength ( str ) == false ) { return str ; } if ( checker == null ) throw new IllegalArgumentException ( "Null character checker" ) ; StringBuffer buf = new StringBuffer ( str ) ; while ( buf . length ( ) > 0 && checker . isCharacterLegal ( buf . charAt ( 0 ) ) ) { buf . deleteCharAt ( 0 ) ; } return buf . toString ( ) ; }


Input: Returns a BlockingMode for the input object converted to a string . [CODESPLIT] public Object getValue ( ) { String text = getAsText ( ) ; BlockingMode mode = BlockingMode . toBlockingMode ( text ) ; return mode ; }


Input: Check if a file is acceptible . [CODESPLIT] public boolean accept ( final File dir , final String name ) { if ( ignoreCase ) { return name . toLowerCase ( ) . endsWith ( suffix ) ; } else { return name . endsWith ( suffix ) ; } }


Input: Initializes the cache for use . Prior to this the cache has no store . [CODESPLIT] public void create ( ) { if ( threadSafe ) entryMap = Collections . synchronizedMap ( new HashMap ( ) ) ; else entryMap = new HashMap ( ) ; now = System . currentTimeMillis ( ) ; }


Input: Get the cache value for key if it has not expired . If the TimedEntry is expired its destroy method is called and then removed from the cache . [CODESPLIT] public Object get ( Object key ) { TimedEntry entry = ( TimedEntry ) entryMap . get ( key ) ; if ( entry == null ) return null ; if ( entry . isCurrent ( now ) == false ) { // Try to refresh the entry if ( entry . refresh ( ) == false ) { // Failed, remove the entry and return null entry . destroy ( ) ; entryMap . remove ( key ) ; return null ; } } Object value = entry . getValue ( ) ; return value ; }


Input: Get the cache value for key . This method does not check to see if the entry has expired . [CODESPLIT] public Object peek ( Object key ) { TimedEntry entry = ( TimedEntry ) entryMap . get ( key ) ; Object value = null ; if ( entry != null ) value = entry . getValue ( ) ; return value ; }


Input: Insert a value into the cache . In order to have the cache entry reshresh itself value would have to implement TimedEntry and implement the required refresh () method logic . [CODESPLIT] public void insert ( Object key , Object value ) { if ( entryMap . containsKey ( key ) ) throw new IllegalStateException ( "Attempt to insert duplicate entry" ) ; TimedEntry entry = null ; if ( ( value instanceof TimedEntry ) == false ) { // Wrap the value in a DefaultTimedEntry entry = new DefaultTimedEntry ( defaultLifetime , value ) ; } else { entry = ( TimedEntry ) value ; } entry . init ( now ) ; entryMap . put ( key , entry ) ; }


Input: Remove the entry associated with key and call destroy on the entry if found . [CODESPLIT] public void remove ( Object key ) { TimedEntry entry = ( TimedEntry ) entryMap . remove ( key ) ; if ( entry != null ) entry . destroy ( ) ; }


Input: Remove all entries from the cache . [CODESPLIT] public void flush ( ) { Map tmpMap = null ; synchronized ( this ) { tmpMap = entryMap ; if ( threadSafe ) entryMap = Collections . synchronizedMap ( new HashMap ( ) ) ; else entryMap = new HashMap ( ) ; } // Notify the entries of their removal Iterator iter = tmpMap . values ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { TimedEntry entry = ( TimedEntry ) iter . next ( ) ; entry . destroy ( ) ; } tmpMap . clear ( ) ; }


Input: Get the list of keys for entries that are not expired . [CODESPLIT] public List getValidKeys ( ) { ArrayList validKeys = new ArrayList ( ) ; synchronized ( entryMap ) { Iterator iter = entryMap . entrySet ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) iter . next ( ) ; TimedEntry value = ( TimedEntry ) entry . getValue ( ) ; if ( value . isCurrent ( now ) == true ) validKeys . add ( entry . getKey ( ) ) ; } } return validKeys ; }


Input: Set the cache timer resolution [CODESPLIT] public synchronized void setResolution ( int resolution ) { if ( resolution <= 0 ) resolution = 60 ; if ( resolution != this . resolution ) { this . resolution = resolution ; theTimer . cancel ( ) ; theTimer = new ResolutionTimer ( ) ; resolutionTimer . scheduleAtFixedRate ( theTimer , 0 , 1000 * resolution ) ; } }


Input: Get the raw TimedEntry for key without performing any expiration check . [CODESPLIT] public TimedEntry peekEntry ( Object key ) { TimedEntry entry = ( TimedEntry ) entryMap . get ( key ) ; return entry ; }


Input: Returns an iterator over the children of the given element with the given tag name . [CODESPLIT] public static Iterator getChildrenByTagName ( Element element , String tagName ) { if ( element == null ) return null ; // getElementsByTagName gives the corresponding elements in the whole  // descendance. We want only children NodeList children = element . getChildNodes ( ) ; ArrayList goodChildren = new ArrayList ( ) ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { Node currentChild = children . item ( i ) ; if ( currentChild . getNodeType ( ) == Node . ELEMENT_NODE && ( ( Element ) currentChild ) . getTagName ( ) . equals ( tagName ) ) { goodChildren . add ( currentChild ) ; } } return goodChildren . iterator ( ) ; }


Input: Gets the child of the specified element having the specified unique name . If there are more than one children elements with the same name and exception is thrown . [CODESPLIT] public static Element getUniqueChild ( Element element , String tagName ) throws Exception { Iterator goodChildren = getChildrenByTagName ( element , tagName ) ; if ( goodChildren != null && goodChildren . hasNext ( ) ) { Element child = ( Element ) goodChildren . next ( ) ; if ( goodChildren . hasNext ( ) ) { throw new Exception ( "expected only one " + tagName + " tag" ) ; } return child ; } else { throw new Exception ( "expected one " + tagName + " tag" ) ; } }


Input: Gets the child of the specified element having the specified name . If the child with this name doesn t exist then null is returned instead . [CODESPLIT] public static Element getOptionalChild ( Element element , String tagName ) throws Exception { return getOptionalChild ( element , tagName , null ) ; }


Input: Get the content of the given element . [CODESPLIT] public static String getElementContent ( Element element , String defaultStr ) throws Exception { if ( element == null ) return defaultStr ; NodeList children = element . getChildNodes ( ) ; String result = "" ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { if ( children . item ( i ) . getNodeType ( ) == Node . TEXT_NODE || children . item ( i ) . getNodeType ( ) == Node . CDATA_SECTION_NODE ) { result += children . item ( i ) . getNodeValue ( ) ; } else if ( children . item ( i ) . getNodeType ( ) == Node . COMMENT_NODE ) { // Ignore comment nodes } } return result . trim ( ) ; }


Input: Macro to get the content of a unique child element . [CODESPLIT] public static String getUniqueChildContent ( Element element , String tagName ) throws Exception { return getElementContent ( getUniqueChild ( element , tagName ) ) ; }


Input: Macro to get the content of an optional child element . [CODESPLIT] public static String getOptionalChildContent ( Element element , String tagName ) throws Exception { return getElementContent ( getOptionalChild ( element , tagName ) ) ; }


Input: ThreadPool ---------------------------------------------------- [CODESPLIT] public void stop ( boolean immediate ) { log . debug ( "stop, immediate=" + immediate ) ; stopped . set ( true ) ; if ( immediate ) executor . shutdownNow ( ) ; else executor . shutdown ( ) ; }


Input: This resets the work queue capacity . This requires recreating the work queue and ThreadPoolExecutor so this needs to be called before doing any work with the pool . [CODESPLIT] public void setMaximumQueueSize ( int size ) { // Reset the executor work queue ArrayList tmp = new ArrayList ( ) ; queue . drainTo ( tmp ) ; queue = new LinkedBlockingQueue ( size ) ; queue . addAll ( tmp ) ; ThreadFactory tf = executor . getThreadFactory ( ) ; RejectedExecutionHandler handler = executor . getRejectedExecutionHandler ( ) ; long keepAlive = executor . getKeepAliveTime ( TimeUnit . SECONDS ) ; int cs = executor . getCorePoolSize ( ) ; int mcs = executor . getMaximumPoolSize ( ) ; executor = new ThreadPoolExecutor ( cs , mcs , keepAlive , TimeUnit . SECONDS , queue ) ; executor . setThreadFactory ( tf ) ; executor . setRejectedExecutionHandler ( handler ) ; }


Input: For backward compatibility with the previous string based mode [CODESPLIT] public void setBlockingMode ( String name ) { blockingMode = BlockingMode . toBlockingMode ( name ) ; if ( blockingMode == null ) blockingMode = BlockingMode . ABORT ; }


Input: For backward compatibility with the previous string based mode This is needed for microcontainer as it gets confused with overloaded setters . [CODESPLIT] public void setBlockingModeString ( String name ) { blockingMode = BlockingMode . toBlockingMode ( name ) ; if ( blockingMode == null ) blockingMode = BlockingMode . ABORT ; }


Input: Execute a task [CODESPLIT] protected void execute ( TaskWrapper wrapper ) { if ( trace ) log . trace ( "execute, wrapper=" + wrapper ) ; try { executor . execute ( wrapper ) ; } catch ( Throwable t ) { wrapper . rejectTask ( new ThreadPoolFullException ( "Error scheduling work: " + wrapper , t ) ) ; } }


Input: The SAX <code > startElement< / code > method recognizes elements from the plain catalog format and instantiates CatalogEntry objects for them . [CODESPLIT] public void startElement ( String namespaceURI , String localName , String qName , Attributes atts ) throws SAXException { int entryType = - 1 ; Vector entryArgs = new Vector ( ) ; if ( localName . equals ( "Base" ) ) { entryType = catalog . BASE ; entryArgs . add ( atts . getValue ( "HRef" ) ) ; catalog . getCatalogManager ( ) . debug . message ( 4 , "Base" , atts . getValue ( "HRef" ) ) ; } else if ( localName . equals ( "Delegate" ) ) { entryType = catalog . DELEGATE_PUBLIC ; entryArgs . add ( atts . getValue ( "PublicId" ) ) ; entryArgs . add ( atts . getValue ( "HRef" ) ) ; catalog . getCatalogManager ( ) . debug . message ( 4 , "Delegate" , PublicId . normalize ( atts . getValue ( "PublicId" ) ) , atts . getValue ( "HRef" ) ) ; } else if ( localName . equals ( "Extend" ) ) { entryType = catalog . CATALOG ; entryArgs . add ( atts . getValue ( "HRef" ) ) ; catalog . getCatalogManager ( ) . debug . message ( 4 , "Extend" , atts . getValue ( "HRef" ) ) ; } else if ( localName . equals ( "Map" ) ) { entryType = catalog . PUBLIC ; entryArgs . add ( atts . getValue ( "PublicId" ) ) ; entryArgs . add ( atts . getValue ( "HRef" ) ) ; catalog . getCatalogManager ( ) . debug . message ( 4 , "Map" , PublicId . normalize ( atts . getValue ( "PublicId" ) ) , atts . getValue ( "HRef" ) ) ; } else if ( localName . equals ( "Remap" ) ) { entryType = catalog . SYSTEM ; entryArgs . add ( atts . getValue ( "SystemId" ) ) ; entryArgs . add ( atts . getValue ( "HRef" ) ) ; catalog . getCatalogManager ( ) . debug . message ( 4 , "Remap" , atts . getValue ( "SystemId" ) , atts . getValue ( "HRef" ) ) ; } else if ( localName . equals ( "XMLCatalog" ) ) { // nop, start of catalog } else { // This is equivalent to an invalid catalog entry type catalog . getCatalogManager ( ) . debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } if ( entryType >= 0 ) { try { CatalogEntry ce = new CatalogEntry ( entryType , entryArgs ) ; catalog . addEntry ( ce ) ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY_TYPE ) { catalog . getCatalogManager ( ) . debug . message ( 1 , "Invalid catalog entry type" , localName ) ; } else if ( cex . getExceptionType ( ) == CatalogException . INVALID_ENTRY ) { catalog . getCatalogManager ( ) . debug . message ( 1 , "Invalid catalog entry" , localName ) ; } } } }


Input: Schedule the given TimerTask to be executed after <code > delay< / code > milliseconds . [CODESPLIT] public void schedule ( TimerTask t , long delay ) { if ( t == null ) throw new IllegalArgumentException ( "Can't schedule a null TimerTask" ) ; if ( delay < 0 ) delay = 0 ; t . setNextExecutionTime ( System . currentTimeMillis ( ) + delay ) ; putJob ( t ) ; }


Input: WorkerQueue overrides --------------------------------------------------- [CODESPLIT] protected void putJobImpl ( Executable task ) { m_heap . insert ( task ) ; ( ( TimerTask ) task ) . setState ( TimerTask . SCHEDULED ) ; notifyAll ( ) ; }


Input: Map the argument text into and Integer using Integer . valueOf . [CODESPLIT] public void setAsText ( final String text ) { Object newValue = Float . valueOf ( text ) ; setValue ( newValue ) ; }


Input: Cleanup and process a Catalog entry . [CODESPLIT] public void addEntry ( CatalogEntry entry ) { int type = entry . getEntryType ( ) ; if ( type == URISUFFIX ) { String suffix = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "URISUFFIX" , suffix , fsi ) ; } else if ( type == SYSTEMSUFFIX ) { String suffix = normalizeURI ( entry . getEntryArg ( 0 ) ) ; String fsi = makeAbsolute ( normalizeURI ( entry . getEntryArg ( 1 ) ) ) ; entry . setEntryArg ( 1 , fsi ) ; catalogManager . debug . message ( 4 , "SYSTEMSUFFIX" , suffix , fsi ) ; } super . addEntry ( entry ) ; }


Input: Return the applicable URI . [CODESPLIT] public String resolveURI ( String uri ) throws MalformedURLException , IOException { String resolved = super . resolveURI ( uri ) ; if ( resolved != null ) { return resolved ; } Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == RESOLVER ) { resolved = resolveExternalSystem ( uri , e . getEntryArg ( 0 ) ) ; if ( resolved != null ) { return resolved ; } } else if ( e . getEntryType ( ) == URISUFFIX ) { String suffix = e . getEntryArg ( 0 ) ; String result = e . getEntryArg ( 1 ) ; if ( suffix . length ( ) <= uri . length ( ) && uri . substring ( uri . length ( ) - suffix . length ( ) ) . equals ( suffix ) ) { return result ; } } } // Otherwise, look in the subordinate catalogs return resolveSubordinateCatalogs ( Catalog . URI , null , null , uri ) ; }


Input: Return the applicable SYSTEM system identifier resorting to external RESOLVERs if necessary . [CODESPLIT] public String resolveSystem ( String systemId ) throws MalformedURLException , IOException { String resolved = super . resolveSystem ( systemId ) ; if ( resolved != null ) { return resolved ; } Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == RESOLVER ) { resolved = resolveExternalSystem ( systemId , e . getEntryArg ( 0 ) ) ; if ( resolved != null ) { return resolved ; } } else if ( e . getEntryType ( ) == SYSTEMSUFFIX ) { String suffix = e . getEntryArg ( 0 ) ; String result = e . getEntryArg ( 1 ) ; if ( suffix . length ( ) <= systemId . length ( ) && systemId . substring ( systemId . length ( ) - suffix . length ( ) ) . equals ( suffix ) ) { return result ; } } } return resolveSubordinateCatalogs ( Catalog . SYSTEM , null , null , systemId ) ; }


Input: Return the applicable PUBLIC or SYSTEM identifier resorting to external resolvers if necessary . [CODESPLIT] public String resolvePublic ( String publicId , String systemId ) throws MalformedURLException , IOException { String resolved = super . resolvePublic ( publicId , systemId ) ; if ( resolved != null ) { return resolved ; } Enumeration enumt = catalogEntries . elements ( ) ; while ( enumt . hasMoreElements ( ) ) { CatalogEntry e = ( CatalogEntry ) enumt . nextElement ( ) ; if ( e . getEntryType ( ) == RESOLVER ) { if ( systemId != null ) { resolved = resolveExternalSystem ( systemId , e . getEntryArg ( 0 ) ) ; if ( resolved != null ) { return resolved ; } } resolved = resolveExternalPublic ( publicId , e . getEntryArg ( 0 ) ) ; if ( resolved != null ) { return resolved ; } } } return resolveSubordinateCatalogs ( Catalog . PUBLIC , null , publicId , systemId ) ; }


Input: Query an external RFC2483 resolver for a system identifier . [CODESPLIT] protected String resolveExternalSystem ( String systemId , String resolver ) throws MalformedURLException , IOException { Resolver r = queryResolver ( resolver , "i2l" , systemId , null ) ; if ( r != null ) { return r . resolveSystem ( systemId ) ; } else { return null ; } }


Input: Query an external RFC2483 resolver for a public identifier . [CODESPLIT] protected String resolveExternalPublic ( String publicId , String resolver ) throws MalformedURLException , IOException { Resolver r = queryResolver ( resolver , "fpi2l" , publicId , null ) ; if ( r != null ) { return r . resolvePublic ( publicId , null ) ; } else { return null ; } }


Input: Query an external RFC2483 resolver . [CODESPLIT] protected Resolver queryResolver ( String resolver , String command , String arg1 , String arg2 ) { String RFC2483 = resolver + "?command=" + command + "&format=tr9401&uri=" + arg1 + "&uri2=" + arg2 ; try { URL url = new URL ( RFC2483 ) ; URLConnection urlCon = url . openConnection ( ) ; urlCon . setUseCaches ( false ) ; Resolver r = ( Resolver ) newCatalog ( ) ; String cType = urlCon . getContentType ( ) ; // I don't care about the character set or subtype if ( cType . indexOf ( ";" ) > 0 ) { cType = cType . substring ( 0 , cType . indexOf ( ";" ) ) ; } r . parseCatalog ( cType , urlCon . getInputStream ( ) ) ; return r ; } catch ( CatalogException cex ) { if ( cex . getExceptionType ( ) == CatalogException . UNPARSEABLE ) { catalogManager . debug . message ( 1 , "Unparseable catalog: " + RFC2483 ) ; } else if ( cex . getExceptionType ( ) == CatalogException . UNKNOWN_FORMAT ) { catalogManager . debug . message ( 1 , "Unknown catalog format: " + RFC2483 ) ; } return null ; } catch ( MalformedURLException mue ) { catalogManager . debug . message ( 1 , "Malformed resolver URL: " + RFC2483 ) ; return null ; } catch ( IOException ie ) { catalogManager . debug . message ( 1 , "I/O Exception opening resolver: " + RFC2483 ) ; return null ; } }


Input: Append two vectors returning the result . [CODESPLIT] private Vector appendVector ( Vector vec , Vector appvec ) { if ( appvec != null ) { for ( int count = 0 ; count < appvec . size ( ) ; count ++ ) { vec . addElement ( appvec . elementAt ( count ) ) ; } } return vec ; }


Input: Find the URNs for a given system identifier in all catalogs . [CODESPLIT] public Vector resolveAllSystemReverse ( String systemId ) throws MalformedURLException , IOException { Vector resolved = new Vector ( ) ; // If there's a SYSTEM entry in this catalog, use it if ( systemId != null ) { Vector localResolved = resolveLocalSystemReverse ( systemId ) ; resolved = appendVector ( resolved , localResolved ) ; } // Otherwise, look in the subordinate catalogs Vector subResolved = resolveAllSubordinateCatalogs ( SYSTEMREVERSE , null , null , systemId ) ; return appendVector ( resolved , subResolved ) ; }


Input: Find the URN for a given system identifier . [CODESPLIT] public String resolveSystemReverse ( String systemId ) throws MalformedURLException , IOException { Vector resolved = resolveAllSystemReverse ( systemId ) ; if ( resolved != null && resolved . size ( ) > 0 ) { return ( String ) resolved . elementAt ( 0 ) ; } else { return null ; } }


Input: Return the applicable SYSTEM system identifiers . [CODESPLIT] public Vector resolveAllSystem ( String systemId ) throws MalformedURLException , IOException { Vector resolutions = new Vector ( ) ; // If there are SYSTEM entries in this catalog, start with them if ( systemId != null ) { Vector localResolutions = resolveAllLocalSystem ( systemId ) ; resolutions = appendVector ( resolutions , localResolutions ) ; } // Then look in the subordinate catalogs Vector subResolutions = resolveAllSubordinateCatalogs ( SYSTEM , null , null , systemId ) ; resolutions = appendVector ( resolutions , subResolutions ) ; if ( resolutions . size ( ) > 0 ) { return resolutions ; } else { return null ; } }