Search in sources :

Example 26 with ObjectFactory

use of ietf.params.xml.ns.icalendar_2.ObjectFactory in project geotoolkit by Geomatys.

the class SmlXMLBindingTest method ComponentMarshalingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws java.lang.Exception
 */
@Test
public void ComponentMarshalingTest() throws Exception {
    ComponentType compo = new ComponentType();
    compo.setValidTime(new TimePeriodType(new TimePositionType("2004-06-01")));
    Marshaller marshaller = SensorMLMarshallerPool.getInstance().acquireMarshaller();
    StringWriter sw = new StringWriter();
    final ObjectFactory factory = new ObjectFactory();
    marshaller.marshal(factory.createComponent(compo), sw);
    String result = sw.toString();
    System.out.println("result:" + result);
}
Also used : ComponentType(org.geotoolkit.sml.xml.v100.ComponentType) Marshaller(javax.xml.bind.Marshaller) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) StringWriter(java.io.StringWriter) ObjectFactory(org.geotoolkit.sml.xml.v100.ObjectFactory) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Example 27 with ObjectFactory

use of ietf.params.xml.ns.icalendar_2.ObjectFactory in project geotoolkit by Geomatys.

the class SmlXMLBindingTest method DataSourceMarshalingTest.

@Test
public void DataSourceMarshalingTest() throws Exception {
    final SystemType system = new SystemType();
    final List<DataComponentPropertyType> fields = new ArrayList<>();
    fields.add(DataComponentPropertyType.LATITUDE_FIELD);
    fields.add(DataComponentPropertyType.LONGITUDE_FIELD);
    fields.add(DataComponentPropertyType.TIME_FIELD);
    final DataRecordType posRecord = new DataRecordType(null, fields);
    final DataBlockDefinitionType definition = new DataBlockDefinitionType(null, Arrays.asList(posRecord), TextBlockType.DEFAULT_ENCODING);
    final DataDefinition dataDefinition = new DataDefinition(definition);
    final org.geotoolkit.sml.xml.v101.Values trajValues = new org.geotoolkit.sml.xml.v101.Values();
    trajValues.setAny("test");
    final DataSourceType datasource = new DataSourceType(dataDefinition, trajValues, null);
    final Position pos = new Position(null, datasource);
    system.setPosition(pos);
    DataSourceType expds = (DataSourceType) pos.getAbstractProcess();
    DataSourceType resds = (DataSourceType) system.getPosition().getAbstractProcess();
    assertEquals(expds.getDataDefinition(), resds.getDataDefinition());
    assertEquals(expds, resds);
    assertEquals(pos.getAbstractProcess(), system.getPosition().getAbstractProcess());
    assertEquals(pos.getPosition(), system.getPosition().getPosition());
    assertEquals(pos, system.getPosition());
    final SensorML sml = new SensorML("1.0.1", Arrays.asList(new SensorML.Member(system)));
    Marshaller m = SensorMLMarshallerPool.getInstance().acquireMarshaller();
    ObjectFactory factory = new ObjectFactory();
    // m.marshal(factory.createPosition(pos), System.out);
    // m.marshal(factory.createSystem(system), System.out);
    // m.marshal(sml, System.out);
    SensorMLMarshallerPool.getInstance().recycle(m);
}
Also used : DataRecordType(org.geotoolkit.swe.xml.v101.DataRecordType) Marshaller(javax.xml.bind.Marshaller) Position(org.geotoolkit.sml.xml.v101.Position) ArrayList(java.util.ArrayList) SystemType(org.geotoolkit.sml.xml.v101.SystemType) DataDefinition(org.geotoolkit.sml.xml.v101.DataDefinition) SensorML(org.geotoolkit.sml.xml.v101.SensorML) DataBlockDefinitionType(org.geotoolkit.swe.xml.v101.DataBlockDefinitionType) ObjectFactory(org.geotoolkit.sml.xml.v101.ObjectFactory) DataSourceType(org.geotoolkit.sml.xml.v101.DataSourceType) DataComponentPropertyType(org.geotoolkit.swe.xml.v101.DataComponentPropertyType)

Example 28 with ObjectFactory

use of ietf.params.xml.ns.icalendar_2.ObjectFactory in project ARLAS-server by gisaia.

the class XmlGetRecordsMessageBodyWriter method writeTo.

