[jboss-svn-commits] JBoss Portal SVN: r5205 - in trunk/common: . src/main/org/jboss/portal/common/util src/main/org/jboss/portal/test/common

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 14 19:21:57 EDT 2006


Author: julien at jboss.com
Date: 2006-09-14 19:21:53 -0400 (Thu, 14 Sep 2006)
New Revision: 5205

Removed:
   trunk/common/src/main/org/jboss/portal/common/util/ThrowableBean.java
   trunk/common/src/main/org/jboss/portal/test/common/ThrowableBeanTestCase.java
Modified:
   trunk/common/build.xml
Log:
- remove useless code

Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml	2006-09-14 22:57:17 UTC (rev 5204)
+++ trunk/common/build.xml	2006-09-14 23:21:53 UTC (rev 5205)
@@ -199,7 +199,6 @@
             <test todir="${test.reports}" name="org.jboss.portal.test.common.URLNavigatorTestCase"/>
             <test todir="${test.reports}" name="org.jboss.portal.test.common.PathTestCase"/>
             <test todir="${test.reports}" name="org.jboss.portal.test.common.JavaBeanModelMBeanBuilderTestCase"/>
-            <test todir="${test.reports}" name="org.jboss.portal.test.common.ThrowableBeanTestCase"/>
             <test todir="${test.reports}" name="org.jboss.portal.test.common.ParameterMapTestCase"/>
             <test todir="${test.reports}" name="org.jboss.portal.test.common.LocalizedStringTestCase"/>
             <test todir="${test.reports}" name="org.jboss.portal.test.common.ImplodeTestCase"/>

Deleted: trunk/common/src/main/org/jboss/portal/common/util/ThrowableBean.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/ThrowableBean.java	2006-09-14 22:57:17 UTC (rev 5204)
+++ trunk/common/src/main/org/jboss/portal/common/util/ThrowableBean.java	2006-09-14 23:21:53 UTC (rev 5205)
@@ -1,288 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.portal.common.util;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.io.ObjectOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ObjectInputStream;
-
-/**
- * A bean to manipulate throwable.
- *
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class ThrowableBean
-{
-
-   /** The stack trace. */
-   private StackTraceElementBean[] stackTrace;
-
-   /** The throwable with its stack trace and its cause cleared. */
-   private Throwable state;
-
-   /** The nested cause if any. */
-   private ThrowableBean cause;
-
-   public ThrowableBean()
-   {
-   }
-
-   public ThrowableBean(Throwable throwable)
-   {
-      if (throwable == null)
-      {
-         throw new IllegalArgumentException();
-      }
-
-      // Clone first the throwable
-      this.state = clone(throwable);
-
-      // Then get its stack trace and clear it on the object itself
-      StackTraceElement[] stackTrace = throwable.getStackTrace();
-      this.stackTrace = new StackTraceElementBean[stackTrace.length];
-      for (int i = 0; i < stackTrace.length; i++)
-      {
-         this.stackTrace[i] = new StackTraceElementBean(stackTrace[i]);
-      }
-      state.setStackTrace(new StackTraceElement[0]);
-
-      // If the throwable has a cause, process recursively and clear the cause as well
-      if (this.state.getCause() != null)
-      {
-         try
-         {
-            this.cause = new ThrowableBean(this.state.getCause());
-            Field f = Throwable.class.getDeclaredField("cause");
-            f.setAccessible(true);
-            f.set(this.state, null);
-         }
-         catch (Exception unexpected)
-         {
-            throw new RuntimeException(unexpected);
-         }
-      }
-   }
-
-   public Throwable getState()
-   {
-      return state;
-   }
-
-   public void setState(Throwable state)
-   {
-      this.state = state;
-   }
-
-   public StackTraceElementBean[] getStackTrace()
-   {
-      return stackTrace;
-   }
-
-   public void setStackTrace(StackTraceElementBean[] stackTrace)
-   {
-      this.stackTrace = stackTrace;
-   }
-
-   public static class StackTraceElementBean
-   {
-
-      private String declaringClass;
-      private String methodName;
-      private String fileName;
-      private int lineNumber;
-
-      public StackTraceElementBean()
-      {
-      }
-
-      public StackTraceElementBean(StackTraceElement ste)
-      {
-         declaringClass = ste.getClassName();
-         methodName = ste.getMethodName();
-         fileName = ste.getFileName();
-         lineNumber = ste.getLineNumber();
-      }
-
-      public String getDeclaringClass()
-      {
-         return declaringClass;
-      }
-
-      public void setDeclaringClass(String declaringClass)
-      {
-         this.declaringClass = declaringClass;
-      }
-
-      public String getMethodName()
-      {
-         return methodName;
-      }
-
-      public void setMethodName(String methodName)
-      {
-         this.methodName = methodName;
-      }
-
-      public String getFileName()
-      {
-         return fileName;
-      }
-
-      public void setFileName(String fileName)
-      {
-         this.fileName = fileName;
-      }
-
-      public int getLineNumber()
-      {
-         return lineNumber;
-      }
-
-      public void setLineNumber(int lineNumber)
-      {
-         this.lineNumber = lineNumber;
-      }
-
-      /**
-       * Create a <code>java.lang.StackTraceElement</code> from this object.
-       */
-      public StackTraceElement toStackTraceElement()
-      {
-         if (declaringClass == null)
-         {
-            throw new IllegalStateException("No declaring class");
-         }
-         if (methodName == null)
-         {
-            throw new IllegalStateException("No method name");
-         }
-         if (fileName == null)
-         {
-            throw new IllegalStateException("No file name");
-         }
-         try
-         {
-            Constructor ctor = StackTraceElement.class.getDeclaredConstructor(new Class[0]);
-            ctor.setAccessible(true);
-            StackTraceElement ste = (StackTraceElement)ctor.newInstance(new Object[0]);
-
-            //
-            Field methodNameSetter = StackTraceElement.class.getDeclaredField("methodName");
-            methodNameSetter.setAccessible(true);
-            methodNameSetter.set(ste, methodName);
-
-            //
-            Field declaringClassSetter = StackTraceElement.class.getDeclaredField("declaringClass");
-            declaringClassSetter.setAccessible(true);
-            declaringClassSetter.set(ste, declaringClass);
-
-            //
-            Field fileNameSetter = StackTraceElement.class.getDeclaredField("fileName");
-            fileNameSetter.setAccessible(true);
-            fileNameSetter.set(ste, fileName);
-
-            //
-            Field lineNumberSetter = StackTraceElement.class.getDeclaredField("lineNumber");
-            lineNumberSetter.setAccessible(true);
-            lineNumberSetter.setInt(ste, lineNumber);
-
-            //
-            return ste;
-         }
-         catch (Exception e)
-         {
-            throw new Error("Not expected", e);
-         }
-      }
-   }
-
-   public Throwable toThrowable()
-   {
-      if (this.state == null)
-      {
-         throw new IllegalStateException("No throwable present");
-      }
-      if (this.stackTrace == null)
-      {
-         throw new IllegalStateException("No stack trace present");
-      }
-
-      // Clone the state
-      Throwable throwable = clone(this.state);
-
-      // Set the stack trace back
-      StackTraceElement[] stackTrace = new StackTraceElement[this.stackTrace.length];
-      for (int i = 0; i < stackTrace.length; i++)
-      {
-         if (this.stackTrace[i] == null)
-         {
-            throw new IllegalStateException("No stack trace element present at index=" + i);
-         }
-         stackTrace[i] = this.stackTrace[i].toStackTraceElement();
-      }
-      throwable.setStackTrace(stackTrace);
-
-      // Process the cause recursively
-      if (cause != null)
-      {
-         try
-         {
-            Field f = Throwable.class.getDeclaredField("cause");
-            f.setAccessible(true);
-            f.set(throwable, cause.toThrowable());
-         }
-         catch (Exception unexpected)
-         {
-            throw new RuntimeException(unexpected);
-         }
-      }
-
-      //
-      return throwable;
-   }
-
-   /**
-    * Clone a throwable using serialization.
-    */
-   private Throwable clone(Throwable t)
-   {
-      try
-      {
-         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-         ObjectOutputStream oos = new ObjectOutputStream(baos);
-         oos.writeObject(t);
-         oos.close();
-         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-         ObjectInputStream ois = new ObjectInputStream(bais);
-         t = (Throwable)ois.readObject();
-         return t;
-      }
-      catch (Exception unexpected)
-      {
-         throw new RuntimeException(unexpected);
-      }
-   }
-}

