Header.java
01 /*
02  *
03  * Licensed to the Apache Software Foundation (ASF) under one
04  * or more contributor license agreements.  See the NOTICE file
05  * distributed with this work for additional information
06  * regarding copyright ownership.  The ASF licenses this file
07  * to you under the Apache License, Version 2.0 (the
08  * "License"); you may not use this file except in compliance
09  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 package org.apache.qpid.transport;
22 
23 import org.apache.qpid.transport.network.Frame;
24 
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.LinkedHashMap;
29 import java.nio.ByteBuffer;
30 
31 
32 /**
33  * Header
34  *
35  @author Rafael H. Schloming
36  */
37 
38 public class Header {
39 
40     private final Struct[] structs;
41 
42     public Header(List<Struct> structs)
43     {
44         this(structs.toArray(new Struct[structs.size()]));
45     }
46 
47     public Header(Struct ... structs)
48     {
49         this.structs = structs;
50     }
51 
52     public Struct[] getStructs()
53     {
54         return structs;
55     }
56 
57 
58     public <T> T get(Class<T> klass)
59     {
60         for (Struct st : structs)
61         {
62             if (klass.isInstance(st))
63             {
64                 return (Tst;
65             }
66         }
67 
68         return null;
69     }
70 
71     public String toString()
72     {
73         StringBuffer str = new StringBuffer();
74         str.append(" Header(");
75         boolean first = true;
76         for (Struct s : structs)
77         {
78             if (first)
79             {
80                 first = false;
81             }
82             else
83             {
84                 str.append(", ");
85             }
86             str.append(s);
87         }
88         str.append(")");
89         return str.toString();
90     }
91 
92 }