Skip to content

Commit

Permalink
CXF-8701: eliminate use of java.beans.Introspector, reduce footprint …
Browse files Browse the repository at this point in the history
…dependency on `java.desktop`

Signed-off-by: Raymond Augé <[email protected]>
  • Loading branch information
rotty3000 committed May 7, 2022
1 parent 3dad415 commit 97819b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import org.w3c.dom.Document;

import org.apache.cxf.common.util.ClassHelper;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.common.xmlschema.SchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaElement;
Expand Down Expand Up @@ -135,7 +136,7 @@ public Object getBeanInfo(Class<?> cls) {
String name = xre == null ? "##default" : xre.name();
String namespace = xre == null ? "##default" : xre.namespace();
if ("##default".equals(name)) {
name = java.beans.Introspector.decapitalize(cls.getSimpleName());
name = ClassHelper.decapitalizedSimpleName(cls);
}
if ("##default".equals(namespace) && cls.getPackage() != null) {
XmlSchema sc = cls.getPackage().getAnnotation(XmlSchema.class);
Expand Down Expand Up @@ -199,7 +200,7 @@ private QName getTypeQName(Class<?> cls, String namespace) {
String tn = xtype == null ? "##default" : xtype.name();
String tns = xtype == null ? "##default" : xtype.namespace();
if ("##default".equals(tn)) {
tn = java.beans.Introspector.decapitalize(cls.getSimpleName());
tn = ClassHelper.decapitalizedSimpleName(cls);
}
if ("##default".equals(tns) || StringUtils.isEmpty(tns)) {
tns = JAXBUtils.getPackageNamespace(cls);
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/org/apache/cxf/common/util/ClassHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ private Object getRealObjectInternal(Object o) {
return o instanceof Proxy ? Proxy.getInvocationHandler(o) : o;
}

public static String decapitalizedSimpleName(Class<?> clazz) {
if (clazz == null) {
return null;
}
String name = clazz.getSimpleName();
if (name == null || name.isEmpty()) {
return name;
}
if (name.length() > 1 && Character.isUpperCase(name.charAt(1))
&& Character.isUpperCase(name.charAt(0))) {
return name;
}
char[] chars = name.toCharArray();
chars[0] = Character.toLowerCase(chars[0]);
return new String(chars);
}

public static Class<?> getRealClass(Object o) {
return getRealClass(null, o);
}
Expand Down

0 comments on commit 97819b5

Please sign in to comment.