/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ #include #include #include #include #include #include "qpid/messaging/Address.h" #include "Address.h" #include "QpidMarshal.h" #include "QpidTypeCheck.h" #include "TypeTranslator.h" #include "QpidException.h" namespace Org { namespace Apache { namespace Qpid { namespace Messaging { /// /// Address is a managed wrapper for a qpid::messaging::Address /// // Create empty Address::Address() { System::Exception ^ newException = nullptr; try { addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative("")); } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } } // Create string address Address::Address(System::String ^ address) { System::Exception ^ newException = nullptr; try { addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative(address)); } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } } // Create with options Address::Address(System::String ^ name, System::String ^ subject, System::Collections::Generic::Dictionary< System::String ^, System::Object ^> ^ options) { System::Exception ^ newException = nullptr; try { addressp = new ::qpid::messaging::Address(); Name = name; Subject = subject; Options = options; Type = ""; } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } } // Create with options and type Address::Address(System::String ^ name, System::String ^ subject, System::Collections::Generic::Dictionary< System::String ^, System::Object ^> ^ options, System::String ^ type) { System::Exception ^ newException = nullptr; try { addressp = new ::qpid::messaging::Address(); Name = name; Subject = subject; Options = options; Type = type; } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } } // Copy constructor look-alike (C#) Address::Address(const Address ^ address) { System::Exception ^ newException = nullptr; try { addressp = new ::qpid::messaging::Address( *(const_cast
(address)->NativeAddress)); } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } } // Copy constructor implicitly dereferenced (C++) Address::Address(const Address % address) { System::Exception ^ newException = nullptr; try { addressp = new ::qpid::messaging::Address( *(const_cast
(address).NativeAddress)); } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } } // unmanaged clone Address::Address(const ::qpid::messaging::Address & addrp) { System::Exception ^ newException = nullptr; try { addressp = new ::qpid::messaging::Address(addrp); } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } } // Destructor Address::~Address() { this->!Address(); } // Finalizer Address::!Address() { msclr::lock lk(this); if (NULL != addressp) { delete addressp; addressp = NULL; } } // // ToString // System::String ^ Address::ToStr() { System::String ^ result = nullptr; System::Exception ^ newException = nullptr; try { result = gcnew System::String(addressp->str().c_str()); } catch (const ::qpid::types::Exception & error) { String ^ errmsg = gcnew String(error.what()); newException = gcnew QpidException(errmsg); } if (newException != nullptr) { throw newException; } return result; } }}}}