use of org.geotoolkit.ops.xml.v110.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);
}
use of org.geotoolkit.ops.xml.v110.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);
}
use of org.geotoolkit.ops.xml.v110.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();
}
use of org.geotoolkit.ops.xml.v110.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());
}
}
use of org.geotoolkit.ops.xml.v110.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;
}
Aggregations