79 import java.io.FileNotFoundException;
80 import java.io.IOException;
81 import java.util.HashMap;
82 import java.util.ArrayList;
83 import java.util.Iterator;
84 import javax.xml.parsers.ParserConfigurationException;
85 import javax.xml.parsers.SAXParser;
86 import javax.xml.parsers.SAXParserFactory;
87 import org.xml.sax.SAXException;
88 import org.xml.sax.Attributes;
89 import org.xml.sax.helpers.DefaultHandler;
114 final String instance,
115 final ArrayList<BACnetPropertyValue> mapPI,
116 final HashMap mapOTname,
117 final HashMap mapOTinst,
118 final HashMap piOrder,
119 final HashMap otOrder)
207 throws ParserConfigurationException, SAXException, IOException
209 final ArrayList<BACnetObjectType> bot_arr =
new ArrayList<BACnetObjectType>();
212 for(
int i=0;
i<dev_arr.size();
i++)
214 String dev_inst = dev_arr.get(
i);
217 HashMap mapOTname = bot.getBACnetObjectTypeNameMap();
218 HashMap mapOTinst = bot.getBACnetObjectTypeInstanceMap();
219 Iterator iterator = mapOTname.keySet().iterator();
220 while( iterator. hasNext() ){
221 String obj_id = iterator.next().toString();
222 String obj_name = mapOTname.get(obj_id).toString();
223 String obj_inst = mapOTinst.get(obj_id).toString();
225 (dev_inst, obj_inst, obj_name,s);
230 catch(SAXException e)
232 String em =
"SAXException when parsing file '" + s +
"'.";
233 throw new SAXException(em +
LS + e.getMessage());
235 catch(ParserConfigurationException e)
237 String em =
"SAXParser error in parsing file '" + s +
"'.";
238 throw new ParserConfigurationException(em +
LS + e.getMessage());
242 String em =
"I/O errors occur while parsing file '" + s +
"'.";
243 throw new IOException(em +
LS + e.getMessage());
257 public ArrayList<String>
readDeviceInst(
final String s)
throws FileNotFoundException,
258 ParserConfigurationException, SAXException, IOException
260 final ArrayList<String> dev_arr =
new ArrayList<String>();
261 File f =
new File(s);
263 throw new FileNotFoundException(
"Configuration file '" + s +
"' could not be found.");
265 SAXParserFactory factory = SAXParserFactory.newInstance();
266 SAXParser saxParser = factory.newSAXParser();
267 DefaultHandler handler =
new DefaultHandler(){
268 String obj_inst =
new String();
269 public void startElement
270 (String uri, String localName, String qName, Attributes attributes)
271 throws SAXException {
272 if (qName.equals(
"Object") && attributes.getValue(
"Type").equals(
"Device"))
274 obj_inst = attributes.getValue(
"Instance");
275 dev_arr.add(obj_inst);
279 saxParser.parse(s, handler);
281 catch(SAXException e)
283 String em =
"SAXException when parsing file '" + s +
"'.";
284 throw new SAXException(em + e.getMessage());
286 catch(ParserConfigurationException e)
288 String em =
"SAXParser error in parsing file '" + s +
"'.";
289 throw new ParserConfigurationException(em + e.getMessage());
293 String em =
"I/O error occurs when parsing configuration file '" + s +
"'.";
294 throw new IOException(em + e.getMessage());
309 throws FileNotFoundException, ParserConfigurationException, SAXException, IOException
311 File f =
new File(s);
313 throw new FileNotFoundException(
"Configuration file '" + s +
"' could not be found");
316 SAXParserFactory factory = SAXParserFactory.newInstance();
317 SAXParser saxParser = factory.newSAXParser();
318 final ArrayList<BACnetPropertyValue> mapPI =
new ArrayList<BACnetPropertyValue>();
319 final HashMap<String, String> mapOTname =
new HashMap<String,String>();
320 final HashMap<String, String> mapOTinst =
new HashMap<String,String>();
321 final HashMap<String, String> piOrder =
new HashMap<String,String>();
322 final HashMap<String, String> otOrder =
new HashMap<String,String>();
323 DefaultHandler handler =
new DefaultHandler(){
325 boolean nonobj =
false;
328 public void startElement
329 (String uri, String localName, String qName, Attributes attributes)
332 if (qName.equals(
"Object")
333 && attributes.getValue(
"Type").equals(
"Device")
334 && attributes.getValue(
"Instance").equals(dev_inst))
339 if(qName.equals(
"PropertyIdentifier") && dev==
true && nonobj==
true)
341 String[] piArray=
new String[4];
342 if(attributes.getValue(
"PropertyValue") != null)
343 piArray[0] = attributes.getValue(
"PropertyValue");
346 if(attributes.getValue(
"ApplicationTag") != null)
347 piArray[1] = attributes.getValue(
"ApplicationTag").toUpperCase();
350 if(attributes.getValue(
"Priority") != null)
351 piArray[2] = attributes.getValue(
"Priority");
354 if(attributes.getValue(
"Index") != null)
355 piArray[3] = attributes.getValue(
"Index");
362 piOrder.put(attributes.getValue(
"Name").toUpperCase(),
363 Integer.toString(piID));
366 if(qName.equals(
"Object") && !attributes.getValue(
"Type").equals(
"Device")
369 mapOTname.put(Integer.toString(otID),
371 mapOTinst.put(Integer.toString(otID),attributes.getValue(
"Instance"));
373 otOrder.put(attributes.getValue(
"Instance"),Integer.toString(otID));
376 if (qName.equals(
"Object")
377 && attributes.getValue(
"Type").equals(
"Device")
378 && !attributes.getValue(
"Instance").equals(dev_inst))
384 saxParser.parse(s, handler);
386 mapPI, mapOTname, mapOTinst, piOrder, otOrder);
389 catch(SAXException e)
391 String em =
"SAXException when parsing file '" + s +
"'.";
392 throw new SAXException(em + e.getMessage());
394 catch(ParserConfigurationException e)
396 String em =
"ParserConfigurationException when parsing file '" + s +
"'.";
397 throw new ParserConfigurationException(em + e.getMessage());
401 String em =
"I/O error occurs when parsing configuraiton file '" + s +
"'.";
402 throw new IOException(em + e.getMessage());
418 (
final String dev_inst,
final String obj_inst,
final String obj_name,
final String s)
419 throws FileNotFoundException, ParserConfigurationException, SAXException, IOException
421 File f =
new File(s);
423 throw new FileNotFoundException(
"Configuration file '" + s +
"' could not be found.");
426 SAXParserFactory factory = SAXParserFactory.newInstance();
427 SAXParser saxParser = factory.newSAXParser();
429 final ArrayList<BACnetPropertyValue> mapPI =
new ArrayList<BACnetPropertyValue>();
430 final HashMap<String, String> mapOTname =
new HashMap<String, String>();
431 final HashMap<String, String> mapOTinst =
new HashMap<String, String>();
432 final HashMap<String, String> piOrder =
new HashMap<String, String>();
433 final HashMap<String, String> otOrder =
new HashMap<String, String>();
434 DefaultHandler handler =
new DefaultHandler(){
439 public void startElement
440 (String uri, String localName, String qName, Attributes attributes)
443 if (qName.equals(
"Object") &&
444 attributes.getValue(
"Type").equals(
"Device") &&
445 attributes.getValue(
"Instance").equals(dev_inst))
450 qName.equals(
"Object") &&
452 attributes.getValue(
"Instance").equals(obj_inst))
455 mapOTname.put(Integer.toString(otID),obj_name);
456 mapOTinst.put(obj_inst,dev_inst);
458 otOrder.put(obj_inst,Integer.toString(otID));
460 if(qName.equals(
"Object") &&
461 attributes.getValue(
"Type").equals(
"Device") &&
462 !attributes.getValue(
"Instance").equals(dev_inst))
466 if(dev==
true && qName.equals(
"Object")
467 && !attributes.getValue(
"Instance").equals(obj_inst))
471 if(dev==
true && qName.equals(
"Object")
476 if(obj==
true && dev ==
true && qName.equals(
"PropertyIdentifier"))
478 String[] piArray=
new String[4];
480 if(attributes.getValue(
"ApplicationTag") != null)
482 attributes.getValue(
"ApplicationTag").toUpperCase();
486 if(attributes.getValue(
"Priority") != null)
487 piArray[2] = attributes.getValue(
"Priority");
491 if(attributes.getValue(
"Index") != null)
492 piArray[3] = attributes.getValue(
"Index");
496 (attributes.getValue(
"Name").toUpperCase(),piArray);
499 piOrder.put(attributes.getValue(
"Name").toUpperCase(),
500 Integer.toString(piID));
506 saxParser.parse(s, handler);
508 (obj_name, obj_inst, mapPI, mapOTname, mapOTinst, piOrder, otOrder);
510 catch(SAXException e)
512 String em =
"SAXException when parsing file '" + s +
"'.";
513 throw new SAXException(em + e.getMessage());
515 catch(ParserConfigurationException e)
517 String em =
"ParserConfigurationException when parsing file '" + s +
"'.";
518 throw new ParserConfigurationException(em + e.getMessage());
522 String em =
"I/O error occurs when parsing configuration file '" + s +
"'.";
523 throw new IOException(em + e.getMessage());
534 return orStr.replace(
" ",
"").concat(
"ObjectType");
560 private final static String
LS = System.getProperty(
"line.separator");
BACnetObjectType()
Empty constructor.
This class reads the XML configuration file and stores the data in the BACnetObjectType data type...
BACnetObjectType readBacnetDeviceObjectType(final String dev_inst, final String s)
Read Bancet DeviceObjectType from xml configuration file.
String getBOTInst()
Get the instance of the bacnet object type.
HashMap getBACnetObjectTypeNameMap()
Get the map of the object type.
HashMap bot_otOrder
Hashmap containing the instance and index pair of object type.
ArrayList< BACnetPropertyValue > getBOTPI()
Get the map of the property identifier.
String bot_name
The BACnetObjectType name.
String convertObjectName(String orStr)
Convert object name to the same convention as in BacnetDeviceManager.
HashMap bot_piOrder
Hashmap containing the name and index pair of property identifier.
String bot_instance
The BACnetObjectType instance.
HashMap bot_mapOTname
Hashmap containing the index and name of the objecty type pair.
BACnetObjectType readBacnetNonDeviceObjectType(final String dev_inst, final String obj_inst, final String obj_name, final String s)
Read NonDevice BACnetObjectType from xml configuration file.
String getBOTName()
Get the bacnet object type name.
HashMap getBACnetObjectTypeInstanceMap()
Get the map of the object type.
HashMap getBACnetObjectTypePropertyIdentifierOrder()
Get the map of the property identifier index.
This class stores the BACnet property name and property value array pair.
ArrayList< BACnetPropertyValue > bot_mapPI
ArrayList with elements of BACnetPropertyValue.
BACnetObjectType(final String name, final String instance, final ArrayList< BACnetPropertyValue > mapPI, final HashMap mapOTname, final HashMap mapOTinst, final HashMap piOrder, final HashMap otOrder)
Construct an instance of BACnet object.
static final String LS
System-dependent line separator.
HashMap getBACnetObjectTypeOrder()
Get the map of the bacnet object type index.
HashMap bot_mapOTinst
Hashmap containing the index and object instance number pair for BACnet Device Object and device inst...
ArrayList< String > readDeviceInst(final String s)
Read ArrayList String from xml configuration file.
ArrayList< BACnetObjectType > parseObjectType(final String s)
Read bacnet object types from the xml configuration.