public ActionDescriptor getAction(int id) {
    // check global actions
    for (Iterator iterator = globalActions.iterator(); iterator.hasNext(); ) {
      ActionDescriptor actionDescriptor = (ActionDescriptor) iterator.next();

      if (actionDescriptor.getId() == id) {
        return actionDescriptor;
      }
    }

    // check steps
    for (Iterator iterator = steps.iterator(); iterator.hasNext(); ) {
      StepDescriptor stepDescriptor = (StepDescriptor) iterator.next();
      ActionDescriptor actionDescriptor = stepDescriptor.getAction(id);

      if (actionDescriptor != null) {
        return actionDescriptor;
      }
    }

    // check initial actions, which we now must have unique id's
    for (Iterator iterator = initialActions.iterator(); iterator.hasNext(); ) {
      ActionDescriptor actionDescriptor = (ActionDescriptor) iterator.next();

      if (actionDescriptor.getId() == id) {
        return actionDescriptor;
      }
    }

    return null;
  }
Exemplo n.º 2
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    List attributes = element.getAttributes();
    Iterator i = attributes.iterator();
    while (i.hasNext()) {
      Attribute a = (Attribute) i.next();
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }
Exemplo n.º 3
0
 public AlbumBean[] getResult() {
   synchronized (libraryList) {
     AlbumBean[] res;
     res = libraryList.toArray(new AlbumBean[libraryList.size()]);
     return res;
   }
 }
Exemplo n.º 4
0
 @Override
 public void processingInstruction(String target, String data) throws SAXException {
   _logger.fine("Processing Instruction " + target);
   _logger.fine("Processing Instruction data: " + data);
   if (target.equals("assemble")) {
     if (!_stack.isEmpty()) {
       ElementInfo element = _stack.get(_stack.size() - 1);
       Matcher matcher = PROCESSING_INSTRUCTION.matcher(data);
       while (matcher.find()) {
         if (matcher.groupCount() == 2) {
           String name = matcher.group(1);
           if (name.charAt(0) == '@') {
             element.inst.put(name, matcher.group(2));
           } else {
             element.args.add(guessUntypedValue(name, matcher.group(2)));
           }
           _logger.fine(
               "Processing Instruction for "
                   + element.data.getClass()
                   + "\n\ttarget = "
                   + target
                   + "\n\t"
                   + name
                   + "="
                   + matcher.group(2));
         }
       }
     }
   }
 }
Exemplo n.º 5
0
  private LinkedHashMap[] obtenerMapeos(CliGol cliGol, NodeList variables, String[] excluye) {

    LinkedHashMap<String, Object> mapa = new LinkedHashMap<String, Object>();

    LinkedHashMap<String, String> puntos = new LinkedHashMap<String, String>();

    List<String> ex = Arrays.asList(excluye);

    for (int i = 0; i < variables.getLength(); i++) {

      String nom = variables.item(i).getNodeName();

      if (!ex.contains(nom)) {

        String golMapdijo = GolMap.xmlGol(nom);

        String val = null;
        if (golMapdijo != null) {
          val = buscaValEnCli(golMapdijo, cliGol);
          mapa.put(nom, val);

          puntos.put(nom, variables.item(i).getTextContent());
        }
      }
    }

    return new LinkedHashMap[] {mapa, puntos};
  }
Exemplo n.º 6
0
 /**
  * This will take the supplied <code>{@link Element}</code> and transfer its namespaces to the
  * global namespace storage.
  *
  * @param element <code>Element</code> to read namespaces from.
  */
 private void transferNamespaces(Element element) {
   Iterator i = declaredNamespaces.iterator();
   while (i.hasNext()) {
     Namespace ns = (Namespace) i.next();
     if (ns != element.getNamespace()) {
       element.addNamespaceDeclaration(ns);
     }
   }
   declaredNamespaces.clear();
 }
