List of usage examples for org.springframework.beans.factory.xml XmlBeanFactory XmlBeanFactory
public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException
From source file:org.araneaframework.ioc.spring.SimpleAraneaSpringDispatcherServlet.java
public void init() throws ServletException { beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); rootConf = new XmlBeanFactory( new ClassPathResource("spring-property-conf/property-custom-webapp-aranea-conf.xml"), beanFactory); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(new ClassPathResource("spring-property-conf/default-aranea-conf.properties")); Properties localConf = new Properties(); try {/*from www. j a va 2 s .c om*/ if (getServletContext().getResource("/WEB-INF/aranea-conf.properties") != null) localConf.load(getServletContext().getResourceAsStream("/WEB-INF/aranea-conf.properties")); } catch (IOException e) { throw new ServletException(e); } cfg.setProperties(localConf); cfg.setLocalOverride(true); cfg.postProcessBeanFactory(rootConf); super.init(); }
From source file:org.jboss.spring.facade.KernelControllerListableBeanFactoryTestCase.java
@Test public void testKernelControllerAssignableAsParentBeanFactory() throws Throwable { BasicBootstrap bootstrap = new BasicBootstrap(); bootstrap.run();//from ww w . jav a2 s . co m BasicXMLDeployer deployer = new BasicXMLDeployer(bootstrap.getKernel()); BeanFactory parentBeanFactory = new KernelControllerListableBeanFactory( bootstrap.getKernel().getController()); deployer.deploy(KernelControllerListableBeanFactory.class.getResource("microcontainer-beans.xml")); BeanFactory beanFactory = new XmlBeanFactory( new UrlResource(KernelControllerListableBeanFactory.class.getResource("spring-beans.xml")), parentBeanFactory); ComplexService service = (ComplexService) beanFactory.getBean("service"); Assert.assertEquals("Result is: 2", service.processNumbers(1, 1)); deployer.shutdown(); }
From source file:org.jboss.spring.facade.KernelControllerListableBeanFactoryTestCase.java
@Test(expected = BeanCreationException.class) public void testConfigurationFailsIfParentBeanMissing() throws Throwable { BasicBootstrap bootstrap = new BasicBootstrap(); bootstrap.run();/*from w ww . j a va2 s .c o m*/ BasicXMLDeployer deployer = new BasicXMLDeployer(bootstrap.getKernel()); BeanFactory parentBeanFactory = new KernelControllerListableBeanFactory( bootstrap.getKernel().getController()); deployer.deploy(KernelControllerListableBeanFactory.class.getResource("microcontainer-beans-2.xml")); BeanFactory beanFactory = new XmlBeanFactory( new UrlResource(KernelControllerListableBeanFactory.class.getResource("spring-beans.xml")), parentBeanFactory); ComplexService service = (ComplexService) beanFactory.getBean("service"); Assert.assertEquals("Result is: 2", service.processNumbers(1, 1)); deployer.shutdown(); }
From source file:net.freedom.gj.beans.config.SpringXmlMapperConfiguration.java
private BeanFactory getContext(String file) { if (cachedContext.containsKey(file)) { return cachedContext.get(file); } else {//from www.j av a2 s. com Resource res = new ClassPathResource(file); cachedContext.put(file, new XmlBeanFactory(res, parentSpringContext)); return cachedContext.get(file); } }
From source file:org.sakaiproject.reports.logic.impl.ReportsManagerImpl.java
/** * Loads the global database reportDefinitions if they haven't been loaded yet * This is a stub.//from ww w .j a v a2 s . com */ private List loadReportsFromDB() { List<ReportDefinition> reportDefArray = new ArrayList<ReportDefinition>(); List<ReportDefinitionXmlFile> reportDefs = getHibernateTemplate() .findByNamedQuery("findReportDefinitionFiles"); for (ReportDefinitionXmlFile xmlFile : reportDefs) { ListableBeanFactory beanFactory = new XmlBeanFactory(new ByteArrayResource(xmlFile.getXmlFile()), getBeanFactory()); ReportDefinition repDef = getReportDefBean(beanFactory); repDef.finishLoading(); repDef.setDbLoaded(true); if (isValidWorksiteType(repDef.getSiteType()) && isValidRole(repDef.getRole()) && hasWarehouseSetting(repDef.getUsesWarehouse())) { reportDefArray.add(repDef); } } Collections.sort(reportDefArray, new ReportDefinition.ReportDefinitionComparator()); return reportDefArray; }
From source file:org.sakaiproject.reports.logic.impl.ReportsManagerImpl.java
public boolean importResource(Id worksiteId, String nodeId) throws UnsupportedFileTypeException, ImportException, RuntimeException { String id = getContentHosting().resolveUuid(nodeId); try {/*ww w .ja va2 s. c om*/ ContentResource resource = getContentHosting().getResource(id); MimeType mimeType = new MimeType(resource.getContentType()); if (mimeType.equals(new MimeType("application/xml")) || mimeType.equals(new MimeType("text/xml"))) { ListableBeanFactory beanFactory = new XmlBeanFactory(new ByteArrayResource(resource.getContent()), getBeanFactory()); ReportDefinitionXmlFile bean = importReport(resource); if (bean != null) { saveReportDef(bean, beanFactory); } return bean != null; } else { throw new UnsupportedFileTypeException("Unsupported file type"); } } catch (ServerOverloadException soe) { logger.warn(soe); } catch (PermissionException pe) { logger.warn("Failed loading content: no permission to view file", pe); } catch (TypeException te) { logger.warn("Wrong type", te); } catch (IdUnusedException iue) { logger.warn("UnusedId: ", iue); } return false; }
From source file:org.sakaiproject.reports.logic.impl.ReportsManagerImpl.java
protected void updateDefinition(ReportsDefinitionWrapper wrapper, ReportDefinitionXmlFile def) { try {/* w w w .j av a2 s . c om*/ InputStream stream = wrapper.getParentClass().getResourceAsStream(wrapper.getDefinitionFileLocation()); if (stream == null) { throw new RuntimeException( "Loaded Report Definition failed: " + wrapper.getDefinitionFileLocation()); } Set xslFilesToBeRemoved = new HashSet(); if (def.getReportXslFiles() != null) { xslFilesToBeRemoved.addAll(def.getReportXslFiles()); } else { def.setReportXslFiles(new HashSet()); } def.setXmlFile(readStreamToBytes( wrapper.getParentClass().getResourceAsStream(wrapper.getDefinitionFileLocation()))); ListableBeanFactory beanFactory = new XmlBeanFactory( new ByteArrayResource(readStreamToBytes( wrapper.getParentClass().getResourceAsStream(wrapper.getDefinitionFileLocation()))), getBeanFactory()); ReportDefinition repDef = getReportDefBean(beanFactory); List xsls = repDef.getXsls(); for (Iterator i = xsls.iterator(); i.hasNext();) { ReportXsl xsl = (ReportXsl) i.next(); ReportXslFile xslFile = new ReportXslFile(); if (wrapper.getParentClass().getResourceAsStream(xsl.getXslLink()) != null) { xslFile.setXslFile( readStreamToBytes(wrapper.getParentClass().getResourceAsStream(xsl.getXslLink()))); xslFile.setXslFileHash(DigestUtils.md5Hex(xslFile.getXslFile())); } //xslFile.setReportDefId(repDef.getIdString()); xslFile.setReportXslFileRef(xsl.getXslLink()); if (def.getReportXslFiles().contains(xslFile)) { xslFilesToBeRemoved.remove(xslFile); } else { def.getReportXslFiles().add(xslFile); } } for (Iterator<ReportXslFile> i = xslFilesToBeRemoved.iterator(); i.hasNext();) { ReportXslFile removedFile = i.next(); def.getReportXslFiles().remove(removedFile); } getHibernateTemplate().saveOrUpdate(def); } catch (Exception e) { throw new RuntimeException("Loaded report def failed", e); } }
From source file:net.sourceforge.vulcan.spring.SpringFileStore.java
@Override public synchronized StateManagerConfigDto loadConfiguration() throws StoreException { final Resource configResource = getConfigurationResource(); final XmlBeanFactory beanFactory = new XmlBeanFactory(configResource, this.beanFactory); beanFactory.registerCustomEditor(java.util.Date.class, new DateEditor()); return (StateManagerConfigDto) beanFactory.getBean("configuration"); }