コード例 #1
1
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and shape.
  *
  * @return Returns true, if the polygon is inside of the image bounds.
  */
 private boolean writePolyAttributes(IXMLElement elem, SVGFigure f, Shape shape) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     StringBuilder buf = new StringBuilder();
     float[] coords = new float[6];
     GeneralPath path = new GeneralPath();
     for (PathIterator i = shape.getPathIterator(t, 1.5f);
     ! i.isDone(); i.next()) {
         switch (i.currentSegment(coords)) {
             case PathIterator.SEG_MOVETO :
                 if (buf.length() != 0) {
                     throw new IllegalArgumentException("Illegal shape "+shape);
                 }
                 if (buf.length() != 0) {
                     buf.append(',');
                 }
                 buf.append((int) coords[0]);
                 buf.append(',');
                 buf.append((int) coords[1]);
                 path.moveTo(coords[0], coords[1]);
                 break;
             case PathIterator.SEG_LINETO :
                 if (buf.length() != 0) {
                     buf.append(',');
                 }
                 buf.append((int) coords[0]);
                 buf.append(',');
                 buf.append((int) coords[1]);
                 path.lineTo(coords[0], coords[1]);
                 break;
             case PathIterator.SEG_CLOSE :
                 path.closePath();
                 break;
             default :
                 throw new InternalError("Illegal segment type "+i.currentSegment(coords));
         }
     }
     elem.setAttribute("shape", "poly");
     elem.setAttribute("coords", buf.toString());
     writeHrefAttribute(elem, f);
     return path.intersects(new Rectangle2D.Float(bounds.x, bounds.y, bounds.width, bounds.height));
 }
コード例 #2
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
コード例 #3
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
  /** @brief Generates the signature for the class constructors */
  private static void generateSignature(IndentWriter writer, IXMLElement constructor)
      throws IOException {
    assert (DebugMsg.debugMsg("ClassWriter", "Begin ClassWriter::generateSignature"));
    writer.write("constructor(");
    boolean comma = false;
    for (Enumeration e = constructor.enumerateChildren(); e.hasMoreElements(); ) {
      IXMLElement element = (IXMLElement) e.nextElement();
      if (!element.getName().equals("arg")) {
        break;
      }
      String argType = XMLUtil.typeOf(element);
      String argName = XMLUtil.getAttribute(element, "name");
      if (comma) {
        writer.write(", ");
      }

      // Argument are structured as: <arg name="argName" type="argType"/>
      if (argType.equals(NddlXmlStrings.x_int)) writer.write("int " + argName);
      else if (argType.equals(NddlXmlStrings.x_float)) writer.write("double " + argName);
      else if (argType.equals(NddlXmlStrings.x_boolean)) writer.write("bool " + argName);
      else if (argType.equals(NddlXmlStrings.x_string)
          || argType.equals(NddlXmlStrings.x_symbol)
          || ModelAccessor.isEnumeration(argType)) writer.write("const LabelStr& " + argName);
      else writer.write("const " + argType + "Id& " + argName);

      comma = true;
    }
    writer.write(")");
    assert (DebugMsg.debugMsg("ClassWriter", "End ClassWriter::generateSignature"));
  }
コード例 #4
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
  /**
   * Helper method to generate the signatures for binding the factory. Must account for the
   * inheritance relationships for any arguments that are classes. Ths, each argument can
   * potentially result in a range of values for type, and we have to handle the cross product of
   * all of these.
   */
  private static Vector makeFactoryNames(IXMLElement constructor) {
    String factoryName = XMLUtil.nameOf(constructor.getParent());
    Vector allPermutations = new Vector();
    for (Enumeration e = constructor.enumerateChildren(); e.hasMoreElements(); ) {
      IXMLElement element = (IXMLElement) e.nextElement();

      if (!element.getName().equals("arg")) {
        break;
      }

      String argType = XMLUtil.typeOf(element);
      Vector argTypeAlternates = new Vector();
      argTypeAlternates.add(argType);

      if (ModelAccessor.isClass(argType)) {
        List ancestors = ModelAccessor.getAncestors(argType);
        if (ancestors != null) argTypeAlternates.addAll(ancestors);
      }

      allPermutations.add(argTypeAlternates);
    }

    // Generate all the signatures
    Vector factoryNames = new Vector();
    makeFactoryNames(factoryName, allPermutations, 0, factoryNames);
    return factoryNames;
  }
