EMMA Coverage Report (generated Sat Nov 12 08:39:53 KST 2005)
[all classes][org.apache.mina.common]

COVERAGE SUMMARY FOR SOURCE FILE [TransportType.java]

nameclass, %method, %block, %line, %
TransportType.java100% (1/1)62%  (5/8)69%  (168/242)69%  (27/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TransportType100% (1/1)62%  (5/8)69%  (168/242)69%  (27/39)
getNames (): Set 0%   (0/1)0%   (0/23)0%   (0/4)
readResolve (): Object 0%   (0/1)0%   (0/22)0%   (0/4)
toString (): String 0%   (0/1)0%   (0/5)0%   (0/1)
TransportType (String [], boolean): void 100% (1/1)60%  (36/60)77%  (10/13)
<static initializer> 100% (1/1)100% (46/46)100% (4/4)
getInstance (String): TransportType 100% (1/1)100% (22/22)100% (4/4)
isConnectionless (): boolean 100% (1/1)100% (3/3)100% (1/1)
register (String [], TransportType): void 100% (1/1)100% (61/61)100% (8/8)

1/*
2 *   @(#) $Id: TransportType.java 332218 2005-11-10 03:52:42Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.common;
20 
21import java.io.InvalidObjectException;
22import java.io.ObjectStreamException;
23import java.io.Serializable;
24import java.util.HashMap;
25import java.util.Map;
26import java.util.Set;
27import java.util.TreeSet;
28 
29/**
30 * Represents network transport types.
31 * MINA provides three transport types by default:
32 * <ul>
33 *   <li>{@link #SOCKET} - TCP/IP</li>
34 *   <li>{@link #DATAGRAM} - UDP/IP</li>
35 *   <li>{@link #VM_PIPE} - in-VM pipe support (only available in protocol
36 *       layer</li>
37 * </ul>
38 * <p>
39 * You can also create your own transport type.  Please refer to
40 * {@link #TransportType(String[], boolean)}.
41 * 
42 * @author The Apache Directory Project (dev@directory.apache.org)
43 * @version $Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
44 */
45public final class TransportType implements Serializable
46{
47    private static final long serialVersionUID = 3258132470497883447L;
48    
49    private static final Map name2type = new HashMap();
50    
51    private static void register( String[] names, TransportType type )
52    {
53        synchronized( name2type )
54        {
55            for( int i = names.length - 1; i >= 0; i -- )
56            {
57                if( name2type.containsKey( names[i] ) )
58                {
59                    throw new IllegalArgumentException(
60                            "Transport type name '" + names[i] + "' is already taken." );
61                }
62            }
63 
64            for( int i = names.length - 1; i >= 0; i -- )
65            {
66                name2type.put( names[i].toUpperCase(), type );
67            }
68        }
69    }
70 
71    /**
72     * Transport type: TCP/IP (Registry name: <tt>"SOCKET"</tt> or <tt>"TCP"</tt>)
73     */
74    public static final TransportType SOCKET =
75        new TransportType( new String[] { "SOCKET", "TCP" }, false );
76 
77    /**
78     * Transport type: UDP/IP (Registry name: <tt>"DATAGRAM"</tt> or <tt>"UDP"</tt>)
79     */
80    public static final TransportType DATAGRAM =
81        new TransportType( new String[] { "DATAGRAM", "UDP" }, true );
82 
83    /**
84     * Transport type: in-VM pipe (Registry name: <tt>"VM_PIPE"</tt>) 
85     * Please refer to
86     * <a href="../protocol/vmpipe/package-summary.htm"><tt>org.apache.mina.protocol.vmpipe</tt></a>
87     * package.
88     */
89    public static final TransportType VM_PIPE =
90        new TransportType( new String[] { "VM_PIPE" }, false );
91    
92 
93    /**
94     * Returns the transport type of the specified name.
95     * All names are case-insensitive.
96     * 
97     * @param name the name of the transport type
98     * @return the transport type
99     * @throws IllegalArgumentException if the specified name is not available.
100     */
101    public static TransportType getInstance( String name )
102    {
103        TransportType type = (TransportType) name2type.get( name.toUpperCase() );
104        if( type != null )
105        {
106            return type;
107        }
108        
109        throw new IllegalArgumentException("Unknown transport type name: " + name);
110    }
111 
112    private final String[] names;
113 
114    private final transient boolean connectionless;
115 
116    /**
117     * Creates a new instance.  New transport type is automatically registered
118     * to internal registry so that you can look it up using {@link #getInstance(String)}.
119     * 
120     * @param names the name or aliases of this transport type
121     * @param connectionless <tt>true</tt> if and only if this transport type is connectionless
122     * 
123     * @throws IllegalArgumentException if <tt>names</tt> are already registered or empty
124     */
125    public TransportType( String[] names, boolean connectionless )
126    {
127        if( names == null )
128        {
129            throw new NullPointerException( "names" );
130        }
131        if( names.length == 0 )
132        {
133            throw new IllegalArgumentException( "names is empty" );
134        }
135 
136        for( int i = 0; i < names.length; i ++ )
137        {
138            if( names[ i ] == null )
139            {
140                throw new NullPointerException( "strVals[" + i + "]" );
141            }
142            
143            names[ i ] = names[ i ].toUpperCase();
144        }
145 
146        register( names, this );
147        this.names = names;
148        this.connectionless = connectionless;
149    }
150 
151    /**
152     * Returns <code>true</code> if the session of this transport type is
153     * connectionless.
154     */
155    public boolean isConnectionless()
156    {
157        return connectionless;
158    }
159    
160    /**
161     * Returns the known names of this transport type.
162     */
163    public Set getNames()
164    {
165        Set result = new TreeSet();
166        for( int i = names.length - 1; i >= 0; i -- )
167        {
168            result.add( names[ i ] );
169        }
170        
171        return result;
172    }
173 
174    public String toString()
175    {
176        return names[0];
177    }
178    
179    private Object readResolve() throws ObjectStreamException
180    {
181        for( int i = names.length - 1; i >= 0; i -- )
182        {
183            try
184            {
185                return getInstance( names[ i ] );
186            }
187            catch( IllegalArgumentException e )
188            {
189                // ignore
190            }
191        }
192        
193        throw new InvalidObjectException( "Unknown transport type." );
194    }
195}

[all classes][org.apache.mina.common]
EMMA 2.0.4217 (C) Vladimir Roubtsov