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.server.config.beans;
021
022
023import org.apache.directory.server.config.ConfigurationElement;
024
025
026/**
027 * A class used to store the Interceptors configuration.
028 *
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 */
031public class InterceptorBean extends AdsBaseBean implements Comparable<InterceptorBean>
032{
033    /** The Interceptor ID */
034    @ConfigurationElement(attributeType = "ads-interceptorId", isRdn = true)
035    private String interceptorId;
036
037    /** The interceptor FQCN */
038    @ConfigurationElement(attributeType = "ads-interceptorClassName")
039    private String interceptorClassName;
040
041    /** The interceptor position in the chain */
042    @ConfigurationElement(attributeType = "ads-interceptorOrder")
043    private int interceptorOrder;
044
045
046    /**
047     * Creates a new InterceptorBean
048     */
049    public InterceptorBean()
050    {
051    }
052
053
054    /**
055     * Compares the order of the interceptor with the given one
056     * @param o An interceptor 
057     * @return -1 if the current interceptor is below the given one, 1 if 
058     * it's above, 0 if it's equal
059     */
060    public int compareTo( InterceptorBean o )
061    {
062        if ( interceptorOrder > o.interceptorOrder )
063        {
064            return 1;
065        }
066        else if ( interceptorOrder < o.interceptorOrder )
067        {
068            return -1;
069        }
070
071        return 0;
072    }
073
074
075    /**
076     * @return the id
077     */
078    public String getInterceptorId()
079    {
080        return interceptorId;
081    }
082
083
084    /**
085     * @param id the id to set
086     */
087    public void setInterceptorId( String id )
088    {
089        this.interceptorId = id;
090    }
091
092
093    /**
094     * @return the interceptor Order
095     */
096    public int getInterceptorOrder()
097    {
098        return interceptorOrder;
099    }
100
101
102    /**
103     * @param interceptorOrder the interceptor Order to set
104     */
105    public void setInterceptorOrder( int interceptorOrder )
106    {
107        this.interceptorOrder = interceptorOrder;
108    }
109
110
111    /**
112     * @return the interceptor ClassName
113     */
114    public String getInterceptorClassName()
115    {
116        return interceptorClassName;
117    }
118
119
120    /**
121     * @param interceptorClassName the interceptor ClassName to set
122     */
123    public void setInterceptorClassName( String interceptorClassName )
124    {
125        this.interceptorClassName = interceptorClassName;
126    }
127
128
129    /**
130     * {@inheritDoc}
131     */
132    @Override
133    public String toString( String tabs )
134    {
135        StringBuilder sb = new StringBuilder();
136
137        sb.append( tabs ).append( "interceptor[" ).append( interceptorOrder ).append( "] : " ).append( '\n' );
138        sb.append( tabs ).append( "  interceptor id : " ).append( interceptorId ).append( '\n' );
139        sb.append( tabs ).append( "  class name : " ).append( interceptorClassName ).append( '\n' );
140
141        return sb.toString();
142    }
143
144
145    /**
146     * {@inheritDoc}
147     */
148    @Override
149    public String toString()
150    {
151        return toString( "" );
152    }
153}