protected static String getString(
      HttpServletRequest request, String propertyName, String propertyValueDefault) {
    String res = null;

    {
      try {
        Principal userPrincipal = request.getUserPrincipal();
        if (userPrincipal != null) {
          PreferenceAccessorFactory f = DefaultPreferenceAccessorFactory.getInstance();
          PreferenceAccessor a = f.getUserPreferenceAccessor();

          res = a.getPreferenceProperty(userPrincipal, propertyName);

          if (res == null || res.length() == 0) {
            if (propertyValueDefault != null) {
              res = propertyValueDefault;
            }
          }
        }
      } catch (Throwable ex) {
        ex.printStackTrace(); // TODO: Log!
      }
    }

    return res;
  }
  protected static void setString(
      HttpServletRequest request, String propertyName, String propertyValue) {
    try {
      Principal userPrincipal = request.getUserPrincipal();
      if (userPrincipal != null) {
        PreferenceAccessorFactory f = DefaultPreferenceAccessorFactory.getInstance();
        PreferenceAccessor a = f.getUserPreferenceAccessor();

        a.setPreferenceProperty(userPrincipal, propertyName, propertyValue);
      }
    } catch (Throwable ex) {
      ex.printStackTrace(); // TODO: Log!
    }
  }
  public static void setMenuPropertyValue(HttpServletRequest request, Integer v) {
    try {
      Principal userPrincipal = request.getUserPrincipal();
      if (userPrincipal != null) {
        PreferenceAccessorFactory f = DefaultPreferenceAccessorFactory.getInstance();
        PreferenceAccessor a = f.getUserPreferenceAccessor();

        if (v == null) {
          a.setPreferenceProperty(userPrincipal, MENU_PROPERTY_NAME, null);
        } else {
          String value = v.toString();
          a.setPreferenceProperty(userPrincipal, MENU_PROPERTY_NAME, value);
        }
      }
    } catch (Throwable ex) {
      ex.printStackTrace(); // TODO: Log!
    }
  }
Beispiel #4
0
    public void run() {
      if (useMainThread) {
        // we have to start first to provide the service ..
        singletonMainThread.waitUntilRunning();
      }

      // start user app ..
      try {
        Class mainClass = ReflectionUtil.getClass(mainClassName, true, getClass().getClassLoader());
        if (null == mainClass) {
          throw new RuntimeException(
              new ClassNotFoundException("MainThread couldn't find main class " + mainClassName));
        }
        try {
          mainClassMain = mainClass.getDeclaredMethod("main", new Class[] {String[].class});
          mainClassMain.setAccessible(true);
        } catch (Throwable t) {
          throw new RuntimeException(t);
        }
        if (DEBUG)
          System.err.println(
              "MainAction.run(): " + Thread.currentThread().getName() + " invoke " + mainClassName);
        mainClassMain.invoke(null, new Object[] {mainClassArgs});
      } catch (InvocationTargetException ite) {
        ite.getTargetException().printStackTrace();
      } catch (Throwable t) {
        t.printStackTrace();
      }

      if (DEBUG)
        System.err.println(
            "MainAction.run(): " + Thread.currentThread().getName() + " user app fin");

      if (useMainThread) {
        singletonMainThread.stop();
        if (DEBUG)
          System.err.println(
              "MainAction.run(): " + Thread.currentThread().getName() + " MainThread fin - stop");
        System.exit(0);
      }
    }
