22 * Copyright (c) 2022, Oracle Corporation and/or its affiliates.
33 * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44 */
5-
65package oracle .weblogic .deploy .util ;
76
87import java .beans .BeanDescriptor ;
2019 *
2120 * Includes an undocumented main intended for ad-hoc printing of a particular bean or bean property help.
2221 */
23-
2422public class WLSBeanHelp {
2523 private static final String EOL = System .getProperty ("line.separator" );
2624
@@ -42,12 +40,7 @@ private WLSBeanHelp() {}
4240 // and margin set to "width"
4341 // - if propDefault not null, inline it as "default=" along with
4442 // 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 ) {
5144 String ds ;
5245
5346 if (propName == null )
@@ -67,76 +60,17 @@ public static String get(
6760 return limits + prettyHTML (ds , width );
6861 }
6962
70- public static String get (
71- String beanName ,
72- int width
73- ) {
63+ public static String get (String beanName , int width ) {
7464 return get (beanName , null , width , null );
7565 }
7666
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-
13167 // convert basic javadoc HTML to plain text
13268 // (package visible to enable unit testing)
13369 static String prettyHTML (String html , int margin ) {
13470 return new PrettyHTML (html , margin ).toString ();
13571 }
13672
137- private static String getFeatureDescription (
138- FeatureDescriptor fd
139- ) {
73+ private static String getFeatureDescription (FeatureDescriptor fd ) {
14074 if (fd == null ) return "" ;
14175 Object d = fd .getValue (PD_ATT_DESCRIPTION );
14276 if (d == null ) return "" ; // should pretty much never happen
@@ -146,11 +80,7 @@ private static String getFeatureDescription(
14680 // gets pretty printed default for a given bean prop, legal values, min, or max
14781 // default is passed in from outside
14882 // 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 ) {
15484 StringBuilder ret = new StringBuilder ();
15585 if (propDefault != null ) {
15686 // we report the passed in default from the alias DB instead of using the
@@ -180,10 +110,7 @@ private static String getPropertyLimits(
180110 }
181111
182112 // 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 ) {
187114 try {
188115 BeanInfo info = getBeanInfo (beanName );
189116 if (info == null ) return null ;
@@ -203,9 +130,7 @@ private static PropertyDescriptor getPropertyDescriptor(
203130 }
204131
205132 // can return null if not found
206- private static BeanDescriptor getBeanDescriptor (
207- String beanName
208- ) {
133+ private static BeanDescriptor getBeanDescriptor (String beanName ) {
209134 try {
210135 BeanInfo info = getBeanInfo (beanName );
211136 if (info == null ) return null ;
@@ -252,15 +177,11 @@ private static BeanInfo getBeanInfo(String beanName)
252177 // use reflection to implement the equivalent of:
253178 // weblogic management provider ManagementServiceClient getBeanInfoAccess()
254179 // getBeanInfoForInterface(beanName, false, null)
255-
180+ //
256181 Class <?> mscClass = Class .forName ("weblogic.management.provider.ManagementServiceClient" );
257-
258182 Method getBeanInfoAccessMethod = mscClass .getMethod ("getBeanInfoAccess" );
259-
260183 Object mscObject = mscClass .getDeclaredConstructor ().newInstance ();
261-
262184 Object biaObject = getBeanInfoAccessMethod .invoke (mscObject );
263-
264185 Class <?> biaClass = Class .forName ("weblogic.management.provider.beaninfo.BeanInfoAccess" );
265186
266187 Method getBeanInfoForInterfaceMethod =
@@ -283,75 +204,6 @@ private static BeanInfo getBeanInfo(String beanName)
283204 return null ;
284205 }
285206
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-
355207 // helper class for converting mbean javadoc HTML to plain text
356208 private static class PrettyHTML {
357209 private static final String PGS = "<p>" ;
@@ -498,5 +350,4 @@ public String toString() {
498350 return sb .toString ();
499351 }
500352 }
501-
502353}
0 commit comments