コード例 #1
0
  private static void exportThisSeries(
      String name,
      String target_sea_state_datum,
      NamedList thisList,
      String[] sea_state_headings,
      Element itt,
      Document doc) {
    // ok, put us into the element
    org.w3c.dom.Element datum = doc.createElement(target_sea_state_datum);

    datum.setAttribute("Type", name);

    // and step through its values
    Collection<Double> indices = thisList.getValues();
    int ctr = 0;
    for (Iterator<Double> iter = indices.iterator(); iter.hasNext(); ) {
      Double val = (Double) iter.next();
      if (val != null) {
        datum.setAttribute(sea_state_headings[ctr], writeThis(val.doubleValue()));
        ctr++;
      } else break;
    }

    itt.appendChild(datum);
  }
コード例 #2
0
  public static void exportThis(
      String target_sea_state_set,
      String target_sea_state_datum,
      String[] sea_state_headings,
      IntegerTargetTypeLookup states,
      Element envElement,
      Document doc) {
    // ok, put us into the element
    org.w3c.dom.Element itt = doc.createElement(target_sea_state_set);

    // get on with the name attribute
    Double unknown = states.getUnknownResult();
    if (unknown != null) itt.setAttribute(UNKNOWN_TYPE, writeThis(unknown.doubleValue()));

    // now the matrix of sea states
    Collection<String> keys = states.getNames();
    for (Iterator<String> iter = keys.iterator(); iter.hasNext(); ) {
      String thisN = (String) iter.next();

      // ok, cycle through the sea states for this participant
      NamedList thisList = states.getThisSeries(thisN);
      exportThisSeries(thisN, target_sea_state_datum, thisList, sea_state_headings, itt, doc);
    }

    envElement.appendChild(itt);
  }
コード例 #3
0
ファイル: XMLUtils.java プロジェクト: firstone/latic
  public static Collection<Node> getChildNodes(Node node) {
    Collection<Node> list = new LinkedList<Node>();

    NodeList nl = node.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++)
      if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) list.add(nl.item(i));

    return list;
  }
コード例 #4
0
ファイル: XMLUtils.java プロジェクト: firstone/latic
  public static Collection<Node> getNodesByName(Node node, String name) {
    Collection<Node> list = new LinkedList<Node>();

    NodeList nl = node.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++)
      if (nl.item(i).getNodeName().equals(name)) list.add(nl.item(i));

    return list;
  }
コード例 #5
0
ファイル: MetatypeTest.java プロジェクト: vikchilu/bnd
 private static void assertEqualList(List<?> a, Collection<?> b) {
   if (a.size() == b.size()) {
     for (Object x : a) {
       if (!b.contains(x))
         throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
     }
     return;
   }
   throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">");
 }
コード例 #6
0
 private static Collection<Node> getNodeMatching(Node body, String regexp) {
   final Collection<Node> nodes = new ArrayList<>();
   if (body.getNodeName().matches(regexp)) nodes.add(body);
   if (body.getChildNodes().getLength() == 0) return nodes;
   NodeList returnList = body.getChildNodes();
   for (int k = 0; k < returnList.getLength(); k++) {
     final Node node = returnList.item(k);
     nodes.addAll(getNodeMatching(node, regexp));
   }
   return nodes;
 }
コード例 #7
0
  public boolean hasRepositoryLocation(IRepositoryLocation repositoryLocationToCheck) {
    Collection c = getAllRepositoryLocations();

    for (Iterator en = c.iterator(); en.hasNext(); ) {
      IRepositoryLocation elt = (IRepositoryLocation) en.next();
      if (elt.isEquivalent(repositoryLocationToCheck)) {
        return true;
      }
    }
    return false;
  }
コード例 #8
0
  public boolean hasSourceCodeFile(IJavaSourceFile sourceCodeFileToCheck) {
    Collection c = getAllSourceCodeFiles();

    for (Iterator en = c.iterator(); en.hasNext(); ) {
      IJavaSourceFile elt = (IJavaSourceFile) en.next();
      if (elt.isEquivalent(sourceCodeFileToCheck)) {
        return true;
      }
    }
    return false;
  }
