Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6886d34c215685f87cd97e4e516a28d3d1c75d0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2002, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     Angelo Zerr <angelo.zerr@gmail.com> - copied from org.eclipse.wst.xml.core.internal.catalog.CatalogSet
 *                                           modified in order to process JSON Objects.            
 *******************************************************************************/
package org.eclipse.wst.json.core.internal.schema.catalog;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.wst.json.core.internal.Logger;

public class CatalogSet {
	protected Map uriResourceMap = new HashMap();
	protected Map catalogPersistenceLocations = new HashMap();

	public CatalogSet() {
		super();
	}

	/**
	 * Find a Catalog with the given ID. If one is not found, create one at the
	 * given URI.
	 * 
	 * @param id
	 * @param uri
	 *            - the URI, the parent of this file path must already exist
	 * @return
	 */
	public Catalog lookupOrCreateCatalog(String id, String uri) {
		Catalog catalog = getCatalog(id, uri);
		if (catalog == null) {
			catalog = new Catalog(this, id, uri);
			try {
				catalog.load();
				uriResourceMap.put(uri, catalog);
			} catch (Exception e) {
				// we catch and log all exceptions, to disallow
				// one bad extension interfering with others
				Logger.logException(
						"error loading catalog: " + id + " " + uri, e); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}
		return catalog;
	}

	private Catalog getCatalog(String id, String uri) {
		return (Catalog) uriResourceMap.get(uri);
	}

	public void putCatalogPersistenceLocation(String logicalURI,
			String actualURI) {
		catalogPersistenceLocations.put(logicalURI, actualURI);
	}

	// Never used?
	public String getCatalogPersistenceLocation(String id) {
		return (String) catalogPersistenceLocations.get(id);
	}

	public void clearResourceCache() {// Clearing only uriResourceMap is
										// required
		uriResourceMap.clear();
	}
}

Back to the top