Exemple #1
0
  public void printAttributeName(PrintNode row, AttributePath attributePath, Adapter scda)
      throws Exception {
    for (int j = 0; j < attributes.size(); j++) {
      Attribute currentAttribute = (Attribute) attributes.get(j);
      int attributeLength = currentAttribute.name.length() + 2;

      if (currentAttribute.getClass() == DVA.class && attributePath.levelsOfIndirection() <= 0) {
        // If the attribute we want is found or we just want everything, output
        if (attributePath.attribute.equals("*")) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format("%s", currentAttribute.name));
          row.addCell(cell);
        } else if (attributePath.attribute.equals(currentAttribute.name)) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format("%s", currentAttribute.name));
          row.addCell(cell);
          return;
        }
      }
      if (currentAttribute.getClass() == EVA.class && attributePath.levelsOfIndirection() > 0) {
        String evaName = attributePath.getIndirection(attributePath.levelsOfIndirection() - 1);
        if (evaName.equals(currentAttribute.name)) {
          ClassDef targetClass = scda.getClass(((EVA) currentAttribute).baseClassName);
          attributePath.removeIndirection(attributePath.levelsOfIndirection() - 1);
          targetClass.printAttributeName(row, attributePath, scda);
          attributePath.addIndirection(evaName);
          return;
        }
      }
    }

    // Got here if we didn't get what we need in this class
    int i = 0;
    while (i < superClasses.size()) {
      try {
        ClassDef superClass = scda.getClass(((String) superClasses.get(i)));
        superClass.printAttributeName(row, attributePath, scda);
        i++;
      } catch (NoSuchFieldException nsfe) {
        if (i < superClasses.size()) {
          i++;
        } else {
          throw nsfe;
        }
      }
    }
  }
Exemple #2
0
  public void padAttribute(PrintNode row, AttributePath attributePath, Adapter scda)
      throws Exception {
    for (int j = 0; j < attributes.size(); j++) {
      Attribute currentAttribute = (Attribute) attributes.get(j);
      int attributeLength = currentAttribute.name.length();

      if (currentAttribute.getClass() == DVA.class && attributePath.levelsOfIndirection() <= 0) {
        // If the attribute we want is found or we just want everything, output
        if (attributePath.attribute.equals("*")) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format(""));
          row.addCell(cell);
        } else if (attributePath.attribute.equals(currentAttribute.name)) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format(""));
          row.addCell(cell);
          return;
        }
      }
      if (currentAttribute.getClass() == EVA.class && attributePath.levelsOfIndirection() > 0) {
        String evaName = attributePath.getIndirection(attributePath.levelsOfIndirection() - 1);
        if (evaName.equals(currentAttribute.name)) {
          ClassDef targetClass = scda.getClass(((EVA) currentAttribute).baseClassName);
          attributePath.removeIndirection(attributePath.levelsOfIndirection() - 1);
          targetClass.padAttribute(row, attributePath, scda);
          attributePath.addIndirection(evaName);
          return;
        }
      }
    }

    if (!(attributePath.attribute.equals("*") && attributePath.levelsOfIndirection() <= 0)) {
      // If we got here and we weren't trying to output all the attributes, we didn't find the
      // requested attribute.

      if (this.getClass() == SubclassDef.class) {
        for (int i = 0; i < ((SubclassDef) this).numberOfSuperClasses(); i++) {
          ClassDef parentClass = scda.getClass(((SubclassDef) this).getSuperClass(i));
          parentClass.padAttribute(row, attributePath, scda);
        }
      } else {
        throw new NoSuchFieldException(
            "Attribute \"" + attributePath.attribute + "\" is not a valid DVA");
      }
    }
  }
Exemple #3
0
 public boolean isSubclassOf(String superClassName, Adapter scda) throws Exception {
   // See if its one of my immediate superclasses.
   if (superClasses.contains(superClassName)) {
     return true;
   }
   // Not immediate superclass of me. Check my parents.
   ClassDef superClass;
   for (int i = 0; i < superClasses.size(); i++) {
     superClass = scda.getClass(((String) superClasses.get(i)));
     if (superClass.isSubclassOf(superClassName, scda)) {
       return true;
     }
   }
   // Not any superClass of mine!
   return false;
 }
Exemple #4
0
  public WDBObject newInstance(WDBObject baseParent, Adapter scda) throws Exception {
    Integer newUid = new Integer(Math.abs((new UID()).hashCode()));
    WDBObject newObject =
        new WDBObject(
            new Hashtable<String, Integer>(),
            new Hashtable<String, Integer>(),
            new Hashtable<String, Object>(),
            new Hashtable<String, Object>(),
            this.name,
            newUid);

    for (int i = 0; i < this.superClasses.size(); i++) {
      ClassDef superClass = scda.getClass((String) this.superClasses.get(i));
      WDBObject parent;
      if (baseParent == null || !superClass.name.equals(baseParent.getClassName())) {
        if (superClass.getClass() == SubclassDef.class) {
          // If this super class is another subclass, then create a new instance of one of those
          // with this object as the child and the parent we want to attach to
          parent = superClass.newInstance(baseParent, scda);
        } else {
          // If this super class is a base class, then create a new isntance but don't pass the
          // parent we want to attach since its a base class
          parent = superClass.newInstance(null, scda);
        }
      } else {
        // The base parent is my immediate parent
        parent = baseParent;
      }

      WDBObject childObject = parent.getChildObject(this.name, scda);

      if (childObject != null) {
        // Parent alreadly extended to this class, just return the child instance
        return childObject;
      }

      parent.addChildObject(newObject);
      parent.commit(scda);
      newObject.addParentObject(parent);
    }

    this.addInstance(newUid);
    this.commit(scda);

    return newObject;
  }
Exemple #5
0
 public ClassDef getBaseClass(Adapter scda) throws Exception {
   // Assume all of our superclasses go back to the same base class alreadly
   ClassDef superClass;
   superClass = scda.getClass(((String) superClasses.get(0)));
   return superClass.getBaseClass(scda);
 }