1 19 20 package org.openide.loaders; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.xml.sax.*; 26 27 36 final class XMLEntityResolverChain implements EntityResolver { 37 38 41 private final List<EntityResolver> resolverChain = new ArrayList<EntityResolver>(3); 42 43 44 45 public XMLEntityResolverChain() { 46 } 47 48 57 public boolean addEntityResolver(EntityResolver resolver) { 58 if (resolver == null) throw new IllegalArgumentException (); 59 synchronized (resolverChain) { 60 if (resolverChain.contains(resolver)) return false; 61 return resolverChain.add(resolver); 62 } 63 } 64 65 72 public EntityResolver removeEntityResolver(EntityResolver resolver) { 73 if (resolver == null) throw new IllegalArgumentException (); 74 synchronized (resolverChain) { 75 int index = resolverChain.indexOf(resolver); 76 if ( index < 0 ) return null; 77 return (EntityResolver) resolverChain.remove(index); 78 } 79 } 80 81 95 public InputSource resolveEntity(String publicID, String systemID) throws SAXException, IOException { 96 97 SAXException lsex = null; 99 IOException lioex = null; 100 101 synchronized (resolverChain) { 102 Iterator it = resolverChain.iterator(); 103 while (it.hasNext()) { 104 EntityResolver resolver = (EntityResolver) it.next(); 105 try { 106 InputSource test = resolver.resolveEntity(publicID, systemID); 107 if (test == null) continue; 108 return test; 109 } catch (SAXException sex) { 110 lsex = sex; 111 continue; 112 } catch (IOException ioex) { 113 lioex = ioex; 114 continue; 115 } 116 } 117 118 120 if (lioex != null) throw lioex; 121 if (lsex != null) throw lsex; 122 123 return null; 125 } 126 } 127 } 128 | Popular Tags |