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 mt...@apache.org on 2006/09/18 19:24:20 UTC
svn commit: r447514 - in /incubator/xap/trunk: WebContent/XapConfig.xml
src/xap/data/DataNamespaceHandler.js
Author: mturyn
Date: Mon Sep 18 12:24:19 2006
New Revision: 447514
URL: http://svn.apache.org/viewvc?view=rev&rev=447514
Log:
Added DataNamespaceHandler (to handle data source namespaces) and set up its use in XapConfig.
Added:
incubator/xap/trunk/src/xap/data/DataNamespaceHandler.js (with props)
Modified:
incubator/xap/trunk/WebContent/XapConfig.xml
Modified: incubator/xap/trunk/WebContent/XapConfig.xml
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/XapConfig.xml?view=diff&rev=447514&r1=447513&r2=447514
==============================================================================
--- incubator/xap/trunk/WebContent/XapConfig.xml (original)
+++ incubator/xap/trunk/WebContent/XapConfig.xml Mon Sep 18 12:24:19 2006
@@ -11,5 +11,6 @@
<plugin-class class="xap.xml.xmodify.XmodifyNamespaceHandler"/>
<plugin-class class="xap.macro.MacroNamespaceHandler"/>
<plugin-class class="xap.xml.XalNamespaceHandler"/>
+ <plugin-class class="xap.data.DataNamespaceHandler"/>
</plugins>
</xap-configuration>
Added: incubator/xap/trunk/src/xap/data/DataNamespaceHandler.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/DataNamespaceHandler.js?view=auto&rev=447514
==============================================================================
--- incubator/xap/trunk/src/xap/data/DataNamespaceHandler.js (added)
+++ incubator/xap/trunk/src/xap/data/DataNamespaceHandler.js Mon Sep 18 12:24:19 2006
@@ -0,0 +1,204 @@
+
+/*
+ * 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.DataNamespaceHandler");
+Xap.require("xap.session.ClientSession");
+Xap.require("xap.taghandling.PluginDocumentHandler");
+Xap.require("xap.xml.dom.Document");
+//Xap.require("xap.xml.DocumentLocation") ;
+//Xap.require("xap.xml.DocumentRegistry") ;
+Xap.require("xap.xml.dom.XapElement");
+//Xap.require("xap.xml.NamespaceHandler") ;
+Xap.require("xap.xml.sax.ParserException");
+Xap.require("xap.xml.sax.SaxParser");
+/**
+ * @class
+ * The namespace handler for the http://openxal.apache.org/data namespace. This handler
+ * will look at a tag in the namespace and determing which document it belongs in (if any),
+ * then add that tag to the document root. It also creates the requisite
+ * documents and makes them plug-in aware.
+ *
+ * @author JMargaris
+ *
+ */
+/**
+ * Creates the handler which in turn sets up the documents
+ * @constructor
+ * @public
+ * @param sess{ClientSession}
+ * @return {DataNamespaceHandler}
+ **/
+xap.data.DataNamespaceHandler = function (sess) {
+ this._session = sess;
+ // Substitute for a session-held document registry, at least for now:
+ this._documentRegistry = new Object();
+ for (var i = 0; i < xap.data.DataNamespaceHandler.DOCUMENT_NAMES.length; i++) {
+ var currentDocumentName = xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i];
+ try {
+ //the root tag for the doc is just the doc name
+ /*Document*/
+ var parser = new xap.xml.sax.SaxParser(new xap.xml.sax.SaxContentHandler());
+ // This is _kludgy_; replace as soon as possible with
+ // just element/document creation and setting:
+ var documentRootString = "<" + currentDocumentName + "/>";
+ var dataDocument = parser.parse(documentRootString);
+
+
+ //IMPORTANT DOC what if the doc is already there? that would be bad
+ //we need to document that they not use these names
+
+ // TODO: Get this right:
+ // s.getDocumentRegistry().registerDocument(
+ // DocumentLocation,
+ // xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i],
+ // dataDocument
+ // ) ;
+ //
+ this._documentRegistry[currentDocumentName] = dataDocument;
+
+ //for each document, create namespace
+ //handler for that document
+ /*PluginDocumentHandler*/
+ var p = new xap.taghandling.PluginDocumentHandler(sess, dataDocument, xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i]);
+ // In an older version, the above wasn't done on creation: );
+ // p.addDocument(dataDocument, xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i]);
+ }
+ catch (ex) {
+ /*ParserException*/
+ //if we did this right this should never ever happen
+ //it can only happen if DOCUMENTS[i] was screwed up somehow
+ //ex.printStackTrace();
+ xap.data.DataNamespaceHandler.s_log.error(ex);
+ }
+ }
+};
+
+
+
+// Object superclass for lack of anything better---I don't think there's enough
+// common namespace handler behavior to abstract into a better superclass:
+Xap.setupClassAsSubclassOf("xap.data.DataNamespaceHandler", "Object");
+/*public static final String*/
+xap.data.DataNamespaceHandler.BINDING_DOCUMENT = "bindings";
+/*public static final String*/
+xap.data.DataNamespaceHandler.DATA_SOURCES_DOCUMENT = "dataSources";
+/*public static final String*/
+xap.data.DataNamespaceHandler.FORMATTERS_DOCUMENT = "formatters";
+
+//the names of the documents to create and make plug-in aware
+/*private static final String[]*/
+xap.data.DataNamespaceHandler.DOCUMENT_NAMES = [xap.data.DataNamespaceHandler.BINDING_DOCUMENT, xap.data.DataNamespaceHandler.DATA_SOURCES_DOCUMENT, xap.data.DataNamespaceHandler.FORMATTERS_DOCUMENT];
+xap.data.DataNamespaceHandler.s_log = xap.util.LogFactory.getLog("xap.data.DataNamespaceHandler");
+/**
+ * @private {ClientSession}
+ **/
+xap.data.DataNamespaceHandler.prototype._session = null;
+/**
+ * @public
+ * @param tagName{String}
+ * @return {boolean}
+ **/
+xap.data.DataNamespaceHandler.prototype.isTagHandled = function (tagName) {
+ if ("iterator" == tagName) {
+ return false;
+ }
+
+
+ //see if the tag was mapped to one of our data docs. If so return true
+ for (var i = 0; i < xap.data.DataNamespaceHandler.DOCUMENT_NAMES.length; i++) {
+ /*String*/
+ var document = xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i];
+ /*Element*/
+ var definition = this._session.getPluginRegistry().getPluginDefinition(tagName, "http://openxal.apache.org/data", document);
+ if (definition != null) {
+ return true;
+ }
+ }
+
+ //if it wasn't mapped to any return false
+ return false;
+};
+/**
+ * @public
+ * @param ns{String} namespace designator
+ * @param tagName{String} tag name without namspace string
+ * @param registry{DocumentRegistry}
+ * @return {void}
+ * @throws xap.util.Exception
+ **/
+xap.data.DataNamespaceHandler.prototype.handleUnknownTagInNamespace = function (ns, tagName, registry) {
+ // Iterators shouldn't have anything printed to the log, they should
+ // be in our namespace, but they shouldn't be handled by this handler,
+ // they will be handled later by the iterator plugin. This will
+ // result in the iterator tag remaining in the document as we
+ // desire. All other tags should be handled the default way.
+ // TODO All of this
+};
+xap.data.DataNamespaceHandler.prototype.pluginLoaded = function (session) {
+ session.getNamespaceHandlerManager().addHandler("http://www.openxal.org/data", this);
+ this._session = session;
+};
+/**
+ * @public
+ * @return {void}
+ * @param element{xap.xml.dom.XapElement}
+ * @param provider{DocumentRegistry}
+ **/
+xap.data.DataNamespaceHandler.prototype.receiveDispatch = function (element) {
+ /*DocumentHandler*/
+// var d = provider; //[Was the second argument.]
+ /*ClientSession*/
+ var clientSession = this._session; //d.getClientSession();
+
+ //when we get a tag like "sqlDataSource" figure out which document
+ //it belonged to it needs to end up in. Technically you could have
+ //sqlDataSource apply to multiple documents with the same name
+ //and then we would be out of luck
+ // TODO: care about that later; for now
+ for (var i = 0; i < xap.data.DataNamespaceHandler.DOCUMENT_NAMES.length; i++) {
+ // "bindings", "formatters", "dataSources"
+ /*String*/
+ var currentDocumentName = xap.data.DataNamespaceHandler.DOCUMENT_NAMES[i];
+ /*Element*/
+ var definition
+ = clientSession.getPluginRegistry().getPluginDefinition(element.getLocalName(), element.getNamespaceUri(), currentDocumentName);
+
+ //we found a definition matching the tag name, namespace
+ //and data doc name, so we are good to go
+ if (definition != null) {
+ // In the absence of a separate document registry:
+ /*Document*/
+ var destinationDocument = this._documentRegistry[currentDocumentName];
+ if (destinationDocument != null) {
+ destinationDocument.getRootElement().appendChild(element);
+
+ //immediately remove the element again, we added it so it would
+ //trigger the plugin operations, but we don't want to keep it
+ //around
+ destinationDocument.getRootElement().removeChild(element);
+ }
+ return;
+ }
+ } // end iteration over document names (["dataSources", "bindings", "formatters"] to date)
+
+
+ //if we got here it means we didn't find any proper definition which is
+ //an error
+ //TODO: fix exception handling
+ clientSession.handleException(xap.data.DataServiceImpl.DATA_FRAMEWORK_EXCEPTION_TYPE, new xap.util.Exception("UNHANDLED_TAG_IN_NAMESPACE" + ": " + element.getNamespaceUri() + ", " + element.getLocalName()));
+};
+
Propchange: incubator/xap/trunk/src/xap/data/DataNamespaceHandler.js
------------------------------------------------------------------------------
svn:eol-style = native