Package org.jostraca

Examples of org.jostraca.Template


  public void testProcessManager() throws Exception {
    CommandLineUserMessageHandler cm = new CommandLineUserMessageHandler();
    FormatManager fm = new BasicFormatManager();
   
    Template tm01 = PackageTest.makeTemplate("tm01");
    Template tm02 = PackageTest.makeTemplate("tm02");
    ArrayList tmlist = ListUtil.make( tm01, tm02 );

    preprocess( cm, fm, tmlist );

    PropertySet sysps = PackageTest.getSystemPropertySet();
View Full Code Here




  public void preprocess( UserMessageHandler pCM, FormatManager pFM, List pTmList ) {
    for( Iterator tmT = pTmList.iterator(); tmT.hasNext(); ) {
      Template tm = (Template) tmT.next();
      tm.getPropertySet( Service.CONF_template )
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Preparer", "org.jostraca.process.GenericPreparer" );
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Parser", "org.jostraca.process.GenericParser" );
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Merger", "org.jostraca.process.GenericMerger" );
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Saver", "org.jostraca.process.GenericSaver" );
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Compiler", "org.jostraca.process.InternalJavaCompiler" );
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Controller", "org.jostraca.process.InternalJavaController" );
    }
  }
View Full Code Here

    // do nothing
  }


  public void process( Template pTemplate ) throws Exception {
    Template    template   = pTemplate;
    PropertySet tmps       = template.getMergedPropertySet();

    // FIX: need to elaborate on this!
    boolean     execute    = !tmps.isNo( Property.main_ExecuteCodeWriter );

    if( execute ) {
View Full Code Here

    }
  }


  protected void processImpl( Template pTemplate ) {
    Template    template   = pTemplate;
    PropertySet tmps       = template.getMergedPropertySet();

    File   codeWriterPath   = template.getCodeWriterPath();
    String codeWriterSource = template.getCodeWriterSource();

    try {
      String externalController        = makeExternalController( tmps );
      String externalControllerOptions = tmps.get( Property.main_ExternalControllerOptions );
      String absoluteCodeWriterPath    = TextUtil.quote(getCodeWriterPath( tmps ));

      String codeWriterOptions = makeCodeWriterOptions( tmps, template );

      // FIX: why use absolute controller path since compile does not?

      String cmd = Standard.EMPTY;
      boolean cwic = tmps.isYes( Property.main_CodeWriterIsController );

      cmd += ( externalController + Standard.SPACE + externalControllerOptions + Standard.SPACE );
    
      if( !cwic ) {
        cmd += absoluteCodeWriterPath;
      }

      cmd += Standard.SPACE + codeWriterOptions;

     
      boolean successful = executeGeneratingCmd( cmd, template );
      WayPointRecorder.add( BasicWayPoint.ExecutingCodeWriter.make( template.getCodeWriterPath().getAbsolutePath() ) );
    }
    catch( StandardException se ) {
      throw se;
    }
    catch( Exception e ) {
View Full Code Here

  // test methods

  public void testPreparer() throws Exception {
    CommandLineUserMessageHandler cm = new CommandLineUserMessageHandler();

    Template tm01 = PackageTest.makeTemplate("tm01");
    tm01.getPropertySet( Service.CONF_template )
      .set( TemplateHandlerManager.PROPERTY_PREFIX+"Preparer", "org.jostraca.process.GenericPreparer" );

    ArrayList tmlist = ListUtil.make( tm01 );
    PreparerProcessStage pps = new PreparerProcessStage();
    pps.setUserMessageHandler( cm );
View Full Code Here

    // do nothing
  }


  protected void processImpl( Template pTemplate ) {
    Template    template   = pTemplate;
    PropertySet tmps       = template.getMergedPropertySet();

    boolean     successful = false;
    PrintStream sysOut     = null;
    PrintStream sysErr     = null;
    RecordingUserMessageHandler rumh = new RecordingUserMessageHandler();

    try {
      String   cw   = tmps.get( Property.main_CodeWriter );
      String   cwo  = makeCodeWriterOptions( tmps, template );
      String[] args = ArgUtil.splitQuoted( cwo );
      String   cwp  = getCodeWriterPath( tmps );

      Properties jythonProps = new Properties();
      jythonProps.put( "python.home", tmps.get("jython.home") );
      PythonInterpreter.initialize( System.getProperties(), jythonProps, args );

      PyStringMap       dict  = new PyStringMap();
      PySystemState     pysys = new PySystemState();
      PythonInterpreter pi    = new PythonInterpreter( dict, pysys );


      // DO NOT use CommandLineUserMessageHandler here - causes infinite recursion
      MessageHandlerOutputStream  out  = new MessageHandlerOutputStream( UserMessageHandler.INFO,  rumh );
      MessageHandlerOutputStream  err  = new MessageHandlerOutputStream( UserMessageHandler.ERROR, rumh );

      // space out dots to avoid accidental replace on System DOT out search
      sysOut = System . out;
      sysErr = System . err;
   
      // set context if not null
      Object context = template.getContext();
      if( null != context ) {
        pi.set( "context", context );
      }

      System.setOut( new PrintStream( out ) );
      System.setErr( new PrintStream( err ) );

      pi.execfile( cwp );
     
      String jythonexec
        = "cw = "+cw+"()\n"
        + (null!=context?"cw._setContext( context )\n":"")
        + "cw.main( sys.argv )\n"
        + "result = cw._getResult()\n"
        ;
      pi.exec( jythonexec );
      WayPointRecorder.add( BasicWayPoint.ExecutingCodeWriter.make( template.getCodeWriterPath().getAbsolutePath() ) );

      Object result = pi.get("result");

      if( result instanceof Integer ) {
        successful = ( 0 == ((Integer)result).intValue() );
      }
      else {
        successful = true;
      }

      template.setResult( result );
    }

    // FIX: need a util to handle general exceptions and just rethrow StandardExceptions
    catch( StandardException se ) {
      throw se;
View Full Code Here



  protected void compileAsFirst( List pTemplateList ) {
    List        tmlist  = pTemplateList;
    Template    firsttm = (Template) pTemplateList.get(0);
    PropertySet tmps    = firsttm.getMergedPropertySet();

    List sourceFilesList = new ArrayList();
    StringBuffer sourceFilesB = new StringBuffer( tmlist.size() * 33 );
    boolean      compile      = makeCompileList( tmlist, sourceFilesB, sourceFilesList );
    String       sourceFiles  = sourceFilesB.toString();
View Full Code Here

    // sort each template into an equivalent compile operation
    HashMap compileBag = new HashMap();

    for( Iterator tmT = tmlist.iterator(); tmT.hasNext(); ) {
      Template tm      = (Template) tmT.next();
      String   bagname = resolveBagName( tm );

      ArrayList bagtmlist = null;
      if( !compileBag.containsKey( bagname ) ) {
        bagtmlist = new ArrayList();
View Full Code Here

  }



  protected String resolveBagName( Template pTemplate ) {
    Template    tm   = pTemplate;
    PropertySet tmps = tm.getMergedPropertySet();

    StringBuffer bagname = new StringBuffer();
    bagname.append( " "+tmps.get( Property.main_ExternalCompiler ) );
    bagname.append( " "+tmps.get( Property.main_ExternalCompilerOptions ) );
View Full Code Here


  // compile using props from first tm
  protected void compileAsFirst( List pTemplateList ) {
    List        tmlist  = pTemplateList;
    Template    firsttm = (Template) pTemplateList.get(0);
    PropertySet tmps    = firsttm.getMergedPropertySet();

    boolean successful = false;
    boolean compile    = false;
    StringBuffer sourceFilesB = new StringBuffer();
    for( Iterator tmT = tmlist.iterator(); tmT.hasNext(); ) {
      Template tm  = (Template) tmT.next();

      File executablePath = makeExecutablePath( tm );
      tm.setCodeWriterExecutablePath( executablePath );

      boolean compileRequired = compileRequired( tm );

      if( compileRequired ) {
        File cwF = tm.getCodeWriterPath();
        sourceFilesB.append( " "+TextUtil.quoteSpaces( cwF.getPath() ) );
        WayPointRecorder.add( BasicWayPoint.CompilingCodeWriter.make( cwF.getAbsolutePath() ) );
        compile = true;
      }
    }
View Full Code Here

TOP

Related Classes of org.jostraca.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.