Exemplo n.º 7
0
  // returns list of statements
  protected static void replaceMultSPO(
      Statement st, NodeFactory f, Map o2n, Collection result, RDFNode toReplace, int position)
      throws ModelException {

    Collection replacements;

    if (toReplace instanceof Statement) {

      List l = new ArrayList();
      replaceMult((Statement) toReplace, f, o2n, l);

      if (l.size() == 1 && toReplace == l.get(0)) {
        result.add(st);
        return; // keep the same
      } else replacements = l;

    } else {

      Object ro = o2n.get(toReplace);

      if (ro instanceof Collection) replacements = (Collection) ro;
      else if (ro != null) {

        replacements = new ArrayList();
        replacements.add(ro);

      } else { // no replacement needed

        result.add(st); // keep the same statement
        return;
      }
    }

    for (Iterator it = replacements.iterator(); it.hasNext(); ) {

      Statement rs = null;
      Object rr = it.next();

      switch (position) {
        case 0:
          rs = f.createStatement((Resource) rr, st.predicate(), st.object());
          break;
        case 1:
          rs = f.createStatement(st.subject(), (Resource) rr, st.object());
          break;
        case 2:
          rs = f.createStatement(st.subject(), st.predicate(), (RDFNode) rr);
          break;
      }
      result.add(rs);
    }
  }
Exemplo n.º 8
0
  public static List getObjects(Model m, Resource subject, Resource predicate)
      throws ModelException {

    List result = new ArrayList();

    if (m == null || m.size() == 0) return result;

    for (Enumeration en = m.find(subject, predicate, null).elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      result.add(st.object());
    }
    return result;
  }
Exemplo n.º 9
0
  public void updateBean(AlbumBean newBean, AlbumBean oldBean) throws LibraryException {
    synchronized (libraryList) {
      // Find the bean
      int index = libraryList.indexOf(oldBean);
      if (index == -1) {
        LibraryException le = new LibraryException(Utils.getResourceString(ERROR_BEAN_NOT_FOUND));
        throw le;
      }

      // Set the new bean
      libraryList.set(index, newBean);
      setChanged();
      fireLibraryChangeEvent(
          new LibraryChangeEvent(this, new AlbumBean[] {oldBean}, LibraryChangeEvent.UPDATE));
    }
  }
Exemplo n.º 10
0
  private AlbumBean addOrUpdateAlbum(
      Map<Integer, AlbumBean> map, SongBean song, boolean albumOnly) {
    // Add an album bean
    if (song != null && song.getAlbum() != null) {
      int hashCode = (song.getAlbum() + (albumOnly ? "" : '\uFFFF' + song.getArtist())).hashCode();

      // Check if the album beam already exists
      AlbumBean album = map.get(hashCode);
      if (album == null) {
        album = new AlbumBean();
        album.setAlbum(song.getAlbum());
        map.put(hashCode, album);
      }

      // Update the album properties
      try {
        // Add the track id to the album bean
        album.addSong(song);
        album.incTracks();
        album.setArtist(song.getArtist());
        album.setGenre(song.getGenre());
        album.setDisc_Count(song.getDisc_Count());
      } catch (LibraryException le) {
        // There was an error adding the song to this album, remove it
        map.remove(hashCode);

        // Add to warning message
        warningList.add(song.getName() + " " + le);
      }

      return album;
    }

    return null;
  }
Exemplo n.º 11
0
  private void guardarEnListas(String nodeName, String informacion) {
    System.out.println(informacion);

    if (nodeName.equals("NoHit")) {
      NoHit.add(informacion);
      return;
    }
    if (nodeName.equals("Hit")) {
      Hit.add(informacion);
      return;
    }
    if (nodeName.equals("Buro")) {
      Buro.add(informacion);
      return;
    }
  }
    public void startElement(String uri, String localName, String qName, Attributes atts) {

      logger.log(
          LogService.LOG_DEBUG,
          "Here is OcdHandler:startElement():" //$NON-NLS-1$
              + qName);
      if (!_isParsedDataValid) return;

      String name = getName(localName, qName);
      if (name.equalsIgnoreCase(AD)) {
        AttributeDefinitionHandler attributeDefHandler = new AttributeDefinitionHandler(this);
        attributeDefHandler.init(name, atts, _ad_vector);
      } else if (name.equalsIgnoreCase(ICON)) {
        IconHandler iconHandler = new IconHandler(this);
        iconHandler.init(name, atts);
        if (iconHandler._isParsedDataValid) icons.add(iconHandler._icon);
      } else {
        logger.log(
            LogService.LOG_WARNING,
            NLS.bind(
                MetaTypeMsg.UNEXPECTED_ELEMENT,
                new Object[] {
                  name,
                  atts.getValue(ID),
                  _dp_url,
                  _dp_bundle.getBundleId(),
                  _dp_bundle.getSymbolicName()
                }));
      }
    }
