📄 gatewayconfigurationhandler.java
字号:
/* * ProxyHandler.java * Used for creating the table containing the association between the method * names and the classes processing the corresponding messages. * Created on February 3, 2003, 10:52 AM */package gov.nist.examples.bps.gateway;import gov.nist.examples.bps.presenceserver.Location;import gov.nist.examples.bps.presenceserver.Rank;import java.io.IOException;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.XMLReader;import org.xml.sax.helpers.DefaultHandler;/** * * @author deruelle */public class GatewayConfigurationHandler extends DefaultHandler { private Configuration configuration; private StackConfiguration stackConfiguration; private String element; private void configurationMessage(String message) { System.out.println(element + ":" + message); } /** Creates a new instance of ProxyHandler */ public GatewayConfigurationHandler(String confFile) { try{ SAXParserFactory saxParserFactory=SAXParserFactory.newInstance(); SAXParser saxParser = saxParserFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setContentHandler(this); xmlReader.setFeature ("http://xml.org/sax/features/validation",false); // parse the xml specification for the event tags. xmlReader.parse(confFile); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException sxe) { sxe.printStackTrace(); } catch (IOException ioe) { // I/O error ioe.printStackTrace(); } catch (Exception pce) { // Parser with specified options can't be built pce.printStackTrace(); } } public Configuration getConfiguration() { return configuration; } //=========================================================== // SAX DocumentHandler methods //=========================================================== public void startDocument() throws SAXException { try { GatewayDebug.println("---------------------------------------"); GatewayDebug.println("Parsing the XML configuration file..."); configuration=new Configuration(); } catch (Exception e) { throw new SAXException("XMLRegistrationsParser error", e); } } public void endDocument() throws SAXException { try { GatewayDebug.println ("The XML configuration file has been successfully parsed!"); GatewayDebug.println("---------------------------------------"); } catch (Exception e) { throw new SAXException("XMLRegistrationsParser error", e); } } public void startElement(String namespaceURI, String lName, // local name String qName, // qualified name Attributes attrs) throws SAXException { String element=qName; this.element = element; if (element.compareToIgnoreCase("BADGES") ==0 ) { String configFile=attrs.getValue("configuration_file"); if (configFile!=null && !configFile.trim().equals("")) { configurationMessage ("INFORMATION: The Badge configuration File is set to " +configFile); configuration.badgesConfigurationFile=configFile.trim(); } } if (element.compareToIgnoreCase("SIP_STACKS") ==0 ) { String pstnGateway=attrs.getValue("pstn_gateway"); if (pstnGateway!=null && !pstnGateway.trim().equals("")) { configurationMessage ("INFORMATION: The pstn Gateway is set to " +pstnGateway); configuration.pstnGateway=pstnGateway.trim(); } } if (element.compareToIgnoreCase("SIP_STACK") ==0 ) { stackConfiguration=new StackConfiguration(); String stackName=attrs.getValue("stack_name"); if (stackName==null || stackName.trim().equals("")) { configurationMessage("ERROR: the name of the stack is not set"); } else { stackConfiguration.stackName=stackName.trim(); configurationMessage("INFORMATION: the name of the stack is set to:"+ stackConfiguration.stackName); } String stackIPAddress=attrs.getValue("stack_IP_address"); if (stackIPAddress==null || stackIPAddress.trim().equals("")) { configurationMessage ("ERROR: the IP address of the stack is not set"); } else { stackConfiguration.stackIPAddress=stackIPAddress.trim(); configurationMessage ("INFORMATION: the stack IP address is set to:" + stackConfiguration.stackIPAddress); } String outboundProxy=attrs.getValue("outbound_proxy"); if (outboundProxy==null || outboundProxy.trim().equals("")) { configurationMessage ("INFORMATION: the outbound proxy is not set"); } else { stackConfiguration.outboundProxy=outboundProxy.trim(); configurationMessage ("INFORMATION: the outbound proxy is " + stackConfiguration.outboundProxy); } String routerPath=attrs.getValue("router_path"); if (routerPath==null || routerPath.trim().equals("")) { configurationMessage ("WARNING: the path for the router is not set using default"); } else { stackConfiguration.routerPath=routerPath.trim(); configurationMessage ("INFORMATION: the path for the router is set to: " + stackConfiguration.routerPath.trim()); } String extensionMethods=attrs.getValue("extension_methods"); if (extensionMethods==null || extensionMethods.trim().equals("") ) { configurationMessage ("INFORMATION: no extensions are supported"); } else { stackConfiguration.extensionMethods=extensionMethods.trim(); configurationMessage ("INFORMATION: extensions supported: " + stackConfiguration.extensionMethods); } String retransmissionFilter=attrs.getValue("retransmission_filter"); if (retransmissionFilter!=null && !retransmissionFilter.trim().equals("")) { configurationMessage ("INFORMATION: the retransmission filter is set to:" + retransmissionFilter); stackConfiguration.retransmissionFilter=retransmissionFilter.trim(); } else configurationMessage ("INFORMATION: no default retransmission filter"); String maxConnections=attrs.getValue("max_connections"); if (maxConnections!=null && !maxConnections.trim().equals("")) { configurationMessage ("INFORMATION: The proxy will authorize only " +maxConnections+" connections"); stackConfiguration.maxConnections=maxConnections.trim(); } String maxServerTransactions=attrs.getValue("max_server_transactions"); if (maxServerTransactions!=null && !maxServerTransactions.trim().equals("")) { configurationMessage ("INFORMATION: The proxy will authorize only " +maxServerTransactions+" server transactions"); stackConfiguration.maxServerTransactions=maxServerTransactions.trim(); } String threadPoolSize=attrs.getValue("thread_pool_size"); if (threadPoolSize!=null && !threadPoolSize.trim().equals("")) { configurationMessage ("INFORMATION: The thread pool size is set to " +threadPoolSize); stackConfiguration.threadPoolSize=threadPoolSize.trim(); } configuration.stackConfigurationList.addElement(stackConfiguration); } if (element.compareToIgnoreCase("LISTENING_POINT") ==0 ) { String stackPort=attrs.getValue("port"); if (stackPort==null || stackPort.trim().equals("")) { configurationMessage ("ERROR: the port of the stack is not set"); } else { String stackTransport=attrs.getValue("transport"); if (stackTransport==null || stackTransport.trim().equals("")) { configurationMessage ("ERROR: the transport is not set"); } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -