To invoke JCam it is worth noting that the class uk.org.jcam.CAM holds the instantiation of the NanoContainer for JCam. To access the container simply call CAM.getContainer() . Once you have the container you may get access to the implementations of the various interfaces that JCam supports. It is suggested that unless you are very experienced that you do not change the implementations of uk.org.jcam.processor.dataObjects classes. These currently use JDOM to handle the XML processing. As CAM enable cross field validation it is possible to have constraints applied which refer to fields in the XML file that further into the file that the node in question. This forward referencing means that CAM must have access to the complete file before processing. This is an overhead but it does enable some of the advanced features of CAM.
To read a template use the following:
cont = CAM.getContainer(); Template ct = cont.getTemplate(); ct.setTemplate(new DocumentFactory().createDocument(camTemplate));
Figure 4 Reading a Template
The parameter camTemplate can be either a URL, a file name or an org.w3c.dom tree. There are large number of potential exceptions raised by these three lines. If you are using an IDE such as Eclipse this will be shown.
To read the XML file for validation assuming the container is known of in the Object cont :
DataFile xmlfile = cont.getDataFile(); xmlfile.setXMLFile(new DocumentFactory().createDocument(xmlFile));
Figure 5 Reading an XML File
Like the Template the xmlfile may be a URL, a file or a dom tree. No all that is left is to invoke the validation.
CAM.getContainer().getValidator().Validate("default");
Figure 6 Validating the XML file
The "default" parameter need not be there if there is only one AssemblyStructure within the Template. To check if the validation has been successful use:
if (CAM.getContainer().getDataFile().hasErrors()){ System.out.println("Errors Occurred); CAM.getContainer().getDataFile().printErrors(); }
Figure 7 Checking for Errors.
That is about it for initial Java integration. One last item that you might need is to be able to set up Global parameters. This can be done by supplying the Template with an array of Strings where each string is in the format 'name=value'. Pass this String[] to the routine setParameterValues in teh following way:
CAM.getContainer().getTemplate().setParameterValues(args);
Figure 8 Setting up Parameter Values.