コード例 #9
0
 private static Collection<String> parseSoapResponseForUrls(byte[] data)
     throws SOAPException, IOException {
   // System.out.println(new String(data));
   final Collection<String> urls = new ArrayList<>();
   MessageFactory factory = MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION);
   final MimeHeaders headers = new MimeHeaders();
   headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE);
   SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data));
   SOAPBody body = message.getSOAPBody();
   for (Node node : getNodeMatching(body, ".*:XAddrs")) {
     if (node.getTextContent().length() > 0) {
       urls.addAll(Arrays.asList(node.getTextContent().split(" ")));
     }
   }
   return urls;
 }
コード例 #10
0
 public Collection hasRepositoryLocations(Collection repositoryLocationsToCheck) {
   Vector v = new Vector();
   for (Iterator en = repositoryLocationsToCheck.iterator(); en.hasNext(); ) {
     IRepositoryLocation elt = (IRepositoryLocation) en.next();
     v.addElement(new Boolean(hasRepositoryLocation(elt)));
   }
   return v;
 }
コード例 #11
0
 public Collection hasSourceCodeFiles(Collection sourceCodeFilesToCheck) {
   Vector v = new Vector();
   for (Iterator en = sourceCodeFilesToCheck.iterator(); en.hasNext(); ) {
     IJavaSourceFile elt = (IJavaSourceFile) en.next();
     v.addElement(new Boolean(hasSourceCodeFile(elt)));
   }
   return v;
 }
コード例 #12
0
 public boolean hasAllSourceCodeFiles(Collection sourceCodeFilesToCheck) {
   for (Iterator en = sourceCodeFilesToCheck.iterator(); en.hasNext(); ) {
     IJavaSourceFile elt = (IJavaSourceFile) en.next();
     if (!hasSourceCodeFile(elt)) {
       return false;
     }
   }
   return true;
 }
コード例 #13
0
 public boolean hasAllRepositoryLocations(Collection repositoryLocationsToCheck) {
   for (Iterator en = repositoryLocationsToCheck.iterator(); en.hasNext(); ) {
     IRepositoryLocation elt = (IRepositoryLocation) en.next();
     if (!hasRepositoryLocation(elt)) {
       return false;
     }
   }
   return true;
 }
コード例 #14
0
 /**
  * Discover WS device on the local network with specified filter
  *
  * @param regexpProtocol url protocol matching regexp like "^http$", might be empty ""
  * @param regexpPath url path matching regexp like "onvif", might be empty ""
  * @return list of unique device urls filtered
  */
 public static Collection<URL> discoverWsDevicesAsUrls(String regexpProtocol, String regexpPath) {
   final Collection<URL> urls =
       new TreeSet<>(
           new Comparator<URL>() {
             public int compare(URL o1, URL o2) {
               return o1.toString().compareTo(o2.toString());
             }
           });
   for (String key : discoverWsDevices()) {
     try {
       final URL url = new URL(key);
       boolean ok = true;
       if (regexpProtocol.length() > 0 && !url.getProtocol().matches(regexpProtocol)) ok = false;
       if (regexpPath.length() > 0 && !url.getPath().matches(regexpPath)) ok = false;
       if (ok) urls.add(url);
     } catch (MalformedURLException e) {
       e.printStackTrace();
     }
   }
   return urls;
 }
コード例 #15
0
  // refactored this out from the three addAction methods above
  private void addAction(Object actionsCollectionOrMap, ActionDescriptor descriptor) {
    if (getAction(descriptor.getId()) != null) {
      throw new IllegalArgumentException(
          "action with id " + descriptor.getId() + " already exists for this step.");
    }

    if (actionsCollectionOrMap instanceof Map) {
      ((Map) actionsCollectionOrMap).put(new Integer(descriptor.getId()), descriptor);
    } else {
      ((Collection) actionsCollectionOrMap).add(descriptor);
    }
  }
