/* (non-Javadoc)
@see org.archive.wayback.resourceindex.SearchResultSource#getPrefixIterator(java.lang.String)
766565
@Override
	public CloseableIterator<CaptureSearchResult> getPrefixIterator(String prefix)
		throws ResourceIndexNotAvailableException {
		try {
			return adaptIterator(getRecordIterator(prefix));
		} catch (IOException e) {
			e.printStackTrace();
			throw new ResourceIndexNotAvailableException(e.getMessage()); 
		}
	}
1117459
@Singleton
    protected @Nonnull TypeConverter<CharSequence, Readable> readableTypeConverter(ResourceResolver resourceResolver) {
        return (object, targetType, context) -> {
            String pathStr = object.toString();
            Optional<ResourceLoader> supportingLoader = resourceResolver.getSupportingLoader(pathStr);
            if (!supportingLoader.isPresent()) {
                context.reject(pathStr, new ConfigurationException(
                        "No supported resource loader for path [" + pathStr + "]. Prefix the path with a supported prefix such as 'classpath:' or 'file:'"
                ));
                return Optional.empty();
            } else {
                final Optional<URL> resource = resourceResolver.getResource(pathStr);
                if (resource.isPresent()) {
                    return Optional.of(Readable.of(resource.get()));
                } else {
                    context.reject(object, new ConfigurationException("No resource exists for value: " + object));
                    return Optional.empty();
                }
            }

        };
    }
248306
@Nullable
  public IndexSearcher getSearcher () throws IOException
  {
    _checkClosing ();
    final IndexReader aReader = getReader ();
    if (aReader == null)
    {
      // Index not readable
      LOGGER.warn ("Index not readable");
      return null;
    }

    if (m_aSearchReader == aReader)
    {
      // Reader did not change - use cached searcher
      assert m_aSearcher != null;
    }
    else
    {
      // Create new searcher only if necessary
      m_aSearchReader = aReader;
      m_aSearcher = new IndexSearcher (aReader);
    }
    return m_aSearcher;
  }
1369702
@Override
	public <T> T get(final String key, DomainResolver resolver) {
		return get(key, null, resolver);
	}
24393
@Override
    public DataSourceHolder getHolder(StatementMetaData metaData, Map<String, Object> runtime) {
        String daoName = metaData.getDAOMetaData().getDAOClass().getName();
        String name = daoName;
        DataSourceHolder dataSource = dataSources.get(name);
        if (dataSource != null) {
            return dataSource;
        }
        while (true) {
            int index = name.lastIndexOf('.');
            if (index == -1) {
                dataSources.putIfAbsent(daoName, defaultDataSource);
                return defaultDataSource;
            }
            name = name.substring(0, index);
            dataSource = dataSources.get(name);
            if (dataSource != null) {
                dataSources.putIfAbsent(daoName, dataSource);
                return dataSource;
            }
        }
    }
1114366
@Pure
	public static Object getContextResolver() throws AndroidException {
		Object resolver;
		synchronized (Android.class) {
			resolver = (contextResolver == null) ? null : contextResolver.get();
		}
		if (resolver == null) {
			final Object context = getContext();
			try {
				final Class<?> resolverType = getContextResolverClass();
				final Class<?> contextType = context.getClass();
				final Method getContextResolverMethod = contextType.getMethod("getContentResolver"); //$NON-NLS-1$
				resolver = getContextResolverMethod.invoke(context);
				resolver = resolverType.cast(resolver);
				synchronized (Android.class) {
					contextResolver = new WeakReference<>(resolver);
				}
			} catch (AssertionError e) {
				throw e;
			} catch (Throwable e) {
				throw new AndroidException(e);
			}
		}
		return resolver;
	}
369299
public Iterator<?> xpathIterator(Collection<?> collection, String query) {
    JXPathContext pathContext = JXPathContext.newContext(collection);
    Iterator<?> result = null;

    try {
      result = pathContext.iteratePointers(query);
    } catch (JXPathNotFoundException e) {
      logger.log(Level.WARNING, "JXPath exception: {0}", e.getMessage());
    }

    return result;
  }
824657
@Override
    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
        if ((defaultNamespace!=null) && (namespaceUri.equals(defaultNamespace))) {
            return "";
        }

        if (namespaceUri.equals(PROV_NS)) {
            return "prov";
        }
        if (namespaceUri.equals(PRINTER_NS)) {
            return "prn";
        }
   //     if (namespaceUri.equals(XSD_NS)) {
   //         return "xsd";
   //     }
        if (namespaceUri.equals(DOMProcessing.XSD_NS_FOR_XML)) { // TODO: TO CHECK that's the one we need
            return "xsd";
        }
        if (namespaceUri.equals(XML_NS)) {
            return "xml";
        }
        if (namespaceUri.equals(XSI_NS)) {
            return "xsi";
        }
        for (String k: nss.keySet()) {
            if (nss.get(k).equals(namespaceUri)) {
                return k;
            }
        }
        return suggestion;
    }
1132182
@SuppressWarnings({"unchecked"})
    public static <T extends LocalizableResource> T get(Class<T> cls, String locale) {
        Map<String, LocalizableResource> localeCache = getLocaleCache(cls);
        T m = (T) localeCache.get(locale);
        if (m != null) {
            return m;
        }
        synchronized (cache) {
            m = (T) localeCache.get(locale);
            if (m != null) {
                return m;
            }
            m = provider.create(cls, locale);
            put(cls, locale, m);
            return m;
        }
    }
658200
public String getPrefix(String namespaceURI)
   {
      String prefix = null;
      try
      {
         prefix = namespaceRegistry.getPrefix(namespaceURI);
      }
      catch (NamespaceException exc)
      {
         prefix = prefixes.get(namespaceURI);
      }
      catch (RepositoryException exc)
      {
         log.error(exc.getMessage(), exc);
      }
      return prefix;

   }
783108
@Override
  @SuppressWarnings("unchecked")
  protected T getNext() {
    // if (lexer == null) {
    //   return null;
    // }
    try {
      return (T) lexer.next();
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    }
    // cdm 2007: this shouldn't be necessary: PTBLexer decides for itself whether to return CRs based on the same flag!
    // get rid of CRs if necessary
    // while (!tokenizeNLs && PTBLexer.cr.equals(((HasWord) token).word())) {
    //   token = (T)lexer.next();
    // }

    // horatio: we used to catch exceptions here, which led to broken
    // behavior and made it very difficult to debug whatever the
    // problem was.
  }
480265
@Override
    public StandardJavaFileManager getStandardFileManager(
            DiagnosticListener<? super JavaFileObject> diagnosticListener,
            Locale locale,
            Charset charset) {
        Context context = new Context();
        context.put(Locale.class, locale);
        if (diagnosticListener != null)
            context.put(DiagnosticListener.class, diagnosticListener);
        PrintWriter pw = (charset == null)
                ? new PrintWriter(System.err, true)
                : new PrintWriter(new OutputStreamWriter(System.err, charset), true);
        context.put(Log.outKey, pw);
        return new JavacFileManager(context, true, charset);
    }
1012729
@Override
	public IResourceFactory getResourceFactory(Mutable<URI> uriRef) {
		final String sourceMethod = "getResourceFactory"; //$NON-NLS-1$
		boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(AbstractAggregatorImpl.class.getName(), sourceMethod, new Object[]{uriRef});
		}
		IResourceFactory factory = null;
		URI uri = uriRef.getValue();
		if (!uri.isAbsolute()) {
			if (uri.getPath().startsWith("/")) { //$NON-NLS-1$
				// server relative URI not supported for server resources.  Probably meant
				// to refer to a web resource.
				if (isTraceLogging) {
					log.exiting(AbstractAggregatorImpl.class.getName(), sourceMethod, null);
				}
				return null;
			}
			// URI is not absolute, so make it absolute.
			try {
				uri = getPlatformServices().getAppContextURI().resolve(uri.getPath());
				if (isTraceLogging) {
					log.logp(Level.FINER, AbstractAggregatorImpl.class.getName(), sourceMethod,
							"URI " + uriRef.getValue().toString() + " transformed to " + uri.toString()); //$NON-NLS-1$ //$NON-NLS-2$
				}
			} catch (URISyntaxException e) {
				throw new IllegalArgumentException(e);
			}
		}

		Iterable<IAggregatorExtension> extensions = getExtensions(IResourceFactoryExtensionPoint.ID);
		if (extensions != null) {	// may be null when unit testing
			for (IAggregatorExtension extension : getExtensions(IResourceFactoryExtensionPoint.ID)) {
				if (uri.getScheme().equals(extension.getAttribute(IResourceFactoryExtensionPoint.SCHEME_ATTRIBUTE))) {
					IResourceFactory test = (IResourceFactory)extension.getInstance();
					if (test.handles(uri)) {
						factory = test;
						break;
					}
				}
			}
		}
		if (factory != null) {
			uriRef.setValue(uri);
		}
		if (isTraceLogging) {
			log.exiting(AbstractAggregatorImpl.class.getName(), sourceMethod, factory);
		}
		return factory;
	}
592618
public String getPrefix(String namespaceURI)
    {
        String prefix = m_prefixMap.lookupPrefix(namespaceURI);
        return prefix;
    }
1363060
@Override
  public String getPrefix(String namespaceURI)
  {
    if (namespaceURI == null || !namespaceURI.equals("http://www.christofreichardt.de/java/tracer"))
      throw new IllegalArgumentException("Accept only default namespace.");
    
    return "dns";
  }
379513
public long getCompletedPrefix()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "getCompletedPrefix");
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "getCompletedPrefix", Long.valueOf(_targetStream.getCompletedPrefix()));

    return _targetStream.getCompletedPrefix();
  }
717326
@Override
  public LookupExtractor get()
  {
    final Lock readLock = startStopSync.readLock();
    try {
      readLock.lockInterruptibly();
    }
    catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
    try {
      if (entry == null) {
        throw new ISE("Factory [%s] not started", extractorID);
      }
      final CacheScheduler.CacheState cacheState = entry.getCacheState();
      if (cacheState instanceof CacheScheduler.NoCache) {
        final String noCacheReason = ((CacheScheduler.NoCache) cacheState).name();
        throw new ISE("%s: %s, extractorID = %s", entry, noCacheReason, extractorID);
      }
      CacheScheduler.VersionedCache versionedCache = (CacheScheduler.VersionedCache) cacheState;
      Map<String, String> map = versionedCache.getCache();
      final byte[] v = StringUtils.toUtf8(versionedCache.getVersion());
      final byte[] id = StringUtils.toUtf8(extractorID);
      return new MapLookupExtractor(map, isInjective())
      {
        @Override
        public byte[] getCacheKey()
        {
          return ByteBuffer
              .allocate(CLASS_CACHE_KEY.length + id.length + 1 + v.length + 1 + 1)
              .put(CLASS_CACHE_KEY)
              .put(id).put((byte) 0xFF)
              .put(v).put((byte) 0xFF)
              .put(isOneToOne() ? (byte) 1 : (byte) 0)
              .array();
        }
      };
    }
    finally {
      readLock.unlock();
    }
  }