JBoss.orgCommunity Documentation

Scribble 2.0

Developer Guide


1. Overview
2. Project Structure
2.1. Project Management
2.1.1. Issue Management
2.1.2. Project Build Management
2.2. Distribution
2.3. Integration
2.3.1. Command Line
2.3.2. Embedded Java
2.3.3. Eclipse
2.4. Modules
2.5. QA
2.5.1. Protocol Conformance Test Kit (CTK)
2.6. Samples
3. Architecture
3.1. OSGi Infrastructure
3.2. Core Components
3.2.1. Error Logging
3.2.2. Protocol Model
3.2.3. Protocol Parser
3.2.4. Protocol Projection
3.2.5. Protocol Validation Manager and Validators
3.2.6. Exporting the Protocol model to other representations
3.2.7. Scribble Protocol Monitor
3.3. Command Line Actions
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 developers guide is intended for two groups of developers,

The document initially discusses information about the project itself, to provide background information on how issues are managed, and the build and distribution performed.

The document then discusses the architecture of the tool chain.

Finally we will look in more detail at how a validation module can be added to the tool chain.

This section outlines the technology used to manage the different aspects of the project.

The issue management is handled through the JIRA system located at https://jira.jboss.org/browse/SCRIBBLE.

Issues can be created for bugs, feature requests and tasks. Bugs are used to report unexpected behaviour, and will generally be created by language/tool users. Feature requests can equally be used by users to request new language or tool features.

Tasks will only generally be created by project developers, as a way of keeping track of work that needs to be done, potentially in support of bugs or feature requests.

Issues in JIRA can be linked, where a dependency exists. It is also possible to create a simple hierarchiy with tasks, such that a parent task can contain related sub-tasks.

An important usage of the issue management system is to keep track of what issues are associated released versions of the tools, and what target release they will be implemented or fixed within. This enables users to understand the schedule of features and bug fixes, aswell as providing an automated mechanism for providing release notes describing the work associated with a particular release.

The runtime branch of the project is concerned with providing integration of the OSGi bundles, defined in the tools/bundles branch, in different execution environments.

The Scribble tools architecture is based on OSGi, which means that the OSGi compliant bundles can run within any OSGi compliant service container. However OSGi is a service framework, intended to manage services in a service container (or server).

Therefore, to leverage OSGi bundles (or services), from a command line invoked application, we need to select a specific OSGi implementation that supports this approach, as it is not defined as part of the OSGi standard.

Therefore, to provide this command line capability, we have selected the Apache Felix OSGi implementation. This is the reason that the Felix jars are included in the distribution's lib sub-folder, rather than just implementation independent OSGi jars.

Although it is possible to define new modules as part of the Scribble project, it is also possible to develop them independently and just place them within the bundle folder of the installed (unpacked) Scribble distribution. This will make them available as part of the command line commands (e.g. if the bundle represents an additional validation module).

There are two types of QA that are performed as part of the project:

This section will discuss the second type of QA, aimed at ensuring multiple implementations behaviour in the same way.

This part of the project structure provides a set of tests to check that the parser (being tested) processes the supplied set of test 'protocol' descriptions, and returns the correct object model.

The test protocol descriptions are stored in the src/test/resources/tests folder. The global sub-folder provides the global representation of the protocols, with the local representation of these protocols (for all of the relevant roles) being defined in the local sub-folder.

Each test is accompanied by a junit test, defined in the class org.scribble.protocol.parser.ctk. For example:

	@org.junit.Test
	public void testSingleInteraction() {
		TestJournal logger=new TestJournal();
		
		ProtocolModel model=CTKUtil.getModel("tests/protocol/global/SingleInteraction.spr", logger);
		
		assertNotNull(model);
		
		assertTrue(logger.getErrorCount() == 0);
		
		// Build expected model
		ProtocolModel expected=new ProtocolModel();
		
		ImportList imp=new ImportList();
		TypeImport t=new TypeImport();
		t.setName("Order");
		imp.getTypeImports().add(t);
		expected.getImports().add(imp);
		
		Protocol protocol=new Protocol();
		expected.setProtocol(protocol);
		
		protocol.setName("SingleInteraction");
		
		RoleList rl=new RoleList();
		Role buyer=new Role();
		buyer.setName("Buyer");
		rl.getRoles().add(buyer);
		Role seller=new Role();
		seller.setName("Seller");
		rl.getRoles().add(seller);
		
		protocol.getBlock().add(rl);
		
		Interaction interaction=new Interaction();
		
		MessageSignature ms=new MessageSignature();
		TypeReference tref=new TypeReference();
		tref.setName("Order");
		ms.getTypeReferences().add(tref);
		interaction.setMessageSignature(ms);
		interaction.setFromRole(buyer);
		interaction.getToRoles().add(seller);
		
		protocol.getBlock().add(interaction);
		
		CTKUtil.verify(model, expected);
	}
				

The CTKUtil.getModel() method retrieves the protocol description from a named file, and invokes the parser implementation being tested.

The parser implementation is defined using the scribble.protocol.parser system property. If this property is not set, then it will default to the ANTLR based implementation.

Once the model has been retrieved using the parser, the unit test will construct an 'expected' object model.

The final step in the unit test is to invoke the CTKUtil.verify() method to compare the model retrieved against the 'expected' version.

To perform the verification, each model is flattened to produce a list of 'model objects'. Then the verification mechanism iterates through the list, checking that the same entry in each list is identical - first checking they are the same class, and then invoking a 'comparator' implementation for that class.

The 'comparator' implementations are defined in the org.scribble.protocol.parser.ctk.comparators package. The comparator implementations are registered in the static initializer for the org.scribble.protocol.parser.ctk.ProtocolParserTest class.

As with the parser, the CTK provides a set of tests that can be used to test the projection implementation.

The projector implementation is defined using the scribble.protocol.projector system property. If this property is not set, then it will use the default implementation.

The tests are performed by initially retrieving the global representation of a Protocol, and then the local representation that is associated with the particular role that will be projected. This local representation effectively becomes the 'expected' projection.

The project is then invoked, for the required role, which will produce another local representation. All that is then left to do is verify that the projected local representation is identical to the local representation loaded from the file.

An example of a projection test is shown below, where the global model is being projected to the Buyer role:

	@org.junit.Test
	public void testSingleInteractionAtBuyer() {
		TestJournal logger=new TestJournal();
		
		ProtocolModel model=CTKUtil.getModel("tests/protocol/global/SingleInteraction.spr", logger);
		
		assertNotNull(model);
		
		assertTrue(logger.getErrorCount() == 0);
		
		ProtocolModel expected=CTKUtil.getModel("tests/protocol/local/SingleInteraction@Buyer.spr", logger);
		
		assertNotNull(expected);
		
		assertTrue(logger.getErrorCount() == 0);
		
		// Produce projection of model to buyer
		Role role=new Role("Buyer");
		ProtocolModel projected=CTKUtil.project(model, role, logger);
		
		CTKUtil.verify(projected, expected);
	}
				

There is a generic logging API within the Scribble framework that can be used for reporting errors, warnings, information or debuging details. This API is org.scribble.common.logging.Journal.

The methods generally take two parameters, a message and a property map. The message is simply a description of the issue being reported. The property map contain specific details about the issue being reported.

For example, when the parser detects a problem, it can report the nature of the problem, and provide the location of the issue in the source file.

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