Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 73901b41aeb968f58b6746afc8014d3a30d3f844 (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
/*****************************************************************************
 * Copyright (c) 2008 CEA LIST.
 *
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *  Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
 *  Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.tools.profile.definition;

import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EcoreFactory;

/**
 * Class that defines various information about a profile definition (author,
 * version, etc.)
 */
public class PapyrusDefinitionAnnotation {

	/** version of the definition */
	private Version version = Version.emptyVersion;

	/** Comment of the definition */
	private String comment = "";

	/** Copyright of the definition */
	private String copyright = "";

	/** date of the definition */
	private String date = "";

	/** author of the definition */
	private String author = "";

	/** undefined PapyrusDefinitionAnnotation */
	public static PapyrusDefinitionAnnotation UNDEFINED_ANNOTATION = new PapyrusDefinitionAnnotation(
			Version.emptyVersion, "<undefined>", "", "", "<undefined>");

	/**
	 * Creates a new PapyrusDefinitionAnnotation.
	 *
	 * @param version
	 *            the version of the definition
	 * @param comment
	 *            the comment associated to this definition
	 * @param copyright
	 *            the copyright of this definition
	 * @param date
	 *            the date this definition was generated
	 * @param the
	 *            author responsible of this definition
	 */
	public PapyrusDefinitionAnnotation(Version version, String comment, String copyright, String date, String author) {
		this.version = version;
		this.comment = comment;
		this.copyright = copyright;
		this.author = author;
		this.date = date;
	}

	/**
	 * Creates a Eannotation from the given configuration
	 *
	 * @return the eAnnotation corresponding to this configuration
	 */
	public EAnnotation convertToEAnnotation() {
		EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
		// set various values (default if elements are null)
		annotation.setSource(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
		annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY, version.toString());
		annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY, comment);
		annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY, copyright);
		annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_DATE_KEY, date);
		annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY, author);
		return annotation;
	}

	/**
	 * Return the PapyrusDefinitionAnnotation corresponding to the given
	 * EAnnotation
	 *
	 * @param annotation
	 *            the annotation to parse
	 * @return a image of the given annotation, with default values if needed.
	 */
	public static PapyrusDefinitionAnnotation parseEAnnotation(EAnnotation annotation) {
		final String versionValue = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY);
		Version version;
		try {
			version = Version.parseVersion(versionValue);
		} catch (IllegalArgumentException e) {
			version = Version.emptyVersion;
		}
		final String comment = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY);
		final String copyright = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY);
		final String date = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_DATE_KEY);
		final String author = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY);
		return new PapyrusDefinitionAnnotation(version, (comment != null) ? comment : "",
				(copyright != null) ? copyright : "", (date != null) ? date : "", (author != null) ? author : "");
	}

	/**
	 * Returns the version of the definition of the profile
	 *
	 * @return the version of the definition of the profile
	 */
	public Version getVersion() {
		return version;
	}

	/**
	 * Returns the comment associated to the definition of the profile
	 *
	 * @return the comment associated to the definition of the profile
	 */
	public String getComment() {
		return comment;
	}

	/**
	 * Returns the copyright associated to the definition of the profile
	 *
	 * @return the copyright associated to the definition of the profile
	 */
	public String getCopyright() {
		return copyright;
	}

	/**
	 * Returns the date associated to the definition of the profile
	 *
	 * @return the date associated to the definition of the profile
	 */
	public String getDate() {
		return date;
	}

	/**
	 * Returns the author responsible to the definition of the profile
	 *
	 * @return the author responsible to the definition of the profile
	 */
	public String getAuthor() {
		return author;
	}
}

Back to the top