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
9 package org.opendaylight.neutron.spi;
11 import com.google.common.base.Preconditions;
12 import java.io.Serializable;
13 import java.util.regex.Pattern;
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
20 @XmlAccessorType(XmlAccessType.NONE)
21 public class NeutronID implements Serializable {
22 private static final long serialVersionUID = 1L;
23 private static final String UUID_PATTERN_REGEX =
24 "^[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}$";
25 private static final Pattern UUID_PATTERN = Pattern.compile(UUID_PATTERN_REGEX);
27 // See OpenStack Network API v2.0 Reference for description of
28 // annotated attributes
30 @XmlElement(name = "id")
33 private void checkUuidPattern(String uuid) {
34 Preconditions.checkNotNull(uuid, "Supplied value may not be null");
35 Preconditions.checkArgument(UUID_PATTERN.matcher(uuid).matches(),
36 "Supplied value \"%s\" does not match uuid pattern \"%s\"", uuid, UUID_PATTERN_REGEX);
42 public NeutronID(String uuid) {
43 checkUuidPattern(uuid);
47 public String getID() {
51 public void setID(String uuid) {
52 checkUuidPattern(uuid);
57 public String toString() {
58 return "NeutronID{" + "id='" + uuid + '\'' + "}";