001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.ietf.jgss;
019:
020: import java.net.InetAddress;
021: import java.util.Arrays;
022:
023: public class ChannelBinding {
024: //initiator address
025: private InetAddress initAddr;
026:
027: //acceptor address
028: private InetAddress acceptAddr;
029:
030: //application data
031: private byte[] appData;
032:
033: public ChannelBinding(InetAddress initAddr, InetAddress acceptAddr,
034: byte[] appData) {
035: this (appData);
036: this .initAddr = initAddr;
037: this .acceptAddr = acceptAddr;
038: }
039:
040: public ChannelBinding(byte[] appData) {
041: super ();
042: if (appData != null) {
043: this .appData = new byte[appData.length];
044: System.arraycopy(appData, 0, this .appData, 0,
045: appData.length);
046: }
047: }
048:
049: public InetAddress getInitiatorAddress() {
050: return initAddr;
051: }
052:
053: public InetAddress getAcceptorAddress() {
054: return acceptAddr;
055: }
056:
057: public byte[] getApplicationData() {
058: byte[] bytes = null;
059: if (appData != null) {
060: bytes = new byte[appData.length];
061: System.arraycopy(appData, 0, bytes, 0, appData.length);
062: }
063: return bytes;
064: }
065:
066: @Override
067: public boolean equals(Object obj) {
068: if (this == obj) {
069: return true;
070: }
071: if (!(obj instanceof ChannelBinding)) {
072: return false;
073: }
074: ChannelBinding another = (ChannelBinding) obj;
075: if (initAddr != another.initAddr
076: && (initAddr == null || !initAddr
077: .equals(another.initAddr))) {
078: return false;
079: }
080:
081: if (acceptAddr != another.acceptAddr
082: && (acceptAddr == null || !acceptAddr
083: .equals(another.acceptAddr))) {
084: return false;
085: }
086:
087: return Arrays.equals(appData, another.appData);
088: }
089:
090: @Override
091: public int hashCode() {
092: if (initAddr != null) {
093: return initAddr.hashCode();
094: }
095: if (acceptAddr != null) {
096: return acceptAddr.hashCode();
097: }
098: if (appData != null) {
099: int hashCode = 0;
100: for (byte element : appData) {
101: hashCode = 31 * hashCode + element;
102: }
103: return hashCode;
104: }
105: return 1;
106: }
107: }
|