[prev in list] [next in list] [prev in thread] [next in thread]
List: jibx-cvs
Subject: [Jibx-cvs] core/build/src/org/jibx/runtime/impl
From: Dennis Sosnoski <dsosnoski () users ! sourceforge ! net>
Date: 2008-07-17 10:59:11
Message-ID: E1KJRCc-0003aJ-TN () mail ! sourceforge ! net
[Download RAW message or body]
Update of /cvsroot/jibx/core/build/src/org/jibx/runtime/impl
In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv13472/src/org/jibx/runtime/impl
Modified Files:
ISO88591StreamWriter.java XMLWriterNamespaceBase.java
GenericXMLWriter.java UTF8StreamWriter.java
StreamWriterBase.java MarshallingContext.java
Log Message:
Add namespace translation table support to marshalling runtime code.
Index: UTF8StreamWriter.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/runtime/impl/UTF8StreamWriter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** UTF8StreamWriter.java 2 Jan 2008 09:49:43 -0000 1.9
--- UTF8StreamWriter.java 17 Jul 2008 10:59:08 -0000 1.10
***************
*** 142,146 ****
* Report that namespace has been defined.
*
! * @param index namespace URI index number
* @param prefix prefix used for namespace
*/
--- 142,146 ----
* Report that namespace has been defined.
*
! * @param index post-translation namespace URI index number
* @param prefix prefix used for namespace
*/
Index: MarshallingContext.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/runtime/impl/MarshallingContext.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** MarshallingContext.java 30 Dec 2007 09:52:32 -0000 1.16
--- MarshallingContext.java 17 Jul 2008 10:59:08 -0000 1.17
***************
*** 33,41 ****
import org.jibx.runtime.*;
- import org.jibx.runtime.ICharacterEscaper;
- import org.jibx.runtime.IMarshallable;
- import org.jibx.runtime.IMarshaller;
- import org.jibx.runtime.IMarshallingContext;
- import org.jibx.runtime.JiBXException;
/**
--- 33,36 ----
***************
*** 1136,1139 ****
--- 1131,1162 ----
/**
+ * Use namespace indexes from a separate binding, as identified by that
+ * binding's factory class name. The target binding must be a precompiled
+ * base binding of the binding used to create this marshalling context,
+ * either directly or by way of some other precompiled base binding(s).
+ *
+ * @param factname binding factory class name for binding defining namespaces
+ */
+ public void pushNamespaces(String factname) {
+ Map tablemap = m_factory.getNamespaceTranslationTableMap();
+ int[] table = (int[])tablemap.get(factname);
+ if (table == null) {
+ throw new IllegalStateException("Binding error: Factory name " +
+ factname + " has no namespace translation table defined");
+ } else {
+ m_writer.pushTranslationTable(table);
+ }
+ }
+
+ /**
+ * End use of namespace indexes from a separate binding. This will undo the
+ * effect of the most-recent call to {@link #pushNamespaces(String)},
+ * restoring whatever namespace usage was in effect prior to that call.
+ */
+ public void popNamespaces() {
+ m_writer.popTranslationTable();
+ }
+
+ /**
* Get shared ID map. The ID map returned is not used directly by the
* marshalling code, but is provided to support user extensions.
Index: GenericXMLWriter.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/runtime/impl/GenericXMLWriter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** GenericXMLWriter.java 26 Jul 2007 01:14:57 -0000 1.9
--- GenericXMLWriter.java 17 Jul 2008 10:59:07 -0000 1.10
***************
*** 167,171 ****
* Report that namespace has been defined.
*
! * @param index namespace URI index number
* @param prefix prefix used for namespace
*/
--- 167,171 ----
* Report that namespace has been defined.
*
! * @param index post-translation namespace URI index number
* @param prefix prefix used for namespace
*/
***************
*** 175,185 ****
* Report that namespace has been undefined.
*
! * @param index namespace URI index number
*/
protected void undefineNamespace(int index) {}
/**
! * Write namespace prefix to output. This internal method is used to throw
! * an exception when an undeclared prefix is used.
*
* @param index namespace URI index number
--- 175,186 ----
* Report that namespace has been undefined.
*
! * @param index post-translation namespace URI index number
*/
protected void undefineNamespace(int index) {}
/**
! * Write namespace prefix to output. This internal method is used to handle
! * translation of namespace indexes to internal form, and also to throw an
! * exception when an undeclared prefix is used.
*
* @param index namespace URI index number
Index: XMLWriterNamespaceBase.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/runtime/impl/XMLWriterNamespaceBase.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** XMLWriterNamespaceBase.java 20 Nov 2007 00:21:31 -0000 1.10
--- XMLWriterNamespaceBase.java 17 Jul 2008 10:59:07 -0000 1.11
***************
*** 1,4 ****
/*
! Copyright (c) 2004-2005, Dennis M. Sosnoski.
All rights reserved.
--- 1,4 ----
/*
! Copyright (c) 2004-2008, Dennis M. Sosnoski.
All rights reserved.
***************
*** 40,44 ****
*
* @author Dennis M. Sosnoski
- * @version 1.0
*/
public abstract class XMLWriterNamespaceBase implements IXMLWriter
--- 40,43 ----
***************
*** 68,71 ****
--- 67,77 ----
private String[][] m_extensionPrefixes;
+ /** Current namespace translation table (<code>null</code> if none). */
+ private int[] m_translateTable;
+
+ /** Stack of namespace translation tables in use (<code>null</code> if
+ none). */
+ private Stack m_translateTableStack;
+
/**
* Constructor.
***************
*** 102,106 ****
* Report to subclass that namespace has been defined.
*
! * @param index namespace URI index number
* @param prefix prefix used for namespace
* @throws IOException if error writing to document
--- 108,112 ----
* Report to subclass that namespace has been defined.
*
! * @param index post-translation namespace URI index number
* @param prefix prefix used for namespace
* @throws IOException if error writing to document
***************
*** 112,116 ****
* Report to subclass that namespace has been undefined.
*
! * @param index namespace URI index number
*/
protected abstract void undefineNamespace(int index);
--- 118,122 ----
* Report to subclass that namespace has been undefined.
*
! * @param index post-translation namespace URI index number
*/
protected abstract void undefineNamespace(int index);
***************
*** 132,136 ****
* Set prefix for namespace.
*
! * @param index namespace URI index number
* @param prefix
*/
--- 138,142 ----
* Set prefix for namespace.
*
! * @param index post-translation namespace URI index number
* @param prefix
*/
***************
*** 205,208 ****
--- 211,219 ----
// replace the full set, tracking the prior values
deltas = nums;
+ if (m_translateTable != null) {
+ for (int i = 0; i < deltas.length; i++) {
+ deltas[i] = m_translateTable[deltas[i]];
+ }
+ }
for (int i = 0; i < count; i++) {
int slot = deltas[i];
***************
*** 220,227 ****
int slot = nums[i];
if (slot >= 0) {
! deltas[fill] = slot;
priors[fill++] = getNamespacePrefix(slot);
! setNamespacePrefix(slot, prefs[i]);
! defineNamespace(slot, prefs[i]);
}
}
--- 231,239 ----
int slot = nums[i];
if (slot >= 0) {
! int xlate = translateNamespace(slot);
! deltas[fill] = xlate;
priors[fill++] = getNamespacePrefix(slot);
! setNamespacePrefix(xlate, prefs[i]);
! defineNamespace(xlate, prefs[i]);
}
}
***************
*** 358,362 ****
public final String getNamespaceUri(int index) {
if (index < m_uris.length) {
! return m_uris[index];
} else if (m_extensionUris != null) {
index -= m_uris.length;
--- 370,374 ----
public final String getNamespaceUri(int index) {
if (index < m_uris.length) {
! return m_uris[translateNamespace(index)];
} else if (m_extensionUris != null) {
index -= m_uris.length;
***************
*** 382,386 ****
public final String getNamespacePrefix(int index) {
if (index < m_prefixes.length) {
! return m_prefixes[index];
} else if (m_extensionUris != null) {
index -= m_prefixes.length;
--- 394,398 ----
public final String getNamespacePrefix(int index) {
if (index < m_prefixes.length) {
! return m_prefixes[translateNamespace(index)];
} else if (m_extensionUris != null) {
index -= m_prefixes.length;
***************
*** 398,404 ****
/**
! * Get index of namespace mapped to prefix. This can be an expensive
! * operation with time proportional to the number of namespaces defined, so
! * it should be used with care.
*
* @param prefix text to match (non-<code>null</code>, use "" for default
--- 410,418 ----
/**
! * Get index of namespace mapped to prefix. If namespace translation is in
! * use, the returned index will be the value prior to translation. This can
! * be an expensive operation (regardless of whether translation is used or
! * not) with time proportional to the number of namespaces defined, so it
! * should be used with care.
*
* @param prefix text to match (non-<code>null</code>, use "" for default
***************
*** 421,427 ****
}
}
! for (int i = m_prefixes.length-1; i >= 0; i--) {
! if (prefix.equals(m_prefixes[i])) {
! return i;
}
}
--- 435,450 ----
}
}
! if (m_translateTable == null) {
! for (int i = m_prefixes.length-1; i >= 0; i--) {
! if (prefix.equals(m_prefixes[i])) {
! return i;
! }
! }
! } else {
! for (int i = m_translateTable.length-1; i >= 0; i--) {
! int xlate = m_translateTable[i];
! if (prefix.equals(m_prefixes[xlate])) {
! return xlate;
! }
}
}
***************
*** 500,503 ****
--- 523,575 ----
/**
+ * Translate a namespace index number to match internal tables.
+ *
+ * @param index raw namespace index
+ * @return namespace index number for internal tables
+ */
+ public int translateNamespace(int index) {
+ if (m_translateTable != null && index < m_uris.length) {
+ if (index > m_translateTable.length) {
+ throw new IllegalStateException("Unable to translate namespace \
outside of binding range"); + } else {
+ return m_translateTable[index];
+ }
+ } else {
+ return index;
+ }
+ }
+
+ /**
+ * Push a translation table to be used for converting namespace index
+ * numbers passed as arguments to values used for internal lookup. This
+ * allows a layer of indirection between the client code and the
+ * namespace definitions, designed for use in supporting precompiled
+ * bindings. The translated values must match the internal tables.
+ *
+ * @param table translation table to be used
+ */
+ public void pushTranslationTable(int[] table) {
+ if (m_translateTable != null) {
+ if (m_translateTableStack == null) {
+ m_translateTableStack = new Stack();
+ }
+ m_translateTableStack.push(m_translateTable);
+ }
+ m_translateTable = table;
+ }
+
+ /**
+ * Pop a translation table used for converting namespace index numbers to
+ * values matching the internal lookup.
+ */
+ public void popTranslationTable() {
+ if (m_translateTableStack != null && m_translateTableStack.size() > 0) {
+ m_translateTable = (int[])m_translateTableStack.pop();
+ } else {
+ m_translateTable = null;
+ }
+ }
+
+ /**
* Namespace declaration tracking information. This tracks all information
* associated with an element that declares namespaces.
Index: ISO88591StreamWriter.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/runtime/impl/ISO88591StreamWriter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ISO88591StreamWriter.java 20 Apr 2008 22:54:08 -0000 1.8
--- ISO88591StreamWriter.java 17 Jul 2008 10:59:07 -0000 1.9
***************
*** 136,140 ****
* Report that namespace has been defined.
*
! * @param index namespace URI index number
* @param prefix prefix used for namespace
* @throws IOException if error writing to document
--- 136,140 ----
* Report that namespace has been defined.
*
! * @param index post-translation namespace URI index number
* @param prefix prefix used for namespace
* @throws IOException if error writing to document
Index: StreamWriterBase.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/runtime/impl/StreamWriterBase.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** StreamWriterBase.java 2 Jan 2008 09:49:43 -0000 1.13
--- StreamWriterBase.java 17 Jul 2008 10:59:08 -0000 1.14
***************
*** 286,290 ****
* Report that namespace has been undefined.
*
! * @param index namespace URI index number
*/
protected void undefineNamespace(int index) {
--- 286,290 ----
* Report that namespace has been undefined.
*
! * @param index post-translation namespace URI index number
*/
protected void undefineNamespace(int index) {
***************
*** 318,322 ****
byte[] bytes = null;
if (index < m_prefixBytes.length) {
! bytes = m_prefixBytes[index];
} else if (m_extensionBytes != null) {
index -= m_prefixes.length;
--- 318,322 ----
byte[] bytes = null;
if (index < m_prefixBytes.length) {
! bytes = m_prefixBytes[translateNamespace(index)];
} else if (m_extensionBytes != null) {
index -= m_prefixes.length;
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Jibx-cvs mailing list
Jibx-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic