예제 #1
0
 /**
  * For each port of the given entity, if the port's derived level is greater than 0 (i.e., it is
  * created automatically by the entity), store the persistent attributes of the port in a "port"
  * XML element.
  *
  * @param entity The entity whose ports are looked at.
  * @param output The output writer.
  * @param depth The depth for the MoML output.
  * @exception IOException If the output writer cannot be written to.
  */
 public static void exportPortProperties(GTEntity entity, Writer output, int depth)
     throws IOException {
   if (entity instanceof Entity) {
     Entity ptEntity = (Entity) entity;
     for (Object portObject : ptEntity.portList()) {
       Port port = (Port) portObject;
       if (port.getDerivedLevel() == 0) {
         continue;
       }
       boolean outputStarted = false;
       for (Object attributeObject : port.attributeList()) {
         Attribute attribute = (Attribute) attributeObject;
         if (attribute.isPersistent()) {
           if (!outputStarted) {
             output.write(
                 StringUtilities.getIndentPrefix(depth)
                     + "<port name=\""
                     + port.getName()
                     + "\">\n");
             outputStarted = true;
           }
           attribute.exportMoML(output, depth + 1);
         }
       }
       if (outputStarted) {
         output.write(StringUtilities.getIndentPrefix(depth) + "</port>\n");
       }
     }
   }
 }
예제 #2
0
  /**
   * Check whether the attribute is unique in the given container.
   *
   * @param attribute The attribute to check.
   * @param container The container.
   * @exception IllegalActionException If the container already has an attribute in the same class.
   */
  public static void checkUniqueness(Attribute attribute, NamedObj container)
      throws IllegalActionException {
    if (container instanceof EntityLibrary) {
      return;
    }

    try {
      container.workspace().getReadAccess();
      List<? extends Attribute> attributeList = container.attributeList(attribute.getClass());
      for (Attribute existingAttribute : attributeList) {
        if (existingAttribute != attribute && existingAttribute.isPersistent()) {
          _delete(attribute);
          throw new IllegalActionException(
              "Only 1 " + attribute.getClass().getSimpleName() + " can be used.");
        }
      }
    } finally {
      container.workspace().doneReading();
    }
  }