Geertjan's Blog

  • November 6, 2011

On the methodvalue attribute in layer.xml file

Geertjan Wielenga
Product Manager

The methodvalue attribute can be in form of pgk1.pkg2.ClassName.methodName
which should point to existing class with static method usually having
no, one or two arguments. This method does not need to be public or in
public class, if the filesystem has permissions to call the method. The
method can take one of the following 5 signatures:

static Value methodName();
static Value methodName(FileObject fo);
static Value methodName(FileObject fo, String attrName);
static Value methodName(Map attrs); // since 7.0
static Value methodName(Map attrs, String attrName); // since 7.0

where Value can be any java type.

For example, note the line in bold below:

<folder name="Actions">
    <folder name="Build">
        <file name="org-module1-SomeAction.instance">
            <attr bundlevalue="org.module1.Bundle#CTL_SomeAction" name="displayName"/>
name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled" />
            <attr name="delegate" newvalue="org.module1.SomeAction"/>
            <attr boolvalue="false" name="noIconInMenu"/>

You can see a method "alwaysEnabled" is being referred to in a class called "Actions". Here's that method:

    static Action alwaysEnabled(Map map) {
        return AlwaysEnabledAction.create(map);

So, in the above code, you see the 4th of the 5 signatures shown at the start of this blog entry. The "map" consists of all the attributes defined in the layer entry and now you can use them elsewhere.

Great blog entry (in German) by Jens Hofschröer in Aachen:


Join the discussion

Comments ( 1 )
  • Jens Hofschr&ouml;er Monday, November 7, 2011


    Even though the comments says "since 7.0", these methods are available since NetBeans 6.7


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.