« Return to Thread: still about how to generate BPEL process without GUI designer

Re: still about how to generate BPEL process without GUI designer

by sam wang-2 :: Rate this Message:

Reply to Author | View in Thread

Dear Nam,

I am very sorry to interrupt you again. The URL
"http://bits.nbextras.org/download/trunk/nightly/latest/" in your email is for NB 6.1 beta, right?
I download it and create the correct environment based on NB 6.1 beta. However, I still got
confused about the following questions:

First, I don't know what's myCatalogModel, even after I read the code of
"CliValidateBpelProjectDelegate" in bpel.project. I attached the source code at the attachment for
your reference.

Second, I have no clue about "myLoadPlainDocumentMethod". Could you please explain a little bit
more for me, or even better, provide me a simple sample?

Third, is your sample code for creating a blank BPEL process or reading a BPEL process project
created by NB GUI? If it's latter, the "pathToSourceFile" means the BPEL file directory or the
BPEL project src directory?

Fourth, does NB BPEL provide the API to process WSDL file? for example, partnerlink definition in
the WSDL file? (from your last email, it seems NB BPEL provides such kind of capability:
wsdl.model, wsdlext). Could you please give me a simple sample to demonstrate the usage? If the
sample code from your last email is for reading a BPEL process, is there a way to retrieve the
corresponding WSDL file in this BPEL project for further processing, and how?


Thank you very much for the great help!
Sam





--- Nam Nguyen <Nam.Nguyen@...> wrote:

> It supposed to be that openide.util is the *only* small basic NB module
> needed for using this stack:
>
> ..bpel.model
> ..wsdl.model
> ..wsdlext
> ..schema.model
> ..xam
>
> I just discovered some unwanted dependencies introduce since the sierra
> merge.  We have removed the extra dependencies.  You can try out the
> following code after get the latest daily NB build at
> http://bits.nbextras.org/download/trunk/nightly/latest/
>
> To create a bpel model, do something like this:
>
>          File bpelFile = new File(pathToSourceFile);
>          Lookup lookup = Lookups.fixed(new Object[]{
>                 bpelFile,
>                 myLoadPlainDocumentMethod(bpelFile),
>                 myCatalogModel,
>             });
>          ModelSource source = new ModelSource(lookup, editable);
>          BpelModelFactory factory =
> Lookup.getDefault().lookup(BpelModelFactory.class);
>          BpelModel model = factory.getModel (source);
>
> For more detail on myCatalogModel, look at file
> CliValidateBpelProjectDelegate in bpel.project module.  You can
> reimplement it quickly removing dependency on the retriever Utilities.
>
> -Nam
>
> sam wang wrote:
> > Hi Jason,
> >
> > Thank you for the reply. Since there are existing codes for generating BPEL, I prefer not to
> > reinvent the wheel :-)
> >
> > Eclipse BPEL also provides an open source BPEL model, which is more clear and simple than
> > NetBeans'. However, since I want to use NetBeans execution engine to run the BPEL process, I'd
> > better use NetBeans' BPEL model to generate BPEL file to make sure the compatibility.
> >
> > Anyway, I really don't think there is no way to re-use NetBeans BPEL model to generate BPEL
> file
> > without GUI.
> >
> > Any hint will be greatly appreciated!
> > Sam
> >
> >
> >
> >
> > --- Jason Baragry <Jason.Baragry@...> wrote:
> >
> >  
> >> Hi Sam,
> >>
> >> BPEL is just an XML document. Why can't you just use XML apis to
> >> programmatically create the BPEL XML document and then import it into
> >> netbeans?
> >>
> >> regards
> >> Jason
> >>
> >>    
> >>> Dear all,
> >>>
> >>> I just checked the source code of BPEL, I found that the BPEL model seems tightly coupled
> with
> >>>      
> >> NB
> >>    
> >>> GUI. For example, first I want to generate a blank BPEL process through:
> >>> org.netbeans.modules.bpel.model.impl.BpelModelFactoryImpl
> >>>
> >>> However, I need to get "org.netbeans.modules.xml.xam.ModelSource", which tightly coupled
> with
> >>>      
> >> the
> >>    
> >>> NB GUI through "org.openide.util.Lookup". I don't know how to instantiate "Lookup".
> >>>
> >>> Another potential approach seems through
> >>> "org.netbeans.modules.bpel.project.BpelproProjectGenerator". However, it only creates an
> empty
> >>> "EjbProject". I have two questions about "EjbProject". First, if it can be treated as a
> "BPEL"
> >>> project. Second, if it can be treated as a "BPEL" project, how can I create a very simple
> >>> "synchronizing BPEL example", just like the example provided by NB SOA. Or simpler, I can
> >>>      
> >> generate
> >>    
> >>> this simple BPEL project through NB GUI first, and then trying to load this project into
> some
> >>> class in order to retrieve the BPEL process with the resources. But I don't know how to do
> >>>      
> >> this. I
> >>    
> >>> think once I get the BPEL instance, I can manipulate it through all the classes in the
> package
> >>> "org.netbeans.modules.bpel.model.impl".
> >>>
> >>> In a word, my requirement is very simple. First, I want to generate a quite simple BPEL
> >>>      
> >> process as
> >>    
> >>> the template (just like the synchronizing BPEL example provided by NB SOA example), then
> >>> manipulating this BPEL process through NB's BPEL model (for example, adding activities such
> as
> >>> "receive", "reply", "invoke","assign", etc.)
> >>>
> >>> Since this is part of my Ph.D research and I am in huge pressure to graduate, any quick
> >>> hint/suggestion will be greatly appreciated!!
> >>>
> >>> Sam
> >>>
> >>>
> >>>       ____________________________________________________________________________________
> >>> Never miss a thing.  Make Yahoo your home page.
> >>> http://www.yahoo.com/r/hs
> >>>  
> >>>      
> >>    
> >
> >
> >
> >       ____________________________________________________________________________________
> > Be a better friend, newshound, and
> > know-it-all with Yahoo! Mobile.  Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 
> >
> >  
>
>


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common
 * Development and Distribution License("CDDL") (collectively, the
 * "License"). You may not use this file except in compliance with the
 * License. You can obtain a copy of the License at
 * http://www.netbeans.org/cddl-gplv2.html
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 * specific language governing permissions and limitations under the
 * License.  When distributing the software, include this License Header
 * Notice in each file and include the License file at
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the GPL Version 2 section of the License file that
 * accompanied this code. If applicable, add the following below the
 * License Header, with the fields enclosed by brackets [] replaced by
 * your own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 *
 * Contributor(s):
 *
 * The Original Software is NetBeans. The Initial Developer of the Original
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
 * Microsystems, Inc. All Rights Reserved.
 *
 * If you wish your version of this file to be governed by only the CDDL
 * or only the GPL Version 2, indicate your decision by adding
 * "[Contributor] elects to include this software in this distribution
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 * single choice of license, a recipient has the option to distribute
 * your version of this file under either the CDDL, the GPL Version 2 or
 * to extend the choice of license to its licensees as provided above.
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 * Version 2 license, then the option applies only if the new code is
 * made subject to such option by the copyright holder.
 */
