Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7877b17dc501f2d21054eeab6f41980865da9c9a (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
/*****************************************************************************
 * Copyright (c) 2010 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:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 *  Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Refactoring
 *  
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.service;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
import org.eclipse.papyrus.uml.diagram.common.service.palette.StereotypePostAction;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Visitor of an XML palette definition that keeps track of the required profiles
 */
public class XMLPaletteDefinitionProfileInspector implements XMLPaletteDefinitionVisitor, IPapyrusPaletteConstant {

	final private Collection<String> requiredProfiles;

	/**
	 * Gets the profiles required for the palette
	 * @return A collection of the required profiles
	 */
	public Collection<String> getRequiredProfiles() {
		return requiredProfiles;
	}
	
	/**
	 * Initializes the inspector
	 */
	public XMLPaletteDefinitionProfileInspector() {
		this.requiredProfiles = new HashSet<String>();
	}

	/**
	 * {@inheritDoc}
	 */
	public void onContent(Node node) {
		// nothing specific here
	}

	/**
	 * {@inheritDoc}
	 */
	public void onDrawer(Node node) {
		// nothing specific here
	}

	/**
	 * {@inheritDoc}
	 */
	public void onToolEntry(Node node) {
		// nothing specific here
	}

	/**
	 * {@inheritDoc}
	 */
	public void onStack(Node node) {
		// nothing specific here
	}

	/**
	 * {@inheritDoc}
	 */
	public void onSeparator(Node node) {
		// nothing specific here
	}

	/**
	 * {@inheritDoc}
	 */
	public void onAspectToolEntry(Node node) {
		if(node.getChildNodes().getLength() > 0) {
			NodeList children = node.getChildNodes();
			for(int i = 0; i < children.getLength(); i++) {
				Node childNode = children.item(i);
				String childName = childNode.getNodeName();
				if(IPapyrusPaletteConstant.POST_ACTION.equals(childName)) {
					// node is a post action => retrieve the id of the provider
					// in charge of this configuration
					IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
					if(provider != null) {
						IAspectAction action = provider.createAction(childNode);
						if(action instanceof StereotypePostAction) {
							List<String> stereotypesToApply = ((StereotypePostAction)action).getStereotypesToApply();
							for(String stereotypeQN : stereotypesToApply) {
								String profileName = PaletteUtil.findProfileNameFromStereotypeName(stereotypeQN);
								requiredProfiles.add(profileName);
							}
						}
					} else {
						Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
					}
				}
			}
		}
	}

}

Back to the top