logo of the SSW institute
Institut für Systemsoftware
Johannes Kepler Universität Linz
Fachbereich Informatik
logo of the Cristian Doppler Research Association
Christian Doppler Labor
Monitoring and Evolution of Very-Large-Scale Software Systems

Home

General
Staff
Contact
Partners
Alumni

Research
Areas
Projects
Papers
Books
Reports
Awards

Teaching
Lectures
Exams
B.Projects
M.Theses
PhD Theses
Go Abroad

Misc
Library
Seminars
Gallery
Links
Search

Webmaster


logo of the Johannes Kepler University (JKU)
back

WordApp Example - Part 2

  • Create a new NetBeans module named "TextFilter" with code name base "at.ssw.textfilter" and add it to the module suite.

  • Create a new Java interface at.ssw.textfilter.TextFilter with a method process.
    public interface TextFilter {
        String process(String s);
    }
    

  • Make the interface accessible from other modules by selecting the package "at.ssw.textfilter" to be part of the public API. This can be done in the properties dialog of the "TextFilter" module.
    screen10

  • Create a new NetBeans module named "MyFilter with code name base "at.ssw.myfilter" and add it to the module suite.

  • Add a module dependency in the properties dialog of the newly created module to the "TextFilter" module.
    screen11

  • Create a class at.ssw.myfilter.UpperCaseFilter that implements the TextFilter interface.
    public class UpperCaseFilter implements TextFilter {
        public String process(String s) {
            return s.toUpperCase();
        }
    }
    

  • Now register the UpperCaseFilter class as an implementor of the TextFilter interface. This can be done by creating a file in the folder src/META-INF/services called at.ssw.textfilter.TextFilter with a single line containing the string "at.ssw.myfilter.UpperCaseFilter".
    screen12

  • The code that handles a click on the filter button now needs to be changed, such that an implementor of the interface TextFilter is searched. When such an implementor is found, it is invoked to filter the text. Before we can do this, we need to add a dependency in the properties dialog of the "WordEngine" module to the "TextFilter" module.
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String s = text.getText();
        TextFilter filter = Lookup.getDefault().lookup(TextFilter.class);
        if (filter != null) {
    	 s = filter.process(s);
        }
        text.setText(s);
    }  
    
    

  • Now you are ready to run the code and check that everything works just as before. While the functionality is the same, the new modular design offers a clear separation between the graphical user interface and the implementation of the filter. The new application has also an increased extensibility.

  • PROPOSAL: As an exercise you could change the code, such that ALL found text filters (use the method lookupAll) are applied consecutively on the text. Add a text filter implementation that removes all whitespaces and test the resulting application.
feedback
back