JBoss.orgCommunity Documentation

Chapter 4. Developing a Validator

4.1. Create the Validator OSGi bundle
4.2. Establish Bundle Dependencies
4.3. Implement the Module
4.4. Create the Maven POM

This section will describe how to create a validator, using the 'simple validator' example within the Scribble distribution samples/validator/simple.validator folder.

This section will explain how to create an OSGi bundle for a validator from within the Eclipse environment.

The first step is to create the plugin project, using the New->Project->Plugin Project menu item.

Ensure the 'Create java project' checkbox is ticked, and then set the source folder to be src/main/java and set the Target Platform to a standard 'OSGi Framework'.

Then press the Next button to set some details associated with the plugin, such as the version, description, provider, etc.

In this example, we will be registering the validator using the OSGi registerService method. This is performed in the bundle activator, whose class is set in the plugin details. For example, in the start method of the created Activator, we would have:

Depending on the type of bundle being developed, it may have a different set of dependencies than the ones required by this 'simple' validator. However the configuration approach will be the same.

Go to the META-INF/MANIFEST.MF file and select it. This will cause the plugin manifest editor to be displayed.

Select the Dependencies tab and select the other bundles that will be required, or preferrably select the packages to be imported (as this avoids dependency on specific bundles, and instead just identifies the packages required). For this example validator, we just need to add the packages from the org.scribble.common bundle which is used by all Scribble plugins. However if additional packages were required, then they could be added as imported packages (e.g. org.scribble.protocol.model and org.scribble.protocol.validation).

Each module will be different, and therefore discussing specific implementation details will not be possible.

However validation modules will tend to access the complete model, but possibly only be interested in certain parts of it. Therefore usually the validation modules will define an implementation of the org.scribble.protocol.model.Visitor interface.

In the example validator, there is a SimpleValidatorVisitor class that is derived from the DefaultVisitor , and only overrides the method to accept an interaction. Therefore only validation of interactions is of interest to this validator. In this particular case, the validator is checking the message types, and reporting an error if a particular value is detected.

The actual main class within the validator module would implement the org.scribble.protocol.validation.ProtocolValidator interface.

There may also exist specialised implementations of the ProtocolValidator interface that help support the validation process. For example, the ProtocolComponentValidator which triggers a ProtocolComponentValidatorRule based on the type of the model component. The visitor is used to traverse the model to identify the model components being validated. So its possible, if validation of only a couple of model component types is required (as in the simple validator), to derive a specialisation of the ProtocolComponentValidator class with the relevant rule implementations.

The simple validator in the Scribble samples uses Maven to build the OSGi bundle.

The main aspect of the Maven pom is to define the dependencies, which are equivalent to the ones defined in the MANIFEST.MF, and to customise the build phase to make sure the delivered jar has the MANIFEST.MF included, rather than the default one.