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 2007/01/09 00:03:21 UTC
svn commit: r494267 - in /incubator/xap/trunk:
src/xap/data/bridge/DataSourceBridge.js src/xap/util/UidProvider.js
src/xap/xml/dom/Document.js src/xap/xml/dom/XapElement.js
testsrc/xap/xml/_TestDocument.js
Author: jmargaris
Date: Mon Jan 8 16:03:19 2007
New Revision: 494267
URL: http://svn.apache.org/viewvc?view=rev&rev=494267
Log:
cleaned up UidProvider, was possible to get non-unique
ID's if you mix static and non-static methods
Modified:
incubator/xap/trunk/src/xap/data/bridge/DataSourceBridge.js
incubator/xap/trunk/src/xap/util/UidProvider.js
incubator/xap/trunk/src/xap/xml/dom/Document.js
incubator/xap/trunk/src/xap/xml/dom/XapElement.js
incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js
Modified: incubator/xap/trunk/src/xap/data/bridge/DataSourceBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/bridge/DataSourceBridge.js?view=diff&rev=494267&r1=494266&r2=494267
==============================================================================
--- incubator/xap/trunk/src/xap/data/bridge/DataSourceBridge.js (original)
+++ incubator/xap/trunk/src/xap/data/bridge/DataSourceBridge.js Mon Jan 8 16:03:19 2007
@@ -21,7 +21,6 @@
Xap.require("xap.session.ClientEvent");
Xap.require("xap.taghandling.AttributeConversionException");
Xap.require("xap.util.LogFactory");
-Xap.require("xap.util.UidProvider");
Xap.require("xap.data.bridge.XmlDataTokens") ;
Xap.require("xap.xml.dom.XapElement");
Xap.require("xap.util.Exception");
Modified: incubator/xap/trunk/src/xap/util/UidProvider.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/UidProvider.js?view=diff&rev=494267&r1=494266&r2=494267
==============================================================================
--- incubator/xap/trunk/src/xap/util/UidProvider.js (original)
+++ incubator/xap/trunk/src/xap/util/UidProvider.js Mon Jan 8 16:03:19 2007
@@ -24,30 +24,6 @@
* @author ikaplansky
*/
-
-/**
- * Creates a xap.util.UidProvider with the given seed.
- *
- * @class xap.util.UidProvider generates a sequences of unique ids. You can use it
- * by instantiating an instance of a xap.util.UidProvider or through the static
- * createId method.
- *
- * @param {String} seed A unique-ish string.
- */
-xap.util.UidProvider = function( seed ) {
- this._count = 0;
- if ( seed == null ) {
- this._seed = xap.util.UidProvider._createSeed();
- } else {
- this._seed = seed;
- }
-
- if ( this._seed[ this._seed.length -1 ] != '-' ) {
- this._seed = this._seed + "-";
- }
-}
-
-
/** @private */
xap.util.UidProvider.XAP_ID_PREFIX = "xap:";
@@ -55,12 +31,7 @@
xap.util.UidProvider.s_count = 0;
/** @private */
-xap.util.UidProvider._createSeed = function () {
- return new Date().getTime();
-}
-
-/** @private */
-xap.util.UidProvider.s_seed = xap.util.UidProvider._createSeed();
+xap.util.UidProvider.s_seed = new Date().getTime();
//-----------------------------------------------------------------------
// Public Class Methods.
@@ -74,21 +45,5 @@
xap.util.UidProvider.createId = function() {
return new String( xap.util.UidProvider.XAP_ID_PREFIX +
xap.util.UidProvider.s_seed + xap.util.UidProvider.s_count++ );
-}
-
-
-//-----------------------------------------------------------------------
-// Public Methods.
-//-----------------------------------------------------------------------
-
-/**
- * Returns a unique id that directly follows the last created ID.
- * Different runs of nextId() starting with the same seed should always
- * return the same IDs.
- *
- * @type String
- */
-xap.util.UidProvider.prototype.nextId = function () {
- return xap.util.UidProvider.XAP_ID_PREFIX + this._seed + this._count++;
}
Modified: incubator/xap/trunk/src/xap/xml/dom/Document.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/Document.js?view=diff&rev=494267&r1=494266&r2=494267
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/Document.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/Document.js Mon Jan 8 16:03:19 2007
@@ -21,7 +21,6 @@
Xap.require("xap.xml.dom.events.StructureChangeEvent");
Xap.require("xap.xml.dom.XapElement");
Xap.require("xap.xml.InvalidXmlException");
-Xap.require("xap.util.UidProvider");
Xap.require("google.dom");
Xap.require("xap.util.ArrayHelper");
@@ -71,7 +70,6 @@
this._idToElementMap = {};
this._prefixToNamespaceMap = {};
- this._uidProvider = new xap.util.UidProvider();
}
xap.xml.dom.Document.prototype = new google.XDocument();
@@ -116,7 +114,7 @@
//note we are passing in NO owner doc here! only is set when node actually
//becomes part of the document
- var e = new xap.xml.dom.XapElement(localName, null, null, null,this._uidProvider );
+ var e = new xap.xml.dom.XapElement(localName, null, null, null );
//if there is no namespace then create it with a blank one
//so we can serialize back out properly
@@ -270,17 +268,6 @@
//-----------------------------------------------------------------------
// Private Methods
//-----------------------------------------------------------------------
-
-/**
- * Returns the xap.util.UidProvider for this document.
- * @private
- */
-xap.xml.dom.Document.prototype._getUidProvider = function() {
- return this._uidProvider;
-}
-
-
-
/**
* @private
Modified: incubator/xap/trunk/src/xap/xml/dom/XapElement.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/XapElement.js?view=diff&rev=494267&r1=494266&r2=494267
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/XapElement.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/XapElement.js Mon Jan 8 16:03:19 2007
@@ -49,11 +49,9 @@
* @param{xap.xml.dom.Document} ownerDoc The owner xap.xml.dom.Document
* @param parentEl The parent xap.xml.dom.XapElement
* @param id The id attribute to use for the new xap.xml.dom.XapElement
- * @param{xap.util.UidProvider} uidProvider The xap.util.UidProvider instance used to generate the id for this
- * xap.xml.dom.XapElement.
*
*/
-xap.xml.dom.XapElement = function(elementName, ownerDoc, parentEl, id, uidProvider ){
+xap.xml.dom.XapElement = function(elementName, ownerDoc, parentEl, id ){
google.XNode.call(this, google.DOM_ELEMENT_NODE, elementName, null, ownerDoc)
this._namespaceUri = null;
@@ -65,11 +63,13 @@
this._attributeChangeListeners = [];
this._structureChangeListeners = [];
+
+ //TODO setting the id here is stupid
if ( id ) {
this.setAttribute( "id", id );
}
- else if ( uidProvider ) {
- this.setAttribute( "id", uidProvider.nextId() );
+ else{
+ this.setAttribute( "id",xap.xml.dom.XapElement._createUniqueElementId() );
}
}
@@ -285,11 +285,11 @@
// We never allow elements not to have IDs - if the id attribute tries
// to be removed - remove it then reset it with one of our IDs
- //TODO does this really make sense? shouldn't this be conditional on
+ //IMPORTANT does this really make sense? shouldn't this be conditional on
//the document type or something like that? Maybe when we add to a doc
//that expects IDs we should assign them then instead of here?
if ( "id" == name ) {
- setAttribute( "id", ( doc ? doc._getUidProvider().nextId() : this._createUniqueElementId()));
+ setAttribute( "id", xap.xml.dom.XapElement._createUniqueElementId());
}
return name;
@@ -1073,14 +1073,7 @@
//if the id was generated replace it with a new generated one
if ( xap.xml.dom.XapElement.isGeneratedId( id ) ) {
-
- var doc = this.ownerDocument;
- if (doc && doc._getUidProvider()){
- e.setAttribute( "id", doc._getUidProvider().nextId());
- }
- else{
- e.setAttribute( "id", xap.xml.dom.XapElement._createUniqueElementId());
- }
+ e.setAttribute( "id", xap.xml.dom.XapElement._createUniqueElementId());
}
}
Modified: incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js?view=diff&rev=494267&r1=494266&r2=494267
==============================================================================
--- incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js (original)
+++ incubator/xap/trunk/testsrc/xap/xml/_TestDocument.js Mon Jan 8 16:03:19 2007
@@ -42,7 +42,6 @@
assertTrue( "doc.createElement", doc.createElement != null );
assertTrue( "doc.getElementById", doc.getElementById != null );
assertTrue( "doc.getRootElement", doc.getRootElement != null );
- assertTrue( "doc._getUidProvider", doc._getUidProvider != null );
assertTrue( "doc._notifyListenersOfStructureChange", doc._notifyListenersOfStructureChange != null );
assertTrue( "doc.removeAttributeChangeListener", doc.removeAttributeChangeListener != null );
assertTrue( "doc._removeDocumentFragmentFromIdMap", doc._removeDocumentFragmentFromIdMap != null );