Processor Tutorial

As an alternative Java intergration 0.8.3 of JCam introduces a new 'processor'. This processor will be driven from the contents of the CAM template entirely. In most cases this will be a simple validation of the content of an XML file against the rule defined in the first two sections of the the CAM template - namely AssemblyStructure and BusinessUseContext. However is the ContentReference, DataValidations or ExternalMapping section exist the processor will use these as well.

Calling the Processor

The processore may be called with the following few lines of code:

Processor proc = new Processor();
proc.setTemplate(new DocumentFactory().createDocument(new URL("http://localhost/TestCAMProcessor.cam")));
proc.setParameterValues(params);
proc.setDataFile(new DocumentFactory().createDocument(new URL("http://localhost/testCAMValidOne.xml")));                        
Document res = (Document) proc.process();
if (proc.hasErrors() && proc.getErrors() != null){
        String[] errors = proc.getErrors();
        for (int i=1; i< errors.length;i++){
                System.err.println(errors[i]);
        }
}

Having instantiated a new processor it must be associated with a Template. This is done using the setTemplate method. If the Template requires any global parameters to be set then these should be passed in using the setParameters call. The parameters are passed as an array pf strings of the form 'name=value'.

The processor is now available to process any datafiles. The result from the Process call is a JDOM Document containing the datafile either with inline errors or transformed after any ExternalMapping.

Use the DocumentWriter.write call to output the result.

Controlling the Processor

The Processor is controlled by two features - the CAM template and a set of flags. The flags allow the behaviour of the Processor in the event of error being found in the datafile. The options are:

  1. DONT_DO_D_OR_E_ON_ERROR - the default behaviour.

    The following have been deprecated.

  2. DO_ONLY_D_ON_ERROR - Only perform the DataValidations section if the initial validation fails.
  3. DO_ONLY_E_ON_ERROR - Only perform the ExternalMapping section if the initial validation fails.
  4. DO_BOTH_D_AND_E_ON_ERROR - Perform all sections of the Template even is error occur.

    The following is an example showing how JCam handles the DataValidations Section and the ExternalMapping section. These are not CAM compliant.

    <as:DataValidations>
        <as:interface>IDataValidator</as:interface>
        <dr:drools>
          <dr:includeRules>http://localhost/rules.drl</dr:includeRules>     
          <dr:applyRules scope="//t:repeatLimited"/>
        </dr:drools>
    </as:DataValidations>
    
    <as:ExternalMapping>
        <as:interface>ITransformer</as:interface>
        <xs:transform>
          <xs:StyleSheet>http://localhost/xsl/Example.xsl</xs:StyleSheet>
        </xs:transform>
    </as:ExternalMapping>
    
    

Conclusion

The processor is a simple method to integrate JCam into any other Java application. It does not proclude the Java integration discussed in the five minute tutorial .