Search in sources :

Example 1 with LightJetBean

use of org.talend.designer.codegen.config.LightJetBean in project tdi-studio-se by Talend.

the class EmfEmittersPersistence method loadEmittersPool.

/**
     * DOC mhirt Comment method "loadEmittersPool".
     * 
     * @return
     * @throws IOException
     * @throws ClassNotFoundException
     */
@SuppressWarnings("unchecked")
public List<LightJetBean> loadEmittersPool() {
    List<LightJetBean> emittersToReturn = new ArrayList<LightJetBean>();
    byte[] poolAsBytes = null;
    try {
        poolAsBytes = loadEmfPoolFactory(persistantFile);
    } catch (IOException e) {
        //$NON-NLS-1$
        log.info(Messages.getString("EmfEmittersPersistence.CodeGen.DataMissing"));
        // Nothing to do if persistent file not found
        return emittersToReturn;
    }
    if (poolAsBytes != null) {
        ByteArrayInputStream stream = new ByteArrayInputStream(poolAsBytes);
        if (stream.available() > 0) {
            try {
                ObjectInputStream oin = new ObjectInputStream(stream);
                emittersToReturn = (List<LightJetBean>) oin.readObject();
                oin.close();
                return emittersToReturn;
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            } catch (ClassNotFoundException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
    return new ArrayList<LightJetBean>();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LightJetBean(org.talend.designer.codegen.config.LightJetBean) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with LightJetBean

use of org.talend.designer.codegen.config.LightJetBean in project tdi-studio-se by Talend.

the class CodeGeneratorEmittersPoolFactory method extractEmfPersistenData.

/**
     * DOC mhirt Comment method "extractEmfPersistenData".
     * 
     * @param alreadyCompiledEmitters
     * @return
     */
private static List<LightJetBean> extractEmfPersistenData(List<JetBean> alreadyCompiledEmitters) {
    List<LightJetBean> toReturn = new ArrayList<LightJetBean>();
    for (JetBean unit : alreadyCompiledEmitters) {
        // long unitCRC = extractTemplateHashCode(unit);
        long unitCRC = unit.getCrc();
        toReturn.add(new LightJetBean(unit.getTemplateRelativeUri(), unit.getClassName(), unit.getMethodName(), unit.getVersion(), unit.getLanguage(), unitCRC));
    }
    return toReturn;
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) ArrayList(java.util.ArrayList)

Example 3 with LightJetBean

use of org.talend.designer.codegen.config.LightJetBean in project tdi-studio-se by Talend.

the class CodeGeneratorEmittersPoolFactory method loadEmfPersistentData.

private static List<JetBean> loadEmfPersistentData(List<LightJetBean> datas, List<JetBean> completeJetBeanList, IProgressMonitor monitorWrap) throws BusinessException {
    List<JetBean> toReturn = new ArrayList<JetBean>();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    //$NON-NLS-1$
    IProject project = workspace.getRoot().getProject(".JETEmitters");
    URL url = null;
    try {
        IFile file = project.getFile(Path.fromOSString("runtime"));
        url = file.getLocationURI().toURL();
        int lightBeanIndex = 0;
        LightJetBean lightBean = null;
        LightJetBean myLightJetBean = null;
        //$NON-NLS-1$
        String unitTemplateFullURI = "";
        long unitTemplateHashCode = 0;
        HashMap<String, LightJetBean> mapOnName = new HashMap<String, LightJetBean>();
        boolean forceMethodLoad = ComponentCompilations.getMarkers();
        if (forceMethodLoad) {
            // init specific map based on component name : mapOnName
            for (LightJetBean ljb : datas) {
                //$NON-NLS-1$
                mapOnName.put(ljb.getTemplateRelativeUri().substring(ljb.getTemplateRelativeUri().lastIndexOf("/")), ljb);
            }
        }
        int monitorBuffer = 0;
        for (JetBean unit : completeJetBeanList) {
            monitorBuffer++;
            if (monitorBuffer % 200 == 0) {
                monitorWrap.worked(200);
                monitorBuffer = 0;
            }
            unitTemplateFullURI = unit.getTemplateRelativeUri();
            unitTemplateHashCode = unit.getCrc();
            myLightJetBean = new LightJetBean(unitTemplateFullURI, unit.getVersion(), unitTemplateHashCode);
            if (((lightBeanIndex = datas.indexOf(myLightJetBean)) > -1) || forceMethodLoad) {
                if (!forceMethodLoad) {
                    lightBean = datas.get(lightBeanIndex);
                } else {
                    lightBean = mapOnName.get(myLightJetBean.getTemplateRelativeUri().substring(//$NON-NLS-1$
                    myLightJetBean.getTemplateRelativeUri().lastIndexOf("/")));
                }
                if (lightBean != null && lightBean.getCrc() == unit.getCrc()) {
                    unit.setClassName(lightBean.getClassName());
                    unit.setMethodName(lightBean.getMethodName());
                    toReturn.add(unit);
                }
            }
        }
        monitorWrap.worked(monitorBuffer);
    } catch (MalformedURLException e) {
        //$NON-NLS-1$
        log.error(Messages.getString("CodeGeneratorEmittersPoolFactory.JETEmitters.NoPresent"));
        throw new BusinessException(e);
    }
    return toReturn;
}
Also used : JetBean(org.talend.designer.codegen.config.JetBean) LightJetBean(org.talend.designer.codegen.config.LightJetBean) MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) LightJetBean(org.talend.designer.codegen.config.LightJetBean) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) BusinessException(org.talend.commons.exception.BusinessException) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

ArrayList (java.util.ArrayList)3 LightJetBean (org.talend.designer.codegen.config.LightJetBean)3 JetBean (org.talend.designer.codegen.config.JetBean)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 BusinessException (org.talend.commons.exception.BusinessException)1