コード例 #16
0
 JdbcIndexDefinition(
     DataSource ds,
     Element element,
     Set allIndexedFields,
     boolean storeText,
     boolean mergeText,
     Analyzer a,
     boolean isSub) {
   this.dataSource = ds;
   indexSql = element.getAttribute("sql");
   key = element.getAttribute("key");
   String elementId = element.getAttribute("identifier");
   identifier = "".equals(elementId) ? key : elementId;
   findSql = element.getAttribute("find");
   NodeList childNodes = element.getChildNodes();
   for (int k = 0; k < childNodes.getLength(); k++) {
     if (childNodes.item(k) instanceof Element) {
       Element childElement = (Element) childNodes.item(k);
       if ("field".equals(childElement.getLocalName())) {
         if (childElement.getAttribute("keyword").equals("true")) {
           keyWords.add(childElement.getAttribute("name"));
         }
         String m = childElement.getAttribute("multiple");
         if ("".equals(m)) m = "add";
         if (!m.equals("add")) {
           nonDefaultMultiples.put(
               childElement.getAttribute("name"), Indexer.Multiple.valueOf(m.toUpperCase()));
         }
         String b = childElement.getAttribute("boost");
         if (!b.equals("")) {
           boosts.put(childElement.getAttribute("name"), Float.valueOf(b));
         }
       } else if ("related".equals(childElement.getLocalName())) {
         subQueries.add(
             new JdbcIndexDefinition(
                 ds, childElement, allIndexedFields, storeText, mergeText, a, true));
       }
     }
   }
   this.analyzer = a;
   this.isSub = isSub;
   assert !isSub || "".equals(findSql);
 }
コード例 #17
0
 /**
  * Discover WS device on the local network
  *
  * @return list of unique devices access strings which might be URLs in most cases
  */
 public static Collection<String> discoverWsDevices() {
   final Collection<String> addresses = new ConcurrentSkipListSet<>();
   final CountDownLatch serverStarted = new CountDownLatch(1);
   final CountDownLatch serverFinished = new CountDownLatch(1);
   final Collection<InetAddress> addressList = new ArrayList<>();
   try {
     final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
     if (interfaces != null) {
       while (interfaces.hasMoreElements()) {
         NetworkInterface anInterface = interfaces.nextElement();
         if (!anInterface.isLoopback()) {
           final List<InterfaceAddress> interfaceAddresses = anInterface.getInterfaceAddresses();
           for (InterfaceAddress address : interfaceAddresses) {
             addressList.add(address.getAddress());
           }
         }
       }
     }
   } catch (SocketException e) {
     e.printStackTrace();
   }
   ExecutorService executorService = Executors.newCachedThreadPool();
   for (final InetAddress address : addressList) {
     Runnable runnable =
         new Runnable() {
           public void run() {
             try {
               final String uuid = UUID.randomUUID().toString();
               final String probe =
                   WS_DISCOVERY_PROBE_MESSAGE.replaceAll(
                       "<wsa:MessageID>urn:uuid:.*</wsa:MessageID>",
                       "<wsa:MessageID>urn:uuid:" + uuid + "</wsa:MessageID>");
               final int port = random.nextInt(20000) + 40000;
               @SuppressWarnings("SocketOpenedButNotSafelyClosed")
               final DatagramSocket server = new DatagramSocket(port, address);
               new Thread() {
                 public void run() {
                   try {
                     final DatagramPacket packet = new DatagramPacket(new byte[4096], 4096);
                     server.setSoTimeout(WS_DISCOVERY_TIMEOUT);
                     long timerStarted = System.currentTimeMillis();
                     while (System.currentTimeMillis() - timerStarted < (WS_DISCOVERY_TIMEOUT)) {
                       serverStarted.countDown();
                       server.receive(packet);
                       final Collection<String> collection =
                           parseSoapResponseForUrls(
                               Arrays.copyOf(packet.getData(), packet.getLength()));
                       for (String key : collection) {
                         addresses.add(key);
                       }
                     }
                   } catch (SocketTimeoutException ignored) {
                   } catch (Exception e) {
                     e.printStackTrace();
                   } finally {
                     serverFinished.countDown();
                     server.close();
                   }
                 }
               }.start();
               try {
                 serverStarted.await(1000, TimeUnit.MILLISECONDS);
               } catch (InterruptedException e) {
                 e.printStackTrace();
               }
               if (address instanceof Inet4Address) {
                 server.send(
                     new DatagramPacket(
                         probe.getBytes(),
                         probe.length(),
                         InetAddress.getByName(WS_DISCOVERY_ADDRESS_IPv4),
                         WS_DISCOVERY_PORT));
               } else {
                 server.send(
                     new DatagramPacket(
                         probe.getBytes(),
                         probe.length(),
                         InetAddress.getByName(WS_DISCOVERY_ADDRESS_IPv6),
                         WS_DISCOVERY_PORT));
               }
             } catch (Exception e) {
               e.printStackTrace();
             }
             try {
               serverFinished.await((WS_DISCOVERY_TIMEOUT), TimeUnit.MILLISECONDS);
             } catch (InterruptedException e) {
               e.printStackTrace();
             }
           }
         };
     executorService.submit(runnable);
   }
   try {
     executorService.shutdown();
     executorService.awaitTermination(WS_DISCOVERY_TIMEOUT + 2000, TimeUnit.MILLISECONDS);
   } catch (InterruptedException ignored) {
   }
   return addresses;
 }
