001: /*
002: * XML 2 Java Binding (X2JB) - the excellent Java tool.
003: * Copyright 2007, by Richard Opalka.
004: *
005: * This is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as
007: * published by the Free Software Foundation; either version 2.1 of
008: * the License, or (at your option) any later version.
009: *
010: * This software is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this software; if not see the FSF site:
017: * http://www.fsf.org/ and search for the LGPL License document there.
018: */
019: package namespaces;
020:
021: import javax.xml.parsers.DocumentBuilder;
022: import javax.xml.parsers.DocumentBuilderFactory;
023: import javax.xml.parsers.ParserConfigurationException;
024: import org.w3c.dom.Document;
025: import org.w3c.dom.Element;
026: import org.x2jb.bind.XML2Java;
027: import namespaces.ifaces.*;
028:
029: /**
030: * Namespaces sample
031: * @author <a href="mailto:richard_opalka@yahoo.com">Richard Opalka</a>
032: * @version 1.0
033: */
034: public final class Main {
035:
036: /**
037: * Lookups specified resource on the classpath and returns parsed document instance
038: * @param classpath resource to return
039: */
040: private static Document getDocument(String resource)
041: throws Exception {
042: Document retVal = null;
043: try {
044: DocumentBuilderFactory builderFactory = DocumentBuilderFactory
045: .newInstance();
046: builderFactory.setNamespaceAware(true);
047: builderFactory.setIgnoringComments(true);
048: DocumentBuilder builder = builderFactory
049: .newDocumentBuilder();
050: retVal = builder.parse(Main.class
051: .getResourceAsStream(resource));
052: } catch (ParserConfigurationException e) {
053: e.printStackTrace(System.err);
054: System.exit(1);
055: }
056: return retVal;
057: }
058:
059: public static void main(String[] args) throws Exception {
060: Document parsedDocument = getDocument("/server.xml");
061: ServerConfig config = (ServerConfig) XML2Java.bind(
062: parsedDocument, ServerConfig.class);
063:
064: ModuleConfig[] modules = config.getRegisteredModules();
065:
066: System.out.println();
067: System.out.println("Registered server modules: ");
068: System.out.println();
069: for (int i = 0; i < modules.length; i++) {
070: System.out.println("Module name: " + modules[i].getName());
071: System.out.println("Module class: "
072: + modules[i].getClassName());
073: InterceptorConfig[] interceptorConfigs = modules[i]
074: .getInterceptors();
075: TransportConfig[] transportConfigs = modules[i]
076: .getTransports();
077:
078: if (interceptorConfigs.length > 0) {
079: // print out interceptor repository configuration
080: System.out.println();
081: System.out.println(" Registered interceptors: ");
082: System.out.println();
083: for (int j = 0; j < interceptorConfigs.length; j++) {
084: InterceptorConfig ic = interceptorConfigs[j];
085: System.out.println(" Name: " + ic.getName());
086: System.out.println(" Class: "
087: + ic.getClassName());
088: System.out.println(" Direction: "
089: + ic.getDirection());
090: System.out.println();
091: }
092: }
093:
094: if (transportConfigs.length > 0) {
095: // print out transport repository configuration
096: System.out.println();
097: System.out.println(" Registered transports: ");
098: System.out.println();
099: for (int j = 0; j < transportConfigs.length; j++) {
100: TransportConfig tc = transportConfigs[j];
101: System.out.println(" Name: " + tc.getName());
102: System.out.println(" Class: "
103: + tc.getClassName());
104: System.out.println(" Protocol: "
105: + tc.getProtocol());
106: System.out.println(" Port: " + tc.getPort());
107: System.out.println(" Max threads count: "
108: + tc.getMaxThreads());
109: System.out.println(" Connection timeout: "
110: + tc.getConnectionTimeout());
111: System.out.println();
112: }
113: }
114:
115: System.out.println();
116: }
117: }
118:
119: }
|