BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / adsal / configuration / api / src / main / java / org / opendaylight / controller / configuration / ConfigurationObject.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.configuration;
10
11 import java.io.Serializable;
12
13 public abstract class ConfigurationObject implements Serializable {
14     private static final long serialVersionUID = 1L;
15     private static final String DEFAULT_REGEX = "^[\\w-=\\+\\*\\.\\(\\)\\[\\]\\@\\|\\:]{1,256}$";
16     private static final String REGEX_PROP_NAME = "resourceNameRegularExpression";
17     private static String regex;
18
19     static {
20         String customRegex = System.getProperty(REGEX_PROP_NAME);
21         regex = (customRegex != null) ? customRegex : DEFAULT_REGEX;
22     }
23
24     /**
25      * Checks if the provided resource name matches the controller resource name
26      * regular expression
27      *
28      * @param name
29      *            The resource name to test
30      * @return true if the resource name is not null and matches the controller
31      *         resource name regular expression, false otherwise
32      */
33     protected boolean isValidResourceName(String name) {
34         return name != null && name.matches(regex);
35     }
36
37     /**
38      * Return the regular expression currently in use for testing the controller
39      * resource names
40      *
41      * @return The regular expression
42      */
43     public static String getRegularExpression() {
44         return regex;
45     }
46 }