Example usage for org.springframework.beans.factory.xml XmlBeanDefinitionReader setValidating

List of usage examples for org.springframework.beans.factory.xml XmlBeanDefinitionReader setValidating

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml XmlBeanDefinitionReader setValidating.

Prototype

public void setValidating(boolean validating) 

Source Link

Document

Set whether to use XML validation.

Usage

From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java

public static GenericApplicationContext getSpringApplicationContext(InputStream applicationContxtInStream,
        String springBeansFilePath) throws AxisFault {
    GenericApplicationContext appContext = new GenericApplicationContext();

    XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
    xbdr.setValidating(false);
    xbdr.loadBeanDefinitions(new InputStreamResource(applicationContxtInStream));
    appContext.refresh();// www  . ja v a 2  s  . com
    return appContext;
}

From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java

public static GenericApplicationContext getSpringApplicationContextClassPath(ClassLoader classLoader,
        String relPath) throws AxisFault {
    GenericApplicationContext appContext = new GenericApplicationContext();
    appContext.setClassLoader(classLoader);
    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
    try {/*from   ww  w .  j  a  va2 s.  c om*/
        Thread.currentThread().setContextClassLoader(classLoader);
        XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
        xbdr.setValidating(false);
        InputStream in = classLoader.getResourceAsStream(relPath);
        if (in == null) {
            throw new AxisFault("Spring context cannot be located for AxisService");
        }
        xbdr.loadBeanDefinitions(new InputStreamResource(in));
        appContext.refresh();
    } catch (Exception e) {
        throw AxisFault.makeFault(e);
    } finally {
        // Restore
        Thread.currentThread().setContextClassLoader(prevCl);
    }
    return appContext;
}

From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java

public static GenericApplicationContext getSpringApplicationContext(String applicationContxtFilePath,
        ClassLoader springBeansClassLoader) throws AxisFault {
    GenericApplicationContext appContext = new GenericApplicationContext();

    appContext.setClassLoader(springBeansClassLoader);

    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();

    try {/*w  w w  . ja v  a  2s.  c o  m*/
        // Save the class loader so that you can restore it later
        Thread.currentThread().setContextClassLoader(
                new MultiParentClassLoader(new URL[] {}, new ClassLoader[] { springBeansClassLoader, prevCl }));
        XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
        xbdr.setValidating(false);
        xbdr.loadBeanDefinitions(
                new InputStreamResource(new FileInputStream(new File(applicationContxtFilePath))));
        appContext.refresh();
    } catch (FileNotFoundException e) {
        throw AxisFault.makeFault(e);
    } finally {
        // Restore
        Thread.currentThread().setContextClassLoader(prevCl);
    }

    return appContext;
}

From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java

/**
 * Method to get the spring application context for a spring service
 *
 * @param axisService - spring service//from   ww  w. j  a va  2  s.  c om
 * @param contextLocation - location of the application context file
 * @return - GenericApplicationContext for the given spring service
 * @throws AxisFault
 */

public static GenericApplicationContext getSpringApplicationContext(AxisService axisService,
        String contextLocation) throws AxisFault {

    Parameter appContextParameter = axisService.getParameter(SPRING_APPLICATION_CONTEXT);

    if (appContextParameter != null) {
        return (GenericApplicationContext) appContextParameter.getValue();

    } else {
        GenericApplicationContext appContext = new GenericApplicationContext();
        ClassLoader classLoader = axisService.getClassLoader();
        appContext.setClassLoader(classLoader);
        ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(classLoader);
            XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
            xbdr.setValidating(false);
            InputStream in = classLoader.getResourceAsStream(contextLocation);
            if (in == null) {
                throw new AxisFault("Spring context cannot be located for AxisService");
            }
            xbdr.loadBeanDefinitions(new InputStreamResource(in));
            appContext.refresh();
            axisService.addParameter(new Parameter(SPRING_APPLICATION_CONTEXT, appContext));
        } catch (Exception e) {
            throw AxisFault.makeFault(e);
        } finally {
            // Restore
            Thread.currentThread().setContextClassLoader(prevCl);
        }
        return appContext;
    }
}

