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 */
020
021package org.apache.directory.api.ldap.extras.controls.ppolicy_impl;
022
023
024import org.apache.directory.api.asn1.ber.AbstractContainer;
025import org.apache.directory.api.ldap.codec.api.LdapApiService;
026import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy;
027import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicyImpl;
028
029
030/**
031 * container for PasswordPolicyResponseControl.
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class PasswordPolicyContainer extends AbstractContainer
036{
037    private PasswordPolicyDecorator control;
038
039
040    /**
041     * Creates a new StoredProcedureContainer instance
042     * 
043     * @param codec The LDAP Service to use
044     */
045    public PasswordPolicyContainer( LdapApiService codec )
046    {
047        super();
048        control = new PasswordPolicyDecorator( codec, new PasswordPolicyImpl() );
049        setGrammar( PasswordPolicyGrammar.getInstance() );
050        setTransition( PasswordPolicyStates.START_STATE );
051    }
052
053
054    /**
055     * Creates a new StoredProcedureContainer instance
056     * 
057     * @param codec The LDAP Service to use
058     * @param ppolicyResponse The PasswordPolicy response
059     */
060    public PasswordPolicyContainer( LdapApiService codec, PasswordPolicy ppolicyResponse )
061    {
062        super();
063
064        if ( ppolicyResponse instanceof PasswordPolicyDecorator )
065        {
066            this.control = ( PasswordPolicyDecorator ) ppolicyResponse;
067        }
068        else
069        {
070            control = new PasswordPolicyDecorator( codec, ppolicyResponse );
071        }
072
073        setGrammar( PasswordPolicyGrammar.getInstance() );
074        setTransition( PasswordPolicyStates.START_STATE );
075    }
076
077
078    /**
079     * @return The decorated PasswordPolicy control
080     */
081    public PasswordPolicyDecorator getPasswordPolicyResponseControl()
082    {
083        return control;
084    }
085
086
087    /**
088     * Sets the password policy control
089     * 
090     * @param control The decorated PasswordPolicy control
091     */
092    public void setPasswordPolicyResponseControl( PasswordPolicyDecorator control )
093    {
094        this.control = control;
095    }
096
097
098    /**
099     * clean the container
100     */
101    @Override
102    public void clean()
103    {
104        super.clean();
105        control = null;
106    }
107
108}