Skip to content

Commit

Permalink
Remove invalid actions instead of failing validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bubbleguuum authored and Christian Bauer committed Jan 22, 2014
1 parent 0aa572b commit ba2e036
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions core/src/main/java/org/fourthline/cling/model/meta/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@

package org.fourthline.cling.model.meta;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.fourthline.cling.model.ServiceReference;
import org.fourthline.cling.model.ValidationError;
import org.fourthline.cling.model.ValidationException;
import org.fourthline.cling.model.types.Datatype;
import org.fourthline.cling.model.types.ServiceId;
import org.fourthline.cling.model.types.ServiceType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* The metadata of a service, with actions and state variables.
*
* @author Christian Bauer
*/
public abstract class Service<D extends Device, S extends Service> {

final private static Logger log = Logger.getLogger(Service.class.getName());

final private ServiceType serviceType;
final private ServiceId serviceId;

Expand Down Expand Up @@ -110,7 +113,7 @@ public Action<S> getAction(String name) {
}

public StateVariable<S> getStateVariable(String name) {
// Some magic necessary for the deprected 'query state variable' action stuff
// Some magic necessary for the deprecated 'query state variable' action stuff
if (QueryStateVariableAction.VIRTUAL_STATEVARIABLE_INPUT.equals(name)) {
return new StateVariable(
QueryStateVariableAction.VIRTUAL_STATEVARIABLE_INPUT,
Expand Down Expand Up @@ -178,7 +181,18 @@ public List<ValidationError> validate() {

if (hasActions()) {
for (Action action : getActions()) {
errors.addAll(action.validate());

// Instead of bailing out here, we try to continue if an action is invalid
// errors.addAll(action.validate());

List<ValidationError> actionErrors = action.validate();
if(actionErrors.size() > 0) {
actions.remove(action.getName()); // Remove it
log.warning("Discarding invalid action of service '" + getServiceId() + "': " + action.getName());
for (ValidationError actionError : actionErrors) {
log.warning("Invalid action '" + action.getName() + "': " + actionError);
}
}
}
}

Expand Down

0 comments on commit ba2e036

Please sign in to comment.