|
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.tmw.core.internal.runtimes; |
|
20 |
|
21 import java.util.Collection; |
|
22 import java.util.HashMap; |
|
23 import java.util.Map; |
|
24 import java.util.TreeMap; |
|
25 |
|
26 import org.eclipse.core.runtime.IConfigurationElement; |
|
27 import org.eclipse.core.runtime.Platform; |
|
28 import org.symbian.tools.tmw.core.TMWCore; |
|
29 import org.symbian.tools.tmw.core.projects.IMTWProject; |
|
30 import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime; |
|
31 import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntimeManager; |
|
32 import org.symbian.tools.tmw.core.runtimes.IPackager; |
|
33 |
|
34 public final class RuntimesManagerImpl implements IMobileWebRuntimeManager { |
|
35 private Map<IMobileWebRuntime, Map<IMobileWebRuntime, IPackager>> packagers; |
|
36 private Map<String, IMobileWebRuntime> runtimes; |
|
37 |
|
38 public RuntimesManagerImpl() { |
|
39 collectRuntimes(); |
|
40 } |
|
41 |
|
42 private void collectPackagers() { |
|
43 packagers = new HashMap<IMobileWebRuntime, Map<IMobileWebRuntime, IPackager>>(); |
|
44 IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( |
|
45 TMWCore.PLUGIN_ID, "packagers"); |
|
46 for (IConfigurationElement element : elements) { |
|
47 IPackager packager = new LazyPackager(element); |
|
48 Map<IMobileWebRuntime, IPackager> map = packagers.get(packager.getTargetRuntime()); |
|
49 if (map == null) { |
|
50 map = new HashMap<IMobileWebRuntime, IPackager>(); |
|
51 packagers.put(packager.getTargetRuntime(), map); |
|
52 } |
|
53 map.put(packager.getSourceRuntime(), packager); |
|
54 } |
|
55 } |
|
56 |
|
57 private void collectRuntimes() { |
|
58 runtimes = new TreeMap<String, IMobileWebRuntime>(); |
|
59 IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor( |
|
60 TMWCore.PLUGIN_ID, "runtimes"); |
|
61 for (IConfigurationElement element : elements) { |
|
62 final MobileWebRuntime runtime = new MobileWebRuntime(element); |
|
63 runtimes.put(getInternalId(runtime.getId(), runtime.getVersion()), runtime); |
|
64 } |
|
65 } |
|
66 |
|
67 public IMobileWebRuntime[] getAllRuntimes() { |
|
68 if (runtimes == null) { |
|
69 collectRuntimes(); |
|
70 } |
|
71 final Collection<IMobileWebRuntime> rts = runtimes.values(); |
|
72 return rts.toArray(new IMobileWebRuntime[rts.size()]); |
|
73 } |
|
74 |
|
75 public IPackager getPackager(IMTWProject project) { |
|
76 return getPackager(project, project.getTargetRuntime()); |
|
77 } |
|
78 |
|
79 public IPackager getPackager(IMTWProject project, IMobileWebRuntime runtime) { |
|
80 if (packagers == null) { |
|
81 collectPackagers(); |
|
82 } |
|
83 final Map<IMobileWebRuntime, IPackager> map = packagers.get(runtime); |
|
84 if (map != null) { |
|
85 return map.get(project.getTargetRuntime()); |
|
86 } |
|
87 return null; |
|
88 } |
|
89 |
|
90 public IMobileWebRuntime getRuntime(String id, String version) { |
|
91 if (runtimes == null) { |
|
92 collectRuntimes(); |
|
93 } |
|
94 final IMobileWebRuntime runtime = runtimes.get(getInternalId(id, version)); |
|
95 if (runtime == null) { |
|
96 TMWCore.log(String.format("Runtime %s@%s", id, version), new Exception()); |
|
97 } |
|
98 return runtime; |
|
99 } |
|
100 |
|
101 private String getInternalId(String id, String version) { |
|
102 return id + ":" + version; |
|
103 } |
|
104 |
|
105 } |