src/share/jaxws_classes/com/sun/xml/internal/ws/model/AbstractWrapperBeanGenerator.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
296 * 296 *
297 * @param exception 297 * @param exception
298 * @return list of properties in the correct order for an exception bean 298 * @return list of properties in the correct order for an exception bean
299 */ 299 */
300 public Collection<A> collectExceptionBeanMembers(C exception) { 300 public Collection<A> collectExceptionBeanMembers(C exception) {
301 return collectExceptionBeanMembers(exception, true);
302 }
303
304 /**
305 * Computes and sorts exception bean members for a given exception as per
306 * the 3.7 section of the spec. It takes all getter properties in the
307 * exception and its superclasses(except getCause, getLocalizedMessage,
308 * getStackTrace, getClass). The returned collection is sorted based
309 * on the property names.
310 *
311 * <p>
312 * But if the exception has @XmlType its values are honored. Only the
313 * propOrder properties are considered. The returned collection is sorted
314 * as per the given propOrder.
315 *
316 * @param exception
317 * @param decapitalize if true, all the property names are decapitalized
318 *
319 * @return list of properties in the correct order for an exception bean
320 */
321 public Collection<A> collectExceptionBeanMembers(C exception, boolean decapitalize ) {
301 TreeMap<String, A> fields = new TreeMap<String, A>(); 322 TreeMap<String, A> fields = new TreeMap<String, A>();
302 getExceptionProperties(exception, fields); 323 getExceptionProperties(exception, fields, decapitalize);
303 324
304 // Consider only the @XmlType(propOrder) properties 325 // Consider only the @XmlType(propOrder) properties
305 XmlType xmlType = annReader.getClassAnnotation(XmlType.class, exception, null); 326 XmlType xmlType = annReader.getClassAnnotation(XmlType.class, exception, null);
306 if (xmlType != null) { 327 if (xmlType != null) {
307 String[] propOrder = xmlType.propOrder(); 328 String[] propOrder = xmlType.propOrder();
323 344
324 return fields.values(); 345 return fields.values();
325 } 346 }
326 347
327 348
328 private void getExceptionProperties(C exception, TreeMap<String, A> fields) { 349 private void getExceptionProperties(C exception, TreeMap<String, A> fields, boolean decapitalize) {
329 C sc = nav.getSuperClass(exception); 350 C sc = nav.getSuperClass(exception);
330 if (sc != null) { 351 if (sc != null) {
331 getExceptionProperties(sc, fields); 352 getExceptionProperties(sc, fields, decapitalize);
332 } 353 }
333 Collection<? extends M> methods = nav.getDeclaredMethods(exception); 354 Collection<? extends M> methods = nav.getDeclaredMethods(exception);
334 355
335 for (M method : methods) { 356 for (M method : methods) {
336 357
353 continue; 374 continue;
354 } 375 }
355 376
356 T returnType = getSafeType(nav.getReturnType(method)); 377 T returnType = getSafeType(nav.getReturnType(method));
357 if (nav.getMethodParameters(method).length == 0) { 378 if (nav.getMethodParameters(method).length == 0) {
358 String fieldName = name.startsWith("get") 379 String fieldName = name.startsWith("get") ? name.substring(3) : name.substring(2);
359 ? StringUtils.decapitalize(name.substring(3)) 380 if (decapitalize) fieldName = StringUtils.decapitalize(fieldName);
360 : StringUtils.decapitalize(name.substring(2));
361 fields.put(fieldName, factory.createWrapperBeanMember(returnType, fieldName, Collections.<Annotation>emptyList())); 381 fields.put(fieldName, factory.createWrapperBeanMember(returnType, fieldName, Collections.<Annotation>emptyList()));
362 } 382 }
363 } 383 }
364 384
365 } 385 }

mercurial