Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 361382 | Differences between
and this patch

Collapse All | Expand All

(-)a/plugins/org.eclipse.xtend.typesystem.uml2/src/org/eclipse/xtend/typesystem/uml2/profile/ProfilingExtensions.java (-1 / +32 lines)
Lines 12-18 package org.eclipse.xtend.typesystem.uml2.profile; Link Here
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.HashMap;
15
import java.util.List;
16
import java.util.List;
17
import java.util.Map;
16
18
17
import org.apache.commons.logging.Log;
19
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
20
import org.apache.commons.logging.LogFactory;
Lines 81-86 public class ProfilingExtensions { Link Here
81
		}
83
		}
82
	}
84
	}
83
	
85
	
86
	/*
87
	 * Caching Profiling Extensions fixes memory leaks. 
88
	 */
89
	private static final Map<String, Profile> ourProfileCache = new HashMap<String, Profile>(1);
90
84
	/**
91
	/**
85
	 * Applies a profile to a Package (or Model).
92
	 * Applies a profile to a Package (or Model).
86
	 * @param model The UML Package instance.
93
	 * @param model The UML Package instance.
Lines 88-104 public class ProfilingExtensions { Link Here
88
	 * @return The loaded Profile
95
	 * @return The loaded Profile
89
	 */
96
	 */
90
	public static Profile applyProfile (org.eclipse.uml2.uml.Package pck, String uri) {
97
	public static Profile applyProfile (org.eclipse.uml2.uml.Package pck, String uri) {
98
		return applyProfile2(pck, uri, false);
99
	}
100
	
101
	/**
102
	 * Applies a profile to a Package (or Model).
103
	 * @param model The UML Package instance.
104
	 * @param uri Resource Path to the .profile.uml/.profile.uml2 file.  
105
	 * @param cacheProfile true if profile should be cached
106
	 * @return The loaded Profile
107
	 */
108
	public static Profile applyProfile2 (org.eclipse.uml2.uml.Package pck, String uri, java.lang.Boolean cacheProfile) {
91
		new Setup().setStandardUML2Setup(true);//setup pathmap
109
		new Setup().setStandardUML2Setup(true);//setup pathmap
92
		if (!uri.endsWith(".profile.uml2") && !uri.endsWith(".profile.uml")) {
110
		if (!uri.endsWith(".profile.uml2") && !uri.endsWith(".profile.uml")) {
93
			uri += ".profile.uml";
111
			uri += ".profile.uml";
94
		}
112
		}
95
		Profile profile = (Profile) new XmiReader().load(uri);
113
		Profile profile;
114
		if (cacheProfile) {
115
			profile = getProfileForURI(uri);
116
		} else {
117
			profile = (Profile) new XmiReader().load(uri);
118
		}
96
		if (profile==null) {
119
		if (profile==null) {
97
			throw new NullPointerException("Profile '"+uri+"' not loaded.");
120
			throw new NullPointerException("Profile '"+uri+"' not loaded.");
98
		}
121
		}
99
		pck.applyProfile(profile);
122
		pck.applyProfile(profile);
100
		return profile;
123
		return profile;
101
	}
124
	}
125
126
	protected static synchronized Profile getProfileForURI(String profileURI) {
127
		if (!ourProfileCache.containsKey(profileURI)) {
128
			Profile profile = (Profile) new XmiReader().load(profileURI);
129
			ourProfileCache.put(profileURI, profile);
130
		}
131
		return ourProfileCache.get(profileURI);
132
	}
102
	
133
	
103
	/**
134
	/**
104
	 * Applies a stereotype by name to an Element. 
135
	 * Applies a stereotype by name to an Element. 
(-)a/plugins/org.eclipse.xtend.typesystem.uml2/src/org/eclipse/xtend/typesystem/uml2/profile/profiling.ext (-2 / +3 lines)
Lines 4-12 import uml; Link Here
4
Standard UML2 Extensions for Profile support.
4
Standard UML2 Extensions for Profile support.
5
*/
5
*/
6
6
7
Profile applyProfile (Model model, String uri) :
7
Profile applyProfile (Package model, String uri) :
8
	JAVA org.eclipse.xtend.typesystem.uml2.profile.ProfilingExtensions.applyProfile(org.eclipse.uml2.uml.Package, java.lang.String);
8
	JAVA org.eclipse.xtend.typesystem.uml2.profile.ProfilingExtensions.applyProfile(org.eclipse.uml2.uml.Package, java.lang.String);
9
9
10
Profile applyProfile (Package model, String uri, Boolean cacheProfile) :
11
	JAVA org.eclipse.xtend.typesystem.uml2.profile.ProfilingExtensions.applyProfile2(org.eclipse.uml2.uml.Package, java.lang.String, java.lang.Boolean);
10
	
12
	
11
cached Stereotype getStereotype (Model m, String stereotype) :
13
cached Stereotype getStereotype (Model m, String stereotype) :
12
	m.getAppliedProfiles().allOwnedElements().typeSelect(Stereotype).select(st|st.qualifiedName==stereotype).first();
14
	m.getAppliedProfiles().allOwnedElements().typeSelect(Stereotype).select(st|st.qualifiedName==stereotype).first();
13
- 

Return to bug 361382