Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/om/MetaRegistry.java
6004 views
/*******************************************************************************1* Copyright (c) 1999, 2017 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.jpp.om;2223import java.io.FileNotFoundException;24import java.util.HashMap;25import java.util.Map;2627import com.ibm.jpp.xml.XMLException;2829/**30* Represents a meta-registry to manage all the ConfigurationRegistries associated31* with configurations32*/33public class MetaRegistry {3435private static Map<String, ConfigurationRegistry> registries = new HashMap<>();3637/**38* Returns the registry associated with the given source root and XML file. If the39* registry cannot be found a new one will be created and it will populated with the40* configurations from the given XML file.41*42* @param baseDir the registry's base directory43* @param srcRoot the registry's source root path44* @param xml the registry's parent XML45* @return the configuration registry requested46*47* @throws FileNotFoundException if the xml file could not be found48* @throws XMLException if there are errors in parsing the XML file49*/50public static ConfigurationRegistry getRegistry(String baseDir, String srcRoot, String xml) throws FileNotFoundException, XMLException {51ConfigurationRegistry registry = registries.get(srcRoot);5253if (registry == null) {54registry = new ConfigurationRegistry(baseDir, srcRoot);55registry.registerXMLSet(xml);5657// Add registry to meta-registry by srcRoot/name58registries.put(srcRoot, registry);59}6061return registry;62}6364/**65* Returns all of the configuration registries available.66*67* @return the configuration registries68*/69public static ConfigurationRegistry[] getRegistries() {70int size = registries.size();71return (size > 0) ? registries.values().toArray(new ConfigurationRegistry[size]) : null;72}7374/**75* Clears the meta registry.76*/77public static void clear() {78registries.clear();79}80}818283