/** * Creates a working copy of the current parse state. * * @return the derived parse-parameters. * @noinspection ObjectAllocationInLoop as this is a cloning operation. */ protected Map deriveParseParameters() { final RootXmlReadHandler rootHandler = getRootHandler(); final HashMap map = new HashMap(); final String[] names = rootHandler.getHelperObjectNames(); final int length = names.length; for (int i = 0; i < length; i++) { final String name = names[i]; final FactoryParameterKey key = new FactoryParameterKey(name); map.put(key, rootHandler.getHelperObject(name)); } return map; }
/** * Parses an external file using LibLoader and returns the parsed result as an object of type * <code>targetClass</code>. The file is given as relative pathname (relative to the current * source file). The current helper-methods are used as parse-parameters for the external parsing. * * @param file the file to be parsed. * @param targetClass the target type of the parse operation. * @param map the map of parse parameters. * @return the result, never null. * @throws ParseException if parsing the result failed for some reason. * @throws ResourceLoadingException if there was an IO error loading the resource. * @see #deriveParseParameters() */ protected Object performExternalParsing(final String file, final Class targetClass, final Map map) throws ParseException, ResourceLoadingException { try { final ResourceManager resourceManager = rootHandler.getResourceManager(); final ResourceKey source = rootHandler.getSource(); final ResourceKey target = resourceManager.deriveKey(source, file, map); final DependencyCollector dc = rootHandler.getDependencyCollector(); final Resource resource = resourceManager.create(target, rootHandler.getContext(), targetClass); dc.add(resource); return resource.getResource(); } catch (ResourceLoadingException rle) { throw rle; } catch (ResourceException e) { throw new ParseException("Failure while loading data: " + file, e, getLocator()); } }
/** * Returns the locator as provided by the XML parser. This method may return null if the XML * parser has no locator support. * * @return the locator or null. */ public Locator getLocator() { return rootHandler.getDocumentLocator(); }