incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r447525 [2/2] - in /incubator/xap/trunk/src/xap/data: ./ bridge/ datasource/
Date Mon, 18 Sep 2006 19:52:15 GMT
Added: incubator/xap/trunk/src/xap/data/datasource/DataSourceImpl.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/datasource/DataSourceImpl.js?view=auto&rev=447525
==============================================================================
--- incubator/xap/trunk/src/xap/data/datasource/DataSourceImpl.js (added)
+++ incubator/xap/trunk/src/xap/data/datasource/DataSourceImpl.js Mon Sep 18 12:52:14 2006
@@ -0,0 +1,886 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *	  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+Xap.provide("xap.data.datasource.DataSourceImpl") ;
+
+Xap.require("xap.util.Vector") ;
+
+Xap.require("xap.session.ClientSession") ; 
+Xap.require("xap.session.Container") ; 
+Xap.require("xap.mco.ContainerLifeCycleObject") ; 
+//Xap.require("xap.requestservice.HttpResponse") ; 
+//Xap.require("xap.requestservice.NetServiceException") ; 
+Xap.require("xap.requestservice.NetServiceListener") ; 
+Xap.require("xap.requestservice.RequestService") ; 
+//Xap.require("xap.data.InitializationException") ; 
+//Xap.require("xap.data.controller.BindingType") ; 
+//Xap.require("xap.data.controller.Context") ; 
+Xap.require("xap.util.LogFactory") ; 
+Xap.require("xap.util.ResourceDictionary") ; 
+Xap.require("xap.xml.dom.XapElement") ; 
+
+/**
+* An ease-of-use base class for DataSource implementations. 
+* 
+* <p/>
+* 
+* This class persists bound queries (i.e. queries whose binding type != 
+* BindingType.ONE_WAY) so that they can be later requeried when the data 
+* changes.
+* 
+* <p/>
+* 
+* This base class can also keep track of any queries that need to be postponed 
+* and executed later if the data is being retrieved at the time of the original
+* query.  It is up to the subclasses to take advantage of this functionality.
+* If subclasses add postponed queries, it is their responsibility to execute or
+* clean them up later (the queries are automatically cleaned up after the 
+* execution).
+* 
+* <br><br>
+* As of 4.5/jRex1.1 this implements NetServiceListener in order
+* to work well with the DataRequest plugin.
+* 
+* @see #addPostponedQuery(String, Context, RetrievalListener)
+* @see #executePostponedQueries()
+* @see #clearPostponedQueries()
+* 
+* @version $Revision: 1.23 $
+* @author Igor Kaplansky
+* @abstract
+*/
+xap.data.datasource.DataSourceImpl = function(){}	
+
+
+//-----------------------------------------------------------------------
+// Constants
+//-----------------------------------------------------------------------
+
+/**
+ * Loading source from server URL: {0}, DataSource class: {1}
+ * <br/>
+ * Args:
+ * <ul>
+ * <li>{0} - the source URL.</li>
+ * <li>{1} - the DataSource class name.</li>
+ * </ul>
+ */
+/*private static final String*/
+xap.data.datasource.DataSourceImpl.LOADING_SOURCE_FROM_SERVER_MSGID =  
+	"loadSourceFromServer";
+	
+/**
+ * Refresh got called on the datasource: {0}.
+ * <br/>
+ * Args:
+ * <ul>
+ * <li>{0} - the class name of the datasource. </li>
+ * </ul>
+ */
+/*private static final String*/
+xap.data.datasource.DataSourceImpl.REFRESH_MSGID =  "refresh";
+	
+/**
+ * Setting null as the source object is not allowed for datasource {0}
+ * <br/>
+ * Args:
+ * <ul>
+ * <li>{0} - the DataSource class name.</li>
+ * </ul>
+ */
+/*protected static final String*/
+xap.data.datasource.DataSourceImpl.NULL_SOURCE_MSGID =  "nullSource";
+   
+	
+//-----------------------------------------------------------------------
+// Instance Variables.
+//-----------------------------------------------------------------------
+/**
+ * @private Element
+ **/
+xap.data.datasource.DataSourceImpl.prototype._dataSourceElement =  null;
+/**
+ * @private ClientSession
+ **/
+xap.data.datasource.DataSourceImpl.prototype._clientSession =  null;
+/**
+ * @private String
+ **/
+xap.data.datasource.DataSourceImpl.prototype._id =  null;
+/**
+ * @private Object
+ **/
+xap.data.datasource.DataSourceImpl.prototype._source =  null;
+// vector of QueryRecords for all bound queries (binding type != ONE_TIME)
+/**
+ * @private Vector
+ **/
+xap.data.datasource.DataSourceImpl.prototype._boundQueries =  null;
+// vector of QueryRecords for all postponed queries.
+/**
+ * @private Vector
+ **/
+xap.data.datasource.DataSourceImpl.prototype._postponedQueries =  null;
+/**
+ * @
+ private Vector
+**/
+xap.data.datasource.DataSourceImpl.prototype._dataChangeListeners =  new xap.util.Vector();
+/**
+ * @
+ private Vector
+**/
+xap.data.datasource.DataSourceImpl.prototype._asynchronouseDataSourceListeners =  new xap.util.Vector();
+	
+//-----------------------------------------------------------------------
+// DataSource Interface.
+//-----------------------------------------------------------------------
+
+/**
+ * @see DataSource#initialize(String, ClientSession, Element)
+ * <p/>
+ * Subclasses have to call <code>super.initialize(String,ClientSession,
+ * Element)</code> if they override this method.
+ */
+/**
+ * @public
+ * @param id{String}
+ * @param session{ClientSession}
+ * @param dataSourceElement{XapElement}
+ * @return {void}
+ * @throws InitializationException
+ **/
+xap.data.datasource.DataSourceImpl.prototype.initialize 
+	= function( id, session,dataSourceElement ){
+	this._id = id;
+	this._clientSession = session;
+	this._dataSourceElement = dataSourceElement;
+	this._boundQueries = new Vector();
+	this._postponedQueries = new Vector();
+	}
+
+/**
+ * @see DataSource#destroy()
+ * <p/>
+ * Subclasses have to call <code>super.destroy()</code> if they override
+ * this method.
+ */
+/**
+ * @public
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.destroy = function() {
+	/**/
+	var _boundQueries =  new Vector();
+	/**/
+	var _postponedQueries =  new Vector();
+}
+
+/**
+ * @see DataSource#getId()
+ */
+/**
+ * @public
+ * @return {String}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getId = function() {
+	return this._id;
+}
+
+/**
+ * @see DataSource#isSupported(BindingType)
+ */
+/**
+ * @public
+ * @param type{BindingType }
+ * @return {boolean}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.isSupported  = function( type ) {
+	return type == BindingType.ONE_TIME ||
+	type == BindingType.ONE_WAY;
+}
+
+/**
+ * @see DataSource#getData(String, DataRetrievalListener)
+ */
+/**
+ * @public
+ * @param query{String}
+ * @param listener{DataRetrievalListener}
+ * @throws DataAccessException, MalformedQueryException,UnsupportedBindingTypeException 
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getData  = function(query, listener ){
+	handleGenericQuery( query, null, listener );
+}
+
+/**
+ * @see DataSource#getDataSet(String, DataSetRetrievalListener)
+ * @public
+ * @param query{String}
+ * @param listener{DataRetrievalListener}
+ * @throws DataAccessException, MalformedQueryException,UnsupportedBindingTypeException 
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getDataSet  = function( query, listener ){
+	handleGenericQuery( query, null, listener );
+}
+	
+/**
+ * @see DataSource#getData(String, DataRetrievalListener, Context)
+ */
+/**
+ * @public
+ * @param query{String}
+ * @param listener{DataRetrievalListener}
+ * @param c
+ * @throws DataAccessException, MalformedQueryException,UnsupportedBindingTypeException 
 
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getData  = function( query, listener, context
) {
+	handleGenericQuery( query, context, listener );
+}
+
+/**
+ * @see DataSource#getDataSet(String, DataSetRetrievalListener, Context)
+ * @public
+ * @return {void}
+ * @param query{String}
+ * @param listener{DataRetrievalListener}
+ * @param context{Context  }
+ * @throws DataAccessException, MalformedQueryException, UnsupportedBindingTypeException

+ **/
+xap.data.datasource.DataSourceImpl.prototype.getData  = function( query, listener, context
){
+	handleGenericQuery( query, context, listener );
+}
+
+/**
+ * @see DataSource#removeListener(String, RetrievalListener, Context)
+ */
+/**
+ * @public
+ * @return {void}
+ * @param query{String}
+ * @param listener{RetrievalListener}
+ * @param context{Context  }
+ **/
+xap.data.datasource.DataSourceImpl.prototype.removeListener = function( query, listener,
context ){
+	for( var i=0; i < this._boundQueries.size(); i++ ) {
+	/*QueryRecord*/
+	var record =  this._boundQueries.elementAt( i );
+	if( record.getQuery().equals( query ) &&
+		record.getListener() == listener  &&
+		record.getContext()== context ) {
+		this._boundQueries.removeElementAt( i-- );
+	}
+	}
+	for( var i=0; i < this._postponedQueries.size(); i++ ) {
+	/*QueryRecord*/
+	var record =  this._postponedQueries.elementAt( i );
+	if( record.getQuery().equals( query ) &&
+		record.getListener() == listener  &&
+		record.getContext() == context ) {
+		this._postponedQueries.removeElementAt( i-- );
+	}
+	}
+}
+
+/**
+ * @see DataSource#removeListener(String, RetrievalListener)
+ * @public
+ * @return {void}
+ * @param query{String}
+ * @param listener{RetrievalListener}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.removeListener = function( query, listener){
+	for( var i=0; i < this._boundQueries.size(); i++ ) {
+	/*QueryRecord*/
+	var record =  this._boundQueries.elementAt( i );
+	if( record.getQuery().equals( query ) &&
+		record.getListener() == listener ) {
+		this._boundQueries.removeElementAt( i-- );
+	}
+	}
+	for( var i=0; i < this._postponedQueries.size(); i++ ) {
+	/*QueryRecord*/
+	var record = this._postponedQueries.elementAt( i );
+	if( record.getQuery().equals( query ) &&
+		record.getListener() == listener ) {
+		this._postponedQueries.removeElementAt( i-- );
+	}
+	}
+}
+
+/**
+ * @see DataSource#removeListener(RetrievalListener)
+ * @public
+ * @param listener{RetrievalListener}
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.removeListener = function( listener ){
+	for( var i=0; i < this._boundQueries.size(); i++ ) {
+		/*QueryRecord*/
+		var record =  this._boundQueries.elementAt( i );
+		if(record.getListener() == listener ) {
+			this._boundQueries.removeElementAt( i-- );
+		}
+	}
+	for( var i=0; i < _postponedQueries.size(); i++ ) {
+		/*QueryRecord*/
+		var record =  this._postponedQueries.elementAt( i );
+		if(record.getListener() == listener ) {
+			this._postponedQueries.removeElementAt( i-- );
+		}
+	}
+}
+	
+/**
+ * @param l{DataChangeListener}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.addDataChangeListener = function(l){
+	if (!this._dataChangeListeners.contains(l)){
+		this._dataChangeListeners.addElement(l);
+	}
+}
+	
+/**
+ * @public
+ * @param l{DataChangeListener}
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.removeDataChangeListener = function(l){
+	this._dataChangeListeners.removeElement(l);		
+}
+	
+/**
+ * @protected
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.fireDataChanged = function(){
+	for(var i = 0; i<_dataChangeListeners.size(); i++){
+		(this._dataChangeListeners.elementAt(i)).onDataChanged(this);
+	}
+}
+	
+/**
+ * @public
+ * @param l{AsynchronousDataSourceListener}
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.addAsynchronousDataSourceListener = function(l){
+	if (!_asynchronouseDataSourceListeners.contains(l)){
+	this._asynchronouseDataSourceListeners.addElement(l);
+	}
+		
+}
+	
+/**
+ * @public
+ * @return {void}
+ * @param l{AsynchronousDataSourceListener}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.removeAsynchronousDataSourceListener = function(l){
+	this._asynchronouseDataSourceListeners.removeElement(l);		
+}
+	
+/**
+ * @protected
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.fireOnDataRetrieveSucess = function(){
+	/*for (int*/
+	for(var i = 0; i<_asynchronouseDataSourceListeners.size(); i++){
+	(this._asynchronouseDataSourceListeners.
+	 elementAt(i)).onDataRequestCompleted(this);
+	}
+}
+	
+/**
+ * @protected
+ * @param failureCause{Exception}
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.fireOnDataRetrieveFailure = function(failureCause){
+	/*for (int*/
+	for(var i = 0; i<_asynchronouseDataSourceListeners.size(); i++){
+	(this._asynchronouseDataSourceListeners.
+	 elementAt(i)).onDataRequestFailed(this, failureCause);
+	}
+}
+
+//-----------------------------------------------------------------------
+// ContainerLifecycleObject Interface.
+//-----------------------------------------------------------------------
+/**
+ * @see ContainerLifecycleObject#addedToContainer(
+ *				   xap.mco.Container, java.lang.String )
+ */
+/**
+ * @public
+ * @return {void}
+ **/
+/**
+ * @param container{Container}
+ * @param name{String}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.addedToContainer = function( container, name
) {
+	//NOOP
+}
+	
+/**
+ * @see ContainerLifecycleObject#removedFromContainer(
+ *					  xap.mco.Container, java.lang.String )
+ */
+/**
+ * @public
+ * @return {void}
+ **/
+/**
+ * @param container{Container}
+ * @param name{String}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.removedFromContainer = function( container,
name ) {
+	destroy();
+}
+	
+//-----------------------------------------------------------------------
+// Public Methods.
+//-----------------------------------------------------------------------
+
+/**
+ * Requeries all bound queries notifying cached RetrievalListeners 
+ * with the new data.
+ * 
+ * @throws DataAccessException
+ * @throws MalformedQueryException
+ */
+/**
+ * @public
+ * @return {synchronized}
+ * @throws DataAccessException, MalformedQueryException
+ **/
+xap.data.datasource.DataSourceImpl.prototype.refresh = function() {
+ 
+	if ( this.getLog().isDebug() ) {
+//		this.getLog().debug( ResourceDictionary.getMessage(
+//							  xap.data.datasource.DataSourceImpl.REFRESH_MSGID, 
+//							  xap.data.datasource.DataSourceImpl,
+//							  this.getClass().getName()));
+	}
+	this.fireDataChanged();
+	this.requeryAll();
+}
+			
+//----------------------------------------------------------------------
+// Protected Abstract Methods.
+//-----------------------------------------------------------------------
+
+/**
+ * Subclasses are responsible for implementing this method.  The query 
+ * details are obviously subclass specific. It is also up to the subclass
+ * whether to execute the query asynchronously or not.
+ * 
+ * @param query The query to execute
+ * @param context The context for executing the query
+ * @param listener The listener to notify with the results of the query
+ * @throws DataAccessException
+ * @throws MalformedQueryException
+ * @protected
+ * @param query{String}
+ * @param context{Context} 
+ * @param listener{DataRetrievalListener}
+ * @throws DataAccessException, MalformedQueryException;
+ **/
+xap.data.datasource.DataSourceImpl.prototype.handleDataQuery 
+	= function( query, context, listener ){}
+
+
+/**
+ * Subclasses are responsible for implementing this method.  The query 
+ * details are obviously subclass specific. It is also up to the subclass
+ * whether to execute the query asynchronously or not.
+ * 
+ * @param query The query to execute
+ * @param context The context for executing the query
+ * @param listener The listener to notify with the results of the query
+ * @throws DataAccessException
+ * @throws MalformedQueryException
+ * @protected
+ * @param query{String}
+ * @param context{Context}
+ * @param listener{DataSetRetrievalListener  }
+ * @throws DataAccessException, MalformedQueryException
+ **/
+xap.data.datasource.DataSourceImpl.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}
+ * @param a{String}, 
+ * @param response{HttpResponse}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.requestCompleted = function( a, response){
+	this.getSourceLoadRequestListener().requestCompleted(a, response);
+}
+	
+/**
+ * Calls requestFailed on the NetServiceListener returned by
+ * <code>getSourceLoadRequestListener</code>. This is for 
+ * compatibility with the DataRequest plugin.
+ * 
+ * @since 4.5/jRex1.1
+ * @public
+ * @param a{String}
+ * @param e{NetServiceException}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.requestFailed = function( a, e ){
+	this.getSourceLoadRequestListener().requestFailed(a, e);
+}
+/**
+ * Returns a NetServiceListener 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.DataSourceImpl.prototype.getSourceLoadRequestListener = function(){
+}
+	
+//----------------------------------------------------------------------
+// Protected Methods.
+//----------------------------------------------------------------------
+	
+/**
+ * @return the ClientSession this DataSource is associated with
+ */
+/**
+ * @protected
+ * @return {ClientSession}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getClientSession = function() {
+	return this._clientSession;
+}
+
+/**
+ * @return the DataSource declaration element
+ */
+/**
+ * @protected
+ * @return {Element}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getDataSourceElement = function() {
+	return this._dataSourceElement;
+}
+	
+/**
+ * @return the source object of the DataSource
+ */
+/**
+ * @protected
+ * @return {Object}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getSource = function() {
+	return this._source;
+}
+
+/**
+ * Asynchronously loads the source object using NetService
+ * 
+ * @param sourceUrl The url to the resource that is expected to return the
+ * source object for this DataSource
+ */
+/**
+ * @protected
+ * @param sourceUri{String}
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.loadSourceFromServer = function(sourceUrl )
{
+	if ( this.getLog().isDebug() ) {
+		this.getLog().debug( ResourceDictionary.getMessage( 
+							   LOADING_SOURCE_FROM_SERVER_MSGID,
+							   xap.data.datasource.DataSourceImpl,
+							   [sourceUrl, this.getClass().getName()]));
+	}
+	/*ClientSession*/
+	var session =  getClientSession();
+	/*RequestService*/
+	var netService =  session.getRequestService();
+	/*NetServiceListener*/
+	var listener =  getSourceLoadRequestListener();
+	netService.retrieveAsynchronously( sourceUrl, listener );
+}
+	
+/**
+ * Sets the source object for this DataSource
+ * 
+ * @param sourceObject The new source object
+ * @protected
+ * @param sourceObject{Object}
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.setSource  = function( sourceObject ) {
+	this._source = sourceObject;
+}
+	
+/**
+ * Adds a postponed query to this DataSource. This method can be used to
+ * cache queries for later execution (for example if the source object is
+ * loaded asynchronously, postponed queries can be executed when the object
+ * finishes loading). Subclasses are responsible for clearing the posponed
+ * query queue after the queries are executed.
+ * 
+ * @param query
+ * @param context
+ * @param listener
+ */
+/**
+ * @protected
+ * @return {void}
+ * @param query{String}
+ * @param context{Context}
+ * @param listener{RetrievalListener  }
+ **/
+xap.data.datasource.DataSourceImpl.prototype.addPostponedQuery = function( query, context,
listener ) {
+	/*QueryRecord*/
+	var queryRecord =  new QueryRecord( query, context, listener );
+	this._postponedQueries.addElement( queryRecord );
+}
+	
+/**
+ * Executes all posponed queries in order they came in.
+ * At the end of this method the postponed query vector is cleared 
+ * regardless of queries' execution result.
+ */
+/**
+ * @protected
+ * @synchronized
+ **/
+xap.data.datasource.DataSourceImpl.prototype.executePostponedQueries = function() {
+	try {
+	for( var i=0; i < this._postponedQueries.size(); i++ ) {
+		/*QueryRecord*/
+		var rec =  this._postponedQueries.elementAt( i );
+		try {
+		handleQuery( rec.getQuery(), rec.getContext(), rec.getListener() );
+		} catch (/* DataAccessException */e ) {
+		//	getLog().exception( e );
+		//} catch ( /*MalformedQueryException */e ) {
+			this.getLog().exception( e );
+		}
+	}
+	} finally {
+	this._postponedQueries.removeAllElements();
+	}
+}
+	
+/**
+ * Clears the posponed query vector. 
+ */
+/**
+ * @protected
+ * @return {void}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.clearPostponedQueries = function() {
+	this._postponedQueries.removeAllElements();
+}
+	
+/**
+ * @return vector of postponed queries whose execution has been postponed 
+ * for some reason (i.e. the source object was not available).
+ */
+/**
+ * @protected
+ * @return {Vector}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getPostponedQueries = function() {
+	return this._postponedQueries;
+}
+	
+/**
+ * @return vector of all bound queries (bound type != ONE_TIME)
+ */
+/**
+ * @protected
+ * @return {Vector}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getBoundQueries = function() {
+	return this._boundQueries;
+}
+	
+/**
+ * Returns true if the url represents an absolute or relative HTTP URL
+ * or classpath entry.
+ * @param url
+ * @return boolean
+ */
+/**
+ * @protected
+ * @param url{String}
+ * @return {boolean}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.isHttpUrl  = function( url ) {
+	return url.startsWith( "http://" ) ||
+	url.startsWith( "https://" ) || url.startsWith("classpath://") ||
+	url.indexOf( "://" ) == -1;
+}
+	
+/**
+ * Extract the container name from the objectUrl.
+ * 
+ * @param sourceUrl
+ * @return container name
+ * @throws DataAccessException
+ */
+/**
+ * @protected
+ * @sourceUrl{String}
+ * @return {String}
+ * @throws DataAccessException  
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getContainerName  = function( sourceUrl ) {
+	/*int*/
+	var i =  sourceUrl.indexOf( "://" );
+	if ( i == -1 ) {
+//	throw new DataAccessException( 
+//					  DataAccessException.INVALID_SOURCE_URL_MSGID, 
+//					  sourceUrl );
+		throw new xap.util.Exception(
+						"Can't find the container name in the source URI '"
+						+ sourceUrl
+						+"'"
+										) ;
+	}
+	/*String*/
+	var containerName =  sourceUrl.substring( 0, i );
+	return containerName;
+}
+	
+/**
+ * @return the static Log instance
+ */
+/**
+ * @protected
+ * @return {Log}
+ **/
+xap.data.datasource.DataSourceImpl.prototype.getLog = function() {
+	return LogFactory.getLog( "DataSource" );
+}
+	
+//-----------------------------------------------------------------------
+// Private Methods.
+//-----------------------------------------------------------------------
+	
+/**
+ * This method persists queries whose binding type != ONE_TIME). 
+ * It then delegates the call to a subclass whose responsibility is to 
+ * process the query in a way it sees fit (i.e. the query could be 
+ * executed synchronously or asynchronously).
+ * 
+ * @param context The context for executing the query
+ * @param query The query to execute
+ * @param listener The listener to notify after the query finishes
+ * 
+ * @throws DataAccessException
+ * @throws MalformedQueryException
+ * @throws UnsupportedBindingTypeException
+ */
+/**
+ * @private
+ * @return {void}
+ * @param query{String}
+ * @param context{Context}
+ * @param listener{RetrievalListener  }
+ * @throws DataAccessException, MalformedQueryException,UnsupportedBindingTypeException
+ **/
+xap.data.datasource.DataSourceImpl.prototype.handleGenericQuery  = function( query, context,
listener ) {
+	if( ! isSupported( listener.getBindingType() )) {
+	throw new UnsupportedBindingTypeException( listener.getBindingType(),
+						   getClass());
+	}
+	// take care of caching queries for later executions when the data
+	// changes
+	if ( listener != null && 
+	 listener.getBindingType() != BindingType.ONE_TIME ) {
+		 /*QueryRecord*/
+		 var queryRecord =  new QueryRecord( query, context, listener );
+		 this._boundQueries.addElement( queryRecord );
+	 }
+	handleQuery( query, context, listener );
+}
+	
+/**
+ * A helper method for calling appropriate handleX methods
+ * 
+ * @param query
+ * @param queryContext
+ * @param listener
+ * @throws DataAccessException
+ * @throws MalformedQueryException
+ */
+/**
+ * @private
+ * @return {void}
+ * @throws DataAccessException, MalformedQueryException  
+ * @param query{String}
+ * @param queryContext{Context}
+ * @param listener{RetrievalListener  }
+ **/
+xap.data.datasource.DataSourceImpl.prototype.handleQuery = function( query, queryContext,
listener ) {
+	if ( listener instanceof DataRetrievalListener ) {
+	this.handleDataQuery( query, queryContext, 
+				  /*(DataRetrievalListener)*/ listener );
+	} else if ( listener instanceof DataSetRetrievalListener ) {
+	this.handleDataSetQuery( query, queryContext, 
+				 /*(DataSetRetrievalListener)*/ listener );
+	}
+}
+	
+/**
+ * Requeries all bound queries (binding type != BindingType.ONE_TIME)
+ * @throws DataAccessException
+ * @throws MalformedQueryException
+ * @private
+ * @return {void}
+ * @throws DataAccessException, MalformedQueryException  
+ **/
+xap.data.datasource.DataSourceImpl.prototype.requeryAll  = function() {
+	for( var i=0; i < this._boundQueries.size(); i++ ) {
+	/*QueryRecord*/
+		var rec =  this._boundQueries.elementAt( i );
+		this.handleQuery( rec.getQuery(), rec.getContext(), rec.getListener() );	
+	}
+}
+
+
+
+

Propchange: incubator/xap/trunk/src/xap/data/datasource/DataSourceImpl.js
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message