/** @since Servlet 3.0 */
  @Override
  public boolean authenticate(HttpServletResponse response) throws IOException, ServletException {
    WebApp webApp = getWebApp();

    if (webApp == null)
      throw new ServletException(
          L.l("No authentication mechanism is configured for '{0}'", getWebApp()));

    // server/1aj{0,1}
    Authenticator auth = webApp.getConfiguredAuthenticator();

    if (auth == null)
      throw new ServletException(
          L.l("No authentication mechanism is configured for '{0}'", getWebApp()));

    Login login = webApp.getLogin();

    if (login == null)
      throw new ServletException(
          L.l("No authentication mechanism is configured for '{0}'", getWebApp()));

    Principal principal = login.login(this, response, true);

    if (principal != null) return true;

    return false;
  }
  /** Creates the SSL ServerSocket. */
  public static QServerSocket createJNI(InetAddress host, int port) throws IOException {
    try {
      Thread thread = Thread.currentThread();
      ClassLoader loader = thread.getContextClassLoader();

      Class cl = Class.forName("com.caucho.vfs.JniServerSocketImpl", false, loader);

      Method method = cl.getMethod("create", new Class[] {String.class, int.class});

      String hostAddress;

      if (host != null) hostAddress = host.getHostAddress();
      else {
        hostAddress = null;
      }

      try {
        return (QServerSocket) method.invoke(null, hostAddress, port);
      } catch (InvocationTargetException e) {
        throw e.getTargetException();
      }
    } catch (IOException e) {
      throw e;
    } catch (ClassNotFoundException e) {
      log.fine(e.toString());

      throw new IOException(L.l("JNI Socket support requires Resin Professional."));
    } catch (Throwable e) {
      log.log(Level.FINE, e.toString(), e);

      throw new IOException(L.l("JNI Socket support requires Resin Professional."));
    }
  }
  /**
   * Sends a message to the destination
   *
   * @param destination the destination the message should be send to
   * @param message the message to send
   * @param deliveryMode the delivery mode
   * @param priority the priority
   * @param timeToLive how long the message should live
   */
  public void send(
      Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
      throws JMSException {
    if (destination == null) destination = _queue;
    else if (_queue != null && destination != _queue)
      throw new UnsupportedOperationException(
          L.l("MessageProducer: '{0}' does not match the queue '{1}'", destination, _queue));

    if (destination == null)
      throw new UnsupportedOperationException(
          L.l("MessageProducer: null destination is not supported."));

    if (_session == null || _session.isClosed())
      throw new javax.jms.IllegalStateException(
          L.l("getDeliveryMode(): message producer is closed."));

    if (destination instanceof TemporaryTopicImpl) {

      // Message can not be sent on Temporary Queue if Session is not active.
      if (((TemporaryTopicImpl) destination).isClosed()) {
        throw new javax.jms.IllegalStateException(
            L.l("temporary queue '{0}' session is not active", destination));
      }
    }

    _session.send((AbstractDestination) destination, message, deliveryMode, priority, timeToLive);
    // _session.checkThread();
  }
  private Bean<?> bindEntityManager(String location, PersistenceContext pContext) {
    String name = pContext.name();
    String unitName = pContext.unitName();

    Bean<?> bean;

    bean = bind(location, EntityManager.class, unitName);

    if (bean == null) bean = bind(location, EntityManager.class, name);

    if (bean != null) {
      // valid bean
    } else if (!"".equals(unitName)) {
      throw new ConfigException(
          location + L.l("unitName='{0}' is an unknown @PersistenceContext.", unitName));
    } else if (!"".equals(name)) {
      throw new ConfigException(
          location + L.l("name='{0}' is an unknown @PersistenceContext.", name));

    } else {
      throw new ConfigException(
          location
              + L.l(
                  "@PersistenceContext cannot find any persistence contexts.  No JPA persistence-units have been deployed"));
    }

    return bean;
  }
Example #5
0
  public DeployClient(String host, int port, String userName, String password) {
    String url = "http://" + host + ":" + port + "/hmtp";

    _url = url;

    HmtpClient client = new HmtpClient(url);
    try {
      client.setVirtualHost("admin.resin");

      client.connect(userName, password);

      _bamClient = client;
      _bamManager = new SimpleBamManager(_bamClient.getBroker());

      _deployAddress = DeployActor.ADDRESS;

      /*
            BamManager bamManager = server.getAdminBrokerManager();
            return BamProxyFactory.createProxy(api, to, sender);
      */
      _deployProxy = _bamManager.createProxy(DeployActorProxy.class, _deployAddress, _bamClient);
    } catch (RemoteConnectionFailedException e) {
      throw new RemoteConnectionFailedException(
          L.l(
              "Connection to '{0}' failed for remote administration.\n  Ensure the local server has started, or include --server and --port parameters to connect to a remote server.\n  {1}",
              url, e.getMessage()),
          e);
    } catch (RemoteListenerUnavailableException e) {
      throw new RemoteListenerUnavailableException(
          L.l(
              "Connection to '{0}' failed for remote administration because RemoteAdminService (HMTP) is not enabled.\n  Ensure <resin:RemoteAdminService> is enabled in resin.xml.\n  {1}",
              url, e.getMessage()),
          e);
    }
  }
Example #6
0
  public void rebind(Name name, Object obj) throws NamingException {
    if (name.size() == 0) throw new NamingException(L.l("can't bind root"));

    AbstractModel model = _model;

    int i = 0;
    for (; i + 1 < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) {
        ((Context) value).bind(name.getSuffix(i + 1), obj);
        return;
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    String first = name.get(i);

    if (obj == null) obj = NullValue.NULL;

    model.bind(first, getReference(model, obj));
  }
  private Arg<X> introspectArg(Annotated ann, AnnotatedParameter<X> param) {
    Annotation[] qualifiers = getQualifiers(param);

    InjectionPoint ip = new InjectionPointImpl<X>(getBeanManager(), this, param);

    if (ann.isAnnotationPresent(Inject.class)) {
      // ioc/022k
      _injectionPointSet.add(ip);
    }

    if (param.isAnnotationPresent(Disposes.class)) {
      throw new ConfigException(
          L.l(
              "{0} is an invalid managed bean because its constructor has a @Disposes parameter",
              getAnnotatedType().getJavaClass().getName()));
    }

    if (param.isAnnotationPresent(Observes.class)) {
      throw new ConfigException(
          L.l(
              "{0} is an invalid managed bean because its constructor has an @Observes parameter",
              getAnnotatedType().getJavaClass().getName()));
    }

    return new BeanArg<X>(getBeanManager(), param.getBaseType(), qualifiers, ip);
  }
Example #8
0
  /** Destroys the named subcontext. */
  public void destroySubcontext(String name) throws NamingException {
    String tail = name;
    AbstractModel model = _model;

    while (true) {
      String first = parseFirst(tail);
      String rest = parseRest(tail);

      if (first == null) throw new NamingException(L.l("can't destroy root subcontext"));

      if (rest == null) {
        model.unbind(first);
        return;
      }

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        tail = rest;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) {
        ((Context) value).destroySubcontext(rest);
        return;
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }
  }
Example #9
0
  public void destroySubcontext(Name name) throws NamingException {
    if (name.size() == 0) throw new NamingException(L.l("can't destroy root subcontext"));

    AbstractModel model = _model;

    int i = 0;
    for (; i + 1 < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) {
        ((Context) value).destroySubcontext(name.getSuffix(i + 1));
        return;
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    String first = name.get(i);

    model.unbind(first);
  }
Example #10
0
  public static void validatePassivating(Class<?> cl, Bean<?> bean, String typeName) {
    Class<?> beanClass = bean.getBeanClass();

    if (!Serializable.class.isAssignableFrom(beanClass) && false) {
      ConfigException exn =
          new ConfigException(
              L.l(
                  "{0}: {1} is an invalid {2} because it is not serializable.",
                  cl.getName(), bean, typeName));

      throw exn;
      // InjectManager.create().addDefinitionError(exn);
    }

    for (InjectionPoint ip : bean.getInjectionPoints()) {
      if (ip.isTransient() || ip.isDelegate()) continue;

      Class<?> type = getRawClass(ip.getType());

      if (type.isInterface()) continue;

      if (!Serializable.class.isAssignableFrom(type)) {
        ConfigException exn =
            new ConfigException(
                L.l(
                    "{0}: {1} is an invalid {4} because its injection point '{2}' of type {3} is not serializable.",
                    cl.getName(), bean, ip.getMember().getName(), ip.getType(), typeName));

        throw exn;
      }
    }
  }
Example #11
0
  @Override
  public void complete() {
    AmberPersistenceUnit persistenceUnit = _sourceType.getPersistenceUnit();

    Class targetClass = getTargetClass();

    if (targetClass == null || void.class.equals(targetClass))
      throw error(
          _field,
          L.l(
              "Can't determine targetEntity for {0}.  @OneToMany properties must target @Entity beans.",
              _fieldName));

    AmberType targetType = persistenceUnit.createType(targetClass);

    if (targetType == null) {
      throw error(
          _field,
          L.l(
              "targetClass '{0}' is not a known element collection class for {1}.  The targetClass of a @ElementCollection must be a basic class.",
              targetClass.getName(), _fieldName));
    }

    /*
    if (_orderBy != null)
      calculateOrderBy(_orderBy);
    */

    addCollection(targetType);
  }
Example #12
0
  private Object lookupImpl(Name name) throws NamingException {
    if (log.isLoggable(Level.FINEST)) log.finest(L.l("JNDI lookup `{0}'", name));

    if (name == null) return create(_model, _env);

    AbstractModel model = _model;

    for (int i = 0; i < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (i + 1 == name.size()) {
        return value;
      } else if (value instanceof Context) {
        return ((Context) value).lookup(name.getSuffix(i + 1));
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    return create(getFullPath(name), model, _env);
  }
  /** Tries to open the log. Called from inside _logLock */
  private void openLog() {
    closeLogStream();

    WriteStream os = _os;
    _os = null;

    IoUtil.close(os);

    Path path = getPath();

    if (path == null) {
      path = getPath(CurrentTime.getCurrentTime());
    }

    Path parent = path.getParent();

    try {
      if (!parent.isDirectory()) {
        if (!parent.mkdirs()) {
          /* XXX:
          logWarning(L.l("Can't create log directory {0}.\n",
                         parent));
          */
        }
      }
    } catch (Exception e) {
      logWarning(L.l("Can't create log directory {0}.\n  Exception={1}", parent, e), e);
    }

    Exception exn = null;

    for (int i = 0; i < 3 && _os == null; i++) {
      try {
        _os = path.openAppend();
      } catch (IOException e) {
        exn = e;
      }
    }

    String pathName = path.getPath();

    try {
      if (pathName.endsWith(".gz")) {
        _zipOut = _os;
        _os = Vfs.openWrite(new GZIPOutputStream(_zipOut));
      } else if (pathName.endsWith(".zip")) {
        throw new ConfigException("Can't support .zip in path-format");
      }
    } catch (Exception e) {
      if (exn == null) exn = e;
    }

    if (exn != null)
      logWarning(
          L.l(
              "Can't create log for {0}.\n  User={1} Exception={2}",
              path, System.getProperty("user.name"), exn),
          exn);
  }
  @PostConstruct
  public void init() {
    if (_enableAt == null)
      throw new ConfigException(
          L.l("{0} requires 'enable-at' attribute", getClass().getSimpleName()));

    if (_disableAt == null)
      throw new ConfigException(
          L.l("{0} requires 'disable-at' attribute", getClass().getSimpleName()));
  }
  /** Notifies that a local transaction has rolled back. */
  public void localTransactionRolledback(ConnectionEvent event) {
    if (_xid != null)
      throw new IllegalStateException(
          L.l("attempted to rollback() local transaction from an active XA transaction."));
    else if (!_isLocalTransaction)
      throw new IllegalStateException(
          L.l("attempted to rollback() with no active local transaction."));

    // #2627, server/30c4
    _isLocalTransaction = false;
  }
Example #16
0
  /** Returns an exception for the named archive or null if there is no exception */
  public Throwable getConfigException(String name) {
    ExpandDeployController<?> controller = getDeployContainer().findController(keyToName(name));

    if (controller == null) {
      if (log.isLoggable(Level.FINE)) log.log(Level.FINE, L.l("unknown name '{0}'", name));

      if (log.isLoggable(Level.FINER))
        log.log(Level.FINER, L.l("known names are {0}", getNamesAsString()));

      return new ConfigException(L.l("unknown name '{0}'", name));
    }

    return controller.getConfigException();
  }
Example #17
0
  /** Stop the archive. */
  public boolean stop(String name) {
    DeployController<?> controller = getDeployContainer().findController(keyToName(name));

    if (controller == null) {
      if (log.isLoggable(Level.FINE)) log.log(Level.FINE, L.l("unknown name '{0}'", name));

      if (log.isLoggable(Level.FINER))
        log.log(Level.FINER, L.l("known names are {0}", getNamesAsString()));

      return false;
    }

    controller.stop();
    return true;
  }
  /** Creates a new connection. */
  private UserPoolItem createConnection(
      ManagedConnectionFactory mcf,
      Subject subject,
      ConnectionRequestInfo info,
      UserPoolItem oldPoolItem)
      throws ResourceException {
    boolean isValid = false;
    ManagedPoolItem poolItem = null;

    try {
      ManagedConnection mConn = mcf.createManagedConnection(subject, info);

      if (mConn == null)
        throw new ResourceException(
            L.l("'{0}' did not return a connection from createManagedConnection", mcf));

      poolItem = new ManagedPoolItem(this, mcf, mConn);

      UserPoolItem userPoolItem;

      // Ensure the connection is still valid
      userPoolItem = poolItem.toActive(subject, info, oldPoolItem);

      if (userPoolItem == null) {
        throw new ResourceException(L.l("Connection '{0}' was not valid on creation", poolItem));
      }

      _connectionCreateCountTotal.incrementAndGet();

      synchronized (_connectionPool) {
        _connectionPool.add(poolItem);
      }

      poolItem = null;
      isValid = true;

      return userPoolItem;
    } finally {
      if (!isValid) {
        _connectionFailCountTotal.incrementAndGet();
        _lastFailTime = CurrentTime.getCurrentTime();
      }

      // server/308b - connection removed on rollback-only, when it's
      // theoretically possible to reuse it
      if (poolItem != null) poolItem.destroy();
    }
  }
  private boolean handleFault(int i) {
    Handler handler = _chain.get(i);

    boolean success = false;
    _invoked[i] = true;

    try {
      if (handler instanceof LogicalHandler) {
        _logicalContext.getMessage().setPayload(_source);
        success = handler.handleFault(_logicalContext);
        _source = _logicalContext.getMessage().getPayload();
      } else if (handler instanceof SOAPHandler) {
        try {
          _soapContext.setMessage(_source);
          success = handler.handleFault(_soapContext);
          _source = _soapContext.getMessage().getSOAPPart().getContent();
        } catch (SOAPException e) {
          throw new WebServiceException(e);
        }
      } else {
        throw new WebServiceException(
            L.l("Unsupported Handler type: {0}", handler.getClass().getName()));
      }

      _protocolException = null;
    } catch (ProtocolException e) {
      _protocolException = e;
      serializeProtocolException();
    } catch (RuntimeException e) {
      _runtimeException = e;
      serializeRuntimeException();
    }

    return success;
  }
 /** A unique id for the api, required. */
 public void setId(String id) throws ConfigException {
   for (int i = 0; i < id.length(); i++) {
     if (!Character.isJavaIdentifierPart(id.charAt(i)))
       throw new ConfigException(L.l("illegal character in `{0}': {1}", "id", id.charAt(i)));
   }
   _id = id;
 }
  public static Filter getFilter(Env env, Value filterIdV) {
    int filterId;

    int defaultFilterId = FILTER_UNSAFE_RAW;

    if (filterIdV.isDefault()) {
      // XXX: lookup in ini
      filterId = defaultFilterId;
    } else if (filterIdV.isArray()) {
      Value value = filterIdV.get(env.createString("filter"));

      if (value.isNull()) {
        filterId = defaultFilterId;
      } else {
        filterId = value.toInt();
      }
    } else {
      filterId = filterIdV.toInt();
    }

    Filter filter = _filterMap.get(filterId);

    if (filter == null) {
      throw new UnimplementedException(
          L.l("filter not implemented: {0} ({1})", filterIdV, filterId));
    }

    return filter;
  }
Example #22
0
  static String getPortType(Class impl, Class api) throws WebServiceException {
    WebService webService = (WebService) impl.getAnnotation(WebService.class);

    if (webService != null) {
      if ("".equals(webService.name()) && "".equals(webService.endpointInterface()))
        return impl.getSimpleName();

      if (!"".equals(webService.name()) && "".equals(webService.endpointInterface()))
        return webService.name();

      if ("".equals(webService.name()) && !"".equals(webService.endpointInterface())) {
        webService = (WebService) api.getAnnotation(WebService.class);

        if (webService != null && !"".equals(webService.name())) return webService.name();
        else return api.getSimpleName();
      }

      if (!"".equals(webService.name()) && !"".equals(webService.endpointInterface()))
        throw new WebServiceException(
            L.l(
                "Cannot specify both name and endpointInterface properties in a WebService annotation: {0}",
                impl));
    }

    return impl.getSimpleName();
  }
Example #23
0
  /** Lists the names for the context. */
  public NamingEnumeration list(Name name) throws NamingException {
    AbstractModel model = _model;

    if (name == null) {
      return new QNameClassEnumeration(create(model, _env), model.list());
    }

    for (int i = 0; i < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) return ((Context) value).list(name.getSuffix(i + 1));
      else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    return new QNameClassEnumeration(create(model, _env), model.list());
  }
  /**
   * Notifies that an application has closed the connection.
   *
   * <p>Remove and close the UserPoolItem associated with the PoolItem. If it's the last
   * UserPoolItem, move to the idle state.
   */
  public void connectionClosed(ConnectionEvent event) {
    Object handle = event.getConnectionHandle();

    if (!_hasConnectionError && handle == null && _shareHead != null) {
      log.fine(
          L.l(
              "JCA close event '{0}' for {1} did not have a connection handle.  Please notify the JCA resource provider.",
              event, _mConn));
    }

    UserPoolItem ptr = _shareHead;
    UserPoolItem prev = null;

    while (ptr != null) {
      UserPoolItem next = ptr.getShareNext();

      Object userConn = ptr.getUserConnection();

      if (userConn == handle || handle == null) {
        if (prev != null) prev.setShareNext(next);
        else _shareHead = next;

        ptr.close();
      } else prev = ptr;

      ptr = next;
    }

    if (_shareHead == null) {
      toIdle();
      return;
    }
  }
Example #25
0
  /** Looks up an object with the given parsed JNDI name, but don't dereference the final object. */
  public Object lookupLink(Name name) throws NamingException {
    if (name == null) return create(_model, _env);

    AbstractModel model = _model;

    for (int i = 0; i < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      if (i + 1 == name.size()) {
        if (value == NullValue.NULL) return null;
        else if (value != null) return value;
        else throw new NameNotFoundException(getFullPath(name));
      }

      value = dereference(value, null, model);

      if (value instanceof Context) return ((Context) value).lookupLink(name.getSuffix(i + 1));
      else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    return create(getFullPath(name), model, _env);
  }
  /** Creates the child bean. */
  @Override
  public Object create(Object parent, QName qName) throws ConfigException {
    Class<?> cl = TypeFactory.loadClass(qName);

    if (cl == null) {
      ConfigType<?> type = TypeFactory.getFactory().getEnvironmentType(qName);

      if (type != null) return type.create(parent, qName);

      throw new ConfigException(
          L.l(
              "'{0}.{1}' is an unknown class for element '{2}'",
              qName.getNamespaceURI(), qName.getLocalName(), qName));
    }

    if (Annotation.class.isAssignableFrom(cl)) {
      return new AnnotationConfig(cl);
    } else {
      XmlBeanConfig<?> config = new XmlBeanConfig(qName, cl, parent);
      config.setInlineBean(true);

      // config.setScope("singleton");

      return config;
    }
  }
  @Override
  public ConfigProgram introspectMethod(AnnotatedMethod<?> method) {
    PersistenceContext pContext = method.getAnnotation(PersistenceContext.class);

    Method javaMethod = method.getJavaMember();
    String location = getLocation(javaMethod);

    Class<?> param = javaMethod.getParameterTypes()[0];

    if (!param.isAssignableFrom(EntityManager.class)) {
      throw new ConfigException(
          L.l(
              "{0}: @PersistenceContext method must be assignable from EntityManager.",
              getLocation(javaMethod)));
    }

    BeanValueGenerator gen;

    /*
    if (PersistenceContextType.EXTENDED.equals(type))
      return generateExtendedContext(field, pContext);
    else
    */

    gen = generateTransactionContext(location, pContext);

    return new MethodGeneratorProgram(javaMethod, gen);
  }
Example #28
0
  /** List the bindings for a context. */
  public NamingEnumeration listBindings(String name) throws NamingException {
    String tail = name;
    AbstractModel model = _model;

    while (true) {
      String first = parseFirst(tail);
      String rest = parseRest(tail);

      if (first == null) {
        return new QBindingEnumeration(create(model, _env), model.list());
      }

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        tail = rest;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) return ((Context) value).listBindings(rest);
      else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }
  }
  /** 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);
    }
  }
Example #30
0
  protected SimpleXMLElement(
      Env env, QuercusClass cls, SimpleXMLElement parent, String name, String namespace) {
    _env = env;
    _cls = cls;

    _parent = parent;

    int p = name.indexOf(':');

    if (p > 0) {
      _name = name.substring(p + 1);
      _prefix = name.substring(0, p);
    } else _name = name;

    if ("".equals(_name)) throw new IllegalArgumentException(L.l("name can't be empty"));

    _namespace = namespace;

    if (namespace != null) {
      if (_prefix == null) _prefix = "";

      if (!hasNamespace(_prefix, namespace)) {
        String ns;

        if ("".equals(_prefix)) ns = "xmlns";
        else ns = "xmlns:" + _prefix;

        addNamespaceAttribute(env, ns, namespace);
      }
    }
  }