public String resolveSuperClassType(DataObject dataObject) {
   StringBuffer type = new StringBuffer("");
   if (dataObject.getSuperClassName() != null && !"".equals(dataObject.getSuperClassName())) {
     type.append("extends ");
     type.append(dataObject.getSuperClassName());
   }
   return type.toString();
 }
 public String resolveAllFieldsConstructor(DataObject dataObject, String indent) {
   if (!dataObject.getProperties().isEmpty()) {
     List<ObjectProperty> sortedProperties = new ArrayList<ObjectProperty>();
     sortedProperties.addAll(dataObject.getProperties().values());
     return resolveConstructor(dataObject, sortByPosition(sortedProperties), indent);
   }
   return "";
 }
Exemplo n.º 3
0
 /** Removes save cookie from the DO. */
 final void removeSaveCookie() {
   DataObject dataObj = getDataObject();
   // add Save cookie to the data object
   if (dataObj instanceof MultiDataObject) {
     if (dataObj.getCookie(SaveCookie.class) == this) {
       getCookieSet((MultiDataObject) dataObj).remove(this);
     }
   }
 }
 public void testGetDataObject() {
   DataCollection allItems = getDefaultCollection();
   int count = 0;
   while (allItems.next()) {
     DataObject obj = allItems.getDataObject();
     assertEquals("Somehow failed to retrieve a Node?", "Node", obj.getObjectType().getName());
     count++;
   }
   assertTrue("No data objects?", count > 0);
 }
  public String resolveEquals(DataObject dataObject, String indent) {

    StringBuilder head = new StringBuilder();
    // head.append(EOL);
    head.append(indent + "@Override" + EOL);
    head.append(indent + "public boolean equals(Object o) {" + EOL);
    head.append(indent + TAB + "if (this == o) return true;" + EOL);
    head.append(indent + TAB + "if (o == null || getClass() != o.getClass()) return false;" + EOL);
    head.append(
        indent
            + TAB
            + dataObject.getClassName()
            + " that = ("
            + dataObject.getClassName()
            + ")o;"
            + EOL);

    StringBuilder end = new StringBuilder();
    end.append(indent + "}");

    StringBuilder sb = new StringBuilder();
    Map<String, ObjectProperty> props = dataObject.getProperties();

    boolean hasTerms = false;
    if (props != null && props.size() > 0) {
      for (String propName : props.keySet()) {
        ObjectProperty prop = props.get(propName);
        String _propName = toJavaVar(propName);
        if (prop.getAnnotation(org.kie.api.definition.type.Key.class.getName()) != null) {
          // Construction: "if (<_propName> != null ? !<_propName>.equals(that.<_propName>) :
          // that.<_propName> != null) return false;"
          sb.append(indent + TAB + "if (");
          sb.append(_propName)
              .append(" != null ? !")
              .append(_propName)
              .append(".equals(that.")
              .append(_propName)
              .append(")");
          sb.append(" : that.").append(_propName).append(" != null").append(") return false;");
          sb.append(EOL);
          hasTerms = true;
        }
      }
    }

    if (hasTerms) {
      sb.append(indent + TAB + "return true;" + EOL);
      head.append(sb);
      head.append(end);
      return head.toString();
    } else {
      return "";
    }
  }
Exemplo n.º 6
0
 public void propertyChange(java.beans.PropertyChangeEvent ev) {
   if (Node.PROP_DISPLAY_NAME.equals(ev.getPropertyName())) {
     updateTitles();
   }
   if (Node.PROP_ICON.equals(ev.getPropertyName())) {
     DataObject obj = getDataObject();
     if (obj.isValid()) {
       editor.setIcon(obj.getNodeDelegate().getIcon(java.beans.BeanInfo.ICON_COLOR_16x16));
     }
   }
 }
