本文整理汇总了Java中org.openhab.core.transform.TransformationHelper类的典型用法代码示例。如果您正苦于以下问题:Java TransformationHelper类的具体用法?Java TransformationHelper怎么用?Java TransformationHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransformationHelper类属于org.openhab.core.transform包,在下文中一共展示了TransformationHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
/**
* Applies a transformation of a given type with some function to a value.
*
* @param type the transformation type, e.g. REGEX or MAP
* @param function the function to call, this value depends on the transformation type
* @param value the value to apply the transformation to
* @return
* the transformed value or the original one, if there was no service registered for the
* given type or a transformation exception occurred.
*/
public static String transform(String type, String function, String value) {
String result;
TransformationService service = TransformationHelper.getTransformationService(CompatibilityActivator.getContext(), type);
if(service!=null) {
try {
result = service.transform(function, value);
} catch (TransformationException e) {
logger.error("Error executing the transformation '" + type + "': " + e.getMessage());
result = value;
}
} else {
logger.warn("No transformation service '" + type + "' could be found.");
result = value;
}
return result;
}
示例2: getCommandTransformationService
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
private TransformationService getCommandTransformationService() {
String name = getCommandTransformName();
if (name == null || name.equals("")) {
return null;
}
if (commandTransformationService != null) {
return commandTransformationService;
}
BundleContext context = MiosActivator.getContext();
commandTransformationService = TransformationHelper.getTransformationService(context, name);
if (commandTransformationService == null) {
logger.warn("Transformation Service (command) '{}' not found for declaration '{}'.", name,
getCommandTransform());
}
return commandTransformationService;
}
示例3: setTransformationRule
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
public boolean setTransformationRule(String rule) {
int pos = rule.indexOf('(');
if (pos == -1)
return false;
// Split the transformation rule
transformationName = rule.substring(0, pos);
transformationParam = rule.substring(pos + 1, rule.length() - 1);
BundleContext context = SnmpActivator.getContext();
// Get the transformation service
transformationService = TransformationHelper.getTransformationService(context, transformationName);
if (transformationService == null) {
logger.debug("No transformation service found for {}", transformationName);
return false;
}
return true;
}
示例4: transform
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
private String transform(String label) {
if(label.contains("[") && label.endsWith("]")) {
Matcher matcher = EXTRACT_TRANSFORMFUNCTION_PATTERN.matcher(label);
if(matcher.find()) {
String type = matcher.group(1);
String pattern = matcher.group(2);
String value = matcher.group(3);
TransformationService transformation =
TransformationHelper.getTransformationService(UIActivator.getContext(), type);
if(transformation!=null) {
try {
label = label.substring(0, label.indexOf("[")+1) + transformation.transform(pattern, value) + "]";
} catch (TransformationException e) {
logger.error("transformation throws exception [transformation="
+ transformation + ", value=" + value + "]", e);
label = label.substring(0, label.indexOf("[")+1) + value + "]";
}
} else {
logger.warn("couldn't transform value in label because transformationService of type '{}' is unavailable", type);
label = label.substring(0, label.indexOf("[")+1) + value + "]";
}
}
}
return label;
}
示例5: transform
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
/**
* Applies a transformation of a given type with some function to a value.
*
* @param type the transformation type, e.g. REGEX or MAP
* @param function the function to call, this value depends on the transformation type
* @param value the value to apply the transformation to
* @return
* the transformed value or the original one, if there was no service registered for the
* given type or a transformation exception occurred.
*/
public static String transform(String type, String function, String value) {
String result;
TransformationService service = TransformationHelper.getTransformationService(TransformationActivator.getContext(), type);
if(service!=null) {
try {
result = service.transform(function, value);
} catch (TransformationException e) {
logger.error("Error executing the transformation '" + type + "': " + e.getMessage());
result = value;
}
} else {
logger.warn("No transformation service '" + type + "' could be found.");
result = value;
}
return result;
}
示例6: resolveMappings
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
/**
* Resolves LCN commands (with mappings) to plain commands.
*
* @param lcnTarget the target or a mapping
* @param openHABcmd the command send by openHAB
* @return the resolved result (can be null)
*/
private static String resolveMappings(String lcnTarget, String openHABcmd) {
String result = null;
Matcher matcher = PATTERN_MAPPING.matcher(lcnTarget);
if (!matcher.matches()) {
result = lcnTarget;
} else {
matcher.reset();
matcher.find();
String s1 = matcher.group(1);
String s2 = matcher.group(2);
TransformationService transformationService = TransformationHelper
.getTransformationService(LcnBindingActivator.getContext(), s1);
if (transformationService != null) {
try {
result = transformationService.transform(s2, openHABcmd);
} catch (TransformationException e) {
result = lcnTarget;
}
} else {
result = lcnTarget;
}
}
return result;
}
示例7: getCommandTransformationService
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
private TransformationService getCommandTransformationService() {
String name = getCommandTransformName();
if (name == null || name.equals("")) {
return null;
}
if (commandTransformationService != null) {
return commandTransformationService;
}
BundleContext context = MiosActivator.getContext();
commandTransformationService = TransformationHelper.getTransformationService(context, name);
if (commandTransformationService == null) {
logger.warn("Transformation Service (command) '{}' not found for declaration '{}'.", name,
getCommandTransform());
}
return commandTransformationService;
}
示例8: getStateWithTransformation
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
private State getStateWithTransformation(BigDecimal val) {
TransformationService transformationService = TransformationHelper.getTransformationService(
FatekPLCActivator.getContext(), transType);
String strVal = String.valueOf(val);
String transOut;
if (transformationService != null) {
try {
transOut = transformationService.transform(transFunc, strVal);
logger.debug("transOut={}", transOut);
} catch (TransformationException e) {
transOut = null;
logger.warn("Transformation error: {}", e.getMessage());
}
} else {
transOut = null;
logger.warn("No transformation service for: {}", transType);
}
if (transOut != null && !"null".equals(transOut)) {
strVal = transOut;
}
return new DecimalType(strVal);
}
示例9: setTransformationRule
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
public boolean setTransformationRule(String rule) {
int pos = rule.indexOf('(');
if (pos == -1) {
return false;
}
// Split the transformation rule
transformationName = rule.substring(0, pos);
transformationParam = rule.substring(pos + 1, rule.length() - 1);
BundleContext context = SnmpActivator.getContext();
// Get the transformation service
transformationService = TransformationHelper.getTransformationService(context, transformationName);
if (transformationService == null) {
logger.debug("No transformation service found for {}", transformationName);
return false;
}
return true;
}
示例10: transformResponse
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
protected String transformResponse(String transformation, String response) {
String transformedResponse;
try {
String[] parts = splitTransformationConfig(transformation);
String transformationType = parts[0];
String transformationFunction = parts[1];
TransformationService transformationService =
TransformationHelper.getTransformationService(TCPActivator.getContext(), transformationType);
if (transformationService != null) {
transformedResponse = transformationService.transform(transformationFunction, response);
} else {
transformedResponse = response;
logger.warn("couldn't transform response because transformationService of type '{}' is unavailable", transformationType);
}
}
catch (Exception te) {
logger.error("transformation throws exception [transformation="
+ transformation + ", response=" + response + "]", te);
// in case of an error we return the response without any
// transformation
transformedResponse = response;
}
logger.debug("transformed response is '{}'", transformedResponse);
return transformedResponse;
}
示例11: transformData
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
/**
* Transform received data by Transformation service.
*
*/
protected org.openhab.core.types.State transformData(
String transformationType, String transformationFunction,
org.openhab.core.types.State data) {
if (transformationType != null && transformationFunction != null) {
String transformedResponse = null;
try {
TransformationService transformationService = TransformationHelper
.getTransformationService(
OpenEnergyMonitorActivator.getContext(),
transformationType);
if (transformationService != null) {
transformedResponse = transformationService.transform(
transformationFunction, String.valueOf(data));
} else {
logger.warn(
"couldn't transform response because transformationService of type '{}' is unavailable",
transformationType);
}
} catch (TransformationException te) {
logger.error(
"transformation throws exception [transformation type="
+ transformationType
+ ", transformation function="
+ transformationFunction + ", response=" + data
+ "]", te);
}
logger.debug("transformed response is '{}'", transformedResponse);
if (transformedResponse != null) {
return new DecimalType(transformedResponse);
}
}
return data;
}
示例12: initTransformService
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
/**
* Start transformation service.
*/
protected void initTransformService() {
if (getTransformationService() != null || StringUtils.isBlank(getTransformationServiceName())) {
return;
}
BundleContext context = MqttActivator.getContext();
transformationService =
TransformationHelper.getTransformationService(context, getTransformationServiceName());
if (transformationService == null) {
logger.debug("No transformation service found for {}", getTransformationServiceName());
}
}
示例13: transformResponse
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
protected String transformResponse(String response, String transformation) {
String transformedResponse;
try {
String[] parts = splitTransformationConfig(transformation);
String transformationType = parts[0];
String transformationFunction = parts[1];
TransformationService transformationService =
TransformationHelper.getTransformationService(ExecActivator.getContext(), transformationType);
if (transformationService != null) {
transformedResponse = transformationService.transform(transformationFunction, response);
} else {
transformedResponse = response;
logger.warn("couldn't transform response because transformationService of type '{}' is unavailable", transformationType);
}
}
catch (TransformationException te) {
logger.error("transformation throws exception [transformation="
+ transformation + ", response=" + response + "]", te);
// in case of an error we return the response without any
// transformation
transformedResponse = response;
}
logger.debug("transformed response is '{}'", transformedResponse);
return transformedResponse;
}
示例14: transformData
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
/**
* Transform received data by Transformation service.
*
*/
protected org.openhab.core.types.State transformData(String transformationType, String transformationFunction,
org.openhab.core.types.State data) {
if (transformationType != null && transformationFunction != null) {
String transformedResponse = null;
try {
TransformationService transformationService = TransformationHelper
.getTransformationService(OpenEnergyMonitorActivator.getContext(), transformationType);
if (transformationService != null) {
transformedResponse = transformationService.transform(transformationFunction, String.valueOf(data));
} else {
logger.warn("couldn't transform response because transformationService of type '{}' is unavailable",
transformationType);
}
} catch (TransformationException te) {
logger.warn(
"transformation throws exception [transformation type=" + transformationType
+ ", transformation function=" + transformationFunction + ", response=" + data + "]",
te);
}
logger.debug("transformed response is '{}'", transformedResponse);
if (transformedResponse != null) {
return new DecimalType(transformedResponse);
}
}
return data;
}
示例15: processTransformation
import org.openhab.core.transform.TransformationHelper; //导入依赖的package包/类
private String processTransformation(String transformation, String response) {
String transformedResponse = response;
if (transformation == null) {
return transformedResponse;
}
try {
String[] parts = splitTransformationConfig(transformation);
String transformationType = parts[0];
String transformationFunction = parts[1];
TransformationService transformationService = TransformationHelper
.getTransformationService(SmarthomaticActivator.getContext(), transformationType);
if (transformationService != null) {
transformedResponse = transformationService.transform(transformationFunction, response);
} else {
transformedResponse = response;
logger.warn("couldn't transform response because transformationService of type '{}' is unavailable",
transformationType);
}
} catch (TransformationException te) {
logger.error("transformation throws exception [transformation= {}, response= {}]", transformation,
response);
logger.error("received transformation exception", te);
// in case of an error we return the response without any
// transformation
transformedResponse = response;
}
logger.debug("transformed response is '{}'", transformedResponse);
return transformedResponse;
}