2
2
* Copyright (c) 2022, Oracle Corporation and/or its affiliates.
3
3
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
*/
5
-
6
5
package oracle .weblogic .deploy .util ;
7
6
8
7
import java .beans .BeanDescriptor ;
20
19
*
21
20
* Includes an undocumented main intended for ad-hoc printing of a particular bean or bean property help.
22
21
*/
23
-
24
22
public class WLSBeanHelp {
25
23
private static final String EOL = System .getProperty ("line.separator" );
26
24
@@ -42,12 +40,7 @@ private WLSBeanHelp() {}
42
40
// and margin set to "width"
43
41
// - if propDefault not null, inline it as "default=" along with
44
42
// any of the discovered prop limits...
45
- public static String get (
46
- String beanName ,
47
- String propName ,
48
- int width ,
49
- String propDefault
50
- ) {
43
+ public static String get (String beanName , String propName , int width , String propDefault ) {
51
44
String ds ;
52
45
53
46
if (propName == null )
@@ -67,76 +60,17 @@ public static String get(
67
60
return limits + prettyHTML (ds , width );
68
61
}
69
62
70
- public static String get (
71
- String beanName ,
72
- int width
73
- ) {
63
+ public static String get (String beanName , int width ) {
74
64
return get (beanName , null , width , null );
75
65
}
76
66
77
- // undocumented main to ad hoc retrieve help for a particular bean or bean prop
78
- public static void main (String [] argv ) {
79
- String beanName = "BeanNotSpecified" ;
80
- String propName = null ;
81
- int margin = 60 ;
82
-
83
- if (argv .length == 0 ) {
84
- mainHelp ();
85
- System .exit (1 );
86
- }
87
-
88
- int i = 0 ;
89
- while (i < argv .length ) {
90
- String arg = argv [i ];
91
- try {
92
- if (arg .equals ("-bean" )) {
93
- beanName = argv [i +1 ]; i ++;
94
- }
95
- else if (arg .equals ("-prop" )) {
96
- propName = argv [i +1 ]; i ++;
97
- }
98
- else if (arg .equals ("-margin" )) {
99
- margin = Integer .parseInt (argv [i +1 ]); i ++;
100
- }
101
- else {
102
- println ("Error: Unrecognized parameter '" + arg +"'." );
103
- mainHelp ();
104
- System .exit (1 );
105
- }
106
- } catch (ArrayIndexOutOfBoundsException a ) {
107
- println ("Error: Expected argument after parameter: " + arg );
108
- mainHelp ();
109
- System .exit (1 );
110
- }
111
- i ++;
112
- }
113
-
114
- if (getBeanInfo (beanName ) == null ) {
115
- println ("Error: Bean '" + beanName + "' not found." );
116
- }
117
-
118
- if (propName == null ) {
119
- println ("*** Full bean help for bean '" + beanName + "':" );
120
- println (get (beanName , null , margin , null ));
121
- println ("***" );
122
- } else {
123
- println ("*** Full property help for property '" + beanName + "/" + propName + "':" );
124
- println (get (beanName , propName , margin , null ));
125
- println ("*** Raw property help for property '" + beanName + "/" + propName + "':" );
126
- printAttributeHelp (beanName , propName , margin );
127
- println ("***" );
128
- }
129
- }
130
-
131
67
// convert basic javadoc HTML to plain text
132
68
// (package visible to enable unit testing)
133
69
static String prettyHTML (String html , int margin ) {
134
70
return new PrettyHTML (html , margin ).toString ();
135
71
}
136
72
137
- private static String getFeatureDescription (
138
- FeatureDescriptor fd
139
- ) {
73
+ private static String getFeatureDescription (FeatureDescriptor fd ) {
140
74
if (fd == null ) return "" ;
141
75
Object d = fd .getValue (PD_ATT_DESCRIPTION );
142
76
if (d == null ) return "" ; // should pretty much never happen
@@ -146,11 +80,7 @@ private static String getFeatureDescription(
146
80
// gets pretty printed default for a given bean prop, legal values, min, or max
147
81
// default is passed in from outside
148
82
// returns "" if not applicable or not found
149
- private static String getPropertyLimits (
150
- String beanName ,
151
- String propName ,
152
- String propDefault
153
- ) {
83
+ private static String getPropertyLimits (String beanName , String propName , String propDefault ) {
154
84
StringBuilder ret = new StringBuilder ();
155
85
if (propDefault != null ) {
156
86
// we report the passed in default from the alias DB instead of using the
@@ -180,10 +110,7 @@ private static String getPropertyLimits(
180
110
}
181
111
182
112
// can return null if not found
183
- private static PropertyDescriptor getPropertyDescriptor (
184
- String beanName ,
185
- String propName
186
- ) {
113
+ private static PropertyDescriptor getPropertyDescriptor (String beanName , String propName ) {
187
114
try {
188
115
BeanInfo info = getBeanInfo (beanName );
189
116
if (info == null ) return null ;
@@ -203,9 +130,7 @@ private static PropertyDescriptor getPropertyDescriptor(
203
130
}
204
131
205
132
// can return null if not found
206
- private static BeanDescriptor getBeanDescriptor (
207
- String beanName
208
- ) {
133
+ private static BeanDescriptor getBeanDescriptor (String beanName ) {
209
134
try {
210
135
BeanInfo info = getBeanInfo (beanName );
211
136
if (info == null ) return null ;
@@ -252,15 +177,11 @@ private static BeanInfo getBeanInfo(String beanName)
252
177
// use reflection to implement the equivalent of:
253
178
// weblogic management provider ManagementServiceClient getBeanInfoAccess()
254
179
// getBeanInfoForInterface(beanName, false, null)
255
-
180
+ //
256
181
Class <?> mscClass = Class .forName ("weblogic.management.provider.ManagementServiceClient" );
257
-
258
182
Method getBeanInfoAccessMethod = mscClass .getMethod ("getBeanInfoAccess" );
259
-
260
183
Object mscObject = mscClass .getDeclaredConstructor ().newInstance ();
261
-
262
184
Object biaObject = getBeanInfoAccessMethod .invoke (mscObject );
263
-
264
185
Class <?> biaClass = Class .forName ("weblogic.management.provider.beaninfo.BeanInfoAccess" );
265
186
266
187
Method getBeanInfoForInterfaceMethod =
@@ -283,75 +204,6 @@ private static BeanInfo getBeanInfo(String beanName)
283
204
return null ;
284
205
}
285
206
286
- // called solely by the main in this class
287
- private static void mainHelp () {
288
- println ("Usage:" );
289
- println (" Ensure weblogic.jar is in CLASSPATH." );
290
- println (" java -cp \" $CLASSPATH:./core/target/classes\" oracle.weblogic.deploy.util.WLSBeanHelp -bean weblogic.j2ee.descriptor.wl.UniformDistributedTopicBean -prop ForwardingPolicy -margin 60" );
291
- println (" java -cp \" $CLASSPATH:./core/target/classes\" oracle.weblogic.deploy.util.WLSBeanHelp -bean weblogic.j2ee.descriptor.wl.UniformDistributedTopicBean -margin 60" );
292
- }
293
-
294
- // called solely by the main in this class
295
- private static boolean printAttributeHelp (String beanName , String propName , int margin ) {
296
- try {
297
- BeanInfo info = getBeanInfo (beanName );
298
-
299
- if (info == null ) {
300
- println ("Error: Bean '" + beanName + "' not found." );
301
- return false ;
302
- }
303
-
304
- for (PropertyDescriptor pd :info .getPropertyDescriptors ()) {
305
- if (propName .equals (pd .getName ())) {
306
- println ("Bean = " + beanName );
307
- println ("" );
308
- printPropertyDescriptor (pd , margin );
309
- return true ;
310
- }
311
- }
312
-
313
- println ("Error: Prop '" + propName + "' not found in bean '" + beanName + "'." );
314
- } catch (Exception th ) {
315
- println ("Exception: " + th .getMessage ());
316
- }
317
- return false ;
318
- }
319
-
320
- // called solely by the main in this class
321
- private static void println (String s ) {
322
- // ignore sonar complaint - this is used for output from main
323
- System .out .println (s );
324
- }
325
-
326
- // called solely by the main in this class
327
- private static void printPropertyDescriptor (PropertyDescriptor o , int margin ) {
328
- println ("\n PROPERTY\n " );
329
- println (" name=" + o .getName ());
330
-
331
- if (!o .getName ().equals (o .getDisplayName ()))
332
- println (" display name=" + o .getDisplayName ());
333
-
334
- if (!o .getName ().equals (o .getShortDescription ()))
335
- println (" short description=" + o .getShortDescription ());
336
-
337
- println (" property type=" + o .getPropertyType ());
338
- println (" hidden=" + o .isHidden ());
339
-
340
- for (Enumeration <String > en = o .attributeNames ();
341
- en .hasMoreElements ();) {
342
- String s = en .nextElement ();
343
- Object v = o .getValue (s );
344
- if (s .equals (PD_ATT_DESCRIPTION )) continue ;
345
- if (s .equals (PD_ATT_LEGALVALUES )) v = legalValuesAsString (v );
346
- if (s .equals (PD_ATT_SEE )) v = legalValuesAsString (v );
347
- println (" " + s + "=" + v );
348
- }
349
-
350
- println (" " + PD_ATT_DESCRIPTION + "=" );
351
- println (prettyHTML (o .getValue (PD_ATT_DESCRIPTION ).toString (), margin ));
352
- println ("" );
353
- }
354
-
355
207
// helper class for converting mbean javadoc HTML to plain text
356
208
private static class PrettyHTML {
357
209
private static final String PGS = "<p>" ;
@@ -498,5 +350,4 @@ public String toString() {
498
350
return sb .toString ();
499
351
}
500
352
}
501
-
502
353
}
0 commit comments