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;
   }
 }