You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/09/09 13:20:01 UTC
[01/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Updated Branches:
refs/heads/develop 0ce9cf993 -> 906a7f4fc
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java
deleted file mode 100644
index 4c0770d..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamWriter.java
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-import java.lang.CharSequence;
-
-/**
- * <p> This interface is similar to
- * <code>javax.xml.stream.XMLStreamWriter</code>; but it does not forces
- * dynamic allocation when formatting (any {@link CharSequence CharSequence}
- * can be used instead of {@link String}).</p>
- *
- * <p> Except for the speed (faster) and the added flexibility, the
- * usage/behavior is about the same as its StAX counterpart.</p>
- *
- * <p> This writer does not require creating new <code>String</code> objects
- * during XML formatting. Attributes values can be held by a single/reusable
- * {@link javolution.text.TextBuilder TextBuilder}
- * (or <code>StringBuilder</code>) instance to avoid adverse effects
- * on memory footprint (heap), garbage collection and performance.
- * [code]
- * // Creates a new writer (potentially recycled).
- * XMLOutputFactory factory = OSGiServices.getXMLOutputFactory();
- * XMLStreamWriter writer = factory.createXMLStreamWriter(outputStream);
- *
- * TextBuilder tmp = new TextBuilder(); // To avoid creating new String instances.
- * writer.writeStartDocument();
- * writer.writeStartElement("Time");
- * writer.writeAttribute("hour", tmp.clear().append(time.hour);
- * writer.writeAttribute("minute", tmp.clear().append(time.minute);
- * writer.writeAttribute("second", tmp.clear().append(time.second);
- * writer.writeEndElement();
- * writer.writeStartDocument();
- *
- * writer.close(); // Closes the writer (does not close underlying output stream).
- * [/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-public interface XMLStreamWriter {
-
- /**
- * Writes a start tag to the output. All writeStartElement methods open a
- * new scope in the internal namespace context. Writing the corresponding
- * EndElement causes the scope to be closed.
- *
- * @param localName local name of the tag.
- * @throws XMLStreamException
- */
- void writeStartElement(CharSequence localName)
- throws XMLStreamException;
-
- /**
- * Writes a start tag to the output.
- *
- * @param namespaceURI the namespaceURI of the prefix to use.
- * @param localName local name of the tag.
- * @throws XMLStreamException if the namespace URI has not been bound
- * to a prefix and this writer does not {@link
- * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}.
- */
- void writeStartElement(CharSequence namespaceURI,
- CharSequence localName) throws XMLStreamException;
-
- /**
- * Writes a start tag to the output.
- *
- * @param localName local name of the tag.
- * @param prefix the prefix of the tag.
- * @param namespaceURI the uri to bind the prefix to.
- * @throws XMLStreamException if the namespace URI has not been bound
- * to a prefix and this writer does not {@link
- * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}.
- */
- void writeStartElement(CharSequence prefix, CharSequence localName,
- CharSequence namespaceURI) throws XMLStreamException;
-
- /**
- * Writes an empty element tag to the output.
- *
- * @param namespaceURI the uri to bind the tag to.
- * @param localName local name of the tag.
- * @throws XMLStreamException if the namespace URI has not been bound
- * to a prefix and this writer does not {@link
- * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}.
- */
- void writeEmptyElement(CharSequence namespaceURI,
- CharSequence localName) throws XMLStreamException;
-
- /**
- * Writes an empty element tag to the output.
- *
- * @param prefix the prefix of the tag.
- * @param localName local name of the tag.
- * @param namespaceURI the uri to bind the tag to.
- * @throws XMLStreamException if the namespace URI has not been bound
- * to a prefix and this writer does not {@link
- * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}.
- */
- void writeEmptyElement(CharSequence prefix, CharSequence localName,
- CharSequence namespaceURI) throws XMLStreamException;
-
- /**
- * Writes an empty element tag to the output.
- *
- * @param localName local name of the tag.
- * @throws XMLStreamException
- */
- void writeEmptyElement(CharSequence localName)
- throws XMLStreamException;
-
- /**
- * Writes an end tag to the output relying on the internal state of the
- * writer to determine the prefix and local name of the event.
- *
- * @throws XMLStreamException
- */
- void writeEndElement() throws XMLStreamException;
-
- /**
- * Closes any start tags and writes corresponding end tags.
- *
- * @throws XMLStreamException
- */
- void writeEndDocument() throws XMLStreamException;
-
- /**
- * Close this writer and free any resources associated with the writer. This
- * must not close the underlying output stream.
- *
- * @throws XMLStreamException
- */
- void close() throws XMLStreamException;
-
- /**
- * Write any cached data to the underlying output mechanism.
- *
- * @throws XMLStreamException
- */
- void flush() throws XMLStreamException;
-
- /**
- * Writes an attribute to the output stream without a prefix.
- *
- * @param localName the local name of the attribute.
- * @param value the value of the attribute.
- * @throws IllegalStateException if the current state does not allow
- * attribute writing.
- * @throws XMLStreamException
- */
- void writeAttribute(CharSequence localName, CharSequence value)
- throws XMLStreamException;
-
- /**
- * Writes an attribute to the output stream.
- *
- * @param prefix the prefix for this attribute.
- * @param namespaceURI the uri of the prefix for this attribute
- * @param localName the local name of the attribute.
- * @param value the value of the attribute.
- * @throws IllegalStateException if the current state does not allow
- * attribute writing.
- * @throws XMLStreamException if the namespace URI has not been bound
- * to a prefix and this writer does not {@link
- * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}.
- */
-
- void writeAttribute(CharSequence prefix, CharSequence namespaceURI,
- CharSequence localName, CharSequence value)
- throws XMLStreamException;
-
- /**
- * Writes an attribute to the output stream.
- *
- * @param namespaceURI the uri of the prefix for this attribute.
- * @param localName the local name of the attribute.
- * @param value the value of the attribute.
- * @throws IllegalStateException if the current state does not allow
- * attribute writing.
- * @throws XMLStreamException if the namespace URI has not been bound
- * to a prefix and this writer does not {@link
- * XMLOutputFactory#IS_REPAIRING_NAMESPACES repair namespaces}.
- */
- void writeAttribute(CharSequence namespaceURI,
- CharSequence localName, CharSequence value)
- throws XMLStreamException;
-
- /**
- * Writes a namespace to the output stream. If the prefix argument to this
- * method is the empty string, "xmlns", or <code>null</code> this method
- * will delegate to writeDefaultNamespace.
- *
- * @param prefix the prefix to bind this namespace to or <code>null</code>
- * @param namespaceURI the uri to bind the prefix.
- * @throws IllegalStateException if the current state does not allow
- * namespace writing.
- * @throws XMLStreamException
- */
- void writeNamespace(CharSequence prefix, CharSequence namespaceURI)
- throws XMLStreamException;
-
- /**
- * Writes the default namespace to the stream.
- *
- * @param namespaceURI the uri to bind the default namespace to or
- * <code>null</code> (to map the prefix to <code>""</code> URI)
- * @throws IllegalStateException if the current state does not allow
- * namespace writing.
- * @throws XMLStreamException
- */
- void writeDefaultNamespace(CharSequence namespaceURI)
- throws XMLStreamException;
-
- /**
- * Writes an xml comment with the data enclosed.
- *
- * @param data the data contained in the comment or <code>null</code>
- * @throws XMLStreamException
- */
- void writeComment(CharSequence data) throws XMLStreamException;
-
- /**
- * Writes a processing instruction.
- *
- * @param target the target of the processing instruction.
- * @throws XMLStreamException
- */
- void writeProcessingInstruction(CharSequence target)
- throws XMLStreamException;
-
- /**
- * Writes a processing instruction
- *
- * @param target the target of the processing instruction.
- * @param data the data contained in the processing instruction.
- * @throws XMLStreamException
- */
- void writeProcessingInstruction(CharSequence target,
- CharSequence data) throws XMLStreamException;
-
- /**
- * Writes a CData section.
- *
- * @param data the data contained in the CData Section.
- * @throws XMLStreamException
- */
- void writeCData(CharSequence data) throws XMLStreamException;
-
- /**
- * Writes a DTD section (representing the entire doctypedecl
- * production from the XML 1.0 specification).
- *
- * @param dtd the DTD to be written.
- * @throws XMLStreamException
- */
- void writeDTD(CharSequence dtd) throws XMLStreamException;
-
- /**
- * Writes an entity reference
- *
- * @param name the name of the entity.
- * @throws XMLStreamException
- */
- void writeEntityRef(CharSequence name) throws XMLStreamException;
-
- /**
- * Writes the XML Declaration. Defaults the XML version to 1.0 and the
- * encoding (if any) to the one specified when the instance is created
- * using {@link XMLOutputFactory}.
- *
- * @throws XMLStreamException
- */
- void writeStartDocument() throws XMLStreamException;
-
- /**
- * Writes the XML Declaration. Default the encoding (if any) to the one
- * specified when the instance is created using {@link XMLOutputFactory}.
- *
- * @param version the version of the xml document or <code>null</code>.
- * @throws XMLStreamException
- */
- void writeStartDocument(CharSequence version)
- throws XMLStreamException;
-
- /**
- * Writes the XML Declaration. Note that the encoding parameter does not set
- * the actual encoding of the underlying output. That must be set when the
- * instance when the instance is created using {@link XMLOutputFactory}.
- *
- * @param encoding the encoding of the xml declaration or <code>null</code>.
- * @param version the version of the xml document or <code>null</code>.
- * @throws XMLStreamException
- */
- void writeStartDocument(CharSequence encoding, CharSequence version)
- throws XMLStreamException;
-
- /**
- * Writes text to the output.
- *
- * @param text the value to write or <code>null</code>.
- * @throws XMLStreamException
- */
- void writeCharacters(CharSequence text) throws XMLStreamException;
-
- /**
- * Writes text to the output.
- *
- * @param text the value to write
- * @param start the starting position in the array.
- * @param length the number of characters to write.
- * @throws XMLStreamException
- */
- void writeCharacters(char[] text, int start, int length)
- throws XMLStreamException;
-
- /**
- * Gets the prefix the specified uri is bound to.
- *
- * @param uri namespace URI
- * @return the prefix for the URI or <code>null</code>
- * @throws XMLStreamException
- */
- CharSequence getPrefix(CharSequence uri) throws XMLStreamException;
-
- /**
- * Sets the prefix the uri is bound to. This prefix is bound in the scope of
- * the current START_ELEMENT / END_ELEMENT pair. If this method is called
- * before a START_ELEMENT has been written the prefix is bound in the root
- * scope.
- *
- * @param prefix the prefix to bind to the uri.
- * @param uri the uri to bind to the prefix or <code>null</code>
- * @throws XMLStreamException
- */
- void setPrefix(CharSequence prefix, CharSequence uri)
- throws XMLStreamException;
-
- /**
- * Binds a URI to the default namespace. This URI is bound in the scope of
- * the current START_ELEMENT / END_ELEMENT pair. If this method is called
- * before a START_ELEMENT has been written the uri is bound in the root
- * scope.
- *
- * @param uri the uri to bind to the default namespace or <code>null</code>.
- * @throws XMLStreamException
- */
- void setDefaultNamespace(CharSequence uri) throws XMLStreamException;
-
- /**
- * Gets the value of a feature/property from the underlying implementation.
- *
- * @param name the name of the property.
- * @return the value of the property.
- * @throws IllegalArgumentException if the property is not supported.
- */
- Object getProperty(String name) throws IllegalArgumentException;
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java
deleted file mode 100644
index 7e0d279..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/package-info.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
-<p> StAX-like XML readers/writers which do not require object
- creation (such as String) and are consequently faster than standard StAX.</p>
-<p> The main difference with "javax.xml.stream.*" classes is the integration with
- OSGi to retrieve {@code XMLInputFactory/XMLOutputFactory} instances and the use
- of <code>CharSequence</code> instead of <code>String</code>. Since
- <code>String</code> is a <code>CharSequence</code> (JDK 1.4+), most
- existing StAX code requires very little modification to be used with these
- new classes.</p>
-<p> For more information about the usage of this package please read the
- documentation for the {@link javolution.xml.stream.XMLStreamReader} and
- {@link javolution.xml.stream.XMLStreamWriter} interfaces.</p>
-<p> For more information about StAX (Streaming API for XML) in general see
- <a href="http://en.wikipedia.org/wiki/StAX">Wikipedia: StAX</a></p>
- */
-package javolution.xml.stream;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java b/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java
deleted file mode 100644
index d960cdf..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/WebServiceClient.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.ws;
-
-import java.io.IOException;
-import javolution.io.AppendableWriter;
-import javolution.io.UTF8StreamWriter;
-import javolution.text.Text;
-import javolution.text.TextBuilder;
-import javolution.xml.XMLObjectReader;
-import javolution.xml.XMLObjectWriter;
-import javolution.xml.stream.XMLStreamException;
-import javolution.xml.stream.XMLStreamReader;
-import javolution.xml.stream.XMLStreamWriter;
-
-/**
- * <p> This class provides a simple web service client capable of leveraging
- * Javolution XML marshalling/unmarshalling.</p>
- *
- * <p> Sub-classes may work from WSDL files, {@link javolution.xml.XMLFormat
- * XMLFormat} or directly with the XML streams (StAX). For example:[code]
- * private static class HelloWorld extends WebServiceClient {
- * protected void writeRequest(XMLObjectWriter out) throws XMLStreamException {
- * XMLStreamWriter xml = out.getStreamWriter();
- * xml.writeDefaultNamespace("http://www.openuri.org/");
- * xml.writeEmptyElement("helloWorld"); // Operation name.
- * }
- * protected void readResponse(XMLObjectReader in) throws XMLStreamException {
- * XMLStreamReader xml = in.getStreamReader();
- * xml.require(START_ELEMENT, "http://www.openuri.org/", "string");
- * xml.next(); // Move to character content.
- * System.out.println(xml.getText());
- * }
- * }
- * WebServiceClient ws = new HelloWorld().setAddress("http://acme.com:80/HelloWorld.jws");
- * ws.invoke();
- *
- * > Hello World!
- * [/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.2, September 16, 2007
- */
-public abstract class WebServiceClient {
-
- /**
- * Holds standard SOAP envelope prefix.
- */
- public static final String ENVELOPE_PREFIX = "env";
-
- /**
- * Holds standard SOAP envelope namespace.
- */
- public static final String ENVELOPE_URI = "http://schemas.xmlsoap.org/soap/envelope/";
-
- /**
- * Holds the URL (J2SE).
- */
- Object _url;
-
- /**
- * Default constructor (address not set).
- */
- public WebServiceClient() {}
-
- /**
- * Sets the address of this web service.
- *
- * @param address the service full address.
- */
- public WebServiceClient setAddress(String address) {
- try {
- _url = new java.net.URL(address);
- } catch (java.net.MalformedURLException e) {
- throw new IllegalArgumentException("Malformed URL: " + address);
- }
- return this;
- }
-
- /**
- * Invokes the web service.
- */
- public void invoke() throws IOException, XMLStreamException {
- try {
- // Formats the request message (we cannot write directly to
- // the output stream because the http request requires the length.
- _out.setOutput(_buffer);
- _writer.setOutput(_out);
- final XMLStreamWriter xmlOut = _writer.getStreamWriter();
- xmlOut.setPrefix(csq(ENVELOPE_PREFIX), csq(ENVELOPE_URI));
- xmlOut.writeStartElement(csq(ENVELOPE_URI), csq("Envelope"));
- xmlOut.writeNamespace(csq(ENVELOPE_PREFIX), csq(ENVELOPE_URI));
- xmlOut.writeStartElement(csq(ENVELOPE_URI), csq("Header"));
- xmlOut.writeEndElement();
- xmlOut.writeStartElement(csq(ENVELOPE_URI), csq("Body"));
- writeRequest(_writer);
- _writer.close();
-
- // Sends the request.
- if (_url == null)
- throw new IOException("URL not set");
- /**/
- java.net.HttpURLConnection http = (java.net.HttpURLConnection) ((java.net.URL) _url)
- .openConnection();
- http.setRequestProperty("Content-Length",
- String.valueOf(_buffer.length()));
- http.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
- // httpConn.setRequestProperty("SOAPAction", "");
- http.setRequestMethod("POST");
- http.setDoOutput(true);
- http.setDoInput(true);
- _utf8Writer.setOutput(http.getOutputStream());
- /**/
- _utf8Writer.append(_buffer);
- _utf8Writer.close();
-
- // Reads the response.
- /**/
- _reader.setInput(http.getInputStream());
- /**/
- final XMLStreamReader xmlIn = _reader.getStreamReader();
- while (xmlIn.hasNext()) {
- if ((xmlIn.next() == XMLStreamReader.START_ELEMENT)
- && xmlIn.getLocalName().equals("Body")
- && xmlIn.getNamespaceURI().equals(ENVELOPE_URI)) {
- // Found body, position reader to next element.
- xmlIn.next();
- readResponse(_reader);
- break;
- }
- }
-
- } finally {
- _reader.close();
- _writer.reset();
- _out.reset();
- _buffer.clear();
- _utf8Writer.reset();
- _reader.reset();
- }
- }
-
- private final TextBuilder _buffer = new TextBuilder();
- private final AppendableWriter _out = new AppendableWriter();
- private final XMLObjectWriter _writer = new XMLObjectWriter();
- private final UTF8StreamWriter _utf8Writer = new UTF8StreamWriter();
- private final XMLObjectReader _reader = new XMLObjectReader();
-
- /**/
-
- /**
- * Writes the web service request (SOAP body).
- *
- * @param out the XML object writer.
- */
- protected abstract void writeRequest(XMLObjectWriter out)
- throws XMLStreamException;
-
- /**
- * Reads the web service response (SOAP body). The default implementation
- * writes the body XML events to <code>System.out</code>.
- *
- * @param in the XML object reader.
- */
- protected void readResponse(XMLObjectReader in) throws XMLStreamException {
- final XMLStreamReader xml = in.getStreamReader();
- while (xml.hasNext()) {
- switch (xml.next()) {
- case XMLStreamReader.START_DOCUMENT:
- System.out.println("Start Document");
- break;
- case XMLStreamReader.END_DOCUMENT:
- System.out.println("End Document.");
- break;
- case XMLStreamReader.START_ELEMENT:
- System.out.println("Start Element: " + xml.getLocalName()
- + "(" + xml.getNamespaceURI() + ")");
- for (int i = 0, n = xml.getAttributeCount(); i < n; i++) {
- System.out.println(" Attribute: "
- + xml.getAttributeLocalName(i) + "("
- + xml.getAttributeNamespace(i) + "), Value: "
- + xml.getAttributeValue(i));
- }
- break;
- case XMLStreamReader.END_ELEMENT:
- if (xml.getLocalName().equals("Body")
- && xml.getNamespaceURI().equals(ENVELOPE_URI))
- return; // End body.
- System.out.println("End Element: " + xml.getLocalName()
- + "(" + xml.getNamespaceURI() + ")");
- break;
- case XMLStreamReader.CHARACTERS:
- System.out.println("Characters: " + xml.getText());
- break;
- case XMLStreamReader.CDATA:
- System.out.println("CDATA: " + xml.getText());
- break;
- case XMLStreamReader.COMMENT:
- System.out.println("Comment: " + xml.getText());
- break;
- case XMLStreamReader.SPACE:
- System.out.println("Space");
- break;
- default:
- System.out.println(xml);
- }
- }
-
- }
-
- // For J2ME compatiblity.
- private static final CharSequence csq(Object string) {
- return (string instanceof CharSequence) ? (CharSequence) string : Text
- .valueOf(string);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java
deleted file mode 100644
index 0eef27c..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/ws/package-info.java
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
-<p> Classes and interfaces to create and handle web services.</p>
- */
-package javolution.xml.ws;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
index ec3febe..63a8352 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
@@ -2281,6 +2281,7 @@ public class KiWiConnection {
}
}
+
}
}
[06/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java
deleted file mode 100644
index a15c002..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLBinding.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import javolution.util.FastMap;
-import javolution.xml.stream.XMLStreamException;
-import javolution.xml.stream.XMLStreamReader;
-import javolution.xml.stream.XMLStreamWriter;
-
-/**
- * <p> This class represents the binding between Java classes and
- * their XML representation ({@link XMLFormat}).</p>
- *
- * <p> Custom XML bindings can also be used to alias class names and
- * ensure that the XML representation is:<ul>
- * <li> Impervious to obfuscation.</li>
- * <li> Unaffected by any class refactoring.</li>
- * <li> Can be mapped to multiple implementations. For example:[code]
- *
- * // Creates a binding to serialize Swing components into high-level XML
- * // and deserialize the same XML into SWT components.
- * XMLBinding swingBinding = new XMLBinding();
- * swingBinding.setAlias(javax.swing.JButton.class, "Button");
- * swingBinding.setAlias(javax.swing.JTable.class, "Table");
- * ...
- * XMLBinding swtBinding = new XMLBinding();
- * swtBinding.setAlias(org.eclipse.swt.widgets.Button.class, "Button");
- * swtBinding.setAlias(org.eclipse.swt.widgets.Table.class, "Table");
- * ...
- *
- * // Writes Swing Desktop to XML.
- * XMLObjectWriter writer = new XMLObjectWriter().setBinding(swingBinding);
- * writer.setOutput(new FileOutputStream("C:/desktop.xml"));
- * writer.write(swingDesktop, "Desktop", SwingDesktop.class);
- * writer.close();
- *
- * // Reads back high-level XML to a SWT implementation!
- * XMLObjectReader reader = new XMLObjectReader().setXMLBinding(swtBinding);
- * reader.setInput(new FileInputStream("C:/desktop.xml"));
- * SWTDesktop swtDesktop = reader.read("Desktop", SWTDesktop.class);
- * reader.close();
- * [/code]</li>
- * </ul></p>
- *
- * <p> More advanced bindings can also be created through sub-classing.[code]
- *
- * // XML binding using reflection.
- * public ReflectionBinding extends XMLBinding {
- * protected XMLFormat getFormat(Class forClass) {
- * Field[] fields = forClass.getDeclaredFields();
- * return new XMLReflectionFormat(fields);
- * }
- * }
- *
- * // XML binding read from DTD input source.
- * public DTDBinding extends XMLBinding {
- * public DTDBinding(InputStream dtd) {
- * ...
- * }
- * }
- *
- * // XML binding overriding default formats.
- * public MyBinding extends XMLBinding {
- * // Non-static formats use unmapped XMLFormat instances.
- * XMLFormat<String> myStringFormat = new XMLFormat<String>(null) {...}
- * XMLFormat<Collection> myCollectionFormat = new XMLFormat<Collection>(null) {...}
- * protected XMLFormat getFormat(Class forClass) throws XMLStreamException {
- * if (String.class.equals(forClass))
- * return myStringFormat;
- * if (Collection.class.isAssignableFrom(forClass))
- * return myCollectionFormat;
- * return super.getFormat(cls);
- * }
- * }
- * [/code]
- *
- * <p> The default XML binding implementation supports all static XML formats
- * (static members of the classes being mapped) as well as the
- * following types:<ul>
- * <li><code>java.lang.Object</code> (empty element)</li>
- * <li><code>java.lang.Class</code></li>
- * <li><code>java.lang.String</code></li>
- * <li><code>java.lang.Appendable</code></li>
- * <li><code>java.util.Collection</code></li>
- * <li><code>java.util.Map</code></li>
- * <li><code>java.lang.Object[]</code></li>
- * <li> all primitive types wrappers (e.g.
- * <code>Boolean, Integer ...</code>)</li>
- * </ul></p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.4, December 1, 2009
- */
-public class XMLBinding implements XMLSerializable {
-
- /**
- * Holds the default instance used by readers/writers (thread-safe).
- */
- static final XMLBinding DEFAULT = new XMLBinding();
-
- /**
- * Holds the class attribute.
- */
- private QName _classAttribute = QName.valueOf("class");
-
- /**
- * Holds the class to alias (QName) mapping.
- */
- private final FastMap<Class<?>, QName> _classToAlias = new FastMap<Class<?>, QName>();
-
- /**
- * Holds the alias (QName) to class mapping.
- */
- private final FastMap<QName, Class<?>> _aliasToClass = new FastMap<QName, Class<?>>();
-
- /**
- * Default constructor.
- */
- public XMLBinding() {}
-
- /**
- * Sets the qualified alias for the specified class.
- *
- * @param cls the class being aliased.
- * @param qName the qualified name.
- */
- public void setAlias(Class<?> cls, QName qName) {
- _classToAlias.put(cls, qName);
- _aliasToClass.put(qName, cls);
- }
-
- /**
- * Convenient method equivalent to {@link #setAlias(Class, QName)
- * setAlias(cls, QName.valueOf(alias))}.
- *
- * @param cls the class being aliased.
- * @param alias the alias for the specified class.
- */
- public final void setAlias(Class<?> cls, String alias) {
- setAlias(cls, QName.valueOf(alias));
- }
-
- /**
- * Sets the qualified name of the attribute holding the
- * class identifier. If the local name is <code>null</code> the class
- * attribute is never read/written (which may prevent unmarshalling).
- *
- * @param classAttribute the qualified name of the class attribute or
- * <code>null<code>.
- */
- public void setClassAttribute(QName classAttribute) {
- _classAttribute = classAttribute;
- }
-
- /**
- * Convenience method equivalent to {@link #setClassAttribute(QName)
- * setClassAttribute(QName.valueOf(name))}.
- *
- * @param name the name of the class attribute or <code>null<code>.
- */
- public final void setClassAttribute(String name) {
- setClassAttribute(name == null ? null : QName.valueOf(name));
- }
-
- /**
- * Returns the XML format for the specified class/interface.
- * The default implementation returns the {@link XMLContext#getFormat}
- * for the specified class.
- *
- * @param forClass the class for which the XML format is returned.
- * @return the XML format for the specified class (never <code>null</code>).
- */
- protected XMLFormat<?> getFormat(Class<?> forClass)
- throws XMLStreamException {
- return XMLContext.getFormat(forClass);
- }
-
- /**
- * Reads the class corresponding to the current XML element.
- *
- * This method is called by {@link XMLFormat.InputElement#getNext()}
- * {@link XMLFormat.InputElement#get(String)} and
- * {@link XMLFormat.InputElement#get(String, String)} to retrieve the
- * Java class corresponding to the current XML element.
- *
- * If <code>useAttributes</code> is set, the default implementation
- * reads the class name from the class attribute; otherwise the class
- * name (or alias) is read from the current element qualified name.
- *
- * @param reader the XML stream reader.
- * @param useAttributes indicates if the element's attributes should be
- * used to identify the class (e.g. when the element name is
- * specified by the user then attributes have to be used).
- * @return the corresponding class.
- * @throws XMLStreamException
- */
- protected Class<?> readClass(XMLStreamReader reader, boolean useAttributes)
- throws XMLStreamException {
- try {
- QName classQName;
- if (useAttributes) {
- if (_classAttribute == null)
- throw new XMLStreamException(
- "Binding has no class attribute defined, cannot retrieve class");
- classQName = QName.valueOf(reader.getAttributeValue(
- _classAttribute.getNamespaceURI(),
- _classAttribute.getLocalName()));
- if (classQName == null)
- throw new XMLStreamException(
- "Cannot retrieve class (class attribute not found)");
- } else {
- classQName = QName.valueOf(reader.getNamespaceURI(),
- reader.getLocalName());
- }
-
- // Searches aliases with namespace URI.
- Class<?> cls = _aliasToClass.get(classQName);
- if (cls != null)
- return cls;
-
- // Searches aliases without namespace URI.
- cls = _aliasToClass.get(QName.valueOf(classQName.getLocalName()));
- if (cls != null)
- return cls;
-
- // Finally convert the qualified name to a class (ignoring namespace URI).
- cls = Class.forName(classQName.getLocalName().toString());
- if (cls == null)
- throw new XMLStreamException(
- "Class "
- + classQName.getLocalName()
- + " not found (see javolution.lang.Reflection to support additional class loader)");
- _aliasToClass.put(classQName, cls);
- return cls;
- } catch (ClassNotFoundException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- /**
- * Writes the specified class to the current XML element attributes or to
- * a new element if the element attributes cannot be used.
- *
- * This method is called by
- * {@link XMLFormat.OutputElement#add(Object)} and
- * {@link XMLFormat.OutputElement#add(Object, String)} and
- * {@link XMLFormat.OutputElement#add(Object, String, String)} to
- * identify the Java class corresponding to the XML element.
- *
- *
- * @param cls the class to be written.
- * @param writer the XML stream writer.
- * @param useAttributes indicates if the element's attributes should be
- * used to identify the class (e.g. when the element name is
- * specified by the user then attributes have to be used).
- * @throws XMLStreamException
- */
- protected void writeClass(Class<?> cls, XMLStreamWriter writer,
- boolean useAttributes) throws XMLStreamException {
- QName qName = (QName) _classToAlias.get(cls);
- String name = qName != null ? qName.toString() : cls.getName();
- if (useAttributes) {
- if (_classAttribute == null)
- return;
- if (_classAttribute.getNamespaceURI() == null) {
- writer.writeAttribute(_classAttribute.getLocalName(), name);
- } else {
- writer.writeAttribute(_classAttribute.getNamespaceURI(),
- _classAttribute.getLocalName(), name);
- }
- } else {
- if (qName != null) {
- if (qName.getNamespaceURI() == null) {
- writer.writeStartElement(qName.getLocalName());
- } else {
- writer.writeStartElement(qName.getNamespaceURI(),
- qName.getLocalName());
- }
- } else {
- writer.writeStartElement(name);
- }
- }
- }
-
- public void reset() {
- _classAttribute = QName.valueOf("class");
- _aliasToClass.clear();
- _classToAlias.clear();
- }
-
- private static final long serialVersionUID = 6611041662550083919L;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java
deleted file mode 100644
index 5b29017..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLContext.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import javolution.context.AbstractContext;
-import javolution.context.FormatContext;
-import javolution.osgi.internal.OSGiServices;
-import javolution.text.TextFormat;
-
-/**
- * <p> A context for xml serialization/deserialization.
- * The default xml format for any class is given by the
- * {@link javolution.text.DefaultTextFormat Format} inheritable annotation.</p>
- *
- * <p> A default xml format exists for the following predefined types:
- * <code><ul>
- * <li>java.lang.Object (value attribute parsed/formatted using {@link TextFormat})</li>
- * <li>java.util.Collection</li>
- * <li>java.util.Map</li>
- * </ul></code></p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-public abstract class XMLContext extends FormatContext {
-
- /**
- * Default constructor.
- */
- protected XMLContext() {}
-
- /**
- * Enters and returns a new xml context instance.
- */
- public static XMLContext enter() {
- return (XMLContext) XMLContext.currentXMLContext().enterInner();
- }
-
- /**
- * Returns the xml format for the specified type; if none defined
- * the default object xml format (based on {@link TextFormat}) is returned.
- */
- public static <T> XMLFormat<T> getFormat(Class<? extends T> type) {
- return XMLContext.currentXMLContext().searchFormat(type);
- }
-
- /**
- * Sets the xml format for the specified type (and its sub-types).
- */
- public abstract <T> void setFormat(Class<? extends T> type,
- XMLFormat<T> format);
-
- /**
- * Searches the xml format for the specified type.
- */
- protected abstract <T> XMLFormat<T> searchFormat(
- Class<? extends T> type);
-
- /**
- * Returns the current xml context.
- */
- private static XMLContext currentXMLContext() {
- XMLContext ctx = AbstractContext.current(XMLContext.class);
- if (ctx != null)
- return ctx;
- return OSGiServices.getXMLContext();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLFormat.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLFormat.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLFormat.java
deleted file mode 100644
index ba201d8..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLFormat.java
+++ /dev/null
@@ -1,1029 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import javolution.text.CharArray;
-import javolution.text.TextBuilder;
-import javolution.text.TextContext;
-import javolution.text.TextFormat;
-import javolution.xml.internal.stream.XMLStreamReaderImpl;
-import javolution.xml.internal.stream.XMLStreamWriterImpl;
-import javolution.xml.sax.Attributes;
-import javolution.xml.stream.XMLStreamException;
-import javolution.xml.stream.XMLStreamReader;
-import javolution.xml.stream.XMLStreamWriter;
-
-/**
- * <p> This class represents the format base class for XML serialization and
- * deserialization.</p>
- *
- * <p> Instances of this class are typically retrieved from the
- * {@link XMLContext} (OSGi service or not).
- * [code]
- * @Format(xml=GraphicXML.class)
- * public abstract class Graphic implements XMLSerializable {
- * private boolean isVisible;
- * private Paint paint; // null if none.
- * private Stroke stroke; // null if none.
- * private Transform transform; // null if none.
- *
- * // XML format with positional associations (members identified by their position),
- * // see XML package description for examples of name associations.
- * public static class GraphicXML extends XMLFormat<Graphic> {
- * public void write(Graphic g, OutputElement xml) {
- * xml.setAttribute("isVisible", g.isVisible);
- * xml.add(g.paint); // First.
- * xml.add(g.stroke); // Second.
- * xml.add(g.transform); // Third.
- * }
- * public void read(InputElement xml, Graphic g) {
- * g.isVisible = xml.getAttribute("isVisible", true);
- * g.paint = xml.getNext();
- * g.stroke = xml.getNext();
- * g.transform = xml.getNext();
- * return g;
- * }
- * };
- * }
- * [/code]
- *
- * <p> Due to the sequential nature of XML serialization/deserialization,
- * formatting/parsing of XML attributes should always be performed before
- * formatting/parsing of the XML content.</p>
- *
- * <p> The mapping between classes and XML formats can be overriden
- * through {@link XMLBinding} instances.
- * Here is an example of serialization/deserialization:
- * [code]
- * // Creates a list holding diverse objects.
- * List list = new ArrayList();
- * list.add("John Doe");
- * list.add(null);
- * Map map = new FastMap();
- * map.put("ONE", 1);
- * map.put("TWO", 2);
- * list.add(map);
- *
- * // Use of custom binding.
- * XMLBinding binding = new XMLBinding();
- * binding.setAlias(FastMap.class, "Map");
- * binding.setAlias(String.class, "String");
- * binding.setAlias(Integer.class, "Integer");
- *
- * // Formats the list to XML .
- * OutputStream out = new FileOutputStream("C:/list.xml");
- * XMLObjectWriter writer = new XMLObjectWriter().setOutput(out).setBinding(binding);
- * writer.write(list, "MyList", ArrayList.class);
- * writer.close();
- * [/code]
- *
- * Here is the output <code>list.xml</code> document produced:[code]
- *
- * <MyList>
- * <String value="John Doe"/>
- * <Null/>
- * <Map>
- * <Key class="String" value="ONE"/>
- * <Value class="Integer" value="1"/>
- * <Key class="String" value="TWO"/>
- * <Value class="Integer" value="2"/>
- * </Map>
- * </MyList>
- * [/code]
- *
- * The list can be read back with the following code:
- * [code]
- * // Reads back to a FastTable instance.
- * InputStream in = new FileInputStream("C:/list.xml");
- * XMLObjectReader reader = new XMLObjectReader().setInput(in).setBinding(binding);
- * FastTable table = reader.read("MyList", FastTable.class);
- * reader.close();
- * [/code]
- * </p>
- *
- * <p> <i>Note:</i> Any type for which a {@link TextFormat text format} is
- * defined can be represented as a XML attribute.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.4, December 1, 2009
- */
-public abstract class XMLFormat<T> {
-
- /**
- * Holds <code>null</code> representation.
- */
- private static final String NULL = "Null";
-
- /**
- * Default constructor.
- */
- protected XMLFormat() {}
-
- /**
- * Indicates if the object serialized through this format can be referenced
- * to (default <code>true</code>). This method can be overriden to return
- * <code>false</code> if serialized objects are manipulated "by value".
- *
- * @return <code>true</code> if serialized object may hold a reference;
- * <code>false</code> otherwise.
- * @see XMLReferenceResolver
- */
- public boolean isReferenceable() {
- return true;
- }
-
- /**
- * Allocates a new object of the specified class from the specified
- * XML input element. By default, this method returns an object created
- * using the public no-arg constructor of the specified class.
- * XML formats may override this method in order to use private/multi-arg
- * constructors.
- *
- * @param cls the class of the object to return.
- * @param xml the XML input element.
- * @return the object corresponding to the specified XML element.
- */
- public T newInstance(Class<? extends T> cls, InputElement xml)
- throws XMLStreamException {
- try {
- return cls.newInstance();
- } catch (InstantiationException e) {
- throw new XMLStreamException(e);
- } catch (IllegalAccessException e) {
- throw new XMLStreamException(e);
- }
- }
-
- /**
- * Formats an object into the specified XML output element.
- *
- * @param obj the object to format.
- * @param xml the <code>XMLElement</code> destination.
- */
- public abstract void write(T obj, OutputElement xml)
- throws XMLStreamException;
-
- /**
- * Parses an XML input element into the specified object.
- *
- * @param xml the XML element to parse.
- * @param obj the object created through {@link #newInstance}
- * and to setup from the specified XML element.
- */
- public abstract void read(InputElement xml, T obj)
- throws XMLStreamException;
-
- /**
- * This class represents an input XML element (unmarshalling).
- */
- @SuppressWarnings("unchecked")
- public static final class InputElement {
-
- /**
- * Holds the stream reader.
- */
- final XMLStreamReaderImpl _reader = new XMLStreamReaderImpl();
-
- /**
- * Holds the XML binding.
- */
- private XMLBinding _binding;
-
- /**
- * Holds the reference resolver.
- */
- private XMLReferenceResolver _referenceResolver;
-
- /**
- * Indicates if the reader is currently positioned on the next element.
- */
- private boolean _isReaderAtNext;
-
- /**
- * Default constructor.
- */
- InputElement() {
- reset();
- }
-
- /**
- * Returns the StAX-like stream reader (provides complete control
- * over the unmarshalling process).
- *
- * @return the stream reader.
- */
- public XMLStreamReader getStreamReader() {
- return _reader;
- }
-
- /**
- * Indicates if more nested XML element can be read. This method
- * positions the {@link #getStreamReader reader} at the start of the
- * next XML element to be read (if any).
- *
- * @return <code>true</code> if there is more XML element to be read;
- * <code>false</code> otherwise.
- */
- public boolean hasNext() throws XMLStreamException {
- if (!_isReaderAtNext) {
- _isReaderAtNext = true;
- _reader.nextTag();
- }
- return _reader.getEventType() == XMLStreamReader.START_ELEMENT;
- }
-
- /**
- * Returns the next object whose type is identified by the local name
- * and URI of the current XML element.
- *
- * @return the next nested object which can be <code>null</code>.
- * @throws XMLStreamException if <code>hasNext() == false</code>.
- */
- public <T> T getNext() throws XMLStreamException {
- if (!hasNext()) // Asserts isReaderAtNext == true
- throw new XMLStreamException("No more element to read",
- _reader.getLocation());
-
- // Checks for null.
- if (_reader.getLocalName().equals(NULL)) {
- if (_reader.next() != XMLStreamReader.END_ELEMENT)
- throw new XMLStreamException("Non Empty Null Element");
- _isReaderAtNext = false;
- return null;
- }
-
- Object ref = readReference();
- if (ref != null)
- return (T) ref;
-
- // Retrieves object's class from element tag.
- Class<?> cls = _binding.readClass(_reader, false);
- return readInstanceOf(cls);
- }
-
- /**
- * Returns the object whose type is identified by a XML class attribute
- * only if the XML element has the specified local name.
- *
- * @param name the local name of the next element.
- * @return the next nested object or <code>null</code>.
- */
- public <T> T get(String name) throws XMLStreamException {
- if (!hasNext()// Asserts isReaderAtNext == true
- || !_reader.getLocalName().equals(name))
- return null;
-
- Object ref = readReference();
- if (ref != null)
- return (T) ref;
-
- // Retrieves object's class from class attribute.
- Class<?> cls = _binding.readClass(_reader, true);
- return readInstanceOf(cls);
- }
-
- /**
- * Returns the object whose type is identified by a XML class attribute
- * only if the XML element has the specified local name and URI.
- *
- * @param localName the local name.
- * @param uri the namespace URI or <code>null</code>.
- * @return the next nested object or <code>null</code>.
- */
- public <T> T get(String localName, String uri)
- throws XMLStreamException {
- if (uri == null)
- return (T) get(localName);
-
- if (!hasNext()// Asserts isReaderAtNext == true
- || !_reader.getLocalName().equals(localName)
- || !_reader.getNamespaceURI().equals(uri))
- return null;
-
- Object ref = readReference();
- if (ref != null)
- return (T) ref;
-
- // Retrieves object's class from class attribute.
- Class<?> cls = _binding.readClass(_reader, true);
- return readInstanceOf(cls);
- }
-
- /**
- * Returns the object of specified type only if the XML element has the
- * specified local name.
- *
- * @param name the local name of the element to match.
- * @param cls the class identifying the format of the object to return.
- * @return the next nested object or <code>null</code>.
- */
- public <T> T get(String name, Class<T> cls) throws XMLStreamException {
- if (!hasNext()// Asserts isReaderAtNext == true
- || !_reader.getLocalName().equals(name))
- return null;
-
- Object ref = readReference();
- if (ref != null)
- return (T) ref;
-
- return readInstanceOf(cls);
- }
-
- /**
- * Returns the object of specified type only if the
- * XML element has the specified local name and namespace URI.
- *
- * @param localName the local name.
- * @param uri the namespace URI or <code>null</code>.
- * @param cls the class identifying the format of the object to return.
- * @return the next nested object or <code>null</code>.
- */
- public <T> T get(String localName, String uri, Class<T> cls)
- throws XMLStreamException {
- if (uri == null)
- return get(localName, cls);
-
- if (!hasNext()// Asserts isReaderAtNext == true
- || !_reader.getLocalName().equals(localName)
- || !_reader.getNamespaceURI().equals(uri))
- return null;
-
- Object ref = readReference();
- if (ref != null)
- return (T) ref;
-
- return readInstanceOf(cls);
- }
-
- // Returns the referenced object if any.
- private Object readReference() throws XMLStreamException {
- if (_referenceResolver == null)
- return null;
- Object ref = _referenceResolver.readReference(this);
- if (ref == null)
- return null;
- if (_reader.next() != XMLStreamReader.END_ELEMENT)
- throw new XMLStreamException("Non Empty Reference Element");
- _isReaderAtNext = false;
- return ref;
- }
-
- // Builds object of specified class.
- @SuppressWarnings("rawtypes")
- private <T> T readInstanceOf(Class cls) throws XMLStreamException {
-
- // Retrieves format.
- XMLFormat xmlFormat = _binding.getFormat(cls);
-
- // Creates object.
- _isReaderAtNext = false; // Makes attributes accessible.
- Object obj = xmlFormat.newInstance(cls, this);
-
- // Adds reference (before reading to support circular reference).
- if (_referenceResolver != null) {
- _referenceResolver.createReference(obj, this);
- }
-
- // Parses xml.
- xmlFormat.read(this, obj);
- if (hasNext()) // Asserts _isReaderAtNext == true
- throw new XMLStreamException("Incomplete element reading",
- _reader.getLocation());
- _isReaderAtNext = false; // Skips end element.
- return (T) obj;
- }
-
- /**
- * Returns the content of a text-only element (equivalent to
- * {@link javolution.xml.stream.XMLStreamReader#getElementText
- * getStreamReader().getElementText()}).
- *
- * @return the element text content or an empty sequence if none.
- */
- public CharArray getText() throws XMLStreamException {
- CharArray txt = _reader.getElementText();
- _isReaderAtNext = true; // End element is next.
- return txt;
- }
-
- /**
- * Returns the attributes for this XML input element.
- *
- * @return the attributes mapping.
- */
- public Attributes getAttributes() throws XMLStreamException {
- if (_isReaderAtNext)
- throw new XMLStreamException(
- "Attributes should be read before content");
- return _reader.getAttributes();
- }
-
- /**
- * Searches for the attribute having the specified name.
- *
- * @param name the name of the attribute.
- * @return the value for the specified attribute or <code>null</code>
- * if the attribute is not found.
- */
- public CharArray getAttribute(String name) throws XMLStreamException {
- if (_isReaderAtNext)
- throw new XMLStreamException(
- "Attributes should be read before reading content");
- return _reader.getAttributeValue(null, name);
- }
-
- /**
- * Returns the specified <code>String</code> attribute.
- *
- * @param name the name of the attribute.
- * @param defaultValue a default value.
- * @return the value for the specified attribute or
- * the <code>defaultValue</code> if the attribute is not found.
- */
- public String getAttribute(String name, String defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? value.toString() : defaultValue;
- }
-
- /**
- * Returns the specified <code>boolean</code> attribute.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>boolean</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public boolean getAttribute(String name, boolean defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? value.toBoolean() : defaultValue;
- }
-
- /**
- * Returns the specified <code>char</code> attribute.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>char</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public char getAttribute(String name, char defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- if (value == null)
- return defaultValue;
- if (value.length() != 1)
- throw new XMLStreamException(
- "Single character expected (read '" + value + "')");
- return value.charAt(0);
- }
-
- /**
- * Returns the specified <code>byte</code> attribute. This method handles
- * string formats that are used to represent octal and hexadecimal numbers.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>byte</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public byte getAttribute(String name, byte defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? (byte) value.toInt() : defaultValue;
- }
-
- /**
- * Returns the specified <code>short</code> attribute. This method handles
- * string formats that are used to represent octal and hexadecimal numbers.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>short</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public short getAttribute(String name, short defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? (short) value.toInt() : defaultValue;
- }
-
- /**
- * Returns the specified <code>int</code> attribute. This method handles
- * string formats that are used to represent octal and hexadecimal numbers.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>int</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public int getAttribute(String name, int defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? value.toInt() : defaultValue;
- }
-
- /**
- * Returns the specified <code>long</code> attribute. This method handles
- * string formats that are used to represent octal and hexadecimal numbers.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>long</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public long getAttribute(String name, long defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? value.toLong() : defaultValue;
- }
-
- /**
- * Returns the specified <code>float</code> attribute.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>float</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public float getAttribute(String name, float defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? value.toFloat() : defaultValue;
- }
-
- /**
- * Returns the specified <code>double</code> attribute.
- *
- * @param name the name of the attribute searched for.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the <code>double</code> value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public double getAttribute(String name, double defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- return (value != null) ? value.toDouble() : defaultValue;
- }
-
- /**
- * Returns the attribute of same type as the specified
- * default value.
- *
- * @param name the name of the attribute.
- * @param defaultValue the value returned if the attribute is not found.
- * @return the parse value for the specified attribute or
- * the default value if the attribute is not found.
- */
- public <T> T getAttribute(String name, T defaultValue)
- throws XMLStreamException {
- CharArray value = getAttribute(name);
- if (value == null)
- return defaultValue;
- // Parses attribute value.
- Class<?> type = defaultValue.getClass();
- TextFormat<?> format = TextContext.getFormat(type);
- if (format == null)
- throw new XMLStreamException("No TextFormat defined for "
- + type);
- return (T) format.parse(value);
- }
-
- // Sets XML binding.
- void setBinding(XMLBinding xmlBinding) {
- _binding = xmlBinding;
- }
-
- // Sets XML reference resolver.
- void setReferenceResolver(XMLReferenceResolver xmlReferenceResolver) {
- _referenceResolver = xmlReferenceResolver;
- }
-
- // Resets for reuse.
- void reset() {
- _binding = XMLBinding.DEFAULT;
- _isReaderAtNext = false;
- _reader.reset();
- _referenceResolver = null;
- }
- }
-
- /**
- * This class represents an output XML element (marshalling).
- */
- @SuppressWarnings("unchecked")
- public static final class OutputElement {
-
- /**
- * Holds the stream writer.
- */
- final XMLStreamWriterImpl _writer = new XMLStreamWriterImpl();
-
- /**
- * Holds the XML binding.
- */
- private XMLBinding _binding;
-
- /**
- * Holds the reference resolver.
- */
- private XMLReferenceResolver _referenceResolver;
-
- /**
- * Default constructor.
- */
- OutputElement() {
- reset();
- }
-
- /**
- * Returns the StAX-like stream writer (provides complete control over
- * the marshalling process).
- *
- * @return the stream writer.
- */
- public XMLStreamWriter getStreamWriter() {
- return _writer;
- }
-
- /**
- * Adds the specified object or <code>null</code> as an anonymous
- * nested element of unknown type.
- *
- * @param obj the object added as nested element or <code>null</code>.
- */
- public void add(Object obj) throws XMLStreamException {
- if (obj == null) {
- _writer.writeEmptyElement(NULL);
- return;
- }
-
- // Writes start element.
- Class<?> cls = obj.getClass();
- _binding.writeClass(cls, _writer, false);
-
- // Checks if reference written.
- XMLFormat<Object> xmlFormat = (XMLFormat<Object>) _binding
- .getFormat(cls);
- if (xmlFormat.isReferenceable() && writeReference(obj))
- return;
-
- xmlFormat.write(obj, this);
- _writer.writeEndElement();
- }
-
- /**
- * Adds the specified object as a named nested element of unknown type
- * (<code>null</code> objects are ignored).
- * The nested XML element contains a class attribute identifying
- * the object type.
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param name the name of the nested element.
- */
- public void add(Object obj, String name) throws XMLStreamException {
- if (obj == null)
- return;
-
- // Writes start element.
- _writer.writeStartElement(name);
-
- // Writes class attribute.
- Class<?> cls = obj.getClass();
- _binding.writeClass(cls, _writer, true);
-
- // Checks if reference written.
- XMLFormat<Object> xmlFormat = (XMLFormat<Object>) _binding
- .getFormat(cls);
- if (xmlFormat.isReferenceable() && writeReference(obj))
- return;
-
- xmlFormat.write(obj, this);
- _writer.writeEndElement();
- }
-
- /**
- * Adds the specified object as a fully qualified nested element of
- * unknown type (<code>null</code> objects are ignored).
- * The nested XML element contains a class attribute identifying
- * the object type.
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param localName the local name of the nested element.
- * @param uri the namespace URI of the nested element.
- */
- public void add(Object obj, String localName, String uri)
- throws XMLStreamException {
- if (obj == null)
- return;
-
- // Writes start element.
- _writer.writeStartElement(uri, localName);
-
- // Writes class attribute.
- Class<?> cls = obj.getClass();
- _binding.writeClass(cls, _writer, true);
-
- // Checks if reference written.
- XMLFormat<Object> xmlFormat = (XMLFormat<Object>) _binding
- .getFormat(cls);
- if (xmlFormat.isReferenceable() && writeReference(obj))
- return;
-
- xmlFormat.write(obj, this);
- _writer.writeEndElement();
- }
-
- /**
- * Adds the specified object as a named nested element of specified
- * actual type (<code>null</code> objects are ignored).
- * The nested XML element does not contain any class attribute.
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param name the name of the nested element.
- * @param cls the class identifying the format of the specified object.
- */
- public <T> void add(T obj, String name, Class<T> cls)
- throws XMLStreamException {
- if (obj == null)
- return;
-
- // Writes start element.
- _writer.writeStartElement(name);
-
- // Checks if reference written.
- XMLFormat<T> xmlFormat = (XMLFormat<T>) _binding.getFormat(cls);
- if (xmlFormat.isReferenceable() && writeReference(obj))
- return;
-
- xmlFormat.write(obj, this);
- _writer.writeEndElement();
- }
-
- /**
- * Adds the specified object as a fully qualified nested element of
- * specified actual type (<code>null</code> objects are ignored).
- * The nested XML element does not contain any class attribute.
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param localName the local name of the nested element.
- * @param uri the namespace URI of the nested element.
- * @param cls the class identifying the format of the specified object.
- */
- public <T> void add(T obj, String localName, String uri, Class<T> cls)
- throws XMLStreamException {
- if (obj == null)
- return;
-
- // Writes start element.
- _writer.writeStartElement(uri, localName);
-
- // Checks if reference written.
- XMLFormat<T> xmlFormat = (XMLFormat<T>) _binding.getFormat(cls);
- if (xmlFormat.isReferenceable() && writeReference(obj))
- return;
-
- xmlFormat.write(obj, this);
- _writer.writeEndElement();
- }
-
- // Returns true if reference written.
- private boolean writeReference(Object obj) throws XMLStreamException {
- if ((_referenceResolver == null)
- || !_referenceResolver.writeReference(obj, this))
- return false;
- _writer.writeEndElement();
- return true; // Reference written.
- }
-
- /**
- * Adds the content of a text-only element (equivalent to {@link
- * javolution.xml.stream.XMLStreamWriter#writeCharacters(CharSequence)
- * getStreamWriter().writeCharacters(text)}).
- *
- * @param text the element text content or an empty sequence if none.
- */
- public void addText(CharSequence text) throws XMLStreamException {
- _writer.writeCharacters(text);
- }
-
- /**
- * Equivalent to {@link #addText(CharSequence)}
- * (for J2ME compatibility).
- *
- * @param text the element text content or an empty sequence if none.
- */
- public void addText(String text) throws XMLStreamException {
- _writer.writeCharacters(text);
- }
-
- /**
- * Sets the specified <code>CharSequence</code> attribute
- * (<code>null</code> values are ignored).
- *
- * @param name the attribute name.
- * @param value the attribute value or <code>null</code>.
- */
- public void setAttribute(String name, CharSequence value)
- throws XMLStreamException {
- if (value == null)
- return;
- _writer.writeAttribute(name, value);
- }
-
- /**
- * Sets the specified <code>String</code> attribute
- * (<code>null</code> values are ignored).
- *
- * @param name the attribute name.
- * @param value the attribute value.
- */
- public void setAttribute(String name, String value)
- throws XMLStreamException {
- if (value == null)
- return;
- _writer.writeAttribute(name, value);
- }
-
- /**
- * Sets the specified <code>boolean</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>boolean</code> value for the specified attribute.
- */
- public void setAttribute(String name, boolean value)
- throws XMLStreamException {
- setAttribute(name, _tmpTextBuilder.clear().append(value));
- }
-
- private TextBuilder _tmpTextBuilder = new TextBuilder();
-
- /**
- * Sets the specified <code>char</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>char</code> value for the specified attribute.
- */
- public void setAttribute(String name, char value)
- throws XMLStreamException {
- setAttribute(name,
- (TextBuilder) _tmpTextBuilder.clear().append(value));
- }
-
- /**
- * Sets the specified <code>byte</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>byte</code> value for the specified attribute.
- */
- public void setAttribute(String name, byte value)
- throws XMLStreamException {
- setAttribute(name, _tmpTextBuilder.clear().append(value));
- }
-
- /**
- * Sets the specified <code>short</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>short</code> value for the specified attribute.
- */
- public void setAttribute(String name, short value)
- throws XMLStreamException {
- setAttribute(name, _tmpTextBuilder.clear().append(value));
- }
-
- /**
- * Sets the specified <code>int</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>int</code> value for the specified attribute.
- */
- public void setAttribute(String name, int value)
- throws XMLStreamException {
- setAttribute(name, _tmpTextBuilder.clear().append(value));
- }
-
- /**
- * Sets the specified <code>long</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>long</code> value for the specified attribute.
- */
- public void setAttribute(String name, long value)
- throws XMLStreamException {
- setAttribute(name, _tmpTextBuilder.clear().append(value));
- }
-
- /**
- * Sets the specified <code>float</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>float</code> value for the specified attribute.
- */
- public void setAttribute(String name, float value)
- throws XMLStreamException {
- setAttribute(name, _tmpTextBuilder.clear().append(value));
- }
-
- /**
- * Sets the specified <code>double</code> attribute.
- *
- * @param name the attribute name.
- * @param value the <code>double</code> value for the specified attribute.
- */
- public void setAttribute(String name, double value)
- throws XMLStreamException {
- setAttribute(name, _tmpTextBuilder.clear().append(value));
- }
-
- /**
- * Sets the specified attribute using its associated
- * {@link javolution.text.TextFormat TextFormat}.
- *
- * @param name the name of the attribute.
- * @param value the value for the specified attribute
- * or <code>null</code> in which case the attribute is not set.
- */
- public void setAttribute(String name, Object value)
- throws XMLStreamException {
- if (value == null)
- return;
- setAttribute(name, _tmpTextBuilder.clear().append(value.toString()));
- }
-
- // Sets XML binding.
- void setBinding(XMLBinding xmlBinding) {
- _binding = xmlBinding;
- }
-
- // Sets XML reference resolver.
- void setReferenceResolver(XMLReferenceResolver xmlReferenceResolver) {
- _referenceResolver = xmlReferenceResolver;
- }
-
- // Resets for reuse.
- void reset() {
- _binding = XMLBinding.DEFAULT;
- _writer.reset();
- _writer.setRepairingNamespaces(true);
- _writer.setAutomaticEmptyElements(true);
- _referenceResolver = null;
- }
- }
-
- /**
- * Returns the default XML format for any object having a
- * {@link TextFormat plain text format}; this XML representation consists
- * of the plain text representation of the object as a "value" attribute.
- */
- public static class Default extends XMLFormat<Object> {
-
- /**
- * Default constructor.
- */
- public Default() {}
-
- @Override
- public boolean isReferenceable() {
- return false; // Always by value (immutable).
- }
-
- @Override
- public Object newInstance(Class<?> cls,
- javolution.xml.XMLFormat.InputElement xml)
- throws XMLStreamException {
- TextFormat<?> format = TextContext.getFormat(cls);
- if (format == null)
- throw new XMLStreamException(
- "No TextFormat defined to parse instances of " + cls);
- CharArray value = xml.getAttribute("value");
- if (value == null)
- throw new XMLStreamException(
- "Missing value attribute (to be able to parse the instance of "
- + cls + ")");
- return format.parse(value);
- }
-
- public void read(XMLFormat.InputElement xml, Object obj)
- throws XMLStreamException {
- // Do nothing.
- }
-
- @SuppressWarnings("unchecked")
- public void write(Object obj, XMLFormat.OutputElement xml)
- throws XMLStreamException {
- TextBuilder tmp = new TextBuilder();
- TextFormat<?> tf = TextContext.getFormat(obj.getClass());
- ((TextFormat<Object>) tf).format(obj, tmp);
- xml.setAttribute("value", tmp);
- }
-
- };
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectReader.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectReader.java
deleted file mode 100644
index f51ebaf..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectReader.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-import javolution.xml.internal.stream.XMLStreamReaderImpl;
-import javolution.xml.stream.XMLStreamException;
-import javolution.xml.stream.XMLStreamReader;
-
-/**
- * <p> This class restores objects which have been serialized in XML
- * format using an {@link XMLObjectWriter}.</p>
- *
- * <p> When the XML document is parsed, each elements are recursively
- * processed and Java objects are created using the {@link XMLFormat}
- * of the class as identified by the {@link XMLBinding}.</p>
- *
- * <p> Multiple objects can be read from the same XML input.
- * For example:[code]
- * XMLObjectReader reader = XMLObjectReader.newInstance(inputStream);
- * while (reader.hasNext()) {
- * Message message = reader.read("Message", Message.class);
- * }
- * reader.close(); // The underlying stream is closed.
- * [/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, September 4, 2006
- */
-public class XMLObjectReader {
-
- /**
- * Hold the xml element used when parsing.
- */
- private final XMLFormat.InputElement _xml = new XMLFormat.InputElement();
-
- /**
- * Holds reader if any.
- */
- private Reader _reader;
-
- /**
- * Holds input stream if any.
- */
- private InputStream _inputStream;
-
- /**
- * Returns a XML object reader having the specified
- * input stream as input.
- *
- * @param in the input stream.
- */
- public static XMLObjectReader newInstance(InputStream in)
- throws XMLStreamException {
- XMLObjectReader reader = new XMLObjectReader();
- reader.setInput(in);
- return reader;
- }
-
- /**
- * Returns a XML object reader (potentially recycled) having the specified
- * input stream/encoding as input.
- *
- * @param in the input stream.
- * @param encoding the input stream encoding
- */
- public static XMLObjectReader newInstance(InputStream in, String encoding)
- throws XMLStreamException {
- XMLObjectReader reader = new XMLObjectReader();
- reader.setInput(in, encoding);
- return reader;
- }
-
- /**
- * Returns a XML object reader (potentially recycled) having the specified
- * reader as input.
- *
- * @param in the reader source.
- */
- public static XMLObjectReader newInstance(Reader in)
- throws XMLStreamException {
- XMLObjectReader reader = new XMLObjectReader();
- reader.setInput(in);
- return reader;
- }
-
- /**
- * Default constructor.
- */
- public XMLObjectReader() {}
-
- /**
- * Returns the stream reader being used by this reader (it can be
- * used to set prefix, read prologs, etc).
- *
- * @return the stream reader.
- */
- public XMLStreamReader getStreamReader() {
- return _xml._reader;
- }
-
- /**
- * Sets the input stream source for this XML object reader
- * (encoding retrieved from XML prolog if any).
- *
- * @param in the source input stream.
- * @return <code>this</code>
- * @see XMLStreamReaderImpl#setInput(InputStream)
- */
- public XMLObjectReader setInput(InputStream in) throws XMLStreamException {
- if ((_inputStream != null) || (_reader != null))
- throw new IllegalStateException("Reader not closed or reset");
- _xml._reader.setInput(in);
- _inputStream = in;
- return this;
- }
-
- /**
- * Sets the input stream source and encoding for this XML object reader.
- *
- * @param in the input source.
- * @param encoding the associated encoding.
- * @return <code>this</code>
- * @see XMLStreamReaderImpl#setInput(InputStream, String)
- */
- public XMLObjectReader setInput(InputStream in, String encoding)
- throws XMLStreamException {
- if ((_inputStream != null) || (_reader != null))
- throw new IllegalStateException("Reader not closed or reset");
- _xml._reader.setInput(in, encoding);
- _inputStream = in;
- return this;
- }
-
- /**
- * Sets the reader input source for this XML stream reader.
- *
- * @param in the source reader.
- * @return <code>this</code>
- * @see XMLStreamReaderImpl#setInput(Reader)
- */
- public XMLObjectReader setInput(Reader in) throws XMLStreamException {
- if ((_inputStream != null) || (_reader != null))
- throw new IllegalStateException("Reader not closed or reset");
- _xml._reader.setInput(in);
- _reader = in;
- return this;
- }
-
- /**
- * Sets the XML binding to use with this object reader.
- *
- * @param binding the XML binding to use.
- * @return <code>this</code>
- */
- public XMLObjectReader setBinding(XMLBinding binding) {
- _xml.setBinding(binding);
- return this;
- }
-
- /**
- * Sets the XML reference resolver to use with this object reader
- * (the same resolver can be used accross multiple readers).
- *
- * @param referenceResolver the XML reference resolver.
- * @return <code>this</code>
- */
- public XMLObjectReader setReferenceResolver(
- XMLReferenceResolver referenceResolver) {
- _xml.setReferenceResolver(referenceResolver);
- return this;
- }
-
- /**
- * Indicates if more elements can be read. This method
- * positions the reader at the start of the
- * next element to be read (if any).
- *
- * @return <code>true</code> if more element/data to be read;
- * <code>false</code> otherwise.
- * @see XMLFormat.InputElement#hasNext()
- */
- public boolean hasNext() throws XMLStreamException {
- return _xml.hasNext();
- }
-
- /**
- * Returns the object corresponding to the next element/data.
- *
- * @return the next nested object (can be <code>null</code>)
- * @throws XMLStreamException if <code>hasNext() == false</code>
- * @see XMLFormat.InputElement#getNext()
- */
- @SuppressWarnings("unchecked")
- public <T> T read() throws XMLStreamException {
- return (T) _xml.getNext();
- }
-
- /**
- * Returns the object corresponding to the next nested element only
- * if it has the specified local name.
- *
- * @param name the local name of the next element.
- * @return the next content object or <code>null</code> if the
- * local name does not match.
- * @see XMLFormat.InputElement#get(String)
- */
- @SuppressWarnings("unchecked")
- public <T> T read(String name) throws XMLStreamException {
- return (T) _xml.get(name);
- }
-
- /**
- * Returns the object corresponding to the next nested element only
- * if it has the specified local name and namespace URI.
- *
- * @param localName the local name.
- * @param uri the namespace URI.
- * @return the next content object or <code>null</code> if the
- * name/uri does not match.
- * @see XMLFormat.InputElement#get(String, String)
- */
- @SuppressWarnings("unchecked")
- public <T> T read(String localName, String uri) throws XMLStreamException {
- return (T) _xml.get(localName, uri);
- }
-
- /**
- * Returns the object corresponding to the next nested element only
- * if it has the specified local name; the actual object type is identified
- * by the specified class parameter.
- *
- * @param name the name of the element to match.
- * @param cls the non-abstract class identifying the object to return.
- * @return <code>read(name, null, cls)</code>
- */
- public <T> T read(String name, Class<T> cls) throws XMLStreamException {
- return _xml.get(name, cls);
- }
-
- /**
- * Returns the object corresponding to the next nested element only
- * if it has the specified local name and namespace URI; the
- * actual object type is identified by the specified class parameter.
- *
- * @param localName the local name.
- * @param uri the namespace URI.
- * @param cls the non-abstract class identifying the object to return.
- * @return the next content object or <code>null</code> if no match.
- */
- public <T> T read(String localName, String uri, Class<T> cls)
- throws XMLStreamException {
- return _xml.get(localName, uri, cls);
- }
-
- /**
- * Closes this reader and its underlying input then {@link #reset reset}
- * this reader for potential reuse.
- */
- public void close() throws XMLStreamException {
- try {
- if (_inputStream != null) {
- _inputStream.close();
- reset();
- } else if (_reader != null) {
- _reader.close();
- reset();
- }
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- }
-
- /**
- * Resets this object reader for reuse.
- */
- public void reset() {
- _xml.reset();
- _reader = null;
- _inputStream = null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectWriter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectWriter.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectWriter.java
deleted file mode 100644
index 7cb3d80..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLObjectWriter.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-
-import javolution.xml.internal.stream.XMLStreamWriterImpl;
-import javolution.xml.stream.XMLStreamException;
-import javolution.xml.stream.XMLStreamWriter;
-
-/**
- * <p> This class takes an object and formats it to XML; the resulting
- * XML can be deserialized using a {@link XMLObjectReader}.</p>
- *
- * <p> When an object is formatted, the {@link XMLFormat} of the
- * object's class as identified by the {@link XMLBinding} is used to
- * write its XML representation.</p>
- *
- * <p> Multiple objects can be written to the same XML output.
- * For example:[code]
- * XMLObjectWriter writer = XMLObjectWriter.newInstance(outputStream);
- * while (true)) {
- * Message message = ...
- * writer.write(message, "Message", Message.class);
- * }
- * writer.close(); // The underlying stream is closed.
- * [/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, September 4, 2006
- */
-public class XMLObjectWriter {
-
- /**
- * Hold the xml element used when formatting.
- */
- private final XMLFormat.OutputElement _xml = new XMLFormat.OutputElement();
-
- /**
- * Holds writer if any.
- */
- private Writer _writer;
-
- /**
- * Holds input stream if any.
- */
- private OutputStream _outputStream;
-
- /**
- * Default constructor.
- */
- public XMLObjectWriter() {}
-
- /**
- * Returns a XML object writer (potentially recycled) having the specified
- * output stream as output.
- *
- * @param out the output stream.
- */
- public static XMLObjectWriter newInstance(OutputStream out)
- throws XMLStreamException {
- XMLObjectWriter writer = new XMLObjectWriter();
- writer.setOutput(out);
- return writer;
- }
-
- /**
- * Returns a XML object writer (potentially recycled) having the specified
- * output stream/encoding as output.
- *
- * @param out the output stream.
- * @param encoding the output stream encoding.
- */
- public static XMLObjectWriter newInstance(OutputStream out, String encoding)
- throws XMLStreamException {
- XMLObjectWriter writer = new XMLObjectWriter();
- writer.setOutput(out, encoding);
- return writer;
- }
-
- /**
- * Returns a XML object writer (potentially recycled) having the specified
- * writer as output.
- *
- * @param out the writer output.
- */
- public static XMLObjectWriter newInstance(Writer out)
- throws XMLStreamException {
- XMLObjectWriter writer = new XMLObjectWriter();
- writer.setOutput(out);
- return writer;
- }
-
- /**
- * Returns the stream writer used by this object writer (it can be used
- * to write prolog, write namespaces, etc). The stream writer is setup to
- * automatically repair namespaces and to automatically output empty
- * elements when a start element is immediately followed by matching end
- * element.
- *
- * @return the stream writer.
- */
- public XMLStreamWriter getStreamWriter() {
- return _xml._writer;
- }
-
- /**
- * Sets the output stream for this XML object writer.
- *
- * @param out the output stream destination.
- * @return <code>this</code>
- * @see XMLStreamWriterImpl#setOutput(OutputStream)
- */
- public XMLObjectWriter setOutput(OutputStream out)
- throws XMLStreamException {
- if ((_outputStream != null) || (_writer != null))
- throw new IllegalStateException("Writer not closed or reset");
- _xml._writer.setOutput(out);
- _outputStream = out;
- _xml._writer.writeStartDocument();
- return this;
- }
-
- /**
- * Sets the output stream and encoding for this XML object writer.
- *
- * @param out the output stream destination.
- * @param encoding the stream encoding.
- * @return <code>this</code>
- * @see XMLStreamWriterImpl#setOutput(OutputStream, String)
- */
- public XMLObjectWriter setOutput(OutputStream out, String encoding)
- throws XMLStreamException {
- if ((_outputStream != null) || (_writer != null))
- throw new IllegalStateException("Writer not closed or reset");
- _xml._writer.setOutput(out, encoding);
- _outputStream = out;
- _xml._writer.writeStartDocument();
- return this;
- }
-
- /**
- * Sets the output writer for this XML object writer.
- *
- * @param out the writer destination.
- * @return <code>this</code>
- * @see XMLStreamWriterImpl#setOutput(Writer)
- */
- public XMLObjectWriter setOutput(Writer out) throws XMLStreamException {
- if ((_outputStream != null) || (_writer != null))
- throw new IllegalStateException("Writer not closed or reset");
- _xml._writer.setOutput(out);
- _writer = out;
- _xml._writer.writeStartDocument();
- return this;
- }
-
- /**
- * Sets the XML binding to use with this object writer.
- *
- * @param binding the XML binding to use.
- * @return <code>this</code>
- */
- public XMLObjectWriter setBinding(XMLBinding binding) {
- _xml.setBinding(binding);
- return this;
- }
-
- /**
- * Sets the indentation to be used by this writer (no indentation
- * by default).
- *
- * @param indentation the indentation string.
- * @return <code>this</code>
- */
- public XMLObjectWriter setIndentation(String indentation) {
- _xml._writer.setIndentation(indentation);
- return this;
- }
-
- /**
- * Sets the XML reference resolver to use with this object writer
- * (the same reference resolver can be used accross multiple writers).
- *
- * @param referenceResolver the XML reference resolver.
- * @return <code>this</code>
- */
- public XMLObjectWriter setReferenceResolver(
- XMLReferenceResolver referenceResolver) {
- _xml.setReferenceResolver(referenceResolver);
- return this;
- }
-
- /**
- * Writes the specified object as an anonymous nested element of
- * unknown type. This result in the actual type of the object being
- * identified by the element name.
- *
- * @param obj the object written as nested element or <code>null</code>.
- * @see XMLFormat.OutputElement#add(Object)
- */
- public void write(Object obj) throws XMLStreamException {
- _xml.add(obj);
- }
-
- /**
- * Writes the specified object as a named nested element of unknown type
- * (<code>null</code> objects are ignored). The nested XML element
- * may contain a class attribute identifying the object type.
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param name the name of the nested element.
- * @see XMLFormat.OutputElement#add(Object, String)
- */
- public void write(Object obj, String name) throws XMLStreamException {
- _xml.add(obj, name);
- }
-
- /**
- * Writes the specified object as a fully qualified nested element of
- * unknown type (<code>null</code> objects are ignored).
- * The nested XML element may contain a class attribute identifying
- * the object type.
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param localName the local name of the nested element.
- * @param uri the namespace URI of the nested element.
- * @see XMLFormat.OutputElement#add(Object, String, String)
- */
- public void write(Object obj, String localName, String uri)
- throws XMLStreamException {
- _xml.add(obj, localName, uri);
- }
-
- /**
- * Writes the specified object as a named nested element of actual type
- * known (<code>null</code> objects are ignored).
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param name the name of the nested element.
- * @param cls the non-abstract class identifying the XML format to use.
- * @see XMLFormat.OutputElement#add(Object, String, Class)
- */
- public <T> void write(T obj, String name, Class<T> cls)
- throws XMLStreamException {
- _xml.add(obj, name, cls);
- }
-
- /**
- * Writes the specified object as a fully qualified nested element of
- * actual type known (<code>null</code> objects are ignored).
- *
- * @param obj the object added as nested element or <code>null</code>.
- * @param localName the local name of the nested element.
- * @param uri the namespace URI of the nested element.
- * @param cls the class identifying the XML format to use.
- * @see XMLFormat.OutputElement#add(Object, String, String, Class)
- */
- public <T> void write(T obj, String localName, String uri, Class<T> cls)
- throws XMLStreamException {
- _xml.add(obj, localName, uri, cls);
- }
-
- /**
- * Flushes the output stream of this writer (automatically done
- * when {@link #close() closing}).
- */
- public void flush() throws XMLStreamException {
- _xml._writer.flush();
- }
-
- /**
- * Ends document writting, closes this writer and its underlying
- * output then {@link #reset reset} this Writer for potential reuse.
- */
- public void close() throws XMLStreamException {
- try {
- if (_outputStream != null) {
- _xml._writer.writeEndDocument();
- _xml._writer.close();
- _outputStream.close();
- reset();
- } else if (_writer != null) {
- _xml._writer.writeEndDocument();
- _xml._writer.close();
- _writer.close();
- reset();
- }
-
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- }
-
- /**
- * Resets this object writer for reuse.
- */
- public void reset() {
- _xml.reset();
- _outputStream = null;
- _writer = null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLReferenceResolver.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLReferenceResolver.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLReferenceResolver.java
deleted file mode 100644
index 2730cf2..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLReferenceResolver.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import javolution.text.CharArray;
-import javolution.text.TextBuilder;
-import javolution.util.FastMap;
-import javolution.util.FastTable;
-import javolution.util.Index;
-import javolution.util.function.Equalities;
-import javolution.xml.stream.XMLStreamException;
-
-/**
- * <p> This class represents a resolver for XML cross references during
- * the marshalling/unmarshalling process.</p>
- *
- * <p> Instances of this class may only be shared by {@link XMLObjectReader}/
- * {@link XMLObjectWriter} running sequentially (for cross references
- * spawning multiple documents).</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, September 4, 2006
- */
-public class XMLReferenceResolver {
-
- /**
- * Holds object to identifier (FastTable.Index) mapping.
- */
- private FastMap<Object, Index> _objectToId = new FastMap<Object, Index>(
- Equalities.IDENTITY);
-
- /**
- * Holds the objects (index to object mapping).
- */
- private FastTable<Object> _idToObject = new FastTable<Object>();
-
- /**
- * Holds the id counter.
- */
- private int _counter;
-
- /**
- * Holds the identifier attribute name.
- */
- private String _idName = "id";
-
- /**
- * Holds the identifier attribute URI if any.
- */
- private String _idURI = null;
-
- /**
- * Holds the reference attribute name.
- */
- private String _refName = "ref";
-
- /**
- * Holds the reference attribute URI if any.
- */
- private String _refURI = null;
-
- /**
- * Default constructor.
- */
- public XMLReferenceResolver() {}
-
- /**
- * Sets the name of the identifier attribute (by default<code>"id"</code>).
- * If the name is <code>null</code> then the identifier attribute
- * is never read/written (which may prevent unmarshalling).
- *
- * @param name the name of the attribute or <code>null</code>.
- */
- public void setIdentifierAttribute(String name) {
- setIdentifierAttribute(name, null);
- }
-
- /**
- * Sets the local name and namespace URI of the identifier attribute.
- *
- * @param localName the local name of the attribute or <code>null</code>.
- * @param uri the URI of the attribute or <code>null</code> if the attribute
- * has no namespace URI.
- */
- public void setIdentifierAttribute(String localName, String uri) {
- _idName = localName;
- _idURI = uri;
- }
-
- /**
- * Sets the name of the reference attribute (by default<code>"ref"</code>).
- * If the name is <code>null</code> then the reference attribute
- * is never read/written (which may prevent unmarshalling).
- *
- * @param name the name of the attribute or <code>null</code>.
- */
- public void setReferenceAttribute(String name) {
- setReferenceAttribute(name, null);
- }
-
- /**
- * Sets the local name and namespace URI of the identifier attribute.
- *
- * @param localName the local name of the attribute or <code>null</code>.
- * @param uri the URI of the attribute or <code>null</code> if the attribute
- * has no namespace URI.
- */
- public void setReferenceAttribute(String localName, String uri) {
- _refName = localName;
- _refURI = uri;
- }
-
- /**
- * Writes a reference to the specified object into the specified XML
- * element. The default implementation writes the reference into the
- * reference attribute and for the first occurences an identifier
- * (counter starting at 1) is written into the identifier attribute.
- *
- * @param obj the object for which the reference is written.
- * @param xml the output XML element.
- * @return <code>true</code> if a reference is written;
- * <code>false</code> if a new identifier is written.
- */
- public boolean writeReference(Object obj, XMLFormat.OutputElement xml)
- throws XMLStreamException {
- Index id = (Index) _objectToId.get(obj);
- if (id == null) { // New identifier.
- id = Index.valueOf(_counter++);
- _objectToId.put(obj, id);
- _tmp.clear().append(id.intValue());
- if (_idURI == null) {
- xml.getStreamWriter().writeAttribute(_idName, _tmp);
- } else {
- xml.getStreamWriter().writeAttribute(_idURI, _idName, _tmp);
- }
- return false;
- }
- _tmp.clear().append(id.intValue());
- if (_refURI == null) {
- xml._writer.writeAttribute(_refName, _tmp);
- } else {
- xml._writer.writeAttribute(_refURI, _refName, _tmp);
- }
- return true;
- }
-
- private TextBuilder _tmp = new TextBuilder();
-
- /**
- * Reads the object referenced by the specified xml input element if any.
- * The default implementation reads the reference attribute to retrieve
- * the object.
- *
- * @param xml the input XML element.
- * @return the referenced object or <code>null</code> if the specified
- * XML input does not have a reference attribute.
- */
- public Object readReference(XMLFormat.InputElement xml)
- throws XMLStreamException {
- CharArray value = xml._reader.getAttributeValue(_refURI, _refName);
- if (value == null)
- return null;
- int ref = value.toInt();
- if (ref >= _idToObject.size())
- throw new XMLStreamException("Reference: " + value + " not found");
- return _idToObject.get(ref);
- }
-
- /**
- * Creates a reference for the specified object (the identifier
- * being specified by the input XML element).
- * The default implementation reads the identifier attribute (if any)
- * and associates it to the specified object.
- *
- * @param obj the object being referenced.
- * @param xml the input XML element holding the reference identifier.
- */
- public void createReference(Object obj, XMLFormat.InputElement xml)
- throws XMLStreamException {
- CharArray value = xml._reader.getAttributeValue(_idURI, _idName);
- if (value == null)
- return;
- int i = value.toInt();
- if (_idToObject.size() != i)
- throw new XMLStreamException("Identifier discontinuity detected "
- + "(expected " + _idToObject.size() + " found " + i + ")");
- _idToObject.add(obj);
- }
-
- public void reset() {
- _idName = "id";
- _idURI = null;
- _refName = "ref";
- _refURI = null;
- _idToObject.clear();
- _objectToId.clear();
- _counter = 0;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLSerializable.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLSerializable.java b/commons/marmotta-commons/src/ext/java/javolution/xml/XMLSerializable.java
deleted file mode 100644
index 46cacde..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/XMLSerializable.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2007 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import java.io.Serializable;
-
-/**
- * <p> This interface identifies classes supporting XML serialization
- * (XML serialization is still possible for classes not implementing this
- * interface through dynamic {@link XMLBinding} though).</p>
- *
- * <p> Typically, classes implementing this interface have a protected static
- * {@link XMLFormat} holding their default XML representation.
- * For example:[code]
- * public final class Complex implements XMLSerializable {
- *
- * // Use the cartesien form for the default XML representation.
- * protected static final XMLFormat<Complex> XML = new XMLFormat<Complex>(Complex.class) {
- * public Complex newInstance(Class<Complex> cls, InputElement xml) throws XMLStreamException {
- * return Complex.valueOf(xml.getAttribute("real", 0.0),
- * xml.getAttribute("imaginary", 0.0));
- * }
- * public void write(Complex complex, OutputElement xml) throws XMLStreamException {
- * xml.setAttribute("real", complex.getReal());
- * xml.setAttribute("imaginary", complex.getImaginary());
- * }
- * public void read(InputElement xml, Complex complex) {
- * // Immutable, deserialization occurs at creation, ref. newIntance(...)
-* }
- * };
- * ...
- * }[/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.2, April 15, 2007
- */
-public interface XMLSerializable extends Serializable {
-
- // No method. Tagging interface.
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/doc-files/xmlDataBinding.png
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/doc-files/xmlDataBinding.png b/commons/marmotta-commons/src/ext/java/javolution/xml/doc-files/xmlDataBinding.png
deleted file mode 100644
index 46c6efd..0000000
Binary files a/commons/marmotta-commons/src/ext/java/javolution/xml/doc-files/xmlDataBinding.png and /dev/null differ
[12/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/internal/StorageContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/StorageContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/StorageContextImpl.java
deleted file mode 100644
index 0f20936..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/internal/StorageContextImpl.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context.internal;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
-import javolution.context.LogContext;
-import javolution.context.SecurityContext;
-import javolution.context.SecurityContext.Permission;
-import javolution.context.StorageContext;
-
-/**
- * Holds the default implementation of StorageContext.
- */
-public final class StorageContextImpl extends StorageContext {
-
- @SuppressWarnings("unchecked")
- @Override
- public <V extends Serializable> V read(Resource<V> resource)
- throws SecurityException {
- SecurityContext.check(new Permission<Resource<V>>(Resource.class,
- "write", resource));
- try {
- File file = new File(FILE_STORAGE_LOCATION.get(),
- resource.uniqueID());
- if (file.exists()) {
- LogContext.debug("Read resource file ", file.getAbsolutePath());
- } else {
- LogContext.debug("Resource file ", file.getAbsolutePath(),
- " does not exist.");
- return null;
- }
-
- FileInputStream fileIn = new FileInputStream(file);
- ObjectInputStream in = new ObjectInputStream(fileIn);
- V value = (V) in.readObject();
- in.close();
- fileIn.close();
- return value;
- } catch (IOException e1) {
- LogContext.error(e1);
- } catch (ClassNotFoundException e2) {
- LogContext.error(e2);
- }
- return null;
-
- }
-
- @Override
- public <V extends Serializable> void write(Resource<V> resource, V value)
- throws SecurityException {
- SecurityContext.check(new Permission<Resource<V>>(Resource.class,
- "write", resource));
- try {
- File storage = FILE_STORAGE_LOCATION.get();
- storage.mkdirs();
- File file = new File(storage, resource.uniqueID());
- LogContext.debug("Write resource ", file.getAbsolutePath());
-
- FileOutputStream fileOut = new FileOutputStream(file);
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
- out.writeObject(value);
- out.close();
- fileOut.close();
- } catch (IOException error) {
- LogContext.error(error);
- }
- }
-
- @Override
- protected StorageContext inner() {
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/context/package-info.java
deleted file mode 100644
index af177ae..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/package-info.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
-<p> Run-time {@link javolution.context.AbstractContext contexts} to facilitate
- separation of concerns and achieve higher level of performance and flexibility.</p>
-
-<h2><a name="OVERVIEW">Separation of Concerns</a></h2>
-
- <p> Separation of concerns is an important design principle greatly misunderstood.
- Most developers think it is limited to modularity and encapsulation or it
- requires special programming tools (e.g. Aspect programming).</p>
-
- <p> Separation of concerns is very powerful and easier than it looks.
- Basically, it could be summarized as the "pass the buck principle".
- If you don't know what to do with some information, just give it to someone
- else who might know.</p>
-
- <p> A frequent example is the catching of exceptions too early (with some logging processing)
- instead of throwing a checked exception. Unfortunately, they are still plenty of cases
- where the separation of concerns is not as good as it could be. For example logging!
- Why low-level code need to know which logging facility to use
- (e.g. standard logging, Log4J library, OSGi LogService or anything else)?
- Why logging should have to be based upon the class hierarchy (standard logging)?
- Why can't we attach some relevant information (such as user id, session number, etc.)
- to the logging content ? </p>
-
- <p> Separation of concerns can be addressed through "Aspect Programming",
- but there is a rather simpler solution <b>"Context Programming"</b>!</p>
-
- <p> It does not require any particular tool, it basically says that every threads
- has a {@link javolution.context.AbstractContext context} which can be customized by someone else
- (the one who knows what to do, when running OSGi it is typically a separate bundle).
- Then, your code looks a lot cleaner and is way more flexible as you don't have
- to worry about logging, security, performance etc. in your low level methods.
-[code]
-void myMethod() {
- ...
- LogContext.info("Don't know where this is going to be logged to");
- ...
-}[/code]</p>
-
- <p> Used properly <i><b>J</b>avolution</i>'s {@link javolution.context.AbstractContext contexts}
- greatly facilitate the separation of concerns. Contexts are fully
- integrated with OSGi (they are published services). Applications
- may dynamically plug-in the "right context" using OSGi mechanisms.
- For example, the {@link javolution.context.SecurityContext SecurityContext}
- might only be known at runtime.</p>
-
- <h2><a name="PREDEFINED">Predefined Contexts:</a></h2>
- <p> <i><b>J</b>avolution</i> provides several useful runtime contexts:<ul>
- <li>{@link javolution.context.ConcurrentContext ConcurrentContext}
- - To take advantage of concurrent algorithms on multi-cores systems.</li>
- <li>{@link javolution.context.LogContext LogContext}
- - To log events according to the runtime environment (e.g. {@link org.osgi.service.log.LogService} when running OSGi).</li>
- <li>{@link javolution.context.LocalContext LocalContext}
- - To define locally scoped environment settings.</li>
- <li>{@link javolution.context.SecurityContext SecurityContext}
- - To address application-level security concerns.</li>
- <li>{@link javolution.context.StorageContext StorageContext}
- - To store/retrieve your persistent data/dataset.</li>
- <li>{@link javolution.context.FormatContext FormatContext}
- - For plugable objects parsing/formatting. Such as {@link javolution.text.TextContext TextContext} for plain text,
- or {@link javolution.xml.XMLContext XMLContext} for XML serialization/deserialization.</li>
- <li>{@link javolution.context.StorageContext StorageContext}
- - To store/retrieve your persistent data/dataset.</li>
- <li>...add your own !</li>
- </ul>
- </p>
-
-<h2><a name="FAQ">FAQ:</a></h2>
-<ol>
- <a name="FAQ-1"></a>
- <li><b>In my application I create new threads on-the-fly and I would like them to inherit
- the current context environment. How can I do that?</b>
- <p> Context is automatically inherited when performing concurrent executions using
- {@link javolution.context.ConcurrentContext ConcurrentContext}. If you create
- new threads yourself you can easily setup their context as shown below.</p>
-[code]
-//Spawns a new thread inheriting the context of the current thread.
-MyThread myThread = new MyThread();
-myThread.inherited = AbstractContext.current();
-myThread.start();
- ...
-class MyThread extends Thread {
- AbstractContext inherited;
- public void run() {
- AbstractContext.inherit(inherited); // Sets current context.
- ...
- }
-}[/code]
-<p></p>
- </li>
-
- <a name="FAQ-2"></a>
- <li><b>Is it possible to configure the context of all running threads (global configuration) ?</b>
- <p> Yes by publishing an OSGi implementation of the customized context
- (published context services are the default contexts of all running threads).
- Otherwise, you can only configure a context that you have entered (for obvious safety reasons).</p>
-<p></p>
- </li>
- </ol>
-
-*/
-package javolution.context;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/AppendableWriter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/AppendableWriter.java b/commons/marmotta-commons/src/ext/java/javolution/io/AppendableWriter.java
deleted file mode 100644
index 84e6f7f..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/AppendableWriter.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-import java.io.IOException;
-import java.io.Writer;
-import javolution.text.Text;
-
-/**
- * <p> This class allows any <code>Appendable</code> to be used as
- * a writer.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 3.8, May 8, 2006
- */
-public final class AppendableWriter extends Writer {
-
- /**
- * Holds the current appendable output or <code>null</code> if closed.
- */
- private Appendable _output;
-
- /**
- * Creates a new appendable writer for which the appendable output
- * is not set.
- *
- * @see #setOutput(Appendable)
- */
- public AppendableWriter() {}
-
- /**
- * Sets the appendable output being written to.
- * For example:[code]
- * Writer writer = new AppendableWriter().setOutput(new TextBuilder());
- * [/code]
- *
- * @param output the appendable written to.
- * @return this writer.
- * @throws IllegalStateException if this writer is being reused and
- * it has not been {@link #close closed} or {@link #reset reset}.
- */
- public AppendableWriter setOutput(Appendable output) {
- if (_output != null)
- throw new IllegalStateException("Writer not closed or reset");
- _output = output;
- return this;
- }
-
- /**
- * Writes a single character.
- *
- * @param c <code>char</code> the character to be written.
- * @throws IOException if an I/O error occurs.
- */
- public void write(char c) throws IOException {
- if (_output == null)
- throw new IOException("Writer closed");
- _output.append(c);
- }
-
- /**
- * Writes the 16 low-order bits of the given integer value;
- * the 16 high-order bits are ignored.
- *
- * @param c the value of the character to be written.
- * @throws IOException if an I/O error occurs.
- */
- public void write(int c) throws IOException {
- if (_output == null)
- throw new IOException("Writer closed");
- _output.append((char) c);
- }
-
- /**
- * Writes a portion of an array of characters.
- *
- * @param cbuf the array of characters.
- * @param off the offset from which to start writing characters.
- * @param len the number of characters to write.
- * @throws IOException if an I/O error occurs.
- */
- public void write(char cbuf[], int off, int len) throws IOException {
- if (_output == null)
- throw new IOException("Writer closed");
- _tmpBuffer = cbuf;
- _output.append(_tmpBufferAsCharSequence, off, off + len);
- _tmpBuffer = null; // Removes temporary references.
- }
-
- private char[] _tmpBuffer;
-
- private final CharSequence _tmpBufferAsCharSequence = new CharSequence() {
- public int length() {
- return _tmpBuffer.length;
- }
-
- public char charAt(int index) {
- return _tmpBuffer[index];
- }
-
- public CharSequence subSequence(int start, int end) {
- throw new UnsupportedOperationException();
- }
- };
-
- /**
- * Writes a portion of a string.
- *
- * @param str a String.
- * @param off the offset from which to start writing characters.
- * @param len the number of characters to write.
- * @throws IOException if an I/O error occurs
- */
- public void write(String str, int off, int len) throws IOException {
- if (_output == null)
- throw new IOException("Writer closed");
- Object obj = str;
- if (obj instanceof CharSequence) {
- _output.append((CharSequence) obj);
- } else {
- _output.append(Text.valueOf(str));
- }
- }
-
- /**
- * Writes the specified character sequence.
- *
- * @param csq the character sequence.
- * @throws IOException if an I/O error occurs
- */
- public void write(CharSequence csq) throws IOException {
- if (_output == null)
- throw new IOException("Writer closed");
- _output.append(csq);
- }
-
- /**
- * Flushes the stream.
- */
- public void flush() {
- // Do nothing (no buffer).
- }
-
- /**
- * Closes and {@link #reset resets} this writer for reuse.
- */
- public void close() {
- if (_output != null) {
- reset();
- }
- }
-
- public void reset() {
- _output = null;
- _tmpBuffer = null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/CharSequenceReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/CharSequenceReader.java b/commons/marmotta-commons/src/ext/java/javolution/io/CharSequenceReader.java
deleted file mode 100644
index 9dd0da2..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/CharSequenceReader.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-import java.io.IOException;
-import java.io.Reader;
-import javolution.lang.MathLib;
-import javolution.text.CharArray;
-import javolution.text.Text;
-import javolution.text.TextBuilder;
-
-/**
- * <p> This class allows any <code>CharSequence</code> to be used as
- * a reader.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 3.8, May 8, 2004
- */
-public final class CharSequenceReader extends Reader {
-
- /**
- * Holds the character sequence input.
- */
- private CharSequence _input;
-
- /**
- * Holds the current index into the character sequence.
- */
- private int _index;
-
- /**
- * Creates a new character sequence reader for which the character
- * sequence input is not set.
- *
- * @see #setInput
- */
- public CharSequenceReader() {}
-
- /**
- * Sets the character sequence to use for reading.
- *
- * @param charSequence the character sequence to be read.
- * @return this reader.
- * @throws IllegalStateException if this reader is being reused and
- * it has not been {@link #close closed} or {@link #reset reset}.
- */
- public CharSequenceReader setInput(CharSequence charSequence) {
- if (_input != null)
- throw new IllegalStateException("Reader not closed or reset");
- _input = charSequence;
- return this;
- }
-
- /**
- * Indicates if this stream is ready to be read.
- *
- * @return <code>true</code> if this reader has remaining characters to
- * read; <code>false</code> otherwise.
- * @throws IOException if an I/O error occurs.
- */
- public boolean ready() throws IOException {
- if (_input == null)
- throw new IOException("Reader closed");
- return true;
- }
-
- /**
- * Closes and {@link #reset resets} this reader for reuse.
- */
- public void close() {
- if (_input != null) {
- reset();
- }
- }
-
- /**
- * Reads a single character. This method does not block, <code>-1</code>
- * is returned if the end of the character sequence input has been reached.
- *
- * @return the 31-bits Unicode of the character read, or -1 if there is
- * no more remaining bytes to be read.
- * @throws IOException if an I/O error occurs (e.g. incomplete
- * character sequence being read).
- */
- public int read() throws IOException {
- if (_input == null)
- throw new IOException("Reader closed");
- return (_index < _input.length()) ? _input.charAt(_index++) : -1;
- }
-
- /**
- * Reads characters into a portion of an array. This method does not
- * block.
- *
- * @param cbuf the destination buffer.
- * @param off the offset at which to start storing characters.
- * @param len the maximum number of characters to read
- * @return the number of characters read, or -1 if there is no more
- * character to be read.
- * @throws IOException if an I/O error occurs.
- */
- public int read(char cbuf[], int off, int len) throws IOException {
- if (_input == null)
- throw new IOException("Reader closed");
- final int inputLength = _input.length();
- if (_index >= inputLength)
- return -1;
- final int count = MathLib.min(inputLength - _index, len);
- final Object csq = _input;
- if (csq instanceof String) {
- String str = (String) csq;
- str.getChars(_index, _index + count, cbuf, off);
- } else if (csq instanceof Text) {
- Text txt = (Text) csq;
- txt.getChars(_index, _index + count, cbuf, off);
- } else if (csq instanceof TextBuilder) {
- TextBuilder tb = (TextBuilder) csq;
- tb.getChars(_index, _index + count, cbuf, off);
- } else if (csq instanceof CharArray) {
- CharArray ca = (CharArray) csq;
- System.arraycopy(ca.array(), _index + ca.offset(), cbuf, off, count);
- } else { // Generic CharSequence.
- for (int i = off, n = off + count, j = _index; i < n;) {
- cbuf[i++] = _input.charAt(j++);
- }
- }
- _index += count;
- return count;
- }
-
- /**
- * Reads characters into the specified appendable. This method does not
- * block.
- *
- * @param dest the destination buffer.
- * @throws IOException if an I/O error occurs.
- */
- public void read(Appendable dest) throws IOException {
- if (_input == null)
- throw new IOException("Reader closed");
- dest.append(_input);
- }
-
- @Override
- public void reset() {
- _index = 0;
- _input = null;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/Struct.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/Struct.java b/commons/marmotta-commons/src/ext/java/javolution/io/Struct.java
deleted file mode 100644
index 3f95451..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/Struct.java
+++ /dev/null
@@ -1,1749 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-import javolution.context.LocalContext;
-import javolution.lang.MathLib;
-import javolution.lang.Realtime;
-import javolution.text.TextBuilder;
-
-/**
- * <p> Equivalent to a <code>C/C++ struct</code>; this class confers
- * interoperability between Java classes and C/C++ struct.</p>
- *
- * <p> Unlike <code>C/C++</code>, the storage layout of Java objects is not
- * determined by the compiler. The layout of objects in memory is deferred
- * to run time and determined by the interpreter (or just-in-time compiler).
- * This approach allows for dynamic loading and binding; but also makes
- * interfacing with <code>C/C++</code> code difficult. Hence, this class for
- * which the memory layout is defined by the initialization order of the
- * {@link Struct}'s {@link Member members} and follows the same wordSize
- * rules as <code>C/C++ structs</code>.</p>
- *
- * <p> This class (as well as the {@link Union} sub-class) facilitates:
- * <ul>
- * <li> Memory sharing between Java applications and native libraries.</li>
- * <li> Direct encoding/decoding of streams for which the structure
- * is defined by legacy C/C++ code.</li>
- * <li> Serialization/deserialization of Java objects (complete control,
- * e.g. no class header)</li>
- * <li> Mapping of Java objects to physical addresses (with JNI).</li>
- * </ul></p>
- *
- * <p> Because of its one-to-one mapping, it is relatively easy to convert C
- * header files (e.g. OpenGL bindings) to Java {@link Struct}/{@link Union}
- * using simple text macros. Here is an example of C struct:
- * [code]
- * enum Gender{MALE, FEMALE};
- * struct Date {
- * unsigned short year;
- * unsigned byte month;
- * unsigned byte day;
- * };
- * struct Student {
- * enum Gender gender;
- * char name[64];
- * struct Date birth;
- * float grades[10];
- * Student* next;
- * };[/code]</p>
- * <p> and here is the Java equivalent using this class:
- * [code]
- * public enum Gender { MALE, FEMALE };
- * public static class Date extends Struct {
- * public final Unsigned16 year = new Unsigned16();
- * public final Unsigned8 month = new Unsigned8();
- * public final Unsigned8 day = new Unsigned8();
- * }
- * public static class Student extends Struct {
- * public final Enum32<Gender> gender = new Enum32<Gender>(Gender.values());
- * public final UTF8String name = new UTF8String(64);
- * public final Date birth = inner(new Date());
- * public final Float32[] grades = array(new Float32[10]);
- * public final Reference32<Student> next = new Reference32<Student>();
- * }[/code]</p>
- * <p> Struct's members are directly accessible:
- * [code]
- * Student student = new Student();
- * student.gender.set(Gender.MALE);
- * student.name.set("John Doe"); // Null terminated (C compatible)
- * int age = 2003 - student.birth.year.get();
- * student.grades[2].set(12.5f);
- * student = student.next.get();[/code]</p>
- *
- * <p> Applications can work with the raw {@link #getByteBuffer() bytes}
- * directly. The following illustrate how {@link Struct} can be used to
- * decode/encode UDP messages directly:
- * [code]
- * class UDPMessage extends Struct {
- * Unsigned16 xxx = new Unsigned16();
- * ...
- * }
- * public void run() {
- * byte[] bytes = new byte[1024];
- * DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
- * UDPMessage message = new UDPMessage();
- * message.setByteBuffer(ByteBuffer.wrap(bytes), 0);
- * // packet and message are now two different views of the same data.
- * while (isListening) {
- * multicastSocket.receive(packet);
- * int xxx = message.xxx.get();
- * ... // Process message fields directly.
- * }
- * }[/code]</p>
- *
- * <p> It is relatively easy to map instances of this class to any physical
- * address using
- * <a href="http://java.sun.com/docs/books/tutorial/native1.1/index.html">
- * JNI</a>. Here is an example:
- * [code]
- * import java.nio.ByteBuffer;
- * class Clock extends Struct { // Hardware clock mapped to memory.
- * Unsigned16 seconds = new Unsigned16(5); // unsigned short seconds:5
- * Unsigned16 minutes = new Unsigned16(5); // unsigned short minutes:5
- * Unsigned16 hours = new Unsigned16(4); // unsigned short hours:4
- * Clock() {
- * setByteBuffer(Clock.nativeBuffer(), 0);
- * }
- * private static native ByteBuffer nativeBuffer();
- * }[/code]</p>
- * <p> Below is the <code>nativeBuffer()</code> implementation
- * (<code>Clock.c</code>):
- * [code]
- * #include <jni.h>
- * #include "Clock.h" // Generated using javah
- * JNIEXPORT jobject JNICALL Java_Clock_nativeBuffer (JNIEnv *env, jclass) {
- * return (*env)->NewDirectByteBuffer(env, clock_address, buffer_size)
- * }[/code]</p>
- *
- * <p> Bit-fields are supported (see <code>Clock</code> example above).
- * Bit-fields allocation order is defined by the Struct {@link #byteOrder}
- * return value. Leftmost bit to rightmost bit if
- * <code>BIG_ENDIAN</code> and rightmost bit to leftmost bit if
- * <code>LITTLE_ENDIAN</code> (same layout as Microsoft Visual C++).
- * C/C++ Bit-fields cannot straddle the storage-unit boundary as defined
- * by their base type (padding is inserted at the end of the first bit-field
- * and the second bit-field is put into the next storage unit).
- * It is possible to avoid bit padding by using the {@link BitField}
- * member (or a sub-class). In which case the allocation order is always
- * from the leftmost to the rightmost bit (same as <code>BIG_ENDIAN</code>).
- * </p>
- *
- * <p> Finally, it is possible to change the {@link #setByteBuffer ByteBuffer}
- * and/or the Struct {@link #setByteBufferPosition position} in its
- * <code>ByteBuffer</code> to allow for a single {@link Struct} object to
- * encode/decode multiple memory mapped instances.</p>
- *
- * <p><i>Note: Because Struct/Union are basically wrappers around
- * <code>java.nio.ByteBuffer</code>, tutorials/usages for the
- * Java NIO package are directly applicable to Struct/Union.</i></p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.5.1, April 1, 2010
- */
-@SuppressWarnings("unchecked")
-@Realtime
-public class Struct {
-
- /**
- * Configurable holding the maximum wordSize in bytes
- * (default <code>4</code>). Should be a value greater or equal to 1.
- */
- public static final LocalContext.Parameter<Integer> MAXIMUM_ALIGNMENT = new LocalContext.Parameter<Integer>() {
- @Override
- protected Integer getDefault() {
- return 4;
- }
- };
-
- /**
- * Holds the outer struct if any.
- */
- Struct _outer;
- /**
- * Holds the byte buffer backing the struct (top struct).
- */
- ByteBuffer _byteBuffer;
- /**
- * Holds the offset of this struct relative to the outer struct or
- * to the byte buffer if there is no outer.
- */
- int _outerOffset;
- /**
- * Holds this struct alignment in bytes (largest word size of its members).
- */
- int _alignment = 1;
- /**
- * Holds this struct's length.
- */
- int _length;
- /**
- * Holds the index position during construction.
- * This is the index a the first unused byte available.
- */
- int _index;
- /**
- * Holds the word size during construction (for bit fields).
- * This is the size of the last word used.
- */
- int _wordSize;
- /**
- * Holds the bits used in the word during construction (for bit fields).
- * This is the number of bits used in the last word.
- */
- int _bitsUsed;
- /**
- * Indicates if the index has to be reset for each new field (
- * <code>true</code> only for Union subclasses).
- */
- boolean _resetIndex;
- /**
- * Holds bytes array for Stream I/O when byteBuffer has no intrinsic array.
- */
- byte[] _bytes;
-
- /**
- * Default constructor.
- */
- public Struct() {
- _resetIndex = isUnion();
- }
-
- /**
- * Returns the size in bytes of this struct. The size includes
- * tail padding to satisfy the struct word size requirement
- * (defined by the largest word size of its {@link Member members}).
- *
- * @return the C/C++ <code>sizeof(this)</code>.
- */
- public final int size() {
- return (_alignment <= 1) ? _length
- : ((_length + _alignment - 1) / _alignment) * _alignment;
- }
-
- /**
- * Returns the outer of this struct or <code>null</code> if this struct
- * is not an inner struct.
- *
- * @return the outer struct or <code>null</code>.
- */
- public Struct outer() {
- return _outer;
- }
-
- /**
- * Returns the byte buffer for this struct. This method will allocate
- * a new <b>direct</b> buffer if none has been set.
- *
- * <p> Changes to the buffer's content are visible in this struct,
- * and vice versa.</p>
- * <p> The buffer of an inner struct is the same as its parent struct.</p>
- * <p> If no byte buffer has been {@link Struct#setByteBuffer set},
- * a direct buffer is allocated with a capacity equals to this
- * struct's {@link Struct#size() size}.</p>
- *
- * @return the current byte buffer or a new direct buffer if none set.
- * @see #setByteBuffer
- */
- public final ByteBuffer getByteBuffer() {
- if (_outer != null) return _outer.getByteBuffer();
- return (_byteBuffer != null) ? _byteBuffer : newBuffer();
- }
-
- private synchronized ByteBuffer newBuffer() {
- if (_byteBuffer != null) return _byteBuffer; // Synchronized check.
- ByteBuffer bf = ByteBuffer.allocateDirect(size());
- bf.order(byteOrder());
- setByteBuffer(bf, 0);
- return _byteBuffer;
- }
-
- /**
- * Sets the current byte buffer for this struct.
- * The specified byte buffer can be mapped to memory for direct memory
- * access or can wrap a shared byte array for I/O purpose
- * (e.g. <code>DatagramPacket</code>).
- * The capacity of the specified byte buffer should be at least the
- * {@link Struct#size() size} of this struct plus the offset position.
- *
- * @param byteBuffer the new byte buffer.
- * @param position the position of this struct in the specified byte buffer.
- * @return <code>this</code>
- * @throws IllegalArgumentException if the specified byteBuffer has a
- * different byte order than this struct.
- * @throws UnsupportedOperationException if this struct is an inner struct.
- * @see #byteOrder()
- */
- public final Struct setByteBuffer(ByteBuffer byteBuffer, int position) {
- if (byteBuffer.order() != byteOrder()) throw new IllegalArgumentException(
- "The byte order of the specified byte buffer"
- + " is different from this struct byte order");
- if (_outer != null) throw new UnsupportedOperationException(
- "Inner struct byte buffer is inherited from outer");
- _byteBuffer = byteBuffer;
- _outerOffset = position;
- return this;
- }
-
- /**
- * Sets the byte position of this struct within its byte buffer.
- *
- * @param position the position of this struct in its byte buffer.
- * @return <code>this</code>
- * @throws UnsupportedOperationException if this struct is an inner struct.
- */
- public final Struct setByteBufferPosition(int position) {
- return setByteBuffer(this.getByteBuffer(), position);
- }
-
- /**
- * Returns the absolute byte position of this struct within its associated
- * {@link #getByteBuffer byte buffer}.
- *
- * @return the absolute position of this struct (can be an inner struct)
- * in the byte buffer.
- */
- public final int getByteBufferPosition() {
- return (_outer != null) ? _outer.getByteBufferPosition() + _outerOffset
- : _outerOffset;
- }
-
- /**
- * Reads this struct from the specified input stream
- * (convenience method when using Stream I/O). For better performance,
- * use of Block I/O (e.g. <code>java.nio.channels.*</code>) is recommended.
- * This method behaves appropriately when not all of the data is available
- * from the input stream. Incomplete data is extremely common when the
- * input stream is associated with something like a TCP connection.
- * The typical usage pattern in those scenarios is to repeatedly call
- * read() until the entire message is received.
- *
- * @param in the input stream being read from.
- * @return the number of bytes read (typically the {@link #size() size}
- * of this struct.
- * @throws IOException if an I/O error occurs.
- */
- public int read(InputStream in) throws IOException {
- ByteBuffer buffer = getByteBuffer();
- int size = size();
- int remaining = size - buffer.position();
- if (remaining == 0) remaining = size;// at end so move to beginning
- int alreadyRead = size - remaining; // typically 0
- if (buffer.hasArray()) {
- int offset = buffer.arrayOffset() + getByteBufferPosition();
- int bytesRead = in.read(buffer.array(), offset + alreadyRead,
- remaining);
- buffer.position(getByteBufferPosition() + alreadyRead + bytesRead
- - offset);
- return bytesRead;
- } else {
- synchronized (buffer) {
- if (_bytes == null) {
- _bytes = new byte[size()];
- }
- int bytesRead = in.read(_bytes, 0, remaining);
- buffer.position(getByteBufferPosition() + alreadyRead);
- buffer.put(_bytes, 0, bytesRead);
- return bytesRead;
- }
- }
- }
-
- /**
- * Writes this struct to the specified output stream
- * (convenience method when using Stream I/O). For better performance,
- * use of Block I/O (e.g. <code>java.nio.channels.*</code>) is recommended.
- *
- * @param out the output stream to write to.
- * @throws IOException if an I/O error occurs.
- */
- public void write(OutputStream out) throws IOException {
- ByteBuffer buffer = getByteBuffer();
- if (buffer.hasArray()) {
- int offset = buffer.arrayOffset() + getByteBufferPosition();
- out.write(buffer.array(), offset, size());
- } else {
- synchronized (buffer) {
- if (_bytes == null) {
- _bytes = new byte[size()];
- }
- buffer.position(getByteBufferPosition());
- buffer.get(_bytes);
- out.write(_bytes);
- }
- }
- }
-
- /**
- * Returns this struct address (if supported by the platform).
- * This method allows for structs to be referenced (e.g. pointer)
- * from other structs.
- *
- * @return the struct memory address.
- * @throws UnsupportedOperationException if not supported by the platform.
- * @see Reference32
- * @see Reference64
- */
- public final long address() {
- try {
- Class<?> dbClass = Class.forName("sun.nio.ch.DirectBuffer");
- java.lang.reflect.Method address = dbClass.getDeclaredMethod(
- "address", new Class[0]);
- return ((Long) address.invoke(this.getByteBuffer(),
- (Object[]) null)).longValue();
- } catch (Throwable error) {
- error.printStackTrace();
- throw new UnsupportedOperationException(
- "Method Struct.address() not supported on this platform.");
- }
- }
-
- /**
- * Returns the <code>String</code> representation of this struct
- * in the form of its constituing bytes (hexadecimal). For example:[code]
- * public static class Student extends Struct {
- * Utf8String name = new Utf8String(16);
- * Unsigned16 year = new Unsigned16();
- * Float32 grade = new Float32();
- * }
- * Student student = new Student();
- * student.name.set("John Doe");
- * student.year.set(2003);
- * student.grade.set(12.5f);
- * System.out.println(student);
- *
- * 4A 6F 68 6E 20 44 6F 65 00 00 00 00 00 00 00 00
- * 07 D3 00 00 41 48 00 00[/code]
- *
- * @return a hexadecimal representation of the bytes content for this
- * struct.
- */
- public String toString() {
- TextBuilder tmp = new TextBuilder();
- final int size = size();
- final ByteBuffer buffer = getByteBuffer();
- final int start = getByteBufferPosition();
- for (int i = 0; i < size; i++) {
- int b = buffer.get(start + i) & 0xFF;
- tmp.append(HEXA[b >> 4]);
- tmp.append(HEXA[b & 0xF]);
- tmp.append(((i & 0xF) == 0xF) ? '\n' : ' ');
- }
- return tmp.toString();
- }
-
- private static final char[] HEXA = { '0', '1', '2', '3', '4', '5', '6',
- '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
- ///////////////////
- // CONFIGURATION //
- ///////////////////
- /**
- * Indicates if this struct's members are mapped to the same location
- * in memory (default <code>false</code>). This method is useful for
- * applications extending {@link Struct} with new member types in order to
- * create unions from these new structs. For example:[code]
- * public abstract class FortranStruct extends Struct {
- * public class FortranString extends Member {...}
- * protected FortranString[] array(FortranString[] array, int stringLength) { ... }
- * }
- * public abstract class FortranUnion extends FortranStruct {
- * // Inherits new members and methods.
- * public final isUnion() {
- * return true;
- * }
- * }[/code]
- *
- * @return <code>true</code> if this struct's members are mapped to
- * to the same location in memory; <code>false</code>
- * otherwise.
- * @see Union
- */
- public boolean isUnion() {
- return false;
- }
-
- /**
- * Returns the byte order for this struct (configurable).
- * The byte order is inherited by inner structs. Sub-classes may change
- * the byte order by overriding this method. For example:[code]
- * public class TopStruct extends Struct {
- * ... // Members initialization.
- * public ByteOrder byteOrder() {
- * // TopStruct and its inner structs use hardware byte order.
- * return ByteOrder.nativeOrder();
- * }
- * }}[/code]</p></p>
- *
- * @return the byte order when reading/writing multibyte values
- * (default: network byte order, <code>BIG_ENDIAN</code>).
- */
- public ByteOrder byteOrder() {
- return (_outer != null) ? _outer.byteOrder() : ByteOrder.BIG_ENDIAN;
- }
-
- /**
- * Indicates if this struct is packed (configurable).
- * By default, {@link Member members} of a struct are aligned on the
- * boundary corresponding to the member base type; padding is performed
- * if necessary. This directive is <b>not</b> inherited by inner structs.
- * Sub-classes may change the packing directive by overriding this method.
- * For example:[code]
- * public class MyStruct extends Struct {
- * ... // Members initialization.
- * public boolean isPacked() {
- * return true; // MyStruct is packed.
- * }
- * }}[/code]
- *
- * @return <code>true</code> if word size requirements are ignored.
- * <code>false</code> otherwise (default).
- */
- public boolean isPacked() {
- return false;
- }
-
- /**
- * Defines the specified struct as inner of this struct.
- *
- * @param struct the inner struct.
- * @return the specified struct.
- * @throws IllegalArgumentException if the specified struct is already
- * an inner struct.
- */
- protected <S extends Struct> S inner(S struct) {
- if (struct._outer != null) throw new IllegalArgumentException(
- "struct: Already an inner struct");
- Member inner = new Member(struct.size() << 3, struct._alignment); // Update indexes.
- struct._outer = this;
- struct._outerOffset = inner.offset();
- return (S) struct;
- }
-
- /**
- * Defines the specified array of structs as inner structs.
- * The array is populated if necessary using the struct component
- * default constructor (which must be public).
- *
- * @param structs the struct array.
- * @return the specified struct array.
- * @throws IllegalArgumentException if the specified array contains
- * inner structs.
- */
- protected <S extends Struct> S[] array(S[] structs) {
- Class<?> structClass = null;
- boolean resetIndexSaved = _resetIndex;
- if (_resetIndex) {
- _index = 0;
- _resetIndex = false; // Ensures the array elements are sequential.
- }
- for (int i = 0; i < structs.length;) {
- S struct = structs[i];
- if (struct == null) {
- try {
- if (structClass == null) {
- String arrayName = structs.getClass().getName();
- String structName = arrayName.substring(2,
- arrayName.length() - 1);
- structClass = Class.forName(structName);
- if (structClass == null) { throw new IllegalArgumentException(
- "Struct class: " + structName + " not found"); }
- }
- struct = (S) structClass.newInstance();
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage());
- }
- }
- structs[i++] = inner(struct);
- }
- _resetIndex = resetIndexSaved;
- return (S[]) structs;
- }
-
- /**
- * Defines the specified two-dimensional array of structs as inner
- * structs. The array is populated if necessary using the struct component
- * default constructor (which must be public).
- *
- * @param structs the two dimensional struct array.
- * @return the specified struct array.
- * @throws IllegalArgumentException if the specified array contains
- * inner structs.
- */
- protected <S extends Struct> S[][] array(S[][] structs) {
- boolean resetIndexSaved = _resetIndex;
- if (_resetIndex) {
- _index = 0;
- _resetIndex = false; // Ensures the array elements are sequential.
- }
- for (int i = 0; i < structs.length; i++) {
- array(structs[i]);
- }
- _resetIndex = resetIndexSaved;
- return (S[][]) structs;
- }
-
- /**
- * Defines the specified three dimensional array of structs as inner
- * structs. The array is populated if necessary using the struct component
- * default constructor (which must be public).
- *
- * @param structs the three dimensional struct array.
- * @return the specified struct array.
- * @throws IllegalArgumentException if the specified array contains
- * inner structs.
- */
- protected <S extends Struct> S[][][] array(S[][][] structs) {
- boolean resetIndexSaved = _resetIndex;
- if (_resetIndex) {
- _index = 0;
- _resetIndex = false; // Ensures the array elements are sequential.
- }
- for (int i = 0; i < structs.length; i++) {
- array(structs[i]);
- }
- _resetIndex = resetIndexSaved;
- return (S[][][]) structs;
- }
-
- /**
- * Defines the specified array member. For predefined members,
- * the array is populated when empty; custom members should use
- * literal (populated) arrays.
- *
- * @param arrayMember the array member.
- * @return the specified array member.
- * @throws UnsupportedOperationException if the specified array
- * is empty and the member type is unknown.
- */
- protected <M extends Member> M[] array(M[] arrayMember) {
- boolean resetIndexSaved = _resetIndex;
- if (_resetIndex) {
- _index = 0;
- _resetIndex = false; // Ensures the array elements are sequential.
- }
- if (BOOL.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Bool();
- }
- } else if (SIGNED_8.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Signed8();
- }
- } else if (UNSIGNED_8.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Unsigned8();
- }
- } else if (SIGNED_16.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Signed16();
- }
- } else if (UNSIGNED_16.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Unsigned16();
- }
- } else if (SIGNED_32.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Signed32();
- }
- } else if (UNSIGNED_32.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Unsigned32();
- }
- } else if (SIGNED_64.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Signed64();
- }
- } else if (FLOAT_32.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Float32();
- }
- } else if (FLOAT_64.isInstance(arrayMember)) {
- for (int i = 0; i < arrayMember.length;) {
- arrayMember[i++] = (M) this.new Float64();
- }
- } else {
- throw new UnsupportedOperationException(
- "Cannot create member elements, the arrayMember should "
- + "contain the member instances instead of null");
- }
- _resetIndex = resetIndexSaved;
- return (M[]) arrayMember;
- }
-
- private static final Class<? extends Bool[]> BOOL = new Bool[0].getClass();
- private static final Class<? extends Signed8[]> SIGNED_8 = new Signed8[0]
- .getClass();
- private static final Class<? extends Unsigned8[]> UNSIGNED_8 = new Unsigned8[0]
- .getClass();
- private static final Class<? extends Signed16[]> SIGNED_16 = new Signed16[0]
- .getClass();
- private static final Class<? extends Unsigned16[]> UNSIGNED_16 = new Unsigned16[0]
- .getClass();
- private static final Class<? extends Signed32[]> SIGNED_32 = new Signed32[0]
- .getClass();
- private static final Class<? extends Unsigned32[]> UNSIGNED_32 = new Unsigned32[0]
- .getClass();
- private static final Class<? extends Signed64[]> SIGNED_64 = new Signed64[0]
- .getClass();
- private static final Class<? extends Float32[]> FLOAT_32 = new Float32[0]
- .getClass();
- private static final Class<? extends Float64[]> FLOAT_64 = new Float64[0]
- .getClass();
-
- /**
- * Defines the specified two-dimensional array member. For predefined
- * members, the array is populated when empty; custom members should use
- * literal (populated) arrays.
- *
- * @param arrayMember the two-dimensional array member.
- * @return the specified array member.
- * @throws UnsupportedOperationException if the specified array
- * is empty and the member type is unknown.
- */
- protected <M extends Member> M[][] array(M[][] arrayMember) {
- boolean resetIndexSaved = _resetIndex;
- if (_resetIndex) {
- _index = 0;
- _resetIndex = false; // Ensures the array elements are sequential.
- }
- for (int i = 0; i < arrayMember.length; i++) {
- array(arrayMember[i]);
- }
- _resetIndex = resetIndexSaved;
- return (M[][]) arrayMember;
- }
-
- /**
- * Defines the specified three-dimensional array member. For predefined
- * members, the array is populated when empty; custom members should use
- * literal (populated) arrays.
- *
- * @param arrayMember the three-dimensional array member.
- * @return the specified array member.
- * @throws UnsupportedOperationException if the specified array
- * is empty and the member type is unknown.
- */
- protected <M extends Member> M[][][] array(M[][][] arrayMember) {
- boolean resetIndexSaved = _resetIndex;
- if (_resetIndex) {
- _index = 0;
- _resetIndex = false; // Ensures the array elements are sequential.
- }
- for (int i = 0; i < arrayMember.length; i++) {
- array(arrayMember[i]);
- }
- _resetIndex = resetIndexSaved;
- return (M[][][]) arrayMember;
- }
-
- /**
- * Defines the specified array of UTF-8 strings, all strings having the
- * specified length (convenience method).
- *
- * @param array the string array.
- * @param stringLength the length of the string elements.
- * @return the specified string array.
- */
- protected UTF8String[] array(UTF8String[] array, int stringLength) {
- boolean resetIndexSaved = _resetIndex;
- if (_resetIndex) {
- _index = 0;
- _resetIndex = false; // Ensures the array elements are sequential.
- }
- for (int i = 0; i < array.length; i++) {
- array[i] = new UTF8String(stringLength);
- }
- _resetIndex = resetIndexSaved;
- return array;
- }
-
- /**
- * Reads the specified bits from this Struct as an long (signed) integer
- * value.
- *
- * @param bitOffset the bit start position in the Struct.
- * @param bitSize the number of bits.
- * @return the specified bits read as a signed long.
- * @throws IllegalArgumentException if
- * <code>(bitOffset + bitSize - 1) / 8 >= this.size()</code>
- */
- public long readBits(int bitOffset, int bitSize) {
- if ((bitOffset + bitSize - 1) >> 3 >= this.size()) throw new IllegalArgumentException(
- "Attempt to read outside the Struct");
- int offset = bitOffset >> 3;
- int bitStart = bitOffset - (offset << 3);
- bitStart = (byteOrder() == ByteOrder.BIG_ENDIAN) ? bitStart : 64
- - bitSize - bitStart;
- int index = getByteBufferPosition() + offset;
- long value = readByteBufferLong(index);
- value <<= bitStart; // Clears preceding bits.
- value >>= (64 - bitSize); // Signed shift.
- return value;
- }
-
- private long readByteBufferLong(int index) {
- ByteBuffer byteBuffer = getByteBuffer();
- if (index + 8 < byteBuffer.limit()) return byteBuffer.getLong(index);
- // Else possible buffer overflow.
- if (byteBuffer.order() == ByteOrder.LITTLE_ENDIAN) {
- return (readByte(index, byteBuffer) & 0xff)
- + ((readByte(++index, byteBuffer) & 0xff) << 8)
- + ((readByte(++index, byteBuffer) & 0xff) << 16)
- + ((readByte(++index, byteBuffer) & 0xffL) << 24)
- + ((readByte(++index, byteBuffer) & 0xffL) << 32)
- + ((readByte(++index, byteBuffer) & 0xffL) << 40)
- + ((readByte(++index, byteBuffer) & 0xffL) << 48)
- + ((readByte(++index, byteBuffer) & 0xffL) << 56);
- } else {
- return (((long) readByte(index, byteBuffer)) << 56)
- + ((readByte(++index, byteBuffer) & 0xffL) << 48)
- + ((readByte(++index, byteBuffer) & 0xffL) << 40)
- + ((readByte(++index, byteBuffer) & 0xffL) << 32)
- + ((readByte(++index, byteBuffer) & 0xffL) << 24)
- + ((readByte(++index, byteBuffer) & 0xff) << 16)
- + ((readByte(++index, byteBuffer) & 0xff) << 8)
- + (readByte(++index, byteBuffer) & 0xffL);
- }
- }
-
- private static byte readByte(int index, ByteBuffer byteBuffer) {
- return (index < byteBuffer.limit()) ? byteBuffer.get(index) : 0;
- }
-
- /**
- * Writes the specified bits into this Struct.
- *
- * @param value the bits value as a signed long.
- * @param bitOffset the bit start position in the Struct.
- * @param bitSize the number of bits.
- * @throws IllegalArgumentException if
- * <code>(bitOffset + bitSize - 1) / 8 >= this.size()</code>
- */
- public void writeBits(long value, int bitOffset, int bitSize) {
- if ((bitOffset + bitSize - 1) >> 3 >= this.size()) throw new IllegalArgumentException(
- "Attempt to write outside the Struct");
- int offset = bitOffset >> 3;
- int bitStart = (byteOrder() == ByteOrder.BIG_ENDIAN) ? bitOffset
- - (offset << 3) : 64 - bitSize - (bitOffset - (offset << 3));
- long mask = -1L;
- mask <<= bitStart; // Clears preceding bits
- mask >>>= (64 - bitSize); // Unsigned shift.
- mask <<= 64 - bitSize - bitStart;
- value <<= (64 - bitSize - bitStart);
- value &= mask; // Protects against out of range values.
- int index = getByteBufferPosition() + offset;
- long oldValue = readByteBufferLong(index);
- long resetValue = oldValue & (~mask);
- long newValue = resetValue | value;
- writeByteBufferLong(index, newValue);
- }
-
- private void writeByteBufferLong(int index, long value) {
- ByteBuffer byteBuffer = getByteBuffer();
- if (index + 8 < byteBuffer.limit()) {
- byteBuffer.putLong(index, value);
- return;
- }
- // Else possible buffer overflow.
- if (byteBuffer.order() == ByteOrder.LITTLE_ENDIAN) {
- writeByte(index, byteBuffer, (byte) value);
- writeByte(++index, byteBuffer, (byte) (value >> 8));
- writeByte(++index, byteBuffer, (byte) (value >> 16));
- writeByte(++index, byteBuffer, (byte) (value >> 24));
- writeByte(++index, byteBuffer, (byte) (value >> 32));
- writeByte(++index, byteBuffer, (byte) (value >> 40));
- writeByte(++index, byteBuffer, (byte) (value >> 48));
- writeByte(++index, byteBuffer, (byte) (value >> 56));
- } else {
- writeByte(index, byteBuffer, (byte) (value >> 56));
- writeByte(++index, byteBuffer, (byte) (value >> 48));
- writeByte(++index, byteBuffer, (byte) (value >> 40));
- writeByte(++index, byteBuffer, (byte) (value >> 32));
- writeByte(++index, byteBuffer, (byte) (value >> 24));
- writeByte(++index, byteBuffer, (byte) (value >> 16));
- writeByte(++index, byteBuffer, (byte) (value >> 8));
- writeByte(++index, byteBuffer, (byte) value);
- }
- }
-
- private static void writeByte(int index, ByteBuffer byteBuffer, byte value) {
- if (index < byteBuffer.limit()) {
- byteBuffer.put(index, value);
- }
- }
-
- /////////////
- // MEMBERS //
- /////////////
- /**
- * This inner class represents the base class for all {@link Struct}
- * members. It allows applications to define additional member types.
- * For example:[code]
- * public class MyStruct extends Struct {
- * BitSet bits = new BitSet(256);
- * ...
- * public BitSet extends Member {
- * public BitSet(int nbrBits) {
- * super(nbrBits, 0); // Direct bit access.
- * }
- * public boolean get(int i) { ... }
- * public void set(int i, boolean value) { ...}
- * }
- * }[/code]
- */
- protected class Member {
-
- /**
- * Holds the relative offset (in bytes) of this member within its struct.
- */
- private final int _offset;
- /**
- * Holds the relative bit offset of this member to its struct offset.
- */
- private final int _bitIndex;
- /**
- * Holds the bit length of this member.
- */
- private final int _bitLength;
-
- /**
- * Base constructor for custom member types.
- *
- * The word size can be zero, in which case the {@link #offset}
- * of the member does not change, only {@link #bitIndex} is
- * incremented.
- *
- * @param bitLength the number of bits or <code>0</code>
- * to force next member on next word boundary.
- * @param wordSize the word size in bytes used when accessing
- * this member data or <code>0</code> if the data is accessed
- * at the bit level.
- */
- protected Member(int bitLength, int wordSize) {
- _bitLength = bitLength;
-
- // Resets index if union.
- if (_resetIndex) {
- _index = 0;
- }
-
- // Check if we can merge bitfields (always true if no word boundary).
- if ((wordSize == 0)
- || ((bitLength != 0) && (wordSize == _wordSize) && ((_bitsUsed + bitLength) <= (wordSize << 3)))) {
-
- _offset = _index - _wordSize;
- _bitIndex = _bitsUsed;
- _bitsUsed += bitLength;
-
- // Straddling word boundary only possible if (wordSize == 0)
- while (_bitsUsed > (_wordSize << 3)) {
- _index++;
- _wordSize++;
- _length = MathLib.max(_length, _index);
- }
- return; // Bit field merge done.
- }
-
- // Check alignment.
- if (!isPacked()) {
-
- // Updates struct's alignment constraint, based on largest word size.
- if ((_alignment < wordSize)) {
- _alignment = wordSize;
- }
-
- // Adds padding if misaligned.
- int misaligned = _index % wordSize;
- if (misaligned != 0) {
- _index += wordSize - misaligned;
- }
- }
-
- // Sets member indices.
- _offset = _index;
- _bitIndex = 0;
-
- // Update struct indices.
- _index += MathLib.max(wordSize, (bitLength + 7) >> 3);
- _wordSize = wordSize;
- _bitsUsed = bitLength;
- _length = MathLib.max(_length, _index);
- // size and index may differ because of {@link Union}
- }
-
- /**
- * Returns the outer {@link Struct struct} container.
- *
- * @return the outer struct.
- */
- public final Struct struct() {
- return Struct.this;
- }
-
- /**
- * Returns the byte offset of this member in its struct.
- * Equivalent to C/C++ <code>offsetof(struct(), this)</code>
- *
- * @return the offset of this member in the Struct.
- */
- public final int offset() {
- return _offset;
- }
-
- /**
- * Holds the bit offset of this member (if any).
- * The actual position of the bits data depends upon the endianess and
- * the word size.
- */
- public final int bitIndex() {
- return _bitIndex;
- }
-
- /**
- * Returns the number of bits in this member. Can be zero if this
- * member is used to force the next member to the next word boundary.
- *
- * @return the number of bits in the member.
- */
- public final int bitLength() {
- return _bitLength;
- }
-
- // Returns the member int value.
- final int get(int wordSize, int word) {
- final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
- - bitIndex() - bitLength()
- : bitIndex();
- word >>= shift;
- int mask = 0xFFFFFFFF >>> (32 - bitLength());
- return word & mask;
- }
-
- // Sets the member int value.
- final int set(int value, int wordSize, int word) {
- final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
- - bitIndex() - bitLength()
- : bitIndex();
- int mask = 0xFFFFFFFF >>> (32 - bitLength());
- mask <<= shift;
- value <<= shift;
- return (word & ~mask) | (value & mask);
- }
-
- // Returns the member long value.
- final long get(int wordSize, long word) {
- final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
- - bitIndex() - bitLength()
- : bitIndex();
- word >>= shift;
- long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
- return word & mask;
- }
-
- // Sets the member long value.
- final long set(long value, int wordSize, long word) {
- final int shift = (byteOrder() == ByteOrder.BIG_ENDIAN) ? (wordSize << 3)
- - bitIndex() - bitLength()
- : bitIndex();
- long mask = 0xFFFFFFFFFFFFFFFFL >>> (64 - bitLength());
- mask <<= shift;
- value <<= shift;
- return (word & ~mask) | (value & mask);
- }
- }
-
- ///////////////////////
- // PREDEFINED FIELDS //
- ///////////////////////
- /**
- * This class represents a UTF-8 character string, null terminated
- * (for C/C++ compatibility)
- */
- public class UTF8String extends Member {
-
- private final UTF8ByteBufferWriter _writer = new UTF8ByteBufferWriter();
- private final UTF8ByteBufferReader _reader = new UTF8ByteBufferReader();
- private final int _length;
-
- public UTF8String(int length) {
- super(length << 3, 1);
- _length = length; // Takes into account 0 terminator.
- }
-
- public void set(String string) {
- final ByteBuffer buffer = getByteBuffer();
- synchronized (buffer) {
- try {
- int index = getByteBufferPosition() + offset();
- buffer.position(index);
- _writer.setOutput(buffer);
- if (string.length() < _length) {
- _writer.write(string);
- _writer.write(0); // Marks end of string.
- } else if (string.length() > _length) { // Truncates.
- _writer.write(string.substring(0, _length));
- } else { // Exact same length.
- _writer.write(string);
- }
- } catch (IOException e) { // Should never happen.
- throw new Error(e.getMessage());
- } finally {
- _writer.reset();
- }
- }
- }
-
- public String get() {
- final ByteBuffer buffer = getByteBuffer();
- synchronized (buffer) {
- TextBuilder tmp = new TextBuilder();
- try {
- int index = getByteBufferPosition() + offset();
- buffer.position(index);
- _reader.setInput(buffer);
- for (int i = 0; i < _length; i++) {
- char c = (char) _reader.read();
- if (c == 0) { // Null terminator.
- return tmp.toString();
- } else {
- tmp.append(c);
- }
- }
- return tmp.toString();
- } catch (IOException e) { // Should never happen.
- throw new Error(e.getMessage());
- } finally {
- _reader.reset();
- }
- }
- }
-
- public String toString() {
- return this.get();
- }
- }
-
- /**
- * This class represents a 8 bits boolean with <code>true</code> represented
- * by <code>1</code> and <code>false</code> represented by <code>0</code>.
- */
- public class Bool extends Member {
-
- public Bool() {
- super(8, 1);
- }
-
- public Bool(int nbrOfBits) {
- super(nbrOfBits, 1);
- }
-
- public boolean get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().get(index);
- word = (bitLength() == 8) ? word : get(1, word);
- return word != 0;
- }
-
- public void set(boolean value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 8) {
- getByteBuffer().put(index, (byte) (value ? -1 : 0));
- } else {
- getByteBuffer().put(
- index,
- (byte) set(value ? -1 : 0, 1, getByteBuffer()
- .get(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 8 bits signed integer.
- */
- public class Signed8 extends Member {
-
- public Signed8() {
- super(8, 1);
- }
-
- public Signed8(int nbrOfBits) {
- super(nbrOfBits, 1);
- }
-
- public byte get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().get(index);
- return (byte) ((bitLength() == 8) ? word : get(1, word));
- }
-
- public void set(byte value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 8) {
- getByteBuffer().put(index, value);
- } else {
- getByteBuffer().put(index,
- (byte) set(value, 1, getByteBuffer().get(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 8 bits unsigned integer.
- */
- public class Unsigned8 extends Member {
-
- public Unsigned8() {
- super(8, 1);
- }
-
- public Unsigned8(int nbrOfBits) {
- super(nbrOfBits, 1);
- }
-
- public short get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().get(index);
- return (short) (0xFF & ((bitLength() == 8) ? word : get(1, word)));
- }
-
- public void set(short value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 8) {
- getByteBuffer().put(index, (byte) value);
- } else {
- getByteBuffer().put(index,
- (byte) set(value, 1, getByteBuffer().get(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 16 bits signed integer.
- */
- public class Signed16 extends Member {
-
- public Signed16() {
- super(16, 2);
- }
-
- public Signed16(int nbrOfBits) {
- super(nbrOfBits, 2);
- }
-
- public short get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getShort(index);
- return (short) ((bitLength() == 16) ? word : get(2, word));
- }
-
- public void set(short value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 16) {
- getByteBuffer().putShort(index, value);
- } else {
- getByteBuffer().putShort(index,
- (short) set(value, 2, getByteBuffer().getShort(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 16 bits unsigned integer.
- */
- public class Unsigned16 extends Member {
-
- public Unsigned16() {
- super(16, 2);
- }
-
- public Unsigned16(int nbrOfBits) {
- super(nbrOfBits, 2);
- }
-
- public int get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getShort(index);
- return 0xFFFF & ((bitLength() == 16) ? word : get(2, word));
- }
-
- public void set(int value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 16) {
- getByteBuffer().putShort(index, (short) value);
- } else {
- getByteBuffer().putShort(index,
- (short) set(value, 2, getByteBuffer().getShort(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 32 bits signed integer.
- */
- public class Signed32 extends Member {
-
- public Signed32() {
- super(32, 4);
- }
-
- public Signed32(int nbrOfBits) {
- super(nbrOfBits, 4);
- }
-
- public int get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getInt(index);
- return (bitLength() == 32) ? word : get(4, word);
- }
-
- public void set(int value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 32) {
- getByteBuffer().putInt(index, value);
- } else {
- getByteBuffer().putInt(index,
- set(value, 4, getByteBuffer().getInt(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 32 bits unsigned integer.
- */
- public class Unsigned32 extends Member {
-
- public Unsigned32() {
- super(32, 4);
- }
-
- public Unsigned32(int nbrOfBits) {
- super(nbrOfBits, 4);
- }
-
- public long get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getInt(index);
- return 0xFFFFFFFFL & ((bitLength() == 32) ? word : get(4, word));
- }
-
- public void set(long value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 32) {
- getByteBuffer().putInt(index, (int) value);
- } else {
- getByteBuffer().putInt(index,
- set((int) value, 4, getByteBuffer().getInt(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 64 bits signed integer.
- */
- public class Signed64 extends Member {
-
- public Signed64() {
- super(64, 8);
- }
-
- public Signed64(int nbrOfBits) {
- super(nbrOfBits, 8);
- }
-
- public long get() {
- final int index = getByteBufferPosition() + offset();
- long word = getByteBuffer().getLong(index);
- return (bitLength() == 64) ? word : get(8, word);
- }
-
- public void set(long value) {
- final int index = getByteBufferPosition() + offset();
- if (bitLength() == 64) {
- getByteBuffer().putLong(index, value);
- } else {
- getByteBuffer().putLong(index,
- set(value, 8, getByteBuffer().getLong(index)));
- }
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents an arbitrary size (unsigned) bit field with
- * no word size constraint (they can straddle words boundaries).
- */
- public class BitField extends Member {
-
- public BitField(int nbrOfBits) {
- super(nbrOfBits, 0);
- }
-
- public long longValue() {
- long signedValue = readBits(bitIndex() + (offset() << 3),
- bitLength());
- return ~(-1L << bitLength()) & signedValue;
- }
-
- public int intValue() {
- return (int) longValue();
- }
-
- public short shortValue() {
- return (short) longValue();
- }
-
- public byte byteValue() {
- return (byte) longValue();
- }
-
- public void set(long value) {
- writeBits(value, bitIndex() + (offset() << 3), bitLength());
- }
-
- public String toString() {
- return String.valueOf(longValue());
- }
- }
-
- /**
- * This class represents a 32 bits float (C/C++/Java <code>float</code>).
- */
- public class Float32 extends Member {
-
- public Float32() {
- super(32, 4);
- }
-
- public float get() {
- final int index = getByteBufferPosition() + offset();
- return getByteBuffer().getFloat(index);
- }
-
- public void set(float value) {
- final int index = getByteBufferPosition() + offset();
- getByteBuffer().putFloat(index, value);
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 64 bits float (C/C++/Java <code>double</code>).
- */
- public class Float64 extends Member {
-
- public Float64() {
- super(64, 8);
- }
-
- public double get() {
- final int index = getByteBufferPosition() + offset();
- return getByteBuffer().getDouble(index);
- }
-
- public void set(double value) {
- final int index = getByteBufferPosition() + offset();
- getByteBuffer().putDouble(index, value);
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * <p> This class represents a 32 bits reference (C/C++ pointer) to
- * a {@link Struct} object (other types may require a {@link Struct}
- * wrapper).</p>
- * <p> Note: For references which can be externally modified, an application
- * may want to check the {@link #isUpToDate up-to-date} status of
- * the reference. For out-of-date references, a {@link Struct}
- * can be created at the address specified by {@link #value}
- * (using JNI) and the reference {@link #set set} accordingly.</p>
- */
- public class Reference32<S extends Struct> extends Member {
-
- private S _struct;
-
- public Reference32() {
- super(32, 4);
- }
-
- public void set(S struct) {
- final int index = getByteBufferPosition() + offset();
- if (struct != null) {
- getByteBuffer().putInt(index, (int) struct.address());
- } else {
- getByteBuffer().putInt(index, 0);
- }
- _struct = struct;
- }
-
- public S get() {
- return _struct;
- }
-
- public int value() {
- final int index = getByteBufferPosition() + offset();
- return getByteBuffer().getInt(index);
- }
-
- public boolean isUpToDate() {
- final int index = getByteBufferPosition() + offset();
- if (_struct != null) {
- return getByteBuffer().getInt(index) == (int) _struct.address();
- } else {
- return getByteBuffer().getInt(index) == 0;
- }
- }
- }
-
- /**
- * <p> This class represents a 64 bits reference (C/C++ pointer) to
- * a {@link Struct} object (other types may require a {@link Struct}
- * wrapper).</p>
- * <p> Note: For references which can be externally modified, an application
- * may want to check the {@link #isUpToDate up-to-date} status of
- * the reference. For out-of-date references, a new {@link Struct}
- * can be created at the address specified by {@link #value}
- * (using JNI) and then {@link #set set} to the reference.</p>
- */
- public class Reference64<S extends Struct> extends Member {
-
- private S _struct;
-
- public Reference64() {
- super(64, 8);
- }
-
- public void set(S struct) {
- final int index = getByteBufferPosition() + offset();
- if (struct != null) {
- getByteBuffer().putLong(index, struct.address());
- } else if (struct == null) {
- getByteBuffer().putLong(index, 0L);
- }
- _struct = struct;
- }
-
- public S get() {
- return _struct;
- }
-
- public long value() {
- final int index = getByteBufferPosition() + offset();
- return getByteBuffer().getLong(index);
- }
-
- public boolean isUpToDate() {
- final int index = getByteBufferPosition() + offset();
- if (_struct != null) {
- return getByteBuffer().getLong(index) == _struct.address();
- } else {
- return getByteBuffer().getLong(index) == 0L;
- }
- }
- }
-
- /**
- * This class represents a 8 bits {@link Enum}.
- */
- public class Enum8<T extends Enum<T>> extends Member {
-
- private final T[] _values;
-
- public Enum8(T[] values) {
- super(8, 1);
- _values = values;
- }
-
- public Enum8(T[] values, int nbrOfBits) {
- super(nbrOfBits, 1);
- _values = values;
- }
-
- public T get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().get(index);
- return _values[0xFF & get(1, word)];
- }
-
- public void set(T e) {
- int value = e.ordinal();
- if (_values[value] != e) throw new IllegalArgumentException(
- "enum: "
- + e
- + ", ordinal value does not reflect enum values position");
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().get(index);
- getByteBuffer().put(index, (byte) set(value, 1, word));
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 16 bits {@link Enum}.
- */
- public class Enum16<T extends Enum<T>> extends Member {
-
- private final T[] _values;
-
- public Enum16(T[] values) {
- super(16, 2);
- _values = values;
- }
-
- public Enum16(T[] values, int nbrOfBits) {
- super(nbrOfBits, 2);
- _values = values;
- }
-
- public T get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getShort(index);
- return _values[0xFFFF & get(2, word)];
- }
-
- public void set(T e) {
- int value = e.ordinal();
- if (_values[value] != e) throw new IllegalArgumentException(
- "enum: "
- + e
- + ", ordinal value does not reflect enum values position");
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getShort(index);
- getByteBuffer().putShort(index, (short) set(value, 2, word));
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 32 bits {@link Enum}.
- */
- public class Enum32<T extends Enum<T>> extends Member {
-
- private final T[] _values;
-
- public Enum32(T[] values) {
- super(32, 4);
- _values = values;
- }
-
- public Enum32(T[] values, int nbrOfBits) {
- super(nbrOfBits, 4);
- _values = values;
- }
-
- public T get() {
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getInt(index);
- return _values[get(4, word)];
- }
-
- public void set(T e) {
- int value = e.ordinal();
- if (_values[value] != e) throw new IllegalArgumentException(
- "enum: "
- + e
- + ", ordinal value does not reflect enum values position");
- final int index = getByteBufferPosition() + offset();
- int word = getByteBuffer().getInt(index);
- getByteBuffer().putInt(index, set(value, 4, word));
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-
- /**
- * This class represents a 64 bits {@link Enum}.
- */
- public class Enum64<T extends Enum<T>> extends Member {
-
- private final T[] _values;
-
- public Enum64(T[] values) {
- super(64, 8);
- _values = values;
- }
-
- public Enum64(T[] values, int nbrOfBits) {
- super(nbrOfBits, 8);
- _values = values;
- }
-
- public T get() {
- final int index = getByteBufferPosition() + offset();
- long word = getByteBuffer().getLong(index);
- return _values[(int) get(8, word)];
- }
-
- public void set(T e) {
- long value = e.ordinal();
- if (_values[(int) value] != e) throw new IllegalArgumentException(
- "enum: "
- + e
- + ", ordinal value does not reflect enum values position");
- final int index = getByteBufferPosition() + offset();
- long word = getByteBuffer().getLong(index);
- getByteBuffer().putLong(index, set(value, 8, word));
- }
-
- public String toString() {
- return String.valueOf(this.get());
- }
- }
-}
[02/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java
deleted file mode 100644
index 31cf51b..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReader.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.sax;
-
-import java.io.IOException;
-import org.xml.sax.DTDHandler;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
-
-/**
- * SAX2-like interface for reading an XML document using callbacks.
- *
- * @author David Megginson
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, June 16, 2005
- * @see <a href="http://www.saxproject.org"> SAX -- Simple API for XML</a>
- */
-public interface XMLReader {
-
- /**
- * Look up the value of a feature flag.
- *
- * <p>The feature name is any fully-qualified URI. It is
- * possible for an XMLReader to recognize a feature name but
- * temporarily be unable to return its value.
- * Some feature values may be available only in specific
- * contexts, such as before, during, or after a parse.
- * Also, some feature values may not be programmatically accessible.
- * (In the case of an adapter for SAX1 {@link org.xml.sax.Parser}, there
- * is no implementation-independent way to expose whether the underlying
- * parser is performing validation, expanding external entities,
- * and so forth.) </p>
- *
- * <p>All XMLReaders are required to recognize the
- * http://xml.org/sax/features/namespaces and the
- * http://xml.org/sax/features/namespace-prefixes feature names.</p>
- *
- * <p>Typical usage is something like this:</p>
- *
- * <pre>
- * XMLReader r = new MySAXDriver();
- *
- * // try to activate validation
- * try {
- * r.setFeature("http://xml.org/sax/features/validation", true);
- * } catch (SAXException e) {
- * System.err.println("Cannot activate validation.");
- * }
- *
- * // register event handlers
- * r.setContentHandler(new MyContentHandler());
- * r.setErrorHandler(new MyErrorHandler());
- *
- * // parse the first document
- * try {
- * r.parse("http://www.foo.com/mydoc.xml");
- * } catch (IOException e) {
- * System.err.println("I/O exception reading XML document");
- * } catch (SAXException e) {
- * System.err.println("XML exception reading document.");
- * }
- * </pre>
- *
- * <p>Implementors are free (and encouraged) to invent their own features,
- * using names built on their own URIs.</p>
- *
- * @param name The feature name, which is a fully-qualified URI.
- * @return The current value of the feature (true or false).
- * @exception org.xml.sax.SAXNotRecognizedException If the feature
- * value can't be assigned or retrieved.
- * @exception org.xml.sax.SAXNotSupportedException When the
- * XMLReader recognizes the feature name but
- * cannot determine its value at this time.
- * @see #setFeature
- */
- public boolean getFeature(String name) throws SAXNotRecognizedException,
- SAXNotSupportedException;
-
- /**
- * Set the value of a feature flag.
- *
- * <p>The feature name is any fully-qualified URI. It is
- * possible for an XMLReader to expose a feature value but
- * to be unable to change the current value.
- * Some feature values may be immutable or mutable only
- * in specific contexts, such as before, during, or after
- * a parse.</p>
- *
- * <p>All XMLReaders are required to support setting
- * http://xml.org/sax/features/namespaces to true and
- * http://xml.org/sax/features/namespace-prefixes to false.</p>
- *
- * @param name The feature name, which is a fully-qualified URI.
- * @param value The requested value of the feature (true or false).
- * @exception org.xml.sax.SAXNotRecognizedException If the feature
- * value can't be assigned or retrieved.
- * @exception org.xml.sax.SAXNotSupportedException When the
- * XMLReader recognizes the feature name but
- * cannot set the requested value.
- * @see #getFeature
- */
- public void setFeature(String name, boolean value)
- throws SAXNotRecognizedException, SAXNotSupportedException;
-
- /**
- * Look up the value of a property.
- *
- * <p>The property name is any fully-qualified URI. It is
- * possible for an XMLReader to recognize a property name but
- * temporarily be unable to return its value.
- * Some property values may be available only in specific
- * contexts, such as before, during, or after a parse.</p>
- *
- * <p>XMLReaders are not required to recognize any specific
- * property names, though an initial core set is documented for
- * SAX2.</p>
- *
- * <p>Implementors are free (and encouraged) to invent their own properties,
- * using names built on their own URIs.</p>
- *
- * @param name The property name, which is a fully-qualified URI.
- * @return The current value of the property.
- * @exception org.xml.sax.SAXNotRecognizedException If the property
- * value can't be assigned or retrieved.
- * @exception org.xml.sax.SAXNotSupportedException When the
- * XMLReader recognizes the property name but
- * cannot determine its value at this time.
- * @see #setProperty
- */
- public Object getProperty(String name) throws SAXNotRecognizedException,
- SAXNotSupportedException;
-
- /**
- * Set the value of a property.
- *
- * <p>The property name is any fully-qualified URI. It is
- * possible for an XMLReader to recognize a property name but
- * to be unable to change the current value.
- * Some property values may be immutable or mutable only
- * in specific contexts, such as before, during, or after
- * a parse.</p>
- *
- * <p>XMLReaders are not required to recognize setting
- * any specific property names, though a core set is defined by
- * SAX2.</p>
- *
- * <p>This method is also the standard mechanism for setting
- * extended handlers.</p>
- *
- * @param name The property name, which is a fully-qualified URI.
- * @param value The requested value for the property.
- * @exception org.xml.sax.SAXNotRecognizedException If the property
- * value can't be assigned or retrieved.
- * @exception org.xml.sax.SAXNotSupportedException When the
- * XMLReader recognizes the property name but
- * cannot set the requested value.
- */
- public void setProperty(String name, Object value)
- throws SAXNotRecognizedException, SAXNotSupportedException;
-
- ////////////////////////////////////////////////////////////////////
- // Event handlers.
- ////////////////////////////////////////////////////////////////////
-
- /**
- * Allow an application to register an entity resolver.
- *
- * <p>If the application does not register an entity resolver,
- * the XMLReader will perform its own default resolution.</p>
- *
- * <p>Applications may register a new or different resolver in the
- * middle of a parse, and the SAX parser must begin using the new
- * resolver immediately.</p>
- *
- * @param resolver The entity resolver.
- * @see #getEntityResolver
- */
- public void setEntityResolver(EntityResolver resolver);
-
- /**
- * Return the current entity resolver.
- *
- * @return The current entity resolver, or null if none
- * has been registered.
- * @see #setEntityResolver
- */
- public EntityResolver getEntityResolver();
-
- /**
- * Allow an application to register a DTD event handler.
- *
- * <p>If the application does not register a DTD handler, all DTD
- * events reported by the SAX parser will be silently ignored.</p>
- *
- * <p>Applications may register a new or different handler in the
- * middle of a parse, and the SAX parser must begin using the new
- * handler immediately.</p>
- *
- * @param handler The DTD handler.
- * @see #getDTDHandler
- */
- public void setDTDHandler(DTDHandler handler);
-
- /**
- * Return the current DTD handler.
- *
- * @return The current DTD handler, or null if none
- * has been registered.
- * @see #setDTDHandler
- */
- public DTDHandler getDTDHandler();
-
- /**
- * Allow an application to register a content event handler.
- *
- * <p>If the application does not register a content handler, all
- * content events reported by the SAX parser will be silently
- * ignored.</p>
- *
- * <p>Applications may register a new or different handler in the
- * middle of a parse, and the SAX parser must begin using the new
- * handler immediately.</p>
- *
- * @param handler The content handler.
- * @see #getContentHandler
- */
- public void setContentHandler(ContentHandler handler);
-
- /**
- * Return the current content handler.
- *
- * @return The current content handler, or null if none
- * has been registered.
- * @see #setContentHandler
- */
- public ContentHandler getContentHandler();
-
- /**
- * Allow an application to register an error event handler.
- *
- * <p>If the application does not register an error handler, all
- * error events reported by the SAX parser will be silently
- * ignored; however, normal processing may not continue. It is
- * highly recommended that all SAX applications implement an
- * error handler to avoid unexpected bugs.</p>
- *
- * <p>Applications may register a new or different handler in the
- * middle of a parse, and the SAX parser must begin using the new
- * handler immediately.</p>
- *
- * @param handler The error handler.
- * @see #getErrorHandler
- */
- public void setErrorHandler(ErrorHandler handler);
-
- /**
- * Return the current error handler.
- *
- * @return The current error handler, or null if none
- * has been registered.
- * @see #setErrorHandler
- */
- public ErrorHandler getErrorHandler();
-
- ////////////////////////////////////////////////////////////////////
- // Parsing.
- ////////////////////////////////////////////////////////////////////
-
- /**
- * Parse an XML document.
- *
- * <p>The application can use this method to instruct the XML
- * reader to begin parsing an XML document from any valid input
- * source (a character stream, a byte stream, or a URI).</p>
- *
- * <p>Applications may not invoke this method while a parse is in
- * progress (they should create a new XMLReader instead for each
- * nested XML document). Once a parse is complete, an
- * application may reuse the same XMLReader object, possibly with a
- * different input source.
- * Configuration of the XMLReader object (such as handler bindings and
- * values established for feature flags and properties) is unchanged
- * by completion of a parse, unless the definition of that aspect of
- * the configuration explicitly specifies other behavior.
- * (For example, feature flags or properties exposing
- * characteristics of the document being parsed.)
- * </p>
- *
- * <p>During the parse, the XMLReader will provide information
- * about the XML document through the registered event
- * handlers.</p>
- *
- * <p>This method is synchronous: it will not return until parsing
- * has ended. If a client application wants to terminate
- * parsing early, it should throw an exception.</p>
- *
- * @param input The input source for the top-level of the
- * XML document.
- * @exception org.xml.sax.SAXException Any SAX exception, possibly
- * wrapping another exception.
- * @exception j2me.io.IOException An IO exception from the parser,
- * possibly from a byte stream or character stream
- * supplied by the application.
- * @see org.xml.sax.InputSource
- * @see #setEntityResolver
- * @see #setDTDHandler
- * @see #setContentHandler
- * @see #setErrorHandler
- */
- public void parse(InputSource input) throws IOException, SAXException;
-
- /**
- * Parse an XML document from a system identifier (URI).
- *
- * <p>This method is a shortcut for the common case of reading a
- * document from a system identifier. It is the exact
- * equivalent of the following:</p>
- *
- * <pre>
- * parse(new InputSource(systemId));
- * </pre>
- *
- * <p>If the system identifier is a URL, it must be fully resolved
- * by the application before it is passed to the parser.</p>
- *
- * @param systemId The system identifier (URI).
- * @exception org.xml.sax.SAXException Any SAX exception, possibly
- * wrapping another exception.
- * @exception j2me.io.IOException An IO exception from the parser,
- * possibly from a byte stream or character stream
- * supplied by the application.
- * @see #parse(org.xml.sax.InputSource)
- */
- public void parse(String systemId) throws IOException, SAXException;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java
deleted file mode 100644
index 12cdf26..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/XMLReaderImpl.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.sax;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.net.URL;
-import javolution.text.CharArray;
-import javolution.xml.internal.stream.XMLStreamReaderImpl;
-import javolution.xml.stream.XMLStreamConstants;
-import javolution.xml.stream.XMLStreamException;
-import org.xml.sax.DTDHandler;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
-
-/**
- * <p> This class provides a real-time SAX2-like XML parser; this parser is
- * <i>extremely</i> fast and <b>does not create temporary objects</b>
- * (no garbage generated and no GC interruption).</p>
- *
- * <p> The parser is implemented as a SAX2 wrapper around
- * {@link XMLStreamReaderImpl} and share the same characteristics.</p>
- *
- * <p><i> Note: This parser is a <b>SAX2-like</b> parser with the
- * <code>java.lang.String</code> type replaced by
- * {@link CharArray}/{@link CharSequence} in the {@link ContentHandler},
- * {@link Attributes} interfaces and {@link DefaultHandler} base class.
- * If a standard SAX2 or JAXP parser is required, you may consider using
- * the wrapping class {@link SAX2ReaderImpl}. Fast but not as fast as
- * <code>java.lang.String</code> instances are dynamically allocated
- * while parsing.</i></p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, June 16, 2006
- */
-public class XMLReaderImpl implements XMLReader {
-
- /**
- * Holds the default handler instance.
- */
- private static DefaultHandler DEFAULT_HANDLER = new DefaultHandler();
-
- /**
- * Holds the content handler.
- */
- private ContentHandler _contentHandler;
-
- /**
- * Holds the error handler.
- */
- private ErrorHandler _errorHandler;
-
- /**
- * Holds reusable StAX reader.
- */
- private final XMLStreamReaderImpl _xmlReader = new XMLStreamReaderImpl();
-
- /**
- * Default constructor.
- */
- public XMLReaderImpl() {
- // Sets default handlers.
- setContentHandler(DEFAULT_HANDLER);
- setErrorHandler(DEFAULT_HANDLER);
- }
-
- /**
- * Parses an XML document from the specified input stream
- * (encoding retrieved from input source and the XML prolog if any).
- *
- * @param in the input stream with unknown encoding.
- * @throws org.xml.sax.SAXException any SAX exception, possibly
- * wrapping another exception.
- * @throws IOException an IO exception from the parser,
- * possibly from a byte stream or character stream
- * supplied by the application.
- */
- public void parse(InputStream in) throws IOException, SAXException {
- try {
- _xmlReader.setInput(in);
- parseAll();
- } catch (XMLStreamException e) {
- if (e.getNestedException() instanceof IOException)
- throw (IOException) e.getNestedException();
- throw new SAXException(e.getMessage());
- } finally {
- _xmlReader.reset();
- }
- }
-
- /**
- * Parses an XML document from the specified input stream and encoding.
- *
- * @param in the input stream.
- * @param encoding the input stream encoding.
- * @throws org.xml.sax.SAXException any SAX exception, possibly
- * wrapping another exception.
- * @throws IOException an IO exception from the parser,
- * possibly from a byte stream or character stream
- * supplied by the application.
- */
- public void parse(InputStream in, String encoding) throws IOException,
- SAXException {
- try {
- _xmlReader.setInput(in, encoding);
- parseAll();
- } catch (XMLStreamException e) {
- if (e.getNestedException() instanceof IOException)
- throw (IOException) e.getNestedException();
- throw new SAXException(e.getMessage());
- } finally {
- _xmlReader.reset();
- }
- }
-
- /**
- * Parses an XML document using the specified reader.
- *
- * @param reader the document reader.
- * @throws SAXException any SAX exception, possibly wrapping another
- * exception.
- * @throws IOException an IO exception from the parser, possibly from
- * a byte stream or character stream supplied by the application.
- * @see javolution.io.UTF8StreamReader
- * @see javolution.io.UTF8ByteBufferReader
- * @see javolution.io.CharSequenceReader
- */
- public void parse(Reader reader) throws IOException, SAXException {
- try {
- _xmlReader.setInput(reader);
- parseAll();
- } catch (XMLStreamException e) {
- if (e.getNestedException() instanceof IOException)
- throw (IOException) e.getNestedException();
- throw new SAXException(e.getMessage());
- } finally {
- _xmlReader.reset();
- }
- }
-
- // Implements XMLReader interface.
- public void parse(InputSource input) throws IOException, SAXException {
- Reader reader = input.getCharacterStream();
- if (reader != null) {
- parse(reader);
- } else {
- InputStream inStream = input.getByteStream();
- if (inStream != null) {
- parse(inStream, input.getEncoding());
- } else {
- parse(input.getSystemId());
- }
- }
- }
-
- // Implements XMLReader interface.
- public void parse(String systemId) throws IOException, SAXException {
- InputStream inStream;
- try {
- URL url = new URL(systemId);
- inStream = url.openStream();
- } catch (Exception urlException) { // Try as filename.
- try {
- inStream = new FileInputStream(systemId);
- } catch (Exception fileException) {
- throw new UnsupportedOperationException("Cannot parse "
- + systemId);
- }
- }
- parse(inStream);
- }
-
- // Implements XMLReader interface.
- public void setContentHandler(ContentHandler handler) {
- if (handler != null) {
- _contentHandler = handler;
- } else {
- throw new NullPointerException();
- }
- }
-
- // Implements XMLReader interface.
- public ContentHandler getContentHandler() {
- return (_contentHandler == DEFAULT_HANDLER) ? null : _contentHandler;
- }
-
- // Implements XMLReader interface.
- public void setErrorHandler(ErrorHandler handler) {
- if (handler != null) {
- _errorHandler = handler;
- } else {
- throw new NullPointerException();
- }
- }
-
- // Implements XMLReader interface.
- public ErrorHandler getErrorHandler() {
- return (_errorHandler == DEFAULT_HANDLER) ? null : _errorHandler;
- }
-
- // Implements XMLReader interface.
- public boolean getFeature(String name) throws SAXNotRecognizedException,
- SAXNotSupportedException {
- if (name.equals("http://xml.org/sax/features/namespaces")) {
- return true;
- } else if (name
- .equals("http://xml.org/sax/features/namespace-prefixes")) {
- return true;
- } else {
- throw new SAXNotRecognizedException("Feature " + name
- + " not recognized");
- }
- }
-
- public void setFeature(String name, boolean value)
- throws SAXNotRecognizedException, SAXNotSupportedException {
- if (name.equals("http://xml.org/sax/features/namespaces")
- || name.equals("http://xml.org/sax/features/namespace-prefixes")) {
- return; // Ignores, these features are always set.
- } else {
- throw new SAXNotRecognizedException("Feature " + name
- + " not recognized");
- }
- }
-
- public Object getProperty(String name) throws SAXNotRecognizedException,
- SAXNotSupportedException {
- throw new SAXNotRecognizedException("Property " + name
- + " not recognized");
- }
-
- public void setProperty(String name, Object value)
- throws SAXNotRecognizedException, SAXNotSupportedException {
- throw new SAXNotRecognizedException("Property " + name
- + " not recognized");
- }
-
- public void setEntityResolver(EntityResolver resolver) {
- _entityResolver = resolver;
- }
-
- private EntityResolver _entityResolver;
-
- public EntityResolver getEntityResolver() {
- return _entityResolver;
- }
-
- public void setDTDHandler(DTDHandler handler) {
- _dtdHandler = handler;
- }
-
- private DTDHandler _dtdHandler;
-
- public DTDHandler getDTDHandler() {
- return _dtdHandler;
- }
-
- // Implements Reusable.
- public void reset() {
- setContentHandler(DEFAULT_HANDLER);
- setErrorHandler(DEFAULT_HANDLER);
- _xmlReader.reset();
- }
-
- /**
- * Parses the whole document using the real-time pull parser.
- *
- * @throws SAXException any SAX exception, possibly wrapping another
- * exception.
- * @throws IOException an IO exception from the parser, possibly from
- * a byte stream or character stream supplied by the application.
- */
- private void parseAll() throws XMLStreamException, SAXException {
- int eventType = _xmlReader.getEventType();
- if (eventType != XMLStreamConstants.START_DOCUMENT)
- throw new SAXException("Currently parsing");
- _contentHandler.startDocument();
-
- boolean doContinue = true;
- while (doContinue) {
- CharArray uri, localName, qName, prefix, text;
- switch (_xmlReader.next()) {
- case XMLStreamConstants.START_ELEMENT:
-
- // Start prefix mapping.
- for (int i = 0, count = _xmlReader.getNamespaceCount(); i < count; i++) {
- prefix = _xmlReader.getNamespacePrefix(i);
- prefix = (prefix == null) ? NO_CHAR : prefix; // Default namespace is ""
- uri = _xmlReader.getNamespaceURI(i);
- _contentHandler.startPrefixMapping(prefix, uri);
- }
-
- // Start element.
- uri = _xmlReader.getNamespaceURI();
- uri = (uri == null) ? NO_CHAR : uri;
- localName = _xmlReader.getLocalName();
- qName = _xmlReader.getQName();
- _contentHandler.startElement(uri, localName, qName,
- _xmlReader.getAttributes());
- break;
-
- case XMLStreamConstants.END_ELEMENT:
-
- // End element.
- uri = _xmlReader.getNamespaceURI();
- uri = (uri == null) ? NO_CHAR : uri;
- localName = _xmlReader.getLocalName();
- qName = _xmlReader.getQName();
- _contentHandler.endElement(uri, localName, qName);
-
- // End prefix mapping.
- for (int i = 0, count = _xmlReader.getNamespaceCount(); i < count; i++) {
- prefix = _xmlReader.getNamespacePrefix(i);
- prefix = (prefix == null) ? NO_CHAR : prefix; // Default namespace is ""
- _contentHandler.endPrefixMapping(prefix);
- }
- break;
-
- case XMLStreamConstants.CDATA:
- case XMLStreamConstants.CHARACTERS:
- text = _xmlReader.getText();
- _contentHandler.characters(text.array(), text.offset(),
- text.length());
- break;
-
- case XMLStreamConstants.SPACE:
- text = _xmlReader.getText();
- _contentHandler.ignorableWhitespace(text.array(),
- text.offset(), text.length());
- break;
-
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- _contentHandler.processingInstruction(
- _xmlReader.getPITarget(), _xmlReader.getPIData());
- break;
-
- case XMLStreamConstants.COMMENT:
- // Ignores.
- break;
-
- case XMLStreamConstants.END_DOCUMENT:
- doContinue = false;
- _xmlReader.close();
- break;
-
- }
- }
- }
-
- private static final CharArray NO_CHAR = new CharArray("");
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java
deleted file mode 100644
index b418101..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/package-info.java
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
-<p> {@link javolution.xml.sax.SAX2ReaderImpl SAX2} and high-performance
- {@link javolution.xml.sax.XMLReaderImpl SAX2-Like} parsers. The later
- being several times faster than conventional SAX2 parsers (by avoiding
- <code>String</code> allocations while parsing).</p>
- */
-package javolution.xml.sax;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java
deleted file mode 100644
index c89a30f..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/Location.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-/**
- * Provides information on the location of an event.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 3.8, May 22, 2006
- */
-public interface Location {
-
- /**
- * Return the line number where the current event ends,
- * returns -1 if none is available.
- * @return the current line number
- */
- int getLineNumber();
-
- /**
- * Return the column number where the current event ends,
- * returns -1 if none is available.
- * @return the current column number
- */
- int getColumnNumber();
-
- /**
- * Return the byte or character offset into the input source this location
- * is pointing to. If the input source is a file or a byte stream then
- * this is the byte offset into that stream, but if the input source is
- * a character media then the offset is the character offset.
- * Returns -1 if there is no offset available.
- *
- * @return the current offset
- */
- int getCharacterOffset();
-
- /**
- * Returns the public ID of the XML
- *
- * @return the public ID, or null if not available
- */
- public String getPublicId();
-
- /**
- * Returns the system ID of the XML
- * @return the system ID, or null if not available
- */
- public String getSystemId();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java
deleted file mode 100644
index 040e8f5..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/NamespaceContext.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-import java.util.Iterator;
-import javolution.text.CharArray;
-
-/**
- * This interface represents the XML namespace context stack while parsing.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, September 12, 2006
- */
-public interface NamespaceContext {
-
- /**
- * Returns the namespace URI bound to a prefix in the current scope
- * or <code>null</code> if the prefix is unbound.
- *
- * @param prefix prefix to look up
- * @return the namespace URI.
- * @throws IllegalArgumentException if <code>prefix</code> is
- * <code>null</code>
- */
- CharArray getNamespaceURI(CharSequence prefix);
-
- /**
- * Returns the prefix bound to the namespace URI in the current scope
- * or <code>null</code> if the namespace URI is unbound.
- *
- * @param namespaceURI URI of the namespace to lookup.
- * @return the prefix bound to the namespace URI.
- * @throws IllegalArgumentException if <code>namespaceURI</code> is
- * <code>null</code>
- */
- CharArray getPrefix(CharSequence namespaceURI);
-
- /**
- * Returns all prefixes bound to a namespace URI in the current scope
- * (including predefined prefixes).
- *
- * @param namespaceURI URI of Namespace to lookup
- * @return an <code>Iterator</code> over {@link CharArray} prefixes.
- * @throws IllegalArgumentException if <code>namespaceURI</code> is
- * <code>null</code>
- */
- Iterator<CharArray> getPrefixes(CharSequence namespaceURI);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java
deleted file mode 100644
index 0ffd10c..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLInputFactory.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-import javolution.lang.Parallelizable;
-
-/**
- * <p> The OSGi factory service to create {@link XMLStreamReader} instances.
- * For each bundle, a distinct factory instance is returned and can be
- * individually configured (if not enough the factory can be
- * {@link #clone cloned}).
- * [code]
- * import javolution.xml.stream.*;
- * public class Activator implements BundleActivator {
- * public void start(BundleContext bc) throws Exception {
- *
- * // Configures factory.
- * ServiceTracker<XMLInputFactory, XMLInputFactory> tracker
- * = new ServiceTracker<>(bc, XMLInputFactory.class, null);
- * tracker.open();
- * tracker.getService().setProperty(IS_COALESCING, true);
- *
- * // Instantiates a reader.
- * String xml = "<test>This is a test</test>";
- * CharSequenceReader in = new CharSequenceReader().setInput(xml);
- * XMLStreamReader reader = tracker.getService().createXMLStreamReader(in);
- *
- * // Parses XML.
- * while (reader.hasNext()) {
- * int eventType = reader.next();
- * if (eventType == XMLStreamConstants.CHARACTERS) {
- * System.out.println(reader.getText());
- * }
- * }
- *
- * // Closes the reader which may be recycled back to the factory.
- * reader.close();
- * }
- * }[/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-@Parallelizable(comment="Factory configuration should be performed sequentially.")
-public interface XMLInputFactory extends Cloneable {
-
- /**
- * The property that requires the parser to coalesce adjacent character data
- * sections.
- */
- public static final String IS_COALESCING = "javolution.xml.stream.isCoalescing";
-
- /**
- * The property that requires the parser to validate the input data.
- */
- public static final String IS_VALIDATING = "javolution.xml.stream.isValidating";
-
- /**
- * Property used to specify additional entities to be recognized by the
- * readers (type: <code>java.util.Map</code>, default: <code>null</code>).
- * For example:[code]
- * FastMap<String, String> HTML_ENTITIES = new FastMap<String, String>();
- * HTML_ENTITIES.put("nbsp", " ");
- * HTML_ENTITIES.put("copy", "©");
- * HTML_ENTITIES.put("eacute", "é");
- * ...
- * XMLInputFactory factory = factoryRef.getService();
- * factory.setProperty(ENTITIES, HTML_ENTITIES);
- * [/code]
- */
- public static final String ENTITIES = "javolution.xml.stream.entities";
-
- /**
- * Returns a XML stream reader for the specified I/O reader.
- *
- * @param reader the XML data to read from.
- * @throws XMLStreamException
- */
- XMLStreamReader createXMLStreamReader(Reader reader)
- throws XMLStreamException;
-
- /**
- * Returns a XML stream reader for the specified input stream
- * (encoding autodetected).
- *
- * @param stream the input stream to read from.
- * @return a xml stream reader possibly recycled.
- * @throws XMLStreamException
- */
- XMLStreamReader createXMLStreamReader(InputStream stream)
- throws XMLStreamException;
-
- /**
- * Returns a XML stream reader for the specified input stream using the
- * specified encoding.
- *
- * @param stream the input stream to read from.
- * @param encoding the character encoding of the stream.
- * @return a xml stream reader possibly recycled.
- * @throws XMLStreamException
- */
- XMLStreamReader createXMLStreamReader(InputStream stream,
- String encoding) throws XMLStreamException;
-
- /**
- * Allows the user to set specific feature/property on the underlying
- * implementation. The underlying implementation is not required to support
- * every setting of every property in the specification and may use
- * <code>IllegalArgumentException</code> to signal that an unsupported
- * property may not be set with the specified value.
- *
- * @param name the name of the property.
- * @param value the value of the property
- * @throws IllegalArgumentException if the property is not supported.
- */
- void setProperty(String name, Object value) throws IllegalArgumentException;
-
- /**
- * Gets the value of a feature/property from the underlying implementation.
- *
- * @param name the name of the property (may not be null).
- * @return the value of the property.
- * @throws IllegalArgumentException if the property is not supported.
- */
- Object getProperty(String name) throws IllegalArgumentException;
-
- /**
- * Queries the set of properties that this factory supports.
- *
- * @param name the name of the property.
- * @return <code>true</code> if the property is supported;
- * <code>false</code> otherwise.
- */
- boolean isPropertySupported(String name);
-
- /**
- * Returns a clone of this factory which can be independently configured.
- */
- XMLInputFactory clone();
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java
deleted file mode 100644
index 8f93138..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLOutputFactory.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-import java.io.OutputStream;
-import java.io.Writer;
-
-import javolution.lang.Parallelizable;
-
-/**
- * <p> The OSGi factory service to create {@link XMLStreamWriter} instances.
- * For each bundle, a distinct factory instance is returned and can be
- * individually configured (if not enough the factory can be
- * {@link #clone cloned}).
- * [code]
- * import javolution.xml.stream.*;
- * public class Activator implements BundleActivator {
- * public void start(BundleContext bc) throws Exception {
- *
- * // Configures factory.
- * ServiceTracker<XMLOutputFactory, XMLOutputFactory> tracker
- * = new ServiceTracker<>(bc, XMLOutputFactory.class, null);
- * tracker.open();
- * tracker.getService().setProperty(XMLOutputFactory.INDENTATION, "/t"); // Use tab for indentations.
- *
- * // Instantiates a new writer.
- * TextBuilder xml = new TextBuilder();
- * AppendableWriter out = new AppendableWriter(xml);
- * XMLStreamWriter writer = tracker.getService().createXMLStreamWriter(out);
- *
- * // Formats to XML.
- * writer.writeStartDocument("1.0");
- * writer.writeCharacters("\n");
- * writer.writeStartElement("ns1", "sample", "http://www.e.com/ns1");
- * writer.writeNamespace("ns1", "http://www.e.com/ns1");
- * writer.writeEndElement();
- * writer.writeEndDocument();
- *
- * // Closes the writer which may be recycled back to the factory.
- * writer.close();
- *
- * // Displays the formatted output.
- * System.out.println(xml);
- * }
- * [/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-@Parallelizable(comment="Factory configuration should be performed sequentially.")
-public interface XMLOutputFactory extends Cloneable {
-
- /**
- * Property used to set prefix defaulting on the output side
- * (type: <code>Boolean</code>, default: <code>FALSE</code>).
- */
- public static final String IS_REPAIRING_NAMESPACES = "javolution.xml.stream.isRepairingNamespaces";
-
- /**
- * Property used to specify the prefix to be appended by a trailing
- * part (a sequence number) in order to make it unique to be usable as
- * a temporary non-colliding prefix when repairing namespaces
- * (type: <code>String</code>, default: <code>"ns"</code>).
- */
- public final static String REPAIRING_PREFIX = "javolution.xml.stream.repairingPrefix";
-
- /**
- * Property used to specify an indentation string; non-null indentation
- * forces the writer to write elements into separate lines
- * (type: <code>String</code>, default: <code>null</code>).
- */
- public static final String INDENTATION = "javolution.xml.stream.indentation";
-
- /**
- * Property used to specify the new line characters
- * (type: <code>String</code>, default: <code>"\n"</code>).
- */
- public static final String LINE_SEPARATOR = "javolution.xml.stream.lineSeparator";
-
- /**
- * Property indicating if the stream writers are allowed to automatically
- * output empty elements when a start element is immediately followed by
- * matching end element
- * (type: <code>Boolean</code>, default: <code>FALSE</code>).
- */
- public final static String AUTOMATIC_EMPTY_ELEMENTS = "javolution.xml.stream.automaticEmptyElements";
-
- /**
- * Property indicating if the stream writers are not allowed to use
- * empty element tags
- * (type: <code>Boolean</code>, default: <code>FALSE</code>).
- * When set, this property forces the use of start/end element tag
- * (e.g. i.e. "<empty />" replaced by "<empty></empty>"),
- * This property takes precedence over {@link #AUTOMATIC_EMPTY_ELEMENTS}.
- */
- public final static String NO_EMPTY_ELEMENT_TAG = "javolution.xml.stream.noEmptyElementTag";
-
- /**
- * Returns a XML stream writer to the specified i/o writer.
- *
- * @param writer the writer to write to.
- * @return a xml stream writer possibly recycled.
- * @throws XMLStreamException
- */
- XMLStreamWriter createXMLStreamWriter(Writer writer)
- throws XMLStreamException;
-
- /**
- * Returns a XML stream writer to the specified output stream (UTF-8
- * encoding).
- *
- * @param stream the stream to write to.
- * @return a xml stream writer possibly recycled.
- * @throws XMLStreamException
- */
- XMLStreamWriter createXMLStreamWriter(OutputStream stream)
- throws XMLStreamException;
-
- /**
- * Returns a XML stream writer to the specified output stream using the
- * specified encoding.
- *
- * @param stream the stream to write to.
- * @param encoding the encoding to use.
- * @return a xml stream writer possibly recycled.
- * @throws XMLStreamException
- */
- XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding)
- throws XMLStreamException;
-
- /**
- * Allows the user to set specific features/properties on the underlying
- * implementation.
- *
- * @param name the name of the property.
- * @param value the value of the property.
- * @throws IllegalArgumentException if the property is not supported.
- */
- void setProperty(String name, Object value) throws IllegalArgumentException;
-
- /**
- * Gets a feature/property on the underlying implementation.
- *
- * @param name the name of the property
- * @return the value of the property
- * @throws IllegalArgumentException if the property is not supported.
- */
- Object getProperty(String name) throws IllegalArgumentException;
-
- /**
- * Queries the set of properties that this factory supports.
- *
- * @param name the name of the property (may not be null).
- * @return <code>true</code> if the property is supported;
- * <code>false</code> otherwise.
- */
- boolean isPropertySupported(String name);
-
- /**
- * Returns a clone of this factory which can be independently configured.
- */
- XMLOutputFactory clone();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java
deleted file mode 100644
index aef6e60..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamConstants.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-/**
- * This interface declares the constants used in this API. Numbers in the range
- * 0 to 256 are reserved for the specification, user defined events must use
- * event codes outside that range.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, June 16, 2006
- */
-public interface XMLStreamConstants {
-
- /**
- * Indicates an event is a start element.
- */
- public static final int START_ELEMENT = 1;
-
- /**
- * Indicates an event is an end element.
- */
- public static final int END_ELEMENT = 2;
-
- /**
- * Indicates an event is a processing instruction.
- */
- public static final int PROCESSING_INSTRUCTION = 3;
-
- /**
- * Indicates an event is characters.
- */
- public static final int CHARACTERS = 4;
-
- /**
- * Indicates an event is a comment.
- */
- public static final int COMMENT = 5;
-
- /**
- * The characters are white space (see [XML], 2.10 "White Space Handling").
- * Events are only reported as SPACE if they are ignorable white space.
- * Otherwise they are reported as CHARACTERS.
- */
- public static final int SPACE = 6;
-
- /**
- * Indicates an event is a start document.
- */
- public static final int START_DOCUMENT = 7;
-
- /**
- * Indicates an event is an end document.
- */
- public static final int END_DOCUMENT = 8;
-
- /**
- * Indicates an event is an entity reference.
- */
- public static final int ENTITY_REFERENCE = 9;
-
- /**
- * Indicates an event is an attribute.
- */
- public static final int ATTRIBUTE = 10;
-
- /**
- * Indicates an event is a DTD.
- */
- public static final int DTD = 11;
-
- /**
- * Indicates an event is a CDATA section.
- */
- public static final int CDATA = 12;
-
- /**
- * Indicates the event is a namespace declaration.
- */
- public static final int NAMESPACE = 13;
-
- /**
- * Indicates a Notation.
- */
- public static final int NOTATION_DECLARATION = 14;
-
- /**
- * Indicates a Entity Declaration.
- */
- public static final int ENTITY_DECLARATION = 15;
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java
deleted file mode 100644
index fd449b6..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamException.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-/**
- * This class represents the base exception for unexpected processing errors.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 3.8, May 22, 2006
- */
-public class XMLStreamException extends Exception {
-
- /**
- * Holds the nested exception if any.
- */
- private Throwable _nested;
-
- /**
- * Holds the location.
- */
- private Location _location;
-
- /**
- * Default constructor
- */
- public XMLStreamException() {
- super();
- }
-
- /**
- * Constructs an exception with the assocated message.
- *
- * @param msg the message to report.
- */
- public XMLStreamException(String msg) {
- super(msg);
- }
-
- /**
- * Constructs an exception with the assocated nested exception.
- *
- * @param nested the nested exception.
- */
- public XMLStreamException(Throwable nested) {
- _nested = nested;
- }
-
- /**
- * Constructs an exception with the assocated message and exception.
- *
- * @param msg the message to report.
- * @param nested the nested exception.
- */
- public XMLStreamException(String msg, Throwable nested) {
- super(msg);
- _nested = nested;
- }
-
- /**
- * Constructs an exception with the assocated message, exception and
- * location.
- *
- * @param msg the message to report.
- * @param location the location.
- * @param nested the nested exception.
- */
- public XMLStreamException(String msg, Location location, Throwable nested) {
- super(msg);
- _nested = nested;
- _location = location;
- }
-
- /**
- * Constructs an exception with the assocated message, exception and
- * location.
- *
- * @param msg the message to report
- * @param location the location of the error
- */
- public XMLStreamException(String msg, Location location) {
- super(msg);
- _location = location;
- }
-
- /**
- * Returns the nested exception.
- *
- * @return the nested exception
- */
- public Throwable getNestedException() {
- return _nested;
- }
-
- /**
- * Returns the location of the exception.
- *
- * @return the location of the exception or <code>null</code>
- * if none is available
- */
- public Location getLocation() {
- return _location;
- }
-
- /**
- * Returns the textual representation of this exception.
- *
- * @return the string representation of the exception.
- */
- public String toString() {
- String msg = super.toString();
- if (_location != null) {
- msg += " (at line " + _location.getLineNumber() + ", column "
- + _location.getColumnNumber() + ")";
- }
- if (_nested != null) {
- msg += " caused by " + _nested.toString();
- }
- return msg;
- }
-
- private static final long serialVersionUID = 1L;
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java b/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java
deleted file mode 100644
index fd407d6..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/stream/XMLStreamReader.java
+++ /dev/null
@@ -1,604 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.stream;
-
-import java.util.NoSuchElementException;
-
-import javolution.text.CharArray;
-
-/**
- * <p> This interface is similar to
- * <code>javax.xml.stream.XMLStreamReader</code>; but it does not forces
- * dynamic allocation when parsing (its methods returns
- * {@link CharArray CharArray} instances instead of {@link String}).</p>
- *
- * <p> Except for the speed (faster) and its real-time characteristics
- * the usage/behavior is about the same as its StAX counterpart.</p>
- *
- * <p> The {@link CharArray CharArray} instances returned by this reader
- * supports fast primitive conversions as illustrated below.
- * [code]
- * // Creates a new reader (potentially recycled).
- * XMLInputFactory factory = OSGiServices.getXMLInputFactory();
- * XMLStreamReader reader = factory.createXMLStreamReader(inputStream);
- *
- * while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
- * switch (reader.next()) {
- * case XMLStreamConstants.START_ELEMENT:
- * if (reader.getLocalName().equals("Time")) {
- * // Reads primitive types (int) attributes directly (no memory allocation).
- * time.hour = reader.getAttributeValue(null, "hour").toInt();
- * time.minute = reader.getAttributeValue(null, "minute").toInt();
- * time.second = reader.getAttributeValue(null, "second").toInt();
- * }
- * ...
- * break;
- * }
- * }
- * reader.close(); // Close the reader (does not close underlying input stream).
- * [/code]
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-public interface XMLStreamReader extends XMLStreamConstants {
-
- /**
- * Gets the value of a feature/property from the underlying implementation
- *
- * @param name the name of the property.
- * @return the value of the property.
- */
- Object getProperty(String name) throws IllegalArgumentException;
-
- /**
- * Gets next parsing event - contiguous character data is returned into a
- * single chunk.
- *
- * By default entity references must be expanded and reported transparently
- * to the application. An exception will be thrown if an entity reference
- * cannot be expanded. If element content is empty (i.e. content is "") then
- * no CHARACTERS event will be reported.
- *
- * <p>
- * Given the following XML:<br>
- * <foo><!--description-->content
- * text<![CDATA[<greeting>Hello</greeting>]]>other content</foo><br>
- * The behavior of calling next() when being on foo will be:<br>
- * 1- the comment (COMMENT)<br>
- * 2- then the characters section (CHARACTERS)<br>
- * 3- then the CDATA section (another CHARACTERS)<br>
- * 4- then the next characters section (another CHARACTERS)<br>
- * 5- then the END_ELEMENT<br>
- *
- * <p>
- * <b>NOTE:</b> empty element (such as <tag/>) will be reported with two
- * separate events: START_ELEMENT, END_ELEMENT - This preserves parsing
- * equivalency of empty element to <tag></tag>.
- *
- * This method will throw an IllegalStateException if it is called after
- * hasNext() returns false.
- *
- * @return the integer code corresponding to the current parse event
- * @throws NoSuchElementException if this is called when hasNext()
- * returns false
- * @throws XMLStreamException if there is an error processing the
- * underlying XML source
- */
- int next() throws XMLStreamException;
-
- /**
- * Tests if the current event is of the given type and if the namespace and
- * name match the current namespace and name of the current event. If the
- * namespaceURI is null it is not checked for equality, if the localName is
- * null it is not checked for equality.
- *
- * @param type the event type.
- * @param namespaceURI the uri of the event, may be null.
- * @param localName the localName of the event, may be null.
- * @throws XMLStreamException if the required values are not matched.
- */
- void require(int type, CharSequence namespaceURI,
- CharSequence localName) throws XMLStreamException;
-
- /**
- * Reads the content of a text-only element, an exception is thrown if this
- * is not a text-only element. Regardless of the value of
- * javax.xml.stream.isCoalescing this method always returns coalesced
- * content. <br />
- * Precondition: the current event is START_ELEMENT. <br />
- * Postcondition: the current event is the corresponding END_ELEMENT.
- *
- * <br />
- * The method does the following (implementations are free to optimized but
- * must do equivalent processing):
- *
- * <pre>
- * if (getEventType() != XMLStreamConstants.START_ELEMENT) {
- * throw new XMLStreamException(
- * "parser must be on START_ELEMENT to read next text", getLocation());
- * }
- * int eventType = next();
- * StringBuffer content = new StringBuffer();
- * while (eventType != XMLStreamConstants.END_ELEMENT) {
- * if (eventType == XMLStreamConstants.CHARACTERS
- * || eventType == XMLStreamConstants.CDATA
- * || eventType == XMLStreamConstants.SPACE
- * || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
- * buf.append(getText());
- * } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
- * || eventType == XMLStreamConstants.COMMENT) {
- * // skipping
- * } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
- * throw new XMLStreamException(
- * "unexpected end of document when reading element text content",
- * this);
- * } else if (eventType == XMLStreamConstants.START_ELEMENT) {
- * throw new XMLStreamException(
- * "element text content may not contain START_ELEMENT",
- * getLocation());
- * } else {
- * throw new XMLStreamException("Unexpected event type " + eventType,
- * getLocation());
- * }
- * eventType = next();
- * }
- * return buf.toString();
- * </pre>
- *
- * @throws XMLStreamException if the current event is not a START_ELEMENT
- * or if a non text element is encountered.
- */
- CharArray getElementText() throws XMLStreamException;
-
- /**
- * Skips any white space (isWhiteSpace() returns true), COMMENT, or
- * PROCESSING_INSTRUCTION, until a START_ELEMENT or END_ELEMENT is reached.
- * If other than white space characters, COMMENT, PROCESSING_INSTRUCTION,
- * START_ELEMENT, END_ELEMENT are encountered, an exception is thrown. This
- * method should be used when processing element-only content seperated by
- * white space.
- *
- * <br />
- * Precondition: none <br />
- * Postcondition: the current event is START_ELEMENT or END_ELEMENT and
- * cursor may have moved over any whitespace event.
- *
- * <br />
- * Essentially it does the following (implementations are free to optimized
- * but must do equivalent processing):
- *
- * <pre>
- * int eventType = next();
- * while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
- * || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
- * // skip whitespace
- * || eventType == XMLStreamConstants.SPACE
- * || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
- * || eventType == XMLStreamConstants.COMMENT
- * ) {
- * eventType = next();
- * }
- * if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
- * throw new String XMLStreamException("expected start or end tag", getLocation());
- * }
- * return eventType;
- * </pre>
- *
- * @return the event type of the element read (START_ELEMENT or END_ELEMENT)
- * @throws XMLStreamException if the current event is not white space,
- * PROCESSING_INSTRUCTION, START_ELEMENT or END_ELEMENT
- * @throws NoSuchElementException if this is called when hasNext()
- * returns false
- */
- int nextTag() throws XMLStreamException;
-
- /**
- * Returns true if there are more parsing events and false if there are no
- * more events. This method will return false if the current state of the
- * XMLStreamReader is END_DOCUMENT.
- *
- * @return true if there are more events, false otherwise.
- * @throws XMLStreamException if there is a fatal error detecting the next
- * state.
- */
- boolean hasNext() throws XMLStreamException;
-
- /**
- * Frees any resources associated with this Reader. This method does not
- * close the underlying input source.
- *
- * @throws XMLStreamException if there are errors freeing associated
- * resources
- */
- void close() throws XMLStreamException;
-
- /**
- * Returns the uri for the given prefix. The uri returned depends on the
- * current state of the processor.
- *
- * <p>
- * <strong>NOTE:</strong>The 'xml' prefix is bound as defined in <a
- * href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a>
- * specification to "http://www.w3.org/XML/1998/namespace".
- *
- * <p>
- * <strong>NOTE:</strong> The 'xmlns' prefix must be resolved to following
- * namespace <a
- * href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a>
- *
- * @param prefix the prefix to lookup.
- * @return the uri bound to the given prefix or <code>null</code> if it is
- * not bound
- */
- CharArray getNamespaceURI(CharSequence prefix);
-
- /**
- * Indicates if the cursor points to a start tag.
- *
- * @return <code>true</code> if the cursor points to a start tag;
- * <code>false</code> otherwise.
- */
- boolean isStartElement();
-
- /**
- * Indicates if the cursor points to an end tag.
- *
- * @return <code>true</code> if the cursor points to a end tag;
- * <code>false</code> otherwise.
- */
- boolean isEndElement();
-
- /**
- * Indicates if the cursor points to character data.
- *
- * @return <code>true</code> if the cursor points to character data;
- * <code>false</code> otherwise.
- */
- boolean isCharacters();
-
- /**
- * Indicates if the cursor points to character data that consists
- * of all whitespace.
- *
- * @return <code>true</code> if the cursor points to whitespaces;
- * <code>false</code> otherwise.
- */
- boolean isWhiteSpace();
-
- /**
- * Returns the normalized attribute value of the attribute with the
- * namespace and localName.
- *
- * @param namespaceURI the namespace of the attribute or <code>null</code>.
- * @param localName the local name of the attribute.
- * @return returns the value of the attribute or <code>null</code>.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- CharArray getAttributeValue(CharSequence namespaceURI,
- CharSequence localName);
-
- /**
- * Returns the count of attributes on this START_ELEMENT, this method is
- * only valid on a START_ELEMENT or ATTRIBUTE. This count excludes namespace
- * definitions. Attribute indices are zero-based.
- *
- * @return returns the number of attributes.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- int getAttributeCount();
-
- /**
- * Returns the namespace of the attribute at the provided index
- *
- * @param index the position of the attribute.
- * @return the namespace URI or <code>null</code> if no prefix.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- CharArray getAttributeNamespace(int index);
-
- /**
- * Returns the localName of the attribute at the provided index.
- *
- * @param index the position of the attribute.
- * @return the localName of the attribute.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- CharArray getAttributeLocalName(int index);
-
- /**
- * Returns the prefix of this attribute at the provided index
- *
- * @param index the position of the attribute.
- * @return the prefix of the attribute or <code>null</code> if no prefix.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- CharArray getAttributePrefix(int index);
-
- /**
- * Returns the XML type of the attribute at the provided index.
- *
- * @param index the position of the attribute
- * @return the XML type of the attribute.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- CharArray getAttributeType(int index);
-
- /**
- * Returns the value of the attribute at the index.
- *
- * @param index the position of the attribute.
- * @return the attribute value.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- CharArray getAttributeValue(int index);
-
- /**
- * Indicates if this attribute was created by default.
- *
- * @param index the position of the attribute.
- * @return <code>true</code> if this is a default attribute;
- * <code>false</code> otherwise.
- * @throws IllegalStateException if not a START_ELEMENT or ATTRIBUTE.
- */
- boolean isAttributeSpecified(int index);
-
- /**
- * Returns the count of namespaces declared on this START_ELEMENT or
- * END_ELEMENT. This method is only valid on a START_ELEMENT, END_ELEMENT or
- * NAMESPACE. On an END_ELEMENT the count is of the namespaces that are
- * about to go out of scope. This is the equivalent of the information
- * reported by SAX callback for an end element event.
- *
- * @return returns the number of namespace declarations on this specific
- * element.
- * @throws IllegalStateException if not a START_ELEMENT or END_ELEMENT.
- */
- int getNamespaceCount();
-
- /**
- * Returns the prefix for the namespace declared at the index.
- *
- * @param index the position of the namespace declaration.
- * @return returns the namespace prefix or <code>null</code> if no prefix.
- * @throws IllegalStateException if this is not a START_ELEMENT,
- * END_ELEMENT or NAMESPACE.
- */
- CharArray getNamespacePrefix(int index);
-
- /**
- * Returns the URI for the namespace declared at the index.
- *
- * @param index the position of the namespace declaration.
- * @return returns the namespace uri or <code>null</code> if no prefix.
- * @throws IllegalStateException if this is not a START_ELEMENT,
- * END_ELEMENT or NAMESPACE.
- */
- CharArray getNamespaceURI(int index);
-
- /**
- * Returns a read only namespace context for the current position.
- *
- * @return return a namespace context
- */
- NamespaceContext getNamespaceContext();
-
- /**
- * Returns an integer code that indicates the type of the event the cursor
- * is pointing to.
- *
- * @return the event type.
- */
- int getEventType();
-
- /**
- * Returns the current value of the parse event as a string, this returns
- * the string value of a CHARACTERS event, returns the value of a COMMENT,
- * the replacement value for an ENTITY_REFERENCE, the string value of a
- * CDATA section, the string value for a SPACE event, or the String value of
- * the internal subset of the DTD. If an ENTITY_REFERENCE has been resolved,
- * any character data will be reported as CHARACTERS events.
- *
- * @return the current text or <code>null</code>
- * @throws IllegalStateException if this state is not a valid text state.
- */
- CharArray getText();
-
- /**
- * Returns an array which contains the characters from this event. This
- * array should be treated as read-only and transient. I.e. the array will
- * contain the text characters until the XMLStreamReader moves on to the
- * next event. Attempts to hold onto the character array beyond that time or
- * modify the contents of the array are breaches of the contract for this
- * interface.
- *
- * @return the current text or an empty array.
- * @throws IllegalStateException if this state is not a valid text state.
- */
- char[] getTextCharacters();
-
- /**
- * Gets the the text associated with a CHARACTERS, SPACE or CDATA event.
- * Text starting a "sourceStart" is copied into "target" starting at
- * "targetStart". Up to "length" characters are copied. The number of
- * characters actually copied is returned.
- *
- * The "sourceStart" argument must be greater or equal to 0 and less than or
- * equal to the number of characters associated with the event. Usually, one
- * requests text starting at a "sourceStart" of 0. If the number of
- * characters actually copied is less than the "length", then there is no
- * more text. Otherwise, subsequent calls need to be made until all text has
- * been retrieved. For example:
- *
- * <code>
- * int length = 1024;
- * char[] myBuffer = new char[ length ];
- *
- * for ( int sourceStart = 0 ; ; sourceStart += length )
- * {
- * int nCopied = stream.getTextCharacters( sourceStart, myBuffer, 0, length );
- *
- * if (nCopied < length)
- * break;
- * }
- * </code> XMLStreamException may be thrown
- * if there are any XML errors in the underlying source. The "targetStart"
- * argument must be greater than or equal to 0 and less than the length of
- * "target", Length must be greater than 0 and "targetStart + length" must
- * be less than or equal to length of "target".
- *
- * @param sourceStart the index of te first character in the source array
- * to copy
- * @param target the destination array
- * @param targetStart the start offset in the target array
- * @param length the number of characters to copy
- * @return the number of characters actually copied
- * @throws XMLStreamException if the XML source is not well-formed.
- * @throws IndexOutOfBoundsException
- * if targetStart < 0 or > than the length of target
- * @throws IndexOutOfBoundsException
- * if length < 0 or targetStart + length > length of target
- * @throws UnsupportedOperationException if this method is not supported.
- */
- int getTextCharacters(int sourceStart, char[] target,
- int targetStart, int length) throws XMLStreamException;
-
- /**
- * Returns the offset into the text character array where the first
- * character (of this text event) is stored.
- *
- * @throws IllegalStateException if this state is not a valid text state.
- */
- int getTextStart();
-
- /**
- * Returns the length of the sequence of characters for this Text event
- * within the text character array.
- *
- * @throws IllegalStateException if this state is not a valid text state.
- */
- int getTextLength();
-
- /**
- * Returns the input encoding if known or <code>null</code> if unknown.
- *
- * @return the encoding of this instance or null.
- */
- String getEncoding();
-
- /**
- * Indicates if the current event has text. The following
- * events have text: CHARACTERS, DTD ,ENTITY_REFERENCE, COMMENT, SPACE.
- *
- * @return <code>true</code> if the current event as text;
- * <code>false</code> otherwise.
- */
- boolean hasText();
-
- /**
- * Return the current location of the processor. If the Location is unknown
- * the processor should return an implementation of Location that returns -1
- * for the location and null for the publicId and systemId. The location
- * information is only valid until next() is called.
- *
- * @return the current location.
- */
- Location getLocation();
-
- /**
- * Returns the (local) name of the current event. For START_ELEMENT or
- * END_ELEMENT returns the (local) name of the current element. For
- * ENTITY_REFERENCE it returns entity name. The current event must be
- * START_ELEMENT or END_ELEMENT, or ENTITY_REFERENCE.
- *
- * @return the localName.
- * @throws IllegalStateException if this not a START_ELEMENT, END_ELEMENT
- * or ENTITY_REFERENCE
- */
- CharArray getLocalName();
-
- /**
- * Indicates if the current event has a name (is a START_ELEMENT or
- * END_ELEMENT).
- *
- * @return <code>true</code> if the current event has a name;
- * <code>false</code> otherwise.
- */
- boolean hasName();
-
- /**
- * If the current event is a START_ELEMENT or END_ELEMENT this method
- * returns the URI of the current element (URI mapping to the prefix
- * element/attribute has; or if no prefix <code>null</code>).
- *
- * @return the URI bound to this elements prefix or <code>null</code>.
- * @throws IllegalStateException if not a START_ELEMENT, END_ELEMENT
- * or ATTRIBUTE.
- */
- CharArray getNamespaceURI();
-
- /**
- * Returns the prefix of the current event or null if the event does not
- * have a prefix.
- *
- * @return the prefix or <code>null</code>
- * @throws IllegalStateException if not a START_ELEMENT or END_ELEMENT.
- */
- CharArray getPrefix();
-
- /**
- * Gets the xml version declared on the xml declaration.
- *
- * @return the XML version or <code>null</code>
- */
- CharArray getVersion();
-
- /**
- * Gets the standalone declaration from the xml declaration.
- *
- * @return <code>true</code> if this is standalone;
- * <code>false</code> otherwise.
- */
- boolean isStandalone();
-
- /**
- * Checks if standalone was set in the document.
- *
- * @return <code>true</code> if standalone was set;
- * <code>false</code> otherwise.
- */
- boolean standaloneSet();
-
- /**
- * Returns the character encoding declared on the xml declaration.
- *
- * @return the encoding declared in the document or <code>null</code>
- */
- CharArray getCharacterEncodingScheme();
-
- /**
- * Returns the target of a processing instruction.
- *
- * @return the target.
- * @throws IllegalStateException if the current event is not a
- * {@link XMLStreamConstants#PROCESSING_INSTRUCTION}
- */
- CharArray getPITarget();
-
- /**
- * Get the data section of a processing instruction.
- *
- * @return the data (if processing instruction has any) or
- * <code>null</code> if the processing instruction only has target.
- * @throws IllegalStateException if the current event is not a
- * {@link XMLStreamConstants#PROCESSING_INSTRUCTION}
- */
- CharArray getPIData();
-
-}
[05/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/XMLContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/XMLContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/XMLContextImpl.java
deleted file mode 100644
index d4a3f6b..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/XMLContextImpl.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.internal;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-import javolution.util.FastMap;
-import javolution.xml.DefaultXMLFormat;
-import javolution.xml.XMLContext;
-import javolution.xml.XMLFormat;
-import javolution.xml.stream.XMLStreamException;
-
-/**
- * Holds the default implementation of XMLContext.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-@SuppressWarnings("rawtypes")
-public final class XMLContextImpl extends XMLContext {
-
- private final FastMap<Class<?>, XMLFormat<?>> formats = new FastMap<Class<?>, XMLFormat<?>>();
-
- @Override
- protected XMLContext inner() {
- XMLContextImpl ctx = new XMLContextImpl();
- ctx.formats.putAll(formats);
- return ctx;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected <T> XMLFormat<T> searchFormat(Class<? extends T> type) {
- XMLFormat xml = formats.get(type);
- if (xml != null)
- return xml;
- DefaultXMLFormat format = type.getAnnotation(DefaultXMLFormat.class);
- if (format != null) {
- Class<? extends XMLFormat> formatClass = format.value();
- try {
- xml = formatClass.newInstance();
- synchronized (formats) { // Required since possible concurrent use
- // (getFormatInContext is not a configuration method).
- formats.put(type, xml);
- }
- return xml;
- } catch (Throwable ex) {
- throw new RuntimeException(ex);
- }
- }
- // Check predefined format as last resource.
- if (Map.class.isAssignableFrom(type))
- return MAP_XML;
- if (Collection.class.isAssignableFrom(type))
- return COLLECTION_XML;
- return OBJECT_XML;
- }
-
- @Override
- public <T> void setFormat(Class<? extends T> type, XMLFormat<T> format) {
- formats.put(type, format);
- }
-
- /////////////////////////
- // PREDEFINED FORMATS //
- /////////////////////////
- /**
- * Holds the static XML format for <code>java.lang.Object.class</code> instances.
- * The XML representation consists of the text representation of the object
- * as a "value" attribute.
- */
- private static final XMLFormat OBJECT_XML = new XMLFormat.Default();
-
- /**
- * Holds the default XML representation for <code>java.util.Collection</code>
- * instances. This representation consists of nested XML elements one for
- * each element of the collection. The elements' order is defined by
- * the collection iterator order. Collections are deserialized using their
- * default constructor.
- */
- private static final XMLFormat COLLECTION_XML = new XMLFormat() {
-
- @SuppressWarnings("unchecked")
- public void read(XMLFormat.InputElement xml, Object obj)
- throws XMLStreamException {
- Collection collection = (Collection) obj;
- while (xml.hasNext()) {
- collection.add(xml.getNext());
- }
- }
-
- public void write(Object obj, XMLFormat.OutputElement xml)
- throws XMLStreamException {
- Collection collection = (Collection) obj;
- for (Iterator i = collection.iterator(); i.hasNext();) {
- xml.add(i.next());
- }
- }
-
- };
-
- /**
- * Holds the default XML representation for <code>java.util.Map</code>
- * instances. This representation consists of key/value pair as nested
- * XML elements. For example:[code]
- * <javolution.util.FastMap>
- * <Key class="java.lang.String" value="ONE"/>
- * <Value class="java.lang.Integer" value="1"/>
- * <Key class="java.lang.String" value="TWO"/>
- * <Value class="java.lang.Integer" value="2"/>
- * <Key class="java.lang.String" value="THREE"/>
- * <Value class="java.lang.Integer" value="3"/>
- * </javolution.util.FastMap>[/code]
- *
- * The elements' order is defined by the map's entries iterator order.
- * Maps are deserialized using their default constructor.
- */
- private static final XMLFormat MAP_XML = new XMLFormat() {
-
- @SuppressWarnings("unchecked")
- public void read(XMLFormat.InputElement xml, Object obj)
- throws XMLStreamException {
- final Map map = (Map) obj;
- while (xml.hasNext()) {
- Object key = xml.get("Key");
- Object value = xml.get("Value");
- map.put(key, value);
- }
- }
-
- public void write(Object obj, XMLFormat.OutputElement xml)
- throws XMLStreamException {
- final Map map = (Map) obj;
- for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- xml.add(entry.getKey(), "Key");
- xml.add(entry.getValue(), "Value");
- }
- }
-
- };
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/AttributesImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/AttributesImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/AttributesImpl.java
deleted file mode 100644
index 9953441..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/AttributesImpl.java
+++ /dev/null
@@ -1,170 +0,0 @@
-package javolution.xml.internal.stream;
-
-import javolution.text.CharArray;
-import javolution.util.FastTable;
-import javolution.xml.sax.Attributes;
-
-/**
- * This class provides the implementation of the {@link Attributes}
- * interface for the StAX parser.
- */
-public final class AttributesImpl implements Attributes {
-
- /**
- * Attribute implementation.
- */
- private static class AttributeImpl {
- CharArray localName;
- CharArray prefix; // null if no namespace URI.
- CharArray qName;
- CharArray value;
- public String toString() {
- return qName + "=" + value;
- }
- }
-
- private static final CharArray CDATA = new CharArray("CDATA");
-
- private static final CharArray EMPTY = new CharArray();
-
- /**
- * Holds the attributes.
- */
- private final FastTable<AttributeImpl> attributes = new FastTable<AttributeImpl>();
-
- /**
- * Holds the current number of attributes set.
- */
- private int length;
-
- /**
- * Holds the namespace stack.
- */
- private final NamespacesImpl namespaces;
-
- /**
- * Creates a list of attribute using the specified namespace stack.
- */
- public AttributesImpl(NamespacesImpl namespaces) {
- this.namespaces = namespaces;
- }
-
- /**
- * Adds an attribute to the end of the attribute list.
- *
- * @param localName the local name.
- * @param prefix the prefix or <code>null</code> if none.
- * @param qName the qualified (prefixed) name.
- * @param value the attribute value.
- */
- public void addAttribute(CharArray localName, CharArray prefix,
- CharArray qName, CharArray value) {
- AttributeImpl attribute;
- if (length >= attributes.size()) {
- attribute = new AttributeImpl();
- attributes.add(attribute);
- } else {
- attribute = attributes.get(length);
- }
- attribute.localName = localName;
- attribute.prefix = prefix;
- attribute.qName = qName;
- attribute.value = value;
- length++;
- }
-
- @Override
- public int getIndex(CharSequence qName) {
- for (int i = 0; i < length; i++) {
- if (qName.equals(attributes.get(i).qName))
- return i;
- }
- return -1;
- }
-
- @Override
- public int getIndex(CharSequence uri, CharSequence localName) {
- for (int i = 0; i < length; i++) {
- AttributeImpl attribute = attributes.get(i);
- if (localName.equals(attribute.localName)) {
- if (attribute.prefix == null) { // No namespace URI.
- if (uri.length() == 0)
- return i;
- } else { // Check if matching namespace URI.
- if (uri.equals(namespaces.getNamespaceURI(attribute.prefix)))
- return i;
- }
- }
- }
- return -1;
- }
-
- @Override
- public int getLength() {
- return length;
- }
-
- @Override
- public CharArray getLocalName(int index) {
- if ((index < 0) || (index >= length)) return null;
- return attributes.get(index).localName;
- }
-
- public CharArray getPrefix(int index) {
- if ((index < 0) || (index >= length)) return null;
- return attributes.get(index).prefix;
- }
-
- @Override
- public CharArray getQName(int index) {
- if ((index < 0) || (index >= length)) return null;
- return attributes.get(index).qName;
- }
-
- @Override
- public CharArray getType(CharSequence qName) {
- return (getIndex(qName) >= 0) ? CDATA : null;
- }
-
- @Override
- public CharArray getType(CharSequence uri, CharSequence localName) {
- return (getIndex(uri, localName) >= 0) ? CDATA : null;
- }
-
- @Override
- public CharArray getType(int index) {
- if ((index < 0) || (index >= length)) return null;
- return CDATA;
- }
- @Override
- public CharArray getURI(int index) {
- if ((index < 0) || (index >= length)) return null;
- CharArray prefix = attributes.get(index).prefix;
- return (prefix == null) ? EMPTY : namespaces.getNamespaceURI(prefix);
- }
-
- @Override
- public CharArray getValue(CharSequence qName) {
- final int index = getIndex(qName);
- return (index >= 0) ? attributes.get(index).value : null;
- }
-
- @Override
- public CharArray getValue(CharSequence uri, CharSequence localName) {
- final int index = getIndex(uri, localName);
- return (index >= 0) ? attributes.get(index).value : null;
- }
-
- @Override
- public CharArray getValue(int index) {
- if ((index < 0) || (index >= length)) return null;
- return attributes.get(index).value;
- }
-
- /**
- * Clear the attribute list for reuse.
- */
- public void reset() {
- length = 0;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/EntitiesImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/EntitiesImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/EntitiesImpl.java
deleted file mode 100644
index 72422d3..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/EntitiesImpl.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.internal.stream;
-
-import java.util.Map;
-
-import javolution.text.CharArray;
-import javolution.util.FastTable;
-import javolution.util.function.Function;
-import javolution.xml.stream.XMLStreamException;
-
-/**
- * Defines entities while parsing.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, June 16, 2006
- */
-public final class EntitiesImpl {
-
- /**
- * Holds maximum length.
- */
- private int _maxLength = 1;
-
- /**
- * Holds the user defined entities mapping.
- */
- private Map<String, String> _entitiesMapping;
-
- /**
- * Default constructor.
- */
- EntitiesImpl() {}
-
- /**
- * Returns the length of the largest entity defined (default {@code 1}).
- */
- public int getMaxLength() {
- return _maxLength;
- }
-
- /**
- * Replaces the entity at the specified position.
- * The five predefined XML entities "&lt;", "&gt;", "&apos;",
- * "&quot;", "&amp;" as well as character refererences
- * (decimal or hexadecimal) are always recognized.
- *
- * @param buffer the data buffer.
- * @param start the index of entity first character (index of '&')
- * @return the length of the replacement entity (including ';')
- * @throws XMLStreamException if the entity is not recognized.
- */
- public int replaceEntity(char[] buffer, int start, int length)
- throws XMLStreamException {
-
- // Checks for character references.
- if (buffer[start + 1] == '#') {
- char c = buffer[start + 2];
- int base = (c == 'x') ? 16 : 10;
- int i = (c == 'x') ? 3 : 2;
- int charValue = 0;
- for (; i < length - 1; i++) {
- c = buffer[start + i];
- charValue *= base;
- charValue += (c <= '9') ? (c - '0') : (c <= 'Z') ? c - 'A'
- : c - 'a';
- }
- buffer[start] = (char) charValue;
- return 1;
- }
-
- if ((buffer[start + 1] == 'l') && (buffer[start + 2] == 't')
- && (buffer[start + 3] == ';')) {
- buffer[start] = '<';
- return 1;
- }
-
- if ((buffer[start + 1] == 'g') && (buffer[start + 2] == 't')
- && (buffer[start + 3] == ';')) {
- buffer[start] = '>';
- return 1;
- }
-
- if ((buffer[start + 1] == 'a') && (buffer[start + 2] == 'p')
- && (buffer[start + 3] == 'o') && (buffer[start + 4] == 's')
- && (buffer[start + 5] == ';')) {
- buffer[start] = '\'';
- return 1;
- }
-
- if ((buffer[start + 1] == 'q') && (buffer[start + 2] == 'u')
- && (buffer[start + 3] == 'o') && (buffer[start + 4] == 't')
- && (buffer[start + 5] == ';')) {
- buffer[start] = '"';
- return 1;
- }
-
- if ((buffer[start + 1] == 'a') && (buffer[start + 2] == 'm')
- && (buffer[start + 3] == 'p') && (buffer[start + 4] == ';')) {
- buffer[start] = '&';
- return 1;
- }
-
- // Searches user defined entities.
- _tmp.setArray(buffer, start + 1, length - 2);
- CharSequence replacementText = (_entitiesMapping != null) ? _entitiesMapping
- .get(_tmp) : null;
- if (replacementText == null)
- throw new XMLStreamException("Entity " + _tmp + " not recognized");
- int replacementTextLength = replacementText.length();
- for (int i = 0; i < replacementTextLength; i++) {
- buffer[start + i] = replacementText.charAt(i);
- }
- return replacementTextLength;
- }
-
- private CharArray _tmp = new CharArray();
-
- /**
- * Sets the current custom entity mapping. For example: {@code
- * new FastMap().put("copy", "©")} to define the copyright entity.
- */
- public void setEntitiesMapping(Map<String, String> entityToReplacementText) {
- FastTable<String> values = new FastTable<String>();
- values.addAll(entityToReplacementText.values());
- _maxLength = values.mapped(new Function<CharSequence, Integer>() {
-
- @Override
- public Integer apply(CharSequence csq) {
- return csq.length();
- }}).max();
-
- _entitiesMapping = entityToReplacementText;
- }
-
- /**
- * Returns the custom entity mapping or {@code null} if none.
- */
- public Map<String, String> getEntitiesMapping() {
- return _entitiesMapping;
- }
-
- // Implements Reusable.
- public void reset() {
- _maxLength = 1;
- _entitiesMapping = null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/NamespacesImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/NamespacesImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/NamespacesImpl.java
deleted file mode 100644
index 47ff23b..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/NamespacesImpl.java
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.internal.stream;
-
-import java.util.Iterator;
-import javolution.text.CharArray;
-import javolution.util.FastTable;
-import javolution.xml.stream.NamespaceContext;
-
-/**
- * This class represents the namespaces stack while parsing.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 3.2, April 2, 2005
- */
-public final class NamespacesImpl implements NamespaceContext {
-
- /**
- * Holds the number of predefined namespaces.
- */
- static final int NBR_PREDEFINED_NAMESPACES = 3;
-
- /**
- * Holds useful CharArray instances (non-static to avoid potential
- * inter-thread corruption).
- */
- final CharArray _nullNsURI = new CharArray(""); // No namespace URI.
-
- final CharArray _defaultNsPrefix = new CharArray("");
-
- final CharArray _xml = new CharArray("xml");
-
- final CharArray _xmlURI = new CharArray(
- "http://www.w3.org/XML/1998/namespace");
-
- final CharArray _xmlns = new CharArray("xmlns");
-
- final CharArray _xmlnsURI = new CharArray("http://www.w3.org/2000/xmlns/");
-
- /**
- * Holds the current nesting level.
- */
- private int _nesting = 0;
-
- /**
- * Holds the currently mapped prefixes.
- */
- CharArray[] _prefixes = new CharArray[16];
-
- /**
- * Holds the currently mapped namespaces.
- */
- CharArray[] _namespaces = new CharArray[_prefixes.length];
-
- /**
- * Indicates if the prefix has to been written (when writing).
- */
- boolean[] _prefixesWritten = new boolean[_prefixes.length];
-
- /**
- * Holds the number of prefix/namespace association per nesting level.
- */
- int[] _namespacesCount = new int[16];
-
- /**
- * Holds the default namespace.
- */
- CharArray _defaultNamespace = _nullNsURI;
-
- /**
- * Holds the default namespace index.
- */
- int _defaultNamespaceIndex;
-
- /**
- * Default constructor.
- */
- public NamespacesImpl() {
- _prefixes[0] = _defaultNsPrefix;
- _namespaces[0] = _nullNsURI;
- _prefixes[1] = _xml;
- _namespaces[1] = _xmlURI;
- _prefixes[2] = _xmlns;
- _namespaces[2] = _xmlnsURI;
- _namespacesCount[0] = NBR_PREDEFINED_NAMESPACES;
- }
-
- // Implements NamespaceContext
- public CharArray getNamespaceURI(CharSequence prefix) {
- if (prefix == null)
- throw new IllegalArgumentException("null prefix not allowed");
- return getNamespaceURINullAllowed(prefix);
- }
-
- CharArray getNamespaceURINullAllowed(CharSequence prefix) {
- if ((prefix == null) || (prefix.length() == 0))
- return _defaultNamespace;
- final int count = _namespacesCount[_nesting];
- for (int i = count; --i >= 0;) {
- if (_prefixes[i].equals(prefix))
- return _namespaces[i];
- }
- return null; // Not bound.
- }
-
- // Implements NamespaceContext
- public CharArray getPrefix(CharSequence uri) {
- if (uri == null)
- throw new IllegalArgumentException("null namespace URI not allowed");
- return _defaultNamespace.equals(uri) ? _defaultNsPrefix : getPrefix(
- uri, _namespacesCount[_nesting]);
- }
-
- CharArray getPrefix(CharSequence uri, int count) {
- for (int i = count; --i >= 0;) {
- CharArray prefix = _prefixes[i];
- CharArray namespace = _namespaces[i];
- if (namespace.equals(uri)) { // Find matching uri.
- // Checks that the prefix has not been overwriten after being set.
- boolean isPrefixOverwritten = false;
- for (int j = i + 1; j < count; j++) {
- if (prefix.equals(_prefixes[j])) {
- isPrefixOverwritten = true;
- break;
- }
- }
- if (!isPrefixOverwritten)
- return prefix;
- }
- }
- return null; // Not bound.
- }
-
- // Implements NamespaceContext
- public Iterator<CharArray> getPrefixes(CharSequence namespaceURI) {
- FastTable<CharArray> prefixes = new FastTable<CharArray>();
- for (int i = _namespacesCount[_nesting]; --i >= 0;) {
- if (_namespaces[i].equals(namespaceURI)) {
- prefixes.add(_prefixes[i]);
- }
- }
- return prefixes.iterator();
- }
-
- // Null values are not allowed.
- void setPrefix(CharArray prefix, CharArray uri) {
- int index = _namespacesCount[_nesting];
- _prefixes[index] = prefix;
- _namespaces[index] = uri;
- if (prefix.length() == 0) { // The default namespace is set.
- _defaultNamespaceIndex = index;
- _defaultNamespace = uri;
- }
- if (++_namespacesCount[_nesting] >= _prefixes.length)
- resizePrefixStack();
- }
-
- // Used only by XMLStreamWriter (converts CharSequence to CharArray).
- // Null values are not allowed.
- void setPrefix(final CharSequence prefix, CharSequence uri,
- boolean isWritten) {
- final int index = _namespacesCount[_nesting];
- _prefixesWritten[index] = isWritten;
- final int prefixLength = prefix.length();
- CharArray prefixTmp = _prefixesTmp[index];
- if ((prefixTmp == null) || (prefixTmp.array().length < prefixLength)) {
- _prefixesTmp[index] = new CharArray().setArray(
- new char[prefixLength + 32], 0, 0);
- prefixTmp = _prefixesTmp[index];
- }
- for (int i = 0; i < prefixLength; i++) {
- prefixTmp.array()[i] = prefix.charAt(i);
- }
- prefixTmp.setArray(prefixTmp.array(), 0, prefixLength);
-
- final int uriLength = uri.length();
- CharArray namespaceTmp = _namespacesTmp[index];
- if ((namespaceTmp == null) || (namespaceTmp.array().length < uriLength)) {
- _namespacesTmp[index] = new CharArray().setArray(
- new char[uriLength + 32], 0, 0);
- namespaceTmp = _namespacesTmp[index];
- }
- for (int i = 0; i < uriLength; i++) {
- namespaceTmp.array()[i] = uri.charAt(i);
- }
- namespaceTmp.setArray(namespaceTmp.array(), 0, uriLength);
-
- // Sets the prefix using CharArray instances.
- setPrefix(prefixTmp, namespaceTmp);
- }
-
- private CharArray[] _prefixesTmp = new CharArray[_prefixes.length];
-
- private CharArray[] _namespacesTmp = new CharArray[_prefixes.length];
-
- void pop() {
- if (_namespacesCount[--_nesting] <= _defaultNamespaceIndex) {
- searchDefaultNamespace();
- }
- }
-
- private void searchDefaultNamespace() {
- int count = _namespacesCount[_nesting];
- for (int i = count; --i >= 0;) {
- if (_prefixes[i].length() == 0) {
- _defaultNamespaceIndex = i;
- return;
- }
- }
- throw new Error("Cannot find default namespace");
- }
-
- void push() {
- _nesting++;
- if (_nesting >= _namespacesCount.length) {
- resizeNamespacesCount();
- }
- _namespacesCount[_nesting] = _namespacesCount[_nesting - 1];
- }
-
- public void reset() {
- _defaultNamespace = _nullNsURI;
- _defaultNamespaceIndex = 0;
- _namespacesCount[0] = NBR_PREDEFINED_NAMESPACES;
- _nesting = 0;
- }
-
- private void resizeNamespacesCount() {
- final int oldLength = _namespacesCount.length;
- final int newLength = oldLength * 2;
-
- // Resizes namespaces counts.
- int[] tmp = new int[newLength];
- System.arraycopy(_namespacesCount, 0, tmp, 0, oldLength);
- _namespacesCount = tmp;
- }
-
- // Resizes prefix mapping stack.
- private void resizePrefixStack() {
- final int oldLength = _prefixes.length;
- final int newLength = oldLength * 2;
-
- // Resizes prefixes.
- CharArray[] tmp0 = new CharArray[newLength];
- System.arraycopy(_prefixes, 0, tmp0, 0, oldLength);
- _prefixes = tmp0;
-
- // Resizes namespaces uri.
- CharArray[] tmp1 = new CharArray[newLength];
- System.arraycopy(_namespaces, 0, tmp1, 0, oldLength);
- _namespaces = tmp1;
-
- // Resizes prefix sets.
- boolean[] tmp2 = new boolean[newLength];
- System.arraycopy(_prefixesWritten, 0, tmp2, 0, oldLength);
- _prefixesWritten = tmp2;
-
- // Resizes temporary prefix (CharSequence to CharArray conversion).
- CharArray[] tmp3 = new CharArray[newLength];
- System.arraycopy(_prefixesTmp, 0, tmp3, 0, oldLength);
- _prefixesTmp = tmp3;
-
- // Resizes temporary namespaces (CharSequence to CharArray conversion).
- CharArray[] tmp4 = new CharArray[newLength];
- System.arraycopy(_namespacesTmp, 0, tmp4, 0, oldLength);
- _namespacesTmp = tmp4;
-
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLInputFactoryImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLInputFactoryImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLInputFactoryImpl.java
deleted file mode 100644
index bd2eaa2..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLInputFactoryImpl.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.internal.stream;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.Map;
-
-import javolution.util.FastTable;
-import javolution.xml.stream.XMLInputFactory;
-import javolution.xml.stream.XMLStreamException;
-
-/**
- * The default XML input factory implementation.
- */
-public final class XMLInputFactoryImpl implements XMLInputFactory {
- private Map<String, String> _entities = null;
- private FastTable<XMLStreamReaderImpl> _recycled = new FastTable<XMLStreamReaderImpl>()
- .shared();
-
- // Implements XMLInputFactory abstract method.
- public XMLStreamReaderImpl createXMLStreamReader(InputStream stream)
- throws XMLStreamException {
- XMLStreamReaderImpl xmlReader = newReader();
- xmlReader.setInput(stream);
- return xmlReader;
- }
-
- // Implements XMLInputFactory abstract method.
- public XMLStreamReaderImpl createXMLStreamReader(InputStream stream,
- String encoding) throws XMLStreamException {
- XMLStreamReaderImpl xmlReader = newReader();
- xmlReader.setInput(stream, encoding);
- return xmlReader;
- }
-
- // Implements XMLInputFactory abstract method.
- public XMLStreamReaderImpl createXMLStreamReader(Reader reader)
- throws XMLStreamException {
- XMLStreamReaderImpl xmlReader = newReader();
- xmlReader.setInput(reader);
- return xmlReader;
- }
-
- // Implements XMLInputFactory abstract method.
- public Object getProperty(String name) throws IllegalArgumentException {
- if (name.equals(IS_COALESCING)) {
- return Boolean.TRUE;
- } else if (name.equals(ENTITIES)) {
- return _entities;
- } else {
- throw new IllegalArgumentException("Property: " + name
- + " not supported");
- }
- }
-
- // Implements XMLInputFactory abstract method.
- public boolean isPropertySupported(String name) {
- return name.equals(IS_COALESCING) || name.equals(ENTITIES);
- }
-
- // Implements XMLInputFactory abstract method.
- @SuppressWarnings("unchecked")
- public void setProperty(String name, Object value)
- throws IllegalArgumentException {
- if (name.equals(IS_COALESCING)) {
- // Do nothing, always coalescing.
- } else if (name.equals(ENTITIES)) {
- _entities = (Map<String, String>) value;
- } else {
- throw new IllegalArgumentException("Property: " + name
- + " not supported");
- }
- }
-
- /** Recycles the specified instance. */
- void recycle(XMLStreamReaderImpl reader) {
- _recycled.addLast(reader);
- }
-
- private XMLStreamReaderImpl newReader() {
- XMLStreamReaderImpl xmlReader = _recycled.pollLast();
- if (xmlReader == null) xmlReader = new XMLStreamReaderImpl(this);
- if (_entities != null) {
- xmlReader.setEntities(_entities);
- }
- return xmlReader;
- }
-
- @Override
- public XMLInputFactory clone() {
- try {
- XMLInputFactoryImpl clone = (XMLInputFactoryImpl) super.clone();
- clone._recycled = new FastTable<XMLStreamReaderImpl>().shared();
- return clone;
- } catch (CloneNotSupportedException e) {
- throw new Error();// Cannot happen since cloneable.
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLOutputFactoryImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLOutputFactoryImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLOutputFactoryImpl.java
deleted file mode 100644
index 7dfd18f..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLOutputFactoryImpl.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.internal.stream;
-
-import java.io.OutputStream;
-import java.io.Writer;
-
-import javolution.util.FastTable;
-import javolution.xml.stream.XMLOutputFactory;
-import javolution.xml.stream.XMLStreamException;
-
-/**
- * This default XML Output factory implementation.
- */
-public final class XMLOutputFactoryImpl implements XMLOutputFactory {
-
- // Property setting.
- private Boolean _automaticEmptyElements = Boolean.FALSE;
-
- // Property setting.
- private String _indentation;
-
- // Property setting.
- private Boolean _isRepairingNamespaces = Boolean.FALSE;
-
- // Property setting.
- private String _lineSeparator = "\n";
-
- // Property setting.
- private Boolean _noEmptyElementTag = Boolean.FALSE;
-
- // Property setting.
- private String _repairingPrefix = "ns";
-
- private FastTable<XMLStreamWriterImpl> _recycled = new FastTable<XMLStreamWriterImpl>()
- .shared();
-
- // Implements XMLOutputFactory abstract method.
- public XMLStreamWriterImpl createXMLStreamWriter(OutputStream stream)
- throws XMLStreamException {
- XMLStreamWriterImpl xmlWriter = newWriter();
- xmlWriter.setOutput(stream);
- return xmlWriter;
- }
-
- // Implements XMLOutputFactory abstract method.
- public XMLStreamWriterImpl createXMLStreamWriter(OutputStream stream,
- String encoding) throws XMLStreamException {
- if ((encoding == null) || encoding.equals("UTF-8")
- || encoding.equals("utf-8"))
- return createXMLStreamWriter(stream);
- XMLStreamWriterImpl xmlWriter = newWriter();
- xmlWriter.setOutput(stream, encoding);
- return xmlWriter;
- }
-
- // Implements XMLOutputFactory abstract method.
- public XMLStreamWriterImpl createXMLStreamWriter(Writer writer)
- throws XMLStreamException {
- XMLStreamWriterImpl xmlWriter = newWriter();
- xmlWriter.setOutput(writer);
- return xmlWriter;
- }
-
- // Implements XMLOutputFactory abstract method.
- public Object getProperty(String name) throws IllegalArgumentException {
- if (name.equals(IS_REPAIRING_NAMESPACES)) {
- return _isRepairingNamespaces;
- } else if (name.equals(REPAIRING_PREFIX)) {
- return _repairingPrefix;
- } else if (name.equals(AUTOMATIC_EMPTY_ELEMENTS)) {
- return _automaticEmptyElements;
- } else if (name.equals(NO_EMPTY_ELEMENT_TAG)) {
- return _noEmptyElementTag;
- } else if (name.equals(INDENTATION)) {
- return _indentation;
- } else if (name.equals(LINE_SEPARATOR)) {
- return _lineSeparator;
- } else {
- throw new IllegalArgumentException("Property: " + name
- + " not supported");
- }
- }
-
- // Implements XMLOutputFactory abstract method.
- public boolean isPropertySupported(String name) {
- return name.equals(IS_REPAIRING_NAMESPACES)
- || name.equals(REPAIRING_PREFIX)
- || name.equals(AUTOMATIC_EMPTY_ELEMENTS)
- || name.equals(NO_EMPTY_ELEMENT_TAG)
- || name.equals(INDENTATION) || name.equals(LINE_SEPARATOR);
- }
-
- // Implements XMLOutputFactory abstract method.
- public void setProperty(String name, Object value)
- throws IllegalArgumentException {
- if (name.equals(IS_REPAIRING_NAMESPACES)) {
- _isRepairingNamespaces = (Boolean) value;
- } else if (name.equals(REPAIRING_PREFIX)) {
- _repairingPrefix = (String) value;
- } else if (name.equals(AUTOMATIC_EMPTY_ELEMENTS)) {
- _automaticEmptyElements = (Boolean) value;
- } else if (name.equals(NO_EMPTY_ELEMENT_TAG)) {
- _noEmptyElementTag = (Boolean) value;
- } else if (name.equals(INDENTATION)) {
- _indentation = (String) value;
- } else if (name.equals(LINE_SEPARATOR)) {
- _lineSeparator = (String) value;
- } else {
- throw new IllegalArgumentException("Property: " + name
- + " not supported");
- }
- }
-
- /**
- * Recycles the specified writer instance.
- */
- void recycle(XMLStreamWriterImpl xmlWriter) {
- _recycled.addLast(xmlWriter);
- }
-
- private XMLStreamWriterImpl newWriter() {
- XMLStreamWriterImpl xmlWriter = _recycled.pollLast();
- if (xmlWriter == null) xmlWriter = new XMLStreamWriterImpl(this);
- xmlWriter.setRepairingNamespaces(_isRepairingNamespaces.booleanValue());
- xmlWriter.setRepairingPrefix(_repairingPrefix);
- xmlWriter.setIndentation(_indentation);
- xmlWriter.setLineSeparator(_lineSeparator);
- xmlWriter.setAutomaticEmptyElements(_automaticEmptyElements
- .booleanValue());
- xmlWriter.setNoEmptyElementTag(_noEmptyElementTag.booleanValue());
- return xmlWriter;
- }
-
- @Override
- public XMLOutputFactory clone() {
- try {
- XMLOutputFactoryImpl clone = (XMLOutputFactoryImpl) super.clone();
- clone._recycled = new FastTable<XMLStreamWriterImpl>().shared();
- return clone;
- } catch (CloneNotSupportedException e) {
- throw new Error();// Cannot happen since cloneable.
- }
- }
-}
[03/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamWriterImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamWriterImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamWriterImpl.java
deleted file mode 100644
index 4305189..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamWriterImpl.java
+++ /dev/null
@@ -1,939 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.internal.stream;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-import javolution.io.UTF8StreamWriter;
-import javolution.lang.Realtime;
-import javolution.text.CharArray;
-import javolution.text.TextBuilder;
-import javolution.xml.stream.XMLOutputFactory;
-import javolution.xml.stream.XMLStreamException;
-import javolution.xml.stream.XMLStreamWriter;
-
-/**
- * <p> This class represents an implementation of {@link XMLStreamWriter}.</p>
- *
- * <p> The <code>writeCharacters</code> methods will escape & , < and
- * >. For attribute values, the <code>writeAttribute</code> methods will
- * escape the above characters plus " and control characters.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, September 4, 2006
- */
-@Realtime
-public final class XMLStreamWriterImpl implements XMLStreamWriter {
-
- /**
- * Holds the length of intermediate buffer.
- */
- private static final int BUFFER_LENGTH = 2048;
-
- /**
- * Holds the current nesting level.
- */
- private int _nesting = 0;
-
- /**
- * Holds the element qualified name (indexed per nesting level)
- */
- private TextBuilder[] _qNames = new TextBuilder[16];
-
- /**
- * Indicates if the current element is open.
- */
- private boolean _isElementOpen;
-
- /**
- * Indicates if the current element is an empty element.
- */
- private boolean _isEmptyElement;
-
- /**
- * Holds intermediate buffer.
- */
- private final char[] _buffer = new char[BUFFER_LENGTH];
-
- /**
- * Holds the namespace stack.
- */
- private final NamespacesImpl _namespaces = new NamespacesImpl();
-
- /**
- * Holds the buffer current index.
- */
- private int _index;
-
- /**
- * Holds repairing namespace property.
- */
- private boolean _isRepairingNamespaces;
-
- /**
- * Holds repairing prefix property.
- */
- private String _repairingPrefix = "ns";
-
- /**
- * Holds indentation property.
- */
- private String _indentation;
-
- /**
- * Holds line separator property.
- */
- private String _lineSeparator = "\n";
-
- /**
- * Holds current indentation level.
- */
- private int _indentationLevel;
-
- /**
- * Holds automatic empty elements property.
- */
- private boolean _automaticEmptyElements;
-
- /**
- * Holds no empty element tag property.
- */
- private boolean _noEmptyElementTag;
-
- /**
- * Holds counter for automatic namespace generation.
- */
- private int _autoNSCount;
-
- /**
- * Indicates if the current object written is an attribute value.
- */
- private boolean _isAttributeValue;
-
- ////////////////////////
- // Temporary Settings //
- ////////////////////////
-
- /**
- * Holds the writer destination (<code>null</code> when unused).
- */
- private Writer _writer;
-
- /**
- * Holds the encoding (<code>null</code> if N/A).
- */
- private String _encoding;
-
- /**
- * Holds the default writer for output streams.
- */
- private final UTF8StreamWriter _utf8StreamWriter = new UTF8StreamWriter();
-
- /**
- * Holds the factory (if any)
- */
- private final XMLOutputFactoryImpl _factory;
-
- /**
- * Default constructor.
- */
- public XMLStreamWriterImpl() {
- this(null);
- }
-
- /**
- * Factory-based constructor.
- */
- XMLStreamWriterImpl(XMLOutputFactoryImpl factory) {
- _factory = factory;
- for (int i = 0; i < _qNames.length;) {
- _qNames[i++] = new TextBuilder();
- }
- }
-
- /**
- * Sets the output stream destination for this XML stream writer
- * (UTF-8 encoding).
- *
- * @param out the output source with utf-8 encoding.
- */
- public void setOutput(OutputStream out) throws XMLStreamException {
- _utf8StreamWriter.setOutput(out);
- _encoding = "UTF-8";
- setOutput(_utf8StreamWriter);
- }
-
- /**
- * Sets the output stream destination and encoding for this XML stream
- * writer.
- *
- * @param out the output source.
- * @param encoding the associated encoding.
- * @throws XMLStreamException if the specified encoding is not supported.
- */
- public void setOutput(OutputStream out, String encoding)
- throws XMLStreamException {
- if (encoding.equals("UTF-8") || encoding.equals("utf-8")
- || encoding.equals("ASCII")) {
- setOutput(out); // Default encoding.
- } else {
- try {
- _encoding = encoding;
- setOutput(new OutputStreamWriter(out, encoding));
- } catch (UnsupportedEncodingException e) {
- throw new XMLStreamException(e);
- }
- }
- }
-
- /**
- * Sets the writer output destination for this XML stream writer.
- *
- * @param writer the output destination writer.
- * @see javolution.io.UTF8StreamWriter
- * @see javolution.io.UTF8ByteBufferWriter
- * @see javolution.io.AppendableWriter
- */
- public void setOutput(Writer writer) throws XMLStreamException {
- if (_writer != null)
- throw new IllegalStateException("Writer not closed or reset");
- _writer = writer;
- }
-
- /**
- * Requires this writer to create a new prefix when a namespace has none
- * (default <code>false</code>).
- *
- * @param isRepairingNamespaces <code>true</code> if namespaces
- * are repaired; <code>false</code> otherwise.
- */
- public void setRepairingNamespaces(boolean isRepairingNamespaces) {
- _isRepairingNamespaces = isRepairingNamespaces;
- }
-
- /**
- * Specifies the prefix to be append by a trailing part
- * (a sequence number) in order to make it unique to be usable as
- * a temporary non-colliding prefix when repairing namespaces
- * (default <code>"ns"</code>).
- *
- * @param repairingPrefix the prefix root.
- */
- public void setRepairingPrefix(String repairingPrefix) {
- _repairingPrefix = repairingPrefix;
- }
-
- /**
- * Specifies the indentation string; non-null indentation
- * forces the writer to write elements into separate lines
- * (default <code>null</code>).
- *
- * @param indentation the indentation string.
- */
- public void setIndentation(String indentation) {
- _indentation = indentation;
- }
-
- /**
- * Specifies the line separator (default <code>"\n"</code>).
- *
- * @param lineSeparator the line separator string.
- */
- public void setLineSeparator(String lineSeparator) {
- _lineSeparator = lineSeparator;
- }
-
- /**
- * Requires this writer to automatically output empty elements when a
- * start element is immediately followed by matching end element
- * (default <code>false</code>).
- *
- * @param automaticEmptyElements <code>true</code> if start element
- * immediately followed by end element results in an empty element
- * beign written; <code>false</code> otherwise.
- */
- public void setAutomaticEmptyElements(boolean automaticEmptyElements) {
- _automaticEmptyElements = automaticEmptyElements;
- }
-
- /**
- * Prevent this writer from using empty element tags
- * (default <code>false</code>).
- *
- * @param noEmptyElementTag <code>true</code> if empty element tags
- * are replaced by start/end elements with no content;
- * <code>false</code> otherwise.
- */
- public void setNoEmptyElementTag(boolean noEmptyElementTag) {
- _noEmptyElementTag = noEmptyElementTag;
- }
-
- // Implements reusable.
- public void reset() {
- _automaticEmptyElements = false;
- _autoNSCount = 0;
- _encoding = null;
- _indentation = null;
- _indentationLevel = 0;
- _index = 0;
- _isAttributeValue = false;
- _isElementOpen = false;
- _isEmptyElement = false;
- _isRepairingNamespaces = false;
- _namespaces.reset();
- _nesting = 0;
- _noEmptyElementTag = false;
- _repairingPrefix = "ns";
- _utf8StreamWriter.reset();
- _writer = null;
-
- if (_factory != null)
- _factory.recycle(this);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeStartElement(CharSequence localName)
- throws XMLStreamException {
- if (localName == null)
- throw new XMLStreamException("Local name cannot be null");
- writeNewElement(null, localName, null);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeStartElement(CharSequence namespaceURI,
- CharSequence localName) throws XMLStreamException {
- if (localName == null)
- throw new XMLStreamException("Local name cannot be null");
- if (namespaceURI == null)
- throw new XMLStreamException("Namespace URI cannot be null");
- writeNewElement(null, localName, namespaceURI);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeStartElement(CharSequence prefix, CharSequence localName,
- CharSequence namespaceURI) throws XMLStreamException {
- if (localName == null)
- throw new XMLStreamException("Local name cannot be null");
- if (namespaceURI == null)
- throw new XMLStreamException("Namespace URI cannot be null");
- if (prefix == null)
- throw new XMLStreamException("Prefix cannot be null");
- writeNewElement(prefix, localName, namespaceURI);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeEmptyElement(CharSequence localName)
- throws XMLStreamException {
- writeStartElement(localName);
- _isEmptyElement = true;
- }
-
- // Implements XMLStreamWriter interface.
- public void writeEmptyElement(CharSequence namespaceURI,
- CharSequence localName) throws XMLStreamException {
- writeStartElement(namespaceURI, localName);
- _isEmptyElement = true;
- }
-
- // Implements XMLStreamWriter interface.
- public void writeEmptyElement(CharSequence prefix, CharSequence localName,
- CharSequence namespaceURI) throws XMLStreamException {
- writeStartElement(prefix, localName, namespaceURI);
- _isEmptyElement = true;
- }
-
- // Implements XMLStreamWriter interface.
- public void writeEndElement() throws XMLStreamException {
- if (_isElementOpen) { // Empty element.
- if (_isEmptyElement) { // Closes the empty element tag.
- closeOpenTag();
- } else { // Start element open.
- if (_automaticEmptyElements) { // Do as if empty element written.
- _isEmptyElement = true;
- closeOpenTag();
- return;
- } else { // Closes the start element tag.
- closeOpenTag();
- }
- }
- }
- if ((_indentation != null) && (_indentationLevel != _nesting - 1)) {
- // Do not indent if no change in indentation level
- // to avoid interfering with text only elements.
- writeNoEscape(_lineSeparator);
- for (int i = 1; i < _nesting; i++) {
- writeNoEscape(_indentation);
- }
- }
-
- write('<');
- write('/');
- writeNoEscape(_qNames[_nesting--]);
- write('>');
- _namespaces.pop();
- }
-
- // Implements XMLStreamWriter interface.
- public void writeEndDocument() throws XMLStreamException {
- if (_isElementOpen)
- closeOpenTag();
- while (_nesting > 0) { // Implicits closing of all elements.
- writeEndElement();
- }
- flush(); // Not mandatory but safer.
- }
-
- // Implements XMLStreamWriter interface.
- public void close() throws XMLStreamException {
- if (_writer != null) {
- if (_nesting != 0) { // Closes all elements.
- writeEndDocument();
- }
- flush();
- }
- reset(); // Explicit reset.
- }
-
- // Implements XMLStreamWriter interface.
- public void flush() throws XMLStreamException {
- flushBuffer();
- try {
- _writer.flush();
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- }
-
- // Implements XMLStreamWriter interface.
- public void writeAttribute(CharSequence localName, CharSequence value)
- throws XMLStreamException {
- if (localName == null)
- throw new XMLStreamException("Local name cannot be null");
- if (value == null)
- throw new XMLStreamException("Value cannot be null");
- writeAttributeOrNamespace(null, null, localName, value);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeAttribute(CharSequence namespaceURI,
- CharSequence localName, CharSequence value)
- throws XMLStreamException {
- if (localName == null)
- throw new XMLStreamException("Local name cannot be null");
- if (value == null)
- throw new XMLStreamException("Value cannot be null");
- if (namespaceURI == null)
- throw new XMLStreamException("Namespace URI cannot be null");
- writeAttributeOrNamespace(null, namespaceURI, localName, value);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeAttribute(CharSequence prefix, CharSequence namespaceURI,
- CharSequence localName, CharSequence value)
- throws XMLStreamException {
- if (localName == null)
- throw new XMLStreamException("Local name cannot be null");
- if (value == null)
- throw new XMLStreamException("Value cannot be null");
- if (namespaceURI == null)
- throw new XMLStreamException("Namespace URI cannot be null");
- if (prefix == null)
- throw new XMLStreamException("Prefix cannot be null");
- writeAttributeOrNamespace(prefix, namespaceURI, localName, value);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeNamespace(CharSequence prefix, CharSequence namespaceURI)
- throws XMLStreamException {
- if ((prefix == null) || (prefix.length() == 0)
- || _namespaces._xmlns.equals(prefix)) {
- prefix = _namespaces._defaultNsPrefix;
- }
- if (!_isElementOpen) // Check now as the actual writting is queued.
- throw new IllegalStateException("No open start element");
- _namespaces.setPrefix(prefix,
- (namespaceURI == null) ? _namespaces._nullNsURI : namespaceURI,
- true);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeDefaultNamespace(CharSequence namespaceURI)
- throws XMLStreamException {
- writeNamespace(_namespaces._defaultNsPrefix, namespaceURI);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeComment(CharSequence data) throws XMLStreamException {
- if (_isElementOpen)
- closeOpenTag();
- writeNoEscape("<!--");
- if (data != null) { // null values allowed.
- writeNoEscape(data);
- }
- writeNoEscape("-->");
- }
-
- // Implements XMLStreamWriter interface.
- public void writeProcessingInstruction(CharSequence target)
- throws XMLStreamException {
- writeProcessingInstruction(target, _noChar);
- }
-
- private final CharArray _noChar = new CharArray("");
-
- // Implements XMLStreamWriter interface.
- public void writeProcessingInstruction(CharSequence target,
- CharSequence data) throws XMLStreamException {
- if (target == null)
- throw new XMLStreamException("Target cannot be null");
- if (data == null)
- throw new XMLStreamException("Data cannot be null");
- if (_isElementOpen)
- closeOpenTag();
- writeNoEscape("<?");
- writeNoEscape(target);
- write(' ');
- writeNoEscape(data);
- writeNoEscape(" ?>");
- }
-
- // Implements XMLStreamWriter interface.
- public void writeCData(CharSequence data) throws XMLStreamException {
- if (data == null)
- throw new XMLStreamException("Data cannot be null");
- if (_isElementOpen)
- closeOpenTag();
- writeNoEscape("<![CDATA[");
- writeNoEscape(data);
- writeNoEscape("]]>");
- }
-
- // Implements XMLStreamWriter interface.
- public void writeDTD(CharSequence dtd) throws XMLStreamException {
- if (dtd == null)
- throw new XMLStreamException("DTD cannot be null");
- if (_nesting > 0)
- throw new XMLStreamException(
- "DOCTYPE declaration (DTD) when not in document root (prolog)");
- writeNoEscape(dtd);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeEntityRef(CharSequence name) throws XMLStreamException {
- write('&');
- writeNoEscape(name);
- write(';');
- }
-
- // Implements XMLStreamWriter interface.
- public void writeStartDocument() throws XMLStreamException {
- writeStartDocument(null, null);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeStartDocument(CharSequence version)
- throws XMLStreamException {
- writeStartDocument(null, version);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeStartDocument(CharSequence encoding, CharSequence version)
- throws XMLStreamException {
- if (_nesting > 0)
- throw new XMLStreamException("Not in document root");
- writeNoEscape("<?xml version=\"");
- if (version != null) {
- writeNoEscape(version);
- write('"');
- } else { // Default to 1.0
- writeNoEscape("1.0\"");
- }
- if (encoding != null) {
- writeNoEscape(" encoding=\"");
- writeNoEscape(encoding);
- write('"');
- } else if (_encoding != null) { // Use init encoding (if any).
- writeNoEscape(" encoding=\"");
- writeNoEscape(_encoding);
- write('"');
- }
- writeNoEscape(" ?>");
- }
-
- // Implements XMLStreamWriter interface.
- public void writeCharacters(CharSequence text) throws XMLStreamException {
- if (_isElementOpen)
- closeOpenTag();
- if (text == null)
- return;
- writeEscape(text);
- }
-
- // Implements XMLStreamWriter interface.
- public void writeCharacters(char[] text, int start, int length)
- throws XMLStreamException {
- _tmpCharArray.setArray(text, start, length);
- writeCharacters(_tmpCharArray);
- }
-
- private final CharArray _tmpCharArray = new CharArray();
-
- // Implements XMLStreamWriter interface.
- public CharSequence getPrefix(CharSequence uri) throws XMLStreamException {
- return _namespaces.getPrefix(uri);
- }
-
- // Implements XMLStreamWriter interface.
- public void setPrefix(CharSequence prefix, CharSequence uri)
- throws XMLStreamException {
- _namespaces.setPrefix(prefix, (uri == null) ? _namespaces._nullNsURI
- : uri, false);
- }
-
- // Implements XMLStreamWriter interface.
- public void setDefaultNamespace(CharSequence uri) throws XMLStreamException {
- setPrefix(_namespaces._defaultNsPrefix, uri);
- }
-
- // Implements XMLStreamWriter interface.
- public Object getProperty(String name) throws IllegalArgumentException {
- if (name.equals(XMLOutputFactory.IS_REPAIRING_NAMESPACES)) {
- return new Boolean(_isRepairingNamespaces);
- } else if (name.equals(XMLOutputFactory.REPAIRING_PREFIX)) {
- return _repairingPrefix;
- } else if (name.equals(XMLOutputFactory.AUTOMATIC_EMPTY_ELEMENTS)) {
- return new Boolean(_automaticEmptyElements);
- } else if (name.equals(XMLOutputFactory.NO_EMPTY_ELEMENT_TAG)) {
- return new Boolean(_noEmptyElementTag);
- } else if (name.equals(XMLOutputFactory.INDENTATION)) {
- return _indentation;
- } else if (name.equals(XMLOutputFactory.LINE_SEPARATOR)) {
- return _lineSeparator;
- } else {
- throw new IllegalArgumentException("Property: " + name
- + " not supported");
- }
- }
-
- // Writes a new start or empty element.
- private void writeNewElement(CharSequence prefix, CharSequence localName,
- CharSequence namespaceURI) throws XMLStreamException {
-
- // Close any open element and gets ready to write a new one.
- if (_isElementOpen)
- closeOpenTag();
- if (_indentation != null) {
- writeNoEscape(_lineSeparator);
- _indentationLevel = _nesting;
- for (int i = 0; i < _indentationLevel; i++) {
- writeNoEscape(_indentation);
- }
- }
- write('<');
- _isElementOpen = true;
-
- // Enters a new local scope.
- if (++_nesting >= _qNames.length)
- resizeElemStack();
- _namespaces.push();
-
- // Constructs qName.
- TextBuilder qName = _qNames[_nesting].clear();
-
- // Writes prefix if any.
- if ((namespaceURI != null)
- && (!_namespaces._defaultNamespace.equals(namespaceURI))) {
- if (_isRepairingNamespaces) { // Repairs prefix.
- prefix = getRepairedPrefix(prefix, namespaceURI);
- } else if (prefix == null) { // Retrieves prefix.
- prefix = getPrefix(namespaceURI);
- if (prefix == null)
- throw new XMLStreamException("URI: " + namespaceURI
- + " not bound and repairing namespaces disabled");
- }
- if (prefix.length() > 0) {
- qName.append(prefix);
- qName.append(':');
- }
- }
- qName.append(localName);
- writeNoEscape(qName);
- }
-
- // Writes a new attribute.
- private void writeAttributeOrNamespace(CharSequence prefix,
- CharSequence namespaceURI, CharSequence localName,
- CharSequence value) throws XMLStreamException {
- if (!_isElementOpen)
- throw new IllegalStateException("No open start element");
- write(' ');
-
- // Writes prefix if any.
- if ((namespaceURI != null)
- && (!_namespaces._defaultNamespace.equals(namespaceURI))) {
- if (_isRepairingNamespaces) { // Repairs prefix if current prefix is not correct.
- prefix = getRepairedPrefix(prefix, namespaceURI);
- } else if (prefix == null) {
- prefix = getPrefix(namespaceURI);
- if (prefix == null)
- throw new XMLStreamException("URI: " + namespaceURI
- + " not bound and repairing namespaces disabled");
- }
- if (prefix.length() > 0) {
- writeNoEscape(prefix);
- write(':');
- }
- }
-
- writeNoEscape(localName);
- write('=');
- write('"');
- _isAttributeValue = true;
- writeEscape(value);
- _isAttributeValue = false;
- write('"');
- }
-
- // Closes the current element (scope if empty element).
- private void closeOpenTag() throws XMLStreamException {
-
- // Writes namespaces now.
- writeNamespaces();
-
- // Closes the tag.
- _isElementOpen = false;
- if (_isEmptyElement) {
- if (_noEmptyElementTag) {
- write('<');
- write('/');
- writeNoEscape(_qNames[_nesting]);
- write('>');
- } else { // Use empty element tag.
- write('/');
- write('>');
- }
- _nesting--;
- _namespaces.pop();
- _isEmptyElement = false;
- } else {
- write('>');
- }
- }
-
- // Writes all namespaces, these include namespaces set but
- // not written in outer scope.
- private void writeNamespaces() throws XMLStreamException {
- int i0 = (_nesting > 1) ? _namespaces._namespacesCount[_nesting - 2]
- : NamespacesImpl.NBR_PREDEFINED_NAMESPACES;
- int i1 = _namespaces._namespacesCount[_nesting - 1];
- int i2 = _namespaces._namespacesCount[_nesting];
- for (int i = i0; i < i2; i++) {
- if (((_isRepairingNamespaces && (i < i1) && !_namespaces._prefixesWritten[i]))
- || ((i >= i1) && _namespaces._prefixesWritten[i])) { // Write namespace.
-
- // In repairing mode, removes redondancy.
- if (_isRepairingNamespaces) {
- CharArray prefix = _namespaces.getPrefix(
- _namespaces._namespaces[i], i);
- if (_namespaces._prefixes[i].equals(prefix))
- continue; // Not necessary.
- } // Direct mode, just write them as requested (no check).
-
- // Writes namespace.
- if (_namespaces._prefixes[i].length() == 0) { // Default namespace.
- writeAttributeOrNamespace(null, null, _namespaces._xmlns,
- _namespaces._namespaces[i]);
- } else {
- writeAttributeOrNamespace(_namespaces._xmlns,
- _namespaces._xmlnsURI, _namespaces._prefixes[i],
- _namespaces._namespaces[i]);
- }
- }
- }
- }
-
- // Returns the prefix for the specified namespace.
- private CharSequence getRepairedPrefix(CharSequence prefix,
- CharSequence namespaceURI) throws XMLStreamException {
- CharArray prefixForURI = _namespaces.getPrefix(namespaceURI);
- if ((prefixForURI != null)
- && ((prefix == null) || prefixForURI.equals(prefix)))
- return prefixForURI; // No repair needed.
- if ((prefix == null) || (prefix.length() == 0)) { // Creates new prefix.
- prefix = _autoPrefix.clear().append(_repairingPrefix)
- .append(_autoNSCount++);
- }
- _namespaces.setPrefix(prefix, namespaceURI, true); // Map to namespace URI.
- return prefix;
- }
-
- private final TextBuilder _autoPrefix = new TextBuilder();
-
- // Resizes element stack (same memory area as the writer).
- private void resizeElemStack() {
- final int oldLength = _qNames.length;
- final int newLength = oldLength * 2;
-
- // Resizes elements qNames stack.
- TextBuilder[] tmp = new TextBuilder[newLength];
- System.arraycopy(_qNames, 0, tmp, 0, oldLength);
- _qNames = tmp;
- for (int i = oldLength; i < newLength; i++) {
- _qNames[i] = new TextBuilder();
- }
- }
-
- // Writes methods.
- //
-
- private final void writeNoEscape(String str) throws XMLStreamException {
- write(str, 0, str.length(), false);
- }
-
- private final void writeNoEscape(TextBuilder tb) throws XMLStreamException {
- write(tb, 0, tb.length(), false);
- }
-
- private final void writeNoEscape(CharSequence csq)
- throws XMLStreamException {
- write(csq, 0, csq.length(), false);
- }
-
- private final void writeEscape(CharSequence csq) throws XMLStreamException {
- write(csq, 0, csq.length(), true);
- }
-
- private final void write(Object csq, int start, int length,
- boolean escapeMarkup) throws XMLStreamException {
- if (_index + length <= BUFFER_LENGTH) { // Enough buffer space.
- if (csq instanceof String) {
- ((String) csq).getChars(start, start + length, _buffer, _index);
- } else if (csq instanceof javolution.text.Text) {
- ((javolution.text.Text) csq).getChars(start, start + length,
- _buffer, _index);
- } else if (csq instanceof javolution.text.TextBuilder) {
- ((javolution.text.TextBuilder) csq).getChars(start, start
- + length, _buffer, _index);
- } else if (csq instanceof javolution.text.CharArray) {
- ((javolution.text.CharArray) csq).getChars(start, start
- + length, _buffer, _index);
- } else {
- getChars((CharSequence) csq, start, start + length, _buffer,
- _index);
- }
- if (escapeMarkup) {
- int end = _index + length;
- for (int i = _index; i < end; i++) {
- char c = _buffer[i];
- if ((c >= '?') || !isEscaped(c))
- continue;
- // Found character to escape.
- _index = i;
- flushBuffer();
- writeDirectEscapedCharacters(_buffer, i, end);
- return; // Done (buffer is empty).
- }
- }
- _index += length;
-
- } else { // Not enough remaining space.
- if (length <= BUFFER_LENGTH) { // Enough space if buffer emptied.
- flushBuffer();
- write(csq, start, length, escapeMarkup);
- } else {
- int half = length >> 1;
- write(csq, start, half, escapeMarkup);
- write(csq, start + half, length - half, escapeMarkup);
- }
- }
- }
-
- private static void getChars(CharSequence csq, int start, int end,
- char dest[], int destPos) {
- for (int i = start, j = destPos; i < end;) {
- dest[j++] = csq.charAt(i++);
- }
- }
-
- // The buffer must have been flushed prior to calling this method.
- private final void writeDirectEscapedCharacters(char[] chars, int start,
- int end) throws XMLStreamException {
- try {
- int blockStart = start;
- for (int i = start; i < end;) {
- char c = chars[i++];
- if ((c >= '?') || !isEscaped(c))
- continue;
- // Flush already read characters (excluding escaped one).
- int blockLength = i - blockStart - 1;
- if (blockLength > 0) {
- _writer.write(_buffer, blockStart, blockLength);
- }
- blockStart = i;
- switch (c) {
- case '<':
- _writer.write("<");
- break;
- case '>':
- _writer.write(">");
- break;
- case '\'':
- _writer.write("'");
- break;
- case '"':
- _writer.write(""");
- break;
- case '&':
- _writer.write("&");
- break;
- default:
- _writer.write("&#");
- _writer.write((char) ('0' + c / 10));
- _writer.write((char) ('0' + c % 10));
- _writer.write(';');
- }
- }
- // Flush the current block.
- int blockLength = end - blockStart;
- if (blockLength > 0) {
- _writer.write(_buffer, blockStart, blockLength);
- }
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- }
-
- private boolean isEscaped(char c) {
- return ((c < ' ') && _isAttributeValue)
- || (c == '"' && _isAttributeValue) || (c == '<') || (c == '>')
- || (c == '&');
- }
-
- private final void write(char c) throws XMLStreamException {
- if (_index == BUFFER_LENGTH) {
- flushBuffer();
- }
- _buffer[_index++] = c;
- }
-
- private void flushBuffer() throws XMLStreamException {
- try {
- _writer.write(_buffer, 0, _index);
- } catch (IOException e) {
- throw new XMLStreamException(e);
- } finally {
- _index = 0;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/xml/package-info.java
deleted file mode 100644
index 32c5661..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/package-info.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/**
-<p>Support for the encoding of objects, and the objects reachable from them,
- into <code>XML</code>; and the complementary reconstruction of the
- object graph from <code>XML</code>.
-</p>
-<p><i> This page has been translated into
-<a href="http://www.webhostinghub.com/support/es/misc/paquete-javolutionxml">Spanish</a>
-language by Maria Ramos from <a href="http://www.webhostinghub.com/support/edu">
-Webhostinghub.com/support/edu</a>.</i></p>
-
-<h2><a name="OVERVIEW">XML marshalling/unmarshalling facility:</a></h2>
-
-
-<IMG alt="XML Data Binding" src="doc-files/xmlDataBinding.png">
-
-<p> Key Advantages:<ul>
- <li> Real-time characteristics with no adverse effect on memory footprint or
- garbage collection (e.g. it can be used for time critical communications).
- {@link javolution.xml.XMLFormat XMLFormat} is basically a "smart"
- wrapper around our real-time StAX-like
- {@link javolution.xml.stream.XMLStreamReader XMLStreamReader} and
- {@link javolution.xml.stream.XMLStreamWriter XMLStreamWriter}.</li>
- <li> Works directly with your existing Java classes, no need to create new classes
- or customize your implementation in any way.</li>
- <li> The XML representation can be high level and impervious to obfuscation
- or changes to your implementation.</li>
- <li> Performance on a par or better than default Java<sup>TM</sup> Serialization/Deserialization
- (See <a href="https://bindmark.dev.java.net/">bindmark</a> for performance comparison).</li>
- <li> Small footprint, runs on any platform including Android.</li>
- <li> The XML mapping can be defined for a top class (or interface) and is automatically
- inherited by all sub-classes (or all implementing classes).</li>
- <li> Supports object references (to avoid expanding objects already serialized).</li>
- </ul>
-</p>
-
-<p> The default XML format for a class is typically defined using
- the {@link javolution.xml.DefaultXMLFormat} annotation tag.
-[code]
-@DefaultXMLFormat(Graphic.XML.class)
-public abstract class Graphic implements XMLSerializable {
- private boolean isVisible;
- private Paint paint; // null if none.
- private Stroke stroke; // null if none.
- private Transform transform; // null if none.
-
- // Default XML format with name associations (members identified by an unique name).
- // See XMLFormat for examples of positional associations.
- public static class XML extends XMLFormat {
- public void write(Graphic g, OutputElement xml) throws XMLStreamException {
- xml.setAttribute("isVisible", g.isVisible);
- xml.add(g.paint, "Paint");
- xml.add(g.stroke, "Stroke");
- xml.add(g.transform, "Transform");
- }
- public void read(InputElement xml, Graphic g) throws XMLStreamException {
- g.isVisible = xml.getAttribute("isVisible", true);
- g.paint = xml.get("Paint");
- g.stroke = xml.get("Stroke");
- g.transform = xml.get("Transform");
- }
- };
-}[/code]
- Sub-classes may override the inherited XML format:
-[code]
-@DefaultXMLFormat(Area.XML.class)
-public class Area extends Graphic {
- private Shape geometry;
-
- // Adds geometry to format.
- public static class XML extends XMLFormat<Area> {
- XMLFormat graphicXML = new Graphic.XML();
- public void write(Area area, OutputElement xml) throws XMLStreamException {
- graphicXML.write(area, xml); // Calls parent write.
- xml.add(area.geometry, "Geometry");
- }
- public void read(InputElement xml, Area area) throws XMLStreamException {
- graphicXML.read(xml, area); // Calls parent read.
- area.geometry = xml.get("Geometry");
- }
- };
-}[/code]
-
-The following writes a graphic area to a file, then reads it:
-
-[code]
-// Creates some useful aliases for class names.
-XMLBinding binding = new XMLBinding();
-binding.setAlias(Color.class, "Color");
-binding.setAlias(Polygon.class, "Polygon");
-binding.setClassAttribute("type"); // Use "type" instead of "class" for class attribute.
-
-// Writes the area to a file.
-XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream("C:/area.xml"));
-writer.setBinding(binding); // Optional.
-writer.setIndentation("\t"); // Optional (use tabulation for indentation).
-writer.write(area, "Area", Area.class);
-writer.close();
-
-// Reads the area back
-XMLObjectReader reader = XMLObjectReader.newInstance(new FileInputStream("C:/area.xml"));
-reader.setBinding(binding);
-Area a = reader.read("Area", Area.class);
-reader.close();
-[/code]
-
- Here is an example of valid XML representation for an area:
-
-[code]
-<Area isVisible="true">
- <Paint type="Color" rgb="#F3EBC6" />
- <Geometry type="Polygon">
- <Vertex x="123" y="-34" />
- <Vertex x="-43" y="-34" />
- <Vertex x="-12" y="123" />
- </Geometry>
-</Area>[/code]
-
-</p>
-<p> The following table illustrates the variety of XML representations supported
- (Foo class with a single String member named text):
- <center>
- <table cellpadding="2" cellspacing="2" border="1" style="text-align: left"><tbody>
- <tr>
- <td style="vertical-align: top; text-align: center;"><span style="font-weight: bold;">XML FORMAT</span></td>
- <td style="vertical-align: top; text-align: center;"><span style="font-weight: bold;">XML DATA</span></td>
- </tr>
- <tr>
-<td>[code]
-XMLFormat<Foo> XML = new XMLFormat<Foo>() {
- public void write(Foo foo, OutputElement xml) throws XMLStreamException {
- xml.setAttribute("text", foo.text);
- }
- public void read(InputElement xml, Foo foo) throws XMLStreamException {
- foo.text = xml.getAttribute("text", "");
- }
-};[/code]</td>
-<td><pre>
- <b><!-- Member as attribute --></b>
- <Foo text="This is a text"/>
-</pre></td>
- </tr>
-
- <tr>
-<td>
-[code]
-XMLFormat<Foo> XML = new XMLFormat<Foo>() {
- public void write(Foo foo, OutputElement xml) throws XMLStreamException {
- xml.add(foo.text);
- }
- public void read(InputElement xml, Foo foo) throws XMLStreamException {
- foo.text = xml.getNext();
- }
-};[/code]</td>
-<td><pre>
- <b><!-- Member as anonymous nested element --></b>
- <Foo>
- <java.lang.String value="This is a text"/>
- </Foo>
-</pre></td>
- </tr>
-
- <tr>
-<td>
-[code]
-XMLFormat<Foo> XML = new XMLFormat<Foo>(Foo.class) {
- public void write(Foo foo, OutputElement xml) throws XMLStreamException {
- xml.addText(foo.text); // or xml.getStreamWriter().writeCDATA(foo.text) to use CDATA block.
- }
- public void read(InputElement xml, Foo foo) throws XMLStreamException {
- foo.text = xml.getText().toString(); // Content of a text-only element.
- }
-};[/code]</td>
-<td><pre>
- <b><!-- Member as Character Data --></b>
- <Foo>This is a text</Foo>
-</pre></td>
- </tr>
-
- <tr>
-<td>
-[code]
-XMLFormat<Foo> XML = new XMLFormat<Foo>(Foo.class) {
- public void write(Foo foo, OutputElement xml) throws XMLStreamException {
- xml.add(foo.text, "Text");
- }
- public void read(InputElement xml, Foo foo) throws XMLStreamException {
- foo.text = xml.get("Text");
- }
-};[/code]</td>
-<td><pre>
- <b><!-- Member as named element of unknown type --></b>
- <Foo>
- <Text class="java.lang.String" value="This is a text"/>
- </Foo>
-</pre></td>
- </tr>
-
- <tr>
-<td><pre>
-[code]
-XMLFormat<Foo> XML = new XMLFormat<Foo>(Foo.class) {
- public void write(Foo foo, OutputElement xml) throws XMLStreamException {
- xml.add(foo.text, "Text", String.class);
- }
- public void read(InputElement xml, Foo foo) throws XMLStreamException {
- foo.text = xml.get("Text", String.class);
- }
-};[/code]</td>
-<td><pre>
- <b><!-- Member as named element of actual type known --></b>
- <Foo>
- <Text value="This is a text"/>
- </Foo>
-</pre></td>
- </tr>
- </tbody></table>
- </center>
-</p>
-
-<p> XML format do not have to use the classes
- public no-arg constructors, instances can be created using factory methods,
- private constructors (with constructor parameters set from the XML element)
- or even retrieved from a collection
- (if the object is shared or unique). For example:
-[code]
-@DefaultXMLFormat(Point.XML.class)
-public final class Point implements XMLSerializable {
- private int x;
- private int y;
- private Point() {}; // No-arg constructor not visible.
- public static Point valueOf(int x, int y) { ... }
- public static class XML = new XMLFormat<Point>() {
- public boolean isReferencable() {
- return false; // Always manipulated by value.
- }
- public Point newInstance(Class<Point> cls, InputElement xml) throws XMLStreamException {
- return Point.valueOf(xml.getAttribute("x", 0), xml.getAttribute("y", 0));
- }
- public void write(Point point, OutputElement xml) throws XMLStreamException {
- xml.setAttribute("x", point.x);
- xml.setAttribute("y", point.y);
- }
- public void read(InputElement xml, Point point) throws XMLStreamException {
- // Do nothing immutable.
- }
- };
-}[/code]
-</p>
-
-<p> Document cross-references are supported, including circular references.
- Let's take for example:
-[code]
-@DefaultXMLFormat(xml=Polygon.XML.class)
-public class Polygon implements Shape, XMLSerializable {
- private Point[] vertices;
- public static class XML extends XMLFormat<Polygon> {
- public void write(Polygon polygon, OutputElement xml) throws XMLStreamException {
- xml.setAttibutes("count", vertices.length);
- for (Point p : vertices) {
- xml.add(p, "Vertex", Point.class);
- }
- }
- public void read(InputElement xml, Polygon polygon) throws XMLStreamException {
- int count = xml.getAttributes("count", 0);
- polygon.vertices = new Point[count];
- for (int i=0; i < count; i++) {
- vertices[i] = xml.get("Vertex", Point.class);
- }
- }
- };
-}
-Polygon[] polygons = new Polygon[] {p1, p2, p1};
-...
-TextBuilder xml = TextBuilder.newInstance();
-AppendableWriter out = new AppendableWriter().setOutput(xml)
-XMLObjectWriter writer = XMLObjectWriter.newInstance(out);
-writer.setXMLReferenceResolver(new XMLReferenceResolver()); // Enables cross-references.
-writer.write(polygons, "Polygons", Polygon[].class);
-writer.close();
-System.out.println(xml);
-[/code]
- Prints the following (noticed that the first polygon and last one are being shared).
-[code]
-<Polygons length="3">
- <Polygon id="0" count="3">
- <Vertex x="123" y="-34" />
- <Vertex x="-43" y="-34" />
- <Vertex x="-12" y="123" />
- </Polygon>
- <Polygon id="1" count="3">
- <Vertex x="-43" y="-34" />
- <Vertex x="123" y="-34" />
- <Vertex x="-12" y="123" />
- </Polygon>
- <Polygon ref="0"/>
- </Polygons>[/code]
-</p>
-
-<B>ALGORITHMS:</B>
-
-<p> Our {@link javolution.xml.XMLObjectReader XMLObjectReader}/{@link javolution.xml.XMLObjectWriter XMLObjectWriter}
- are in fact simple wrappers around our <b>J</b>avolution high-performance StAX-like
- {@link javolution.xml.stream.XMLStreamReader XMLStreamReader} and
- {@link javolution.xml.stream.XMLStreamWriter XMLStreamWriter} classes.
- The logic of these wrappers is described below:
-<pre>
-
-OutputElement.add(object, name, uri, class):
-
-1. if (object == null) return
-
-2. getStreamWriter().writeStartElement(uri, name)
-
-3. isReference = referenceResolver.writeReference(object, this)
-
-4. if (!isReference) binding.getFormat(class).write(object, this)
-
-5. getStreamWriter().writeEndElement()
-
-6. end
-
-
-InputElement.get(name, uri, class):
-
-1. if (!getStreamReader().getLocalName().equals(name) ||
-!getStreamReader().getNamespaceURI().equals(uri)) return null
-
-2. object = referenceResolver.readReference(inputElement)
-
-3. if (object != null) Goto 8 // Found reference
-
-4. format = binding.getFormat(class)
-
-5. object = format.newInstance(class, inputElement)
-
-6. referenceResolver.createReference(object, inputElement) // Done before parsing to support circular references.
-
-7. format.read(inputElement, object)
-
-8. getStreamReader().nextTag()
-
-9. end
-</pre></p>
- */
-package javolution.xml;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java
deleted file mode 100644
index 9192ffc..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/Attributes.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.sax;
-
-import java.lang.CharSequence;
-
-import javolution.text.CharArray;
-
-/**
- * <p> This interface represents a list of XML attributes.</p>
- *
- * <p> It is a more efficient version of <code>org.xml.sax.Attributes</code>
- * with {@link CharArray CharArray}/{@link CharSequence CharSequence}
- * instead of the <code>String</code> to avoid forcing dynamic object
- * allocations.</p>
- *
- * @author <a href="mailto:sax@megginson.com">David Megginson</a>
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, June 16, 2006
- */
-public interface Attributes {
-
- /**
- * Returns the number of attributes in this list of attributes.
- *
- * @return the number of attributes.
- */
- int getLength();
-
- /**
- * Looks up an attribute's Namespace URI by index.
- *
- * @param index the attribute index (zero-based).
- * @return the Namespace URI, or an empty character sequence if none is
- * available, or <code>null</code> if the index is out of range.
- * @see #getLength
- */
- CharArray getURI(int index);
-
- /**
- * Looks up an attribute's local name by index.
- *
- * @param index the attribute index (zero-based).
- * @return the local name, or an empty character sequence if Namespace
- * processing is not being performed, or <code>null</code> if
- * the index is out of range.
- * @see #getLength
- */
- CharArray getLocalName(int index);
-
- /**
- * Looks up an attribute's XML 1.0 qualified name by index.
- *
- * @param index the attribute index (zero-based).
- * @return the XML 1.0 qualified name, or an empty character sequence if
- * none is available, or <code>null</code> if the index is out
- * of range.
- * @see #getLength
- */
- CharArray getQName(int index);
-
- /**
- * Looks up an attribute's type by index.
- *
- * <p> The attribute type is one of the strings "CDATA", "ID",
- * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
- * or "NOTATION" (always in upper case).</p>
- *
- * <p> If the parser has not read a declaration for the attribute,
- * or if the parser does not report attribute types, then it must
- * return the value "CDATA" as stated in the XML 1.0 Recommentation
- * (clause 3.3.3, "Attribute-TextBuilder Normalization").</p>
- *
- * <p> For an enumerated attribute that is not a notation, the
- * parser will report the type as "NMTOKEN".</p>
- *
- * @param index the attribute index (zero-based).
- * @return the attribute's type as a string, or null if the
- * index is out of range.
- * @see #getLength
- */
- CharArray getType(int index);
-
- /**
- * Looks up an attribute's value by index.
- *
- * <p> If the attribute value is a list of tokens (IDREFS,
- * ENTITIES, or NMTOKENS), the tokens will be concatenated
- * into a single string with each token separated by a
- * single space.</p>
- *
- * @param index the attribute index (zero-based).
- * @return the attribute's value as a character sequence,
- * <code>null</code> if the index is out of range.
- * @see #getLength
- */
- CharArray getValue(int index);
-
- /**
- * Looks up the index of an attribute by namespace name (convenience
- * method).
- * This method returns the index of the attribute whose uri/localName
- * have the same character content as the specified uri/localName.
- *
- * @param uri the Namespace URI, or an empty character sequence if
- * the name has no Namespace URI.
- * @param localName the attribute's local name.
- * @return the index of the attribute, or <code>-1</code> if it does not
- * appear in the list.
- */
- int getIndex(CharSequence uri, CharSequence localName);
-
- /**
- * Looks up the index of an attribute by XML 1.0 qualified name
- * (convenience method). This method returns the index of the attribute
- * whose name has the same character content as the specified qName.
- *
- * @param qName the qualified (prefixed) name.
- * @return the index of the attribute, or <code>-1</code> if it does not
- * appear in the list.
- */
- int getIndex(CharSequence qName);
-
- /**
- * Looks up an attribute's type by Namespace name (convenience method).
- * This method returns the type of the attribute whose uri/localName
- * have the same character content as the specified uri/localName.
- *
- * @param uri the Namespace URI, or an empty string if the
- * name has no Namespace URI.
- * @param localName the local name of the attribute.
- * @return the attribute type as a string, or null if the attribute is not
- * in the list or if Namespace processing is not being performed.
- */
- CharArray getType(CharSequence uri, CharSequence localName);
-
- /**
- * Looks up an attribute's type by XML 1.0 qualified name.
- * This method returns the type of the attribute whose qName
- * has the same character content as the specified qName.
- *
- * @param qName The XML 1.0 qualified name.
- * @return the attribute type as a string, or null if the attribute is not
- * in the list or if qualified names are not available.
- */
- CharArray getType(CharSequence qName);
-
- /**
- * Looks up an attribute's value by Namespace name (convenience method).
- * This method returns the value of the attribute whose uri/localName
- * have the same character content as the specified uri/localName.
- *
- * @param uri the Namespace URI, or the empty string if the name has no
- * Namespace URI.
- * @param localName the local name of the attribute.
- * @return the attribute value as a character sequence, or <code>null</code>
- * if the attribute is not in the list.
- */
- CharArray getValue(CharSequence uri, CharSequence localName);
-
- /**
- * Looks up an attribute's value by XML 1.0 qualified name (convenience
- * method). This method returns the value of the attribute whose qName
- * has the same character content as the specified qName.
- *
- * @param qName The XML 1.0 qualified name.
- * @return the attribute value as a character sequence, or <code>null</code>
- * if the attribute is not in the list or if qualified names
- * are not available.
- */
- CharArray getValue(CharSequence qName);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/ContentHandler.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/ContentHandler.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/ContentHandler.java
deleted file mode 100644
index 3c38511..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/ContentHandler.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.sax;
-
-import javolution.text.CharArray;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-
-/**
- * <p> Receives notification of the logical content of a document.</p>
- *
- * <p> It is a more efficient version of <code>org.xml.sax.ContentHandler</code>
- * with {@link CharArray CharArray}/{@link CharSequence CharSequence}
- * instead of the <code>String</code> to avoid forcing dynamic object
- * allocations.</p>
- *
- * @author <a href="mailto:sax@megginson.com">David Megginson</a>
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, June 16, 2006
- */
-public interface ContentHandler {
-
- /**
- * Receives an object for locating the origin of SAX document events.
- *
- * @param locator the document locator.
- */
- void setDocumentLocator(Locator locator);
-
- /**
- * Receives notification of the beginning of a document.
- *
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void startDocument() throws SAXException;
-
- /**
- * Receives notification of the end of a document.
- *
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void endDocument() throws SAXException;
-
- /**
- * Begins the scope of a prefix-URI Namespace mapping.
- *
- * @param prefix the Namespace prefix being declared.
- * @param uri the namespace URI the prefix is mapped to.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void startPrefixMapping(CharArray prefix, CharArray uri)
- throws SAXException;
-
- /**
- * Ends the scope of a prefix-URI mapping.
- *
- * @param prefix the prefix that was being mapping.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void endPrefixMapping(CharArray prefix) throws SAXException;
-
- /**
- * Receives notification of the beginning of an element.
- *
- * @param uri the namespace URI, or an empty character sequence if the
- * element has no Namespace URI or if namespace processing is not
- * being performed.
- * @param localName the local name (without prefix), or an empty character
- * sequence if namespace processing is not being performed.
- * @param qName the qualified name (with prefix), or an empty character
- * sequence if qualified names are not available.
- * @param atts the attributes attached to the element. If there are no
- * attributes, it shall be an empty {@link Attributes} object.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void startElement(CharArray uri, CharArray localName, CharArray qName,
- Attributes atts) throws SAXException;
-
- /**
- * Receives notification of the end of an element.
- *
- * @param uri the namespace URI, or an empty character sequence if the
- * element has no Namespace URI or if namespace processing is not
- * being performed.
- * @param localName the local name (without prefix), or an empty character
- * sequence if namespace processing is not being performed.
- * @param qName the qualified XML 1.0 name (with prefix), or an empty
- * character sequence if qualified names are not available.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void endElement(CharArray uri, CharArray localName, CharArray qName)
- throws SAXException;
-
- /**
- * Receives notification of character data.
- *
- * @param ch the characters from the XML document.
- * @param start the start position in the array.
- * @param length the number of characters to read from the array.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void characters(char ch[], int start, int length) throws SAXException;
-
- /**
- * Receives notification of ignorable whitespace in element content.
- *
- * @param ch the characters from the XML document.
- * @param start the start position in the array.
- * @param length the number of characters to read from the array.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void ignorableWhitespace(char ch[], int start, int length)
- throws SAXException;
-
- /**
- * Receives notification of a processing instruction.
- *
- * @param target the processing instruction target.
- * @param data the processing instruction data, or null if
- * none was supplied. The data does not include any
- * whitespace separating it from the target.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void processingInstruction(CharArray target, CharArray data)
- throws SAXException;
-
- /**
- * Receives notification of a skipped entity.
- *
- * @param name the name of the skipped entity. If it is a
- * parameter entity, the name will begin with '%', and if
- * it is the external DTD subset, it will be the character sequence
- * "[dtd]".
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- void skippedEntity(CharArray name) throws SAXException;
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/DefaultHandler.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/DefaultHandler.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/DefaultHandler.java
deleted file mode 100644
index 325e832..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/DefaultHandler.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.sax;
-
-import javolution.text.CharArray;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/**
- * Default base class for real-time handling of XML events.
- *
- * @author <a href="mailto:sax@megginson.com">David Megginson</a>
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 3.1, March 11, 2005
- */
-public class DefaultHandler implements ContentHandler, ErrorHandler {
-
- /**
- * Receives notification of a warning. The default behaviour is to take no
- * action.
- *
- * @param e the warning information encapsulated in a SAX parse exception.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- public void warning(SAXParseException e) throws SAXException {}
-
- /**
- * Receives notification of recoverable parser error. The default behaviour
- * is to take no action.
- *
- * @param e the error information encapsulated in a SAX parse exception.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- public void error(SAXParseException e) throws SAXException {}
-
- /**
- * Reports a fatal XML parsing error. The default behaviour is to throw
- * the specified exception.
- *
- * @param e the error information encapsulated in a SAX parse exception.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- public void fatalError(SAXParseException e) throws SAXException {
- throw e;
- }
-
- // Implements ContentHandler
- public void setDocumentLocator(Locator locator) {}
-
- // Implements ContentHandler
- public void startDocument() throws SAXException {}
-
- // Implements ContentHandler
- public void endDocument() throws SAXException {}
-
- // Implements ContentHandler
- public void startPrefixMapping(CharArray prefix, CharArray uri)
- throws SAXException {}
-
- // Implements ContentHandler
- public void endPrefixMapping(CharArray prefix) throws SAXException {}
-
- // Implements ContentHandler
- public void startElement(CharArray namespaceURI, CharArray localName,
- CharArray qName, Attributes atts) throws SAXException {}
-
- // Implements ContentHandler
- public void endElement(CharArray namespaceURI, CharArray localName,
- CharArray qName) throws SAXException {}
-
- // Implements ContentHandler
- public void characters(char ch[], int start, int length)
- throws SAXException {}
-
- // Implements ContentHandler
- public void ignorableWhitespace(char ch[], int start, int length)
- throws SAXException {}
-
- // Implements ContentHandler
- public void processingInstruction(CharArray target, CharArray data)
- throws SAXException {}
-
- // Implements ContentHandler
- public void skippedEntity(CharArray name) throws SAXException {}
-
- /**
- * <p> Generates compile-time error if <code>startElement</code> is not
- * correctly overriden. This method generates a compile-error
- * <code>"final method cannot be overridden"</code> if
- * <code>org.xml.sax.Attributes</code> is used instead of
- * <code>javolution.xml.sax.Attributes</code> (common mistake).</p>
- * @param uri the namespace URI, or an empty character sequence if the
- * element has no Namespace URI or if namespace processing is not
- * being performed.
- * @param localName the local name (without prefix), or an empty character
- * sequence if namespace processing is not being performed.
- * @param qName the qualified name (with prefix), or an empty character
- * sequence if qualified names are not available.
- * @param atts the attributes attached to the element. If there are no
- * attributes, it shall be an empty {@link Attributes} object.
- * @throws org.xml.sax.SAXException any SAX exception.
- */
- protected final void startElement(CharArray uri, CharArray localName,
- CharArray qName, org.xml.sax.Attributes atts) throws SAXException {
- throw new UnsupportedOperationException();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/SAX2ReaderImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/SAX2ReaderImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/sax/SAX2ReaderImpl.java
deleted file mode 100644
index 3b51cd9..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/sax/SAX2ReaderImpl.java
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.sax;
-
-import java.io.IOException;
-
-import javolution.text.CharArray;
-import javolution.text.Text;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.DTDHandler;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.XMLReader;
-
-import java.lang.CharSequence;
-
-/**
- * <p> This class provides a SAX2-compliant parser wrapping a
- * {@link javolution.xml.sax.XMLReaderImpl}. This parser allocates
- * <code>java.lang.String</code> instances while parsing in accordance
- * with the SAX2 specification. For faster performance (2-5x), the use of
- * the SAX2-like {@link javolution.xml.sax.XMLReaderImpl
- * XMLSaxParserImpl} or better{@link javolution.xml.stream.XMLStreamReader
- * XMLStreamReader} is recommended.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 4.0, June 16, 2005
- * @see <a href="http://www.saxproject.org"> SAX -- Simple API for XML</a>
- */
-public final class SAX2ReaderImpl implements XMLReader {
-
- /**
- * Holds the SAX2 default handler instance.
- */
- private static Sax2DefaultHandler DEFAULT_HANDLER = new Sax2DefaultHandler();
-
- /**
- * Holds the real-time parser instance associated to this SAX2 parser.
- */
- private final XMLReaderImpl _parser = new XMLReaderImpl();
-
- /**
- * Holds the content handler proxy.
- */
- private final Proxy _proxy = new Proxy();
-
- /**
- * Default constructor.
- */
- public SAX2ReaderImpl() {}
-
- // Implements org.xml.sax.XMLReader interface.
- public boolean getFeature(String name) throws SAXNotRecognizedException,
- SAXNotSupportedException {
- return _parser.getFeature(name);
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void setFeature(String name, boolean value)
- throws SAXNotRecognizedException, SAXNotSupportedException {
- _parser.setFeature(name, value);
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public Object getProperty(String name) throws SAXNotRecognizedException,
- SAXNotSupportedException {
- return _parser.getProperty(name);
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void setProperty(String name, Object value)
- throws SAXNotRecognizedException, SAXNotSupportedException {
- _parser.setProperty(name, value);
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void setEntityResolver(EntityResolver resolver) {
- _parser.setEntityResolver(resolver);
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public EntityResolver getEntityResolver() {
- return _parser.getEntityResolver();
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void setDTDHandler(DTDHandler handler) {
- _parser.setDTDHandler(handler);
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public DTDHandler getDTDHandler() {
- return _parser.getDTDHandler();
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void setContentHandler(ContentHandler handler) {
- if (handler != null) {
- _proxy._sax2Handler = handler;
- _parser.setContentHandler(_proxy);
- } else {
- throw new NullPointerException();
- }
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public ContentHandler getContentHandler() {
- return (_proxy._sax2Handler == DEFAULT_HANDLER) ? null
- : _proxy._sax2Handler;
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void setErrorHandler(ErrorHandler handler) {
- _parser.setErrorHandler(handler);
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public ErrorHandler getErrorHandler() {
- return _parser.getErrorHandler();
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void parse(InputSource input) throws IOException, SAXException {
- try {
- _parser.parse(input);
- } finally {
- _parser.reset();
- }
- }
-
- // Implements org.xml.sax.XMLReader interface.
- public void parse(String systemId) throws IOException, SAXException {
- try {
- _parser.parse(systemId);
- } finally {
- _parser.reset();
- }
- }
-
- // Implements Reusable interface.
- public void reset() {
- _parser.reset();
- }
-
- /**
- * This class defines the proxy for content handler and attributes.
- */
- private static final class Proxy implements
- javolution.xml.sax.ContentHandler, Attributes {
-
- /**
- * Holds the SAX2 content handler to which SAX2 events are forwarded.
- */
- private ContentHandler _sax2Handler = DEFAULT_HANDLER;
-
- /**
- * Holds the real-time attributes implementation from which attributes
- * values are read.
- */
- private javolution.xml.sax.Attributes _attributes;
-
- /**
- * Default constructor.
- */
- public Proxy() {}
-
- // Implements ContentHandler
- public void setDocumentLocator(Locator locator) {
- _sax2Handler.setDocumentLocator(locator);
- }
-
- // Implements ContentHandler
- public void startDocument() throws SAXException {
- _sax2Handler.startDocument();
- }
-
- // Implements ContentHandler
- public void endDocument() throws SAXException {
- _sax2Handler.endDocument();
- _sax2Handler = DEFAULT_HANDLER;
- }
-
- // Implements ContentHandler
- public void startPrefixMapping(CharArray prefix, CharArray uri)
- throws SAXException {
- _sax2Handler.startPrefixMapping(prefix.toString(), uri.toString());
- }
-
- // Implements ContentHandler
- public void endPrefixMapping(CharArray prefix) throws SAXException {
- _sax2Handler.endPrefixMapping(prefix.toString());
- }
-
- // Implements ContentHandler
- public void startElement(CharArray namespaceURI, CharArray localName,
- CharArray qName, javolution.xml.sax.Attributes atts)
- throws SAXException {
- _attributes = atts;
- _sax2Handler.startElement(namespaceURI.toString(),
- localName.toString(), qName.toString(), this);
- }
-
- // Implements ContentHandler
- public void endElement(CharArray namespaceURI, CharArray localName,
- CharArray qName) throws SAXException {
- _sax2Handler.endElement(namespaceURI.toString(),
- localName.toString(), qName.toString());
- }
-
- // Implements ContentHandler
- public void characters(char ch[], int start, int length)
- throws SAXException {
- _sax2Handler.characters(ch, start, length);
- }
-
- // Implements ContentHandler
- public void ignorableWhitespace(char ch[], int start, int length)
- throws SAXException {
- _sax2Handler.ignorableWhitespace(ch, start, length);
- }
-
- // Implements ContentHandler
- public void processingInstruction(CharArray target, CharArray data)
- throws SAXException {
- _sax2Handler.processingInstruction(target.toString(),
- data.toString());
- }
-
- // Implements ContentHandler
- public void skippedEntity(CharArray name) throws SAXException {
- _sax2Handler.skippedEntity(name.toString());
- }
-
- // Implements Attributes
- public int getLength() {
- return (_attributes != null ? _attributes.getLength() : 0);
- }
-
- // Implements Attributes
- public String getURI(int index) {
- CharSequence chars = (_attributes != null ? _attributes
- .getURI(index) : null);
- return (chars != null ? chars.toString() : "");
- }
-
- // Implements Attributes
- public String getLocalName(int index) {
- CharSequence chars = (_attributes != null ? _attributes
- .getLocalName(index) : null);
- return (chars != null ? chars.toString() : "");
- }
-
- // Implements Attributes
- public String getQName(int index) {
- CharSequence chars = (_attributes != null ? _attributes
- .getQName(index) : null);
- return (chars != null ? chars.toString() : "");
- }
-
- // Implements Attributes
- public String getType(int index) {
- return (_attributes != null ? _attributes.getType(index).toString()
- : null);
- }
-
- // Implements Attributes
- public String getValue(int index) {
- CharSequence chars = (_attributes != null ? _attributes
- .getValue(index) : null);
- return (chars != null ? chars.toString() : null);
- }
-
- // Implements Attributes
- public int getIndex(String uri, String localName) {
- return (uri != null && localName != null && _attributes != null ? _attributes
- .getIndex(toCharSequence(uri), toCharSequence(localName))
- : -1);
- }
-
- // Implements Attributes
- public int getIndex(String qName) {
- return (qName != null && _attributes != null ? _attributes
- .getIndex(toCharSequence(qName)) : -1);
- }
-
- // Implements Attributes
- public String getType(String uri, String localName) {
- return (uri != null && localName != null && _attributes != null ? _attributes
- .getType(toCharSequence(uri), toCharSequence(localName))
- .toString() : null);
- }
-
- // Implements Attributes
- public String getType(String qName) {
- return (qName != null && _attributes != null ? _attributes.getType(
- toCharSequence(qName)).toString() : null);
- }
-
- // Implements Attributes
- public String getValue(String uri, String localName) {
- return (uri != null
- && localName != null
- && _attributes != null
- && _attributes.getValue(toCharSequence(uri),
- toCharSequence(localName)) != null ? _attributes
- .getValue(toCharSequence(uri), toCharSequence(localName))
- .toString() : null);
- }
-
- // Implements Attributes
- public String getValue(String qName) {
- return (qName != null && _attributes != null ? _attributes
- .getValue(toCharSequence(qName)).toString() : null);
- }
- }
-
- private static final class Sax2DefaultHandler implements EntityResolver,
- DTDHandler, ContentHandler, ErrorHandler {
-
- public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException, IOException {
- return null;
- }
-
- public void notationDecl(String name, String publicId, String systemId)
- throws SAXException {}
-
- public void unparsedEntityDecl(String name, String publicId,
- String systemId, String notationName) throws SAXException {}
-
- public void setDocumentLocator(Locator locator) {}
-
- public void startDocument() throws SAXException {}
-
- public void endDocument() throws SAXException {}
-
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {}
-
- public void endPrefixMapping(String prefix) throws SAXException {}
-
- public void startElement(String uri, String localName, String qName,
- Attributes atts) throws SAXException {}
-
- public void endElement(String uri, String localName, String qName)
- throws SAXException {}
-
- public void characters(char[] ch, int start, int length)
- throws SAXException {}
-
- public void ignorableWhitespace(char[] ch, int start, int length)
- throws SAXException {}
-
- public void processingInstruction(String target, String data)
- throws SAXException {}
-
- public void skippedEntity(String name) throws SAXException {}
-
- public void warning(SAXParseException exception) throws SAXException {}
-
- public void error(SAXParseException exception) throws SAXException {}
-
- public void fatalError(SAXParseException exception) throws SAXException {
- throw exception;
- }
- }
-
- private static CharSequence toCharSequence(Object obj) {
- return obj instanceof CharSequence ? (CharSequence) obj : Text
- .valueOf(obj);
- }
-
-}
\ No newline at end of file
[11/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferReader.java b/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferReader.java
deleted file mode 100644
index 5defa8c..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferReader.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-import java.io.CharConversionException;
-import java.io.IOException;
-import java.io.Reader;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-
-/**
- * <p> A UTF-8 <code>java.nio.ByteBuffer</code> reader.
- * </p>
- *
- * <p> This reader can be used for efficient decoding of native byte
- * buffers (e.g. <code>MappedByteBuffer</code>), high-performance
- * messaging (no intermediate buffer), etc.</p>
- *
- * <p> This reader supports surrogate <code>char</code> pairs (representing
- * characters in the range [U+10000 .. U+10FFFF]). It can also be used
- * to read characters unicodes (31 bits) directly
- * (ref. {@link #read()}).</p>
- *
- * <p> Each invocation of one of the <code>read()</code> methods may cause one
- * or more bytes to be read from the underlying byte buffer.
- * The end of stream is reached when the byte buffer position and limit
- * coincide.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 2.0, December 9, 2004
- * @see UTF8ByteBufferWriter
- */
-public final class UTF8ByteBufferReader extends Reader {
-
- /**
- * Holds the byte buffer source.
- */
- private ByteBuffer _byteBuffer;
-
- /**
- * Default constructor.
- */
- public UTF8ByteBufferReader() {}
-
- /**
- * Sets the <code>ByteBuffer</code> to use for reading available bytes
- * from current buffer position.
- *
- * @param byteBuffer the <code>ByteBuffer</code> source.
- * @return this UTF-8 reader.
- * @throws IllegalStateException if this reader is being reused and
- * it has not been {@link #close closed} or {@link #reset reset}.
- */
- public UTF8ByteBufferReader setInput(ByteBuffer byteBuffer) {
- if (_byteBuffer != null)
- throw new IllegalStateException("Reader not closed or reset");
- _byteBuffer = byteBuffer;
- return this;
- }
-
- /**
- * Indicates if this stream is ready to be read.
- *
- * @return <code>true</code> if the byte buffer has remaining bytes to
- * read; <code>false</code> otherwise.
- * @throws IOException if an I/O error occurs.
- */
- public boolean ready() throws IOException {
- if (_byteBuffer != null) {
- return _byteBuffer.hasRemaining();
- } else {
- throw new IOException("Reader closed");
- }
- }
-
- /**
- * Closes and {@link #reset resets} this reader for reuse.
- *
- * @throws IOException if an I/O error occurs.
- */
- public void close() throws IOException {
- if (_byteBuffer != null) {
- reset();
- }
- }
-
- /**
- * Reads a single character. This method does not block, <code>-1</code>
- * is returned if the buffer's limit has been reached.
- *
- * @return the 31-bits Unicode of the character read, or -1 if there is
- * no more remaining bytes to be read.
- * @throws IOException if an I/O error occurs (e.g. incomplete
- * character sequence being read).
- */
- public int read() throws IOException {
- if (_byteBuffer != null) {
- if (_byteBuffer.hasRemaining()) {
- byte b = _byteBuffer.get();
- return (b >= 0) ? b : read2(b);
- } else {
- return -1;
- }
- } else {
- throw new IOException("Reader closed");
- }
- }
-
- // Reads one full character, throws CharConversionException if limit reached.
- private int read2(byte b) throws IOException {
- try {
- // Decodes UTF-8.
- if ((b >= 0) && (_moreBytes == 0)) {
- // 0xxxxxxx
- return b;
- } else if (((b & 0xc0) == 0x80) && (_moreBytes != 0)) {
- // 10xxxxxx (continuation byte)
- _code = (_code << 6) | (b & 0x3f); // Adds 6 bits to code.
- if (--_moreBytes == 0) {
- return _code;
- } else {
- return read2(_byteBuffer.get());
- }
- } else if (((b & 0xe0) == 0xc0) && (_moreBytes == 0)) {
- // 110xxxxx
- _code = b & 0x1f;
- _moreBytes = 1;
- return read2(_byteBuffer.get());
- } else if (((b & 0xf0) == 0xe0) && (_moreBytes == 0)) {
- // 1110xxxx
- _code = b & 0x0f;
- _moreBytes = 2;
- return read2(_byteBuffer.get());
- } else if (((b & 0xf8) == 0xf0) && (_moreBytes == 0)) {
- // 11110xxx
- _code = b & 0x07;
- _moreBytes = 3;
- return read2(_byteBuffer.get());
- } else if (((b & 0xfc) == 0xf8) && (_moreBytes == 0)) {
- // 111110xx
- _code = b & 0x03;
- _moreBytes = 4;
- return read2(_byteBuffer.get());
- } else if (((b & 0xfe) == 0xfc) && (_moreBytes == 0)) {
- // 1111110x
- _code = b & 0x01;
- _moreBytes = 5;
- return read2(_byteBuffer.get());
- } else {
- throw new CharConversionException("Invalid UTF-8 Encoding");
- }
- } catch (BufferUnderflowException e) {
- throw new CharConversionException("Incomplete Sequence");
- }
- }
-
- private int _code;
-
- private int _moreBytes;
-
- /**
- * Reads characters into a portion of an array. This method does not
- * block.
- *
- * <p> Note: Characters between U+10000 and U+10FFFF are represented
- * by surrogate pairs (two <code>char</code>).</p>
- *
- * @param cbuf the destination buffer.
- * @param off the offset at which to start storing characters.
- * @param len the maximum number of characters to read
- * @return the number of characters read, or -1 if there is no more
- * byte remaining.
- * @throws IOException if an I/O error occurs.
- */
- public int read(char cbuf[], int off, int len) throws IOException {
- if (_byteBuffer == null)
- throw new IOException("Reader closed");
- final int off_plus_len = off + len;
- int remaining = _byteBuffer.remaining();
- if (remaining <= 0)
- return -1;
- for (int i = off; i < off_plus_len;) {
- if (remaining-- > 0) {
- byte b = _byteBuffer.get();
- if (b >= 0) {
- cbuf[i++] = (char) b; // Most common case.
- } else {
- if (i < off_plus_len - 1) { // Up to two 'char' can be read.
- int code = read2(b);
- remaining = _byteBuffer.remaining(); // Recalculates.
- if (code < 0x10000) {
- cbuf[i++] = (char) code;
- } else if (code <= 0x10ffff) { // Surrogates.
- cbuf[i++] = (char) (((code - 0x10000) >> 10) + 0xd800);
- cbuf[i++] = (char) (((code - 0x10000) & 0x3ff) + 0xdc00);
- } else {
- throw new CharConversionException(
- "Cannot convert U+"
- + Integer.toHexString(code)
- + " to char (code greater than U+10FFFF)");
- }
- } else { // Not enough space in destination (go back).
- _byteBuffer.position(_byteBuffer.position() - 1);
- remaining++;
- return i - off;
- }
- }
- } else {
- return i - off;
- }
- }
- return len;
- }
-
- /**
- * Reads characters into the specified appendable. This method does not
- * block.
- *
- * <p> Note: Characters between U+10000 and U+10FFFF are represented
- * by surrogate pairs (two <code>char</code>).</p>
- *
- * @param dest the destination buffer.
- * @throws IOException if an I/O error occurs.
- */
- public void read(Appendable dest) throws IOException {
- if (_byteBuffer == null)
- throw new IOException("Reader closed");
- while (_byteBuffer.hasRemaining()) {
- byte b = _byteBuffer.get();
- if (b >= 0) {
- dest.append((char) b); // Most common case.
- } else {
- int code = read2(b);
- if (code < 0x10000) {
- dest.append((char) code);
- } else if (code <= 0x10ffff) { // Surrogates.
- dest.append((char) (((code - 0x10000) >> 10) + 0xd800));
- dest.append((char) (((code - 0x10000) & 0x3ff) + 0xdc00));
- } else {
- throw new CharConversionException("Cannot convert U+"
- + Integer.toHexString(code)
- + " to char (code greater than U+10FFFF)");
- }
- }
- }
- }
-
- public void reset() {
- _byteBuffer = null;
- _code = 0;
- _moreBytes = 0;
- }
-
- /**
- * @deprecated Replaced by {@link #setInput(ByteBuffer)}
- */
- public UTF8ByteBufferReader setByteBuffer(ByteBuffer byteBuffer) {
- return this.setInput(byteBuffer);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferWriter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferWriter.java b/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferWriter.java
deleted file mode 100644
index 5765c41..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8ByteBufferWriter.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-import java.io.CharConversionException;
-import java.io.IOException;
-import java.io.Writer;
-import java.nio.ByteBuffer;
-
-/**
- * <p> A UTF-8 <code>java.nio.ByteBuffer</code> writer.</p>
- *
- * <p> This writer supports surrogate <code>char</code> pairs (representing
- * characters in the range [U+10000 .. U+10FFFF]). It can also be used
- * to write characters from their unicodes (31 bits) directly
- * (ref. {@link #write(int)}).</p>
- *
- * <p> Instances of this class can be reused for different output streams
- * and can be part of a higher level component (e.g. serializer) in order
- * to avoid dynamic buffer allocation when the destination output changes.
- * Also wrapping using a <code>java.io.BufferedWriter</code> is unnescessary
- * as instances of this class embed their own data buffers.</p>
- *
- * <p> Note: This writer is unsynchronized and always produces well-formed
- * UTF-8 sequences.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 2.0, December 9, 2004
- * @see UTF8ByteBufferReader
- */
-public final class UTF8ByteBufferWriter extends Writer {
-
- /**
- * Holds the byte buffer destination.
- */
- private ByteBuffer _byteBuffer;
-
- /**
- * Default constructor.
- */
- public UTF8ByteBufferWriter() {}
-
- /**
- * Sets the byte buffer to use for writing until this writer is closed.
- *
- * @param byteBuffer the destination byte buffer.
- * @return this UTF-8 writer.
- * @throws IllegalStateException if this writer is being reused and
- * it has not been {@link #close closed} or {@link #reset reset}.
- */
- public UTF8ByteBufferWriter setOutput(ByteBuffer byteBuffer) {
- if (_byteBuffer != null)
- throw new IllegalStateException("Writer not closed or reset");
- _byteBuffer = byteBuffer;
- return this;
- }
-
- /**
- * Writes a single character. This method supports 16-bits
- * character surrogates.
- *
- * @param c <code>char</code> the character to be written (possibly
- * a surrogate).
- * @throws IOException if an I/O error occurs.
- */
- public void write(char c) throws IOException {
- if ((c < 0xd800) || (c > 0xdfff)) {
- write((int) c);
- } else if (c < 0xdc00) { // High surrogate.
- _highSurrogate = c;
- } else { // Low surrogate.
- int code = ((_highSurrogate - 0xd800) << 10) + (c - 0xdc00)
- + 0x10000;
- write(code);
- }
- }
-
- private char _highSurrogate;
-
- /**
- * Writes a character given its 31-bits Unicode.
- *
- * @param code the 31 bits Unicode of the character to be written.
- * @throws IOException if an I/O error occurs.
- */
- public void write(int code) throws IOException {
- if ((code & 0xffffff80) == 0) {
- _byteBuffer.put((byte) code);
- } else { // Writes more than one byte.
- write2(code);
- }
- }
-
- private void write2(int c) throws IOException {
- if ((c & 0xfffff800) == 0) { // 2 bytes.
- _byteBuffer.put((byte) (0xc0 | (c >> 6)));
- _byteBuffer.put((byte) (0x80 | (c & 0x3f)));
- } else if ((c & 0xffff0000) == 0) { // 3 bytes.
- _byteBuffer.put((byte) (0xe0 | (c >> 12)));
- _byteBuffer.put((byte) (0x80 | ((c >> 6) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | (c & 0x3f)));
- } else if ((c & 0xff200000) == 0) { // 4 bytes.
- _byteBuffer.put((byte) (0xf0 | (c >> 18)));
- _byteBuffer.put((byte) (0x80 | ((c >> 12) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | ((c >> 6) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | (c & 0x3f)));
- } else if ((c & 0xf4000000) == 0) { // 5 bytes.
- _byteBuffer.put((byte) (0xf8 | (c >> 24)));
- _byteBuffer.put((byte) (0x80 | ((c >> 18) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | ((c >> 12) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | ((c >> 6) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | (c & 0x3f)));
- } else if ((c & 0x80000000) == 0) { // 6 bytes.
- _byteBuffer.put((byte) (0xfc | (c >> 30)));
- _byteBuffer.put((byte) (0x80 | ((c >> 24) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | ((c >> 18) & 0x3f)));
- _byteBuffer.put((byte) (0x80 | ((c >> 12) & 0x3F)));
- _byteBuffer.put((byte) (0x80 | ((c >> 6) & 0x3F)));
- _byteBuffer.put((byte) (0x80 | (c & 0x3F)));
- } else {
- throw new CharConversionException("Illegal character U+"
- + Integer.toHexString(c));
- }
- }
-
- /**
- * Writes a portion of an array of characters.
- *
- * @param cbuf the array of characters.
- * @param off the offset from which to start writing characters.
- * @param len the number of characters to write.
- * @throws IOException if an I/O error occurs.
- */
- public void write(char cbuf[], int off, int len) throws IOException {
- final int off_plus_len = off + len;
- for (int i = off; i < off_plus_len;) {
- char c = cbuf[i++];
- if (c < 0x80) {
- _byteBuffer.put((byte) c);
- } else {
- write(c);
- }
- }
- }
-
- /**
- * Writes a portion of a string.
- *
- * @param str a String.
- * @param off the offset from which to start writing characters.
- * @param len the number of characters to write.
- * @throws IOException if an I/O error occurs
- */
- public void write(String str, int off, int len) throws IOException {
- final int off_plus_len = off + len;
- for (int i = off; i < off_plus_len;) {
- char c = str.charAt(i++);
- if (c < 0x80) {
- _byteBuffer.put((byte) c);
- } else {
- write(c);
- }
- }
- }
-
- /**
- * Writes the specified character sequence.
- *
- * @param csq the character sequence.
- * @throws IOException if an I/O error occurs
- */
- public void write(CharSequence csq) throws IOException {
- final int length = csq.length();
- for (int i = 0; i < length;) {
- char c = csq.charAt(i++);
- if (c < 0x80) {
- _byteBuffer.put((byte) c);
- } else {
- write(c);
- }
- }
- }
-
- /**
- * Flushes the stream (this method has no effect, the data is
- * always directly written to the <code>ByteBuffer</code>).
- *
- * @throws IOException if an I/O error occurs.
- */
- public void flush() throws IOException {
- if (_byteBuffer == null) { throw new IOException("Writer closed"); }
- }
-
- /**
- * Closes and {@link #reset resets} this writer for reuse.
- *
- * @throws IOException if an I/O error occurs
- */
- public void close() throws IOException {
- if (_byteBuffer != null) {
- reset();
- }
- }
-
- // Implements Reusable.
- public void reset() {
- _byteBuffer = null;
- _highSurrogate = 0;
- }
-
- /**
- * @deprecated Replaced by {@link #setOutput(ByteBuffer)}
- */
- public UTF8ByteBufferWriter setByteBuffer(ByteBuffer byteBuffer) {
- return this.setOutput(byteBuffer);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamReader.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamReader.java b/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamReader.java
deleted file mode 100644
index 61fa4fb..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamReader.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-import java.io.CharConversionException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-/**
- * <p> A UTF-8 stream reader.</p>
- *
- * <p> This reader supports surrogate <code>char</code> pairs (representing
- * characters in the range [U+10000 .. U+10FFFF]). It can also be used
- * to read characters unicodes (31 bits) directly
- * (ref. {@link #read()}).</p>
- *
- * <p> Each invocation of one of the <code>read()</code> methods may cause one
- * or more bytes to be read from the underlying byte-input stream.
- * To enable the efficient conversion of bytes to characters, more bytes may
- * be read ahead from the underlying stream than are necessary to satisfy
- * the current read operation.</p>
- *
- * <p> Instances of this class can be reused for different input streams
- * and can be part of a higher level component (e.g. parser) in order
- * to avoid dynamic buffer allocation when the input source changes.
- * Also wrapping using a <code>java.io.BufferedReader</code> is unnescessary
- * as instances of this class embed their own data buffers.</p>
- *
- * <p> Note: This reader is unsynchronized and does not test if the UTF-8
- * encoding is well-formed (e.g. UTF-8 sequences longer than
- * necessary to encode a character).</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 2.0, December 9, 2004
- * @see UTF8StreamWriter
- */
-public final class UTF8StreamReader extends Reader {
-
- /**
- * Holds the current input stream or <code>null</code> if closed.
- */
- private InputStream _inputStream;
-
- /**
- * Holds the start index.
- */
- private int _start;
-
- /**
- * Holds the end index.
- */
- private int _end;
-
- /**
- * Holds the bytes buffer.
- */
- private final byte[] _bytes;
-
- /**
- * Creates a UTF-8 reader having a byte buffer of moderate capacity (2048).
- */
- public UTF8StreamReader() {
- _bytes = new byte[2048];
- }
-
- /**
- * Creates a UTF-8 reader having a byte buffer of specified capacity.
- *
- * @param capacity the capacity of the byte buffer.
- */
- public UTF8StreamReader(int capacity) {
- _bytes = new byte[capacity];
- }
-
- /**
- * Sets the input stream to use for reading until this reader is closed.
- * For example:[code]
- * Reader reader = new UTF8StreamReader().setInput(inStream);
- * [/code] is equivalent but reads twice as fast as [code]
- * Reader reader = new java.io.InputStreamReader(inStream, "UTF-8");
- * [/code]
- *
- * @param inStream the input stream.
- * @return this UTF-8 reader.
- * @throws IllegalStateException if this reader is being reused and
- * it has not been {@link #close closed} or {@link #reset reset}.
- */
- public UTF8StreamReader setInput(InputStream inStream) {
- if (_inputStream != null)
- throw new IllegalStateException("Reader not closed or reset");
- _inputStream = inStream;
- return this;
- }
-
- /**
- * Indicates if this stream is ready to be read.
- *
- * @return <code>true</code> if the next read() is guaranteed not to block
- * for input; <code>false</code> otherwise.
- * @throws IOException if an I/O error occurs.
- */
- public boolean ready() throws IOException {
- if (_inputStream == null)
- throw new IOException("Stream closed");
- return ((_end - _start) > 0) || (_inputStream.available() != 0);
- }
-
- /**
- * Closes and {@link #reset resets} this reader for reuse.
- *
- * @throws IOException if an I/O error occurs.
- */
- public void close() throws IOException {
- if (_inputStream != null) {
- _inputStream.close();
- reset();
- }
- }
-
- /**
- * Reads a single character. This method will block until a character is
- * available, an I/O error occurs or the end of the stream is reached.
- *
- * @return the 31-bits Unicode of the character read, or -1 if the end of
- * the stream has been reached.
- * @throws IOException if an I/O error occurs.
- */
- public int read() throws IOException {
- byte b = _bytes[_start];
- return ((b >= 0) && (_start++ < _end)) ? b : read2();
- }
-
- // Reads one full character, blocks if necessary.
- private int read2() throws IOException {
- if (_start < _end) {
- byte b = _bytes[_start++];
-
- // Decodes UTF-8.
- if ((b >= 0) && (_moreBytes == 0)) {
- // 0xxxxxxx
- return b;
- } else if (((b & 0xc0) == 0x80) && (_moreBytes != 0)) {
- // 10xxxxxx (continuation byte)
- _code = (_code << 6) | (b & 0x3f); // Adds 6 bits to code.
- if (--_moreBytes == 0) {
- return _code;
- } else {
- return read2();
- }
- } else if (((b & 0xe0) == 0xc0) && (_moreBytes == 0)) {
- // 110xxxxx
- _code = b & 0x1f;
- _moreBytes = 1;
- return read2();
- } else if (((b & 0xf0) == 0xe0) && (_moreBytes == 0)) {
- // 1110xxxx
- _code = b & 0x0f;
- _moreBytes = 2;
- return read2();
- } else if (((b & 0xf8) == 0xf0) && (_moreBytes == 0)) {
- // 11110xxx
- _code = b & 0x07;
- _moreBytes = 3;
- return read2();
- } else if (((b & 0xfc) == 0xf8) && (_moreBytes == 0)) {
- // 111110xx
- _code = b & 0x03;
- _moreBytes = 4;
- return read2();
- } else if (((b & 0xfe) == 0xfc) && (_moreBytes == 0)) {
- // 1111110x
- _code = b & 0x01;
- _moreBytes = 5;
- return read2();
- } else {
- throw new CharConversionException("Invalid UTF-8 Encoding");
- }
- } else { // No more bytes in buffer.
- if (_inputStream == null)
- throw new IOException("No input stream or stream closed");
- _start = 0;
- _end = _inputStream.read(_bytes, 0, _bytes.length);
- if (_end > 0) {
- return read2(); // Continues.
- } else { // Done.
- if (_moreBytes == 0) {
- return -1;
- } else { // Incomplete sequence.
- throw new CharConversionException(
- "Unexpected end of stream");
- }
- }
- }
- }
-
- private int _code;
-
- private int _moreBytes;
-
- /**
- * Reads characters into a portion of an array. This method will block
- * until some input is available, an I/O error occurs or the end of
- * the stream is reached.
- *
- * <p> Note: Characters between U+10000 and U+10FFFF are represented
- * by surrogate pairs (two <code>char</code>).</p>
- *
- * @param cbuf the destination buffer.
- * @param off the offset at which to start storing characters.
- * @param len the maximum number of characters to read
- * @return the number of characters read, or -1 if the end of the
- * stream has been reached
- * @throws IOException if an I/O error occurs.
- */
- public int read(char cbuf[], int off, int len) throws IOException {
- if (_inputStream == null)
- throw new IOException("No input stream or stream closed");
- if (_start >= _end) { // Fills buffer.
- _start = 0;
- _end = _inputStream.read(_bytes, 0, _bytes.length);
- if (_end <= 0) { // Done.
- return _end;
- }
- }
- final int off_plus_len = off + len;
- for (int i = off; i < off_plus_len;) {
- // assert(_start < _end)
- byte b = _bytes[_start];
- if ((b >= 0) && (++_start < _end)) {
- cbuf[i++] = (char) b; // Most common case.
- } else if (b < 0) {
- if (i < off_plus_len - 1) { // Up to two 'char' can be read.
- int code = read2();
- if (code < 0x10000) {
- cbuf[i++] = (char) code;
- } else if (code <= 0x10ffff) { // Surrogates.
- cbuf[i++] = (char) (((code - 0x10000) >> 10) + 0xd800);
- cbuf[i++] = (char) (((code - 0x10000) & 0x3ff) + 0xdc00);
- } else {
- throw new CharConversionException("Cannot convert U+"
- + Integer.toHexString(code)
- + " to char (code greater than U+10FFFF)");
- }
- if (_start < _end) {
- continue;
- }
- }
- return i - off;
- } else { // End of buffer (_start >= _end).
- cbuf[i++] = (char) b;
- return i - off;
- }
- }
- return len;
- }
-
- /**
- * Reads characters into the specified appendable. This method will block
- * until the end of the stream is reached.
- *
- * @param dest the destination buffer.
- * @throws IOException if an I/O error occurs.
- */
- public void read(Appendable dest) throws IOException {
- if (_inputStream == null)
- throw new IOException("No input stream or stream closed");
- while (true) {
- if (_start >= _end) { // Fills buffer.
- _start = 0;
- _end = _inputStream.read(_bytes, 0, _bytes.length);
- if (_end <= 0) { // Done.
- break;
- }
- }
- byte b = _bytes[_start];
- if (b >= 0) {
- dest.append((char) b); // Most common case.
- _start++;
- } else {
- int code = read2();
- if (code < 0x10000) {
- dest.append((char) code);
- } else if (code <= 0x10ffff) { // Surrogates.
- dest.append((char) (((code - 0x10000) >> 10) + 0xd800));
- dest.append((char) (((code - 0x10000) & 0x3ff) + 0xdc00));
- } else {
- throw new CharConversionException("Cannot convert U+"
- + Integer.toHexString(code)
- + " to char (code greater than U+10FFFF)");
- }
- }
- }
- }
-
- public void reset() {
- _code = 0;
- _end = 0;
- _inputStream = null;
- _moreBytes = 0;
- _start = 0;
- }
-
- /**
- * @deprecated Replaced by {@link #setInput(InputStream)}
- */
- public UTF8StreamReader setInputStream(InputStream inStream) {
- return this.setInput(inStream);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamWriter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamWriter.java b/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamWriter.java
deleted file mode 100644
index a5872e3..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/UTF8StreamWriter.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-import java.io.CharConversionException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-
-/**
- * <p> A UTF-8 stream writer.</p>
- *
- * <p> This writer supports surrogate <code>char</code> pairs (representing
- * characters in the range [U+10000 .. U+10FFFF]). It can also be used
- * to write characters from their unicodes (31 bits) directly
- * (ref. {@link #write(int)}).</p>
- *
- * <p> Instances of this class can be reused for different output streams
- * and can be part of a higher level component (e.g. serializer) in order
- * to avoid dynamic buffer allocation when the destination output changes.
- * Also wrapping using a <code>java.io.BufferedWriter</code> is unnescessary
- * as instances of this class embed their own data buffers.</p>
- *
- * <p> Note: This writer is unsynchronized and always produces well-formed
- * UTF-8 sequences.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 2.0, December 9, 2004
- */
-public final class UTF8StreamWriter extends Writer {
-
- /**
- * Holds the current output stream or <code>null</code> if closed.
- */
- private OutputStream _outputStream;
-
- /**
- * Holds the bytes' buffer.
- */
- private final byte[] _bytes;
-
- /**
- * Holds the bytes buffer index.
- */
- private int _index;
-
- /**
- * Creates a UTF-8 writer having a byte buffer of moderate capacity (2048).
- */
- public UTF8StreamWriter() {
- _bytes = new byte[2048];
- }
-
- /**
- * Creates a UTF-8 writer having a byte buffer of specified capacity.
- *
- * @param capacity the capacity of the byte buffer.
- */
- public UTF8StreamWriter(int capacity) {
- _bytes = new byte[capacity];
- }
-
- /**
- * Sets the output stream to use for writing until this writer is closed.
- * For example:[code]
- * Writer writer = new UTF8StreamWriter().setOutputStream(out);
- * [/code] is equivalent but writes faster than [code]
- * Writer writer = new java.io.OutputStreamWriter(out, "UTF-8");
- * [/code]
- *
- * @param out the output stream.
- * @return this UTF-8 writer.
- * @throws IllegalStateException if this writer is being reused and
- * it has not been {@link #close closed} or {@link #reset reset}.
- */
- public UTF8StreamWriter setOutput(OutputStream out) {
- if (_outputStream != null)
- throw new IllegalStateException("Writer not closed or reset");
- _outputStream = out;
- return this;
- }
-
- /**
- * Writes a single character. This method supports 16-bits
- * character surrogates.
- *
- * @param c <code>char</code> the character to be written (possibly
- * a surrogate).
- * @throws IOException if an I/O error occurs.
- */
- public void write(char c) throws IOException {
- if ((c < 0xd800) || (c > 0xdfff)) {
- write((int) c);
- } else if (c < 0xdc00) { // High surrogate.
- _highSurrogate = c;
- } else { // Low surrogate.
- int code = ((_highSurrogate - 0xd800) << 10) + (c - 0xdc00)
- + 0x10000;
- write(code);
- }
- }
-
- private char _highSurrogate;
-
- /**
- * Writes a character given its 31-bits Unicode.
- *
- * @param code the 31 bits Unicode of the character to be written.
- * @throws IOException if an I/O error occurs.
- */
- public void write(int code) throws IOException {
- if ((code & 0xffffff80) == 0) {
- _bytes[_index] = (byte) code;
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else { // Writes more than one byte.
- write2(code);
- }
- }
-
- private void write2(int c) throws IOException {
- if ((c & 0xfffff800) == 0) { // 2 bytes.
- _bytes[_index] = (byte) (0xc0 | (c >> 6));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | (c & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else if ((c & 0xffff0000) == 0) { // 3 bytes.
- _bytes[_index] = (byte) (0xe0 | (c >> 12));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 6) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | (c & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else if ((c & 0xff200000) == 0) { // 4 bytes.
- _bytes[_index] = (byte) (0xf0 | (c >> 18));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 12) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 6) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | (c & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else if ((c & 0xf4000000) == 0) { // 5 bytes.
- _bytes[_index] = (byte) (0xf8 | (c >> 24));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 18) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 12) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 6) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | (c & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else if ((c & 0x80000000) == 0) { // 6 bytes.
- _bytes[_index] = (byte) (0xfc | (c >> 30));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 24) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 18) & 0x3f));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 12) & 0x3F));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | ((c >> 6) & 0x3F));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- _bytes[_index] = (byte) (0x80 | (c & 0x3F));
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else {
- throw new CharConversionException("Illegal character U+"
- + Integer.toHexString(c));
- }
- }
-
- /**
- * Writes a portion of an array of characters.
- *
- * @param cbuf the array of characters.
- * @param off the offset from which to start writing characters.
- * @param len the number of characters to write.
- * @throws IOException if an I/O error occurs.
- */
- public void write(char cbuf[], int off, int len) throws IOException {
- final int off_plus_len = off + len;
- for (int i = off; i < off_plus_len;) {
- char c = cbuf[i++];
- if (c < 0x80) {
- _bytes[_index] = (byte) c;
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else {
- write(c);
- }
- }
- }
-
- /**
- * Writes a portion of a string.
- *
- * @param str a String.
- * @param off the offset from which to start writing characters.
- * @param len the number of characters to write.
- * @throws IOException if an I/O error occurs
- */
- public void write(String str, int off, int len) throws IOException {
- final int off_plus_len = off + len;
- for (int i = off; i < off_plus_len;) {
- char c = str.charAt(i++);
- if (c < 0x80) {
- _bytes[_index] = (byte) c;
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else {
- write(c);
- }
- }
- }
-
- /**
- * Writes the specified character sequence.
- *
- * @param csq the character sequence.
- * @throws IOException if an I/O error occurs
- */
- public void write(CharSequence csq) throws IOException {
- final int length = csq.length();
- for (int i = 0; i < length;) {
- char c = csq.charAt(i++);
- if (c < 0x80) {
- _bytes[_index] = (byte) c;
- if (++_index >= _bytes.length) {
- flushBuffer();
- }
- } else {
- write(c);
- }
- }
- }
-
- /**
- * Flushes the stream. If the stream has saved any characters from the
- * various write() methods in a buffer, write them immediately to their
- * intended destination. Then, if that destination is another character or
- * byte stream, flush it. Thus one flush() invocation will flush all the
- * buffers in a chain of Writers and OutputStreams.
- *
- * @throws IOException if an I/O error occurs.
- */
- public void flush() throws IOException {
- flushBuffer();
- _outputStream.flush();
- }
-
- /**
- * Closes and {@link #reset resets} this writer for reuse.
- *
- * @throws IOException if an I/O error occurs
- */
- public void close() throws IOException {
- if (_outputStream != null) {
- flushBuffer();
- _outputStream.close();
- reset();
- }
- }
-
- /**
- * Flushes the internal bytes buffer.
- *
- * @throws IOException if an I/O error occurs
- */
- private void flushBuffer() throws IOException {
- if (_outputStream == null)
- throw new IOException("Stream closed");
- _outputStream.write(_bytes, 0, _index);
- _index = 0;
- }
-
- public void reset() {
- _highSurrogate = 0;
- _index = 0;
- _outputStream = null;
- }
-
- /**
- * @deprecated Replaced by {@link #setOutput(OutputStream)}
- */
- public UTF8StreamWriter setOutputStream(OutputStream out) {
- return this.setOutput(out);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/Union.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/Union.java b/commons/marmotta-commons/src/ext/java/javolution/io/Union.java
deleted file mode 100644
index e8ae270..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/Union.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.io;
-
-/**
- * <p> Equivalent to <code>C/C++ union</code>; this class works in the same
- * way as {@link Struct} (sub-class) except that all members are mapped
- * to the same location in memory.</p>
- * <p> Here is an example of C union:
- * [code]
- * union Number {
- * int asInt;
- * float asFloat;
- * char asString[12];
- * };[/code]</p>
- * <p> And its Java equivalent:
- * [code]
- * public class Number extends Union {
- * Signed32 asInt = new Signed32();
- * Float32 asFloat = new Float32();
- * Utf8String asString = new Utf8String(12);
- * }[/code]</p>
- * <p> As for any {@link Struct}, fields are directly accessible:
- * [code]
- * Number num = new Number();
- * num.asInt.set(23);
- * num.asString.set("23"); // Null terminated (C compatible)
- * float f = num.asFloat.get();[/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 1.0, October 4, 2004
- */
-public abstract class Union extends Struct {
-
- /**
- * Default constructor.
- */
- public Union() {}
-
- /**
- * Returns <code>true</code>.
- *
- * @return <code>true</code>
- */
- public final boolean isUnion() {
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/io/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/io/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/io/package-info.java
deleted file mode 100644
index 6e000ae..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/io/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
-<p> Utility classes for input and output such as
- {@link javolution.io.Struct Struct} and {@link javolution.io.Union Union}
- for direct interoperability with C/C++.</p>
- */
-package javolution.io;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/lang/Configurable.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/lang/Configurable.java b/commons/marmotta-commons/src/ext/java/javolution/lang/Configurable.java
deleted file mode 100644
index 394c60e..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/lang/Configurable.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.lang;
-
-import java.lang.reflect.Field;
-
-import javolution.context.LogContext;
-import javolution.context.SecurityContext;
-import javolution.context.SecurityContext.Permission;
-import javolution.osgi.internal.OSGiServices;
-import javolution.text.DefaultTextFormat;
-import javolution.text.TextContext;
-
-/**
- * <p> An element which is configurable without presupposing how the
- * configuration is done.</p>
- *
- * <p> Does your class need to know or has to assume that the configuration is
- * coming from system properties ??</p>
- *
- * <p> The response is obviously NO !</p>
- *
- * <p> Let's compare the following examples:
- * [code]
- * class Document {
- * private static final Font FONT
- * = Font.decode(System.getProperty("pkg.Document#FONT") != null ?
- * System.getProperty("FONT") : "Arial-BOLD-18");
- * }[/code]</p>
- *
- * <p>With the following:
- * [code]
- * class Document {
- * public static final Configurable<Font> FONT = new Configurable<Font>() {
- * @Override
- * protected Font getDefault() {
- * new Font("Arial", Font.BOLD, 18);
- * }
- * };
- * }[/code]</p>
- *
- * <p> Not only the second example is cleaner, but the actual configuration
- * data can come from anywhere, from system properties (default),
- * OSGi Configuration Admin service, another bundle, etc.
- * Low level code does not need to know.</p>
- *
- * <p> Configurables may perform any logic upon initialization or
- * update. Users are notified of configuration events through
- * the OSGi {@link Configurable.Listener} service.
- * [code]
- * class Index {
- * // Holds the number of unique preallocated instances (default {@code 1024}).
- * public static final Configurable<Integer> UNIQUE = new Configurable<Integer>() {
- * @Override
- * protected Integer getDefault() {
- * return 1024;
- * }
- * @Override
- * protected Integer initialized(Integer value) {
- * return MathLib.min(value, 65536); // Hard-limiting
- * }
- * @Override
- * protected Integer reconfigured(Integer oldCount, Integer newCount) {
- * throw new UnsupportedOperationException("Unicity reconfiguration not supported.");
- * }
- * }
- * }[/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-public abstract class Configurable<T> {
-
- /**
- * Services to be published by any one interested in being informed of
- * configurable changes.
- */
- public interface Listener {
-
- /**
- * Receives notification that a configurable has been initialized..
- *
- * @param configurable the configurable instance being initialized.
- * @param value the initial value.
- */
- <T> void configurableInitialized(Configurable<T> configurable, T value);
-
- /**
- * Receives notification that a configurable has been updated.
- *
- * @param configurable the configurable instance being updated.
- * @param oldValue the previous value.
- * @param newValue the updated value.
- */
- <T> void configurableReconfigured(Configurable<T> configurable,
- T oldValue, T newValue);
-
- }
-
- /**
- * Holds the general permission to reconfigure configurable instances
- * (action <code>"reconfigure"</code>).
- * Whether or not that permission is granted depends on the current
- * {@link SecurityContext}. It is possible that the general permission
- * to reconfigure a configurable is granted but revoked for a specific
- * instance. Also, the general permission to reconfigure a configurable
- * may be revoked but granted only for a specific instance.
- */
- public static Permission<Configurable<?>> RECONFIGURE_PERMISSION = new Permission<Configurable<?>>(
- Configurable.class, "reconfigure");
-
- /**
- * Holds the configurable name.
- */
- private String name;
-
- /**
- * Holds the reconfigure permission.
- */
- private final Permission<Configurable<T>> reconfigurePermission;
-
- /**
- * Holds the configurable value.
- */
- private volatile T value;
-
- /**
- * Creates a new configurable. If a system property exist for this
- * configurable's {@link #getName() name}, then
- * the {@link #parse parsed} value of the property supersedes the
- * {@link #getDefault() default} value of this configurable.
- * For example, running the JVM with
- * the option {@code -Djavolution.context.ConcurrentContext#CONCURRENCY=0}
- * disables concurrency support.
- */
- public Configurable() {
- reconfigurePermission = new Permission<Configurable<T>>(
- Configurable.class, "reconfigure", this);
- String name = getName();
- T defaultValue = getDefault();
- if (name != null) {
- try { // Checks system properties.
- String property = System.getProperty(name);
- if (property != null) {
- defaultValue = parse(property); // Supersedes.
- LogContext.debug(name, ", System Properties Value: ",
- defaultValue);
- }
- } catch (SecurityException securityError) {
- // Ok, current runtime does not allow system properties access.
- }
- }
- this.name = name;
- this.value = initialized(defaultValue);
- Object[] listeners = OSGiServices.getConfigurableListeners();
- for (Object listener : listeners) {
- ((Listener) listener).configurableInitialized(this, this.value);
- }
- }
-
- /**
- * Returns this configurable value.
- */
- public T get() {
- return value;
- }
-
- /**
- * Returns this configurable name. By convention, the name of the
- * configurable is the name of the static field holding the
- * configurable (e.g. "javolution.context.ConcurrentContext#CONCURRENCY").
- * This method should be overridden if the enclosing class needs to be
- * impervious to obfuscation or if the enclosing class defines multiple
- * configurable fields.
- *
- * @throws UnsupportedOperationException if the enclosing class has
- * multiple configurable static fields.
- */
- public String getName() {
- if (name != null)
- return name; // Already set.
- Class<?> thisClass = this.getClass();
- Class<?> enclosingClass = thisClass.getEnclosingClass();
- String fieldName = null;
- for (Field field : enclosingClass.getFields()) {
- if (field.getType().isAssignableFrom(thisClass)) {
- if (fieldName != null) // Indistinguishable field types.
- throw new UnsupportedOperationException(
- "Multiple configurables static fields in the same class" +
- "requires the Configurable.getName() method to be overriden.");
- fieldName = field.getName();
- }
- }
- return (fieldName != null) ? enclosingClass.getName() + "#" + fieldName
- : null;
- }
-
- /**
- * Returns the permission to configure this instance.
- */
- public Permission<Configurable<T>> getReconfigurePermission() {
- return reconfigurePermission;
- }
-
- /**
- * Reconfigures this instance with the specified value if authorized
- * by the {@link SecurityContext}. This method returns the actual new
- * value which may be different from the requested new value
- * (see {@link #reconfigured(Object, Object)}).
- *
- * @param newValue the requested new value.
- * @return the actual new value.
- * @throws SecurityException if the permission to reconfigure this
- * configurable is not granted.
- * @throws UnsupportedOperationException if this configurable does not
- * support dynamic reconfiguration.
- */
- public T reconfigure(T newValue) {
- SecurityContext.check(reconfigurePermission);
- synchronized (this) {
- T oldValue = this.value;
- this.value = reconfigured(oldValue, newValue);
- Object[] listeners = OSGiServices.getConfigurableListeners();
- for (Object listener : listeners) {
- ((Listener) listener).configurableReconfigured(this, oldValue,
- this.value);
- }
- return this.value;
- }
- }
-
- /**
- * Returns this configurable default value (always different from
- * {@code null}).
- */
- protected abstract T getDefault();
-
- /**
- * This methods is called when the configurable is initialized.
- * Developers may override this method to perform
- * any initialization logic (e.g. input validation).
- *
- * @param value the requested value for this configurable.
- * @return the actual value of this configurable.
- */
- protected T initialized(T value) {
- return value;
- }
-
- /**
- * Parses the specified text to return the corresponding value.
- * This method is used to initialize this configurable from
- * system properties. The default implementation uses the
- * {@link TextContext} to retrieve the text format
- * (based on the {@link DefaultTextFormat} class annotation).
- */
- @SuppressWarnings("unchecked")
- protected T parse(String str) {
- Class<? extends T> type = (Class<? extends T>) getDefault().getClass();
- return TextContext.getFormat(type).parse(str);
- }
-
- /**
- * This methods is called when the configurable is reconfigured.
- * Developers may override this method to perform
- * any reconfiguration logic (e.g. hard limiting values).
- *
- * @param oldValue the old value.
- * @param newValue the requested new value.
- * @return the actual new value of this configurable.
- * @throws UnsupportedOperationException if this configurable does not
- * support dynamic reconfiguration.
- */
- protected T reconfigured(T oldValue, T newValue) {
- return newValue;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/lang/Initializer.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/lang/Initializer.java b/commons/marmotta-commons/src/ext/java/javolution/lang/Initializer.java
deleted file mode 100644
index 81f2823..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/lang/Initializer.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.lang;
-
-import java.util.Vector;
-import javolution.context.LogContext;
-
-/**
- * <p> An initializer for all classes loaded by any given class loader.</p>
- *
- * <p> Initialization of classes at startup (or during bundle activation)
- * ensures a significantly improved worst case execution time especially
- * if the classes has {@link Configurable configuration logic} to be
- * executed then.</p>
- *
- * <p> Javolution activator initialize {@link Realtime} classes when started.
- * When running outside OSGi the method
- * {@code javolution.osgi.internal.OSGiServices.initializeRealtimeClasses()}
- * can be used to that effect..</p>
- *
- * <p> Class loading can be performed in a lazy manner and therefore some parts
- * of the class loading process may be done on first use rather than at
- * load time. Javolution bundle activator ensure that <b>all</b> its classes
- * are initialized at start up.
- * The following code illustrates how this can be done for any bundle.
- * [code]
- * public class MyActivator implements BundleActivator {
- * public void start(BundleContext bc) throws Exception {
- * Initializer initializer = new Initializer(MyActivator.class.getClassLoader());
- * initializer.loadClass(com.foo.internal.UnreferencedClass.class);
- * // Load explicitly classes not directly or indirectly referenced.
- * ...
- * initializer.initializeLoadedClasses(); // Recursive loading/initialization.
- * ... // Continue activation
- * }
- * }[/code]</p>
- *
- * <p> This utility use reflection to find the classes loaded and may not be
- * supported on all platforms.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.1, July 26, 2007
- */
-public class Initializer {
-
- /**
- * Indicates if the class being initialized should be logged
- * (default {@code false}).
- */
- public static final Configurable<Boolean> SHOW_INITIALIZED = new Configurable<Boolean>() {
- @Override
- protected Boolean getDefault() {
- return false;
- }
- };
-
- /** The class loader for this initializer */
- private final ClassLoader classLoader;
-
- /**
- * Creates an initializer for the specified class loader.
- */
- public Initializer(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- /**
- * Returns the classes loaded by the class loader of this initializer or
- * <code>null</code> if not supported by the platform.
- */
- @SuppressWarnings("unchecked")
- public Class<?>[] loadedClasses() {
- Class<?> cls = classLoader.getClass();
- while (cls != java.lang.ClassLoader.class) {
- cls = cls.getSuperclass();
- }
- try {
- java.lang.reflect.Field fldClasses = cls
- .getDeclaredField("classes");
- fldClasses.setAccessible(true);
- Vector<Class<?>> list = (Vector<Class<?>>) fldClasses
- .get(classLoader);
- Class<?>[] classes = new Class<?>[list.size()];
- for (int i = 0; i < classes.length; i++) {
- classes[i] = list.get(i);
- }
- return classes;
- } catch (Throwable e) {
- return null;
- }
- }
-
- /**
- * Loads the specified class (does not perform any initialization).
- * This method is typically used to load unreferenced classes.
- */
- public void loadClass(Class<?> cls) {
- try {
- classLoader.loadClass(cls.getName());
- } catch (ClassNotFoundException e) {
- LogContext.debug("Class " + cls + " not found.");
- }
- }
-
- /**
- * Initializes all the loaded classes. If the initialization leads to more
- * classes being loaded, these classes are initialized as well
- * (recursive process).
- *
- * @return {@code true} if initialization has been performed successfully;
- * {@code false} otherwise.
- */
- public boolean initializeLoadedClasses() {
- boolean isInitializationSuccessful = true;
- int nbrClassesInitialized = 0;
- while (true) {
- Class<?>[] classes = loadedClasses();
- if (classes == null) {
- LogContext
- .debug("Automatic class initialization not supported.");
- return false;
- }
- if (nbrClassesInitialized >= classes.length)
- break; // Done.
- for (int i = nbrClassesInitialized; i < classes.length; i++) {
- Class<?> cls = classes[i];
- try {
- if (SHOW_INITIALIZED.get())
- LogContext.debug("Initialize ", cls.getName());
- Class.forName(cls.getName(), true, classLoader);
- } catch (ClassNotFoundException ex) {
- isInitializationSuccessful = false;
- LogContext.error(ex); // Should never happen.
- }
- }
- nbrClassesInitialized = classes.length;
- }
- LogContext.debug("Initialization of ", nbrClassesInitialized,
- " classes loaded by ", classLoader);
- return isInitializationSuccessful;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/lang/Parallelizable.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/lang/Parallelizable.java b/commons/marmotta-commons/src/ext/java/javolution/lang/Parallelizable.java
index 5238c1d..0c1001a 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/lang/Parallelizable.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/lang/Parallelizable.java
@@ -8,12 +8,7 @@
*/
package javolution.lang;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
/**
* <p> Indicates that a class, a method or a field can be used by multiple
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/lang/Realtime.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/lang/Realtime.java b/commons/marmotta-commons/src/ext/java/javolution/lang/Realtime.java
index 2757ad3..0b7a24a 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/lang/Realtime.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/lang/Realtime.java
@@ -8,12 +8,7 @@
*/
package javolution.lang;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
/**
* <p> Indicates if an element has a bounded
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ConfigurableListenerImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ConfigurableListenerImpl.java b/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ConfigurableListenerImpl.java
deleted file mode 100644
index 8983824..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ConfigurableListenerImpl.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.osgi.internal;
-
-import javolution.context.LogContext;
-import javolution.lang.Configurable;
-
-/**
- * Holds the default implementation of Configurable.Listener when running
- * outside OSGi (logs configuration events).
- */
-public final class ConfigurableListenerImpl implements Configurable.Listener {
-
- @Override
- public <T> void configurableInitialized(Configurable<T> configurable,
- T value) {
- LogContext.debug(configurable.getName(), "=", value);
- }
-
- @Override
- public <T> void configurableReconfigured(Configurable<T> configurable,
- T oldValue, T newValue) {
- LogContext.debug(configurable.getName(),
- " reconfigured from ", oldValue, " to ", newValue);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/JavolutionActivator.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/JavolutionActivator.java b/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/JavolutionActivator.java
deleted file mode 100644
index a4b1c6d..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/JavolutionActivator.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.osgi.internal;
-
-import javolution.xml.stream.XMLInputFactory;
-import javolution.xml.stream.XMLOutputFactory;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * Javolution OSGi bundle activator.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-public class JavolutionActivator implements BundleActivator {
-
- // Services provided by Javolution.
- private ServiceRegistration<XMLInputFactory> xmlInputFactoryRegistration;
- private ServiceRegistration<XMLOutputFactory> xmlOutputFactoryRegistration;
-
- @SuppressWarnings("unchecked")
- public void start(BundleContext bc) throws Exception {
-
- // Activate services trackers.
- OSGiServices.CONCURRENT_CONTEXT_TRACKER.activate(bc);
- OSGiServices.CONFIGURABLE_LISTENER_TRACKER.activate(bc);
- OSGiServices.LOCAL_CONTEXT_TRACKER.activate(bc);
- OSGiServices.LOG_CONTEXT_TRACKER.activate(bc);
- OSGiServices.LOG_SERVICE_TRACKER.activate(bc);
- OSGiServices.SECURITY_CONTEXT_TRACKER.activate(bc);
- OSGiServices.STORAGE_CONTEXT_TRACKER.activate(bc);
- OSGiServices.TEXT_CONTEXT_TRACKER.activate(bc);
- OSGiServices.XML_CONTEXT_TRACKER.activate(bc);
- OSGiServices.XML_INPUT_FACTORY_TRACKER.activate(bc);
- OSGiServices.XML_OUTPUT_FACTORY_TRACKER.activate(bc);
-
- // Publish XMLInputFactory/XMLOutputFactory services.
- xmlInputFactoryRegistration = (ServiceRegistration<XMLInputFactory>) bc
- .registerService(XMLInputFactory.class.getName(),
- new XMLInputFactoryProvider(), null);
- xmlOutputFactoryRegistration = (ServiceRegistration<XMLOutputFactory>) bc
- .registerService(XMLOutputFactory.class.getName(),
- new XMLOutputFactoryProvider(), null);
-
- // Ensures low latency for real-time classes.
- OSGiServices.initializeRealtimeClasses();
- }
-
- public void stop(BundleContext bc) throws Exception {
- OSGiServices.CONCURRENT_CONTEXT_TRACKER.deactivate(bc);
- OSGiServices.CONFIGURABLE_LISTENER_TRACKER.deactivate(bc);
- OSGiServices.LOCAL_CONTEXT_TRACKER.deactivate(bc);
- OSGiServices.LOG_CONTEXT_TRACKER.deactivate(bc);
- OSGiServices.LOG_SERVICE_TRACKER.deactivate(bc);
- OSGiServices.SECURITY_CONTEXT_TRACKER.deactivate(bc);
- OSGiServices.STORAGE_CONTEXT_TRACKER.deactivate(bc);
- OSGiServices.TEXT_CONTEXT_TRACKER.deactivate(bc);
- OSGiServices.XML_CONTEXT_TRACKER.deactivate(bc);
- OSGiServices.XML_INPUT_FACTORY_TRACKER.deactivate(bc);
- OSGiServices.XML_OUTPUT_FACTORY_TRACKER.deactivate(bc);
-
- xmlInputFactoryRegistration.unregister();
- xmlOutputFactoryRegistration.unregister();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/LogServiceImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/LogServiceImpl.java b/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/LogServiceImpl.java
deleted file mode 100644
index 8fa4ece..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/LogServiceImpl.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.osgi.internal;
-
-import javolution.util.FastTable;
-
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-
-/**
- * Holds the default implementation of LogService to be used when running
- * outside OSGi or when the Javolution bundle is not started.
- */
-public final class LogServiceImpl extends Thread implements LogService {
-
- private static class LogEvent {
- Throwable exception;
- int level;
- String message;
- }
-
- private final FastTable<LogEvent> eventQueue = new FastTable<LogEvent>();
-
- public LogServiceImpl() {
- super("Logging-Thread");
- setDaemon(true);
- this.start();
- Thread hook = new Thread(new Runnable() {
- @Override
- public void run() { // Maintains the VM alive until the event queue is flushed
- synchronized (eventQueue) {
- try {
- while (!eventQueue.isEmpty())
- eventQueue.wait();
- } catch (InterruptedException e) {}
- }
- }
- });
- Runtime.getRuntime().addShutdownHook(hook);
- }
-
- @Override
- public void log(int level, String message) {
- log(level, message, null);
- }
-
- @Override
- public void log(int level, String message, Throwable exception) {
- LogEvent event = new LogEvent();
- event.level = level;
- event.message = message;
- event.exception = exception;
- synchronized (eventQueue) {
- eventQueue.addFirst(event);
- eventQueue.notify();
- }
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public void log(ServiceReference sr, int level, String message) {
- throw new UnsupportedOperationException();
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public void log(ServiceReference sr, int level, String message,
- Throwable exception) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void run() {
- while (true) {
- try {
- LogEvent event;
- synchronized (eventQueue) {
- while (eventQueue.isEmpty())
- eventQueue.wait();
- event = eventQueue.pollLast();
- eventQueue.notify();
- }
- switch (event.level) {
- case LogService.LOG_DEBUG:
- System.out.println("[DEBUG] " + event.message);
- break;
- case LogService.LOG_INFO:
- System.out.println("[INFO] " + event.message);
- break;
- case LogService.LOG_WARNING:
- System.out.println("[WARNING] " + event.message);
- break;
- case LogService.LOG_ERROR:
- System.out.println("[ERROR] " + event.message);
- break;
- default:
- System.out.println("[UNKNOWN] " + event.message);
- break;
- }
- if (event.exception != null) {
- event.exception.printStackTrace(System.out);
- }
- } catch (InterruptedException error) {
- error.printStackTrace(System.err);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/OSGiServices.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/OSGiServices.java b/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/OSGiServices.java
deleted file mode 100644
index 5c35abe..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/OSGiServices.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.osgi.internal;
-
-import javolution.context.ConcurrentContext;
-import javolution.context.LocalContext;
-import javolution.context.LogContext;
-import javolution.context.SecurityContext;
-import javolution.context.StorageContext;
-import javolution.context.internal.ConcurrentContextImpl;
-import javolution.context.internal.LocalContextImpl;
-import javolution.context.internal.LogContextImpl;
-import javolution.context.internal.SecurityContextImpl;
-import javolution.context.internal.StorageContextImpl;
-import javolution.io.Struct;
-import javolution.lang.Configurable;
-import javolution.lang.Initializer;
-import javolution.lang.MathLib;
-import javolution.text.Text;
-import javolution.text.TextContext;
-import javolution.text.TypeFormat;
-import javolution.text.internal.TextContextImpl;
-import javolution.util.FastBitSet;
-import javolution.util.FastSortedMap;
-import javolution.util.FastSortedSet;
-import javolution.util.FastSortedTable;
-import javolution.util.Index;
-import javolution.util.function.Equalities;
-import javolution.util.function.Reducers;
-import javolution.xml.XMLContext;
-import javolution.xml.internal.XMLContextImpl;
-import javolution.xml.internal.stream.XMLInputFactoryImpl;
-import javolution.xml.internal.stream.XMLOutputFactoryImpl;
-import javolution.xml.internal.stream.XMLStreamReaderImpl;
-import javolution.xml.internal.stream.XMLStreamWriterImpl;
-import javolution.xml.stream.XMLInputFactory;
-import javolution.xml.stream.XMLOutputFactory;
-
-import org.osgi.service.log.LogService;
-
-/**
- * The OSGi services tracked by the Javolution bundle.
- * When running outside OSGi or when the Javolution bundle is not started
- * the default service implementation is returned.
- */
-public class OSGiServices {
-
- final static ServiceTrackerImpl<ConcurrentContext> CONCURRENT_CONTEXT_TRACKER = new ServiceTrackerImpl<ConcurrentContext>(
- ConcurrentContext.class, ConcurrentContextImpl.class);
- final static ServiceTrackerImpl<Configurable.Listener> CONFIGURABLE_LISTENER_TRACKER = new ServiceTrackerImpl<Configurable.Listener>(
- Configurable.Listener.class, ConfigurableListenerImpl.class);
- final static ServiceTrackerImpl<LocalContext> LOCAL_CONTEXT_TRACKER = new ServiceTrackerImpl<LocalContext>(
- LocalContext.class, LocalContextImpl.class);
- final static ServiceTrackerImpl<LogContext> LOG_CONTEXT_TRACKER = new ServiceTrackerImpl<LogContext>(
- LogContext.class, LogContextImpl.class);
- final static ServiceTrackerImpl<LogService> LOG_SERVICE_TRACKER = new ServiceTrackerImpl<LogService>(
- LogService.class, LogServiceImpl.class);
- final static ServiceTrackerImpl<SecurityContext> SECURITY_CONTEXT_TRACKER = new ServiceTrackerImpl<SecurityContext>(
- SecurityContext.class, SecurityContextImpl.class);
- final static ServiceTrackerImpl<StorageContext> STORAGE_CONTEXT_TRACKER = new ServiceTrackerImpl<StorageContext>(
- StorageContext.class, StorageContextImpl.class);
- final static ServiceTrackerImpl<TextContext> TEXT_CONTEXT_TRACKER = new ServiceTrackerImpl<TextContext>(
- TextContext.class, TextContextImpl.class);
- final static ServiceTrackerImpl<XMLContext> XML_CONTEXT_TRACKER = new ServiceTrackerImpl<XMLContext>(
- XMLContext.class, XMLContextImpl.class);
- final static ServiceTrackerImpl<XMLInputFactory> XML_INPUT_FACTORY_TRACKER = new ServiceTrackerImpl<XMLInputFactory>(
- XMLInputFactory.class, XMLInputFactoryImpl.class);
- final static ServiceTrackerImpl<XMLOutputFactory> XML_OUTPUT_FACTORY_TRACKER = new ServiceTrackerImpl<XMLOutputFactory>(
- XMLOutputFactory.class, XMLOutputFactoryImpl.class);
-
- /** Returns concurrent context services. */
- public static ConcurrentContext getConcurrentContext() {
- return (ConcurrentContext)CONCURRENT_CONTEXT_TRACKER.getServices()[0];
- }
-
- /** Returns configurable listener services. */
- public static Object[] getConfigurableListeners() {
- return CONFIGURABLE_LISTENER_TRACKER.getServices();
- }
-
- /** Returns local context service. */
- public static LocalContext getLocalContext() {
- return (LocalContext)LOCAL_CONTEXT_TRACKER.getServices()[0];
- }
-
- /** Returns log context service. */
- public static LogContext getLogContext() {
- return (LogContext)LOG_CONTEXT_TRACKER.getServices()[0];
- }
-
- /** Returns OSGi log service. */
- public static Object[] getLogServices() {
- return LOG_SERVICE_TRACKER.getServices();
- }
-
- /** Returns security context service. */
- public static SecurityContext getSecurityContext() {
- return (SecurityContext) SECURITY_CONTEXT_TRACKER.getServices()[0];
- }
-
- /** Returns storage context service. */
- public static StorageContext getStorageContext() {
- return (StorageContext) STORAGE_CONTEXT_TRACKER.getServices()[0];
- }
-
- /** Returns text context service. */
- public static TextContext getTextContext() {
- return (TextContext)TEXT_CONTEXT_TRACKER.getServices()[0];
- }
-
- /** Returns xml context service. */
- public static XMLContext getXMLContext() {
- return (XMLContext)XML_CONTEXT_TRACKER.getServices()[0];
- }
-
- /** Returns xml input factory service. */
- public static XMLInputFactory getXMLInputFactory() {
- return (XMLInputFactory)XML_INPUT_FACTORY_TRACKER.getServices()[0];
- }
-
- /** Returns xml output factory service. */
- public static XMLOutputFactory getXMLOutputFactory() {
- return (XMLOutputFactory)XML_OUTPUT_FACTORY_TRACKER.getServices()[0];
- }
-
- /** Initializes all real-time classes. */
- public static boolean initializeRealtimeClasses() {
- Initializer initializer = new Initializer(OSGiServices.class.getClassLoader());
- initializer.loadClass(MathLib.class);
- initializer.loadClass(Text.class);
- initializer.loadClass(TypeFormat.class);
- initializer.loadClass(Struct.class);
- initializer.loadClass(FastBitSet.class);
- initializer.loadClass(FastSortedMap.class);
- initializer.loadClass(FastSortedSet.class);
- initializer.loadClass(FastSortedTable.class);
- initializer.loadClass(Index.class); // Preallocates.
- initializer.loadClass(Reducers.class);
- initializer.loadClass(Equalities.class);
- initializer.loadClass(XMLStreamReaderImpl.class);
- initializer.loadClass(XMLStreamWriterImpl.class);
- return initializer.initializeLoadedClasses();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ServiceTrackerImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ServiceTrackerImpl.java b/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ServiceTrackerImpl.java
deleted file mode 100644
index ac4afdf..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/ServiceTrackerImpl.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.osgi.internal;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Bridge to service tracker (does not trigger class loading exception
- * if running outside OSGi).
- */
-public final class ServiceTrackerImpl<C> {
-
- private volatile ServiceTracker<C, C> tracker;
- private final Class<C> type;
- private final Class<? extends C> defaultImplClass;
- private C defaultImpl;
-
- /** Creates a context tracker for the specified context type. */
- public ServiceTrackerImpl(Class<C> type, Class<? extends C> defaultImplClass) {
- this.defaultImplClass = defaultImplClass;
- this.type = type;
- }
-
- /** Activates OSGi tracking. */
- public void activate(BundleContext bc) {
- ServiceTracker<C, C> trk = new ServiceTracker<C, C>(bc, type, null);
- trk.open();
- tracker = trk;
- }
-
- /** Deactivates OSGi tracking. */
- public void deactivate(BundleContext bc) {
- tracker.close();
- tracker = null;
- }
-
- /** Returns the published services or the default implementation if none. */
- public Object[] getServices() {
- ServiceTracker<C, C> trk = tracker;
- if (trk != null) {
- Object[] services = trk.getServices();
- if (services != null) return services;
- }
- synchronized (this) {
- if (defaultImpl == null) {
- try {
- defaultImpl = defaultImplClass.newInstance();
- } catch (Throwable error) {
- throw new RuntimeException(error);
- }
- }
- }
- return new Object[] { defaultImpl };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLInputFactoryProvider.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLInputFactoryProvider.java b/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLInputFactoryProvider.java
deleted file mode 100644
index e051200..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLInputFactoryProvider.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.osgi.internal;
-
-import javolution.xml.internal.stream.XMLInputFactoryImpl;
-import javolution.xml.stream.XMLInputFactory;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * Holds the service factory providing XMLInputFactory instances.
- */
-public final class XMLInputFactoryProvider implements ServiceFactory<XMLInputFactory> {
-
- @Override
- public XMLInputFactory getService(Bundle bundle,
- ServiceRegistration<XMLInputFactory> registration) {
- return new XMLInputFactoryImpl();
- }
-
- @Override
- public void ungetService(Bundle bundle,
- ServiceRegistration<XMLInputFactory> registration,
- XMLInputFactory service) {
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLOutputFactoryProvider.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLOutputFactoryProvider.java b/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLOutputFactoryProvider.java
deleted file mode 100644
index e606805..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/osgi/internal/XMLOutputFactoryProvider.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.osgi.internal;
-
-import javolution.xml.internal.stream.XMLOutputFactoryImpl;
-import javolution.xml.stream.XMLOutputFactory;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * Holds the service factory providing XMLInputFactory instances.
- */
-public final class XMLOutputFactoryProvider implements ServiceFactory<XMLOutputFactory> {
-
- @Override
- public XMLOutputFactory getService(Bundle bundle,
- ServiceRegistration<XMLOutputFactory> registration) {
- return new XMLOutputFactoryImpl();
- }
-
- @Override
- public void ungetService(Bundle bundle,
- ServiceRegistration<XMLOutputFactory> registration,
- XMLOutputFactory service) {
- }
-}
[07/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/Index.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/Index.java b/commons/marmotta-commons/src/ext/java/javolution/util/Index.java
deleted file mode 100644
index e63df1f..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/util/Index.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util;
-
-import java.io.IOException;
-import java.io.ObjectStreamException;
-
-import javolution.lang.Configurable;
-import javolution.lang.MathLib;
-import javolution.lang.Realtime;
-import javolution.lang.ValueType;
-import javolution.text.Cursor;
-import javolution.text.DefaultTextFormat;
-import javolution.text.TextContext;
-import javolution.text.TextFormat;
-import javolution.text.TypeFormat;
-
-/**
- * <p> A non-negative number representing a position in an arrangement.
- * For example:
- * [code]
- * class SparseVector<F> {
- * FastMap<Index, F> elements = new FastMap<Index, F>();
- * ...
- * }[/code]</p>
-
- * <p> Index performance is on-par with the primitive {@code int} type
- * for small values and similar to {@link Integer} instances for large
- * values. Small indexes have no adverse effect on the garbage collector
- * and have fast {@link #equals(Object) equals} method due to their unicity.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.1, July 26, 2007
- */
-@Realtime
-@DefaultTextFormat(Index.Decimal.class)
-public final class Index extends Number implements Comparable<Index>,
- ValueType<Index> {
-
- /**
- * Default text format for indices (decimal value representation).
- */
- public static class Decimal extends TextFormat<Index> {
-
- @Override
- public Appendable format(Index obj, Appendable dest) throws IOException {
- return TypeFormat.format(obj.intValue(), dest);
- }
-
- @Override
- public Index parse(CharSequence csq, Cursor cursor)
- throws IllegalArgumentException {
- return Index.valueOf(TypeFormat.parseInt(csq, cursor));
- }
-
- }
-
- /**
- * Holds the number of unique preallocated instances (default {@code 1024}).
- * This number is configurable, for example with
- * {@code -Djavolution.util.Index#UNIQUE=0} there is no unique instance.
- */
- public static final Configurable<Integer> UNIQUE = new Configurable<Integer>() {
-
- @Override
- protected Integer getDefault() {
- return 1024;
- }
-
- @Override
- protected Integer initialized(Integer value) {
- return MathLib.min(value, 65536); // Hard-limiting
- }
-
- @Override
- protected Integer reconfigured(Integer oldCount, Integer newCount) {
- throw new UnsupportedOperationException(
- "Unicity reconfiguration not supported.");
- }
- };
-
- /**
- * Holds the index zero (value <code>0</code>).
- */
- public static final Index ZERO = new Index(0);
-
- private static final long serialVersionUID = 0x600L; // Version.
- private static final Index[] INSTANCES = new Index[UNIQUE.get()];
- static {
- INSTANCES[0] = ZERO;
- for (int i = 1; i < INSTANCES.length; i++) {
- INSTANCES[i] = new Index(i);
- }
- }
-
- /**
- * Returns the index for the specified {@code int} non-negative
- * value (returns a preallocated instance if the specified value is
- * small).
- *
- * @param value the index value.
- * @return the corresponding index.
- * @throws IndexOutOfBoundsException if <code>value < 0</code>
- */
- public static Index valueOf(int value) {
- return (value < INSTANCES.length) ? INSTANCES[value] : new Index(value);
- }
-
- /**
- * Holds the index value.
- */
- private final int value;
-
- /**
- * Creates an index having the specified value.
- */
- private Index(int value) {
- this.value = value;
- }
-
- /**
- * Compares this index with the specified index for order. Returns a
- * negative integer, zero, or a positive integer as this index is less
- * than, equal to, or greater than the specified index.
- *
- * @param that the index to be compared.
- * @return a negative integer, zero, or a positive integer as this index
- * is less than, equal to, or greater than the specified index.
- */
- public int compareTo(Index that) {
- return this.value - that.value;
- }
-
- /**
- * Compares this index with the specified integer value for order. Returns a
- * negative integer, zero, or a positive integer as this index is less
- * than, equal to, or greater than the specified value.
- *
- * @param value the value to be compared.
- * @return a negative integer, zero, or a positive integer as this index
- * is less than, equal to, or greater than the specified value.
- */
- public int compareTo(int value) {
- return this.value - value;
- }
-
- /**
- * Returns a copy of this index or <code>this</code> if the indexes
- * is small (in permanent memory) in order to maintain unicity.
- */
- public Index copy() {
- return value < INSTANCES.length ? this : new Index(value);
- }
-
- /**
- * Returns the index value as <code>double</code>.
- *
- * @return the index value.
- */
- public double doubleValue() {
- return (double) value;
- }
-
- /**
- * Indicates if this index is equals to the one specified (for small
- * indices this method is equivalent to <code>==</code>).
- */
- @Override
- public boolean equals(Object obj) {
- return (this.value < INSTANCES.length) ? (this == obj)
- : ((obj instanceof Index) ? (((Index) obj).value == value)
- : false);
- }
-
- /**
- * Returns the index value as <code>float</code>.
- *
- * @return the index value.
- */
- public float floatValue() {
- return (float) value;
- }
-
- /**
- * Returns the hash code for this index.
- */
- @Override
- public int hashCode() {
- return value;
- }
-
- /**
- * Returns the index value as <code>int</code>.
- *
- * @return the index value.
- */
- public int intValue() {
- return value;
- }
-
- /**
- * Indicates if this index is zero.
- *
- * @return {@code this == ZERO}
- */
- public boolean isZero() {
- return this == ZERO;
- }
-
- /**
- * Returns the index value as <code>long</code>.
- *
- * @return the index value.
- */
- public long longValue() {
- return value;
- }
-
- /**
- * Returns the index after this one.
- */
- public Index next() {
- return Index.valueOf(value + 1);
- }
-
- /**
- * Returns the index before this one.
- *
- * @throws IndexOutOfBoundsException if (this == Index.ZERO)
- */
- public Index previous() {
- return Index.valueOf(value - 1);
- }
-
- /**
- * Ensures index unicity during deserialization.
- */
- protected final Object readResolve() throws ObjectStreamException {
- return Index.valueOf(value);
- }
-
- /**
- * Returns the {@link String} representation of this index.
- *
- * @return {@code TextContext.getFormat(Index.class).format(this)}
- */
- @Override
- public String toString() {
- return TextContext.getFormat(Index.class).format(this);
- }
-
- @Override
- public Index value() {
- return this;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/function/Equalities.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/function/Equalities.java b/commons/marmotta-commons/src/ext/java/javolution/util/function/Equalities.java
index 75e1441..4eb4c29 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/function/Equalities.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/function/Equalities.java
@@ -2,12 +2,7 @@ package javolution.util.function;
import javolution.lang.Parallelizable;
import javolution.lang.Realtime;
-import javolution.util.internal.comparator.ArrayComparatorImpl;
-import javolution.util.internal.comparator.IdentityComparatorImpl;
-import javolution.util.internal.comparator.LexicalCaseInsensitiveComparatorImpl;
-import javolution.util.internal.comparator.LexicalComparatorImpl;
-import javolution.util.internal.comparator.LexicalFastComparatorImpl;
-import javolution.util.internal.comparator.StandardComparatorImpl;
+import javolution.util.internal.comparator.*;
import static javolution.lang.Realtime.Limit.*;
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/function/Reducers.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/function/Reducers.java b/commons/marmotta-commons/src/ext/java/javolution/util/function/Reducers.java
index 8705e12..020c44e 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/function/Reducers.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/function/Reducers.java
@@ -8,7 +8,9 @@
*/
package javolution.util.function;
-import static javolution.lang.Realtime.Limit.LINEAR;
+import javolution.lang.Parallelizable;
+import javolution.lang.Realtime;
+import javolution.util.FastCollection;
import java.util.Collection;
import java.util.Comparator;
@@ -16,9 +18,7 @@ import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
-import javolution.lang.Parallelizable;
-import javolution.lang.Realtime;
-import javolution.util.FastCollection;
+import static javolution.lang.Realtime.Limit.LINEAR;
/**
* <p> A set of useful {@link Reducer reducers} of collection elements.</p>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetIteratorImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetIteratorImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetIteratorImpl.java
deleted file mode 100644
index d5cadc9..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetIteratorImpl.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util.internal.bitset;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import javolution.util.Index;
-import javolution.util.service.BitSetService;
-
-/**
- * An iterator over a bit set.
- */
-public final class BitSetIteratorImpl implements Iterator<Index> {
-
- private final BitSetService that;
-
- private int nextIndex;
-
- private int currentIndex = -1;
-
- public BitSetIteratorImpl(BitSetService that, int index) {
- this.that = that;
- this.nextIndex = that.nextSetBit(index);
- }
-
- public boolean hasNext() {
- return (nextIndex >= 0);
- }
-
- public Index next() {
- if (nextIndex < 0)
- throw new NoSuchElementException();
- currentIndex = nextIndex;
- nextIndex = that.nextSetBit(nextIndex + 1);
- return Index.valueOf(currentIndex);
- }
-
- public void remove() {
- if (currentIndex < 0)
- throw new IllegalStateException();
- that.clear(currentIndex);
- currentIndex = -1;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetServiceImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetServiceImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetServiceImpl.java
deleted file mode 100644
index 77c8c0c..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/bitset/BitSetServiceImpl.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util.internal.bitset;
-
-import java.io.Serializable;
-import java.util.Iterator;
-
-import javolution.lang.MathLib;
-import javolution.util.Index;
-import javolution.util.function.Equalities;
-import javolution.util.function.Equality;
-import javolution.util.internal.set.SetView;
-import javolution.util.service.BitSetService;
-
-/**
- * A table of indices implemented using packed bits (long[]).
- */
-public class BitSetServiceImpl extends SetView<Index> implements BitSetService, Serializable {
-
- private static final long serialVersionUID = 0x600L; // Version.
-
- /** Holds the bits (64 bits per long), trimmed. */
- private long[] bits;
-
- /** Creates a bit set (256 bits). */
- public BitSetServiceImpl() {
- super(null); // Root.
- bits = new long[4];
- }
-
- @Override
- public boolean add(Index index) {
- return !getAndSet(index.intValue(), true);
- }
-
- @Override
- public void and(BitSetService that) {
- long[] thatBits = that.toLongArray();
- int n = MathLib.min(this.bits.length, thatBits.length);
- for (int i = 0; i < n; i++) {
- this.bits[i] &= thatBits[i];
- }
- for (int i = n; i < bits.length; i++) {
- this.bits[i] = 0L;
- }
- trim();
- }
-
- @Override
- public void andNot(BitSetService that) {
- long[] thatBits = that.toLongArray();
- int n = MathLib.min(this.bits.length, thatBits.length);
- for (int i = 0; i < n; i++) {
- this.bits[i] &= ~thatBits[i];
- }
- trim();
- }
-
- @Override
- public int cardinality() {
- int sum = 0;
- for (int i = 0; i < bits.length; i++) {
- sum += MathLib.bitCount(bits[i]);
- }
- return sum;
- }
-
- @Override
- public void clear() {
- bits = new long[0];
- }
-
- @Override
- public void clear(int bitIndex) {
- int longIndex = bitIndex >> 6;
- if (longIndex >= bits.length)
- return;
- bits[longIndex] &= ~(1L << bitIndex);
- trim();
- }
-
- @Override
- public void clear(int fromIndex, int toIndex) {
- if ((fromIndex < 0) || (toIndex < fromIndex))
- throw new IndexOutOfBoundsException();
- int i = fromIndex >>> 6;
- if (i >= bits.length)
- return; // Ensures that i < _length
- int j = toIndex >>> 6;
- if (i == j) {
- bits[i] &= ((1L << fromIndex) - 1) | (-1L << toIndex);
- return;
- }
- bits[i] &= (1L << fromIndex) - 1;
- if (j < bits.length) {
- bits[j] &= -1L << toIndex;
- }
- for (int k = i + 1; (k < j) && (k < bits.length); k++) {
- bits[k] = 0;
- }
- trim();
- }
-
- @Override
- public Equality<? super Index> comparator() {
- return Equalities.IDENTITY;
- }
-
- @Override
- public boolean contains(Object index) {
- return get(((Index)index).intValue());
- }
-
- @Override
- public void flip(int bitIndex) {
- int i = bitIndex >> 6;
- ensureCapacity(i + 1);
- bits[i] ^= 1L << bitIndex;
- trim();
- }
-
- @Override
- public void flip(int fromIndex, int toIndex) {
- if ((fromIndex < 0) || (toIndex < fromIndex))
- throw new IndexOutOfBoundsException();
- int i = fromIndex >>> 6;
- int j = toIndex >>> 6;
- ensureCapacity(j + 1);
- if (i == j) {
- bits[i] ^= (-1L << fromIndex) & ((1L << toIndex) - 1);
- return;
- }
- bits[i] ^= -1L << fromIndex;
- bits[j] ^= (1L << toIndex) - 1;
- for (int k = i + 1; k < j; k++) {
- bits[k] ^= -1;
- }
- trim();
- }
-
- @Override
- public boolean get(int bitIndex) {
- int i = bitIndex >> 6;
- return (i >= bits.length) ? false : (bits[i] & (1L << bitIndex)) != 0;
- }
-
- @Override
- public BitSetServiceImpl get(int fromIndex, int toIndex) {
- if (fromIndex < 0 || fromIndex > toIndex)
- throw new IndexOutOfBoundsException();
- BitSetServiceImpl bitSet = new BitSetServiceImpl();
- int length = MathLib.min(bits.length, (toIndex >>> 6) + 1);
- bitSet.bits = new long[length];
- System.arraycopy(bits, 0, bitSet.bits, 0, length);
- bitSet.clear(0, fromIndex);
- bitSet.clear(toIndex, length << 6);
- return bitSet;
- }
-
- /** Sets the specified bit, returns <code>true</code> if previously set. */
- @Override
- public boolean getAndSet(int bitIndex, boolean value) {
- int i = bitIndex >> 6;
- ensureCapacity(i + 1);
- boolean previous = (bits[i] & (1L << bitIndex)) != 0;
- if (value) {
- bits[i] |= 1L << bitIndex;
- } else {
- bits[i] &= ~(1L << bitIndex);
- }
- trim();
- return previous;
- }
-
- @Override
- public boolean intersects(BitSetService that) {
- long[] thatBits = that.toLongArray();
- int i = MathLib.min(this.bits.length, thatBits.length);
- while (--i >= 0) {
- if ((bits[i] & thatBits[i]) != 0) return true;
- }
- return false;
- }
-
- @Override
- public Iterator<Index> iterator() {
- return new BitSetIteratorImpl(this, 0);
- }
-
- @Override
- public int length() {
- if (bits.length == 0) return 0;
- return (bits.length << 6) - MathLib.numberOfLeadingZeros(bits[bits.length -1]);
- }
-
- @Override
- public int nextClearBit(int fromIndex) {
- int offset = fromIndex >> 6;
- long mask = 1L << fromIndex;
- while (offset < bits.length) {
- long h = bits[offset];
- do {
- if ((h & mask) == 0) { return fromIndex; }
- mask <<= 1;
- fromIndex++;
- } while (mask != 0);
- mask = 1;
- offset++;
- }
- return fromIndex;
- }
-
- @Override
- public int nextSetBit(int fromIndex) {
- int offset = fromIndex >> 6;
- long mask = 1L << fromIndex;
- while (offset < bits.length) {
- long h = bits[offset];
- do {
- if ((h & mask) != 0)
- return fromIndex;
- mask <<= 1;
- fromIndex++;
- } while (mask != 0);
- mask = 1;
- offset++;
- }
- return -1;
- }
-
- @Override
- public void or(BitSetService that) {
- long[] thatBits = (that instanceof BitSetServiceImpl) ? ((BitSetServiceImpl) that).bits
- : that.toLongArray();
- ensureCapacity(thatBits.length);
- for (int i = thatBits.length; --i >= 0;) {
- bits[i] |= thatBits[i];
- }
- trim();
- }
-
- @Override
- public int previousClearBit(int fromIndex) {
- int offset = fromIndex >> 6;
- long mask = 1L << fromIndex;
- while (offset >= 0) {
- long h = bits[offset];
- do {
- if ((h & mask) == 0)
- return fromIndex;
- mask >>= 1;
- fromIndex--;
- } while (mask != 0);
- mask = 1L << 63;
- offset--;
- }
- return -1;
- }
-
- @Override
- public int previousSetBit(int fromIndex) {
- int offset = fromIndex >> 6;
- long mask = 1L << fromIndex;
- while (offset >= 0) {
- long h = bits[offset];
- do {
- if ((h & mask) != 0)
- return fromIndex;
- mask >>= 1;
- fromIndex--;
- } while (mask != 0);
- mask = 1L << 63;
- offset--;
- }
- return -1;
- }
-
- @Override
- public boolean remove(Object index) {
- return getAndSet(((Index)index).intValue(), false);
- }
-
- @Override
- public void set(int bitIndex) {
- int i = bitIndex >> 6;
- ensureCapacity(i + 1);
- bits[i] |= 1L << bitIndex;
- }
-
- @Override
- public void set(int bitIndex, boolean value) {
- if (value) {
- set(bitIndex);
- } else {
- clear(bitIndex);
- }
- }
-
- @Override
- public void set(int fromIndex, int toIndex) {
- int i = fromIndex >>> 6;
- int j = toIndex >>> 6;
- ensureCapacity(j + 1);
- if (i == j) {
- bits[i] |= (-1L << fromIndex) & ((1L << toIndex) - 1);
- return;
- }
- bits[i] |= -1L << fromIndex;
- bits[j] |= (1L << toIndex) - 1;
- for (int k = i + 1; k < j; k++) {
- bits[k] = -1;
- }
- }
-
- @Override
- public void set(int fromIndex, int toIndex, boolean value) {
- if (value) {
- set(fromIndex, toIndex);
- } else {
- clear(fromIndex, toIndex);
- }
- }
-
- @Override
- public int size() {
- return cardinality();
- }
-
- @Override
- public long[] toLongArray() {
- return bits;
- }
-
- @Override
- public void xor(BitSetService that) {
- long[] thatBits = (that instanceof BitSetServiceImpl) ? ((BitSetServiceImpl) that).bits
- : that.toLongArray();
- ensureCapacity(thatBits.length);
- for (int i = thatBits.length; --i >= 0;) {
- bits[i] ^= thatBits[i];
- }
- trim();
- }
-
- // Checks capacity.
- private void ensureCapacity(int capacity) {
- if (bits.length < capacity) resize(capacity);
- }
-
- // Resize.
- private void resize(int min) {
- int newLength = bits.length * 2;
- while (newLength < min) newLength *= 2;
- long[] tmp = new long[newLength];
- System.arraycopy(bits, 0, tmp, 0, bits.length);
- bits = tmp;
- }
-
- /**
- * Removes the tails words if cleared.
- */
- private void trim() {
- int n = bits.length;
- while ((--n >= 0) && (bits[n] == 0L)) {}
- if (++n < bits.length) ensureCapacity(n);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/AtomicCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/AtomicCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/AtomicCollectionImpl.java
index 9773743..a76ce38 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/AtomicCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/AtomicCollectionImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.collection;
-import java.util.Collection;
-import java.util.Iterator;
-
import javolution.util.function.Consumer;
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
+import java.util.Collection;
+import java.util.Iterator;
+
/**
* An atomic view over a collection (copy-on-write).
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/CollectionView.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/CollectionView.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/CollectionView.java
index c077ad7..a2ed55b 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/CollectionView.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/CollectionView.java
@@ -8,17 +8,17 @@
*/
package javolution.util.internal.collection;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
import javolution.util.FastCollection;
import javolution.util.function.Consumer;
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
/**
* Collection view implementation; can be used as root class for implementations
* if target is {@code null}.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/DistinctCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/DistinctCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/DistinctCollectionImpl.java
index 713dc5b..404e76e 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/DistinctCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/DistinctCollectionImpl.java
@@ -8,12 +8,12 @@
*/
package javolution.util.internal.collection;
-import java.util.Iterator;
-
import javolution.util.FastSet;
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
+import java.util.Iterator;
+
/**
* A view which does not iterate twice over the same elements.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/FilteredCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/FilteredCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/FilteredCollectionImpl.java
index 8f1574c..e64f4c5 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/FilteredCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/FilteredCollectionImpl.java
@@ -8,12 +8,12 @@
*/
package javolution.util.internal.collection;
-import java.util.Iterator;
-
import javolution.util.function.Equality;
import javolution.util.function.Predicate;
import javolution.util.service.CollectionService;
+import java.util.Iterator;
+
/**
* A filtered view over a collection.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/MappedCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/MappedCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/MappedCollectionImpl.java
index 425b7b8..114bba4 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/MappedCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/MappedCollectionImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.collection;
-import java.util.Iterator;
-
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
import javolution.util.function.Function;
import javolution.util.service.CollectionService;
+import java.util.Iterator;
+
/**
* A mapped view over a collection.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ParallelCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ParallelCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ParallelCollectionImpl.java
deleted file mode 100644
index 8056aed..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ParallelCollectionImpl.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util.internal.collection;
-
-import java.util.Iterator;
-
-import javolution.context.ConcurrentContext;
-import javolution.util.function.Consumer;
-import javolution.util.function.Equality;
-import javolution.util.service.CollectionService;
-
-/**
- * A parallel view over a collection.
- */
-public class ParallelCollectionImpl<E> extends CollectionView<E> {
-
- private static final long serialVersionUID = 0x600L; // Version.
-
- public ParallelCollectionImpl(CollectionService<E> target) {
- super(target);
- }
-
- @Override
- public boolean add(E e) {
- return target().add(e);
- }
-
- @Override
- public void clear() {
- target().clear();
- }
-
- @Override
- public Equality<? super E> comparator() {
- return target().comparator();
- }
-
- @Override
- public boolean contains(Object obj) {
- return target().contains(obj);
- }
-
- @Override
- public boolean isEmpty() {
- return target().isEmpty();
- }
-
- @Override
- public Iterator<E> iterator() {
- return target().iterator();
- }
-
- @Override
- public void perform(final Consumer<CollectionService<E>> action,
- CollectionService<E> view) {
- ConcurrentContext ctx = ConcurrentContext.enter();
- try {
- int concurrency = ctx.getConcurrency();
- CollectionService<E>[] subViews = view.split(concurrency + 1, false);
- for (int i = 1; i < subViews.length; i++) {
- final CollectionService<E> subView = subViews[i];
- ctx.execute(new Runnable() {
- @Override
- public void run() {
- target().perform(action, subView);
- }
- });
- }
- target().perform(action, subViews[0]); // This thread works too !
- } finally {
- // Any exception raised during parallel iterations will be re-raised here.
- ctx.exit();
- }
- }
-
- @Override
- public boolean remove(Object obj) {
- return target().remove(obj);
- }
-
- @Override
- public int size() {
- return target().size();
- }
-
- @Override
- public CollectionService<E>[] split(int n, boolean threadsafe) {
- return target().split(n, threadsafe); // Forwards.
- }
-
- @Override
- public void update(final Consumer<CollectionService<E>> action,
- CollectionService<E> view) {
- ConcurrentContext ctx = ConcurrentContext.enter();
- try {
- int concurrency = ctx.getConcurrency();
- CollectionService<E>[] subViews = view.split(concurrency + 1, true);
- for (int i = 1; i < subViews.length; i++) {
- final CollectionService<E> subView = subViews[i];
- ctx.execute(new Runnable() {
- @Override
- public void run() {
- target().update(action, subView);
- }
- });
- }
- target().perform(action, subViews[0]); // This thread works too !
- } finally {
- // Any exception raised during parallel iterations will be re-raised here.
- ctx.exit();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ReversedCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ReversedCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ReversedCollectionImpl.java
index 4eef132..edb5b1d 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ReversedCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/ReversedCollectionImpl.java
@@ -8,11 +8,11 @@
*/
package javolution.util.internal.collection;
-import java.util.Iterator;
-
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
+import java.util.Iterator;
+
/**
* A reversed view over a collection.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SequentialCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SequentialCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SequentialCollectionImpl.java
index 5b7ff6f..0623bfe 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SequentialCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SequentialCollectionImpl.java
@@ -8,12 +8,12 @@
*/
package javolution.util.internal.collection;
-import java.util.Iterator;
-
import javolution.util.function.Consumer;
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
+import java.util.Iterator;
+
/**
* A sequential view over a collection.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SharedCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SharedCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SharedCollectionImpl.java
index 74ff05c..689fa5c 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SharedCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SharedCollectionImpl.java
@@ -8,14 +8,14 @@
*/
package javolution.util.internal.collection;
-import java.util.Collection;
-import java.util.Iterator;
-
import javolution.util.function.Consumer;
import javolution.util.function.Equality;
import javolution.util.internal.ReadWriteLockImpl;
import javolution.util.service.CollectionService;
+import java.util.Collection;
+import java.util.Iterator;
+
/**
* A shared view over a collection (reads-write locks).
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SortedCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SortedCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SortedCollectionImpl.java
index 6f35d53..9c04c9c 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SortedCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/SortedCollectionImpl.java
@@ -8,14 +8,14 @@
*/
package javolution.util.internal.collection;
-import java.util.Comparator;
-import java.util.Iterator;
-
import javolution.util.FastTable;
import javolution.util.function.Equality;
import javolution.util.internal.comparator.WrapperComparatorImpl;
import javolution.util.service.CollectionService;
+import java.util.Comparator;
+import java.util.Iterator;
+
/**
* A sorted view over a collection.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/UnmodifiableCollectionImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/UnmodifiableCollectionImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/UnmodifiableCollectionImpl.java
index d6b0481..be13365 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/UnmodifiableCollectionImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/collection/UnmodifiableCollectionImpl.java
@@ -8,11 +8,11 @@
*/
package javolution.util.internal.collection;
-import java.util.Iterator;
-
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
+import java.util.Iterator;
+
/**
* An unmodifiable view over a collection.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/comparator/WrapperComparatorImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/comparator/WrapperComparatorImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/comparator/WrapperComparatorImpl.java
index 5578107..e5f0b51 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/comparator/WrapperComparatorImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/comparator/WrapperComparatorImpl.java
@@ -8,10 +8,10 @@
*/
package javolution.util.internal.comparator;
-import java.util.Comparator;
-
import javolution.util.function.Equality;
+import java.util.Comparator;
+
/**
* A comparator service wrapping a {@ link Comparator}, since
* consistency with hashcode cannot be maintained. The hashcode
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/AtomicMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/AtomicMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/AtomicMapImpl.java
index 988b677..3c097ee 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/AtomicMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/AtomicMapImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.map;
-import java.util.Iterator;
-import java.util.Map;
-
import javolution.util.function.Consumer;
import javolution.util.function.Equality;
import javolution.util.service.MapService;
+import java.util.Iterator;
+import java.util.Map;
+
/**
* An atomic view over a map (copy-on-write).
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/FastMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/FastMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/FastMapImpl.java
index 7676647..8e13e89 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/FastMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/FastMapImpl.java
@@ -8,11 +8,11 @@
*/
package javolution.util.internal.map;
+import javolution.util.function.Equality;
+
import java.util.Iterator;
import java.util.NoSuchElementException;
-import javolution.util.function.Equality;
-
/**
* The default {@link javolution.util.FastMap FastMap} implementation
* based on {@link FractalMapImpl fractal maps}.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/MapView.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/MapView.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/MapView.java
index 6ec0238..f957c55 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/MapView.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/MapView.java
@@ -8,10 +8,6 @@
*/
package javolution.util.internal.map;
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.Map;
-
import javolution.util.function.Consumer;
import javolution.util.function.Equality;
import javolution.util.function.Function;
@@ -22,6 +18,10 @@ import javolution.util.service.CollectionService;
import javolution.util.service.MapService;
import javolution.util.service.SetService;
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Map;
+
/**
* Map view implementation; can be used as root class for implementations
* if target is {@code null}.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/ParallelMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/ParallelMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/ParallelMapImpl.java
deleted file mode 100644
index 21d079e..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/ParallelMapImpl.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util.internal.map;
-
-import java.util.Iterator;
-
-import javolution.context.ConcurrentContext;
-import javolution.util.function.Consumer;
-import javolution.util.function.Equality;
-import javolution.util.service.MapService;
-
-/**
- * A parallel view over a map.
- */
-public class ParallelMapImpl<K, V> extends MapView<K, V> {
-
- private static final long serialVersionUID = 0x600L; // Version.
-
- public ParallelMapImpl(MapService<K, V> target) {
- super(target);
- }
-
- @Override
- public void clear() {
- target().clear();
- }
-
- @Override
- public boolean containsKey(Object key) {
- return target().containsKey(key);
- }
-
- @Override
- public V get(Object key) {
- return target().get(key);
- }
-
- @Override
- public boolean isEmpty() {
- return target().isEmpty();
- }
-
- @Override
- public Iterator<java.util.Map.Entry<K, V>> iterator() {
- return target().iterator();
- }
-
- @Override
- public Equality<? super K> keyComparator() {
- return target().keyComparator();
- }
-
- @Override
- public void perform(final Consumer<MapService<K, V>> action,
- MapService<K, V> view) {
- ConcurrentContext ctx = ConcurrentContext.enter();
- try {
- int concurrency = ctx.getConcurrency();
- MapService<K, V>[] subViews = view.split(concurrency + 1, false);
- for (int i = 1; i < subViews.length; i++) {
- final MapService<K, V> subView = subViews[i];
- ctx.execute(new Runnable() {
- @Override
- public void run() {
- target().perform(action, subView);
- }
- });
- }
- target().perform(action, subViews[0]); // This thread works too !
- } finally {
- // Any exception raised during parallel iterations will be re-raised here.
- ctx.exit();
- }
- }
-
- @Override
- public V put(K key, V value) {
- return target().put(key, value);
- }
-
- @Override
- public V remove(Object key) {
- return target().remove(key);
- }
-
- @Override
- public int size() {
- return target().size();
- }
-
- @Override
- public void update(final Consumer<MapService<K, V>> action,
- MapService<K, V> view) {
- ConcurrentContext ctx = ConcurrentContext.enter();
- try {
- int concurrency = ctx.getConcurrency();
- MapService<K, V>[] subViews = view.split(concurrency + 1, true);
- for (int i = 1; i < subViews.length; i++) {
- final MapService<K, V> subView = subViews[i];
- ctx.execute(new Runnable() {
- @Override
- public void run() {
- target().update(action, subView);
- }
- });
- }
- target().perform(action, subViews[0]); // This thread works too !
- } finally {
- // Any exception raised during parallel iterations will be re-raised here.
- ctx.exit();
- }
- }
-
- @Override
- public Equality<? super V> valueComparator() {
- return target().valueComparator();
- }
-
- @Override
- public MapService<K, V>[] split(int n, boolean threadsafe) {
- return target().split(n, threadsafe); // Forwards.
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SequentialMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SequentialMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SequentialMapImpl.java
index 114a884..86b9f40 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SequentialMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SequentialMapImpl.java
@@ -8,12 +8,12 @@
*/
package javolution.util.internal.map;
-import java.util.Iterator;
-
import javolution.util.function.Consumer;
import javolution.util.function.Equality;
import javolution.util.service.MapService;
+import java.util.Iterator;
+
/**
* A sequential view over a map.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SharedMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SharedMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SharedMapImpl.java
index 833e728..1df80ac 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SharedMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/SharedMapImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.map;
-import java.util.Iterator;
-import java.util.Map;
-
import javolution.util.function.Equality;
import javolution.util.internal.ReadWriteLockImpl;
import javolution.util.service.MapService;
+import java.util.Iterator;
+import java.util.Map;
+
/**
* A shared view over a map.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/UnmodifiableMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/UnmodifiableMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/UnmodifiableMapImpl.java
index 196e9cc..c448166 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/UnmodifiableMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/UnmodifiableMapImpl.java
@@ -8,11 +8,11 @@
*/
package javolution.util.internal.map;
-import java.util.Iterator;
-
import javolution.util.function.Equality;
import javolution.util.service.MapService;
+import java.util.Iterator;
+
/**
* * An unmodifiable view over a map.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/AtomicSortedMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/AtomicSortedMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/AtomicSortedMapImpl.java
index c26c500..5cc4839 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/AtomicSortedMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/AtomicSortedMapImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.map.sorted;
-import java.util.Comparator;
-import java.util.Map;
-
import javolution.util.internal.map.AtomicMapImpl;
import javolution.util.service.SortedMapService;
import javolution.util.service.SortedSetService;
+import java.util.Comparator;
+import java.util.Map;
+
/**
* An atomic view over a sorted map (copy-on-write).
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/FastSortedMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/FastSortedMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/FastSortedMapImpl.java
index 111bc1d..f30cc49 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/FastSortedMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/FastSortedMapImpl.java
@@ -8,11 +8,11 @@
*/
package javolution.util.internal.map.sorted;
-import java.util.Iterator;
-
import javolution.util.function.Equality;
import javolution.util.internal.table.sorted.FastSortedTableImpl;
+import java.util.Iterator;
+
/**
* A map view over a sorted table of entries.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SharedSortedMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SharedSortedMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SharedSortedMapImpl.java
index fecc094..9d1df7d 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SharedSortedMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SharedSortedMapImpl.java
@@ -8,14 +8,14 @@
*/
package javolution.util.internal.map.sorted;
-import java.util.Comparator;
-import java.util.Map;
-
import javolution.util.internal.ReadWriteLockImpl;
import javolution.util.internal.map.SharedMapImpl;
import javolution.util.service.SortedMapService;
import javolution.util.service.SortedSetService;
+import java.util.Comparator;
+import java.util.Map;
+
/**
* A shared view over a sorted map.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SortedMapView.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SortedMapView.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SortedMapView.java
index bb51d56..bd7e54f 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SortedMapView.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SortedMapView.java
@@ -8,14 +8,14 @@
*/
package javolution.util.internal.map.sorted;
-import java.util.Comparator;
-import java.util.Map;
-
import javolution.util.internal.map.MapView;
import javolution.util.internal.set.sorted.SubSortedSetImpl;
import javolution.util.service.SortedMapService;
import javolution.util.service.SortedSetService;
+import java.util.Comparator;
+import java.util.Map;
+
/**
* Sorted map view implementation; can be used as root class for implementations
* if target is {@code null}.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SubSortedMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SubSortedMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SubSortedMapImpl.java
index 59e4cbd..481e653 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SubSortedMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/SubSortedMapImpl.java
@@ -8,12 +8,12 @@
*/
package javolution.util.internal.map.sorted;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
import javolution.util.function.Equality;
import javolution.util.service.SortedMapService;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
/**
* A view over a portion of a sorted map.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/UnmodifiableSortedMapImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/UnmodifiableSortedMapImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/UnmodifiableSortedMapImpl.java
index 60db2b2..fc80711 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/UnmodifiableSortedMapImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/map/sorted/UnmodifiableSortedMapImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.map.sorted;
-import java.util.Comparator;
-import java.util.Map;
-
import javolution.util.internal.map.UnmodifiableMapImpl;
import javolution.util.service.SortedMapService;
import javolution.util.service.SortedSetService;
+import java.util.Comparator;
+import java.util.Map;
+
/**
* * An unmodifiable view over a map.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/set/sorted/SubSortedSetImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/set/sorted/SubSortedSetImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/set/sorted/SubSortedSetImpl.java
index 3673004..d44ca86 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/set/sorted/SubSortedSetImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/set/sorted/SubSortedSetImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.set.sorted;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
import javolution.util.function.Equality;
import javolution.util.service.CollectionService;
import javolution.util.service.SortedSetService;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
/**
* A view over a portion of a sorted set.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/AtomicTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/AtomicTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/AtomicTableImpl.java
index 056c149..4ed8926 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/AtomicTableImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/AtomicTableImpl.java
@@ -8,13 +8,13 @@
*/
package javolution.util.internal.table;
+import javolution.util.internal.collection.AtomicCollectionImpl;
+import javolution.util.service.TableService;
+
import java.util.Collection;
import java.util.Iterator;
import java.util.ListIterator;
-import javolution.util.internal.collection.AtomicCollectionImpl;
-import javolution.util.service.TableService;
-
/**
* An atomic view over a table.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/FastTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/FastTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/FastTableImpl.java
index 070da4d..dc92d09 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/FastTableImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/FastTableImpl.java
@@ -8,11 +8,11 @@
*/
package javolution.util.internal.table;
+import javolution.util.function.Equality;
+
import java.util.Iterator;
import java.util.NoSuchElementException;
-import javolution.util.function.Equality;
-
/**
* The default {@link javolution.util.FastTable FastTable} implementation
* based on {@link FractalTableImpl fractal tables}. The memory footprint
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/QuickSort.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/QuickSort.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/QuickSort.java
index 13cf342..4bfd9f8 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/QuickSort.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/QuickSort.java
@@ -8,10 +8,10 @@
*/
package javolution.util.internal.table;
-import java.util.Comparator;
-
import javolution.util.service.TableService;
+import java.util.Comparator;
+
/**
* A quick sort utility class.
* From Wikipedia Quick Sort - http://en.wikipedia.org/wiki/Quicksort
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SharedTableImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SharedTableImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SharedTableImpl.java
index bc68a16..4f77098 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SharedTableImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/SharedTableImpl.java
@@ -8,14 +8,14 @@
*/
package javolution.util.internal.table;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.ListIterator;
-
import javolution.util.internal.ReadWriteLockImpl;
import javolution.util.internal.collection.SharedCollectionImpl;
import javolution.util.service.TableService;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ListIterator;
+
/**
* A shared view over a table allowing concurrent access and sequential updates.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java
index 913e9a0..b280181 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableIteratorImpl.java
@@ -8,11 +8,11 @@
*/
package javolution.util.internal.table;
+import javolution.util.service.TableService;
+
import java.util.ListIterator;
import java.util.NoSuchElementException;
-import javolution.util.service.TableService;
-
/**
* A generic iterator over a table.
*/
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java
index eaa8a4d..e377755 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/internal/table/TableView.java
@@ -8,15 +8,15 @@
*/
package javolution.util.internal.table;
+import javolution.util.function.Equality;
+import javolution.util.internal.collection.CollectionView;
+import javolution.util.service.TableService;
+
import java.util.Collection;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.NoSuchElementException;
-import javolution.util.function.Equality;
-import javolution.util.internal.collection.CollectionView;
-import javolution.util.service.TableService;
-
/**
* Table view implementation; can be used as root class for implementations
* if target is {@code null}.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java
deleted file mode 100644
index 6c45891..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/util/service/BitSetService.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util.service;
-
-import javolution.util.FastBitSet;
-import javolution.util.FastTable;
-import javolution.util.Index;
-
-/**
- * The set of related functionalities which can be used/reused to
- * implement bit-sets collections.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- * @see FastTable
- */
-public interface BitSetService extends SetService<Index> {
-
- //
- // Read Accessors.
- //
-
- /** See {@link FastBitSet#cardinality() } */
- int cardinality();
-
- /** See {@link FastBitSet#get(int) } */
- boolean get(int bitIndex);
-
- /** See {@link FastBitSet#get(int, int) } */
- BitSetService get(int fromIndex, int toIndex);
-
- /** See {@link FastBitSet#intersects(FastBitSet) } */
- boolean intersects(BitSetService that);
-
- /** See {@link FastBitSet#length() } */
- int length();
-
- //
- // Iterations
- //
-
- /** See {@link FastBitSet#nextClearBit(int) } */
- int nextClearBit(int fromIndex);
-
- /** See {@link FastBitSet#nextSetBit(int) } */
- int nextSetBit(int fromIndex);
-
- /** See {@link FastBitSet#previousClearBit(int) } */
- int previousClearBit(int fromIndex);
-
- /** See {@link FastBitSet#previousSetBit(int) } */
- int previousSetBit(int fromIndex);
-
- //
- // Clear/Set/Flip Operations
- //
-
- /** See {@link FastBitSet#clear(int) } */
- void clear(int bitIndex);
-
- /** See {@link FastBitSet#clear(int, int) } */
- void clear(int fromIndex, int toIndex);
-
- /** Clear or sets the specified bit, returns <code>true</code>
- * if previously set; <code>false</code> otherwise. */
- boolean getAndSet(int bitIndex, boolean value);
-
- /** See {@link FastBitSet#set(int) } */
- void set(int bitIndex);
-
- /** See {@link FastBitSet#set(int, boolean) } */
- void set(int bitIndex, boolean value);
-
- /** See {@link FastBitSet#set(int, int) } */
- void set(int fromIndex, int toIndex);
-
- /** See {@link FastBitSet#set(int, int, boolean) } */
- void set(int fromIndex, int toIndex, boolean value);
-
- /** See {@link FastBitSet#flip(int) } */
- void flip(int bitIndex);
-
- /** See {@link FastBitSet#flip(int, int) } */
- void flip(int fromIndex, int toIndex);
-
- //
- // Operators Operations
- //
-
- /** See {@link FastBitSet#and(FastBitSet) } */
- void and(BitSetService that);
-
- /** See {@link FastBitSet#andNot(FastBitSet) } */
- void andNot(BitSetService that);
-
- /** See {@link FastBitSet#or(FastBitSet) } */
- void or(BitSetService that);
-
- /** See {@link FastBitSet#xor(FastBitSet) } */
- void xor(BitSetService that);
-
- //
- // Misc.
- //
-
- /** Returns the minimal length <code>long[]</code> representation of this
- * bitset. */
- long[] toLongArray();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java
index 37dbb8a..f4664a8 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/CollectionService.java
@@ -8,12 +8,12 @@
*/
package javolution.util.service;
-import java.io.Serializable;
-import java.util.Collection;
-
import javolution.util.function.Equality;
import javolution.util.function.Splittable;
+import java.io.Serializable;
+import java.util.Collection;
+
/**
* The fundamental set of related functionalities required to implement
* fast collections.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java
index 20090a3..c4a8f91 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/MapService.java
@@ -8,14 +8,14 @@
*/
package javolution.util.service;
+import javolution.util.function.Equality;
+import javolution.util.function.Splittable;
+
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
-import javolution.util.function.Equality;
-import javolution.util.function.Splittable;
-
/**
* The set of related map functionalities required to implement fast maps.
*
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java b/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java
index 21af9d7..e338840 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/service/TableService.java
@@ -8,8 +8,8 @@
*/
package javolution.util.service;
-import java.util.List;
import java.util.Deque;
+import java.util.List;
import java.util.RandomAccess;
/**
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java b/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java
deleted file mode 100644
index f4e894e..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/DefaultXMLFormat.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-/**
- * <p> Specifies the default xml format of a class (for xml serialization/deserialization).
- * The default format is used by the {@link javolution.xml.XMLObjectReader}
- * and {@link javolution.xml.XMLObjectWriter} classes. It can be locally overridden
- * in the scope of a {@link javolution.xml.XMLContext XMLContext}.</p>
- *
- * [code]
- * @DefaultXMLFormat(Complex.XML.class)
- * public class Complex {
- * public Complex(double real, double imaginary) { ... }
- * public double getReal() { ... }
- * public double getImaginary() { ... }
- * public static class XML extends XMLFormat<Complex> {
- * public Complex newInstance(Class<? extends Complex> cls, InputElement xml) throws XMLStreamException {
- * return new Complex(xml.getAttribute("real", 0.0), xml.getAttribute("imaginary", 0.0));
- * }
- * public void read(InputElement xml, Complex c) throws XMLStreamException {
- * // Immutable object, no further processing.
- * }
- * public void write(Complex c, OutputElement xml) throws XMLStreamException {
- * xml.setAttribute("real", c.getReal());
- * xml.setAttribute("imaginary", c.getImaginary());
- * }
- * };
- * }[/code]
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-@Documented
-@Inherited
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface DefaultXMLFormat {
-
- /**
- * Returns the default xml format of the annotated class.
- */
- Class<? extends XMLFormat<?>> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java b/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java
deleted file mode 100644
index 0b8298a..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/QName.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2007 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml;
-
-import java.io.ObjectStreamException;
-import java.lang.CharSequence;
-
-import javolution.lang.Immutable;
-import javolution.text.CharArray;
-import javolution.text.TextBuilder;
-import javolution.util.FastMap;
-import javolution.util.function.Equalities;
-
-/**
- * <p> This class represents unique identifiers for XML elements (tags) or
- * attributes (names).</p>
- *
- * <p> It should be noted that <code>QName.valueOf(null, "name")</code> and
- * <code>QName.valueOf("", "name")</code> are distinct; the first one has no
- * namespace associated with; whereas the second is associated
- * to the root namespace.</p>
- *
- * <p> {@link QName} have a textual representation ({@link CharSequence}) which
- * is either the local name (if no namespace URI) or
- * <code>{namespaceURI}localName</code> (otherwise).</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.3, January 14, 2007
- * @see <a href="http://en.wikipedia.org/wiki/Qname">Wikipedia: QName</a>
- */
-public final class QName implements XMLSerializable, Immutable<QName>, CharSequence {
-
- /**
- * Holds the local name.
- */
- private transient final CharArray _localName;
-
- /**
- * Holds the namespace URI reference or <code>null</code> if none.
- */
- private transient final CharArray _namespaceURI;
-
- /**
- * Holds the string representation.
- */
- private final String _toString;
-
- /**
- * Holds the full name (String) to QName mapping.
- */
- private static final FastMap<CharSequence, QName> FULL_NAME_TO_QNAME = new FastMap<CharSequence, QName>(
- Equalities.LEXICAL);
-
- /**
- * Creates a qualified name having the specified local name and namespace
- * reference.
- *
- * @param namespaceURI the URI reference or <code>null</code> if none.
- * @param localName the local name.
- * @param toString the string representation.
- */
- private QName(String namespaceURI, String localName, String toString) {
- _namespaceURI = (namespaceURI == null) ? null : new CharArray(
- namespaceURI);
- _localName = new CharArray(localName);
- _toString = toString;
- }
-
- /**
- * Returns the qualified name corresponding to the specified character
- * sequence representation (may include the "{namespaceURI}" prefix).
- *
- * @param name the qualified name lexical representation.
- * @see #toString()
- */
- public static QName valueOf(CharSequence name) {
- QName qName = (QName) FULL_NAME_TO_QNAME.get(name);
- return (qName != null) ? qName : QName.createNoNamespace(name
- .toString());
- }
-
- private static QName createNoNamespace(String name) {
- String localName = name;
- String namespaceURI = null;
- if (name.length() > 0 && name.charAt(0) == '{') { // Namespace URI.
- int index = name.lastIndexOf('}');
- localName = name.substring(index + 1);
- namespaceURI = name.substring(1, index);
- }
- QName qName = new QName(namespaceURI, localName, name);
- synchronized (FULL_NAME_TO_QNAME) {
- QName tmp = (QName) FULL_NAME_TO_QNAME.putIfAbsent(name, qName);
- return tmp == null ? qName : tmp;
- }
- }
-
- /**
- * Equivalent to {@link #valueOf(CharSequence)} (for J2ME compatibility).
- *
- * @param name the qualified name lexical representation.
- * @see #toString()
- */
- public static QName valueOf(String name) {
- QName qName = (QName) FULL_NAME_TO_QNAME.get(name);
- return (qName != null) ? qName : QName.createNoNamespace(name);
- }
-
- /**
- * Returns the qualified name corresponding to the specified namespace URI
- * and local name.
- *
- * @param namespaceURI the URI reference or <code>null</code> if none.
- * @param localName the local name.
- * @see #toString()
- */
- public static QName valueOf(CharSequence namespaceURI,
- CharSequence localName) {
- if (namespaceURI == null)
- return QName.valueOf(localName);
- TextBuilder tmp = new TextBuilder();
- tmp.append('{');
- tmp.append(namespaceURI);
- tmp.append('}');
- tmp.append(localName);
- return QName.valueOf(tmp);
- }
-
- /**
- * Returns the local part of this qualified name or the full qualified
- * name if there is no namespace.
- *
- * @return the local name.
- */
- public CharSequence getLocalName() {
- return _localName;
- }
-
- /**
- * Returns the namespace URI of this qualified name or <code>null</code>
- * if none (the local name is then the full qualified name).
- *
- * @return the URI reference or <code>null</code>
- */
- public CharSequence getNamespaceURI() {
- return _namespaceURI;
- }
-
- /**
- * Instances of this class are unique; object's equality can be
- * replaced object identity (<code>==</code>).
- *
- * @return <code>this == obj</code>
- */
- public boolean equals(Object obj) {
- return this == obj;
- }
-
- /**
- * Returns the <code>String</code> representation of this qualified name.
- *
- * @return the textual representation.
- */
- public String toString() {
- return _toString;
- }
-
- /**
- * Returns the hash code for this qualified name.
- *
- * <p> Note: Returns the same hashCode as <code>java.lang.String</code>
- * (consistent with {@link #equals})</p>
- * @return the hash code value.
- */
- public int hashCode() {
- return _toString.hashCode();
- }
-
- /**
- * Returns the character at the specified index.
- *
- * @param index the index of the character starting at <code>0</code>.
- * @return the character at the specified index of this character sequence.
- * @throws IndexOutOfBoundsException if <code>((index < 0) ||
- * (index >= length))</code>
- */
- public char charAt(int index) {
- return _toString.charAt(index);
- }
-
- /**
- * Returns the length of this character sequence.
- *
- * @return the number of characters (16-bits Unicode) composing this
- * character sequence.
- */
- public int length() {
- return _toString.length();
- }
-
- /**
- * Returns a new character sequence that is a subsequence of this sequence.
- *
- * @param start the index of the first character inclusive.
- * @param end the index of the last character exclusive.
- * @return the character sequence starting at the specified
- * <code>start</code> position and ending just before the specified
- * <code>end</code> position.
- * @throws IndexOutOfBoundsException if {@code (start < 0) || (end < 0) ||
- * (start > end) || (end > this.length())}
- */
- public CharSequence subSequence(int start, int end) {
- return _toString.substring(start, end);
- }
-
- //Maintains unicity.
- private Object readResolve() throws ObjectStreamException {
- return QName.valueOf(_toString);
- }
-
- private static final long serialVersionUID = -6126031630693748647L;
-
- @Override
- public QName value() {
- return this;
- }
-
-}
\ No newline at end of file
[10/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/test/Perfometer.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/test/Perfometer.java b/commons/marmotta-commons/src/ext/java/javolution/test/Perfometer.java
deleted file mode 100644
index bd9707d..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/test/Perfometer.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.test;
-
-import javolution.context.LogContext;
-import javolution.lang.Configurable;
-import javolution.lang.MathLib;
-import javolution.text.TextBuilder;
-import javolution.util.FastTable;
-
-/**
- * <p> Utility class to measure the worst case execution time and average
- * execution time with high precision. Here an example measuring the
- * worst case execution time of {@link java.util.List#add(int, Object)}
- * for diverse list implementations.</p>
- * [code]
- * Perfometer<Class<? extends List>> insertPerf = new Perfometer<>("java.util.List#add(int, Object)") {
- * List<Object> list;
- * Random random;
- * protected void initialize() throws Exception {
- * list = getInput().newInstance();
- * random = new Random(-1); // Use seed to ensure same execution path.
- * }
- * protected void run(boolean measure) {
- * Object obj = new Object();
- * int i = random.nextInt(list.size() + 1);
- * if (measure) list.add(i, obj);
- * }
- * protected void validate() { // Optional.
- * assert list.size() == getNbrOfIterations();
- * }
- * }
- * ...
- * public void testExecutionTime() {
- * insertPerf.measure(java.util.ArrayList.class, 10000).print();
- * insertPerf.measure(java.util.LinkedList.class, 10000).print();
- * insertPerf.measure(javolution.util.FastTable.class, 10000).print();
- * }
- * ...
- * > [INFO] java.util.List#add(int, Object) (10000) for java.util.ArrayList: 590.21450 ns (avg), 8443.0000 ns (wcet#9369)
- * > [INFO] java.util.List#add(int, Object) (10000) for java.util.LinkedList: 4849.8313 ns (avg), 26536.000 ns (wcet#9863)
- * > [INFO] java.util.List#add(int, Object) (10000) for javolution.util.FastTable: 217.26300 ns (avg), 534.00000 ns (wcet#8864)
- * [/code]
- *
- * @param <T> the perfometer input type.
- */
-public abstract class Perfometer<T> {
-
- /**
- * Hold the measurement duration in milliseconds (default 1000 ms).
- */
- public static final Configurable<Integer> DURATION_MS = new Configurable<Integer>() {
-
- @Override
- public String getName() { // Requires since there are multiple configurable fields.
- return this.getClass().getEnclosingClass().getName()
- + "#DURATION_MS";
- }
-
- @Override
- protected Integer getDefault() {
- return 1000;
- }
-
- };
- /**
- * Indicates if perfometer measurements should be skipped (
- * e.g. {@code -Djavolution.test.Perfometer#SKIP=true} to skip
- * performance measurements).
- * When skipped, {@link #measure} and {@link #print} don't do anything.
- */
- public static final Configurable<Boolean> SKIP = new Configurable<Boolean>() {
-
- @Override
- public String getName() { // Requires since there are multiple configurable fields.
- return this.getClass().getEnclosingClass().getName() + "#SKIP";
- }
-
- @Override
- protected Boolean getDefault() {
- return false;
- }
- };
-
- private final String description;
- private T input;
- private long[] times; // Nano-Seconds.
-
- /**
- * Creates a perfometer having the specified description.
- *
- * @param description the description of the code being measured.
- */
- public Perfometer(String description) {
- this.description = description;
- }
-
- /**
- * Returns the average execution time in seconds.
- */
- public double getAvgTimeInSeconds() {
- if (times == null) return Double.NaN;
- long sum = 0;
- for (long time : times) {
- sum += time;
- }
- return sum / 1e9 / times.length;
- }
-
- /**
- * Returns this perfometer description.
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Returns this perfometer current inputs.
- */
- public T getInput() {
- return input;
- }
-
- /**
- * Returns this perfometer current number of iterations performed.
- */
- public int getNbrOfIterations() {
- return (times != null) ? times.length : 0;
- }
-
- /**
- * Returns the execution times in seconds.
- */
- public double[] getTimesInSeconds() {
- if (times == null) return new double[0];
- double[] timesSec = new double[times.length];
- for (int i=0; i < times.length; i++) {
- timesSec[i] = times[i] / 1e9;
- }
- return timesSec;
- }
-
- /**
- * Measures the worst case execution time and average execution time.
- *
- * @param input the test input.
- * @param nbrOfIterations the number of iterations performed on which
- * the average will be calculated.
- */
- public Perfometer<T> measure(T input, int nbrOfIterations) {
- if (SKIP.get()) return this; // Skip.
- this.input = input;
- this.times = new long[nbrOfIterations];
- long[] calibrations = longArray(nbrOfIterations, Long.MAX_VALUE);
- long[] measures = longArray(nbrOfIterations, Long.MAX_VALUE);
- try {
- long exitTime = System.currentTimeMillis() + DURATION_MS.get();
- do {
- // Calibration.
- initialize();
- for (int i = 0; i < nbrOfIterations; i++) {
- long start = System.nanoTime();
- run(false);
- long time = System.nanoTime() - start;
- calibrations[i] = MathLib.min(calibrations[i], time);
- }
- // Measurement.
- initialize();
- for (int i = 0; i < nbrOfIterations; i++) {
- long start = System.nanoTime();
- run(true);
- long time = System.nanoTime() - start;
- measures[i] = MathLib.min(measures[i], time);
- }
- } while (System.currentTimeMillis() < exitTime);
- for (int i = 0; i < nbrOfIterations; i++) {
- times[i] = measures[i] - calibrations[i];
- }
- return this;
- } catch (Exception error) {
- throw new RuntimeException("Perfometer Exception", error);
- }
- }
-
- /**
- * Outputs the result.
- */
- public void print() {
- if (Perfometer.SKIP.get()) return;
- TextBuilder txt = new TextBuilder();
- txt.append(description).append(" (").append(getNbrOfIterations())
- .append(") for ").append(input).append(": ");
- while (txt.length() < 80)
- txt.append(' ');
- txt.append(getAvgTimeInSeconds() * 1E9, 8, false, true); // Nano-Seconds.
- txt.append(" ns (avg), ");
- txt.append(getWCETinSeconds() * 1E9, 8, false, true); // Nano-Seconds.
- txt.append(" ns (wcet#").append(getWorstCaseNumber()).append(")");
- LogContext.info(txt);
- }
-
- /**
- * Outputs the measurements in nanoseconds.
- */
- public void printDetails() {
- if (Perfometer.SKIP.get()) return;
- FastTable<Long> measurements = new FastTable<Long>();
- for (long time : times)
- measurements.add(time);
- LogContext.debug(measurements);
- }
-
- /**
- * Returns the worst case execution time in seconds.
- */
- public double getWCETinSeconds() {
- if (times == null) return Double.NaN;
- long wcet = 0;
- for (long time : times) {
- if (time > wcet) wcet = time;
- }
- return wcet / 1e9;
- }
-
- /**
- * Returns the iteration number having the slowest execution time.
- */
- public int getWorstCaseNumber() {
- if (times == null) return -1;
- long wcet = 0;
- int j = -1;
- for (int i=0; i < times.length; i++) {
- if (times[i] > wcet) {
- wcet = times[i];
- j = i;
- }
- }
- return j;
- }
-
- /**
- * Performs the initialization.
- */
- protected abstract void initialize() throws Exception;
-
- /**
- * Runs the code being benchmarked.
- *
- * @param measure {@code false} when calibration is performed;
- * {@code true} otherwise.
- */
- protected abstract void run(boolean measure) throws Exception;
-
- /**
- * Validates the final result (after all iterations are completed).
- */
- protected void validate() {}
-
- private long[] longArray(int length, long initialValue) {
- long[] array = new long[length];
- for (int i = 0; i < length; i++)
- array[i] = initialValue;
- return array;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/test/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/test/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/test/package-info.java
deleted file mode 100644
index be22b58..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/test/package-info.java
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
-<p> Testing tools for validation and performance.</p>
- */
-package javolution.test;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/CharArray.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/CharArray.java b/commons/marmotta-commons/src/ext/java/javolution/text/CharArray.java
deleted file mode 100644
index 320bd00..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/CharArray.java
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import javolution.util.function.Equalities;
-
-/**
- * <p> A {@link CharSequence} backed up by a <code>char</code> array.
- * Instances of this class are
- * typically used/reused to provide <code>CharSequence</code> views
- * over existing character buffers.</p>
- *
- * <p> Instances of this classes have the following properties:<ul>
- *
- * <li> They support equality or lexical comparison with any
- * <code>CharSequence</code> (e.g. <code>String</code>).</li>
- *
- * <li> They have the same hashcode than <code>String</code> and can be
- * used to retrieve data from maps for which the keys are
- * <code>String</code> instances.</li>
- *
- * <li> They support fast conversions to primitive types
- * (e.g. {@link #toBoolean() Boolean}, {@link #toInt int}).</li>
- *
- * </ul></p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.3, January 10, 2007
- */
-public final class CharArray implements CharSequence, Comparable<CharSequence> {
-
- /**
- * Holds the character array.
- */
- private char[] _array;
-
- /**
- * Holds the index of the first character.
- */
- private int _offset;
-
- /**
- * Holds the length of char sequence.
- */
- private int _length;
-
- /**
- * Default constructor (empty character array).
- */
- public CharArray() {
- _array = NO_CHAR;
- }
-
- private static final char[] NO_CHAR = new char[0];
-
- /**
- * Creates a character array of specified default capacity.
- *
- * @param capacity the backing array default capacity.
- */
- public CharArray(int capacity) {
- _array = new char[capacity];
- }
-
- /**
- * Creates a character array from the specified String.
- *
- * @param string the string source.
- */
- public CharArray(String string) {
- _array = string.toCharArray();
- _length = string.length();
- }
-
- /**
- * Returns the underlying array.
- *
- * @return the underlying array.
- */
- public char[] array() {
- return _array;
- }
-
- /**
- * Returns the length of this character sequence.
- *
- * @return the number of characters (16-bits Unicode).
- */
- public int length() {
- return _length;
- }
-
- /**
- * Returns the offset of the first character in the underlying array.
- *
- * @return the offset of the first character.
- */
- public int offset() {
- return _offset;
- }
-
- /**
- * Sets the underlying array of this CharArray.
- *
- * @param offset the new offset.
- * @param array the new underlying array.
- * @param length the new length.
- * @return <code>this</code>
- */
- public CharArray setArray(char[] array, int offset, int length) {
- _array = array;
- _offset = offset;
- _length = length;
- return this;
- }
-
- /**
- * Returns the index within this character sequence of the first occurrence
- * of the specified characters sequence searching forward.
- *
- * @param csq a character sequence searched for.
- * @return the index of the specified character sequence in the range
- * <code>[0, length()[</code>
- * or <code>-1</code> if the character sequence is not found.
- */
- public final int indexOf(java.lang.CharSequence csq) {
- final char c = csq.charAt(0);
- final int csqLength = csq.length();
- for (int i = _offset, end = _offset + _length - csqLength + 1; i < end; i++) {
- if (_array[i] == c) { // Potential match.
- boolean match = true;
- for (int j = 1; j < csqLength; j++) {
- if (_array[i + j] != csq.charAt(j)) {
- match = false;
- break;
- }
- }
- if (match) { return i - _offset; }
- }
- }
- return -1;
- }
-
- /**
- * Returns the index within this character sequence of the first occurrence
- * of the specified character searching forward.
- *
- * @param c the character to search for.
- * @return the indext of the specified character in the range
- * <code>[0, length()[</code>
- * or <code>-1</code> if the character is not found.
- */
- public final int indexOf(char c) {
- for (int i = _offset, end = _offset + _length; i < end; i++) {
- if (_array[i] == c)
- return i - _offset;
- }
- return -1;
- }
-
- /**
- * Returns the <code>String</code> corresponding to this character
- * sequence. The <code>String</code> returned is always allocated on the
- * heap and can safely be referenced elsewhere.
- *
- * @return the <code>java.lang.String</code> for this character sequence.
- */
- @Override
- public String toString() {
- return new String(_array, _offset, _length);
- }
-
- /**
- * Returns the hash code for this {@link CharArray}.
- *
- * <p> Note: Returns the same hashCode as <code>java.lang.String</code>
- * (consistent with {@link #equals})</p>
- * @return the hash code value.
- */
- @Override
- public int hashCode() {
- int h = 0;
- for (int i = 0, j = _offset; i < _length; i++) {
- h = 31 * h + _array[j++];
- }
- return h;
- }
-
- /**
- * Compares this character sequence against the specified object
- * (<code>String</code> or <code>CharSequence</code>).
- *
- * @param that the object to compare with.
- * @return <code>true</code> if both objects represent the same sequence;
- * <code>false</code> otherwise.
- */
- @Override
- public boolean equals(Object that) {
- if (that instanceof String) {
- return equals((String) that);
- } else if (that instanceof CharArray) {
- return equals((CharArray) that);
- } else if (that instanceof java.lang.CharSequence) {
- return equals((java.lang.CharSequence) that);
- } else {
- return false;
- }
- }
-
- // Do not make public or String instances may not use equals(String)
- private boolean equals(java.lang.CharSequence chars) {
- if (chars == null)
- return false;
- if (this._length != chars.length())
- return false;
- for (int i = _length, j = _offset + _length; --i >= 0;) {
- if (_array[--j] != chars.charAt(i))
- return false;
- }
- return true;
- }
-
- /**
- * Compares this character array against the specified {@link CharArray}.
- *
- * @param that the character array to compare with.
- * @return <code>true</code> if both objects represent the same sequence;
- * <code>false</code> otherwise.
- */
- public boolean equals(CharArray that) {
- if (this == that)
- return true;
- if (that == null)
- return false;
- if (this._length != that._length)
- return false;
- final char[] thatArray = that._array;
- for (int i = that._offset + _length, j = _offset + _length; --j >= _offset;) {
- if (_array[j] != thatArray[--i])
- return false;
- }
- return true;
- }
-
- /**
- * Compares this character array against the specified String.
- * In case of equality, the CharArray keeps a reference to the
- * String for future comparisons.
- *
- * @param str the string to compare with.
- * @return <code>true</code> if both objects represent the same sequence;
- * <code>false</code> otherwise.
- */
- public boolean equals(String str) {
- if (str == null)
- return false;
- if (_length != str.length())
- return false;
- for (int i = _length, j = _offset + _length; --i >= 0;) {
- if (_array[--j] != str.charAt(i))
- return false;
- }
- return true;
- }
-
- /**
- * Compares this character array with the specified character
- * sequence lexicographically.
- *
- * @param seq the character sequence to be compared.
- * @return <code>{@link Equalities#LEXICAL}.compare(this, seq)</code>
- * @throws ClassCastException if the specifed object is not a
- * <code>CharSequence</code>.
- */
- public int compareTo(CharSequence seq) {
- return Equalities.LEXICAL.compare(this, seq);
- }
-
- /**
- * Returns the <code>boolean</code> represented by this character array.
- *
- * @return the corresponding <code>boolean</code> value.
- * @throws NumberFormatException if this character sequence
- * does not contain a parsable <code>boolean</code>.
- */
- public boolean toBoolean() {
- return TypeFormat.parseBoolean(this);
- }
-
- /**
- * Returns the decimal <code>int</code> represented by this character array.
- *
- * @return <code>toInt(10)</code>
- * @throws NumberFormatException if this character sequence
- * does not contain a parsable <code>int</code>.
- */
- public int toInt() {
- return TypeFormat.parseInt(this);
- }
-
- /**
- * Returns the <code>int</code> represented by this character array
- * in the specified radix.
- *
- * @param radix the radix (e.g. <code>16</code> for hexadecimal).
- * @return the corresponding <code>int</code> value.
- * @throws NumberFormatException if this character sequence
- * does not contain a parsable <code>int</code>.
- */
- public int toInt(int radix) {
- return TypeFormat.parseInt(this, radix);
- }
-
- /**
- * Returns the decimal <code>long</code> represented by this character
- * array.
- *
- * @return the corresponding <code>long</code> value.
- * @throws NumberFormatException if this character sequence
- * does not contain a parsable <code>long</code>.
- */
- public long toLong() {
- return TypeFormat.parseLong(this);
- }
-
- /**
- * Returns the decimal <code>long</code> represented by this character
- * array in the specified radix.
- *
- * @param radix the radix (e.g. <code>16</code> for hexadecimal).
- * @return the corresponding <code>long</code> value.
- * @throws NumberFormatException if this character sequence
- * does not contain a parsable <code>long</code>.
- */
- public long toLong(int radix) {
- return TypeFormat.parseLong(this, radix);
- }
-
- /**
- * Returns the <code>float</code> represented by this character array.
- *
- * @return the corresponding <code>float</code> value.
- * @return <code>TypeFormat.parseFloat(this)</code>
- * @throws NumberFormatException if this character sequence
- * does not contain a parsable <code>float</code>.
- */
- public float toFloat() {
- return TypeFormat.parseFloat(this);
- }
-
- /**
- * Returns the <code>double</code> represented by this character array.
- *
- * @return the corresponding <code>double</code> value.
- * @throws NumberFormatException if this character sequence
- * does not contain a parsable <code>double</code>.
- */
- public double toDouble() {
- return TypeFormat.parseDouble(this);
- }
-
- // Implements CharSequence
- public char charAt(int index) {
- if ((index < 0) || (index >= _length))
- throw new IndexOutOfBoundsException("index: " + index);
- return _array[_offset + index];
- }
-
- // Implements CharSequence
- public java.lang.CharSequence subSequence(int start, int end) {
- if ((start < 0) || (end < 0) || (start > end) || (end > this.length()))
- throw new IndexOutOfBoundsException();
- CharArray chars = new CharArray();
- chars._array = _array;
- chars._offset = _offset + start;
- chars._length = end - start;
- return chars;
- }
-
- // Implements CharSequence
- public void getChars(int start, int end, char dest[], int destPos) {
- if ((start < 0) || (end < 0) || (start > end) || (end > _length))
- throw new IndexOutOfBoundsException();
- System.arraycopy(_array, start + _offset, dest, destPos, end - start);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/CharSet.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/CharSet.java b/commons/marmotta-commons/src/ext/java/javolution/text/CharSet.java
deleted file mode 100644
index 414d758..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/CharSet.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import javolution.lang.Immutable;
-import javolution.lang.MathLib;
-
-/**
- * <p> A set of characters (typically used for parsing purpose where it is
- * significantly faster than regular expressions for simple patterns).
- * For example:
- * [code]
- * // Integration with Text.
- * Text number;
- * int exponentIndex = num.indexOfAny(CharSet.valueOf('e', 'E'));
- *
- * // Integration with TextFormat.
- * public List<Integer> parse(CharSequence csq, Cursor cursor) {
- * FastTable<Integer> numbers = FastTable.newInstance();
- * while (cursor.skip(CharSet.WHITESPACES, csq)) {
- * numbers.add(TypeFormat.parseInt(csq, cursor));
- * }
- * return numbers;
- * } [/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 3.7, January 1, 2006
- */
-public final class CharSet implements Immutable<CharSet> {
-
- /**
- * Represents an empty character set.
- */
- public static final CharSet EMPTY = new CharSet(new long[0]);
-
- /**
- * Represents white spaces characters according to Java
- * (see {@link Character#isWhitespace(char)}).
- */
- public static final CharSet WHITESPACES = CharSet.valueOf(new char[] { 0x9,
- 0xA, 0xB, 0xC, 0xD, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x1680, 0x180E,
- 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2008,
- 0x2009, 0x200A, 0x200B, 0x2028, 0x2029, 0x205F, 0x3000 });
-
- /**
- * Represents spaces characters according to Java
- * (see {@link Character#isSpaceChar(char)}).
- */
- public static final CharSet SPACES = CharSet.valueOf(new char[] { 0x20,
- 0xA0, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004,
- 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x200B, 0x2028,
- 0x2029, 0x202F, 0x205F, 0x3000 });
-
- /**
- * Represents ISO control characters according to Java
- * (see {@link Character#isISOControl(char)}).
- */
- public static final CharSet ISO_CONTROLS = CharSet.valueOf(new char[] {
- 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC,
- 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x7F, 0x80, 0x81,
- 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C,
- 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
- 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F });
-
- /**
- * Holds the containment mapping.
- */
- private final long[] _mapping;
-
- /**
- * Creates a character set with the specified mapping.
- *
- * @param mapping the character set mapping.
- */
- private CharSet(long[] mapping) {
- _mapping = mapping;
- }
-
- /**
- * Returns the character set holding the specified characters.
- *
- * @param chars the characters contained by this character set.
- * @return the corresponding character set.
- */
- public static CharSet valueOf(char... chars) {
- int maxChar = 0;
- for (int i = chars.length; --i >= 0;) {
- if (chars[i] > maxChar) {
- maxChar = chars[i];
- }
- }
- CharSet charSet = new CharSet(new long[(maxChar >> 6) + 1]);
- for (int i = chars.length; --i >= 0;) {
- char c = chars[i];
- charSet._mapping[c >> 6] |= 1L << (c & 63);
- }
- return charSet;
- }
-
- /**
- * Returns the character set holding the characters in the specified
- * range.
- *
- * @param first the first character.
- * @param last the last character.
- * @return the corresponding character set.
- * @throws IllegalArgumentException if <code>first > last</code>
- */
- public static CharSet rangeOf(char first, char last) {
- if (first > last)
- throw new IllegalArgumentException(
- "first should be less or equal to last");
- CharSet charSet = new CharSet(new long[(last >> 6) + 1]);
- for (char c = first; c <= last; c++) {
- charSet._mapping[c >> 6] |= 1L << (c & 63);
- }
- return charSet;
-
- }
-
- /**
- * Indicates if the specified character is contained by this character set.
- *
- * @param c the character to test.
- * @return <code>true</code> if this character set contains the specified
- * character; <code>false</code> otherwise.
- */
- public boolean contains(char c) {
- final int i = c >> 6;
- return i < _mapping.length ? (_mapping[i] & (1L << (c & 63))) != 0
- : false;
- }
-
- /**
- * Equivalent to
- * {@link #indexIn(java.lang.CharSequence, int) indexIn(csq, 0)}
- *
- * @param csq the character sequence to be searched.
- * @return the index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int indexIn(CharSequence csq) {
- return indexIn(csq, 0);
- }
-
- /**
- * Returns the first index in the specified character sequence of
- * one of the character of this set.
- *
- * @param csq the character sequence to be searched.
- * @param fromIndex the index to search from.
- * @return the index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int indexIn(CharSequence csq, int fromIndex) {
- for (int i = fromIndex, n = csq.length(); i < n; i++) {
- if (contains(csq.charAt(i)))
- return i;
- }
- return -1;
- }
-
- /**
- * Equivalent to {@link #indexIn(char[], int) indexIn(chars, 0)}
- *
- * @return the index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int indexIn(char[] chars) {
- return indexIn(chars, 0);
- }
-
- /**
- * Returns the first index in the specified character array of
- * one of the character of this set.
- *
- * @param chars the character array to be searched.
- * @param fromIndex the index to search from.
- * @return the index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int indexIn(char[] chars, int fromIndex) {
- for (int i = fromIndex, n = chars.length; i < n; i++) {
- if (contains(chars[i]))
- return i;
- }
- return -1;
- }
-
- /**
- * Equivalent to
- * {@link #lastIndexIn(java.lang.CharSequence, int)
- * lastIndexIn(csq, csq.length()-1)}
- *
- * @param csq the character sequence to be searched.
- * @return the last index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int lastIndexIn(CharSequence csq) {
- return lastIndexIn(csq, csq.length() - 1);
- }
-
- /**
- * Returns the last index in the specified character sequence of
- * one of the character of this set.
- *
- * @param csq the character sequence to be searched.
- * @param fromIndex the index to search from (backward).
- * @return the index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int lastIndexIn(CharSequence csq, int fromIndex) {
- for (int i = fromIndex; i >= 0; --i) {
- if (contains(csq.charAt(i)))
- return i;
- }
- return -1;
- }
-
- /**
- * Equivalent to {@link #lastIndexIn(char[], int)
- * lastIndexIn(chars, chars.length-1)}
- *
- * @return the index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int lastIndexIn(char[] chars) {
- return lastIndexIn(chars, chars.length - 1);
- }
-
- /**
- * Returns the last index in the specified character array of
- * one of the character of this set.
- *
- * @param chars the character array to be searched.
- * @param fromIndex the index to search from (backward).
- * @return the index in the specified character sequence or
- * <code>-1</code> if none found.
- */
- public int lastIndexIn(char[] chars, int fromIndex) {
- for (int i = fromIndex; i >= 0; i--) {
- if (contains(chars[i]))
- return i;
- }
- return -1;
- }
-
- /**
- * Returns the character set containing the characters from this
- * character set plus the characters from the character set specified.
- *
- * @param that the set containing the characters to be added.
- * @return <code>this + that</code>
- */
- public CharSet plus(CharSet that) {
- if (that._mapping.length > this._mapping.length)
- return that.plus(this);
- CharSet result = this.copy();
- for (int i = that._mapping.length; --i >= 0;) {
- result._mapping[i] |= that._mapping[i];
- }
- return result;
- }
-
- /**
- * Returns the character set containing the characters from this
- * character minus the characters from the character set specified.
- *
- * @param that the set containing the character to be removed.
- * @return <code>this - that</code>
- */
- public CharSet minus(CharSet that) {
- CharSet result = this.copy();
- for (int i = MathLib.min(this._mapping.length, that._mapping.length); --i >= 0;) {
- result._mapping[i] &= ~that._mapping[i];
- }
- return result;
- }
-
- /**
- * Returns the textual representation of this character set.
- *
- * @return the textual representation.
- */
- @Override
- public String toString() {
- TextBuilder tb = new TextBuilder();
- tb.append('{');
- int length = _mapping.length << 6;
- for (int i = 0; i < length; i++) {
- if (this.contains((char) i)) {
- if (tb.length() > 1) {
- tb.append(',');
- tb.append(' ');
- }
- tb.append('\'');
- tb.append((char) i);
- tb.append('\'');
- }
- }
- tb.append('}');
- return tb.toString();
- }
-
- /**
- * Returns a copy of this character set.
- */
- private CharSet copy() {
- CharSet charSet = new CharSet(new long[this._mapping.length]);
- for (int i = _mapping.length; --i >= 0;) {
- charSet._mapping[i] = _mapping[i];
- }
- return charSet;
- }
-
- @Override
- public CharSet value() {
- return this;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/Cursor.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/Cursor.java b/commons/marmotta-commons/src/ext/java/javolution/text/Cursor.java
deleted file mode 100644
index b27a9b4..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/Cursor.java
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-/**
- * <p> A parsing cursor over the characters read. Cursor
- * allows for token iterations over any {@link CharSequence}.
- * [code]
- * String str = "this is a test";
- * Cursor cursor = new Cursor();
- * for (CharSequence token; (token=cursor.nextToken(str, ' '))!= null;)
- * System.out.println(token);
- * [/code]
- * Prints the following output:<pre>
- * this
- * is
- * a
- * test</pre>
- * Cursors are typically used with {@link TextFormat} instances.
- * [code]
- * // Parses decimal number (e.g. "xxx.xxxxxExx" or "NaN")
- * public Decimal parse(CharSequence csq, Cursor cursor) throws IllegalArgumentException {
- * TextFormat<LargeInteger> largeIntegerFormat = TextContext.getFormat(LargeInteger.class);
- * if (cursor.skip("NaN", csq))
- * return Decimal.NaN;
- * LargeInteger significand = LargeIntegerFormat.parse(csq, cursor);
- * LargeInteger fraction = cursor.skip('.', csq) ? largeIntegerFormat.parse(csq, cursor) : LargeInteger.ZERO;
- * int exponent = cursor.skip(CharSet.valueOf('E', 'e'), csq) ? TypeFormat.parseInt(csq, cursor) : 0;
- * int fractionDigits = fraction.digitLength();
- * return Decimal.valueOf(significand.E(fractionDigits).plus(fraction), exponent - fractionDigits);
- * }
- * [/code]
- * </p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.4, November 19, 2009
- */
-public class Cursor {
-
- /**
- * Holds the index.
- */
- private int index;
-
- /**
- * Default constructor.
- */
- public Cursor() {}
-
- /**
- * Returns this cursor index.
- *
- * @return the index of the next character to parse.
- */
- public final int getIndex() {
- return index;
- }
-
- /**
- * Sets the cursor current index.
- *
- * @param i the index of the next character to parse.
- */
- public final void setIndex(int i) {
- index = i;
- }
-
- /**
- * Indicates if this cursor points to the end of the specified
- * character sequence.
- *
- * @param csq the character sequence iterated by this cursor.
- * @return <code>getIndex() >= csq.length()</code>
- */
- public final boolean atEnd(CharSequence csq) {
- return index >= csq.length();
- }
-
- /**
- * Indicates if this cursor points to the specified character in the
- * specified character sequence.
- *
- * @param c the character to test.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>csq.charAt(this.getIndex()) == c</code>
- */
- public final boolean at(char c, CharSequence csq) {
- return index < csq.length() ? csq.charAt(index) == c : false;
- }
-
- /**
- * Indicates if this cursor points to any of the specified character in the
- * specified character sequence.
- *
- * @param charSet any of the character to test.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>csq.charAt(this.getIndex()) == c</code>
- */
- public final boolean at(CharSet charSet, CharSequence csq) {
- return index < csq.length() ? charSet.contains(csq.charAt(index))
- : false;
- }
-
- /**
- * Indicates if this cursor points to the specified characters in the
- * specified sequence.
- *
- * @param str the characters to test.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>true</code> if this cursor points to the specified
- * characters; <code>false</code> otherwise.
- */
- public final boolean at(String str, CharSequence csq) {
- int i = index;
- int length = csq.length();
- for (int j = 0; j < str.length();) {
- if ((i >= length) || (str.charAt(j++) != csq.charAt(i++)))
- return false;
- }
- return true;
- }
-
- /**
- * Returns the current character at this cursor position.
- *
- * @param csq the character sequence iterated by this cursor.
- * @return the current character this cursor points to.
- * @throws IndexOutOfBoundsException if {@link #atEnd this.atEnd(csq)}
- */
- public final char currentChar(CharSequence csq) {
- return csq.charAt(index);
- }
-
- /**
- * Returns the next character at this cursor position.The cursor
- * position is incremented by one.
- *
- * @param csq the character sequence iterated by this cursor.
- * @return the next character this cursor points to.
- * @throws IndexOutOfBoundsException if {@link #atEnd this.atEnd(csq)}
- */
- public final char nextChar(CharSequence csq) {
- return csq.charAt(index++);
- }
-
- /**
- * Moves this cursor forward until it points to a character
- * different from the specified character.
- *
- * @param c the character to skip.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>true</code> if this cursor has skipped at least one
- * character;<code>false</code> otherwise (e.g. end of sequence
- * reached).
- */
- public final boolean skipAny(char c, CharSequence csq) {
- int i = index;
- int n = csq.length();
- for (; (i < n) && (csq.charAt(i) == c); i++) {}
- if (i == index)
- return false; // Cursor did not moved.
- index = i;
- return true;
- }
-
- /**
- * Moves this cursor forward until it points to a character
- * different from any of the character in the specified set.
- * For example: [code]
- * // Reads numbers separated by tabulations or spaces.
- * FastTable<Integer> numbers = new FastTable<Integer>();
- * while (cursor.skipAny(CharSet.SPACE_OR_TAB, csq)) {
- * numbers.add(TypeFormat.parseInt(csq, cursor));
- * }[/code]
- *
- * @param charSet the character to skip.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>true</code> if this cursor has skipped at least one
- * character;<code>false</code> otherwise (e.g. end of sequence
- * reached).
- */
- public final boolean skipAny(CharSet charSet, CharSequence csq) {
- int i = index;
- int n = csq.length();
- for (; (i < n) && charSet.contains(csq.charAt(i)); i++) {}
- if (i == index)
- return false; // Cursor did not moved.
- index = i;
- return true;
- }
-
- /**
- * Moves this cursor forward only if at the specified character.
- * This method is equivalent to:
- * [code]
- * if (at(c, csq))
- * increment();
- * [/code]
- *
- * @param c the character to skip.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>true</code> if this cursor has skipped the specified
- * character;<code>false</code> otherwise.
- */
- public final boolean skip(char c, CharSequence csq) {
- if (this.at(c, csq)) {
- index++;
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Moves this cursor forward only if at any of the specified character.
- * This method is equivalent to:
- * [code]
- * if (at(charSet, csq))
- * increment();
- * [/code]
- *
- * @param charSet holding the characters to skip.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>true</code> if this cursor has skipped any the specified
- * character;<code>false</code> otherwise.
- */
- public final boolean skip(CharSet charSet, CharSequence csq) {
- if (this.at(charSet, csq)) {
- index++;
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Moves this cursor forward only if at the specified string.
- * This method is equivalent to:
- * [code]
- * if (at(str, csq))
- * increment(str.length());
- * [/code]
- *
- * @param str the string to skip.
- * @param csq the character sequence iterated by this cursor.
- * @return <code>true</code> if this cursor has skipped the specified
- * string;<code>false</code> otherwise (e.g. end of sequence
- * reached).
- */
- public final boolean skip(String str, CharSequence csq) {
- if (this.at(str, csq)) {
- index += str.length();
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Returns the subsequence from the specified cursor position not holding
- * the specified character. For example:[code]
- * CharSequence csq = "This is a test";
- * for (CharSequence token; (token=cursor.nextToken(csq, ' '))!= null;) {
- * System.out.println(token); // Prints one word at a time.
- * }[/code]
- *
- * @param csq the character sequence iterated by this cursor.
- * @param c the character being skipped.
- * @return the subsequence not holding the specified character or
- * <code>null</code> if none.
- */
- public final CharSequence nextToken(CharSequence csq, char c) {
- int n = csq.length();
- for (int i = index; i < n; i++) {
- if (csq.charAt(i) != c) {
- int j = i;
- for (; (++j < n) && (csq.charAt(j) != c);) {
- // Loop until j at the end of sequence or at specified character.
- }
- index = j;
- return csq.subSequence(i, j);
- }
- }
- index = n;
- return null;
- }
-
- /**
- * Returns the subsequence from the specified cursor position not holding
- * any of the characters specified. For example:[code]
- * CharSequence csq = "This is a test";
- * for (CharSequence token; (token=cursor.nextToken(csq, CharSet.WHITESPACE))!= null;) {
- * System.out.println(token); // Prints one word at a time.
- * }[/code]
- *
- * @param csq the character sequence iterated by this cursor.
- * @param charSet the characters being skipped.
- * @return the subsequence not holding the specified character or
- * <code>null</code> if none.
- */
- public final CharSequence nextToken(CharSequence csq, CharSet charSet) {
- int n = csq.length();
- for (int i = index; i < n; i++) {
- if (!charSet.contains(csq.charAt(i))) {
- int j = i;
- for (; (++j < n) && !charSet.contains(csq.charAt(j));) {
- // Loop until j at the end of sequence or at specified characters.
- }
- index = j;
- return csq.subSequence(i, j);
- }
- }
- index = n;
- return null;
- }
-
- /**
- * Returns the head of the specified character sequence until
- * this cursor position.
- *
- * @return the corresponding sub-sequence.
- */
- public final CharSequence head(CharSequence csq) {
- return csq.subSequence(0, index);
- }
-
- /**
- * Returns the tail of the specified character sequence starting at
- * this cursor position.
- *
- * @return the corresponding sub-sequence.
- */
- public final CharSequence tail(CharSequence csq) {
- return csq.subSequence(index, csq.length());
- }
-
- /**
- * Increments the cursor index by one.
- *
- * @return <code>this</code>
- */
- public final Cursor increment() {
- return increment(1);
- }
-
- /**
- * Increments the cursor index by the specified value.
- *
- * @param i the increment value.
- * @return <code>this</code>
- */
- public final Cursor increment(int i) {
- index += i;
- return this;
- }
-
- /**
- * Returns the string representation of this cursor.
- *
- * @return the index value as a string.
- */
- @Override
- public String toString() {
- return "Cursor: " + index;
- }
-
- /**
- * Indicates if this cursor is equals to the specified object.
- *
- * @return <code>true</code> if the specified object is a cursor
- * at the same index; <code>false</code> otherwise.
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == null)
- return false;
- if (!(obj instanceof Cursor))
- return false;
- return index == ((Cursor) obj).index;
- }
-
- /**
- * Returns the hash code for this cursor.
- *
- * @return the hash code value for this object
- */
- @Override
- public int hashCode() {
- return index;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/DefaultTextFormat.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/DefaultTextFormat.java b/commons/marmotta-commons/src/ext/java/javolution/text/DefaultTextFormat.java
deleted file mode 100644
index 98cdc87..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/DefaultTextFormat.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-/**
- * <p> Specifies the default text format of a class (for parsing/formatting).
- * The default format is typically used by the {@link Object#toString()}
- * method and can be locally overridden in the scope of a
- * {@link javolution.text.TextContext TextContext}.</p>
- *
- * [code]
- * @DefaultTextFormat(Complex.Cartesian.class)
- * public class Complex {
- * public String toString() { // Uses the default format unless locally overridden.
- * return TextContext.toString(this);
- * }
- * public static Complex valueOf(CharSequence csq) {
- * return TextContext.parse(csq, Complex.class);
- * }
- * public static class Cartesian extends TextFormat<Complex> { ... }
- * public static class Polar extends TextFormat<Complex> { ... }
- * }
- * ...
- * TextContext ctx = TextContext.enter(); // Enters a local textual context.
- * try {
- * ctx.setFormat(Complex.class, new Complex.Polar()); // Configure the local context.
- * System.out.println(complexMatrix); // Displays complex numbers in polar coordinates.
- * } finally {
- * ctx.exit(); // Exits local context (reverts to previous Cartesian format).
- * }[/code]
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-@Documented
-@Inherited
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface DefaultTextFormat {
-
- /**
- * Returns the default text format of the annotated class.
- */
- Class<? extends TextFormat<?>> value();
-
-}
[13/15] git commit: cut down the included source code from javolution
(no more OSGi dependencies) and updated NOTICE and LICENSE files in source
root
Posted by ss...@apache.org.
cut down the included source code from javolution (no more OSGi dependencies) and updated NOTICE and LICENSE files in source root
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/e60b1a9a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/e60b1a9a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/e60b1a9a
Branch: refs/heads/develop
Commit: e60b1a9aef62e6d1dc3b49270de6e481c092bac8
Parents: 8253fe5
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Sep 9 13:12:41 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Sep 9 13:12:41 2013 +0200
----------------------------------------------------------------------
LICENSE.txt | 30 +
NOTICE.txt | 5 +
commons/marmotta-commons/pom.xml | 12 -
.../java/javolution/util/FastTableTest.java | 331 ----
.../javolution/context/AbstractContext.java | 178 --
.../javolution/context/ConcurrentContext.java | 258 ---
.../java/javolution/context/FormatContext.java | 39 -
.../java/javolution/context/LocalContext.java | 125 --
.../ext/java/javolution/context/LogContext.java | 157 --
.../javolution/context/SecurityContext.java | 256 ---
.../java/javolution/context/StorageContext.java | 125 --
.../context/internal/ConcurrentContextImpl.java | 120 --
.../context/internal/ConcurrentThreadImpl.java | 74 -
.../context/internal/LocalContextImpl.java | 44 -
.../context/internal/LogContextImpl.java | 91 -
.../context/internal/SecurityContextImpl.java | 61 -
.../context/internal/StorageContextImpl.java | 87 -
.../java/javolution/context/package-info.java | 103 --
.../java/javolution/io/AppendableWriter.java | 163 --
.../java/javolution/io/CharSequenceReader.java | 156 --
.../src/ext/java/javolution/io/Struct.java | 1749 ------------------
.../javolution/io/UTF8ByteBufferReader.java | 267 ---
.../javolution/io/UTF8ByteBufferWriter.java | 224 ---
.../java/javolution/io/UTF8StreamReader.java | 316 ----
.../java/javolution/io/UTF8StreamWriter.java | 338 ----
.../src/ext/java/javolution/io/Union.java | 54 -
.../ext/java/javolution/io/package-info.java | 7 -
.../ext/java/javolution/lang/Configurable.java | 283 ---
.../ext/java/javolution/lang/Initializer.java | 149 --
.../java/javolution/lang/Parallelizable.java | 7 +-
.../src/ext/java/javolution/lang/Realtime.java | 7 +-
.../osgi/internal/ConfigurableListenerImpl.java | 32 -
.../osgi/internal/JavolutionActivator.java | 75 -
.../osgi/internal/LogServiceImpl.java | 115 --
.../javolution/osgi/internal/OSGiServices.java | 150 --
.../osgi/internal/ServiceTrackerImpl.java | 62 -
.../osgi/internal/XMLInputFactoryProvider.java | 34 -
.../osgi/internal/XMLOutputFactoryProvider.java | 34 -
.../ext/java/javolution/test/Perfometer.java | 271 ---
.../ext/java/javolution/test/package-info.java | 5 -
.../src/ext/java/javolution/text/CharArray.java | 393 ----
.../src/ext/java/javolution/text/CharSet.java | 327 ----
.../src/ext/java/javolution/text/Cursor.java | 397 ----
.../java/javolution/text/DefaultTextFormat.java | 60 -
.../src/ext/java/javolution/text/Text.java | 1333 -------------
.../ext/java/javolution/text/TextBuilder.java | 888 ---------
.../ext/java/javolution/text/TextContext.java | 93 -
.../ext/java/javolution/text/TextFormat.java | 125 --
.../ext/java/javolution/text/TypeFormat.java | 732 --------
.../text/internal/TextContextImpl.java | 345 ----
.../ext/java/javolution/text/package-info.java | 67 -
.../ext/java/javolution/util/FastBitSet.java | 361 ----
.../java/javolution/util/FastCollection.java | 119 +-
.../src/ext/java/javolution/util/FastMap.java | 40 +-
.../src/ext/java/javolution/util/FastSet.java | 8 +-
.../ext/java/javolution/util/FastSortedMap.java | 10 +-
.../ext/java/javolution/util/FastSortedSet.java | 8 +-
.../java/javolution/util/FastSortedTable.java | 3 +-
.../src/ext/java/javolution/util/FastTable.java | 25 +-
.../src/ext/java/javolution/util/Index.java | 262 ---
.../javolution/util/function/Equalities.java | 7 +-
.../java/javolution/util/function/Reducers.java | 8 +-
.../internal/bitset/BitSetIteratorImpl.java | 51 -
.../util/internal/bitset/BitSetServiceImpl.java | 373 ----
.../collection/AtomicCollectionImpl.java | 6 +-
.../internal/collection/CollectionView.java | 10 +-
.../collection/DistinctCollectionImpl.java | 4 +-
.../collection/FilteredCollectionImpl.java | 4 +-
.../collection/MappedCollectionImpl.java | 4 +-
.../collection/ParallelCollectionImpl.java | 120 --
.../collection/ReversedCollectionImpl.java | 4 +-
.../collection/SequentialCollectionImpl.java | 4 +-
.../collection/SharedCollectionImpl.java | 6 +-
.../collection/SortedCollectionImpl.java | 6 +-
.../collection/UnmodifiableCollectionImpl.java | 4 +-
.../comparator/WrapperComparatorImpl.java | 4 +-
.../util/internal/map/AtomicMapImpl.java | 6 +-
.../util/internal/map/FastMapImpl.java | 4 +-
.../javolution/util/internal/map/MapView.java | 8 +-
.../util/internal/map/ParallelMapImpl.java | 130 --
.../util/internal/map/SequentialMapImpl.java | 4 +-
.../util/internal/map/SharedMapImpl.java | 6 +-
.../util/internal/map/UnmodifiableMapImpl.java | 4 +-
.../map/sorted/AtomicSortedMapImpl.java | 6 +-
.../internal/map/sorted/FastSortedMapImpl.java | 4 +-
.../map/sorted/SharedSortedMapImpl.java | 6 +-
.../util/internal/map/sorted/SortedMapView.java | 6 +-
.../internal/map/sorted/SubSortedMapImpl.java | 6 +-
.../map/sorted/UnmodifiableSortedMapImpl.java | 6 +-
.../internal/set/sorted/SubSortedSetImpl.java | 6 +-
.../util/internal/table/AtomicTableImpl.java | 6 +-
.../util/internal/table/FastTableImpl.java | 4 +-
.../util/internal/table/QuickSort.java | 4 +-
.../util/internal/table/SharedTableImpl.java | 8 +-
.../util/internal/table/TableIteratorImpl.java | 4 +-
.../util/internal/table/TableView.java | 8 +-
.../javolution/util/service/BitSetService.java | 116 --
.../util/service/CollectionService.java | 6 +-
.../javolution/util/service/MapService.java | 6 +-
.../javolution/util/service/TableService.java | 2 +-
.../java/javolution/xml/DefaultXMLFormat.java | 59 -
.../src/ext/java/javolution/xml/QName.java | 233 ---
.../src/ext/java/javolution/xml/XMLBinding.java | 298 ---
.../src/ext/java/javolution/xml/XMLContext.java | 74 -
.../src/ext/java/javolution/xml/XMLFormat.java | 1029 -----------
.../java/javolution/xml/XMLObjectReader.java | 291 ---
.../java/javolution/xml/XMLObjectWriter.java | 311 ----
.../javolution/xml/XMLReferenceResolver.java | 206 ---
.../java/javolution/xml/XMLSerializable.java | 47 -
.../javolution/xml/doc-files/xmlDataBinding.png | Bin 15305 -> 0 bytes
.../javolution/xml/internal/XMLContextImpl.java | 151 --
.../xml/internal/stream/AttributesImpl.java | 170 --
.../xml/internal/stream/EntitiesImpl.java | 155 --
.../xml/internal/stream/NamespacesImpl.java | 276 ---
.../internal/stream/XMLInputFactoryImpl.java | 106 --
.../internal/stream/XMLOutputFactoryImpl.java | 151 --
.../internal/stream/XMLStreamReaderImpl.java | 1523 ---------------
.../internal/stream/XMLStreamWriterImpl.java | 939 ----------
.../ext/java/javolution/xml/package-info.java | 346 ----
.../ext/java/javolution/xml/sax/Attributes.java | 178 --
.../java/javolution/xml/sax/ContentHandler.java | 144 --
.../java/javolution/xml/sax/DefaultHandler.java | 116 --
.../java/javolution/xml/sax/SAX2ReaderImpl.java | 386 ----
.../ext/java/javolution/xml/sax/XMLReader.java | 346 ----
.../java/javolution/xml/sax/XMLReaderImpl.java | 363 ----
.../java/javolution/xml/sax/package-info.java | 8 -
.../java/javolution/xml/stream/Location.java | 56 -
.../javolution/xml/stream/NamespaceContext.java | 55 -
.../javolution/xml/stream/XMLInputFactory.java | 150 --
.../javolution/xml/stream/XMLOutputFactory.java | 169 --
.../xml/stream/XMLStreamConstants.java | 98 -
.../xml/stream/XMLStreamException.java | 128 --
.../javolution/xml/stream/XMLStreamReader.java | 604 ------
.../javolution/xml/stream/XMLStreamWriter.java | 365 ----
.../javolution/xml/stream/package-info.java | 17 -
.../javolution/xml/ws/WebServiceClient.java | 223 ---
.../java/javolution/xml/ws/package-info.java | 5 -
.../kiwi/persistence/KiWiConnection.java | 1 +
138 files changed, 180 insertions(+), 22768 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/LICENSE.txt
----------------------------------------------------------------------
diff --git a/LICENSE.txt b/LICENSE.txt
index 0205189..f9de3d8 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -599,6 +599,36 @@ For the JSONLD-Java component,
THE POSSIBILITY OF SUCH DAMAGE.
+For the marmotta-commons component,
+
+ located at commons/marmotta-commons/src/ext/java
+
+ Javolution - Java(tm) Solution for Real-Time and Embedded Systems
+ Copyright (c) 2012, Javolution (http://javolution.org/)
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
Apache Marmotta 3rd party data files:
====================================
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/NOTICE.txt
----------------------------------------------------------------------
diff --git a/NOTICE.txt b/NOTICE.txt
index f092f22..4c9d58f 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -115,6 +115,11 @@ The SwingBits library is copyright (C) 2006 Michael Hjembaek, and licensed
under a New BSD License. The source code is available at
http://swingbits.sourceforge.net/
+The module commons/marmotta-commons contains a modified and reduced version
+of the javolution library. Javolution has copyright (c) 2012, Javolution and
+ is licensed under BSD license. The original source code is available at
+http://javolution.org/
+
The module commons/sesame-tools-rio-rss contains source code from the
orphaned ROME project. ROME has copyright 2004 Sun Microsystems, Inc.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/pom.xml
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/pom.xml b/commons/marmotta-commons/pom.xml
index 890d36a..a672ec2 100644
--- a/commons/marmotta-commons/pom.xml
+++ b/commons/marmotta-commons/pom.xml
@@ -140,18 +140,6 @@
</dependency>
-->
- <!-- OSGi dependencies for Javolution -->
- <dependency> <!-- OSGI Core Library -->
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>4.3.1</version>
- </dependency>
- <dependency> <!-- OSGI Compendium (log service) -->
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>4.3.1</version>
- </dependency>
-
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java b/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java
deleted file mode 100644
index bee5ca0..0000000
--- a/commons/marmotta-commons/src/ext-test/java/javolution/util/FastTableTest.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util;
-
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Random;
-
-import javolution.context.LogContext;
-import javolution.osgi.internal.OSGiServices;
-import javolution.test.Perfometer;
-
-/**
- * Validation and performance tests of FastTable.
- */
-public class FastTableTest {
-
- static final boolean INITIALIZE_REALTIME_CLASSES = OSGiServices
- .initializeRealtimeClasses();
-
- @SuppressWarnings("rawtypes")
- Perfometer<Class<? extends List>> addPerf = new Perfometer<Class<? extends List>>(
- "java.util.List#add(Object)") {
- List<Object> list;
-
- @SuppressWarnings("unchecked")
- public void initialize() throws Exception {
- list = getInput().newInstance();
- }
-
- protected void run(boolean measure) {
- Object obj = new Object();
- if (measure) list.add(obj);
- }
- };
-
- @SuppressWarnings("rawtypes")
- Perfometer<Class<? extends List>> insertPerf = new Perfometer<Class<? extends List>>(
- "java.util.List#add(int, Object)") {
- List<Object> list;
- Random random;
-
- @SuppressWarnings("unchecked")
- public void initialize() throws Exception {
- list = getInput().newInstance();
- random = new Random(-1);
- }
-
- protected void run(boolean measure) {
- Object obj = new Object();
- int i = random.nextInt(list.size() + 1);
- if (measure) list.add(i, obj);
- }
-
- protected void validate() {
- assert list.size() == getNbrOfIterations();
- }
- };
-
- @SuppressWarnings("rawtypes")
- Perfometer<Class<? extends List>> newPerf = new Perfometer<Class<? extends List>>(
- "new java.util.List()") {
- Class<? extends List> cls;
-
- protected void initialize() throws Exception {
- cls = getInput();
- }
-
- protected void run(boolean measure) throws Exception {
- if (measure) cls.newInstance();
- }
- };
-
- @SuppressWarnings("rawtypes")
- Perfometer<Class<? extends List>> removePerf = new Perfometer<Class<? extends List>>(
- "java.util.List#remove(int)") {
- List<Object> list;
- Random random;
-
- @SuppressWarnings("unchecked")
- public void initialize() throws Exception {
- list = getInput().newInstance();
- random = new Random(-1);
- for (int i = 0; i < getNbrOfIterations(); i++) {
- list.add(new Object());
- }
- }
-
- protected void run(boolean measure) {
- int i = random.nextInt(list.size());
- if (measure) list.remove(i);
- }
-
- protected void validate() {
- assert list.size() == 0;
- }
- };
-
- private final long ONE_SECOND_IN_NS = 1000 * 1000 * 1000L;
- private Random random = new Random();
-
- public void testDequeuOperations() {
- Deque<Integer> ft = new FastTable<Integer>();
- Deque<Integer> ad = new ArrayDeque<Integer>();
- for (long start = System.nanoTime(), time = start; time < start + 2
- * ONE_SECOND_IN_NS; time = System.nanoTime()) {
- long seed = random.nextLong();
- Throwable found = anyDequeOperation(seed, ft);
- Throwable expected = anyDequeOperation(seed, ad);
- assertEquals(found, expected);
- assert areEquals(ad, ft) : found.getMessage() + "\nFound: " + ft
- + "\nExpected: " + ad;
- }
- LogContext.info("FastTable - Deque Operations Validated!");
- }
-
- public void testListOperations() {
- List<Integer> ft = new FastTable<Integer>();
- List<Integer> al = new ArrayList<Integer>();
- for (long start = System.nanoTime(), time = start; time < start + 2
- * ONE_SECOND_IN_NS; time = System.nanoTime()) {
- long seed = random.nextLong();
- Throwable found = anyListOperation(seed, ft);
- Throwable expected = anyListOperation(seed, al);
- assertEquals(found, expected);
- assert al.equals(ft) && ft.equals(al) : found.getMessage()
- + "\nFound: " + ft + "\nExpected: " + al;
- }
- LogContext.info("FastTable - List Operations Validated!");
- }
-
- public void testPerformance() {
- int N = 10000;
- newPerf.measure(ArrayList.class, 1).print();
- newPerf.measure(LinkedList.class, 1).print();
- newPerf.measure(FastTable.class, 1).print();
- addPerf.measure(ArrayList.class, N).print();
- addPerf.measure(LinkedList.class, N).print();
- addPerf.measure(FastTable.class, N).print();
- insertPerf.measure(ArrayList.class, N).print();
- insertPerf.measure(LinkedList.class, N).print();
- insertPerf.measure(FastTable.class, N).print();
- removePerf.measure(ArrayList.class, N).print();
- removePerf.measure(LinkedList.class, N).print();
- removePerf.measure(FastTable.class, N).print();
- }
-
- private Throwable anyDequeOperation(long seed, Deque<Integer> deque) {
- random.setSeed(seed);
- int operation = random.nextInt(20);
- String test = "N/A";
- try {
- switch (operation) {
- case 1: {
- test = "Test add(E)";
- deque.add(random.nextInt());
- break;
- }
- case 2: {
- test = "Test addFirst(E)";
- deque.addFirst(random.nextInt());
- break;
- }
- case 3: {
- test = "Test addLast(E)";
- deque.addLast(random.nextInt());
- break;
- }
- case 4: {
- test = "Test removeFirst(E)";
- deque.removeFirst();
- break;
- }
- case 5: {
- test = "Test removeLast(E)";
- deque.removeLast();
- break;
- }
- case 6: {
- test = "Test peekFirst/peekLast/element/pop/push/pollFirst/pollLast";
- deque.push(random.nextInt());
- deque.addFirst(deque.peekLast());
- deque.addLast(deque.peekFirst());
- deque.add(deque.element());
- deque.addFirst(deque.pop());
- deque.push(random.nextInt());
- deque.addLast(deque.pollFirst());
- deque.addFirst(deque.pollLast());
- break;
- }
- case 7: {
- test = "Test descendingIterator";
- int obj = random.nextInt();
- for (Iterator<Integer> i = deque.descendingIterator(); i
- .hasNext(); i.next()) {
- if (random.nextInt(deque.size()) == 0) obj = i.next();
- }
- deque.add(obj);
- break;
- }
- default:
- if (deque.size() > 100000) deque.clear();
- deque.add(random.nextInt());
- }
- } catch (Throwable error) {
- return error;
- }
- return new Throwable(test);
- }
-
- private Throwable anyListOperation(long seed, List<Integer> list) {
- random.setSeed(seed);
- int operation = random.nextInt(20);
- String test = "N/A";
- try {
- switch (operation) {
- case 1: {
- test = "Test add(int, E)";
- int i = random.nextInt(list.size() + 1);
- list.add(i, random.nextInt());
- break;
- }
- case 2: {
- test = "Test remove(int)";
- int i = random.nextInt(list.size());
- list.remove(i);
- break;
- }
- case 3: {
- test = "Test add(E)";
- list.add(random.nextInt());
- break;
- }
- case 4: {
- test = "Test contains(Object)";
- int r = random.nextInt();
- int i = random.nextInt(list.size() + 1);
- list.add(i, r);
- list.add(list.contains(r) ? 1 : 0);
- break;
- }
- case 5: {
- test = "Test indexOf/lastIndexOf";
- int r = random.nextInt();
- list.add(random.nextInt(list.size() + 1), r);
- list.add(random.nextInt(list.size() + 1), r);
- int first = list.indexOf(r);
- int last = list.lastIndexOf(r);
- list.add(first);
- list.add(last);
- break;
- }
- case 6: {
- test = "Test subList/addAll";
- int s = list.size();
- int i = random.nextInt(s);
- int j = random.nextInt(s);
- if (i > j) break; // ArrayList throw IllegalArgumentException instead of
- // IndexOutOfBoundsException (which is incorrect as per List.subList contract).
- list.addAll(list.subList(i, j));
- break;
- }
- case 7: {
- test = "Test subList/clear";
- int s = list.size();
- int i = random.nextInt(s);
- int j = random.nextInt(s);
- if (i > j) break;
- list.subList(i, j).clear();
- break;
- }
- case 8: {
- test = "Test subList/containsAll";
- int s = list.size();
- int i = random.nextInt(s);
- int j = random.nextInt(s);
- if (i > j) break;
- boolean containsAll = list.containsAll(list.subList(i, j));
- list.add(containsAll ? 1 : 0);
- break;
- }
- case 9: {
- test = "Test iterator";
- int j = 0;
- for (ListIterator<Integer> i = list.listIterator(); i
- .hasNext(); i.next()) {
- if (random.nextInt(list.size()) == 0) j = i.next();
- if (random.nextInt(list.size()) == 0) j = i.previous();
- if (random.nextInt(list.size()) == 0) i.remove();
- }
- list.add(j);
- break;
- }
- default:
- if (list.size() > 100000) list.clear();
- list.add(random.nextInt());
- }
- } catch (Throwable error) {
- return error;
- }
- return new Throwable(test);
- }
-
- private boolean areEquals(Deque<?> left, Deque<?> right) {
- if (left.size() != right.size()) return false;
- for (Iterator<?> il = left.iterator(), ir = right.iterator(); il
- .hasNext();) {
- if (!il.next().equals(ir.next())) return false;
- }
- return true;
- }
-
- private void assertEquals(Throwable found, Throwable expected) {
- if (found.getClass().equals(expected.getClass())) return;
- found.printStackTrace(System.err);
- expected.printStackTrace(System.err);
- assert false : "Exception mismatch found: " + found + ", expected: "
- + expected;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java
deleted file mode 100644
index 3258d53..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/AbstractContext.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context;
-
-import javolution.lang.Parallelizable;
-import javolution.context.SecurityContext.Permission;
-import javolution.lang.Realtime;
-
-/**
- * <p> The parent class for all contexts.
- * Contexts allow for cross cutting concerns (performance, logging,
- * security, ...) to be addressed at run-time through OSGi published
- * services without polluting the application code
- * (<a href="http://en.wikipedia.org/wiki/Separation_of_concerns">
- * Separation of Concerns</a>).</p>
- *
- * <p> Context configuration is performed in a {@code try, finally}
- * block statement and impacts only the current thread (although inherited
- * by inner {@link ConcurrentContext} threads).
- * [code]
- * AnyContext ctx = AnyContext.enter(); // Enters a context scope.
- * try {
- * ctx.configure(...); // Local configuration (optional).
- * ... // Current thread executes using the configured context.
- * } finally {
- * ctx.exit();
- * }[/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-@Realtime
-@Parallelizable(comment = "Sequential configuration, parallel use")
-public abstract class AbstractContext {
-
- /**
- * Holds the last context entered (thread-local).
- */
- private static final ThreadLocal<AbstractContext> CURRENT = new ThreadLocal<AbstractContext>();
-
- /**
- * Holds the outer context or {@code null} if none (top context).
- */
- private AbstractContext outer;
-
- /**
- * Default constructor.
- */
- protected AbstractContext() {}
-
- /**
- * Returns the current context for the current thread or {@code null}
- * if this thread has no context (default).
- */
- public static AbstractContext current() {
- return AbstractContext.CURRENT.get();
- }
-
- /**
- * Returns the current context of specified type or {@code null} if none.
- */
- @SuppressWarnings("unchecked")
- protected static <T extends AbstractContext> T current(Class<T> type) {
- AbstractContext ctx = AbstractContext.CURRENT.get();
- while (ctx != null) {
- if (type.isInstance(ctx))
- return (T) ctx;
- ctx = ctx.outer;
- }
- return null;
- }
-
- /**
- * <p> Enters the scope of a custom context. This method raises a
- * {@link SecurityException} if the permission to enter contexts of
- * the specified class is not granted. For example, the following
- * disallow entering any custom context.
- *[code]
- * SecurityContext ctx = SecurityContext.enter();
- * try {
- * ctx.revoke(new SecurityContext.Permission(AbstractContext.class, "enter"));
- * ... // Cannot enter any custom context.
- * } finally {
- * ctx.exit(); // Back to previous security settings.
- * }[/code]</p>
- *
- * @param custom the custom context to enter.
- * @throws IllegalArgumentException if the specified class default constructor
- * cannot be instantiated.
- * @throws SecurityException if {@code SecurityContext.Permission(custom, "enter")}
- * is not granted.
- * @see SecurityContext.Permission
- */
- @SuppressWarnings("unchecked")
- public static <T extends AbstractContext> T enter(Class<T> custom) {
- SecurityContext.check(new Permission<T>(custom, "enter"));
- try {
- return (T) custom.newInstance().enterInner();
- } catch (InstantiationException e) {
- throw new IllegalArgumentException(
- "Cannot instantiate instance of " + custom, e);
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException("Cannot access " + custom, e);
- }
- }
-
- /**
- * Inherits the specified context which becomes the context of the current
- * thread. This method is particularly useful when creating new threads to
- * make them inherits from the context stack of the parent thread.
- * [code]
- * //Spawns a new thread inheriting the context of the current thread.
- * MyThread myThread = new MyThread();
- * myThread.inherited = AbstractContext.current();
- * myThread.start();
- * ...
- * class MyThread extends Thread {
- * AbstractContext inherited;
- * public void run() {
- * AbstractContext.inherit(inherited); // Sets current context.
- * ...
- * }
- * }[/code]</p>
- */
- public static void inherit(AbstractContext ctx) {
- CURRENT.set(ctx);
- }
-
- /**
- * Enters the scope of an inner context which becomes the current context;
- * the previous current context becomes the outer of this context.
- *
- * @return the inner context entered.
- */
- protected AbstractContext enterInner() {
- AbstractContext inner = inner();
- inner.outer = AbstractContext.CURRENT.get();
- AbstractContext.CURRENT.set(inner);
- return inner;
- }
-
- /**
- * Exits the scope of this context; the outer of this context becomes
- * the current context.
- *
- * @throws IllegalStateException if this context is not the current
- * context.
- */
- public void exit() {
- if (this != AbstractContext.CURRENT.get())
- throw new IllegalStateException(
- "This context is not the current context");
- AbstractContext.CURRENT.set(outer);
- outer = null;
- }
-
- /**
- * Returns the outer context of this context or {@code null} if this
- * context has no outer context.
- */
- protected AbstractContext getOuter() {
- return outer;
- }
-
- /**
- * Returns a new inner instance of this context inheriting the properties
- * of this context. The new instance can be configured independently
- * from its parent.
- */
- protected abstract AbstractContext inner();
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java
deleted file mode 100644
index 8e1442a..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/ConcurrentContext.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context;
-
-import javolution.lang.Configurable;
-import javolution.lang.MathLib;
-import javolution.osgi.internal.OSGiServices;
-
-/**
- * <p> A context able to take advantage of concurrent algorithms on
- * multi-processors systems.</p>
- *
- * <p> When a thread enters a concurrent context, it may performs concurrent
- * executions by calling the {@link #execute(Runnable)} static method.
- * The logic is then executed by a concurrent thread or by the current
- * thread itself if there is no concurrent thread immediately available
- * (the number of concurrent threads is limited, see {@link #CONCURRENCY}).
- * [code]
- * ConcurrentContext ctx = ConcurrentContext.enter();
- * try {
- * ctx.execute(new Runnable() {...});
- * ctx.execute(new Runnable() {...});
- * } finally {
- * ctx.exit(); // Waits for all concurrent executions to complete.
- * // Re-exports any exception raised during concurrent executions.
- * }[/code]</p>
- *
- * <p> or equivalent shorter notation:
- * [code]
- * ConcurrentContext.execute(new Runnable() {...}, new Runnable() {...});[/code]</p>
- *
- * <p> Only after all concurrent executions are completed, is the current
- * thread allowed to exit the scope of the concurrent context
- * (internal synchronization).</p>
- *
- * <p> Concurrent logics always execute within the same {@link AbstractContext
- * context} as the calling thread.</p>
- *
- * <p> Concurrent contexts ensure the same behavior whether or not the execution
- * is performed by the current thread or a concurrent thread. Any error or
- * runtime exception raised during the concurrent logic executions is
- * propagated to the current thread.</p>
- *
- * <p> Concurrent contexts are easy to use, and provide automatic
- * load-balancing between processors with almost no overhead.
- * Here is a concurrent/recursive quick/merge sort using anonymous inner
- * classes.
- * [code]
- * static void concurrentSort(final FastTable<? extends Comparable> table) {
- * final int size = table.size();
- * if (size < 100) {
- * table.sort(); // Direct quick sort.
- * } else {
- * // Splits table in two and sort both part concurrently.
- * final FastTable<? extends Comparable> t1 = new FastTable();
- * final FastTable<? extends Comparable> t2 = new FastTable();
- * ConcurrentContext ctx = ConcurrentContext.enter();
- * try {
- * ctx.execute(new Runnable() {
- * public void run() {
- * t1.addAll(table.subList(0, size / 2));
- * concurrentSort(t1); // Recursive.
- * }
- * });
- * ctx.execute(new Runnable() {
- * public void run() {
- * t2.addAll(table.subList(size / 2, size));
- * concurrentSort(t2); // Recursive.
- * }
- * });
- * } finally {
- * ctx.exit(); // Joins.
- * }
- * // Merges results.
- * for (int i=0, i1=0, i2=0; i < size; i++) {
- * if (i1 >= t1.size()) {
- * table.set(i, t2.get(i2++));
- * } else if (i2 >= t2.size()) {
- * table.set(i, t1.get(i1++));
- * } else {
- * Comparable o1 = t1.get(i1);
- * Comparable o2 = t2.get(i2);
- * if (o1.compareTo(o2) < 0) {
- * table.set(i, o1);
- * i1++;
- * } else {
- * table.set(i, o2);
- * i2++;
- * }
- * }
- * }
- * }
- * }[/code]</p>
- *
- * <p> Here is another example using {@link #execute(java.lang.Runnable[])
- * execute(Runnable ...)} static method
- * (Karatsuba recursive multiplication for large integers).
- * [code]
- * public LargeInteger times(LargeInteger that) {
- * if (that._size <= 1) {
- * return times(that.longValue()); // Direct multiplication.
- * } else { // Karatsuba multiplication in O(n^log2(3))
- * int bitLength = this.bitLength();
- * int n = (bitLength >> 1) + (bitLength & 1);
- *
- * // this = a + 2^n b, that = c + 2^n d
- * LargeInteger b = this.shiftRight(n);
- * LargeInteger a = this.minus(b.shiftLeft(n));
- * LargeInteger d = that.shiftRight(n);
- * LargeInteger c = that.minus(d.shiftLeft(n));
- * Multiply ac = new Multiply(a, c);
- * Multiply bd = new Multiply(b, d);
- * Multiply abcd = new Multiply(a.plus(b), c.plus(d));
- * ConcurrentContext.execute(ac, bd, abcd); // Convenience method.
- * // a*c + ((a+b)*(c+d)-a*c-b*d) 2^n + b*d 2^2n
- * return ac.result.plus(abcd.result.minus(ac.result.plus(bd.result)).shiftWordLeft(n))
- * .plus(bd.result.shiftWordLeft(n << 1));
- * }
- * }
- * private static class Multiply implements Runnable {
- * LargeInteger left, right, result;
- * Multiply(LargeInteger left, LargeInteger right) {
- * this.left = left;
- * this.right = right;
- * }
- * public void run() {
- * result = left.times(right); // Recursive.
- * }
- * }[/code]</p>
- *
- * <p> Concurrency can be adjusted or disabled. The default concurrency
- * is defined by the {@link #CONCURRENCY} configurable.
- * [code]
- * ConcurrentContext ctx = ConcurrentContext.enter();
- * try {
- * ctx.setConcurrency(0); // Disables concurrency
- * runAnalysis(); // Performs analysis sequentially.
- * } finally {
- * ctx.exit(); // Back to previous concurrency settings.
- * }[/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-public abstract class ConcurrentContext extends AbstractContext {
-
- /**
- * Holds the maximum concurrency
- * (default {@code Runtime.getRuntime().availableProcessors() - 1}).
- * The maximum concurrency is configurable. For example, the JVM option
- * {@code -Djavolution.context.ConcurrentContext#CONCURRENCY=0}
- * disables concurrency.
- */
- public static final Configurable<Integer> CONCURRENCY = new Configurable<Integer>() {
- @Override
- protected Integer getDefault() {
- return Runtime.getRuntime().availableProcessors() - 1;
- }
-
- @Override
- protected Integer initialized(Integer value) {
- return MathLib.min(value, 65536); // Hard-limiting
- }
-
- @Override
- protected Integer reconfigured(Integer oldCount, Integer newCount) {
- throw new UnsupportedOperationException(
- "Concurrency reconfiguration not supported.");
- }
- };
-
- /**
- * Default constructor.
- */
- protected ConcurrentContext() {}
-
- /**
- * Enters and returns a new concurrent context instance.
- */
- public static ConcurrentContext enter() {
- ConcurrentContext ctx = current(ConcurrentContext.class);
- if (ctx == null) { // Root.
- ctx = OSGiServices.getConcurrentContext();
- }
- return (ConcurrentContext) ctx.enterInner();
- }
-
- /**
- * Convenience method to executes the specified logics concurrently.
- * This method is equivalent to:
- * [code]
- * ConcurrentContext ctx = ConcurrentContext.enter();
- * try {
- * ctx.execute(logics[0]);
- * ctx.execute(logics[1]);
- * ...
- * } finally {
- * ctx.exit();
- * }[/code]
- *
- * @param logics the logics to execute concurrently if possible.
- */
- public static void execute(Runnable... logics) {
- ConcurrentContext ctx = ConcurrentContext.enter();
- try {
- for (Runnable logic : logics) {
- ctx.execute(logic);
- }
- } finally {
- ctx.exit();
- }
- }
-
- /**
- * Executes the specified logic by a concurrent thread if
- * one available; otherwise the logic is executed by the current thread.
- * Any exception or error occurring during the concurrent execution is
- * propagated to the current thread upon exit of the concurrent context.
- *
- * @param logic the logic to be executed concurrently when possible.
- */
- public abstract void execute(Runnable logic);
-
- /**
- * Sets the maximum concurrency. Setting a value greater than the
- * {@link #getConcurrency() current concurrency} has no effect
- * (concurrency can only be reduced).
- */
- public abstract void setConcurrency(int concurrency);
-
- /**
- * Returns the current concurrency which is basically the number of
- * concurrent threads authorized to do concurrent work (on top of all
- * others threads of course).
- */
- public abstract int getConcurrency();
-
- /**
- * Exits the scope of this concurrent context; this method blocks until
- * all the concurrent executions are completed.
- *
- * @throws RuntimeException re-exports any exception raised during concurrent
- * executions.
- * @throws Error re-exports any error raised during concurrent executions.
- * @throws IllegalStateException if this context is not the current
- * context.
- */
- @Override
- public void exit() { // Redefine here for documentation purpose.
- super.exit();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java
deleted file mode 100644
index a17b595..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/FormatContext.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context;
-
-/**
- * <p> The parent class for all serializer/deserializer contexts.
- * The context format type (plain text, XML, JSON, ...) is specified by
- * sub-classes. Classes may identify the plain text format through the
- * {@link javolution.text.DefaultTextFormat DefaultTextFormat} annotation
- * or the default XML format through the
- * {@link javolution.xml.DefaultXMLFormat DefaultXMLFormat} annotation.
- * [code]
- * @DefaultTextFormat(Complex.Cartesian.class)
- * @DefaultXMLFormat(Complex.XML.class)
- * public Complex {
- * public static final class Cartesian extends javolution.text.TextFormat<Complex> { ... }
- * public static final class Polar extends javolution.text.TextFormat<Complex> { ... }
- * public static final class XML extends javolution.text.XMLFormat<Complex> { ... }
- * ...
- * }
- * [/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-public abstract class FormatContext extends AbstractContext {
-
- /**
- * Default constructor.
- */
- protected FormatContext() {}
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java
deleted file mode 100644
index e4c5c28..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/LocalContext.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context;
-
-import javolution.context.SecurityContext.Permission;
-import javolution.lang.Configurable;
-import javolution.osgi.internal.OSGiServices;
-
-/**
- * <p> A context holding locally scoped {@link Parameter parameters} values.</p>
- * <p> For example, when performing modulo arithmetics the actual modulo
- * being used is usually the same for most operations and does not need
- * to be specified for each operation.
- * [code]
- * import javolution.context.LocalContext.Parameter;
- * public class ModuloInteger extends Number {
- * public static final Parameter<Integer> MODULO = new Parameter<Integer>() {
- * protected Integer getDefault() { return -1; }
- * };
- * public ModuloInteger times(ModuloInteger that) { ... }
- * }
- * LocalContext ctx = LocalContext.enter();
- * try {
- * ctx.supersede(ModuloInteger.MODULO, 13); // Sets local modulo value.
- * x = a.times(b).plus(c.times(d)); // Operations modulo 13
- * ...
- * } finally {
- * ctx.exit(); // Reverts to previous modulo setting.
- * }[/code]</p>
- *
- * <p> As for any context, local context settings are inherited during
- * {@link ConcurrentContext} executions.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-public abstract class LocalContext extends AbstractContext {
-
- /**
- * A {@link Configurable configurable} parameter whose value can
- * be locally superseded within the scope of {@link LocalContext}.</p>
- */
- public static abstract class Parameter<T> extends Configurable<T> {
-
- /**
- * Holds the general permission to supersede any parameter value
- * (action "supersede").
- */
- public static final Permission<Parameter<?>> SUPERSEDE_PERMISSION = new Permission<Parameter<?>>(
- Parameter.class, "supersede");
-
- /**
- * Holds this instance supersede permission.
- */
- private final Permission<Parameter<T>> supersedePermission;
-
- /**
- * Creates a new parameter (configurable).
- */
- public Parameter() {
- this.supersedePermission = new Permission<Parameter<T>>(
- Parameter.class, "supersede", this);
- }
-
- /**
- * Returns the permission to locally supersede the current value
- * of this instance.
- */
- public Permission<Parameter<T>> getSupersedePermission() {
- return supersedePermission;
- }
-
- /**
- * Returns the current parameter value (the default value if not
- * reconfigured nor {@link LocalContext#supersede superseded}).
- */
- public T get() {
- LocalContext ctx = current(LocalContext.class);
- return (ctx != null) ? ctx.getValue(this, super.get()) : super.get();
- }
- }
-
- /**
- * Default constructor.
- */
- protected LocalContext() {}
-
- /**
- * Enters and returns a new local context instance.
- */
- public static LocalContext enter() {
- LocalContext ctx = current(LocalContext.class);
- if (ctx == null) { // Root.
- ctx = OSGiServices.getLocalContext();
- }
- return (LocalContext) ctx.enterInner();
- }
-
- /**
- * Supersedes the value of the specified parameter.
- *
- * @param param the local parameter whose local value is overridden.
- * @param localValue the new local value.
- * @throws SecurityException if the permission to override the specified
- * parameter is not granted.
- * @throws NullPointerException if the specified local value is {@code null}.
- */
- public abstract <T> void supersede(Parameter<T> param, T localValue);
-
- /**
- * Returns the local value of the specified parameter or the specified
- * default value if not {@link LocalContext#supersede superseded}.
- *
- * @param param the local parameter whose local value is returned.
- * @param defaultValue the parameter value if not superseded.
- */
- protected abstract <T> T getValue(Parameter<T> param, T defaultValue);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java
deleted file mode 100644
index 2856244..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/LogContext.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context;
-
-import javolution.lang.Configurable;
-import javolution.osgi.internal.OSGiServices;
-import javolution.text.TextContext;
-
-/**
- * <p> Asynchronous logging context integrated with the OSGi logging framework.
- * The logging back-end, or how the log entries are displayed, stored, or
- * processed is unspecified but always performed asynchronously.
- * When running outside OSGi, log messages are sent to {@link System#out}.
- * Message formatting itself is always performed synchronously using the
- * current {@link TextContext}.</p>
- *
- * <p> Logging contexts support automatic prefixing/suffixing of any information
- * relevant to the user/developer (thread info, user id, and so on).
- * [code]
- * void run() {
- * LogContext ctx = LogContext.enter();
- * try {
- * // Prefix the executing thread to any message being logged.
- * ctx.prefix("[Thread: ", Thead.currentThread(), "] ");
- * ...
- * } finally {
- * ctx.exit();
- * }
- * }[/code]</p>
- *
- * <p> Applications should separate messages elements by commas and not
- * use {@link String} concatenations when calling log methods otherwise
- * the concatenation is performed even when log events are filtered out.
- * [code]
- * LogContext ctx = LogContext.enter();
- * try {
- * ctx.setLevel(Level.INFO); // Does not log debug messages.
- * ...
- * LogContext.debug("Index: ", index, " at maximum value"); // GOOD, no formatting performed !
- * LogContext.debug("Index: " + index + " at maximum value"); // BAD, formatting performed even though nothing is logged !
- * ...
- * } finally {
- * ctx.exit();
- * }[/code]</p>
- *
- * <p> In general, the {@link Level#DEBUG} level provides information only
- * relevant to developers and can be turned off after deployment.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- * @see <a href="https://code.google.com/p/osgi-logging/wiki/UnderstandingTheOSGiLogging">Understanding OSGi Logging</a>
- */
-public abstract class LogContext extends AbstractContext {
-
- /**
- * Defines the logging levels.
- */
- public enum Level {
-
- DEBUG, INFO, WARNING, ERROR, FATAL
-
- }
-
- /**
- * Holds the default logging level (<code>DEBUG</code>).
- * This level is configurable. For example, running with
- * the option <code>-Djavolution.context.LogContext#LEVEL=WARNING</code>
- * causes the debug/info not to be logged.
- */
- public static final Configurable<Level> LEVEL = new Configurable<Level>() {
- @Override
- protected Level getDefault() {
- return Level.DEBUG;
- }
- @Override
- public Level parse(String str) {
- return Level.valueOf(str);
- }
- };
-
- /**
- * Logs the specified debug message.
- */
- public static void debug(Object... message) {
- currentLogContext().log(Level.DEBUG, message);
- }
-
- /**
- * Enters and returns a new log context instance.
- */
- public static LogContext enter() {
- return (LogContext) currentLogContext().enterInner();
- }
-
- /**
- * Logs the specified error message (which may include any {@link Throwable}
- * instance).
- */
- public static void error(Object... message) {
- currentLogContext().log(Level.ERROR, message);
- }
-
- /**
- * Logs the specified info message.
- */
- public static void info(Object... message) {
- currentLogContext().log(Level.INFO, message);
- }
-
- /**
- * Logs the specified warning message.
- */
- public static void warning(Object... message) {
- currentLogContext().log(Level.WARNING, message);
- }
-
- private static LogContext currentLogContext() {
- LogContext ctx = current(LogContext.class);
- if (ctx != null)
- return ctx;
- return OSGiServices.getLogContext();
- }
-
- /**
- * Default constructor.
- */
- protected LogContext() {}
-
- /**
- * Prefixes all messages being logged by the specified prefixes
- * (prefixing existing prefixes if any).
- */
- public abstract void prefix(Object... prefixes);
-
- /**
- * Set the logging level, messages below that level are not logged.
- */
- public abstract void setLevel(Level level);
-
- /**
- * Suffixes all messages being logged by the specified suffixes
- * (suffixing existing suffixes if any).
- */
- public abstract void suffix(Object... suffixes);
-
- /**
- * Logs the specified message at the specified level.
- */
- protected abstract void log(Level level, Object... message);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java
deleted file mode 100644
index 6fab057..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/SecurityContext.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2007 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context;
-
-import javolution.osgi.internal.OSGiServices;
-
-/**
- * <p> A high-level security context integrated with OSGi.</p>
- *
- * <p> When granting/revoking permission the order is important.
- * For example, the following code revokes all configurable permissions
- * except for setting the concurrency level.
- * [code]
- * SecurityContext ctx = SecurityContext.enter();
- * try {
- * ctx.revoke(Configurable.RECONFIGURE_PERMISSION);
- * ctx.grant(ConcurrentContext.CONCURRENCY.getReconfigurePermission());
- * ...
- * ConcurrentContext.CONCURRENCY.reconfigure(0); // Ok (permission specifically granted).
- * ...
- * } finally {
- * ctx.exit(); // Back to previous security settings.
- * }[/code]</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-public abstract class SecurityContext extends AbstractContext {
-
- /**
- * A permission associated to a specific class/action/instance.
- * There are three levels of permission possible, at
- * the class/category level, at the action level and at the instance level.
- * Any permission granted/revoked at the higher level is explicitly
- * granted/revoked at the lower level. The order in which the permission
- * are granted/revoked is important. For example, it is possible to grant
- * a permission at the class level, then to revoke it at the action or
- * instance level. In which case, for that class the permission is granted
- * for all actions/instances except for those actions/instances for which the
- * permission has been explicitly revoked.
- */
- public static class Permission<T> {
-
- /**
- * Holds the global permission for anything.
- */
- public static final Permission<Object> ALL = new Permission<Object>(
- null);
-
- private final Class<? super T> category;
-
- private final String action;
-
- private final T instance;
-
- /**
- * Creates a security permission for all actions of the specified category.
- */
- public Permission(Class<? super T> category) {
- this(category, null, null);
- }
-
- /**
- * Creates a security permission for the specified action of the
- * specified category.
- */
- public Permission(Class<? super T> category, String action) {
- this(category, action, null);
- }
-
- /**
- * Creates a security permission for the specified instance and the
- * specified action of the specified category.
- */
- public Permission(Class<? super T> category, String action, T instance) {
- this.category = category;
- this.action = action;
- this.instance = instance;
- }
-
- /**
- * Returns the permission category or <code>null</code> for all categories.
- */
- public Class<? super T> getCategory() {
- return category;
- }
-
- /**
- * Returns the permission action or <code>null</code> for all actions.
- */
- public String getAction() {
- return action;
- }
-
- /**
- * Returns the permission instance or <code>null</code> for all instances.
- */
- public T getInstance() {
- return instance;
- }
-
- /**
- * Checks if the specified permission is automatically granted/revoked
- * by 'this' permission being granted/revoked.
- *
- * @param that the permission to check.
- * @return <code>true</code> if this permission being granted/revoked
- * implies that the specified permission is granted/revoked;
- * <code>false</code> otherwise.
- */
- public boolean implies(Permission<?> that) {
- if (category == null)
- return true;
- if (!category.isAssignableFrom(that.category))
- return false;
- if (action == null)
- return true;
- if (!action.equals(that.action))
- return false;
- if (instance == null)
- return true;
- if (!instance.equals(that.instance))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- if (category == null)
- return "All permissions";
- if (action == null)
- return "Permission for any action on " + category.getName();
- if (instance == null)
- return "Permission for " + action + " on " + category.getName();
- return "Permission for " + action + " on instance " + instance
- + " of " + category.getName();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (!(obj instanceof Permission))
- return false;
- Permission<?> that = (Permission<?>) obj;
- if ((category == null) && (that.category != null))
- return false;
- if ((category != null) && (!category.equals(that.category)))
- return false;
- if ((action == null) && (that.action != null))
- return false;
- if ((action != null) && (!action.equals(that.action)))
- return false;
- if ((instance == null) && (that.instance != null))
- return false;
- if ((instance != null) && (!instance.equals(that.instance)))
- return false;
- return false;
- }
-
- @Override
- public int hashCode() {
- return (category != null ? category.hashCode() : 0)
- + (action != null ? action.hashCode() : 0)
- + (instance != null ? instance.hashCode() : 0);
- }
- }
-
- /**
- * Default constructor.
- */
- protected SecurityContext() {}
-
- /**
- * Enters and returns a new security context instance.
- *
- * @return the new security context implementation entered.
- */
- public static SecurityContext enter() {
- return (SecurityContext) currentSecurityContext().enterInner();
- }
-
- /**
- * Checks if the specified permission is granted.
- *
- * @param permission the permission to check.
- * @throws SecurityException if the specified permission is not granted.
- */
- public static void check(Permission<?> permission) {
- if (!currentSecurityContext().isGranted(permission))
- throw new SecurityException(permission + " is not granted.");
- }
-
- /**
- * Indicates if the specified permission is granted.
- *
- * @param permission the permission to check.
- */
- public abstract boolean isGranted(Permission<?> permission);
-
- /**
- * Grants the specified permission.
- *
- * @param permission the permission to grant.
- * @param certificate the certificate used to grant that permission or
- * <code>null</code> if none.
- * @throws SecurityException if the specified permission cannot be granted.
- */
- public abstract void grant(Permission<?> permission, Object certificate);
-
- /**
- * Revokes the specified permission.
- *
- * @param permission the permission to grant.
- * @param certificate the certificate used to grant that permission or
- * <code>null</code> if none.
- * @throws SecurityException if the specified permission cannot be revoked.
- */
- public abstract void revoke(Permission<?> permission, Object certificate);
-
- /**
- * Grants the specified permission (convenience method).
- *
- * @param permission the permission to grant.
- * @throws SecurityException if the specified permission cannot be granted.
- */
- public final void grant(Permission<?> permission) {
- grant(permission, null);
- }
-
- /**
- * Revokes the specified permission (convenience method).
- *
- * @param permission the permission to grant.
- * @throws SecurityException if the specified permission cannot be revoked.
- */
- public final void revoke(Permission<?> permission) {
- revoke(permission, null);
- }
-
- /**
- * Returns the current security context.
- */
- private static SecurityContext currentSecurityContext() {
- SecurityContext ctx = current(SecurityContext.class);
- if (ctx != null)
- return ctx;
- return OSGiServices.getSecurityContext();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java b/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java
deleted file mode 100644
index fe7cdba..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/StorageContext.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2007 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context;
-
-import java.io.File;
-import java.io.Serializable;
-
-import javolution.lang.Configurable;
-import javolution.osgi.internal.OSGiServices;
-
-/**
- * <p> A context for persistent storage integrated with OSGi and
- * {@link SecurityContext}.</p>
- *
- * <p> How the data is going to be stored (database, files) is implementation
- * dependent. But how the resources are structured (hierarchical, semantics)
- * is defined by the client implementing the {@link Resource} class.
- * [code]
- * class SemanticResource<T> extends SemanticEntity implements Resource<T> { ... }
- * ...
- * StorageContext ctx = StorageContext.enter(); // Enters the current storage service.
- * try {
- * // Stores resource.
- * SemanticResource<Image> logoId = new SemanticResource<Image>(
- * "http://purl.org/goodrelations/v1#Logo|MyCompany");
- * ctx.write(logoId, logoImg); // May raise SecurityException.
- * ...
- * // Retrieves resource.
- * Image logoImg = ctx.read(logoId); // May raise SecurityException.
- * } finally {
- * ctx.exit();
- * }[/code]</p>
- *
- * <p> Permission to read/write resource values may or not be granted at all
- * or only for particular resources. Sensitive data should always be
- * encrypted (e.g. using a {@code SecuredStorageContext} sub-class).
- * There is no limit in the size of the data being stored (except the actual
- * storage available). It is nonetheless recommended to split large data
- * set in smaller resources to allow for partial/concurrent retrieval.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-public abstract class StorageContext extends AbstractContext {
-
- /**
- * Holds the default storage location for file based-implementations
- * (default {@code new File("storage")}).
- */
- public static final Configurable<File> FILE_STORAGE_LOCATION = new Configurable<File>() {
- @Override
- protected File getDefault() {
- return new File("storage");
- }
-
- protected File parse(String pathname) {
- return new File(pathname);
- }
- };
-
- /**
- * A resource identifier.
- *
- * @param <T> The resource type (the type of the value stored).
- */
- public interface Resource<T> {
-
- /**
- * Returns an unique identifier for this resource.
- */
- public String uniqueID();
-
- }
-
- /**
- * Default constructor.
- */
- protected StorageContext() {}
-
- /**
- * Enters and returns a storage context instance.
- */
- public static StorageContext enter() {
- return (StorageContext) currentStorageContext().enterInner();
- }
-
- /**
- * Reads the persistent value of the specified resource value.
- *
- * @param resource the entity whose persistent value is returned.
- * @return the resource value or <code>null</code> if none.
- * @throws SecurityException if the permission to read the resource
- * is not granted ({@code new
- * Permission<Resource<V>>(Resource.class, "read", resource)}).
- */
- public abstract <V extends Serializable> V read(Resource<V> resource)
- throws SecurityException;
-
- /**
- * Writes the persistent value of the specified resource.
- *
- * @param resource the entity whose persistent value is stored.
- * @param value the persistent value.
- * @throws SecurityException if the permission to write the resource
- * is not granted ({@code new
- * Permission<Resource<V>>(Resource.class, "write", resource)}).
- */
- public abstract <V extends Serializable> void write(Resource<V> resource,
- V value) throws SecurityException;
-
- /**
- * Returns the current storage context.
- */
- private static StorageContext currentStorageContext() {
- StorageContext ctx = current(StorageContext.class);
- if (ctx != null) return ctx;
- return OSGiServices.getStorageContext();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java
deleted file mode 100644
index 1a3d341..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentContextImpl.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context.internal;
-
-import javolution.context.ConcurrentContext;
-import javolution.lang.MathLib;
-
-/**
- * Holds the default implementation of ConcurrentContext.
- */
-public final class ConcurrentContextImpl extends ConcurrentContext {
-
- private int completedCount; // Nbr of concurrent task completed.
- private Throwable error; // Any error raised.
-
- private int initiatedCount; // Nbr of concurrent task initiated.
- private final ConcurrentContextImpl parent;
- private ConcurrentThreadImpl[] threads;
- private int lastThreadInitiated; // Holds index of the last thread initiated.
-
- /**
- * Default constructor (root).
- */
- public ConcurrentContextImpl() {
- this.parent = null;
- int nbThreads = ConcurrentContext.CONCURRENCY.get();
- threads = new ConcurrentThreadImpl[nbThreads];
- for (int i = 0; i < nbThreads; i++) {
- threads[i] = new ConcurrentThreadImpl();
- threads[i].start();
- }
- }
-
- /**
- * Inner implementation.
- */
- public ConcurrentContextImpl(ConcurrentContextImpl parent) {
- this.parent = parent;
- this.threads = parent.threads; // Inherit threads from parents.
- }
-
- // Informs this context of the completion of a task (with possible error).
- public synchronized void completed(Throwable error) {
- if (error != null) {
- this.error = error;
- }
- completedCount++;
- this.notify();
- }
-
- @Override
- public void execute(Runnable logic) {
- if (threads.length > 0) {
- int i = lastThreadInitiated;
- while (true) { // Searches available thread.
- i++;
- if (i >= threads.length) i = 0;
- if (threads[i].execute(logic, this)) {
- initiatedCount++;
- lastThreadInitiated = i;
- return;
- }
- if (i == lastThreadInitiated) break; // Cycled through.
- }
- }
- // No concurrent thread to do the job, lets do it ourself.
- try {
- logic.run();
- } catch (Throwable e) {
- error = e;
- }
- }
-
- @Override
- public synchronized void exit() {
- super.exit();
- try {
- while (initiatedCount != completedCount) {
- this.wait();
- }
- } catch (InterruptedException ex) {
- this.error = ex;
- }
- if (error == null)
- return; // Everything fine.
- if (error instanceof RuntimeException)
- throw (RuntimeException) error;
- if (error instanceof Error)
- throw (Error) error;
- throw new RuntimeException(error);
- }
-
- @Override
- public int getConcurrency() {
- return threads.length;
- }
-
- @Override
- public void setConcurrency(int concurrency) {
- // The setting of the concurrency can only reduce the number
- // of threads available in the context.
- int nbThreads = MathLib.min(parent.threads.length, concurrency);
- threads = new ConcurrentThreadImpl[nbThreads];
- for (int i = 0; i < nbThreads; i++) { // Reused from parent threads.
- threads[i] = parent.threads[i];
- }
- }
-
- @Override
- protected ConcurrentContext inner() {
- return new ConcurrentContextImpl(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java
deleted file mode 100644
index 78ca5c4..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/internal/ConcurrentThreadImpl.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context.internal;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import javax.realtime.RealtimeThread;
-
-import javolution.context.AbstractContext;
-
-/**
- * A worker thread executing in a concurrent context.
- */
-public class ConcurrentThreadImpl extends RealtimeThread {
-
- private static int count;
- private ConcurrentContextImpl context;
- private AtomicBoolean isBusy = new AtomicBoolean();
- private Runnable logic;
- private int priority;
-
- /**
- * Default constructor.
- */
- public ConcurrentThreadImpl() {
- this.setName("ConcurrentThread-" + ++count);
- setDaemon(true);
- }
-
- /**
- * Executes the specified logic by this thread if ready; returns
- * {@code false} if this thread is busy.
- */
- public boolean execute(Runnable logic, ConcurrentContextImpl inContext) {
- if (!isBusy.compareAndSet(false, true))
- return false;
- synchronized (this) {
- this.priority = Thread.currentThread().getPriority();
- this.context = inContext;
- this.logic = logic;
- this.notify();
- }
- return true;
- }
-
- @Override
- public void run() {
- while (true) { // Main loop.
- try {
- synchronized (this) {
- while (logic == null) this.wait();
- }
- this.setPriority(priority);
- AbstractContext.inherit(context);
- logic.run();
- context.completed(null);
- } catch (Throwable error) {
- context.completed(error);
- }
- // Clean up.
- logic = null;
- context = null;
- AbstractContext.inherit(null);
- isBusy.set(false);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java
deleted file mode 100644
index ff8685d..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LocalContextImpl.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context.internal;
-
-import javolution.context.LocalContext;
-import javolution.util.FastMap;
-
-/**
- * Holds the default implementation of LocalContext.
- */
-public final class LocalContextImpl extends LocalContext {
-
- private FastMap<Parameter<?>, Object> localSettings = new FastMap<Parameter<?>, Object>();
- private LocalContextImpl parent;
-
- @Override
- protected LocalContext inner() {
- LocalContextImpl ctx = new LocalContextImpl();
- ctx.parent = this;
- return ctx;
- }
-
- @Override
- public <T> void supersede(Parameter<T> param, T localValue) {
- if (localValue == null) throw new NullPointerException();
- localSettings.put(param, localValue);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected <T> T getValue(Parameter<T> param, T defaultValue) {
- Object value = localSettings.get(param);
- if (value != null) return (T) value;
- if (parent != null) return parent.getValue(param, defaultValue);
- return defaultValue;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java
deleted file mode 100644
index 3005d03..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/internal/LogContextImpl.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context.internal;
-
-import javolution.context.LogContext;
-import javolution.osgi.internal.OSGiServices;
-import javolution.text.TextBuilder;
-
-import org.osgi.service.log.LogService;
-
-/**
- * The default implementation of LogContext.
- */
-public final class LogContextImpl extends LogContext {
-
- private static final Object[] NONE = new Object[0];
- private static final int[] TO_OSGI_LEVEL = { LogService.LOG_DEBUG,
- LogService.LOG_INFO, LogService.LOG_WARNING, LogService.LOG_ERROR };
-
- private Level level; // Null to use configurable LEVEL.
- private Object[] prefix = NONE;
- private Object[] suffix = NONE;
-
- @Override
- public void prefix(Object... pfx) {
- Object[] tmp = new Object[prefix.length + pfx.length];
- System.arraycopy(pfx, 0, tmp, 0, pfx.length);
- System.arraycopy(prefix, 0, tmp, pfx.length, prefix.length);
- prefix = tmp;
- }
-
- @Override
- public void setLevel(Level level) {
- this.level = level;
- }
-
- @Override
- public void suffix(Object... sfx) {
- Object[] tmp = new Object[suffix.length + sfx.length];
- System.arraycopy(suffix, 0, tmp, 0, suffix.length);
- System.arraycopy(sfx, 0, tmp, suffix.length, sfx.length);
- suffix = tmp;
- }
-
- @Override
- protected LogContext inner() {
- LogContextImpl ctx = new LogContextImpl();
- ctx.prefix = prefix;
- ctx.suffix = suffix;
- ctx.level = level;
- return ctx;
- }
-
- @Override
- protected void log(Level level, Object... message) {
- if (level.compareTo(currentLevel()) < 0)
- return;
- TextBuilder tmp = new TextBuilder();
- Throwable exception = null;
- for (Object pfx : prefix) {
- tmp.append(pfx); // Uses TextContext for formatting.
- }
- for (Object obj : message) {
- if ((exception == null) && (obj instanceof Throwable)) {
- exception = (Throwable) obj;
- } else {
- tmp.append(obj); // Uses TextContext for formatting.
- }
- }
- for (Object sfx : suffix) {
- tmp.append(sfx); // Uses TextContext for formatting.
- }
- int osgiLevel = TO_OSGI_LEVEL[level.ordinal()];
- String msg = tmp.toString();
- Object[] logServices = OSGiServices.getLogServices();
- for (Object logService : logServices) {
- ((LogService)logService).log(osgiLevel, msg, exception);
- }
- }
- private Level currentLevel() {
- if (LEVEL == null) return Level.DEBUG; // Only during class initialization.
- if (level == null) return LEVEL.get();
- return level;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/context/internal/SecurityContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/context/internal/SecurityContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/context/internal/SecurityContextImpl.java
deleted file mode 100644
index 2615119..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/context/internal/SecurityContextImpl.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.context.internal;
-
-import javolution.context.SecurityContext;
-import javolution.util.FastTable;
-
-/**
- * Holds the default implementation of SecurityContext.
- */
-public final class SecurityContextImpl extends SecurityContext {
-
- private FastTable<Action> actions = new FastTable<Action>();
-
- @Override
- public boolean isGranted(Permission<?> permission) {
- boolean isGranted = true;
- for (Action a : actions) {
- if (a.permission.implies(permission))
- isGranted = a.grant;
- }
- return isGranted;
- }
-
- @Override
- public void grant(Permission<?> permission, Object certificate)
- throws SecurityException {
- Action a = new Action();
- a.grant = true;
- a.permission = permission;
- actions.add(a);
- }
-
- @Override
- public void revoke(Permission<?> permission, Object certificate)
- throws SecurityException {
- Action a = new Action();
- a.grant = false;
- a.permission = permission;
- actions.add(a);
- }
-
- @Override
- protected SecurityContext inner() {
- SecurityContextImpl ctx = new SecurityContextImpl();
- ctx.actions.addAll(actions);
- return ctx;
- }
-
- // Represents the grant/revoke action performed.
- private static class Action {
- boolean grant; // Else revoke.
- Permission<?> permission;
- }
-}
[14/15] git commit: updated LICENSE and NOTICE files
Posted by ss...@apache.org.
updated LICENSE and NOTICE files
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/84011103
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/84011103
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/84011103
Branch: refs/heads/develop
Commit: 840111038ea1538a73cdabf6bd040bcc9f61bd4b
Parents: e60b1a9a
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Sep 9 13:19:28 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Sep 9 13:19:28 2013 +0200
----------------------------------------------------------------------
NOTICE.txt | 1 -
.../src/main/resources/installer/LICENSE.txt | 31 ++++++++++++++++++++
.../src/main/resources/installer/NOTICE.txt | 3 ++
.../src/main/webapp/META-INF/LICENSE | 31 ++++++++++++++++++++
.../src/main/webapp/META-INF/NOTICE | 3 ++
5 files changed, 68 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/84011103/NOTICE.txt
----------------------------------------------------------------------
diff --git a/NOTICE.txt b/NOTICE.txt
index 4c9d58f..544564f 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -120,7 +120,6 @@ of the javolution library. Javolution has copyright (c) 2012, Javolution and
is licensed under BSD license. The original source code is available at
http://javolution.org/
-
The module commons/sesame-tools-rio-rss contains source code from the
orphaned ROME project. ROME has copyright 2004 Sun Microsystems, Inc.
and copyright 2011 The ROME Team, and is licensed under Apache License 2.0.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/84011103/launchers/marmotta-installer/src/main/resources/installer/LICENSE.txt
----------------------------------------------------------------------
diff --git a/launchers/marmotta-installer/src/main/resources/installer/LICENSE.txt b/launchers/marmotta-installer/src/main/resources/installer/LICENSE.txt
index 4a0bf89..9e10bdc 100644
--- a/launchers/marmotta-installer/src/main/resources/installer/LICENSE.txt
+++ b/launchers/marmotta-installer/src/main/resources/installer/LICENSE.txt
@@ -2692,6 +2692,37 @@ For the JSONLD-Java component,
THE POSSIBILITY OF SUCH DAMAGE.
+For the marmotta-commons component,
+
+ located at commons/marmotta-commons/src/ext/java
+
+ Javolution - Java(tm) Solution for Real-Time and Embedded Systems
+ Copyright (c) 2012, Javolution (http://javolution.org/)
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
Apache Marmotta 3rd party data files:
====================================
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/84011103/launchers/marmotta-installer/src/main/resources/installer/NOTICE.txt
----------------------------------------------------------------------
diff --git a/launchers/marmotta-installer/src/main/resources/installer/NOTICE.txt b/launchers/marmotta-installer/src/main/resources/installer/NOTICE.txt
index 4f1eabe..f88874c 100644
--- a/launchers/marmotta-installer/src/main/resources/installer/NOTICE.txt
+++ b/launchers/marmotta-installer/src/main/resources/installer/NOTICE.txt
@@ -302,3 +302,6 @@ This product also includes the following third-party components:
Copyright (c) 2011 Ben Fortuna
+* Javolution, http://javolution.org/
+
+ Copyright (c) 2012 Javolution
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/84011103/launchers/marmotta-webapp/src/main/webapp/META-INF/LICENSE
----------------------------------------------------------------------
diff --git a/launchers/marmotta-webapp/src/main/webapp/META-INF/LICENSE b/launchers/marmotta-webapp/src/main/webapp/META-INF/LICENSE
index 9631d61..28c0c4f 100644
--- a/launchers/marmotta-webapp/src/main/webapp/META-INF/LICENSE
+++ b/launchers/marmotta-webapp/src/main/webapp/META-INF/LICENSE
@@ -2689,6 +2689,37 @@ For the JSONLD-Java component,
THE POSSIBILITY OF SUCH DAMAGE.
+For the marmotta-commons component,
+
+ located at commons/marmotta-commons/src/ext/java
+
+ Javolution - Java(tm) Solution for Real-Time and Embedded Systems
+ Copyright (c) 2012, Javolution (http://javolution.org/)
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
Apache Marmotta 3rd party data files:
====================================
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/84011103/launchers/marmotta-webapp/src/main/webapp/META-INF/NOTICE
----------------------------------------------------------------------
diff --git a/launchers/marmotta-webapp/src/main/webapp/META-INF/NOTICE b/launchers/marmotta-webapp/src/main/webapp/META-INF/NOTICE
index 8ecf0d1..cf429e7 100644
--- a/launchers/marmotta-webapp/src/main/webapp/META-INF/NOTICE
+++ b/launchers/marmotta-webapp/src/main/webapp/META-INF/NOTICE
@@ -259,3 +259,6 @@ This product also includes the following third-party components:
Copyright (c) 2011 Ben Fortuna
+* Javolution, http://javolution.org/
+
+ Copyright (c) 2012 Javolution
[15/15] git commit: Merge branch 'develop' of
https://git-wip-us.apache.org/repos/asf/incubator-marmotta into develop
Posted by ss...@apache.org.
Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/incubator-marmotta into develop
Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/906a7f4f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/906a7f4f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/906a7f4f
Branch: refs/heads/develop
Commit: 906a7f4fc279d198405475ceed235e6ec2daf7ae
Parents: 8401110 0ce9cf9
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Sep 9 13:19:47 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Sep 9 13:19:47 2013 +0200
----------------------------------------------------------------------
.../platform/core/api/prefix/PrefixService.java | 8 +++++++
.../core/services/prefix/PrefixServiceImpl.java | 11 ++++++++++
.../webservices/prefix/PrefixWebService.java | 18 +++++++++++++++
.../src/main/resources/web/admin/prefixes.html | 23 +++++++++++++++++++-
.../webservices/LDPathUtilWebService.java | 7 ++++++
5 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
[09/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/Text.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/Text.java b/commons/marmotta-commons/src/ext/java/javolution/text/Text.java
deleted file mode 100644
index 285ab34..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/Text.java
+++ /dev/null
@@ -1,1333 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import java.io.PrintStream;
-
-import javolution.lang.MathLib;
-import javolution.lang.Realtime;
-import javolution.lang.ValueType;
-import javolution.util.FastMap;
-import javolution.util.function.Equalities;
-import javolution.xml.XMLSerializable;
-
-/**
- * <p> An immutable character sequence with fast {@link #concat concatenation},
- * {@link #insert insertion} and
- * {@link #delete deletion} capabilities (O[Log(n)]) instead of
- * O[n] for StringBuffer/StringBuilder).</p>
- * <p> This class has the same methods as
- * <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html">
- * Java String</a> and
- * <a href="http://msdn2.microsoft.com/en-us/library/system.string.aspx">
- * .NET String</a> with the following benefits:<ul>
- * <li> No need for an intermediate
- * {@link StringBuffer}/{@link StringBuilder} in order to manipulate
- * textual documents (insertion, deletion or concatenation).</li>
- * <li> Bug free. They are not plagued by the {@link String#substring} <a
- * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4513622">
- * memory leak bug</a> (when small substrings prevent memory from
- * larger string from being garbage collected).</li>
- * <li> More flexible as they allows for search and comparison with any
- * <code>java.lang.String</code> or <code>CharSequence</code>.</li>
- * </ul></p>
- * <p> {@link Text} literals should be explicitly {@link #intern interned}.
- * Unlike strings literals and strings-value constant expressions,
- * interning is not implicit. For example:[code]
- * final static Text TRUE = new Text("true").intern();
- * final static Text FALSE = new Text("true").intern("false");
- * [/code]</p>
- *
- * <p><i> Implementation Note: To avoid expensive copy operations ,
- * {@link Text} instances are broken down into smaller immutable
- * sequences, they form a minimal-depth binary tree.
- * The tree is maintained balanced automatically through <a
- * href="http://en.wikipedia.org/wiki/Tree_rotation">tree rotations</a>.
- * Insertion/deletions are performed in <code>O[Log(n)]</code>
- * instead of <code>O[n]</code> for
- * <code>StringBuffer/StringBuilder</code>.</i></p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @author Wilfried Middleton
- * @version 6.0, July 21, 2013
- */
-@Realtime
-public final class Text implements CharSequence, Comparable<CharSequence>,
- XMLSerializable, ValueType<Text> {
-
- private static final long serialVersionUID = 0x600L; // Version.
-
- /**
- * Holds the default size for primitive blocks of characters.
- */
- private static final int BLOCK_SIZE = 1 << 5;
-
- /**
- * Holds the mask used to ensure a block boundary cesures.
- */
- private static final int BLOCK_MASK = ~(BLOCK_SIZE - 1);
-
- /**
- * Holds the texts interned in immortal memory.
- */
- private static final FastMap<Text, Text> INTERN = new FastMap<Text, Text>()
- .shared();
-
- /**
- * Holds an empty character sequence.
- */
- public static final Text EMPTY = new Text("").intern();
-
- /**
- * Holds the raw data (primitive) or <code>null</code> (composite).
- */
- private final char[] _data;
-
- /**
- * Holds the total number of characters.
- */
- private int _count;
-
- /**
- * Holds the head block of character (composite).
- */
- private Text _head;
-
- /**
- * Holds the tail block of character (composite).
- */
- private Text _tail;
-
- /**
- * Creates a new text instance.
- *
- * @param isPrimitive indicates if primitive or composite.
- */
- private Text(boolean isPrimitive) {
- _data = isPrimitive ? new char[BLOCK_SIZE] : null;
- }
-
- /**
- * Creates a text holding the characters from the specified <code>String
- * </code>.
- *
- * @param str the string holding the character content.
- */
- public Text(String str) {
- this(str.length() <= BLOCK_SIZE);
- _count = str.length();
- if (_data != null) { // Primitive.
- str.getChars(0, _count, _data, 0);
- } else { // Composite, splits on a block boundary.
- int half = ((_count + BLOCK_SIZE) >> 1) & BLOCK_MASK;
- _head = new Text(str.substring(0, half));
- _tail = new Text(str.substring(half, _count));
- }
- }
-
- /**
- * Returns the text representing the specified object.
- *
- * @param obj the object to represent as text.
- * @return {@code new TextBuilder().append(obj).toText()}
- */
- public static Text valueOf(Object obj) {
- return new TextBuilder().append(obj).toText();
- }
-
- private static Text valueOf(String str) {
- return Text.valueOf(str, 0, str.length());
- }
-
- private static Text valueOf(String str, int start, int end) {
- int length = end - start;
- if (length <= BLOCK_SIZE) {
- Text text = newPrimitive(length);
- str.getChars(start, end, text._data, 0);
- return text;
- } else { // Splits on a block boundary.
- int half = ((length + BLOCK_SIZE) >> 1) & BLOCK_MASK;
- return newComposite(Text.valueOf(str, start, start + half),
- Text.valueOf(str, start + half, end));
- }
- }
-
- /**
- * Returns the text that contains the characters from the specified
- * array.
- *
- * @param chars the array source of the characters.
- * @return the corresponding instance.
- */
- public static Text valueOf(char[] chars) {
- return Text.valueOf(chars, 0, chars.length);
- }
-
- /**
- * Returns the text that contains the characters from the specified
- * subarray of characters.
- *
- * @param chars the source of the characters.
- * @param offset the index of the first character in the data soure.
- * @param length the length of the text returned.
- * @return the corresponding instance.
- * @throws IndexOutOfBoundsException if <code>(offset < 0) ||
- * (length < 0) || ((offset + length) > chars.length)</code>
- */
- public static Text valueOf(char[] chars, int offset, int length) {
- if ((offset < 0) || (length < 0) || ((offset + length) > chars.length))
- throw new IndexOutOfBoundsException();
- if (length <= BLOCK_SIZE) {
- Text text = Text.newPrimitive(length);
- System.arraycopy(chars, offset, text._data, 0, length);
- return text;
- } else { // Splits on a block boundary.
- int half = ((length + BLOCK_SIZE) >> 1) & BLOCK_MASK;
- return Text.newComposite(Text.valueOf(chars, offset, half),
- Text.valueOf(chars, offset + half, length - half));
- }
- }
-
- /**
- * Converts a text builder to a text instance (optimization for
- * TextBuilder.toText()).
- *
- * @param start the index of the first character inclusive.
- * @param end the index of the last character exclusive.
- * @return the corresponding text instance.
- */
- static Text valueOf(TextBuilder tb, int start, int end) {
- int length = end - start;
- if (length <= BLOCK_SIZE) {
- Text text = Text.newPrimitive(length);
- tb.getChars(start, end, text._data, 0);
- return text;
- } else { // Splits on a block boundary.
- int half = ((length + BLOCK_SIZE) >> 1) & BLOCK_MASK;
- return Text.newComposite(Text.valueOf(tb, start, start + half),
- Text.valueOf(tb, start + half, end));
- }
- }
-
- /**
- * Returns the text representation of the <code>boolean</code> argument.
- *
- * @param b a <code>boolean</code>.
- * @return if the argument is <code>true</code>, the text
- * <code>"true"</code> is returned; otherwise, the text
- * <code>"false"</code> is returned.
- */
- public static Text valueOf(boolean b) {
- return b ? TRUE : FALSE;
- }
-
- private static final Text TRUE = new Text("true").intern();
-
- private static final Text FALSE = new Text("false").intern();
-
- /**
- * Returns the text instance corresponding to the specified character.
- *
- * @param c a character.
- * @return a text of length <code>1</code> containing <code>'c'</code>.
- */
- public static Text valueOf(char c) {
- Text text = Text.newPrimitive(1);
- text._data[0] = c;
- return text;
- }
-
- /**
- * Returns the decimal representation of the specified <code>int</code>
- * argument.
- *
- * @param i the <code>int</code> to format.
- * @return the corresponding text instance.
- */
- public static Text valueOf(int i) {
- TextBuilder tb = new TextBuilder();
- return tb.append(i).toText();
- }
-
- /**
- * Returns the radix representation of the specified <code>int</code>
- * argument.
- *
- * @param i the <code>int</code> to format.
- * @param radix the radix (e.g. <code>16</code> for hexadecimal).
- * @return the corresponding text instance.
- */
- public static Text valueOf(int i, int radix) {
- TextBuilder tb = new TextBuilder();
- return tb.append(i, radix).toText();
- }
-
- /**
- * Returns the decimal representation of the specified <code>long</code>
- * argument.
- *
- * @param l the <code>long</code> to format.
- * @return the corresponding text instance.
- */
- public static Text valueOf(long l) {
- TextBuilder tb = new TextBuilder();
- return tb.append(l).toText();
- }
-
- /**
- * Returns the radix representation of the specified <code>long</code>
- * argument.
- *
- * @param l the <code>long</code> to format.
- * @param radix the radix (e.g. <code>16</code> for hexadecimal).
- * @return the corresponding text instance.
- */
- public static Text valueOf(long l, int radix) {
- TextBuilder tb = new TextBuilder();
- return tb.append(l, radix).toText();
- }
-
- /**
- * Returns the textual representation of the specified <code>float</code>
- * instance.
- *
- * @param f the <code>float</code> to format.
- * @return the corresponding text instance.
- */
- public static Text valueOf(float f) {
- TextBuilder tb = new TextBuilder();
- return tb.append(f).toText();
- }
-
- /**
- * Returns the textual representation of the specified <code>double</code>
- * argument.
- *
- * @param d the <code>double</code> to format.
- * @return the corresponding text instance.
- */
- public static Text valueOf(double d) {
- TextBuilder tb = new TextBuilder();
- return tb.append(d).toText();
- }
-
- /**
- * Returns the textual representation of the specified <code>double</code>
- * argument formatted as specified.
- *
- * @param d the <code>double</code> to format.
- * @param digits the number of significative digits (excludes exponent) or
- * <code>-1</code> to mimic the standard library (16 or 17 digits).
- * @param scientific <code>true</code> to forces the use of the scientific
- * notation (e.g. <code>1.23E3</code>); <code>false</code>
- * otherwise.
- * @param showZero <code>true</code> if trailing fractional zeros are
- * represented; <code>false</code> otherwise.
- * @return the corresponding text instance.
- * @throws IllegalArgumentException if <code>(digits > 19)</code>)
- */
- public static Text valueOf(double d, int digits, boolean scientific,
- boolean showZero) {
- TextBuilder tb = new TextBuilder();
- return tb.append(d, digits, scientific, showZero).toText();
- }
-
- /**
- * Returns the length of this text.
- *
- * @return the number of characters (16-bits Unicode) composing this text.
- */
- public int length() {
- return _count;
- }
-
- /**
- * Returns the concatenation of this text and the textual
- * representation of the specified object.
- *
- * @param obj the object whose textual representation is concatenated.
- * @return <code>this.concat(Text.valueOf(obj))</code>
- */
- public Text plus(Object obj) {
- return this.concat(Text.valueOf(obj));
- }
-
- /**
- * Returns the concatenation of this text and the specified
- * <code>String</code> (optimization).
- *
- * @param str the string whose characters are concatenated.
- * @return <code>this.concat(Text.valueOf(obj))</code>
- */
- public Text plus(String str) {
-
- Text merge = this.append(str);
- return merge != null ? merge : concat(Text.valueOf(str));
- }
-
- private Text append(String str) { // Try to append, returns null if cannot.
- int length = str.length();
- if (_data == null) {
- Text merge = _tail.append(str);
- return merge != null ? Text.newComposite(_head, merge) : null;
- } else { // Primitive.
- if (_count + length > BLOCK_SIZE)
- return null; // Cannot merge.
- Text text = Text.newPrimitive(_count + length);
- System.arraycopy(_data, 0, text._data, 0, _count);
- str.getChars(0, length, text._data, _count);
- return text;
- }
- }
-
- /**
- * Concatenates the specified text to the end of this text.
- * This method is very fast (faster even than
- * <code>StringBuffer.append(String)</code>) and still returns
- * a text instance with an internal binary tree of minimal depth!
- *
- * @param that the text that is concatenated.
- * @return <code>this + that</code>
- */
- public Text concat(Text that) {
- // All Text instances are maintained balanced:
- // (head < tail * 2) & (tail < head * 2)
-
- final int length = this._count + that._count;
- if (length <= BLOCK_SIZE) { // Merges to primitive.
- Text text = Text.newPrimitive(length);
- this.getChars(0, this._count, text._data, 0);
- that.getChars(0, that._count, text._data, this._count);
- return text;
-
- } else { // Returns a composite.
- Text head = this;
- Text tail = that;
-
- if (((head._count << 1) < tail._count) && (tail._data == null)) { // tail is composite
- // head too small, returns (head + tail/2) + (tail/2)
- if (tail._head._count > tail._tail._count) {
- // Rotates to concatenate with smaller part.
- tail = tail.rightRotation();
- }
- head = head.concat(tail._head);
- tail = tail._tail;
-
- } else if (((tail._count << 1) < head._count)
- && (head._data == null)) { // head is composite.
- // tail too small, returns (head/2) + (head/2 concat tail)
- if (head._tail._count > head._head._count) {
- // Rotates to concatenate with smaller part.
- head = head.leftRotation();
- }
- tail = head._tail.concat(tail);
- head = head._head;
- }
- return Text.newComposite(head, tail);
- }
- }
-
- private Text rightRotation() {
- // See: http://en.wikipedia.org/wiki/Tree_rotation
- Text P = this._head;
- if (P._data != null)
- return this; // Head not a composite, cannot rotate.
- Text A = P._head;
- Text B = P._tail;
- Text C = this._tail;
- return Text.newComposite(A, Text.newComposite(B, C));
- }
-
- private Text leftRotation() {
- // See: http://en.wikipedia.org/wiki/Tree_rotation
- Text Q = this._tail;
- if (Q._data != null)
- return this; // Tail not a composite, cannot rotate.
- Text B = Q._head;
- Text C = Q._tail;
- Text A = this._head;
- return Text.newComposite(Text.newComposite(A, B), C);
- }
-
- /**
- * Returns a portion of this text.
- *
- * @param start the index of the first character inclusive.
- * @return the sub-text starting at the specified position.
- * @throws IndexOutOfBoundsException if <code>(start < 0) ||
- * (start > this.length())</code>
- */
- public Text subtext(int start) {
- return subtext(start, length());
- }
-
- /**
- * Returns the text having the specified text inserted at
- * the specified location.
- *
- * @param index the insertion position.
- * @param txt the text being inserted.
- * @return <code>subtext(0, index).concat(txt).concat(subtext(index))</code>
- * @throws IndexOutOfBoundsException if <code>(index < 0) ||
- * (index > this.length())</code>
- */
- public Text insert(int index, Text txt) {
- return subtext(0, index).concat(txt).concat(subtext(index));
- }
-
- /**
- * Returns the text without the characters between the specified indexes.
- *
- * @param start the beginning index, inclusive.
- * @param end the ending index, exclusive.
- * @return <code>subtext(0, start).concat(subtext(end))</code>
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0) ||
- * (start > end) || (end > this.length()</code>
- */
- public Text delete(int start, int end) {
- if (start > end)
- throw new IndexOutOfBoundsException();
- return subtext(0, start).concat(subtext(end));
- }
-
- /**
- * Replaces each character sequence of this text that matches the specified
- * target sequence with the specified replacement sequence.
- *
- * @param target the character sequence to be replaced.
- * @param replacement the replacement sequence.
- * @return the resulting text.
- */
- public Text replace(java.lang.CharSequence target,
- java.lang.CharSequence replacement) {
- int i = indexOf(target);
- return (i < 0) ? this : // No target sequence found.
- subtext(0, i).concat(Text.valueOf(replacement)).concat(
- subtext(i + target.length()).replace(target,
- replacement));
- }
-
- /**
- * Replaces the specified characters in this text with the specified
- * replacement sequence.
- *
- * @param charSet the set of characters to be replaced.
- * @param replacement the replacement sequence.
- * @return the resulting text.
- */
- public Text replace(CharSet charSet, java.lang.CharSequence replacement) {
- int i = indexOfAny(charSet);
- return (i < 0) ? this : // No character to replace.
- subtext(0, i).concat(Text.valueOf(replacement)).concat(
- subtext(i + 1).replace(charSet, replacement));
- }
-
- /**
- * Returns {@link #subtext(int, int) subtext(start, end)}.
- *
- * @param start the index of the first character inclusive.
- * @param end the index of the last character exclusive.
- * @return <code>this.subtext(start, end)</code>
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0) ||
- * (start > end) || (end > this.length())</code>
- */
- public java.lang.CharSequence subSequence(int start, int end) {
- return subtext(start, end);
- }
-
- /**
- * Returns the index within this text of the first occurrence
- * of the specified character sequence searching forward.
- *
- * @param csq a character sequence.
- * @return the index of the first character of the character sequence found;
- * or <code>-1</code> if the character sequence is not found.
- */
- public int indexOf(java.lang.CharSequence csq) {
- return indexOf(csq, 0);
- }
-
- /**
- * Returns the index within this text of the first occurrence
- * of the specified characters sequence searching forward from
- * the specified index.
- *
- * @param csq a character sequence.
- * @param fromIndex the index to start the search from.
- * @return the index in the range
- * <code>[fromIndex, length() - csq.length()]</code>
- * or <code>-1</code> if the character sequence is not found.
- */
- public int indexOf(java.lang.CharSequence csq, int fromIndex) {
-
- // Limit cases.
- final int csqLength = csq.length();
- final int min = Math.max(0, fromIndex);
- final int max = _count - csqLength;
- if (csqLength == 0) { return (min > max) ? -1 : min; }
-
- // Searches for csq.
- final char c = csq.charAt(0);
- for (int i = indexOf(c, min); (i >= 0) && (i <= max); i = indexOf(c,
- ++i)) {
- boolean match = true;
- for (int j = 1; j < csqLength; j++) {
- if (this.charAt(i + j) != csq.charAt(j)) {
- match = false;
- break;
- }
- }
- if (match) { return i; }
- }
- return -1;
- }
-
- /**
- * Returns the index within this text of the last occurrence of
- * the specified characters sequence searching backward.
- *
- * @param csq a character sequence.
- * @return the index of the first character of the character sequence found;
- * or <code>-1</code> if the character sequence is not found.
- */
- public int lastIndexOf(java.lang.CharSequence csq) {
- return lastIndexOf(csq, _count);
- }
-
- /**
- * Returns the index within this text of the last occurrence of
- * the specified character sequence searching backward from the specified
- * index.
- *
- * @param csq a character sequence.
- * @param fromIndex the index to start the backward search from.
- * @return the index in the range <code>[0, fromIndex]</code> or
- * <code>-1</code> if the character sequence is not found.
- */
- public int lastIndexOf(java.lang.CharSequence csq, int fromIndex) {
-
- // Limit cases.
- final int csqLength = csq.length();
- final int min = 0;
- final int max = Math.min(fromIndex, _count - csqLength);
- if (csqLength == 0) { return (min > max) ? -1 : max; }
-
- // Searches for csq.
- final char c = csq.charAt(0);
- for (int i = lastIndexOf(c, max); (i >= 0); i = lastIndexOf(c, --i)) {
- boolean match = true;
- for (int j = 1; j < csqLength; j++) {
- if (this.charAt(i + j) != csq.charAt(j)) {
- match = false;
- break;
- }
- }
- if (match) { return i; }
- }
- return -1;
-
- }
-
- /**
- * Indicates if this text starts with the specified prefix.
- *
- * @param prefix the prefix.
- * @return <code>true</code> if the character sequence represented by the
- * argument is a prefix of the character sequence represented by
- * this text; <code>false</code> otherwise.
- */
- public boolean startsWith(java.lang.CharSequence prefix) {
- return startsWith(prefix, 0);
- }
-
- /**
- * Indicates if this text ends with the specified suffix.
- *
- * @param suffix the suffix.
- * @return <code>true</code> if the character sequence represented by the
- * argument is a suffix of the character sequence represented by
- * this text; <code>false</code> otherwise.
- */
- public boolean endsWith(java.lang.CharSequence suffix) {
- return startsWith(suffix, length() - suffix.length());
- }
-
- /**
- * Indicates if this text starts with the specified prefix
- * at the specified index.
- *
- * @param prefix the prefix.
- * @param index the index of the prefix location in this string.
- * @return <code>this.substring(index).startsWith(prefix)</code>
- */
- public boolean startsWith(java.lang.CharSequence prefix, int index) {
- final int prefixLength = prefix.length();
- if ((index >= 0) && (index <= (this.length() - prefixLength))) {
- for (int i = 0, j = index; i < prefixLength;) {
- if (prefix.charAt(i++) != this.charAt(j++)) { return false; }
- }
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Returns a copy of this text, with leading and trailing
- * whitespace omitted.
- *
- * @return a copy of this text with leading and trailing white
- * space removed, or this text if it has no leading or
- * trailing white space.
- */
- public Text trim() {
- int first = 0; // First character index.
- int last = length() - 1; // Last character index.
- while ((first <= last) && (charAt(first) <= ' ')) {
- first++;
- }
- while ((last >= first) && (charAt(last) <= ' ')) {
- last--;
- }
- return subtext(first, last + 1);
- }
-
- /**
- * Returns a text equals to this one from a pool of
- * unique text instances.
- *
- * @return an unique text instance allocated in permanent memory.
- */
- public Text intern() {
- Text txt = INTERN.putIfAbsent(this, this);
- return txt == null ? this : txt;
- }
-
- /**
- * Indicates if this text has the same character content as the specified
- * character sequence.
- *
- * @param csq the character sequence to compare with.
- * @return <code>true</code> if the specified character sequence has the
- * same character content as this text; <code>false</code> otherwise.
- */
- public boolean contentEquals(java.lang.CharSequence csq) {
- if (csq.length() != _count)
- return false;
- for (int i = 0; i < _count;) {
- if (this.charAt(i) != csq.charAt(i++))
- return false;
- }
- return true;
- }
-
- /**
- * Indicates if this text has the same character contend as the specified
- * character sequence ignoring case considerations.
- *
- * @param csq the <code>CharSequence</code> to compare this text against.
- * @return <code>true</code> if the argument and this text are equal,
- * ignoring case; <code>false</code> otherwise.
- */
- public boolean contentEqualsIgnoreCase(java.lang.CharSequence csq) {
- if (this._count != csq.length())
- return false;
- for (int i = 0; i < _count;) {
- char u1 = this.charAt(i);
- char u2 = csq.charAt(i++);
- if (u1 != u2) {
- u1 = Character.toUpperCase(u1);
- u2 = Character.toUpperCase(u2);
- if ((u1 != u2)
- && (Character.toLowerCase(u1) != Character
- .toLowerCase(u2)))
- return false;
-
- }
- }
- return true;
- }
-
- /**
- * Compares this text against the specified object for equality.
- * Returns <code>true</code> if the specified object is a text having
- * the same character sequence as this text.
- * For generic comparaison with any character sequence the
- * {@link #contentEquals(CharSequence)} should be used.
- *
- * @param obj the object to compare with or <code>null</code>.
- * @return <code>true</code> if that is a text with the same character
- * sequence as this text; <code>false</code> otherwise.
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!(obj instanceof Text))
- return false;
- final Text that = (Text) obj;
- if (this._count != that._count)
- return false;
- for (int i = 0; i < _count;) {
- if (this.charAt(i) != that.charAt(i++))
- return false;
- }
- return true;
- }
-
- /**
- * Returns the hash code for this text.
- *
- * @return the hash code value.
- */
- @Override
- public int hashCode() {
- int h = 0;
- final int length = this.length();
- for (int i = 0; i < length;) {
- h = 31 * h + charAt(i++);
- }
- return h;
- }
-
- /**
- * Compares this text to another character sequence or string
- * lexicographically.
- *
- * @param csq the character sequence to be compared.
- * @return <code>TypeFormat.LEXICAL_COMPARATOR.compare(this, csq)</code>
- * @throws ClassCastException if the specifed object is not a
- * <code>CharSequence</code> or a <code>String</code>.
- */
- public int compareTo(CharSequence csq) {
- return Equalities.LEXICAL.compare(this, csq);
- }
-
- /**
- * Returns <code>this</code> (implements
- * {@link javolution.lang.ValueType Realtime} interface).
- *
- * @return <code>this</code>
- */
- public Text toText() {
- return this;
- }
-
- /**
- * Prints the current statistics on this text tree structure.
- *
- * @param out the stream to use for output (e.g. <code>System.out</code>)
- */
- public void printStatistics(PrintStream out) {
- int length = this.length();
- int leaves = getNbrOfLeaves();
- synchronized (out) {
- out.print("LENGTH: " + length());
- out.print(", MAX DEPTH: " + getDepth());
- out.print(", NBR OF BRANCHES: " + getNbrOfBranches());
- out.print(", NBR OF LEAVES: " + leaves);
- out.print(", AVG LEAVE LENGTH: " + (length + (leaves >> 1))
- / leaves);
- out.println();
- }
- }
-
- private int getDepth() {
- if (_data != null) // Primitive.
- return 0;
- return MathLib.max(_head.getDepth(), _tail.getDepth()) + 1;
- }
-
- private int getNbrOfBranches() {
- return (_data == null) ? _head.getNbrOfBranches()
- + _tail.getNbrOfBranches() + 1 : 0;
- }
-
- private int getNbrOfLeaves() {
- return (_data == null) ? _head.getNbrOfLeaves()
- + _tail.getNbrOfLeaves() : 1;
- }
-
- /**
- * Converts the characters of this text to lower case.
- *
- * @return the text in lower case.
- * @see Character#toLowerCase(char)
- */
- public Text toLowerCase() {
- if (_data == null) // Composite.
- return Text.newComposite(_head.toLowerCase(), _tail.toLowerCase());
- Text text = Text.newPrimitive(_count);
- for (int i = 0; i < _count;) {
- text._data[i] = Character.toLowerCase(_data[i++]);
- }
- return text;
- }
-
- /**
- * Converts the characters of this text to upper case.
- *
- * @return the text in lower case.
- * @see Character#toUpperCase(char)
- */
- public Text toUpperCase() {
- if (_data == null) // Composite.
- return newComposite(_head.toUpperCase(), _tail.toUpperCase());
- Text text = Text.newPrimitive(_count);
- for (int i = 0; i < _count;) {
- text._data[i] = Character.toUpperCase(_data[i++]);
- }
- return text;
- }
-
- /**
- * Returns the character at the specified index.
- *
- * @param index the index of the character.
- * @return the character at the specified index.
- * @throws IndexOutOfBoundsException if <code>(index < 0) ||
- * (index >= this.length())</code>
- */
- public char charAt(int index) {
- if (index >= _count)
- throw new IndexOutOfBoundsException();
- return (_data != null) ? _data[index] : (index < _head._count) ? _head
- .charAt(index) : _tail.charAt(index - _head._count);
- }
-
- /**
- * Returns the index within this text of the first occurrence of the
- * specified character, starting the search at the beginning.
- *
- * @param c the character to search for.
- * @return the index of the first occurrence of the character in this text
- * that is greater than or equal to <code>0</code>,
- * or <code>-1</code> if the character does not occur.
- */
- public int indexOf(char c) {
- return indexOf(c, 0);
- }
-
- /**
- * Returns the index within this text of the first occurrence of the
- * specified character, starting the search at the specified index.
- *
- * @param c the character to search for.
- * @param fromIndex the index to start the search from.
- * @return the index of the first occurrence of the character in this text
- * that is greater than or equal to <code>fromIndex</code>,
- * or <code>-1</code> if the character does not occur.
- */
- public int indexOf(char c, int fromIndex) {
- if (_data != null) { // Primitive.
- for (int i = MathLib.max(fromIndex, 0); i < _count; i++) {
- if (_data[i] == c)
- return i;
- }
- return -1;
- } else { // Composite.
- final int cesure = _head._count;
- if (fromIndex < cesure) {
- final int headIndex = _head.indexOf(c, fromIndex);
- if (headIndex >= 0)
- return headIndex; // Found in head.
- }
- final int tailIndex = _tail.indexOf(c, fromIndex - cesure);
- return (tailIndex >= 0) ? tailIndex + cesure : -1;
- }
- }
-
- /**
- * Returns the index within this text of the first occurrence of the
- * specified character, searching backward and starting at the specified
- * index.
- *
- * @param c the character to search for.
- * @param fromIndex the index to start the search backward from.
- * @return the index of the first occurrence of the character in this text
- * that is less than or equal to <code>fromIndex</code>,
- * or <code>-1</code> if the character does not occur.
- */
- public int lastIndexOf(char c, int fromIndex) {
- if (_data != null) { // Primitive.
- for (int i = MathLib.min(fromIndex, _count - 1); i >= 0; i--) {
- if (_data[i] == c)
- return i;
- }
- return -1;
- } else { // Composite.
- final int cesure = _head._count;
- if (fromIndex >= cesure) {
- final int tailIndex = _tail.lastIndexOf(c, fromIndex - cesure);
- if (tailIndex >= 0)
- return tailIndex + cesure; // Found in tail.
- }
- return _head.lastIndexOf(c, fromIndex);
- }
- }
-
- /**
- * Returns a portion of this text.
- *
- * @param start the index of the first character inclusive.
- * @param end the index of the last character exclusive.
- * @return the sub-text starting at the specified start position and
- * ending just before the specified end position.
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0) ||
- * (start > end) || (end > this.length())</code>
- */
- public Text subtext(int start, int end) {
- if (_data != null) { // Primitive.
- if ((start < 0) || (start > end) || (end > _count))
- throw new IndexOutOfBoundsException();
- if ((start == 0) && (end == _count))
- return this;
- if (start == end)
- return Text.EMPTY;
- int length = end - start;
- Text text = Text.newPrimitive(length);
- System.arraycopy(_data, start, text._data, 0, length);
- return text;
- } else { // Composite.
- final int cesure = _head._count;
- if (end <= cesure)
- return _head.subtext(start, end);
- if (start >= cesure)
- return _tail.subtext(start - cesure, end - cesure);
- if ((start == 0) && (end == _count))
- return this;
- // Overlaps head and tail.
- return _head.subtext(start, cesure).concat(
- _tail.subtext(0, end - cesure));
- }
- }
-
- /**
- * Copies the characters from this text into the destination
- * character array.
- *
- * @param start the index of the first character to copy.
- * @param end the index after the last character to copy.
- * @param dest the destination array.
- * @param destPos the start offset in the destination array.
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0) ||
- * (start > end) || (end > this.length())</code>
- */
- public void getChars(int start, int end, char dest[], int destPos) {
- if (_data != null) { // Primitive.
- if ((start < 0) || (end > _count) || (start > end))
- throw new IndexOutOfBoundsException();
- System.arraycopy(_data, start, dest, destPos, end - start);
- } else { // Composite.
- final int cesure = _head._count;
- if (end <= cesure) {
- _head.getChars(start, end, dest, destPos);
- } else if (start >= cesure) {
- _tail.getChars(start - cesure, end - cesure, dest, destPos);
- } else { // Overlaps head and tail.
- _head.getChars(start, cesure, dest, destPos);
- _tail.getChars(0, end - cesure, dest, destPos + cesure - start);
- }
- }
- }
-
- /**
- * Returns the <code>String</code> representation of this text.
- *
- * @return the <code>java.lang.String</code> for this text.
- */
- public String toString() {
- if (_data != null) { // Primitive.
- return new String(_data, 0, _count);
- } else { // Composite.
- char[] data = new char[_count];
- this.getChars(0, _count, data, 0);
- return new String(data, 0, _count);
- }
- }
-
- // Implements ValueType interface.
- public Text copy() {
- if (_data != null) { // Primitive.
- Text text = Text.newPrimitive(_count);
- System.arraycopy(_data, 0, text._data, 0, _count);
- return text;
- } else { // Composite.
- return Text.newComposite((Text) _head.copy(), (Text) _tail.copy());
- }
- }
-
- //////////////////////////////////////////////////////////////////
- // Wilfried add-ons (methods provided by Microsoft .Net in C#)
- //
- /**
- * Returns the text that contains a specific length sequence of the
- * character specified.
- *
- * @param c the character to fill this text with.
- * @param length the length of the text returned.
- * @return the corresponding instance.
- * @throws IndexOutOfBoundsException if <code>(length < 0)</code>
- */
- public static Text valueOf(char c, int length) {
- if (length < 0)
- throw new IndexOutOfBoundsException();
- if (length <= BLOCK_SIZE) {
- Text text = Text.newPrimitive(length);
- for (int i = 0; i < length;) {
- text._data[i++] = c;
- }
- return text;
- } else {
- final int middle = (length >> 1);
- return Text.newComposite(Text.valueOf(c, middle),
- Text.valueOf(c, length - middle));
- }
- }
-
- /**
- * Indicates if all characters of this text are whitespaces
- * (no characters greater than the space character).
- *
- *@return <code>true</code> if this text contains only whitespace.
- */
- public boolean isBlank() {
- return isBlank(0, length());
- }
-
- /**
- * Indicates if the specified sub-range of characters of this text
- * are whitespaces (no characters greater than the space character).
- *
- *@param start the start index.
- *@param length the number of characters to inspect.
- */
- public boolean isBlank(int start, int length) {
- for (; start < length; start++) {
- if (charAt(start) > ' ')
- return false;
- }
- return true;
- }
-
- /**
- * Returns a copy of this text, with leading whitespace omitted.
- *
- * @return a copy of this text with leading white space removed,
- * or this text if it has no leading white space.
- */
- public Text trimStart() {
- int first = 0; // First character index.
- int last = length() - 1; // Last character index.
- while ((first <= last) && (charAt(first) <= ' ')) {
- first++;
- }
- return subtext(first, last + 1);
- }
-
- /**
- * Returns a copy of this text, with trailing
- * whitespace omitted.
- *
- * @return a copy of this text with trailing white space removed,
- * or this text if it has no trailing white space.
- */
- public Text trimEnd() {
- int first = 0; // First character index.
- int last = length() - 1; // Last character index.
- while ((last >= first) && (charAt(last) <= ' ')) {
- last--;
- }
- return subtext(first, last + 1);
- }
-
- /**
- * Pads this text on the left with spaces to make the minimum total length
- * as specified.
- * The new length of the new text is equal to the original length plus
- * <code>(length()-len)</code> spaces.
- *
- * @param len the total number of characters to make this text equal to.
- * @return a new text or the same text if no padding required.
- * @throws an IllegalArgumentException if the <code>(len<0)</code>.
- */
- public Text padLeft(int len) {
- return padLeft(len, ' ');
- }
-
- /**
- * Pads this text on the left to make the minimum total length as specified.
- * Spaces or the given Unicode character are used to pad with.
- * <br>
- * The new length of the new text is equal to the original length plus
- * <code>(length()-len)</code> pad characters.
- *
- * @param len the total number of characters to make this text equal to.
- * @param c the character to pad using.
- * @return a new text or the same text if no padding required.
- * @throws an IllegalArgumentException if the <code>(len<0)</code>.
- */
- public Text padLeft(int len, char c) {
- final int padSize = (len <= length()) ? 0 : len - length();
- return insert(0, Text.valueOf(c, padSize));
- }
-
- /**
- * Pads this text on the right with spaces to make the minimum total length
- * as specified.
- * The new length of the new text is equal to the original length plus
- * <code>(length()-len)</code> spaces.
- *
- * @param len the total number of characters to make this text equal to.
- * @return a new text or the same text if no padding required.
- * @throws an IllegalArgumentException if the <code>(len<0)</code>.
- */
- public Text padRight(int len) {
- return padRight(len, ' ');
- }
-
- /**
- * Pads this text on the right to make the minimum total length as specified.
- * Spaces or the given Unicode character are used to pad with.
- * <br>
- * The new length of the new text is equal to the original length plus
- * <code>(length()-len)</code> pad characters.
- *
- * @param len the total number of characters to make this text equal to.
- * @param c the character to pad using.
- * @return a new text or the same text if no padding required.
- * @throws an IllegalArgumentException if the <code>(len<0)</code>.
- */
- public Text padRight(int len, char c) {
- final int padSize = (len <= length()) ? 0 : len - length();
- return concat(Text.valueOf(c, padSize));
- }
-
- /**
- * Returns the index within this text of the first occurrence
- * of any character in the specified character set.
- *
- * @param charSet the character set.
- * @return the index of the first character that matches one of the
- * characters in the supplied set; or <code>-1</code> if none.
- */
- public int indexOfAny(CharSet charSet) {
- return indexOfAny(charSet, 0, length());
- }
-
- /**
- * Returns the index within a region of this text of the first occurrence
- * of any character in the specified character set.
- *
- * @param charSet the character set.
- * @param start the index of the start of the search region in this text.
- * @return the index of the first character that matches one of the
- * characters in the supplied set; or <code>-1</code> if none.
- */
- public int indexOfAny(CharSet charSet, int start) {
- return indexOfAny(charSet, start, length() - start);
- }
-
- /**
- * Returns the index within a region of this text of the first occurrence
- * of any character in the specified character set.
- *
- * @param charSet the character set.
- * @param start the index of the start of the search region in this text.
- * @param length the length of the region to search.
- * @return the index of the first character that matches one of the
- * characters in the supplied array; or <code>-1</code> if none.
- */
- public int indexOfAny(CharSet charSet, int start, int length) {
- final int stop = start + length;
- for (int i = start; i < stop; i++) {
- if (charSet.contains(charAt(i)))
- return i;
- }
- return -1;
- }
-
- /**
- * Returns the index within this text of the last occurrence
- * of any character in the specified character set.
- *
- * @param charSet the character set.
- * @return the index of the last character that matches one of the
- * characters in the supplied array; or <code>-1</code> if none.
- */
- public int lastIndexOfAny(CharSet charSet) {
- return lastIndexOfAny(charSet, 0, length());
- }
-
- /**
- * Returns the index within a region of this text of the last occurrence
- * of any character in the specified character set.
- *
- * @param charSet the character set.
- * @param start the index of the start of the search region in this text.
- * @return the index of the last character that matches one of the
- * characters in the supplied array; or <code>-1</code> if none.
- */
- public int lastIndexOfAny(CharSet charSet, int start) {
- return lastIndexOfAny(charSet, start, length() - start);
- }
-
- /**
- * Returns the index within a region of this text of the last occurrence
- * of any character in the specified character set.
- *
- * @param charSet the character set.
- * @param start the index of the start of the search region in this text.
- * @param length the length of the region to search.
- * @return the index of the last character that matches one of the
- * characters in the supplied array; or <code>-1</code> if none.
- */
- public int lastIndexOfAny(CharSet charSet, int start, int length) {
- for (int i = start + length; --i >= start;) {
- if (charSet.contains(charAt(i)))
- return i;
- }
- return -1;
- }
-
- //
- ////////////////////////////////////////////////////////////////////////////
- /**
- * Returns a {@link javolution.context.AllocatorContext context allocated}
- * primitive text instance.
- *
- * @param length the primitive length.
- */
- private static Text newPrimitive(int length) {
- Text text = new Text(true);
- text._count = length;
- return text;
- }
-
- /**
- * Returns a {@link javolution.context.AllocatorContext context allocated}
- * composite text instance.
- *
- * @param head the composite head.
- * @param tail the composite tail.
- */
- private static Text newComposite(Text head, Text tail) {
- Text text = new Text(false);
- text._count = head._count + tail._count;
- text._head = head;
- text._tail = tail;
- return text;
- }
-
- @Override
- public Text value() {
- return this;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/TextBuilder.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/TextBuilder.java b/commons/marmotta-commons/src/ext/java/javolution/text/TextBuilder.java
deleted file mode 100644
index c5f0a9f..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/TextBuilder.java
+++ /dev/null
@@ -1,888 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import java.io.Serializable;
-import javolution.lang.MathLib;
-
-/**
- * <p> An {@link Appendable} text whose capacity expands
- * gently without incurring expensive resize/copy operations ever.</p>
- *
- * <p> This class is not intended for large documents manipulations which
- * should be performed with the {@link Text} class directly
- * (<code>O(Log(n))</code> {@link Text#insert insertion} and
- * {@link Text#delete deletion} capabilities).</p>
- *
- * <p> The textual format of any appended object is retrieved
- * from the current {@link TextContext}.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.3, January 20, 2008
- */
-public class TextBuilder implements Appendable, CharSequence, Serializable {
-
- private static final long serialVersionUID = 0x600L; // Version.
- // We do a full resize (and copy) only when the capacity is less than C1.
- // For large collections, multi-dimensional arrays are employed.
- private static final int B0 = 5; // Initial capacity in bits.
- private static final int C0 = 1 << B0; // Initial capacity (32)
- private static final int B1 = 10; // Low array maximum capacity in bits.
- private static final int C1 = 1 << B1; // Low array maximum capacity (1024).
- private static final int M1 = C1 - 1; // Mask.
- // Resizes up to 1024 maximum (32, 64, 128, 256, 512, 1024).
- private char[] _low = new char[C0];
- // For larger capacity use multi-dimensional array.
- private char[][] _high = new char[1][];
-
- /**
- * Holds the current length.
- */
- private int _length;
-
- /**
- * Holds current capacity.
- */
- private int _capacity = C0;
-
- /**
- * Creates a text builder of small initial capacity.
- */
- public TextBuilder() {
- _high[0] = _low;
- }
-
- /**
- * Creates a text builder holding the specified <code>String</code>
- * (convenience method).
- *
- * @param str the initial string content of this text builder.
- */
- public TextBuilder(String str) {
- this();
- append(str);
- }
-
- /**
- * Creates a text builder of specified initial capacity.
- * Unless the text length exceeds the specified capacity, operations
- * on this text builder will not allocate memory.
- *
- * @param capacity the initial capacity.
- */
- public TextBuilder(int capacity) {
- this();
- while (capacity > _capacity) {
- increaseCapacity();
- }
- }
-
- /**
- * Returns the length (character count) of this text builder.
- *
- * @return the number of characters (16-bits Unicode).
- */
- public final int length() {
- return _length;
- }
-
- /**
- * Returns the character at the specified index.
- *
- * @param index the index of the character.
- * @return the character at the specified index.
- * @throws IndexOutOfBoundsException if
- * <code>(index < 0) || (index >= this.length())</code>.
- */
- public final char charAt(int index) {
- if (index >= _length)
- throw new IndexOutOfBoundsException();
- return index < C1 ? _low[index] : _high[index >> B1][index & M1];
- }
-
- /**
- * Copies the character from this text builder into the destination
- * character array.
- *
- * @param srcBegin this text start index.
- * @param srcEnd this text end index (not included).
- * @param dst the destination array to copy the data into.
- * @param dstBegin the offset into the destination array.
- * @throws IndexOutOfBoundsException if <code>(srcBegin < 0) ||
- * (dstBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.length())
- * || ((dstBegin + srcEnd - srcBegin) > dst.length)</code>
- */
- public final void getChars(int srcBegin, int srcEnd, char[] dst,
- int dstBegin) {
- if ((srcBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this._length))
- throw new IndexOutOfBoundsException();
- for (int i = srcBegin, j = dstBegin; i < srcEnd;) {
- char[] chars0 = _high[i >> B1];
- int i0 = i & M1;
- int length = MathLib.min(C1 - i0, srcEnd - i);
- System.arraycopy(chars0, i0, dst, j, length);
- i += length;
- j += length;
- }
- }
-
- /**
- * Sets the character at the specified position.
- *
- * @param index the index of the character to modify.
- * @param c the new character.
- * @throws IndexOutOfBoundsException if <code>(index < 0) ||
- * (index >= this.length())</code>
- */
- public final void setCharAt(int index, char c) {
- if ((index < 0) || (index >= _length))
- throw new IndexOutOfBoundsException();
- _high[index >> B1][index & M1] = c;
- }
-
- /**
- * Convenience method equivalent to {@link #setLength(int, char)
- * setLength(newLength, '\u0000')}.
- *
- * @param newLength the new length of this builder.
- * @throws IndexOutOfBoundsException if <code>(newLength < 0)</code>
- */
- public final void setLength(int newLength) {
- setLength(newLength, '\u0000');
- }
-
- /**
- * Sets the length of this character builder.
- * If the length is greater than the current length; the
- * specified character is inserted.
- *
- * @param newLength the new length of this builder.
- * @param fillChar the character to be appended if required.
- * @throws IndexOutOfBoundsException if <code>(newLength < 0)</code>
- */
- public final void setLength(int newLength, char fillChar) {
- if (newLength < 0)
- throw new IndexOutOfBoundsException();
- if (newLength <= _length)
- _length = newLength;
- else
- for (int i = _length; i++ < newLength;) {
- append(fillChar);
- }
- }
-
- /**
- * Returns a {@link java.lang.CharSequence} corresponding
- * to the character sequence between the specified indexes.
- *
- * @param start the index of the first character inclusive.
- * @param end the index of the last character exclusive.
- * @return a character sequence.
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0) ||
- * (start > end) || (end > this.length())</code>
- */
- public final java.lang.CharSequence subSequence(int start, int end) {
- if ((start < 0) || (end < 0) || (start > end) || (end > _length))
- throw new IndexOutOfBoundsException();
- return Text.valueOf(this, start, end);
- }
-
- /**
- * Appends the specified character.
- *
- * @param c the character to append.
- * @return <code>this</code>
- */
- public final TextBuilder append(char c) {
- if (_length >= _capacity)
- increaseCapacity();
- _high[_length >> B1][_length & M1] = c;
- _length++;
- return this;
- }
-
- /**
- * Appends the textual representation of the specified object.
- * This method is equivalent to
- * {@code TextContext.getFormat(obj.getClass()).format(obj, this)}
- */
- public final TextBuilder append(Object obj) {
- if (obj == null) return append("null");
- TextFormat<Object> textFormat = TextContext.getFormat(obj.getClass());
- if (textFormat == null) return append(obj.toString());
- return textFormat.format(obj, this);
- }
-
- /**
- * Appends the specified character sequence. If the specified character
- * sequence is <code>null</code> this method is equivalent to
- * <code>append("null")</code>.
- *
- * @param csq the character sequence to append or <code>null</code>.
- * @return <code>this</code>
- */
- public final TextBuilder append(CharSequence csq) {
- return (csq == null) ? append("null") : append(csq, 0, csq.length());
- }
-
- /**
- * Appends a subsequence of the specified character sequence.
- * If the specified character sequence is <code>null</code> this method
- * is equivalent to <code>append("null")</code>.
- *
- * @param csq the character sequence to append or <code>null</code>.
- * @param start the index of the first character to append.
- * @param end the index after the last character to append.
- * @return <code>this</code>
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0)
- * || (start > end) || (end > csq.length())</code>
- */
- public final TextBuilder append(CharSequence csq, int start,
- int end) {
- if (csq == null)
- return append("null");
- if ((start < 0) || (end < 0) || (start > end) || (end > csq.length()))
- throw new IndexOutOfBoundsException();
- for (int i = start; i < end;) {
- append(csq.charAt(i++));
- }
- return this;
- }
-
- /**
- * Appends the specified string to this text builder.
- * If the specified string is <code>null</code> this method
- * is equivalent to <code>append("null")</code>.
- *
- * @param str the string to append or <code>null</code>.
- * @return <code>this</code>
- */
- public final TextBuilder append(String str) {
- return (str == null) ? append("null") : append(str, 0, str.length());
- }
-
- /**
- * Appends a subsequence of the specified string.
- * If the specified character sequence is <code>null</code> this method
- * is equivalent to <code>append("null")</code>.
- *
- * @param str the string to append or <code>null</code>.
- * @param start the index of the first character to append.
- * @param end the index after the last character to append.
- * @return <code>this</code>
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0)
- * || (start > end) || (end > str.length())</code>
- */
- public final TextBuilder append(String str, int start, int end) {
- if (str == null)
- return append("null");
- if ((start < 0) || (end < 0) || (start > end) || (end > str.length()))
- throw new IndexOutOfBoundsException("start: " + start + ", end: "
- + end + ", str.length(): " + str.length());
- int newLength = _length + end - start;
- while (_capacity < newLength) {
- increaseCapacity();
- }
- for (int i = start, j = _length; i < end;) {
- char[] chars = _high[j >> B1];
- int dstBegin = j & M1;
- int inc = MathLib.min(C1 - dstBegin, end - i);
- str.getChars(i, (i += inc), chars, dstBegin);
- j += inc;
- }
- _length = newLength;
- return this;
- }
-
- /**
- * Appends the specified text to this text builder.
- * If the specified text is <code>null</code> this method
- * is equivalent to <code>append("null")</code>.
- *
- * @param txt the text to append or <code>null</code>.
- * @return <code>this</code>
- */
- public final TextBuilder append(Text txt) {
- return (txt == null) ? append("null") : append(txt, 0, txt.length());
- }
-
- /**
- * Appends a subsequence of the specified text.
- * If the specified character sequence is <code>null</code> this method
- * is equivalent to <code>append("null")</code>.
- *
- * @param txt the text to append or <code>null</code>.
- * @param start the index of the first character to append.
- * @param end the index after the last character to append.
- * @return <code>this</code>
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0)
- * || (start > end) || (end > txt.length())</code>
- */
- public final TextBuilder append(Text txt, int start, int end) {
- if (txt == null)
- return append("null");
- if ((start < 0) || (end < 0) || (start > end) || (end > txt.length()))
- throw new IndexOutOfBoundsException();
- int newLength = _length + end - start;
- while (_capacity < newLength) {
- increaseCapacity();
- }
- for (int i = start, j = _length; i < end;) {
- char[] chars = _high[j >> B1];
- int dstBegin = j & M1;
- int inc = MathLib.min(C1 - dstBegin, end - i);
- txt.getChars(i, (i += inc), chars, dstBegin);
- j += inc;
- }
- _length = newLength;
- return this;
- }
-
- /**
- * Appends the characters from the char array argument.
- *
- * @param chars the character array source.
- * @return <code>this</code>
- */
- public final TextBuilder append(char chars[]) {
- append(chars, 0, chars.length);
- return this;
- }
-
- /**
- * Appends the characters from a subarray of the char array argument.
- *
- * @param chars the character array source.
- * @param offset the index of the first character to append.
- * @param length the number of character to append.
- * @return <code>this</code>
- * @throws IndexOutOfBoundsException if <code>(offset < 0) ||
- * (length < 0) || ((offset + length) > chars.length)</code>
- */
- public final TextBuilder append(char chars[], int offset, int length) {
- final int end = offset + length;
- if ((offset < 0) || (length < 0) || (end > chars.length))
- throw new IndexOutOfBoundsException();
- int newLength = _length + length;
- while (_capacity < newLength) {
- increaseCapacity();
- }
- for (int i = offset, j = _length; i < end;) {
- char[] dstChars = _high[j >> B1];
- int dstBegin = j & M1;
- int inc = MathLib.min(C1 - dstBegin, end - i);
- System.arraycopy(chars, i, dstChars, dstBegin, inc);
- i += inc;
- j += inc;
- }
- _length = newLength;
- return this;
- }
-
- /**
- * Appends the textual representation of the specified <code>boolean</code>
- * argument.
- *
- * @param b the <code>boolean</code> to format.
- * @return <code>this</code>
- * @see TypeFormat
- */
- public final TextBuilder append(boolean b) {
- return b ? append("true") : append("false");
- }
-
- /**
- * Appends the decimal representation of the specified <code>int</code>
- * argument.
- *
- * @param i the <code>int</code> to format.
- * @return <code>this</code>
- */
- public final TextBuilder append(int i) {
- if (i <= 0) {
- if (i == 0)
- return append("0");
- if (i == Integer.MIN_VALUE) // Negation would overflow.
- return append("-2147483648");
- append('-');
- i = -i;
- }
- int digits = MathLib.digitLength(i);
- if (_capacity < _length + digits)
- increaseCapacity();
- _length += digits;
- for (int index = _length - 1;; index--) {
- int j = i / 10;
- _high[index >> B1][index & M1] = (char) ('0' + i - (j * 10));
- if (j == 0)
- return this;
- i = j;
- }
- }
-
- /**
- * Appends the radix representation of the specified <code>int</code>
- * argument.
- *
- * @param i the <code>int</code> to format.
- * @param radix the radix (e.g. <code>16</code> for hexadecimal).
- * @return <code>this</code>
- */
- public final TextBuilder append(int i, int radix) {
- if (radix == 10)
- return append(i); // Faster.
- if (radix < 2 || radix > 36)
- throw new IllegalArgumentException("radix: " + radix);
- if (i < 0) {
- append('-');
- if (i == Integer.MIN_VALUE) { // Negative would overflow.
- appendPositive(-(i / radix), radix);
- return (TextBuilder) append(DIGIT_TO_CHAR[-(i % radix)]);
- }
- i = -i;
- }
- appendPositive(i, radix);
- return this;
- }
-
- private void appendPositive(int l1, int radix) {
- if (l1 >= radix) {
- int l2 = l1 / radix;
- // appendPositive(l2, radix);
- if (l2 >= radix) {
- int l3 = l2 / radix;
- // appendPositive(l3, radix);
- if (l3 >= radix) {
- int l4 = l3 / radix;
- appendPositive(l4, radix);
- append(DIGIT_TO_CHAR[l3 - (l4 * radix)]);
- } else
- append(DIGIT_TO_CHAR[l3]);
- append(DIGIT_TO_CHAR[l2 - (l3 * radix)]);
- } else
- append(DIGIT_TO_CHAR[l2]);
- append(DIGIT_TO_CHAR[l1 - (l2 * radix)]);
- } else
- append(DIGIT_TO_CHAR[l1]);
- }
-
- private final static char[] DIGIT_TO_CHAR = { '0', '1', '2', '3', '4', '5',
- '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
- 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
- 'w', 'x', 'y', 'z' };
-
- /**
- * Appends the decimal representation of the specified <code>long</code>
- * argument.
- *
- * @param l the <code>long</code> to format.
- * @return <code>this</code>
- */
- public final TextBuilder append(long l) {
- if (l <= 0) {
- if (l == 0)
- return append("0");
- if (l == Long.MIN_VALUE) // Negation would overflow.
- return append("-9223372036854775808");
- append('-');
- l = -l;
- }
- if (l <= Integer.MAX_VALUE)
- return append((int) l);
- append(l / 1000000000);
- int i = (int) (l % 1000000000);
- int digits = MathLib.digitLength(i);
- append("000000000", 0, 9 - digits);
- return append(i);
- }
-
- /**
- * Appends the radix representation of the specified <code>long</code>
- * argument.
- *
- * @param l the <code>long</code> to format.
- * @param radix the radix (e.g. <code>16</code> for hexadecimal).
- * @return <code>this</code>
- */
- public final TextBuilder append(long l, int radix) {
- if (radix == 10)
- return append(l); // Faster.
- if (radix < 2 || radix > 36)
- throw new IllegalArgumentException("radix: " + radix);
- if (l < 0) {
- append('-');
- if (l == Long.MIN_VALUE) { // Negative would overflow.
- appendPositive(-(l / radix), radix);
- return (TextBuilder) append(DIGIT_TO_CHAR[(int) -(l % radix)]);
- }
- l = -l;
- }
- appendPositive(l, radix);
- return this;
- }
-
- private void appendPositive(long l1, int radix) {
- if (l1 >= radix) {
- long l2 = l1 / radix;
- // appendPositive(l2, radix);
- if (l2 >= radix) {
- long l3 = l2 / radix;
- // appendPositive(l3, radix);
- if (l3 >= radix) {
- long l4 = l3 / radix;
- appendPositive(l4, radix);
- append(DIGIT_TO_CHAR[(int) (l3 - (l4 * radix))]);
- } else
- append(DIGIT_TO_CHAR[(int) l3]);
- append(DIGIT_TO_CHAR[(int) (l2 - (l3 * radix))]);
- } else
- append(DIGIT_TO_CHAR[(int) l2]);
- append(DIGIT_TO_CHAR[(int) (l1 - (l2 * radix))]);
- } else
- append(DIGIT_TO_CHAR[(int) l1]);
- }
-
- /**
- * Appends the textual representation of the specified <code>float</code>.
- *
- * @param f the <code>float</code> to format.
- * @return <code>append(f, 10, (abs(f) >= 1E7) || (abs(f) < 0.001), false)</code>
- */
- public final TextBuilder append(float f) {
- return append(f, 10, (MathLib.abs(f) >= 1E7)
- || (MathLib.abs(f) < 0.001), false);
- }
-
- /**
- * Appends the textual representation of the specified <code>double</code>;
- * the number of digits is 17 or 16 when the 16 digits representation
- * can be parsed back to the same <code>double</code> (mimic the standard
- * library formatting).
- *
- * @param d the <code>double</code> to format.
- * @return <code>append(d, -1, (MathLib.abs(d) >= 1E7) ||
- * (MathLib.abs(d) < 0.001), false)</code>
- */
- public final TextBuilder append(double d) {
- return append(d, -1, (MathLib.abs(d) >= 1E7)
- || (MathLib.abs(d) < 0.001), false);
- }
-
- /**
- * Appends the textual representation of the specified <code>double</code>
- * according to the specified formatting arguments.
- *
- * @param d the <code>double</code> value.
- * @param digits the number of significative digits (excludes exponent) or
- * <code>-1</code> to mimic the standard library (16 or 17 digits).
- * @param scientific <code>true</code> to forces the use of the scientific
- * notation (e.g. <code>1.23E3</code>); <code>false</code>
- * otherwise.
- * @param showZero <code>true</code> if trailing fractional zeros are
- * represented; <code>false</code> otherwise.
- * @return <code>TypeFormat.format(d, digits, scientific, showZero, this)</code>
- * @throws IllegalArgumentException if <code>(digits > 19)</code>)
- */
- public final TextBuilder append(double d, int digits, boolean scientific,
- boolean showZero) {
- if (digits > 19)
- throw new IllegalArgumentException("digits: " + digits);
- if (d != d) // NaN
- return append("NaN");
- if (d == Double.POSITIVE_INFINITY)
- return append("Infinity");
- if (d == Double.NEGATIVE_INFINITY)
- return append("-Infinity");
- if (d == 0.0) { // Zero.
- if (digits < 0)
- return append("0.0");
- append('0');
- if (showZero) {
- append('.');
- for (int j = 1; j < digits; j++) {
- append('0');
- }
- }
- return this;
- }
- if (d < 0) { // Work with positive number.
- d = -d;
- append('-');
- }
-
- // Find the exponent e such as: value == x.xxx * 10^e
- int e = MathLib.floorLog10(d);
-
- long m;
- if (digits < 0) { // Use 16 or 17 digits.
- // Try 17 digits.
- long m17 = MathLib.toLongPow10(d, (17 - 1) - e);
- // Check if we can use 16 digits.
- long m16 = m17 / 10;
- double dd = MathLib.toDoublePow10(m16, e - 16 + 1);
- if (dd == d) { // 16 digits is enough.
- digits = 16;
- m = m16;
- } else { // We cannot remove the last digit.
- digits = 17;
- m = m17;
- }
- } else
- // Use the specified number of digits.
- m = MathLib.toLongPow10(d, (digits - 1) - e);
-
- // Formats.
- if (scientific || (e >= digits)) {
- // Scientific notation has to be used ("x.xxxEyy").
- long pow10 = POW10_LONG[digits - 1];
- int k = (int) (m / pow10); // Single digit.
- append((char) ('0' + k));
- m = m - pow10 * k;
- appendFraction(m, digits - 1, showZero);
- append('E');
- append(e);
- } else { // Dot within the string ("xxxx.xxxxx").
- int exp = digits - e - 1;
- if (exp < POW10_LONG.length) {
- long pow10 = POW10_LONG[exp];
- long l = m / pow10;
- append(l);
- m = m - pow10 * l;
- } else
- append('0'); // Result of the division by a power of 10 larger than any long.
- appendFraction(m, exp, showZero);
- }
- return this;
- }
-
- private void appendFraction(long l, int digits, boolean showZero) {
- append('.');
- if (l == 0)
- if (showZero)
- for (int i = 0; i < digits; i++) {
- append('0');
- }
- else
- append('0');
- else { // l is different from zero.
- int length = MathLib.digitLength(l);
- for (int j = length; j < digits; j++) {
- append('0'); // Add leading zeros.
- }
- if (!showZero)
- while (l % 10 == 0) {
- l /= 10; // Remove trailing zeros.
- }
- append(l);
- }
- }
-
- private static final long[] POW10_LONG = new long[] { 1L, 10L, 100L, 1000L,
- 10000L, 100000L, 1000000L, 10000000L, 100000000L, 1000000000L,
- 10000000000L, 100000000000L, 1000000000000L, 10000000000000L,
- 100000000000000L, 1000000000000000L, 10000000000000000L,
- 100000000000000000L, 1000000000000000000L };
-
- /**
- * Inserts the specified character sequence at the specified location.
- *
- * @param index the insertion position.
- * @param csq the character sequence being inserted.
- * @return <code>this</code>
- * @throws IndexOutOfBoundsException if <code>(index < 0) ||
- * (index > this.length())</code>
- */
- public final TextBuilder insert(int index, java.lang.CharSequence csq) {
- if ((index < 0) || (index > _length))
- throw new IndexOutOfBoundsException("index: " + index);
- final int shift = csq.length();
- int newLength = _length + shift;
- while (newLength >= _capacity) {
- increaseCapacity();
- }
- _length = newLength;
- for (int i = _length - shift; --i >= index;) {
- this.setCharAt(i + shift, this.charAt(i));
- }
- for (int i = csq.length(); --i >= 0;) {
- this.setCharAt(index + i, csq.charAt(i));
- }
- return this;
- }
-
- /**
- * Removes all the characters of this text builder
- * (equivalent to <code>this.delete(start, this.length())</code>).
- *
- * @return <code>this.delete(0, this.length())</code>
- */
- public final TextBuilder clear() {
- _length = 0;
- return this;
- }
-
- /**
- * Removes the characters between the specified indices.
- *
- * @param start the beginning index, inclusive.
- * @param end the ending index, exclusive.
- * @return <code>this</code>
- * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0)
- * || (start > end) || (end > this.length())</code>
- */
- public final TextBuilder delete(int start, int end) {
- if ((start < 0) || (end < 0) || (start > end) || (end > this.length()))
- throw new IndexOutOfBoundsException();
- for (int i = end, j = start; i < _length;) {
- this.setCharAt(j++, this.charAt(i++));
- }
- _length -= end - start;
- return this;
- }
-
- /**
- * Reverses this character sequence.
- *
- * @return <code>this</code>
- */
- public final TextBuilder reverse() {
- final int n = _length - 1;
- for (int j = (n - 1) >> 1; j >= 0;) {
- char c = charAt(j);
- setCharAt(j, charAt(n - j));
- setCharAt(n - j--, c);
- }
- return this;
- }
-
- /**
- * Returns the {@link Text} corresponding to this {@link TextBuilder}.
- *
- * @return the corresponding {@link Text} instance.
- */
- public final Text toText() {
- return Text.valueOf(this, 0, _length);
- }
-
- /**
- * Returns the <code>String</code> representation of this
- * {@link TextBuilder}.
- *
- * @return the <code>java.lang.String</code> for this text builder.
- */
- @Override
- public final String toString() {
- return (_length < C1) ? new String(_low, 0, _length) : toLargeString();
- }
-
- private String toLargeString() {
- char[] data = new char[_length];
- this.getChars(0, _length, data, 0);
- return new String(data, 0, _length);
- }
-
- /**
- * Returns the <code>CharArray</code> representation of this
- * {@link TextBuilder}.
- *
- * @return the corresponding {@link CharArray} instance.
- */
- public final CharArray toCharArray() {
- CharArray cArray = new CharArray();
- char[] data;
- if (_length < C1) {
- data = _low;
- } else {
- data = new char[_length];
- this.getChars(0, _length, data, 0);
- }
- cArray.setArray(data, 0, _length);
- return cArray;
- }
-
- /**
- * Returns the hash code for this text builder.
- *
- * @return the hash code value.
- */
- @Override
- public final int hashCode() {
- int h = 0;
- for (int i = 0; i < _length;) {
- h = 31 * h + charAt(i++);
- }
- return h;
- }
-
- /**
- * Compares this text builder against the specified object for equality.
- * Returns <code>true</code> if the specified object is a text builder
- * having the same character content.
- *
- * @param obj the object to compare with or <code>null</code>.
- * @return <code>true</code> if that is a text builder with the same
- * character content as this text; <code>false</code> otherwise.
- */
- @Override
- public final boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!(obj instanceof TextBuilder))
- return false;
- TextBuilder that = (TextBuilder) obj;
- if (this._length != that._length)
- return false;
- for (int i = 0; i < _length;) {
- if (this.charAt(i) != that.charAt(i++))
- return false;
- }
- return true;
- }
-
- /**
- * Indicates if this text builder has the same character content as the
- * specified character sequence.
- *
- * @param csq the character sequence to compare with.
- * @return <code>true</code> if the specified character sequence has the
- * same character content as this text; <code>false</code> otherwise.
- */
- public final boolean contentEquals(java.lang.CharSequence csq) {
- if (csq.length() != _length)
- return false;
- for (int i = 0; i < _length;) {
- char c = _high[i >> B1][i & M1];
- if (csq.charAt(i++) != c)
- return false;
- }
- return true;
- }
-
- /**
- * Increases this text builder capacity.
- */
- private void increaseCapacity() {
- if (_capacity < C1) { // For small capacity, resize.
- _capacity <<= 1;
- char[] tmp = new char[_capacity];
- System.arraycopy(_low, 0, tmp, 0, _length);
- _low = tmp;
- _high[0] = tmp;
- } else { // Add a new low block of 1024 elements.
- int j = _capacity >> B1;
- if (j >= _high.length) { // Resizes _high.
- char[][] tmp = new char[_high.length * 2][];
- System.arraycopy(_high, 0, tmp, 0, _high.length);
- _high = tmp;
- }
- _high[j] = new char[C1];
- _capacity += C1;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/TextContext.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/TextContext.java b/commons/marmotta-commons/src/ext/java/javolution/text/TextContext.java
deleted file mode 100644
index cc8311b..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/TextContext.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import javolution.context.AbstractContext;
-import javolution.context.FormatContext;
-import javolution.osgi.internal.OSGiServices;
-
-/**
- * <p> A context for plain text parsing/formatting. This context provides
- * the {@link javolution.text.TextFormat TextFormat} to parse/format objects
- * of any class. If not superseded, the text format for a class is specified
- * by the {@link javolution.text.DefaultTextFormat DefaultTextFormat}
- * annotation.</p>
- *
- * <p> A text context always returns the most specialized format. If the class
- * has no default format annotation (inherited or not), then the default
- * {@link java.lang.Object} format (which calls {@link Object#toString})
- * is returned. A predefined format exists for the following standard types:
- * <code><ul>
- * <li>java.lang.Object (parsing not supported, formatting calls toString())</li>
- * <li>java.lang.Boolean</li>
- * <li>java.lang.Character</li>
- * <li>java.lang.Byte</li>
- * <li>java.lang.Short</li>
- * <li>java.lang.Integer</li>
- * <li>java.lang.Long</li>
- * <li>java.lang.Float</li>
- * <li>java.lang.Double</li>
- * <li>java.lang.Class</li>
- * <li>java.lang.String</li>
- * <li>java.util.Date (ISO 8601)</li>
- * <li>java.math.BigInteger</li>
- * <li>java.math.BigDecimal</li>
- * <li>java.awt.Color (hexadecimal RGB value, e.g. {@code 0x112233})</li>
- * <li>java.awt.Font</li>
- * </ul></code>
- * </p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0 December 12, 2012
- */
-public abstract class TextContext extends FormatContext {
-
- /**
- * Default constructor.
- */
- protected TextContext() {}
-
- /**
- * Enters and returns a new text context instance.
- */
- public static TextContext enter() {
- return (TextContext) TextContext.currentTextContext().enterInner();
- }
-
- /**
- * Returns the text format for the specified type. It is the most
- * specialized format able to parse/format instances of the specified
- * class. If there is no default format for the specified class,
- * the standard object format (toString based) is returned.
- */
- public static <T> TextFormat<T> getFormat(Class<? extends T> type) {
- return TextContext.currentTextContext().searchFormat(type);
- }
-
- /**
- * Sets the text format for the specified type (and its sub-types).
- */
- public abstract <T> void setFormat(Class<? extends T> type,
- TextFormat<T> newFormat);
-
- /**
- * Searches the most specialized format for the specified type.
- */
- protected abstract <T> TextFormat<T> searchFormat(Class<? extends T> type);
-
- /**
- * Returns the current text context.
- */
- private static TextContext currentTextContext() {
- TextContext ctx = AbstractContext.current(TextContext.class);
- if (ctx != null)
- return ctx;
- return OSGiServices.getTextContext();
- }
-}
\ No newline at end of file
[04/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamReaderImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamReaderImpl.java b/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamReaderImpl.java
deleted file mode 100644
index 57066fa..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/xml/internal/stream/XMLStreamReaderImpl.java
+++ /dev/null
@@ -1,1523 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.xml.internal.stream;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.util.Map;
-import javolution.io.UTF8StreamReader;
-import javolution.lang.Realtime;
-import javolution.text.CharArray;
-import javolution.xml.sax.Attributes;
-import javolution.xml.stream.Location;
-import javolution.xml.stream.NamespaceContext;
-import javolution.xml.stream.XMLInputFactory;
-import javolution.xml.stream.XMLStreamConstants;
-import javolution.xml.stream.XMLStreamException;
-import javolution.xml.stream.XMLStreamReader;
-
-/**
- * {@link XMLStreamReader} implementation.
- *
- * This implementation returns all contiguous character data in a single
- * chunk (always coalescing). It is non-validating (DTD is returned
- * unparsed). Although, users may define custom entities mapping using
- * the {@link #setEntities} method (e.g. after parsing/resolving
- * external entities).
- */
-@Realtime
-public final class XMLStreamReaderImpl implements XMLStreamReader {
-
- /**
- * Holds the textual representation for events.
- */
- static final String[] NAMES_OF_EVENTS = new String[] { "UNDEFINED",
- "START_ELEMENT", "END_ELEMENT", "PROCESSING_INSTRUCTIONS",
- "CHARACTERS", "COMMENT", "SPACE", "START_DOCUMENT", "END_DOCUMENT",
- "ENTITY_REFERENCE", "ATTRIBUTE", "DTD", "CDATA", "NAMESPACE",
- "NOTATION_DECLARATION", "ENTITY_DECLARATION" };
-
- /**
- * Holds the reader buffer capacity.
- */
- static final int READER_BUFFER_CAPACITY = 4096;
-
- /**
- * Holds the prolog if any.
- */
- CharArray _prolog;
-
- /**
- * Holds the current index in the character buffer.
- */
- private int _readIndex;
-
- /**
- * Number of characters read from reader
- */
- private int _readCount;
-
- /**
- * Holds the data buffer for CharSequence produced by this parser.
- */
- private char[] _data = new char[READER_BUFFER_CAPACITY * 2];
-
- /**
- * Holds the current index of the data buffer (_data).
- */
- private int _index;
-
- /**
- * Holds the current element nesting.
- */
- private int _depth;
-
- /**
- * Holds qualified name (include prefix).
- */
- private CharArray _qName;
-
- /**
- * Holds element prefix separator index.
- */
- private int _prefixSep;
-
- /**
- * Holds attribute qualified name.
- */
- private CharArray _attrQName;
-
- /**
- * Holds attribute prefix separator index.
- */
- private int _attrPrefixSep;
-
- /**
- * Holds attribute value.
- */
- private CharArray _attrValue;
-
- /**
- * Holds current event type
- */
- private int _eventType = START_DOCUMENT;
-
- /**
- * Indicates if event type is START_TAG, and tag is empty, i.e. <sometag/>
- */
- private boolean _isEmpty;
-
- /**
- * Indicates if characters are pending for potential coalescing.
- */
- boolean _charactersPending = false;
-
- /**
- * Holds the start index for the current state within _data array.
- */
- private int _start;
-
- /**
- * Holds the parser state.
- */
- private int _state = STATE_CHARACTERS;
-
- /**
- * Holds the current text.
- */
- private CharArray _text;
-
- /**
- * Holds the reader input source (<code>null</code> when unused).
- */
- private Reader _reader;
-
- /**
- * Holds the character buffer used for reading.
- */
- private final char[] _readBuffer = new char[READER_BUFFER_CAPACITY];
-
- /**
- * Holds the start offset in the character buffer (due to auto detection
- * of encoding).
- */
- private int _startOffset; // Byte Order Mark count.
-
- /**
- * Holds the location object.
- */
- private final LocationImpl _location = new LocationImpl();
-
- /**
- * Holds the namespace stack.
- */
- private final NamespacesImpl _namespaces = new NamespacesImpl();
-
- /**
- * Holds the current attributes.
- */
- private final AttributesImpl _attributes = new AttributesImpl(_namespaces);
-
- /**
- * Holds working stack (by nesting level).
- */
- private CharArray[] _elemStack = new CharArray[16];
-
- /**
- * Holds stream encoding if known.
- */
- private String _encoding;
-
- /**
- * Holds the entities.
- */
- private final EntitiesImpl _entities = new EntitiesImpl();
-
- /**
- * Holds the reader for input streams.
- */
- private final UTF8StreamReader _utf8StreamReader = new UTF8StreamReader();
-
- /**
- * Holds the factory (if any)
- */
- private final XMLInputFactoryImpl _factory;
-
- /**
- * Default constructor.
- */
- public XMLStreamReaderImpl() {
- this(null);
- }
-
- /**
- * Factory-based constructor.
- */
- XMLStreamReaderImpl(XMLInputFactoryImpl factory) {
- _factory = factory;
- }
-
- /**
- * Sets the input stream source for this XML stream reader
- * (encoding retrieved from XML prolog if any). This method
- * attempts to detect the encoding automatically.
- *
- * @param in the input source with unknown encoding.
- */
- public void setInput(InputStream in) throws XMLStreamException {
- setInput(in, detectEncoding(in));
- CharArray prologEncoding = getCharacterEncodingScheme();
-
- // Checks if necessary to change the reader.
- if ((prologEncoding != null) && !prologEncoding.equals(_encoding)
- && !(isUTF8(prologEncoding) && isUTF8(_encoding))) {
- // Changes reader (keep characters already read).
- int startOffset = _readCount;
- reset();
- _startOffset = startOffset;
- setInput(in, prologEncoding.toString());
- }
- }
-
- private static boolean isUTF8(Object encoding) {
- return encoding.equals("utf-8") || encoding.equals("UTF-8")
- || encoding.equals("ASCII") || encoding.equals("utf8")
- || encoding.equals("UTF8");
- }
-
- /**
- * Sets the input stream source and encoding for this XML stream reader.
- *
- * @param in the input source.
- * @param encoding the associated encoding.
- */
- public void setInput(InputStream in, String encoding)
- throws XMLStreamException {
- _encoding = encoding;
- if (isUTF8(encoding)) { // Use our fast UTF-8 Reader.
- setInput(_utf8StreamReader.setInput(in));
- } else {
- try {
- setInput(new InputStreamReader(in, encoding));
- } catch (UnsupportedEncodingException e) {
- throw new XMLStreamException(e);
- }
- }
- }
-
- /**
- * Sets the reader input source for this XML stream reader.
- * This method reads the prolog (if any).
- *
- * @param reader the input source reader.
- * @see javolution.io.UTF8StreamReader
- * @see javolution.io.UTF8ByteBufferReader
- * @see javolution.io.CharSequenceReader
- */
- public void setInput(Reader reader) throws XMLStreamException {
- if (_reader != null)
- throw new IllegalStateException("Reader not closed or reset");
- _reader = reader;
- try { // Reads prolog (if there)
- int readCount = reader.read(_readBuffer, _startOffset,
- _readBuffer.length - _startOffset);
- _readCount = (readCount >= 0) ? readCount + _startOffset
- : _startOffset;
- if ((_readCount >= 5) && (_readBuffer[0] == '<')
- && (_readBuffer[1] == '?') && (_readBuffer[2] == 'x')
- && (_readBuffer[3] == 'm') && (_readBuffer[4] == 'l')
- && (_readBuffer[5] == ' ')) { // Prolog detected.
- next(); // Processing instruction.
- _prolog = this.getPIData();
- _index = _prolog.offset() + _prolog.length(); // Keep prolog.
- _start = _index; // Default state.
- _eventType = START_DOCUMENT; // Resets to START_DOCUMENT.
- }
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- }
-
- /**
- * Returns the current depth of the element. Outside the root element,
- * the depth is 0. The depth is incremented by 1 when a start tag is
- * reached. The depth is decremented AFTER the end tag event was observed.
- * [code]
- * <!-- outside --> 0
- * <root> 1
- * sometext 1
- * <foobar> 2
- * </foobar> 2
- * </root> 1
- * <!-- outside --> 0 [/code]
- *
- * @return the nesting depth.
- */
- public int getDepth() {
- return _depth;
- }
-
- /**
- * Returns the qualified name of the current event.
- *
- * @return the qualified name.
- * @throws IllegalStateException if this not a START_ELEMENT or END_ELEMENT.
- */
- public CharArray getQName() {
- if ((_eventType != XMLStreamConstants.START_ELEMENT)
- && (_eventType != XMLStreamConstants.END_ELEMENT))
- throw new IllegalStateException(
- "Not a start element or an end element");
- return _qName;
- }
-
- /**
- * Returns the qualified name of the element at the specified level.
- * This method can be used to retrieve the XPath of the current element.
- *
- * @return the qualified name of the element at the specified level.
- * @throws IllegalArgumentException if <code>depth > getDepth()</code>
- */
- public CharArray getQName(int depth) {
- if (depth > this.getDepth())
- throw new IllegalArgumentException();
- return _elemStack[depth];
- }
-
- /**
- * Returns the current attributes (SAX2-Like).
- *
- * @return returns the number of attributes.
- * @throws IllegalStateException if not a START_ELEMENT.
- */
- public Attributes getAttributes() {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw new IllegalStateException("Not a start element");
- return _attributes;
- }
-
- /**
- * Defines a custom entities to replacement text mapping for this reader.
- * For example:[code]
- * FastMap<String, String> HTML_ENTITIES = new FastMap<String, String>();
- * HTML_ENTITIES.put("nbsp", " ");
- * HTML_ENTITIES.put("copy", "©");
- * HTML_ENTITIES.put("eacute", "é");
- * ...
- * XMLStreamReaderImpl reader = new XMLStreamReaderImpl();
- * reader.setEntities(HTML_ENTITIES);
- * [/code]
- * The entities mapping may be changed dynamically (e.g.
- * after reading the DTD and all external entities references are resolved).
- *
- * @param entities the entities to replacement texts mapping
- * (both must be <code>CharSequence</code> instances).
- */
- public void setEntities(Map<String, String> entities) {
- _entities.setEntitiesMapping(entities);
- }
-
- /**
- * Returns the textual representation of this reader current state.
- *
- * @return the textual representation of the current state.
- */
- public String toString() {
- return "XMLStreamReader - State: " + NAMES_OF_EVENTS[_eventType]
- + ", Location: " + _location.toString();
- }
-
- // Implements XMLStreamReader Interface.
- public int next() throws XMLStreamException {
-
- // Clears previous state.
- if (_eventType == START_ELEMENT) {
- if (_isEmpty) { // Previous empty tag, generates END_TAG automatically.
- _isEmpty = false;
- return _eventType = END_ELEMENT;
- }
- } else if (_eventType == END_ELEMENT) {
- _namespaces.pop();
- CharArray startElem = _elemStack[_depth--];
- _start = _index = startElem.offset();
- while (_seqs[--_seqsIndex] != startElem) { // Recycles CharArray instances.
- }
- }
- // Reader loop.
- while (true) {
-
- // Main character reading block.
- if ((_readIndex >= _readCount) && isEndOfStream())
- return _eventType; // END_DOCUMENT or CHARACTERS.
- char c = _readBuffer[_readIndex++];
- if (c <= '&')
- c = (c == '&') ? replaceEntity()
- : (c < ' ') ? handleEndOfLine(c) : c;
- _data[_index++] = c;
-
- // Main processing.
- //
- switch (_state) {
-
- case STATE_CHARACTERS:
- while (true) { // Read characters data all at once.
-
- if (c == '<') {
- int length = _index - _start - 1;
- if (length > 0) {
- if (_charactersPending) {
- _text.setArray(_data, _text.offset(),
- _text.length() + length); // Coalescing.
- } else {
- _text = newSeq(_start, length);
- _charactersPending = true;
- }
- _start = _index - 1; // Keeps '<' as part of markup.
- }
- _state = STATE_MARKUP;
- break;
- }
-
- // Local character reading block.
- if ((_readIndex >= _readCount) && isEndOfStream())
- return _eventType;
- c = _readBuffer[_readIndex++];
- if (c <= '&')
- c = (c == '&') ? replaceEntity()
- : (c < ' ') ? handleEndOfLine(c) : c;
- _data[_index++] = c;
- }
- break;
-
- case STATE_CDATA:
- while (true) { // Reads CDATA all at once.
-
- if ((c == '>') && (_index - _start >= 3)
- && (_data[_index - 2] == ']')
- && (_data[_index - 3] == ']')) {
- _index -= 3;
- int length = _index - _start;
- if (length > 0) { // Not empty.
- if (_charactersPending) {
- _text.setArray(_data, _text.offset(),
- _text.length() + length); // Coalescing.
- } else {
- _text = newSeq(_start, length);
- _charactersPending = true;
- }
- }
- _start = _index;
- _state = STATE_CHARACTERS;
- break;
- }
-
- // Local character reading block.
- if (_readIndex >= _readCount)
- reloadBuffer();
- c = _readBuffer[_readIndex++];
- if (c < ' ')
- c = handleEndOfLine(c);
- _data[_index++] = c;
- }
- break;
-
- case STATE_DTD:
- if (c == '>') {
- _text = newSeq(_start, _index - _start);
- _index = _start; // Do not keep DTD.
- _state = STATE_CHARACTERS;
- return _eventType = DTD;
- } else if (c == '[') {
- _state = STATE_DTD_INTERNAL;
- }
- break;
-
- case STATE_DTD_INTERNAL:
- if (c == ']') {
- _state = STATE_DTD;
- }
- break;
-
- case STATE_MARKUP: // Starts with '<'
- if (_index - _start == 2) {
- if (c == '/') {
- _start = _index = _index - 2;
- _state = STATE_CLOSE_TAGxREAD_ELEM_NAME;
- _prefixSep = -1;
- if (_charactersPending) { // Flush characters event.
- _charactersPending = false;
- return _eventType = CHARACTERS;
- }
- } else if (c == '?') {
- _start = _index = _index - 2;
- _state = STATE_PI;
- if (_charactersPending) { // Flush characters event.
- _charactersPending = false;
- return _eventType = CHARACTERS;
- }
- } else if (c != '!') { // Element tag (first letter).
- _data[_start] = c;
- _index = _start + 1;
- _state = STATE_OPEN_TAGxREAD_ELEM_NAME;
- _prefixSep = -1;
- if (_charactersPending) { // Flush character event.
- _charactersPending = false;
- return _eventType = CHARACTERS;
- }
- }
- } else if ((_index - _start == 4)
- && (_data[_start + 1] == '!')
- && (_data[_start + 2] == '-')
- && (_data[_start + 3] == '-')) {
- _start = _index = _index - 4; // Removes <!--
- _state = STATE_COMMENT;
- if (_charactersPending) { // Flush character event.
- _charactersPending = false;
- return _eventType = CHARACTERS;
- }
-
- } else if ((_index - _start == 9)
- && (_data[_start + 1] == '!')
- && (_data[_start + 2] == '[')
- && (_data[_start + 3] == 'C')
- && (_data[_start + 4] == 'D')
- && (_data[_start + 5] == 'A')
- && (_data[_start + 6] == 'T')
- && (_data[_start + 7] == 'A')
- && (_data[_start + 8] == '[')) {
- _start = _index = _index - 9; // Do not keep <![CDATA[
- _state = STATE_CDATA;
-
- } else if ((_index - _start == 9)
- && (_data[_start + 1] == '!')
- && (_data[_start + 2] == 'D')
- && (_data[_start + 3] == 'O')
- && (_data[_start + 4] == 'C')
- && (_data[_start + 5] == 'T')
- && (_data[_start + 6] == 'Y')
- && (_data[_start + 7] == 'P')
- && (_data[_start + 8] == 'E')) {
- // Keeps <!DOCTYPE as part of DTD.
- _state = STATE_DTD;
- } else {
- // Ignores, e.g. <!ELEMENT <!ENTITY...
- }
- break;
-
- case STATE_COMMENT:
- while (true) { // Read comment all at once.
-
- if ((c == '>') && (_index - _start >= 3)
- && (_data[_index - 2] == '-')
- && (_data[_index - 3] == '-')) {
- _index -= 3; // Removes -->
- _text = newSeq(_start, _index - _start);
- _state = STATE_CHARACTERS;
- _index = _start; // Do not keep comments.
- return _eventType = COMMENT;
- }
-
- // Local character reading block.
- if (_readIndex >= _readCount)
- reloadBuffer();
- c = _readBuffer[_readIndex++];
- if (c < ' ')
- c = handleEndOfLine(c);
- _data[_index++] = c;
- }
-
- case STATE_PI:
- if ((c == '>') && (_index - _start >= 2)
- && (_data[_index - 2] == '?')) {
- _index -= 2; // Removes ?>
- _text = newSeq(_start, _index - _start);
- _state = STATE_CHARACTERS;
- _index = _start; // Do not keep processing instructions.
- return _eventType = PROCESSING_INSTRUCTION;
- }
- break;
-
- // OPEN_TAG:
- case STATE_OPEN_TAGxREAD_ELEM_NAME:
- _attributes.reset();
- _namespaces.push();
- while (true) { // Read element name all at once.
-
- if (c < '@') { // Else avoid multiple checks.
- if (c == '>') {
- _qName = newSeq(_start, --_index - _start);
- _start = _index;
- _state = STATE_CHARACTERS;
- processStartTag();
- _isEmpty = false;
- return _eventType = START_ELEMENT;
- } else if (c == '/') {
- _qName = newSeq(_start, --_index - _start);
- _start = _index;
- _state = STATE_OPEN_TAGxEMPTY_TAG;
- break;
- } else if (c == ':') {
- _prefixSep = _index - 1;
- } else if (c <= ' ') {
- _qName = newSeq(_start, --_index - _start);
- _state = STATE_OPEN_TAGxELEM_NAME_READ;
- break;
- }
- }
-
- if (_readIndex >= _readCount)
- reloadBuffer();
- c = _data[_index++] = _readBuffer[_readIndex++];
- }
- break;
-
- case STATE_OPEN_TAGxELEM_NAME_READ:
- if (c == '>') {
- _start = --_index;
- _state = STATE_CHARACTERS;
- processStartTag();
- _isEmpty = false;
- return _eventType = START_ELEMENT;
- } else if (c == '/') {
- _state = STATE_OPEN_TAGxEMPTY_TAG;
- } else if (c > ' ') {
- _start = _index - 1; // Includes current character.
- _attrPrefixSep = -1;
- _state = STATE_OPEN_TAGxREAD_ATTR_NAME;
- }
- break;
-
- case STATE_OPEN_TAGxREAD_ATTR_NAME:
- while (true) { // Read attribute name all at once.
-
- if (c < '@') { // Else avoid multiple checks.
- if (c <= ' ') {
- _attrQName = newSeq(_start, --_index - _start);
- _state = STATE_OPEN_TAGxATTR_NAME_READ;
- break;
- } else if (c == '=') {
- _attrQName = newSeq(_start, --_index - _start);
- _state = STATE_OPEN_TAGxEQUAL_READ;
- break;
- } else if (c == ':') {
- _attrPrefixSep = _index - 1;
- }
- }
-
- if (_readIndex >= _readCount)
- reloadBuffer();
- _data[_index++] = c = _readBuffer[_readIndex++];
- }
- break;
-
- case STATE_OPEN_TAGxATTR_NAME_READ:
- if (c == '=') {
- --_index;
- _state = STATE_OPEN_TAGxEQUAL_READ;
- } else if (c > ' ') { throw new XMLStreamException(
- "'=' expected", _location); }
- break;
-
- case STATE_OPEN_TAGxEQUAL_READ:
- if (c == '\'') {
- _start = --_index;
- _state = STATE_OPEN_TAGxREAD_ATTR_VALUE_SIMPLE_QUOTE;
- } else if (c == '\"') {
- _start = --_index;
- _state = STATE_OPEN_TAGxREAD_ATTR_VALUE_DOUBLE_QUOTE;
- } else if (c > ' ') { throw new XMLStreamException(
- "Quotes expected", _location); }
- break;
-
- case STATE_OPEN_TAGxREAD_ATTR_VALUE_SIMPLE_QUOTE:
- while (true) { // Read attribute value all at once.
-
- if (c == '\'') {
- _attrValue = newSeq(_start, --_index - _start);
- processAttribute();
- _state = STATE_OPEN_TAGxELEM_NAME_READ;
- break;
- }
-
- // Local character reading block.
- if (_readIndex >= _readCount)
- reloadBuffer();
- c = _readBuffer[_readIndex++];
- if (c == '&')
- c = replaceEntity();
- _data[_index++] = c;
- }
- break;
-
- case STATE_OPEN_TAGxREAD_ATTR_VALUE_DOUBLE_QUOTE:
- while (true) { // Read attribute value all at once.
-
- if (c == '\"') {
- _attrValue = newSeq(_start, --_index - _start);
- processAttribute();
- _state = STATE_OPEN_TAGxELEM_NAME_READ;
- break;
- }
-
- // Local character reading block.
- if (_readIndex >= _readCount)
- reloadBuffer();
- c = _readBuffer[_readIndex++];
- if (c == '&')
- c = replaceEntity();
- _data[_index++] = c;
- }
- break;
-
- case STATE_OPEN_TAGxEMPTY_TAG:
- if (c == '>') {
- _start = --_index;
- _state = STATE_CHARACTERS;
- processStartTag();
- _isEmpty = true;
- return _eventType = START_ELEMENT;
- } else {
- throw new XMLStreamException("'>' expected", _location);
- }
-
- // CLOSE_TAG:
- case STATE_CLOSE_TAGxREAD_ELEM_NAME:
- while (true) { // Element name can be read all at once.
-
- if (c < '@') { // Else avoid multiple checks.
- if (c == '>') {
- _qName = newSeq(_start, --_index - _start);
- _start = _index;
- _state = STATE_CHARACTERS;
- processEndTag();
- return _eventType = END_ELEMENT;
- } else if (c == ':') {
- _prefixSep = _index - 1;
- } else if (c <= ' ') {
- _qName = newSeq(_start, --_index - _start);
- _state = STATE_CLOSE_TAGxELEM_NAME_READ;
- break;
- }
- }
-
- if (_readIndex >= _readCount)
- reloadBuffer();
- c = _data[_index++] = _readBuffer[_readIndex++];
- }
- break;
-
- case STATE_CLOSE_TAGxELEM_NAME_READ:
- if (c == '>') {
- _start = --_index;
- _state = STATE_CHARACTERS;
- processEndTag();
- return _eventType = END_ELEMENT;
- } else if (c > ' ') { throw new XMLStreamException(
- "'>' expected", _location); }
- break;
-
- default:
- throw new XMLStreamException("State unknown: " + _state,
- _location);
- }
- }
- }
-
- // Defines parsing states (keep values close together to avoid lookup).
- private static final int STATE_CHARACTERS = 1;
-
- private static final int STATE_MARKUP = 2;
-
- private static final int STATE_COMMENT = 3;
-
- private static final int STATE_PI = 4;
-
- private static final int STATE_CDATA = 5;
-
- private static final int STATE_OPEN_TAGxREAD_ELEM_NAME = 6;
-
- private static final int STATE_OPEN_TAGxELEM_NAME_READ = 7;
-
- private static final int STATE_OPEN_TAGxREAD_ATTR_NAME = 8;
-
- private static final int STATE_OPEN_TAGxATTR_NAME_READ = 9;
-
- private static final int STATE_OPEN_TAGxEQUAL_READ = 10;
-
- private static final int STATE_OPEN_TAGxREAD_ATTR_VALUE_SIMPLE_QUOTE = 11;
-
- private static final int STATE_OPEN_TAGxREAD_ATTR_VALUE_DOUBLE_QUOTE = 12;
-
- private static final int STATE_OPEN_TAGxEMPTY_TAG = 13;
-
- private static final int STATE_CLOSE_TAGxREAD_ELEM_NAME = 14;
-
- private static final int STATE_CLOSE_TAGxELEM_NAME_READ = 15;
-
- private static final int STATE_DTD = 16;
-
- private static final int STATE_DTD_INTERNAL = 17;
-
- /**
- * Reloads data buffer.
- *
- * @param detectEndOfStream indicates
- * @return <code>true</code> if the buffer has been reloaded;
- * <code>false</code> if the end of stream has being reached
- * and the event type (CHARACTERS or END_DOCUMENT) has been set.
- */
- private void reloadBuffer() throws XMLStreamException {
- if (_reader == null)
- throw new XMLStreamException("Input not specified");
- _location._column += _readIndex;
- _location._charactersRead += _readIndex;
- _readIndex = 0;
- try {
- _readCount = _reader.read(_readBuffer, 0, _readBuffer.length);
- if ((_readCount <= 0)
- && ((_depth != 0) || (_state != STATE_CHARACTERS)))
- throw new XMLStreamException("Unexpected end of document",
- _location);
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- while ((_index + _readCount) >= _data.length) { // Potential overflow.
- increaseDataBuffer();
- }
- }
-
- /**
- * Detects end of stream.
- *
- * @return <code>true</code> if end of stream has being reached
- * and the event type (CHARACTERS or END_DOCUMENT) has been set;
- * <code>false</code> otherwise.
- */
- private boolean isEndOfStream() throws XMLStreamException {
- if (_readIndex >= _readCount)
- reloadBuffer();
- if (_readCount <= 0) {
- // _state == STATE_CHARACTERS (otherwise reloadBuffer() exception)
- if (_eventType == END_DOCUMENT)
- throw new XMLStreamException(
- "End document has already been reached");
- int length = _index - _start;
- if (length > 0) { // Flushes trailing characters.
- if (_charactersPending) {
- _text.setArray(_data, _text.offset(), _text.length()
- + length); // Coalescing.
- } else {
- _text = newSeq(_start, length);
- }
- _start = _index;
- _eventType = CHARACTERS;
- } else {
- _eventType = END_DOCUMENT;
- }
- return true;
- }
- return false;
- }
-
- /**
- * Handles end of line as per XML Spec. 2.11
- *
- * @param c the potential end of line character.
- * @return the replacement character for end of line.
- */
- private char handleEndOfLine(char c) throws XMLStreamException {
- if (c == 0xD) { // Replaces #xD with #xA
- // Unless next char is #xA, then skip,
- // #xD#xA will be replaced by #xA
- if (_readIndex >= _readCount)
- reloadBuffer();
- if ((_readIndex < _readCount) && (_readBuffer[_readIndex] == 0xA))
- _readIndex++; // Skips 0xD
- c = (char) 0xA;
- }
- if (c == 0xA) {
- _location._line++;
- _location._column = -_readIndex; // column = 0
- } else if (c == 0x0) { throw new XMLStreamException(
- "Illegal XML character U+0000", _location); }
- return c;
- }
-
- /**
- * Replaces an entity if the current state allows it.
- *
- * @return the next character after the text replacement or '&' if no
- * replacement took place.
- */
- private char replaceEntity() throws XMLStreamException {
- if ((_state == STATE_COMMENT) || (_state == STATE_PI)
- || (_state == STATE_CDATA))
- return '&'; // (&2.4)
-
- int start = _index; // Index of first replacement character.
- _data[_index++] = '&';
- while (true) {
- if (_readIndex >= _readCount)
- reloadBuffer();
- char c = _data[_index++] = _readBuffer[_readIndex++];
- if (c == ';')
- break;
- if (c <= ' ')
- throw new XMLStreamException("';' expected", _location);
- }
- // Ensures that the replacement string holds in the data buffer.
- while (start + _entities.getMaxLength() >= _data.length) {
- increaseDataBuffer();
- }
-
- // Replaces the entity.
- int length = _entities.replaceEntity(_data, start, _index - start);
-
- // Returns the next character after entity unless ampersand.
- _index = start + length;
-
- // Local character reading block.
- if (_readIndex >= _readCount)
- reloadBuffer();
- char c = _readBuffer[_readIndex++];
- return (c == '&') ? (c = replaceEntity()) : c;
- }
-
- /**
- * Processes the attribute just read.
- */
- private void processAttribute() throws XMLStreamException {
- if (_attrPrefixSep < 0) { // No prefix.
- if (isXMLNS(_attrQName)) { // Sets default namespace.
- _namespaces.setPrefix(_namespaces._defaultNsPrefix, _attrValue);
- } else {
- _attributes.addAttribute(_attrQName, null, _attrQName,
- _attrValue);
- }
- } else { // Prefix.
- final int offset = _attrQName.offset();
- final int length = _attrQName.length();
-
- CharArray prefix = newSeq(offset, _attrPrefixSep - offset);
-
- CharArray localName = newSeq(_attrPrefixSep + 1, offset + length
- - _attrPrefixSep - 1);
-
- if (isXMLNS(prefix)) { // Namespace association.
- _namespaces.setPrefix(localName, _attrValue);
- } else {
- _attributes.addAttribute(localName, prefix, _attrQName,
- _attrValue);
- }
- }
- }
-
- private static boolean isXMLNS(CharArray chars) {
- return (chars.length() == 5) && (chars.charAt(0) == 'x')
- && (chars.charAt(1) == 'm') && (chars.charAt(2) == 'l')
- && (chars.charAt(3) == 'n') && (chars.charAt(4) == 's');
- }
-
- private void processEndTag() throws XMLStreamException {
- if (!_qName.equals(_elemStack[_depth]))
- throw new XMLStreamException("Unexpected end tag for " + _qName,
- _location);
- }
-
- private void processStartTag() throws XMLStreamException {
- if (++_depth >= _elemStack.length) {
- increaseStack();
- }
- _elemStack[_depth] = _qName;
- }
-
- // Implements Reusable.
- public void reset() {
- // Resets all members (alphabetically ordered).
- _attributes.reset();
- _attrPrefixSep = 0;
- _attrQName = null;
- _attrValue = null;
- _attrQName = null;
- _charactersPending = false;
- _encoding = null;
- _entities.reset();
- _eventType = START_DOCUMENT;
- _index = 0;
- _isEmpty = false;
- _location.reset();
- _namespaces.reset();
- _prolog = null;
- _readCount = 0;
- _reader = null;
- _depth = 0;
- _readIndex = 0;
- _seqsIndex = 0;
- _start = 0;
- _startOffset = 0;
- _state = STATE_CHARACTERS;
- _utf8StreamReader.reset();
-
- // Recycles if factory produced.
- if (_factory != null)
- _factory.recycle(this);
- }
-
- // Returns a new character sequence from the pool.
- private CharArray newSeq(int offset, int length) {
- CharArray seq = (_seqsIndex < _seqsCapacity) ? _seqs[_seqsIndex++]
- : newSeq2();
- return seq.setArray(_data, offset, length);
- }
-
- private CharArray newSeq2() {
- _createSeqLogic.run();
- return _seqs[_seqsIndex++];
- }
-
- private final Runnable _createSeqLogic = new Runnable() {
-
- public void run() {
- if (_seqsCapacity >= _seqs.length) { // Resizes.
- CharArray[] tmp = new CharArray[_seqs.length * 2];
- System.arraycopy(_seqs, 0, tmp, 0, _seqs.length);
- _seqs = tmp;
- }
- CharArray seq = new CharArray();
- _seqs[_seqsCapacity++] = seq;
- }
-
- };
-
- private CharArray[] _seqs = new CharArray[256];
-
- private int _seqsIndex;
-
- private int _seqsCapacity;
-
- // Increases internal data buffer capacity.
- private void increaseDataBuffer() {
- // Note: The character data at any nesting level is discarded
- // only when moving to outer nesting level (due to coalescing).
- // This accumulation may cause resize of the data buffer if
- // numerous elements at the same nesting level are separated by
- // spaces or indentation.
- char[] tmp = new char[_data.length * 2];
- javolution.context.LogContext.info(new CharArray(
- "XMLStreamReaderImpl: Data buffer increased to " + tmp.length));
- System.arraycopy(_data, 0, tmp, 0, _data.length);
- _data = tmp;
- }
-
- // Increases statck.
- private void increaseStack() {
- CharArray[] tmp = new CharArray[_elemStack.length * 2];
- javolution.context.LogContext.info(new CharArray(
- "XMLStreamReaderImpl: CharArray stack increased to "
- + tmp.length));
- System.arraycopy(_elemStack, 0, tmp, 0, _elemStack.length);
- _elemStack = tmp;
- }
-
- /**
- * This inner class represents the parser location.
- */
- private final class LocationImpl implements Location {
-
- int _column;
-
- int _line;
-
- int _charactersRead;
-
- public int getLineNumber() {
- return _line + 1;
- }
-
- public int getColumnNumber() {
- return _column + _readIndex;
- }
-
- public int getCharacterOffset() {
- return _charactersRead + _readIndex;
- }
-
- public String getPublicId() {
- return null; // Not available.
- }
-
- public String getSystemId() {
- return null; // Not available.
- }
-
- public String toString() {
- return "Line " + getLineNumber() + ", Column " + getColumnNumber();
- }
-
- public void reset() {
- _line = 0;
- _column = 0;
- _charactersRead = 0;
- }
-
- }
-
- //////////////////////////////////////////
- // Implements XMLStreamReader Interface //
- //////////////////////////////////////////
- // Implements XMLStreamReader Interface.
- public void require(int type, CharSequence namespaceURI,
- CharSequence localName) throws XMLStreamException {
- if (_eventType != type)
- throw new XMLStreamException("Expected event: "
- + NAMES_OF_EVENTS[type] + ", found event: "
- + NAMES_OF_EVENTS[_eventType]);
- if ((namespaceURI != null) && !getNamespaceURI().equals(namespaceURI))
- throw new XMLStreamException("Expected namespace URI: "
- + namespaceURI + ", found: " + getNamespaceURI());
- if ((localName != null) && !getLocalName().equals(localName))
- throw new XMLStreamException("Expected local name: " + localName
- + ", found: " + getLocalName());
- }
-
- // Implements XMLStreamReader Interface.
- public CharArray getElementText() throws XMLStreamException {
- // Derived from interface specification code.
- if (getEventType() != XMLStreamConstants.START_ELEMENT) { throw new XMLStreamException(
- "Parser must be on START_ELEMENT to read next text",
- getLocation()); }
- CharArray text = null;
- int eventType = next();
- while (eventType != XMLStreamConstants.END_ELEMENT) {
- if (eventType == XMLStreamConstants.CHARACTERS) {
- if (text == null) {
- text = getText();
- } else { // Merge (adjacent text, comments and PI are not kept).
- text.setArray(_data, text.offset(), text.length()
- + getText().length());
- }
- } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
- || eventType == XMLStreamConstants.COMMENT) {
- // Skips (not kept).
- } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
- throw new XMLStreamException(
- "Unexpected end of document when reading element text content",
- getLocation());
- } else if (eventType == XMLStreamConstants.START_ELEMENT) {
- throw new XMLStreamException(
- "Element text content may not contain START_ELEMENT",
- getLocation());
- } else {
- throw new XMLStreamException("Unexpected event type "
- + NAMES_OF_EVENTS[eventType], getLocation());
- }
- eventType = next();
- }
- return (text != null) ? text : newSeq(0, 0);
- }
-
- // Implements XMLStreamReader Interface.
- public Object getProperty(String name) throws IllegalArgumentException {
- if (name.equals(XMLInputFactory.IS_COALESCING)) {
- return Boolean.TRUE;
- } else if (name.equals(XMLInputFactory.ENTITIES)) {
- return _entities.getEntitiesMapping();
- } else {
- throw new IllegalArgumentException("Property: " + name
- + " not supported");
- }
- }
-
- // Implements XMLStreamReader Interface.
- public void close() throws XMLStreamException {
- reset();
- }
-
- public int getAttributeCount() {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw illegalState("Not a start element");
- return _attributes.getLength();
- }
-
- public CharArray getAttributeLocalName(int index) {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw illegalState("Not a start element");
- return _attributes.getLocalName(index);
- }
-
- public CharArray getAttributeNamespace(int index) {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw illegalState("Not a start element");
- CharArray prefix = _attributes.getPrefix(index);
- return _namespaces.getNamespaceURINullAllowed(prefix);
- }
-
- public CharArray getAttributePrefix(int index) {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw illegalState("Not a start element");
- return _attributes.getPrefix(index);
- }
-
- public CharArray getAttributeType(int index) {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw illegalState("Not a start element");
- return _attributes.getType(index);
- }
-
- public CharArray getAttributeValue(CharSequence uri, CharSequence localName) {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw illegalState("Not a start element");
- return (uri == null) ? _attributes.getValue(localName) : _attributes
- .getValue(uri, localName);
- }
-
- public CharArray getAttributeValue(int index) {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw illegalState("Not a start element");
- return _attributes.getValue(index);
- }
-
- public CharArray getCharacterEncodingScheme() {
- return readPrologAttribute(ENCODING);
- }
-
- private static final CharArray ENCODING = new CharArray("encoding");
-
- public String getEncoding() {
- return _encoding;
- }
-
- public int getEventType() {
- return _eventType;
- }
-
- public CharArray getLocalName() {
- if ((_eventType != XMLStreamConstants.START_ELEMENT)
- && (_eventType != XMLStreamConstants.END_ELEMENT))
- throw illegalState("Not a start or end element");
- if (_prefixSep < 0)
- return _qName;
- CharArray localName = newSeq(_prefixSep + 1,
- _qName.offset() + _qName.length() - _prefixSep - 1);
- return localName;
- }
-
- public Location getLocation() {
- return _location;
- }
-
- public int getNamespaceCount() {
- if ((_eventType != XMLStreamConstants.START_ELEMENT)
- && (_eventType != XMLStreamConstants.END_ELEMENT))
- throw illegalState("Not a start or end element");
- return _namespaces._namespacesCount[_depth];
- }
-
- public CharArray getNamespacePrefix(int index) {
- if ((_eventType != XMLStreamConstants.START_ELEMENT)
- && (_eventType != XMLStreamConstants.END_ELEMENT))
- throw illegalState("Not a start or end element");
- return _namespaces._prefixes[index];
- }
-
- public CharArray getNamespaceURI(CharSequence prefix) {
- if ((_eventType != XMLStreamConstants.START_ELEMENT)
- && (_eventType != XMLStreamConstants.END_ELEMENT))
- throw illegalState("Not a start or end element");
- return _namespaces.getNamespaceURI(prefix);
- }
-
- public CharArray getNamespaceURI(int index) {
- if ((_eventType != XMLStreamConstants.START_ELEMENT)
- && (_eventType != XMLStreamConstants.END_ELEMENT))
- throw illegalState("Not a start or end element");
- return _namespaces._namespaces[index];
- }
-
- public NamespaceContext getNamespaceContext() {
- return _namespaces;
- }
-
- public CharArray getNamespaceURI() {
- return _namespaces.getNamespaceURINullAllowed(getPrefix());
- }
-
- public CharArray getPrefix() {
- if ((_eventType != XMLStreamConstants.START_ELEMENT)
- && (_eventType != XMLStreamConstants.END_ELEMENT))
- throw illegalState("Not a start or end element");
- if (_prefixSep < 0)
- return null;
- int offset = _qName.offset();
- CharArray prefix = newSeq(offset, _prefixSep - offset);
- return prefix;
- }
-
- public CharArray getPIData() {
- if (_eventType != XMLStreamConstants.PROCESSING_INSTRUCTION)
- throw illegalState("Not a processing instruction");
- int offset = _text.indexOf(' ') + _text.offset() + 1;
- CharArray piData = newSeq(offset, _text.length() - offset);
- return piData;
- }
-
- public CharArray getPITarget() {
- if (_eventType != XMLStreamConstants.PROCESSING_INSTRUCTION)
- throw illegalState("Not a processing instruction");
- CharArray piTarget = newSeq(_text.offset(),
- _text.indexOf(' ') + _text.offset());
- return piTarget;
- }
-
- public CharArray getText() {
- if ((_eventType != XMLStreamConstants.CHARACTERS)
- && (_eventType != XMLStreamConstants.COMMENT)
- && (_eventType != XMLStreamConstants.DTD))
- throw illegalState("Not a text event");
- return _text;
- }
-
- public char[] getTextCharacters() {
- return getText().array();
- }
-
- public int getTextCharacters(int sourceStart, char[] target,
- int targetStart, int length) throws XMLStreamException {
- CharArray text = getText();
- int copyLength = Math.min(length, text.length());
- System.arraycopy(text.array(), sourceStart + text.offset(), target,
- targetStart, copyLength);
- return copyLength;
- }
-
- public int getTextLength() {
- return getText().length();
- }
-
- public int getTextStart() {
- return getText().offset();
- }
-
- public CharArray getVersion() {
- return readPrologAttribute(VERSION);
- }
-
- private static final CharArray VERSION = new CharArray("version");
-
- public boolean isStandalone() {
- CharArray standalone = readPrologAttribute(STANDALONE);
- return (standalone != null) ? standalone.equals("no") : true;
- }
-
- public boolean standaloneSet() {
- return readPrologAttribute(STANDALONE) != null;
- }
-
- private static final CharArray STANDALONE = new CharArray("standalone");
-
- public boolean hasName() {
- return (_eventType == XMLStreamConstants.START_ELEMENT)
- || (_eventType == XMLStreamConstants.END_ELEMENT);
- }
-
- public boolean hasNext() throws XMLStreamException {
- return _eventType != XMLStreamConstants.END_DOCUMENT;
- }
-
- public boolean hasText() {
- return ((_eventType == XMLStreamConstants.CHARACTERS)
- || (_eventType == XMLStreamConstants.COMMENT) || (_eventType == XMLStreamConstants.DTD))
- && (_text.length() > 0);
- }
-
- public boolean isAttributeSpecified(int index) {
- if (_eventType != XMLStreamConstants.START_ELEMENT)
- throw new IllegalStateException("Not a start element");
- return _attributes.getValue(index) != null;
- }
-
- public boolean isCharacters() {
- return _eventType == XMLStreamConstants.CHARACTERS;
- }
-
- public boolean isEndElement() {
- return _eventType == XMLStreamConstants.END_ELEMENT;
- }
-
- public boolean isStartElement() {
- return _eventType == XMLStreamConstants.START_ELEMENT;
- }
-
- public boolean isWhiteSpace() {
- if (isCharacters()) {
- char[] chars = _text.array();
- for (int i = _text.offset(), end = _text.offset() + _text.length(); i < end;) {
- if (!isWhiteSpace(chars[i++]))
- return false;
- }
- return true;
- }
- return false;
- }
-
- // Whitespaces according to XML 1.1 Specification.
- private static boolean isWhiteSpace(char c) {
- return (c == 0x20) || (c == 0x9) || (c == 0xD) || (c == 0xA);
- }
-
- public int nextTag() throws XMLStreamException {
- int eventType = next();
- while (eventType == XMLStreamConstants.COMMENT
- || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
- || eventType == XMLStreamConstants.DTD
- || (eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace())) {
- eventType = next();
- }
- if (eventType != XMLStreamConstants.START_ELEMENT
- && eventType != XMLStreamConstants.END_ELEMENT)
- throw new XMLStreamException("Tag expected (but found "
- + NAMES_OF_EVENTS[_eventType] + ")");
- return eventType;
- }
-
- private IllegalStateException illegalState(String msg) {
- return new IllegalStateException(msg + " ("
- + NAMES_OF_EVENTS[_eventType] + ")");
- }
-
- private String detectEncoding(InputStream input) throws XMLStreamException {
- // Autodetect encoding (see http://en.wikipedia.org/wiki/UTF-16)
- int byte0;
- try {
- byte0 = input.read();
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- if (byte0 == -1)
- throw new XMLStreamException("Premature End-Of-File");
- if (byte0 == '<') { // UTF-8 or compatible encoding.
- _readBuffer[_startOffset++] = '<';
- return "UTF-8";
- } else {
- int byte1;
- try {
- byte1 = input.read();
- } catch (IOException e) {
- throw new XMLStreamException(e);
- }
- if (byte1 == -1)
- throw new XMLStreamException("Premature End-Of-File");
- if ((byte0 == 0) && (byte1 == '<')) { // UTF-16 BIG ENDIAN
- _readBuffer[_startOffset++] = '<';
- return "UTF-16BE";
- } else if ((byte0 == '<') && (byte1 == 0)) { // UTF-16 LITTLE ENDIAN
- _readBuffer[_startOffset++] = '<';
- return "UTF-16LE";
- } else if ((byte0 == 0xFF) && (byte1 == 0xFE)) { // BOM for UTF-16 LITTLE ENDIAN
- return "UTF-16";
- } else if ((byte0 == 0xFE) && (byte1 == 0xFF)) { // BOM for UTF-16 BIG ENDIAN
- return "UTF-16";
- } else { // Encoding unknown (or no prolog) assumes UTF-8
- _readBuffer[_startOffset++] = (char) byte0;
- _readBuffer[_startOffset++] = (char) byte1;
- return "UTF-8";
- }
- }
- }
-
- private final CharArray readPrologAttribute(CharSequence name) {
- if (_prolog == null)
- return null;
- final int READ_EQUAL = 0;
- final int READ_QUOTE = 1;
- final int VALUE_SIMPLE_QUOTE = 2;
- final int VALUE_DOUBLE_QUOTE = 3;
-
- int i = _prolog.indexOf(name);
- if (i >= 0) {
- i += _prolog.offset();
- int maxIndex = _prolog.offset() + _prolog.length();
- i += name.length();
- int state = READ_EQUAL;
- int valueOffset = 0;
- while (i < maxIndex) {
- char c = _prolog.array()[i++];
- switch (state) {
- case READ_EQUAL:
- if (c == '=') {
- state = READ_QUOTE;
- }
- break;
- case READ_QUOTE:
- if (c == '"') {
- state = VALUE_DOUBLE_QUOTE;
- valueOffset = i;
- } else if (c == '\'') {
- state = VALUE_SIMPLE_QUOTE;
- valueOffset = i;
- }
- break;
- case VALUE_SIMPLE_QUOTE:
- if (c == '\'')
- return newSeq(valueOffset, i - valueOffset - 1);
- break;
- case VALUE_DOUBLE_QUOTE:
- if (c == '"')
- return newSeq(valueOffset, i - valueOffset - 1);
- break;
- }
- }
- }
- return null;
- }
-
-}
\ No newline at end of file
[08/15] cut down the included source code from javolution (no more
OSGi dependencies) and updated NOTICE and LICENSE files in source root
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/TextFormat.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/TextFormat.java b/commons/marmotta-commons/src/ext/java/javolution/text/TextFormat.java
deleted file mode 100644
index 5ba009a..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/TextFormat.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import java.io.IOException;
-
-import javolution.lang.Parallelizable;
-
-/**
- * <p> The service for plain text parsing and formatting;
- * it supports {@link CharSequence} and {@link Appendable} interfaces
- * for greater flexibility.</p>
- *
- * <p> Instances of this class are typically retrieved from the
- * current {@link TextContext} (OSGi service or not).
- * [code]
- * @DefaultTextFormat(Complex.Cartesian.class)
- * public class Complex extends Number {
- * public static Complex valueOf(CharSequence csq) {
- * return TextContext.getFormat(Complex.class).parse(csq);
- * }
- * public String toString() {
- * return TextContext.getFormat(Complex.class).format(this);
- * }
- * public static class Cartesian extends javolution.text.TextFormat<Complex> { ... }
- * public static class Polar extends javolution.text.TextFormat<Complex> { ... }
- * }[/code]</p>
- *
- * <p> Text formats can be locally overridden.
- * [code]
- * TextContext ctx = TextContext.enter();
- * try {
- * ctx.setFormat(Complex.class, Complex.Polar.class); // No impact on others threads.
- * System.out.println(complexMatrix); // Displays complex numbers in polar coordinates.
- * } finally {
- * ctx.exit(); // Reverts to previous cartesian format for complex numbers.
- * }[/code]</p>
- *
- * <p> For parsing/formatting of primitive types, the {@link TypeFormat}
- * utility class is recommended.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle </a>
- * @version 6.0, July 21, 2013
- */
-@Parallelizable
-public abstract class TextFormat<T> {
-
- /**
- * Reads a portion of the specified <code>CharSequence</code> from the
- * specified cursor position to produce an object. If parsing succeeds,
- * then the index of the <code>cursor</code> argument is updated to the
- * index after the last character used.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor holding the current parsing index.
- * @return the object parsed.
- * @throws IllegalArgumentException if the syntax of the specified
- * character sequence is incorrect.
- * @throws UnsupportedOperationException if parsing is not supported.
- */
- public abstract T parse(CharSequence csq, Cursor cursor);
-
- /**
- * Formats the specified object into an <code>Appendable</code>
- *
- * @param obj the object to format.
- * @param dest the appendable destination.
- * @return the specified <code>Appendable</code>.
- */
- public abstract Appendable format(T obj, Appendable dest)
- throws IOException;
-
- /**
- * Convenience method to parse the whole character sequence; if there are
- * unread extraneous characters after parsing then an exception is raised.
- *
- * @param csq the <code>CharSequence</code> to parse from the first character
- * to the last.
- * @throws IllegalArgumentException if the syntax of the specified
- * character sequence is incorrect or if there are extraneous
- * characters at the end not parsed.
- */
- public T parse(CharSequence csq) throws IllegalArgumentException {
- Cursor cursor = new Cursor();
- T obj = parse(csq, cursor);
- if (!cursor.atEnd(csq))
- throw new IllegalArgumentException("Extraneous character(s) \""
- + cursor.tail(csq) + "\"");
- return obj;
- }
-
- /**
- * Convenience method to format the specified object to a {@link TextBuilder};
- * unlike the abstract format method, this method does not throw {@link IOException}.
- *
- * @param obj the object to format.
- * @param dest the appendable destination.
- * @return the specified <code>TextBuilder</code>.
- */
- public TextBuilder format(T obj, TextBuilder dest) {
- try {
- this.format(obj, (Appendable) dest);
- return dest;
- } catch (IOException e) {
- throw new Error(e); // Cannot happens.
- }
- }
-
- /**
- * Convenience method to format the specified object to a {@link String}.
- *
- * @param obj the object to format.
- * @return the formatting result as a string.
- */
- public String format(T obj) {
- return this.format(obj, new TextBuilder()).toString();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/TypeFormat.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/TypeFormat.java b/commons/marmotta-commons/src/ext/java/javolution/text/TypeFormat.java
deleted file mode 100644
index 70207ff..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/TypeFormat.java
+++ /dev/null
@@ -1,732 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text;
-
-import java.io.IOException;
-import javolution.lang.MathLib;
-import javolution.lang.Realtime;
-
-/**
- * <p> Utility class to parse {@link CharSequence} into primitive types and
- * to format primitive types into any {@link Appendable}.</p>
- *
- * <p> Methods from this class <b>do not create temporary objects</b> and
- * are typically faster than standard library methods.</p>
- *
- * <p> The number of digits when formatting floating point numbers can be
- * specified. The default setting for <code>double</code> is 17 digits
- * or even 16 digits when the conversion is lossless back and forth
- * (mimic the standard library formatting).</p>
- * <p>[code]
- * TypeFormat.format(0.2, a) = "0.2" // 17 or 16 digits (as long as lossless conversion), remove trailing zeros.
- * TypeFormat.format(0.2, 17, false, false, a) = "0.20000000000000001" // Closest 17 digits number.
- * TypeFormat.format(0.2, 19, false, false, a) = "0.2000000000000000111" // Closest 19 digits.
- * TypeFormat.format(0.2, 4, false, false, a) = "0.2" // Fixed-point notation, remove trailing zeros.
- * TypeFormat.format(0.2, 4, false, true, a) = "0.2000" // Fixed-point notation, fixed number of digits.
- * TypeFormat.format(0.2, 4, true, false, a) = "2.0E-1" // Scientific notation, remove trailing zeros.
- * TypeFormat.format(0.2, 4, true, true, a) = "2.000E-1" // Scientific notation, fixed number of digits.
- * [/code]</p>
- *
- * <p> For non-primitive objects, formatting is typically performed using
- * specialized {@link TextFormat} instances.</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 5.3, February 15, 2009
- */
-@Realtime
-public final class TypeFormat {
-
- /**
- * Default constructor (forbids derivation).
- */
- private TypeFormat() {}
-
- /////////////
- // PARSING //
- /////////////
-
- /**
- * Parses the specified character sequence from the specified position
- * as a <code>boolean</code> ignoring cases.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor position (being maintained).
- * @return the next boolean value.
- * @throws IllegalArgumentException if the character sequence from the
- * specified position is different from "true" or "false" ignoring
- * cases.
- */
- public static boolean parseBoolean(CharSequence csq, Cursor cursor) {
- int start = cursor.getIndex();
- int end = csq.length();
- if ((end >= start + 5)
- && (csq.charAt(start) == 'f' || csq.charAt(start) == 'F')) { // False.
- if ((csq.charAt(++start) == 'a' || csq.charAt(start) == 'A')
- && (csq.charAt(++start) == 'l' || csq.charAt(start) == 'L')
- && (csq.charAt(++start) == 's' || csq.charAt(start) == 'S')
- && (csq.charAt(++start) == 'e' || csq.charAt(start) == 'E')) {
- cursor.increment(5);
- return false;
- }
- } else if ((end >= start + 4)
- && (csq.charAt(start) == 't' || csq.charAt(start) == 'T')) // True.
- if ((csq.charAt(++start) == 'r' || csq.charAt(start) == 'R')
- && (csq.charAt(++start) == 'u' || csq.charAt(start) == 'U')
- && (csq.charAt(++start) == 'e' || csq.charAt(start) == 'E')) {
- cursor.increment(4);
- return true;
- }
- throw new IllegalArgumentException("Invalid boolean representation");
- }
-
- /**
- * Parses the whole specified character sequence as a <code>boolean</code>.
- *
- * @param csq the character sequence to parse.
- * @return <code>parseBoolean(csq, new Cursor())</code>
- * @throws IllegalArgumentException if the specified character sequence
- * is different from "true" or "false" ignoring cases.
- */
- public static boolean parseBoolean(CharSequence csq) {
- Cursor cursor = new Cursor();
- boolean result = parseBoolean(csq, cursor);
- if (!cursor.atEnd(csq))
- throw new IllegalArgumentException("Extraneous characters \""
- + cursor.tail(csq) + "\"");
- return result;
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed <code>byte</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>byte</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>byte</code>.
- */
- public static byte parseByte(CharSequence csq, int radix, Cursor cursor) {
- int i = parseInt(csq, radix, cursor);
- if ((i < Byte.MIN_VALUE) || (i > Byte.MAX_VALUE))
- throw new NumberFormatException("Overflow");
- return (byte) i;
- }
-
- /**
- * Parses the whole specified character sequence
- * as a signed <code>byte</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @return the corresponding <code>byte</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>byte</code> or contains
- * extraneous characters.
- */
- public static byte parseByte(CharSequence csq, int radix) {
- Cursor cursor = new Cursor();
- byte result = parseByte(csq, radix, cursor);
- if (!cursor.atEnd(csq))
- throw new IllegalArgumentException("Extraneous characters \""
- + cursor.tail(csq) + "\"");
- return result;
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed decimal <code>byte</code>.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>byte</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>byte</code>.
- */
- public static byte parseByte(CharSequence csq, Cursor cursor) {
- return parseByte(csq, 10, cursor);
- }
-
- /**
- * Parses the whole specified character sequence as a signed decimal
- * <code>byte</code>.
- *
- * @param csq the character sequence to parse.
- * @return <code>parseByte(csq, 10)</code>
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>byte</code> or contains
- * extraneous characters.
- */
- public static byte parseByte(CharSequence csq) {
- return parseByte(csq, 10);
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed <code>short</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>short</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>short</code>.
- */
- public static short parseShort(CharSequence csq, int radix, Cursor cursor) {
- int i = parseInt(csq, radix, cursor);
- if ((i < Short.MIN_VALUE) || (i > Short.MAX_VALUE))
- throw new NumberFormatException("Overflow");
- return (short) i;
- }
-
- /**
- * Parses the whole specified character sequence
- * as a signed <code>short</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @return the corresponding <code>short</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>short</code> or contains
- * extraneous characters.
- */
- public static short parseShort(CharSequence csq, int radix) {
- Cursor cursor = new Cursor();
- short result = parseShort(csq, radix, cursor);
- if (!cursor.atEnd(csq))
- throw new IllegalArgumentException("Extraneous characters \""
- + cursor.tail(csq) + "\"");
- return result;
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed decimal <code>short</code>.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>short</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>short</code>.
- */
- public static short parseShort(CharSequence csq, Cursor cursor) {
- return parseShort(csq, 10, cursor);
- }
-
- /**
- * Parses the whole specified character sequence as a signed decimal
- * <code>short</code>.
- *
- * @param csq the character sequence to parse.
- * @return <code>parseShort(csq, 10)</code>
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>short</code> or contains
- * extraneous characters.
- */
- public static short parseShort(CharSequence csq) {
- return parseShort(csq, 10);
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed <code>int</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>int</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>int</code>.
- */
- public static int parseInt(CharSequence csq, int radix, Cursor cursor) {
- int start = cursor.getIndex();
- int end = csq.length();
- boolean isNegative = false;
- int result = 0; // Accumulates negatively (avoid MIN_VALUE overflow).
- int i = start;
- for (; i < end; i++) {
- char c = csq.charAt(i);
- int digit = (c <= '9') ? c - '0'
- : ((c <= 'Z') && (c >= 'A')) ? c - 'A' + 10
- : ((c <= 'z') && (c >= 'a')) ? c - 'a' + 10 : -1;
- if ((digit >= 0) && (digit < radix)) {
- int newResult = result * radix - digit;
- if (newResult > result)
- throw new NumberFormatException("Overflow parsing "
- + csq.subSequence(start, end));
- result = newResult;
- } else if ((c == '-') && (i == start))
- isNegative = true;
- else if ((c == '+') && (i == start)) {
- // Ok.
- } else
- break;
- }
- // Requires one valid digit character and checks for opposite overflow.
- if ((result == 0) && ((end == 0) || (csq.charAt(i - 1) != '0')))
- throw new NumberFormatException(
- "Invalid integer representation for "
- + csq.subSequence(start, end));
- if ((result == Integer.MIN_VALUE) && !isNegative)
- throw new NumberFormatException("Overflow parsing "
- + csq.subSequence(start, end));
- cursor.increment(i - start);
- return isNegative ? result : -result;
- }
-
- /**
- * Parses the whole specified character sequence
- * as a signed <code>int</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @return the corresponding <code>int</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>int</code> or contains
- * extraneous characters.
- */
- public static int parseInt(CharSequence csq, int radix) {
- Cursor cursor = new Cursor();
- int result = parseInt(csq, radix, cursor);
- if (!cursor.atEnd(csq))
- throw new IllegalArgumentException("Extraneous characters \""
- + cursor.tail(csq) + "\"");
- return result;
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed decimal <code>int</code>.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>int</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>int</code>.
- */
- public static int parseInt(CharSequence csq, Cursor cursor) {
- return parseInt(csq, 10, cursor);
- }
-
- /**
- * Parses the whole specified character sequence as a signed decimal
- * <code>int</code>.
- *
- * @param csq the character sequence to parse.
- * @return <code>parseInt(csq, 10)</code>
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>int</code> or contains
- * extraneous characters.
- */
- public static int parseInt(CharSequence csq) {
- return parseInt(csq, 10);
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed <code>long</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>long</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>long</code>.
- */
- public static long parseLong(CharSequence csq, int radix, Cursor cursor) {
- final int start = cursor.getIndex();
- final int end = csq.length();
- boolean isNegative = false;
- long result = 0; // Accumulates negatively (avoid MIN_VALUE overflow).
- int i = start;
- for (; i < end; i++) {
- char c = csq.charAt(i);
- int digit = (c <= '9') ? c - '0'
- : ((c <= 'Z') && (c >= 'A')) ? c - 'A' + 10
- : ((c <= 'z') && (c >= 'a')) ? c - 'a' + 10 : -1;
- if ((digit >= 0) && (digit < radix)) {
- long newResult = result * radix - digit;
- if (newResult > result)
- throw new NumberFormatException("Overflow parsing "
- + csq.subSequence(start, end));
- result = newResult;
- } else if ((c == '-') && (i == start))
- isNegative = true;
- else if ((c == '+') && (i == start)) {
- // Ok.
- } else
- break;
- }
- // Requires one valid digit character and checks for opposite overflow.
- if ((result == 0) && ((end == 0) || (csq.charAt(i - 1) != '0')))
- throw new NumberFormatException(
- "Invalid integer representation for "
- + csq.subSequence(start, end));
- if ((result == Long.MIN_VALUE) && !isNegative)
- throw new NumberFormatException("Overflow parsing "
- + csq.subSequence(start, end));
- cursor.increment(i - start);
- return isNegative ? result : -result;
- }
-
- /**
- * Parses the whole specified character sequence
- * as a signed <code>long</code> in the specified radix.
- *
- * @param csq the character sequence to parse.
- * @param radix the radix to be used while parsing.
- * @return the corresponding <code>long</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>long</code> or contains
- * extraneous characters.
- */
- public static long parseLong(CharSequence csq, int radix) {
- Cursor cursor = new Cursor();
- long result = parseLong(csq, radix, cursor);
- if (!cursor.atEnd(csq))
- throw new IllegalArgumentException("Extraneous characters \""
- + cursor.tail(csq) + "\"");
- return result;
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a signed decimal <code>long</code>.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor position being updated.
- * @return the corresponding <code>long</code>.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>long</code>.
- */
- public static long parseLong(CharSequence csq, Cursor cursor) {
- return parseLong(csq, 10, cursor);
- }
-
- /**
- * Parses the whole specified character sequence as a signed decimal
- * <code>long</code>.
- *
- * @param csq the character sequence to parse.
- * @return <code>parseLong(csq, 10)</code>
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>long</code> or contains
- * extraneous characters.
- */
- public static long parseLong(CharSequence csq) {
- return parseLong(csq, 10);
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a <code>float</code>.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor position (being maintained) or
- * <code>null></code> to parse the whole character sequence.
- * @return the float number represented by the specified character sequence.
- */
- public static float parseFloat(CharSequence csq, Cursor cursor) {
- return (float) parseDouble(csq, cursor);
- }
-
- /**
- * Parses the whole specified character sequence as a <code>float</code>.
- *
- * @param csq the character sequence to parse.
- * @return the float number represented by the specified character sequence.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>long</code> or contains
- * extraneous characters.
- */
- public static float parseFloat(CharSequence csq) {
- return (float) parseDouble(csq);
- }
-
- /**
- * Parses the specified character sequence from the specified position
- * as a <code>double</code>.
- *
- * @param csq the character sequence to parse.
- * @param cursor the cursor position (being maintained) or
- * <code>null></code> to parse the whole character sequence.
- * @return the double number represented by this character sequence.
- * @throws NumberFormatException if the character sequence does not contain
- * a parsable <code>double</code>.
- */
- public static double parseDouble(CharSequence csq, Cursor cursor)
- throws NumberFormatException {
- final int start = cursor.getIndex();
- final int end = csq.length();
- int i = start;
- char c = csq.charAt(i);
-
- // Checks for NaN.
- if ((c == 'N') && match("NaN", csq, i, end)) {
- cursor.increment(3);
- return Double.NaN;
- }
-
- // Reads sign.
- boolean isNegative = (c == '-');
- if ((isNegative || (c == '+')) && (++i < end))
- c = csq.charAt(i);
-
- // Checks for Infinity.
- if ((c == 'I') && match("Infinity", csq, i, end)) {
- cursor.increment(i + 8 - start);
- return isNegative ? Double.NEGATIVE_INFINITY
- : Double.POSITIVE_INFINITY;
- }
-
- // At least one digit or a '.' required.
- if (((c < '0') || (c > '9')) && (c != '.'))
- throw new NumberFormatException("Digit or '.' required");
-
- // Reads decimal and fraction (both merged to a long).
- long decimal = 0;
- int decimalPoint = -1;
- while (true) {
- int digit = c - '0';
- if ((digit >= 0) && (digit < 10)) {
- long tmp = decimal * 10 + digit;
- if ((decimal > LONG_MAX_DIV10) || (tmp < decimal))
- throw new NumberFormatException(
- "Too many digits - Overflow");
- decimal = tmp;
- } else if ((c == '.') && (decimalPoint < 0))
- decimalPoint = i;
- else
- break;
- if (++i >= end)
- break;
- c = csq.charAt(i);
- }
- if (isNegative)
- decimal = -decimal;
- int fractionLength = (decimalPoint >= 0) ? i - decimalPoint - 1 : 0;
-
- // Reads exponent.
- int exp = 0;
- if ((i < end) && ((c == 'E') || (c == 'e'))) {
- c = csq.charAt(++i);
- boolean isNegativeExp = (c == '-');
- if ((isNegativeExp || (c == '+')) && (++i < end))
- c = csq.charAt(i);
- if ((c < '0') || (c > '9')) // At least one digit required.
- throw new NumberFormatException("Invalid exponent");
- while (true) {
- int digit = c - '0';
- if ((digit >= 0) && (digit < 10)) {
- int tmp = exp * 10 + digit;
- if ((exp > INT_MAX_DIV10) || (tmp < exp))
- throw new NumberFormatException("Exponent Overflow");
- exp = tmp;
- } else
- break;
- if (++i >= end)
- break;
- c = csq.charAt(i);
- }
- if (isNegativeExp)
- exp = -exp;
- }
- cursor.increment(i - start);
- return javolution.lang.MathLib.toDoublePow10(decimal, exp
- - fractionLength);
- }
- private static final int INT_MAX_DIV10 = Integer.MAX_VALUE / 10;
- private static final long LONG_MAX_DIV10 = Long.MAX_VALUE / 10;
-
- /**
- * Parses the whole specified character sequence as a <code>double</code>.
- * The format must be of the form:<code>
- * <decimal>{'.'<fraction>}{'E|e'<exponent>}</code>.
- *
- * @param csq the character sequence to parse.
- * @return the double number represented by this character sequence.
- * @throws NumberFormatException if the specified character sequence
- * does not contain a parsable <code>long</code> or contains
- * extraneous characters.
- */
- public static double parseDouble(CharSequence csq)
- throws NumberFormatException {
- Cursor cursor = new Cursor();
- double result = parseDouble(csq, cursor);
- if (!cursor.atEnd(csq))
- throw new IllegalArgumentException("Extraneous characters \""
- + cursor.tail(csq) + "\"");
- return result;
- }
-
- static boolean match(String str, CharSequence csq, int start, int length) {
- for (int i = 0; i < str.length(); i++) {
- if ((start + i >= length) || csq.charAt(start + i) != str.charAt(i))
- return false;
- }
- return true;
- }
-
- static boolean match(String str, String csq, int start, int length) {
- for (int i = 0; i < str.length(); i++) {
- if ((start + i >= length) || csq.charAt(start + i) != str.charAt(i))
- return false;
- }
- return true;
- }
-
- ////////////////
- // FORMATTING //
- ////////////////
- /**
- * Formats the specified <code>boolean</code> and appends the resulting
- * text to the <code>Appendable</code> argument.
- *
- * @param b a <code>boolean</code>.
- * @param a the <code>Appendable</code> to append.
- * @return the specified <code>StringBuffer</code> object.
- * @throws IOException if an I/O exception occurs.
- */
- public static Appendable format(boolean b, Appendable a) throws IOException {
- return b ? a.append("true") : a.append("false");
- }
-
- /**
- * Formats the specified <code>int</code> and appends the resulting
- * text (decimal representation) to the <code>Appendable</code> argument.
- *
- *
- * @param i the <code>int</code> number.
- * @param a the <code>Appendable</code> to append.
- * @return the specified <code>Appendable</code> object.
- * @throws IOException if an I/O exception occurs.
- */
- public static Appendable format(int i, Appendable a) throws IOException {
- if (a instanceof TextBuilder)
- return ((TextBuilder) a).append(i);
- TextBuilder tb = new TextBuilder();
- tb.append(i);
- return a.append(tb);
- }
-
- /**
- * Formats the specified <code>int</code> in the specified radix and appends
- * the resulting text to the <code>Appendable</code> argument.
- *
- * @param i the <code>int</code> number.
- * @param radix the radix.
- * @param a the <code>Appendable</code> to append.
- * @return the specified <code>Appendable</code> object.
- * @throws IllegalArgumentException if radix is not in [2 .. 36] range.
- * @throws IOException if an I/O exception occurs.
- */
- public static Appendable format(int i, int radix, Appendable a)
- throws IOException {
- if (a instanceof TextBuilder)
- return ((TextBuilder) a).append(i, radix);
- TextBuilder tb = new TextBuilder();
- tb.append(i, radix);
- return a.append(tb);
- }
-
- /**
- * Formats the specified <code>long</code> and appends the resulting
- * text (decimal representation) to the <code>Appendable</code> argument.
- *
- * @param l the <code>long</code> number.
- * @param a the <code>Appendable</code> to append.
- * @return the specified <code>Appendable</code> object.
- * @throws IOException if an I/O exception occurs.
- * @see #parseLong
- */
- public static Appendable format(long l, Appendable a) throws IOException {
- if (a instanceof TextBuilder)
- return ((TextBuilder) a).append(l);
- TextBuilder tb = new TextBuilder();
- tb.append(l);
- return a.append(tb);
- }
-
- /**
- * Formats the specified <code>long</code> in the specified radix and
- * appends the resulting text to the <code>Appendable</code> argument.
- *
- * @param l the <code>long</code> number.
- * @param radix the radix.
- * @param a the <code>Appendable</code> to append.
- * @return the specified <code>Appendable</code> object.
- * @throws IllegalArgumentException if radix is not in [2 .. 36] range.
- * @throws IOException if an I/O exception occurs.
- * @see #parseLong(CharSequence, int)
- */
- public static Appendable format(long l, int radix, Appendable a)
- throws IOException {
- if (a instanceof TextBuilder)
- return ((TextBuilder) a).append(l, radix);
- TextBuilder tb = new TextBuilder();
- tb.append(l, radix);
- return a.append(tb);
- }
-
- /**
- * Formats the specified <code>float</code> value.
- *
- * @param f the <code>float</code> value.
- * @param a the <code>Appendable</code> to append.
- * @return <code>TypeFormat.format(f, 10, (MathLib.abs(f) >= 1E7) || (MathLib.abs(f) < 0.001), false, a)</code>
- * @throws IOException if an I/O exception occurs.
- */
- public static Appendable format(float f, Appendable a) throws IOException {
- return TypeFormat.format(f, 10,
- (MathLib.abs(f) >= 1E7) || (MathLib.abs(f) < 0.001), false, a);
- }
-
- /**
- * Formats the specified <code>double</code> value (16 or 17 digits output).
- *
- * @param d the <code>double</code> value.
- * @param a the <code>Appendable</code> to append.
- * @return <code>TypeFormat.format(d, -1, (MathLib.abs(d) >= 1E7) || (MathLib.abs(d) < 0.001), false, a)</code>
- * @throws IOException if an I/O exception occurs.
- * @see TextBuilder#append(double)
- */
- public static Appendable format(double d, Appendable a) throws IOException {
- return TypeFormat.format(d, -1,
- (MathLib.abs(d) >= 1E7) || (MathLib.abs(d) < 0.001), false, a);
- }
-
- /**
- * Formats the specified <code>double</code> value according to the
- * specified formatting arguments.
- *
- * @param d the <code>double</code> value.
- * @param digits the number of significative digits (excludes exponent) or
- * <code>-1</code> to mimic the standard library (16 or 17 digits).
- * @param scientific <code>true</code> to forces the use of the scientific
- * notation (e.g. <code>1.23E3</code>); <code>false</code>
- * otherwise.
- * @param showZero <code>true</code> if trailing fractional zeros are
- * represented; <code>false</code> otherwise.
- * @param a the <code>Appendable</code> to append.
- * @return the specified <code>Appendable</code> object.
- * @throws IllegalArgumentException if <code>(digits > 19)</code>)
- * @throws IOException if an I/O exception occurs.
- * @see TextBuilder#append(double, int, boolean, boolean)
- */
- public static Appendable format(double d, int digits, boolean scientific,
- boolean showZero, Appendable a) throws IOException {
- if (a instanceof TextBuilder)
- return ((TextBuilder) a).append(d, digits, scientific, showZero);
- TextBuilder tb = new TextBuilder();
- tb.append(d, digits, scientific, showZero);
- return a.append(tb);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/internal/TextContextImpl.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/internal/TextContextImpl.java b/commons/marmotta-commons/src/ext/java/javolution/text/internal/TextContextImpl.java
deleted file mode 100644
index 9e92f81..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/internal/TextContextImpl.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.text.internal;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-
-import javolution.context.LogContext;
-import javolution.text.CharSet;
-import javolution.text.Cursor;
-import javolution.text.DefaultTextFormat;
-import javolution.text.TextContext;
-import javolution.text.TextFormat;
-import javolution.text.TypeFormat;
-import javolution.util.FastMap;
-
-/**
- * Holds the default implementation of TextContext.
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-public final class TextContextImpl extends TextContext {
-
- private static final TextFormat<?> OBJECT_FORMAT = new TextFormat<Object>() {
- ThreadLocal<Object> objToString = new ThreadLocal<Object>();
-
- public Appendable format(Object obj, Appendable dest)
- throws IOException {
- if (obj == null) return dest.append("null");
- if (objToString.get() == obj) // Circularity in toString !
- return TypeFormat.format(System.identityHashCode(obj),
- dest.append("Object#"));
- objToString.set(obj);
- try {
- String str = obj.toString();
- return dest.append(str);
- } finally {
- objToString.set(null);
- }
- }
-
- public Object parse(CharSequence csq, Cursor cursor) {
- throw new UnsupportedOperationException(
- "Generic object parsing not supported.");
- }
-
- };
- // Holds class->format local mapping.
- private final FastMap<Class<?>, TextFormat<?>> localFormats;
-
- // Caches class->format from class annotations.
- private final FastMap<Class<?>, TextFormat<?>> defaultFormats;
-
- /** Default constructor for root */
- public TextContextImpl() {
- localFormats = new FastMap<Class<?>, TextFormat<?>>(); // Updated only during configuration.
- defaultFormats = new FastMap<Class<?>, TextFormat<?>>().shared(); // Can be updated concurrently.
- storePrimitiveTypesFormats();
- }
-
- /** Inner constructor */
- public TextContextImpl(TextContextImpl parent) {
- localFormats = new FastMap<Class<?>, TextFormat<?>>()
- .putAll(parent.localFormats);
- defaultFormats = parent.defaultFormats;
- }
-
- @Override
- protected TextContext inner() {
- return new TextContextImpl(this);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- protected <T> TextFormat<T> searchFormat(Class<? extends T> type) {
- Class<?> cls = type;
- while (cls != null) {
- TextFormat<?> format;
- // Search local format first.
- if (localFormats.size() > 0) {
- format = localFormats.get(cls);
- if (format != null) return (TextFormat<T>) format;
- }
- // Then search default format.
- format = defaultFormats.get(cls);
- if (format != null) return (TextFormat<T>) format;
-
- // Search annotations.
- DefaultTextFormat annotation = cls
- .getAnnotation(DefaultTextFormat.class);
- if (annotation != null) { // Found it.
- try {
- format = annotation.value().newInstance();
- } catch (Throwable error) {
- LogContext.warning(error);
- }
- // Updates the default mapping.
- Class<?> mappedClass = type;
- while (true) {
- defaultFormats.put(mappedClass, format);
- if (mappedClass.equals(cls)) break;
- mappedClass = mappedClass.getSuperclass();
- }
- return (TextFormat<T>) format;
- }
-
- // Search superclass.
- cls = cls.getSuperclass();
- }
- throw new Error("Object default format not found !");
- }
-
- @Override
- public <T> void setFormat(Class<? extends T> type, TextFormat<T> format) {
- localFormats.put(type, format);
- }
-
- ////////////////////////
- // PREDEFINED FORMATS //
- ////////////////////////
-
- private void storePrimitiveTypesFormats() {
- defaultFormats.put(Object.class, OBJECT_FORMAT);
- defaultFormats.put(Boolean.class, new TextFormat<Boolean>() {
-
- public Appendable format(Boolean obj, Appendable dest)
- throws IOException {
- return TypeFormat.format(obj.booleanValue(), dest);
- }
-
- public Boolean parse(CharSequence csq, Cursor cursor) {
- return TypeFormat.parseBoolean(csq, cursor);
- }
-
- });
- defaultFormats.put(Character.class, new TextFormat<Character>() {
-
- public Appendable format(Character obj, Appendable dest)
- throws IOException {
- return dest.append(obj.charValue());
- }
-
- public Character parse(CharSequence csq, Cursor cursor) {
- return Character.valueOf(cursor.nextChar(csq));
- }
-
- });
- defaultFormats.put(Byte.class, new TextFormat<Byte>() {
-
- public Appendable format(Byte obj, Appendable dest)
- throws IOException {
- return TypeFormat.format(obj.byteValue(), dest);
- }
-
- public Byte parse(CharSequence csq, Cursor cursor) {
- return Byte.valueOf(TypeFormat.parseByte(csq, 10, cursor));
- }
-
- });
- defaultFormats.put(Short.class, new TextFormat<Short>() {
-
- public Appendable format(Short obj, Appendable dest)
- throws IOException {
- return TypeFormat.format(obj.shortValue(), dest);
- }
-
- public Short parse(CharSequence csq, Cursor cursor) {
- return Short.valueOf(TypeFormat.parseShort(csq, 10, cursor));
- }
-
- });
- defaultFormats.put(Integer.class, new TextFormat<Integer>() {
-
- public Appendable format(Integer obj, Appendable dest)
- throws IOException {
- return TypeFormat.format(obj.intValue(), dest);
- }
-
- public Integer parse(CharSequence csq, Cursor cursor) {
- return Integer.valueOf(TypeFormat.parseInt(csq, 10, cursor));
- }
-
- });
- defaultFormats.put(Long.class, new TextFormat<Long>() {
-
- public Appendable format(Long obj, Appendable dest)
- throws IOException {
- return TypeFormat.format(obj.longValue(), dest);
- }
-
- public Long parse(CharSequence csq, Cursor cursor) {
- return Long.valueOf(TypeFormat.parseLong(csq, 10, cursor));
- }
-
- });
- defaultFormats.put(Float.class, new TextFormat<Float>() {
-
- public Appendable format(Float obj, Appendable dest)
- throws IOException {
- return TypeFormat.format(obj.floatValue(), dest);
- }
-
- public Float parse(CharSequence csq, Cursor cursor) {
- return new Float(TypeFormat.parseFloat(csq, cursor));
- }
-
- });
- defaultFormats.put(Double.class, new TextFormat<Double>() {
-
- public Appendable format(Double obj, Appendable dest)
- throws IOException {
- return TypeFormat.format(obj.doubleValue(), dest);
- }
-
- public Double parse(CharSequence csq, Cursor cursor) {
- return new Double(TypeFormat.parseDouble(csq, cursor));
- }
-
- });
- defaultFormats.put(String.class, new TextFormat<String>() {
-
- public Appendable format(String obj, Appendable dest)
- throws IOException {
- return dest.append(obj);
- }
-
- public String parse(CharSequence csq, Cursor cursor) {
- CharSequence tmp = csq.subSequence(cursor.getIndex(),
- csq.length());
- cursor.setIndex(csq.length());
- return tmp.toString();
- }
-
- });
- defaultFormats.put(Class.class, new TextFormat<Class<?>>() {
-
- public Appendable format(Class<?> obj, Appendable dest)
- throws IOException {
- return dest.append(obj.getName());
- }
-
- public Class<?> parse(CharSequence csq, Cursor cursor) {
- CharSequence name = cursor.nextToken(csq, CharSet.WHITESPACES);
- try {
- return Class.forName(name.toString());
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Class " + name
- + " Not Found");
- }
- }
-
- });
- defaultFormats.put(Date.class, new TextFormat<Date>() {
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
- {
- df.setTimeZone(tz);
- }
-
- public Appendable format(Date obj, Appendable dest)
- throws IOException {
- return dest.append(df.format(obj));
- }
-
- public Date parse(CharSequence csq, Cursor cursor) {
- CharSequence date = cursor.nextToken(csq, CharSet.WHITESPACES);
- try {
- return df.parse(date.toString());
- } catch (ParseException error) {
- throw new IllegalArgumentException(error);
- }
- }
- });
- defaultFormats.put(BigInteger.class, new TextFormat<BigInteger>() {
-
- public Appendable format(BigInteger obj, Appendable dest)
- throws IOException {
- return dest.append(obj.toString());
- }
-
- public BigInteger parse(CharSequence csq, Cursor cursor) {
- CharSequence value = cursor.nextToken(csq, CharSet.WHITESPACES);
- return new BigInteger(value.toString());
- }
-
- });
- defaultFormats.put(BigDecimal.class, new TextFormat<BigDecimal>() {
-
- public Appendable format(BigDecimal obj, Appendable dest)
- throws IOException {
- return dest.append(obj.toString());
- }
-
- public BigDecimal parse(CharSequence csq, Cursor cursor) {
- CharSequence value = cursor.nextToken(csq, CharSet.WHITESPACES);
- return new BigDecimal(value.toString());
- }
-
- });
- defaultFormats.put(Font.class, new TextFormat<Font>() {
-
- public Appendable format(Font obj, Appendable dest)
- throws IOException {
- return dest.append(obj.getName());
- }
-
- public Font parse(CharSequence csq, Cursor cursor) {
- CharSequence name = cursor.nextToken(csq, CharSet.WHITESPACES);
- return Font.decode(name.toString());
- }
-
- });
- defaultFormats.put(Color.class, new TextFormat<Color>() {
-
- public Appendable format(Color obj, Appendable dest)
- throws IOException {
- return dest.append('#').append(
- Integer.toHexString(obj.getRGB()));
- }
-
- public Color parse(CharSequence csq, Cursor cursor) {
- CharSequence name = cursor.nextToken(csq, CharSet.WHITESPACES);
- return Color.decode(name.toString());
- }
-
- });
-
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/text/package-info.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/text/package-info.java b/commons/marmotta-commons/src/ext/java/javolution/text/package-info.java
deleted file mode 100644
index 3c82f97..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/text/package-info.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
-<p> Text handling package.</p>
-<h2><a name="FAQ">FAQ:</a></h2>
-<ol>
- <a name="FAQ-1"></a>
- <li><b> Is parsing/formatting of floating-points numbers (e.g. <code>double</code>)
- equivalent to standard String/Double methods?</b>
- <p> With Javolution 4.1, <code>double</code> formatting/parsing is lossless
- and functionally the same as with the standard library. Parsing a character
- sequence will always result in the same number whether it is performed with
- {@link javolution.text.TypeFormat TypeFormat} or using <code>Double.parseDouble(String))</code>.
- When formatting a <code>double</code> number, the number of digits output
- is adjustable. The default (if the number of digits is unspecified) is <code>17</code>
- or <code>16</code> when the the 16 digits representation can be parsed back to
- the same <code>double</code> (mimic the standard library formatting).</p>
- <p> Javolution parsing/formatting do not generate garbage and has no adverse
- effect on GC. Better, it does not force the user to create intermediate <code>String</code>
- objects, any <code>CharSequence/Appendable</code> can be used! Serial parsing is also supported
- (cursor parameter).</p>
- <p></p>
- <a name="FAQ-2"></a>
- <li><b> I'm accumulating a large string, and all I want to do is
-append to the end of the current string, which is the better class to use,
-Text or TextBuilder? Bearing in mind that speed is important, but I also want
-to conserve memory.</b>
- <p> It all depends of the size of the text to append (the actual size of the
- document being appended has almost no impact in both cases).</p>
- <p> If the text being appended is large (or arbitrarily large) then using
- {@link javolution.text.Text Text} is preferable.
-[code]
-class FastCollection<T> {
- public final Text toText() {
- // We don't know the length of the text representation for
- // the collection's elements, we use Text concatenation
- // to avoid copying what could be quite large.
- Text text = Text.valueOf("{");
- boolean isFirst = true;
- for (T e : this) {
- if (!isFirst) { text = text.plus(", "); isFirst = false; }
- text = text.plus(e);
- }
- return text.plus("}");
- }
-}[/code]</p>
- <p></p>
- <a name="FAQ-3"></a>
- <li><b> In our project's use of strings, there are a lot of
- instances of directory path names, such as
-<code>"/proj/lodecase/src/com/lodecase/util/foo.java"</code>, and
-<code>"/proj/lodecase/src/com/lodecase/util/bar.java"</code>.
-Can the 'Text' class save us memory when strings
-have common prefixes?</b>
- <p> It depends how you build your text. For example in following code:
-[code]
-Text directoryName = Text.valueOf("/proj/lodecase/src/com/lodecase/util/");
-Text fooFileName = directoryName.plus("foo.java");
-Text barFileName = directoryName.plus("bar.java");[/code]
- The prefix (directoryName)is shared between <code>fooFileName</code> and <code>barFileName</code>.</p>
- <p> Text is a binary tree of blocks of characters. In the example,
- above, <code>fooFileName</code> is a node with <code>directoryName</code> for
- head and "foo.java" for tail. The tree is maintained balanced automatically
- through <a href="http://en.wikipedia.org/wiki/Tree_rotation">tree rotations</a>.</p>
- <p></p>
-</ol>
- */
-package javolution.text;
-
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastBitSet.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastBitSet.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastBitSet.java
deleted file mode 100644
index f7c6234..0000000
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastBitSet.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
- * Copyright (C) 2012 - Javolution (http://javolution.org/)
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software is
- * freely granted, provided that this notice is preserved.
- */
-package javolution.util;
-
-import static javolution.lang.Realtime.Limit.LINEAR;
-import javolution.lang.Realtime;
-import javolution.util.internal.bitset.BitSetServiceImpl;
-import javolution.util.service.BitSetService;
-
-/**
- * <p> A high-performance bitset with {@link Realtime real-time} behavior.</p>
- *
- * <p> This class is integrated with the collection framework as
- * a set of {@link Index indices} and obeys the collection semantic
- * for methods such as {@link #size} (cardinality) or {@link #equals}
- * (same set of indices).</p>
- *
- * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
- * @version 6.0, July 21, 2013
- */
-public class FastBitSet extends FastSet<Index> {
-
- private static final long serialVersionUID = 0x600L; // Version.
-
- /**
- * Holds the bit set implementation.
- */
- private final BitSetService service;
-
- /**
- * Creates an empty bit set.
- */
- public FastBitSet() {
- service = new BitSetServiceImpl();
- }
-
- /**
- * Creates a fast bit set based on the specified implementation.
- */
- protected FastBitSet(BitSetService impl) {
- this.service = impl;
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // Views.
- //
-
- @Override
- public FastBitSet unmodifiable() {
- throw new UnsupportedOperationException("NOT DONE YET"); // TODO
- }
-
- @Override
- public FastBitSet shared() {
- throw new UnsupportedOperationException("NOT DONE YET"); // TODO
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // BitSet Operations.
- //
-
- /**
- * Performs the logical AND operation on this bit set and the
- * given bit set. This means it builds the intersection
- * of the two sets. The result is stored into this bit set.
- *
- * @param that the second bit set.
- */
- @Realtime(limit = LINEAR)
- public void and(FastBitSet that) {
- service.and(that.service);
- }
-
- /**
- * Performs the logical AND operation on this bit set and the
- * complement of the given bit set. This means it
- * selects every element in the first set, that isn't in the
- * second set. The result is stored into this bit set.
- *
- * @param that the second bit set
- */
- @Realtime(limit = LINEAR)
- public void andNot(FastBitSet that) {
- service.andNot(that.service);
- }
-
- /**
- * Returns the number of bits set to {@code true} (or the size of this
- * set).
- *
- * @return the number of bits being set.
- */
- public int cardinality() {
- return service.cardinality();
- }
-
- /**
- * Sets all bits in the set to {@code false} (empty the set).
- */
- @Override
- public void clear() {
- service.clear();
- }
-
- /**
- * Removes the specified integer value from this set. That is
- * the corresponding bit is cleared.
- *
- * @param bitIndex a non-negative integer.
- * @throws IndexOutOfBoundsException if {@code index < 0}
- */
- public void clear(int bitIndex) {
- service.clear(bitIndex);
- }
-
- /**
- * Sets the bits from the specified {@code fromIndex} (inclusive) to the
- * specified {@code toIndex} (exclusive) to {@code false}.
- *
- * @param fromIndex index of the first bit to be cleared.
- * @param toIndex index after the last bit to be cleared.
- * @throws IndexOutOfBoundsException if
- * {@code (fromIndex < 0) | (toIndex < fromIndex)}
- */
- @Realtime(limit = LINEAR)
- public void clear(int fromIndex, int toIndex) {
- service.clear(fromIndex, toIndex);
- }
-
- /**
- * Sets the bit at the index to the opposite value.
- *
- * @param bitIndex the index of the bit.
- * @throws IndexOutOfBoundsException if {@code bitIndex < 0}
- */
- public void flip(int bitIndex) {
- service.flip(bitIndex);
- }
-
- /**
- * Sets a range of bits to the opposite value.
- *
- * @param fromIndex the low index (inclusive).
- * @param toIndex the high index (exclusive).
- * @throws IndexOutOfBoundsException if
- * {@code (fromIndex < 0) | (toIndex < fromIndex)}
- */
- @Realtime(limit = LINEAR)
- public void flip(int fromIndex, int toIndex) {
- service.flip(fromIndex, toIndex);
- }
-
- /**
- * Returns {@code true } if the specified integer is in
- * this bit set; {@code false } otherwise.
- *
- * @param bitIndex a non-negative integer.
- * @return the value of the bit at the specified index.
- * @throws IndexOutOfBoundsException if {@code bitIndex < 0}
- */
- public boolean get(int bitIndex) {
- return service.get(bitIndex);
- }
-
- /**
- * Returns a new bit set composed of a range of bits from this one.
- *
- * @param fromIndex the low index (inclusive).
- * @param toIndex the high index (exclusive).
- * @return a context allocated bit set instance.
- * @throws IndexOutOfBoundsException if
- * {@code (fromIndex < 0) | (toIndex < fromIndex)}
- */
- @Realtime(limit = LINEAR)
- public FastBitSet get(int fromIndex, int toIndex) {
- return new FastBitSet(service.get(fromIndex, toIndex));
- }
-
- /**
- * Returns {@code true} if this bit set shares at least one
- * common bit with the specified bit set.
- *
- * @param that the bit set to check for intersection
- * @return {@code true} if the sets intersect; {@code false} otherwise.
- */
- @Realtime(limit = LINEAR)
- public boolean intersects(FastBitSet that) {
- return service.intersects(that.service);
- }
-
- /**
- * Returns the logical number of bits actually used by this bit
- * set. It returns the index of the highest set bit plus one.
- *
- * <p> Note: This method does not return the number of set bits
- * which is returned by {@link #size} </p>
- *
- * @return the index of the highest set bit plus one.
- */
- public int length() {
- return service.length();
- }
-
- /**
- * Returns the index of the next {@code false} bit, from the specified bit
- * (inclusive).
- *
- * @param fromIndex the start location.
- * @return the first {@code false} bit.
- * @throws IndexOutOfBoundsException if {@code fromIndex < 0}
- */
- public int nextClearBit(int fromIndex) {
- return service.nextClearBit(fromIndex);
- }
-
- /**
- * Returns the index of the next {@code true} bit, from the specified bit
- * (inclusive). If there is none, {@code -1} is returned.
- * The following code will iterates through the bit set:[code]
- * for (int i=nextSetBit(0); i >= 0; i = nextSetBit(i+1)) {
- * ...
- * }[/code]
- *
- * @param fromIndex the start location.
- * @return the first {@code false} bit.
- * @throws IndexOutOfBoundsException if {@code fromIndex < 0}
- */
- public int nextSetBit(int fromIndex) {
- return service.nextSetBit(fromIndex);
- }
-
- /**
- * Returns the index of the previous {@code false} bit,
- * from the specified bit (inclusive).
- *
- * @param fromIndex the start location.
- * @return the first {@code false} bit.
- * @throws IndexOutOfBoundsException if {@code fromIndex < -1}
- */
- public int previousClearBit(int fromIndex) {
- return service.previousClearBit(fromIndex);
- }
-
- /**
- * Returns the index of the previous {@code true} bit, from the
- * specified bit (inclusive). If there is none, {@code -1} is returned.
- * The following code will iterates through the bit set:[code]
- * for (int i = length(); (i = previousSetBit(i-1)) >= 0; ) {
- * ...
- * }[/code]
- *
- * @param fromIndex the start location.
- * @return the first {@code false} bit.
- * @throws IndexOutOfBoundsException if {@code fromIndex < -1}
- */
- public int previousSetBit(int fromIndex) {
- return service.previousSetBit(fromIndex);
- }
-
- /**
- * Performs the logical OR operation on this bit set and the one specified.
- * In other words, builds the union of the two sets.
- * The result is stored into this bit set.
- *
- * @param that the second bit set.
- */
- @Realtime(limit = LINEAR)
- public void or(FastBitSet that) {
- service.or(that.service);
- }
-
- /**
- * Adds the specified integer to this set (corresponding bit is set to
- * {@code true}.
- *
- * @param bitIndex a non-negative integer.
- * @throws IndexOutOfBoundsException if {@code bitIndex < 0}
- */
- public void set(int bitIndex) {
- service.set(bitIndex);
- }
-
- /**
- * Sets the bit at the given index to the specified value.
- *
- * @param bitIndex the position to set.
- * @param value the value to set it to.
- * @throws IndexOutOfBoundsException if {@code bitIndex < 0}
- */
- public void set(int bitIndex, boolean value) {
- service.set(bitIndex, value);
- }
-
- /**
- * Sets the bits from the specified {@code fromIndex} (inclusive) to the
- * specified {@code toIndex} (exclusive) to {@code true}.
- *
- * @param fromIndex index of the first bit to be set.
- * @param toIndex index after the last bit to be set.
- * @throws IndexOutOfBoundsException if
- * {@code (fromIndex < 0) | (toIndex < fromIndex)}
- */
- @Realtime(limit = LINEAR)
- public void set(int fromIndex, int toIndex) {
- if ((fromIndex < 0) || (toIndex < fromIndex)) throw new IndexOutOfBoundsException();
- service.set(fromIndex, toIndex);
- }
-
- /**
- * Sets the bits between from (inclusive) and to (exclusive) to the
- * specified value.
- *
- * @param fromIndex the start range (inclusive).
- * @param toIndex the end range (exclusive).
- * @param value the value to set it to.
- * @throws IndexOutOfBoundsException if {@code bitIndex < 0}
- */
- @Realtime(limit = LINEAR)
- public void set(int fromIndex, int toIndex, boolean value) {
- service.set(fromIndex, toIndex, value);
- }
-
- /**
- * Performs the logical XOR operation on this bit set and the one specified.
- * In other words, builds the symmetric remainder of the two sets
- * (the elements that are in one set, but not in the other).
- * The result is stored into this bit set.
- *
- * @param that the second bit set.
- */
- @Realtime(limit = LINEAR)
- public void xor(FastBitSet that) {
- service.xor(that.service);
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // Misc.
- //
-
- @Override
- public FastBitSet addAll(Index... elements) {
- return (FastBitSet) super.addAll(elements);
- }
-
- @Override
- public FastBitSet addAll(FastCollection<? extends Index> elements) {
- return (FastBitSet) super.addAll(elements);
- }
-
- @Override
- protected BitSetService service() {
- return service;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastCollection.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastCollection.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastCollection.java
index 8160097..100d59e 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastCollection.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/FastCollection.java
@@ -8,42 +8,20 @@
*/
package javolution.util;
-import static javolution.lang.Realtime.Limit.CONSTANT;
-import static javolution.lang.Realtime.Limit.LINEAR;
-import static javolution.lang.Realtime.Limit.N_SQUARE;
+import javolution.lang.Immutable;
+import javolution.lang.Parallelizable;
+import javolution.lang.Realtime;
+import javolution.util.function.*;
+import javolution.util.internal.collection.*;
+import javolution.util.service.CollectionService;
-import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
-import javolution.lang.Immutable;
-import javolution.lang.Parallelizable;
-import javolution.lang.Realtime;
-import javolution.text.Cursor;
-import javolution.text.DefaultTextFormat;
-import javolution.text.TextContext;
-import javolution.text.TextFormat;
-import javolution.util.function.Consumer;
-import javolution.util.function.Equalities;
-import javolution.util.function.Equality;
-import javolution.util.function.Function;
-import javolution.util.function.Predicate;
-import javolution.util.function.Reducer;
-import javolution.util.function.Reducers;
-import javolution.util.internal.collection.AtomicCollectionImpl;
-import javolution.util.internal.collection.DistinctCollectionImpl;
-import javolution.util.internal.collection.FilteredCollectionImpl;
-import javolution.util.internal.collection.MappedCollectionImpl;
-import javolution.util.internal.collection.ParallelCollectionImpl;
-import javolution.util.internal.collection.ReversedCollectionImpl;
-import javolution.util.internal.collection.SequentialCollectionImpl;
-import javolution.util.internal.collection.SharedCollectionImpl;
-import javolution.util.internal.collection.SortedCollectionImpl;
-import javolution.util.internal.collection.UnmodifiableCollectionImpl;
-import javolution.util.service.CollectionService;
+import static javolution.lang.Realtime.Limit.*;
/**
* <p> A closure-based collection supporting numerous views which can be chained.
@@ -165,7 +143,6 @@ import javolution.util.service.CollectionService;
* @version 6.0, July 21, 2013
*/
@Realtime
-@DefaultTextFormat(FastCollection.Format.class)
public abstract class FastCollection<E> implements Collection<E>, Serializable {
private static final long serialVersionUID = 0x600L; // Version.
@@ -206,24 +183,6 @@ public abstract class FastCollection<E> implements Collection<E>, Serializable {
}
/**
- * Returns a parallel collection. Closure-based operations are
- * performed {@link javolution.context.ConcurrentContext in parallel}
- * on {@link CollectionService#split sub-views} of this collection.
- * The number of parallel views is equals to
- * {@link javolution.context.ConcurrentContext#getConcurrency()
- * concurrency}{@code + 1}.
- *
- * @see #perform(Consumer)
- * @see #update(Consumer)
- * @see #forEach(Consumer)
- * @see #removeIf(Predicate)
- * @see #reduce(Reducer)
- */
- public FastCollection<E> parallel() {
- return new ParallelCollectionImpl<E>(service());
- }
-
- /**
* Returns a sequential view of this collection. Using this view,
* all closure-based iterations are performed sequentially.
*/
@@ -640,16 +599,21 @@ public abstract class FastCollection<E> implements Collection<E>, Serializable {
return service().hashCode();
}
- /**
- * Returns the string representation of this collection using its
- * default {@link TextFormat format}.
- *
- * @see TextContext
- */
@Override
@Realtime(limit = LINEAR)
public String toString() {
- return TextContext.getFormat(FastCollection.class).format(this);
+ StringBuilder builder = new StringBuilder();
+ builder.append("[");
+
+ Iterator<E> it = this.iterator();
+ while(it.hasNext()) {
+ builder.append(it.next().toString());
+ if(it.hasNext()) {
+ builder.append(",");
+ }
+ }
+ builder.append("]");
+ return builder.toString();
}
/**
@@ -666,50 +630,5 @@ public abstract class FastCollection<E> implements Collection<E>, Serializable {
return collection.service();
}
- ////////////////////////////////////////////////////////////////////////////
- // Textual format.
- //
-
- /**
- * Default text format for fast collections (parsing not supported).
- * It is the format used when printing standard {@code java.util.Collection}
- * instances except that elements are written using
- * their current {@link TextContext TextContext} format.
- */
- @Parallelizable
- public static class Format extends TextFormat<FastCollection<?>> {
-
- @Override
- public FastCollection<Object> parse(CharSequence csq, Cursor cursor)
- throws IllegalArgumentException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Appendable format(FastCollection<?> that, final Appendable dest)
- throws IOException {
- dest.append('[');
- Class<?> elementType = null;
- TextFormat<Object> format = null;
- for (Object element : that) {
- if (elementType == null) elementType = Void.class;
- else dest.append(", "); // Not the first.
- if (element == null) {
- dest.append("null");
- continue;
- }
- Class<?> cls = element.getClass();
- if (elementType.equals(cls)) {
- format.format(element, dest);
- continue;
- }
- elementType = cls;
- format = TextContext.getFormat(cls);
- format.format(element, dest);
- }
- return dest.append(']');
- }
-
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastMap.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastMap.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastMap.java
index 852d86c..528aa47 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastMap.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/FastMap.java
@@ -8,30 +8,24 @@
*/
package javolution.util;
-import static javolution.lang.Realtime.Limit.CONSTANT;
-import static javolution.lang.Realtime.Limit.LINEAR;
-
-import java.io.Serializable;
-import java.util.ConcurrentModificationException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-
import javolution.lang.Immutable;
import javolution.lang.Parallelizable;
import javolution.lang.Realtime;
-import javolution.text.TextContext;
import javolution.util.function.Consumer;
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
-import javolution.util.internal.map.AtomicMapImpl;
-import javolution.util.internal.map.FastMapImpl;
-import javolution.util.internal.map.ParallelMapImpl;
-import javolution.util.internal.map.SequentialMapImpl;
-import javolution.util.internal.map.SharedMapImpl;
-import javolution.util.internal.map.UnmodifiableMapImpl;
+import javolution.util.internal.map.*;
import javolution.util.service.CollectionService;
import javolution.util.service.MapService;
+import java.io.Serializable;
+import java.util.ConcurrentModificationException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
+import static javolution.lang.Realtime.Limit.CONSTANT;
+import static javolution.lang.Realtime.Limit.LINEAR;
+
/**
* <p> A high-performance hash map with {@link Realtime real-time} behavior.
* Related to {@link FastCollection}, fast map supports various views.
@@ -164,20 +158,6 @@ public class FastMap<K, V> implements Map<K, V>, ConcurrentMap<K, V>,
}
/**
- * Returns a parallel map. Parallel maps affect closure-based operations
- * over the map or any of its views (entry, key, values, etc.), all others
- * operations behaving the same. Parallel maps do not require this map
- * to be thread-safe (internal synchronization).
- *
- * @see #perform(Consumer)
- * @see #update(Consumer)
- * @see FastCollection#parallel()
- */
- public FastMap<K, V> parallel() {
- return new FastMap<K, V>(new ParallelMapImpl<K, V>(service));
- }
-
- /**
* Returns a sequential view of this collection. Using this view,
* all closure-based iterations are performed sequentially.
*/
@@ -409,7 +389,7 @@ public class FastMap<K, V> implements Map<K, V>, ConcurrentMap<K, V>,
@Override
@Realtime(limit = LINEAR)
public String toString() {
- return TextContext.getFormat(FastCollection.class).format(entrySet());
+ return entrySet().toString();
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastSet.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastSet.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastSet.java
index 792173d..c5283c5 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastSet.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/FastSet.java
@@ -8,10 +8,6 @@
*/
package javolution.util;
-import static javolution.lang.Realtime.Limit.CONSTANT;
-
-import java.util.Set;
-
import javolution.lang.Realtime;
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
@@ -23,6 +19,10 @@ import javolution.util.internal.set.SharedSetImpl;
import javolution.util.internal.set.UnmodifiableSetImpl;
import javolution.util.service.SetService;
+import java.util.Set;
+
+import static javolution.lang.Realtime.Limit.CONSTANT;
+
/**
* <p> A high-performance hash set with {@link Realtime real-time} behavior.</p>
*
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedMap.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedMap.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedMap.java
index c971a66..7623f78 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedMap.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedMap.java
@@ -8,11 +8,6 @@
*/
package javolution.util;
-import static javolution.lang.Realtime.Limit.LOG_N;
-
-import java.util.Comparator;
-import java.util.SortedMap;
-
import javolution.lang.Realtime;
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
@@ -22,6 +17,11 @@ import javolution.util.internal.map.sorted.SharedSortedMapImpl;
import javolution.util.internal.map.sorted.UnmodifiableSortedMapImpl;
import javolution.util.service.SortedMapService;
+import java.util.Comparator;
+import java.util.SortedMap;
+
+import static javolution.lang.Realtime.Limit.LOG_N;
+
/**
* <p> A high-performance sorted map with {@link Realtime real-time} behavior.</p>
*
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedSet.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedSet.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedSet.java
index 1d446d7..8559070 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedSet.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedSet.java
@@ -8,10 +8,6 @@
*/
package javolution.util;
-import static javolution.lang.Realtime.Limit.LOG_N;
-
-import java.util.SortedSet;
-
import javolution.lang.Realtime;
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
@@ -21,6 +17,10 @@ import javolution.util.internal.set.sorted.SharedSortedSetImpl;
import javolution.util.internal.set.sorted.UnmodifiableSortedSetImpl;
import javolution.util.service.SortedSetService;
+import java.util.SortedSet;
+
+import static javolution.lang.Realtime.Limit.LOG_N;
+
/**
* <p> A high-performance sorted set with {@link Realtime real-time} behavior.</p>
*
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedTable.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedTable.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedTable.java
index 9151026..1b90692 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedTable.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/FastSortedTable.java
@@ -8,7 +8,6 @@
*/
package javolution.util;
-import static javolution.lang.Realtime.Limit.LOG_N;
import javolution.lang.Realtime;
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
@@ -18,6 +17,8 @@ import javolution.util.internal.table.sorted.SharedSortedTableImpl;
import javolution.util.internal.table.sorted.UnmodifiableSortedTableImpl;
import javolution.util.service.SortedTableService;
+import static javolution.lang.Realtime.Limit.LOG_N;
+
/**
* <p> A high-performance sorted table with {@link Realtime real-time} behavior.
* Sorted table have significantly faster {@link #contains},
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/e60b1a9a/commons/marmotta-commons/src/ext/java/javolution/util/FastTable.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/ext/java/javolution/util/FastTable.java b/commons/marmotta-commons/src/ext/java/javolution/util/FastTable.java
index 1e87fb8..40c171a 100644
--- a/commons/marmotta-commons/src/ext/java/javolution/util/FastTable.java
+++ b/commons/marmotta-commons/src/ext/java/javolution/util/FastTable.java
@@ -8,32 +8,17 @@
*/
package javolution.util;
-import static javolution.lang.Realtime.Limit.CONSTANT;
-import static javolution.lang.Realtime.Limit.LINEAR;
-import static javolution.lang.Realtime.Limit.LOG_N;
-import static javolution.lang.Realtime.Limit.N_LOG_N;
-import static javolution.lang.Realtime.Limit.N_SQUARE;
-
-import java.util.Collection;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.RandomAccess;
-
import javolution.lang.Realtime;
import javolution.util.function.Consumer;
import javolution.util.function.Equalities;
import javolution.util.function.Equality;
-import javolution.util.internal.table.AtomicTableImpl;
-import javolution.util.internal.table.FastTableImpl;
-import javolution.util.internal.table.QuickSort;
-import javolution.util.internal.table.ReversedTableImpl;
-import javolution.util.internal.table.SharedTableImpl;
-import javolution.util.internal.table.SubTableImpl;
-import javolution.util.internal.table.UnmodifiableTableImpl;
+import javolution.util.internal.table.*;
import javolution.util.service.TableService;
+import java.util.*;
+
+import static javolution.lang.Realtime.Limit.*;
+
/**
* <p> A high-performance table (fractal-based) with {@link Realtime real-time}
* behavior.</p>