[xwiki-notifications] r10957 - xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection

sdumitriu (SVN) notifications at xwiki.org
Tue Jul 1 01:46:37 CEST 2008


Author: sdumitriu
Date: 2008-07-01 01:46:37 +0200 (Tue, 01 Jul 2008)
New Revision: 10957

Modified:
   xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/AbstractChainableUberspector.java
   xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/ChainingUberspector.java
Log:
[cleanup] Apply codestyle, improve javadoc


Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/AbstractChainableUberspector.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/AbstractChainableUberspector.java	2008-06-30 23:44:13 UTC (rev 10956)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/AbstractChainableUberspector.java	2008-06-30 23:46:37 UTC (rev 10957)
@@ -30,16 +30,14 @@
 import org.apache.velocity.util.introspection.VelPropertySet;
 
 /**
- * Default implementation of a {@link ChainableUberspector chainable uberspector} that forwards all
- * calls to the wrapped uberspector (when that is possible). It should be used as the base class for
- * all chainable uberspectors.
+ * Default implementation of a {@link ChainableUberspector chainable uberspector} that forwards all calls to the wrapped
+ * uberspector (when that is possible). It should be used as the base class for all chainable uberspectors.
  * 
  * @version $Id$
  * @since 1.5M1
  * @see ChainableUberspector
  */
-public abstract class AbstractChainableUberspector extends UberspectImpl implements
-    ChainableUberspector
+public abstract class AbstractChainableUberspector extends UberspectImpl implements ChainableUberspector
 {
     /** The wrapped (decorated) uberspector. */
     protected Uberspect inner;
@@ -58,16 +56,16 @@
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.velocity.util.introspection.UberspectImpl#init()
+     * @see org.apache.velocity.util.introspection.Uberspect#init()
      */
     @Override
     public void init()
     {
-        if (inner != null) {
+        if (this.inner != null) {
             try {
-                inner.init();
+                this.inner.init();
             } catch (Exception e) {
-                log.error(e.getMessage(), e);
+                this.log.error(e.getMessage(), e);
             }
         }
     }
@@ -75,51 +73,49 @@
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.velocity.util.introspection.UberspectImpl#getIterator(java.lang.Object,
+     * @see org.apache.velocity.util.introspection.Uberspect#getIterator(java.lang.Object,
      *      org.apache.velocity.util.introspection.Info)
      */
     @SuppressWarnings("unchecked")
     @Override
     public Iterator getIterator(Object obj, Info i) throws Exception
     {
-        return (inner != null) ? inner.getIterator(obj, i) : null;
+        return (this.inner != null) ? this.inner.getIterator(obj, i) : null;
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.velocity.util.introspection.UberspectImpl#getMethod(java.lang.Object,
-     *      java.lang.String, java.lang.Object[], org.apache.velocity.util.introspection.Info)
+     * @see org.apache.velocity.util.introspection.Uberspect#getMethod(java.lang.Object, java.lang.String,
+     *      java.lang.Object[], org.apache.velocity.util.introspection.Info)
      */
     @Override
-    public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i)
-        throws Exception
+    public VelMethod getMethod(Object obj, String methodName, Object[] args, Info i) throws Exception
     {
-        return (inner != null) ? inner.getMethod(obj, methodName, args, i) : null;
+        return (this.inner != null) ? this.inner.getMethod(obj, methodName, args, i) : null;
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.velocity.util.introspection.UberspectImpl#getPropertyGet(java.lang.Object,
-     *      java.lang.String, org.apache.velocity.util.introspection.Info)
+     * @see org.apache.velocity.util.introspection.Uberspect#getPropertyGet(java.lang.Object, java.lang.String,
+     *      org.apache.velocity.util.introspection.Info)
      */
     @Override
     public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) throws Exception
     {
-        return (inner != null) ? inner.getPropertyGet(obj, identifier, i) : null;
+        return (this.inner != null) ? this.inner.getPropertyGet(obj, identifier, i) : null;
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @see org.apache.velocity.util.introspection.UberspectImpl#getPropertySet(java.lang.Object,
-     *      java.lang.String, java.lang.Object, org.apache.velocity.util.introspection.Info)
+     * @see org.apache.velocity.util.introspection.Uberspect#getPropertySet(java.lang.Object, java.lang.String,
+     *      java.lang.Object, org.apache.velocity.util.introspection.Info)
      */
     @Override
-    public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i)
-        throws Exception
+    public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) throws Exception
     {
-        return (inner != null) ? inner.getPropertySet(obj, identifier, arg, i) : null;
+        return (this.inner != null) ? this.inner.getPropertySet(obj, identifier, arg, i) : null;
     }
 }

