Search in sources :

Example 11 with ObjectFactory

use of org.geotoolkit.swe.xml.v101.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 12 with ObjectFactory

use of org.geotoolkit.swe.xml.v101.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 13 with ObjectFactory

use of org.geotoolkit.swe.xml.v101.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 14 with ObjectFactory

use of org.geotoolkit.swe.xml.v101.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)

Example 15 with ObjectFactory

use of org.geotoolkit.swe.xml.v101.ObjectFactory in project struts by apache.

the class Dispatcher method cleanup.

/**
 * Releases all instances bound to this dispatcher instance.
 */
public void cleanup() {
    // clean up ObjectFactory
    ObjectFactory objectFactory = getContainer().getInstance(ObjectFactory.class);
    if (objectFactory == null) {
        LOG.warn("Object Factory is null, something is seriously wrong, no clean up will be performed");
    }
    if (objectFactory instanceof ObjectFactoryDestroyable) {
        try {
            ((ObjectFactoryDestroyable) objectFactory).destroy();
        } catch (Exception e) {
            // catch any exception that may occurred during destroy() and log it
            LOG.error("Exception occurred while destroying ObjectFactory [{}]", objectFactory.toString(), e);
        }
    }
    // clean up Dispatcher itself for this thread
    instance.set(null);
    servletContext.setAttribute(StrutsStatics.SERVLET_DISPATCHER, null);
    // clean up DispatcherListeners
    if (!dispatcherListeners.isEmpty()) {
        for (DispatcherListener l : dispatcherListeners) {
            l.dispatcherDestroyed(this);
        }
    }
    // clean up all interceptors by calling their destroy() method
    Set<Interceptor> interceptors = new HashSet<>();
    Collection<PackageConfig> packageConfigs = configurationManager.getConfiguration().getPackageConfigs().values();
    for (PackageConfig packageConfig : packageConfigs) {
        for (Object config : packageConfig.getAllInterceptorConfigs().values()) {
            if (config instanceof InterceptorStackConfig) {
                for (InterceptorMapping interceptorMapping : ((InterceptorStackConfig) config).getInterceptors()) {
                    interceptors.add(interceptorMapping.getInterceptor());
                }
            }
        }
    }
    for (Interceptor interceptor : interceptors) {
        interceptor.destroy();
    }
    // Clear container holder when application is unloaded / server shutdown
    ContainerHolder.clear();
    // cleanup action context
    ActionContext.clear();
    // clean up configuration
    configurationManager.destroyConfiguration();
    configurationManager = null;
}
Also used : InterceptorStackConfig(com.opensymphony.xwork2.config.entities.InterceptorStackConfig) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) ObjectFactoryDestroyable(org.apache.struts2.util.ObjectFactoryDestroyable) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) Interceptor(com.opensymphony.xwork2.interceptor.Interceptor) ServletException(javax.servlet.ServletException) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) StrutsException(org.apache.struts2.StrutsException) IOException(java.io.IOException) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) HashSet(java.util.HashSet)

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