blob: b7e9b6252f4978c48e17f216f7b4a60a40b8faae (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.branch.management.exchange.resource;
import java.net.URI;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.resource.management.IResourceLocator;
import org.eclipse.osee.framework.resource.management.IResourceLocatorProvider;
import org.eclipse.osee.framework.resource.management.exception.MalformedLocatorException;
import org.eclipse.osee.framework.resource.management.util.ResourceLocator;
/**
* @author Roberto E. Escobar
*/
public class ExchangeLocatorProvider implements IResourceLocatorProvider {
public static final String PROTOCOL = "exchange";
@Override
public IResourceLocator generateResourceLocator(String seed, String name) throws OseeCoreException {
URI uri = null;
try {
uri = new URI(generatePath(name));
} catch (Exception ex) {
throw new MalformedLocatorException(ex);
}
return new ResourceLocator(uri);
}
@Override
public IResourceLocator getResourceLocator(String path) throws OseeCoreException {
URI uri = null;
if (isPathValid(path) != false) {
try {
uri = new URI(path);
} catch (Exception ex) {
throw new MalformedLocatorException(ex);
}
} else {
throw new MalformedLocatorException(String.format("Invalid path hint: [%s]", path));
}
return new ResourceLocator(uri);
}
@Override
public String getSupportedProtocol() {
return PROTOCOL;
}
@Override
public boolean isValid(String protocol) {
return Strings.isValid(protocol) != false && protocol.startsWith(getSupportedProtocol()) != false;
}
private boolean isPathValid(String value) {
return Strings.isValid(value) && value.startsWith(getSupportedProtocol() + "://");
}
private String generatePath(String name) throws MalformedLocatorException {
StringBuilder builder = new StringBuilder(getSupportedProtocol() + "://");
if (Strings.isValid(name)) {
builder.append(name);
} else {
throw new MalformedLocatorException("Invalid arguments during locator generation.");
}
return builder.toString();
}
}
|