Modified: xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/ChainingUberspector.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/ChainingUberspector.java	2008-06-30 23:44:13 UTC (rev 10956)
+++ xwiki-platform/core/trunk/xwiki-velocity/src/main/java/org/xwiki/velocity/introspection/ChainingUberspector.java	2008-06-30 23:46:37 UTC (rev 10957)
@@ -30,39 +30,39 @@
 
 /**
  * <p>
- * Since the current version of the Velocity engine (1.5) does not allow chaining uberspectors, this
- * class is a workaround. It manually constructs the uberspectors chain, loading the classes in the
- * order defined in the <code>"runtime.introspector.uberspect.chainClasses"</code> property and
- * after that simply forwarding all calls to the top of the chain. Note that the calls will be made
- * from the rightmost class to the leftmost one.
+ * Since the current version of the Velocity engine (1.5) does not allow more than one uberspector, this class is a
+ * workaround. It manually constructs a <strong>chain of uberspectors</strong>, loading the classes in the order
+ * defined in the <code>"runtime.introspector.uberspect.chainClasses"</code> property, and after that simply
+ * forwarding all calls to the top of the chain. Note that the calls will be made from the rightmost class to the
+ * leftmost one. Along the chain, each uberspectors can forward the call to the rest of the chain, build its own result,
+ * and/or process in any way the resulting value. This allows uberspectors to enhance the list of returned methods,
+ * block out methods returned by other uberspectors, or take various actions on the returned method (for example add or
+ * remove parameters before searching the method, log executed method names, or catch exceptions when executing those
+ * methods).
  * </p>
  * <p>
- * This is not actually part of the chain, but is more of a handle that allows the calls intended
- * for only one uberspector to reach the chain. It duplicates some of the code from the velocity
- * runtime initialization code, hoping that a future version of the engine will support chaining
- * natively.
+ * This is not actually part of the chain, but is more of a handle that allows the calls intended for only one
+ * uberspector to reach the chain. It duplicates some of the code from the velocity runtime initialization code, hoping
+ * that a future version of the engine will support chaining natively.
  * </p>
  * <p>
- * The chain is defined using the configuration parameter
- * <code>runtime.introspector.uberspect.chainClasses</code>. This property should contain a list
- * of canonical class names. Any wrong entry in the list will be ignored. If this property is not
- * defined or contains only wrong classnames, then by default a <code>SecureUberspector</code> is
- * used as the only entry in the chain. The first (leftmost) uberspector does not have to be
- * chainable (as it will not need to forward calls). If a uberspector in the middle of the chain is
- * not chainable, then it will break the chain at that point (all previos uberspectors will be
- * discarded from the chain).
+ * The chain is defined using the configuration parameter <code>runtime.introspector.uberspect.chainClasses</code>.
+ * This property should contain a list of canonical class names. Any wrong entry in the list will be ignored. If this
+ * property is not defined or contains only wrong classnames, then by default a <code>SecureUberspector</code> is used
+ * as the only entry in the chain. The first (leftmost) uberspector does not have to be chainable (as it will not need
+ * to forward calls). If a uberspector in the middle of the chain is not chainable, then it will break the chain at that
+ * point (all previos uberspectors will be discarded from the chain).
  * </p>
  * 
  * @since 1.5M1
  * @see ChainableUberspector
  * @version $Id$
  */
