Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 3ec32b76aec84aa4ae21f1578210064814c725e7 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/********************************************************************************
 * Copyright (c) 2002, 2006 IBM Corporation. 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
 * 
 * Initial Contributors:
 * The following IBM employees contributed to the Remote System Explorer
 * component that contains this file: David McKnight, Kushal Munir, 
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
 * 
 * Contributors:
 * {Name} (company) - description of contribution.
 ********************************************************************************/

package org.eclipse.dstore.core.model;

import java.util.ArrayList;

import org.eclipse.dstore.core.util.ExternalLoader;

/**
 * SchemaRegistry implements the interface for external tools to contribute their
 * schemas to the DataStore. 
 */
public class SchemaRegistry implements ISchemaRegistry
{


	private ArrayList _initializedDataStores = new ArrayList();
	private ArrayList _extenders = new ArrayList();

	/**
	 * Registers a schema extender with the associated DataStores
	 * @param extender the schema extender to register
	 */
	public void registerSchemaExtender(ISchemaExtender extender)
	{
		if (!_extenders.contains(extender))
		{
			_extenders.add(extender);
			for (int i = 0; i < _initializedDataStores.size(); i++)
			{
				DataStore dataStore = (DataStore) _initializedDataStores.get(i);
				DataElement schemaRoot = dataStore.getDescriptorRoot();
				extender.extendSchema(schemaRoot);
			}
		}
	}

	/**
	 * Calls extendSchema() on each of the registered schema extenders to
	 * extend the schema of the specified DataStore
	 * 
	 * @param dataStore the DataStore whos schema will be updated
	 */
	public void extendSchema(DataStore dataStore)
	{
		if (!_initializedDataStores.contains(dataStore))
		{
			DataElement schemaRoot = dataStore.getDescriptorRoot();
			for (int i = 0; i < _extenders.size(); i++)
			{
				ISchemaExtender extender = (ISchemaExtender) _extenders.get(i);
				extender.extendSchema(schemaRoot);
			}
			_initializedDataStores.add(dataStore);
		}
	}

	/**
	 * Gets the <code>ExternalLoader</code> for the specified qualified classname
	 * 
	 * @param source the qualified classname
	 * @return the external loader for the specified classname
	 */
	public ExternalLoader getLoaderFor(String source)
	{
		for (int i = 0; i < _extenders.size(); i++)
		{
			ISchemaExtender extender = (ISchemaExtender) _extenders.get(i);
			ExternalLoader loader = extender.getExternalLoader();
			if (loader.canLoad(source))
			{
				return loader;
			}
		}
		return null;
	}
}

Back to the top