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    
018    package org.apache.activemq.openwire.v3;
019    
020    import java.io.DataInput;
021    import java.io.DataOutput;
022    import java.io.IOException;
023    
024    import org.apache.activemq.command.DataStructure;
025    import org.apache.activemq.command.ProducerInfo;
026    import org.apache.activemq.openwire.BooleanStream;
027    import org.apache.activemq.openwire.OpenWireFormat;
028    
029    /**
030     * Marshalling code for Open Wire Format for ProducerInfoMarshaller
031     * 
032     * 
033     * NOTE!: This file is auto generated - do not modify! if you need to make a
034     * change, please see the modify the groovy scripts in the under src/gram/script
035     * and then use maven openwire:generate to regenerate this file.
036     * 
037     * 
038     */
039    public class ProducerInfoMarshaller extends BaseCommandMarshaller {
040    
041        /**
042         * Return the type of Data Structure we marshal
043         * 
044         * @return short representation of the type data structure
045         */
046        public byte getDataStructureType() {
047            return ProducerInfo.DATA_STRUCTURE_TYPE;
048        }
049    
050        /**
051         * @return a new object instance
052         */
053        public DataStructure createObject() {
054            return new ProducerInfo();
055        }
056    
057        /**
058         * Un-marshal an object instance from the data input stream
059         * 
060         * @param o the object to un-marshal
061         * @param dataIn the data input stream to build the object from
062         * @throws IOException
063         */
064        public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs)
065            throws IOException {
066            super.tightUnmarshal(wireFormat, o, dataIn, bs);
067    
068            ProducerInfo info = (ProducerInfo)o;
069            info.setProducerId((org.apache.activemq.command.ProducerId)tightUnmarsalCachedObject(wireFormat,
070                                                                                                 dataIn, bs));
071            info
072                .setDestination((org.apache.activemq.command.ActiveMQDestination)tightUnmarsalCachedObject(
073                                                                                                           wireFormat,
074                                                                                                           dataIn,
075                                                                                                           bs));
076    
077            if (bs.readBoolean()) {
078                short size = dataIn.readShort();
079                org.apache.activemq.command.BrokerId value[] = new org.apache.activemq.command.BrokerId[size];
080                for (int i = 0; i < size; i++) {
081                    value[i] = (org.apache.activemq.command.BrokerId)tightUnmarsalNestedObject(wireFormat,
082                                                                                               dataIn, bs);
083                }
084                info.setBrokerPath(value);
085            } else {
086                info.setBrokerPath(null);
087            }
088            info.setDispatchAsync(bs.readBoolean());
089            info.setWindowSize(dataIn.readInt());
090    
091        }
092    
093        /**
094         * Write the booleans that this object uses to a BooleanStream
095         */
096        public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException {
097    
098            ProducerInfo info = (ProducerInfo)o;
099    
100            int rc = super.tightMarshal1(wireFormat, o, bs);
101            rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getProducerId(), bs);
102            rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getDestination(), bs);
103            rc += tightMarshalObjectArray1(wireFormat, info.getBrokerPath(), bs);
104            bs.writeBoolean(info.isDispatchAsync());
105    
106            return rc + 4;
107        }
108    
109        /**
110         * Write a object instance to data output stream
111         * 
112         * @param o the instance to be marshaled
113         * @param dataOut the output stream
114         * @throws IOException thrown if an error occurs
115         */
116        public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs)
117            throws IOException {
118            super.tightMarshal2(wireFormat, o, dataOut, bs);
119    
120            ProducerInfo info = (ProducerInfo)o;
121            tightMarshalCachedObject2(wireFormat, (DataStructure)info.getProducerId(), dataOut, bs);
122            tightMarshalCachedObject2(wireFormat, (DataStructure)info.getDestination(), dataOut, bs);
123            tightMarshalObjectArray2(wireFormat, info.getBrokerPath(), dataOut, bs);
124            bs.readBoolean();
125            dataOut.writeInt(info.getWindowSize());
126    
127        }
128    
129        /**
130         * Un-marshal an object instance from the data input stream
131         * 
132         * @param o the object to un-marshal
133         * @param dataIn the data input stream to build the object from
134         * @throws IOException
135         */
136        public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException {
137            super.looseUnmarshal(wireFormat, o, dataIn);
138    
139            ProducerInfo info = (ProducerInfo)o;
140            info.setProducerId((org.apache.activemq.command.ProducerId)looseUnmarsalCachedObject(wireFormat,
141                                                                                                 dataIn));
142            info
143                .setDestination((org.apache.activemq.command.ActiveMQDestination)looseUnmarsalCachedObject(
144                                                                                                           wireFormat,
145                                                                                                           dataIn));
146    
147            if (dataIn.readBoolean()) {
148                short size = dataIn.readShort();
149                org.apache.activemq.command.BrokerId value[] = new org.apache.activemq.command.BrokerId[size];
150                for (int i = 0; i < size; i++) {
151                    value[i] = (org.apache.activemq.command.BrokerId)looseUnmarsalNestedObject(wireFormat, dataIn);
152                }
153                info.setBrokerPath(value);
154            } else {
155                info.setBrokerPath(null);
156            }
157            info.setDispatchAsync(dataIn.readBoolean());
158            info.setWindowSize(dataIn.readInt());
159    
160        }
161    
162        /**
163         * Write the booleans that this object uses to a BooleanStream
164         */
165        public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException {
166    
167            ProducerInfo info = (ProducerInfo)o;
168    
169            super.looseMarshal(wireFormat, o, dataOut);
170            looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut);
171            looseMarshalCachedObject(wireFormat, (DataStructure)info.getDestination(), dataOut);
172            looseMarshalObjectArray(wireFormat, info.getBrokerPath(), dataOut);
173            dataOut.writeBoolean(info.isDispatchAsync());
174            dataOut.writeInt(info.getWindowSize());
175    
176        }
177    }