Exemplo n.º 1
0
// Init
bool COpcXmlDocument::LoadXml(LPCWSTR szXml)
{
    HRESULT hResult = S_OK;

    BSTR bstrXml = SysAllocString(szXml);

    TRY
    {
        // create new document instance.
        if (!Init())
        {
            THROW_(hResult, E_FAIL);
        }

        // parse the XML.
        VARIANT_BOOL bResult = VARIANT_FALSE;

        hResult = m_ipDocument->loadXML(bstrXml, &bResult);

        if (FAILED(hResult))
        {
            THROW();
        }

        if (!bResult)
        {
            THROW_(hResult, E_FAIL);
        }

        // add predefined namespaces
        AddNamespace(TAG_XSD,  OPCXML_NS_SCHEMA);
        AddNamespace(TAG_XSI,  OPCXML_NS_SCHEMA_INSTANCE);
    }

    CATCH
    {
        Clear();
    }

    FINALLY
    {
        SysFreeString(bstrXml);
    }

    return SUCCEEDED(hResult);
}
Exemplo n.º 2
0
// New
bool COpcXmlDocument::New()
{
    HRESULT hResult = S_OK;

    IXMLDOMProcessingInstruction* ipHeader = NULL;
    IXMLDOMNode*                  ipResult = NULL;

    BSTR bstrDocType = SysAllocString(TAG_DOCTYPE);
    BSTR bstrFormat  = SysAllocString(TAG_FORMAT);

    TRY
    {
        // create new document instance.
        if (!Init())
        {
            THROW_(hResult, E_FAIL);
        }

        // add document header.
        hResult = m_ipDocument->createProcessingInstruction(bstrDocType, bstrFormat, &ipHeader);

        if (FAILED(hResult))
        {
            THROW();
        }

        hResult = m_ipDocument->appendChild(ipHeader, &ipResult);

        if (FAILED(hResult))
        {
            THROW();
        }
    }

    CATCH
    {
        Clear();
    }

    FINALLY
    {
        // release memory.
        if (ipHeader != NULL) ipHeader->Release();
        if (ipResult != NULL) ipResult->Release();

        SysFreeString(bstrDocType);
        SysFreeString(bstrFormat);
    }

    return SUCCEEDED(hResult);
}
BasicType JVMCIRuntime::kindToBasicType(Handle kind, TRAPS) {
  if (kind.is_null()) {
    THROW_(vmSymbols::java_lang_NullPointerException(), T_ILLEGAL);
  }
  jchar ch = JavaKind::typeChar(kind);
  switch(ch) {
    case 'z': return T_BOOLEAN;
    case 'b': return T_BYTE;
    case 's': return T_SHORT;
    case 'c': return T_CHAR;
    case 'i': return T_INT;
    case 'f': return T_FLOAT;
    case 'j': return T_LONG;
    case 'd': return T_DOUBLE;
    case 'a': return T_OBJECT;
    case '-': return T_ILLEGAL;
    default:
      JVMCI_ERROR_(T_ILLEGAL, "unexpected Kind: %c", ch);
  }
}
Exemplo n.º 4
0
// Load
bool COpcXmlDocument::Load(const COpcString& cFilePath)
{
    HRESULT hResult = S_OK;

    VARIANT varFile;

    varFile.vt      = VT_BSTR;
    varFile.bstrVal = SysAllocString((LPCWSTR)cFilePath);

    TRY
    {
        // create new document instance.
        if (!Init())
        {
            THROW_(hResult, E_FAIL);
        }

        // load the file.
        VARIANT_BOOL bResult = VARIANT_FALSE;

        hResult = m_ipDocument->load(varFile, &bResult);

        if (FAILED(hResult))
        {
            THROW();
        }

        if (!bResult)
        {
            IXMLDOMParseError* ipError = NULL;

            hResult = m_ipDocument->get_parseError(&ipError);

            if (FAILED(hResult))
            {
                THROW_(hResult, E_FAIL);
            }

            BSTR bstrReason = NULL;

            hResult = ipError->get_reason(&bstrReason);

            if (SUCCEEDED(hResult))
            {
                SysFreeString(bstrReason);
            }

            ipError->Release();
        }

        // update default path.
        if (!cFilePath.IsEmpty()) m_cFilePath = cFilePath;
    }

    CATCH
    {
        Clear();
    }

    FINALLY
    {
        OpcVariantClear(&varFile);
    }

    return SUCCEEDED(hResult);
}
Exemplo n.º 5
0
// New
bool COpcXmlDocument::New(const COpcString& cRoot, const COpcString& cDefaultNamespace)
{
    HRESULT hResult = S_OK;

    IXMLDOMElement* ipRoot   = NULL;
    IXMLDOMNode*    ipResult = NULL;

    BSTR bstrRoot = SysAllocString((LPCWSTR)cRoot);

    TRY
    {
        // create new document instance.
        if (!New())
        {
            THROW_(hResult, E_FAIL);
        }

        // create root element.
        VARIANT vNodeType;
        vNodeType.vt   = VT_I4;
        vNodeType.lVal = NODE_ELEMENT;

        BSTR bstrNamespace = SysAllocString(cDefaultNamespace);
        hResult = m_ipDocument->createNode(vNodeType, bstrRoot, bstrNamespace, (IXMLDOMNode**)&ipRoot);
        SysFreeString(bstrNamespace);

        if (FAILED(hResult))
        {
            THROW();
        }

        // add root element to document.
        hResult = m_ipDocument->appendChild(ipRoot, &ipResult);

        if (FAILED(hResult))
        {
            THROW();
        }

        if (ipResult != NULL)
        {
            ipResult->Release();
            ipResult = NULL;
        }

        // declare element as the document element.
        hResult = m_ipDocument->putref_documentElement(ipRoot);

        if (FAILED(hResult))
        {
            THROW();
        }

        // add predefined namespaces
        AddNamespace(TAG_XSD, OPCXML_NS_SCHEMA);
        AddNamespace(TAG_XSI, OPCXML_NS_SCHEMA_INSTANCE);
    }

    CATCH
    {
        Clear();
    }

    FINALLY
    {
        // release memory.
        if (ipRoot != NULL) ipRoot->Release();
        if (ipResult != NULL) ipResult->Release();

        SysFreeString(bstrRoot);
    }

    return SUCCEEDED(hResult);
}
Exemplo n.º 6
0
// New
bool COpcXmlDocument::New(IXMLDOMElement* ipElement)
{
    HRESULT hResult = S_OK;

    IXMLDOMElement* ipClone  = NULL;
    IXMLDOMNode*    ipParent = NULL;
    IXMLDOMNode*    ipResult = NULL;

    TRY
    {
        // create new document instance.
        if (!New())
        {
            THROW_(hResult, E_FAIL);
        }

        // clone the element.
        hResult = ipElement->cloneNode(VARIANT_TRUE, (IXMLDOMNode**)&ipClone);

        if (FAILED(hResult))
        {
            THROW();
        }

        // remove clone from parent.
        hResult = ipClone->get_parentNode(&ipParent);

        if (FAILED(hResult))
        {
            THROW();
        }

        if (ipParent != NULL)
        {
            hResult = ipParent->removeChild(ipClone, &ipResult);

            if (FAILED(hResult))
            {
                THROW();
            }

            if (ipResult != NULL)
            {
                ipResult->Release();
                ipResult = NULL;
            }
        }

        // add root element to document.
        hResult = m_ipDocument->appendChild(ipClone, &ipResult);

        if (FAILED(hResult))
        {
            THROW();
        }

        if (ipResult != NULL)
        {
            ipResult->Release();
            ipResult = NULL;
        }

        // declare element as the document element.
        hResult = m_ipDocument->putref_documentElement(ipClone);

        if (FAILED(hResult))
        {
            THROW();
        }

        // add predefined namespaces
        AddNamespace(TAG_XSD, OPCXML_NS_SCHEMA);
        AddNamespace(TAG_XSI, OPCXML_NS_SCHEMA_INSTANCE);
    }

    CATCH
    {
        Clear();
    }

    FINALLY
    {
        // release memory.
        if (ipClone != NULL)  ipClone->Release();
        if (ipParent != NULL) ipParent->Release();
        if (ipResult != NULL) ipResult->Release();
    }

    return SUCCEEDED(hResult);
}