Exemplo n.º 13
0
  /** @deprecated use immediateChildrenByTagName( Element parent, String tagName ) */
  public static NodeList getImmediateChildElementsByTagName(Element parent, String tagName)
      throws DOMException {
    final List nodes = new ArrayList();
    for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling())
      if (child instanceof Element && ((Element) child).getTagName().equals(tagName))
        nodes.add(child);
    return new NodeList() {
      public int getLength() {
        return nodes.size();
      }

      public Node item(int i) {
        return (Node) nodes.get(i);
      }
    };
  }
Exemplo n.º 14
0
  /**
   * This will add the prefix mapping to the JDOM <code>Document</code> object.
   *
   * @param prefix <code>String</code> namespace prefix.
   * @param uri <code>String</code> namespace URI.
   */
  public void startPrefixMapping(String prefix, String uri) throws SAXException {

    if (suppress) return;

    Namespace ns = Namespace.getNamespace(prefix, uri);
    declaredNamespaces.add(ns);
  }
  /**
   * Add a step
   *
   * @param descriptor The step descriptor to add
   * @throws IllegalArgumentException if the descriptor's ID already exists in the workflow
   */
  public void addStep(StepDescriptor descriptor) {
    if (getStep(descriptor.getId()) != null) {
      throw new IllegalArgumentException("Step with id " + descriptor.getId() + " already exists");
    }

    steps.add(descriptor);
  }
  /**
   * Add a join
   *
   * @param descriptor The join descriptor to add
   * @throws IllegalArgumentException if the descriptor's ID already exists in the workflow
   */
  public void addJoin(JoinDescriptor descriptor) {
    if (getJoin(descriptor.getId()) != null) {
      throw new IllegalArgumentException("Join with id " + descriptor.getId() + " already exists");
    }

    joins.add(descriptor);
  }
  /**
   * Add a split
   *
   * @param descriptor The split descriptor to add
   * @throws IllegalArgumentException if the descriptor's ID already exists in the workflow
   */
  public void addSplit(SplitDescriptor descriptor) {
    if (getSplit(descriptor.getId()) != null) {
      throw new IllegalArgumentException("Split with id " + descriptor.getId() + " already exists");
    }

    splits.add(descriptor);
  }
  private QueryResult gatherResultInfoForSelectQuery(
      String queryString, int queryNr, boolean sorted, Document doc, String[] rows) {
    Element root = doc.getRootElement();

    // Get head information
    Element child =
        root.getChild("head", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));

    // Get result rows (<head>)
    List headChildren =
        child.getChildren(
            "variable", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));

    Iterator it = headChildren.iterator();
    ArrayList<String> headList = new ArrayList<String>();
    while (it.hasNext()) {
      headList.add(((Element) it.next()).getAttributeValue("name"));
    }

    List resultChildren =
        root.getChild("results", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"))
            .getChildren(
                "result", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));
    int nrResults = resultChildren.size();

    QueryResult queryResult = new QueryResult(queryNr, queryString, nrResults, sorted, headList);

    it = resultChildren.iterator();
    while (it.hasNext()) {
      Element resultElement = (Element) it.next();
      String result = "";

      // get the row values and paste it together to one String
      for (int i = 0; i < rows.length; i++) {
        List bindings =
            resultElement.getChildren(
                "binding", Namespace.getNamespace("http://www.w3.org/2005/sparql-results#"));
        String rowName = rows[i];
        for (int j = 0; j < bindings.size(); j++) {
          Element binding = (Element) bindings.get(j);
          if (binding.getAttributeValue("name").equals(rowName))
            if (result.equals(""))
              result +=
                  rowName + ": " + ((Element) binding.getChildren().get(0)).getTextNormalize();
            else
              result +=
                  "\n"
                      + rowName
                      + ": "
                      + ((Element) binding.getChildren().get(0)).getTextNormalize();
        }
      }

      queryResult.addResult(result);
    }
    return queryResult;
  }
