From b1be740f87533dd7381268018072cc71174935ae Mon Sep 17 00:00:00 2001 From: michelou Date: Thu, 22 Jun 2006 13:55:30 +0000 Subject: removed leading/trailing tabs/blanks in library... removed leading/trailing tabs/blanks in library files --- src/library/scala/concurrent/Actor.scala | 29 +- src/library/scala/concurrent/Pid.scala | 37 +- src/library/scala/xml/parsing/FactoryAdapter.scala | 485 ++++++++++----------- 3 files changed, 273 insertions(+), 278 deletions(-) diff --git a/src/library/scala/concurrent/Actor.scala b/src/library/scala/concurrent/Actor.scala index f810a65ac8..22278df39e 100644 --- a/src/library/scala/concurrent/Actor.scala +++ b/src/library/scala/concurrent/Actor.scala @@ -9,31 +9,36 @@ // $Id$ -package scala.concurrent; - - +package scala.concurrent + +/** + * The class Actor ... + * + * @author Martin Odersky + * @version 1.0 + */ abstract class Actor extends Thread { - private val in = new MailBox; + private val in = new MailBox def send(msg: in.Message) = - in.send(msg); + in.send(msg) def receive[a](f: PartialFunction[in.Message, a]): a = - if (Thread.currentThread() == this) in.receive(f); - else error("receive called not on own process"); + if (Thread.currentThread() == this) in.receive(f) + else error("receive called not on own process") def receiveWithin[a](msec: long)(f: PartialFunction[in.Message, a]): a = - if (Thread.currentThread() == this) in.receiveWithin(msec)(f); - else error("receiveWithin called not on own process"); + if (Thread.currentThread() == this) in.receiveWithin(msec)(f) + else error("receiveWithin called not on own process") - private var pid: Pid = null; + private var pid: Pid = null def self = { - if (pid == null) pid = new Pid(this); + if (pid == null) pid = new Pid(this) pid } - def self_= (p: Pid) = pid = p; + def self_= (p: Pid) = pid = p } diff --git a/src/library/scala/concurrent/Pid.scala b/src/library/scala/concurrent/Pid.scala index 1f3bb033e1..6fa1f24123 100644 --- a/src/library/scala/concurrent/Pid.scala +++ b/src/library/scala/concurrent/Pid.scala @@ -9,35 +9,40 @@ // $Id$ -package scala.concurrent; - - +package scala.concurrent + +/** + * The class Pid provides process identifiers + * to thread-based actors. + * + * @author Philipp Haller + * @version 1.0 + */ class Pid(actor: Actor) { - var target = actor; + private var target = actor - def !(msg: MailBox#Message) = target send msg; + def !(msg: MailBox#Message) = target send msg def spawn(body: Actor => Unit): Pid = { val a = new Actor { - override def run: Unit = body(this); - }; - a.start; + override def run: Unit = body(this) + } + a.start a.self } - def spawnReceive(cases: PartialFunction[MailBox#Message,Unit]) = { + def spawnReceive(cases: PartialFunction[MailBox#Message, Unit]) = { val a = new Actor { - override def run: Unit = receive(cases); - }; - a.start; + override def run: Unit = receive(cases) + } + a.start a.self } - override def hashCode() = target.hashCode(); + override def hashCode() = target.hashCode() override def equals(that: Any) = - if (this.hashCode() == that.hashCode()) true; - else false; + this.hashCode() == that.hashCode() - override def toString() = "Pid(" + target + ")"; + override def toString() = "Pid(" + target + ")" } diff --git a/src/library/scala/xml/parsing/FactoryAdapter.scala b/src/library/scala/xml/parsing/FactoryAdapter.scala index 5cd4692f2c..867cbc8fb6 100644 --- a/src/library/scala/xml/parsing/FactoryAdapter.scala +++ b/src/library/scala/xml/parsing/FactoryAdapter.scala @@ -9,27 +9,27 @@ // $Id$ -package scala.xml.parsing; +package scala.xml.parsing -import java.io._ ; -import scala.collection.mutable.{HashMap,Stack}; +import java.io._ +import scala.collection.mutable.{HashMap,Stack} -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; +import org.xml.sax.Attributes +import org.xml.sax.ContentHandler -import org.xml.sax.ErrorHandler; -import org.xml.sax.Locator; -import org.xml.sax.InputSource; +import org.xml.sax.ErrorHandler +import org.xml.sax.Locator +import org.xml.sax.InputSource -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; +import org.xml.sax.SAXException +import org.xml.sax.SAXNotRecognizedException +import org.xml.sax.SAXNotSupportedException +import org.xml.sax.SAXParseException +import org.xml.sax.helpers.DefaultHandler -import javax.xml.parsers.SAXParserFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory +import javax.xml.parsers.ParserConfigurationException +import javax.xml.parsers.SAXParser /** SAX adapter class, for use with Java SAX parser. Keeps track of @@ -38,21 +38,21 @@ import javax.xml.parsers.SAXParser; */ abstract class FactoryAdapter extends DefaultHandler() { - val buffer = new StringBuffer(); - val attribStack = new Stack[MetaData]; - val hStack = new Stack[Node]; // [ element ] contains siblings - val tagStack = new Stack[String]; - var scopeStack = new Stack[NamespaceBinding]; + val buffer = new StringBuffer() + val attribStack = new Stack[MetaData] + val hStack = new Stack[Node] // [ element ] contains siblings + val tagStack = new Stack[String] + var scopeStack = new Stack[NamespaceBinding] - var curTag : String = null ; - var capture: Boolean = false; + var curTag : String = null + var capture: Boolean = false // abstract methods /** Tests if an XML element contains text. * @return true if element named localName contains text. */ - def nodeContainsText(localName: String): Boolean ; // abstract + def nodeContainsText(localName: String): Boolean // abstract /** creates an new non-text(tree) node. * @param elemName @@ -60,290 +60,275 @@ abstract class FactoryAdapter extends DefaultHandler() { * @param chIter * @return a new XML element. */ - def createNode(pre: String, elemName: String, attribs: MetaData, scope: NamespaceBinding, chIter: List[Node] ):Node; //abstract + def createNode(pre: String, elemName: String, attribs: MetaData, + scope: NamespaceBinding, chIter: List[Node]): Node //abstract /** creates a Text node. * @param text * @return a new Text node. */ - def createText( text:String ):Text; // abstract + def createText(text: String): Text // abstract // // ContentHandler methods // - val normalizeWhitespace = false; + val normalizeWhitespace = false /** Characters. * @param ch * @param offset * @param length */ - override def characters(ch: Array[Char], offset: Int, length: Int): Unit = { - - if (capture) { - if( normalizeWhitespace ) { // normalizing whitespace is not compliant, but useful */ - var i: Int = offset - var ws = false - while (i < offset + length) { - if ( Character.isWhitespace( ch(i) ) ) { - if (!ws) { - buffer.append(' ') - ws = true - } - } else { - buffer.append(ch(i)) - ws = false - } - i = i+1 + override def characters(ch: Array[Char], offset: Int, length: Int): Unit = { + if (capture) { + if (normalizeWhitespace) { + // normalizing whitespace is not compliant, but useful */ + var i: Int = offset + var ws = false + while (i < offset + length) { + if (Character.isWhitespace(ch(i))) { + if (!ws) { + buffer.append(' ') + ws = true } - } else { // compliant:report every character - - buffer.append( ch, offset, length ) - + } else { + buffer.append(ch(i)) + ws = false } - } - } - - //var elemCount = 0; //STATISTICS - - /* ContentHandler methods */ - - /* Start prefix mapping - use default impl. - def startPrefixMapping( prefix:String , uri:String ):Unit = {} - */ - - - - /* Start element. */ - override def startElement(uri:String, _localName:String, qname:String, attributes:Attributes ):Unit = { - /*elemCount = elemCount + 1; STATISTICS */ - captureText(); - //Console.println("FactoryAdapter::startElement("+uri+","+_localName+","+qname+","+attributes+")"); - tagStack.push(curTag); - curTag = qname; //localName ; - - val colon = qname.indexOf(':'.asInstanceOf[Int]); - val localName = if(-1 == colon) qname else qname.substring(colon+1,qname.length()); + i = i + 1 + } + } else { // compliant:report every character + buffer.append(ch, offset, length) + } + } + } - //Console.println("FactoryAdapter::startElement - localName ="+localName); + //var elemCount = 0; //STATISTICS - capture = nodeContainsText(localName) ; + /* ContentHandler methods */ - hStack.push( null ); - var m: MetaData = Null; + /* Start prefix mapping - use default impl. + def startPrefixMapping( prefix:String , uri:String ):Unit = {} + */ - var scpe = scopeStack.top; - for( val i <- List.range( 0, attributes.getLength() )) { - //val attrType = attributes.getType(i); // unused for now - val qname = attributes.getQName(i); - val value = attributes.getValue(i); - val colon = qname.indexOf(':'.asInstanceOf[Int]); - if(-1 != colon) { // prefixed attribute - val pre = qname.substring(0, colon); - val key = qname.substring(colon+1, qname.length()); - if("xmlns" /*XML.xmlns*/ == pre) - scpe = value.length() match { - case 0 => new NamespaceBinding(key, null, scpe); - case _ => new NamespaceBinding(key, value, scpe); - } - else - m = new PrefixedAttribute(pre, key, value, m); - } else if("xmlns" /*XML.xmlns*/ == qname) + /* Start element. */ + override def startElement(uri: String, _localName: String, + qname: String, attributes: Attributes): Unit = { + /*elemCount = elemCount + 1; STATISTICS */ + captureText() + //Console.println("FactoryAdapter::startElement("+uri+","+_localName+","+qname+","+attributes+")"); + tagStack.push(curTag) + curTag = qname; //localName ; + + val colon = qname.indexOf(':'.asInstanceOf[Int]) + val localName = if(-1 == colon) qname else qname.substring(colon+1,qname.length()) + + //Console.println("FactoryAdapter::startElement - localName ="+localName); + + capture = nodeContainsText(localName) + + hStack.push(null) + var m: MetaData = Null + + var scpe = scopeStack.top + for (val i <- List.range(0, attributes.getLength())) { + //val attrType = attributes.getType(i); // unused for now + val qname = attributes.getQName(i) + val value = attributes.getValue(i) + val colon = qname.indexOf(':'.asInstanceOf[Int]) + if (-1 != colon) { // prefixed attribute + val pre = qname.substring(0, colon) + val key = qname.substring(colon+1, qname.length()) + if ("xmlns" /*XML.xmlns*/ == pre) scpe = value.length() match { - case 0 => new NamespaceBinding(null, null, scpe); - case _ => new NamespaceBinding(null, value, scpe); + case 0 => new NamespaceBinding(key, null, scpe) + case _ => new NamespaceBinding(key, value, scpe) } - else - m = new UnprefixedAttribute(qname, value, m) - } - scopeStack.push(scpe); - attribStack.push( m ); - {} - } // startElement(String,String,String,Attributes) - - - /** captures text, possibly normalizing whitespace - */ - def captureText():Unit = { - if (capture == true) { - val text = buffer.toString(); - if(( text.length() > 0 )&&( !( text.equals(" ")))) { - val _ = hStack.push( createText( text ) ); - } + else + m = new PrefixedAttribute(pre, key, value, m) + } else if ("xmlns" /*XML.xmlns*/ == qname) + scpe = value.length() match { + case 0 => new NamespaceBinding(null, null, scpe) + case _ => new NamespaceBinding(null, value, scpe) } - buffer.setLength(0); + else + m = new UnprefixedAttribute(qname, value, m) } + scopeStack.push(scpe) + attribStack.push(m) + {} + } // startElement(String,String,String,Attributes) - /** End element. - * @param uri - * @param localName - * @param qname - * @throws org.xml.sax.SAXException if .. - */ - override def endElement(uri:String , _localName:String , qname:String ):Unit = { - captureText(); - - val metaData = attribStack.pop; - - // reverse order to get it right - var v:List[Node] = Nil; - var child:Node = hStack.pop; - while( child != null ) { - v = child::v; - child = hStack.pop; - } - - val colon = qname.indexOf(':'.asInstanceOf[Int]); - val localName = if(-1 == colon) qname else qname.substring(colon+1,qname.length()); - val scp = scopeStack.pop; - // create element - rootElem = if(-1 == colon) - createNode( null, localName, metaData, scp, v ); - else - createNode( qname.substring(0,colon), localName, metaData, scp, v ); + /** captures text, possibly normalizing whitespace + */ + def captureText(): Unit = { + if (capture) { + val text = buffer.toString() + if (text.length() > 0 && !text.equals(" ")) { + hStack.push(createText(text)) + } + } + buffer.setLength(0) + } + + /** End element. + * @param uri + * @param localName + * @param qname + * @throws org.xml.sax.SAXException if .. + */ + override def endElement(uri: String , _localName: String , qname: String): Unit = { + captureText() - hStack.push(rootElem); + val metaData = attribStack.pop - // set - curTag = tagStack.pop; + // reverse order to get it right + var v: List[Node] = Nil + var child: Node = hStack.pop + while (child != null) { + v = child::v + child = hStack.pop + } - if (curTag != null) // root level - capture = nodeContainsText(curTag); - else - capture = false; + val colon = qname.indexOf(':'.asInstanceOf[Int]) + val localName = + if (-1 == colon) qname + else qname.substring(colon+1, qname.length()) - } // endElement(String,String,String) + val scp = scopeStack.pop + // create element + val pre = if (-1 == colon) null else qname.substring(0, colon) + rootElem = createNode(pre, localName, metaData, scp, v) - // - // ErrorHandler methods - // + hStack.push(rootElem) - /** Warning.*/ - override def warning(ex:SAXParseException ):Unit = { - // ignore warning, crimson warns even for entity resolution! - //printError("Warning", ex); - } - /** Error. */ - override def error(ex:SAXParseException ):Unit = { - printError("Error", ex); - } + // set + curTag = tagStack.pop - /** Fatal error.*/ - override def fatalError(ex:SAXParseException ):Unit = { - printError("Fatal Error", ex); - } + capture = + if (curTag != null) nodeContainsText(curTag) // root level + else false + } // endElement(String,String,String) - // - // Protected methods - // + // + // ErrorHandler methods + // - /** Prints the error message */ - protected def printError( errtype:String , ex:SAXParseException ):Unit = { + /** Warning.*/ + override def warning(ex: SAXParseException): Unit = { + // ignore warning, crimson warns even for entity resolution! + //printError("Warning", ex); + } - System.err.print("["); - System.err.print(errtype); - System.err.print("] "); + /** Error. */ + override def error(ex: SAXParseException): Unit = + printError("Error", ex) - var systemId = ex.getSystemId(); - if (systemId != null) { - val index = systemId.lastIndexOf('/'.asInstanceOf[Int]); - if (index != -1) - systemId = systemId.substring(index + 1); - //System.err.print(systemId); - } + /** Fatal error.*/ + override def fatalError(ex: SAXParseException): Unit = + printError("Fatal Error", ex) - System.err.print(':'); - System.err.print(ex.getLineNumber()); - System.err.print(':'); - System.err.print(ex.getColumnNumber()); - System.err.print(": "); - System.err.print(ex.getMessage()); - System.err.println(); - System.err.flush(); + // + // Protected methods + // + /** Prints the error message */ + protected def printError(errtype: String, ex: SAXParseException): Unit = { + System.err.print("[") + System.err.print(errtype) + System.err.print("] ") + + var systemId = ex.getSystemId() + if (systemId != null) { + val index = systemId.lastIndexOf('/'.asInstanceOf[Int]) + if (index != -1) + systemId = systemId.substring(index + 1) + //System.err.print(systemId) } - var rootElem : Node = null:Node; - - //FactoryAdapter - // MAIN - // - - /** load XML document - * @param source - * @return a new XML document object - */ - def loadXML( source:InputSource ):Node = { - - // variables - var parser:SAXParser = null; - - // create parser - try { - val f = SAXParserFactory.newInstance(); - f.setNamespaceAware( false ); - parser = f.newSAXParser(); - } catch { - case ( e:Exception ) => { - System.err.println("error: Unable to instantiate parser"); - System.exit(-1); - } - } + System.err.print(':') + System.err.print(ex.getLineNumber()) + System.err.print(':') + System.err.print(ex.getColumnNumber()) + System.err.print(": ") + System.err.print(ex.getMessage()) + System.err.println() + System.err.flush() + } - // parse file - //try { - //System.err.println("[parsing \"" + source + "\"]"); - scopeStack.push(TopScope); - parser.parse( source, this ); - scopeStack.pop; - /* - } catch { - case ( e:SAXParseException ) => { - // ignore - } - case ( e:Exception ) => { - System.err.println("error: Parse error occurred - " + e.getMessage()); - if (e.isInstanceOf[ SAXException ]) { - (e.asInstanceOf[ SAXException ]) - .getException() - .printStackTrace( System.err ); - } else { - e.printStackTrace(System.err); - } - } - } // catch -*/ - //System.err.println("[FactoryAdapter: total #elements = "+elemCount+"]"); - rootElem + var rootElem: Node = null:Node - } // loadXML + //FactoryAdapter + // MAIN + // + /** load XML document + * @param source + * @return a new XML document object + */ + def loadXML(source: InputSource): Node = { + // create parser + val parser: SAXParser = try { + val f = SAXParserFactory.newInstance() + f.setNamespaceAware(false) + f.newSAXParser() + } catch { + case e: Exception => + System.err.println("error: Unable to instantiate parser") + exit(1) + } + // parse file + //try { + //System.err.println("[parsing \"" + source + "\"]"); + scopeStack.push(TopScope) + parser.parse(source, this) + scopeStack.pop + /* + } catch { + case ( e:SAXParseException ) => { + // ignore + } + case ( e:Exception ) => { + System.err.println("error: Parse error occurred - " + e.getMessage()); + if (e.isInstanceOf[ SAXException ]) { + (e.asInstanceOf[ SAXException ]) + .getException() + .printStackTrace( System.err ); + } else { + e.printStackTrace(System.err); + } + } + } // catch +*/ + //System.err.println("[FactoryAdapter: total #elements = "+elemCount+"]"); + rootElem + } // loadXML /** loads XML from given file */ - def loadFile( file:File ):Node = loadXML( new InputSource( - new FileInputStream( file ) - )); + def loadFile(file: File): Node = + loadXML(new InputSource(new FileInputStream(file))) /** loads XML from given file descriptor */ - def loadFile( fileDesc:FileDescriptor ):Node = loadXML( new InputSource( - new FileInputStream( fileDesc ) - )); + def loadFile(fileDesc: FileDescriptor): Node = + loadXML(new InputSource(new FileInputStream(fileDesc))) /** loads XML from given file */ - def loadFile( fileName:String ):Node = loadXML( new InputSource( - new FileInputStream( fileName ) - )); + def loadFile(fileName: String): Node = + loadXML(new InputSource(new FileInputStream(fileName))) /** loads XML from given InputStream */ - def load( is:InputStream ):Node = loadXML( new InputSource( is )); + def load(is: InputStream): Node = + loadXML(new InputSource(is)) /** loads XML from given Reader */ - def load( reader:Reader ):Node = loadXML( new InputSource( reader )); + def load(reader: Reader): Node = + loadXML(new InputSource(reader)) /** loads XML from given sysID */ - def load( sysID:String ):Node = loadXML( new InputSource( sysID )); + def load(sysID: String): Node = + loadXML(new InputSource(sysID)) } -- cgit v1.2.3