View Javadoc

1   /*
2    * Copyright (c) 2006 Stiftung Deutsches Elektronen-Synchroton,
3    * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
4    *
5    * THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS.
6    * WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
7    * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE AND
8    * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
9    * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
11   * THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE DEFECTIVE
12   * IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING, REPAIR OR
13   * CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
14   * NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
15   * DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
16   * OR MODIFICATIONS.
17   * THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION, MODIFICATION,
18   * USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE DISTRIBUTION OF THIS
19   * PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU MAY FIND A COPY
20   * AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM
21   */
22  
23  package de.desy.acop.displayers.chart;
24  
25  import java.io.Serializable;
26  
27  /**
28   * <code>HistoryParameters</code> defines a connection point for the history data.
29   * This class defines the remote connection which can be used to connect
30   * to history or archive server and obtain data provided by those servers.
31   * 
32   * @author Tilen Kusterle, Cosylab
33   *
34   */
35  public class HistoryParameters implements Serializable {
36  	
37  	private static final long serialVersionUID = 1L;
38  	
39  	private String historyContext;
40  	private String historyServer;
41  	private String historyDevice;
42  	private String historyProperty;
43  	private int historyIndex;
44  	
45  	/**
46  	 * Constructs new HistoryParameters.
47  	 * 
48  	 * @param historyContext
49  	 * @param historyServer
50  	 * @param historyDevice
51  	 * @param historyProperty
52  	 * @param historyIndex
53  	 */
54  	public HistoryParameters(String historyContext, String historyServer, String historyDevice, String historyProperty, int historyIndex) {
55  		this.historyContext = historyContext;
56  		this.historyServer = historyServer;
57  		this.historyDevice = historyDevice;
58  		this.historyProperty = historyProperty;
59  		this.historyIndex = historyIndex;
60  	}
61  	
62  	/**
63  	 * Constructs a new HistoryParameters from the remote name. The remote name
64  	 * should have th structure context/server/device/property.
65  	 * 
66  	 * @param remoteName
67  	 */
68  	public HistoryParameters(String remoteName) {
69  		String[] s = remoteName.split("/");
70  	    
71  		this.historyContext = (s.length>0 && s[0]!=null) ? s[0] : "";
72  		this.historyServer = (s.length>1 && s[1]!=null) ? s[1] : "";
73  		this.historyProperty = (s.length>3 && s[s.length-1]!=null) ? s[s.length-1] : "";
74  		
75  		StringBuilder sb= new StringBuilder(128);
76  		
77  		if (s.length>2 && s[2]!=null) {
78  			sb.append(s[2]);
79  		}
80  		for (int i = 3; i < s.length-1; i++) {
81  			sb.append('/');
82  			if (s[i]!=null) sb.append(s[i]);
83  		}
84  		
85  		this.historyDevice = sb.toString();
86  	}
87  	
88  	/* (non-Javadoc)
89  	 * @see java.lang.Object#equals(java.lang.Object)
90  	 */
91  	@Override
92  	public boolean equals(Object obj) {
93  		if (!(obj instanceof HistoryParameters)) return false;
94  		return this.toString().equals(obj.toString());
95  	}
96  
97  	/* (non-Javadoc)
98  	 * @see java.lang.Object#toString()
99  	 */
100 	@Override
101 	public String toString() {
102 		return historyContext + "/" + historyServer + "/" + historyDevice + "/" + historyProperty;
103 	}
104 	
105 	/**
106 	 * Returnst the remote name.
107 	 * 
108 	 * @return the remote name
109 	 * @see HistoryParameters#HistoryParameters(String)
110 	 */
111 	public String getRemoteName() {
112 		return historyContext + "/" + historyServer + "/" + historyDevice + "/" + historyProperty;
113 	}
114 
115 	/**
116 	 * Returns the context.
117 	 * 
118 	 * @return the historyContext
119 	 */
120 	public String getHistoryContext() {
121 		return historyContext;
122 	}
123 	/**
124 	 * Sets the new context.
125 	 * 
126 	 * @param historyContext the historyContext to set
127 	 */
128 	public void setHistoryContext(String historyContext) {
129 		this.historyContext = historyContext;
130 	}
131 	
132 	/**
133 	 * Returns the device name.
134 	 * 
135 	 * @return the historyDevice
136 	 */
137 	public String getHistoryDevice() {
138 		return historyDevice;
139 	}
140 	
141 	/**
142 	 * Sets new device name.
143 	 * 
144 	 * @param historyDevice the historyDevice to set
145 	 */
146 	public void setHistoryDevice(String historyDevice) {
147 		this.historyDevice = historyDevice;
148 	}
149 	
150 	/**
151 	 * Returns the property name
152 	 * 
153 	 * @return the historyProperty
154 	 */
155 	public String getHistoryProperty() {
156 		return historyProperty;
157 	}
158 	
159 	/**
160 	 * Sets new property name 
161 	 * @param historyProperty the historyProperty to set
162 	 */
163 	public void setHistoryProperty(String historyProperty) {
164 		this.historyProperty = historyProperty;
165 	}
166 	
167 	/** Returns the device server.
168 	 * 
169 	 * @return the historyServer
170 	 */
171 	public String getHistoryServer() {
172 		return historyServer;
173 	}
174 	
175 	/**
176 	 *  Sets new device server.
177 	 *  
178 	 * @param historyServer the historyServer to set
179 	 */
180 	public void setHistoryServer(String historyServer) {
181 		this.historyServer = historyServer;
182 	}
183 
184 	/**
185 	 * Returns the index of the device.
186 	 * 
187 	 * @return the historyIndex
188 	 */
189 	public int getHistoryIndex() {
190 		return historyIndex;
191 	}
192 
193 	/**
194 	 * Sets the index of the device.
195 	 * 
196 	 * @param historyIndex the historyIndex to set
197 	 */
198 	public void setHistoryIndex(int historyIndex) {
199 		this.historyIndex = historyIndex;
200 	}
201 	
202 	@Override
203 	public int hashCode() {
204 		return getRemoteName().hashCode();
205 	}
206 	
207 }