List of usage examples for org.apache.commons.digester.xmlrules FromXmlRuleSet FromXmlRuleSet
public FromXmlRuleSet(InputSource inputSource, DigesterRuleParser parser)
From source file:com.meidusa.venus.frontend.http.VenusPoolFactory.java
private void loadConfiguration(List<ObjectPool> realPools) throws Exception { VenusClient all = new VenusClient(); for (String configFile : configFiles) { configFile = (String) ConfigUtil.filter(configFile); RuleSet ruleSet = new FromXmlRuleSet(ServiceFactory.class.getResource("venusClientRule.xml"), new DigesterRuleParser()); Digester digester = new Digester(); digester.setValidating(false);/*from ww w . ja v a 2 s . com*/ digester.addRuleSet(ruleSet); try { InputStream is = ResourceUtils.getURL(configFile.trim()).openStream(); VenusClient venus = (VenusClient) digester.parse(is); for (ServiceConfig config : venus.getServiceConfigs()) { if (config.getType() == null) { throw new ConfigurationException("Service type can not be null:" + configFile); } } all.getRemoteMap().putAll(venus.getRemoteMap()); all.getServiceConfigs().addAll(venus.getServiceConfigs()); } catch (Exception e) { throw new ConfigurationException("can not parser xml:" + configFile, e); } } // ? remotePool for (Map.Entry<String, Remote> entry : all.getRemoteMap().entrySet()) { pool = createObjectPool(entry.getValue(), realPools); } }
From source file:com.meidusa.venus.client.VenusServiceFactory.java
private void loadConfiguration(Map<String, Tuple<ObjectPool, BackendConnectionPool>> poolMap, Map<Class<?>, Tuple<Object, RemotingInvocationHandler>> servicesMap, Map<Class<?>, ServiceConfig> serviceConfig, Map<String, Object> realPools) throws Exception { VenusClient all = new VenusClient(); for (String configFile : configFiles) { configFile = (String) ConfigUtil.filter(configFile); URL url = this.getClass().getResource("venusClientRule.xml"); if (url == null) { throw new VenusConfigException("venusClientRule.xml not found!,pls rebuild venus!"); }//from w ww. j ava2 s. c o m RuleSet ruleSet = new FromXmlRuleSet(url, new DigesterRuleParser()); Digester digester = new Digester(); digester.setValidating(false); digester.addRuleSet(ruleSet); try { InputStream is = ResourceUtils.getURL(configFile.trim()).openStream(); VenusClient venus = (VenusClient) digester.parse(is); for (ServiceConfig config : venus.getServiceConfigs()) { if (config.getType() == null) { logger.error("Service type can not be null:" + configFile); throw new ConfigurationException("Service type can not be null:" + configFile); } } all.getRemoteMap().putAll(venus.getRemoteMap()); all.getServiceConfigs().addAll(venus.getServiceConfigs()); } catch (Exception e) { throw new ConfigurationException("can not parser xml:" + configFile, e); } } // ? remotePool for (Map.Entry<String, Remote> entry : all.getRemoteMap().entrySet()) { RemoteContainer container = createRemoteContainer(entry.getValue(), realPools); Tuple<ObjectPool, BackendConnectionPool> tuple = new Tuple<ObjectPool, BackendConnectionPool>(); tuple.left = container.getBioPool(); tuple.right = container.getNioPool(); poolMap.put(entry.getKey(), tuple); } for (ServiceConfig config : all.getServiceConfigs()) { Remote remote = all.getRemoteMap().get(config.getRemote()); Tuple<ObjectPool, BackendConnectionPool> tuple = null; if (!StringUtil.isEmpty(config.getRemote())) { tuple = poolMap.get(config.getRemote()); if (tuple == null) { throw new ConfigurationException("remote=" + config.getRemote() + " not found!!"); } } else { String ipAddress = config.getIpAddressList(); tuple = poolMap.get(ipAddress); if (ipAddress != null && tuple == null) { RemoteContainer container = createRemoteContainer(true, ipAddress, realPools); tuple = new Tuple<ObjectPool, BackendConnectionPool>(); tuple.left = container.getBioPool(); tuple.right = container.getNioPool(); poolMap.put(ipAddress, tuple); } } if (tuple != null) { RemotingInvocationHandler invocationHandler = new RemotingInvocationHandler(); invocationHandler.setBioConnPool(tuple.left); invocationHandler.setNioConnPool(tuple.right); invocationHandler.setServiceFactory(this); invocationHandler.setVenusExceptionFactory(this.getVenusExceptionFactory()); if (remote != null && remote.getAuthenticator() != null) { invocationHandler.setSerializeType(remote.getAuthenticator().getSerializeType()); } invocationHandler.setContainer(this.container); Object object = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { config.getType() }, invocationHandler); for (Method method : config.getType().getMethods()) { Endpoint endpoint = method.getAnnotation(Endpoint.class); if (endpoint != null) { Class[] eclazz = method.getExceptionTypes(); for (Class clazz : eclazz) { if (venusExceptionFactory != null && CodedException.class.isAssignableFrom(clazz)) { venusExceptionFactory.addException(clazz); } } } } serviceConfig.put(config.getType(), config); Tuple<Object, RemotingInvocationHandler> serviceTuple = new Tuple<Object, RemotingInvocationHandler>( object, invocationHandler); servicesMap.put(config.getType(), serviceTuple); if (config.getBeanName() != null) { serviceBeanMap.put(config.getBeanName(), serviceTuple); } } else { if (config.getInstance() != null) { Tuple<Object, RemotingInvocationHandler> serviceTuple = new Tuple<Object, RemotingInvocationHandler>( config.getInstance(), null); servicesMap.put(config.getType(), serviceTuple); if (config.getBeanName() != null) { serviceBeanMap.put(config.getBeanName(), serviceTuple); } } else { throw new ConfigurationException( "Service instance or ipAddressList or remote can not be null:" + config.getType()); } } } }