2 * Copyright (c) 2015 IBM Corporation 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
8 package org.opendaylight.neutron.spi;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.Preconditions;
13 import java.io.Serializable;
14 import java.util.regex.Pattern;
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
21 @XmlAccessorType(XmlAccessType.NONE)
22 public class NeutronID implements Serializable {
23 private static final long serialVersionUID = 1L;
24 private static final String UUID_PATTERN_REGEX =
25 "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
26 private static final Pattern UUID_PATTERN = Pattern.compile(UUID_PATTERN_REGEX);
28 // See OpenStack Network API v2.0 Reference for description of
29 // annotated attributes
31 @XmlElement(name = "id")
34 private static void checkUuidPattern(String uuid) {
35 Preconditions.checkArgument(
36 UUID_PATTERN.matcher(requireNonNull(uuid, "Supplied value may not be null")).matches(),
37 "Supplied value \"%s\" does not match uuid pattern \"%s\"", uuid, UUID_PATTERN_REGEX);
43 public NeutronID(String uuid) {
44 checkUuidPattern(uuid);
48 public String getID() {
52 public void setID(String newUuid) {
53 checkUuidPattern(newUuid);
58 public String toString() {
59 return "NeutronID{" + "id='" + uuid + '\'' + "}";