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 */
25
26package com.oracle.webservices.internal.api.message;
27
28import java.lang.annotation.ElementType;
29import java.lang.annotation.Inherited;
30import java.lang.annotation.Retention;
31import java.lang.annotation.RetentionPolicy;
32import java.lang.annotation.Target;
33import java.util.Map;
34
35import javax.xml.ws.handler.MessageContext;
36
37/**
38 * A set of "properties" that can be accessed via strongly-typed fields
39 * as well as reflexibly through the property name.
40 *
41 * @author Kohsuke Kawaguchi
42 */
43public interface PropertySet {
44
45    /**
46     * Marks a field on {@link PropertySet} as a
47     * property of {@link MessageContext}.
48     *
49     * <p>
50     * To make the runtime processing easy, this annotation
51     * must be on a public field (since the property name
52     * can be set through {@link Map} anyway, you won't be
53     * losing abstraction by doing so.)
54     *
55     * <p>
56     * For similar reason, this annotation can be only placed
57     * on a reference type, not primitive type.
58     *
59     * @author Kohsuke Kawaguchi
60     */
61    @Inherited
62    @Retention(RetentionPolicy.RUNTIME)
63    @Target({ElementType.FIELD,ElementType.METHOD})
64    public @interface Property {
65        /**
66         * Name of the property.
67         */
68        String[] value();
69    }
70
71    public boolean containsKey(Object key);
72
73    /**
74     * Gets the name of the property.
75     *
76     * @param key
77     *      This field is typed as {@link Object} to follow the {@link Map#get(Object)}
78     *      convention, but if anything but {@link String} is passed, this method
79     *      just returns null.
80     */
81    public Object get(Object key);
82
83    /**
84     * Sets a property.
85     *
86     * <h3>Implementation Note</h3>
87     * This method is slow. Code inside JAX-WS should define strongly-typed
88     * fields in this class and access them directly, instead of using this.
89     *
90     * @see Property
91     */
92    public Object put(String key, Object value);
93
94    /**
95     * Checks if this {@link PropertySet} supports a property of the given name.
96     */
97    public boolean supports(Object key);
98
99    public Object remove(Object key);
100
101    /**
102     * Creates a {@link Map} view of this {@link PropertySet}.
103     *
104     * <p>
105     * This map is partially live, in the sense that values you set to it
106     * will be reflected to {@link PropertySet}.
107     *
108     * <p>
109     * However, this map may not pick up changes made
110     * to {@link PropertySet} after the view is created.
111     *
112     * @deprecated use newer implementation {@link com.sun.xml.internal.ws.api.PropertySet#asMap()} which produces
113     * readwrite {@link Map}
114     *
115     * @return
116     *      always non-null valid instance.
117     */
118    @Deprecated
119    public Map<String,Object> createMapView();
120
121    /**
122     * Creates a modifiable {@link Map} view of this {@link PropertySet}.
123     * <p/>
124     * Changes done on this {@link Map} or on {@link PropertySet} object work in both directions - values made to
125     * {@link Map} are reflected to {@link PropertySet} and changes done using getters/setters on {@link PropertySet}
126     * object are automatically reflected in this {@link Map}.
127     * <p/>
128     * If necessary, it also can hold other values (not present on {@link PropertySet}) -
129     * {@see PropertySet#mapAllowsAdditionalProperties}
130     *
131     * @return always non-null valid instance.
132     */
133    public Map<String, Object> asMap();
134}
135