View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: CoreServiceLocator.java
13   * Created: 2009-08-05
14   * Author: tmilos
15   * $Id$
16   */
17  
18  package pl.edu.agh.cast;
19  
20  import pl.edu.agh.cast.data.converter.ConverterRegistry;
21  import pl.edu.agh.cast.data.persistence.IObservablePersistenceProvider;
22  import pl.edu.agh.cast.data.persistence.PersistenceProviderLocator;
23  import pl.edu.agh.cast.data.persistence.TransparentPersistenceProvider;
24  import pl.edu.agh.cast.resource.IResourceRegistry;
25  import pl.edu.agh.cast.resource.ResourceRegistry;
26  
27  /**
28   * Locator of core CAST services.
29   *
30   * @see IObservablePersistenceProvider
31   * @see IResourceRegistry
32   * @see ConverterRegistry
33   *
34   * @author AGH CAST Team
35   */
36  public class CoreServiceLocator {
37  
38  	private static IResourceRegistry resourceRegistry;
39  
40  	/**
41  	 * Initializes the CAST services.
42  	 *
43  	 * @throws Exception
44  	 */
45  	public static synchronized void initialize() throws Exception {
46  		if (resourceRegistry == null) {
47  			resourceRegistry = new ResourceRegistry();
48  			resourceRegistry.initalize();
49  		}
50  		PersistenceProviderLocator.getProvider().initialize();
51  		ConverterRegistry.getInstance();
52  	}
53  
54  	/**
55  	 * Returns the persistence provider.
56  	 *
57  	 * @return persistence provider
58  	 */
59  	public static TransparentPersistenceProvider getPersistenceProvider() {
60  		return PersistenceProviderLocator.getProvider();
61  	}
62  
63  	/**
64  	 * Returns the resource registry.
65  	 *
66  	 * @return resource registry
67  	 */
68  	public static IResourceRegistry getResourceRegistry() {
69  		return resourceRegistry;
70  	}
71  
72  	/**
73  	 * Returns the converter registry.
74  	 *
75  	 * @return converter registry
76  	 */
77  	public static ConverterRegistry getConverterRegistry() {
78  		return ConverterRegistry.getInstance();
79  	}
80  
81  }