コード例 #5
0
 private void writePolygonElement(IXMLElement parent, SVGPathFigure f) throws IOException {
     IXMLElement elem = parent.createElement("area");
     if (writePolyAttributes(elem, f, new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)).
             createStrokedShape(f.getChild(0).getBezierPath())
             )) {
         parent.addChild(elem);
     }
 }
コード例 #6
0
 private void writeEllipseElement(IXMLElement parent, SVGEllipseFigure f) throws IOException  {
     IXMLElement elem = parent.createElement("area");
     Rectangle2D.Double r = f.getBounds();
     double grow = getPerpendicularHitGrowth(f);
     Ellipse2D.Double ellipse = new Ellipse2D.Double(r.x - grow, r.y - grow, r.width + grow, r.height + grow);
     if (writeCircleAttributes(elem, f, ellipse)) {
         parent.addChild(elem);
     }
 }
コード例 #7
0
 private void writeLineElement(IXMLElement parent, SVGPathFigure f) throws IOException {
     IXMLElement elem = parent.createElement("area");
     if (writePolyAttributes(elem, f, new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)).
             createStrokedShape(new Line2D.Double(
             f.getStartPoint(), f.getEndPoint()
             )))) {
         parent.addChild(elem);
     }
 }
コード例 #8
0
 private void writeHrefAttribute(IXMLElement elem, SVGFigure f) {
     if (LINK.get(f) != null && LINK.get(f).trim().length() > 0) {
         elem.setAttribute("href", LINK.get(f));
         elem.setAttribute("title", LINK.get(f));
         elem.setAttribute("alt", LINK.get(f));
     } else {
         elem.setAttribute("nohref", "true");
     }
 }
コード例 #9
0
 private void writeTextAreaElement(IXMLElement parent, SVGTextAreaFigure f) throws IOException {
     IXMLElement elem = parent.createElement("AREA");
     Rectangle2D.Double rect = f.getBounds();
     double grow = getPerpendicularHitGrowth(f);
     rect.x -= grow;
     rect.y -= grow;
     rect.width += grow;
     rect.height += grow;
     if (writeRectAttributes(elem, f, rect)) {
         parent.addChild(elem);
     }
 }
コード例 #10
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
 private static String getVariableType(Vector classVariables, String name) {
   String type = "!ERROR";
   for (int i = 0; i < classVariables.size(); i++) {
     IXMLElement variable = (IXMLElement) classVariables.elementAt(i);
     if (XMLUtil.nameOf(variable).equals(name)) {
       type = XMLUtil.getAttribute(variable, "type");
       String _class = XMLUtil.getAttribute(variable.getParent(), "name");
       if (ModelAccessor.isEnumeration(_class + "::" + type)) type = _class + "::" + type;
       break;
     }
   }
   return type;
 }
