1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.schema.bootstrap.partition;
22
23 import java.net.URL;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.Enumeration;
27 import java.util.List;
28
29
30
31
32
33 public class UniqueResourceException extends RuntimeException
34 {
35 private static final long serialVersionUID = 1L;
36
37 private final String resourceName;
38 private final List<URL> urls;
39 private final String resourceDescription;
40
41 public UniqueResourceException( String resourceName, String resourceDescription )
42 {
43 this( resourceName, null, resourceDescription );
44 }
45
46 public UniqueResourceException( String resourceName, List<URL> urls, String resourceDescription )
47 {
48 this.resourceName = resourceName;
49 this.urls = urls;
50 this.resourceDescription = resourceDescription;
51 }
52
53 public UniqueResourceException( String resourceName, URL first, Enumeration<URL> urlEnum, String resourceDescription )
54 {
55 this( resourceName, toList( first, urlEnum ), resourceDescription );
56 }
57
58 private static List<URL> toList( URL first, Enumeration<URL> urlEnum )
59 {
60 ArrayList<URL> urls = new ArrayList<URL>();
61 urls.add( first );
62 while( urlEnum.hasMoreElements() )
63 {
64 urls.add( urlEnum.nextElement() );
65 }
66 return urls;
67 }
68
69 public String getMessage()
70 {
71 StringBuffer buf = new StringBuffer( "Problem locating " ).append( resourceDescription ).append( "\n" );
72 if ( urls == null )
73 {
74 buf.append( "No resources named '" ).append( resourceName ).append( "' located on classpath" );
75 } else
76 {
77 buf.append( "Multiple copies of resource named '" ).append( resourceName ).append(
78 "' located on classpath at urls" );
79 for ( URL url : urls )
80 {
81 buf.append( "\n " ).append( url );
82 }
83 }
84 return buf.toString();
85 }
86
87
88 public String getResourceName()
89 {
90 return resourceName;
91 }
92
93 public List<URL> getUrls()
94 {
95 return Collections.unmodifiableList( urls );
96 }
97 }