void daeURIResolver::attemptResolveURI(daeURI& uri) { int i,cnt = (int)_KnownResolvers.getCount(); daeBool foundProtocol = false; for(i=0;i<cnt;i++) if (_KnownResolvers[i]->isProtocolSupported(uri.getProtocol())) { foundProtocol = true; if (_KnownResolvers[i]->resolveURI(uri)) return; } #if defined(_DEBUG) && defined(WIN32) fprintf(stderr, "daeURIResolver::attemptResolveURI(%s) - failed\n", uri.getURI()); #endif if (!foundProtocol) { uri.setState(daeURI::uri_failed_unsupported_protocol); #if defined(_DEBUG) && defined(WIN32) fprintf(stderr,"**protocol '%s' is not supported**\n",uri.getProtocol()); fflush(stderr); #endif } else { #if defined(_DEBUG) && defined(WIN32) fprintf(stderr,"**file(%s/%s) or id(%s) failed to resolve\n", uri.getFilepath(),uri.getFile(),uri.getID()); fflush(stderr); #endif } }
daeBool daeLIBXMLResolver::resolveElement(daeURI& uri, daeString typeNameHint) { // Make sure the URI is validated if (uri.getState() == daeURI::uri_loaded) { uri.validate(); } daeElement* resolved = NULL; int status; // Does the URI have a document reference? if ( (uri.getFile() != NULL) && (strlen(uri.getFile())>0)) { // The URI contains a document reference, see if it is loaded and try to load it if it's not if (!_database->isDocumentLoaded(uri.getURI())) { if ( _loadExternalDocuments ) { _plugin->read(uri,NULL); } else { uri.setState( daeURI::uri_failed_external_document ); return false; } } // Try to find the id by searching this document only status = _database->getElement(&resolved,0,uri.getID(),typeNameHint,uri.getURI()); } else { // The URI was just a fragment, so try to find it in the document that contains it. // !!!GAC not sure if all these pointers will be set when we get here, so assert if any of them aren't daeElement *tempElement = uri.getContainer(); //assert(tempElement); daeDocument *tempDocument; if ( tempElement == NULL || (tempDocument = tempElement->getDocument()) == NULL ) { uri.setState(daeURI::uri_failed_missing_container); char msg[256]; sprintf(msg, "daeLIBXMLResolver::resolveElement() - failed to resolve %s\n", uri.getURI()); daeErrorHandler::get()->handleError( msg ); return false; } //assert(tempDocument); daeURI *tempURI = tempDocument->getDocumentURI(); //assert(tempURI); status = _database->getElement(&resolved,0,uri.getID(),typeNameHint,tempURI->getURI()); } uri.setElement(resolved); // Error if we didn't successfully resolve the uri if (status ||(resolved==NULL)) { uri.setState(daeURI::uri_failed_id_not_found); char msg[256]; sprintf(msg, "daeLIBXMLResolver::resolveElement() - failed to resolve %s\n", uri.getURI()); daeErrorHandler::get()->handleError( msg ); return false; } uri.setState(daeURI::uri_success); return true; }