@Test
  public void testAtt() {
    String nsUri = "nsUri";
    String prefix = "prefix";
    String localName = "localName";
    String value = "value";

    Attribute att = new Attribute(nsUri, localName, value);

    Assert.assertEquals(nsUri, att.getNamespace());
    Assert.assertEquals(localName, att.getName());
    Assert.assertEquals(value, att.getValue());

    String nsUri2 = "nsUri2";
    String prefix2 = "prefix2";
    String localName2 = "localName2";
    String value2 = "value2";

    att.setNsURI(nsUri2);
    att.setName(localName2);
    att.setValue(value2);

    Assert.assertEquals(nsUri2, att.getNamespace());
    Assert.assertEquals(localName2, att.getName());
    Assert.assertEquals(value2, att.getValue());
  }
  /**
   * An attribute will have the following 4bytes words :
   *
   * <ul>
   *   <li>0th word : index of namespace uri in StringIndexTable, or 0xFFFFFFFF for default NS
   *   <li>1st word : index of attribute name in StringIndexTable
   *   <li>2nd word : index of attribute value, or 0xFFFFFFFF if value is a typed value
   *   <li>3rd word : value type
   *   <li>4th word : resource id value
   * </ul>
   */
  private Attribute parseAttribute() {
    final int attrNSIdx = getLEWord(mParserOffset);
    final int attrNameIdx = getLEWord(mParserOffset + (1 * WORD_SIZE));
    final int attrValueIdx = getLEWord(mParserOffset + (2 * WORD_SIZE));
    final int attrType = getLEWord(mParserOffset + (3 * WORD_SIZE));
    final int attrData = getLEWord(mParserOffset + (4 * WORD_SIZE));

    final Attribute attr = new Attribute();
    attr.setName(getString(attrNameIdx));

    if (attrNSIdx == 0xFFFFFFFF) {
      attr.setNamespace(null);
      attr.setPrefix(null);
    } else {
      String uri = getString(attrNSIdx);
      if (mNamespaces.containsKey(uri)) {
        attr.setNamespace(uri);
        attr.setPrefix(mNamespaces.get(uri));
      }
    }

    if (attrValueIdx == 0xFFFFFFFF) {
      attr.setValue(getAttributeValue(attrType, attrData));
    } else {
      attr.setValue(getString(attrValueIdx));
    }

    return attr;
  }
  /**
   * Called by Java2XML
   *
   * @return Attributes with enough information to be saved to a project file
   */
  public List getAttributes() {
    ArrayList persistentAttributes = new ArrayList();

    for (int i = 0; i < super.getAttributeCount(); i++) {
      // if(super.getAttributeType(i)==AttributeType.GEOMETRY) continue;
      Attribute attribute = new Attribute();
      attribute.setName(super.getAttributeName(i));
      attribute.setType(super.getAttributeType(i).toString());
      attribute.setColumn(getColumnByAttribute(super.getAttributeName(i)));
      attribute.setAccessType((String) attributeAccess.get(i));
      persistentAttributes.add(attribute);
    }

    return persistentAttributes;
  }
  /**
   * Updates attributes list on node selection change in the tags tree. Loads attributes of the
   * selected node into the attributes list. Just clears attributes if no node is selected.
   *
   * @param e
   */
  public void onTagChange(TreeSelectionEvent e) {
    if (e.getNewLeadSelectionPath() != null) {
      TreePath path = e.getNewLeadSelectionPath();
      attributes.clear();
      if (path.getPathCount() >= 1) {

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Tag tag = (Tag) node.getUserObject();
        for (String name : tag.getAttributes().keySet()) {
          Attribute attr = new Attribute();
          attr.setName(name);
          attr.setValue(tag.getAttribute(name));
          attributes.add(attr);
        }
      }
    }
  }
    /**
     * Merge in another section
     *
     * @param section the section to be merged with this one.
     * @throws ManifestException if the sections cannot be merged.
     */
    public void merge(Section section) throws ManifestException {
      if (name == null && section.getName() != null
          || name != null && !(name.equalsIgnoreCase(section.getName()))) {
        throw new ManifestException("Unable to merge sections with different names");
      }

      Enumeration e = section.getAttributeKeys();
      Attribute classpathAttribute = null;
      while (e.hasMoreElements()) {
        String attributeName = (String) e.nextElement();
        Attribute attribute = section.getAttribute(attributeName);
        if (attributeName.equalsIgnoreCase(ATTRIBUTE_CLASSPATH)) {
          if (classpathAttribute == null) {
            classpathAttribute = new Attribute();
            classpathAttribute.setName(ATTRIBUTE_CLASSPATH);
          }
          Enumeration cpe = attribute.getValues();
          while (cpe.hasMoreElements()) {
            String value = (String) cpe.nextElement();
            classpathAttribute.addValue(value);
          }
        } else {
          // the merge file always wins
          storeAttribute(attribute);
        }
      }

      if (classpathAttribute != null) {
        // the merge file *always* wins, even for Class-Path
        storeAttribute(classpathAttribute);
      }

      // add in the warnings
      Enumeration warnEnum = section.warnings.elements();
      while (warnEnum.hasMoreElements()) {
        warnings.addElement(warnEnum.nextElement());
      }
    }
  private AttributeStatement buildAttributeStatement(Map<String, String> claims) {
    AttributeStatement attStmt = null;
    if (claims != null) {
      attStmt = new AttributeStatementBuilder().buildObject();
      Iterator<String> ite = claims.keySet().iterator();

      for (int i = 0; i < claims.size(); i++) {
        Attribute attrib = new AttributeBuilder().buildObject();
        String claimUri = ite.next();
        attrib.setName(claimUri);
        // look
        // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes
        XSStringBuilder stringBuilder =
            (XSStringBuilder) Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME);
        XSString stringValue =
            stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
        stringValue.setValue(claims.get(claimUri));
        attrib.getAttributeValues().add(stringValue);
        attStmt.getAttributes().add(attrib);
      }
    }
    return attStmt;
  }
  public void setUp() throws Exception {
    os = ObjectStoreFactory.getObjectStore("os.unittest");

    item = new Item();
    item.setClassName("Department");
    item.setImplementations("Broke");
    item.setIdentifier("1");
    Attribute attr1 = new Attribute();
    attr1.setName("name");
    attr1.setValue("Department1");
    item.addAttribute(attr1);
    Attribute attr2 = new Attribute();
    attr2.setName("debt");
    attr2.setValue("10");
    item.addAttribute(attr2);
    Reference ref1 = new Reference();
    ref1.setName("address");
    ref1.setRefId("2");
    item.addReference(ref1);
    ReferenceList col1 = new ReferenceList();
    col1.setName("employees");
    col1.addRefId("3");
    col1.addRefId("4");
    item.addCollection(col1);

    dbItem = new org.intermine.model.fulldata.Item();
    dbItem.setClassName("Department");
    dbItem.setImplementations("Broke");
    dbItem.setIdentifier("1");
    dbItem.setId(1001);
    org.intermine.model.fulldata.Attribute dbAttr1 = new org.intermine.model.fulldata.Attribute();
    dbAttr1.setName("name");
    dbAttr1.setValue("Department1");
    dbAttr1.setItem(dbItem);
    dbItem.addAttributes(dbAttr1);
    org.intermine.model.fulldata.Attribute dbAttr2 = new org.intermine.model.fulldata.Attribute();
    dbAttr2.setName("debt");
    dbAttr2.setValue("10");
    dbAttr2.setItem(dbItem);
    dbItem.addAttributes(dbAttr2);
    org.intermine.model.fulldata.Reference dbRef1 = new org.intermine.model.fulldata.Reference();
    dbRef1.setName("address");
    dbRef1.setRefId("2");
    dbRef1.setItem(dbItem);
    dbItem.addReferences(dbRef1);
    org.intermine.model.fulldata.ReferenceList dbCol1 =
        new org.intermine.model.fulldata.ReferenceList();
    dbCol1.setName("employees");
    dbCol1.setRefIds("3 4");
    dbCol1.setItem(dbItem);
    dbItem.addCollections(dbCol1);

    referenceList = new ReferenceList();
    referenceList.setName("employees");
    referenceList.setRefIds(Arrays.asList("3", "4"));

    dbReferenceList = new org.intermine.model.fulldata.ReferenceList();
    dbReferenceList.setName("employees");
    dbReferenceList.setRefIds("3 4");
    departmentProxy = new ProxyReference(os, 1, Department.class);
    dbReferenceList.proxyItem(departmentProxy);
    // dbReferenceList.setId(2002);
  }
