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 package org.apache.servicemix.jbi.messaging;
018
019 import java.io.IOException;
020 import java.io.ObjectInput;
021
022 import javax.jbi.messaging.InOnly;
023
024 /**
025 * InOnly message exchange.
026 *
027 * @version $Revision: 564607 $
028 */
029 public class InOnlyImpl extends MessageExchangeImpl implements InOnly {
030
031 private static final long serialVersionUID = -4851111881482457905L;
032
033 private static final int[][] STATES_CONSUMER = {
034 {CAN_CONSUMER + CAN_OWNER + CAN_SET_IN_MSG + CAN_SEND + CAN_STATUS_ACTIVE, 1, -1, -1, -1 },
035 {CAN_CONSUMER, -1, -1, 2, 2 },
036 {CAN_CONSUMER + CAN_OWNER, -1, -1, -1, -1 }
037 };
038
039 private static final int[][] STATES_PROVIDER = {
040 {CAN_PROVIDER, 1, -1, -1, -1 },
041 {CAN_PROVIDER + CAN_OWNER + CAN_SEND + CAN_STATUS_DONE + CAN_STATUS_ERROR, -1, -1, 2, 2 },
042 {CAN_PROVIDER, -1, -1, -1, -1 }
043 };
044
045 public InOnlyImpl() {
046 }
047
048 public InOnlyImpl(String exchangeId) {
049 super(exchangeId, MessageExchangeSupport.IN_ONLY, STATES_CONSUMER);
050 this.mirror = new InOnlyImpl(this);
051 }
052
053 public InOnlyImpl(ExchangePacket packet) {
054 super(packet, STATES_CONSUMER);
055 this.mirror = new InOnlyImpl(this);
056 }
057
058 protected InOnlyImpl(InOnlyImpl mep) {
059 super(mep.packet, STATES_PROVIDER);
060 this.mirror = mep;
061 }
062
063 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
064 this.packet = new ExchangePacket();
065 this.packet.readExternal(in);
066 if (this.packet.in != null) {
067 this.packet.in.exchange = this;
068 }
069 if (this.packet.out != null) {
070 this.packet.out.exchange = this;
071 }
072 if (this.packet.fault != null) {
073 this.packet.fault.exchange = this;
074 }
075 this.state = in.read();
076 this.mirror = new InOnlyImpl();
077 this.mirror.mirror = this;
078 this.mirror.packet = this.packet;
079 this.mirror.state = in.read();
080 boolean provider = in.readBoolean();
081 if (provider) {
082 this.states = STATES_PROVIDER;
083 this.mirror.states = STATES_CONSUMER;
084 } else {
085 this.states = STATES_CONSUMER;
086 this.mirror.states = STATES_PROVIDER;
087 }
088 }
089
090 }