org.bidib.wizard.common.node.SwitchingNode Maven / Gradle / Ivy
package org.bidib.wizard.common.node;
import java.lang.ref.WeakReference;
import org.bidib.jbidibc.messages.BidibLibrary;
import org.bidib.jbidibc.messages.Feature;
import org.bidib.wizard.api.model.NodeInterface;
import org.bidib.wizard.api.model.SwitchingNodeInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jgoodies.binding.beans.Model;
public class SwitchingNode extends Model implements SwitchingNodeInterface {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(SwitchingNode.class);
private final WeakReference parent;
private boolean portQueryAllEnabled;
public SwitchingNode(final NodeInterface parent) {
this.parent = new WeakReference<>(parent);
}
@Override
public NodeInterface getNode() {
return parent.get();
}
@Override
public boolean isQueryPortStatusEnabled() {
boolean queryPortStatusEnabled = false;
try {
Feature featurePortQuery =
Feature.findFeature(getNode().getNode().getFeatures(), BidibLibrary.FEATURE_CTRL_PORT_QUERY_AVAILABLE);
if (featurePortQuery != null) {
queryPortStatusEnabled = featurePortQuery.getValue() > 0;
}
LOGGER
.info("Query the port status enabled: {}, featurePortQuery: {}", queryPortStatusEnabled,
featurePortQuery);
}
catch (Exception ex) {
LOGGER.warn("Check if query the port status is enabled failed.", ex);
throw new RuntimeException("Check if query the port status is enabled failed.", ex);
}
return queryPortStatusEnabled;
}
@Override
public void setPortQueryAllEnabled(boolean enabled) {
portQueryAllEnabled = enabled;
}
@Override
public boolean isPortQueryAllEnabled() {
return portQueryAllEnabled;
}
@Override
public String toString() {
return getNode().toString();
}
}