001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017 018package org.opends.server.admin; 019 020 021 022import static org.forgerock.util.Reject.ifNull; 023 024import java.util.EnumSet; 025 026import org.forgerock.i18n.LocalizedIllegalArgumentException; 027import org.forgerock.opendj.ldap.AddressMask; 028 029 030 031/** 032 * IP address mask property definition. 033 */ 034public final class IPAddressMaskPropertyDefinition extends 035 PropertyDefinition<AddressMask> { 036 037 /** 038 * An interface for incrementally constructing IP address mask property 039 * definitions. 040 */ 041 public static class Builder extends 042 AbstractBuilder<AddressMask, IPAddressMaskPropertyDefinition> { 043 044 /** Private constructor. */ 045 private Builder( 046 AbstractManagedObjectDefinition<?, ?> d, String propertyName) { 047 super(d, propertyName); 048 } 049 050 051 052 /** {@inheritDoc} */ 053 @Override 054 protected IPAddressMaskPropertyDefinition buildInstance( 055 AbstractManagedObjectDefinition<?, ?> d, 056 String propertyName, EnumSet<PropertyOption> options, 057 AdministratorAction adminAction, 058 DefaultBehaviorProvider<AddressMask> defaultBehavior) { 059 return new IPAddressMaskPropertyDefinition(d, propertyName, options, 060 adminAction, defaultBehavior); 061 } 062 063 } 064 065 066 067 /** 068 * Create a IP address mask property definition builder. 069 * 070 * @param d 071 * The managed object definition associated with this 072 * property definition. 073 * @param propertyName 074 * The property name. 075 * @return Returns the new IP address mask property definition builder. 076 */ 077 public static Builder createBuilder( 078 AbstractManagedObjectDefinition<?, ?> d, String propertyName) { 079 return new Builder(d, propertyName); 080 } 081 082 083 084 /** Private constructor. */ 085 private IPAddressMaskPropertyDefinition( 086 AbstractManagedObjectDefinition<?, ?> d, String propertyName, 087 EnumSet<PropertyOption> options, 088 AdministratorAction adminAction, 089 DefaultBehaviorProvider<AddressMask> defaultBehavior) { 090 super(d, AddressMask.class, propertyName, options, adminAction, 091 defaultBehavior); 092 } 093 094 095 096 /** {@inheritDoc} */ 097 @Override 098 public void validateValue(AddressMask value) 099 throws PropertyException { 100 ifNull(value); 101 102 // No additional validation required. 103 } 104 105 106 107 /** {@inheritDoc} */ 108 @Override 109 public AddressMask decodeValue(String value) 110 throws PropertyException { 111 ifNull(value); 112 113 try { 114 return AddressMask.valueOf(value); 115 } catch (LocalizedIllegalArgumentException e) { 116 // TODO: it would be nice to throw the cause. 117 throw PropertyException.illegalPropertyValueException(this, value); 118 } 119 } 120 121 122 123 /** {@inheritDoc} */ 124 @Override 125 public <R, P> R accept(PropertyDefinitionVisitor<R, P> v, P p) { 126 return v.visitIPAddressMask(this, p); 127 } 128 129 130 131 /** {@inheritDoc} */ 132 @Override 133 public <R, P> R accept(PropertyValueVisitor<R, P> v, AddressMask value, P p) { 134 return v.visitIPAddressMask(this, value, p); 135 } 136 137 138 139 /** {@inheritDoc} */ 140 @Override 141 public int compare(AddressMask o1, AddressMask o2) { 142 return o1.toString().compareTo(o2.toString()); 143 } 144}