Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Changed a bit the way the compiler generates the cbp file. Used to ha…
Browse files Browse the repository at this point in the history
…ve some issues with several processes having the same name (but different namespaces) in the same bundle. So now:

1. The cbp file has the same name as the original bpel file.
2. It's generated in the same directory.

Also added a dry run mode so people can run the compiler to check their process without having any cbp file generated.

git-svn-id: https://svn.apache.org/repos/asf/incubator/ode/trunk@537229 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Matthieu Riou committed May 11, 2007
1 parent 67881d2 commit 35e7fe2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 53 deletions.
90 changes: 39 additions & 51 deletions bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public class BpelC {

private CompileListener _compileListener;
public OutputStream _outputStream = null;
private File _outputDir = null;

private File _bpelFile;
private ResourceFinder _wsdlFinder;
private URI _bpel11wsdl;
private Map<String,Object> _compileProperties;
private boolean _dryRun = false;

public static BpelC newBpelCompiler() {
return new BpelC();
Expand All @@ -82,7 +82,6 @@ private void invalidate() {
this.setResourceFinder(null);
this.setCompileListener(null);
this.setOutputStream(null);
this.setOutputDirectory(null);
}

/**
Expand All @@ -95,6 +94,15 @@ public void setCompileListener(CompileListener cl) {
_compileListener = cl;
}

/**
* Configures the compiler to run a dry compilation, doesn't generate the produced
* compiled process.
* @param dryRun
*/
public void setDryRun(boolean dryRun) {
_dryRun = dryRun;
}

/**
* <p>
* Tell the compiler how to locate WSDL imports for a BPEL process. Setting this
Expand Down Expand Up @@ -149,30 +157,6 @@ public void setOutputStream(OutputStream os) {
}
}

/**
* <p>
* Set the target directory for output. This overrides {@link #setOutputStream(OutputStream)}.
* </p>
* @param outputDir the filesystem directory to write the compiled process to.
* @see #setOutputStream(OutputStream)
*/
public void setOutputDirectory(File outputDir) {
// override any outputStream setting
this.setOutputStream(null);

// check if this is suitable for output
if (outputDir != null) {
if (outputDir.exists() && outputDir.isDirectory() && outputDir.canWrite()) {
_outputDir = outputDir;
if (__log.isDebugEnabled()) {
__log.debug("Set output directory to " + outputDir.toURI());
}
} else {
throw new IllegalArgumentException("outputDirectory not writeable: " + outputDir.toURI());
}
}
}

/**
* <p>
* Compile a BPEL process from a BOM {@link Process} object.
Expand All @@ -187,7 +171,7 @@ public void setOutputDirectory(File outputDir) {
* @throws CompilationException
* if one occurs while compiling.
*/
public void compile(final Process process) throws CompilationException, IOException {
public void compile(final Process process, String outputPath) throws CompilationException, IOException {
if (process == null)
throw new NullPointerException("Attempt to compile NULL process.");

Expand Down Expand Up @@ -272,35 +256,37 @@ public void onCompilationMessage(CompilationMessage compilationMessage) {
throw cex;
}

if (_outputStream != null) {
if (__log.isDebugEnabled()) {
__log.debug("Writing compilation results to " + _outputStream.getClass().getName());
}
} else if (_outputDir != null) {
File outFile = new File(_outputDir, oprocess.getName() + ".cbp");
this.setOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
if (__log.isDebugEnabled()) {
__log.debug("Writing compilation results to " + outFile.toURI().toString());
if (!_dryRun) {
if (outputPath != null) {
this.setOutputStream(new BufferedOutputStream(new FileOutputStream(outputPath)));
System.out.println("Writing compilation results to " + outputPath);
if (__log.isDebugEnabled()) {
__log.debug("Writing compilation results to " + outputPath);
}
} else if (_outputStream != null) {
if (__log.isDebugEnabled()) {
__log.debug("Writing compilation results to " + _outputStream.getClass().getName());
}
} else {
throw new IllegalStateException("must setOutputStream() or setOutputDirectory()!");
}
} else {
throw new IllegalStateException("must setOutputStream() or setOutputDirectory()!");
}

try {
Serializer fileHeader = new Serializer(System.currentTimeMillis());
fileHeader.writeOProcess(oprocess, _outputStream);
} finally {
// close & mark myself invalid
this.invalidate();
try {
Serializer fileHeader = new Serializer(System.currentTimeMillis());
fileHeader.writeOProcess(oprocess, _outputStream);
} finally {
// close & mark myself invalid
this.invalidate();
}
}
}

/**
* <p>
* Compile a BPEL process from a URL. This method uses a {@link BpelProcessBuilder}
* to parse the XML and then calls {@link #compile(Process)}.
* Compile a BPEL process from a file. This method uses a {@link BpelObjectFactory}
* to parse the XML and then calls {@link #compile(Process,String)}.
* </p>
* @param bpelFile the URL of the BPEL process to be compiled.
* @param bpelFile the file of the BPEL process to be compiled.
* @throws IOException if one occurs while reading the BPEL process or writing the
* output.
* @throws CompilationException if one occurs while compiling the process.
Expand All @@ -322,8 +308,6 @@ public void compile(File bpelFile) throws CompilationException, IOException {
isrc.setSystemId(bpelFile.getAbsolutePath());

process = BpelObjectFactory.getInstance().parse(isrc,_bpelFile.toURI());


} catch (Exception e) {
CompilationMessage cmsg = __cmsgs.errBpelParseErr().setSource(new SourceLocationImpl(bpelFile.toURI()));
this.invalidate();
Expand All @@ -332,7 +316,11 @@ public void compile(File bpelFile) throws CompilationException, IOException {

assert process != null;

compile(process);
// Output file = bpel file with a cbp extension
String bpelPath = bpelFile.getAbsolutePath();
String cbpPath = bpelPath.substring(0, bpelPath.lastIndexOf(".")) + ".cbp";

compile(process, cbpPath);
this.invalidate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ void scan() {
HashMap<QName, CBPInfo> processes = new HashMap<QName, CBPInfo>();
ArrayList<File> cbps = listFilesRecursively(_duDirectory, DeploymentUnitDir._cbpFilter);
for (File file : cbps) {
System.out.println("Found CBP file " + file.getAbsolutePath());
CBPInfo cbpinfo = loadCBPInfo(file);
System.out.println("Process name " + cbpinfo.processName);
processes.put(cbpinfo.processName, cbpinfo);
}
_processes = processes;
Expand All @@ -146,8 +148,8 @@ boolean isRemoved() {
}

private void compile(File bpelFile) {
System.out.println("Compiling " + bpelFile.getAbsolutePath());
BpelC bpelc = BpelC.newBpelCompiler();
bpelc.setOutputDirectory(_duDirectory);
bpelc.setCompileProperties(prepareCompileProperties(bpelFile));
try {
bpelc.compile(bpelFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public void onCompilationMessage(CompilationMessage m) {
if (u != null) {
compiler.setProcessWSDL(u);
}
compiler.setOutputDirectory(_outputDir);
compiler.setCompileListener(myListener);

File bpelFile = new File(bpelURI);
Expand Down

0 comments on commit 35e7fe2

Please sign in to comment.