Package org.jostraca

Examples of org.jostraca.Template


    // 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();
    Object                      result     = null;

    try {
      String   cwo  = makeCodeWriterOptions( tmps, template );
      String[] args = ArgUtil.splitQuoted( cwo );

      // 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();

      boolean throwWriterExceptions = tmps.isYes( Property.main_CodeWriter_throwExceptions );

      String script = template.getCodeWriterSource();

      Context cx = Context.enter();

      // DO NOT put System.out in MessageHandler as this will cause infinite loop
      System.setOut( new PrintStream( out ) );
      System.setErr( new PrintStream( err ) );

      Scriptable scope = cx.initStandardObjects();
      cx.evaluateString(scope, script, "CodeWriter Line Number: ", 1, null);     

      Object codewriterObj = scope.get( "codewriter", scope );
      if( null == codewriterObj || !(codewriterObj instanceof Scriptable) ) {
        throw new RuntimeException( "no codewriter in script" );
      }
      Scriptable codewriter = (Scriptable) codewriterObj;

      Object _setContextObj = codewriter.get( "_setContext", codewriter );
      if( null == _setContextObj || !(_setContextObj instanceof Function) ) {
        throw new RuntimeException( "no codewriter._setContext in script" );
      }

      Function _setContext = (Function) _setContextObj;
      _setContext.call(cx,scope,codewriter,new Object[]{context});

      Object _generateObj = codewriter.get( "_generate", codewriter );
      if( null == _generateObj || !(_generateObj instanceof Function) ) {
        throw new RuntimeException( "no codewriter._generate in script" );
      }

      Function _generate = (Function) _generateObj;
      result = _generate.call(cx,scope,codewriter,new Object[]{args,new Boolean(throwWriterExceptions)});

      template.setResult( result );
    }

    catch( StandardException se ) {
      if( null != sysOut ) {
        System.setOut( sysOut );
View Full Code Here


    // do nothing
  }


  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    = getCodeWriterPath( tmps );
      String codeWriterOptions         = makeCodeWriterOptions( tmps, template );

      String cmd
        = externalController + Standard.SPACE
        + externalControllerOptions + Standard.SPACE
        + absoluteCodeWriterPath + 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

    // do nothing
  }


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

    String src = template.getSource();
    TemplateParser templateParser = getTemplateParser( tmps );
    templateParser.setPropertySet( tmps );
    templateParser.setSectionSet( sectionSet );
    templateParser.setSourceText( src );

    iUserMessageHandler.debug( UserText.get(UserText.TXT_parsing), src.length()+" characters" );

    // FIX: how about .parse(template) and remove sets above?
    templateParser.parse();

    sectionSet = templateParser.getSectionSet();
    template.setSectionSet( sectionSet );

    // FIX: do we need a way to stop processing?
    boolean displaytmdoc = displayTemplateDocumentation( tmps, sectionSet, iUserMessageHandler );
    if( displaytmdoc ) {
      PropertySet ops = pTemplate.getPropertySet( Constants.CONF_override );
View Full Code Here

    // do nothing
  }


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

    WriterFormat wf = makeWriterFormat( tmps );

    modifySections( wf.getSource(), sectionSet, tmps );

    String codeWriterSource = insertText( wf.getPath(), wf.getSource(), sectionSet, tmps );

    // perform some text transformations after code writer has been generated
    codeWriterSource = postProcess( codeWriterSource, tmps );

    String codeWriterPath    = createCodeWriterPath( tmps );
    template.setCodeWriterPath( new File( codeWriterPath ) );
    template.setCodeWriterSource( codeWriterSource );
  }
View Full Code Here

    // do nothing
  }


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

    String codeWriterLang = template.getCodeWriterLang();
    //t.track( "codeWriterLang", codeWriterLang );

    PropertySet langPS = loadLangPropertySet( codeWriterLang, tmps );
    iUserMessageHandler.debug( "Template Script:", codeWriterLang );

    template.setPropertySet( CONF_lang, langPS );

    // prepare settings
    handleCodeWriterName( template );
    overridePropertySet( template, iPropertySetModifierManager );

    template.modifyForOldVersion();

    validateMergedPropertySet( template.getMergedPropertySet() );

    tmps = template.getMergedPropertySet();
    TemplatePath tp   = template.getTemplatePath();
    dumpPropertySet(    tmps, tp );
    dumpTemplateSource( tmps, tp, template );
  }
View Full Code Here

  }


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

    StringBuffer sourceFilesB = new StringBuffer( tmlist.size() * 33 );
    boolean      compile      = makeCompileList( tmlist, sourceFilesB );
    String       sourceFiles  = sourceFilesB.toString();

View Full Code Here

  // test methods

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

    Template tm03 = PackageTest.makeTemplate("tm03");
    Template tm04 = PackageTest.makeTemplate("tm04");
    ArrayList tmlist = ListUtil.make( tm03, tm04 );

    for( Iterator tmT = tmlist.iterator(); tmT.hasNext(); ) {
      Template tm = (Template) tmT.next();
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Compiler", "org.jostraca.process.GenericCompiler" );
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Controller", "org.jostraca.process.GenericController" );
    }

    preprocess( cm, tmlist );
View Full Code Here

  public void testExternalJavaController() throws Exception {
    CommandLineUserMessageHandler cm = new CommandLineUserMessageHandler();
    cm.setThreshold( UserMessageHandler.DEBUG );

    Template tm01 = PackageTest.makeTemplate("tm01");
    Template tm02 = PackageTest.makeTemplate("tm02");
    ArrayList tmlist = ListUtil.make( tm01, tm02 );

    for( Iterator tmT = tmlist.iterator(); tmT.hasNext(); ) {
      Template tm = (Template) tmT.next();
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Compiler", "org.jostraca.process.ExternalJavaCompiler" );
      tm.getPropertySet(Service.CONF_template)
        .set( TemplateHandlerManager.PROPERTY_PREFIX+"Controller", "org.jostraca.process.ExternalJavaController" );
    }

    preprocess( cm, tmlist );
View Full Code Here


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

    Template tm01 = PackageTest.makeTemplate("tm01");
    Template tm02 = PackageTest.makeTemplate("tm02");
    ArrayList tmlist = ListUtil.make( tm01, tm02 );

    preprocess( cm, tmlist );

    for( Iterator tmT = tmlist.iterator(); tmT.hasNext(); ) {
      Template tm = (Template) tmT.next();
      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" );
    }

    ControllerProcessStage ctps = new ControllerProcessStage();
    ctps.setUserMessageHandler( cm );
View Full Code Here



  public void preprocess( UserMessageHandler pCM, 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" );
    }

    PreparerProcessStage prps = new PreparerProcessStage();
    prps.setUserMessageHandler( pCM );
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.