View Javadoc
1   package ca.uhn.hl7v2.testpanel.model.conf;
2   
3   import java.io.File;
4   import java.io.FileNotFoundException;
5   import java.io.IOException;
6   import java.io.StringReader;
7   import java.util.UUID;
8   
9   import jakarta.xml.bind.JAXB;
10  import jakarta.xml.bind.annotation.XmlAccessType;
11  import jakarta.xml.bind.annotation.XmlAccessorType;
12  import jakarta.xml.bind.annotation.XmlElement;
13  import jakarta.xml.bind.annotation.XmlType;
14  
15  import ca.uhn.hl7v2.conf.ProfileException;
16  import ca.uhn.hl7v2.conf.parser.ProfileParser;
17  import ca.uhn.hl7v2.conf.spec.RuntimeProfile;
18  import ca.uhn.hl7v2.testpanel.util.FileUtils;
19  
20  @XmlAccessorType(XmlAccessType.FIELD)
21  @XmlType(name = "ProfileProxy")
22  public class ProfileProxy {
23  
24  	@XmlElement(name = "fileName")
25  	private String myFileName;
26  
27  	@XmlElement(name = "id")
28  	private String myId;
29  
30  	@XmlElement(name = "name")
31  	private String myName;
32  
33  	private transient RuntimeProfile myProfile;
34  
35  	@XmlElement(name = "evtType")
36  	private String myStructureEventType;
37  
38  	@XmlElement(name = "msgType")
39  	private String myStructureMessageType;
40  
41  	public File getFile() {
42  		return new File(myFileName);
43  	}
44  
45  	/**
46  	 * @return the fileName
47  	 */
48  	public String getFileName() {
49  		return myFileName;
50  	}
51  
52  	/**
53  	 * @return the id
54  	 */
55  	public String getId() {
56  		return myId;
57  	}
58  
59  	/**
60  	 * @return the name
61  	 */
62  	public String getName() {
63  		return myName;
64  	}
65  
66  	public RuntimeProfile getProfile() throws IOException, ProfileException {
67  		if (myProfile == null) {
68  			String profileString = getProfileAsString();
69  			myProfile = new ProfileParser(false).parse(profileString);
70  		}
71  		return myProfile;
72  	}
73  
74  	public String getProfileAsString() throws FileNotFoundException, IOException {
75  		return FileUtils.readFile(getFile());
76  	}
77  
78  	/**
79  	 * @return the structureEventType
80  	 */
81  	public String getStructureEventType() {
82  		return myStructureEventType;
83  	}
84  
85  	/**
86  	 * @return the structureMessageType
87  	 */
88  	public String getStructureMessageType() {
89  		return myStructureMessageType;
90  	}
91  
92  	/**
93  	 * @param theFileName the fileName to set
94  	 */
95  	public void setFileName(String theFileName) {
96  		myFileName = theFileName;
97  	}
98  
99  	/**
100 	 * @param theId the id to set
101 	 */
102 	public void setId(String theId) {
103 		myId = theId;
104 	}
105 
106 	/**
107 	 * @param theName the name to set
108 	 */
109 	public void setName(String theName) {
110 		myName = theName;
111 	}
112 
113 	/**
114 	 * @param theStructureEventType the structureEventType to set
115 	 */
116 	public void setStructureEventType(String theStructureEventType) {
117 		myStructureEventType = theStructureEventType;
118 	}
119 
120 	/**
121 	 * @param theStructureMessageType the structureMessageType to set
122 	 */
123 	public void setStructureMessageType(String theStructureMessageType) {
124 		myStructureMessageType = theStructureMessageType;
125 	}
126 
127 	public static ProfileProxy createFromProfileString(String theProfile) throws IOException, ProfileException {
128 		ProfileProxy profileProxy = new ProfileProxy();
129 		profileProxy.setId(UUID.randomUUID().toString());
130 		
131 		profileProxy.myProfile = new ProfileParser(false).parse(theProfile);
132 		RuntimeProfile p = profileProxy.getProfile();
133 		profileProxy.setName(p.getName());
134 		profileProxy.setStructureMessageType(p.getMessage().getMsgType());
135 		profileProxy.setStructureEventType(p.getMessage().getEventType());
136 		
137 		return profileProxy;
138 	}
139 
140 	public static ProfileProxy loadFromFile(File theFile) throws IOException, ProfileException {
141 		ProfileProxy profileProxy = new ProfileProxy();
142 		profileProxy.setFileName(theFile.getAbsolutePath());
143 		profileProxy.setId(UUID.randomUUID().toString());
144 		
145 		RuntimeProfile p = profileProxy.getProfile();
146 		profileProxy.setName(p.getName());
147 		profileProxy.setStructureMessageType(p.getMessage().getMsgType());
148 		profileProxy.setStructureEventType(p.getMessage().getEventType());
149 		
150 		return profileProxy;
151 	}
152 
153 	public static ProfileProxy loadFromString(String theString) {
154 		StringReader r = new StringReader(theString);
155 		ProfileProxy retVal = JAXB.unmarshal(r, ProfileProxy.class);
156 		return retVal;
157 	}
158 
159 	
160 
161 }