Introduction

In this guide we will describe the basic concepts of using JParam, and the interface used to extend it for your own usage.

Basic usage

  1. Parsing and Formatting data, serialization
  2. Handling of complex input parameters
This guide is still very preliminary, but the XParam Guide can be a very good reference regarding the concepts of using JParam, most of the examples (except for the template related ones) are valid for JParam as well, so it is very recommended to use it as a reference.

Parser/Formatter

The most simplistic usage of JParam is to read and write object from/into readable text.

The interface is very simple:

JParam can in the same way be used for serialization by using the very similar methods but with streams:

Input Parameter Handling

The reacher and more elaborate usage is handling input parameters. Using the ParamSet along with the different Param classes, it is possible to define a set of arguments along with restrictions and excpected types, and have those argument handled by ParamSet input method or one of its variant.

This enables the user to handle a complex set of arguments each potentially representing a complex variable. If for some reason the input doesn't conform to the defined parameter set JParam will throw a meaningfull error indicating what was the problem.

Because the ParamSet class encapsulates all the information needed for handling input, it can perform additional stuff such as "Usage:" output to the user, context sensitive help, and argument matching (the user can pass only a prefix of the argument and if it is not ambigous it will be used).

Another options that makes JParam very appealing for parameter handling is inherent support for redirection, the "@" directive can be used to inform JParam to read input from another location, the location is indicated by a URL. Redirection is enabled both as additional assignments (a file containing arg=val pairs), and value assignments (arg=@file.txt).

Since command line operation was in mind, a special construct of "shell_strings" is supported as an input, which enables execution of commands with '*' directives that in certain unix shell will be translated by the shell itself to a space delimited list of file names. This construct will automatically be converted to a list of Strings, enableling an application to use these advanced shell features.