You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2007/03/28 21:00:47 UTC

svn commit: r523437 - in /incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler: IfGenerator.java IfGeneratorMessages.java bom/IfActivity.java

Author: mriou
Date: Wed Mar 28 12:00:46 2007
New Revision: 523437

URL: http://svn.apache.org/viewvc?view=rev&rev=523437
Log:
ODE-86 & ODE-95 Allowing if with no then element (the success activity being directly nested) as specified by BPEL 2.0 final. Complaining if no condition is provided.

Added:
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGeneratorMessages.java
Modified:
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGenerator.java
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/bom/IfActivity.java

Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGenerator.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGenerator.java?view=diff&rev=523437&r1=523436&r2=523437
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGenerator.java (original)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGenerator.java Wed Mar 28 12:00:46 2007
@@ -21,32 +21,47 @@
 
 package org.apache.ode.bpel.compiler;
 
+import org.apache.ode.bpel.compiler.api.CompilationException;
 import org.apache.ode.bpel.compiler.bom.Activity;
 import org.apache.ode.bpel.compiler.bom.IfActivity;
 import org.apache.ode.bpel.o.OActivity;
 import org.apache.ode.bpel.o.OSwitch;
+import org.apache.ode.utils.msg.MessageBundle;
 
 
 /**
  * Generates code for the <code>&lt;switch&gt;</code> activities.
  */
 class IfGenerator extends DefaultActivityGenerator {
-  public OActivity newInstance(Activity src) {
+    private static final IfGeneratorMessages __cmsgs = MessageBundle.getMessages(IfGeneratorMessages.class);
+
+    public OActivity newInstance(Activity src) {
         return new OSwitch(_context.getOProcess(), _context.getCurrent());
-  }
+    }
+
+    public void compile(OActivity output, Activity src) {
+        OSwitch oswitch = (OSwitch) output;
+        IfActivity switchDef = (IfActivity)src;
+
+        if (switchDef.getCondition() == null)
+            throw new CompilationException(__cmsgs.errIfWithNoCondition());
+
+        boolean first = true;
+        if (switchDef.getActivity() != null) {
+            OSwitch.OCase ocase = new OSwitch.OCase(_context.getOProcess());
+            ocase.activity = _context.compile(switchDef.getActivity());
+            ocase.expression = _context.compileExpr(switchDef.getCondition());
+            oswitch.addCase(ocase);
+            first = false;
+        }
 
-  public void compile(OActivity output, Activity src) {
-    OSwitch oswitch = (OSwitch) output;
-    IfActivity switchDef = (IfActivity)src;
-
-    boolean first = true;
-    for (IfActivity.Case ccase : switchDef.getCases()) {
-      OSwitch.OCase ocase = new OSwitch.OCase(_context.getOProcess());
-      ocase.activity = _context.compile(ccase.getActivity());
-      ocase.expression = first ? _context.compileExpr(switchDef.getCondition())
-              : (ccase.getCondition() == null ? _context.constantExpr(true) : _context.compileExpr(ccase.getCondition()));
-      oswitch.addCase(ocase);
-      first = false;
+        for (IfActivity.Case ccase : switchDef.getCases()) {
+            OSwitch.OCase ocase = new OSwitch.OCase(_context.getOProcess());
+            ocase.activity = _context.compile(ccase.getActivity());
+            ocase.expression = first ? _context.compileExpr(switchDef.getCondition())
+                    : (ccase.getCondition() == null ? _context.constantExpr(true) : _context.compileExpr(ccase.getCondition()));
+            oswitch.addCase(ocase);
+            first = false;
+        }
     }
-  }
 }

Added: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGeneratorMessages.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGeneratorMessages.java?view=auto&rev=523437
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGeneratorMessages.java (added)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/IfGeneratorMessages.java Wed Mar 28 12:00:46 2007
@@ -0,0 +1,35 @@
+/*
+ * 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 Matthieu Riou <mriou at apache dot org>
+ */
+public class IfGeneratorMessages extends CompilationMessageBundle {
+
+    /** The &lt;if&gt; must have a condition element. */
+    public CompilationMessage errIfWithNoCondition() {
+        return this.formatCompilationMessage("A <if> activity is declared with no <condition> element.");
+    }
+
+}

Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/bom/IfActivity.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/bom/IfActivity.java?view=diff&rev=523437&r1=523436&r2=523437
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/bom/IfActivity.java (original)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/bom/IfActivity.java Wed Mar 28 12:00:46 2007
@@ -18,10 +18,10 @@
  */
 package org.apache.ode.bpel.compiler.bom;
 
-import java.util.List;
-
 import org.w3c.dom.Element;
 
+import java.util.List;
+
 /**
  * Representation of the BPEL <code>&lt;switch&gt;</code> activity.
  */
@@ -34,6 +34,16 @@
         return getFirstChild(Expression.class);
     }
     
+    /**
+     * Get the activity for this if. BPEL 2.0 draft mandated the inclusion of the
+     * condition success activity in a <then> element. In that case this will be
+     * null. For BPEL 2.0 final this should return the condition success activity.
+     *
+     * @return activity enabled when case is satisfied
+     */
+    public Activity getActivity() {
+        return getFirstChild(Activity.class);
+    }
 
     /**
      * Get the cases for this switch.