コード例 #11
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
  /**
   * Builds the argument invocation string for calling a constructor
   *
   * @param classVariables The collection of member variables as XMLElements
   * @param constructorArguments The set of names for constructor arguments
   * @param allocatedMemberVariables The set of member variables already allocated
   * @param element The specific 'new' xml element
   */
  private static String buildArguments(
      Vector classVariables,
      Set constructorArguments,
      Set allocatedMemberVariables,
      IXMLElement element)
      throws IOException {
    XMLUtil.checkExpectedNode("new", element);

    boolean comma = false;
    String arguments = "";
    for (Enumeration e = element.enumerateChildren(); e.hasMoreElements(); ) {
      IXMLElement argument = (IXMLElement) e.nextElement();
      String argType = ModelAccessor.getValueType(argument);
      String value = ModelAccessor.getValue(argument);

      /* Exclude cases where we do nothing to the value */
      if (!primitives.contains(argType) && !value.equals("true") && !value.equals("false")) {
        // CASE 0: Translate 'this'
        if (value.equalsIgnoreCase("this")) {
          value = "m_id";
        }

        // CASE 1: It is a singleton member variable which must be mapped to the singleton
        else if (allocatedMemberVariables.contains(value)) {
          String singletonType = getVariableType(classVariables, value);
          if (primitives.contains(singletonType)) {
            value = "(" + singletonType + ") singleton(" + value + ")";
          } else value = "singleton(" + value + ")";
        }

        // CASE 2: It is a constructor argument
        else if (constructorArguments.contains(value)) { // Do nothing, just use the string as is.
        }

        // CASE 3: Test for error - using a member before initializing it
        else if (!allocatedMemberVariables.contains(value) && isMember(classVariables, value)) {
          value = "!ERROR: Cannot use " + value + " without prior initialization.";
        }

        // Otherwise it is a string or enumerataion
        else if (argType.equals("string")
            || // It is an enumeartion of some kind
            ModelAccessor.isEnumeration(argType)
            || argType.equals("symbol")) {
          value = "LabelStr(\"" + XMLUtil.escapeQuotes(value) + "\")";
        }

        // If we fall through to here, there is an error.
        else value = "!ERROR:BAD ASSIGNMENT";
      }

      // CASE 3: It is a true or false value
      if (comma) arguments = arguments + ", ";

      arguments = arguments + value;
      comma = true;
    }

    return arguments;
  }
コード例 #12
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
  public static void generateImplementation(IndentWriter writer, IXMLElement klass)
      throws IOException {
    String superClass = ModelAccessor.getSuperClass(klass);
    String name = XMLUtil.getAttribute(klass, "name");

    if (ModelAccessor.isPredefinedClass(name)) {
      writer.write("// SKIPPING IMPLEMENTATION FOR BUILT-IN CLASS " + name + "\n\n");
      return;
    }

    ModelAccessor.setCurrentObjectType(name);

    String longname = XMLUtil.qualifiedName(klass);

    boolean extendsBuiltIn = ModelAccessor.isPredefinedClass(superClass);

    String superCppClass = ModelAccessor.getCppClass(superClass);

    writer.write("\n");
    SharedWriter.generateFileLocation(writer, klass);
    writer.write(
        longname + "::" + name + "(const PlanDatabaseId& planDatabase, const LabelStr& name)\n");
    if (extendsBuiltIn)
      writer.write(" : " + superCppClass + "(planDatabase, \"" + name + "\", name, true)");
    else writer.write(" : " + superCppClass + "(planDatabase, \"" + name + "\", name)");
    writer.write(" {\n");
    writer.write("}\n");

    writer.write(
        longname
            + "::"
            + name
            + "(const PlanDatabaseId& planDatabase, const LabelStr& type, const LabelStr& name)\n");
    if (extendsBuiltIn) writer.write(" : " + superCppClass + "(planDatabase, type, name, true)");
    else writer.write(" : " + superCppClass + "(planDatabase, type, name)");
    writer.write(" {\n");
    writer.write("}\n");

    writer.write(longname + "::" + name + "(const ObjectId& parent, const LabelStr& name)\n");
    if (extendsBuiltIn)
      writer.write(" : " + superCppClass + "(parent, \"" + name + "\", name, true)");
    else writer.write(" : " + superCppClass + "(parent, \"" + name + "\", name)");
    writer.write(" {}\n");

    writer.write(
        longname
            + "::"
            + name
            + "(const ObjectId& parent, const LabelStr& type, const LabelStr& name)\n");
    if (extendsBuiltIn) writer.write(" : " + superCppClass + "(parent, type, name, true)");
    else writer.write(" : " + superCppClass + "(parent, type, name)");
    writer.write(" {}\n");

    Vector classVariables = klass.getChildrenNamed("var");
    SharedWriter.defineHandleDefaults(writer, klass, classVariables);

    generateChildren(writer, klass);
    ModelAccessor.resetCurrentObjectType();
  }
