View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  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,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.core.service;
21  
22  import java.net.SocketAddress;
23  import java.util.Collections;
24  import java.util.Set;
25  
26  import org.apache.mina.core.session.IoSessionConfig;
27  import org.apache.mina.util.IdentityHashSet;
28  
29  
30  /**
31   * A default immutable implementation of {@link TransportMetadata}.
32   *
33   * @author The Apache MINA Project (dev@mina.apache.org)
34   * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $
35   */
36  public class DefaultTransportMetadata implements TransportMetadata {
37  
38      private final String providerName;
39      private final String name;
40      private final boolean connectionless;
41      private final boolean fragmentation;
42      private final Class<? extends SocketAddress> addressType;
43      private final Class<? extends IoSessionConfig> sessionConfigType;
44      private final Set<Class<? extends Object>> envelopeTypes;
45  
46      public DefaultTransportMetadata(
47              String providerName,
48              String name,
49              boolean connectionless,
50              boolean fragmentation,
51              Class<? extends SocketAddress> addressType,
52              Class<? extends IoSessionConfig> sessionConfigType,
53              Class<?>... envelopeTypes) {
54  
55          if (providerName == null) {
56              throw new NullPointerException("providerName");
57          }
58          if (name == null) {
59              throw new NullPointerException("name");
60          }
61  
62          providerName = providerName.trim().toLowerCase();
63          if (providerName.length() == 0) {
64              throw new IllegalArgumentException("providerName is empty.");
65          }
66          name = name.trim().toLowerCase();
67          if (name.length() == 0) {
68              throw new IllegalArgumentException("name is empty.");
69          }
70          
71          if (addressType == null) {
72              throw new NullPointerException("addressType");
73          }
74  
75          if (envelopeTypes == null) {
76              throw new NullPointerException("envelopeTypes");
77          }
78  
79          if (envelopeTypes.length == 0) {
80              throw new NullPointerException("envelopeTypes is empty.");
81          }
82  
83          if (sessionConfigType == null) {
84              throw new NullPointerException("sessionConfigType");
85          }
86  
87          this.providerName = providerName;
88          this.name = name;
89          this.connectionless = connectionless;
90          this.fragmentation = fragmentation;
91          this.addressType = addressType;
92          this.sessionConfigType = sessionConfigType;
93  
94          Set<Class<? extends Object>> newEnvelopeTypes =
95              new IdentityHashSet<Class<? extends Object>>();
96          for (Class<? extends Object> c: envelopeTypes) {
97              newEnvelopeTypes.add(c);
98          }
99          this.envelopeTypes = Collections.unmodifiableSet(newEnvelopeTypes);
100     }
101 
102     public Class<? extends SocketAddress> getAddressType() {
103         return addressType;
104     }
105 
106     public Set<Class<? extends Object>> getEnvelopeTypes() {
107         return envelopeTypes;
108     }
109 
110     public Class<? extends IoSessionConfig> getSessionConfigType() {
111         return sessionConfigType;
112     }
113 
114     public String getProviderName() {
115         return providerName;
116     }
117 
118     public String getName() {
119         return name;
120     }
121 
122     public boolean isConnectionless() {
123         return connectionless;
124     }
125 
126     public boolean hasFragmentation() {
127         return fragmentation;
128     }
129 
130     @Override
131     public String toString() {
132         return name;
133     }
134 }