You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2006/11/16 08:16:58 UTC
svn commit: r475627 -
/incubator/xap/trunk/src/xap/data/datasource/AbstractDataSource.js
Author: jmargaris
Date: Thu Nov 16 00:16:58 2006
New Revision: 475627
URL: http://svn.apache.org/viewvc?view=rev&rev=475627
Log:
reworking mostly around asynch requests
Modified:
incubator/xap/trunk/src/xap/data/datasource/AbstractDataSource.js
Modified: incubator/xap/trunk/src/xap/data/datasource/AbstractDataSource.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/datasource/AbstractDataSource.js?view=diff&rev=475627&r1=475626&r2=475627
==============================================================================
--- incubator/xap/trunk/src/xap/data/datasource/AbstractDataSource.js (original)
+++ incubator/xap/trunk/src/xap/data/datasource/AbstractDataSource.js Thu Nov 16 00:16:58 2006
@@ -25,13 +25,6 @@
Xap.require("xap.util.Vector");
Xap.require("xap.data.datasource.QueryRecord") ;
-
-// Xap.require("xap.plugin.data.controller.BindingType") ;
-// Xap.require("xap.plugin.data.controller.ContextFrame") ;
-// Xap.require("xap.client.netservice.HttpResponse") ;
-// Xap.require("xap.plugin.data.InitializationException") ;
-// Xap.require("xap.util.Log") ;
-// Xap.require("xap.client.netservice.NetServiceException") ;
/**
* An ease-of-use base class for DataSource implementations.
*
@@ -207,19 +200,8 @@
|| type.getTypeId() == xap.data.controller.BindingType.ONE_TIME.getTypeId()
) ;
};
-/**
- * @see DataSource#getData(String, DataRetrievalListener)
- */
-/**
- * @public
- * @param query{String}
- * @param listener{DataRetrievalListener}
- * @throws DataAccessException, MalformedQueryException,UnsupportedBindingTypeException
- * @return {void}
- **/
-xap.data.datasource.AbstractDataSource.prototype.getData = function (query, listener) {
- this.handleGenericQuery(query, null, listener);
-};
+
+
/**
* @see DataSource#getDataSet(String, DataSetRetrievalListener)
* @public
@@ -297,6 +279,8 @@
}
}
};
+
+
/**
* @see DataSource#removeListener(RetrievalListener)
* @public
@@ -369,7 +353,7 @@
xap.data.datasource.AbstractDataSource.prototype.fireOnDataRetrieveSucess = function () {
/*for (int*/
for (var i = 0; i < this._asynchronouseDataSourceListeners.size(); i++) {
- (this._asynchronouseDataSourceListeners.elementAt(i)).onDataRequestCompleted(this);
+ this._asynchronouseDataSourceListeners.elementAt(i).onDataRequestCompleted(this);
}
};
/**
@@ -434,11 +418,8 @@
* @throws DataAccessException, MalformedQueryException
**/
xap.data.datasource.AbstractDataSource.prototype.refresh = function () {
- if (this.getLog().isDebug()) {
- this.getLog().debug(ResourceDictionary.getMessage(xap.data.datasource.AbstractDataSource.REFRESH_MSGID, xap.data.datasource.AbstractDataSource, this.getClass().getName()));
- }
- fireDataChanged();
- requeryAll();
+ this.fireDataChanged();
+ this.requeryAll();
};
//----------------------------------------------------------------------
@@ -480,49 +461,60 @@
**/
xap.data.datasource.AbstractDataSource.prototype.handleDataSetQuery = function (query, context, listener) {
};
+
+
/**
- * Calls requestCompleted on the NetServiceListener returned by
- * <code>getSourceLoadRequestListener</code>. This is for
- * compatibility with the DataRequest plugin.
- *
- * @since 4.5/jRex1.1
- * @public
- * @return {void}
+ * Subclass should override to implement asynch loading of data source that comes
+ * in a response body
+ */
+xap.data.datasource.AbstractDataSource.prototype.responseToDataSource = function(response){
+
+}
+/**
+ * This should be overridden by subclasses to handle the asynchronous loading
+ * of data.
* @param a{String},
* @param response{HttpResponse}
**/
xap.data.datasource.AbstractDataSource.prototype.requestCompleted = function (a, response) {
- this.getSourceLoadRequestListener().requestCompleted(a, response);
+ try{
+ var dataSource = this.responseToDataSource( response );
+ this.setSource( dataSource );
+
+ //the ordering here is a bit tricky in that
+ //setSource will fire dataChanged BEFORE we fire
+ //this sucess message. But we probably want them
+ //to be able to get the new source their listener
+ this.fireOnDataRetrieveSucess();
+ //this.executePostponedQueries();
+ }
+ catch(e){
+ this.getClientSession().handleException(e);
+ this.fireOnDataRetrieveFailure(e);
+ }
+ finally {
+ // this.clearPostponedQueries();
+ }
};
/**
- * Calls requestFailed on the NetServiceListener returned by
- * <code>getSourceLoadRequestListener</code>. This is for
- * compatibility with the DataRequest plugin.
- *
- * @since 4.5/jRex1.1
- * @public
+ * This should be overridden by subclasses to handle the asynchronous loading
+ * of data.
* @param a{String}
* @param e{NetServiceException}
**/
xap.data.datasource.AbstractDataSource.prototype.requestFailed = function (a, e) {
- this.getSourceLoadRequestListener().requestFailed(a, e);
-};
-/**
- * Returns a listener used to retrieve the source object from the
- * server asynchronously. Subclasses should implement NetServiceListener
- * interface with their specific behaviour. For example, DocumentDataSource's
- * listener parses the response from the server into a Document while the
- * ObjectDataSource's listener deserializes the received bytes into an Object.
- *
- * @return NetServiceListener that knows how to convert the server's response
- * into a datasource specific source object.
- */
-/**
- * @protected
- * @return {NetServiceListener}
- **/
-xap.data.datasource.AbstractDataSource.prototype.getSourceLoadRequestListener = function () {
+ alert("requestFailed to load source:" + a);
+ try {
+ this.getClientSession().handleException(e);
+ this.fireOnDataRetrieveFailure(e);
+ }
+ finally {
+ // this.clearPostponedQueries();
+ }
+
};
+
+
//----------------------------------------------------------------------
// Protected Methods.
@@ -563,16 +555,11 @@
* @return {void}
**/
xap.data.datasource.AbstractDataSource.prototype.loadSourceFromServer = function (sourceUrl) {
- if (this.getLog().isDebug()) {
- this.getLog().debug(ResourceDictionary.getMessage(LOADING_SOURCE_FROM_SERVER_MSGID, xap.data.datasource.AbstractDataSource, [sourceUrl, this.getClass().getName()]));
- }
/*ClientSession*/
var session = this.getClientSession();
/*RequestService*/
var netService = session.getRequestService();
- /*NetServiceListener*/
- var listener = this.getSourceLoadRequestListener();
- netService.retrieveAsynchronously(sourceUrl, listener);
+ netService.retrieveAsynchronously(sourceUrl, this);
};
/**
* Sets the source object for this DataSource
@@ -649,6 +636,8 @@
// this._postponedQueries.removeAllElements();
// }
//};
+
+
/**
* Clears the posponed query vector.
*
@@ -656,8 +645,10 @@
* @return {void}
**/
//xap.data.datasource.AbstractDataSource.prototype.clearPostponedQueries = function () {
-// this._postponedQueries.removeAllElements();
+// this._postponedQueries = new xap.util.Vector();
//};
+
+
///**
// * @return vector of postponed queries whose execution has been postponed
// * for some reason (i.e. the source object was not available).
@@ -714,6 +705,7 @@
var containerName = sourceUrl.substring(0, i);
return containerName;
};
+
/**
* @return the static Log instance
*
@@ -721,7 +713,7 @@
* @return {Log}
**/
xap.data.datasource.AbstractDataSource.prototype.getLog = function () {
- return t;
+ return xap.util.LogFactory.getLog("DataSource");
};
//-----------------------------------------------------------------------
@@ -756,6 +748,7 @@
// changes
if (listener != null && listener.getBindingType() != xap.data.controller.BindingType.ONE_TIME) {
/*QueryRecord*/
+
var queryRecord = new xap.data.datasource.QueryRecord(query, context, listener);
this._boundQueries.addElement(queryRecord);
}
@@ -797,23 +790,8 @@
for (var i = 0; i < this._boundQueries.size(); i++) {
/*QueryRecord*/
var rec = this._boundQueries.elementAt(i);
+
this.handleQuery(rec.getQuery(), rec.getContext(), rec.getListener());
}
-};
-
-/**
- * Sets the _refreshOnPropertyChange to the newValue. If set to true,
- * the datasource will be refreshed every time the source object fires
- * property change events (granted the object contains methods for adding
- * and removing PropertyChangeListener instances)
- *
- * @param newValue - the new value for the setting
- *
- * @public
- * @param newValue{boolean}
- * @return {void}
-**/
-xap.data.datasource.AbstractDataSource.prototype.setRefreshOnPropertyChange = function (newValue) {
- this._refreshOnPropertyChange = newValue;
};