コード例 #13
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
 private static void generateChildren(IndentWriter writer, IXMLElement parent) throws IOException {
   for (Enumeration e = parent.enumerateChildren(); e.hasMoreElements(); ) {
     IXMLElement element = (IXMLElement) e.nextElement();
     if (element.getName().equals("enum")) {
       EnumerationWriter.generateImplementation(writer, element);
     } else if (element.getName().equals("predicate")) {
       PredicateWriter.generateImplementation(writer, element);
     } else if (element.getName().equals("var")) {
     } else if (element.getName().equals("constructor")) {
       defineConstructor(writer, element);
       generateFactory(writer, element);
     } else {
       System.err.println("generateImplementation:");
       XMLUtil.dump(element);
     }
   }
 }
コード例 #14
0
 private void writePathElement(IXMLElement parent, SVGPathFigure f) throws IOException {
     GrowStroke growStroke = new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f));
     BasicStroke basicStroke = new BasicStroke((float) getStrokeTotalWidth(f));
     for (Figure child : f.getChildren()) {
         SVGBezierFigure bezier = (SVGBezierFigure) child;
         IXMLElement elem = parent.createElement("area");
         if (bezier.isClosed()) {
             writePolyAttributes(elem, f, growStroke.
                     createStrokedShape(bezier.getBezierPath())
                     );
         } else {
             writePolyAttributes(elem, f, basicStroke.
                     createStrokedShape(bezier.getBezierPath())
                     );
         }
         parent.addChild(elem);
     }
 }
コード例 #15
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
 public static void declareConstructor(IndentWriter writer, IXMLElement constructor)
     throws IOException {
   IXMLElement klass = constructor.getParent();
   SharedWriter.generateFileLocation(writer, klass);
   if (klass == null) {
     throw new RuntimeException("constructor not contained in a class");
   }
   String name = XMLUtil.getAttribute(klass, "name");
   writer.write("virtual void ");
   generateSignature(writer, constructor);
   writer.write(";\n");
 }
コード例 #16
0
  public void load(IXMLElement xml) throws Exception {
    super.load(xml);

    final int priority = parameters().getAttribute(PARAM_PRIORITY, 3);
    this.socials = new MudObjectInterpreter(getName(), priority, this);

    for (Enumeration enu = xml.enumerateChildren(); enu.hasMoreElements(); ) {

      IXMLElement nxt = (IXMLElement) enu.nextElement();
      String nom = nxt.getName();

      if (nom.equals(Social.MARKUP)) {

        this.socials.addCommand(Social.loadSocial(nxt));

      } else if (nom.equals(PROPERTY_SOCIALS)) {

        loadSocialsElement(nxt);
      }
    }
  }
コード例 #17
0
  public void loadSocialsElement(IXMLElement xml) throws Exception {
    String src = xml.getAttribute(PROPERTY_SRC, null);

    // If the passed xml element just points to a file
    if (src != null) {
      IXMLParser xmp = new StdXMLParser();
      xmp.setBuilder(new StdXMLBuilder());
      xmp.setValidator(new NonValidator());
      xmp.setReader(StdXMLReader.fileReader(src));

      xml = (XMLElement) xmp.parse();
      xmp = null;
    }

    int count = 0;
    for (Enumeration enu = xml.getChildrenNamed(Social.MARKUP).elements();
        enu.hasMoreElements();
        count++) {

      IXMLElement nxt = (IXMLElement) enu.nextElement();
      this.socials.addCommand(Social.loadSocial(nxt));
    }
  }
