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


Java XmlType类代码示例

本文整理汇总了Java中javax.xml.bind.annotation.XmlType的典型用法代码示例。如果您正苦于以下问题:Java XmlType类的具体用法?Java XmlType怎么用?Java XmlType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: addsCorrectAnnotations

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
/**
 * PageBuilder can add correct annotations.
 * @throws Exception If there is some problem inside
 */
@Test
public void addsCorrectAnnotations() throws Exception {
    final String xsl = "/some/path/test.xsl";
    final Object page = new PageBuilder()
        .stylesheet(xsl)
        .build(PageBuilderTest.BarPage.class);
    MatcherAssert.assertThat(
        page.getClass().getAnnotation(XmlType.class).name(),
        Matchers.equalTo(
            "com.rexsl.page.PageBuilderTest$BarPage$somepathtestxsl"
        )
    );
    MatcherAssert.assertThat(
        page.getClass().getAnnotation(Stylesheet.class).value(),
        Matchers.equalTo(xsl)
    );
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:22,代码来源:PageBuilderTest.java

示例2: canRead

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p>Jaxb2CollectionHttpMessageConverter can read a generic
 * {@link Collection} where the generic type is a JAXB type annotated with
 * {@link XmlRootElement} or {@link XmlType}.
 */
@Override
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
	if (!(type instanceof ParameterizedType)) {
		return false;
	}
	ParameterizedType parameterizedType = (ParameterizedType) type;
	if (!(parameterizedType.getRawType() instanceof Class)) {
		return false;
	}
	Class<?> rawType = (Class<?>) parameterizedType.getRawType();
	if (!(Collection.class.isAssignableFrom(rawType))) {
		return false;
	}
	if (parameterizedType.getActualTypeArguments().length != 1) {
		return false;
	}
	Type typeArgument = parameterizedType.getActualTypeArguments()[0];
	if (!(typeArgument instanceof Class)) {
		return false;
	}
	Class<?> typeArgumentClass = (Class<?>) typeArgument;
	return (typeArgumentClass.isAnnotationPresent(XmlRootElement.class) ||
			typeArgumentClass.isAnnotationPresent(XmlType.class)) && canRead(mediaType);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:Jaxb2CollectionHttpMessageConverter.java

示例3: marshal

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static String marshal(Object obj) {
	StringWriter stringWriter = new StringWriter();
	try {
		JAXBContext jaxbContext = JAXBContext.newInstance(obj.getClass());
		Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
		jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
		jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
		XmlRootElement xmlRootAnnotation = obj.getClass().getAnnotation(XmlRootElement.class);
		System.out.println(xmlRootAnnotation);
		if (xmlRootAnnotation == null) {
			XmlType xmlTypeAnnotation = obj.getClass().getAnnotation(XmlType.class);
			QName qname = new QName("", xmlTypeAnnotation.name());
			JAXBElement<Object> jaxbElement = new JAXBElement<Object>(qname, (Class<Object>) obj.getClass(), null, obj);
			jaxbMarshaller.marshal(jaxbElement, stringWriter);
		} else {
			jaxbMarshaller.marshal(obj, stringWriter);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return stringWriter.toString();
}
 
开发者ID:SoapboxRaceWorld,项目名称:soapbox-race-core,代码行数:24,代码来源:MarshalXML.java

示例4: writeTo

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
		OutputStream entityStream) throws IOException, WebApplicationException {
	try {
		JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
		Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
		jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
		jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
		for (Annotation annotation : annotations) {
			if (annotation instanceof XsiSchemaLocation) {
				XsiSchemaLocation schemaAnnotation = (XsiSchemaLocation) annotation;
				String schemaLocation = schemaAnnotation.schemaLocation();
				jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation);
			}
		}
		XmlType xmlTypeAnnotation = object.getClass().getAnnotation(XmlType.class);
		QName qname = new QName("", xmlTypeAnnotation.name());
		StringWriter stringWriter = new StringWriter();
		JAXBElement<Object> jaxbElement = new JAXBElement<Object>(qname, (Class<Object>) object.getClass(), null, object);
		jaxbMarshaller.marshal(jaxbElement, stringWriter);
		entityStream.write(stringWriter.toString().getBytes());
	} catch (Exception e) {
		throw new WebApplicationException(e);
	}
}
 
开发者ID:SoapboxRaceWorld,项目名称:soapbox-race-core,代码行数:27,代码来源:MarshallerInterceptor.java

示例5: determineNamespaceUncached

import javax.xml.bind.annotation.XmlType; //导入依赖的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

示例6: determineTypeForClassUncached

import javax.xml.bind.annotation.XmlType; //导入依赖的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

示例7: getShortName

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
/**
 * Returns a short name for this node which can be useful for ID generation or referring to related resources like images
 *
 * @return defaults to "node" but derived nodes should overload this to provide a unique name
 */
@Override
public String getShortName() {
    if (shortName == null) {
        XmlRootElement root = getClass().getAnnotation(XmlRootElement.class);
        if (root != null) {
            shortName = root.name();
        }
        if (shortName == null) {
            XmlType type = getClass().getAnnotation(XmlType.class);
            if (type != null) {
                shortName = type.name();
            }
        }
    }
    return shortName;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:OptionalIdentifiedDefinition.java

示例8: findQNameForSoapActionOrType

import javax.xml.bind.annotation.XmlType; //导入依赖的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

示例9: getTagName

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
public static String getTagName(Class<?> handled) {
    if (TAG_NAMES.containsKey(handled)) {
        return TAG_NAMES.get(handled);
    }

    XmlType xmlType = handled.getAnnotation(XmlType.class);
    if (xmlType != null && xmlType.name() != null && xmlType.name().trim().length() > 0) {
        TAG_NAMES.put(handled, xmlType.name());
        return xmlType.name();
    } else {
        XmlRootElement xmlRoot = handled.getAnnotation(XmlRootElement.class);
        if (xmlRoot != null && xmlRoot.name() != null && xmlRoot.name().trim().length() > 0) {
            TAG_NAMES.put(handled, xmlRoot.name());
            return xmlRoot.name();
        }
    }
    throw new IllegalArgumentException("XML name not found for " + handled.getName());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:StAXUtil.java

示例10: convertToStub

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
public static Stub convertToStub(JavaLanguageVariable variable, Stub parentStub, StubTypeTreeRepository typeTreeRepository) {

		Stub stub = new Stub();
		stub.setParentStubRelation(parentStub);
		stub.setStubName(variable.getVariableName());
		stub.setRequired(variable.isRequired());
		stub.setHeader(variable.isHeader());
		stub.setMultiOccurs(variable.isMultiOccurs());
		stub.setType(variable.getType());

		if (variable.getType().isAnnotationPresent(XmlType.class) && !variable.getType().isEnum() && !stub.isSameTypeWithSomeAncestor()) {
			convertFieldsToChildStubs(stub, variable.getType(), typeTreeRepository);
		}

		return stub;

	}
 
开发者ID:chenjianjx,项目名称:wsdl2html,代码行数:18,代码来源:Variable2Stub.java

示例11: getFieldsIncludingAncestorTypes

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
private static List<Field> getFieldsIncludingAncestorTypes(Class<?> type) {
	List<Field> allFields = new ArrayList<Field>();
	while (true) {
		Field[] fieldsArray = type.getDeclaredFields();
		List<Field> fields = new ArrayList<Field>();
		if (fieldsArray != null) {
			for (Field f : fieldsArray) {
				fields.add(f);
			}
		}
		allFields.addAll(0, fields);

		type = type.getSuperclass();
		if (type == null) {
			break;
		}
		if (!type.isAnnotationPresent(XmlType.class)) {
			break;
		}

	}
	return allFields;
}
 
开发者ID:chenjianjx,项目名称:wsdl2html,代码行数:24,代码来源:Variable2Stub.java

示例12: validateCollection

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
private void validateCollection(Field f, Object obj) throws IllegalArgumentException, IllegalAccessException {
    XmlType xtype = obj.getClass().getAnnotation(XmlType.class);
    if (xtype == null) {
        return;
    }
    String elementName = xtype.name();
    logger.debug(String.format("validating %s->%s", elementName, f.getName()));

    Collection l = (Collection) f.get(obj);
    XmlElement eat = f.getAnnotation(XmlElement.class);
    if (eat != null && (eat.required() && (l == null || l.isEmpty()))) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", f.getName(), elementName));
    }
    XmlAttribute aat = f.getAnnotation(XmlAttribute.class);
    if (aat != null && (aat.required() && (l == null || l.isEmpty()))) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", aat.name(), elementName));
    }

    if (l != null) {
        Object val = l.iterator().next();
        if (val != null) {
            validateObject(val);
        }
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:26,代码来源:DeployerValidator.java

示例13: validateField

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
private void validateField(Field f, Object obj) throws IllegalArgumentException, IllegalAccessException {
    XmlType xtype = obj.getClass().getAnnotation(XmlType.class);
    if (xtype == null) {
        return;
    }

    Object val = f.get(obj);
    String elementName = xtype.name();
    logger.debug(String.format("validating %s->%s", elementName, f.getName()));

    XmlElement eat = f.getAnnotation(XmlElement.class);
    if (eat != null && eat.required() && val == null) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", f.getName(), elementName));
    }

    XmlAttribute aat = f.getAnnotation(XmlAttribute.class);
    if (aat != null && aat.required() && val == null) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", aat.name(), elementName));
    }

    if (val != null) {
        validateObject(val);
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:25,代码来源:DeployerValidator.java

示例14: getPropertyOrder

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
private static int getPropertyOrder(final Map<String, Integer> propMap, final Class<?> beanClass, final int offset) {
	int index = offset;
	if (beanClass.getSuperclass() != null) {
		index = getPropertyOrder(propMap, beanClass.getSuperclass(), offset);
	}
	final XmlType xmlTypeAnnotation = beanClass.getAnnotation(XmlType.class);
	if (xmlTypeAnnotation != null && xmlTypeAnnotation.propOrder() != null && !xmlTypeAnnotation.propOrder()[0].isEmpty()) {
		for (final String propName : xmlTypeAnnotation.propOrder()) {
			propMap.put(propName, index++);
		}
	} else {
		try {
			final BeanInfo beanInfo = Introspector.getBeanInfo(beanClass, beanClass.getSuperclass());
			for (final PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
				propMap.put(propertyDescriptor.getName(), index++);
			}
		} catch (final IntrospectionException e) {
			throw new JXPathException(e);
		}
	}
	return index;
}
 
开发者ID:mklemm,项目名称:jxpath-object-formatter,代码行数:23,代码来源:JaxbJXPathBeanInfo.java

示例15: writeOut

import javax.xml.bind.annotation.XmlType; //导入依赖的package包/类
public <T> void writeOut(T node, Class<T> declaredType) throws JAXBException {
    try {
        if (this.context == null) {
            init();
        }

        Marshaller marshaller = this.context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, SCHEMA_LOCATION);
        marshaller.marshal(new JAXBElement(
                new QName(declaredType.getDeclaredAnnotation(XmlType.class).name()), declaredType, node),
                new File(xmlPath));
    } catch (JAXBException ex) {
        getLogger(FlowProcessor.class.getName()).log(Level.SEVERE,
                "Fail to write configuration down to config file[{0}] due to error : \n{1}",
                new Object[]{this.xmlPath, ex});
        throw ex;
    }
}
 
开发者ID:toyboxman,项目名称:yummy-xml-UI,代码行数:20,代码来源:FlowProcessor.java


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