Package com.caucho.util

Examples of com.caucho.util.CharBuffer


  /**
   * Generates the clause to create the column.
   */
  String generateCreateTableSQL(AmberPersistenceUnit manager)
  {
    CharBuffer cb = new CharBuffer();
    cb.append(_name + " ");
    String sqlType = _sqlType;

    if (_sqlType != null)
      sqlType = _sqlType;
    else {
      sqlType = _type.generateCreateColumnSQL(manager, _length, _precision, _scale);
    }

    String generatorType = _generatorType;
   
    if ("auto".equals(_generatorType)
        && manager.getMetaData().supportsIdentity())
      generatorType = "identity";

    if ("identity".equals(generatorType))
      cb.append(manager.getMetaData().createIdentitySQL(sqlType));
    else
      cb.append(sqlType);

    if (isPrimaryKey()) {
      cb.append(" primary key");
    } else if (! "identity".equals(generatorType)) {
      if (isNotNull())
        cb.append(" not null");
      if (isUnique())
        cb.append(" unique");
    }

    return cb.toString();
  }
View Full Code Here


   * Generates the target select.
   */
  @Override
  public String generateTargetSelect(String id)
  {
    CharBuffer cb = CharBuffer.allocate();

    Id key = getEntityTargetType().getId();

    cb.append(key.generateSelect(id));

    String value = getEntityTargetType().generateLoadSelect(id);

    if (cb.length() > 0 && value.length() > 0)
      cb.append(", ");

    cb.append(value);

    return cb.close();
  }
View Full Code Here

   *
   * @return a mangled string.
   */
  protected String mangleMethodName(String name, Class []param, boolean isFull)
  {
    CharBuffer cb = CharBuffer.allocate();
   
    cb.append(name);
   
    for (int i = 0; i < param.length; i++) {
      cb.append('_');
      mangleClass(cb, param[i], isFull);
    }

    return cb.close();
  }
