public Link getLink() throws Exception
{
Link link = new Link();
link.setSubscription(new Subscription());
link.setSubscriptionQueue(new SubscriptionQueue());
if (_linkPropAccess != null)
{
link.setDurable(getBooleanProperty(_linkPropAccess,DURABLE,false));
link.setName(_linkPropAccess.getString(NAME));
String reliability = _linkPropAccess.getString(RELIABILITY);
if ( reliability != null)
{
if (reliability.equalsIgnoreCase("unreliable"))
{
link.setReliability(Reliability.UNRELIABLE);
}
else if (reliability.equalsIgnoreCase("at-least-once"))
{
link.setReliability(Reliability.AT_LEAST_ONCE);
}
else
{
throw new Exception("The reliability mode '" +
reliability + "' is not yet supported");
}
}
if (((Map) _address.getOptions().get(LINK)).get(CAPACITY) instanceof Map)
{
MapAccessor capacityProps = new MapAccessor(
(Map) ((Map) _address.getOptions().get(LINK))
.get(CAPACITY));
link
.setConsumerCapacity(capacityProps
.getInt(CAPACITY_SOURCE) == null ? 0
: capacityProps.getInt(CAPACITY_SOURCE));
link
.setProducerCapacity(capacityProps
.getInt(CAPACITY_TARGET) == null ? 0
: capacityProps.getInt(CAPACITY_TARGET));
}
else
{
int cap = _linkPropAccess.getInt(CAPACITY) == null ? 0 : _linkPropAccess
.getInt(CAPACITY);
link.setConsumerCapacity(cap);
link.setProducerCapacity(cap);
}
link.setFilter(_linkPropAccess.getString(FILTER));
// so far filter type not used
Map linkMap = (Map) _address.getOptions().get(LINK);
if (linkMap != null && linkMap.containsKey(X_SUBSCRIBE))
{
Map x_subscribe = (Map)((Map) _address.getOptions().get(LINK)).get(X_SUBSCRIBE);
if (x_subscribe.containsKey(ARGUMENTS))
{
link.getSubscription().setArgs((Map<String,Object>)x_subscribe.get(ARGUMENTS));
}
boolean exclusive = x_subscribe.containsKey(EXCLUSIVE) ?
Boolean.parseBoolean((String)x_subscribe.get(EXCLUSIVE)): false;
link.getSubscription().setExclusive(exclusive);
}
link.setBindings(getBindings(linkMap));
Map xDeclareMap = getDeclareArgs(linkMap);
SubscriptionQueue queue = link.getSubscriptionQueue();
if (!xDeclareMap.isEmpty() && xDeclareMap.containsKey(ARGUMENTS))
{
MapAccessor xDeclareMapAccessor = new MapAccessor(xDeclareMap);
queue.setAutoDelete(getBooleanProperty(xDeclareMapAccessor,AUTO_DELETE,true));
queue.setAutoDelete(getBooleanProperty(xDeclareMapAccessor,EXCLUSIVE,true));
queue.setAlternateExchange(xDeclareMapAccessor.getString(ALT_EXCHANGE));
queue.setDeclareArgs((Map<String,Object>)xDeclareMap.get(ARGUMENTS));
}
}
return link;
}