Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Re: ApplyStereotype method - issue
Re: ApplyStereotype method - issue [message #522212] Sun, 21 March 2010 10:26 Go to next message
Ed Merks is currently offline Ed Merks
Messages: 26137
Registered: July 2009
Senior Member
Mario,

It's best to ask UML-specific question on the UML newsgroup/forum, which
I've added to the "to" list of the reply, so no need to repost.


mario wrote:
> Hello all,
> I got question concerning programatic approach to defing EMF models
> and applying profiles.
> I have problem with applying UML2 profile stereotypes to an Elements
> of the UML2 Model.
>
> Based on the following specifications:
> http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Getti ng_Started_with_UML2/article.html
> and
> http://www.eclipse.org/modeling/mdt/uml2/docs/articles/Intro duction_to_UML2_Profiles/article.html
> I've defined:
>
> 1. Model with: package1, package2 in package1, class in package1,
> attributes and operations in class.
> 2. and a Profile with stereotypes.
> Every time when I want to apply stereotype using
> 'applyStereotype(UMLElement, Stereotype)' I got an error:
>
> "java.lang.IllegalArgumentException:
> mailto:org.eclipse.uml2.uml.internal.impl.StereotypeImpl@19f332b (
> name: @Stereotype, visibility: <unset>) (isLeaf: false, isAbstract:
> true) (isActive: false)
> at org.eclipse.uml2.uml.internal.operations.ElementOperations.a
> pplyStereotype(ElementOperations.java:1411)
> at org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereoty
> pe(ElementImpl.java:499)
> ..."
>
> The following code snipped shows what Im doing now :
>
> protected static void registerPathmaps(URI uri) {
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),
> uri.appendSegment("libraries").appendSegment(""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),
> uri.appendSegment("metamodels").appendSegment(""));
>
>
> URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),
> uri.appendSegment("profiles").appendSegment(""));
> }
>
> protected static void registerResourceFactories() {
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
> UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> }
>
> ------------------------------------------------------------ -------
>
> URI uri = URI.createURI("file://home/mario/model.profile/resource");
>
> /* Part1: MODEL - model was creating properly */
> // creating model, packages, class, attributes and operations
> Model model = createModel("Model"); //Model
> createPackages("package1"); //Model::package1
> createPackages("package2"); //Model::package1::package2
> createClass("Class"); //Model::package1:package2::Class
> createAttribute("attribute1")
> //Model::package1:package2::Class::attribute1
> createAttribute("attribute2")
> //Model::package1:package2::Class::attribute2
> createMethods("method1"); //Model::package1:package2::Class::method1
> createMethods("method2");
> ////Model::package1:package2::Class::method2
> registerResourceFactories();
> registerPathmaps(URI.createURI(" jar:file:/home/mario/Programy/eclipse/plugins/org.eclipse.um l2.uml.resources_3.0.0.v200906011111.jar!/ "));
>
>
> writer.saveModel(model,
> uri.appendSegment(model.getNam()).appendFileExtension(UMLRes ource.FILE_EXTENSION));
>
>
> /* Part2: PROFILE - I got also properly generated and saved Profile*/
> // creating Profile
> Profile profileFromReader = createProfile("Profile");
>
> // importing primitive Type
> Type stringType = importPrimitiveType(profileFromReader, "String");
> Type boolType = importPrimitiveType(profileFromReader, "Boolean");
>
> // meta-classes
> Class propertyMetaClass = referenceMetaclass(profileFromReader,
> UMLPackage.Literals.PROPERTY.getName());
> Class packageMetaClass = referenceMetaclass(profileFromReader,
> UMLPackage.Literals.PACKAGE.getName());
>
> // stereotype examplewith with with Stereotype stereotype =
> createStereotype(profileFromReader, "@Stereotype", true);
> // stereotype property
> Property stereotypeProperty1 = stereotypeProperty =
> writer.writeAttribute(stereotype, "attributeStereo1", boolType, 0, 1);
> Property stereotypeProperty = writer.writeAttribute(stereotype,
> "attributeStereo2", stringType, 0, 1);
>
> // creating extensions
> createExtension(propertyMetaClass, stereotype, false);
> createExtension(packageMetaClass, stereotype, false);
>
> // defining Profile
> writer.defineProfile(profileFromReader);
>
> // saving Profile
> saveProfile(profileFromReader,
> uri.appendSegment("ProfileEx").appendFileExtension(UMLResource.PROFILE_FILE_EXTENSION));
>
>
> // loading model and standard profiles (ecore and standard)
> Model modelLoaded = (Model)
> load(uri.appendSegment(model.getName()).appendFileExtension( UMLResource.FILE_EXTENSION));
>
> Profile ecoreProfile = (Profile)
> load(URI.createURI("pathmap://UML_PROFILES/Ecore.profile.uml"));
> Profile standardProfile = (Profile)
> load(URI.createURI("pathmap://UML_PROFILES/Standard.profile.uml"));
>
> // applying ecore, standard and my profiles
> if(!model.isProfileApplied(ecoreProfile))
> writer.applyProfile(modelLoaded, ecoreProfile);
> if(!model.isProfileApplied(standardProfile))
> writer.applyProfile(modelLoaded, standardProfile);
> if(!modelLoaded.isProfileApplied(profileFromReader))
> writer.applyProfile(modelLoaded, profileFromReader);
>
> // HERE IS AN ISSUE :/
> // no matter if first parameter is Package, Class or Attribute...
> I got IllegalArgumentException
> applyStereotype(package1, stereotype)
> applyStereotype(class, stereotype)
> applyStereotype(attribute1, stereotype)[
>
>
> I've no idea what's wrong.... I've beed checking and comparing code
> with introduction from website several time. obviously I've searching
> for the answer on the forums but coudn't find for that case....
> Could someone help me? Maybe I'm doing sth with wrong order?
>
> Cheers,
> Mario
Re: ApplyStereotype method - issue [message #522233 is a reply to message #522212] Sun, 21 March 2010 15:25 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael Chaves
Messages: 161
Registered: July 2009
Senior Member
Mario, it seems you are making the stereotype to extend the right metaclasses, defining the profile, applying it to the package. Can't be 100% sure because much of the code does not show here. I could try to reproduce the problem but I would need the entire code, not only this class (or you could produce a more straightforward version of this code that was self-contained).

Or even better, you could try to step through the UML2 code and determine what is going on. The stacktrace you have tells this is the code in ElementOperations that is throwing the exception:

if (definition == null || getExtension(element, stereotype) == null
        || element.getStereotypeApplication(stereotype) != null) {
    throw new IllegalArgumentException(String.valueOf(stereotype));
}


If you debug into this section, you should be able which of the conditions is causing UML2 to reject your request to apply a stereotype to an element.

Cheers,

Rafael
http://abstratt.com/blog

[Updated on: Sun, 21 March 2010 15:26]

Report message to a moderator

Re: ApplyStereotype method - issue [message #522275 is a reply to message #522233] Mon, 22 March 2010 01:10 Go to previous messageGo to next message
mario is currently offline mario
Messages: 3
Registered: March 2010
Junior Member
Finally I found the solution.
I tried to apply my entire profile to the model AFTER applied 'ecore' and 'standard' profiles. It was incorrect because that EMF profiles was attached standard stereotypes to all elements from model. Therefore I coudn't apply any new stereotypes... -> 2 days of working... damm Wink

Rafael thanks for your answer.

Cheers

[Updated on: Mon, 22 March 2010 01:17]

Report message to a moderator

Re: ApplyStereotype method - issue [message #628331 is a reply to message #522212] Sun, 21 March 2010 15:25 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael Chaves
Messages: 161
Registered: July 2009
Senior Member
Mario, it seems you are making the stereotype to extend the right metaclasses, defining the profile, applying it to the package. Can't be 100% sure because much of the code does not show here. I could try to reproduce the problem but I would need the entire code, not only this class (or producing a more straightforward version of this code that was self-contained).

Or even better, you could try to step through the UML2 code and determine what is going on. The stacktrace you have tells this is the code in ElementOperations that is throwing the exception:


if (definition == null || getExtension(element, stereotype) == null
|| element.getStereotypeApplication(stereotype) != null) {
throw new IllegalArgumentException(String.valueOf(stereotype));
}


If you debug into this section, you should be able which of the conditions is causing UML2 to reject your request to apply a stereotype to an element.

Cheers,

Rafael
http://abstratt.com/blog
Re: ApplyStereotype method - issue [message #628332 is a reply to message #628331] Mon, 22 March 2010 01:10 Go to previous message
mario is currently offline mario
Messages: 3
Registered: March 2010
Junior Member
Finally I found the solution.
I tried to apply my entire profile to the model AFTER applied 'ecore' and 'standard' profiles. It was mistake because that EMF profiles was attached standard stereotypes to all elements from model. Therefore we coudn't apply any new stereotypes... -> 2 days of working...

Rafael thanks for your answer.

Cheers
Previous Topic:Re: ApplyStereotype method - issue
Next Topic:Unexpected interaction between UML Association#ownedEnds and DeleteCommand - AssocTest.java (1/1)
Goto Forum:
  


Current Time: Thu Oct 23 15:17:59 GMT 2014

Powered by FUDForum. Page generated in 0.02012 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software