Esempio n. 1
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());
  }
Esempio n. 2
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));
  }
Esempio n. 3
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));
    }
  }
Esempio n. 4
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));
    }
  }
Esempio n. 5
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);
  }
Esempio n. 6
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);
  }
Esempio n. 7
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);
  }
 @Override
 public void initialize(Scanner s) {
   double start = System.currentTimeMillis();
   int count = readChars(s);
   double end = System.currentTimeMillis();
   double time = (end - start) / 1000.0;
   super.messageViews("#read: " + count + " chars in: " + time + " secs");
 }
Esempio n. 9
0
  /**
   * Binds an object to the context, overriding any old value.
   *
   * @param name the name to bind
   * @param obj the object to bind
   */
  @Override
  public void rebind(String name, Object obj) throws NamingException {
    if (log.isLoggable(Level.FINEST)) log.finest(L.l("JNDI rebind `{0}' value: {1}", name, obj));

    String tail = name;
    AbstractModel model = _model;

    // env/0gde
    if (obj == null) obj = NullValue.NULL;

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

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

      if (rest == null) {
        model.bind(first, getReference(model, obj));
        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).rebind(rest, obj);
        return;
      } else if (value != null)
        throw new NotContextException(
            L.l(
                "{0}: expected intermediate context at '{1}'\n  {2}",
                getFullPath(name), value, Thread.currentThread().getContextClassLoader()));
      else
        throw new NameNotFoundException(
            L.l(
                "{0}: JNDI rebind requires the parent Context '{1}' to be created but it is null.\n  {2}',",
                getFullPath(name), first, Thread.currentThread().getContextClassLoader()));
    }
  }
Esempio n. 10
0
  /** Binds an object to the context. */
  public void bind(String name, Object obj) throws NamingException {
    String tail = name;
    AbstractModel model = _model;

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

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

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

      if (rest == null) {
        Object value = model.lookup(first);

        if (value != null)
          throw new NamingException(L.l("`{0}' is already bound to `{1}'", name, value));

        model.bind(first, getReference(model, obj));

        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).bind(rest, 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));
      }
    }
  }
Esempio n. 11
0
  boolean update(SQLiteDatabase db) {
    ContentValues cv = new ContentValues();
    super.update(cv);
    if (alarmId > 0) cv.put(COL_ALARMID, alarmId);
    if (datetime > 0) cv.put(COL_DATETIME, datetime);
    if (status != null) cv.put(COL_STATUS, status);

    return db.update(TABLE_NAME, cv, COL_ID + " = ?", new String[] {String.valueOf(id)}) == 1
        ? true
        : false;
  }
Esempio n. 12
0
 @Override
 public void closeIterator(Iterator<?> iter) {
   super.closeIterator(iter);
   if (iter instanceof StatementIterator) {
     try {
       ((StatementIterator) iter).stmts.close();
     } catch (RepositoryException e) {
       throw new ModelException(e);
     }
   }
 }
Esempio n. 13
0
  @Override
  public void loadBean(ModelBean b, boolean loadReferenceIds) {
    CheckUtils.isNotNull(b);
    CheckUtils.isInstanceOf(b, LocationBean.class);

    LocationBean bean = (LocationBean) b;

    this.setDescription(bean.getDescription());
    this.setLatitude(bean.getLatitude());
    this.setLongitude(bean.getLongitude());

    super.loadBean(bean, loadReferenceIds);
  }
Esempio n. 14
0
  /** Looks up an object given the name, but doesn't dereference links. */
  @Override
  public Object lookupLink(String name) throws NamingException {
    String tail = name;
    AbstractModel model = _model;

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

      if (first == null) {
        return create(getFullPath(name), model, _env);
      }

      Object value = model.lookup(first);

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

      if (rest == null) {
        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(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));
    }

    return create(getFullPath(name), model, _env);
  }
Esempio n. 15
0
 static String getSql() {
   return Util.concat(
       "CREATE TABLE ",
       TABLE_NAME,
       " (",
       AbstractModel.getSql(),
       COL_ALARMID,
       " INTEGER, ",
       COL_DATETIME,
       " INTEGER, ",
       COL_STATUS,
       " TEXT",
       ");");
 }
Esempio n. 16
0
  public Object clone() {
    ModelImpl cloned = new ModelImpl();
    super.cloneTo(cloned);
    cloned.type = this.type;
    cloned.name = this.name;
    cloned.required = this.required;
    cloned.properties = this.properties;
    cloned.isSimple = this.isSimple;
    cloned.description = this.description;
    cloned.example = this.example;
    cloned.additionalProperties = this.additionalProperties;
    cloned.discriminator = this.discriminator;
    cloned.xml = this.xml;
    cloned.defaultValue = this.defaultValue;

    return cloned;
  }
Esempio n. 17
0
 public boolean load(SQLiteDatabase db) {
   Cursor cursor =
       db.query(
           TABLE_NAME, null, COL_ID + " = ?", new String[] {String.valueOf(id)}, null, null, null);
   try {
     if (cursor.moveToFirst()) {
       reset();
       super.load(cursor);
       alarmId = cursor.getLong(cursor.getColumnIndex(COL_ALARMID));
       datetime = cursor.getLong(cursor.getColumnIndex(COL_DATETIME));
       status = cursor.getString(cursor.getColumnIndex(COL_STATUS));
       return true;
     }
     return false;
   } finally {
     cursor.close();
   }
 }
Esempio n. 18
0
 /** 在目标模型上添加该连接线 */
 public void attachTarget() {
   // 连接的尾端添加到Source
   if (!target.getTargetConnections().contains(this)) {
     target.addTargetConnection(this);
   }
 }
Esempio n. 19
0
 /** 在源模型上删除该连接线 */
 public void detachSource() {
   source.removeSourceConnection(this);
 }
Esempio n. 20
0
 /** 在目标模型上删除该连接线 */
 public void detachTarget() {
   target.removeTargetConnection(this);
 }
Esempio n. 21
0
 public void reset() {
   super.reset();
   alarmId = 0;
   datetime = 0;
   status = null;
 }
Esempio n. 22
0
 /** 在源模型上添加该连接线 */
 public void attachSource() {
   // 连接的头端添加到Source
   if (!source.getSourceConnections().contains(this)) {
     source.addSourceConnection(this);
   }
 }