Exemplo n.º 7
0
 /** Overrides superclass method. Initializes editor component. */
 protected void initializeCloneableEditor(CloneableEditor editor) {
   DataObject obj = getDataObject();
   if (obj.isValid()) {
     org.openide.nodes.Node ourNode = obj.getNodeDelegate();
     editor.setActivatedNodes(new org.openide.nodes.Node[] {ourNode});
     editor.setIcon(ourNode.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16));
     NodeListener nl = new DataNodeListener(editor);
     ourNode.addNodeListener(WeakListener.node(nl, ourNode));
     nodeL = nl;
   }
 }
 public String resolveKeyFieldsConstructor(DataObject dataObject, String indent) {
   if (!dataObject.getProperties().isEmpty()) {
     List<ObjectProperty> sortedProperties = new ArrayList<ObjectProperty>();
     for (ObjectProperty property : dataObject.getProperties().values()) {
       if (property.getAnnotation(KeyAnnotationDefinition.getInstance().getClassName()) != null) {
         // the property is marked as key.
         sortedProperties.add(property);
       }
     }
     if (sortedProperties.size() > 0
         && sortedProperties.size() < dataObject.getProperties().size()) {
       return resolveConstructor(dataObject, sortByPosition(sortedProperties), indent);
     }
   }
   return "";
 }
Exemplo n.º 9
0
 /*
 public Compiler(int numbr, String nme, String hndl, String pth, String clsPath, String srcPath, String stdPath, String outFileName)
 {
   number = numbr;
   name = nme;
   handle = hndl;
   path = pth;
   classPath = clsPath;
   sourcePath = srcPath;
   studentPath = stdPath;
   outputFileName = outFileName;
   success = 1;  // Outcome of compilation, success = 0
 }
 */
 public Compiler(DataObject data) {
   number = data.numbr;
   name = data.nme;
   handle = data.hndl;
   path = data.pth;
   classPath = data.clsPath;
   sourcePath = data.srcPath;
   studentPath = data.stdPath;
   outputFileName = data.outFileName;
   success = data.success; // Outcome of compilation, success = 0
   System.out.println("COMPILER CONSTRUCTOR:\n" + data.showDataObject());
 }
  /**
   * return editor cookie for this filehandler
   *
   * @throws CollabException
   * @return cookie
   */
  public EditorCookie getEditorCookie() throws CollabException {
    Debug.log(
        this,
        "CollabJavaHandler, "
            + // NoI18n
            "geteditorCookie for file: "
            + getName()); // NoI18n

    try {
      if (editorCookie == null) {
        FileObject file = getFileObject();

        // Get the FileObject
        if (file == null) {
          return null;
        }

        // Get the DataObject
        DataObject dataObject = DataObject.find(file);

        if (dataObject == null) {
          throw new IllegalArgumentException("No DataObject found for file \"" + getName() + "\"");
        }

        // Get the editor cookie for the file
        editorCookie = (EditorCookie) dataObject.getCookie(EditorCookie.class);

        // add reset Document Reference Listener
        addResetDocumentRefListener(editorCookie, getEditorObservableCookie());
      }

      return editorCookie;
    } catch (org.openide.loaders.DataObjectNotFoundException notFound) {
      throw new CollabException(notFound);
    } catch (java.io.IOException io) {
      throw new CollabException(io);
    }
  }
  /**
   * return document object for this file
   *
   * @throws CollabException
   * @return document
   */
  public StyledDocument getDocument() throws CollabException {
    try {
      FileObject file = getFileObject();

      // Get the DataObject
      DataObject dataObject = DataObject.find(file);

      if (dataObject == null) {
        throw new IllegalArgumentException("No DataObject found for file \"" + getName() + "\"");
      }

      // Get the Swing document for the file
      EditorCookie cookie = (EditorCookie) dataObject.getCookie(EditorCookie.class);

      StyledDocument document = cookie.openDocument();

      return document;
    } catch (org.openide.loaders.DataObjectNotFoundException notFound) {
      throw new CollabException(notFound);
    } catch (java.io.IOException io) {
      throw new CollabException(io);
    }
  }
