diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2012-05-14 23:10:20 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2012-05-14 23:10:20 +0000 |
commit | 76856048976e63df37f8a0ba2cd71a75f368d8c1 (patch) | |
tree | 689a23a2237bf0b4a0f4fd3552efa12a5ecbb762 | |
parent | fbb85197b26d8c3127373d4e593ff7f836b0a10e (diff) | |
download | qpid-python-76856048976e63df37f8a0ba2cd71a75f368d8c1.tar.gz |
QPID-3401 The address object is now immutable. All fields are marked
final and should be passed in the constructor.Introduced a new class to
hold the data given by the existing address parser. TODO The toString field needs
to be constructed. The intermediate class AddressRaw can be eliminated
with a more clever parser.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/address-refactor2@1338482 13f79535-47bb-0310-9956-ffa450edef68
4 files changed, 81 insertions, 57 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java index 8edf07d7ee..24646e94e7 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/Address.java @@ -20,44 +20,34 @@ */ package org.apache.qpid.messaging; -import static org.apache.qpid.messaging.util.PyPrint.pprint; - -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - import org.apache.qpid.messaging.address.Link; import org.apache.qpid.messaging.address.Node; import org.apache.qpid.messaging.util.AddressParser; - /** * Address * */ - public class Address { + private final String _name; + private final String _subject; + private final Node _node; + private final Link _link; + private final String _toString; - private String _name; - private String _subject; - private Map _options; - private final String _myToString; - - private Node _node; - private Link _link; - private AtomicBoolean readOnly = new AtomicBoolean(false); - - public static Address parse(String address) + public static AddressRaw parse(String address) { return new AddressParser(address).parse(); } - public Address(String name, String subject, Map options) + public Address (String name, String subject, Node node, Link link) { this._name = name; this._subject = subject; - this._options = options; - this._myToString = String.format("%s/%s; %s", pprint(_name), pprint(_subject), pprint(_options)); + this._node = node; + this._link = link; + this._toString = null; // TODO } public String getName() @@ -70,14 +60,9 @@ public class Address return _subject; } - public Map getOptions() - { - return _options; - } - public String toString() { - return _myToString; + return _toString; } public Node getNode() @@ -85,31 +70,8 @@ public class Address return _node; } - public void setNode(Node n) - { - if (readOnly.get()) - { - throw new IllegalArgumentException("Once initialized the address object is immutable"); - } - this._node = n; - } - public Link getLink() { return _link; } - - public void setLink(Link l) - { - if (readOnly.get()) - { - throw new IllegalArgumentException("Once initialized the address object is immutable"); - } - this._link = l; - } - - public void markReadOnly() - { - readOnly.set(true); - } } diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/AddressRaw.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/AddressRaw.java new file mode 100644 index 0000000000..33d450be56 --- /dev/null +++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/AddressRaw.java @@ -0,0 +1,61 @@ +/* + * + * 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. + * + */ +package org.apache.qpid.messaging; + +import static org.apache.qpid.messaging.util.PyPrint.pprint; + +import java.util.Map; + +public class AddressRaw +{ + private String _name; + private String _subject; + private Map _options; + private final String _myToString; + + public AddressRaw(String name, String subject, Map options) + { + this._name = name; + this._subject = subject; + this._options = options; + this._myToString = String.format("%s/%s; %s", pprint(_name), pprint(_subject), pprint(_options)); + } + + public String getName() + { + return _name; + } + + public String getSubject() + { + return _subject; + } + + public Map getOptions() + { + return _options; + } + + public String toString() + { + return _myToString; + } +} diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java index 29c0af6a6c..285edac629 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressHelper.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.qpid.configuration.Accessor.NestedMapAccessor; import org.apache.qpid.messaging.Address; +import org.apache.qpid.messaging.AddressRaw; import org.apache.qpid.messaging.address.NodeType; import org.apache.qpid.messaging.address.AddressException; import org.slf4j.Logger; @@ -64,14 +65,14 @@ public class AddressHelper public static final String ARGUMENTS = "arguments"; public static final String RELIABILITY = "reliability"; - private Address address; + private AddressRaw address; private NestedMapAccessor addressProps; private NestedMapAccessor nodeProps; private NestedMapAccessor linkProps; private static final Logger _logger = LoggerFactory.getLogger(AddressHelper.class); - public AddressHelper(Address address) + public AddressHelper(AddressRaw address) { this.address = address; addressProps = new NestedMapAccessor(address.getOptions()); diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java index d1e10607ac..9dad5d377d 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/AddressParser.java @@ -20,13 +20,13 @@ */ package org.apache.qpid.messaging.util; -import org.apache.qpid.messaging.Address; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.qpid.messaging.AddressRaw; + /** * AddressParser @@ -236,14 +236,14 @@ public class AddressParser extends Parser super(wlex(input)); } - public Address parse() + public AddressRaw parse() { - Address result = address(); + AddressRaw result = address(); eat(EOF); return result; } - public Address address() + public AddressRaw address() { String name = toks2str(eat_until(SLASH, SEMI, EOF)); @@ -278,7 +278,7 @@ public class AddressParser extends Parser options = null; } - return new Address(name, subject, options); + return new AddressRaw(name, subject, options); } public Map<Object,Object> map() |