Exemplo n.º 19
0
  /**
   * This will output a list of JDOM nodes as a fragment of an XML document, firing off the SAX
   * events that have been registered.
   *
   * <p><strong>Warning</strong>: This method does not call the {@link
   * ContentHandler#setDocumentLocator}, {@link ContentHandler#startDocument} and {@link
   * ContentHandler#endDocument} callbacks on the {@link #setContentHandler ContentHandler}. The
   * user shall invoke these methods directly prior/after outputting the document fragments.
   *
   * @param nodes <code>List</code> of JDOM nodes to output.
   * @throws JDOMException if any error occurred.
   * @see #outputFragment(org.jdom2.Content)
   */
  public void outputFragment(List<? extends Content> nodes) throws JDOMException {
    if ((nodes == null) || (nodes.size() == 0)) {
      return;
    }

    // Output node list as a document fragment.
    elementContent(nodes, new NamespaceStack());
  }
Exemplo n.º 20
0
    boolean load(Object[] props, int offset) {
      if (_values.size() > 0) {
        int p = _values.size() - 1;
        while (_index[p] > _values.get(p).size() - 1 && p > 0) {
          _index[p] = 0;
          --p;
          ++_index[p];
        }
        if (_index[p] > _values.get(p).size() - 1) {
          return false;
        }

        // System.err.print("\t TypedValueGroup.load{");
        for (int i = 0; i < _values.size(); ++i) {
          props[i + offset] = _values.get(i).get(_index[i]).data;
          // System.err.print("[" + _index[i] + "](" + props[i+offset].getClass().getSimpleName() +
          // ')');
        }
        // System.err.println("}");
        ++_index[_values.size() - 1];
        return true;
      } else {
        return false;
      }
    }
  public StepDescriptor getStep(int id) {
    for (Iterator iterator = steps.iterator(); iterator.hasNext(); ) {
      StepDescriptor step = (StepDescriptor) iterator.next();

      if (step.getId() == id) {
        return step;
      }
    }

    return null;
  }
  public SplitDescriptor getSplit(int id) {
    for (Iterator iterator = splits.iterator(); iterator.hasNext(); ) {
      SplitDescriptor splitDescriptor = (SplitDescriptor) iterator.next();

      if (splitDescriptor.getId() == id) {
        return splitDescriptor;
      }
    }

    return null;
  }
  public JoinDescriptor getJoin(int id) {
    for (Iterator iterator = joins.iterator(); iterator.hasNext(); ) {
      JoinDescriptor joinDescriptor = (JoinDescriptor) iterator.next();

      if (joinDescriptor.getId() == id) {
        return joinDescriptor;
      }
    }

    return null;
  }
  public ActionDescriptor getInitialAction(int id) {
    for (Iterator iterator = initialActions.iterator(); iterator.hasNext(); ) {
      ActionDescriptor actionDescriptor = (ActionDescriptor) iterator.next();

      if (actionDescriptor.getId() == id) {
        return actionDescriptor;
      }
    }

    return null;
  }
Exemplo n.º 25
0
  /**
   * This will invoke the <code>ContentHandler.startPrefixMapping</code> callback when a new
   * namespace is encountered in the <code>Document</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   * @return <code>Attributes</code> declaring the namespaces local to <code>element</code> or
   *     <code>null</code>.
   */
  private Attributes startPrefixMapping(Element element, NamespaceStack namespaces)
      throws JDOMException {
    AttributesImpl nsAtts = null; // The namespaces as xmlns attributes

    Namespace ns = element.getNamespace();
    if (ns != Namespace.XML_NAMESPACE) {
      String prefix = ns.getPrefix();
      String uri = namespaces.getURI(prefix);
      if (!ns.getURI().equals(uri)) {
        namespaces.push(ns);
        nsAtts = this.addNsAttribute(nsAtts, ns);
        try {
          contentHandler.startPrefixMapping(prefix, ns.getURI());
        } catch (SAXException se) {
          throw new JDOMException("Exception in startPrefixMapping", se);
        }
      }
    }

    // Fire additional namespace declarations
    List additionalNamespaces = element.getAdditionalNamespaces();
    if (additionalNamespaces != null) {
      Iterator itr = additionalNamespaces.iterator();
      while (itr.hasNext()) {
        ns = (Namespace) itr.next();
        String prefix = ns.getPrefix();
        String uri = namespaces.getURI(prefix);
        if (!ns.getURI().equals(uri)) {
          namespaces.push(ns);
          nsAtts = this.addNsAttribute(nsAtts, ns);
          try {
            contentHandler.startPrefixMapping(prefix, ns.getURI());
          } catch (SAXException se) {
            throw new JDOMException("Exception in startPrefixMapping", se);
          }
        }
      }
    }
    return nsAtts;
  }