コード例 #18
0
ファイル: IGVSessionReader.java プロジェクト: dhmay/IGV
  private void processResource(Session session, Element element, HashMap additionalInformation) {

    String nodeName = element.getNodeName();
    boolean oldSession = nodeName.equals(SessionElement.DATA_FILE.getText());

    String label = getAttribute(element, SessionAttribute.LABEL.getText());
    String name = getAttribute(element, SessionAttribute.NAME.getText());
    String sampleId = getAttribute(element, SessionAttribute.SAMPLE_ID.getText());
    String description = getAttribute(element, SessionAttribute.DESCRIPTION.getText());
    String type = getAttribute(element, SessionAttribute.TYPE.getText());
    String coverage = getAttribute(element, SessionAttribute.COVERAGE.getText());
    String trackLine = getAttribute(element, SessionAttribute.TRACK_LINE.getText());
    String colorString = getAttribute(element, SessionAttribute.COLOR.getText());

    String relPathValue = getAttribute(element, SessionAttribute.RELATIVE_PATH.getText());
    boolean isRelativePath = ((relPathValue != null) && relPathValue.equalsIgnoreCase("true"));
    String serverURL = getAttribute(element, SessionAttribute.SERVER_URL.getText());

    // Older sessions used the "name" attribute for the path.
    String path = getAttribute(element, SessionAttribute.PATH.getText());

    if (oldSession && name != null) {
      path = name;
      int idx = name.lastIndexOf("/");
      if (idx > 0 && idx + 1 < name.length()) {
        name = name.substring(idx + 1);
      }
    }

    ResourceLocator resourceLocator;
    if (isRelativePath) {
      final String sessionPath = session.getPath();

      String absolutePath;
      if (sessionPath == null) {
        log.error("Null session path -- this is not expected");
        MessageUtils.showMessage("Unexpected error loading session: null session path");
        return;
      }
      absolutePath = FileUtils.getAbsolutePath(path, sessionPath);
      fullToRelPathMap.put(absolutePath, path);
      resourceLocator = new ResourceLocator(serverURL, absolutePath);

      // If the resourceLocator is relative, we assume coverage is as well
      if (coverage != null) {
        String absoluteCoveragePath = FileUtils.getAbsolutePath(coverage, sessionPath);
        resourceLocator.setCoverage(absoluteCoveragePath);
      }
    } else {
      resourceLocator = new ResourceLocator(serverURL, path);
      resourceLocator.setCoverage(coverage);
    }

    String url = getAttribute(element, SessionAttribute.URL.getText());
    if (url == null) {
      url = getAttribute(element, SessionAttribute.FEATURE_URL.getText());
    }
    resourceLocator.setUrl(url);

    String infolink = getAttribute(element, SessionAttribute.HYPERLINK.getText());
    if (infolink == null) {
      infolink = getAttribute(element, SessionAttribute.INFOLINK.getText());
    }
    resourceLocator.setInfolink(infolink);

    // Label is deprecated in favor of name.
    if (name != null) {
      resourceLocator.setName(name);
    } else {
      resourceLocator.setName(label);
    }

    resourceLocator.setSampleId(sampleId);

    resourceLocator.setDescription(description);
    // This test added to get around earlier bug in the writer
    if (type != null && !type.equals("local")) {
      resourceLocator.setType(type);
    }
    resourceLocator.setCoverage(coverage);
    resourceLocator.setTrackLine(trackLine);

    if (colorString != null) {
      try {
        Color c = ColorUtilities.stringToColor(colorString);
        resourceLocator.setColor(c);
      } catch (Exception e) {
        log.error("Error setting color: ", e);
      }
    }

    dataFiles.add(resourceLocator);

    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);
  }
