Building Controls Virtual Test Bed
ADInterfaceMCCObjectType.java
Go to the documentation of this file.
1 /*
2 ********************************************************************
3 Copyright Notice
4 ----------------
5 
6 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
7 Regents of the University of California, through Lawrence Berkeley
8 National Laboratory (subject to receipt of any required approvals from
9 the U.S. Dept. of Energy). All rights reserved.
10 
11 If you have questions about your rights to use or distribute this
12 software, please contact Berkeley Lab's Technology Transfer Department
13 at TTD@lbl.gov
14 
15 NOTICE. This software was developed under partial funding from the U.S.
16 Department of Energy. As such, the U.S. Government has been granted for
17 itself and others acting on its behalf a paid-up, nonexclusive,
18 irrevocable, worldwide license in the Software to reproduce, prepare
19 derivative works, and perform publicly and display publicly. Beginning
20 five (5) years after the date permission to assert copyright is obtained
21 from the U.S. Department of Energy, and subject to any subsequent five
22 (5) year renewals, the U.S. Government is granted for itself and others
23 acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide
24 license in the Software to reproduce, prepare derivative works,
25 distribute copies to the public, perform publicly and display publicly,
26 and to permit others to do so.
27 
28 
29 Modified BSD License agreement
30 ------------------------------
31 
32 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
33 Regents of the University of California, through Lawrence Berkeley
34 National Laboratory (subject to receipt of any required approvals from
35 the U.S. Dept. of Energy). All rights reserved.
36 
37 Redistribution and use in source and binary forms, with or without
38 modification, are permitted provided that the following conditions are met:
39 
40  1. Redistributions of source code must retain the above copyright
41  notice, this list of conditions and the following disclaimer.
42  2. Redistributions in binary form must reproduce the above copyright
43  notice, this list of conditions and the following disclaimer in
44  the documentation and/or other materials provided with the
45  distribution.
46  3. Neither the name of the University of California, Lawrence
47  Berkeley National Laboratory, U.S. Dept. of Energy nor the names
48  of its contributors may be used to endorse or promote products
49  derived from this software without specific prior written permission.
50 
51 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
52 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
53 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
54 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
55 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
58 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
59 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
60 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 
63 You are under no obligation whatsoever to provide any bug fixes,
64 patches, or upgrades to the features, functionality or performance of
65 the source code ("Enhancements") to anyone; however, if you choose to
66 make your Enhancements available either publicly, or directly to
67 Lawrence Berkeley National Laboratory, without imposing a separate
68 written license agreement for such Enhancements, then you hereby grant
69 the following license: a non-exclusive, royalty-free perpetual license
70 to install, use, modify, prepare derivative works, incorporate into
71 other computer software, distribute, and sublicense such enhancements or
72 derivative works thereof, in binary and source code form.
73 
74 ********************************************************************
75 */
76 
77 package adInterfaceMCC.util;
78 import java.util.List;
79 import java.io.File;
80 import java.io.FileNotFoundException;
81 import java.io.IOException;
82 import java.util.ArrayList;
83 import java.util.HashSet;
84 import java.util.Iterator;
85 import java.util.Set;
86 
87 import javax.xml.parsers.ParserConfigurationException;
88 import javax.xml.parsers.SAXParser;
89 import javax.xml.parsers.SAXParserFactory;
90 import org.xml.sax.SAXException;
91 import org.xml.sax.Attributes;
92 import org.xml.sax.helpers.DefaultHandler;
93 
95 
103 {
114  final String boardnumber,
115  final String channelnumber,
116  final String channelgain,
117  final String channelvalue,
118  final String channeloptions,
119  final String applicationtag)
120  {
121  boardNumber = boardnumber;
122  channelNumber = channelnumber;
123  channelGain = channelgain;
124  channelValue = channelvalue;
125  channelOptions = channeloptions;
126  applicationTag = applicationtag;
127 
128  }
129 
133  public String getBoardNumber() {
134  return boardNumber;
135  }
139  public void setBoardNumber(String boardNumber) {
140  this.boardNumber = boardNumber;
141  }
145  public String getChannelNumber() {
146  return channelNumber;
147  }
151  public void setChannelNumber(String channelNumber) {
152  this.channelNumber = channelNumber;
153  }
154 
158  public String getChannelGain() {
159  return channelGain;
160  }
164  public void setChannelGain(String channelGain) {
165  this.channelGain = channelGain;
166  }
170  public String getChannelValue() {
171  return channelValue;
172  }
176  public void setChannelValue(String channelValue) {
177  this.channelValue = channelValue;
178  }
182  public String getChannelOptions() {
183  return channelOptions;
184  }
188  public void setChannelOptions(String channelOptions) {
189  this.channelOptions = channelOptions;
190  }
194  public String getApplicationTag() {
195  return applicationTag;
196  }
200  public void setApplicationTag(String applicationTag) {
201  this.applicationTag = applicationTag;
202  }
203 
208  }
217  public static ArrayList<ADInterfaceMCCObjectType> readADInterfaceMCCObjects(final String s) throws FileNotFoundException,
218  ParserConfigurationException, SAXException, IOException
219 {
220  final ArrayList<ADInterfaceMCCObjectType> ad_objs = new ArrayList<ADInterfaceMCCObjectType>();
221  File f = new File(s);
222  if (f.exists() != true)
223  throw new FileNotFoundException("Configuration file '" + s
224  + "' could not be found.");
225  try {
226  SAXParserFactory factory = SAXParserFactory.newInstance();
227  SAXParser saxParser = factory.newSAXParser();
228  DefaultHandler handler = new DefaultHandler() {
229 
230  public void startElement(String uri, String localName,
231  String qName, Attributes attributes)
232  throws SAXException {
233  if (qName.equals("Object")) {
235  currentAD_obj.setBoardNumber(attributes.getValue("BoardNumber")) ;
236  currentAD_obj.setChannelNumber(attributes.getValue("ChannelNumber"));
237  currentAD_obj.setChannelGain(attributes.getValue("ChannelGain"));
238  currentAD_obj.setChannelOptions(attributes.getValue("ChannelOptions"));
239  currentAD_obj.setChannelNumber(attributes.getValue("ChannelNumber"));
240  currentAD_obj.setApplicationTag(attributes.getValue("ApplicationTag").toUpperCase());
241  currentAD_obj.setChannelValue("0");
242  ad_objs.add(currentAD_obj);
243  }
244  }
245  };
246  saxParser.parse(s, handler);
247  } catch (SAXException e) {
248  String em = "SAXException when parsing file '" + s + "'.";
249  throw new SAXException(em + e.getMessage());
250  } catch (ParserConfigurationException e) {
251  String em = "SAXParser error in parsing file '" + s + "'.";
252  throw new ParserConfigurationException(em + e.getMessage());
253  } catch (IOException e) {
254  String em = "I/O error occurs when parsing configuration file '"
255  + s + "'.";
256  throw new IOException(em + e.getMessage());
257  }
258  return ad_objs;
259  }
260 
262  protected String boardNumber;
263 
265  protected String channelNumber;
266 
268  protected String channelGain;
269 
271  protected String channelValue;
272 
274  protected String channelOptions;
275 
277  protected String applicationTag;
278 
280  private final static String LS = System.getProperty("line.separator");
281 }
This class reads the XML configuration file and stores the data in the ADInterfaceMCCObjectType data ...
void setChannelNumber(String channelNumber)
Set the adinterface channel number.
String getChannelOptions()
Get the adinterface channel options.
void setChannelGain(String channelGain)
Set the adinterface channel gain.
static final String LS
System-dependent line separator.
String getChannelNumber()
Get the adinterface channel number.
static ArrayList< ADInterfaceMCCObjectType > readADInterfaceMCCObjects(final String s)
Read adInterfaceMCC object types from the xml configuration.
String getChannelValue()
Get the adinterface present channel value.
void setBoardNumber(String boardNumber)
Set the adinterface boardnumber.
void setChannelOptions(String channelOptions)
Set the adinterface channel options.
String getApplicationTag()
Get the adinterface application Tag.
String getChannelGain()
Get the adinterface channel gain.
ADInterfaceMCCObjectType(final String boardnumber, final String channelnumber, final String channelgain, final String channelvalue, final String channeloptions, final String applicationtag)
Construct an instance of ADInterfaceMCC object.
void setChannelValue(String channelValue)
Sett the adinterface channel value.
void setApplicationTag(String applicationTag)
Set the adinterface application tag.
String getBoardNumber()
Get the adinterface boardnumber.