コード例 #18
0
 private void writeRectElement(IXMLElement parent, SVGRectFigure f) throws IOException {
     IXMLElement elem = parent.createElement("AREA");
     boolean isContained;
     if (f.getArcHeight() == 0 && f.getArcWidth() == 0) {
         Rectangle2D.Double rect = f.getBounds();
         double grow = getPerpendicularHitGrowth(f);
         rect.x -= grow;
         rect.y -= grow;
         rect.width += grow;
         rect.height += grow;
         isContained = writeRectAttributes(elem, f, rect);
     } else {
         isContained = writePolyAttributes(elem, f,
                 new GrowStroke((float) (getStrokeTotalWidth(f) / 2d), (float) getStrokeTotalWidth(f)).
                 createStrokedShape(new RoundRectangle2D.Double(
                 f.getX(), f.getY(), f.getWidth(), f.getHeight(),
                 f.getArcWidth(), f.getArcHeight()
                 )));
     }
     if (isContained) {
         parent.addChild(elem);
     }
 }
コード例 #19
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and rectangle.
  *
  * @return Returns true, if the rect is inside of the image bounds.
  */
 private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType()
             ) {
         
         Point2D.Double start = new Point2D.Double(rect.x, rect.y);
         Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height);
         t.transform(start, start);
         t.transform(end, end);
         Rectangle r = new Rectangle(
                 (int) Math.min(start.x, end.x),
                 (int) Math.min(start.y, end.y),
                 (int) Math.abs(start.x - end.x),
                 (int) Math.abs(start.y - end.y)
                 );
         
         elem.setAttribute("shape", "rect");
         elem.setAttribute("coords",
                 r.x + ","+
                 r.y + ","+
                 (r.x + r.width) + ","+
                 (r.y + r.height)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(r);
     } else {
         return writePolyAttributes(elem, f, (Shape) rect);
     }
 }