Exemple #8
0
  void insertAttribute(String line) {

    int indexL, indexR;
    String type;

    // Treating string and declaring a string tokenizer
    line.replace("{", " {");
    // line.replace ("["," [");

    // System.out.println ("  > Processing line: "+  line );
    StringTokenizer st = new StringTokenizer(line, " [{\t");

    // Disregarding the first token. It is @attribute
    st.nextToken();

    Attribute at = new Attribute();
    at.setName(st.nextToken().trim());
    // System.out.println ( "   > Attribute name: "+ at.getName() );

    // Next action depends on the type of attribute: continuous or nominal
    if (!st.hasMoreTokens()) { // Parsing a nominal attribute with no definition of values
      // System.out.println ("    > Parsing nominal attribute without values ");
      at.setType(Attribute.NOMINAL);
    } else if (line.indexOf("{") != -1) { // Parsing a nominal attribute
      // System.out.println ("    > Parsing nominal attribute with values: "+line );
      at.setType(Attribute.NOMINAL);
      at.setFixedBounds(true);

      indexL = line.indexOf("{");
      indexR = line.indexOf("}");

      // System.out.println ( "      > The Nominal values are: " + line.substring( indexL+1, indexR)
      // );
      StringTokenizer st2 = new StringTokenizer(line.substring(indexL + 1, indexR), ",");

      while (st2.hasMoreTokens()) {
        at.addNominalValue(st2.nextToken().trim());
      }
    } else { // Parsing an integer or real
      type = st.nextToken().trim();

      // System.out.println ("    > Parsing "+ type + " attributes");
      if (type.equalsIgnoreCase("integer")) at.setType(Attribute.INTEGER);
      if (type.equalsIgnoreCase("real")) at.setType(Attribute.REAL);

      indexL = line.indexOf("[");
      indexR = line.indexOf("]");

      if (indexL != -1 && indexR != -1) {
        // System.out.println ( "      > The real values are: " + line.substring( indexL+1, indexR)
        // );
        StringTokenizer st2 = new StringTokenizer(line.substring(indexL + 1, indexR), ",");

        double min = Double.parseDouble(st2.nextToken().trim());
        double max = Double.parseDouble(st2.nextToken().trim());

        at.setBounds(min, max);
      }
    }

    Attributes.addAttribute(at);
  } // end insertAttribute