List of usage examples for java.net URI equals
public boolean equals(Object ob)
From source file:eu.asterics.mw.services.TestResourceRegistry.java
@Test public void testRelativeToAbsoluteToRelative() { URI relative = URI.create(ResourceRegistry.MODELS_FOLDER); URI absolute = ResourceRegistry.getInstance().toAbsolute(ResourceRegistry.MODELS_FOLDER); URI convertedRelative = ResourceRegistry.getInstance().toRelative(absolute.toString()); if (!relative.equals(convertedRelative)) { fail("Testing URI toAbsolute and back toRelative failed: original <" + relative + ">, convertedRelative <" + convertedRelative + ">"); }/*from w w w . j a v a 2s . com*/ }
From source file:de.uni_rostock.goodod.evaluator.OntologyTest.java
private void writeTable(FileWriter writer, StatType type) throws IOException { String theTable = ""; Set<URI> allOntologies = new HashSet<URI>(25); allOntologies.addAll(groupAOntologies); allOntologies.addAll(groupBOntologies); if (null != modelOntology) { allOntologies.add(modelOntology); }//from w ww .java 2 s . c o m List<URI> ontologyList = new ArrayList<URI>(allOntologies); theTable = tableHeader(ontologyList) + '\n'; for (URI u : ontologyList) { if ((null != modelOntology) && u.equals(modelOntology)) { continue; } if (null == resultMap.get(u)) { continue; } theTable = theTable + writeTableLine(u, ontologyList, type) + '\n'; } writer.write(theTable); writer.flush(); }
From source file:org.apache.taverna.scufl2.wfdesc.WfdescSerialiser.java
protected OntModel save(final WorkflowBundle bundle) { final OntModel model = ModelFactory.createOntologyModel(); bundle.accept(new VisitorWithPath() { Scufl2Tools scufl2Tools = new Scufl2Tools(); public boolean visit() { WorkflowBean node = getCurrentNode(); // System.out.println(node); if (node instanceof WorkflowBundle) { return true; }//from w ww . j ava 2 s. co m // @SuppressWarnings("rawtypes") if (node instanceof org.apache.taverna.scufl2.api.core.Workflow) { entityForBean(node, Wfdesc.Workflow); } else if (node instanceof Processor) { Processor processor = (Processor) node; Individual process = entityForBean(processor, Wfdesc.Process); Individual wf = entityForBean(processor.getParent(), Wfdesc.Workflow); wf.addProperty(Wfdesc.hasSubProcess, process); } else if (node instanceof InputPort) { WorkflowBean parent = ((Child) node).getParent(); Individual input = entityForBean(node, Wfdesc.Input); Individual process = entityForBean(parent, Wfdesc.Process); process.addProperty(Wfdesc.hasInput, input); } else if (node instanceof OutputPort) { WorkflowBean parent = ((Child) node).getParent(); Individual output = entityForBean(node, Wfdesc.Output); Individual process = entityForBean(parent, Wfdesc.Process); process.addProperty(Wfdesc.hasOutput, output); } else if (node instanceof DataLink) { WorkflowBean parent = ((Child) node).getParent(); DataLink link = (DataLink) node; Individual dl = entityForBean(link, Wfdesc.DataLink); Individual source = entityForBean(link.getReceivesFrom(), Wfdesc.Output); dl.addProperty(Wfdesc.hasSource, source); Individual sink = entityForBean(link.getSendsTo(), Wfdesc.Input); dl.addProperty(Wfdesc.hasSink, sink); Individual wf = entityForBean(parent, Wfdesc.Workflow); wf.addProperty(Wfdesc.hasDataLink, dl); } else if (node instanceof Profile) { // So that we can get at the ProcessorBinding - buy only if // it is the main Profile return node == bundle.getMainProfile(); } else if (node instanceof ProcessorBinding) { ProcessorBinding b = (ProcessorBinding) node; Activity a = b.getBoundActivity(); Processor boundProcessor = b.getBoundProcessor(); Individual process = entityForBean(boundProcessor, Wfdesc.Process); // Note: We don't describe the activity and processor // binding in wfdesc. Instead we // assign additional types and attributes to the parent // processor try { URI type = a.getType(); Configuration c = scufl2Tools.configurationFor(a, b.getParent()); JsonNode json = c.getJson(); if (type.equals(BEANSHELL)) { process.addRDFType(Wf4ever.BeanshellScript); String s = json.get("script").asText(); process.addProperty(Wf4ever.script, s); JsonNode localDep = json.get("localDependency"); if (localDep != null && localDep.isArray()) { for (int i = 0; i < localDep.size(); i++) { String depStr = localDep.get(i).asText(); // FIXME: Better class for dependency? Individual dep = model.createIndividual(OWL.Thing); dep.addLabel(depStr, null); dep.addComment("JAR dependency", "en"); process.addProperty(Roterms.requiresSoftware, dep); // Somehow this gets the whole thing to fall // out of the graph! // QName depQ = new // QName("http://google.com/", ""+ // UUID.randomUUID()); // sesameManager.rename(dep, depQ); } } } if (type.equals(RSHELL)) { process.addRDFType(Wf4ever.RScript); String s = json.get("script").asText(); process.addProperty(Wf4ever.script, s); } if (type.equals(WSDL)) { process.addRDFType(Wf4ever.SOAPService); JsonNode operation = json.get("operation"); URI wsdl = URI.create(operation.get("wsdl").asText()); process.addProperty(Wf4ever.wsdlURI, wsdl.toASCIIString()); process.addProperty(Wf4ever.wsdlOperationName, operation.get("name").asText()); process.addProperty(Wf4ever.rootURI, wsdl.resolve("/").toASCIIString()); } if (type.equals(REST)) { process.addRDFType(Wf4ever.RESTService); // System.out.println(json); JsonNode request = json.get("request"); String absoluteURITemplate = request.get("absoluteURITemplate").asText(); String uriTemplate = absoluteURITemplate.replace("{", ""); uriTemplate = uriTemplate.replace("}", ""); // TODO: Detect {} try { URI root = new URI(uriTemplate).resolve("/"); process.addProperty(Wf4ever.rootURI, root.toASCIIString()); } catch (URISyntaxException e) { logger.warning("Potentially invalid URI template: " + absoluteURITemplate); // Uncomment to temporarily break // TestInvalidURITemplate: // rest.getWfRootURI().add(URI.create("http://example.com/FRED")); } } if (type.equals(TOOL)) { process.addRDFType(Wf4ever.CommandLineTool); JsonNode desc = json.get("toolDescription"); // System.out.println(json); JsonNode command = desc.get("command"); if (command != null) { process.addProperty(Wf4ever.command, command.asText()); } } if (type.equals(NESTED_WORKFLOW)) { Workflow nestedWf = scufl2Tools.nestedWorkflowForProcessor(boundProcessor, b.getParent()); // The parent process is a specialization of the // nested workflow // (because the nested workflow could exist as // several processors) specializationOf(boundProcessor, nestedWf); process.addRDFType(Wfdesc.Workflow); // Just like the Processor specializes the nested // workflow, the // ProcessorPorts specialize the WorkflowPort for (ProcessorPortBinding portBinding : b.getInputPortBindings()) { // Map from activity port (not in wfdesc) to // WorkflowPort WorkflowPort wfPort = nestedWf.getInputPorts() .getByName(portBinding.getBoundActivityPort().getName()); if (wfPort == null) { continue; } specializationOf(portBinding.getBoundProcessorPort(), wfPort); } for (ProcessorPortBinding portBinding : b.getOutputPortBindings()) { WorkflowPort wfPort = nestedWf.getOutputPorts() .getByName(portBinding.getBoundActivityPort().getName()); if (wfPort == null) { continue; } specializationOf(portBinding.getBoundProcessorPort(), wfPort); } } } catch (IndexOutOfBoundsException ex) { } return false; } else { // System.out.println("--NO!"); return false; } for (Annotation ann : scufl2Tools.annotationsFor(node, bundle)) { String annotationBody = ann.getBody().toASCIIString(); String baseURI = bundle.getGlobalBaseURI().resolve(ann.getBody()).toASCIIString(); InputStream annotationStream; try { annotationStream = bundle.getResources().getResourceAsInputStream(annotationBody); try { // FIXME: Don't just assume Lang.TURTLE RDFDataMgr.read(model, annotationStream, baseURI, Lang.TURTLE); } catch (RiotException e) { logger.log(Level.WARNING, "Can't parse RDF Turtle from " + annotationBody, e); } finally { annotationStream.close(); } } catch (IOException e) { logger.log(Level.WARNING, "Can't read " + annotationBody, e); } } if (node instanceof Named) { Named named = (Named) node; entityForBean(node, OWL.Thing).addLabel(named.getName(), null); } return true; } private void specializationOf(WorkflowBean special, WorkflowBean general) { Individual specialEnt = entityForBean(special, Prov_o.Entity); Individual generalEnt = entityForBean(general, Prov_o.Entity); specialEnt.addProperty(Prov_o.specializationOf, generalEnt); } private Individual entityForBean(WorkflowBean bean, Resource thing) { return model.createIndividual(uriForBean(bean), thing); } // @Override // public boolean visitEnter(WorkflowBean node) { // if (node instanceof Processor // || node instanceof org.apache.taverna.scufl2.api.core.Workflow // || node instanceof Port || node instanceof DataLink) { // visit(node); // return true; // } // // The other node types (e.g. dispatch stack, configuration) are // // not (directly) represented in wfdesc //// System.out.println("Skipping " + node); // return false; // }; }); return model; }
From source file:net.di2e.ecdr.source.rest.CDROpenSearchSource.java
@Override public ResourceResponse retrieveResource(URI uri, Map<String, Serializable> requestProperties) throws ResourceNotFoundException, ResourceNotSupportedException, IOException { LOGGER.debug("Retrieving Resource from remote CDR Source named [{}] using URI [{}]", localId, uri); // Check to see if the resource-uri value was passed through which is // the original metacard uri which // can be different from what was returned or used by the client Serializable resourceUriProperty = requestProperties.get(Metacard.RESOURCE_URI); if (resourceUriProperty != null && resourceUriProperty instanceof URI) { URI resourceUri = (URI) resourceUriProperty; if (!resourceUri.equals(uri)) { LOGGER.debug(/*from www . ja va2s .c om*/ "Overriding the passed in resourceUri [{}] with the value found in the request properties [{}]", uri, resourceUri); uri = resourceUri; } } else if (uri != null) { String scheme = uri.getScheme(); if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) { uri = getURIFromMetacard(uri); } } ResourceResponse resourceResponse = null; if (uri != null) { LOGGER.debug("Retrieving the remote resource using the uri [{}]", uri); WebClient retrieveWebClient = WebClient.create(uri); WebClient.getConfig(retrieveWebClient).getHttpConduit(); TLSUtil.setTLSOptions(retrieveWebClient, getDisableCNCheck()); resourceResponse = doRetrieval(retrieveWebClient, requestProperties); } if (resourceResponse == null) { LOGGER.warn("Could not retrieve resource from CDR Source named [{}] using uri [{}]", localId, uri); throw new ResourceNotFoundException( "Could not retrieve resource from source [" + localId + "] and uri [" + uri + "]"); } return resourceResponse; }
From source file:org.objectweb.proactive.core.remoteobject.RemoteObjectSet.java
private Throwable handleProtocolException(Throwable e, URI uri, boolean multiProtocol, MutableBoolean anyException) {//w ww. j av a 2 s . c om anyException.setValue(true); if (!uri.equals(defaultURI)) { LOGGER_RO.warn("[ROAdapter] Disabling protocol " + uri.getScheme() + " because of received exception", e); lastBenchmarkResults.put(uri, UNREACHABLE_VALUE); return null; } else { if (multiProtocol) { LOGGER_RO.warn("[ROAdapter] Skipping default protocol " + uri.getScheme() + " because of received exception", e); } lastBenchmarkResults.put(uri, UNREACHABLE_VALUE); return e; } }
From source file:org.wrml.runtime.rest.ApiBuilder.java
private boolean isSuitableLinkEndpoint(final Resource referrerResource, final LinkRelation linkRelation, final Resource endpointResource, final URI linkResponseSchemaUri) { if (referrerResource == null || linkRelation == null || endpointResource == null || linkResponseSchemaUri == null) { return false; }/*from w w w. ja v a 2s .c o m*/ if (linkRelation.getUri().equals(SystemLinkRelation.self.getUri()) && (referrerResource == endpointResource)) { return true; } final Context context = getContext(); final SchemaLoader schemaLoader = context.getSchemaLoader(); final URI defaultSchemaUri = endpointResource.getDefaultSchemaUri(); if (defaultSchemaUri != null) { if (defaultSchemaUri.equals(linkResponseSchemaUri)) { return true; } final Prototype defaultSchemaPrototype = schemaLoader.getPrototype(defaultSchemaUri); if (defaultSchemaPrototype.isAssignableFrom(linkResponseSchemaUri)) { return true; } } final Method method = linkRelation.getMethod(); final Set<URI> responseSchemaUris = endpointResource.getResponseSchemaUris(method); if (responseSchemaUris != null) { if (responseSchemaUris.contains(linkResponseSchemaUri)) { return true; } if (responseSchemaUris.size() > 0) { for (final URI responseSchemaUri : responseSchemaUris) { final Prototype responseSchemaPrototype = schemaLoader.getPrototype(responseSchemaUri); if (responseSchemaPrototype.isAssignableFrom(linkResponseSchemaUri)) { return true; } } } } return false; }
From source file:eu.esdihumboldt.hale.common.core.io.PathUpdate.java
/** * Create a path updater based on a pair of known old and new locations. * // ww w . j a v a 2 s .co m * @param oldLocation the old location of a file, may be null * @param newLocation the new location of the same file (though the file * name may be different), may be null */ public PathUpdate(URI oldLocation, URI newLocation) { super(); this.oldLocation = oldLocation; this.newLocation = newLocation; /* * analyze paths (w/o file name) of both URIs to find out which of the * later parts are equal, to determine which part of the old location * has to be replaced by which part of the new location for other files * that have been moved in a similar way to the analyzed file. */ if (oldLocation != null && newLocation != null && !oldLocation.equals(newLocation)) analysePaths(oldLocation, newLocation); }
From source file:org.fcrepo.kernel.utils.BasicCacheEntry.java
/** * Calculate the fixity of a CacheEntry by piping it through * a simple fixity-calculating InputStream * * @param checksum the checksum previously generated for the entry * @param size the size of the entry// www .j av a 2s.c o m * @return * @throws RepositoryException */ @Override public Collection<FixityResult> checkFixity(final URI checksum, final long size) throws RepositoryException { final String digest = ContentDigest.getAlgorithm(checksum); try (FixityInputStream fixityInputStream = new FixityInputStream(this.getInputStream(), MessageDigest.getInstance(digest))) { IOUtils.copy(fixityInputStream, NULL_OUTPUT_STREAM); final URI calculatedChecksum = ContentDigest.asURI(digest, fixityInputStream.getMessageDigest().digest()); final FixityResult result = new FixityResultImpl(this, fixityInputStream.getByteCount(), calculatedChecksum); if (checksum == null || checksum.equals(ContentDigest.missingChecksum()) || size == -1L) { result.getStatus().add(MISSING_STORED_FIXITY); } if (!result.matches(checksum)) { result.getStatus().add(BAD_CHECKSUM); } if (!result.matches(size)) { result.getStatus().add(BAD_SIZE); } if (result.matches(size, checksum)) { result.getStatus().add(SUCCESS); } LOGGER.debug("Got {}", result.toString()); return ImmutableSet.of(result); } catch (final IOException e) { LOGGER.debug("Got error closing input stream: {}", e); throw propagate(e); } catch (final NoSuchAlgorithmException e1) { throw propagate(e1); } }
From source file:org.wrml.runtime.service.file.FileSystemService.java
@Override public Model save(final Model model) { if (model == null) { final ServiceException e = new ServiceException("The model to save cannot be null.", null, this); LOG.error(e.getMessage(), e);/* w w w. j a v a2 s. c o m*/ throw e; } final Context context = model.getContext(); final Keys keys = model.getKeys(); if (keys == null) { final ServiceException e = new ServiceException("The model must have keys in order to be saved.", null, this); LOG.error(e.getMessage(), e); throw e; } final Set<URI> keyedSchemaUris = keys.getKeyedSchemaUris(); if (keyedSchemaUris == null || keyedSchemaUris.isEmpty()) { final ServiceException e = new ServiceException( "The model must have one or more key values in order to be saved.", null, this); LOG.error(e.getMessage(), e); throw e; } final int keyCount = keyedSchemaUris.size(); final Set<Path> keyLinkPaths = new LinkedHashSet<Path>(keyCount); // TODO Perhaps this flag should be overridable via config? //final URI documentSchemaUri = context.getSchemaLoader().getDocumentSchemaUri(); UUID managedDataFileHandle = null; final URI filedSchemaUri = getFiledSchemaUri(context); for (final URI keyedSchemaUri : keyedSchemaUris) { if (keyedSchemaUri.equals(filedSchemaUri)) { continue; } final Object keyValue = keys.getValue(keyedSchemaUri); final Path keyLinkPath = getKeyLinkPath(keyedSchemaUri, keyValue); if (keyLinkPath == null) { continue; } if (managedDataFileHandle == null && Files.exists(keyLinkPath)) { // This model has been saved here (managed) before. // Get the name of the file associated with the (existing) model's data (so we can overwrite it). final String dataFileHandleString = keyLinkPath.getFileName().toString(); try { managedDataFileHandle = UUID.fromString(dataFileHandleString); } catch (final Exception e) { managedDataFileHandle = null; } } // Add the key link path keyLinkPaths.add(keyLinkPath); } Path dataFilePath = null; if (model instanceof Filed) { final Filed filed = (Filed) model; final File file = filed.getFile(); if (file != null) { dataFilePath = file.toPath(); } } if (dataFilePath == null) { if (managedDataFileHandle == null) { managedDataFileHandle = UUID.randomUUID(); } dataFilePath = getManagedDataFilePath(model.getSchemaUri(), managedDataFileHandle.toString()); } // TODO: All of the writes should probably be synchronized somehow, yes?. // Write the model data to a "data" file writeDataFile(model, dataFilePath); for (final Path keyLinkPath : keyLinkPaths) { // Write each key as a symlink "key" that references the model's data file writeKeyLink(keyLinkPath, dataFilePath); } return get(keys, model.getDimensions()); }
From source file:org.paxle.core.norm.impl.ReferenceNormalizer.java
/** * Normalizes all {@link IParserDocument#getLinks() links} contained in a * {@link IParserDocument parser-document}. * /*from w w w . j ava2 s . c o m*/ * @param pdoc the {@link IParserDocument parser-document} */ private void normalizeParserDoc(final IParserDocument pdoc) { /* ============================================================= * Normalize Sub-Documents * ============================================================= */ final Map<String, IParserDocument> subdocMap = pdoc.getSubDocs(); if (subdocMap != null && subdocMap.size() > 0) { for (final IParserDocument subdoc : subdocMap.values()) { this.normalizeParserDoc(subdoc); } } /* ============================================================= * Normalize Links * ============================================================= */ final Map<URI, LinkInfo> linkMap = pdoc.getLinks(); if (linkMap == null || linkMap.size() == 0) return; final Map<URI, LinkInfo> normalizedLinks = new HashMap<URI, LinkInfo>(); final Charset charset = (pdoc.getCharset() == null) ? UTF8 : pdoc.getCharset(); // UTF-8 is a recommended fallback but not standard yet final Iterator<Map.Entry<URI, LinkInfo>> it = linkMap.entrySet().iterator(); while (it.hasNext()) { final Map.Entry<URI, LinkInfo> entry = it.next(); final URI locationURI = entry.getKey(); final String location = locationURI.toASCIIString(); final URI normalizedURI = this.normalizeReference(location, charset); if (normalizedURI == null) { this.logger.info("removing malformed reference: " + location); // FIXME: shouldn't we call it.remove() here? continue; } else if (normalizedURI.equals(locationURI)) { continue; } this.logger.debug("normalized reference " + location + " to " + normalizedURI); normalizedLinks.put(normalizedURI, entry.getValue()); it.remove(); } linkMap.putAll(normalizedLinks); }