001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.api.ldap.extras.controls.ppolicy;
021
022
023import org.apache.directory.api.ldap.model.message.Control;
024
025
026/**
027 * A simple {@link PasswordPolicy} {@link Control} implementation.
028 *
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 * @version $Rev$, $Date$
031 */
032public class PasswordPolicyImpl implements PasswordPolicy
033{
034    /** The criticality of this {@link Control} */
035    private boolean criticality;
036
037    /** The password policy response component if this is a response control */
038    private PasswordPolicyResponse response;
039
040
041    /**
042     * Creates a new instance of a PasswordPolicy request Control without any
043     * response data associated with it.
044     */
045    public PasswordPolicyImpl()
046    {
047        response = null;
048    }
049
050
051    /**
052     * Creates a new instance of a PasswordPolicy request Control without any
053     * response data associated with it.
054     */
055    public PasswordPolicyImpl( boolean hasResponse )
056    {
057        if ( hasResponse )
058        {
059            response = new PasswordPolicyResponseImpl();
060        }
061        else
062        {
063            response = null;
064        }
065    }
066
067
068    /**
069     * Creates a new instance of PasswordPolicy response Control with response 
070     * information packaged into the control.
071     */
072    public PasswordPolicyImpl( PasswordPolicyResponse response )
073    {
074        this.response = response;
075    }
076
077
078    /**
079     * {@inheritDoc}
080     */
081    public String getOid()
082    {
083        return PasswordPolicy.OID;
084    }
085
086
087    /**
088     * {@inheritDoc}
089     */
090    public boolean isCritical()
091    {
092        return criticality;
093    }
094
095
096    /**
097     * {@inheritDoc}
098     */
099    public void setCritical( boolean isCritical )
100    {
101        this.criticality = isCritical;
102    }
103
104
105    /**
106     * 
107     * {@inheritDoc}
108     */
109    public void setResponse( PasswordPolicyResponse response )
110    {
111        this.response = response;
112    }
113
114
115    /**
116     * {@inheritDoc}
117     */
118    public boolean hasResponse()
119    {
120        return response != null;
121    }
122
123
124    /**
125     * 
126     * {@inheritDoc}
127     */
128    public PasswordPolicyResponse setResponse( boolean hasResponse )
129    {
130        PasswordPolicyResponse old = this.response;
131
132        if ( hasResponse )
133        {
134            this.response = new PasswordPolicyResponseImpl();
135        }
136        else
137        {
138            this.response = null;
139        }
140
141        return old;
142    }
143
144
145    /**
146     * {@inheritDoc}
147     */
148    public PasswordPolicyResponse getResponse()
149    {
150        return response;
151    }
152}