/* * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.xml.internal.ws.api; import com.sun.istack.internal.NotNull; import com.sun.istack.internal.Nullable; import com.sun.xml.internal.ws.api.message.Packet; import com.sun.xml.internal.ws.util.ReadOnlyPropertyException; import javax.xml.ws.handler.MessageContext; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.AbstractMap; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; /** * A set of "properties" that can be accessed via strongly-typed fields * as well as reflexibly through the property name. * * @author Kohsuke Kawaguchi */ @SuppressWarnings("SuspiciousMethodCalls") public abstract class PropertySet { /** * Creates a new instance of TypedMap. */ protected PropertySet() {} /** * Marks a field on {@link PropertySet} as a * property of {@link MessageContext}. * *
* To make the runtime processing easy, this annotation * must be on a public field (since the property name * can be set through {@link Map} anyway, you won't be * losing abstraction by doing so.) * *
* For similar reason, this annotation can be only placed * on a reference type, not primitive type. * * @see Packet * @author Kohsuke Kawaguchi */ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD,ElementType.METHOD}) public @interface Property { /** * Name of the property. */ String[] value(); } /** * Represents the list of strongly-typed known propertyies * (keyed by property names.) * *
* Just giving it an alias to make the use of this class more fool-proof.
*/
protected static final class PropertyMap extends HashMap
* At the end of the derivation chain this method just needs to be implemented
* as:
*
*
// * Returning a non-null name from this method allows methods like
// * {@link #get(Object)} and {@link #put(String, Object)} to work faster.
// * This is especially so with {@link DistributedPropertySet}, so implementations
// * are encouraged to set a common prefix, as much as possible.
// *
// *
// * Currently, this is used only by {@link DistributedPropertySet}.
// *
// * @return
// * Null if no such common prefix exists. Otherwise string like
// * "javax.xml.ws.http." (the dot at the last is usually preferrable,
// * so that properties like "javax.xml.ws.https.something" won't match.
// */
//protected abstract String getPropertyPrefix();
/**
* This method parses a class for fields and methods with {@link Property}.
*/
protected static PropertyMap parse(final Class clazz) {
// make all relevant fields and methods accessible.
// this allows runtime to skip the security check, so they runs faster.
return AccessController.doPrivileged(new PrivilegedAction
* This map is partially live, in the sense that values you set to it
* will be reflected to {@link PropertySet}.
*
*
* However, this map may not pick up changes made
* to {@link PropertySet} after the view is created.
*
* @return
* always non-null valid instance.
*/
public final Map
* private static final PropertyMap model;
* static {
* model = parse(MyDerivedClass.class);
* }
* protected PropertyMap getPropertyMap() {
* return model;
* }
*
*/
protected abstract PropertyMap getPropertyMap();
// maybe we can use this some time
///**
// * If all the properties defined on this {@link PropertySet} has a certain prefix
// * (such as, say, "javax.xml.ws.http."), then return it.
// *
// * Implementation Note
* This method is slow. Code inside JAX-WS should define strongly-typed
* fields in this class and access them directly, instead of using this.
*
* @throws ReadOnlyPropertyException
* if the given key is an alias of a strongly-typed field,
* and if the name object given is not assignable to the field.
*
* @see Property
*/
public Object put(String key, Object value) {
Accessor sp = getPropertyMap().get(key);
if(sp!=null) {
Object old = sp.get(this);
sp.set(this,value);
return old;
} else {
throw new IllegalArgumentException("Undefined property "+key);
}
}
/**
* Checks if this {@link PropertySet} supports a property of the given name.
*/
public boolean supports(Object key) {
return getPropertyMap().containsKey(key);
}
public Object remove(Object key) {
Accessor sp = getPropertyMap().get(key);
if(sp!=null) {
Object old = sp.get(this);
sp.set(this,null);
return old;
} else {
throw new IllegalArgumentException("Undefined property "+key);
}
}
/**
* Lazily created view of {@link Property}s that
* forms the core of {@link #createMapView()}.
*/
/*package*/ Set