Exemplo n.º 12
0
  public String resolveHashCode(DataObject dataObject, String indent) {

    StringBuilder head = new StringBuilder();
    // head.append(EOL);
    head.append(indent + "@Override" + EOL);
    head.append(indent + "public int hashCode() {" + EOL);
    head.append(indent + TAB + "int result = 17;" + EOL);

    StringBuilder end = new StringBuilder();
    end.append(indent + "}");

    StringBuilder sb = new StringBuilder();
    Map<String, ObjectProperty> props = dataObject.getProperties();

    boolean hasTerms = false;
    if (props != null && props.size() > 0) {
      for (String propName : props.keySet()) {
        ObjectProperty prop = props.get(propName);
        String _propName = toJavaVar(propName);
        if (prop.getAnnotation(org.kie.api.definition.type.Key.class.getName()) != null) {
          // Construction: "result = 13 * result + (<_propName> != null ? <_propName>.hashCode() :
          // 0);"
          sb.append(indent + TAB + "result = 13 * result + (")
              .append(_propName)
              .append(" != null ? ")
              .append(_propName)
              .append(".hashCode() : 0);");
          sb.append(EOL);
          hasTerms = true;
        }
      }
    }

    if (hasTerms) {
      sb.append(indent + TAB + "return result;" + EOL);
      head.append(sb);
      head.append(end);
      return head.toString();
    } else {
      return "";
    }
  }
Exemplo n.º 13
0
  public String resolveConstructor(
      DataObject dataObject, List<ObjectProperty> properties, String indent) {

    StringBuilder head = new StringBuilder();
    StringBuilder body = new StringBuilder();

    head.append(indent + "public " + dataObject.getName() + "(");

    if (properties != null && properties.size() > 0) {
      boolean isFirst = true;
      String propertyName;
      for (ObjectProperty property : properties) {
        if (!isFirst) {
          head.append(", ");
          body.append(EOL);
        }
        propertyName = toJavaVar(property.getName());
        head.append(resolveAttributeType(property));
        head.append(" ");
        head.append(propertyName);

        body.append(indent);
        body.append(indent);
        body.append("this.");
        body.append(propertyName);
        body.append(" = ");
        body.append(propertyName);
        body.append(";");

        isFirst = false;
      }
      body.append(EOL);
    }

    head.append(") {" + EOL);
    head.append(body);
    head.append(indent + "}");

    return head.toString();
  }
  /**
   * This method process the information for the txt files layouts that are not related with the
   * Qualifying questions layout.
   *
   * @param parseInputObject
   * @param sc
   * @param contRow
   * @param contCol
   * @param mapDataByCol
   * @param mapDataByRow
   * @param mapDataByMatrix
   * @param listColumnsNames
   */
  private static void parseRowColumIdxLayout(
      ParseInputObject parseInputObject,
      Scanner sc,
      Integer contRow,
      Integer contCol,
      Map<String, List<DataObject>> mapDataByCol,
      Map<String, List<DataObject>> mapDataByRow,
      Map<Integer, List<DataObject>> mapDataByMatrix,
      List<String> listColumnsNames) {
    Map<Integer, String> dataMap = new HashMap<Integer, String>();

    while (sc.hasNextLine()) {
      String valueX = sc.nextLine();
      List<DataObject> listMapDataByRow = new ArrayList<DataObject>();
      String rowName = "";

      if (valueX.isEmpty() == false) {
        Scanner sc1 = new Scanner(valueX);
        sc1.useDelimiter("\\t");
        while (sc1.hasNext()) {
          String valueY = sc1.next();
          boolean validated = false;

          if ((parseInputObject.getParseType() == PARSE_TYPES.BYCOLUMNNAME
                  && valueY.isEmpty() == false)
              || (parseInputObject.getParseType() == PARSE_TYPES.BYROWFIELD)
              || parseInputObject.getParseType() == PARSE_TYPES.ROWINDEX) {
            validated = true;
          }

          if (validated) {
            /*
             * LOG.debug("valueX3 : " + Pattern.compile("\\t").matcher(valueX).replaceAll("").length());
             */
            DataObject dataObject = new DataObject();
            dataObject.setColPos(contCol);
            dataObject.setRowNum(contRow);
            dataObject.setData(valueY);

            if (contRow == 0 && parseInputObject.getParseType() == PARSE_TYPES.BYCOLUMNNAME) {
              mapDataByCol.put(valueY, new ArrayList<DataObject>());
              dataMap.put(contCol, valueY);
            } else if (contCol == 0 && parseInputObject.getParseType() == PARSE_TYPES.BYROWFIELD) {
              rowName = valueY;
            }

            if (parseInputObject.getParseType() == PARSE_TYPES.BYROWFIELD && contCol > 0) {
              listMapDataByRow.add(dataObject);
            } else if (parseInputObject.getParseType() == PARSE_TYPES.BYCOLUMNNAME && contRow > 0) {
              String value = dataMap.get(contCol);

              if (mapDataByCol.containsKey(value)) {
                List<DataObject> listColumns = mapDataByCol.get(value);
                listColumns.add(dataObject);
                mapDataByCol.put(value, listColumns);
              }

            } else if (parseInputObject.getParseType() == PARSE_TYPES.ROWINDEX && contRow == 0) {
              listColumnsNames.add(valueY);
              /*
               *LOG.debug("listColumnsNames : " + listColumnsNames);
               */
            } else if (parseInputObject.getParseType() == PARSE_TYPES.ROWINDEX && contRow > 0) {
              dataObject.setColumnName(listColumnsNames.get(contCol));
              listMapDataByRow.add(dataObject);
            }
          }
          contCol++;
        }
      }

      if (parseInputObject.getParseType() == PARSE_TYPES.BYROWFIELD
          && !rowName.isEmpty()
          && !listMapDataByRow.isEmpty()) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Rp3UtilityParser parse rowName : " + rowName);
        }
        mapDataByRow.put(rowName, listMapDataByRow);
      } else if (parseInputObject.getParseType() == PARSE_TYPES.ROWINDEX) {
        mapDataByMatrix.put(contRow, listMapDataByRow);
      }

      contRow++;
      contCol = 0;
    }
  }
