1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.spring;
17
18 import java.io.File;
19
20 import org.kuali.common.util.Artifact;
21 import org.kuali.common.util.Assert;
22 import org.kuali.common.util.LocationUtils;
23 import org.kuali.common.util.RepositoryUtils;
24 import org.springframework.beans.factory.FactoryBean;
25
26 public class ArtifactPathFactoryBean extends Artifact implements FactoryBean<String> {
27
28 File localRepositoryDir = RepositoryUtils.getDefaultLocalRepositoryDir();
29 boolean mustExist;
30
31 @Override
32 public String getObject() {
33
34 Assert.notNull(localRepositoryDir);
35 Assert.hasText(getGroupId());
36 Assert.hasText(getArtifactId());
37 Assert.hasText(getVersion());
38 Assert.hasText(getType());
39
40 File file = RepositoryUtils.getFile(localRepositoryDir, this);
41 validate(file);
42 return LocationUtils.getCanonicalPath(file);
43 }
44
45 protected void validate(File file) {
46 if (!file.exists() && mustExist) {
47 throw new IllegalStateException(file + " does not exist");
48 }
49 }
50
51 @Override
52 public Class<String> getObjectType() {
53 return String.class;
54 }
55
56 @Override
57 public boolean isSingleton() {
58 return false;
59 }
60
61 public File getLocalRepositoryDir() {
62 return localRepositoryDir;
63 }
64
65 public void setLocalRepositoryDir(File localRepositoryDir) {
66 this.localRepositoryDir = localRepositoryDir;
67 }
68
69 public boolean isMustExist() {
70 return mustExist;
71 }
72
73 public void setMustExist(boolean mustExist) {
74 this.mustExist = mustExist;
75 }
76
77 }