5 import java.security.acl.*;
7 public class ArpShar extends ArpCore implements Serializable{
10 protected String name;
11 protected boolean isDefault;
14 protected Vector resources;
18 public ArpShar(String name, boolean isDefault)throws NotOwnerException{
20 this.isDefault = isDefault;
21 resources = new Vector();
26 public String toString() {
27 return name+(isDefault?"(default)":"");
30 public boolean isDefault(){
34 public boolean addAResource(String url)
35 throws NotOwnerException,AAPermissionException{
37 if(resources.contains(new ArpResource(url)))
38 return false; // already there
40 if(! insertPermitted())
41 throw new AAPermissionException("No INSERT right for "+getCaller());
43 resources.add(new ArpResource(url));
48 * Adds a given resource to the resources for this Shar.
49 * Does not replace if resource already exists.
50 * returns false if resource already exists.
53 public boolean addAResource(ArpResource rsrc)
54 throws AAPermissionException{
55 return addAResource(rsrc, false);
59 * Adds the given resource to the resources for this Shar.
60 * if force flag is true and resource already exists
61 * then replaces the existing reource otherwise leaves the existing
63 * returns false if reource already existed.
65 public boolean addAResource(ArpResource rsrc, boolean force)
66 throws AAPermissionException{
68 if(resources.contains(rsrc)){
70 if(! replacePermitted())
71 throw new AAPermissionException("No replace right for "+getCaller());
72 resources.remove(rsrc);
75 return false; // already there
77 if(! insertPermitted())
78 throw new AAPermissionException("No INSERT right for "+getCaller());
83 public boolean removeAResource(String url)
84 throws NotOwnerException, AAPermissionException{
85 if(resources.contains(new ArpResource(url))){
86 if(! removePermitted())
87 throw new AAPermissionException("No DELETE right for "+getCaller());
88 resources.remove(new ArpResource(url));
91 return false; // not found
94 public ArpResource getResource(String url) {
95 Enumeration en = resources.elements();
96 while(en.hasMoreElements()){
97 ArpResource aResource = (ArpResource)en.nextElement();
98 if(aResource.getName().equals(url))
104 public ArpResource[] getResources() {
105 int len = resources.size();
106 ArpResource[] a = new ArpResource[len];
107 for(int i = 0; i < len; i++)
108 a[i] = (ArpResource)resources.get(i);
114 * Go throu all resource objects and find the one that
115 * best matches the given url. This is based on comparison
116 * of TNames of urls provided by fit method of ArpResource.
118 * returns an ArpResource or null if no match found;
120 public ArpResource bestFit(String url) {
122 ArpResource[] ara = new ArpResource[resources.size()];
123 ara = (ArpResource[])resources.toArray(ara);
125 ArpResource bestResource = null;
126 for(int i=0; i < ara.length; i++){
127 int score = ara[i].fit(url);
128 if(score > bestScore){
130 bestResource = ara[i];
136 public String getName(){
140 public boolean equals(Object shar){
141 return name.equals(((ArpShar)shar).getName());
144 } /* end class ArpShar */