1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.mtw.core.internal.runtimes; |
|
20 |
|
21 import java.util.HashMap; |
|
22 import java.util.Map; |
|
23 import java.util.TreeMap; |
|
24 |
|
25 import org.eclipse.core.runtime.IConfigurationElement; |
|
26 import org.eclipse.core.runtime.Platform; |
|
27 import org.symbian.tools.mtw.core.MTWCore; |
|
28 import org.symbian.tools.mtw.core.projects.IMTWProject; |
|
29 import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntime; |
|
30 import org.symbian.tools.mtw.core.runtimes.IMobileWebRuntimeManager; |
|
31 import org.symbian.tools.mtw.core.runtimes.IPackager; |
|
32 |
|
33 public final class RuntimesManagerImpl implements IMobileWebRuntimeManager { |
|
34 private final Map<String, IMobileWebRuntime> runtimes = new TreeMap<String, IMobileWebRuntime>(); |
|
35 private final Map<IMobileWebRuntime, Map<IMobileWebRuntime, IPackager>> packagers = new HashMap<IMobileWebRuntime, Map<IMobileWebRuntime, IPackager>>(); |
|
36 |
|
37 public RuntimesManagerImpl() { |
|
38 collectRuntimes(); |
|
39 collectPackagers(); |
|
40 } |
|
41 |
|
42 private void collectPackagers() { |
|
43 IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( |
|
44 MTWCore.PLUGIN_ID, "packagers"); |
|
45 for (IConfigurationElement element : elements) { |
|
46 final String target = element.getAttribute("targetRuntime"); |
|
47 final IMobileWebRuntime targetRuntime = getRuntime(target); |
|
48 if (targetRuntime == null) { |
|
49 MTWCore.log("Runtime %s referenced from plugin %s was not found", target, element |
|
50 .getDeclaringExtension().getNamespaceIdentifier()); |
|
51 break; |
|
52 } |
|
53 |
|
54 final String source = element.getAttribute("sourceRuntime"); |
|
55 IMobileWebRuntime sourceRuntime; |
|
56 if (source == null) { |
|
57 sourceRuntime = targetRuntime; |
|
58 } else { |
|
59 sourceRuntime = getRuntime(source); |
|
60 if (sourceRuntime == null) { |
|
61 MTWCore.log("Runtime %s referenced from plugin %s was not found", source, element |
|
62 .getDeclaringExtension().getNamespaceIdentifier()); |
|
63 break; |
|
64 } |
|
65 } |
|
66 IPackager packager = new LazyPackager(element); |
|
67 Map<IMobileWebRuntime, IPackager> map = packagers.get(targetRuntime); |
|
68 if (map == null) { |
|
69 map = new HashMap<IMobileWebRuntime, IPackager>(); |
|
70 packagers.put(targetRuntime, map); |
|
71 } |
|
72 map.put(sourceRuntime, packager); |
|
73 } |
|
74 } |
|
75 |
|
76 private void collectRuntimes() { |
|
77 IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( |
|
78 MTWCore.PLUGIN_ID, "runtimes"); |
|
79 for (IConfigurationElement element : elements) { |
|
80 final MobileWebRuntime runtime = new MobileWebRuntime(element); |
|
81 runtimes.put(runtime.getId(), runtime); |
|
82 } |
|
83 } |
|
84 |
|
85 public IPackager getPackager(IMTWProject project) { |
|
86 return getPackager(project, project.getTargetRuntime()); |
|
87 } |
|
88 |
|
89 public IPackager getPackager(IMTWProject project, IMobileWebRuntime runtime) { |
|
90 final Map<IMobileWebRuntime, IPackager> map = packagers.get(runtime); |
|
91 if (map != null) { |
|
92 return map.get(project.getTargetRuntime()); |
|
93 } |
|
94 return null; |
|
95 } |
|
96 |
|
97 public IMobileWebRuntime getRuntime(String id) { |
|
98 return runtimes.get(id); |
|
99 } |
|
100 |
|
101 } |
|