Exemplo n.º 1
0
 /**
  * Get the children of the given object. The children can be either attributes, ports, entities,
  * or relations if permitted by the arguments.
  *
  * @param object The object.
  * @param includeAttributes Whether the children can be attributes.
  * @param includePorts Whether the children can be ports.
  * @param includeEntities Whether the children can be entities.
  * @param includeRelations Whether the children can be relations.
  * @return The collection of children.
  */
 public static Collection<NamedObj> getChildren(
     NamedObj object,
     boolean includeAttributes,
     boolean includePorts,
     boolean includeEntities,
     boolean includeRelations) {
   Collection<NamedObj> collection = new CombinedCollection<NamedObj>();
   if (includeAttributes) {
     collection.addAll(object.attributeList());
   }
   if (includePorts && object instanceof Entity) {
     Entity entity = (Entity) object;
     collection.addAll(entity.portList());
   }
   if (object instanceof CompositeEntity) {
     CompositeEntity entity = (CompositeEntity) object;
     if (includeEntities) {
       collection.addAll(entity.entityList());
     }
     if (includeRelations) {
       collection.addAll(entity.relationList());
     }
   }
   return collection;
 }
Exemplo n.º 2
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");
       }
     }
   }
 }