Exemplo n.º 15
0
 /**
  * Constructor
  *
  * @param obj data object we belong to. The appropriate editor support is acquired as the
  *     DataObject's EditorSupport.class cookie.
  */
 public Editor(DataObject obj) {
   this(obj, (EditorSupport) obj.getCookie(EditorSupport.class));
 }
  public void testReferenceLinkAttribute() {
    Session ssn = SessionManager.getSession();
    DataObject user = ssn.create(getModelName() + ".User");
    user.set("id", BigInteger.valueOf(0));
    user.set("email", "*****@*****.**");
    user.set("firstName", "foo");
    user.set("lastNames", "bar");
    user.save();

    DataObject[] images = new DataObject[2];
    for (int i = 0; i < images.length; i++) {
      images[i] = ssn.create(getModelName() + ".Image");
      images[i].set("id", BigInteger.valueOf(i));
      byte[] bytes = "This is the image.".getBytes();
      images[i].set("bytes", bytes);
      images[i].save();
    }

    // set image
    user.set("image", images[0]);
    user.save();

    // retrieve and then update caption
    DataAssociationCursor dac = ((DataAssociation) images[0].get("users")).cursor();
    dac.next();
    assertNull(dac.getLinkProperty("caption"));
    assertEquals(user, dac.getDataObject());
    DataObject link = dac.getLink();
    link.set("caption", "caption");
    link.save();

    dac = ((DataAssociation) images[0].get("users")).cursor();
    dac.next();
    assertEquals("caption", dac.getLinkProperty("caption"));
    assertEquals(1L, ((DataAssociation) images[0].get("users")).size());

    // set new image as image
    user.set("image", images[1]);
    user.save();

    // check that old image is no longer associated with user
    assertEquals(0L, ((DataAssociation) images[0].get("users")).size());

    // check that new image is associated with user and has no caption
    dac = ((DataAssociation) images[1].get("users")).cursor();
    dac.next();
    assertNull(dac.getLinkProperty("caption"));
    assertEquals(1L, ((DataAssociation) images[1].get("users")).size());
  }
  private DataCollection getOrderCollection() {
    int id = 1;
    Calendar now = Calendar.getInstance();
    int currentDay = now.get(Calendar.DAY_OF_YEAR);

    DataObject order = getSession().create("examples.Order");
    order.set("id", new BigDecimal(id++));
    order.set("buyer", "Rafael H. Schloming");
    order.set("shippingAddress", "102 R Inman St.\nCambridge MA, 02139");
    order.set("seller", "ArsDigita");
    order.set("shippingDate", now.getTime());
    order.set("hasShipped", Boolean.FALSE);
    order.save();

    now.set(Calendar.DAY_OF_YEAR, ++currentDay);

    order = getSession().create("examples.Order");
    order.set("id", new BigDecimal(id++));
    order.set("buyer", "Jon Orris");
    order.set("shippingAddress", "80 Prospect St");
    order.set("shippingDate", now.getTime());
    order.set("hasShipped", Boolean.TRUE);
    order.set("seller", "ArsDigita");
    order.save();
    now.set(Calendar.DAY_OF_YEAR, ++currentDay);

    order = getSession().create("examples.Order");
    order.set("id", new BigDecimal(id++));
    order.set("buyer", "Foo Bar");
    order.set("shippingAddress", "Nowhere, MA");
    order.set("shippingDate", now.getTime());
    order.set("seller", "ArsDigita");
    order.set("hasShipped", Boolean.TRUE);
    order.save();
    now.set(Calendar.DAY_OF_YEAR, ++currentDay);

    order = getSession().create("examples.Order");
    order.set("id", new BigDecimal(id++));
    order.set("buyer", "Micro Soft");
    order.set("shippingAddress", "Redmond, WA");
    order.set("shippingDate", now.getTime());
    order.set("seller", "ArsDigita");
    order.set("hasShipped", Boolean.TRUE);
    order.save();
    now.set(Calendar.DAY_OF_YEAR, ++currentDay);

    order = getSession().create("examples.Order");
    order.set("id", new BigDecimal(id++));
    order.set("buyer", "Micro Soft");
    order.set("shippingAddress", "Redmond, WA");
    order.set("shippingDate", now.getTime());
    order.set("seller", "FooBar consulting");
    order.set("hasShipped", Boolean.TRUE);
    order.save();
    now.set(Calendar.DAY_OF_YEAR, ++currentDay);

    order = getSession().create("examples.Order");
    order.set("id", new BigDecimal(id++));
    order.set("buyer", "Foo Bar");
    order.set("shippingAddress", "Nowhere, MA");
    order.set("shippingDate", now.getTime());
    order.set("seller", "Smurf!");
    order.set("hasShipped", Boolean.TRUE);
    order.save();

    return getSession().retrieve("examples.Order");
  }
