1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/PropertySet.java Thu Apr 04 19:05:24 2013 -0700 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/PropertySet.java Tue Apr 09 14:51:13 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,256 +25,35 @@ 1.11 1.12 package com.sun.xml.internal.ws.api; 1.13 1.14 -import com.sun.istack.internal.NotNull; 1.15 -import com.sun.istack.internal.Nullable; 1.16 -import com.sun.xml.internal.ws.util.ReadOnlyPropertyException; 1.17 - 1.18 -import java.lang.reflect.Field; 1.19 -import java.lang.reflect.InvocationTargetException; 1.20 -import java.lang.reflect.Method; 1.21 -import java.security.AccessController; 1.22 -import java.security.PrivilegedAction; 1.23 -import java.util.AbstractMap; 1.24 -import java.util.HashMap; 1.25 -import java.util.HashSet; 1.26 import java.util.Map; 1.27 +import java.util.Set; 1.28 import java.util.Map.Entry; 1.29 -import java.util.Set; 1.30 1.31 /** 1.32 - * A set of "properties" that can be accessed via strongly-typed fields 1.33 - * as well as reflexibly through the property name. 1.34 + * Placeholder for backwards compatibility. 1.35 * 1.36 - * @author Kohsuke Kawaguchi 1.37 + * @deprecated Use com.oracle.webservices.internal.api.message.PropertySet instead. 1.38 + * @author snajper 1.39 */ 1.40 -@SuppressWarnings("SuspiciousMethodCalls") 1.41 -public abstract class PropertySet implements com.sun.xml.internal.org.jvnet.ws.message.PropertySet { 1.42 - 1.43 +public abstract class PropertySet extends com.oracle.webservices.internal.api.message.BasePropertySet { 1.44 /** 1.45 - * Creates a new instance of TypedMap. 1.46 - */ 1.47 - protected PropertySet() {} 1.48 - 1.49 - /** 1.50 - * Represents the list of strongly-typed known propertyies 1.51 + * Represents the list of strongly-typed known properties 1.52 * (keyed by property names.) 1.53 * 1.54 * <p> 1.55 * Just giving it an alias to make the use of this class more fool-proof. 1.56 + * @deprecated 1.57 */ 1.58 - protected static final class PropertyMap extends HashMap<String,Accessor> {} 1.59 + protected static class PropertyMap extends com.oracle.webservices.internal.api.message.BasePropertySet.PropertyMap {} 1.60 1.61 /** 1.62 - * Map representing the Fields and Methods annotated with {@link Property}. 1.63 - * Model of {@link PropertySet} class. 1.64 - * 1.65 - * <p> 1.66 - * At the end of the derivation chain this method just needs to be implemented 1.67 - * as: 1.68 - * 1.69 - * <pre> 1.70 - * private static final PropertyMap model; 1.71 - * static { 1.72 - * model = parse(MyDerivedClass.class); 1.73 - * } 1.74 - * protected PropertyMap getPropertyMap() { 1.75 - * return model; 1.76 - * } 1.77 - * </pre> 1.78 - */ 1.79 - protected abstract PropertyMap getPropertyMap(); 1.80 - 1.81 - // maybe we can use this some time 1.82 - ///** 1.83 - // * If all the properties defined on this {@link PropertySet} has a certain prefix 1.84 - // * (such as, say, "javax.xml.ws.http."), then return it. 1.85 - // * 1.86 - // * <p> 1.87 - // * Returning a non-null name from this method allows methods like 1.88 - // * {@link #get(Object)} and {@link #put(String, Object)} to work faster. 1.89 - // * This is especially so with {@link DistributedPropertySet}, so implementations 1.90 - // * are encouraged to set a common prefix, as much as possible. 1.91 - // * 1.92 - // * <p> 1.93 - // * Currently, this is used only by {@link DistributedPropertySet}. 1.94 - // * 1.95 - // * @return 1.96 - // * Null if no such common prefix exists. Otherwise string like 1.97 - // * "javax.xml.ws.http." (the dot at the last is usually preferrable, 1.98 - // * so that properties like "javax.xml.ws.https.something" won't match. 1.99 - // */ 1.100 - //protected abstract String getPropertyPrefix(); 1.101 - 1.102 - /** 1.103 - * This method parses a class for fields and methods with {@link Property}. 1.104 + * @deprecated 1.105 */ 1.106 protected static PropertyMap parse(final Class clazz) { 1.107 - // make all relevant fields and methods accessible. 1.108 - // this allows runtime to skip the security check, so they runs faster. 1.109 - return AccessController.doPrivileged(new PrivilegedAction<PropertyMap>() { 1.110 - public PropertyMap run() { 1.111 - PropertyMap props = new PropertyMap(); 1.112 - for( Class c=clazz; c!=null; c=c.getSuperclass()) { 1.113 - for (Field f : c.getDeclaredFields()) { 1.114 - Property cp = f.getAnnotation(Property.class); 1.115 - if(cp!=null) { 1.116 - for(String value : cp.value()) { 1.117 - props.put(value, new FieldAccessor(f, value)); 1.118 - } 1.119 - } 1.120 - } 1.121 - for (Method m : c.getDeclaredMethods()) { 1.122 - Property cp = m.getAnnotation(Property.class); 1.123 - if(cp!=null) { 1.124 - String name = m.getName(); 1.125 - assert name.startsWith("get") || name.startsWith("is"); 1.126 - 1.127 - String setName = name.startsWith("is") ? "set"+name.substring(3) : // isFoo -> setFoo 1.128 - 's'+name.substring(1); // getFoo -> setFoo 1.129 - Method setter; 1.130 - try { 1.131 - setter = clazz.getMethod(setName,m.getReturnType()); 1.132 - } catch (NoSuchMethodException e) { 1.133 - setter = null; // no setter 1.134 - } 1.135 - for(String value : cp.value()) { 1.136 - props.put(value, new MethodAccessor(m, setter, value)); 1.137 - } 1.138 - } 1.139 - } 1.140 - } 1.141 - 1.142 - return props; 1.143 - } 1.144 - }); 1.145 - } 1.146 - 1.147 - /** 1.148 - * Represents a typed property defined on a {@link PropertySet}. 1.149 - */ 1.150 - protected interface Accessor { 1.151 - String getName(); 1.152 - boolean hasValue(PropertySet props); 1.153 - Object get(PropertySet props); 1.154 - void set(PropertySet props, Object value); 1.155 - } 1.156 - 1.157 - static final class FieldAccessor implements Accessor { 1.158 - /** 1.159 - * Field with the annotation. 1.160 - */ 1.161 - private final Field f; 1.162 - 1.163 - /** 1.164 - * One of the values in {@link Property} annotation on {@link #f}. 1.165 - */ 1.166 - private final String name; 1.167 - 1.168 - protected FieldAccessor(Field f, String name) { 1.169 - this.f = f; 1.170 - f.setAccessible(true); 1.171 - this.name = name; 1.172 - } 1.173 - 1.174 - public String getName() { 1.175 - return name; 1.176 - } 1.177 - 1.178 - public boolean hasValue(PropertySet props) { 1.179 - return get(props)!=null; 1.180 - } 1.181 - 1.182 - public Object get(PropertySet props) { 1.183 - try { 1.184 - return f.get(props); 1.185 - } catch (IllegalAccessException e) { 1.186 - throw new AssertionError(); 1.187 - } 1.188 - } 1.189 - 1.190 - public void set(PropertySet props, Object value) { 1.191 - try { 1.192 - f.set(props,value); 1.193 - } catch (IllegalAccessException e) { 1.194 - throw new AssertionError(); 1.195 - } 1.196 - } 1.197 - } 1.198 - 1.199 - static final class MethodAccessor implements Accessor { 1.200 - /** 1.201 - * Getter method. 1.202 - */ 1.203 - private final @NotNull Method getter; 1.204 - /** 1.205 - * Setter method. 1.206 - * Some property is read-only. 1.207 - */ 1.208 - private final @Nullable Method setter; 1.209 - 1.210 - /** 1.211 - * One of the values in {@link Property} annotation on {@link #getter}. 1.212 - */ 1.213 - private final String name; 1.214 - 1.215 - protected MethodAccessor(Method getter, Method setter, String value) { 1.216 - this.getter = getter; 1.217 - this.setter = setter; 1.218 - this.name = value; 1.219 - getter.setAccessible(true); 1.220 - if(setter!=null) 1.221 - setter.setAccessible(true); 1.222 - } 1.223 - 1.224 - public String getName() { 1.225 - return name; 1.226 - } 1.227 - 1.228 - public boolean hasValue(PropertySet props) { 1.229 - return get(props)!=null; 1.230 - } 1.231 - 1.232 - public Object get(PropertySet props) { 1.233 - try { 1.234 - return getter.invoke(props); 1.235 - } catch (IllegalAccessException e) { 1.236 - throw new AssertionError(); 1.237 - } catch (InvocationTargetException e) { 1.238 - handle(e); 1.239 - return 0; // never reach here 1.240 - } 1.241 - } 1.242 - 1.243 - public void set(PropertySet props, Object value) { 1.244 - if(setter==null) 1.245 - throw new ReadOnlyPropertyException(getName()); 1.246 - try { 1.247 - setter.invoke(props,value); 1.248 - } catch (IllegalAccessException e) { 1.249 - throw new AssertionError(); 1.250 - } catch (InvocationTargetException e) { 1.251 - handle(e); 1.252 - } 1.253 - } 1.254 - 1.255 - /** 1.256 - * Since we don't expect the getter/setter to throw a checked exception, 1.257 - * it should be possible to make the exception propagation transparent. 1.258 - * That's what we are trying to do here. 1.259 - */ 1.260 - private Exception handle(InvocationTargetException e) { 1.261 - Throwable t = e.getTargetException(); 1.262 - if(t instanceof Error) 1.263 - throw (Error)t; 1.264 - if(t instanceof RuntimeException) 1.265 - throw (RuntimeException)t; 1.266 - throw new Error(e); 1.267 - } 1.268 - } 1.269 - 1.270 - 1.271 - public final boolean containsKey(Object key) { 1.272 - return get(key)!=null; 1.273 + com.oracle.webservices.internal.api.message.BasePropertySet.PropertyMap pm = com.oracle.webservices.internal.api.message.BasePropertySet.parse(clazz); 1.274 + PropertyMap map = new PropertyMap(); 1.275 + map.putAll(pm); 1.276 + return map; 1.277 } 1.278 1.279 /** 1.280 @@ -316,9 +95,6 @@ 1.281 } 1.282 } 1.283 1.284 - /** 1.285 - * Checks if this {@link PropertySet} supports a property of the given name. 1.286 - */ 1.287 public boolean supports(Object key) { 1.288 return getPropertyMap().containsKey(key); 1.289 } 1.290 @@ -334,39 +110,7 @@ 1.291 } 1.292 } 1.293 1.294 - 1.295 - /** 1.296 - * Lazily created view of {@link Property}s that 1.297 - * forms the core of {@link #createMapView()}. 1.298 - */ 1.299 - /*package*/ Set<Entry<String,Object>> mapViewCore; 1.300 - 1.301 - /** 1.302 - * Creates a {@link Map} view of this {@link PropertySet}. 1.303 - * 1.304 - * <p> 1.305 - * This map is partially live, in the sense that values you set to it 1.306 - * will be reflected to {@link PropertySet}. 1.307 - * 1.308 - * <p> 1.309 - * However, this map may not pick up changes made 1.310 - * to {@link PropertySet} after the view is created. 1.311 - * 1.312 - * @return 1.313 - * always non-null valid instance. 1.314 - */ 1.315 - public final Map<String,Object> createMapView() { 1.316 - final Set<Entry<String,Object>> core = new HashSet<Entry<String,Object>>(); 1.317 - createEntrySet(core); 1.318 - 1.319 - return new AbstractMap<String, Object>() { 1.320 - public Set<Entry<String,Object>> entrySet() { 1.321 - return core; 1.322 - } 1.323 - }; 1.324 - } 1.325 - 1.326 - /*package*/ void createEntrySet(Set<Entry<String,Object>> core) { 1.327 + protected void createEntrySet(Set<Entry<String,Object>> core) { 1.328 for (final Entry<String, Accessor> e : getPropertyMap().entrySet()) { 1.329 core.add(new Entry<String, Object>() { 1.330 public String getKey() { 1.331 @@ -386,4 +130,6 @@ 1.332 }); 1.333 } 1.334 } 1.335 + 1.336 + protected abstract PropertyMap getPropertyMap(); 1.337 }