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

Commit

Permalink
OPEN - issue ODE-159: ExtensionActivity and ExtensionAssignOperation:…
Browse files Browse the repository at this point in the history
… Support for parser and compiler

http://issues.apache.org/jira/browse/ODE-159

git-svn-id: https://svn.apache.org/repos/asf/ode/trunk@582638 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
vanto committed Oct 7, 2007
1 parent e62de9c commit 5ef6923
Show file tree
Hide file tree
Showing 35 changed files with 1,015 additions and 85 deletions.
Expand Up @@ -18,35 +18,39 @@
*/
package org.apache.ode.bpel.compiler;

import javax.xml.namespace.QName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.compiler.api.CompilationException;
import org.apache.ode.bpel.compiler.bom.Activity;
import org.apache.ode.bpel.compiler.bom.AssignActivity;
import org.apache.ode.bpel.compiler.bom.Copy;
import org.apache.ode.bpel.compiler.bom.ExtensionAssignOperation;
import org.apache.ode.bpel.compiler.bom.ExtensionVal;
import org.apache.ode.bpel.compiler.bom.From;
import org.apache.ode.bpel.compiler.bom.LiteralVal;
import org.apache.ode.bpel.compiler.bom.PartnerLinkVal;
import org.apache.ode.bpel.compiler.bom.PropertyVal;
import org.apache.ode.bpel.compiler.bom.To;
import org.apache.ode.bpel.compiler.bom.VariableVal;
import org.apache.ode.bpel.compiler.bom.AssignActivity.AssignOperation;
import org.apache.ode.bpel.o.DebugInfo;
import org.apache.ode.bpel.o.OActivity;
import org.apache.ode.bpel.o.OAssign;
import org.apache.ode.bpel.o.OAssign.RValue;
import org.apache.ode.bpel.o.OMessageVarType;
import org.apache.ode.bpel.o.OAssign.RValue;
import org.apache.ode.utils.DOMUtils;
import org.apache.ode.utils.SerializableElement;
import org.apache.ode.utils.msg.MessageBundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.xml.namespace.QName;

