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.v2;
019    
020    import java.io.DataInput;
021    import java.io.DataOutput;
022    import java.io.IOException;
023    
024    import org.apache.activemq.command.BrokerInfo;
025    import org.apache.activemq.command.DataStructure;
026    import org.apache.activemq.openwire.BooleanStream;
027    import org.apache.activemq.openwire.OpenWireFormat;
028    
029    /**
030     * Marshalling code for Open Wire Format for BrokerInfoMarshaller
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 BrokerInfoMarshaller 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 BrokerInfo.DATA_STRUCTURE_TYPE;
048        }
049    
050        /**
051         * @return a new object instance
052         */
053        public DataStructure createObject() {
054            return new BrokerInfo();
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            BrokerInfo info = (BrokerInfo)o;
069            info.setBrokerId((org.apache.activemq.command.BrokerId)tightUnmarsalCachedObject(wireFormat, dataIn,
070                                                                                             bs));
071            info.setBrokerURL(tightUnmarshalString(dataIn, bs));
072    
073            if (bs.readBoolean()) {
074                short size = dataIn.readShort();
075                org.apache.activemq.command.BrokerInfo value[] = new org.apache.activemq.command.BrokerInfo[size];
076                for (int i = 0; i < size; i++) {
077                    value[i] = (org.apache.activemq.command.BrokerInfo)tightUnmarsalNestedObject(wireFormat,
078                                                                                                 dataIn, bs);
079                }
080                info.setPeerBrokerInfos(value);
081            } else {
082                info.setPeerBrokerInfos(null);
083            }
084            info.setBrokerName(tightUnmarshalString(dataIn, bs));
085            info.setSlaveBroker(bs.readBoolean());
086            info.setMasterBroker(bs.readBoolean());
087            info.setFaultTolerantConfiguration(bs.readBoolean());
088            info.setDuplexConnection(bs.readBoolean());
089            info.setNetworkConnection(bs.readBoolean());
090            info.setConnectionId(tightUnmarshalLong(wireFormat, dataIn, bs));
091    
092        }
093    
094        /**
095         * Write the booleans that this object uses to a BooleanStream
096         */
097        public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException {
098    
099            BrokerInfo info = (BrokerInfo)o;
100    
101            int rc = super.tightMarshal1(wireFormat, o, bs);
102            rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getBrokerId(), bs);
103            rc += tightMarshalString1(info.getBrokerURL(), bs);
104            rc += tightMarshalObjectArray1(wireFormat, info.getPeerBrokerInfos(), bs);
105            rc += tightMarshalString1(info.getBrokerName(), bs);
106            bs.writeBoolean(info.isSlaveBroker());
107            bs.writeBoolean(info.isMasterBroker());
108            bs.writeBoolean(info.isFaultTolerantConfiguration());
109            bs.writeBoolean(info.isDuplexConnection());
110            bs.writeBoolean(info.isNetworkConnection());
111            rc += tightMarshalLong1(wireFormat, info.getConnectionId(), bs);
112    
113            return rc + 0;
114        }
115    
116        /**
117         * Write a object instance to data output stream
118         * 
119         * @param o the instance to be marshaled
120         * @param dataOut the output stream
121         * @throws IOException thrown if an error occurs
122         */
123        public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs)
124            throws IOException {
125            super.tightMarshal2(wireFormat, o, dataOut, bs);
126    
127            BrokerInfo info = (BrokerInfo)o;
128            tightMarshalCachedObject2(wireFormat, (DataStructure)info.getBrokerId(), dataOut, bs);
129            tightMarshalString2(info.getBrokerURL(), dataOut, bs);
130            tightMarshalObjectArray2(wireFormat, info.getPeerBrokerInfos(), dataOut, bs);
131            tightMarshalString2(info.getBrokerName(), dataOut, bs);
132            bs.readBoolean();
133            bs.readBoolean();
134            bs.readBoolean();
135            bs.readBoolean();
136            bs.readBoolean();
137            tightMarshalLong2(wireFormat, info.getConnectionId(), dataOut, bs);
138    
139        }
140    
141        /**
142         * Un-marshal an object instance from the data input stream
143         * 
144         * @param o the object to un-marshal
145         * @param dataIn the data input stream to build the object from
146         * @throws IOException
147         */
148        public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException {
149            super.looseUnmarshal(wireFormat, o, dataIn);
150    
151            BrokerInfo info = (BrokerInfo)o;
152            info.setBrokerId((org.apache.activemq.command.BrokerId)looseUnmarsalCachedObject(wireFormat, dataIn));
153            info.setBrokerURL(looseUnmarshalString(dataIn));
154    
155            if (dataIn.readBoolean()) {
156                short size = dataIn.readShort();
157                org.apache.activemq.command.BrokerInfo value[] = new org.apache.activemq.command.BrokerInfo[size];
158                for (int i = 0; i < size; i++) {
159                    value[i] = (org.apache.activemq.command.BrokerInfo)looseUnmarsalNestedObject(wireFormat,
160                                                                                                 dataIn);
161                }
162                info.setPeerBrokerInfos(value);
163            } else {
164                info.setPeerBrokerInfos(null);
165            }
166            info.setBrokerName(looseUnmarshalString(dataIn));
167            info.setSlaveBroker(dataIn.readBoolean());
168            info.setMasterBroker(dataIn.readBoolean());
169            info.setFaultTolerantConfiguration(dataIn.readBoolean());
170            info.setDuplexConnection(dataIn.readBoolean());
171            info.setNetworkConnection(dataIn.readBoolean());
172            info.setConnectionId(looseUnmarshalLong(wireFormat, dataIn));
173    
174        }
175    
176        /**
177         * Write the booleans that this object uses to a BooleanStream
178         */
179        public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException {
180    
181            BrokerInfo info = (BrokerInfo)o;
182    
183            super.looseMarshal(wireFormat, o, dataOut);
184            looseMarshalCachedObject(wireFormat, (DataStructure)info.getBrokerId(), dataOut);
185            looseMarshalString(info.getBrokerURL(), dataOut);
186            looseMarshalObjectArray(wireFormat, info.getPeerBrokerInfos(), dataOut);
187            looseMarshalString(info.getBrokerName(), dataOut);
188            dataOut.writeBoolean(info.isSlaveBroker());
189            dataOut.writeBoolean(info.isMasterBroker());
190            dataOut.writeBoolean(info.isFaultTolerantConfiguration());
191            dataOut.writeBoolean(info.isDuplexConnection());
192            dataOut.writeBoolean(info.isNetworkConnection());
193            looseMarshalLong(wireFormat, info.getConnectionId(), dataOut);
194    
195        }
196    }