76 package adInterfaceMCC.util;
78 import java.io.FileNotFoundException;
79 import java.io.IOException;
80 import java.util.ArrayList;
81 import java.util.HashSet;
82 import java.util.Iterator;
83 import java.util.List;
86 import org.xml.sax.SAXParseException;
87 import javax.xml.parsers.ParserConfigurationException;
88 import javax.xml.validation.Schema;
89 import javax.xml.validation.SchemaFactory;
90 import javax.xml.validation.Validator;
91 import javax.xml.transform.sax.SAXSource;
92 import javax.xml.XMLConstants;
93 import org.xml.sax.SAXException;
94 import org.xml.sax.InputSource;
114 private final static String
bcvtbhome = System.getenv(
"BCVTB_HOME");
117 private final static String
LS = System.getProperty(
"line.separator");
120 private final static String
FS = System.getProperty(
"file.separator");
123 private final static String
osName= System.getProperty(
"os.name");
126 private final static String
cmd =
"java";
148 String s =
new String();
150 +
"bin-windows" +
FS +
"adInterfaceReader.jar";
164 String s =
new String();
166 +
"bin-windows" +
FS +
"adInterfaceWriter.jar";
180 ParserConfigurationException, SAXException, IOException
182 ArrayList<ADInterfaceMCCObjectType> ad_arr =
new ArrayList<ADInterfaceMCCObjectType>();
185 ad_arr = ad.readADInterfaceMCCObjects(s);
187 catch (SAXException e) {
188 String em =
"Parser error occurs while parsing xml configuration file '"
190 throw new SAXException(em +
LS + e.getMessage());
192 catch(ParserConfigurationException e)
194 String em =
"SAX Parser configuration error in parsing configuration file '"
196 throw new ParserConfigurationException(em +
LS + e.getMessage());
200 final String em =
"IOException when parsing configuration file '" + s +
"'." +
202 throw new IOException(em);
215 Set<Integer> set =
new HashSet<Integer>();
216 List<Integer> newList =
new ArrayList<Integer>();
217 List<Integer> newListDuplicates =
new ArrayList<Integer>();
218 for (Iterator<Integer> iter = arlList.iterator(); iter.hasNext();) {
219 Integer element = iter.next();
220 if (set.add(element))
221 newList.add(element);
223 newListDuplicates.add(element);
227 arlList.addAll(newListDuplicates);
236 public ArrayList<ProcessBuilder>
getProcesses(ArrayList<ADInterfaceMCCObjectType> prop_arr)
241 ArrayList<ProcessBuilder> pro =
new ArrayList<ProcessBuilder>();
242 for(
int i=0;
i<prop_arr.size();
i++)
245 final String pro_app = prop_arr.get(
i).getApplicationTag();
246 final boolean isReader = pro_app.equals(
"READ");
247 final String binPat = isReader ?
253 String boardNumber = bcp.getBoardNumber();
254 String channelNumber = bcp.getChannelNumber();
255 String channelGain = bcp.getChannelGain();
256 String channelValue = bcp.getChannelValue();
257 String channelOptions = bcp.getChannelOptions();
260 ProcessBuilder procBui =
new ProcessBuilder
262 channelGain, channelOptions);
266 ProcessBuilder procBui =
new ProcessBuilder
268 channelGain, channelValue, channelOptions);
281 throws IllegalArgumentException{
282 ArrayList<String> s =
new ArrayList<String>();
285 if(arg.equals(
"ADInterfaceMCCApplicationTag"))
289 throw new IllegalArgumentException(
"Program error. Argument '" + arg +
"' is not known.");
302 for(
int i=0;
i<s.size();
i++){
303 final String ele = s.get(
i);
304 strLen += ele.length() + 2;
326 ADInterfaceMCCApplicationTag.valueOf(s);
328 catch(IllegalArgumentException e)
330 String em =
"'" + s +
331 "' is not allowed as the value for 'ApplicationTag.'" +
332 LS +
"Possible values are:" +
LS +
toString(
"ADInterfaceMCCApplicationTag") +
".";
333 throw new IllegalArgumentException(em +
LS + e.getMessage());
349 throws SAXException, FileNotFoundException,IOException
352 Validator validator = schema.newValidator();
353 SAXSource
source =
new SAXSource(
354 new InputSource(
new java.io.FileInputStream(xmlfile)));
355 validator.validate(
source);
357 catch(SAXParseException e)
359 String em = xmlfile +
": Line " + e.getLineNumber() +
", column "
360 + e.getColumnNumber() +
": " + e.getMessage();
361 throw new SAXException(em);
363 catch(FileNotFoundException e)
365 String em =
"XML file configuration file '" + xmlfile +
"' cannot be found.";
366 throw new FileNotFoundException(em +
LS + e.getMessage());
370 String em =
"Error while validating XML configuration file '" + xmlfile +
".";
371 throw new IOException(em +
LS + e.getMessage());
383 public Schema
loadSchema(
final String name)
throws SAXException
385 Schema schema = null;
387 String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
388 SchemaFactory factory = SchemaFactory.newInstance(language);
389 schema = factory.newSchema(
new File(name));
391 catch (SAXException e) {
392 throw new SAXException(
"Error while loading schema: " + name +
LS +
Schema loadSchema(final String name)
Load schema.
This class reads the XML configuration file and stores the data in the ADInterfaceMCCObjectType data ...
static final String cmdOptions
Options of the command to run the process.
static final String FS
System-dependent file separator.
String getWritePropertyBinaryPath()
Returns the ADWriter.jar binary file path.
void validateApplicationTag(final String s)
Application tag validation.
static final String osName
Name of the operating system.
enumeration object, contains all the BACnet application tags specified in ADInterfaceMCC ...
static ArrayList< Integer > saveDuplicates(ArrayList< Integer > arlList)
Removes duplicates from an array list of integers.
static final String cmd
Name of the command to run the process.
ArrayList< ProcessBuilder > getProcesses(ArrayList< ADInterfaceMCCObjectType > prop_arr)
Prepare the process to be executed.
ArrayList< ADInterfaceMCCObjectType > parseADInterfaceMCCObjectType(final String s)
Parse the configuration file and generate an ArrayList that contains the xml content as specified in ...
const int * strLen
the length of string parsed to this function
static final String bcvtbhome
String that points to root directory of the BCVTB.
This is the driver class in ADInterfaceMCC.
static final String LS
System-dependent line separator.
static String toString(String arg)
Gets a string representation of the enumeration.
void validateXMLFile(final String xmlfile, final Schema schema)
XMLfile validation.
int source
flag for function /c getepvariables 0=EnergyPlus, 1=Ptolemy
String getReadPropertyBinaryPath()
Returns the ADReader.jar binary file path.