All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.st.p2012.mind.DefinitionDocumentGenerator Maven / Gradle / Ivy

The newest version!
/**
   \file com/st/p2012/mind/DefinitionDocumentGenerator.java
   \brief A class to generate the documentation page for an ADL.


   
   \n
   This file is part of the Platform 2012 program,
   a cooperation between STMicroelectronics and CEA.\n
   Redistribution of this file to outside parties is
   strictly prohibited without the written consent
   of the module owner indicated below.\n
   

   \par  Module owner: [email protected]


   \par  Copyright (C) 2009 STMicroelectronics

   \par  Authors: [email protected]

   \par  Id: $Id$
   \par  Date: $Date$
   \par  Revision: $Rev$

 */
package com.st.p2012.mind;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Map;

import org.objectweb.fractal.adl.ADLException;
import org.objectweb.fractal.adl.Definition;
import org.objectweb.fractal.adl.Loader;
import org.objectweb.fractal.adl.NodeFactoryImpl;
import org.objectweb.fractal.adl.xml.XMLNodeFactory;
import org.objectweb.fractal.adl.xml.XMLNodeFactoryImpl;
import org.objectweb.fractal.mind.BasicInputResourceLocator;
import org.objectweb.fractal.mind.adl.ADLLocator;
import org.objectweb.fractal.mind.adl.DefinitionCompiler;
import org.objectweb.fractal.mind.annotation.AnnotationLocatorHelper;
import org.objectweb.fractal.mind.idl.IDLLoader;
import org.objectweb.fractal.mind.idl.IDLLocator;
import org.objectweb.fractal.mind.idl.IDLVisitor;
import org.objectweb.fractal.mind.idl.ast.IDL;
import org.objectweb.fractal.mind.io.BasicOutputFileLocator;
import org.objectweb.fractal.mind.plugin.SimpleClassPluginFactory;
import org.objectweb.fractal.mind.st.BasicASTTransformer;
import org.objectweb.fractal.mind.st.StringTemplateASTTransformer;
import org.objectweb.fractal.mind.st.StringTemplateComponentLoader;
import org.objectweb.fractal.mind.st.templates.parser.StringTemplateLoader;

import com.st.p2012.mind.adl.DocumentationBackendFactory;
import com.st.p2012.mind.adl.DocumentationFrontendFactory;
import com.st.p2012.mind.idl.IDLBackendFactory;
import com.st.p2012.mind.idl.IDLLoaderChainFactory;

public class DefinitionDocumentGenerator {
  public Loader                       adlLoader;
  public IDLLoader                    idlLoader;

// /public Instantiator graphInstantiator;

  public DefinitionCompiler    adlCompiler;
  public IDLVisitor            idlCompiler;

  public StringTemplateASTTransformer astTransformer;

  public Map          context;

  public DefinitionDocumentGenerator(final File sourceDirectories[], final File rootDirectory, final File targetDirectory) throws IOException {

    // input locators
    final BasicInputResourceLocator inputResourceLocator = new BasicInputResourceLocator();
    final IDLLocator idlLocator = IDLLoaderChainFactory.newLocator();
    final ADLLocator adlLocator = DocumentationFrontendFactory.newLocator();

    // String Template Component Loaders
    final StringTemplateComponentLoader stcLoader = new StringTemplateComponentLoader();
    final StringTemplateLoader templateLoader = new StringTemplateLoader();
    final XMLNodeFactory nodeFactory = new XMLNodeFactoryImpl();

    templateLoader.nodeFactoryItf = nodeFactory;
    stcLoader.loaderItf = templateLoader;

    // Plugin Manager Components
    final org.objectweb.fractal.adl.Factory pluginFactory = new SimpleClassPluginFactory();

    // loader chains
    idlLoader = IDLLoaderChainFactory.newLoader(idlLocator);
    adlLoader = DocumentationFrontendFactory.newLoader(inputResourceLocator,
        adlLocator, idlLocator, idlLoader, pluginFactory);

    // instantiator chain
    // graphInstantiator = Factory.newInstantiator(adlLoader);

    adlCompiler = DocumentationBackendFactory.newDefinitionCompiler();

    idlCompiler = IDLBackendFactory.newIDLCompiler();

    // AST Transformer;
    final BasicASTTransformer basicASTTransformer = new BasicASTTransformer();
    basicASTTransformer.nodeFactoryItf = new NodeFactoryImpl();
    astTransformer = basicASTTransformer;

    // init context
    context = new HashMap();
    context.put(BasicOutputFileLocator.OUTPUT_DIR_CONTEXT_KEY, targetDirectory);
    final URL urls[] = new URL[sourceDirectories.length];
    for (int i = 0; i < sourceDirectories.length; i++) {
      final File directory = sourceDirectories[i];
      urls[i] = directory.toURI().toURL();
    }

    AnnotationLocatorHelper.addDefaultAnnotationPackage("org.objectweb.fractal.mind.adl.annotation.predefined",
        context);

    final ClassLoader srcClassLoader = new URLClassLoader(urls, getClass().getClassLoader());
    context.put("classloader", srcClassLoader);
    context.put("sourceDirectory", rootDirectory);
  }

  public Definition loadADL(final String adlName) throws ADLException {
    return adlLoader.load(adlName, context);
  }

  public void generateADLDocumentation(final String adlName)
      throws ADLException, InterruptedException {
    Definition d = loadADL(adlName);
    d = astTransformer.toStringTemplateAST(d);
    adlCompiler.visit(d, context);
  }

  public IDL loadIDL(final String idlName) throws ADLException {
    return idlLoader.load(idlName, context);
  }

  public void generateIDLDocumentation(final String idlName)
      throws ADLException, InterruptedException {
    IDL idl = loadIDL(idlName);
    idl = astTransformer.toStringTemplateAST(idl);
    idlCompiler.visit(idl, context);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy