001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.wsdlextensions.jms.validator;
021:
022: import java.util.ArrayList;
023: import java.util.Properties;
024: import java.util.StringTokenizer;
025:
026: /**
027: * The format of the ConnectionURL is as follows:
028: * ConnectionURL := url[,url]*
029: * url := protocol://server:host/service[?options]
030: * protocol := mq, mqtcp, mqssl, http, https
031: * service := jms, ssljms, connectRoot/tunnel
032: * options := key=value[&key=value]*
033: *
034: */
035: public class SunOneUrlParser extends ConnectionUrl {
036: private SunOneConnectionUrl[] mConnectionUrls;
037:
038: /**
039: * Protocol 1
040: */
041: public static final String PROT_MQ = "mq";
042: /**
043: * Protocol 2
044: */
045: public static final String PROT_MQTCP = "mqtcp";
046: /**
047: * Protocol 3
048: */
049: public static final String PROT_MQSSL = "mqssl";
050: /**
051: * Protocol 4
052: */
053: public static final String PROT_HTTP = "httpjms";
054: /**
055: * Protocol 5
056: */
057: public static final String PROT_HTTPS = "httpsjms";
058: /**
059: * conection schema list
060: */
061: public static final String[] URL_PREFIXES = new String[] {
062: PROT_MQ + "://", PROT_MQTCP + "://", PROT_MQSSL + "://",
063: PROT_HTTP + "://", PROT_HTTPS + "://", };
064: /**
065: * connection schema list
066: */
067: public static final String[] PROTOCOLS = new String[] { PROT_MQ,
068: PROT_MQTCP, PROT_MQSSL, PROT_HTTP, PROT_HTTPS, };
069:
070: /**
071: * Constructor
072: *
073: * @param s connection url string
074: */
075: public SunOneUrlParser(String s) {
076: ArrayList urls = new ArrayList();
077: for (StringTokenizer it = new StringTokenizer(s, ","); it
078: .hasMoreTokens();) {
079: String url = it.nextToken();
080: urls.add(new SunOneConnectionUrl(url));
081: }
082: mConnectionUrls = (SunOneConnectionUrl[]) urls
083: .toArray(new SunOneConnectionUrl[urls.size()]);
084: }
085:
086: /**
087: * @param toAddTo properties to be added to.
088: * @throws ValidationException
089: * if the URL validation failed.
090: * @see com.stc.jmsjca.util.ConnectionUrl#getQueryProperties(java.util.Properties)
091: */
092: public void getQueryProperties(Properties toAddTo)
093: throws ValidationException {
094: SunOneConnectionUrl[] urls = getConnectionUrls();
095: for (int i = 0; i < urls.length; i++) {
096: urls[i].getQueryProperties(toAddTo);
097: }
098: }
099:
100: /**
101: * Checks the validity of the URL; adjusts the port number if necessary
102: *
103: * @throws ValidationException
104: * if the URL validation failed.
105: * @return boolean true if the url specified url object was changed by this
106: * validation
107: */
108: public boolean validate() throws ValidationException {
109:
110: if (mConnectionUrls.length == 0) {
111: throw new ValidationException(
112: "URL should be a comma delimited set of URLs");
113: }
114: boolean protOk = true;
115: for (int j = 0; j < mConnectionUrls.length; j++) {
116: SunOneConnectionUrl url = mConnectionUrls[j];
117: protOk = false;
118: for (int i = 0; i < PROTOCOLS.length; i++) {
119: if (PROTOCOLS[i].equals(url.getProtocol())) {
120: protOk = true;
121: break;
122: }
123: }
124: if (!protOk) {
125: throw new ValidationException("Invalid protocol ["
126: + url.getProtocol() + "]: should be one of ["
127: + Str.concat(PROTOCOLS, ", ") + "].");
128: }
129: }
130: return protOk;
131: }
132:
133: /**
134: * Returns the parsers that constitute the URL
135: *
136: * @return ConnectionUrl
137: */
138: public SunOneConnectionUrl[] getConnectionUrls() {
139: return mConnectionUrls;
140: }
141:
142: /**
143: * Constructs a comma delimited string of schema://host:port/service
144: *
145: * @return String
146: * @throws ValidationException
147: * if the URL validation failed.
148: */
149: public String getSunOneUrlSet() throws ValidationException {
150: SunOneConnectionUrl[] urls = getConnectionUrls();
151: StringBuffer buf = new StringBuffer();
152: for (int i = 0; i < urls.length; i++) {
153: if (i != 0) {
154: buf.append(",");
155: }
156: buf.append(urls[i].getProtocol() + "://"
157: + urls[i].getHost() + ":" + urls[i].getPort() + "/"
158: + urls[i].getService());
159: }
160: return buf.toString();
161: }
162:
163: /**
164: * Constructs a comma delimited string of schema://host:port/admin or schema://host:port/ssladmin
165: *
166: * @return String
167: * @throws ValidationException
168: * if the URL validation failed.
169: */
170: public String getSunOneUrlAdminSet() throws ValidationException {
171: SunOneConnectionUrl[] urls = getConnectionUrls();
172: StringBuffer buf = new StringBuffer();
173: for (int i = 0; i < urls.length; i++) {
174: if (i != 0) {
175: buf.append(",");
176: }
177: if ("jms".equals(urls[i].getService())) {
178: buf.append(urls[i].getProtocol() + "://"
179: + urls[i].getHost() + ":" + urls[i].getPort()
180: + "/admin");
181: } else if ("jssljms".equals(urls[i].getService())) {
182: buf.append(urls[i].getProtocol() + "://"
183: + urls[i].getHost() + ":" + urls[i].getPort()
184: + "/ssladmin");
185: } else {
186: buf.append(urls[i].getProtocol() + "://"
187: + urls[i].getHost() + ":" + urls[i].getPort()
188: + "/admin");
189: }
190: }
191: return buf.toString();
192: }
193:
194: }
|