Being a general purpose library, RoKlib offers a range of utility classes and frameworks for very different fields of application. The library does not fulfill one particular single purpose. Instead, it serves as a repository for all utility classes which originate from my open source projects and which can be reasonably employed in other software as well.
Following is a list of RoKlib's features together with a short description of them. This list is intended to provide you with a brief overview of RoKlib. You'll find more detailed descriptions for each of these items in the documentation section.
Overview
RoKlib provides an object-oriented abstraction model of boolean expressions. Usually, in the Java programming language boolean expressions are used in a static way. That is, when writing conditional code, for example when using if- or while-statements, predefined expressions are used to describe some condition. These expressions cannot change dynamically and are not reusable. In addition to that, the evaluation of a boolean expression merely leads to a branching decision in the control flow. No event is emitted that conveys the outcome of the evaluation to interested listeners.
The RoKlib library defines a set of classes which allow you to create an object representation of a boolean expression. Using this framework you can work with boolean expressions in an object-oriented way, that is you can use boolean expressions as method parameters or register listeners with them. When such an expression is evaluated all registered listeners are notified of the outcome of this operation.
There are situations when you want to simultaneously enable or disable a group of components based on some specific condition, or you want to make them conditionally (in)visible. Such a condition might in turn consist of a number of different other subconditions connected with boolean operators. Each of these conditions represents the state of one particular part of an application, such as for example whether the current user is anonymous or logged in, or whether a file has been opened for editing.
An example for this is the menu item for printing a document in a word processing application. This item may form a group with other GUI elements for printing the current document, such as push buttons or keyboard shortcuts. This group of elements should be disabled if it is not possible to print out a document at the moment. This is the case if no document has been opened or if the current user does not have the right to use the printing function.
It would now be very awkward to check each time that one of the governing condition changes if the items from the component group should be enabled or disabled. For example, if a printable document has been opended it must be checked if the current user is allowed to print and if so, all print items had to be enabled if they aren't already.
To make these situation easier to handle, RoKlib's conditional engine is used. A manager class is defined that manages groups of components. Each of these groups is associated with a condition object defining the condition for being enabled/disabled or visible/invisible. Each time the value of one of these conditions changes its value, an internal event is triggered and processed by the manager. Depending on the type of condition, the manager then decides if the component group should be enabled or disabled or made visible or invisible.
Quoting from Wikipedia.org: "In computer science, a ternary search tree is a ternary (three-way) tree data structure of strings which combines the speed of a prefix search tree, or trie, with the space efficiency of a binary search tree." This search tree allows extremely fast prefix matching and spell checking. RoKlib provides a full implementation of a ternary search tree which implements the java.util.SortedMap interface. The data structure allows a mapping of java.lang.CharSequence keys (which includes all Strings and StringBuffers) on an arbitrary data type. A case-insensitive implementation is also available. If only the prefix matching and spell checking capability without the map values is needed, a java.util.Set implementation of the ternary search tree is available as well.
The implementation of the ternary search tree was inspired by Wally Flint's article on JavaWorld.com.
As far as I know, RoKlib's implementation is the only Java implementation of this data structure which fully implements the java.util.SortedMap contract and which offers a case-insensitive mode. If I'm wrong with this assumption, I'd be glad to be corrected.
To assure the correctness of the ternary search tree implementation, currently some 250 unit tests exist exclusively for this data structure.
Even though most modern web application frameworks go to great lengths to hide the context of the web from the programmer and make writing a web application as natural as writing a desktop application, it often cannot be avoided to also address the particularities of the web. One of these areas is dealing with URLs. In spite of modern web technologies such as AJAX, which abstract away the request-response model of the web, you will often want to handle URLs visited by the user directly. RoKlib assists you in doing so in a structured, accurate and well maintainable way. It lets you define action handlers for every URL that can be visited by the user. To these handlers you add action commands which will be executed when a corresponding URL has been visited. These action handlers are arranged in a tree-like structure which mimics the directory strucure of a website's URL structure.
To each URL action handler, an arbitrary number of URL parameter objects can be added. These objects allow an automatic evaluation of the argument section of a URL. Thus, the direct parsing of a URL is not necessary. What's more, every action handler can generate a valid java.net.URL object corresponding to this handler and containing all URL parameter values in the URL's argument list with the values defined by the application. Thus, no error-prone manual assembling of URLs is necessary and the name of some URL parameter can be changed in one place.
RoKlib's URL action handling framework allows evaluating parameterized URLs in three different ways. Following are these three modes together with an example URL:
http://www.example.com/path/to/page?id=5&category=news&mode=view
http://www.example.com/path/to/page/id/5/category/news/mode/view
http://www.example.com/path/to/page/5/news/view
RoKlib provides some advanced graphical user interface classes and corresponding support classes. They are partly designed for Java Swing and can partly be used generically, for instance in company with web frameworks.
See the screenshot section for an example of that.
Defining the option set of a command line tool and having the command line arguments parsed by a command line argument parser can be accomplished with the CLI classes of RoKlib. You can configure the valid options of a program in several ways. For example, flag options, single value and list options can be configured. You can also declare two command line options as mutually exclusive. If the user then uses both options simultaneously, the options are marked as invalid and an error message can be shown to the user.
It is sometimes necessary to observe a file or directory on the local file system and have a callback function invoked when this file or directory has been modified. This package provides a FileModificationWatchdog thread that calls registered listeners when the observed file object has changed. There are listeners for the events that a file has been changed or deleted, and for the events that files have been added or removed from an observed directory.
The StreamUtilities class offers a convenient interface for data stream-related tasks. You can copy files directly using nothing more than the java.io.File class, copy a Reader to a Writer, or copy an InputStream into an OutputStream. In addition to that, it is also possible to directly read the contents of a File object, a Reader object, or an InputStream into a String. For InputStreams you can define the character set with which the data is encoded.
Extensibility through the use of plugins is one of the core feature of a lot of applications. In order to facilitate establishing a plugin architecture for a program, RoKlib provides a framework for writing plugins packaged as normal JAR files. A loader class takes care of loading these file from the file system or from a URL. With that, writing plugins is as easy as extending the AbstractPlugin class, defining some manifest entries in the plugin's MANIFEST.MF file and packaging the plugin's classes in a self-contained JAR file.
Excessive swapping of memory pages to and from the virtual memory is the performance death of any application. Therefore, it may be important for an application to become warned when such a situation arises. Unfortunately, the Java language does not provide any platform independent mechanism to detect excessive memory swapping (at least to my knowledge). RoKlib therefore provides a class framework which allows for setting up a swapping detection facility and respective event listeners which get notified of detected memory swapping conditions. There is a corresponding listener interface and an AbstractMemorySwappingDetectionThread available.
Since the detection mechanism itself is inherently platform dependent, there is also a concrete implementation of the AbstractMemorySwappingDetectionThread for Unix systems available which uses the vmstat command to detect excessive memory swapping.
The Java language offers the possibility to load resource files directly from the classpath or from JAR files on the classpath through java.net.URL class instances. RoKlib in turn provides a ResourceHandlingManager class that uses this mechanism to transparently locate and load such resources for a client. By this, a client does not have to handle URL object instances or locate the required resouces in the JAR files on the classpath on its own. A client only has to know the name of the resource.
Entities can have a domain-specific state. Usually defined by a private variable with a user-defined enum type, an entity's state can typically only be accessed on demand through its property accessor methods. RoKlib introduces a State class which encapsulates a state in an own object. Such a State object can now partake in a greater object-oriented scheme. For example, the State of an object can be used as the governing element of a condition object in RoKlib's conditional engine.
There are a number of recurring tasks and features which are needed for almost every web application. Among this is a user registration process, user management, user rights management, and so on. RoKlib offers a number of classes that support you in writing these features. For example, there are classes which manage the whole user registration process for you. You only have to write the glue code that binds these classes to your specific application.
In addition to that, RoKlib's web application support classes offer subclasses of State and special web-related condition classes for use with the condition engine. Then there is a role-enabled class GenericUser which represents a user of a web application.
Last but not least there are the obligatory helper and utility classes that make a programmer's life easier. Here is what RoKlib has to offer in this respect: