Java Code Examples for javax.xml.bind.annotation.XmlRootElement#name()
The following examples show how to use
javax.xml.bind.annotation.XmlRootElement#name() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeInfoImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 2
Source File: TypeInfoImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 3
Source File: TypeInfoImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 4
Source File: TransactionBindTest.java From staedi with Apache License 2.0 | 6 votes |
QName getRootElementName(Class<?> type) { XmlRootElement rootElement = type.getAnnotation(XmlRootElement.class); String ns; String localName; if (rootElement != null) { if ("##default".equals(rootElement.name())) { localName = decapitalize(type.getSimpleName()); } else { localName = rootElement.name(); } if ("##default".equals(rootElement.namespace())) { ns = ""; } else { ns = rootElement.namespace(); } return new QName(ns, localName); } throw new IllegalStateException("Missing XmlRootElement annotation on root class"); }
Example 5
Source File: TypeInfoImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 6
Source File: TypeInfoImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 7
Source File: TypeInfoImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 8
Source File: TypeInfoImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 9
Source File: TypeInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Parses an {@link XmlRootElement} annotation on a class * and determine the element name. * * @return null * if none was found. */ protected final QName parseElementName(ClassDeclT clazz) { XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this); if(e==null) return null; String local = e.name(); if(local.equals("##default")) { // if defaulted... local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz)); } String nsUri = e.namespace(); if(nsUri.equals("##default")) { // if defaulted ... XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this); if(xs!=null) nsUri = xs.namespace(); else { nsUri = builder.defaultNsUri; } } return new QName(nsUri.intern(),local.intern()); }
Example 10
Source File: CamelModelHelper.java From fabric8-forge with Apache License 2.0 | 5 votes |
/** * Returns the pattern name */ public static String getPatternName(OptionalIdentifiedDefinition camelNode) { // we should grab the annotation instead XmlRootElement root = camelNode.getClass().getAnnotation(XmlRootElement.class); if (root != null) { return root.name(); } String simpleName = Strings.stripSuffix(camelNode.getClass().getSimpleName(), "Definition"); return Introspector.decapitalize(simpleName); }
Example 11
Source File: PluginContext.java From jaxb2-rich-contract-plugin with MIT License | 5 votes |
private static String getLocalName(final Class<?> boundClass) { final XmlRootElement elementAnnotation = boundClass.getAnnotation(XmlRootElement.class); if (elementAnnotation != null && !"##default".equals(elementAnnotation.name())) { return elementAnnotation.name(); } else { final XmlType xmlTypeAnnotation = boundClass.getAnnotation(XmlType.class); if (xmlTypeAnnotation != null && !"##default".equals(xmlTypeAnnotation.name())) { return xmlTypeAnnotation.name(); } else { return boundClass.getSimpleName(); } } }
Example 12
Source File: XPathUtil.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
static private String getElementName(Class<?> clazz){ while(clazz != null){ XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class); if(rootElement != null){ return rootElement.name(); } clazz = clazz.getSuperclass(); } throw new IllegalArgumentException(); }
Example 13
Source File: JAXBDocumentType.java From ph-commons with Apache License 2.0 | 4 votes |
/** * Constructor * * @param aClass * The JAXB generated class of the root element. May not be * <code>null</code>. This class must have the <code>@XmlType</code> * annotation and the package the class resides in must have the * <code>@XmlSchema</code> annotation with a non-null * <code>namespace</code> property! * @param aXSDs * The classpath relative paths to the XML Schema. May not be * <code>null</code> but maybe empty. If the main XSD imports another * XSD, the imported XSD must come first in the list. So the XSDs * without any dependencies must come first! * @param aTypeToElementNameMapper * An optional function to determine element name from type name. E.g. * in UBL the type has an additional "Type" at the end that may not * occur here. SBDH in contrary does not have such a suffix. May be * <code>null</code> indicating that no name mapping is necessary. */ public JAXBDocumentType (@Nonnull final Class <?> aClass, @Nullable final List <? extends ClassPathResource> aXSDs, @Nullable final Function <? super String, ? extends String> aTypeToElementNameMapper) { ValueEnforcer.notNull (aClass, "Class"); if (aXSDs != null) { ValueEnforcer.notEmptyNoNullValue (aXSDs, "XSDs"); for (final ClassPathResource aRes : aXSDs) ValueEnforcer.isTrue (aRes.hasClassLoader (), () -> "ClassPathResource " + aRes + " should define its ClassLoader for OSGI handling!"); } // Check whether it is an @XmlType class final XmlType aXmlType = aClass.getAnnotation (XmlType.class); if (aXmlType == null) throw new IllegalArgumentException ("The passed class '" + aClass.getName () + "' does not have an @XmlType annotation!"); // Get the package of the passed Class final Package aPackage = aClass.getPackage (); // The package must have the annotation "XmlSchema" with the corresponding // namespace it supports (maybe empty but not null). If the base XSD does // not contain any namespace URI, the XMLSchema annotation might be missing! final XmlSchema aXmlSchema = aPackage.getAnnotation (XmlSchema.class); if (aXmlSchema != null && aXmlSchema.namespace () == null) throw new IllegalArgumentException ("The package '" + aPackage.getName () + "' has no namespace URI in the @XmlSchema annotation!"); // Depending on the generation mode, the class may have the @XmlRootElement // annotation or not. If it is present, use the namespace URI and the local // name from it, else try to deduce the name from the type. String sNamespaceURI; String sLocalName; final XmlRootElement aRootElement = aClass.getAnnotation (XmlRootElement.class); if (aRootElement != null) { // Annotation is present sNamespaceURI = aRootElement.namespace (); if (JAXB_DEFAULT.equals (sNamespaceURI) && aXmlSchema != null) sNamespaceURI = aXmlSchema.namespace (); sLocalName = aRootElement.name (); if (JAXB_DEFAULT.equals (sLocalName)) sLocalName = aXmlType.name (); } else { // Hack: build the element name from the type name if (aXmlSchema != null) sNamespaceURI = aXmlSchema.namespace (); else sNamespaceURI = null; sLocalName = aXmlType.name (); } // Call customizer (if provided) if (aTypeToElementNameMapper != null) sLocalName = aTypeToElementNameMapper.apply (sLocalName); if (StringHelper.hasNoText (sLocalName)) throw new IllegalArgumentException ("Failed to determine the local name of the element to be created!"); m_aClass = aClass; if (aXSDs != null) m_aXSDs.addAll (aXSDs); m_sNamespaceURI = StringHelper.getNotNull (sNamespaceURI); m_sLocalName = sLocalName; }