Deleted: trunk/common/src/main/org/jboss/portal/test/common/ThrowableBeanTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/ThrowableBeanTestCase.java	2006-09-14 22:57:17 UTC (rev 5204)
+++ trunk/common/src/main/org/jboss/portal/test/common/ThrowableBeanTestCase.java	2006-09-14 23:21:53 UTC (rev 5205)
@@ -1,109 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-import junit.framework.AssertionFailedError;
-import org.jboss.portal.common.util.ThrowableBean;
-
-/**
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-public class ThrowableBeanTestCase extends TestCase
-{
-
-   public void testException()
-   {
-      Exception e1 = new Exception();
-      ThrowableBean tb = new ThrowableBean(e1);
-      Exception e2 = (Exception)tb.toThrowable();
-      assertEquals(e1, e2);
-   }
-
-   public void testNestedException()
-   {
-      Exception e1 = new Exception(new Exception());
-      ThrowableBean tb = new ThrowableBean(e1);
-      Exception e2 = (Exception)tb.toThrowable();
-      assertEquals(e1, e2);
-   }
-
-   public void testExceptionNotEquals()
-   {
-      Exception e1 = (Exception)new ThrowableBean(new Exception()).toThrowable();
-      Exception e2 = (Exception)new ThrowableBean(new Exception()).toThrowable();
-      assertNotEquals(e1, e2);
-   }
-
-   private void assertNotEquals(Throwable t1, Throwable t2)
-   {
-      try
-      {
-         assertEquals(t1, t2);
-         fail();
-      }
-      catch (AssertionFailedError expected)
-      {
-      }
-   }
-
-   private void assertEquals(Throwable t1, Throwable t2)
-   {
-      if (t1 == null || t2 == null)
-      {
-         fail();
-      }
-      if (!t1.getClass().equals(t2.getClass()))
-      {
-         fail();
-      }
-      StackTraceElement[] st1 = t1.getStackTrace();
-      assertNotNull(st1);
-      StackTraceElement[] st2 = t2.getStackTrace();
-      assertNotNull(st2);
-      assertEquals(st1.length, st2.length);
-      for (int i = 0; i < st2.length; i++)
-      {
-         assertEquals(st1[i], st2[i]);
-      }
-      Throwable cause1 = t1.getCause();
-      Throwable cause2 = t2.getCause();
-      if (cause1 == null)
-      {
-         assertNull(cause2);
-      }
-      else
-      {
-         assertNotNull(cause2);
-         assertEquals(cause1, cause2);
-      }
-   }
-
-//   private void assertBinaryEquals(Throwable t1, Throwable t2)
-//   {
-//      String a1 = Base64.encodeObject(t1);
-//      String a2 = Base64.encodeObject(t2);
-//      assertEquals(a1, a2);
-//
-//   }
-}




More information about the jboss-svn-commits mailing list