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: */package org.apache.cxf.jaxws.interceptors;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022: import java.util.logging.Logger;
023:
024: import javax.xml.ws.Holder;
025:
026: import org.apache.cxf.interceptor.Fault;
027: import org.apache.cxf.message.Exchange;
028: import org.apache.cxf.message.Message;
029: import org.apache.cxf.message.MessageContentsList;
030: import org.apache.cxf.phase.AbstractPhaseInterceptor;
031: import org.apache.cxf.phase.Phase;
032: import org.apache.cxf.service.model.MessagePartInfo;
033: import org.apache.cxf.service.model.OperationInfo;
034:
035: public class HolderOutInterceptor extends
036: AbstractPhaseInterceptor<Message> {
037:
038: private static final Logger LOG = Logger
039: .getLogger(HolderOutInterceptor.class.getName());
040:
041: public HolderOutInterceptor() {
042: super (Phase.PRE_LOGICAL);
043: addBefore(WrapperClassOutInterceptor.class.getName());
044: }
045:
046: public void handleMessage(Message message) throws Fault {
047: MessageContentsList outObjects = MessageContentsList
048: .getContentsList(message);
049: Exchange exchange = message.getExchange();
050: OperationInfo op = exchange.get(OperationInfo.class);
051:
052: LOG.fine("op: " + op);
053: if (null != op) {
054: LOG.fine("op.hasOutput(): " + op.hasOutput());
055: if (op.hasOutput()) {
056: LOG.fine("op.getOutput().size(): "
057: + op.getOutput().size());
058: }
059: }
060:
061: if (op == null || !op.hasOutput() || op.getOutput().size() == 0) {
062: LOG.fine("Returning.");
063: return;
064: }
065:
066: if (!Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
067: List<MessagePartInfo> parts = op.getOutput()
068: .getMessageParts();
069: MessageContentsList inObjects = MessageContentsList
070: .getContentsList(exchange.getInMessage());
071: if (inObjects != null) {
072: for (int x = 0; x < inObjects.size(); x++) {
073: Object o = inObjects.get(x);
074: if (o instanceof Holder) {
075: outObjects.set(x + 1, o);
076: }
077: }
078: }
079: for (MessagePartInfo part : parts) {
080: if (part.getIndex() > 0) {
081: Holder holder = (Holder) outObjects.get(part);
082: outObjects.put(part, holder.value);
083: }
084: }
085: } else {
086: List<MessagePartInfo> parts = op.getOutput()
087: .getMessageParts();
088: List<Object> holders = new ArrayList<Object>(outObjects);
089: for (int x = 0; x < outObjects.size(); x++) {
090: Object o = outObjects.get(x);
091: if (!(o instanceof Holder)) {
092: holders.set(x, null);
093: }
094: }
095: message.put(HolderInInterceptor.CLIENT_HOLDERS, holders);
096: for (MessagePartInfo part : parts) {
097: if (part.getIndex() > 0) {
098: Holder holder = (Holder) outObjects.get(part
099: .getIndex() - 1);
100: outObjects.set(part.getIndex() - 1, holder.value);
101: }
102: }
103: }
104:
105: }
106: }
|