public Map<String,String> getXmlNs(String namespaceUri) { if(xmlNsCache==null) { xmlNsCache = new HashMap<String,Map<String,String>>(); for (ClassInfoImpl<T, C, F, M> ci : beans().values()) { XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null ); if(xs==null) continue; String uri = xs.namespace(); Map<String,String> m = xmlNsCache.get(uri); if(m==null) xmlNsCache.put(uri,m=new HashMap<String, String>()); for( XmlNs xns : xs.xmlns() ) { m.put(xns.prefix(),xns.namespaceURI()); } } } Map<String,String> r = xmlNsCache.get(namespaceUri); if(r!=null) return r; else return Collections.emptyMap(); }
private static String getPrefix(final Package targetPackage, String namespaceURI) { String prefix; final Map<String, String> namespacePrefixes = new HashMap<String, String>(); if (targetPackage != null) { final XmlSchema xmlSchemaAnnotation = targetPackage .getAnnotation(XmlSchema.class); if (xmlSchemaAnnotation != null) { for (XmlNs xmlns : xmlSchemaAnnotation.xmlns()) { namespacePrefixes.put(xmlns.namespaceURI(), xmlns.prefix()); } } } prefix = namespacePrefixes.get(namespaceURI); return prefix; }
@Override public boolean run(final Outline outline, final Options options, final ErrorHandler errorHandler) { final JClass xmlNsClass = outline.getCodeModel().ref(XmlNs.class); final JClass xmlSchemaClass = outline.getCodeModel().ref(XmlSchema.class); for (PackageOutline packageOutline : outline.getAllPackageContexts()) { final JPackage p = packageOutline._package(); // get the target namespaces of all schemas that bind to the current package final Set<String> packageNamespaces = getPackageNamespace(packageOutline); // is there any prefix binding defined for the current package ? final Model packageModel = getPackageModel((PackageOutlineImpl) packageOutline); final List<Pair> list = getPrefixBinding(packageModel, packageNamespaces); acknowledgePrefixAnnotations(packageModel); if (list == null || list.isEmpty()) { // no prefix binding, nothing to do continue; } // add XML namespace prefix annotations final JAnnotationUse xmlSchemaAnnotation = getOrAddXmlSchemaAnnotation(p, xmlSchemaClass); if (xmlSchemaAnnotation == null) { throw new RuntimeException("Unable to get/add 'XmlSchema' annotation to package [" + p.name() + "]"); } final JAnnotationArrayMember members = xmlSchemaAnnotation.paramArray("xmlns"); for (Pair pair : list) { addNamespacePrefix(xmlNsClass, members, pair.getNamespace(), pair.getPrefix()); } } return true; }
public XmlNs[] xmlns() { return core.xmlns(); }
/** * Returns declared XmlNs annotations (from package-level annotation XmlSchema * * @return set of all present XmlNs annotations */ public Set<XmlNs> getXmlNsSet() { return xmlNsSet; }