diff options
author | buraq <buraq@epfl.ch> | 2004-06-14 10:54:37 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-06-14 10:54:37 +0000 |
commit | 3b26120ff86f1ca66e7b92c8ae9df085940e4d39 (patch) | |
tree | 350d6b3cf3fc64d9663bfe882f0469946c5d186a /sources | |
parent | a278f799614f22ddf3c2f035e0282120c2b8862d (diff) | |
download | scala-3b26120ff86f1ca66e7b92c8ae9df085940e4d39.tar.gz scala-3b26120ff86f1ca66e7b92c8ae9df085940e4d39.tar.bz2 scala-3b26120ff86f1ca66e7b92c8ae9df085940e4d39.zip |
support for namespaces
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/xml/Namespace.scala | 12 | ||||
-rw-r--r-- | sources/scala/xml/NamespaceRegistry.scala | 46 |
2 files changed, 58 insertions, 0 deletions
diff --git a/sources/scala/xml/Namespace.scala b/sources/scala/xml/Namespace.scala new file mode 100644 index 0000000000..51b8337488 --- /dev/null +++ b/sources/scala/xml/Namespace.scala @@ -0,0 +1,12 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ +package scala.xml ; + +/** an XML namespace URI */ +case class Namespace( uri:String ) ; diff --git a/sources/scala/xml/NamespaceRegistry.scala b/sources/scala/xml/NamespaceRegistry.scala new file mode 100644 index 0000000000..4eb9b0ba85 --- /dev/null +++ b/sources/scala/xml/NamespaceRegistry.scala @@ -0,0 +1,46 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2004, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +** $Id$ +\* */ +package scala.xml ; + +import scala.collection.mutable.HashMap; +import scala.collection.immutable.TreeMap; + +/** thread-safe storage of namespace URIs. */ +object NamespaceRegistry { + + final var next = 0; + /* hashmap from namespaces to ints */ + final var nmap: HashMap[String, Int] = new HashMap(); + final var dmap: TreeMap[Int,String] = new TreeMap(); + + private def newCode( uri:String ):Int = { + val d = next; + next = next + 1; + nmap( uri ) = d; + dmap( d ) = uri; + d + } + + /* returns a code for the argument namespace. Registers it if needed */ + //def getCode(ns: Namespace):Int = getCode( ns.uri ); + + /* returns a code for the argument namespace uri. Registers it if needed */ + def getCode(uri: String):Int = synchronized { + val c = nmap.get( uri ); + if( c.isEmpty ) newCode( uri ) else c.get + } + + def getNamespace( i:Int ):Namespace = synchronized { + Namespace( dmap( i ) ); + } + + /* empty namespace has code 0 */ + getCode(""); + +} |