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 javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlElement;
14 import javax.xml.bind.annotation.XmlRootElement;
15 import java.io.Serializable;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
22 * Represents the generic action to be applied to the matched
23 * frame/packet/message
26 @XmlAccessorType(XmlAccessType.NONE)
27 public abstract class Action implements Serializable {
28 private static final long serialVersionUID = 1L;
29 private static final Logger logger = LoggerFactory.getLogger(Action.class);
30 private static boolean debug = false; // Enable to find where in the code an
31 // invalid assignment is made
33 protected ActionType type;
34 private transient boolean isValid = true;
36 /* Dummy constructor for JAXB */
41 * Checks if the passed value is in the valid range for this action
46 protected void checkValue(int value) {
47 if (type.isValidTarget(value) == false) {
49 throwValueException(value);
54 * Checks if the passed value is in the valid range for the passed action
55 * type This method is used for complex Action types which are
60 protected void checkValue(ActionType type, int value) {
61 if (type.isValidTarget(value) == false) {
63 throwValueException(value);
68 * Throw and handle the invalid value exception
73 private void throwValueException(int value) {
74 String error = "Invalid field value assignement. For type: " + type.getId() + " Expected: " + type.getRange()
75 + ", Got: 0x" + Integer.toHexString(value);
77 throw new Exception(error);
78 } catch (Exception e) {
79 logger.error(e.getMessage());
87 * Returns the type of this action
91 public ActionType getType() {
96 * Returns the id of this action
100 public String getId() {
105 * Returns whether the Action is valid or not
109 public boolean isValid() {
114 public int hashCode() {
115 final int prime = 31;
117 result = prime * result + ((type == null) ? 0 : type.calculateConsistentHashCode());
122 public boolean equals(Object obj) {
129 if (getClass() != obj.getClass()) {
132 Action other = (Action) obj;
133 if (type != other.type) {
140 public String toString() {
141 return type.toString();