コード例 #19
0
 public void removeRepositoryLocations(Collection repositoryLocations) {
   for (Iterator en = repositoryLocations.iterator(); en.hasNext(); ) {
     IRepositoryLocation elt = (IRepositoryLocation) en.next();
     removeRepositoryLocation(elt);
   }
 }
コード例 #20
0
 public void removeSourceCodeFiles(Collection sourceCodeFiles) {
   for (Iterator en = sourceCodeFiles.iterator(); en.hasNext(); ) {
     IJavaSourceFile elt = (IJavaSourceFile) en.next();
     removeSourceCodeFile(elt);
   }
 }
コード例 #21
0
  public void addPackageClass(PackageClass pClass) {

    Document doc;
    try {
      doc = getDocument();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    String name = pClass.getName();

    // check if such class exists and remove duplicates
    Element rootEl = doc.getDocumentElement();
    NodeList classEls = rootEl.getElementsByTagName(EL_CLASS);
    for (int i = 0; i < classEls.getLength(); i++) {
      Element nameEl = getElementByName((Element) classEls.item(i), EL_NAME);
      if (name.equals(nameEl.getTextContent())) {
        rootEl.removeChild(classEls.item(i));
      }
    }

    Element classNode = doc.createElement(EL_CLASS);
    doc.getDocumentElement().appendChild(classNode);
    classNode.setAttribute(ATR_TYPE, PackageClass.ComponentType.SCHEME.getXmlName());
    classNode.setAttribute(ATR_STATIC, "false");

    Element className = doc.createElement(EL_NAME);
    className.setTextContent(name);
    classNode.appendChild(className);

    Element desrc = doc.createElement(EL_DESCRIPTION);
    desrc.setTextContent(pClass.getDescription());
    classNode.appendChild(desrc);

    Element icon = doc.createElement(EL_ICON);
    icon.setTextContent(pClass.getIcon());
    classNode.appendChild(icon);

    // graphics
    classNode.appendChild(generateGraphicsNode(doc, pClass.getGraphics()));

    // ports
    List<Port> ports = pClass.getPorts();
    if (!ports.isEmpty()) {
      Element portsEl = doc.createElement(EL_PORTS);
      classNode.appendChild(portsEl);

      for (Port port : ports) {
        portsEl.appendChild(generatePortNode(doc, port));
      }
    }

    // fields
    Collection<ClassField> fields = pClass.getFields();
    if (!fields.isEmpty()) {
      Element fieldsEl = doc.createElement(EL_FIELDS);
      classNode.appendChild(fieldsEl);

      for (ClassField cf : fields) {
        fieldsEl.appendChild(generateFieldNode(doc, cf));
      }
    }

    // write
    try {
      writeDocument(doc, new FileOutputStream(xmlFile));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
コード例 #22
0
ファイル: IGVSessionReader.java プロジェクト: dhmay/IGV
  private void processResources(Session session, Element element, HashMap additionalInformation) {
    dataFiles = new ArrayList();
    missingDataFiles = new ArrayList();
    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);

    if (missingDataFiles.size() > 0) {
      StringBuffer message = new StringBuffer();
      message.append("<html>The following data file(s) could not be located.<ul>");
      for (ResourceLocator file : missingDataFiles) {
        if (file.isLocal()) {
          message.append("<li>");
          message.append(file.getPath());
          message.append("</li>");
        } else {
          message.append("<li>Server: ");
          message.append(file.getServerURL());
          message.append("  Path: ");
          message.append(file.getPath());
          message.append("</li>");
        }
      }
      message.append("</ul>");
      message.append("Common reasons for this include: ");
      message.append("<ul><li>The session or data files have been moved.</li> ");
      message.append(
          "<li>The data files are located on a drive that is not currently accessible.</li></ul>");
      message.append("</html>");

      MessageUtils.showMessage(message.toString());
    }
    if (dataFiles.size() > 0) {

      final List<String> errors = new ArrayList<String>();

      // Load files concurrently -- TODO, put a limit on # of threads?
      List<Thread> threads = new ArrayList(dataFiles.size());
      long t0 = System.currentTimeMillis();
      int i = 0;
      List<Runnable> synchronousLoads = new ArrayList<Runnable>();
      for (final ResourceLocator locator : dataFiles) {

        final String suppliedPath = locator.getPath();
        final String relPath = fullToRelPathMap.get(suppliedPath);

        Runnable runnable =
            new Runnable() {
              public void run() {
                List<Track> tracks = null;
                try {
                  tracks = igv.load(locator);
                  for (Track track : tracks) {
                    if (track == null) {
                      log.info("Null track for resource " + locator.getPath());
                      continue;
                    }

                    String id = track.getId();
                    if (id == null) {
                      log.info("Null track id for resource " + locator.getPath());
                      continue;
                    }

                    if (relPath != null) {
                      id = id.replace(suppliedPath, relPath);
                    }

                    List<Track> trackList = trackDictionary.get(id);
                    if (trackList == null) {
                      trackList = new ArrayList();
                      trackDictionary.put(id, trackList);
                    }
                    trackList.add(track);
                  }
                } catch (Exception e) {
                  log.error("Error loading resource " + locator.getPath(), e);
                  String ms =
                      "<b>" + locator.getPath() + "</b><br>&nbs;p&nbsp;" + e.toString() + "<br>";
                  errors.add(ms);
                }
              }
            };

        boolean isAlignment =
            locator.getPath().endsWith(".bam")
                || locator.getPath().endsWith(".entries")
                || locator.getPath().endsWith(".sam");

        // Run synchronously if in batch mode or if there are no "track" elments, or if this is an
        // alignment file
        if (isAlignment || Globals.isBatch() || !hasTrackElments) {
          synchronousLoads.add(runnable);
        } else {
          Thread t = new Thread(runnable);
          threads.add(t);
          t.start();
        }
        i++;
      }
      // Wait for all threads to complete
      for (Thread t : threads) {
        try {
          t.join();
        } catch (InterruptedException ignore) {
        }
      }

      // Now load data that must be loaded synchronously
      for (Runnable runnable : synchronousLoads) {
        runnable.run();
      }

      long dt = System.currentTimeMillis() - t0;
      log.debug("Total load time = " + dt);

      if (errors.size() > 0) {
        StringBuffer buf = new StringBuffer();
        buf.append("<html>Errors were encountered loading the session:<br>");
        for (String msg : errors) {
          buf.append(msg);
        }
        MessageUtils.showMessage(buf.toString());
      }
    }
    dataFiles = null;
  }