List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getStringArray
public String[] getStringArray(String key)
From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderETSImpl.java
private void parseTopologyView(HierarchicalConfiguration areaConfig, Obj parent, Network n, ObjectBroker objectBroker, Hashtable<String, EntityImpl> entityById, Hashtable<String, DatapointImpl> datapointById, Hashtable<String, String> resourceById) { for (int areaIdx = 0; areaIdx < sizeOfConfiguration(areaConfig.getProperty("area.[@id]")); areaIdx++) { String areaId = areaConfig.getString("area(" + areaIdx + ").[@id]"); String areaName = arrayToString(areaConfig.getStringArray("area(" + areaIdx + ").[@name]")); String areaDescription = arrayToString( areaConfig.getStringArray("area(" + areaIdx + ").[@description]")); String areaMediaTypeId = areaConfig.getString("area(" + areaIdx + ").[@mediaTypeId]"); long areaAddress = areaConfig.getLong("area(" + areaIdx + ").[@address]"); String areaMediaType = null; if (areaMediaTypeId != null) { areaMediaType = resourceById.get(areaMediaTypeId); }/*from w ww .ja v a 2 s . c o m*/ AreaImpl area = new AreaImpl(areaId, areaName, areaDescription, areaAddress, areaMediaType); // add part to parent part if (parent instanceof ViewTopologyImpl) ((ViewTopologyImpl) parent).addArea(area); else if (parent instanceof DomainImpl) ((AreaImpl) parent).addArea(area); else parent.add(area); objectBroker.addObj(area, true); // add instances to part HierarchicalConfiguration concreteArea = areaConfig.configurationAt("area(" + areaIdx + ")"); for (int instanceIdx = 0; instanceIdx < sizeOfConfiguration( concreteArea.getProperty("instance.[@id]")); instanceIdx++) { String instanceId = concreteArea.getString("instance(" + instanceIdx + ").[@id]"); long address = concreteArea.getLong("instance(" + instanceIdx + ").[@address]"); Obj addInstance = area.addInstance(entityById.get(instanceId), address); objectBroker.addObj(addInstance, true); } // recursively add more domains parseTopologyView(concreteArea, area, n, objectBroker, entityById, datapointById, resourceById); } }
From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderETSImpl.java
private void parseFunctionalView(HierarchicalConfiguration groupConfig, Obj parent, Network n, ObjectBroker objectBroker, Hashtable<String, EntityImpl> entityById, Hashtable<String, DatapointImpl> datapointById, KNXConnector knxConnector, Hashtable<String, String> groupAddressByDatapointId) { for (int groupsIdx = 0; groupsIdx < sizeOfConfiguration( groupConfig.getProperty("group.[@id]")); groupsIdx++) { String groupId = groupConfig.getString("group(" + groupsIdx + ").[@id]"); String groupName = arrayToString(groupConfig.getStringArray("group(" + groupsIdx + ").[@name]")); String groupDescription = arrayToString( groupConfig.getStringArray("group(" + groupsIdx + ").[@description]")); long groupAddress = groupConfig.getLong("group(" + groupsIdx + ").[@address]"); GroupImpl group = new GroupImpl(groupId, groupName, groupDescription, groupAddress); // add part to parent part if (parent instanceof ViewFunctionalImpl) ((ViewFunctionalImpl) parent).addGroup(group); else if (parent instanceof GroupImpl) ((GroupImpl) parent).addGroup(group); else// ww w . ja va2 s. c o m parent.add(group); objectBroker.addObj(group, true); // add instances to part HierarchicalConfiguration concreteGroup = groupConfig.configurationAt("group(" + groupsIdx + ")"); for (int instanceIdx = 0; instanceIdx < sizeOfConfiguration( concreteGroup.getProperty("instance.[@id]")); instanceIdx++) { String instanceId = concreteGroup.getString("instance(" + instanceIdx + ").[@id]"); String connector = concreteGroup.getString("instance(" + instanceIdx + ").[@connector]"); try { DatapointImpl dp = datapointById.get(instanceId); if (dp == null) { log.warning("No datapoint type found for instance: " + instanceId); continue; } Class<?> clazz = dp.getClass(); if (clazz != null) { Constructor<?> constructor = clazz.getConstructor(KNXConnector.class, DataPointInit.class); Object[] object = new Object[2]; object[0] = knxConnector; DataPointInit dptInit = new DataPointInit(); dptInit.setName("function"); dptInit.setReadable(dp.isValueReadable()); dptInit.setWritable(dp.isValueWritable()); dptInit.setGroupAddress( new GroupAddress(Integer.parseInt(groupAddressByDatapointId.get(instanceId)))); object[1] = dptInit; DatapointImpl dataPoint = (DatapointImpl) constructor.newInstance(object); group.addFunction(dataPoint); objectBroker.addObj(dataPoint, true); } } catch (Exception e) { e.printStackTrace(); } group.addInstance(datapointById.get(instanceId), connector); } // recursively add more parts parseFunctionalView(concreteGroup, group, n, objectBroker, entityById, datapointById, knxConnector, groupAddressByDatapointId); } }
From source file:edu.hawaii.soest.hioos.isus.ISUSSource.java
/** * A method that processes the data object passed and flushes the * data to the DataTurbine given the sensor properties in the XMLConfiguration * passed in./*from w w w. java2s . c om*/ * * @param xmlConfig - the XMLConfiguration object containing the list of * sensor properties * @param frameMap - the parsed data as a HierarchicalMap object */ public boolean process(XMLConfiguration xmlConfig, HierarchicalMap frameMap) { logger.debug("ISUSSource.process() called."); // do not execute the stream if there is no connection if (!isConnected()) return false; boolean success = false; try { // add channels of data that will be pushed to the server. // Each sample will be sent to the Data Turbine as an rbnb frame. Information // on each channel is found in the XMLConfiguration file (email.account.properties.xml) // and the StorXParser object (to get the data string) ChannelMap rbnbChannelMap = new ChannelMap(); // used to flush channels ChannelMap registerChannelMap = new ChannelMap(); // used to register channels int channelIndex = 0; String sensorName = null; String sensorSerialNumber = null; String sensorDescription = null; boolean isImmersed = false; String[] calibrationURLs = null; String calibrationURL = null; String type = null; List sensorList = xmlConfig.configurationsAt("account.logger.sensor"); for (Iterator sIterator = sensorList.iterator(); sIterator.hasNext();) { // HierarchicalConfiguration sensorConfig = (HierarchicalConfiguration) sIterator.next(); sensorSerialNumber = sensorConfig.getString("serialNumber"); // find the correct sensor configuration properties if (sensorSerialNumber.equals(frameMap.get("serialNumber"))) { sensorName = sensorConfig.getString("name"); sensorDescription = sensorConfig.getString("description"); isImmersed = new Boolean(sensorConfig.getString("isImmersed")).booleanValue(); calibrationURLs = sensorConfig.getStringArray("calibrationURL"); type = (String) frameMap.get("type"); // find the correct calibrationURL from the list given the type for (String url : calibrationURLs) { if (url.indexOf(type) > 0) { calibrationURL = url; break; } else { logger.debug("There was no match for " + type); } } // get a Calibration instance to interpret raw sensor values Calibration calibration = new Calibration(); if (calibration.parse(calibrationURL)) { // Build the RBNB channel map // get the sample date and convert it to seconds since the epoch Date frameDate = (Date) frameMap.get("date"); Calendar frameDateTime = Calendar.getInstance(); frameDateTime.setTime(frameDate); double sampleTimeAsSecondsSinceEpoch = (double) (frameDateTime.getTimeInMillis() / 1000); // and create a string formatted date for the given time zone DATE_FORMAT.setTimeZone(TZ); String frameDateAsString = DATE_FORMAT.format(frameDate).toString(); // get the sample data from the frame map ByteBuffer rawFrame = (ByteBuffer) frameMap.get("rawFrame"); ISUSFrame isusFrame = (ISUSFrame) frameMap.get("parsedFrameObject"); String serialNumber = isusFrame.getSerialNumber(); String sampleDate = isusFrame.getSampleDate(); String sampleTime = isusFrame.getSampleTime(); SimpleDateFormat dtFormat = new SimpleDateFormat(); Date sampleDateTime = isusFrame.getSampleDateTime(); dtFormat.setTimeZone(TimeZone.getTimeZone("UTC")); dtFormat.applyPattern("MM/dd/yy"); String sampleDateUTC = dtFormat.format(sampleDateTime); dtFormat.applyPattern("HH:mm:ss"); String sampleTimeUTC = dtFormat.format(sampleDateTime); dtFormat.setTimeZone(TimeZone.getTimeZone("HST")); dtFormat.applyPattern("MM/dd/yy"); String sampleDateHST = dtFormat.format(sampleDateTime); dtFormat.applyPattern("HH:mm:ss"); String sampleTimeHST = dtFormat.format(sampleDateTime); dtFormat.applyPattern("dd-MMM-yy HH:mm"); String sampleDateTimeHST = dtFormat.format(sampleDateTime); double rawNitrogenConcentration = isusFrame.getNitrogenConcentration(); double rawAuxConcentration1 = isusFrame.getAuxConcentration1(); double rawAuxConcentration2 = isusFrame.getAuxConcentration2(); double rawAuxConcentration3 = isusFrame.getAuxConcentration3(); double rawRmsError = isusFrame.getRmsError(); double rawInsideTemperature = isusFrame.getInsideTemperature(); double rawSpectrometerTemperature = isusFrame.getSpectrometerTemperature(); double rawLampTemperature = isusFrame.getLampTemperature(); int rawLampTime = isusFrame.getLampTime(); double rawHumidity = isusFrame.getHumidity(); double rawLampVoltage12 = isusFrame.getLampVoltage12(); double rawInternalPowerVoltage5 = isusFrame.getInternalPowerVoltage5(); double rawMainPowerVoltage = isusFrame.getMainPowerVoltage(); double rawReferenceAverage = isusFrame.getReferenceAverage(); double rawReferenceVariance = isusFrame.getReferenceVariance(); double rawSeaWaterDarkCounts = isusFrame.getSeaWaterDarkCounts(); double rawSpectrometerAverage = isusFrame.getSpectrometerAverage(); int checksum = isusFrame.getChecksum(); //// apply calibrations to the observed data double nitrogenConcentration = calibration.apply(rawNitrogenConcentration, isImmersed, "NITRATE"); double auxConcentration1 = calibration.apply(rawAuxConcentration1, isImmersed, "AUX1"); double auxConcentration2 = calibration.apply(rawAuxConcentration2, isImmersed, "AUX2"); double auxConcentration3 = calibration.apply(rawAuxConcentration3, isImmersed, "AUX3"); double rmsError = calibration.apply(rawRmsError, isImmersed, "RMSe"); double insideTemperature = calibration.apply(rawInsideTemperature, isImmersed, "T_INT"); double spectrometerTemperature = calibration.apply(rawSpectrometerTemperature, isImmersed, "T_SPEC"); double lampTemperature = calibration.apply(rawLampTemperature, isImmersed, "T_LAMP"); int lampTime = rawLampTime; double humidity = calibration.apply(rawHumidity, isImmersed, "HUMIDITY"); double lampVoltage12 = calibration.apply(rawLampVoltage12, isImmersed, "VOLT_12"); double internalPowerVoltage5 = calibration.apply(rawInternalPowerVoltage5, isImmersed, "VOLT_5"); double mainPowerVoltage = calibration.apply(rawMainPowerVoltage, isImmersed, "VOLT_MAIN"); double referenceAverage = calibration.apply(rawReferenceAverage, isImmersed, "REF_AVG"); double referenceVariance = calibration.apply(rawReferenceVariance, isImmersed, "REF_STD"); double seaWaterDarkCounts = calibration.apply(rawSeaWaterDarkCounts, isImmersed, "SW_DARK"); double spectrometerAverage = calibration.apply(rawSpectrometerAverage, isImmersed, "SPEC_AVG"); // iterate through the individual wavelengths List<String> variableNames = calibration.getVariableNames(); TreeMap<String, Double> wavelengthsMap = new TreeMap<String, Double>(); Collections.sort(variableNames); int rawWavelengthCounts = 0; int count = 1; for (String name : variableNames) { // just handle the wavelength channels if (name.startsWith("UV_")) { rawWavelengthCounts = isusFrame.getChannelWavelengthCounts(count); double value = calibration.apply(rawWavelengthCounts, isImmersed, name); count++; wavelengthsMap.put(name, new Double(value)); } } String sampleString = ""; sampleString += sampleDate + "\t"; sampleString += sampleDateUTC + "\t"; sampleString += sampleTime + "\t"; sampleString += sampleTimeUTC + "\t"; sampleString += sampleDateHST + "\t"; sampleString += sampleTimeHST + "\t"; sampleString += sampleDateTimeHST + "\t"; sampleString += String.format("%-15.11f", nitrogenConcentration) + "\t"; //sampleString += String.format("%15.11f", auxConcentration1) + "\t"; //sampleString += String.format("%15.11f", auxConcentration2) + "\t"; //sampleString += String.format("%15.11f", auxConcentration3) + "\t"; sampleString += String.format("%15.11f", rmsError) + "\t"; sampleString += String.format("%15.11f", insideTemperature) + "\t"; sampleString += String.format("%15.11f", spectrometerTemperature) + "\t"; sampleString += String.format("%15.11f", lampTemperature) + "\t"; sampleString += String.format("%6d", lampTime) + "\t"; sampleString += String.format("%15.11f", humidity) + "\t"; sampleString += String.format("%15.11f", lampVoltage12) + "\t"; sampleString += String.format("%15.11f", internalPowerVoltage5) + "\t"; sampleString += String.format("%15.11f", mainPowerVoltage) + "\t"; sampleString += String.format("%15.11f", referenceAverage) + "\t"; sampleString += String.format("%15.11f", referenceVariance) + "\t"; sampleString += String.format("%15.11f", seaWaterDarkCounts) + "\t"; sampleString += String.format("%15.11f", spectrometerAverage) + "\t"; Set<String> wavelengths = wavelengthsMap.keySet(); Iterator wIterator = wavelengths.iterator(); while (wIterator.hasNext()) { String name = (String) wIterator.next(); Double wavelengthValue = (Double) wavelengthsMap.get(name); sampleString += String.format("%6d", wavelengthValue.intValue()) + "\t"; channelIndex = registerChannelMap.Add(name); registerChannelMap.PutUserInfo(channelIndex, "units=counts"); channelIndex = rbnbChannelMap.Add(name); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { wavelengthValue.doubleValue() }); } sampleString += String.format("%03d", checksum); sampleString += "\n"; // add the sample timestamp to the rbnb channel map //registerChannelMap.PutTime(sampleTimeAsSecondsSinceEpoch, 0d); rbnbChannelMap.PutTime(sampleTimeAsSecondsSinceEpoch, 0d); // add the BinaryRawSatlanticFrameData channel to the channelMap channelIndex = registerChannelMap.Add("BinaryRawSatlanticFrameData"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("BinaryRawSatlanticFrameData"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsByteArray(channelIndex, rawFrame.array()); // add the DecimalASCIISampleData channel to the channelMap channelIndex = registerChannelMap.Add(getRBNBChannelName()); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add(getRBNBChannelName()); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, sampleString); // add the serialNumber channel to the channelMap channelIndex = registerChannelMap.Add("serialNumber"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("serialNumber"); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, serialNumber); // add the sampleDateUTC channel to the channelMap channelIndex = registerChannelMap.Add("sampleDateUTC"); registerChannelMap.PutUserInfo(channelIndex, "units=YYYYDDD"); channelIndex = rbnbChannelMap.Add("sampleDateUTC"); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, sampleDate); // add the sampleTimeUTC channel to the channelMap channelIndex = registerChannelMap.Add("sampleTimeUTC"); registerChannelMap.PutUserInfo(channelIndex, "units=hh.hhhhhh"); channelIndex = rbnbChannelMap.Add("sampleTimeUTC"); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, sampleTimeUTC); // add the nitrogenConcentration channel to the channelMap channelIndex = registerChannelMap.Add("nitrogenConcentration"); registerChannelMap.PutUserInfo(channelIndex, "units=uM"); channelIndex = rbnbChannelMap.Add("nitrogenConcentration"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { nitrogenConcentration }); // add the auxConcentration1 channel to the channelMap channelIndex = registerChannelMap.Add("auxConcentration1"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("auxConcentration1"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { auxConcentration1 }); // add the auxConcentration3 channel to the channelMap channelIndex = registerChannelMap.Add("auxConcentration2"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("auxConcentration2"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { auxConcentration2 }); // add the serialNumber channel to the channelMap channelIndex = registerChannelMap.Add("auxConcentration3"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("auxConcentration3"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { auxConcentration3 }); // add the rmsError channel to the channelMap channelIndex = registerChannelMap.Add("rmsError"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("rmsError"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { rmsError }); // add the insideTemperature channel to the channelMap channelIndex = registerChannelMap.Add("insideTemperature"); registerChannelMap.PutUserInfo(channelIndex, "units=Celsius"); channelIndex = rbnbChannelMap.Add("insideTemperature"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { insideTemperature }); // add the spectrometerTemperature channel to the channelMap channelIndex = registerChannelMap.Add("spectrometerTemperature"); registerChannelMap.PutUserInfo(channelIndex, "units=Celsius"); channelIndex = rbnbChannelMap.Add("spectrometerTemperature"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { spectrometerTemperature }); // add the lampTemperature channel to the channelMap channelIndex = registerChannelMap.Add("lampTemperature"); registerChannelMap.PutUserInfo(channelIndex, "units=Celsius"); channelIndex = rbnbChannelMap.Add("lampTemperature"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { lampTemperature }); // add the lampTime channel to the channelMap channelIndex = registerChannelMap.Add("lampTime"); registerChannelMap.PutUserInfo(channelIndex, "units=seconds"); channelIndex = rbnbChannelMap.Add("lampTime"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsInt32(channelIndex, new int[] { lampTime }); // add the humidity channel to the channelMap channelIndex = registerChannelMap.Add("humidity"); registerChannelMap.PutUserInfo(channelIndex, "units=%"); channelIndex = rbnbChannelMap.Add("humidity"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { humidity }); // add the lampVoltage12 channel to the channelMap channelIndex = registerChannelMap.Add("lampVoltage12"); registerChannelMap.PutUserInfo(channelIndex, "units=V"); channelIndex = rbnbChannelMap.Add("lampVoltage12"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { lampVoltage12 }); // add the internalPowerVoltage5 channel to the channelMap channelIndex = registerChannelMap.Add("internalPowerVoltage5"); registerChannelMap.PutUserInfo(channelIndex, "units=V"); channelIndex = rbnbChannelMap.Add("internalPowerVoltage5"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { internalPowerVoltage5 }); // add the mainPowerVoltage channel to the channelMap channelIndex = registerChannelMap.Add("mainPowerVoltage"); registerChannelMap.PutUserInfo(channelIndex, "units=V"); channelIndex = rbnbChannelMap.Add("mainPowerVoltage"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { mainPowerVoltage }); // add the referenceAverage channel to the channelMap channelIndex = registerChannelMap.Add("referenceAverage"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("referenceAverage"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { referenceAverage }); // add the referenceVariance channel to the channelMap channelIndex = registerChannelMap.Add("referenceVariance"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("referenceVariance"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { referenceVariance }); // add the seaWaterDarkCounts channel to the channelMap channelIndex = registerChannelMap.Add("seaWaterDarkCounts"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("seaWaterDarkCounts"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { seaWaterDarkCounts }); // add the spectrometerAverage channel to the channelMap channelIndex = registerChannelMap.Add("spectrometerAverage"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("averageWavelength"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { spectrometerAverage }); // Now register the RBNB channels, and flush the rbnbChannelMap to the // DataTurbine getSource().Register(registerChannelMap); getSource().Flush(rbnbChannelMap); logger.info(frameDateAsString + " " + "Sample sent to the DataTurbine: (" + serialNumber + ") " + sampleString); registerChannelMap.Clear(); rbnbChannelMap.Clear(); } else { logger.info("Couldn't apply the calibration coefficients. " + "Skipping this sample."); } // end if() } // end if() } // end for() //getSource.Detach(); success = true; } catch (ParseException pe) { // parsing of the calibration file failed. Log the exception, return false success = false; logger.debug("There was a problem parsing the calibration file. The " + "error message was: " + pe.getMessage()); return success; } catch (SAPIException sapie) { // In the event of an RBNB communication exception, log the exception, // and allow execute() to return false, which will prompt a retry. success = false; sapie.printStackTrace(); return success; } return success; }
From source file:org.ambraproject.service.user.UserServiceImpl.java
@Override @SuppressWarnings("unchecked") public List<UserAlert> getAvailableAlerts() { List<UserAlert> alerts = new ArrayList<UserAlert>(); final SortedMap<Integer, Pair> categoryNames = new ConcurrentSkipListMap<Integer, Pair>(); HierarchicalConfiguration hc = (HierarchicalConfiguration) configuration; List<HierarchicalConfiguration> categories = hc.configurationsAt(ALERTS_CATEGORIES_CATEGORY); for (HierarchicalConfiguration c : categories) { String key = c.getString("[@key]"); int order = c.getInt("[@displayOrder]", categoryNames.size()); String value = c.getString(""); categoryNames.put(order, new Pair<String, String>(key, value)); }// w w w .j a va 2 s . c o m final String[] weeklyCategories = hc.getStringArray(ALERTS_WEEKLY); final String[] monthlyCategories = hc.getStringArray(ALERTS_MONTHLY); final String[] subjectFilters = hc.getStringArray(SUBJECT_FILTER); final Set<Map.Entry<Integer, Pair>> categoryNamesSet = categoryNames.entrySet(); for (final Map.Entry<Integer, Pair> category : categoryNamesSet) { final String key = (String) category.getValue().getFirst(); boolean weeklyCategoryKey = false; boolean monthlyCategoryKey = false; boolean subjectFilter = false; if (ArrayUtils.contains(weeklyCategories, key)) { weeklyCategoryKey = true; } if (ArrayUtils.contains(monthlyCategories, key)) { monthlyCategoryKey = true; } if (ArrayUtils.contains(subjectFilters, key)) { subjectFilter = true; } alerts.add( new UserAlert((String) category.getValue().getFirst(), (String) category.getValue().getSecond(), weeklyCategoryKey, monthlyCategoryKey, subjectFilter)); } return alerts; }
From source file:org.ambraproject.user.service.UserServiceImpl.java
@Override @SuppressWarnings("unchecked") public List<UserAlert> getAvailableAlerts() { List<UserAlert> alerts = new ArrayList<UserAlert>(); final Map<String, String> categoryNames = new HashMap<String, String>(); HierarchicalConfiguration hc = (HierarchicalConfiguration) configuration; List<HierarchicalConfiguration> categories = hc.configurationsAt(ALERTS_CATEGORIES_CATEGORY); for (HierarchicalConfiguration c : categories) { String key = c.getString("[@key]"); String value = c.getString(""); categoryNames.put(key, value);/* w ww .j a v a 2 s.co m*/ } final String[] weeklyCategories = hc.getStringArray(ALERTS_WEEKLY); final String[] monthlyCategories = hc.getStringArray(ALERTS_MONTHLY); final Set<Map.Entry<String, String>> categoryNamesSet = categoryNames.entrySet(); for (final Map.Entry<String, String> category : categoryNamesSet) { final String key = category.getKey(); boolean weeklyCategoryKey = false; boolean monthlyCategoryKey = false; if (ArrayUtils.contains(weeklyCategories, key)) { weeklyCategoryKey = true; } if (ArrayUtils.contains(monthlyCategories, key)) { monthlyCategoryKey = true; } alerts.add(new UserAlert(key, category.getValue(), weeklyCategoryKey, monthlyCategoryKey)); } return alerts; }
From source file:org.apache.james.container.spring.bean.factory.mailrepositorystore.MailRepositoryStoreBeanFactory.java
/** * <p>/*from w w w .j a va2 s .c o m*/ * Registers a new mail repository type in the mail store's registry based * upon a passed in <code>Configuration</code> object. * </p> * <p/> * <p> * This is presumably synchronized to prevent corruption of the internal * registry. * </p> * * @param repConf the Configuration object used to register the repository * @throws ConfigurationException if an error occurs accessing the Configuration object */ public synchronized void registerRepository(HierarchicalConfiguration repConf) throws ConfigurationException { String className = repConf.getString("[@class]"); boolean infoEnabled = getLogger().isInfoEnabled(); for (String protocol : repConf.getStringArray("protocols.protocol")) { HierarchicalConfiguration defConf = null; if (repConf.getKeys("config").hasNext()) { // Get the default configuration for these protocol/type // combinations. defConf = repConf.configurationAt("config"); } if (infoEnabled) { StringBuilder infoBuffer = new StringBuilder(128); infoBuffer.append("Registering Repository instance of class "); infoBuffer.append(className); infoBuffer.append(" to handle "); infoBuffer.append(protocol); infoBuffer.append(" protocol requests for repositories with key "); infoBuffer.append(protocol); getLogger().info(infoBuffer.toString()); } if (classes.get(protocol) != null) { throw new ConfigurationException( "The combination of protocol and type comprise a unique key for repositories. This constraint has been violated. Please check your repository configuration."); } classes.put(protocol, className); if (defConf != null) { defaultConfigs.put(protocol, defConf); } } }
From source file:org.apache.james.dnsservice.dnsjava.DNSJavaService.java
@Override public void configure(HierarchicalConfiguration configuration) throws ConfigurationException { boolean autodiscover = configuration.getBoolean("autodiscover", true); List<Name> sPaths = new ArrayList<Name>(); if (autodiscover) { logger.info("Autodiscovery is enabled - trying to discover your system's DNS Servers"); String[] serversArray = ResolverConfig.getCurrentConfig().servers(); if (serversArray != null) { for (String aServersArray : serversArray) { dnsServers.add(aServersArray); logger.info("Adding autodiscovered server " + aServersArray); }/*from w w w.ja v a 2 s . c o m*/ } Name[] systemSearchPath = ResolverConfig.getCurrentConfig().searchPath(); if (systemSearchPath != null && systemSearchPath.length > 0) { sPaths.addAll(Arrays.asList(systemSearchPath)); } if (logger.isInfoEnabled()) { for (Name searchPath : sPaths) { logger.info("Adding autodiscovered search path " + searchPath.toString()); } } } // singleIPPerMX = configuration.getBoolean( "singleIPperMX", false ); setAsDNSJavaDefault = configuration.getBoolean("setAsDNSJavaDefault", true); // Get the DNS servers that this service will use for lookups Collections.addAll(dnsServers, configuration.getStringArray("servers.server")); // Get the DNS servers that this service will use for lookups for (String aSearchPathsConfiguration : configuration.getStringArray("searchpaths.searchpath")) { try { sPaths.add(Name.fromString(aSearchPathsConfiguration)); } catch (TextParseException e) { throw new ConfigurationException("Unable to parse searchpath host: " + aSearchPathsConfiguration, e); } } searchPaths = sPaths.toArray(new Name[sPaths.size()]); if (dnsServers.isEmpty()) { logger.info("No DNS servers have been specified or found by autodiscovery - adding 127.0.0.1"); dnsServers.add("127.0.0.1"); } boolean authoritative = configuration.getBoolean("authoritative", false); // TODO: Check to see if the credibility field is being used correctly. // From the // docs I don't think so dnsCredibility = authoritative ? Credibility.AUTH_ANSWER : Credibility.NONAUTH_ANSWER; maxCacheSize = configuration.getInt("maxcachesize", maxCacheSize); }
From source file:org.apache.james.domainlist.lib.DomainListConfiguration.java
public static DomainListConfiguration from(HierarchicalConfiguration config) { ImmutableList<Domain> configuredDomains = StreamUtils .ofNullable(config.getStringArray(CONFIGURE_DOMAIN_NAMES)).filter(s -> !s.isEmpty()).map(Domain::of) .collect(Guavate.toImmutableList()); return builder().autoDetect(Optional.ofNullable(config.getBoolean(CONFIGURE_AUTODETECT, null))) .autoDetectIp(Optional.ofNullable(config.getBoolean(CONFIGURE_AUTODETECT_IP, null))) .defaultDomain(//from w w w. j a va 2s .c o m Optional.ofNullable(config.getString(CONFIGURE_DEFAULT_DOMAIN, null)).map(Domain::of)) .addConfiguredDomains(configuredDomains).build(); }
From source file:org.apache.james.domainlist.xml.XMLDomainList.java
@Override public void configure(HierarchicalConfiguration config) throws ConfigurationException { super.configure(config); for (String serverNameConf : config.getStringArray("domainnames.domainname")) { try {/*from w w w.jav a2s . com*/ addToServedDomains(serverNameConf); } catch (DomainListException e) { throw new ConfigurationException("Unable to add domain to memory", e); } } }
From source file:org.apache.james.mailrepository.memory.MemoryMailRepositoryStore.java
private void readConfigurationEntry(HierarchicalConfiguration repositoryConfiguration) throws ConfigurationException { String className = repositoryConfiguration.getString("[@class]"); MailRepositoryProvider usedMailRepository = mailRepositories.stream() .filter(mailRepositoryProvider -> mailRepositoryProvider.canonicalName().equals(className)) .findAny().orElseThrow(() -> new ConfigurationException( "MailRepository " + className + " has not been registered")); for (String protocol : repositoryConfiguration.getStringArray("protocols.protocol")) { protocolToRepositoryProvider.put(new Protocol(protocol), usedMailRepository); registerRepositoryDefaultConfiguration(repositoryConfiguration, new Protocol(protocol)); }/*from w w w.j a va 2s .c o m*/ }