summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-12-08 15:40:35 +0000
committerburaq <buraq@epfl.ch>2003-12-08 15:40:35 +0000
commit35e4fb5175521346ce272d9d850696f13c6c2ef6 (patch)
tree4c6b46c17ffb91d7e0d81feda9f44c70d0cf4d63
parent2d473fd67a7999d823ad5be9de3d5c5c59d0e40f (diff)
downloadscala-35e4fb5175521346ce272d9d850696f13c6c2ef6.tar.gz
scala-35e4fb5175521346ce272d9d850696f13c6c2ef6.tar.bz2
scala-35e4fb5175521346ce272d9d850696f13c6c2ef6.zip
class symbol instead of element
-rw-r--r--sources/scala/xml/nobinding/NoBindingFactoryAdapter.scala23
-rw-r--r--sources/scala/xml/nobinding/XML.scala8
2 files changed, 18 insertions, 13 deletions
diff --git a/sources/scala/xml/nobinding/NoBindingFactoryAdapter.scala b/sources/scala/xml/nobinding/NoBindingFactoryAdapter.scala
index 54c9ea5dcc..e0c64a5d97 100644
--- a/sources/scala/xml/nobinding/NoBindingFactoryAdapter.scala
+++ b/sources/scala/xml/nobinding/NoBindingFactoryAdapter.scala
@@ -2,7 +2,7 @@ package scala.xml.nobinding;
import java.net.URL;
import scala.collection.mutable.HashMap ;
-import scala.xml.{Node,Text,FactoryAdapter} ;
+import scala.xml.{Node,Text,FactoryAdapter,Utility} ;
/** nobinding adaptor providing callbacks to parser to create elements.
* implements hash-consing
@@ -12,9 +12,9 @@ class NoBindingFactoryAdapter extends FactoryAdapter {
def nodeContainsText( label:java.lang.String ):boolean = true;
/* default behaviour is hash-consing */
- val cache = new HashMap[int,Element]();
+ val cache = new HashMap[int,Symbol]();
- def createNode( label: String, attrs: HashMap[String,String], children: List[Node] ):Element = {
+ def createNode( label: String, attrs: HashMap[String,String], children: List[Node] ):Symbol = {
val elHashCode = Utility.hashCode( label, attrs, children ) ;
@@ -22,10 +22,17 @@ class NoBindingFactoryAdapter extends FactoryAdapter {
case Some(cachedElem) =>
//System.err.println("[using cached elem +"+cachedElem.toXML+"!]");
cachedElem
- case None =>
- val el = new Element( label, children ) {
+ case None => val el = if( children.isEmpty ) {
+ new Symbol( label ) {
override def attributes = attrs;
+ override def hashCode() = Utility.hashCode( label, attrs.toList.hashCode(), children );
};
+ } else {
+ new Symbol( label, children:_* ) {
+ override def attributes = attrs;
+ override def hashCode() = Utility.hashCode( label, attrs.toList.hashCode(), children );
+ };
+ }
cache.update( elHashCode, el );
el
}
@@ -33,8 +40,8 @@ class NoBindingFactoryAdapter extends FactoryAdapter {
def createText( text:String ) = Text( text );
- override def loadXML( url:URL ):Element = loadXML( url.getFile() );
+ override def loadXML( url:URL ):Symbol = loadXML( url.getFile() );
- override def loadXML( filename:String ):Element =
- super.loadXML( filename ).asInstanceOf[ Element ]
+ override def loadXML( filename:String ):Symbol =
+ super.loadXML( filename ).asInstanceOf[ Symbol ]
}
diff --git a/sources/scala/xml/nobinding/XML.scala b/sources/scala/xml/nobinding/XML.scala
index a0334b45d5..3735d5e9cc 100644
--- a/sources/scala/xml/nobinding/XML.scala
+++ b/sources/scala/xml/nobinding/XML.scala
@@ -10,20 +10,18 @@ import scala.xml.Utility ;
**/
object XML {
- def < (def s:Symbol) = s;
-
// functions for generic xml loading, saving
/** loads XML from a given file*/
- def load( filename:String ):Element =
+ def load( filename:String ):Symbol =
new NoBindingFactoryAdapter().loadXML( filename );
/** loads XML from a (file) URL */
- def load( url:URL ):Element =
+ def load( url:URL ):Symbol =
new NoBindingFactoryAdapter().loadXML( url );
/** saves XML to filename with encoding ISO-8859-1 */
- def save( filename:String, doc:Element ):Unit = {
+ def save( filename:String, doc:Symbol ):Unit = {
/* using NIO classes of JDK 1.4 */
import java.io.{FileOutputStream,Writer};
import java.nio.channels.{Channels,FileChannel};