Esempio n. 1
0
//--------------------------------------------------------------------------------------------------------------
tresult PLUGIN_API HostApplication::queryInterface (const char* _iid, void** obj)
{
	QUERY_INTERFACE (_iid, obj, FUnknown::iid, IHostApplication)
	QUERY_INTERFACE (_iid, obj, IHostApplication::iid, IHostApplication)
	*obj = 0;
	return kResultFalse;
}
void
CellMLEventsTest::setUp()
{
  mGlycolysis = NULL;
  mBootstrap = CreateCellMLBootstrap();
  mModelLoader = mBootstrap->modelLoader();
  mGlycolysis =
    mModelLoader->loadFromURL
    (BASE_DIRECTORY L"glycolysis_pathway_1997.xml");
  QUERY_INTERFACE(mGlyET, mGlycolysis, events::EventTarget);
}
void
CDA_CellMLElementEventAdaptor::handlePossibleMathModified
(
 iface::events::Event* aEvent,
 iface::dom::Node* aNode
)
  throw(std::exception&)
{
  // We have a MathML node. Head towards the parent until we hit non-MathML or
  // CellML...
  ObjRef<iface::dom::Node> prevNode, currentNode = aNode;

  while (true)
  {
    ElementType elType;
    uint16_t nodeType = ClassifyNode(currentNode, elType);
    if (nodeType != iface::dom::Node::ELEMENT_NODE)
      return;
    if (elType == NODETYPE_CELLML)
      break;
    if (elType != NODETYPE_MATHML)
      return;
    prevNode = currentNode;
    currentNode = already_AddRefd<iface::dom::Node>(prevNode->parentNode());
    if (currentNode == NULL)
      return;
  }

  // We now have a MathML node in prevNode, which will be our target, and a
  // CellML node in currentNode, which we have to translate to a CelLMLElement
  // to get our relatedElement.
  RETURN_INTO_OBJREF(me, CDA_CellMLMutationEvent,
                     new CDA_CellMLMutationEvent());
  mParent->add_ref();
  me->mCurrentTarget = mParent;
  QUERY_INTERFACE(me->mTarget, prevNode, events::EventTarget);
  me->mRelatedElement = findCellMLElementFromNode(currentNode);
  if (me->mRelatedElement == NULL)
    return;
  me->mEventPhase = iface::events::Event::BUBBLING_PHASE;
  me->mType = L"MathModified";
  mCellMLListener->handleEvent(me);
  if (me->mPropagationStopped)
    aEvent->stopPropagation();
  if (me->mDefaultPrevented)
    aEvent->preventDefault();
}
void
CDA_CellMLElementEventAdaptor::handleNonCellMLIntoCellML
(
 iface::events::Event* aEvent,
 const wchar_t* event, iface::dom::Node* aParentEl, iface::dom::Node* aChildEl
)
  throw(std::exception&)
{
  RETURN_INTO_OBJREF(me, CDA_CellMLMutationEvent,
                     new CDA_CellMLMutationEvent());
  mParent->add_ref();
  me->mCurrentTarget = mParent;
  QUERY_INTERFACE(me->mTarget, aChildEl, events::EventTarget);
  me->mRelatedElement = findCellMLElementFromNode(aParentEl);
  me->mEventPhase = iface::events::Event::BUBBLING_PHASE;
  me->mType = event;
  mCellMLListener->handleEvent(me);
  if (me->mPropagationStopped)
    aEvent->stopPropagation();
  if (me->mDefaultPrevented)
    aEvent->preventDefault();
}
Esempio n. 5
0
void _pdo_oledb_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, HRESULT result, const char *file, int line TSRMLS_DC)
{
	pdo_oledb_db_handle *H = (pdo_oledb_db_handle *)dbh->driver_data;
	pdo_error_type *pdo_err;
	pdo_oledb_error_info *einfo;
	pdo_oledb_stmt *S;
	int persistent = 0;

	if (!H) return;

	if (stmt) {
		S = (pdo_oledb_stmt*)stmt->driver_data;
		pdo_err = &stmt->error_code;
		einfo   = &S->einfo;
	} else {
		pdo_err = &dbh->error_code;
		einfo   = &H->einfo;
		persistent = dbh->is_persistent;
	}

	einfo->file = file;
	einfo->line = line;
	einfo->errcode = result;

	if (einfo->errmsg) {
		pefree(einfo->errmsg, persistent);
		einfo->errmsg = NULL;
	}

	if (!SUCCEEDED(result)) {
		HRESULT hr;
		IErrorInfo *pIErrorInfo = NULL;
		IErrorRecords *pIErrorRecords = NULL;
		ISQLErrorInfo *pISQLErrorInfo = NULL;

		/* get the error object */
		hr = GetErrorInfo(0, &pIErrorInfo);
		if (pIErrorInfo) {
			BSTR descr_w = NULL;
			BSTR sql_state_w = NULL;
			LONG native_error = 0;
			char *descr = NULL;

			/* use IErrorRecords if possible */
			hr = QUERY_INTERFACE(pIErrorInfo, IID_IErrorRecords, pIErrorRecords);
			if (pIErrorRecords) {
				BSTR *record_descrs;
				LONG record_count = 0, i;
				
				hr = CALL(GetRecordCount, pIErrorRecords, &record_count);
				record_descrs = (BSTR *) ecalloc(record_count, sizeof(*record_descrs));
				for (i = 0; i < record_count; i++) {
					IErrorInfo *pIErrorRecordInfo = NULL;
					hr = CALL(GetErrorInfo, pIErrorRecords, i, 0x0409, &pIErrorRecordInfo);
					if (pIErrorRecordInfo) {
						hr = CALL(GetDescription, pIErrorRecordInfo, &record_descrs[i]);
						RELEASE(pIErrorRecordInfo);
					}
				}

				if (record_descrs) {
					/* join the descriptions together */
					int total_len = 0, offset = 0;
					for (i = 0; i < record_count; i++) {
						if (record_descrs[i]) {
							total_len += wcslen(record_descrs[i]) + 1;
						}
					}
					descr_w = SysAllocStringLen(NULL, total_len);
					for (i = 0; i < record_count; i++) {
						/* don't append description if it's the same as the previous one */
						if (record_descrs[i] && (i == 0 || wcscmp(record_descrs[i], record_descrs[i - 1]) != 0)) {
							if(offset != 0) {
								descr_w[offset - 1] = ' ';
							}
							wcscpy(descr_w + offset, record_descrs[i]);
							offset += wcslen(record_descrs[i]) + 1;
							SysFreeString(record_descrs[i]);
						}
					}
					efree(record_descrs);
				}

				for (i = 0; i < record_count; i++) {
					/* get a ISQLErrorInfo interface to retrieve the SQL state */
					hr = CALL(GetCustomErrorObject, pIErrorRecords, i, &IID_ISQLErrorInfo, (IUnknown **) &pISQLErrorInfo);
					if (pISQLErrorInfo) {
						hr = CALL(GetSQLInfo, pISQLErrorInfo, &sql_state_w, &native_error);
						if (SUCCEEDED(hr)) {
							/* use the first one obtained */
							break;
						}
					}
				}
			} else {
				hr = CALL(GetDescription, pIErrorInfo, &descr_w);
			}

			if (sql_state_w) {
				char *sql_state;
				int sql_state_len;
				oledb_convert_bstr(H->conv, sql_state_w, -1, &sql_state, &sql_state_len, CONVERT_FROM_UNICODE_TO_OUTPUT);
				if(sql_state_len <= 5) {
					strcpy(*pdo_err, sql_state);
				}
				efree(sql_state);
			} else {
				/* don't know what happened */
				strcpy(*pdo_err, "58004");
			}
			if (descr_w) {
				oledb_convert_bstr(H->conv, descr_w, -1, &descr, NULL, CONVERT_FROM_UNICODE_TO_OUTPUT);
				if (persistent) {
					einfo->errmsg = pestrdup(descr, persistent);
					efree(descr);
				} else {
					einfo->errmsg = descr;
				}
			}

			SysFreeString(descr_w);
			SysFreeString(sql_state_w);

			SAFE_RELEASE(pISQLErrorInfo);
			SAFE_RELEASE(pIErrorInfo);
			SAFE_RELEASE(pIErrorRecords);
		} else {
			/* no IErrorInfo, see if it's a pre-defined OLE-DB error  */
			const char *msg = oledb_hresult_text(result);
			if (msg) {
				einfo->errmsg = pestrdup(msg, persistent);
			} else {
				/* maybe it's a generic Windows error */
				LPVOID lpMsgBuf;
				FormatMessage( 
					FORMAT_MESSAGE_ALLOCATE_BUFFER | 
					FORMAT_MESSAGE_FROM_SYSTEM | 
					FORMAT_MESSAGE_IGNORE_INSERTS,
					NULL,
					result,
					MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
					(LPTSTR) &lpMsgBuf,
					0,
					NULL 
				);
				if (lpMsgBuf) {
					einfo->errmsg = pestrdup((char *) lpMsgBuf, persistent);
					LocalFree(lpMsgBuf);
				}
			}
		}

		if (!dbh->methods) {
			zend_throw_exception_ex(_php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
					*pdo_err, einfo->errcode, einfo->errmsg);
		}
	} else { /* no error */
		strcpy(*pdo_err, PDO_ERR_NONE);
	}
}
CellmlFileRdfTripleElement::CellmlFileRdfTripleElement(iface::rdf_api::Node *pNode) :
    mId(QString()),
    mUriReference(QString()),
    mLexicalForm(QString()),
    mLanguage(QString()),
    mDataTypeUri(QString())
{
    // Check which interface is supported by the node and initialise it in case
    // it supports the rdf_api::URIReference, rdf_api::PlainLiteral or
    // rdf_api::TypedLiteral interface

    ObjRef<iface::rdf_api::URIReference> uriReference;
    QUERY_INTERFACE(uriReference, pNode, rdf_api::URIReference);

    if (uriReference) {
        // The rdf_api::URIReference interface is supported, so initialise the
        // triple element using that interface

        mType = UriReference;

        mUriReference = QString::fromStdWString(uriReference->URI()).trimmed();
    } else {
        ObjRef<iface::rdf_api::PlainLiteral> plainLiteral;
        QUERY_INTERFACE(plainLiteral, pNode, rdf_api::PlainLiteral);

        if (plainLiteral) {
            // The rdf_api::PlainLiteral interface is supported, so initialise
            // the triple element using that interface

            mType = PlainLiteral;

            mLexicalForm = QString::fromStdWString(plainLiteral->lexicalForm()).trimmed();
            mLanguage    = QString::fromStdWString(plainLiteral->language()).trimmed();
        } else {
            ObjRef<iface::rdf_api::TypedLiteral> typedLiteral;
            QUERY_INTERFACE(typedLiteral, pNode, rdf_api::TypedLiteral);

            if (typedLiteral) {
                // The rdf_api::TypedLiteral interface is supported, so
                // initialise the triple element using that interface

                mType = TypedLiteral;

                mLexicalForm = QString::fromStdWString(typedLiteral->lexicalForm()).trimmed();
                mDataTypeUri = QString::fromStdWString(typedLiteral->datatypeURI()).trimmed();
            } else {
                // The node doesn't support any interface, so initialise the
                // triple element using its id
                // Note: the id returned by the CellML API will look something
                //       like
                //
                //          7EQ?;?Y?A?w???A
                //
                //       This is clearly not user-friendly, so we generate and
                //       use our own id instead...

                static QMap<QString, QString> ids;
                static int counter = 0;

                QString id = QString::fromStdString(pNode->objid()).trimmed();

                mType = Id;

                mId = ids.value(id);

                if (mId == QString()) {
                    // There is no genId value for the current id, so generate
                    // one and keep track of it

                    mId = QString("id_%1").arg(++counter, 5, 10, QChar('0'));

                    ids.insert(id, mId);
                }
            }
        }
    }
}