Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4ec3515a72a615f6b26ce10d12afbb758c2d6e7c (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
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST 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:
 *   CEA LIST - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.infra.services.localizer.util;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResourceSet;
import org.eclipse.papyrus.infra.services.localizer.DefaultObjectLocalizer;
import org.eclipse.papyrus.infra.services.localizer.IObjectLocalizer;
import org.eclipse.papyrus.infra.services.localizer.internal.Activator;


/**
 * Utilities for getting/working with localizers.
 */
public class LocalizerUtil {

	/**
	 * Not instantiable by clients.
	 */
	private LocalizerUtil() {
		super();
	}

	public static IObjectLocalizer getDefault() {
		return DefaultObjectLocalizer.INSTANCE;
	}

	public static IObjectLocalizer getInstance(ResourceSet rset) {
		try {
			return getInstance(ServiceUtilsForResourceSet.getInstance().getServiceRegistry(rset));
		} catch (ServiceException e) {
			Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$
		}

		return getDefault();
	}

	public static IObjectLocalizer getInstance(Resource resource) {
		try {
			return getInstance(ServiceUtilsForResource.getInstance().getServiceRegistry(resource));
		} catch (ServiceException e) {
			Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$
		}

		return getDefault();
	}

	public static IObjectLocalizer getInstance(EObject object) {
		try {
			return getInstance(ServiceUtilsForEObject.getInstance().getServiceRegistry(object));
		} catch (ServiceException e) {
			Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$
		}

		return getDefault();
	}

	public static IObjectLocalizer getInstance(ServicesRegistry services) {
		try {
			return services.getService(IObjectLocalizer.class);
		} catch (ServiceException e) {
			Activator.log.error("Failed to get localizer service.", e); //$NON-NLS-1$
		}

		return getDefault();
	}

}

Back to the top