01: /*
02: * Created on 2005.11.29
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.enhydra.util;
08:
09: import java.io.*;
10: import javax.xml.parsers.*;
11: import org.xml.sax.*;
12: import org.xml.sax.helpers.*;
13: import java.util.regex.Pattern;
14:
15: /**
16: * A utility class extracts Axis service names from (server-config) wsdd file
17: * and forms a pattern which can be used to recognize Axis requests
18: *
19: * @author dt
20: *
21: *
22: */
23: public class ServiceExtractor {
24: private DefaultHandler handler = new MyHandler();
25:
26: private Pattern pattern;
27:
28: static final char SLASH = '/';
29:
30: static final String ANYSLASH = ".*/";
31:
32: static class MyHandler extends DefaultHandler {
33:
34: static final String SERVICE = "service";
35:
36: static final String NAME = "name";
37:
38: static final String EMPTY = "";
39:
40: static final char DOLLAR = '$';
41:
42: static final char PIPE = '|';
43:
44: static String prefix = EMPTY;
45:
46: static String services = EMPTY;
47:
48: public void startElement(String namespaceURI, String localName,
49: String qName, Attributes atts) throws SAXException {
50: if (qName.equals(SERVICE)) {
51: String name = prefix + atts.getValue(NAME) + DOLLAR;
52: if (services == EMPTY) {
53: services = name;
54: } else {
55: services = services + PIPE + name;
56: }
57: }
58: }
59: }
60:
61: /*
62: * ServiceExtractor constructor
63: *
64: * @param fileName path to the service-config.wsdd file
65: *
66: * @param prefix prefix added into each pattern element
67: */
68: public ServiceExtractor(String fileName, String prefix) {
69: MyHandler.prefix = ANYSLASH + prefix + SLASH;
70: try {
71: // Create a builder factory
72: SAXParserFactory factory = SAXParserFactory.newInstance();
73: factory.setValidating(false);
74: // Create the builder and parse the file
75: factory.newSAXParser().parse(new File(fileName), handler);
76: } catch (Exception e) {
77: return;
78: }
79: pattern = Pattern.compile(MyHandler.services);
80: }
81:
82: public Pattern getPattern() {
83: return pattern;
84: }
85:
86: public String toString() {
87: return MyHandler.services;
88: }
89: }
|