Пример #1
0
  /**
   * Creates a new instance of Object. The object will contain instances of all the classes in the
   * <code>classes</code> collection.
   *
   * @todo Could we pass a DataType in here?
   * @param classes The classes which this object should
   * @throws LemRuntimeException if the <code>classes</code> collection does not represent a valid
   *     type for the new object
   */
  public Object(DomainContext c, Collection classes) throws LemRuntimeException {
    context = c;
    objectId = ArbitraryIdVariable.getInstance();
    System.out.println(objectId + " : Object Created");

    // Do these classes actually participate in the same inheritance
    // hierarchy?
    if (!validClasses(classes)) {
      throw new LemRuntimeException("Specified class list will not produce a valid Object");
    }

    // Maintain a list of classes already instantiated
    ArrayList instantiatedClasses = new ArrayList();

    for (Iterator i = classes.iterator(); i.hasNext(); ) {
      org.jdns.xtuml.metamodel.Class theClass = (org.jdns.xtuml.metamodel.Class) i.next();
      Instance inst = new Instance(theClass, this);

      // Instantiate all parent classes as well
      Collection gens = theClass.getAllGeneralisations().values();

      for (Iterator j = gens.iterator(); j.hasNext(); ) {
        Generalisation g = (Generalisation) j.next();

        org.jdns.xtuml.metamodel.Class superClass = g.getSuperclass();
        /* The root class of a generalisation hierarchy can
         * appear in more than one call to "getAllGeneraliations",
         * but we don't want to instantiate it again
         */
        if (instantiatedClasses.contains(superClass)) {
          continue;
        }

        instantiatedClasses.add(superClass);
        Instance superInst = new Instance(superClass, this);
        addInstance(superInst);
      }

      addInstance(inst);
    }
  }
Пример #2
0
 public Object(DomainContext c) {
   context = c;
   objectId = ArbitraryIdVariable.getInstance();
 }