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 */ 020package org.apache.mina.core.service; 021 022import java.net.SocketAddress; 023import java.util.Collections; 024import java.util.Set; 025 026import org.apache.mina.core.session.IoSessionConfig; 027import org.apache.mina.util.IdentityHashSet; 028 029/** 030 * A default immutable implementation of {@link TransportMetadata}. 031 * 032 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 033 */ 034public class DefaultTransportMetadata implements TransportMetadata { 035 036 private final String providerName; 037 038 private final String name; 039 040 private final boolean connectionless; 041 042 private final boolean fragmentation; 043 044 private final Class<? extends SocketAddress> addressType; 045 046 private final Class<? extends IoSessionConfig> sessionConfigType; 047 048 private final Set<Class<? extends Object>> envelopeTypes; 049 050 public DefaultTransportMetadata(String providerName, String name, boolean connectionless, boolean fragmentation, 051 Class<? extends SocketAddress> addressType, Class<? extends IoSessionConfig> sessionConfigType, 052 Class<?>... envelopeTypes) { 053 054 if (providerName == null) { 055 throw new IllegalArgumentException("providerName"); 056 } 057 if (name == null) { 058 throw new IllegalArgumentException("name"); 059 } 060 061 providerName = providerName.trim().toLowerCase(); 062 if (providerName.length() == 0) { 063 throw new IllegalArgumentException("providerName is empty."); 064 } 065 name = name.trim().toLowerCase(); 066 if (name.length() == 0) { 067 throw new IllegalArgumentException("name is empty."); 068 } 069 070 if (addressType == null) { 071 throw new IllegalArgumentException("addressType"); 072 } 073 074 if (envelopeTypes == null) { 075 throw new IllegalArgumentException("envelopeTypes"); 076 } 077 078 if (envelopeTypes.length == 0) { 079 throw new IllegalArgumentException("envelopeTypes is empty."); 080 } 081 082 if (sessionConfigType == null) { 083 throw new IllegalArgumentException("sessionConfigType"); 084 } 085 086 this.providerName = providerName; 087 this.name = name; 088 this.connectionless = connectionless; 089 this.fragmentation = fragmentation; 090 this.addressType = addressType; 091 this.sessionConfigType = sessionConfigType; 092 093 Set<Class<? extends Object>> newEnvelopeTypes = new IdentityHashSet<Class<? extends Object>>(); 094 for (Class<? extends Object> c : envelopeTypes) { 095 newEnvelopeTypes.add(c); 096 } 097 this.envelopeTypes = Collections.unmodifiableSet(newEnvelopeTypes); 098 } 099 100 public Class<? extends SocketAddress> getAddressType() { 101 return addressType; 102 } 103 104 public Set<Class<? extends Object>> getEnvelopeTypes() { 105 return envelopeTypes; 106 } 107 108 public Class<? extends IoSessionConfig> getSessionConfigType() { 109 return sessionConfigType; 110 } 111 112 public String getProviderName() { 113 return providerName; 114 } 115 116 public String getName() { 117 return name; 118 } 119 120 public boolean isConnectionless() { 121 return connectionless; 122 } 123 124 public boolean hasFragmentation() { 125 return fragmentation; 126 } 127 128 @Override 129 public String toString() { 130 return name; 131 } 132}