Topic
9 replies Latest Post - ‏2013-01-10T11:38:08Z by MerlinUK
SystemAdmin
SystemAdmin
1305 Posts
ACCEPTED ANSWER

Pinned topic plugin command in the hep file

‏2012-12-21T07:02:51Z |
Hello experts,

I have a question on helpers file. Is there any plugin commands for a customized stereotype? I've created a stereotype (e.g. <<MySystem>>) applicable to Rhapsody project Packages only.
Then, in the helpers file is there any command, for example, applicableToStereotype = MySystem.

thanks in advance

Best
A.John
Updated on 2013-01-10T11:38:08Z at 2013-01-10T11:38:08Z by MerlinUK
  • MerlinUK
    MerlinUK
    106 Posts
    ACCEPTED ANSWER

    Re: plugin command in the hep file

    ‏2012-12-21T09:04:16Z  in response to SystemAdmin
    That should work - provided your Stereotype is a New Term
    You cannot use applicableTo for 'ordinary' stereotypes

    Cheers
    Andy
    • SystemAdmin
      SystemAdmin
      1305 Posts
      ACCEPTED ANSWER

      Re: plugin command in the hep file

      ‏2012-12-24T08:13:27Z  in response to MerlinUK
      Hi Andy,
      If I want to specify the package with the new stereotype using java method, how it could be?

      Let's say I have a Rhapsody function when it is activated:
      1)get the current package name:- getName()?
      2)add my new stereotype on it:- addStereotype()?
      3)check whether it exist or not.

      Best regards,
      John
      • MerlinUK
        MerlinUK
        106 Posts
        ACCEPTED ANSWER

        Re: plugin command in the hep file

        ‏2013-01-02T10:37:10Z  in response to SystemAdmin
        Hi John
        Not sure if I'm understanding you correctly:

        1. yes the getname() function will return the name of the Package
        2. You could use AddStereotype - in which case Rhapsody will add the stereotype if the stereotype exists - or create a new one if it doesnt
        3. Do you mean check if the Stereotype exists ? In which case I would look for the Stereotype first and then use setStereotype to apply it .. something like this:

        
        
        
        private 
        
        static 
        
        boolean setStereotypeOnElement(IRPModelElement applyTo, String name) 
        { IRPModelElement elt = prj.findNestedElementRecursive(name, 
        "Stereotype"); 
        
        if (elt == 
        
        null) 
        
        return 
        
        false;   IRPStereotype st = (IRPStereotype) elt; 
        
        try 
        { applyTo.setStereotype(st); 
        
        return 
        
        true; 
        } 
        
        catch (Exception e) 
        { 
        //In Case the Stereotype is not Applicable to the Selected Element 
        
        return 
        
        false; 
        }     
        }
        

        btw if this is all you want to do then the stereotype does not have to be a new term. You can make your helper applicableTo Package
        • SystemAdmin
          SystemAdmin
          1305 Posts
          ACCEPTED ANSWER

          Re: plugin command in the hep file

          ‏2013-01-08T06:47:35Z  in response to MerlinUK
          Hi again Andy,

          If I have a package named e.g. MyPackage and it is stereotyped with e.g. <<MyLibrary>>, so I need to check weather or not the package has been applied with the said stereotype. if it is true it should do the next task. I don't know which Rhapsody interfaces and java method to use.

          Hope you can help.

          Best
          A.John
        • SystemAdmin
          SystemAdmin
          1305 Posts
          ACCEPTED ANSWER

          Re: plugin command in the hep file

          ‏2013-01-08T06:49:34Z  in response to MerlinUK
          Hi again Andy,

          If I have a package named e.g. MyPackage and it is stereotyped with e.g. <<MyLibrary>>, so I need to check weather or not the package has been applied with the said stereotype. if it is true it should do the next task. I don't know which Rhapsody interfaces and java method to use.

          Hope you can help.

          Best
          A.John
          • MerlinUK
            MerlinUK
            106 Posts
            ACCEPTED ANSWER

            Re: plugin command in the hep file

            ‏2013-01-08T09:30:49Z  in response to SystemAdmin
            I tend to maintain my own libraries of utility functions like that - here's mine - it works for any model element not just packages

            
            
            
            public 
            
            static 
            
            boolean hasStereotype(IRPModelElement elt, String name)
            { 
            /* * Checks if a model element has a certain Stereotype */ 
            
            for (Object o:elt.getStereotypes().toList()) 
            { IRPStereotype s = (IRPStereotype) o; 
            
            if (s.getName().equals(name)) 
            
            return 
            
            true; 
            } 
            
            return 
            
            false; 
            }
            
            • SystemAdmin
              SystemAdmin
              1305 Posts
              ACCEPTED ANSWER

              Re: plugin command in the hep file

              ‏2013-01-09T06:34:17Z  in response to MerlinUK
              Hi,

              How to retrieve a package name if the package has the stereotype applied?

              could it be like this?
              /* checks if the package has a certain stereotype*/
              for (Object o:elt.getStereotypes().toList()) {
              IRPStereotype s = (IRPStereotype) o;
              if (s.getName().equals(name))
              elt.getName();<---does this return the package name if the stereotype has been applied?
              }

              I've tried it but doesn't work. Here is my sample code:-

              String stereotypeName = "MyLibrary";
              IRPPackage pkg = (IRPPackage) prj.getStereotypes().toList();
              /*
              * IRPPackage pkg = (IRPPackage) prj.findNestedElementRecursive(
              * stereotypeName, "Stereotype");
              */
              IRPStereotype s = (IRPStereotype) pkg;
              if (s.getName().equals(stereotypeName)) {
              packageName = pkg.getName();
              m_rhpApplication.writeToOutputWindow("Log",
              (new StringBuilder("\n")).append(packageName)
              .toString());
              }
              • MerlinUK
                MerlinUK
                106 Posts
                ACCEPTED ANSWER

                Re: plugin command in the hep file

                ‏2013-01-10T11:38:08Z  in response to SystemAdmin
                Hi ..
                Sorry but the code you have here is fundamentally flawed - for example ..

                IRPPackage pkg = (IRPPackage) prj.getStereotypes().toList();

                (a) You cannot cast a Stereotype to a Package - that will cause an exception.

                (b) You cannot cast a List of any type to a single element

                Try something like this instead:

                
                
                
                public 
                
                static 
                
                void test() 
                { String stereotypeName = 
                "MyLibrary"; 
                
                for (Object o: prj.getNestedElementsRecursive().toList()) 
                { IRPModelElement e = (IRPModelElement) o; 
                
                if (e.getMetaClass().equals(
                "Package")) 
                { IRPPackage pkg = (IRPPackage) e; IRPStereotype s = pkg.getStereotype(); 
                
                if (s !=
                
                null) 
                { 
                
                if (s.getName().equals(stereotypeName)) 
                { String packageName = pkg.getName(); rpy.writeToOutputWindow(
                "Log", (
                
                new StringBuilder(
                "\n")).append(packageName).toString()); 
                } 
                } 
                } 
                } 
                }
                


                Note that getStereotype() is deprecated and instead you should really iterate over the stereotypes as I showed in a previous post (although this will work right now)
  • SystemAdmin
    SystemAdmin
    1305 Posts
    ACCEPTED ANSWER

    Re: plugin command in the hep file

    ‏2012-12-24T03:29:48Z  in response to SystemAdmin
    Many thanks, Andy.