/**
* Generates code for <code>&lt;assign&gt;</code> activities.
*
* @author Maciej Szefler ( m s z e f l e r @ g m a i l . c o m )
* @author Tammo van Lessen (University of Stuttgart)
*/
class AssignGenerator extends DefaultActivityGenerator {
private static final Log __log = LogFactory.getLog(AssignGenerator.class);
Expand All @@ -61,25 +65,49 @@ public OActivity newInstance(Activity src) {
public void compile(OActivity dest, Activity source) {
OAssign oassign = (OAssign) dest;
AssignActivity ad = (AssignActivity) source;
for (Copy scopy : ad.getCopies()) {
OAssign.Copy ocopy = new OAssign.Copy(_context.getOProcess());
ocopy.keepSrcElementName = scopy.isKeepSrcElement();
ocopy.debugInfo = new DebugInfo(_context.getSourceLocation(), scopy.getLineNo(),
source.getExtensibilityElements());
try {
if (scopy.getFrom() == null)
throw new CompilationException(__cmsgs.errMissingFromSpec().setSource(scopy));
ocopy.from = compileFrom(scopy.getFrom());
if (scopy.getTo() == null)
throw new CompilationException(__cmsgs.errMissingToSpec().setSource(scopy));
ocopy.to = compileTo(scopy.getTo());

verifyCopy(ocopy);
oassign.copy.add(ocopy);

} catch (CompilationException ce) {
_context.recoveredFromError(scopy, ce);
}

for (AssignOperation operation : ad.getOperations()) {
if (operation instanceof Copy) {
Copy scopy = (Copy)operation;
OAssign.Copy ocopy = new OAssign.Copy(_context.getOProcess());
ocopy.keepSrcElementName = scopy.isKeepSrcElement();
ocopy.debugInfo = new DebugInfo(_context.getSourceLocation(), scopy.getLineNo(),
source.getExtensibilityElements());
try {
if (scopy.getFrom() == null)
throw new CompilationException(__cmsgs.errMissingFromSpec().setSource(scopy));
ocopy.from = compileFrom(scopy.getFrom());
if (scopy.getTo() == null)
throw new CompilationException(__cmsgs.errMissingToSpec().setSource(scopy));
ocopy.to = compileTo(scopy.getTo());

verifyCopy(ocopy);
oassign.operations.add(ocopy);

} catch (CompilationException ce) {
_context.recoveredFromError(scopy, ce);
}
} else if (operation instanceof ExtensionAssignOperation) {
ExtensionAssignOperation sop = (ExtensionAssignOperation)operation;
OAssign.ExtensionAssignOperation oext = new OAssign.ExtensionAssignOperation(_context.getOProcess());
oext.debugInfo = new DebugInfo(_context.getSourceLocation(), sop.getLineNo(), source.getExtensibilityElements());
try {
if (source.is20Draft()) {
throw new CompilationException(__cmsgs.errExtensibleAssignNotSupported());
}
Element el = sop.getNestedElement();
if (el == null) {
throw new CompilationException(__cmsgs.errMissingExtensionAssignOperationElement().setSource(sop));
}
if (!_context.isExtensionDeclared(el.getNamespaceURI())) {
throw new CompilationException(__cmsgs.errUndeclaredExtensionAssignOperation().setSource(sop));
}
oext.nestedElement = new SerializableElement(el);
oassign.operations.add(oext);
} catch (CompilationException ce) {
_context.recoveredFromError(sop, ce);
}
}
}
}

Expand Down
Expand Up @@ -86,4 +86,19 @@ public CompilationMessage errUnknownToSpec() {
return this.formatCompilationMessage("To-spec format is unrecognized.");
}

/**ExtensionAssignOperation's nested element missing*/
public CompilationMessage errMissingExtensionAssignOperationElement(){
return this.formatCompilationMessage("Extensibility element in <extensionAssignOperation> is missing.");
}

/**ExtensionAssignOperation's nested element missing*/
public CompilationMessage errUndeclaredExtensionAssignOperation(){
return this.formatCompilationMessage("Extension namespace of <extensionAssignOperation> has not been declared.");
}

/**Draft extensibleAssign is not supported.*/
public CompilationMessage errExtensibleAssignNotSupported(){
return this.formatCompilationMessage("ExtensibleAssign is not supported, please upgrade to BPEL 2.0 final.");
}

}
Expand Up @@ -18,6 +18,31 @@
*/
package org.apache.ode.bpel.compiler;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

import javax.wsdl.Definition;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Part;
import javax.wsdl.PortType;
import javax.wsdl.WSDLException;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.compiler.api.CompilationException;
Expand All @@ -36,6 +61,7 @@
import org.apache.ode.bpel.compiler.bom.CorrelationSet;
import org.apache.ode.bpel.compiler.bom.Expression;
import org.apache.ode.bpel.compiler.bom.Expression11;
import org.apache.ode.bpel.compiler.bom.Extension;
import org.apache.ode.bpel.compiler.bom.FaultHandler;
import org.apache.ode.bpel.compiler.bom.Import;
import org.apache.ode.bpel.compiler.bom.LinkSource;
Expand Down Expand Up @@ -84,38 +110,16 @@
import org.apache.ode.utils.GUID;
import org.apache.ode.utils.NSContext;
import org.apache.ode.utils.StreamUtils;
import org.apache.ode.utils.xsd.XSUtils;
import org.apache.ode.utils.xsd.XsdException;
import org.apache.ode.utils.fs.FileUtils;
import org.apache.ode.utils.msg.MessageBundle;
import org.apache.ode.utils.stl.CollectionsX;
import org.apache.ode.utils.stl.MemberOfFunction;
import org.apache.ode.utils.stl.UnaryFunction;
import org.apache.ode.utils.xsd.XSUtils;
import org.apache.ode.utils.xsd.XsdException;
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.w3c.dom.Node;

import javax.wsdl.Definition;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Part;
import javax.wsdl.PortType;
import javax.wsdl.WSDLException;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;

/**
* Compiler for converting BPEL process descriptions (and their associated WSDL and XSD documents) into compiled representations
* suitable for execution by the ODE BPEL Service Provider. TODO: Move process validation into this class.
Expand Down Expand Up @@ -164,6 +168,8 @@ abstract class BpelCompiler implements CompilerContext {

private final HashMap<String, OExpressionLanguage> _expLanguages = new HashMap<String, OExpressionLanguage>();

private final Set<String> _declaredExtensionNS = new HashSet<String>();

private WSDLFactory4BPEL _wsdlFactory;

private OExpressionLanguage _konstExprLang;
Expand Down Expand Up @@ -683,6 +689,11 @@ public OProcess compile(final Process process, ResourceFinder rf) throws Compila
}
}

// compile extensions
for (Extension e : _processDef.getExtensions()) {
compileExtension(e);
}

OScope procesScope = new OScope(_oprocess, null);
procesScope.name = "__PROCESS_SCOPE:" + process.getName();
procesScope.debugInfo = createDebugInfo(process, null);
Expand Down Expand Up @@ -1496,6 +1507,26 @@ public OXslSheet compileXslt(String docStrUri) throws CompilationException {
return oXslSheet;
}

/**
* Registers a declared extension.
* Since compilation may take place independently of the target
* engine configuration, the compiler will not check whether a
* extension implementation is registered.
*/
private void compileExtension(Extension ext){
OProcess.OExtension oextension = new OProcess.OExtension(_oprocess);
oextension.namespaceURI = ext.getNamespaceURI();
oextension.mustUnderstand = ext.isMustUnderstand();

oextension.debugInfo = createDebugInfo(_processDef, "Extension " + ext.getNamespaceURI());

_oprocess.declaredExtensions.add(oextension);
_declaredExtensionNS.add(ext.getNamespaceURI());

if (__log.isDebugEnabled())
__log.debug("Compiled extension " + oextension);
}

private String loadXsltSheet(URI uri) {

// TODO: lots of null returns, should have some better error messages.
Expand Down Expand Up @@ -1527,11 +1558,14 @@ public boolean isPartnerLinkAssigned(String plink) {
for (OActivity act : _compiledActivities) {
if (act instanceof OAssign) {
OAssign assign = (OAssign) act;
for (OAssign.Copy copy : assign.copy) {
if (copy.to instanceof OAssign.PartnerLinkRef) {
if (((OAssign.PartnerLinkRef) copy.to).partnerLink.getName().equals(plink))
return true;
}
for (OAssign.OAssignOperation operation: assign.operations) {
if (operation instanceof OAssign.Copy) {
OAssign.Copy copy = (OAssign.Copy)operation;
if (copy.to instanceof OAssign.PartnerLinkRef) {
if (((OAssign.PartnerLinkRef) copy.to).partnerLink.getName().equals(plink))
return true;
}
}
}
}
}
Expand Down Expand Up @@ -1611,6 +1645,10 @@ protected void registerExpressionLanguage(String expLangUri, String classname) t
registerExpressionLanguage(expLangUri, (ExpressionCompiler) cls.newInstance());
}

public boolean isExtensionDeclared(String namespace) {
return _declaredExtensionNS.contains(namespace);
}

public List<OActivity> getActivityStack() {
ArrayList<OActivity> rval = new ArrayList<OActivity>(_structureStack._stack);
Collections.reverse(rval);
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.ode.bpel.compiler.bom.CompensateActivity;
import org.apache.ode.bpel.compiler.bom.CompensateScopeActivity;
import org.apache.ode.bpel.compiler.bom.EmptyActivity;
import org.apache.ode.bpel.compiler.bom.ExtensionActivity;
import org.apache.ode.bpel.compiler.bom.FlowActivity;
import org.apache.ode.bpel.compiler.bom.ForEachActivity;
import org.apache.ode.bpel.compiler.bom.IfActivity;
Expand Down Expand Up @@ -70,7 +71,8 @@ public BpelCompiler20() throws Exception {
registerActivityCompiler(TerminateActivity.class, new TerminateGenerator());
registerActivityCompiler(RethrowActivity.class, new RethrowGenerator());
registerActivityCompiler(ForEachActivity.class, new ForEachGenerator());

registerActivityCompiler(ExtensionActivity.class, new ExtensionActivtityGenerator());

registerExpressionLanguage(OASIS_EXPLANG_XPATH_1_0, new XPath10ExpressionCompilerBPEL20());

try {
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.ode.bpel.compiler.bom.Bpel20QNames;
import org.apache.ode.bpel.compiler.bom.CompensateScopeActivity;
import org.apache.ode.bpel.compiler.bom.EmptyActivity;
import org.apache.ode.bpel.compiler.bom.ExtensionActivity;
import org.apache.ode.bpel.compiler.bom.FlowActivity;
import org.apache.ode.bpel.compiler.bom.ForEachActivity;
import org.apache.ode.bpel.compiler.bom.IfActivity;
Expand Down Expand Up @@ -69,6 +70,7 @@ public BpelCompiler20Draft() throws Exception {
registerActivityCompiler(TerminateActivity.class, new TerminateGenerator());
registerActivityCompiler(RethrowActivity.class, new RethrowGenerator());
registerActivityCompiler(ForEachActivity.class, new ForEachGenerator());
registerActivityCompiler(ExtensionActivity.class, new ExtensionActivtityGenerator());

registerExpressionLanguage(OASIS_EXPLANG_XPATH_1_0, new XPath10ExpressionCompilerBPEL20Draft());
try {
Expand Down
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.ode.bpel.compiler;

import org.apache.ode.bpel.compiler.api.CompilationMessage;
import org.apache.ode.bpel.compiler.api.CompilationMessageBundle;

/**
* @author Tammo van Lessen (University of Stuttgart)
*/
public class ExtensionActivityGeneratorMessages extends CompilationMessageBundle {

/** ExtensionActivity is empty. */
public CompilationMessage errMissingExtensionActivityElement() {
return this.formatCompilationMessage("Extensibility element in <extensionActivity> is missing.");
}

/** Extension namespace is not yet declared. */
public CompilationMessage errUndeclaredExtensionActivity() {
return this.formatCompilationMessage("Extension namespace of <extensionActivity> has not been declared.");
}

}

0 comments on commit 5ef6923

Please sign in to comment.