コード例 #1
0
ファイル: WebAppContainer.java プロジェクト: dlitz/resin
 /** Starts the container. */
 public void start() {
   try {
     _appDeploy.start();
   } catch (Exception e) {
     throw ConfigException.create(e);
   }
 }
コード例 #2
0
ファイル: WebAppContainer.java プロジェクト: dlitz/resin
  /** Returns the webApp for the current request. */
  private WebApp getWebApp(
      Invocation invocation, WebAppController controller, boolean isTopRequest) {
    try {
      if (controller != null) {
        WebApp webApp;

        if (isTopRequest) webApp = controller.request();
        else webApp = controller.subrequest();

        if (webApp == null) {
          return null;
        }

        invocation.setWebApp(webApp);

        return webApp;
      } else {
        return null;
      }
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }
コード例 #3
0
  /** Sets the value of the attribute */
  public void setValue(Object bean, QName name, Object value) throws ConfigException {
    try {
      if (value instanceof XmlBeanConfig<?>) {
        XmlBeanConfig<?> config = (XmlBeanConfig<?>) value;

        value = config.toObject();
      } else if (value instanceof AnnotationConfig) {
        AnnotationConfig config = (AnnotationConfig) value;

        value = config.replace();
      }

      if (_setMethod != null && value != null) {
        if (!_setMethod.getParameterTypes()[0].isAssignableFrom(value.getClass()))
          throw new ConfigException(
              L.l(
                  "'{0}.{1}' is not assignable from {2}",
                  _setMethod.getDeclaringClass().getSimpleName(), _setMethod.getName(), value));

        _setMethod.invoke(bean, value);
      }
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }
コード例 #4
0
  /** Looks up the local database, creating if necessary. */
  private DataSource findDatabaseImpl(String url, String driverName) throws SQLException {
    try {
      synchronized (_databaseMap) {
        DBPool db = _databaseMap.get(url);

        if (db == null) {
          db = new DBPool();

          db.setVar(url + "-" + _gId++);

          DriverConfig driver = db.createDriver();

          ClassLoader loader = Thread.currentThread().getContextClassLoader();

          Class driverClass = Class.forName(driverName, false, loader);

          driver.setType(driverClass);
          driver.setURL(url);

          db.init();

          _databaseMap.put(url, db);
        }

        return db;
      }
    } catch (RuntimeException e) {
      throw e;
    } catch (SQLException e) {
      throw e;
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }
コード例 #5
0
ファイル: QuercusContext.java プロジェクト: dlitz/resin
 /** Adds a java class */
 public void addJavaClass(String name, Class type) throws ConfigException {
   try {
     if (type.isAnnotationPresent(ClassImplementation.class))
       _moduleContext.introspectJavaImplClass(name, type, null);
     else _moduleContext.introspectJavaClass(name, type, null, null);
   } catch (Exception e) {
     throw ConfigException.create(e);
   }
 }
コード例 #6
0
 public void configurePhaseListeners(ArrayList<PhaseListener> list) {
   try {
     for (int i = 0; i < _phaseListenerList.size(); i++)
       list.add((PhaseListener) _phaseListenerList.get(i).newInstance());
   } catch (RuntimeException e) {
     throw e;
   } catch (Exception e) {
     throw ConfigException.create(e);
   }
 }
コード例 #7
0
ファイル: ClusterListener.java プロジェクト: GEFFROY/Quercus
  public ClusterListener(String address, int port) {
    try {
      setAddress(address);

      setPort(port);

      // setProtocol(new HmuxProtocol());
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }
コード例 #8
0
  /** Sets the value of the attribute */
  @Override
  public void setValue(Object bean, QName name, Object value) throws ConfigException {
    if ("#text".equals(name.getLocalName()))
      throw new ConfigException(L.l("text is not allowed in this context\n  '{0}'", value));

    try {
      _putMethod.invoke(bean, name.getLocalName(), value);
    } catch (Exception e) {
      throw ConfigException.create(_putMethod, e);
    }
  }
コード例 #9
0
ファイル: DateType.java プロジェクト: dlitz/resin
  /**
   * Returns the type's configured value
   *
   * @param builder the context builder
   * @param node the configuration node
   * @param parent
   */
  @Override
  public Object valueOf(String text) {
    try {
      if (text == null) return null;
      else if ("".equals(text)) return new Date(Alarm.getCurrentTime());

      QDate date = new QDate();
      date.parseDate(text);

      return new Date(date.getGMTTime());
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }
コード例 #10
0
 public void caucho_init(ServletConfig config) {
   try {
     com.caucho.server.webapp.WebApp webApp =
         (com.caucho.server.webapp.WebApp) config.getServletContext();
     init(config);
     if (com.caucho.jsp.JspManager.getCheckInterval() >= 0)
       _caucho_depends.setCheckInterval(com.caucho.jsp.JspManager.getCheckInterval());
     _jsp_pageManager = webApp.getJspApplicationContext().getPageManager();
     com.caucho.jsp.TaglibManager manager = webApp.getJspApplicationContext().getTaglibManager();
     com.caucho.jsp.PageContextImpl pageContext =
         new com.caucho.jsp.InitPageContextImpl(webApp, this);
   } catch (Exception e) {
     throw com.caucho.config.ConfigException.create(e);
   }
 }
コード例 #11
0
  /** Sets the value of the attribute */
  @Override
  public void setText(Object bean, QName name, String value) throws ConfigException {
    if ("#text".equals(name.getLocalName())) {
      if (value == null || value.trim().length() == 0) return;

      throw new ConfigException(
          L.l(
              "text is not allowed for bean {0}\n  '{1}'",
              bean.getClass().getName(), value.trim()));
    }

    try {
      _putMethod.invoke(bean, name.getLocalName(), _type.valueOf(value));
    } catch (Exception e) {
      throw ConfigException.create(_putMethod, e);
    }
  }
コード例 #12
0
  /** Compile a schema. */
  public Schema compileSchema(InputSource is) throws SAXException, IOException {
    try {
      CompactParser parser = new CompactParser();

      parser.parse(is);

      SchemaImpl schema = new SchemaImpl(parser.getGrammar());

      schema.setFilename(is.getSystemId());

      return schema;
    } catch (SAXException e) {
      throw e;
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }
コード例 #13
0
  public static void setHandle(Object obj, Object handle) {
    if (obj instanceof HandleAware) {
      ((HandleAware) obj).setSerializationHandle(handle);
    } else {
      try {
        Class cl = obj.getClass();

        for (Field field : cl.getDeclaredFields()) {
          if (field.getName().equals("__caucho_handle")) {
            field.setAccessible(true);
            field.set(obj, handle);
          }
        }
      } catch (Exception e) {
        throw ConfigException.create(e);
      }
    }
  }
コード例 #14
0
  protected void configure(FilterMapping filterMapping) {
    try {
      if (_urlPattern != null) filterMapping.createUrlPattern().addText(_urlPattern).init();

      if (_servletName != null) filterMapping.addServletName(_servletName);

      filterMapping.setFilterName(_filterName);

      if (_filterClass != null) filterMapping.setFilterClass(_filterClass);

      for (Map.Entry<String, String> entry : _initParamMap.entrySet()) {
        filterMapping.setInitParam(entry.getKey(), entry.getValue());
      }

      filterMapping.setInit(_init);

      // filterMapping.init();
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }
コード例 #15
0
    @Override
    public <T> void inject(T instance, CreationalContext<T> cxt) {
      try {
        CreationalContextImpl<T> env;

        if (cxt instanceof CreationalContextImpl<?>) env = (CreationalContextImpl<T>) cxt;
        else env = null;

        Object[] args = new Object[_args.length];

        for (int i = 0; i < _args.length; i++) {
          if (_factoryArgs[i] == null)
            _factoryArgs[i] = getBeanManager().getReferenceFactory(_args[i]);

          args[i] = _factoryArgs[i].create(null, env, _args[i]);
        }

        _method.invoke(instance, args);
      } catch (Exception e) {
        throw ConfigException.create(_method, e);
      }
    }
コード例 #16
0
  @Override
  public int doCommand(WatchdogArgs args, WatchdogClient client, WebAppDeployClient deployClient) {
    String fileName = args.getDefaultArg();

    if (fileName == null) {
      throw new ConfigException(L.l("Cannot find a filename in command line"));
    }

    CommitBuilder commit = createCommitBuilder(args);

    try {
      WriteStream out = Vfs.openWrite(System.out);

      deployClient.getFile(commit.getId(), fileName, out);

      out.flush();
    } catch (IOException e) {
      throw ConfigException.create(e);
    }

    return 0;
  }
コード例 #17
0
    @Override
    public <T> void inject(T instance, CreationalContext<T> cxt) {
      try {
        CreationalContextImpl<?> env;

        if (cxt instanceof CreationalContextImpl<?>) env = (CreationalContextImpl<?>) cxt;
        else env = null;

        // server/30i1 vs ioc/0155
        Object value = _fieldFactory.create(null, env, _ip);

        _field.set(instance, value);
      } catch (AmbiguousResolutionException e) {
        throw new AmbiguousResolutionException(getFieldName(_field) + e.getMessage(), e);
      } catch (IllegalProductException e) {
        throw new IllegalProductException(getFieldName(_field) + e.getMessage(), e);
      } catch (InjectionException e) {
        throw new InjectionException(getFieldName(_field) + e.getMessage(), e);
      } catch (Exception e) {
        throw ConfigException.create(_field, e);
      }
    }
コード例 #18
0
ファイル: WebAppContainer.java プロジェクト: dlitz/resin
  private WebApp createErrorWebApp() {
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    try {
      thread.setContextClassLoader(_classLoader);

      Path errorRoot = new MemoryPath().lookup("/error-root");
      errorRoot.mkdirs();

      String id = "error/webapp/" + getHostName() + "/error";

      UnknownWebAppController webAppController = new UnknownWebAppController(id, errorRoot, this);
      webAppController.init();
      webAppController.startOnInit();

      return webAppController.request();
    } catch (Exception e) {
      throw ConfigException.create(e);
    } finally {
      thread.setContextClassLoader(loader);
    }
  }
コード例 #19
0
  /** Introspects the constructor */
  private void introspectConstructor(AnnotatedType<X> beanType) {
    if (_beanCtor != null) return;

    // XXX: may need to modify BeanFactory
    if (beanType.getJavaClass().isInterface()) return;

    try {
      /*
      Class cl = getInstanceClass();

      if (cl == null)
        cl = getTargetClass();
      */

      AnnotatedConstructor<X> best = null;
      AnnotatedConstructor<X> second = null;

      for (AnnotatedConstructor<X> ctor : beanType.getConstructors()) {
        if (_newArgs != null && ctor.getParameters().size() != _newArgs.length) {
          continue;
        } else if (best == null) {
          best = ctor;
        } else if (ctor.isAnnotationPresent(Inject.class)) {
          if (best != null && best.isAnnotationPresent(Inject.class))
            throw new ConfigException(
                L.l(
                    "'{0}' can't have two constructors marked by @Inject or by a @Qualifier, because the Java Injection BeanManager can't tell which one to use.",
                    beanType.getJavaClass().getName()));
          best = ctor;
          second = null;
        } else if (best.isAnnotationPresent(Inject.class)) {
        } else if (ctor.getParameters().size() == 0) {
          best = ctor;
        } else if (best.getParameters().size() == 0) {
        } else if (ctor.getParameters().size() == 1
            && ctor.getParameters().get(0).equals(String.class)) {
          second = best;
          best = ctor;
        }
      }

      if (best == null) {
        // ioc/0q00
        best =
            new AnnotatedConstructorImpl(
                beanType, beanType.getJavaClass().getConstructor(new Class[0]));
      }

      if (best == null) {
        throw new ConfigException(
            L.l(
                "{0}: no constructor found while introspecting bean for Java Injection",
                beanType.getJavaClass().getName()));
      }

      if (second == null) {
      } else if (beanType.getJavaClass().getName().startsWith("java.lang")
          && best.getParameters().size() == 1
          && best.getParameters().get(0).equals(String.class)) {
        log.fine(
            L.l(
                "{0}: WebBean does not have a unique constructor, choosing String-arg constructor",
                beanType.getJavaClass().getName()));
      } else
        throw new ConfigException(
            L.l(
                "{0}: Bean does not have a unique constructor.  One constructor must be marked with @Inject or have a qualifier annotation.",
                beanType.getJavaClass().getName()));

      _beanCtor = best;
      _javaCtor = _beanCtor.getJavaMember();
      _javaCtor.setAccessible(true);

    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      throw ConfigException.create(e);
    }
  }