コード例 #20
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
  public static void defineConstructor(IndentWriter writer, IXMLElement constructor)
      throws IOException {
    assert (DebugMsg.debugMsg("ClassWriter", "Begin ClassWriter::defineConstructor"));
    IXMLElement klass = constructor.getParent();
    SharedWriter.generateFileLocation(writer, klass);

    if (klass == null) {
      throw new RuntimeException("missing class for constructor");
    }

    String longname = XMLUtil.nameOf(klass);
    writer.write("void " + longname + "::");
    generateSignature(writer, constructor);
    writer.write(" {\n");
    writer.indent();

    // If the constructor has a call to the super class, invoke it.
    assert (DebugMsg.debugMsg(
        "ClassWriter", "ClassWriter::defineConstructor -  getting children named 'super'"));
    Vector superCalls = constructor.getChildrenNamed("super");
    assert (DebugMsg.debugMsg(
        "ClassWriter",
        "ClassWriter::defineConstructor -  " + superCalls.size() + " children named retrieved"));
    if (!superCalls.isEmpty()) {
      assert (DebugMsg.debugMsg("ClassWriter", "ClassWriter::defineConstructor -  calling super"));

      if (superCalls.size() > 1) writer.write("!ERROR: AT MOST ONE CALL TO SUPER ALLOWED\n");

      IXMLElement superCall = (IXMLElement) superCalls.elementAt(0);
      String superClass = ModelAccessor.getParentClassName(klass);
      String superCppClass = ModelAccessor.getCppClass(superClass);
      writer.write(superCppClass + "::constructor(");
      String comma = "";
      Enumeration arguments = superCall.enumerateChildren();
      while (arguments.hasMoreElements()) {
        IXMLElement argument = (IXMLElement) arguments.nextElement();
        String value = ModelAccessor.getValue(argument);
        if (argument.getName().equals("value")
            && XMLUtil.getAttribute(argument, "type").equals("string"))
          writer.write(comma + "\"" + value + "\"");
        else writer.write(comma + value);
        comma = ", ";
      }
      writer.write(");\n");
    }

    Set allocatedMemberVariables = new HashSet(); // Store names as we go for reference

    /* Now capture names of constructor arguments */
    Set constructorArguments = new HashSet(); // Store for names of constructor arguments
    {
      Vector args = constructor.getChildrenNamed("arg");
      assert (DebugMsg.debugMsg(
          "ClassWriter",
          "ClassWriter::defineConstructor -  getting " + args.size() + " arguments"));
      for (int i = 0; i < args.size(); i++) {
        IXMLElement arg = (IXMLElement) args.elementAt(i);
        String argName = XMLUtil.getAttribute(arg, "name");
        constructorArguments.add(argName);
      }
    }

    Vector constructorAssignments = constructor.getChildrenNamed("assign");
    Vector classVariables = klass.getChildrenNamed("var");

    // Use the set below  to track when an assignment is being made more than once for same variable
    Set assignmentsMade = new HashSet();

    for (int i = 0; i < constructorAssignments.size(); i++) {
      IXMLElement element = (IXMLElement) constructorAssignments.elementAt(i);
      String target = XMLUtil.getAttribute(element, "name");

      if (assignmentsMade.contains(target)) {
        writer.write("!ERROR: Duplicate assignment for " + target + "\n");
      } else {
        assignmentsMade.add(target);
        // String type = getVariableType(classVariables, target);
        // trust in the parser, for it will assign the correct types
        String type = XMLUtil.getAttribute(element, "type");
        IXMLElement sourceElement = element.getChildAtIndex(0);

        if (sourceElement.getName().equals("new")) { // Handle object allocation
          assert (DebugMsg.debugMsg(
              "ClassWriter", "ClassWriter::defineConstructor -  allocating object for " + target));
          String sourceType = XMLUtil.typeOf(sourceElement);
          writer.write(target + " = addVariable(");
          writer.write(
              sourceType
                  + "Domain((new "
                  + sourceType
                  + "(m_id, \""
                  + target
                  + "\"))->getId(), \""
                  + sourceType
                  + "\")");
          writer.write(", " + makeObjectVariableNameString(target) + ");\n");
          writer.write(
              "Id<"
                  + type
                  + ">(singleton("
                  + target
                  + "))->constructor("
                  + buildArguments(
                      classVariables, constructorArguments, allocatedMemberVariables, sourceElement)
                  + ");\n"); // Invoke initialization
          writer.write(
              "Id<"
                  + type
                  + ">(singleton("
                  + target
                  + "))->handleDefaults();\n"); // Default variable setup
        } else { // Handle variable allocation
          String value = ModelAccessor.getValue(sourceElement);

          if (sourceElement.getName().equals("id") && type.equals(NddlXmlStrings.x_string))
            value = XMLUtil.escapeQuotes(value);
          else if (sourceElement.getName().equals(NddlXmlStrings.x_symbol)
              || XMLUtil.getAttribute(sourceElement, "type").equals(NddlXmlStrings.x_string))
            value = "LabelStr(\"" + XMLUtil.escapeQuotes(value) + "\")";
          else if (ModelAccessor.isNumericPrimitive(type)
              && !type.equals(NddlXmlStrings.x_boolean)) {
            // Set both bounds to singleton value
            value = value + ", " + value;
          }

          writer.write(target + " = addVariable(");

          if (allocatedMemberVariables.contains(
              value)) // If we are assigning one member to another, we obtain the base domain for it
          writer.write(value + "->baseDomain()");
          else writer.write(ModelAccessor.getDomain(type) + "(" + value + ", \"" + type + "\")");

          writer.write(", " + makeObjectVariableNameString(target) + ");\n");
        }
        // Add member to the set
        allocatedMemberVariables.add(target);
      }
    }

    writer.unindent();
    writer.write("}\n");
    assert (DebugMsg.debugMsg("ClassWriter", "End ClassWriter::defineConstructor"));
  }