From source file:net.solarnetwork.web.gemini.NonValidatingServerOsgiBundleXmlWebApplicationContext.java

@Override
protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
    super.initBeanDefinitionReader(beanDefinitionReader);
    beanDefinitionReader.setValidating(false);
}

From source file:technology.tikal.gae.optimization.CustomXmlWebApplicationContext.java

protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
    super.initBeanDefinitionReader(beanDefinitionReader);
    if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
        beanDefinitionReader.setValidating(false);
        beanDefinitionReader.setNamespaceAware(true);
    }/*from   w ww.ja v a  2 s.  co m*/
}

From source file:name.livitski.tools.springlet.Launcher.java

protected BeanFactory getBeanFactory() {
    if (null == beanFactory) {
        beanFactory = new DefaultListableBeanFactory();
        final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(beanFactory);
        xmlReader.setValidating(false);
        xmlReader.loadBeanDefinitions(MAIN_BEAN_CONFIG_FILE);
    }//  www. j a v a  2s .c o  m
    return beanFactory;
}

From source file:com.opengamma.component.factory.AbstractSpringComponentFactory.java

/**
 * Creates the application context./*from  www . ja v a  2 s .c  om*/
 * 
 * @param repo  the component repository, not null
 * @return the Spring application context, not null
 */
protected GenericApplicationContext createApplicationContext(ComponentRepository repo) {
    Resource springFile = getSpringFile();
    try {
        repo.getLogger().logDebug("  Spring file: " + springFile.getURI());
    } catch (Exception ex) {
        // ignore
    }

    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    GenericApplicationContext appContext = new GenericApplicationContext(beanFactory);

    PropertyPlaceholderConfigurer properties = new PropertyPlaceholderConfigurer();
    properties.setLocation(getPropertiesFile());

    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    beanDefinitionReader.setValidating(true);
    beanDefinitionReader.setResourceLoader(appContext);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(appContext));
    beanDefinitionReader.loadBeanDefinitions(springFile);

    appContext.getBeanFactory().registerSingleton("injectedProperties", properties);
    appContext.getBeanFactory().registerSingleton("componentRepository", repo);

    appContext.refresh();
    return appContext;
}

From source file:com.github.yihtserns.jaxbean.unmarshaller.api.SpringBeanHandlerTest.java

@Override
protected <T> T unmarshal(String xml, Class<T> rootType, Class<?>... allTypes) throws Exception {
    JaxbeanUnmarshaller unmarshaller = JaxbeanUnmarshaller.newInstance(merge(rootType, allTypes));
    final UnmarshallerNamespaceHandler unmarshallerNamespaceHandler = new UnmarshallerNamespaceHandler(
            unmarshaller);//from  w w w  .  j a  va2  s  . com

    GenericApplicationContext appContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext) {

        @Override
        protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
            final NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver();
            return new NamespaceHandlerResolver() {

                public NamespaceHandler resolve(String namespaceUri) {
                    if (namespaceUri.equals("http://example.com/jaxb")) {
                        return unmarshallerNamespaceHandler;
                    }
                    return defaultResolver.resolve(namespaceUri);
                }
            };
        }
    };
    xmlReader.setValidating(false);
    xmlReader.loadBeanDefinitions(new InputSource(new StringReader(xml)));
    appContext.refresh();

    return appContext.getBean(rootType);
}

From source file:org.apache.synapse.mediators.spring.SpringMediator.java

private synchronized void buildAppContext(MessageContext synCtx) {
    log.debug("Creating Spring ApplicationContext from property key : " + configKey);
    GenericApplicationContext appContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
    xbdr.setValidating(false);
    xbdr.loadBeanDefinitions(new InputStreamResource(
            Util.getStreamSource(synCtx.getConfiguration().getProperty(configKey)).getInputStream()));
    appContext.refresh();/*from  www.  j av a 2s.c o m*/
    this.appContext = appContext;
}