package org.netbeans.modules.bpel.project.anttasks.cli;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Reference;
import org.netbeans.modules.bpel.model.api.BpelModel;
import org.netbeans.modules.bpel.project.CommandlineBpelProjectXmlCatalogProvider;
import org.netbeans.modules.bpel.project.anttasks.util.Util;
import org.netbeans.modules.xml.xam.Component;
import org.netbeans.modules.xml.xam.Model;
import org.netbeans.modules.xml.xam.spi.Validation;
import org.netbeans.modules.xml.xam.spi.Validation.ValidationType;
import org.netbeans.modules.xml.xam.spi.Validator;
import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;

/**
 * Validates BPEL Module
 * @author Sreenivasan Genipudi
 */
public class CliValidateBpelProjectDelegate extends Task {
   
    private String mSourceDirectory;
    private String mProjectClassPath;
    private String mBuildDirectory;
    private String mBuildDependentProjectFilesDirectory;
    private File mSourceDir;
    private File mBuildDir;
    private Map mBpelFileNamesToFileInBuildDir = new HashMap();
    private boolean isFoundErrors = false;
    private boolean mAllowBuildWithError = false;
   
    public CliValidateBpelProjectDelegate() {
        // Does nothing
    }
   
    public void setSourceDirectory(String srcDir) {
        this.mSourceDirectory = srcDir;
    }
   
    public void setBuildDirectory(String buildDir) {
        this.mBuildDirectory = buildDir;
    }
   
    public void setRunValidation(String flag) {
        setAllowBuildWithError(flag);
        mAllowBuildWithError = !mAllowBuildWithError;
    }
   
    public void setAllowBuildWithError(String flag) {
        if (flag != null) {
            if (flag.equals("false")) {
                mAllowBuildWithError = false;
            } else if (flag.equals("true")) {
                mAllowBuildWithError = true;
            }
        }
    }
   
    public void setClasspathRef(Reference ref) {
    }
   