Exemplo n.º 18
0
  public ProjectEvent(Object source, DataObject contextObject, String action) {

    this(source, contextObject.getObjectType(), action, contextObject);
  }
  public void testDeepLink() {
    Session ssn = SessionManager.getSession();

    DataObject[] users = new DataObject[4];

    DataObject group = getSession().create(getModelName() + ".Group");
    group.set("id", BigInteger.valueOf(users.length));
    group.set("email", "*****@*****.**");
    group.set("name", "SIPB");
    group.save();
    DataAssociation members = (DataAssociation) group.get("members");

    for (int i = 0; i < users.length; i++) {
      users[i] = ssn.create(getModelName() + ".User");
      users[i].set("id", BigInteger.valueOf(i));
      users[i].set("email", "*****@*****.**");
      users[i].set("firstName", "foo");
      users[i].set("lastNames", "bar");
      users[i].save();
      members.add(users[i]);
    }
    group.save();

    DataObject[] images = new DataObject[users.length / 2];
    for (int i = 0; i < images.length; i++) {
      images[i] = ssn.create(getModelName() + ".Image");
      images[i].set("id", BigInteger.valueOf(i));
      byte[] bytes = "This is the image.".getBytes();
      images[i].set("bytes", bytes);
      images[i].save();
    }

    // create link between user i and image i/2 with caption i
    for (int i = 0; i < users.length; i++) {
      // set image
      DataAssociation imageUsers = (DataAssociation) images[i / 2].get("users");
      DataObject link = imageUsers.add(users[i]);
      link.set("caption", String.valueOf(i));
      link.save();
    }

    DataCollection dc = ssn.retrieve(getModelName() + ".Group");
    dc.addEqualsFilter("members.image.link.caption", "0");
    assertEquals(1, dc.size());

    dc = ssn.retrieve(getModelName() + ".User");
    dc.addPath("image.link.caption");
    assertEquals(users.length, dc.size());
    while (dc.next()) {
      assertEquals(dc.get("id").toString(), dc.get("image.link.caption"));
    }

    dc = ssn.retrieve(getModelName() + ".User");
    dc.addPath("image.id");
    assertEquals(users.length, dc.size());
    while (dc.next()) {
      int id = ((BigInteger) dc.get("id")).intValue();
      assertEquals(BigInteger.valueOf(id / 2), dc.get("image.id"));
    }

    DataCollection dcUp = ssn.retrieve(getModelName() + ".User");
    DataCollection dcDown = ssn.retrieve(getModelName() + ".User");
    dcUp.addOrder("image.link.caption asc");
    dcDown.addOrder("image.link.caption desc");
    dcUp.next();
    dcDown.next();
    assertEquals(BigInteger.valueOf(0), dcUp.get("id"));
    assertEquals(BigInteger.valueOf(users.length - 1), dcDown.get("id"));
    dcUp.close();
    dcDown.close();

    dcUp = ssn.retrieve(getModelName() + ".Image");
    dcDown = ssn.retrieve(getModelName() + ".Image");
    dcUp.addOrder("users.link.caption asc");
    dcDown.addOrder("users.link.caption desc");
    dcUp.next();
    dcDown.next();
    assertEquals(BigInteger.valueOf(0), dcUp.get("id"));
    assertEquals(BigInteger.valueOf(images.length - 1), dcDown.get("id"));
    dcUp.close();
    dcDown.close();

    dc = ssn.retrieve(getModelName() + ".Group");
    dc.addFilter("members.image.id = 0");
    assertEquals(2, dc.size());

    dc = ssn.retrieve(getModelName() + ".Image");
    dc.addFilter("users.id = 0 and users.link.caption = '1'");
    assertEquals(0, dc.size());

    dc = ssn.retrieve(getModelName() + ".Group");
    dc.addPath("members.id");
    dc.addFilter("members.image.id = 0 and members.image.link.caption = '1'");
    assertTrue(dc.next());
    assertEquals(BigInteger.valueOf(1), dc.get("members.id"));
    assertFalse(dc.next());
  }
  protected void setUp() {
    DataObject parent = getSession().create("examples.Node");
    m_nodeType = parent.getObjectType();
    parent.set("id", new BigDecimal(0));
    parent.set("name", "Root");
    parent.save();

    for (int i = 1; i < 10; i++) {
      DataObject child = getSession().create("examples.Node");
      child.set("id", new BigDecimal(i));
      child.set("name", "child" + i);
      child.set("parent", parent);
      child.save();
      parent.save();

      parent = child;
    }
  }