com.opsdatastore.annotation.StandardProperty Maven / Gradle / Ivy
package com.opsdatastore.annotation;
/*-
* #%L
* OpsDataStore SDK
* %%
* Copyright (C) 2017 OpsDataStore
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import com.opsdatastore.util.NetworkAddressValidator;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation that indicates that this property is of a standard type
* @author kguthrie
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface StandardProperty {
/**
* Enumeration of the types of standard property types
*/
public static enum Type {
/** Property representing a mac address in the form MM:MM:MM:SS:SS:SS */
MacAddress("MAC Address")
/** Property representing an ip address v4 or v6 */
, IpAddress("IP Address") {
@Override
public String getTypeName(String ipAddress) {
if (ipAddress != null
&& NetworkAddressValidator.isIPV6(ipAddress)) {
return "IPV6 Address";
}
return propertyName;
}
}
/**
* Property representing the "Service Tag" of a piece of hardware, this
* is in a format dependant on the hardware's manufacturer
*/
, ServiceTag("Service Tag")
;
protected final String propertyName;
private Type() {
this(null);
}
private Type(String propertyName) {
this.propertyName = propertyName;
}
/**
* Get the name of the standard property based on the value. This is
* here originally for IpAddress, to distinguish between ipV6 address
* and ipV4
* @param value value to get the property name for
* @return the name of the property for the given value
*/
public String getTypeName(String value) {
return propertyName;
}
}
/**
* Indication of which standard type this property represents
* @return
*/
Type value();
}