È possibile utilizzare script Ant per richiamare componenti J2C, richiamando tali script dal workbench o dalla riga comandi.
Le procedure guidate J2C consentono di creare velocemente un file di configurazione Ant catturando le selezioni ed i valori immessi. Poiché un file di configurazione Ant è essenzialmente un file XML, può essere modificato o generato interamente a mano.
Un file di configurazione Ant consiste in un albero di destinazione in cui vengono eseguite diverse attività. Le attività in una destinazione vengono elaborate in modo sequenziale. Ciascuna attività viene eseguita tramite un oggetto che implementa una particolare interfaccia dell'attività. Quando viene richiamato un file di configurazione Ant, le proprietà corrispondenti a ciascuna attività vengono caricate negli oggetti attività di implementazione. Una volta caricate le informazioni, viene richiamato l'oggetto attività.
Attività di rilevamento dati
<adapter:discover> <adapter:performImport agent="{com/ibm/adapter}CobolDiscoveryAgent"> <adapter:importResource> <adapter:propertyGroup name="CobolFileGroup"> <adapter:propertyElement name="CobolFile" value="/${project}/taderc99.ccp"/> </adapter:propertyGroup> </adapter:importResource> <adapter:queryProperties> <adapter:propertyGroup name="ImportProperties"> <adapter:propertyElement name="Platform" value="Win32"/> </adapter:propertyGroup> </adapter:queryProperties> <adapter:queryResult> <adapter:selectElement name="DFHCOMMAREA"/> </adapter:queryResult> </adapter:performImport> <adapter:writeToWorkspace writer="{com/ibm/adapter/cobol/writer}JAVA_WRITER"> <adapter:propertyGroup name="COBOLToJavaResourceWriter"> <adapter:propertyElement name="GenerationStyle" value="0"/> <adapter:propertyGroup name="Java Type Name"> <adapter:propertyElement name="Overwrite existing class" value="true"/> <adapter:propertyElement name="Project Name" value="${project}"/> <adapter:propertyElement name="Package Name" value="com.ibm.test"/> <adapter:propertyElement name="Class Name" value="Taderc99"/> </adapter:propertyGroup> </adapter:propertyGroup> </adapter:writeToWorkspace> </adapter:discover>
<?xml version="1.0" encoding="UTF-8" ?> <project xmlns:adapter="http://com.ibm.adapter" default="DataBinding1" name="/Taderc99/CustomerInfo.xml"> <property name="debug" value="true" /> <property name="project1" value="Taderc99" /> <target name="DataBinding1"> <adapter:createProject projectName="${project1}" projectType="Java" /> <adapter:discover> <adapter:performImport agent="{com/ibm/adapter}CobolDiscoveryAgent"> <adapter:importResource> <adapter:propertyGroup name="CobolFileGroup"> <adapter:propertyElement name="CobolFile" value="C:\Samples\CICS\taderc99\taderc99.cbl" /> </adapter:propertyGroup> </adapter:importResource> <adapter:queryProperties> <adapter:propertyGroup name="ImportProperties"> <adapter:propertyElement name="Platform" value="Win32" /> <adapter:propertyElement name="Codepage" value="ISO-8859-1" /> <adapter:propertyElement name="Numproc" value="PFD" /> <adapter:propertyElement name="FloatingPointFormat" value="IEEE 754" /> <adapter:propertyGroup name="ExternalDecimalSignGroup"> <adapter:propertyElement name="ExternalDecimalSign" value="ASCII" /> </adapter:propertyGroup> <adapter:propertyGroup name="EndianGroup"> <adapter:propertyElement name="Endian" value="Little" /> <adapter:propertyElement name="RemoteEndian" value="Little" /> </adapter:propertyGroup> <adapter:propertyGroup name="CompileOptions"> <adapter:propertyElement name="Quote" value="DOUBLE" /> <adapter:propertyElement name="Trunc" value="STD" /> <adapter:propertyElement name="Nsymbol" value="DBCS" /> </adapter:propertyGroup> </adapter:propertyGroup> </adapter:queryProperties> <adapter:queryResult> <adapter:selectElement name="DFHCOMMAREA" /> </adapter:queryResult> </adapter:performImport> <adapter:writeToWorkspace writer="{com/ibm/adapter/cobol/writer}JAVA_WRITER"> <adapter:propertyGroup name="COBOLToJavaResourceWriter"> <adapter:propertyElement name="GenerationStyle" value="Default" /> <adapter:propertyGroup name="Java Type Name"> <adapter:propertyElement name="Project Name" value="${project1}" /> <adapter:propertyElement name="Package Name" value="sample.cics" /> <adapter:propertyElement name="Class Name" value="CustomerInfo" /> <adapter:propertyElement name="Overwrite existing class" value="true" /> </adapter:propertyGroup> </adapter:propertyGroup> </adapter:writeToWorkspace> </adapter:discover> <eclipse.refreshLocal depth="infinite" resource="${project1}" /> <eclipse.incrementalBuild project="${project1}" /> </target> </project>
Attività di generazione servizio
Nel caso particolare dell'importazione di linguaggio (COBOL, C e PL/1), vi è una fase ulteriore: la generazione di binding interfaccia. Il seguente esempio descrive la sezione di rilevamento dati dello script Ant utilizzata per la generazione del bean J2C:
<j2c:generateService> <j2c:buildService package="com.ibm.test" class="Taderc99Interface"> <j2c:method> <j2c:methodName value="gettaderc99"/> <j2c:methodInput value="${project}/com/ibm/test/Taderc99.java"> <j2c:argumentBinding property="commareaLength" propertyType="InteractionSpec" name="length" type="int"/> </j2c:methodInput> <j2c:methodOutput value="${project}/com/ibm/test/Taderc99.java"/> <j2c:interactionSpec class="com.ibm.connector2.cics.ECIInteractionSpec"> <adapter:propertyGroup name="InteractionSpec property group"> <adapter:propertyElement name="functionName" value="TADERC99"/> </adapter:propertyGroup> </j2c:interactionSpec> </j2c:method> <j2c:managedConnectionFactory class="com.ibm.connector2.cics.ECIManagedConnectionFactory" target="myJNDIName"> <adapter:propertyGroup name="Managed connection property group"> <adapter:propertyGroup name="Server"> <adapter:propertyElement name="ConnectionURL" value="rubicon.torolab.ibm.com"/> <adapter:propertyElement name="ServerName" value="rubicon"/> </adapter:propertyGroup> <adapter:propertyGroup name="UserVerification"> <adapter:propertyElement name="UserName" value="sysad"/> <adapter:propertyElement name="Password" value="sysad"/> </adapter:propertyGroup> </adapter:propertyGroup> </j2c:managedConnectionFactory> <j2c:connectionSpec class="com.ibm.connector2.cics.ECIConnectionSpec"/> <j2c:resourceAdapter project="CICS ECI"/> </j2c:buildService> <adapter:writeToWorkspace writer="com/ibm/adapter/j2c/codegen:J2CAnnotationWriter"> <adapter:propertyGroup name="J2C Writer Properties"> <adapter:propertyElement name="Project" value="${project}"/> <adapter:propertyElement name="InterfaceName" value="Taderc99Interface"/> <adapter:propertyElement name="BindingName" value="Taderc99Binding"/> <adapter:propertyElement name="PackageName" value="com.ibm.test"/> <adapter:propertyGroup name="CommandBean"> <adapter:propertyGroup name="gettaderc99"> <adapter:propertyElement name="EnableGenerate" value="true"/> <adapter:propertyElement name="CommandBeanName" value="Taderc99CICSECIServiceProxy"/> <adapter:propertyElement name="Input" value="Taderc99Part"/> <adapter:propertyElement name="Output" value="Taderc99Part"/> </adapter:propertyGroup> </adapter:propertyGroup> </adapter:propertyGroup> </adapter:writeToWorkspace> </j2c:generateService>
Ulteriori attività
Di seguito vengono indicate attività di utilità ma non obbligatorie per la generazione di risorse.
<adapter:createProject projectName="taderc99Project" projectType="Web" runtimeName="J2EE Runtime Library" addToEAR="yes" EARProjectName="TestEAR"/>Dove:
<j2c:importResourceAdapter connectorModule="cicseci602" connectorFile="D:\IBM\SDP70\ResourceAdapters\cics15\cicseci602.rar" targetRuntime="J2EE Runtime Library" addToEAR="yes" EARProjectName="TestEAR"/>
Definizione delle proprietà
Gli agenti di rilevamento e il programma di scrittura dell'area di lavoro sono indicati dai rispettivi nomi (QName) che sono identificati in maniera univoca. Per trovare tutti gli agenti di rilevamento registrati, i programmi di utilità di scrittura risorse dell'area di lavoro e le configurazioni di importazione, utilizzare lo script displayAll.xml che si trova nella directory degli esempi.
Come osservato negli script di esempio, i valori passati agli agenti di rilevamento o alle utilità di scrittura risorse vengono definiti da tag propertyGroup e propertyElement. Un gruppo di proprietà definisce un raggruppamento logico di proprietà in una struttura nidificata. Il layout della struttura, il gruppo contenuto e i nomi proprietà devono essere descritti nella documentazione dell'agente di rilevamento e dell'utilità di scrittura risorse.
Le proprietà vengono definite da una coppia di attributi nome-valore. Il nome è effettivamente una proprietà definita internamente dall'agente di rilevamento o dall'utilità di scrittura risorse, e viene utilizzato per il passaggio del valore. È importante che il nome sia corretto. Se il nome non viene riconosciuto dal componente, il valore non verrà impostato.