You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/09/03 20:12:42 UTC

svn commit: r439815 - /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/LdapResult.java

Author: elecharny
Date: Sun Sep  3 11:12:41 2006
New Revision: 439815

URL: http://svn.apache.org/viewvc?view=rev&rev=439815
Log:
Added the new LdapResult class

Added:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/LdapResult.java

Added: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/LdapResult.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/LdapResult.java?view=auto&rev=439815
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/LdapResult.java (added)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/main/java/org/apache/directory/shared/ldap/messages/LdapResult.java Sun Sep  3 11:12:41 2006
@@ -0,0 +1,236 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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. 
+ *  
+ */
+package org.apache.directory.shared.ldap.messages;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.Name;
+
+import org.apache.directory.shared.ldap.utils.LdapURI;
+
+/**
+ * LDAPv3 result structure embedded into Responses. See section 4.1.10 in <a
+ * href="">RFC 2251</a> for a description of the LdapResult ASN.1 structure,
+ * here's a snippet from it:
+ * 
+ * <pre>
+ *   The LDAPResult is the construct used in this protocol to return
+ *   success or failure indications from servers to clients. In response
+ *   to various requests servers will return responses containing fields
+ *   of type LDAPResult to indicate the final status of a protocol
+ *   operation request.
+ * </pre>
+ * 
+ * There are slight differences between the ASN.1 grammar used in RFC 2251
+ * and in RFC 4511 :
+ *  - error code 8 has been changed from 'strongAuthRequired' to 'strongerAuthRequired' 
+ *  - 'errorMessage' was modified to 'diagnosticMessage'
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapResult
+{
+    /**
+     * Declares the Serial Version Uid.
+     *
+     * @see <a
+     *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
+     *      Declare Serial Version Uid</a>
+     */
+    static final long serialVersionUID = 2L;
+
+    /** Resultant operation error code - defaults to SUCCESS */
+    private ResultCode resultCode = ResultCode.SUCCESS;
+
+    /** The DN that is matched by the Bind */
+    private Name matchedDN;
+
+    /** The diagnostic message (was errorMessage in RFC 2251) */
+    private String diagnosticMessage;
+
+    /** The referrals, if any. This is an optional element */
+    private List<LdapURI> referrals;
+
+    /**
+     * Gets the descriptive diagnostic message associated with the error code. May be
+     * null for SUCCESS, COMPARE_TRUE, COMPARE_FALSE and REFERRAL operations.
+     * 
+     * @return the descriptive diagnostic message.
+     */
+    public String getDiagnosticMessage()
+    {
+        return diagnosticMessage;
+    }
+
+    /**
+     * Sets the descriptive diagnostic message associated with the error code. May be
+     * null for SUCCESS, COMPARE_TRUE, and COMPARE_FALSE operations.
+     * 
+     * @param diagnosticMessage
+     *            the descriptive diagnostic message.
+     */
+    public void setErrorMessage( String diagnosticMessage )
+    {
+        this.diagnosticMessage = diagnosticMessage;
+    }
+
+
+    /**
+     * Gets the lowest entry in the directory that was matched. For result codes
+     * of noSuchObject, aliasProblem, invalidDNSyntax and
+     * aliasDereferencingProblem, the matchedDN field is set to the name of the
+     * lowest entry (object or alias) in the directory that was matched. If no
+     * aliases were dereferenced while attempting to locate the entry, this will
+     * be a truncated form of the name provided, or if aliases were
+     * dereferenced, of the resulting name, as defined in section 12.5 of X.511
+     * [8]. The matchedDN field is to be set to a zero length string with all
+     * other result codes.
+     * 
+     * @return the Dn of the lowest matched entry.
+     */
+    public Name getMatchedDN()
+    {
+        return matchedDN;
+    }
+
+
+    /**
+     * Sets the lowest entry in the directory that was matched.
+     * 
+     * @see #getMatchedDN()
+     * @param matchedDN the DN of the lowest matched entry.
+     */
+    public void setMatchedsDn( Name matchedDN )
+    {
+        this.matchedDN = matchedDN;
+    }
+
+    /**
+     * Gets the result code enumeration associated with the response.
+     * Corresponds to the <b> resultCode </b> field within the LDAPResult ASN.1
+     * structure.
+     * 
+     * @return the result code enum value.
+     */
+    public ResultCode getResultCode()
+    {
+        return resultCode;
+    }
+
+    /**
+     * Sets the result code enumeration associated with the response.
+     * Corresponds to the <b> resultCode </b> field within the LDAPResult ASN.1
+     * structure.
+     * 
+     * @param resultCode the result code enum value.
+     */
+    public void setResultCode( ResultCode resultCode )
+    {
+        this.resultCode = resultCode;
+    }
+
+    /**
+     * Gets the URIs associated with this LdapResult if the resultCode
+     * property is set to the REFERRAL ResultCode. 
+     * 
+     * @return the URIs on REFERRAL errors, null on all others.
+     */
+    public List<LdapURI> getReferrals()
+    {
+        return referrals;
+    }
+
+
+    /**
+     * Gets whether or not this result represents a Referral. For referrals the
+     * error code is set to REFERRAL and the referral property is not null.
+     * 
+     * @return true if this result represents a referral.
+     */
+    public boolean isReferral()
+    {
+        return referrals != null;
+    }
+
+
+    /**
+     * Sets the URIs associated with this LdapResult if the resultCode
+     * property is set to the REFERRAL ResultCode. Setting this property
+     * will result in a true return from isReferral and the resultCode should be
+     * set to REFERRAL.
+     * 
+     * @param referral optional referrals on REFERRAL errors.
+     */
+    public void setReferrals( List<LdapURI> referrals )
+    {
+        this.referrals = referrals;
+    }
+
+    /**
+     * Sets the URIs associated with this LdapResult if the resultCode
+     * property is set to the REFERRAL ResultCode. Setting this property
+     * will result in a true return from isReferral and the resultCode should be
+     * set to REFERRAL.
+     * 
+     * @param referral optional referrals on REFERRAL errors.
+     */
+    public void addReferral( LdapURI ldapURI )
+    {
+        if ( this.referrals == null )
+        {
+            this.referrals = new ArrayList<LdapURI>();
+        }
+        
+        this.referrals.add( ldapURI );
+    }
+
+    /**
+     * Get a String representation of a LdapResult
+     * 
+     * @return A LdapResult String
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "        Ldap Result\n" );
+        sb.append( "            Result code : (" ).append( resultCode ).append( ')' );
+        sb.append( ' ' ).append( resultCode.getMessage() ).append(  '\n' );
+        
+        sb.append( "            Matched DN : '" ).append( matchedDN.toString() ).append( "'\n" );
+        sb.append( "            Diagnostic message : '" ).append( diagnosticMessage.toString() ).append( "'\n" );
+
+        if ( referrals.size() != 0 )
+        {
+            sb.append( "            Referrals :\n" );
+            int i = 0;
+
+            for ( LdapURI ldapURI : referrals )
+            {
+                sb.append( "                Referral[" ).append( i++ ).append( "] :" ).append( ldapURI.toString() )
+                    .append( '\n' );
+            }
+        }
+
+        return sb.toString();
+    }
+}