View Javadoc

1   /*
2    * Created on Mar 6, 2004
3    * 
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    * 
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   * 
14   * Full GNU LGPL license terms : http://www.gnu.org/copyleft/lesser.txt
15   * 
16   * Project : iky-container
17   * Package : net.wmind.commons
18   * Author : mchaplin@users.sourceforge.net
19   *
20   */
21  package net.mchaplin.commons;
22  
23  import net.mchaplin.commons.i18n.PropertyResourceHelperI;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  
28  /***
29   * Utility object. Provide variables declarations
30   * for various resources as well as handful
31   * methods
32   * 
33   * @author mchaplin@users.sourceforge.net
34   * 
35   * $Header: 
36   * $Revision: 
37   * $Date:
38   */
39  public class WmindObject {
40  	
41      protected transient PropertyResourceHelperI propertyHelper = null;
42      protected static final String METHOD_CALL = "Method Call : ";
43      protected static final String STACK_PREFIX = "\t at ";
44      
45      /***
46       * log reference
47       */
48      protected static Log log = null;
49      public static final String EX_STACK = "\n Full Stack : ";
50      public static final String EX_CAUSE = "\n Cause : ";
51  	
52  	public WmindObject() {
53  		log = LogFactory.getLog(this.getClass());
54  		log.debug("Instanciating : ["+this.getClass().getName()+"]");
55  	}
56  	
57      /***
58       * Return a formatted String enumerating
59       * interfaces & classes inheritance
60       * for this object.
61       * 
62       * @param oFactory the object to introspect
63       */
64      protected String printInheritance(Object oFactory) {
65          
66          Class[] curClassEnum = null;
67          Class curClass = null;
68          
69          String sFactoryType = oFactory.toString().substring(6);
70          
71          curClassEnum = oFactory.getClass().getInterfaces();
72      	StringBuffer sb = new StringBuffer("Object "+sFactoryType+" implements interfaces : [");
73      	for (int i=0 ; i<curClassEnum.length ; i++) {
74      	    curClass = curClassEnum[i];
75      	    sb.append(curClass.getName()).append(", ");
76      	}
77      	sb.delete(sb.length()-2, sb.length()).append("]");
78      	curClassEnum = oFactory.getClass().getDeclaredClasses();
79      	sb.append(", extends : [");
80      	for (int i=0 ; i<curClassEnum.length ; i++) {
81      	    curClass = curClassEnum[i];
82      	    sb.append(curClass.getName()).append(", ");
83      	}
84      	sb.delete(sb.length()-2, sb.length()).append("]");
85      	
86      	// TODO improve WmindObject.printInheritance
87      	
88          /*if (oFactory.getClass().isInstance(new DefaultComponentFactory())) {
89              logger.debug("Factory " + sFactoryType + " is a valid factory");
90          }
91          if (oFactory.getClass().isAssignableFrom(DefaultComponentFactory.class)) {
92              logger.debug("Factory " + sFactoryType + " is a valid factory");
93          }
94          */
95      	return sb.toString();
96      }
97  }