Thu, 31 Aug 2017 15:18:52 +0800
merge
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.xml.internal.ws.api;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.Map.Entry;
32 /**
33 * Placeholder for backwards compatibility.
34 *
35 * @deprecated Use com.oracle.webservices.internal.api.message.PropertySet instead.
36 * @author snajper
37 */
38 public abstract class PropertySet extends com.oracle.webservices.internal.api.message.BasePropertySet {
39 /**
40 * Represents the list of strongly-typed known properties
41 * (keyed by property names.)
42 *
43 * <p>
44 * Just giving it an alias to make the use of this class more fool-proof.
45 * @deprecated
46 */
47 protected static class PropertyMap extends com.oracle.webservices.internal.api.message.BasePropertySet.PropertyMap {}
49 /**
50 * @deprecated
51 */
52 protected static PropertyMap parse(final Class clazz) {
53 com.oracle.webservices.internal.api.message.BasePropertySet.PropertyMap pm = com.oracle.webservices.internal.api.message.BasePropertySet.parse(clazz);
54 PropertyMap map = new PropertyMap();
55 map.putAll(pm);
56 return map;
57 }
59 /**
60 * Gets the name of the property.
61 *
62 * @param key
63 * This field is typed as {@link Object} to follow the {@link Map#get(Object)}
64 * convention, but if anything but {@link String} is passed, this method
65 * just returns null.
66 */
67 public Object get(Object key) {
68 Accessor sp = getPropertyMap().get(key);
69 if(sp!=null)
70 return sp.get(this);
71 throw new IllegalArgumentException("Undefined property "+key);
72 }
74 /**
75 * Sets a property.
76 *
77 * <h3>Implementation Note</h3>
78 * This method is slow. Code inside JAX-WS should define strongly-typed
79 * fields in this class and access them directly, instead of using this.
80 *
81 * @throws ReadOnlyPropertyException
82 * if the given key is an alias of a strongly-typed field,
83 * and if the name object given is not assignable to the field.
84 *
85 * @see Property
86 */
87 public Object put(String key, Object value) {
88 Accessor sp = getPropertyMap().get(key);
89 if(sp!=null) {
90 Object old = sp.get(this);
91 sp.set(this,value);
92 return old;
93 } else {
94 throw new IllegalArgumentException("Undefined property "+key);
95 }
96 }
98 public boolean supports(Object key) {
99 return getPropertyMap().containsKey(key);
100 }
102 public Object remove(Object key) {
103 Accessor sp = getPropertyMap().get(key);
104 if(sp!=null) {
105 Object old = sp.get(this);
106 sp.set(this,null);
107 return old;
108 } else {
109 throw new IllegalArgumentException("Undefined property "+key);
110 }
111 }
113 protected void createEntrySet(Set<Entry<String,Object>> core) {
114 for (final Entry<String, Accessor> e : getPropertyMap().entrySet()) {
115 core.add(new Entry<String, Object>() {
116 public String getKey() {
117 return e.getKey();
118 }
120 public Object getValue() {
121 return e.getValue().get(PropertySet.this);
122 }
124 public Object setValue(Object value) {
125 Accessor acc = e.getValue();
126 Object old = acc.get(PropertySet.this);
127 acc.set(PropertySet.this,value);
128 return old;
129 }
130 });
131 }
132 }
134 protected abstract PropertyMap getPropertyMap();
135 }