当前位置: 首页>>代码示例>>Java>>正文


Java XmlRootElement.namespace方法代码示例

本文整理汇总了Java中javax.xml.bind.annotation.XmlRootElement.namespace方法的典型用法代码示例。如果您正苦于以下问题:Java XmlRootElement.namespace方法的具体用法?Java XmlRootElement.namespace怎么用?Java XmlRootElement.namespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.bind.annotation.XmlRootElement的用法示例。


在下文中一共展示了XmlRootElement.namespace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseElementName

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:TypeInfoImpl.java

示例2: findQNameForSoapActionOrType

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
@Override
public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
    XmlType xmlType = type.getAnnotation(XmlType.class);
    if (xmlType == null || xmlType.name() == null) {
        throw new RuntimeException("The type " + type.getName() + " needs to have an XmlType annotation with name");
    }
    // prefer name+ns from the XmlRootElement, and fallback to XmlType
    String localName = null;
    String nameSpace = null;

    XmlRootElement root = type.getAnnotation(XmlRootElement.class);
    if (root != null) {
        localName = ObjectHelper.isEmpty(localName) ? root.name() : localName;
        nameSpace = isInValidNamespace(nameSpace) ? root.namespace() : nameSpace;
    }

    if (ObjectHelper.isEmpty(localName)) {
        localName = xmlType.name();
    }

    if (isInValidNamespace(nameSpace)) {
        XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class);
        if (xmlSchema != null) {
            nameSpace = xmlSchema.namespace();
        }
    }

    if (isInValidNamespace(nameSpace)) {
        nameSpace = xmlType.namespace();
    }

    if (ObjectHelper.isEmpty(localName) || isInValidNamespace(nameSpace)) {
        throw new IllegalStateException("Unable to determine localName or namespace for type <" + type.getName() + ">");
    }
    return new QName(nameSpace, localName);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:37,代码来源:XmlRootElementPreferringElementNameStrategy.java

示例3: getTargetNamespace

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
private String getTargetNamespace(final Class<?> clazz) {
	final XmlRootElement xmlRootElementAnnotation = clazz.getAnnotation(XmlRootElement.class);
	if (xmlRootElementAnnotation == null) {
		final XmlType xmlTypeAnnotation = clazz.getAnnotation(XmlType.class);
		return xmlTypeAnnotation == null ? null : xmlTypeAnnotation.namespace();
	} else {
		return xmlRootElementAnnotation.namespace();
	}
}
 
开发者ID:mklemm,项目名称:jxpath-object-formatter,代码行数:10,代码来源:JaxbJXPathBeanInfo.java

示例4: getXmlRootElementQName

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
/**
 * @param clazz
 * @return namespace of root element qname or null if this is not object does not represent a
 *         root element
 */
