Example #1
0
  public void prepareAttributes() throws XPathException {

    AttributeCollection atts = getAttributeList();
    overrideAtt = "yes";
    for (int a = 0; a < atts.getLength(); a++) {
      String f = atts.getQName(a);
      if (f.equals(StandardNames.NAME)) {
        nameAtt = Whitespace.trim(atts.getValue(a));
        assert (nameAtt != null);
        if (nameAtt.indexOf(':') < 0) {
          compileError("Function name must have a namespace prefix", "XTSE0740");
        }
        try {
          setObjectName(makeQName(nameAtt));
        } catch (NamespaceException err) {
          compileError(err.getMessage(), "XTSE0280");
        } catch (XPathException err) {
          compileError(err);
        }
      } else if (f.equals(StandardNames.AS)) {
        asAtt = atts.getValue(a);
      } else if (f.equals(StandardNames.OVERRIDE)) {
        overrideAtt = Whitespace.trim(atts.getValue(a));
        if ("yes".equals(overrideAtt)) {
          override = true;
        } else if ("no".equals(overrideAtt)) {
          override = false;
        } else {
          override = true;
          compileError("override must be 'yes' or 'no'", "XTSE0020");
        }
      } else if (f.equals("memo-function") && atts.getURI(a).equals(NamespaceConstant.SAXON)) {
        String memoAtt = Whitespace.trim(atts.getValue(a));
        if ("yes".equals(memoAtt)) {
          memoFunction = true;
        } else if ("no".equals(memoAtt)) {
          memoFunction = false;
        } else {
          compileError("saxon:memo-function must be 'yes' or 'no'", "XTSE0020");
        }
      } else {
        checkUnknownAttribute(atts.getNodeName(a));
      }
    }

    if (nameAtt == null) {
      reportAbsence("name");
      nameAtt = "xsl:unnamed-function-" + generateId();
    }

    if (asAtt == null) {
      resultType = SequenceType.ANY_SEQUENCE;
    } else {
      resultType = makeSequenceType(asAtt);
    }

    functionName = nameAtt;
  }
  /**
   * Create all attribute declarations. This method is called once in the constructor of the super
   * class. The <code>H1</code> element may have the following attributes:
   *
   * <table>
   * <tbody>
   *   <tr>
   *     <th>NAME</th><th>TYPE</th><th>USAGE</th><th>DEFAULT (INITIAL) VALUE</th><th>MEMO</th>
   *   </tr>
   *   <tr>
   *     <td>%attrs;</td><td>-</td><td>-</td><td>-</td><td>-</td>
   *   </tr>
   *   <tr>
   *     <td>%align;</td><td>-</td><td>-</td><td>-</td><td>-</td>
   *   </tr>
   * </tbody>
   * </table>
   *
   * <p><b>%align;</b> means <code>align (left|center|right|justify) #IMPLIED</code>. Unfortunately,
   * this <code>align</code> is different from one in <code>IMG</code> or <code>TABLE</code>. So,
   * the attribute declaration of <code>align</code> should be localy created and it shouldn't be
   * registered in a <code>HCMDocImpl</code> instance.
   *
   * <p>However, %align is used in sevaral times. I wouldn't write same code in many times. So, I
   * add a new utility method into <code>CMUtil</code> to create the attribute declaration. <br>
   */
  protected void createAttributeDeclarations() {
    if (attributes != null) return; // already created.
    if (attributeCollection == null) return; // fatal

    attributes = new CMNamedNodeMapImpl();

    // %attrs;
    attributeCollection.getAttrs(attributes);
    // align
    HTMLAttrDeclImpl attr = AttributeCollection.createAlignForParagraph();
    if (attr != null) attributes.putNamedItem(CHTMLNamespace.ATTR_NAME_ALIGN, attr);
  }
  public void reload(DatasetConfigTreeNode editingNode, DatasetConfigTreeNode parentNode) {
    int start, finish;
    String parentClassName = (parentNode.getUserObject().getClass()).getName();
    String childClassName = (editingNode.getUserObject().getClass()).getName();
    start = childClassName.lastIndexOf(".") + 1;
    finish = childClassName.length();
    String childName = childClassName.substring(start, finish);
    if (parentClassName.equals("org.ensembl.mart.lib.config.DatasetConfig")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.FilterPage")) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.addFilterPage((FilterPage) editingNode.getUserObject());
        // config.removeAttributePage();

      } else if (childClassName.equals("org.ensembl.mart.lib.config.AttributePage")) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.addAttributePage((AttributePage) editingNode.getUserObject());

      } else if (childClassName.equals("org.ensembl.mart.lib.config.Importable")) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.addImportable((Importable) editingNode.getUserObject());

      } else if (childClassName.equals("org.ensembl.mart.lib.config.Exportable")) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.addExportable((Exportable) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.FilterPage")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.FilterGroup")) {
        FilterPage fp = (FilterPage) parentNode.getUserObject();
        fp.addFilterGroup((FilterGroup) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.FilterGroup")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.FilterCollection")) {
        FilterGroup fg = (FilterGroup) parentNode.getUserObject();
        fg.addFilterCollection((FilterCollection) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.FilterCollection")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.FilterDescription")) {
        FilterCollection fc = (FilterCollection) parentNode.getUserObject();
        fc.addFilterDescription((FilterDescription) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.FilterDescription")) {

      if (childClassName.equals("org.ensembl.mart.lib.config.Option")) {
        FilterDescription fd = (FilterDescription) parentNode.getUserObject();
        fd.addOption((Option) editingNode.getUserObject());

      } else if (childClassName.equals("org.ensembl.mart.lib.config.SpecificFilterContent")) {
        FilterDescription ad = (FilterDescription) parentNode.getUserObject();
        ad.addSpecificFilterContent((SpecificFilterContent) editingNode.getUserObject());
      }

    } else if (parentClassName.equals("org.ensembl.mart.lib.config.Option")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.SpecificOptionContent")) {
        Option ad = (Option) parentNode.getUserObject();
        ad.addSpecificOptionContent((SpecificOptionContent) editingNode.getUserObject());
      } else if (childClassName.equals("org.ensembl.mart.lib.config.PushAction")) {
        Option op = (Option) parentNode.getUserObject();
        op.addPushAction((PushAction) editingNode.getUserObject());
      } else if (childClassName.equals("org.ensembl.mart.lib.config.Option")) {
        Option op = (Option) parentNode.getUserObject();
        op.addOption((Option) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.PushAction")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.Option")) {
        PushAction pa = (PushAction) parentNode.getUserObject();
        pa.addOption((Option) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.AttributePage")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.AttributeGroup")) {
        AttributePage ap = (AttributePage) parentNode.getUserObject();
        ap.addAttributeGroup((AttributeGroup) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.AttributeGroup")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.AttributeCollection")) {
        AttributeGroup ag = (AttributeGroup) parentNode.getUserObject();
        ag.addAttributeCollection((AttributeCollection) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.AttributeCollection")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.AttributeDescription")) {
        AttributeCollection ac = (AttributeCollection) parentNode.getUserObject();
        ac.addAttributeDescription((AttributeDescription) editingNode.getUserObject());
      } else if (childClassName.equals("org.ensembl.mart.lib.config.AttributeList")) {
        AttributeCollection ac = (AttributeCollection) parentNode.getUserObject();
        ac.addAttributeList((AttributeList) editingNode.getUserObject());
      }
    } else if (parentClassName.equals("org.ensembl.mart.lib.config.AttributeDescription")) {

      if (childClassName.equals("org.ensembl.mart.lib.config.SpecificAttributeContent")) {
        AttributeDescription ad = (AttributeDescription) parentNode.getUserObject();
        ad.addSpecificAttributeContent((SpecificAttributeContent) editingNode.getUserObject());
      }

    } else if (parentClassName.equals("org.ensembl.mart.lib.config.SpecificFilterContent")) {
      if (childClassName.equals("org.ensembl.mart.lib.config.Option")) {
        SpecificFilterContent fd = (SpecificFilterContent) parentNode.getUserObject();
        System.out.println(
            "TREE MODEL -- ADDING DYN OPTION "
                + ((Option) editingNode.getUserObject()).getInternalName());
        fd.addOption((Option) editingNode.getUserObject());
      }
    }

    super.reload(parentNode);
  }
 public void removeNodeFromParent(DatasetConfigTreeNode node) {
   Object child = node.getUserObject();
   if (node.getParent() == null) return; // Can't remove root node.
   Object parent = ((DatasetConfigTreeNode) node.getParent()).getUserObject();
   if (parent instanceof org.ensembl.mart.lib.config.DatasetConfig) {
     if (child instanceof org.ensembl.mart.lib.config.FilterPage) {
       config = (DatasetConfig) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       config.removeFilterPage((FilterPage) node.getUserObject());
     } else if (child instanceof org.ensembl.mart.lib.config.AttributePage) {
       config = (DatasetConfig) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       config.removeAttributePage((AttributePage) node.getUserObject());
     } else if (child instanceof org.ensembl.mart.lib.config.Exportable) {
       config = (DatasetConfig) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       config.removeExportable((Exportable) node.getUserObject());
     } else if (child instanceof org.ensembl.mart.lib.config.Importable) {
       config = (DatasetConfig) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       config.removeImportable((Importable) node.getUserObject());
     }
   } else if (node.getUserObject() instanceof DynamicDataset) {
     config =
         (DatasetConfig) ((DatasetConfigTreeNode) node.getParent().getParent()).getUserObject();
     config.removeDynamicDataset((DynamicDataset) node.getUserObject());
   } else if (parent instanceof org.ensembl.mart.lib.config.FilterPage) {
     if (child instanceof org.ensembl.mart.lib.config.FilterGroup) {
       FilterPage fp = (FilterPage) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       fp.removeFilterGroup((FilterGroup) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.FilterGroup) {
     if (child instanceof org.ensembl.mart.lib.config.FilterCollection) {
       FilterGroup fg = (FilterGroup) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       fg.removeFilterCollection((FilterCollection) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.FilterCollection) {
     if (child instanceof org.ensembl.mart.lib.config.FilterDescription) {
       FilterCollection fc =
           (FilterCollection) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       fc.removeFilterDescription((FilterDescription) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.FilterDescription) {
     if (child instanceof org.ensembl.mart.lib.config.Option) {
       FilterDescription fd =
           (FilterDescription) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       fd.removeOption((Option) node.getUserObject());
     } else if (child instanceof org.ensembl.mart.lib.config.SpecificFilterContent) {
       FilterDescription ad =
           (FilterDescription) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       ad.removeSpecificFilterContent((SpecificFilterContent) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.Option) {
     if (child instanceof org.ensembl.mart.lib.config.SpecificOptionContent) {
       Option ad = (Option) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       ad.removeSpecificOptionContent((SpecificOptionContent) node.getUserObject());
     } else if (child instanceof org.ensembl.mart.lib.config.PushAction) {
       Option op = (Option) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       op.removePushAction((PushAction) node.getUserObject());
     } else if (child instanceof org.ensembl.mart.lib.config.Option) {
       Option fd = (Option) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       fd.removeOption((Option) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.PushAction) {
     if (child instanceof org.ensembl.mart.lib.config.Option) {
       PushAction pa = (PushAction) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       pa.removeOption((Option) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.AttributePage) {
     if (child instanceof org.ensembl.mart.lib.config.AttributeGroup) {
       AttributePage ap =
           (AttributePage) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       ap.removeAttributeGroup((AttributeGroup) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.AttributeGroup) {
     if (child instanceof org.ensembl.mart.lib.config.AttributeCollection) {
       AttributeGroup ag =
           (AttributeGroup) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       ag.removeAttributeCollection((AttributeCollection) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.AttributeCollection) {
     if (child instanceof org.ensembl.mart.lib.config.AttributeDescription) {
       AttributeCollection ac =
           (AttributeCollection) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       ac.removeAttributeDescription((AttributeDescription) node.getUserObject());
     } else if (child instanceof org.ensembl.mart.lib.config.AttributeList) {
       AttributeCollection ac =
           (AttributeCollection) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       ac.removeAttributeList((AttributeList) node.getUserObject());
     }
   } else if (parent instanceof org.ensembl.mart.lib.config.AttributeDescription) {
     if (child instanceof org.ensembl.mart.lib.config.SpecificAttributeContent) {
       AttributeDescription ad =
           (AttributeDescription) ((DatasetConfigTreeNode) node.getParent()).getUserObject();
       ad.removeSpecificAttributeContent((SpecificAttributeContent) node.getUserObject());
     }
   }
   super.removeNodeFromParent(node);
 }
  public String insertNodeInto(
      DatasetConfigTreeNode editingNode, DatasetConfigTreeNode parentNode, int index) {
    int start, finish;
    Object child = editingNode.getUserObject();
    Object parent = parentNode.getUserObject();
    BaseNamedConfigurationObject parentObj = (BaseNamedConfigurationObject) parent;
    BaseNamedConfigurationObject childObj = (BaseNamedConfigurationObject) child;
    if (parentObj.getHidden() != null && parentObj.getHidden().equals("true")) {
      childObj.setHidden("true");
      Enumeration children = editingNode.breadthFirstEnumeration();
      DatasetConfigTreeNode childNode = null;
      while (children.hasMoreElements()) {
        childNode = (DatasetConfigTreeNode) children.nextElement();
        BaseNamedConfigurationObject ch = (BaseNamedConfigurationObject) childNode.getUserObject();
        ch.setHidden("true");
      }
    }

    String childClassName = (editingNode.getUserObject().getClass()).getName();
    start = childClassName.lastIndexOf(".") + 1;
    finish = childClassName.length();
    String childName = childClassName.substring(start, finish);

    // index is a Node index. objectIndex may be different
    int objIndex = index - DatasetConfigTreeNode.getHeterogenousOffset(parent, child);
    if (parent instanceof org.ensembl.mart.lib.config.DatasetConfig) {
      if (child instanceof org.ensembl.mart.lib.config.FilterPage) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.insertFilterPage(objIndex, (FilterPage) editingNode.getUserObject());

      } else if (child instanceof org.ensembl.mart.lib.config.AttributePage) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.insertAttributePage(objIndex, (AttributePage) editingNode.getUserObject());

      } else if (child instanceof org.ensembl.mart.lib.config.Importable) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.insertImportable(objIndex, (Importable) editingNode.getUserObject());

      } else if (child instanceof org.ensembl.mart.lib.config.Exportable) {
        config = (DatasetConfig) parentNode.getUserObject();
        config.insertExportable(objIndex, (Exportable) editingNode.getUserObject());
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in a DatasetConfig.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.FilterPage) {
      if (child instanceof org.ensembl.mart.lib.config.FilterGroup) {
        FilterPage fp = (FilterPage) parentNode.getUserObject();
        fp.insertFilterGroup(objIndex, (FilterGroup) editingNode.getUserObject());
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in a FilterPage.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.FilterGroup) {
      if (child instanceof org.ensembl.mart.lib.config.FilterCollection) {
        FilterGroup fg = (FilterGroup) parentNode.getUserObject();
        fg.insertFilterCollection(objIndex, (FilterCollection) editingNode.getUserObject());
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in a FilterGroup.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.FilterCollection) {
      if (child instanceof org.ensembl.mart.lib.config.FilterDescription) {
        FilterCollection fc = (FilterCollection) parentNode.getUserObject();
        fc.insertFilterDescription(objIndex, (FilterDescription) editingNode.getUserObject());
      } else if (child instanceof org.ensembl.mart.lib.config.Option) {
        FilterCollection fc = (FilterCollection) parentNode.getUserObject();
        FilterDescription fdConvert = new FilterDescription((Option) editingNode.getUserObject());
        fc.insertFilterDescription(objIndex, fdConvert);
        editingNode.setUserObject(fdConvert);
      } else if (child instanceof org.ensembl.mart.lib.config.AttributeDescription) {
        FilterCollection fc = (FilterCollection) parentNode.getUserObject();
        // FilterDescription fdConvert = new FilterDescription((AttributeDescription)
        // editingNode.getUserObject());
        AttributeDescription ad = (AttributeDescription) editingNode.getUserObject();

        FilterDescription fdConvert = null;
        try {
          fdConvert =
              new FilterDescription(
                  ad.getInternalName(),
                  ad.getField(),
                  "text",
                  "=",
                  "=",
                  ad.getDisplayName(),
                  ad.getTableConstraint(),
                  ad.getKey(),
                  ad.getDescription(),
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "",
                  "");
        } catch (ConfigurationException e) {
          // guaranteed internal name for atts
        }
        fc.insertFilterDescription(objIndex, fdConvert);
        editingNode.setUserObject(fdConvert);
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in a FilterCollection.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.FilterDescription) {
      if (child instanceof org.ensembl.mart.lib.config.SpecificFilterContent) {
        FilterDescription ad = (FilterDescription) parentNode.getUserObject();
        ad.insertSpecificFilterContent(
            objIndex, (SpecificFilterContent) editingNode.getUserObject());
      } else if (child instanceof org.ensembl.mart.lib.config.FilterDescription) {
        FilterDescription fd = (FilterDescription) parentNode.getUserObject();
        Option opConvert = new Option((FilterDescription) editingNode.getUserObject());
        fd.insertOption(objIndex, opConvert);
        editingNode.setUserObject(opConvert);
      } else if (child instanceof org.ensembl.mart.lib.config.Option) {
        FilterDescription fd = (FilterDescription) parentNode.getUserObject();
        fd.insertOption(objIndex, (Option) editingNode.getUserObject());
      } else if (child instanceof org.ensembl.mart.lib.config.PushAction) {
        FilterDescription fd = (FilterDescription) parentNode.getUserObject();
        // fd.insertPushAction(objIndex, (PushAction) editingNode.getUserObject());
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in a FilterDescription.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.Option) {
      if (child instanceof org.ensembl.mart.lib.config.SpecificOptionContent) {
        Option ad = (Option) parentNode.getUserObject();
        ad.insertSpecificOptionContent(
            objIndex, (SpecificOptionContent) editingNode.getUserObject());
      } else if (child instanceof org.ensembl.mart.lib.config.PushAction) {
        Option op = (Option) parentNode.getUserObject();
        op.insertPushAction(objIndex, (PushAction) editingNode.getUserObject());
      } else if (child instanceof org.ensembl.mart.lib.config.Option) {
        Option op = (Option) parentNode.getUserObject();
        op.insertOption(objIndex, (Option) editingNode.getUserObject());
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.PushAction) {
      if (child instanceof org.ensembl.mart.lib.config.Option) {
        PushAction pa = (PushAction) parentNode.getUserObject();
        pa.insertOption(objIndex, (Option) editingNode.getUserObject());
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.AttributePage) {
      if (child instanceof org.ensembl.mart.lib.config.AttributeGroup) {
        AttributePage ap = (AttributePage) parentNode.getUserObject();
        ap.insertAttributeGroup(objIndex, (AttributeGroup) editingNode.getUserObject());
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in an AttributePage.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.AttributeGroup) {
      if (child instanceof org.ensembl.mart.lib.config.AttributeCollection) {
        AttributeGroup ag = (AttributeGroup) parentNode.getUserObject();
        ag.insertAttributeCollection(objIndex, (AttributeCollection) editingNode.getUserObject());
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in an AttributeGroup.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.AttributeCollection) {
      if (child instanceof org.ensembl.mart.lib.config.AttributeDescription) {
        AttributeCollection ac = (AttributeCollection) parentNode.getUserObject();
        ac.insertAttributeDescription(objIndex, (AttributeDescription) editingNode.getUserObject());
      } else if (child instanceof org.ensembl.mart.lib.config.AttributeList) {
        AttributeCollection ac = (AttributeCollection) parentNode.getUserObject();
        ac.insertAttributeList(objIndex, (AttributeList) editingNode.getUserObject());
      } else {
        String error_string =
            "Error: " + childName + " cannot be inserted in an AttributeCollection.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.AttributeDescription) {
      if (child instanceof org.ensembl.mart.lib.config.SpecificAttributeContent) {
        AttributeDescription ad = (AttributeDescription) parentNode.getUserObject();
        ad.insertSpecificAttributeContent(
            objIndex, (SpecificAttributeContent) editingNode.getUserObject());
      } else {
        String error_string = "Error: " + childName + " cannot be inserted in a FilterDescription.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.SpecificFilterContent) {
      if (child instanceof org.ensembl.mart.lib.config.Option) {
        SpecificFilterContent fd = (SpecificFilterContent) parentNode.getUserObject();
        System.out.println(
            "TREE MODEL 2 -- ADDING DYN OPTION "
                + ((Option) editingNode.getUserObject()).getInternalName());

        fd.insertOption(objIndex, (Option) editingNode.getUserObject());
      } else {
        String error_string =
            "Error: " + childName + " cannot be inserted in an DynamicFilterContent.";
        return error_string;
      }
    } else if (parent instanceof org.ensembl.mart.lib.config.SpecificAttributeContent) {
      String error_string =
          "Error: " + childName + " cannot be inserted in an DynamicAttributeContent.";
      return error_string;
    } else if (parent instanceof org.ensembl.mart.lib.config.SpecificOptionContent) {
      String error_string =
          "Error: " + childName + " cannot be inserted in an DynamicOptionContent.";
      return error_string;
    }
    super.insertNodeInto(editingNode, parentNode, index);
    return "success";
  }
  public void prepareAttributes() throws XPathException {

    AttributeCollection atts = getAttributeList();

    String nameAtt = null;
    String namespaceAtt = null;
    String selectAtt = null;
    String separatorAtt = null;
    String validationAtt = null;
    String typeAtt = null;

    for (int a = 0; a < atts.getLength(); a++) {
      int nc = atts.getNameCode(a);
      String f = getNamePool().getClarkName(nc);
      if (f == StandardNames.NAME) {
        nameAtt = Whitespace.trim(atts.getValue(a));
      } else if (f == StandardNames.NAMESPACE) {
        namespaceAtt = Whitespace.trim(atts.getValue(a));
      } else if (f == StandardNames.SELECT) {
        selectAtt = atts.getValue(a);
      } else if (f == StandardNames.SEPARATOR) {
        separatorAtt = atts.getValue(a);
      } else if (f == StandardNames.VALIDATION) {
        validationAtt = Whitespace.trim(atts.getValue(a));
      } else if (f == StandardNames.TYPE) {
        typeAtt = Whitespace.trim(atts.getValue(a));
      } else {
        checkUnknownAttribute(nc);
      }
    }

    if (nameAtt == null) {
      reportAbsence("name");
      return;
    }
    attributeName = makeAttributeValueTemplate(nameAtt);
    if (attributeName instanceof StringLiteral) {
      if (!getConfiguration()
          .getNameChecker()
          .isQName(((StringLiteral) attributeName).getStringValue())) {
        invalidAttributeName("Attribute name " + Err.wrap(nameAtt) + " is not a valid QName");
      }
      if (nameAtt.equals("xmlns")) {
        if (namespace == null) {
          invalidAttributeName("Invalid attribute name: xmlns");
        }
      }
      if (nameAtt.startsWith("xmlns:")) {
        if (namespaceAtt == null) {
          invalidAttributeName("Invalid attribute name: " + Err.wrap(nameAtt));
        } else {
          // ignore the prefix "xmlns"
          nameAtt = nameAtt.substring(6);
          attributeName = new StringLiteral(nameAtt);
        }
      }
    }

    if (namespaceAtt != null) {
      namespace = makeAttributeValueTemplate(namespaceAtt);
      if (namespace instanceof StringLiteral) {
        if (!AnyURIValue.isValidURI(((StringLiteral) namespace).getStringValue())) {
          compileError("The value of the namespace attribute must be a valid URI", "XTDE0865");
        }
      }
    }

    if (selectAtt != null) {
      select = makeExpression(selectAtt);
    }

    if (separatorAtt == null) {
      if (selectAtt == null) {
        separator = new StringLiteral(StringValue.EMPTY_STRING);
      } else {
        separator = new StringLiteral(StringValue.SINGLE_SPACE);
      }
    } else {
      separator = makeAttributeValueTemplate(separatorAtt);
    }

    if (validationAtt != null) {
      validationAction = Validation.getCode(validationAtt);
      if (validationAction != Validation.STRIP && !getExecutable().isSchemaAware()) {
        validationAction = Validation.STRIP;
        compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660");
      }
      if (validationAction == Validation.INVALID) {
        compileError("Invalid value of validation attribute", "XTSE0020");
        validationAction = getContainingStylesheet().getDefaultValidation();
      }
    } else {
      validationAction = getContainingStylesheet().getDefaultValidation();
    }

    if (typeAtt != null) {
      if (!getExecutable().isSchemaAware()) {
        compileError(
            "The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660");
      } else {
        SchemaType type = getSchemaType(typeAtt);
        if (type == null) {
          compileError("Unknown attribute type " + typeAtt, "XTSE1520");
        } else {
          if (type.isSimpleType()) {
            schemaType = (SimpleType) type;
          } else {
            compileError("Type annotation for attributes must be a simple type", "XTSE1530");
            type = null;
          }
        }
        validationAction = Validation.BY_TYPE;
      }
    }

    if (typeAtt != null && validationAtt != null) {
      compileError("The validation and type attributes are mutually exclusive", "XTSE1505");
      validationAction = getContainingStylesheet().getDefaultValidation();
      schemaType = null;
    }
  }
Example #7
0
  public void prepareAttributes() throws XPathException {

    AttributeCollection atts = getAttributeList();

    for (int a = 0; a < atts.getLength(); a++) {
      int nc = atts.getNameCode(a);
      String f = getNamePool().getClarkName(nc);
      if (f.equals(StandardNames.MODE)) {
        modeAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.NAME)) {
        nameAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.MATCH)) {
        matchAtt = atts.getValue(a);
      } else if (f.equals(StandardNames.PRIORITY)) {
        priorityAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.AS)) {
        asAtt = atts.getValue(a);
      } else {
        checkUnknownAttribute(nc);
      }
    }
    try {
      if (modeAtt == null) {
        modeNames = new StructuredQName[1];
        modeNames[0] = Mode.DEFAULT_MODE_NAME;
      } else {
        if (matchAtt == null) {
          compileError(
              "The mode attribute must be absent if the match attribute is absent", "XTSE0500");
        }
        // mode is a space-separated list of mode names, or "#default", or "#all"

        int count = 0;
        boolean allModes = false;
        StringTokenizer st = new StringTokenizer(modeAtt, " \t\n\r", false);
        while (st.hasMoreTokens()) {
          st.nextToken();
          count++;
        }

        if (count == 0) {
          compileError("The mode attribute must not be empty", "XTSE0550");
        }

        modeNames = new StructuredQName[count];
        count = 0;
        st = new StringTokenizer(modeAtt, " \t\n\r", false);
        while (st.hasMoreTokens()) {
          String s = st.nextToken();
          StructuredQName mname;
          if ("#default".equals(s)) {
            mname = Mode.DEFAULT_MODE_NAME;
          } else if ("#all".equals(s)) {
            allModes = true;
            mname = Mode.ALL_MODES;
          } else {
            mname = makeQName(s);
          }
          for (int e = 0; e < count; e++) {
            if (modeNames[e].equals(mname)) {
              compileError("In the list of modes, the value " + s + " is duplicated", "XTSE0550");
            }
          }
          modeNames[count++] = mname;
        }
        if (allModes && (count > 1)) {
          compileError("mode='#all' cannot be combined with other modes", "XTSE0550");
        }
      }
    } catch (NamespaceException err) {
      compileError(err.getMessage(), "XTSE0280");
    } catch (XPathException err) {
      if (err.getErrorCodeLocalPart() == null) {
        err.setErrorCode("XTSE0280");
      } else if (err.getErrorCodeLocalPart().equals("XTSE0020")) {
        err.setErrorCode("XTSE0550");
      }
      err.setIsStaticError(true);
      compileError(err);
    }

    try {
      if (nameAtt != null) {
        StructuredQName qName = makeQName(nameAtt);
        setObjectName(qName);
        diagnosticId = nameAtt;
      }
    } catch (NamespaceException err) {
      compileError(err.getMessage(), "XTSE0280");
    } catch (XPathException err) {
      if (err.getErrorCodeLocalPart() == null) {
        err.setErrorCode("XTSE0280");
      }
      err.setIsStaticError(true);
      compileError(err);
    }

    prioritySpecified = (priorityAtt != null);
    if (prioritySpecified) {
      if (matchAtt == null) {
        compileError(
            "The priority attribute must be absent if the match attribute is absent", "XTSE0500");
      }
      try {
        // it's got to be a valid decimal, but we want it as a double, so parse it twice
        if (!DecimalValue.castableAsDecimal(priorityAtt)) {
          compileError("Invalid numeric value for priority (" + priority + ')', "XTSE0530");
        }
        priority = Double.parseDouble(priorityAtt);
      } catch (NumberFormatException err) {
        // shouldn't happen
        compileError("Invalid numeric value for priority (" + priority + ')', "XTSE0530");
      }
    }

    if (matchAtt != null) {
      match = makePattern(matchAtt);
      if (diagnosticId == null) {
        diagnosticId = "match=\"" + matchAtt + '\"';
        if (modeAtt != null) {
          diagnosticId += " mode=\"" + modeAtt + '\"';
        }
      }
    }

    if (match == null && nameAtt == null)
      compileError("xsl:template must have a name or match attribute (or both)", "XTSE0500");

    if (asAtt != null) {
      requiredType = makeSequenceType(asAtt);
    }
  }