Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/com.ibm.jpp.preprocessor/com/ibm/jpp/om/MetaRegistry.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 1999, 2017 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
package com.ibm.jpp.om;
23
24
import java.io.FileNotFoundException;
25
import java.util.HashMap;
26
import java.util.Map;
27
28
import com.ibm.jpp.xml.XMLException;
29
30
/**
31
* Represents a meta-registry to manage all the ConfigurationRegistries associated
32
* with configurations
33
*/
34
public class MetaRegistry {
35
36
private static Map<String, ConfigurationRegistry> registries = new HashMap<>();
37
38
/**
39
* Returns the registry associated with the given source root and XML file. If the
40
* registry cannot be found a new one will be created and it will populated with the
41
* configurations from the given XML file.
42
*
43
* @param baseDir the registry's base directory
44
* @param srcRoot the registry's source root path
45
* @param xml the registry's parent XML
46
* @return the configuration registry requested
47
*
48
* @throws FileNotFoundException if the xml file could not be found
49
* @throws XMLException if there are errors in parsing the XML file
50
*/
51
public static ConfigurationRegistry getRegistry(String baseDir, String srcRoot, String xml) throws FileNotFoundException, XMLException {
52
ConfigurationRegistry registry = registries.get(srcRoot);
53
54
if (registry == null) {
55
registry = new ConfigurationRegistry(baseDir, srcRoot);
56
registry.registerXMLSet(xml);
57
58
// Add registry to meta-registry by srcRoot/name
59
registries.put(srcRoot, registry);
60
}
61
62
return registry;
63
}
64
65
/**
66
* Returns all of the configuration registries available.
67
*
68
* @return the configuration registries
69
*/
70
public static ConfigurationRegistry[] getRegistries() {
71
int size = registries.size();
72
return (size > 0) ? registries.values().toArray(new ConfigurationRegistry[size]) : null;
73
}
74
75
/**
76
* Clears the meta registry.
77
*/
78
public static void clear() {
79
registries.clear();
80
}
81
}
82
83