當前位置: 首頁>>代碼示例>>Java>>正文


Java XmlSchema類代碼示例

本文整理匯總了Java中javax.xml.bind.annotation.XmlSchema的典型用法代碼示例。如果您正苦於以下問題:Java XmlSchema類的具體用法?Java XmlSchema怎麽用?Java XmlSchema使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XmlSchema類屬於javax.xml.bind.annotation包,在下文中一共展示了XmlSchema類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getXMLFilterForClass

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
public static <T> XMLFilter getXMLFilterForClass(final Class<T> clazz) throws SAXException {
	final XMLFilter filter;
	final XmlSchema schema = clazz.getPackage().getAnnotation(XmlSchema.class);
	if (schema != null) {
		final String namespace = schema.namespace();
		if (namespace != null && !"".equals(namespace)) {
			LogUtils.tracef(clazz, "found namespace %s for class %s", namespace, clazz);
			filter = new SimpleNamespaceFilter(namespace, true);
		} else {
			filter = new SimpleNamespaceFilter("", false);
		}
	} else {
		filter = new SimpleNamespaceFilter("", false);
	}

	final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
	filter.setParent(xmlReader);
	return filter;
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:20,代碼來源:JaxbUtils.java

示例2: getXmlNs

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
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();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:TypeInfoSetImpl.java

示例3: parseElementName

import javax.xml.bind.annotation.XmlSchema; //導入依賴的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

示例4: parseElementName

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
final QName parseElementName(XmlElementDecl e) {
    String local = e.name();
    String nsUri = e.namespace();
    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,
            nav().getDeclaringClassForMethod(method),this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:ElementInfoImpl.java

示例5: getNamespaceUriForType

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
/**
 * Returns the schema namespace URI for the specified JAXB type. The URI
 * can then be used to create a {@link QName} instance that is necessary
 * to instantiate a {@link JAXBElement}.
 *
 * @param type a JAXB generated type.
 * @return the namespace URI.
 */
@SuppressWarnings("unchecked")
public static String getNamespaceUriForType( Class<?> type )
{
  String pkgInfoFqcn = type.getPackage().getName() + ".package-info";
  try
  {
    /*
     * package-info.class is a special class generated by JAXB - it contains the schema namespace
     * URI for all generated classes.
     */
    Class<?> pkgInfo = Class.forName( pkgInfoFqcn );
    XmlSchema schema = pkgInfo.getAnnotation( XmlSchema.class );
    return schema.namespace();
  }
  catch ( ClassNotFoundException e )
  {
    return null;
  }
}
 
開發者ID:quartzdesk,項目名稱:quartzdesk-executor,代碼行數:28,代碼來源:JaxbHelper.java

示例6: determineNamespaceUncached

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
private String determineNamespaceUncached(Class<? extends Object> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }

    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }

    return namespace;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:18,代碼來源:PrismBeanInspector.java

示例7: determineTypeForClassUncached

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
private QName determineTypeForClassUncached(Class<? extends Object> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }

    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }

    return new QName(namespace, xmlType.name());
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:18,代碼來源:PrismBeanInspector.java

示例8: getXmlSchemaNamespace

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
/**
 * Gets the xml schema namespace.
 * 
 * @param clazz the clazz
 * 
 * @return the xml schema namespace
 */
public static String getXmlSchemaNamespace(Class<?> clazz) {

    AnnotatedElement pack = clazz.getPackage();
    if (pack == null) {
        return "";
    }

    XmlSchema schema = pack.getAnnotation(XmlSchema.class);
    String namespace = null;
    if (schema != null) {
        namespace = schema.namespace();
    } else {
        namespace = "";
    }
    return namespace;

}
 
開發者ID:clstoulouse,項目名稱:motu,代碼行數:25,代碼來源:ReflectionUtils.java

