[prev in list] [next in list] [prev in thread] [next in thread]
List: jibx-cvs
Subject: [Jibx-cvs] core/build/src/org/jibx/binding/def
From: Dennis Sosnoski <dsosnoski () users ! sourceforge ! net>
Date: 2008-07-22 1:13:26
Message-ID: E1KL6RW-0004WW-7O () mail ! sourceforge ! net
[Download RAW message or body]
Update of /cvsroot/jibx/core/build/src/org/jibx/binding/def
In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv4158/src/org/jibx/binding/def
Modified Files:
DefinitionContext.java PrecompiledAbstractMapping.java
PrecompiledBinding.java NamespaceDefinition.java
BindingBuilder.java BindingDefinition.java
Log Message:
Full implementation of namespace support for modular bindings, including use with abstract mappings.
Index: DefinitionContext.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/binding/def/DefinitionContext.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** DefinitionContext.java 18 Dec 2006 10:44:06 -0000 1.11
--- DefinitionContext.java 22 Jul 2008 01:13:23 -0000 1.12
***************
*** 35,39 ****
import org.jibx.binding.classes.MethodBuilder;
import org.jibx.binding.util.ArrayMap;
-
import org.jibx.runtime.JiBXException;
import org.jibx.runtime.QName;
--- 35,38 ----
***************
*** 64,70 ****
private ArrayList m_namespaces;
- /** Mapping from prefix to namespace definition (lazy create). */
- private HashMap m_prefixMap;
-
/** Mapping from URI to namespace definition (lazy create). */
private HashMap m_uriMap;
--- 63,66 ----
***************
*** 105,109 ****
/**
! * Check for duplicate or conflicting namespace. This also intializes the
* namespace structures for this context the first time the method is
* called.
--- 101,105 ----
/**
! * Check for duplicate namespace definition. This also initializes the
* namespace structures for this context the first time the method is
* called.
***************
*** 112,156 ****
* @return duplicate flag (either complete duplicate, or prior definition
* of same URI with prefix is present)
- * @throws JiBXException on conflicting prefix
*/
! private boolean checkDuplicateNamespace(NamespaceDefinition def)
! throws JiBXException {
// create structures if not already done
if (m_namespaces == null) {
m_namespaces = new ArrayList();
- m_prefixMap = new HashMap();
m_uriMap = new HashMap();
}
! // check for conflict (or duplicate) on prefix
String uri = def.getUri();
! String prefix = def.getPrefix();
! NamespaceDefinition dup = (NamespaceDefinition)m_prefixMap.get(prefix);
! DefinitionContext ctx = this;
! while (dup == null && (ctx = ctx.m_context) != null) {
! if (ctx.m_prefixMap != null) {
! dup = (NamespaceDefinition)ctx.m_prefixMap.get(prefix);
! }
! }
! if (dup == null) {
!
! // check for duplicate definition of same URI, but with prefix
! NamespaceDefinition prior = (NamespaceDefinition)m_uriMap.get(uri);
! if (prior != null && prior.getPrefix() != null) {
! return true;
! } else {
! return false;
! }
!
! } else {
!
! // check for repeated definition of same namespace
! if (uri.equals(dup.getUri())) {
! return true;
! } else {
! throw new JiBXException("Namespace prefix conflict");
! }
! }
}
--- 108,124 ----
* @return duplicate flag (either complete duplicate, or prior definition
* of same URI with prefix is present)
*/
! private boolean checkDuplicateNamespace(NamespaceDefinition def) {
// create structures if not already done
if (m_namespaces == null) {
m_namespaces = new ArrayList();
m_uriMap = new HashMap();
}
! // check for conflict (or duplicate) definition
String uri = def.getUri();
! NamespaceDefinition prior = (NamespaceDefinition)m_uriMap.get(uri);
! return prior != null && (prior.getPrefix() != null || def.getPrefix() == null);
}
***************
*** 166,170 ****
getNamespaceUriIndex(uri, prefix));
m_namespaces.add(def);
- m_prefixMap.put(prefix, def);
m_uriMap.put(uri, def);
}
--- 134,137 ----
***************
*** 176,202 ****
*
* @param def namespace definition to be added (duplicates ignored)
- * @throws JiBXException on namespace definition conflict
*/
! public void addNamespace(NamespaceDefinition def) throws JiBXException {
if (!checkDuplicateNamespace(def)) {
// check for conflict as default for attributes
if (def.isAttributeDefault()) {
! if (m_attributeDefault == null) {
! m_attributeDefault = def;
! } else {
! throw new JiBXException
! ("Multiple default attribute namespaces at level");
! }
}
// check for conflict as default for elements
if (def.isElementDefault()) {
! if (m_elementDefault == null) {
! m_elementDefault = def;
! } else {
! throw new JiBXException
! ("Multiple default element namespaces at level");
! }
}
--- 143,158 ----
*
* @param def namespace definition to be added (duplicates ignored)
*/
! public void addNamespace(NamespaceDefinition def) {
if (!checkDuplicateNamespace(def)) {
// check for conflict as default for attributes
if (def.isAttributeDefault()) {
! m_attributeDefault = def;
}
// check for conflict as default for elements
if (def.isElementDefault()) {
! m_elementDefault = def;
}
***************
*** 213,219 ****
*
* @param def namespace definition to be added (duplicates ignored)
- * @throws JiBXException on namespace definition conflict
*/
! public void addImpliedNamespace(NamespaceDefinition def) throws JiBXException {
if (!checkDuplicateNamespace(def)) {
internalAddNamespace(def);
--- 169,174 ----
*
* @param def namespace definition to be added (duplicates ignored)
*/
! public void addImpliedNamespace(NamespaceDefinition def) {
if (!checkDuplicateNamespace(def)) {
internalAddNamespace(def);
Index: BindingBuilder.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/binding/def/BindingBuilder.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** BindingBuilder.java 17 Jul 2008 10:57:17 -0000 1.42
--- BindingBuilder.java 22 Jul 2008 01:13:24 -0000 1.43
***************
*** 1827,1830 ****
--- 1827,1832 ----
* @param factory binding factory for mapping information
* @param parent containing binding definition structure
+ * @param nsxlate namespace index translation table (<code>null</code> if
+ * none)
* @param nss extra namespaces to be included in this mapping definition
* (may be <code>null</code>)
***************
*** 1832,1836 ****
*/
private static void unmarshalPrecompiledMappings(UnmarshallingContext ctx,
! IBindingFactory factory, IContainer parent) throws JiBXException {
// flag classes with binding code as unmodifiable
--- 1834,1838 ----
*/
private static void unmarshalPrecompiledMappings(UnmarshallingContext ctx,
! IBindingFactory factory, IContainer parent, int[] nsxlate) throws JiBXException {
// flag classes with binding code as unmodifiable
***************
*** 1909,1913 ****
PrecompiledAbstractMapping mapping =
new PrecompiledAbstractMapping(type, tname, index, factory,
! parent);
parent.getDefinitionContext().addMapping(mapping);
}
--- 1911,1915 ----
PrecompiledAbstractMapping mapping =
new PrecompiledAbstractMapping(type, tname, index, factory,
! nsxlate, parent);
parent.getDefinitionContext().addMapping(mapping);
}
***************
*** 1994,2001 ****
IBindingFactory factory = BindingDirectory.getFactory(name,
tpack, ClassFile.getClassLoader());
! bdef.addPrecompiledBinding(factory, major, minor);
// add mapping information from precompiled binding
! unmarshalPrecompiledMappings(ictx, factory, bdef);
} else {
--- 1996,2004 ----
IBindingFactory factory = BindingDirectory.getFactory(name,
tpack, ClassFile.getClassLoader());
! int[] nsxlate =
! bdef.addPrecompiledBinding(factory, major, minor);
// add mapping information from precompiled binding
! unmarshalPrecompiledMappings(ictx, factory, bdef, nsxlate);
} else {
***************
*** 2005,2009 ****
} catch (IOException e) {
throw new JiBXException
! ("Error accessing included binding with path " + path, e);
}
}
--- 2008,2012 ----
} catch (IOException e) {
throw new JiBXException
! ("Error accessing included binding with path " + path + " (" + fpath + ')', e);
}
}
Index: BindingDefinition.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/binding/def/BindingDefinition.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** BindingDefinition.java 17 Jul 2008 10:55:48 -0000 1.27
--- BindingDefinition.java 22 Jul 2008 01:13:24 -0000 1.28
***************
*** 32,37 ****
--- 32,40 ----
import java.util.ArrayList;
import java.util.HashMap;
+ import java.util.HashSet;
import java.util.List;
import java.util.Map;
+ import java.util.Set;
+ import java.util.TreeSet;
import org.apache.bcel.Constants;
***************
*** 63,66 ****
--- 66,72 ----
// Miscellaneous static data.
+ /** First namespace index available for user definitions. */
+ public static final int BASE_USER_NAMESPACE = 3;
+
/** Current distribution file name. This is filled in by the Ant build
process to match the current distribution. */
***************
*** 260,263 ****
--- 266,272 ----
private ArrayList m_namespacePrefixes;
+ /** High mark in prefixes from from precompiled base bindings. */
+ private int m_highBasePrefix;
+
/** Outer definition context with default definitions. */
private DefinitionContext m_outerContext;
***************
*** 276,309 ****
/** Classes handled by in-line marshaller/unmarshaller references. */
! private List m_extraClasses;
/** Marshaller classes used in-line. */
! private List m_extraMarshallers;
/** Unmarshaller classes used in-line. */
! private List m_extraUnmarshallers;
/** Precompiled base binding names used by this binding. */
! private List m_precompiledBindings;
!
! /** Factory classes for precompiled base bindings used by this binding. */
! private List m_precompiledBindingFactories;
! /** Required major versions for base bindings (same order as factories). */
! private List m_precompiledMajors;
! /** Required minor versions for base bindings (same order as factories). */
! private List m_precompiledMinors;
! /** Namespace index mapping tables for base bindings (same order as
! factories). */
! private List m_precompiledNamespaceTables;
/** Factory classes for base bindings of base bindings. */
! private List m_closureFactories;
/** Namespace index mapping tables for base bindings of base bindings (same
order as factories). */
! private List m_closureNamespaceTables;
/** Generated binding factory class. */
--- 285,316 ----
/** Classes handled by in-line marshaller/unmarshaller references. */
! private ArrayList m_extraClasses;
/** Marshaller classes used in-line. */
! private ArrayList m_extraMarshallers;
/** Unmarshaller classes used in-line. */
! private ArrayList m_extraUnmarshallers;
/** Precompiled base binding names used by this binding. */
! private ArrayList m_baseBindings;
! /** Factory class names for precompiled base bindings (same order as binding
! names). */
! private ArrayList m_baseBindingFactories;
! /** Hashes for base binding factories (same order as binding names). */
! private ArrayList m_baseHashes;
! /** Namespace index mapping tables for base bindings (same order as binding
! names). */
! private ArrayList m_baseNamespaceTables;
/** Factory classes for base bindings of base bindings. */
! private ArrayList m_closureFactories;
/** Namespace index mapping tables for base bindings of base bindings (same
order as factories). */
! private ArrayList m_closureNamespaceTables;
/** Generated binding factory class. */
***************
*** 344,352 ****
m_majorVersion = major;
m_minorVersion = minor;
! m_precompiledBindings = new ArrayList();
! m_precompiledBindingFactories = new ArrayList();
! m_precompiledMajors = new ArrayList();
! m_precompiledMinors = new ArrayList();
! m_precompiledNamespaceTables = new ArrayList();
m_closureFactories = new ArrayList();
m_closureNamespaceTables = new ArrayList();
--- 351,358 ----
m_majorVersion = major;
m_minorVersion = minor;
! m_baseBindings = new ArrayList();
! m_baseBindingFactories = new ArrayList();
! m_baseHashes = new ArrayList();
! m_baseNamespaceTables = new ArrayList();
m_closureFactories = new ArrayList();
m_closureNamespaceTables = new ArrayList();
***************
*** 644,649 ****
public int getNamespaceUriIndex(String uri, String prefix) {
int index = m_namespaceUris.findOrAdd(uri);
! if (index > m_namespacePrefixes.size()) {
m_namespacePrefixes.add(prefix);
}
return index;
--- 650,658 ----
public int getNamespaceUriIndex(String uri, String prefix) {
int index = m_namespaceUris.findOrAdd(uri);
! int size = m_namespacePrefixes.size();
! if (index == size) {
m_namespacePrefixes.add(prefix);
+ } else if (index > size) {
+ throw new IllegalStateException("Internal error - prefixes not matched with namespaces");
}
return index;
***************
*** 666,678 ****
* @param major required major version number
* @param minor required minor version number
*/
! public void addPrecompiledBinding(IBindingFactory factory, int major,
int minor) {
// add basic information for precompiled base binding
! m_precompiledBindings.add(factory.getBindingName());
! m_precompiledBindingFactories.add(factory.getClass().getName());
! m_precompiledMajors.add(IntegerCache.getInteger(major));
! m_precompiledMinors.add(IntegerCache.getInteger(minor));
// add all namespaces from precompiled binding
--- 675,687 ----
* @param major required major version number
* @param minor required minor version number
+ * @return namespace index translation table (<code>null</code> if none)
*/
! public int[] addPrecompiledBinding(IBindingFactory factory, int major,
int minor) {
// add basic information for precompiled base binding
! m_baseBindings.add(factory.getBindingName());
! m_baseBindingFactories.add(factory.getClass().getName());
! m_baseHashes.add(new Integer(factory.getHash()));
// add all namespaces from precompiled binding
***************
*** 682,686 ****
boolean xlate = false;
for (int i = 1; i < namespaces.length; i++) {
! int index = getNamespaceUriIndex(namespaces[i], prefixes[i-1]);
indexes[i] = index;
if (i != index) {
--- 691,695 ----
boolean xlate = false;
for (int i = 1; i < namespaces.length; i++) {
! int index = getNamespaceUriIndex(namespaces[i], prefixes[i]);
indexes[i] = index;
if (i != index) {
***************
*** 688,695 ****
}
}
if (xlate) {
// add translation table to list of tables for bindings
! m_precompiledNamespaceTables.add(indexes);
// generate substitute translation tables for all base bindings
--- 697,705 ----
}
}
+ m_highBasePrefix = m_namespacePrefixes.size();
if (xlate) {
// add translation table to list of tables for bindings
! m_baseNamespaceTables.add(indexes);
// generate substitute translation tables for all base bindings
***************
*** 708,716 ****
}
}
} else {
// no need for translation table, just add null to list of tables
! m_precompiledNamespaceTables.add(null);
}
--- 718,728 ----
}
}
+ return indexes;
} else {
// no need for translation table, just add null to list of tables
! m_baseNamespaceTables.add(null);
! return null;
}
***************
*** 718,721 ****
--- 730,789 ----
/**
+ * Fix the prefixes for namespaces imported from precompiled base bindings.
+ * If there are no namespaces from precompiled base bindings, or these
+ * namespaces use prefixes which are unique from each other and from those
+ * used in this binding, nothing is done. If there are conflicts or
+ * namespaces used without prefixes this sets unique prefixes for each
+ * namespace.
+ */
+ private void fixPrefixes() {
+ if (m_highBasePrefix > 0) {
+ Set prefset = new HashSet();
+ prefset.add("");
+ for (int i = m_highBasePrefix; i < m_namespacePrefixes.size(); i++) {
+ prefset.add((String)m_namespacePrefixes.get(i));
+ }
+ int genindex = 0;
+ for (int i = BASE_USER_NAMESPACE; i < m_highBasePrefix; i++) {
+ String prefix = (String)m_namespacePrefixes.get(i);
+ while (prefset.contains(prefix)) {
+ StringBuffer buff = new StringBuffer();
+ buff.append((char)('a' + genindex++ % 26));
+ int remain = genindex / 26;
+ while (remain > 0) {
+ int next = remain % 36;
+ if (next < 10) {
+ buff.append((char)('0' + next));
+ } else {
+ buff.append((char)('a' + next));
+ }
+ remain /= 36;
+ }
+ prefix = buff.toString();
+ }
+ prefset.add(prefix);
+ m_namespacePrefixes.set(i, prefix);
+ }
+ }
+ }
+
+ /**
+ * Get the prefix assigned for a namespace. This is intended mainly for use
+ * with precompiled bindings, where the {@link #fixPrefixes()} method may
+ * change the initial prefixes (if any) in order to avoid conflicts.
+ *
+ * @param uri namespace URI
+ * @return prefix for namespace
+ */
+ public String getPrefix(String uri) {
+ int index = m_namespaceUris.find(uri);
+ if (index >= 0) {
+ return (String)m_namespacePrefixes.get(index);
+ } else {
+ throw new IllegalStateException("Internal error - URI not registered");
+ }
+ }
+
+ /**
* Build a class or method name blob from an array of fully-qualified class
* and/or method names. The returned string consists of compacted
***************
*** 917,920 ****
--- 985,989 ----
// handle basic linkage and child code generation
BoundClass.setModify(m_targetRoot, m_targetPackage);
+ fixPrefixes();
m_activeContext.linkMappings();
m_activeContext.setLinkages();
***************
*** 1064,1070 ****
}
! // create argument blob of abstract mapping information
ArrayList allnames = new ArrayList();
int abmapcnt = 0;
for (int i = 0; i < count; i++) {
String tname = (String)s_mappedClasses.get(i);
--- 1133,1140 ----
}
! // create argument blobs of abstract mapping information
ArrayList allnames = new ArrayList();
int abmapcnt = 0;
+ StringBuffer buff = new StringBuffer();
for (int i = 0; i < count; i++) {
String tname = (String)s_mappedClasses.get(i);
***************
*** 1084,1103 ****
allnames.add(bind.getContentMarshalMethod());
abmapcnt++;
}
}
codegenString(buildClassNamesBlob(allnames), mb);
// create argument blobs of precompiled base binding names and factories
! int basecount = m_precompiledBindings.size();
String[] bindings = new String[basecount];
! bindings = (String[])m_precompiledBindings.toArray(bindings);
codegenString(buildNamesBlob(bindings), mb);
! String namesblob = buildClassNamesBlob(m_precompiledBindingFactories) +
buildClassNamesBlob(m_closureFactories);
codegenString(namesblob, mb);
! // create argument blobs for major and minor version numbers
! codegenString(buildIntsBlob(m_precompiledMajors), mb);
! codegenString(buildIntsBlob(m_precompiledMinors), mb);
// create array of blobs of base binding namespace translation tables
--- 1154,1190 ----
allnames.add(bind.getContentMarshalMethod());
abmapcnt++;
+ ArrayList nss = map.getNamespaces();
+ if (nss == null) {
+ buff.append((char)1);
+ } else {
+ buff.append((char)(nss.size()+1));
+ for (int j = 0; j < nss.size(); j++) {
+ NamespaceDefinition nsdef =
+ (NamespaceDefinition)nss.get(j);
+ buff.append((char)(nsdef.getIndex()+1));
+ }
+ }
}
}
codegenString(buildClassNamesBlob(allnames), mb);
+ codegenString(buff.toString(), mb);
// create argument blobs of precompiled base binding names and factories
! int basecount = m_baseBindings.size();
String[] bindings = new String[basecount];
! bindings = (String[])m_baseBindings.toArray(bindings);
codegenString(buildNamesBlob(bindings), mb);
! String namesblob = buildClassNamesBlob(m_baseBindingFactories) +
buildClassNamesBlob(m_closureFactories);
codegenString(namesblob, mb);
! // create argument blob for base binding factory hashes
! char[] hashchars = new char[basecount*2];
! for (int i = 0; i < basecount; i++) {
! int hash = ((Integer)m_baseHashes.get(i)).intValue();
! hashchars[i*2] = (char)(hash >> 16);
! hashchars[i*2+1] = (char)hash;
! }
! codegenString(new String(hashchars), mb);
// create array of blobs of base binding namespace translation tables
***************
*** 1105,1109 ****
mb.appendCreateArray("java.lang.String");
for (int i = 0; i < basecount; i++) {
! int[] table = (int[])m_precompiledNamespaceTables.get(i);
if (table != null) {
mb.appendDUP();
--- 1192,1196 ----
mb.appendCreateArray("java.lang.String");
for (int i = 0; i < basecount; i++) {
! int[] table = (int[])m_baseNamespaceTables.get(i);
if (table != null) {
mb.appendDUP();
***************
*** 1274,1278 ****
}
}
!
/**
* Add the list of classes used by the binding compiler to the binding
--- 1361,1365 ----
}
}
!
/**
* Add the list of classes used by the binding compiler to the binding
***************
*** 1288,1300 ****
public void addClassList(ClassFile[] adds, ClassFile[] keeps) {
! // build an array of all the class names used in the binding
int addcount = adds.length;
- String[] refs = new String[addcount + keeps.length];
for (int i = 0; i < addcount; i++) {
! refs[i] = adds[i].getName();
}
for (int i = 0; i < keeps.length; i++) {
! refs[addcount + i] = keeps[i].getName();
}
// replace dummy static fields in factory with actual values
--- 1375,1388 ----
public void addClassList(ClassFile[] adds, ClassFile[] keeps) {
! // build a sorted tree of all the class names used in the binding
! Set tree = new TreeSet();
int addcount = adds.length;
for (int i = 0; i < addcount; i++) {
! tree.add(adds[i].getName());
}
for (int i = 0; i < keeps.length; i++) {
! tree.add(keeps[i].getName());
}
+ String[] refs = (String[])tree.toArray(new String[tree.size()]);
// replace dummy static fields in factory with actual values
Index: PrecompiledBinding.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/binding/def/PrecompiledBinding.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PrecompiledBinding.java 2 Jul 2008 11:54:31 -0000 1.2
--- PrecompiledBinding.java 22 Jul 2008 01:13:23 -0000 1.3
***************
*** 58,61 ****
--- 58,68 ----
private static final String PRESENCE_TEST_SIG =
"(" + UNMARSHALLING_CONTEXT_SIG + ")Z";
+ private static final String PUSH_NAMESPACES_METHOD =
+ "org.jibx.runtime.IMarshallingContext.pushNamespaces";
+ private static final String PUSH_NAMESPACES_SIG =
+ "(Ljava/lang/String;)V";
+ private static final String POP_NAMESPACES_METHOD =
+ "org.jibx.runtime.IMarshallingContext.popNamespaces";
+ private static final String POP_NAMESPACES_SIG = "()V";
//
***************
*** 100,103 ****
--- 107,114 ----
/** Signature used for marshalling (and prepare) methods. */
private final String m_marshalSignature;
+
+ /** Binding factory name used for activating namespace translation on
+ marshalling (<code>null</code> if translation not required). */
+ private final String m_factoryName;
/**
***************
*** 106,112 ****
* @param index abstract mapping index in binding
* @param abmaps abstract mapping information from binding
* @throws JiBXException on error loading class information
*/
! public PrecompiledBinding(int index, String[][] abmaps) throws JiBXException {
m_class = ClassCache.getClassFile(abmaps[IBindingFactory.ABMAP_CLASSNAME_INDEX][index]);
m_newInstanceName = abmaps[IBindingFactory.ABMAP_CREATEMETH_INDEX][index];
--- 117,126 ----
* @param index abstract mapping index in binding
* @param abmaps abstract mapping information from binding
+ * @param xlated translated namespaces for binding flag
+ * @param factname binding factory name
* @throws JiBXException on error loading class information
*/
! public PrecompiledBinding(int index, String[][] abmaps, boolean xlated,
! String factname) throws JiBXException {
m_class = ClassCache.getClassFile(abmaps[IBindingFactory.ABMAP_CLASSNAME_INDEX][index]);
m_newInstanceName = abmaps[IBindingFactory.ABMAP_CREATEMETH_INDEX][index];
***************
*** 124,127 ****
--- 138,142 ----
m_completeSignature = basesig + "V";
m_marshalSignature = "(" + classig + MARSHALLING_CONTEXT_SIG + ")V";
+ m_factoryName = xlated ? factname : null;
}
***************
*** 144,149 ****
--- 159,174 ----
throws JiBXException {
if (m_marshalAttributeName != null) {
+ if (m_factoryName != null) {
+ mb.loadContext();
+ mb.appendCallInterface(PUSH_NAMESPACES_METHOD,
+ PUSH_NAMESPACES_SIG);
+ }
mb.loadContext(MARSHALLING_CONTEXT);
mb.appendCallStatic(m_marshalAttributeName, m_marshalSignature);
+ if (m_factoryName != null) {
+ mb.loadContext();
+ mb.appendCallInterface(POP_NAMESPACES_METHOD,
+ POP_NAMESPACES_SIG);
+ }
}
}
***************
*** 160,165 ****
--- 185,201 ----
throws JiBXException {
if (m_marshalContentName != null) {
+ if (m_factoryName != null) {
+ mb.loadContext();
+ mb.appendLoadConstant(m_factoryName);
+ mb.appendCallInterface(PUSH_NAMESPACES_METHOD,
+ PUSH_NAMESPACES_SIG);
+ }
mb.loadContext(MARSHALLING_CONTEXT);
mb.appendCallStatic(m_marshalContentName, m_marshalSignature);
+ if (m_factoryName != null) {
+ mb.loadContext();
+ mb.appendCallInterface(POP_NAMESPACES_METHOD,
+ POP_NAMESPACES_SIG);
+ }
}
}
Index: NamespaceDefinition.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/binding/def/NamespaceDefinition.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** NamespaceDefinition.java 3 Jul 2004 19:42:39 -0000 1.1.1.1
--- NamespaceDefinition.java 22 Jul 2008 01:13:23 -0000 1.2
***************
*** 1,4 ****
/*
! Copyright (c) 2003-2004, Dennis M. Sosnoski
All rights reserved.
--- 1,4 ----
/*
! Copyright (c) 2003-2008, Dennis M. Sosnoski.
All rights reserved.
***************
*** 29,41 ****
package org.jibx.binding.def;
- import org.jibx.runtime.JiBXException;
-
/**
* Namespace definition from binding.
*
* @author Dennis M. Sosnoski
- * @version 1.0
*/
-
public class NamespaceDefinition
{
--- 29,37 ----
***************
*** 73,81 ****
* namespace, but not "")
* @param usage code for default usage of namespace
- * @throws JiBXException if configuration error
*/
!
! public NamespaceDefinition(String uri, String prefix, int usage)
! throws JiBXException {
m_uri = uri;
m_prefix = prefix;
--- 69,74 ----
* namespace, but not "")
* @param usage code for default usage of namespace
*/
! public NamespaceDefinition(String uri, String prefix, int usage) {
m_uri = uri;
m_prefix = prefix;
***************
*** 84,94 ****
m_attributeDefault =
(usage == ALLDEFAULT_USAGE) || (usage == ATTRIBUTES_USAGE);
- if (usage != ELEMENTS_USAGE && prefix == null) {
- throw new JiBXException
- ("Prefix required for namespace unless element default");
- }
- if (m_attributeDefault && m_prefix == null) {
- throw new JiBXException("Prefix required for attribute namespace");
- }
}
--- 77,80 ----
***************
*** 99,103 ****
* <code>false</code> if not
*/
-
public boolean isAttributeDefault() {
return m_attributeDefault;
--- 85,88 ----
***************
*** 110,117 ****
* <code>false</code> if not
*/
-
public boolean isElementDefault() {
return m_elementDefault;
}
/**
--- 95,110 ----
* <code>false</code> if not
*/
public boolean isElementDefault() {
return m_elementDefault;
}
+
+ /**
+ * Set prefix for namespace.
+ *
+ * @param prefix namespace prefix (may be <code>null</code>, but not "")
+ */
+ public void setPrefix(String prefix) {
+ m_prefix = prefix;
+ }
/**
***************
*** 120,124 ****
* @return namespace prefix (may be <code>null</code>, but not "")
*/
-
public String getPrefix() {
return m_prefix;
--- 113,116 ----
***************
*** 130,134 ****
* @return namespace URI
*/
-
public String getUri() {
return m_uri;
--- 122,125 ----
***************
*** 140,144 ****
* @param index namespace index
*/
-
public void setIndex(int index) {
m_index = index;
--- 131,134 ----
***************
*** 150,154 ****
* @return namespace index
*/
-
public int getIndex() {
return m_index;
--- 140,143 ----
***************
*** 160,168 ****
* @param uri namespace URI
* @param prefix namespace prefix
- * @throws JiBXException if configuration error
*/
-
public static NamespaceDefinition buildNamespace(String uri,
! String prefix) throws JiBXException {
return new NamespaceDefinition(uri, prefix, NODEFAULT_USAGE);
}
--- 149,155 ----
* @param uri namespace URI
* @param prefix namespace prefix
*/
public static NamespaceDefinition buildNamespace(String uri,
! String prefix) {
return new NamespaceDefinition(uri, prefix, NODEFAULT_USAGE);
}
***************
*** 177,179 ****
System.out.println();
}
! }
--- 164,166 ----
System.out.println();
}
! }
\ No newline at end of file
Index: PrecompiledAbstractMapping.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/binding/def/PrecompiledAbstractMapping.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PrecompiledAbstractMapping.java 2 Jul 2008 11:51:49 -0000 1.2
--- PrecompiledAbstractMapping.java 22 Jul 2008 01:13:23 -0000 1.3
***************
*** 31,35 ****
import java.util.ArrayList;
! import org.jibx.binding.classes.*;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.JiBXException;
--- 31,36 ----
import java.util.ArrayList;
! import org.jibx.binding.classes.BoundClass;
! import org.jibx.binding.classes.ClassFile;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.JiBXException;
***************
*** 44,47 ****
--- 45,51 ----
public class PrecompiledAbstractMapping implements IMapping
{
+ /** Namespace index translation required flag. */
+ private final boolean m_translated;
+
/** Class linked to mapping. */
private final BoundClass m_class;
***************
*** 59,62 ****
--- 63,69 ----
private final ArrayList m_namespaces;
+ /** Containing context for definition. */
+ private final IContainer m_parent;
+
/**
* Constructor.
***************
*** 67,80 ****
* @param index abstract mapping index in binding
* @param factory binding factory for mapping information
* @param parent containing context
* @throws JiBXException if class definition not found
*/
! public PrecompiledAbstractMapping(String type, String tname,
! int index, IBindingFactory factory, IContainer parent) throws JiBXException {
m_class = BoundClass.getInstance(type, null);
m_typeName = tname;
! m_binding = new PrecompiledBinding(index, factory.getAbstractMappings());
m_referenceType = type == null ? "java.lang.Object" : type;
m_namespaces = new ArrayList();
}
--- 74,106 ----
* @param index abstract mapping index in binding
* @param factory binding factory for mapping information
+ * @param nsxlate namespace index translation table (<code>null</code> if
+ * none)
* @param parent containing context
* @throws JiBXException if class definition not found
*/
! public PrecompiledAbstractMapping(String type, String tname, int index,
! IBindingFactory factory, int[] nsxlate, IContainer parent)
! throws JiBXException {
! m_translated = nsxlate != null;
m_class = BoundClass.getInstance(type, null);
m_typeName = tname;
! m_binding = new PrecompiledBinding(index, factory.getAbstractMappings(),
! m_translated, factory.getClass().getName());
m_referenceType = type == null ? "java.lang.Object" : type;
m_namespaces = new ArrayList();
+ m_parent = parent;
+ String[] uris = factory.getNamespaces();
+ int[] nss = factory.getAbstractMappingNamespaces(index);
+ for (int i = 0; i < nss.length; i++) {
+ int nsi = nss[i];
+ String uri = uris[nsi];
+ NamespaceDefinition def = new NamespaceDefinition(uri, null,
+ NamespaceDefinition.NODEFAULT_USAGE);
+ if (nsxlate != null) {
+ nsi = nsxlate[nsi];
+ }
+ def.setIndex(nsi);
+ m_namespaces.add(def);
+ }
}
***************
*** 192,195 ****
--- 218,226 ----
public void setLinkages() throws JiBXException {
+ BindingDefinition binding = m_parent.getBindingRoot();
+ for (int i = 0; i < m_namespaces.size(); i++) {
+ NamespaceDefinition def = (NamespaceDefinition)m_namespaces.get(i);
+ def.setPrefix(binding.getPrefix(def.getUri()));
+ }
}
-------------------------------------------------------------------------
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