2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.sal.action;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
14 import javax.xml.bind.annotation.*;
15 import java.io.Serializable;
18 * Represents the generic action to be applied to the matched
19 * frame/packet/message
22 @XmlAccessorType(XmlAccessType.NONE)
23 public abstract class Action implements Serializable {
24 private static final long serialVersionUID = 1L;
25 private static final Logger logger = LoggerFactory.getLogger(Action.class);
26 private static boolean debug = false; // Enable to find where in the code an
27 // invalid assignment is made
29 protected ActionType type;
30 private transient boolean isValid = true;
32 /* Dummy constructor for JAXB */
37 * Checks if the passed value is in the valid range for this action
42 protected void checkValue(int value) {
43 if (type.isValidTarget(value) == false) {
45 throwValueException(value);
50 * Checks if the passed value is in the valid range for the passed action
51 * type This method is used for complex Action types which are
56 protected void checkValue(ActionType type, int value) {
57 if (type.isValidTarget(value) == false) {
59 throwValueException(value);
64 * Throw and handle the invalid value exception
69 private void throwValueException(int value) {
70 String error = "Invalid field value assignement. For type: " + type.getId() + " Expected: " + type.getRange()
71 + ", Got: 0x" + Integer.toHexString(value);
73 throw new Exception(error);
74 } catch (Exception e) {
75 logger.error(e.getMessage());
83 * Returns the type of this action
87 public ActionType getType() {
92 * Returns the id of this action
96 public String getId() {
101 * Returns whether the Action is valid or not
105 public boolean isValid() {
110 public int hashCode() {
111 final int prime = 31;
113 result = prime * result + ((type == null) ? 0 : type.calculateConsistentHashCode());
118 public boolean equals(Object obj) {
125 if (getClass() != obj.getClass()) {
128 Action other = (Action) obj;
129 if (type != other.type) {
136 public String toString() {
137 return type.toString();