|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Plug-in formatter / parser management |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.engine.rules; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.Iterator; |
|
23 |
|
24 import com.nokia.tracebuilder.engine.plugin.TraceAPIPluginManager; |
|
25 import com.nokia.tracebuilder.engine.rules.plugin.PluginTraceFormatRule; |
|
26 import com.nokia.tracebuilder.engine.rules.plugin.PluginTraceParserRule; |
|
27 import com.nokia.tracebuilder.model.TraceModel; |
|
28 import com.nokia.tracebuilder.model.TraceObject; |
|
29 import com.nokia.tracebuilder.plugin.TraceAPIFormatter; |
|
30 import com.nokia.tracebuilder.plugin.TraceAPIParser; |
|
31 import com.nokia.tracebuilder.project.TraceProjectAPI; |
|
32 import com.nokia.tracebuilder.project.TraceProjectAPIList; |
|
33 |
|
34 /** |
|
35 * Plug-in formatter / parser management |
|
36 * |
|
37 */ |
|
38 final class RulesEnginePluginManager implements TraceAPIPluginManager, |
|
39 TraceProjectAPIList { |
|
40 |
|
41 /** |
|
42 * Rules engine |
|
43 */ |
|
44 private RulesEngine engine; |
|
45 |
|
46 /** |
|
47 * Trace model |
|
48 */ |
|
49 private TraceModel model; |
|
50 |
|
51 /** |
|
52 * List of API's |
|
53 */ |
|
54 private ArrayList<TraceProjectAPI> apis = new ArrayList<TraceProjectAPI>(); |
|
55 |
|
56 /** |
|
57 * Constructor |
|
58 * |
|
59 * @param engine |
|
60 * the plug-in engine |
|
61 */ |
|
62 RulesEnginePluginManager(RulesEngine engine) { |
|
63 this.engine = engine; |
|
64 } |
|
65 |
|
66 /* |
|
67 * (non-Javadoc) |
|
68 * |
|
69 * @see com.nokia.tracebuilder.engine.plugin.TraceAPIPluginManager# |
|
70 * addFormatters(com.nokia.tracebuilder.plugin.TraceAPIFormatter[]) |
|
71 */ |
|
72 public void addFormatters(TraceAPIFormatter[] formatters) { |
|
73 if (formatters != null) { |
|
74 for (TraceAPIFormatter element : formatters) { |
|
75 apis.add(new PluginTraceFormatRule(element)); |
|
76 } |
|
77 } |
|
78 } |
|
79 |
|
80 /* |
|
81 * (non-Javadoc) |
|
82 * |
|
83 * @see com.nokia.tracebuilder.engine.plugin.TraceAPIPluginManager# |
|
84 * addParsers(com.nokia.tracebuilder.plugin.TraceAPIParser[]) |
|
85 */ |
|
86 public void addParsers(TraceAPIParser[] parsers) { |
|
87 // All parsers are registered to the model |
|
88 if (parsers != null) { |
|
89 for (TraceAPIParser element : parsers) { |
|
90 model.addExtension(new PluginTraceParserRule(element)); |
|
91 } |
|
92 } |
|
93 } |
|
94 |
|
95 /* |
|
96 * (non-Javadoc) |
|
97 * |
|
98 * @see com.nokia.tracebuilder.engine.plugin.TraceAPIPluginManager#createDefaultAPI() |
|
99 */ |
|
100 public void createDefaultAPI() { |
|
101 engine.setDefaultTraceAPI(); |
|
102 } |
|
103 |
|
104 /* |
|
105 * (non-Javadoc) |
|
106 * |
|
107 * @see com.nokia.tracebuilder.model.TraceModelExtension#getOwner() |
|
108 */ |
|
109 public TraceObject getOwner() { |
|
110 return model; |
|
111 } |
|
112 |
|
113 /* |
|
114 * (non-Javadoc) |
|
115 * |
|
116 * @see com.nokia.tracebuilder.model.TraceModelExtension# |
|
117 * setOwner(com.nokia.tracebuilder.model.TraceObject) |
|
118 */ |
|
119 public void setOwner(TraceObject owner) { |
|
120 model = (TraceModel) owner; |
|
121 } |
|
122 |
|
123 /* |
|
124 * (non-Javadoc) |
|
125 * |
|
126 * @see com.nokia.tracebuilder.project.TraceProjectAPIList#getAPIs() |
|
127 */ |
|
128 public Iterator<TraceProjectAPI> getAPIs() { |
|
129 return apis.iterator(); |
|
130 } |
|
131 |
|
132 /** |
|
133 * Adds an API to the list |
|
134 * |
|
135 * @param api |
|
136 * the API |
|
137 */ |
|
138 void addAPI(TraceProjectAPI api) { |
|
139 apis.add(api); |
|
140 } |
|
141 |
|
142 } |