Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 21043ddda8089f725840702f69fa41654302302b (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
 * Copyright (c) 2017 CEA LIST.
 * 
 *  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:
 *  Maged Elaasar - Initial API and implementation
 *  
 * 
 */
package org.eclipse.papyrus.infra.core.architecture.merged;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.infra.core.architecture.ADElement;
import org.eclipse.papyrus.infra.core.architecture.ArchitectureContext;
import org.eclipse.papyrus.infra.core.architecture.ArchitectureViewpoint;
import org.eclipse.papyrus.infra.types.ElementTypeSetConfiguration;
import org.osgi.framework.Bundle;

/**
 * An element that represents a merged collection of {@link org.eclipse.papyrus.infra.core.
 * architecture.ArchitectureContext}s. This allows the definition of architecture contexts 
 * to be split across several architectural models (*.architecture). 
 * 
 * This class is a subclass of {@link org.eclipse.papyrus.infra.core.architecture.merged.
 * MergedADElement}s
 *  
 * @see org.eclipse.papyrus.infra.core.architecture.ArchitectureContext
 * @since 1.0
 */
public abstract class MergedArchitectureContext extends MergedADElement {

	/**
	 * Create a new '<em><b>Merged Architecture Context</b></em>'.
	 *
	 * @param domain the merged parent domain of this context
	 */
	public MergedArchitectureContext(MergedArchitectureDomain domain) {
		super(domain);
	}

	/**
	 * Gets the context's extension prefix
	 * 
	 * @return an extension prefix
	 */
	public String getExtensionPrefix() {
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			if (context.getExtensionPrefix() != null)
				return context.getExtensionPrefix();
		}
		return null;
	}

	/**
	 * Gets the context's creation command class
	 * 
	 * @return a creation command class
	 */
	public Class<?> getCreationCommandClass() throws ClassNotFoundException {
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			if (context.getCreationCommandClass() != null) {
				URI uri = context.eResource().getURI();
				if (uri.isPlatformPlugin()) {
					String bundleName = uri.segment(1);
					Bundle bundle = Platform.getBundle(bundleName);
					return bundle.loadClass(context.getCreationCommandClass());
				}
			}
		}
		return null;
	}

	/**
	 * Gets the context's conversion command class
	 * 
	 * @return a conversion command class
	 */
	public Class<?> getConversionCommandClass() throws ClassNotFoundException {
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			if (context.getConversionCommandClass() != null) {
				URI uri = context.eResource().getURI();
				if (uri.isPlatformPlugin()) {
					String bundleName = uri.segment(1);
					Bundle bundle = Platform.getBundle(bundleName);
					return bundle.loadClass(context.getConversionCommandClass());
				}
			}
		}
		return null;
	}

	/**
	 * Gets the context's creation command class name
	 * 
	 * @return a creation command class name
	 * @since 2.0
	 */
	public String getCreationCommandClassName() {
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			if (context.getCreationCommandClass() != null) 
				return context.getCreationCommandClass();
		}
		return null;
	}

	/**
	 * Gets the context's conversion command class name
	 * 
	 * @return a conversion command class name
	 * @since 2.0
	 */
	public String getConversionCommandClassName() {
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			if (context.getConversionCommandClass() != null)
				return context.getConversionCommandClass();
		}
		return null;
	}

	/**
	 * Gets the context's parent domain
	 * 
	 * @return the parent domain
	 */
	public MergedArchitectureDomain getDomain() {
		return (MergedArchitectureDomain) getParent();
	}

	/**
	 * Gets the context's element type set configurations
	 * 
	 * @return a merged collection of element type set configurations
	 */
	public Collection<ElementTypeSetConfiguration> getElementTypes() {
		Set<ElementTypeSetConfiguration> configurations = new LinkedHashSet<ElementTypeSetConfiguration>();
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			configurations.addAll(context.getElementTypes());
		}
		return Collections.unmodifiableCollection(configurations);
	}

	/**
	 * Gets the context's viewpoints
	 * 
	 * @return a merged collection of viewpoints
	 */
	public Collection<MergedArchitectureViewpoint> getViewpoints() {
		Map<String, MergedArchitectureViewpoint> viewpoints = new HashMap<String, MergedArchitectureViewpoint>();
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			for (ArchitectureViewpoint viewpoint : context.getViewpoints()) {
				MergedArchitectureViewpoint merged = viewpoints.get(viewpoint.getName());
				if (merged == null) {
					viewpoints.put(viewpoint.getName(), merged = new MergedArchitectureViewpoint(this));
				}
				merged.merge(viewpoint);
			}
		}
		return Collections.unmodifiableCollection(viewpoints.values());
	}

	/**
	 * Gets the context's default viewpoints
	 * 
	 * @return a merged collection of viewpoints
	 */
	public Collection<MergedArchitectureViewpoint> getDefaultViewpoints() {
		Map<String, MergedArchitectureViewpoint> viewpoints = new HashMap<String, MergedArchitectureViewpoint>();
		for (ADElement element : elements) {
			ArchitectureContext context = (ArchitectureContext) element;
			for (ArchitectureViewpoint viewpoint : context.getDefaultViewpoints()) {
				MergedArchitectureViewpoint merged = viewpoints.get(viewpoint.getName());
				if (merged == null) {
					viewpoints.put(viewpoint.getName(), merged = new MergedArchitectureViewpoint(this));
				}
				merged.merge(viewpoint);
			}
		}
		return Collections.unmodifiableCollection(viewpoints.values());
	}

}

Back to the top