summaryrefslogtreecommitdiff
path: root/qpid/java/amqp-1-0-client/src/main/java/org/apache/qpid/amqp_1_0/client/Message.java
blob: e8ac1de6c192dfdaad6c8179dd4fd36f76afc563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
package org.apache.qpid.amqp_1_0.client;

import org.apache.qpid.amqp_1_0.type.Binary;
import org.apache.qpid.amqp_1_0.type.DeliveryState;
import org.apache.qpid.amqp_1_0.type.Section;
import org.apache.qpid.amqp_1_0.type.messaging.AmqpValue;
import org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties;
import org.apache.qpid.amqp_1_0.type.messaging.Header;
import org.apache.qpid.amqp_1_0.type.messaging.Properties;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Message
{
    private Binary _deliveryTag;
    private List<Section> _payload = new ArrayList<Section>();
    private Boolean _resume;
    private boolean _settled;
    private DeliveryState _deliveryState;
    private Receiver _receiver;


    public Message()
    {
    }

    public Message(Collection<Section> sections)
    {
        _payload.addAll(sections);
    }

    public Message(Section section)
    {
        this(Collections.singletonList(section));
    }

    public Message(String message)
    {
        this(new AmqpValue(message));
    }


    public Binary getDeliveryTag()
    {
        return _deliveryTag;
    }

    public void setDeliveryTag(Binary deliveryTag)
    {
        _deliveryTag = deliveryTag;
    }

    public List<Section> getPayload()
    {
        return Collections.unmodifiableList(_payload);
    }

    private <T extends Section> T getSection(Class<T> clazz)
    {
        for(Section s : _payload)
        {
            if(clazz.isAssignableFrom(s.getClass()))
            {
                return (T) s;
            }
        }
        return null;
    }

    public ApplicationProperties getApplicationProperties()
    {
        return getSection(ApplicationProperties.class);
    }

    public Properties getProperties()
    {
        return getSection(Properties.class);
    }

    public Header getHeader()
    {
        return getSection(Header.class);
    }


    public void setResume(final Boolean resume)
    {
        _resume = resume;
    }

    public boolean isResume()
    {
        return Boolean.TRUE.equals(_resume);
    }

    public void setDeliveryState(DeliveryState state)
    {
        _deliveryState = state;
    }

    public DeliveryState getDeliveryState()
    {
        return _deliveryState;
    }

    public void setSettled(boolean settled)
    {
        _settled = settled;
    }

    public boolean getSettled()
    {
        return _settled;
    }

    public void setReceiver(final Receiver receiver)
    {
        _receiver = receiver;
    }

    public Receiver getReceiver()
    {
        return _receiver;
    }
}