The example below performs the necessary initialization and demonstrates how to create a new CCL file named hello.ccl with a single CREATE INPUT STREAM CCL statement. Note that all the Java code is necessary for file creation except for the three lines involving the Input Stream statement.
package com.sybase.esp.ccl.example1; import java.io.File; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.xtext.resource.SaveOptions; import org.eclipse.xtext.resource.XtextResourceSet; import com.sybase.esp.CclStandaloneSetup; import com.sybase.esp.ccl.CclFactory; import com.sybase.esp.ccl.CclPackage; import com.sybase.esp.ccl.InputStream; import com.sybase.esp.ccl.Statements; public class HelloCcl { public static void main(String[] args) { // This call must be made once in order to use the CCL API. CclStandaloneSetup.doSetup(); // The file to be created. If it exists, remove it. String theFile = "hello.ccl"; File cclFile = new File(theFile); if(cclFile.exists()) { cclFile.delete(); } // Ccl elements need to be placed in a Resource which is // within a ResourceSet. This is default EMF behavior. XtextResourceSet myResourceSet = new XtextResourceSet(); URI uri = URI.createFileURI(theFile); Resource resource = myResourceSet.createResource(uri); // Use the CclFactory to create new Ccl elements, this is a // standard way EMF creates new elements in the Ccl API. CclFactory fact = CclPackage.eINSTANCE.getCclFactory(); // Statements is the root object for the Ccl model. // Create one and add it to the Resource. Statements root = fact.createStatements(); resource.getContents().add(root); // Create and name the InputStream. InputStream theInput = fact.createInputStream(); theInput.setName("NewInput"); // Add the InputStream to the Stmts collection. root.getStmts().add(theInput); // Save an EMF Resource named hello.ccl try { SaveOptions saveOptions = SaveOptions.newBuilder().getOptions(); resource.save(saveOptions.toOptionsMap()); } catch(Exception e) { System.out.println(e.getMessage()); } } }
CREATE INPUT STREAM NewInput ;