View Full Code Here

  {
    _index = 0;

    _returnType = parseType(skipWhitespace(read()));

    CharBuffer cb = CharBuffer.allocate();
    int ch = skipWhitespace(read());

    for (; Character.isJavaIdentifierPart((char) ch); ch = read())
      cb.append((char) ch);

    if (cb.length() == 0)
      throw new ConfigException(L.l("unexpected empty function name in '{0}'",
                                        _signature));

    _name = cb.toString();

    ch = skipWhitespace(ch);

    if (ch != '(')
      throw new ConfigException(L.l("function syntax is 'ret-type name(arg1, ..., argn)' in '{0}'",
View Full Code Here

   * Parses the type.
   */
  private Class parseType(int ch)
    throws ConfigException
  {
    CharBuffer cb = CharBuffer.allocate();

    for (; Character.isJavaIdentifierPart((char) ch); ch = read())
      cb.append((char) ch);

    if (cb.length() == 0)
      throw new ConfigException(L.l("unexpected empty type in '{0}'",
                                        _signature));

    String className = cb.toString();

    unread(ch);

    return findClass(className);
  }
View Full Code Here

   *
   * @return a mangled string.
   */
  protected String mangleMethodName(String name, Method method, boolean isFull)
  {
    CharBuffer cb = CharBuffer.allocate();
   
    cb.append(name);
   
    Class []params = method.getParameterTypes();
    for (int i = 0; i < params.length; i++) {
      cb.append('_');
      mangleClass(cb, params[i], isFull);
    }

    return cb.close();
  }
View Full Code Here

   */
  public static HashMap<String,String> splitNameList(String name)
    throws IOException
  {
    HashMap<String,String> attrs = new HashMap<String,String>();
    CharBuffer cb = new CharBuffer();

    int length = name.length();
    int i = 0;
    int ch = 0;
    while (i < length) {
      for (; i < length && XmlChar.isWhitespace(ch = name.charAt(i)); i++) {
      }

      if (i < length && ! XmlChar.isNameStart(ch))
        throw new IOException("expected name at " + (char) ch);
     
      cb.clear();
      while (i < length && XmlChar.isNameChar(ch)) {
        cb.append((char) ch);

        ch = name.charAt(++i);
      }
      String key = cb.toString();
      cb.clear();

      for (; i < length && XmlChar.isWhitespace(ch = name.charAt(i)); i++) {
      }

      if (ch != '=') {
        attrs.put(key, "");
        continue;
      }

      while (++i < length && XmlChar.isWhitespace(ch = name.charAt(i))) {
      }

      if (i >= length)
        break;

      cb.clear();
      if (ch == '\'') {
        while (++i < length && (ch = name.charAt(i)) != '\'')
          cb.append((char) ch);
        i++;
      } else if (ch == '"') {
        while (++i < length && (ch = name.charAt(i)) != '\"')
          cb.append((char) ch);
        i++;
      } else if (XmlChar.isNameChar(ch)) {
        cb.append((char) ch);
        while (++i < length && XmlChar.isNameChar(ch = name.charAt(i)))
          cb.append((char) ch);
      } else
        throw new IOException("unexpected");

      attrs.put(key, cb.toString());
    }

    return attrs;
  }
View Full Code Here

   * @param key the attribute key
   * @return the value corresponding to the attribute key.
   */
  public static String getPIAttribute(String pi, String key)
  {
    CharBuffer nameBuf = new CharBuffer();
    CharBuffer valueBuf = new CharBuffer();

    int i = 0;
    int length = pi.length();;
    while (i < length) {
      int ch = 0;
      for (; i < length && XmlChar.isWhitespace(ch = pi.charAt(i)); i++) {
      }

      nameBuf.clear();
      for (; i < length && XmlChar.isNameChar(ch = pi.charAt(i)); i++)
        nameBuf.append((char) ch);

      for (; i < length && XmlChar.isWhitespace(ch = pi.charAt(i)); i++) {
      }
     
      if (i < length && ch != '=') {
        if (nameBuf.length() == 0)
          return null;
        else if (nameBuf.toString().equals(key))
          return nameBuf.toString();
        else
          continue;
      }

      i++;
      for (; i < length && XmlChar.isWhitespace(ch = pi.charAt(i)); i++) {
      }

      // Parse the attribute value: '.*' or ".*" or \w+
      valueBuf.clear();
      if (ch == '\'') {
        i++;
        for (; i < length && (ch = pi.charAt(i)) != '\''; i++)
          valueBuf.append((char) ch);
        i++;
      }
      else if (ch == '\"') {
        i++;
        for (; i < length && (ch = pi.charAt(i)) != '\"'; i++)
          valueBuf.append((char) ch);
        i++;
      }
      else if (XmlChar.isNameChar(ch)) {
        for (; i < length && XmlChar.isNameChar(ch = pi.charAt(i)); i++)
          valueBuf.append((char) ch);
      }
      else
        return null; // XXX: should throw an exception?

      String name = nameBuf.toString();
      if (name.equals(key))
        return valueBuf.toString();
    }

    return null;
  }
View Full Code Here

   */
  public static String textValue(Node node)
  {
    if (node instanceof Element || node instanceof DocumentFragment) {
      String s = null;
      CharBuffer cb = null;
     
      for (Node child = node.getFirstChild();
           child != null;
           child = child.getNextSibling()) {
        String value = null;
       
        if (child instanceof Element || child instanceof Document) {
          if (cb == null)
            cb = CharBuffer.allocate();
          if (s != null)
            cb.append(s);
          s = null;

          textValue(cb, child);
        }
        else if ((value = child.getNodeValue()) == null || value == "") {
        }
        else if (cb != null)
          cb.append(value);
        else if (s == null && s != "") {
          s = value;
        }
        else {
          cb = CharBuffer.allocate();

          cb.append(s);
          cb.append(value);
          s = null;
        }
      }

      if (s != null)
        return s;
      else if (cb != null)
        return cb.close();
      else
        return "";
    }
    else {
      String value = node.getNodeValue();
View Full Code Here

  @Override
  public String generateSelect(String id)
  {
    ArrayList<IdField> keys = getKeys();

    CharBuffer cb = CharBuffer.allocate();

    for (int i = 0; i < keys.size(); i++) {
      if (i != 0)
        cb.append(", ");

      cb.append(keys.get(i).generateSelect(id));
    }

    return cb.close();
  }
View Full Code Here

TOP

Related Classes of com.caucho.util.CharBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.