use of javax.xml.bind.JAXBElement in project springside4 by springside.
the class XmlMapper method toXml.
/**
* Java Collection->Xml with encoding, 特别支持Root Element是Collection的情形.
*/
public static String toXml(Collection<?> root, String rootName, Class clazz, String encoding) {
try {
CollectionWrapper wrapper = new CollectionWrapper();
wrapper.collection = root;
JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName), CollectionWrapper.class, wrapper);
StringWriter writer = new StringWriter();
createMarshaller(clazz, encoding).marshal(wrapperElement, writer);
return writer.toString();
} catch (JAXBException e) {
throw ExceptionUtil.unchecked(e);
}
}
use of javax.xml.bind.JAXBElement in project hibernate-orm by hibernate.
the class FilterDefinitionBinder method processFilterDefinition.
/**
* Handling for a {@code <filter-def/>} declaration.
*
* @param context Access to information relative to the mapping document containing this binding
* @param jaxbFilterDefinitionMapping The {@code <filter-def/>} JAXB mapping
*/
@SuppressWarnings("unchecked")
public static void processFilterDefinition(HbmLocalMetadataBuildingContext context, JaxbHbmFilterDefinitionType jaxbFilterDefinitionMapping) {
Map<String, Type> parameterMap = null;
String condition = jaxbFilterDefinitionMapping.getCondition();
for (Serializable content : jaxbFilterDefinitionMapping.getContent()) {
if (String.class.isInstance(content)) {
final String contentString = content.toString().trim();
if (StringHelper.isNotEmpty(contentString)) {
if (condition != null) {
log.debugf("filter-def [name=%s, origin=%s] defined multiple conditions, accepting arbitrary one", jaxbFilterDefinitionMapping.getName(), context.getOrigin().toString());
}
}
} else {
final JaxbHbmFilterParameterType jaxbParameterMapping;
if (JaxbHbmFilterParameterType.class.isInstance(content)) {
jaxbParameterMapping = (JaxbHbmFilterParameterType) content;
} else if (JAXBElement.class.isInstance(content)) {
final JAXBElement<JaxbHbmFilterParameterType> jaxbElement = (JAXBElement<JaxbHbmFilterParameterType>) content;
jaxbParameterMapping = jaxbElement.getValue();
} else {
throw new MappingException("Unable to decipher filter-def content type [" + content.getClass().getName() + "]", context.getOrigin());
}
if (parameterMap == null) {
parameterMap = new HashMap<String, Type>();
}
parameterMap.put(jaxbParameterMapping.getParameterName(), context.getMetadataCollector().getTypeResolver().heuristicType(jaxbParameterMapping.getParameterValueTypeName()));
}
}
context.getMetadataCollector().addFilterDefinition(new FilterDefinition(jaxbFilterDefinitionMapping.getName(), condition, parameterMap));
log.debugf("Processed filter definition : %s", jaxbFilterDefinitionMapping.getName());
}
use of javax.xml.bind.JAXBElement in project hibernate-orm by hibernate.
the class NamedQueryBinder method processNamedQueryContentItem.
private static boolean processNamedQueryContentItem(Object content, NamedSQLQueryDefinitionBuilder builder, ImplicitResultSetMappingDefinition.Builder implicitResultSetMappingBuilder, JaxbHbmNamedNativeQueryType namedQueryBinding, HbmLocalMetadataBuildingContext context) {
if (String.class.isInstance(content)) {
// Especially when the query string is wrapped in CDATA we will get
// "extra" Strings here containing just spaces and/or newlines. This
// bit tries to account for them.
final String contentString = StringHelper.nullIfEmpty(((String) content).trim());
if (contentString != null) {
builder.setQuery((String) content);
return true;
} else {
return false;
}
} else if (JAXBElement.class.isInstance(content)) {
return processNamedQueryContentItem(((JAXBElement) content).getValue(), builder, implicitResultSetMappingBuilder, namedQueryBinding, context);
}
if (JaxbHbmQueryParamType.class.isInstance(content)) {
final JaxbHbmQueryParamType paramTypeBinding = (JaxbHbmQueryParamType) content;
builder.addParameterType(paramTypeBinding.getName(), paramTypeBinding.getType());
} else if (JaxbHbmSynchronizeType.class.isInstance(content)) {
final JaxbHbmSynchronizeType synchronizedSpace = (JaxbHbmSynchronizeType) content;
builder.addSynchronizedQuerySpace(synchronizedSpace.getTable());
} else if (JaxbHbmNativeQueryScalarReturnType.class.isInstance(content)) {
implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryScalarReturnType) content);
} else if (JaxbHbmNativeQueryReturnType.class.isInstance(content)) {
implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryReturnType) content);
} else if (JaxbHbmNativeQueryJoinReturnType.class.isInstance(content)) {
implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryJoinReturnType) content);
} else if (JaxbHbmNativeQueryCollectionLoadReturnType.class.isInstance(content)) {
implicitResultSetMappingBuilder.addReturn((JaxbHbmNativeQueryCollectionLoadReturnType) content);
} else {
throw new org.hibernate.boot.MappingException(String.format(Locale.ENGLISH, "Encountered unexpected content type [%s] for named native query [%s] : [%s]", content.getClass().getName(), namedQueryBinding.getName(), content.toString()), context.getOrigin());
}
return false;
}
use of javax.xml.bind.JAXBElement in project midpoint by Evolveum.
the class JaxbTestUtil method unmarshalElement.
public <T> JAXBElement<T> unmarshalElement(Reader reader, Class<T> type) throws JAXBException, SchemaException {
Object object = getUnmarshaller().unmarshal(reader);
JAXBElement<T> jaxbElement = (JAXBElement<T>) object;
adopt(jaxbElement);
return jaxbElement;
}
use of javax.xml.bind.JAXBElement in project midpoint by Evolveum.
the class JaxbTestUtil method unmarshalElement.
public <T> JAXBElement<T> unmarshalElement(Node node, Class<T> type) throws JAXBException, SchemaException {
Object object = createUnmarshaller().unmarshal(node);
JAXBElement<T> jaxbElement = (JAXBElement<T>) object;
adopt(jaxbElement);
return jaxbElement;
}
Aggregations