1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.jboss.managed.util;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.modeshape.common.text.Inflector;
30 import org.modeshape.common.util.CheckArg;
31 import org.modeshape.common.util.Logger;
32 import org.modeshape.common.util.Reflection;
33 import org.modeshape.common.util.Reflection.Property;
34 import org.modeshape.jboss.managed.JBossManagedI18n;
35 import org.modeshape.jboss.managed.ManagedEngine.Component;
36 import org.modeshape.jboss.managed.ManagedEngine.ManagedProperty;
37
38
39
40
41 public class ManagedUtils {
42
43 private static final Logger LOGGER = Logger.getLogger(ManagedUtils.class);
44
45 public static List<ManagedProperty> getProperties( Component objectType,
46 Object object ) {
47 Reflection reflection = new Reflection(object.getClass());
48 List<ManagedProperty> managedProps = new ArrayList<ManagedProperty>();
49 List<Property> props = new ArrayList<Property>();
50 boolean allInferred = true;
51 try {
52 props = reflection.getAllPropertiesOn(object);
53 for (Property prop : props) {
54 if (prop.isInferred()) continue;
55 allInferred = false;
56 if (prop.isPrimitive() || prop.getType().toString().contains("java.lang.String")){
57 String valueAsString = reflection.getPropertyAsString(object, prop);
58 managedProps.add(new ManagedProperty(prop, valueAsString));
59 }
60 }
61
62
63 if (allInferred){
64 for (Property prop : props) {
65 if (prop.isPrimitive() || prop.getType().toString().contains("java.lang.String")){
66 String valueAsString = reflection.getPropertyAsString(object, prop);
67 managedProps.add(new ManagedProperty(prop, valueAsString));
68 }
69 }
70 }
71
72 } catch (Throwable e) {
73 LOGGER.error(e, JBossManagedI18n.errorGettingPropertiesFromManagedObject, objectType);
74 }
75
76 return managedProps;
77 }
78
79
80
81
82
83
84
85
86 public static String createLabel( String name ) {
87
88 CheckArg.isNotNull(name, "name");
89 name = name.replaceFirst("option.", "");
90 name = name.replaceFirst("custom.", "");
91 name = name.replace(".", " ");
92 String label = null;
93 Inflector inflector = Inflector.getInstance();
94
95 if (name != null) {
96 label = inflector.titleCase(inflector.humanize(name));
97 label = label.replaceFirst("Jcr", "JCR");
98 }
99 return label;
100 }
101
102 }