Search in sources :

Example 16 with JAXBElement

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);
    }
}
Also used : StringWriter(java.io.StringWriter) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement)

Example 17 with JAXBElement

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());
}
Also used : FilterDefinition(org.hibernate.engine.spi.FilterDefinition) JaxbHbmFilterParameterType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterParameterType) JaxbHbmFilterDefinitionType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterDefinitionType) Type(org.hibernate.type.Type) Serializable(java.io.Serializable) JaxbHbmFilterParameterType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmFilterParameterType) JAXBElement(javax.xml.bind.JAXBElement) MappingException(org.hibernate.boot.MappingException)

Example 18 with JAXBElement

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;
}
Also used : JaxbHbmQueryParamType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmQueryParamType) JaxbHbmNativeQueryCollectionLoadReturnType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryCollectionLoadReturnType) JAXBElement(javax.xml.bind.JAXBElement) JaxbHbmSynchronizeType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType) JaxbHbmNativeQueryReturnType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryReturnType)

Example 19 with JAXBElement

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;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) JAXBElement(javax.xml.bind.JAXBElement)

Example 20 with 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;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)210 QName (javax.xml.namespace.QName)71 ArrayList (java.util.ArrayList)43 Test (org.junit.Test)42 JAXBException (javax.xml.bind.JAXBException)28 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)28 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)24 JAXBContext (javax.xml.bind.JAXBContext)19 Unmarshaller (javax.xml.bind.Unmarshaller)18 Marshaller (javax.xml.bind.Marshaller)16 LineString (com.vividsolutions.jts.geom.LineString)15 StringWriter (java.io.StringWriter)14 List (java.util.List)14 Element (org.w3c.dom.Element)13 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)12 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9