public static QName getXmlRootElementQName(Class clazz) {

    // See if the object represents a root element
    XmlRootElement root = (XmlRootElement)
        getAnnotation(clazz,XmlRootElement.class);
    if (root == null) {
        return null;
    }

    String name = root.name();
    String namespace = root.namespace();

    // The name may need to be defaulted
    if (name == null || name.length() == 0 || name.equals("##default")) {
        name = getSimpleName(clazz.getCanonicalName());
    }

    // The namespace may need to be defaulted
    if (namespace == null || namespace.length() == 0 || namespace.equals("##default")) {
        Package pkg = clazz.getPackage();
        XmlSchema schema = (XmlSchema)
            getAnnotation(pkg, XmlSchema.class);
        if (schema != null) {
            namespace = schema.namespace();
        } else {
            namespace = "";
        }
    }

    return new QName(namespace, name);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:37,代码来源:XMLRootElementUtil.java

示例5: getNamespaceUri

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
private static String getNamespaceUri(final Class<?> boundClass) {
	final XmlRootElement elementAnnotation = boundClass.getAnnotation(XmlRootElement.class);
	if (elementAnnotation != null && !"##default".equals(elementAnnotation.namespace())) {
		return elementAnnotation.namespace();
	} else {
		final XmlType xmlTypeAnnotation = boundClass.getAnnotation(XmlType.class);
		if (xmlTypeAnnotation != null && !"##default".equals(xmlTypeAnnotation.namespace())) {
			return xmlTypeAnnotation.namespace();
		} else {
			return getNamespaceUri(boundClass.getPackage());
		}
	}
}
 
开发者ID:mklemm,项目名称:jaxb2-rich-contract-plugin,代码行数:14,代码来源:PluginContext.java

示例6: getDefaultNamespace

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
private static String getDefaultNamespace(Class<?> rootClass) {
  DefaultNamespace defaultNs = rootClass.getAnnotation(DefaultNamespace.class);
  if (defaultNs == null && rootClass.getPackage() != null) {
    defaultNs = rootClass.getPackage().getAnnotation(DefaultNamespace.class);
  }

  String defaultNamespace = "";
  if (defaultNs != null) {
    defaultNamespace = defaultNs.value();
  }
  else {
    XmlRootElement rootElement = rootClass.getAnnotation(XmlRootElement.class);
    if (rootElement != null) {
      if ("##default".equals(rootElement.namespace())) {
        if (rootClass.getPackage() != null) {
          XmlSchema xmlSchema = rootClass.getPackage().getAnnotation(XmlSchema.class);
          if (xmlSchema != null) {
            defaultNamespace = xmlSchema.namespace();
          }
        }
      }
      else {
        defaultNamespace = rootElement.namespace();
      }
    }
  }

  return defaultNamespace;
}
 
开发者ID:FamilySearch,项目名称:gedcomx-java,代码行数:30,代码来源:GedcomNamespaceManager.java

示例7: getJsonName

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
/**
 * Get the JSON name for the specified type.
 *
 * @param type The type.
 * @return The json name.
 */
public static String getJsonName(Class<?> type) {
  if (type.isAnnotationPresent(JsonElementWrapper.class)) {
    //support custom json element name
    JsonElementWrapper ext = type.getAnnotation(JsonElementWrapper.class);
    return nameFromQName(ext.namespace(), ext.name());
  }
  else if (type.isAnnotationPresent(XmlRootElement.class)) {
    XmlRootElement rootElement = type.getAnnotation(XmlRootElement.class);
    if (rootElement != null) {
      String localPart = rootElement.name();
      if ("##default".equals(localPart)) {
        localPart = Introspector.decapitalize(type.getSimpleName());
      }
      String namespaceURI = rootElement.namespace();
      if ("##default".equals(namespaceURI)) {
        Package pkg = type.getPackage();
        if (pkg != null && pkg.isAnnotationPresent(XmlSchema.class)) {
          namespaceURI = pkg.getAnnotation(XmlSchema.class).namespace();
        }
        else {
          namespaceURI = "";
        }
      }

      return nameFromQName(namespaceURI, localPart);
    }
  }

  return null;
}
 
开发者ID:FamilySearch,项目名称:gedcomx-java,代码行数:37,代码来源:GedcomNamespaceManager.java

示例8: JAXBDocumentType

import javax.xml.bind.annotation.XmlRootElement; //导入方法依赖的package包/类
/**
 * 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 aXSDPaths
 *        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 <String> aXSDPaths,
                         @Nullable final Function <? super String, ? extends String> aTypeToElementNameMapper)
{
  ValueEnforcer.notNull (aClass, "Class");
  ValueEnforcer.noNullValue (aXSDPaths, "XSDPaths");

  // Check whether it is an @XmlType class
  final XmlType aXmlType = aClass.getAnnotation (XmlType.class);
  if (aXmlType == null)
    throw new IllegalArgumentException ("The passed class 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)
  {
    sNamespaceURI = aRootElement.namespace ();
    if ("##default".equals (sNamespaceURI) && aXmlSchema != null)
      sNamespaceURI = aXmlSchema.namespace ();

    sLocalName = aRootElement.name ();
    if ("##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 ();
  }
  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;
  m_aXSDPaths = new CommonsArrayList <> (aXSDPaths);
  m_sNamespaceURI = StringHelper.getNotNull (sNamespaceURI);
  m_sLocalName = sLocalName;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:81,代码来源:JAXBDocumentType.java


注:本文中的javax.xml.bind.annotation.XmlRootElement.namespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。