01: /**
02: *
03: * Copyright 2004 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.ws.scout.registry.infomodel;
17:
18: import java.util.Collection;
19: import java.util.Collections;
20: import java.util.HashSet;
21:
22: import javax.xml.registry.JAXRException;
23: import javax.xml.registry.infomodel.Slot;
24:
25: /**
26: * Implements Jaxr API
27: *
28: * @author <mailto:anil@apache.org>Anil Saldhana
29: * @since Nov 20, 2004
30: */
31: public class SlotImpl implements Slot {
32: private String slotType;
33: private String name;
34: private Collection<String> values;
35:
36: @SuppressWarnings("unchecked")
37: public SlotImpl() {
38: values = Collections.EMPTY_SET;
39: }
40:
41: public String getName() throws JAXRException {
42: return name;
43: }
44:
45: public String getSlotType() throws JAXRException {
46: return slotType;
47: }
48:
49: public Collection<String> getValues() throws JAXRException {
50: return values;
51: }
52:
53: public void setName(String s) throws JAXRException {
54: name = s;
55: }
56:
57: public void setSlotType(String s) throws JAXRException {
58: slotType = s;
59: }
60:
61: public void setValues(Collection<String> collection)
62: throws JAXRException {
63: if (collection == null) {
64: throw new IllegalArgumentException("values cannot be null");
65: }
66: // "the value of a Slot is locally unique within a slot instance"
67: // to enforce this, convert the supplied Collection to a Set
68: values = new HashSet<String>(collection);
69: }
70:
71: /**
72: * Slots can be used in Collections but the spec does not define equals()
73: * We define two slots with the same name as being equal as the spec says
74: * name is unique within the scope of the RegistryObject.
75: */
76: public boolean equals(Object o) {
77: if (this == o)
78: return true;
79: if (!(o instanceof SlotImpl))
80: return false;
81:
82: final SlotImpl slot = (SlotImpl) o;
83:
84: if (name != null ? !name.equals(slot.name) : slot.name != null)
85: return false;
86:
87: return true;
88: }
89:
90: public int hashCode() {
91: return (name != null ? name.hashCode() : 0);
92: }
93: }
|