001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *
019: */
020: package org.apache.mina.common;
021:
022: import java.net.SocketAddress;
023: import java.util.Collections;
024: import java.util.Set;
025:
026: import org.apache.mina.util.IdentityHashSet;
027:
028: /**
029: * A default immutable implementation of {@link TransportMetadata}.
030: *
031: * @author The Apache MINA Project (dev@mina.apache.org)
032: * @version $Rev: 596886 $, $Date: 2007-11-20 17:09:39 -0700 (Tue, 20 Nov 2007) $
033: */
034: public class DefaultTransportMetadata implements TransportMetadata {
035:
036: private final String providerName;
037: private final String name;
038: private final boolean connectionless;
039: private final boolean fragmentation;
040: private final Class<? extends SocketAddress> addressType;
041: private final Class<? extends IoSessionConfig> sessionConfigType;
042: private final Set<Class<? extends Object>> envelopeTypes;
043:
044: public DefaultTransportMetadata(String providerName, String name,
045: boolean connectionless, boolean fragmentation,
046: Class<? extends SocketAddress> addressType,
047: Class<? extends IoSessionConfig> sessionConfigType,
048: Class<?>... envelopeTypes) {
049:
050: if (providerName == null) {
051: throw new NullPointerException("providerName");
052: }
053: if (name == null) {
054: throw new NullPointerException("name");
055: }
056:
057: providerName = providerName.trim().toLowerCase();
058: if (providerName.length() == 0) {
059: throw new IllegalArgumentException("providerName is empty.");
060: }
061: name = name.trim().toLowerCase();
062: if (name.length() == 0) {
063: throw new IllegalArgumentException("name is empty.");
064: }
065:
066: if (addressType == null) {
067: throw new NullPointerException("addressType");
068: }
069:
070: if (envelopeTypes == null) {
071: throw new NullPointerException("envelopeTypes");
072: }
073:
074: if (envelopeTypes.length == 0) {
075: throw new NullPointerException("envelopeTypes is empty.");
076: }
077:
078: if (sessionConfigType == null) {
079: throw new NullPointerException("sessionConfigType");
080: }
081:
082: this .providerName = providerName;
083: this .name = name;
084: this .connectionless = connectionless;
085: this .fragmentation = fragmentation;
086: this .addressType = addressType;
087: this .sessionConfigType = sessionConfigType;
088:
089: Set<Class<? extends Object>> newEnvelopeTypes = new IdentityHashSet<Class<? extends Object>>();
090: for (Class<? extends Object> c : envelopeTypes) {
091: newEnvelopeTypes.add(c);
092: }
093: this .envelopeTypes = Collections
094: .unmodifiableSet(newEnvelopeTypes);
095: }
096:
097: public Class<? extends SocketAddress> getAddressType() {
098: return addressType;
099: }
100:
101: public Set<Class<? extends Object>> getEnvelopeTypes() {
102: return envelopeTypes;
103: }
104:
105: public Class<? extends IoSessionConfig> getSessionConfigType() {
106: return sessionConfigType;
107: }
108:
109: public String getProviderName() {
110: return providerName;
111: }
112:
113: public String getName() {
114: return name;
115: }
116:
117: public boolean isConnectionless() {
118: return connectionless;
119: }
120:
121: public boolean hasFragmentation() {
122: return fragmentation;
123: }
124:
125: @Override
126: public String toString() {
127: return name;
128: }
129: }
|