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/06/29 17:44:53 UTC
svn commit: r418096 - in /incubator/xap/trunk/src/xap: macro/ mco/ session/
xml/ xml/xmodify/
Author: jmargaris
Date: Thu Jun 29 10:44:53 2006
New Revision: 418096
URL: http://svn.apache.org/viewvc?rev=418096&view=rev
Log:
cleanup of namespace handlers, some simplification
Modified:
incubator/xap/trunk/src/xap/macro/Macro.js
incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js
incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js
incubator/xap/trunk/src/xap/session/ClientSession.js
incubator/xap/trunk/src/xap/xml/DocumentContainer.js
incubator/xap/trunk/src/xap/xml/NamespaceHandler.js
incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js
incubator/xap/trunk/src/xap/xml/XalNamespaceHandler.js
incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js
Modified: incubator/xap/trunk/src/xap/macro/Macro.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/macro/Macro.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/macro/Macro.js (original)
+++ incubator/xap/trunk/src/xap/macro/Macro.js Thu Jun 29 10:44:53 2006
@@ -26,7 +26,7 @@
/**
* Creates a new Macro instance.
* @param {String} macroText The content of the macro
- * @param {DocumentContainer} container The DocumentContainer
+ * @param {ClientSession} session The client session.
* @constructor
* @class A macro is a segment of stored xml that can be run oncommand as if
@@ -34,9 +34,9 @@
* like java MessageFormat but these don't yet.
*
*/
-Macro = function( macroText, container ) {
+Macro = function( macroText, session ) {
this._macroText = macroText;
- this._container = container;
+ this._session = session;
}
@@ -46,5 +46,5 @@
Macro.prototype.execute = function() {
//TODO allow arguments that plug into message format style string
var parser = new SaxParser( new SaxContentHandler() );
- this._container.getSession().processDocument( parser.parse( this._macroText ) );
+ this._session.processDocument( parser.parse( this._macroText ) );
}
Modified: incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/macro/MacroNamespaceHandler.js Thu Jun 29 10:44:53 2006
@@ -28,10 +28,10 @@
* @class The MacroNamespaceHandler is responsible for reading the xml under a
* macro and saving it for later by creating a Macro object and storing it in
* the macro container.
- * <p>
- *
*/
-MacroNamespaceHandler = function(){}
+MacroNamespaceHandler = function( session ){
+ NamespaceHandler.call(this, session);
+}
MacroNamespaceHandler.prototype = new NamespaceHandler;
@@ -54,13 +54,7 @@
* @param container The DocumentContainer to be used for processing.
* @throws UpdateException
*/
-MacroNamespaceHandler.prototype.receiveDispatch = function( element, container ) {
- MacroNamespaceHandler.s_log.debug("receiveDispatch:" + element);
- if ( container == null ) {
- //TODO
- throw "No DocumentContainer supplied";
- }
-
+MacroNamespaceHandler.prototype.receiveDispatch = function( element ) {
var id = element.getAttribute("id");
if ( id == null ||
id == "" ||
@@ -75,19 +69,15 @@
//TODO we really need to clarify whether or not XAP is a generic wrapping
//tag or something with more meaning
- var macro = new Macro( "<xap>" + element.getChildAt(0).toXmlWithoutAutoAssignedIds() + "</xap>", container );
+ var macro = new Macro( "<xap>" + element.getChildAt(0).toXmlWithoutAutoAssignedIds() + "</xap>", this.getSession() );
//TODO if we are replacing and existing one should probably
//output that to info at least.
- var macroContainer = container.getSession().getMacroContainer();
+ var macroContainer = this.getSession().getMacroContainer();
if ( macroContainer.get( id ) != null ){
MacroNamespaceHandler.s_log.info( "Replacing an existing macro registered" +
" with id:" + id + ". Element:" + element.toXml() );
}
macroContainer.put( id, macro );
-}
-
-MacroNamespaceHandler.prototype.isTagHandled = function( tagName ) {
- return "macro" == tagName;
-}
+}
\ No newline at end of file
Modified: incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/mco/McoNamespaceHandler.js Thu Jun 29 10:44:53 2006
@@ -15,21 +15,22 @@
*
*/
- /**
- * Responsible for handling everything in the MCO namespace.
- * Currently that is a single mco declaration without any
- * initial properties, just a src and id
- *
+/**
+ * @fileoverview The handler for the mco namespace.
+ *
* @author jmargaris
- * TODO error checking in general
+ * @author ikaplansky
*/
+
-
-
-//-----------------------------------------------------------------------
-// Constructors.
-//-----------------------------------------------------------------------
-McoNamespaceHandler = function(){}
+/**
+ * @class The handler for the mco namespace.
+ *
+ * @constructor
+ */
+McoNamespaceHandler = function( session){
+ NamespaceHandler.call(this, session);
+}
McoNamespaceHandler.prototype = new NamespaceHandler;
@@ -60,28 +61,21 @@
* @param container The DocumentContainer to be used for processing.
* @throws UpdateException
*/
-McoNamespaceHandler.prototype.receiveDispatch = function( element, container ) {
- McoNamespaceHandler.s_log.debug( "receiveDispatch:" + element );
- if ( container == null ) {
- throw "No DocumentContainer supplied";
- }
+McoNamespaceHandler.prototype.receiveDispatch = function( element ) {
+ McoNamespaceHandler.s_log.debug( "receiveDispatch:" + element );
+
var name = element.getLocalName();
if ( name == McoNamespaceHandler.EXECUTE ) {
//this.handleExecute( element, clientSession );
} else if ( name == McoNamespaceHandler.MCO ) {
- this._handleMcoDeclaration( element, container );
+ this._handleMcoDeclaration( element );
}
}
-McoNamespaceHandler.prototype.isTagHandled = function( tagName ) {
- return McoNamespaceHandler.MCO == tagName ||
- McoNamespaceHandler.EXECUTE == tagName;
-}
-McoNamespaceHandler.prototype._handleMcoDeclaration = function( element,
- container ) {
+McoNamespaceHandler.prototype._handleMcoDeclaration = function( element ) {
+ var session = this.getSession();
var id = element.getAttribute( "id" );
- var session = container.getSession();
if ( id == null ||
id == "" ||
XapElement.isGeneratedId( id )) {
@@ -106,7 +100,7 @@
var mco = eval("new " + src + "()");
McoNamespaceHandler.s_log.debug("Created mco: " + mco);
//TODO info if replacing existing macro?
- container.getSession().getMcoContainer().put( id, mco );
+ session.getMcoContainer().put( id, mco );
} catch ( e ) {
session.handleException(
e );
Modified: incubator/xap/trunk/src/xap/session/ClientSession.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/session/ClientSession.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/session/ClientSession.js (original)
+++ incubator/xap/trunk/src/xap/session/ClientSession.js Thu Jun 29 10:44:53 2006
@@ -50,7 +50,7 @@
this._pluginRegistry = new PluginRegistryImpl( this );
- this._namespaceHandlerManager = new NamespaceHandlerManager();
+ this._namespaceHandlerManager = new NamespaceHandlerManager( this );
//set up a plugin document handler for the UI document
@@ -178,8 +178,7 @@
var ns = child.getNamespaceUri();
if( ns != null &&
namespaceHandlerManager.isNamespaceRegistered( ns )) {
- namespaceHandlerManager.dispatch( child,
- this.getDocumentContainer());
+ namespaceHandlerManager.dispatch( child );
}
}
}
Modified: incubator/xap/trunk/src/xap/xml/DocumentContainer.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/DocumentContainer.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/DocumentContainer.js (original)
+++ incubator/xap/trunk/src/xap/xml/DocumentContainer.js Thu Jun 29 10:44:53 2006
@@ -1,5 +1,41 @@
-
-
+/*
+ * 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.
+ *
+ */
+
+/**
+ * @fileoverview A Container that holds xml documents.
+ *
+ * @author jmargaris
+ */
+
+
+/**
+ *
+ * Creates a new DocumentContainer.
+ *
+ * @class DocumentContainer is a version of Container that holds
+ * xml documents. It extends the normal Container by adding
+ * the <code>getUiDocument</code> method that returns the starting
+ * UI document that exists at startup for all applications.
+ *
+ * @see Container
+ * @constructor
+ *
+ * @param {ClientSession} session The current session
+ */
DocumentContainer = function( session ){
Container.call(this, session);
@@ -18,6 +54,7 @@
}
}
+DocumentContainer.prototype = new Container;
/**
* A constant name for the UI document.
@@ -25,16 +62,11 @@
DocumentContainer.UI_DOCUMENT_NAME = "xal";
-/**
- * @private
- */
+/** @private */
DocumentContainer.RESERVED_DOCUMENT_NAMES = new Array(
DocumentContainer.UI_DOCUMENT_NAME );
-DocumentContainer.prototype = new Container;
-
-
/**
* Returns the UI document, this is a simple wrapper
* around get() with the UI_DOCUMENT_NAME.
Modified: incubator/xap/trunk/src/xap/xml/NamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/NamespaceHandler.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/NamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/xml/NamespaceHandler.js Thu Jun 29 10:44:53 2006
@@ -14,45 +14,53 @@
* limitations under the License.
*
*/
-
- /**
- * This is a "base class" for NamespaceHandler implementations and should not
- * be instantiated directly. To implement a specific handler for some namespace,
- * developers should extend this class and implement the two methods contained
- * in it.
- * @constructor
+
+/**
+ * @fileoverview The base class for all NamespaceHandlers that handle
+ * top-level XML blocks based on namespace URI.
*
- * @fileoverview NamespaceHandler extensions handle specific Element namespaces.
- * This class serves as a "base class" of what NamespaceHandler object should
- * contain.
+ * @author ikaplansky
+ * @author jmargaris
*
- * @class NamespaceHandler extensions handle specific Element namespaces.
- * This class serves as a "base class" of what NamespaceHandler object should
- * contain.
- * <p>
- * During parsing, the SaxContentHandler passes a parsed element to a
- * NamespaceHandler instance configured to handle the namespace
- * (@see NamespaceHandlerManager). At this point the Element
- * is permanently removed from the Document being parsed.
+ */
+
+/**
+ * This is a "base class" for NamespaceHandler implementations and should not
+ * be instantiated directly.
*
- * <p>
+ * @class The base class for all NamespaceHandlers that handle
+ * top-level XML blocks based on namespace URI. Subclasses of NamespaceHandler
+ * should override <code>receiveDispatch</code> to handle the XML
+ * they are interested in appropriately.
+ * <br><br>
+ * NamespaceHandlers are registered with the NamespaceHandlerManager,
+ * and are called during RequestService.retrieveAndProcess() and other
+ * "process" calls.
+ * <br><br>
* An example of a NamespaceHandler implementation is XmodifyNamespaceHandler.
- * <p>
- * @author ikaplansky
+ *
+ * @param {ClientSession} session The current session.
+ * @constructor
*/
-NamespaceHandler = function() {}
+NamespaceHandler = function( session ) {
+ this._session = session;
+}
-//-----------------------------------------------------------------------
-// Public Methods.
-//-----------------------------------------------------------------------
-NamespaceHandler.prototype.receiveDispatch = function( element, container ) {}
+/**
+ * @return {ClientSession} Returns the current session this NamespaceHandler
+ * belongs to.
+ */
+NamespaceHandler.prototype.getSession = function(){
+ return this._session;
+}
/**
- * This method should be implemented by NamespaceHandlers to return true
- * only for tag names that they know how to handle.
- *
- * @param tagName The tag name.
+ * Called during document processing when a namespace matching the uri
+ * this handler was registered for is encountered one level below the root tag
+ * of the document. Subclasses should override this method to handle
+ * their XML appropriately, for example the XModifyNamespaceHandler
+ * overrides this method to implement xmodify commands.
+ *
+ * @param {XapElement} element The element the matching uri was found on.
*/
-NamespaceHandler.prototype.isTagHandled = function( tagName ){
- return false;
-}
\ No newline at end of file
+NamespaceHandler.prototype.receiveDispatch = function( element ) {}
Modified: incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js (original)
+++ incubator/xap/trunk/src/xap/xml/NamespaceHandlerManager.js Thu Jun 29 10:44:53 2006
@@ -34,9 +34,13 @@
* for that namespace. Currently the mapping of namespace URI to namespace
* handler is hard-coded. We should probably allow users to add their own
* mappings to support new namespaces like data.
+ *
+ * @constructor
+ * @param {ClientSession} session The client session.
*
*/
-NamespaceHandlerManager = function() {
+NamespaceHandlerManager = function( session ) {
+ this._session = session;
this._namespaceToHandlersMap = new Hashtable();
this._loadConfig();
}
@@ -44,9 +48,25 @@
//-----------------------------------------------------------------------
// Constants.
//-----------------------------------------------------------------------
+
+/**
+ * Constant for "http://www.openxal.org/xmodify"
+ */
NamespaceHandlerManager.XMODIFY_NAMESPACE = "http://www.openxal.org/xmodify";
+
+/**
+ * Constant for "http://www.openxal.org/mco"
+ */
NamespaceHandlerManager.MCO_NAMESPACE = "http://www.openxal.org/mco";
+
+/**
+ * Constant for "http://www.openxal.org/macro"
+ */
NamespaceHandlerManager.MACRO_NAMESPACE = "http://www.openxal.org/macro";
+
+/**
+ * Constant for "http://www.openxal.org/xal"
+ */
NamespaceHandlerManager.XAL_NAMESPACE = "http://www.openxal.org/xal";
/** @private */
@@ -56,7 +76,7 @@
//-----------------------------------------------------------------------
// Public Methods.
//-----------------------------------------------------------------------
-NamespaceHandlerManager.prototype.dispatch = function( element, container ) {
+NamespaceHandlerManager.prototype.dispatch = function( element ) {
if( ! this.isNamespaceRegistered( element.getNamespaceUri() )) {
// TODO - internationalize
throw new IllegalArgumentException( "The namespace supplied [" +
@@ -65,12 +85,12 @@
var handler = this._namespaceToHandlersMap.get(
element.getNamespaceUri() );
try {
- handler.receiveDispatch( element, container );
+ handler.receiveDispatch( element );
} catch ( e ) {
NamespaceHandlerManager.s_log.debug( "NamespaceHandler.dispatch:" + e );
throw new ParserException(
ParserException.NAMESPACE_HANDLER_FAILURE,
- new Array( handler, "-1", "-1" ),
+ new Array( handler + " " + element.getNamespaceUri(), "-1", "-1" ),
e );
}
}
@@ -88,16 +108,20 @@
//----------------------------------------------------------------------
// Private Methods.
//-----------------------------------------------------------------------
+
+/**
+ * @private
+ */
NamespaceHandlerManager.prototype._loadConfig = function() {
this._namespaceToHandlersMap.put(
- NamespaceHandlerManager.XMODIFY_NAMESPACE, new XmodifyNamespaceHandler() );
+ NamespaceHandlerManager.XMODIFY_NAMESPACE, new XmodifyNamespaceHandler( this._session ) );
this._namespaceToHandlersMap.put(
- NamespaceHandlerManager.MCO_NAMESPACE, new McoNamespaceHandler() );
+ NamespaceHandlerManager.MCO_NAMESPACE, new McoNamespaceHandler( this._session ) );
this._namespaceToHandlersMap.put(
- NamespaceHandlerManager.MACRO_NAMESPACE, new MacroNamespaceHandler() );
+ NamespaceHandlerManager.MACRO_NAMESPACE, new MacroNamespaceHandler( this._session ) );
this._namespaceToHandlersMap.put(
- NamespaceHandlerManager.XAL_NAMESPACE, new XalNamespaceHandler() );
+ NamespaceHandlerManager.XAL_NAMESPACE, new XalNamespaceHandler( this._session ) );
}
Modified: incubator/xap/trunk/src/xap/xml/XalNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/XalNamespaceHandler.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/XalNamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/xml/XalNamespaceHandler.js Thu Jun 29 10:44:53 2006
@@ -38,8 +38,12 @@
* This is sort of placeholder functionality, we definitely want something like
* this so you don't need xmodify on the first page.
*
+ * @constructor
+ *
*/
-XalNamespaceHandler = function(){}
+XalNamespaceHandler = function( session ){
+ NamespaceHandler.call(this, session);
+}
XalNamespaceHandler.prototype = new NamespaceHandler;
@@ -59,22 +63,13 @@
*
* @param element the element that is namespaced, including all of its
* children
- * @param container The DocumentContainer to be used for processing.
* @throws UpdateException
*/
-XalNamespaceHandler.prototype.receiveDispatch = function( element, container ) {
+XalNamespaceHandler.prototype.receiveDispatch = function( element ) {
XalNamespaceHandler.s_log.debug("receiveDispatch:" + element);
- if ( container == null ) {
- //TODO
- throw "No DocumentContainer supplied";
- }
//get the root and just append to it
- var uiDocument = container.getUiDocument();
+ var uiDocument = this.getSession().getDocumentContainer().getUiDocument();
var rootElement = uiDocument.getRootElement();
rootElement.appendChild(element);
-}
-
-XalNamespaceHandler.prototype.isTagHandled = function( tagName ) {
- return true; //TODO return true if it is in the plugin document mapping
}
Modified: incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js?rev=418096&r1=418095&r2=418096&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js (original)
+++ incubator/xap/trunk/src/xap/xml/xmodify/XmodifyNamespaceHandler.js Thu Jun 29 10:44:53 2006
@@ -14,17 +14,25 @@
* limitations under the License.
*
*/
-
- /**
- * XmodifyNamespaceHandler receives elements in the
+
+/**
+ * @fileoverview XmodifyNamespaceHandler receives elements in the
* NamespaceHandlerManager.XMODIFY_NAMESPACE namespace and uses XModify
* to execute them.
- *
+ *
* @author ikaplansky
*/
+
-XmodifyNamespaceHandler = function(){
- NamespaceHandler.call(this);
+/**
+ * @class XmodifyNamespaceHandler receives elements in the
+ * NamespaceHandlerManager.XMODIFY_NAMESPACE namespace and uses XModify
+ * to execute them.
+ *
+ * @constructor
+ */
+XmodifyNamespaceHandler = function( session ){
+ NamespaceHandler.call(this, session);
}
XmodifyNamespaceHandler.MODIFICATIONS_TAG = "modifications";
@@ -49,15 +57,7 @@
* @param container The DocumentContainer to be used for processing.
* @throws UpdateException
*/
-XmodifyNamespaceHandler.prototype.receiveDispatch = function( element, container ) {
+XmodifyNamespaceHandler.prototype.receiveDispatch = function( element ) {
var xmodify = new Xmodify( element );
- if ( container == null ) {
- //TODO
- throw "No DocumentContainer supplied";
- }
- xmodify.execute( container );
+ xmodify.execute( this.getSession().getDocumentContainer() );
}
-
-XmodifyNamespaceHandler.prototype.isTagHandled = function( tagName ) {
- return XmodifyNamespaceHandler.MODIFICATIONS_TAG == tagName;
-}
\ No newline at end of file