Exemplo n.º 26
0
  /**
   * This will invoke the callbacks for the content of an element.
   *
   * @param content element content as a <code>List</code> of nodes.
   * @param namespaces <code>List</code> stack of Namespaces in scope.
   */
  private void elementContent(List content, NamespaceStack namespaces) throws JDOMException {
    for (Iterator i = content.iterator(); i.hasNext(); ) {
      Object obj = i.next();

      if (obj instanceof Content) {
        this.elementContent((Content) obj, namespaces);
      } else {
        // Not a valid element child. This could happen with
        // application-provided lists which may contain non
        // JDOM objects.
        handleError(new JDOMException("Invalid element content: " + obj));
      }
    }
  }
Exemplo n.º 27
0
    /**
     * Returns the content of a JDOM Element detached from it.
     *
     * @param elt the element to get the content from.
     * @return a (possibly empty) list of JDOM nodes, detached from their parent.
     */
    private List getDetachedContent(Element elt) {
      List content = elt.getContent();
      List nodes = new ArrayList(content.size());

      while (content.size() != 0) {
        Object o = content.remove(0);
        nodes.add(o);
      }
      return (nodes);
    }
Exemplo n.º 28
0
  /**
   * This will output a list of JDOM nodes as a document, firing off the SAX events that have been
   * registered.
   *
   * <p><strong>Warning</strong>: This method may output ill-formed XML documents if the list
   * contains top-level objects that are not legal at the document level (e.g. Text or CDATA nodes,
   * multiple Element nodes, etc.). Thus, it should only be used to output document portions towards
   * ContentHandlers capable of accepting such ill-formed documents (such as XSLT processors).
   *
   * @param nodes <code>List</code> of JDOM nodes to output.
   * @throws JDOMException if any error occurred.
   * @see #output(org.jdom2.Document)
   */
  public void output(List<? extends Content> nodes) throws JDOMException {
    if ((nodes == null) || (nodes.size() == 0)) {
      return;
    }

    // contentHandler.setDocumentLocator()
    documentLocator(null);

    // contentHandler.startDocument()
    startDocument();

    // Process node list.
    elementContent(nodes, new NamespaceStack());

    // contentHandler.endDocument()
    endDocument();
  }
  /** finish handling and set up the enclosed object Usually called when the end tag is seen */
  @Override
  public void finishProcessing() {
    IMeasuredSpectrum pMeasured = null;

    final double pScore = getScore();
    final double pHyperScore = getHyperScore();
    final double rawScore = getRawScore();
    IonTypeScorer scorer = getIonScore();

    IProteinPosition[] containedInProteins = m_Positions.toArray(IProteinPosition.EMPTY_ARRAY);
    ((Polypeptide) m_Peptide).setContainedInProteins(containedInProteins);
    SpectralMatch scan =
        new SpectralMatch(m_Peptide, pMeasured, pScore, pHyperScore, rawScore, scorer, null);

    if (m_Usage != null) scan.getUsage().addTo(m_Usage);

    setElementObject(scan);
  }
Exemplo n.º 30
0
  // returns list of statements
  public static void replaceMult(Statement st, NodeFactory f, Map o2n, Collection result)
      throws ModelException {

    List l1 = new ArrayList();
    replaceMultSPO(st, f, o2n, l1, st.subject(), 0);

    List l2 = new ArrayList();
    for (int i = 0; i < l1.size(); i++)
      replaceMultSPO((Statement) l1.get(i), f, o2n, l2, st.predicate(), 1);

    for (int i = 0; i < l2.size(); i++)
      replaceMultSPO((Statement) l2.get(i), f, o2n, result, st.object(), 2);
  }