예제 #1
0
  void setClassName(String newClassName) {
    if (newClassName != null && newClassName.trim().length() == 0) {
      newClassName = null;
    }

    Embeddable embeddable = mediator.getCurrentEmbeddable();

    if (embeddable == null) {
      return;
    }

    if (Util.nullSafeEquals(newClassName, embeddable.getClassName())) {
      return;
    }

    if (newClassName == null) {
      throw new ValidationException("Embeddable name is required.");
    } else if (embeddable.getDataMap().getEmbeddable(newClassName) == null) {

      // if newClassName dupliucates in other DataMaps
      DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
      if (domain != null) {
        for (DataMap nextMap : domain.getDataMaps()) {
          if (nextMap == embeddable.getDataMap()) {
            continue;
          }

          Embeddable conflictingEmbeddable = nextMap.getEmbeddable(newClassName);
          if (conflictingEmbeddable != null) {
            throw new ValidationException(
                "Duplicate Embeddable name in another DataMap: " + newClassName + ".");
          }
        }
      }

      // completely new name, set new name for embeddable
      EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
      String oldName = embeddable.getClassName();
      embeddable.setClassName(newClassName);

      mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());

      Iterator it =
          ((DataChannelDescriptor) mediator.getProject().getRootNode()).getDataMaps().iterator();
      while (it.hasNext()) {
        DataMap dataMap = (DataMap) it.next();
        Iterator<ObjEntity> ent = dataMap.getObjEntities().iterator();

        while (ent.hasNext()) {

          Collection<ObjAttribute> attr = ent.next().getAttributes();
          Iterator<ObjAttribute> attrIt = attr.iterator();

          while (attrIt.hasNext()) {
            ObjAttribute atribute = attrIt.next();
            if (atribute.getType() == null || atribute.getType().equals(oldName)) {
              atribute.setType(newClassName);
              AttributeEvent ev = new AttributeEvent(this, atribute, atribute.getEntity());
              mediator.fireObjAttributeEvent(ev);
            }
          }
        }
      }

    } else {
      // there is an embeddable with the same name
      throw new ValidationException(
          "There is another embeddable with name '" + newClassName + "'.");
    }
  }
예제 #2
0
 private void initFromModel(Embeddable embeddable) {
   className.setText(embeddable.getClassName());
 }