Example #1
0
 /**
  * Bounds the specified Vaadin application instance to the current thread.
  *
  * @param app the application instance, or null to unbound any previously bound application
  *     instance.
  */
 public static void setApplication(Application app) {
   if (app == null) {
     application.remove();
   } else {
     application.set(app);
   }
 }
Example #2
0
  protected void setupStreams(ITestResult result, boolean printMethodName) {
    String test_name = result.getTestClass().getName();
    File dir = new File(output_dir + File.separator + test_name);
    if (!dir.exists()) dir.mkdirs();
    File _tests = new File(dir, TESTS),
        _stdout = new File(dir, STDOUT),
        _stderr = new File(dir, STDERR);
    try {
      Class<?> clazz = result.getTestClass().getRealClass();
      if (!tests.containsKey(clazz)) {
        DataOutputStream output = new DataOutputStream(new FileOutputStream(_tests, true));
        DataOutputStream tmp = tests.putIfAbsent(clazz, output);
        if (tmp != null) {
          Util.close(output);
          output = tmp;
        }
      }

      if (stdout.get() == null) stdout.set(new PrintStream(new FileOutputStream(_stdout, true)));
      if (stderr.get() == null) stderr.set(new PrintStream(new FileOutputStream(_stderr, true)));
      if (printMethodName)
        stdout.get().println("\n\n------------- " + getMethodName(result) + " -----------");
    } catch (IOException e) {
      error(e.toString());
    }
  }
 public static RemoteContext get() {
   RemoteContext ctx = context.get();
   if (ctx == null) {
     ctx = new RemoteContext();
     context.set(ctx);
   }
   return ctx;
 }
 public void doFilter(
     ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
     throws IOException, ServletException {
   HttpServletRequest request = (HttpServletRequest) servletRequest;
   LOCAL.set(request);
   try {
     chain.doFilter(request, servletResponse);
   } finally {
     LOCAL.remove();
   }
 }
Example #5
0
 public static void removeCurrentAnalysisContext() {
   AnalysisContext context = currentAnalysisContext();
   if (context != null) {
     context.clear();
   }
   currentAnalysisContext.remove();
 }
 /**
  * Flushes stream associated with current thread.
  *
  * @throws IOException if an error occurs
  */
 @Override
 public void flush() throws IOException {
   OutputStream output = m_streams.get();
   if (null != output) {
     output.flush();
   }
 }
 /**
  * Writes byte to stream associated with current thread.
  *
  * @param ch the byte to write to stream
  * @throws IOException if an error occurs
  */
 @Override
 public void write(int ch) throws IOException {
   OutputStream output = m_streams.get();
   if (null != output) {
     output.write(ch);
   }
 }
  /**
   * Set the current base URL.
   *
   * <p>The value will be normalized to never end with "/".
   */
  public static void set(String url) {
    checkNotNull(url);

    // strip off trailing "/", note this is done so that script/template can easily $baseUrl/foo
    if (url.endsWith("/")) {
      url = url.substring(0, url.length() - 1);
    }

    log.trace("Set: {}", url);
    value.set(url);
  }
Example #9
0
 public static ApplicationContext getApplicationContext() throws NotInNextContextException {
   ApplicationContext nextApplicationContext = applicationContext.get();
   if (nextApplicationContext == null) {
     StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
     throw new NotInNextContextException(
         "The code is not running in a NEXT context! "
             + "\nClass: "
             + stackTrace[3].getClassName()
             + " "
             + "\nMethod: "
             + stackTrace[3].getMethodName()
             + " "
             + "\nLine: "
             + stackTrace[3].getLineNumber());
   }
   return nextApplicationContext;
 }
  public When validate(Object constantValue) {
    if (validator == null) throw new IllegalStateException("No validator");
    IAnalysisCache analysisCache = Global.getAnalysisCache();
    Profiler profiler = analysisCache.getProfiler();
    profiler.start(validator.getClass());
    AtomicBoolean performing = performingValidation.get();
    try {
      if (!performing.compareAndSet(false, true)) {
        throw new IllegalStateException("recursive validation");
      }

      return validator.forConstantValue(proxy, constantValue);
    } catch (Exception e) {
      AnalysisContext.logError(
          "Error executing custom validator for " + typeQualifier + " " + constantValue, e);
      return When.UNKNOWN;
    } finally {
      if (!performing.compareAndSet(true, false)) {
        throw new IllegalStateException("performingValidation not set when validation completes");
      }
      profiler.end(validator.getClass());
    }
  }
Example #11
0
 /**
  * Sets the locale for the current thread only.
  *
  * <p>Each thread could have an independent locale, called the thread locale.
  *
  * <p>When Invoking this method under a thread that serves requests, remember to clean up the
  * setting upon completing each request.
  *
  * <pre><code>Locale old = Locales.setThreadLocal(newValue);
  * try {
  *  ...
  * } finally {
  *  Locales.setThreadLocal(old);
  * }</code></pre>
  *
  * @param locale the thread locale; null to denote no thread locale
  * @return the previous thread locale
  */
 public static final Locale setThreadLocal(Locale locale) {
   final Locale old = _thdLocale.get();
   _thdLocale.set(locale);
   return old;
 }
Example #12
0
 /**
  * Bind the specified stream to the current thread.
  *
  * @param output the stream to bind
  * @return the OutputStream that was previously active
  */
 public OutputStream bindStream(OutputStream output) {
   OutputStream stream = m_streams.get();
   m_streams.set(output);
   return stream;
 }
 @Override
 public void checkPermission(Permission perm, Object context) {
   if (performingValidation.get().get())
     throw new SecurityException("not permissions granted while performing JSR-305 validation");
 }
Example #14
0
 /**
  * Gets the Vaadin application instance bound to the current thread.
  *
  * @return the application instance, or null if no application has been bound.
  */
 public static Application getApplication() {
   return application.get();
 }
 @Override
 public void checkPermission(Permission perm) {
   //            System.out.println("Checking " + perm);
   if (performingValidation.get().get())
     throw new SecurityException("not permissions granted while performing JSR-305 validation");
 }
 /**
  * Returns this thread's PrintStream
  *
  * @return this thread's PrintStream
  */
 public PrintStream getPrintStream() {
   PrintStream result = (PrintStream) streams.get();
   return ((result == null) ? defaultPrintStream : result);
 }
Example #17
0
 public Context getContext() {
   return currentContext.get();
 }
 public static HttpServletRequest getRequest() {
   return LOCAL.get();
 }
 /**
  * Sets the PrintStream for the current thread
  *
  * @param streamForCurrentThread the PrintStream for the current thread
  */
 public void init(PrintStream streamForCurrentThread) {
   streams.set(streamForCurrentThread);
 }
Example #20
0
 /**
  * Returns the locale defined by {@link #setThreadLocal}.
  *
  * @since 3.0.0
  * @see #getCurrent
  */
 public static final Locale getThreadLocal() {
   return _thdLocale.get();
 }
Example #21
0
 /**
  * Set the current analysis context for this thread.
  *
  * @param analysisContext the current analysis context for this thread
  */
 public static void setCurrentAnalysisContext(AnalysisContext analysisContext) {
   currentAnalysisContext.set(analysisContext);
   if (Global.getAnalysisCache() != null) {
     currentXFactory.set(new XFactory());
   }
 }
Example #22
0
 public static boolean isInApplicationContext() {
   return applicationContext.get() != null;
 }
Example #23
0
 /** Called to set the Service context for this thread and inherited threads */
 public void setAsThreadLocal() {
   threadLocalInstance.set(this);
 }
Example #24
0
 /**
  * ServiceManager sets the service context thread local when dispatch is called. this method will
  * return null or the service context
  *
  * @return the service context set by service context or null if no in an inherited thread
  */
 @CheckForNull
 public static ServiceContext get() {
   return threadLocalInstance.get();
 }
Example #25
0
 public static void setApplicationContext(ApplicationContext context) {
   applicationContext.set(context);
 }
Example #26
0
 public static void setRequestContext(RequestContext context) {
   requestContext.set(context);
   applicationContext.set(context.getApplicationContext());
 }
Example #27
0
 /** Get the AnalysisContext associated with this thread */
 public static AnalysisContext currentAnalysisContext() {
   return currentAnalysisContext.get();
 }
Example #28
0
 public static void unset() {
   log.trace("Unset");
   value.remove();
 }
Example #29
0
 /**
  * Returns the current base URL; never null.
  *
  * @throws IllegalStateException
  */
 public static String get() {
   String url = value.get();
   checkState(url != null, "Base URL not set");
   return url;
 }
Example #30
0
 public static boolean isSet() {
   return value.get() != null;
 }