View Javadoc

1   /*
2    *
3    * The Seasar Software License, Version 1.1
4    *
5    * Copyright (c) 2003-2004 The Seasar Project. All rights reserved.
6    *
7    * Redistribution and use in source and binary forms, with or
8    * without modification, are permitted provided that the following
9    * conditions are met:
10   *
11   * 1. Redistributions of source code must retain the above
12   *    copyright notice, this list of conditions and the following
13   *    disclaimer.
14   *
15   * 2. Redistributions in binary form must reproduce the above
16   *    copyright notice, this list of conditions and the following
17   *    disclaimer in the documentation and/or other materials provided
18   *    with the distribution.
19   *
20   * 3. The end-user documentation included with the redistribution,
21   *    if any, must include the following acknowledgement:
22   *    "This product includes software developed by the
23   *    Seasar Project (http://www.seasar.org/)."
24   *    Alternately, this acknowledgement may appear in the software
25   *    itself, if and wherever such third-party acknowledgements
26   *    normally appear.
27   *
28   * 4. Neither the name "The Seasar Project" nor the names of its
29   *    contributors may be used to endorse or promote products derived
30   *    from this software without specific prior written permission of
31   *    the Seasar Project.
32   *
33   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR
34   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE SEASAR PROJECT
37   * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38   * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42   * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING
43   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
44   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45   */
46  package org.seasar.remoting.common.url;
47  
48  import java.net.URL;
49  import java.net.URLConnection;
50  import java.net.URLStreamHandler;
51  
52  /***
53   * デフォルトのポート番号を持ち、オープンすることの出来ない <code>URL</code> のための
54   * <code>URLStreamHandler</code> です。
55   * 
56   * @author koichik
57   */
58  public class UnopenableURLStreamHandler extends URLStreamHandler {
59      protected final int defaultPort;
60  
61      /***
62       * 指定されたポート番号をデフォルトとして持つ新しいインスタンスを構築します。
63       * 
64       * @param defaultPort
65       *            このプロトコルのデフォルトのポート番号
66       */
67      public UnopenableURLStreamHandler(final int defaultPort) {
68          this.defaultPort = defaultPort;
69      }
70  
71      /***
72       * この操作はサポートされません。
73       * 
74       * @throws UnsupportedOperationException
75       *             常にスローされます
76       */
77      protected URLConnection openConnection(final URL url) {
78          throw new UnsupportedOperationException();
79      }
80  
81      /***
82       * <code>URL</code> 引数フィールド値を、指定された値に設定します。 <br>
83       * ポート番号が指定されていない場合は、コンストラクタで指定されたデフォルトのポート番号を設定します。
84       * 
85       * @param url
86       *            修正する <code>URL</code>
87       * @param protocol
88       *            プロトコル名
89       * @param host
90       *            <code>URL</code> のリモートホスト値
91       * @param port
92       *            リモートマシン上のポート
93       * @param authority
94       *            <code>URL</code> の権限部分
95       * @param userInfo
96       *            <code>URL</code> のユーザ情報部分
97       * @param path
98       *            <code>URL</code> のパスコンポーネント
99       * @param query
100      *            <code>URL</code> のクエリー部分
101      * @param ref
102      *            参照
103      */
104     protected void setURL(final URL url, final String protocol, final String host, int port,
105             final String authority, final String userInfo, final String path, final String query,
106             final String ref) {
107         if (port == -1) {
108             port = defaultPort;
109         }
110         super.setURL(url, protocol, host, port, authority, userInfo, path, query, ref);
111     }
112 }