blob: 5fee7148070d59ac94c0389465781243aeb358be [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.incubator.net.l2monitoring.cfm.identifier;
17
18import org.onlab.util.Identifier;
19
20/**
21 * A representation of a string identifier as an MA identifier.
22 */
23public final class MaIdCharStr extends Identifier<String> implements MaIdShort {
24 private static final String MANAME_PATTERN = "[a-zA-Z0-9\\-:]{1,48}";
25
26 protected MaIdCharStr(String mdName) {
27 super(mdName);
28 }
29
30 @Override
31 public String maName() {
32 return identifier;
33 }
34
35 @Override
36 public int getNameLength() {
37 return identifier.length();
38 }
39
40 @Override
41 public MaIdType nameType() {
42 return MaIdType.CHARACTERSTRING;
43 }
44
45 public static MaIdShort asMaId(String maName) {
46 if (maName == null || !maName.matches(MANAME_PATTERN)) {
47 throw new IllegalArgumentException("MA Name must follow pattern "
48 + MANAME_PATTERN + " Rejecting: " + maName);
49 }
50 return new MaIdCharStr(maName);
51 }
52}