DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_validator / checker / src / main / java / org / onap / sdc / dcae / checker / Target.java
1 package org.onap.sdc.dcae.checker;
2
3 import org.onap.sdc.common.onaplog.OnapLoggerDebug;
4 import org.onap.sdc.common.onaplog.OnapLoggerError;
5
6 import java.io.InputStream;
7 import java.io.InputStreamReader;
8 import java.io.Reader;
9 import java.io.BufferedReader;
10 import java.io.IOException;
11
12 import java.net.URI;
13 import java.net.URL;
14 import java.net.MalformedURLException;
15
16 /**
17  * Represents a yaml document to be parsed/validated/checked
18  */
19 public class Target {
20
21         private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
22         private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
23
24
25         private String                          name;                   //maintained mainly for logging
26         private URI                                             location;
27         private Object                          target;         //this is the parsed form of the target
28
29         private Report  report = new Report(); //collects the errors related to this target
30
31         public Target(String theName, URI theLocation) {
32                 this.name = theName;
33                 this.location = theLocation;
34         }
35
36         public String getName() {
37                 return this.name;
38         }
39
40         public URI getLocation() {
41                 return this.location;
42         }
43
44         public Report getReport() {
45                 return this.report;
46         }
47
48         public void report(Throwable theError) {
49                 this.report.add(theError); 
50         }
51         
52         public void report(String theErrMsg) {
53                 this.report.add(new Exception(theErrMsg)); 
54         }
55
56         public void setTarget(Object theTarget) {
57                 this.target = theTarget;
58         }
59
60         public Object getTarget() {
61                 return this.target;
62         }
63
64         /*
65          * @return a reader for the source or null if failed
66          */
67         public Reader open() throws IOException {
68
69     return new BufferedReader(
70                                                 new InputStreamReader(
71                         this.location.toURL().openStream()));
72         }
73
74         public String toString() {
75                 //return String.format("Target %s (%.20s ...)", this.location, this.target == null ? "" : this.target.toString());
76                 return String.format("Target %s at %s", this.name, this.location);
77
78         }
79 }
80