| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
package nl.toolforge.karma.core.location; |
| 5 |
|
|
| 6 |
|
import nl.toolforge.karma.core.KarmaRuntimeException; |
| 7 |
|
import nl.toolforge.karma.core.vc.cvsimpl.CVSRepository; |
| 8 |
|
import nl.toolforge.karma.core.vc.svnimpl.SubversionRepository; |
| 9 |
|
import org.apache.commons.logging.Log; |
| 10 |
|
import org.apache.commons.logging.LogFactory; |
| 11 |
|
|
| 12 |
|
public class LocationFactory { |
| 13 |
|
|
| 14 |
330 |
private static Log logger = LogFactory.getLog(LocationFactory.class); |
| 15 |
447 |
private static LocationFactory instance = null; |
| 16 |
141 |
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
public static LocationFactory getInstance() { |
| 21 |
|
|
| 22 |
1320 |
if (instance == null) { |
| 23 |
1403 |
instance = new LocationFactory(); |
| 24 |
141 |
} |
| 25 |
1320 |
return instance; |
| 26 |
1238 |
} |
| 27 |
|
|
| 28 |
165 |
private LocationFactory() { } |
| 29 |
141 |
|
| 30 |
|
public Location createLocation(LocationDescriptor descriptor) throws LocationException { |
| 31 |
|
|
| 32 |
1320 |
LocationType type = null; |
| 33 |
1238 |
try { |
| 34 |
1320 |
type = LocationType.getTypeInstance(descriptor.getType()); |
| 35 |
1238 |
} catch (IllegalArgumentException e) { |
| 36 |
0 |
throw new LocationException(LocationException.INVALID_LOCATION_TYPE, class="keyword">new Object[]{descriptor.getType(), descriptor.getId()}); |
| 37 |
1320 |
} |
| 38 |
1238 |
|
| 39 |
|
try { |
| 40 |
1320 |
if (type.equals(LocationType.CVS)) { |
| 41 |
1238 |
|
| 42 |
1200 |
CVSRepository location = new CVSRepository(descriptor.getId()); |
| 43 |
1090 |
|
| 44 |
|
try { |
| 45 |
1200 |
location.setProtocol(descriptor.getProtocol()); |
| 46 |
1090 |
} catch (RuntimeException r) { |
| 47 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"protocol"}); |
| 48 |
1200 |
} |
| 49 |
1090 |
try { |
| 50 |
1200 |
location.setHost(descriptor.getHost()); |
| 51 |
1090 |
} catch (RuntimeException r) { |
| 52 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"host"}); |
| 53 |
1200 |
} |
| 54 |
1090 |
try { |
| 55 |
1200 |
location.setPort(descriptor.getPort()); |
| 56 |
1090 |
} catch (RuntimeException r) { |
| 57 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"port"}); |
| 58 |
1200 |
} |
| 59 |
1090 |
try { |
| 60 |
1200 |
location.setRepository(descriptor.getRepository()); |
| 61 |
1090 |
} catch (RuntimeException r) { |
| 62 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"repository"}); |
| 63 |
1200 |
} |
| 64 |
1090 |
try { |
| 65 |
1200 |
location.setOffset(descriptor.getModuleOffset()); |
| 66 |
1090 |
} catch (RuntimeException r) { |
| 67 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"module-offset"}); |
| 68 |
1200 |
} |
| 69 |
2290 |
return location; |
| 70 |
1090 |
|
| 71 |
120 |
} else if (type.equals(LocationType.SUBVERSION)) { |
| 72 |
148 |
|
| 73 |
120 |
SubversionRepository location = new SubversionRepository(descriptor.getId()); |
| 74 |
148 |
|
| 75 |
|
try { |
| 76 |
120 |
location.setProtocol(descriptor.getProtocol()); |
| 77 |
148 |
} catch (RuntimeException r) { |
| 78 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"protocol"}); |
| 79 |
120 |
} |
| 80 |
148 |
try { |
| 81 |
120 |
location.setHost(descriptor.getHost()); |
| 82 |
148 |
} catch (RuntimeException r) { |
| 83 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"host"}); |
| 84 |
120 |
} |
| 85 |
148 |
try { |
| 86 |
120 |
location.setPort(descriptor.getPort()); |
| 87 |
148 |
} catch (RuntimeException r) { |
| 88 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"port"}); |
| 89 |
120 |
} |
| 90 |
148 |
try { |
| 91 |
120 |
location.setRepository(descriptor.getRepository()); |
| 92 |
148 |
} catch (RuntimeException r) { |
| 93 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"repository"}); |
| 94 |
120 |
} |
| 95 |
148 |
try { |
| 96 |
120 |
location.setOffset(descriptor.getModuleOffset()); |
| 97 |
148 |
} catch (RuntimeException r) { |
| 98 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE, class="keyword">new Object[]{"module-offset"}); |
| 99 |
120 |
} |
| 100 |
268 |
return location; |
| 101 |
148 |
} |
| 102 |
0 |
} catch (RuntimeException r) { |
| 103 |
0 |
logger.error(r); |
| 104 |
0 |
throw new LocationException(LocationException.INVALID_ELEMENT_VALUE); |
| 105 |
0 |
} |
| 106 |
0 |
throw new KarmaRuntimeException("Not implemented for other types than '"+LocationType.CVS+"' and '"+LocationType.SUBVERSION+"' "); |
| 107 |
|
} |
| 108 |
|
} |