示例9: findQNameForSoapActionOrType

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
/**
 * @return determine element name by using the XmlType.name() of the type to
 *         be marshalled and the XmlSchema.namespace() of the package-info
 */
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");
    }
    String nameSpace = xmlType.namespace();
    if ("##default".equals(nameSpace)) {
        XmlSchema xmlSchema = type.getPackage().getAnnotation(XmlSchema.class);
        if (xmlSchema != null) {
            nameSpace = xmlSchema.namespace();
        }
    }
    // prefer name from the XmlType, and fallback to XmlRootElement
    String localName = xmlType.name();
    if (ObjectHelper.isEmpty(localName)) {
        XmlRootElement root = type.getAnnotation(XmlRootElement.class);
        if (root != null) {
            localName = root.name();
        }
    }
    return new QName(nameSpace, localName);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:27,代碼來源:TypeNameStrategy.java

示例10: write

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
public void write(OutputStream stream, T object) {
    try {
        JAXBContext context = JAXBContext.newInstance(object.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        XmlSchema schemaAnnotation = object.getClass().getPackage().getAnnotation(XmlSchema.class);
        if (schemaAnnotation != null && schemaAnnotation.location() != null) {
            marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaAnnotation.location());
            // TODO: May just this ArtifactoryConfigVersion.getCurrent().getXsdLocation());
        }
        marshaller.marshal(object, stream);
    } catch (Exception e) {
        throw new RuntimeException("Failed to write object to stream.", e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:18,代碼來源:JaxbHelper.java

示例11: getPrefix

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
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;
}
 
開發者ID:highsource,項目名稱:jaxb2-basics,代碼行數:18,代碼來源:XmlTypeUtils.java

示例12: getNamespace

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
private static String getNamespace(final Package targetPackage) {
	String namespaceURI;
	if (targetPackage == null) {
		namespaceURI = "";
	} else {
		final XmlSchema xmlSchemaAnnotation = targetPackage
				.getAnnotation(XmlSchema.class);
		if (xmlSchemaAnnotation == null) {
			namespaceURI = "";
		} else {
			final String packageNamespace = xmlSchemaAnnotation.namespace();
			if (packageNamespace == null || "".equals(packageNamespace)) {
				namespaceURI = "";
			} else {
				namespaceURI = packageNamespace;
			}
		}
	}
	return namespaceURI;
}
 
開發者ID:highsource,項目名稱:jaxb2-basics,代碼行數:21,代碼來源:XmlTypeUtils.java

示例13: determineNamespaceUncached

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
private String determineNamespaceUncached(Class<?> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }

    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }

    return namespace;
}
 
開發者ID:Evolveum,項目名稱:midpoint,代碼行數:18,代碼來源:PrismBeanInspector.java

示例14: determineTypeForClassUncached

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
private QName determineTypeForClassUncached(Class<?> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }

    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }

    return new QName(namespace, xmlType.name());
}
 
開發者ID:Evolveum,項目名稱:midpoint,代碼行數:18,代碼來源:PrismBeanInspector.java

示例15: getTypeIdName

import javax.xml.bind.annotation.XmlSchema; //導入依賴的package包/類
/**
 * Get the id for the specified type.
 *
 * @param type The type.
 * @return The type id.
 */
public static String getTypeIdName(Class<?> type) {
  String ns = "";
  if (type.getPackage() != null && type.getPackage().isAnnotationPresent(XmlSchema.class)) {
    ns = type.getPackage().getAnnotation(XmlSchema.class).namespace();
  }

  String name = Introspector.decapitalize(type.getSimpleName());
  if (type.isAnnotationPresent(XmlType.class)) {
    XmlType typeMeta = type.getAnnotation(XmlType.class);
    if (!"##default".equals(typeMeta.name())) {
      name = typeMeta.name();
    }

    if (!"##default".equals(typeMeta.namespace())) {
      ns = typeMeta.namespace();
    }
  }

  return ns + name;
}
 
開發者ID:FamilySearch,項目名稱:gedcomx-java,代碼行數:27,代碼來源:GedcomNamespaceManager.java


注:本文中的javax.xml.bind.annotation.XmlSchema類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。