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 2012-2015 ForgeRock AS. 015 */ 016package org.opends.dsml.protocol; 017 018import java.util.HashMap; 019 020/** 021 * A utility class to help creating ResultCode objects containing a 022 * code value (integer) and a descr value (String). 023 */ 024public class ResultCodeFactory 025{ 026 static HashMap<Integer,LDAPResultCode> codeToDescr = new HashMap<>(); 027 static 028 { 029 codeToDescr.put(0, LDAPResultCode.SUCCESS); 030 codeToDescr.put(1, LDAPResultCode.OPERATIONS_ERROR); 031 codeToDescr.put(2, LDAPResultCode.PROTOCOL_ERROR); 032 codeToDescr.put(3, LDAPResultCode.TIME_LIMIT_EXCEEDED); 033 codeToDescr.put(4, LDAPResultCode.SIZE_LIMIT_EXCEEDED); 034 codeToDescr.put(5, LDAPResultCode.COMPARE_FALSE); 035 codeToDescr.put(6, LDAPResultCode.COMPARE_TRUE); 036 codeToDescr.put(7, LDAPResultCode.AUTH_METHOD_NOT_SUPPORTED); 037 // Note not STRONGER_AUTH_REQUIRED, that's the RFC 4511 name 038 codeToDescr.put(8, LDAPResultCode.STRONG_AUTH_REQUIRED); 039 codeToDescr.put(10, LDAPResultCode.REFERRAL); 040 codeToDescr.put(11, LDAPResultCode.ADMIN_LIMIT_EXCEEDED); 041 codeToDescr.put(12, LDAPResultCode.UNAVAILABLE_CRITICAL_EXTENSION); 042 codeToDescr.put(13, LDAPResultCode.CONFIDENTIALITY_REQUIRED); 043 codeToDescr.put(14, LDAPResultCode.SASL_BIND_IN_PROGRESS); 044 codeToDescr.put(16, LDAPResultCode.NO_SUCH_ATTRIBUTE); 045 codeToDescr.put(17, LDAPResultCode.UNDEFINED_ATTRIBUTE_TYPE); 046 codeToDescr.put(18, LDAPResultCode.INAPPROPRIATE_MATCHING); 047 codeToDescr.put(19, LDAPResultCode.CONSTRAINT_VIOLATION); 048 codeToDescr.put(20, LDAPResultCode.ATTRIBUTE_OR_VALUE_EXISTS); 049 codeToDescr.put(21, LDAPResultCode.INVALID_ATTRIBUTE_SYNTAX); 050 codeToDescr.put(32, LDAPResultCode.NO_SUCH_OBJECT); 051 codeToDescr.put(33, LDAPResultCode.ALIAS_PROBLEM); 052 codeToDescr.put(34, LDAPResultCode.INVALID_DN_SYNTAX); 053 codeToDescr.put(36, LDAPResultCode.ALIAS_DEREFERENCING_PROBLEM); 054 codeToDescr.put(48, LDAPResultCode.INAPPROPRIATE_AUTHENTICATION); 055 codeToDescr.put(49, LDAPResultCode.INVALID_CREDENTIALS); 056 codeToDescr.put(50, LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS); 057 codeToDescr.put(51, LDAPResultCode.BUSY); 058 codeToDescr.put(52, LDAPResultCode.UNAVAILABLE); 059 codeToDescr.put(53, LDAPResultCode.UNWILLING_TO_PERFORM); 060 codeToDescr.put(54, LDAPResultCode.LOOP_DETECT); 061 codeToDescr.put(64, LDAPResultCode.NAMING_VIOLATION); 062 codeToDescr.put(65, LDAPResultCode.OBJECT_CLASS_VIOLATION); 063 codeToDescr.put(66, LDAPResultCode.NOT_ALLOWED_ON_NON_LEAF); 064 codeToDescr.put(67, LDAPResultCode.NOT_ALLOWED_ON_RDN); 065 codeToDescr.put(68, LDAPResultCode.ENTRY_ALREADY_EXISTS); 066 codeToDescr.put(69, LDAPResultCode.OBJECT_CLASS_MODS_PROHIBITED); 067 // Note not AFFECTS_MULTIPLE_DSAS, xjc mangles the string. 068 codeToDescr.put(71, LDAPResultCode.AFFECT_MULTIPLE_DS_AS); 069 codeToDescr.put(80, LDAPResultCode.OTHER); 070 } 071 072 /** 073 * Create a ResultCode object that contains the resultCode, and, if valid, 074 * a text description (from RFC 2251) of the resultCode. 075 * 076 * @param objFactory 077 * The JAXB factory used to create the underlying object. 078 * @param resultCode 079 * The LDAP result code. 080 * @return A ResultCode object with a code and possibly a description. 081 */ 082 public static ResultCode create(ObjectFactory objFactory, int resultCode) 083 { 084 ResultCode result = objFactory.createResultCode(); 085 result.setCode(resultCode); 086 Integer r = Integer.valueOf(resultCode); 087 if (ResultCodeFactory.codeToDescr.containsKey(r)) 088 { 089 result.setDescr(ResultCodeFactory.codeToDescr.get(r)); 090 } 091 return result; 092 } 093}