PropertySet.java revision 524:dcaa586ab756
12116Sjkh/*
22116Sjkh * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
32116Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42116Sjkh *
52116Sjkh * This code is free software; you can redistribute it and/or modify it
62116Sjkh * under the terms of the GNU General Public License version 2 only, as
72116Sjkh * published by the Free Software Foundation.  Oracle designates this
82116Sjkh * particular file as subject to the "Classpath" exception as provided
92116Sjkh * by Oracle in the LICENSE file that accompanied this code.
102116Sjkh *
118870Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
122116Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
132116Sjkh * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
142116Sjkh * version 2 for more details (a copy is included in the LICENSE file that
152116Sjkh * accompanied this code).
16176451Sdas *
17176451Sdas * You should have received a copy of the GNU General Public License version
182116Sjkh * 2 along with this work; if not, write to the Free Software Foundation,
192116Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
202116Sjkh *
212116Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
222116Sjkh * or visit www.oracle.com if you need additional information or have any
2397413Salfred * questions.
2497413Salfred */
252116Sjkh
2697413Salfredpackage com.sun.xml.internal.ws.api;
2797413Salfred
282116Sjkhimport java.util.Map;
292116Sjkhimport java.util.Set;
302116Sjkhimport java.util.Map.Entry;
312116Sjkh
322116Sjkh/**
33121590Sdas * Placeholder for backwards compatibility.
342116Sjkh *
352116Sjkh * @deprecated Use com.oracle.webservices.internal.api.message.PropertySet instead.
362116Sjkh * @author snajper
372116Sjkh */
382116Sjkhpublic abstract class PropertySet extends com.oracle.webservices.internal.api.message.BasePropertySet {
392116Sjkh    /**
402116Sjkh     * Represents the list of strongly-typed known properties
412116Sjkh     * (keyed by property names.)
422116Sjkh     *
432116Sjkh     * <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 {}
48
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    }
58
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    }
73
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    }
97
98    public boolean supports(Object key) {
99        return getPropertyMap().containsKey(key);
100    }
101
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    }
112
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                }
119
120                public Object getValue() {
121                    return e.getValue().get(PropertySet.this);
122                }
123
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    }
133
134    protected abstract PropertyMap getPropertyMap();
135}
136