@Override
public void writeTo(GetRecordsResponseType getRecordsResponseType, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
    ObjectFactory cswFactory = new ObjectFactory();
    JAXB.marshal(cswFactory.createGetRecordsResponse(getRecordsResponseType), outputStream);
}
Also used : ObjectFactory(net.opengis.cat.csw._3.ObjectFactory)

Example 29 with ObjectFactory

use of ietf.params.xml.ns.icalendar_2.ObjectFactory in project struts by apache.

the class DomHelper method parse.

/**
 * Creates a W3C Document that remembers the location of each element in
 * the source file. The location of element nodes can then be retrieved
 * using the {@link #getLocationObject(Element)} method.
 *
 * @param inputSource the inputSource to read the document from
 * @param dtdMappings a map of DTD names and public ids
 *
 * @return the W3C Document
 */
public static Document parse(InputSource inputSource, Map<String, String> dtdMappings) {
    SAXParserFactory factory = null;
    String parserProp = System.getProperty("xwork.saxParserFactory");
    if (parserProp != null) {
        try {
            ObjectFactory objectFactory = ActionContext.getContext().getContainer().getInstance(ObjectFactory.class);
            Class clazz = objectFactory.getClassInstance(parserProp);
            factory = (SAXParserFactory) clazz.newInstance();
        } catch (Exception e) {
            LOG.error("Unable to load saxParserFactory set by system property 'xwork.saxParserFactory': {}", parserProp, e);
        }
    }
    if (factory == null) {
        factory = SAXParserFactory.newInstance();
    }
    factory.setValidating((dtdMappings != null));
    factory.setNamespaceAware(true);
    SAXParser parser;
    try {
        parser = factory.newSAXParser();
    } catch (Exception ex) {
        throw new StrutsException("Unable to create SAX parser", ex);
    }
    DOMBuilder builder = new DOMBuilder();
    // Enhance the sax stream with location information
    ContentHandler locationHandler = new LocationAttributes.Pipe(builder);
    try {
        parser.parse(inputSource, new StartHandler(locationHandler, dtdMappings));
    } catch (Exception ex) {
        throw new StrutsException(ex);
    }
    return builder.getDocument();
}
Also used : StrutsException(org.apache.struts2.StrutsException) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) SAXParser(javax.xml.parsers.SAXParser) StrutsException(org.apache.struts2.StrutsException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 30 with ObjectFactory

use of ietf.params.xml.ns.icalendar_2.ObjectFactory in project struts by apache.

the class AbstractBeanSelectionProvider method alias.

protected void alias(Class type, String key, ContainerBuilder builder, Properties props, Scope scope) {
    if (!builder.contains(type, Container.DEFAULT_NAME)) {
        String foundName = props.getProperty(key, DEFAULT_BEAN_NAME);
        if (builder.contains(type, foundName)) {
            LOG.trace("Choosing bean ({}) for ({})", foundName, type.getName());
            builder.alias(type, foundName, Container.DEFAULT_NAME);
        } else {
            try {
                Class cls = ClassLoaderUtil.loadClass(foundName, this.getClass());
                LOG.trace("Choosing bean ({}) for ({})", cls.getName(), type.getName());
                builder.factory(type, cls, scope);
            } catch (ClassNotFoundException ex) {
                // Perhaps a spring bean id, so we'll delegate to the object factory at runtime
                LOG.trace("Choosing bean ({}) for ({}) to be loaded from the ObjectFactory", foundName, type.getName());
                if (DEFAULT_BEAN_NAME.equals(foundName)) {
                // Probably an optional bean, will ignore
                } else {
                    if (ObjectFactory.class != type) {
                        builder.factory(type, new ObjectFactoryDelegateFactory(foundName, type), scope);
                    } else {
                        throw new ConfigurationException("Cannot locate the chosen ObjectFactory implementation: " + foundName);
                    }
                }
            }
        }
    } else {
        LOG.warn("Unable to alias bean type ({}), default mapping already assigned.", type.getName());
    }
}
Also used : ObjectFactory(com.opensymphony.xwork2.ObjectFactory) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)35 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)26 Marshaller (javax.xml.bind.Marshaller)24 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 StringWriter (java.io.StringWriter)19 JAXBContext (javax.xml.bind.JAXBContext)19 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 ObjectFactory (no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory)16 QName (javax.xml.namespace.QName)15 BigInteger (java.math.BigInteger)13 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ObjectFactory (slash.navigation.kml.binding22.ObjectFactory)12 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11