Beispiel #5
0
  public void run() {
    if (DEBUG) System.err.println("MainThread.run(): " + Thread.currentThread().getName());
    synchronized (taskWorkerLock) {
      isRunning = true;
      taskWorkerLock.notifyAll();
    }
    while (!shouldStop) {
      try {
        // wait for something todo ..
        synchronized (taskWorkerLock) {
          while (!shouldStop && tasks.size() == 0) {
            try {
              taskWorkerLock.wait();
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          }

          // take over the tasks ..
          if (!shouldStop && tasks.size() > 0) {
            Runnable task = (Runnable) tasks.remove(0);
            task.run(); // FIXME: could be run outside of lock
          }
          taskWorkerLock.notifyAll();
        }
      } catch (Throwable t) {
        // handle errors ..
        t.printStackTrace();
      } finally {
        // epilog - unlock locked stuff
      }
    }
    if (DEBUG) System.err.println("MainThread.run(): " + Thread.currentThread().getName() + " fin");
    synchronized (taskWorkerLock) {
      isRunning = false;
      isExit = true;
      taskWorkerLock.notifyAll();
    }
  }
  private static Integer getMenuPropertyValue(HttpServletRequest request) {
    Integer res = null;

    {
      try {
        Principal userPrincipal = request.getUserPrincipal();
        if (userPrincipal != null) {
          PreferenceAccessorFactory f = DefaultPreferenceAccessorFactory.getInstance();
          PreferenceAccessor a = f.getUserPreferenceAccessor();

          String name = a.getPreferenceProperty(userPrincipal, MENU_PROPERTY_NAME);
          if (name != null) {
            res = Integer.parseInt(name);
          }
        }
      } catch (Throwable ex) {
        ex.printStackTrace(); // TODO: Log!
      }
    }

    return res;
  }
Beispiel #7
0
  /**
   * Given another class, return a transformed version of the class which replaces specified calls
   * with alternative static implementations
   */
  public byte[] transform(
      ClassLoader loader,
      String className,
      Class<?> classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer)
      throws IllegalClassFormatException {

    // debug = className.equals ("chicory/Test");

    String fullClassName = className.replace("/", ".");

    debug_transform.log("In Transform: class = %s%n", className);

    // Don't instrument boot classes.  We only want to instrument
    // user classes classpath.
    // Most boot classes have the null loader,
    // but some generated classes (such as those in sun.reflect) will
    // have a non-null loader.  Some of these have a null parent loader,
    // but some do not.  The check for the sun.reflect package is a hack
    // to catch all of these.  A more consistent mechanism to determine
    // boot classes would be preferrable.
    if (loader == null) {
      debug_transform.log("ignoring system class %s, class loader == null", fullClassName);
      return (null);
    } else if (loader.getParent() == null) {
      debug_transform.log("ignoring system class %s, parent loader == null\n", fullClassName);
      return (null);
    } else if (fullClassName.startsWith("sun.reflect")) {
      debug_transform.log("ignoring system class %s, in sun.reflect package", fullClassName);
      return (null);
    } else if (fullClassName.startsWith("com.sun")) {
      System.out.printf("Class from com.sun package %s with nonnull loaders\n", fullClassName);
    }

    // Don't intrument our code
    if (className.startsWith("randoop.")) {
      debug_transform.log("Not considering randoop class %s%n", fullClassName);
      return (null);
    }

    // Look for match with specified regular expressions for class
    method_map = null;
    debug_class = false;
    for (MethodMapInfo mmi : map_list) {
      if (mmi.class_regex.matcher(className).matches()) {
        if (false && className.startsWith("RandoopTest")) debug_class = true;
        if (debug_class)
          System.out.printf("Classname %s matches re %s%n", className, mmi.class_regex);
        method_map = mmi.map;
        break;
      }
    }
    if (method_map == null) return null;

    debug_transform.log(
        "transforming class %s, loader %s - %s%n", className, loader, loader.getParent());

    // Parse the bytes of the classfile, die on any errors
    JavaClass c = null;
    ClassParser parser = new ClassParser(new ByteArrayInputStream(classfileBuffer), className);
    try {
      c = parser.parse();
    } catch (Exception e) {
      throw new RuntimeException("Unexpected error", e);
    }

    try {
      // Get the class information
      ClassGen cg = new ClassGen(c);
      ifact = new InstructionFactory(cg);

      map_calls(cg, className, loader);

      JavaClass njc = cg.getJavaClass();
      if (debug) njc.dump("/tmp/ret/" + njc.getClassName() + ".class");

      if (true) {
        return (cg.getJavaClass().getBytes());
      } else {
        debug_transform.log("not including class %s (filtered out)", className);
        return null;
      }

    } catch (Throwable e) {
      out.format("Unexpected error %s in transform", e);
      e.printStackTrace();
      return (null);
    }
  }
Beispiel #8
0
 /** Called by the AppletPanel to provide feedback when an exception has happened. */
 protected void showAppletException(Throwable t) {
   t.printStackTrace();
   repaint();
 }