|
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. |