public void commitChanges(VariableInstance var, ScopeFrame scopeFrame, Node value)
     throws ExternalVariableModuleException {
   if (var.declaration.extVar != null) /* external variable */ {
     if (__log.isDebugEnabled())
       __log.debug(
           "Write external variable: name="
               + var.declaration
               + " value="
               + DOMUtils.domToString(value));
     VariableInstance related = scopeFrame.resolve(var.declaration.extVar.related);
     Node reference = null;
     try {
       reference = fetchVariableData(var, scopeFrame, true);
     } catch (FaultException fe) {
       // In this context this is not necessarily a problem, since the assignment may re-init the
       // related var
     }
     VariableContext.ValueReferencePair vrp = _brc.writeExtVar(var, reference, value);
     commitChanges(related, scopeFrame, vrp.reference);
   } else /* normal variable */ {
     if (__log.isDebugEnabled())
       __log.debug(
           "Write variable: name=" + var.declaration + " value=" + DOMUtils.domToString(value));
     _brc.commitChanges(var, value);
   }
   writeProperties(var, value);
 }
 public Node fetchVariableData(
     VariableInstance variable, ScopeFrame scopeFrame, boolean forWriting) throws FaultException {
   if (variable.declaration.extVar != null) {
     // Note, that when using external variables, the database will not contain the value of the
     // variable, instead we need to go the external variable subsystems.
     Element reference =
         (Element)
             _brc.fetchVariableData(
                 scopeFrame.resolve(variable.declaration.extVar.related), false);
     try {
       Node ret = _brc.readExtVar(variable, reference);
       if (ret == null) {
         throw new FaultException(
             _runtime._oprocess.constants.qnUninitializedVariable,
             "The external variable \""
                 + variable.declaration.name
                 + "\" has not been initialized.");
       }
       return ret;
     } catch (IncompleteKeyException ike) {
       // This indicates that the external variable needed to be written do, put has not been.
       __log.error(
           "External variable could not be read due to incomplete key; the following key "
               + "components were missing: "
               + ike.getMissing());
       throw new FaultException(
           _runtime._oprocess.constants.qnUninitializedVariable,
           "The extenral variable \""
               + variable.declaration.name
               + "\" has not been properly initialized;"
               + "the following key compoenents were missing:"
               + ike.getMissing());
     } catch (ExternalVariableModuleException e) {
       throw new BpelEngineException(e);
     }
   } else /* not external */ {
     Node data = _brc.fetchVariableData(variable, forWriting);
     if (data == null) {
       // Special case of messageType variables with no part
       if (variable.declaration.type instanceof OMessageVarType) {
         OMessageVarType msgType = (OMessageVarType) variable.declaration.type;
         if (msgType.parts.size() == 0) {
           Document doc = DOMUtils.newDocument();
           Element root = doc.createElement("message");
           doc.appendChild(root);
           return root;
         }
       }
       throw new FaultException(
           _runtime._oprocess.constants.qnUninitializedVariable,
           "The variable " + variable.declaration.name + " isn't properly initialized.");
     }
     return data;
   }
 }