/**
  * Proxy to {@link OdeRTInstanceContext#initializeVariable(Variable, Node)} then write properties.
  */
 public Node initializeVariable(VariableInstance var, ScopeFrame scopeFrame, Node val)
     throws ExternalVariableModuleException {
   try {
     if (var.declaration.extVar != null) /* external variable */ {
       if (__log.isDebugEnabled())
         __log.debug(
             "Initialize external variable: name="
                 + var.declaration
                 + " value="
                 + DOMUtils.domToString(val));
       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
       }
       if (reference != null) val = _brc.readExtVar(var, reference);
       return val;
     } else /* normal variable */ {
       if (__log.isDebugEnabled())
         __log.debug(
             "Initialize variable: name="
                 + var.declaration
                 + " value="
                 + DOMUtils.domToString(val));
       return _brc.initializeVariable(var, val);
     }
   } finally {
     writeProperties(var, val);
   }
 }
 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;
   }
 }