コード例 #21
0
 private void writeImageElement(IXMLElement parent, SVGImageFigure f) {
     IXMLElement elem = parent.createElement("area");
     Rectangle2D.Double rect = f.getBounds();
     writeRectAttributes(elem, f, rect);
     parent.addChild(elem);
 }
コード例 #22
0
ファイル: ClassWriter.java プロジェクト: rpgoldman/europa-pso
  public static void generateFactory(IndentWriter writer, IXMLElement constructor)
      throws IOException {
    IXMLElement klass = constructor.getParent();
    SharedWriter.generateFileLocation(writer, klass);

    if (klass == null) throw new RuntimeException("missing class for factory");

    String longname = XMLUtil.nameOf(klass) + "Factory" + s_factoryCounter++;

    writer.write("class " + longname + ": public ObjectFactory {\n");
    writer.write("public:\n");
    writer.indent();
    writer.write(longname + "(const LabelStr& name): ObjectFactory(name){}\n");
    writer.unindent();
    writer.write("private:\n");
    writer.indent();
    writer.write("ObjectId createInstance(const PlanDatabaseId& planDb,\n");
    writer.write("                        const LabelStr& objectType, \n");
    writer.write("                        const LabelStr& objectName,\n");
    writer.write(
        "                        const std::vector<const AbstractDomain*>& arguments) const {\n");
    writer.indent();

    Vector constructorAssignments = constructor.getChildrenNamed("arg");
    String klassName = XMLUtil.nameOf(klass);
    String constructorArguments = "";
    String comma = "";

    // Do some type checking - at least the size must match!
    writer.write("check_error(arguments.size() == " + constructorAssignments.size() + ");\n");

    // Process arguments, defining local variables and giving them initial values
    for (int i = 0; i < constructorAssignments.size(); i++) {
      IXMLElement element = (IXMLElement) constructorAssignments.elementAt(i);
      String target = XMLUtil.getAttribute(element, "name");
      String type = XMLUtil.getAttribute(element, "type");
      writer.write("check_error(AbstractDomain::canBeCompared(*arguments[" + i + "], \n");
      writer.write(
          "                                          planDb->getConstraintEngine()->getCESchema()->baseDomain(\""
              + type
              + "\")), \n");
      writer.write(
          "            \"Cannot convert \" + arguments["
              + i
              + "]->getTypeName().toString() + \" to "
              + type
              + "\");\n");
      writer.write("check_error(arguments[" + i + "]->isSingleton());\n");

      String localVarType =
          makeArgumentType(
              type); // Some conversion may be required for Id's or strings or enumerations

      // Declare local variable for current argument
      writer.write(
          localVarType
              + " "
              + target
              + "(("
              + localVarType
              + ")arguments["
              + i
              + "]->getSingletonValue());\n\n");
      constructorArguments = constructorArguments + comma + target;
      comma = ", ";
    }

    // Now do the declaration and allocation of the instance
    writer.write(
        klassName
            + "Id instance = (new "
            + klassName
            + "(planDb, objectType, objectName))->getId();\n");
    writer.write("instance->constructor(" + constructorArguments + ");\n");
    writer.write("instance->handleDefaults();\n");
    writer.write("return instance;\n");
    writer.unindent();
    writer.write("}\n");
    writer.unindent();
    writer.write("};\n");

    // Generate all appropriate registration informationLabelStr
    Vector factoryNames = makeFactoryNames(constructor);
    for (int i = 0; i < factoryNames.size(); i++) {
      String factoryName = (String) factoryNames.elementAt(i);
      SchemaWriter.addFactory(
          "REGISTER_OBJECT_FACTORY(id," + longname + ", " + factoryName + ");\n");
    }
  }