コード例 #1
0
  public Component getEntityByCFCName(String cfcName, boolean unique) throws PageException {
    String name = cfcName;
    int pointIndex = cfcName.lastIndexOf('.');
    if (pointIndex != -1) {
      name = cfcName.substring(pointIndex + 1);
    } else cfcName = null;

    ComponentPro cfc;
    String[] names = null;
    // search array (array exist when cfcs is in generation)

    if (arr != null) {
      names = new String[arr.size()];
      int index = 0;
      Iterator<ComponentPro> it2 = arr.iterator();
      while (it2.hasNext()) {
        cfc = it2.next();
        names[index++] = cfc.getName();
        if (isEntity(cfc, cfcName, name)) // if(cfc.equalTo(name))
        return unique ? (Component) cfc.duplicate(false) : cfc;
      }
    } else {
      // search cfcs
      Iterator<Entry<String, CFCInfo>> it = cfcs.entrySet().iterator();
      Entry<String, CFCInfo> entry;
      while (it.hasNext()) {
        entry = it.next();
        cfc = entry.getValue().getCFC();
        if (isEntity(cfc, cfcName, name)) // if(cfc.instanceOf(name))
        return unique ? (Component) cfc.duplicate(false) : cfc;

        // if(name.equalsIgnoreCase(HibernateCaster.getEntityName(cfc)))
        //	return cfc;
      }
      names = cfcs.keySet().toArray(new String[cfcs.size()]);
    }

    // search by entityname //TODO is this ok?
    CFCInfo info = cfcs.get(name.toLowerCase());
    if (info != null) {
      cfc = info.getCFC();
      return unique ? (Component) cfc.duplicate(false) : cfc;
    }

    throw new ORMException(
        this,
        "entity ["
            + name
            + "] "
            + (StringUtil.isEmpty(cfcName) ? "" : "with cfc name [" + cfcName + "] ")
            + "does not exist, existing  entities are ["
            + railo.runtime.type.List.arrayToList(names, ", ")
            + "]");
  }