    public void setProjectClassPath(String projectClassPath) {
        this.mProjectClassPath = projectClassPath;
    }
   
    public void setBuildDependentProjectDir(String dependentProjectFilesDir) {
        this.mBuildDependentProjectFilesDirectory = dependentProjectFilesDir;
    }
   
    public boolean isFoundErrors() {
        return this.isFoundErrors;
    }
   
    @Override
    public void execute() throws BuildException {
        if (this.mSourceDirectory == null) {
            throw new BuildException("No directory is set for source files.");
        }

        if (this.mBuildDirectory == null) {
            throw new BuildException("No build directory is set.");
        }

        if (this.mBuildDependentProjectFilesDirectory == null) {
            throw new BuildException("No dependentProjectFiles directory is set.");
        }

        try {
            this.mSourceDir = new File(this.mSourceDirectory);
            CommandlineBpelProjectXmlCatalogProvider.getInstance().setSourceDirectory(this.mSourceDirectory);

        } catch (Exception ex) {
            throw new BuildException("Failed to get File object for project source directory " + this.mSourceDirectory, ex);
        }

        try {
            this.mBuildDir = new File(this.mBuildDirectory);
        } catch (Exception ex) {
            throw new BuildException("Failed to get File object for project build directory " + this.mBuildDirectory, ex);
        }

        processBuildDir(this.mBuildDir);
        processSourceDir(this.mSourceDir);
    }
   
    private void processBuildDir(File folder) {
        final File files[] = folder.listFiles(new Util.BpelFileFilter());
       
        if (files == null) return; // no children
       
        for (int i = 0; i < files.length; i++) {
            final File file = files[i];
           
            if (file.isFile()) {
                this.mBpelFileNamesToFileInBuildDir.put(
                        Util.getRelativePath(this.mBuildDir, file),
                        file);
            } else {
                processBuildDir(file);
            }
        }
    }
   
    private void processSourceDir(File file) {
        if (file.isDirectory()) {
            final File[] children = file.listFiles(new Util.BpelFileFilter());
           
            if (children == null) return; // no children
           
            for (int i = 0; i < children.length; i++) {
                processSourceDir(children[i]);
            }
        } else {
            if (isModified(file)) {
                validate(file);
            }
        }
    }
   
    private boolean isModified(File bpelFile) {
        boolean modified = true;
        String relativePath = Util.getRelativePath(this.mSourceDir, bpelFile);
        File bpelFileInBuildDir = (File) this.mBpelFileNamesToFileInBuildDir.get(relativePath);

        if (bpelFileInBuildDir != null) {
            if (bpelFileInBuildDir.lastModified() == bpelFile.lastModified()) {
                modified = false;
            }
        }
        return modified;
    }
   
    private void validate(File bpelFile) throws BuildException {
        try {
            BpelModel model = CliBpelCatalogModel.
                    getDefault().getBPELModel(bpelFile.toURI());
                   
            Validation validation = new Validation();
            validation.validate((Model) model, ValidationType.COMPLETE);
            Collection col = validation.getValidationResult();
            boolean isError = false;
           
            for (Iterator itr = col.iterator(); itr.hasNext();) {
                ResultItem resultItem = (ResultItem) itr.next();
               
                if (!mAllowBuildWithError) {
                    if (resultItem.getType() == Validator.ResultType.ERROR) {
                        System.out.println(getValidationError(resultItem));
                        System.out.println();
                    }
                }
               
                if (resultItem.getType() == Validator.ResultType.ERROR) {
                    isError = true;
                }
            }

            if (isError) {
                this.isFoundErrors = true;
            }
        } catch (Throwable e) {
            if (!mAllowBuildWithError) {
                throw new BuildException(e);
            }
        }
    }
   
    private String getValidationError(ResultItem resultItem) {
        int lineNumber = 0;
        int columnNumber = 0;
        String errorDescription = resultItem.getDescription();
        String msgType = resultItem.getType().name();
        Component component = resultItem.getComponents();
        File file = null;

        if (component == null) {
            columnNumber = resultItem.getColumnNumber();
            lineNumber = resultItem.getLineNumber();
            file = (File) resultItem.getModel().getModelSource().getLookup().lookup(File.class);
        } else {
            lineNumber = Util.getLineNumber(component);
            columnNumber = Util.getColumnNumber(component);
            file = (File) component.getModel().getModelSource().getLookup().lookup(File.class);
        }
        return Util.getError(file, columnNumber, lineNumber, errorDescription, msgType);
    }
}

 « Return to Thread: still about how to generate BPEL process without GUI designer

LightInTheBox - Buy quality products at wholesale price