/** * {@link #parse(Element) Parses <code>properties</code>} and then adds * the resulting protocol stack configurations to the set available for use. * * @param properties document root node for XML content in the JGroups * <code>stacks.xml</code> format * @param replace <code>true</code> if a configuration with the same * stack name as an already registered configuration should * replace that configuration; <code>false</code> if it * should be discarded. */ public void setMultiplexerConfig(Element properties, boolean replace) throws Exception { Map<String, ProtocolStackConfigInfo> map = ProtocolStackUtil.parse(properties); for (Map.Entry<String, ProtocolStackConfigInfo> entry : map.entrySet()) { addConfig(entry.getKey(), entry.getValue(), replace); } }
/** * Parses the contents of <code>input</code> into a map of the * protocol stack configurations contained in the XML. * * @param input stream which must contain XML content in the JGroups * <code>stacks.xml</code> format * * @return a map of the protocol stack configurations contained in the XML * * @throws IllegalArgumentException if <code>input</code> is <code>null</code> * @throws Exception */ public static Map<String, ProtocolStackConfigInfo> parse(InputStream input) throws Exception { if (input == null) { throw new IllegalArgumentException("null input"); } DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); factory.setValidating(false); //for now DocumentBuilder builder=factory.newDocumentBuilder(); Document document=builder.parse(input); // The root element of the document should be the "protocol_stacks" element, // but the parser(Element) method checks this so a check is not // needed here. Element configElement = document.getDocumentElement(); return parse(configElement); }
private void addConfigs(InputStream input, String source, boolean replace) throws Exception { if(input == null) { throw new FileNotFoundException(source); } Map<String, ProtocolStackConfigInfo> map = null; try { map = ProtocolStackUtil.parse(input); } catch(Exception ex) { throw new Exception("failed parsing " + source, ex); } finally { Util.close(input); } for (Map.Entry<String, ProtocolStackConfigInfo> entry : map.entrySet()) { addConfig(entry.getKey(), entry.getValue(), replace); } }