1 package rydeen.io;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 import rydeen.ProcessTarget;
8 import rydeen.TargetSource;
9 import rydeen.TargetType;
10
11
12
13
14
15
16 public abstract class AbstractProcessTarget implements ProcessTarget{
17 private TargetSource source;
18 private String name;
19 private TargetType type;
20 private InputStream in;
21
22
23
24
25
26
27
28
29
30 public AbstractProcessTarget(TargetSource source, String name, TargetType type){
31 this.source = source;
32 this.name = name;
33 this.type = type;
34 }
35
36
37
38
39
40
41
42
43
44
45
46 public AbstractProcessTarget(TargetSource source, String name){
47 this.source = source;
48 this.name = name;
49 this.type = TargetType.getType(name);
50 }
51
52
53
54
55
56
57
58
59
60
61
62
63 @Override
64 public String getClassName(){
65 if(type == TargetType.CLASS_FILE){
66 String className = name.substring(0, name.lastIndexOf('.'));
67 className = className.replace('/', '.');
68 return className.replace(File.separatorChar, '.');
69 }
70 throw new IllegalStateException("not class file");
71 }
72
73
74
75
76 @Override
77 public String getName(){
78 return name;
79 }
80
81
82
83
84 @Override
85 public final TargetType getType(){
86 return type;
87 }
88
89
90
91
92
93
94
95
96
97 @Override
98 public final InputStream getSource() throws IOException{
99 if(in == null){
100 in = openStream();
101 }
102 return in;
103 }
104
105
106
107
108 public final TargetSource getTargetSource(){
109 return source;
110 }
111
112
113
114
115
116
117 protected abstract InputStream openStream() throws IOException;
118 }