}
}
}
// define the namespace prefixes to be used (unless otherwise specified at individual binding level)
UniqueNameSet prefset = new UniqueNameSet();
Map uridfltpref = new HashMap();
Map urifrcdpref = buildDefaultPrefixes(prefset, uridfltpref);
// check if only single binding defined
BindingHolder roothold = null;
BindingElement rootbind;
List includes = new ArrayList(pregens);
if (objs.size() == 1) {
// single binding, just write it using supplied name and added namespaces
roothold = (BindingHolder)m_objectBindings.get(objs.get(0));
rootbind = roothold.getBinding();
} else {
// first look for existing binding with supplied name
for (Iterator iter = objs.iterator(); iter.hasNext();) {
BindingHolder hold = (BindingHolder)m_objectBindings.get(iter.next());
if (rootname.equals(hold.getFileName())) {
roothold = hold;
break;
}
}
if (roothold == null) {
// get or create no namespace binding
roothold = getBinding(null);
if (roothold == null) {
roothold = addBinding(null, null, "", true);
}
}
rootbind = roothold.getBinding();
// add root binding namespace to set declared at root
if (roothold.isBindingNamespaceUsed()) {
String uri = roothold.getNamespace();
if (uri != null && !MarshallingContext.XML_NAMESPACE.equals(uri)) {
m_nsRootUris.add(uri);
}
}
// set file names and add to list for root binding
UniqueNameSet nameset = new UniqueNameSet();
nameset.add(rootname);
for (Iterator iter = objs.iterator(); iter.hasNext();) {
BindingHolder holder = (BindingHolder)m_objectBindings.get(iter.next());
if (holder != roothold) {
if (holder.getFileName() == null) {
// get last part of namespace URI as file name candidate
String bindname;
String raw = holder.getNamespace();
if (raw == null) {
bindname = "nonamespaceBinding";
} else {
// strip off protocol and any trailing slash
raw = raw.replace('\\', '/');
int split = raw.indexOf("://");
if (split >= 0) {
raw = raw.substring(split + 3);
}
while (raw.endsWith("/")) {
raw = raw.substring(0, raw.length()-1);
}
// strip off host portion if present and followed by path
split = raw.indexOf('/');
if (split > 0 && raw.substring(0, split).indexOf('.') > 0) {
raw = raw.substring(split+1);
}
// eliminate any invalid characters in name
StringBuffer buff = new StringBuffer();
int index = 0;
char chr = raw.charAt(0);
if (isAsciiAlpha(chr)) {
buff.append(chr);
index = 1;
} else {
buff.append('_');
}
boolean toupper = false;
while (index < raw.length()) {
chr = raw.charAt(index++);
if (isAsciiAlphaNum(chr)) {
if (toupper) {
chr = Character.toUpperCase(chr);
toupper = false;
}
buff.append(chr);
} else if (chr == '.') {
toupper = true;
} else if (chr == ':' || chr == '/') {
buff.append('_');
}
}
buff.append("Binding");
bindname = buff.toString();
}
// ensure uniqueness of the name
holder.setFileName(nameset.add(bindname) + ".xml");
}
// finish construction of this binding
holder.finish(Collections.EMPTY_LIST, Collections.EMPTY_LIST, m_nsRootUris, uridfltpref,
urifrcdpref);