01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.message;
19:
20: import java.util.ArrayList;
21: import java.util.Arrays;
22: import java.util.List;
23:
24: import org.apache.cxf.helpers.CastUtils;
25: import org.apache.cxf.service.model.MessagePartInfo;
26:
27: public class MessageContentsList extends ArrayList<Object> {
28: public static final Object REMOVED_MARKER = new Object();
29:
30: public MessageContentsList() {
31: super (6);
32: }
33:
34: public MessageContentsList(Object... values) {
35: super (Arrays.asList(values));
36: }
37:
38: public MessageContentsList(List<?> values) {
39: super (values);
40: }
41:
42: public static MessageContentsList getContentsList(Message msg) {
43: List<Object> o = CastUtils.cast(msg.getContent(List.class));
44: if (o == null) {
45: return null;
46: }
47: if (!(o instanceof MessageContentsList)) {
48: MessageContentsList l2 = new MessageContentsList(o);
49: msg.setContent(List.class, l2);
50: return l2;
51: }
52: return (MessageContentsList) o;
53: }
54:
55: public Object set(int idx, Object value) {
56: ensureSize(idx);
57: return super .set(idx, value);
58: }
59:
60: private void ensureSize(int idx) {
61: while (idx >= size()) {
62: add(null);
63: }
64: }
65:
66: public Object put(MessagePartInfo key, Object value) {
67: ensureSize(key.getIndex());
68: return super .set(key.getIndex(), value);
69: }
70:
71: public boolean hasValue(MessagePartInfo key) {
72: return super .get(key.getIndex()) != REMOVED_MARKER;
73: }
74:
75: public Object get(MessagePartInfo key) {
76: Object o = super .get(key.getIndex());
77: return o == REMOVED_MARKER ? null : o;
78: }
79:
80: public void remove(MessagePartInfo key) {
81: put(key, REMOVED_MARKER);
82: }
83: }
|