Menu

Home

Uwe Pachler Gurce

NoSAF

This is a tool to convert your SAF-based projects into Non-SAF-based projects (ie, pure-ish Swing).

The wiki uses Markdown syntax.

Project Admins:

Draft usage notes

I wanted to share a few notes of my own personal experiences getting nosaf to work. This probably isn't the most 'ideal' form of documentation, but it's a start. Please correct, refine and improve as desired.

  • My personal learning curve relating to NoSAF started upon reading the following netbeans-bugzilla thread:
  • That thread relates to various users complaining about the removal of SAF-based projects-support from NetBeans upon the transition from NetBeans 7.0.1 to 7.1
  • A user there, rcasha, provided a tool he attached to his post. The attachment was called "XSLT file to convert SAF-based forms into non-SAF-based forms"
  • Within the "mb-nosaf.tgz" download, I found two things:
    • The "mb-nosaf/" sub-folder contained the actual tool (to be built with maven, then run by ant)
    • The "ConvertSAF/" sub-folder contained an example for you to test the tool on
      • The "ConvertSAF/SampleSAF" sub-folder housed a sample SAF application to be converted (treat it as your source folder)
      • The "ConvertSAF/SampleNoSAF" sub-folder served as sample of what the tool outputs (treat it as your destination folder)
  • NOTE: The contents of the download on this sourceforge site seem a little different, there's a mention of adding a frontend, I haven't looked into this thus far (the aforementioned example also seems to be missing). For those that know more about this, please feel free to elaborate on it here too. But for now, I'll focus here on the notes I gathered while using the original attachment from the bugzilla site.

Building the Tool

  • Edit the "mb-nosaf/src/main/resources/build.xml" file
  • Let's work with the given example, so modify the src and dest paths to the extracted paths for the sample source+destination examples on your hard-drive:
    <target name="all" depends="init">

        <!-- Replace these folders with a source copy of your project and a
             destination where they will be created. -->
        <convert src="${user.home}/**Systems/ConvertSAF/SampleSAF/src/main/java**"
                 dest="${user.home}/**Systems/ConvertSAF/SampleNoSAF/src/main/java**" />

    </target>
  • To build, I then go:
    • cd md-nosaf
    • mvn package (to build the *.jar package representing the tool)
  • At this point, I did bump into the following errors:
/home/gurce/Downloads/mb-nosaf/mb-nosaf/src/main/java/net/megabyte/nosaf/MBAction.java:[80,46] error: variable-arity methods are not supported in -source 1.3

  (use -source 5 or higher to enable variable-arity methods)
/home/gurce/Downloads/mb-nosaf/mb-nosaf/src/main/java/net/megabyte/nosaf/MBAction.java:[242,5] error: annotations are not supported in -source 1.3

  (use -source 5 or higher to enable annotations)
/home/gurce/Downloads/mb-nosaf/mb-nosaf/src/main/java/net/megabyte/nosaf/Utils.java:[136,9] error: annotations are not supported in -source 1.3

  (use -source 5 or higher to enable annotations)
/home/gurce/Downloads/mb-nosaf/mb-nosaf/src/main/java/net/megabyte/nosaf/XalanExt.java:[21,32] error: generics are not supported in -source 1.3
  • To overcome this, after reading a suggestion on google, I edited the "mb-nosaf/pom.xml" and added the following "<build>...</build>" section into it:
<project ....>
 <build>
  <plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
        </configuration>
    </plugin>
   </plugins>
  </build>
</project>
  • After doing so, the tool built fine for me.

Running the Tool (converting the forms)

  • Go to "cd mb-nosaf/target/classes"
    • Note that this contains a compiled copy of the "build.xml"
  • Type "ant all" to run the tool
    • This will scan the source path for all saf *.form files in your source-path and save them out in a tweaked non-saf-style in your destination-path

Additional Manual Steps (refreshing the source)

  • The tool only gets us halfway there, by just updating the *.form files.
  • To update the corresponding *.java files, open them up in the NetBeans IDE via the Matisse Form Editor
  • Slightly re-size the form in the editor and re-save it (this will update the details within the *.java file to be non-SAF also).

If you try build your app at this point, you might notice errors relating to a missing/unknown MSGS variable.

  • This can be resolved by adding the member variable into your class in a way similar to this:
public class Test {
  protected static final ResourceBundle MSGS = ResourceBundle.getBundle(MBAction.classBundleBaseName(Test.class));
  ...
  • If you build this, you will get another error relating to the missing "MBAction.classBundleBaseName()" method.
  • I saw two possible ways of going about resolving this:
    • A) From the "Building the Tool" steps you did earlier, find the *.jar file that was built (eg, "mb-nosaf-1.0.2-SNAPSHOT.jar"), and add it to your NetBeans project. (This .jar will provide you the MBAction.classBundleBaseName() method)
    • B) Alternatively, I didn't want to add the entire .jar file into my project, so I opted to just copy/paste the source for the MBAction.classBundleBaseName() method into my own application's source.

As an example of case B), I added the method into my "Common.java" file (where I put a lot of my common methods):

Public Common {
...
    public static String classBundleBaseName(Class cls) {
        String className = cls.getName();
        StringBuilder sb = new StringBuilder();
        int i = className.lastIndexOf('.');
        if (i > 0) {
            sb.append(className.substring(0, i));
            sb.append(".resources."); //NOI18N
            sb.append(cls.getSimpleName());
        } else {
            sb.append("resources."); //NOI18N
            sb.append(cls.getSimpleName());
        }
        return sb.toString();
    }
...
}

Then I could re-write the line earlier as follows:

public class Test {
  protected static final ResourceBundle MSGS = ResourceBundle.getBundle(Common.classBundleBaseName(Test.class));
  ...

You should then be able to successfully run the app non-SAF-ified app successfully within newer versions of NetBeans.

Still, I did notice that some of the text-strings within the mattise editor looked a bit funny/odd, with lots of angled brackets. Despite things looking a bit weird in the matisse editor, all these text-strings looked fine when the app was run, so I suppose I'm content with that for now...

Ok, that about wraps up all the notes I jotted down on this occasion. Feel free to add more details with your own findings and usage-cases. Gurce (22/02/2016).


MongoDB Logo MongoDB