-public class ChainingUberspector extends AbstractChainableUberspector implements Uberspect,
-    RuntimeServicesAware, UberspectLoggable
+public class ChainingUberspector extends AbstractChainableUberspector implements Uberspect, RuntimeServicesAware,
+    UberspectLoggable
 {
     /** The key of the parameter that allows defining the list of chained uberspectors. */
-    public static final String UBERSPECT_CHAIN_CLASSNAMES =
-        "runtime.introspector.uberspect.chainClasses";
+    public static final String UBERSPECT_CHAIN_CLASSNAMES = "runtime.introspector.uberspect.chainClasses";
 
     /** The runtime is needed for accessing the configuration. */
     private RuntimeServices runtime;
@@ -89,41 +89,38 @@
     @Override
     public void init()
     {
-        log.debug("Initializing the chaining uberspector.");
+        this.log.debug("Initializing the chaining uberspector.");
         // Create the chain
         // TODO Since we're in Plexus already, should we use components?
-        String[] chainClassnames =
-            runtime.getConfiguration().getStringArray(UBERSPECT_CHAIN_CLASSNAMES);
+        String[] chainClassnames = this.runtime.getConfiguration().getStringArray(UBERSPECT_CHAIN_CLASSNAMES);
         for (String classname : chainClassnames) {
             initializeUberspector(classname);
         }
         // If the chain is empty, use a SecureUberspector
-        if (inner == null) {
-            log.error("No chained uberspectors defined! "
+        if (this.inner == null) {
+            this.log.error("No chained uberspectors defined! "
                 + "This uberspector is just a placeholder that relies on a real uberspector "
                 + "to actually allow method calls. Using SecureUberspect instead as a fallback.");
             initializeUberspector(SecureUberspector.class.getCanonicalName());
         }
         // Initialize all the uberspectors in the chain
         try {
-            inner.init();
+            this.inner.init();
         } catch (Exception e) {
-            log.warn(e.getMessage());
+            this.log.warn(e.getMessage());
         }
     }
 
     /**
-     * Instantiates an uberspector class and adds it to the chain. Also set the log and runtime
-     * services, if the class implements the proper interfaces. The {@link Uberspect#init()} method
-     * is not called.
+     * Instantiates an uberspector class and adds it to the chain. Also set the log and runtime services, if the class
+     * implements the proper interfaces. The {@link Uberspect#init()} method is not called.
      * 
      * @param classname The name of the uberspector class to add to the chain.
      */
     protected void initializeUberspector(String classname)
     {
         // Avoids direct recursive calls
-        if (!StringUtils.isEmpty(classname)
-            && !classname.equals(this.getClass().getCanonicalName())) {
+        if (!StringUtils.isEmpty(classname) && !classname.equals(this.getClass().getCanonicalName())) {
             Uberspect u = instantiateUberspector(classname);
             if (u == null) {
                 return;
@@ -131,17 +128,17 @@
 
             // Set the log and runtime services, if applicable
             if (u instanceof UberspectLoggable) {
-                ((UberspectLoggable) u).setLog(log);
+                ((UberspectLoggable) u).setLog(this.log);
             }
             if (u instanceof RuntimeServicesAware) {
-                ((RuntimeServicesAware) u).setRuntimeServices(runtime);
+                ((RuntimeServicesAware) u).setRuntimeServices(this.runtime);
             }
 
             // Link it in the chain
             if (u instanceof ChainableUberspector) {
-                ((ChainableUberspector) u).wrap(inner);
+                ((ChainableUberspector) u).wrap(this.inner);
             }
-            inner = u;
+            this.inner = u;
         }
     }
 
@@ -149,9 +146,8 @@
      * Tries to create an uberspector instance using reflection.
      * 
      * @param classname The name of the uberspector class to instantiate.
-     * @return An instance of the specified Uberspector. If the class cannot be instantiated using
-     *         the default constructor, or does not implement {@link Uberspect}, <code>null</code>
-     *         is returned.
+     * @return An instance of the specified Uberspector. If the class cannot be instantiated using the default
+     *         constructor, or does not implement {@link Uberspect}, <code>null</code> is returned.
      */
     protected Uberspect instantiateUberspector(String classname)
     {
@@ -159,24 +155,22 @@
         try {
             o = ClassUtils.getNewInstance(classname);
         } catch (ClassNotFoundException cnfe) {
-            log.warn(String.format("The specified uberspector [%s]"
+            this.log.warn(String.format("The specified uberspector [%s]"
                 + " does not exist or is not accessible to the current classloader.", classname));
         } catch (IllegalAccessException e) {
-            log.warn(String.format(
-                "The specified uberspector [%s] does not have a public default constructor.",
+            this.log.warn(String.format("The specified uberspector [%s] does not have a public default constructor.",
                 classname));
         } catch (InstantiationException e) {
-            log.warn(String.format("The specified uberspector [%s] cannot be instantiated.",
-                classname));
+            this.log.warn(String.format("The specified uberspector [%s] cannot be instantiated.", classname));
         } catch (ExceptionInInitializerError e) {
-            log.warn(String.format("Exception while instantiating the Uberspector [%s]: %s",
-                classname, e.getMessage()));
+            this.log.warn(String.format("Exception while instantiating the Uberspector [%s]: %s", classname, e
+                .getMessage()));
         }
 
         if (!(o instanceof Uberspect)) {
             if (o != null) {
-                log.warn("The specified class for Uberspect [" + classname
-                    + "] does not implement " + Uberspect.class.getName());
+                this.log.warn("The specified class for Uberspect [" + classname + "] does not implement "
+                    + Uberspect.class.getName());
             }
             return null;
         }



More information about the notifications mailing list