1 20 21 package org.apache.directory.ldapstudio.dsmlv2.reponse; 22 23 24 import org.apache.directory.ldapstudio.dsmlv2.DsmlDecorator; 25 import org.apache.directory.shared.ldap.codec.LdapResponse; 26 import org.dom4j.Element; 27 28 29 47 public class ErrorResponse extends LdapResponse implements DsmlDecorator 48 { 49 55 public enum ErrorResponseType 56 { 57 NOT_ATTEMPTED, COULD_NOT_CONNECT, CONNECTION_CLOSED, MALFORMED_REQUEST, GATEWAY_INTERNAL_ERROR, AUTHENTICATION_FAILED, UNRESOLVABLE_URI, OTHER 58 }; 59 60 61 private ErrorResponseType type; 62 63 64 private String message; 65 66 67 private int requestID; 68 69 70 73 public ErrorResponse() 74 { 75 } 76 77 78 88 public ErrorResponse( int requestID, ErrorResponseType type, String message ) 89 { 90 this.requestID = requestID; 91 this.type = type; 92 this.message = message; 93 } 94 95 96 99 public Element toDsml( Element root ) 100 { 101 Element element = root.addElement( "errorResponse" ); 102 103 if ( requestID != 0 ) 105 { 106 element.addAttribute( "requestID", "" + requestID ); 107 } 108 109 element.addAttribute( "type", getTypeDescr( type ) ); 111 112 114 if ( ( message != null ) && ( !"".equals( message ) ) ) 115 { 116 Element messageElement = element.addElement( "message" ); 117 messageElement.addText( message ); 118 } 119 120 return element; 121 } 122 123 124 132 public String getTypeDescr( ErrorResponseType type ) 133 { 134 if ( type.equals( ErrorResponseType.NOT_ATTEMPTED ) ) 135 { 136 return "notAttempted"; 137 } 138 else if ( type.equals( ErrorResponseType.COULD_NOT_CONNECT ) ) 139 { 140 return "couldNotConnect"; 141 } 142 else if ( type.equals( ErrorResponseType.CONNECTION_CLOSED ) ) 143 { 144 return "connectionClosed"; 145 } 146 else if ( type.equals( ErrorResponseType.MALFORMED_REQUEST ) ) 147 { 148 return "malformedRequest"; 149 } 150 else if ( type.equals( ErrorResponseType.GATEWAY_INTERNAL_ERROR ) ) 151 { 152 return "gatewayInternalError"; 153 } 154 else if ( type.equals( ErrorResponseType.AUTHENTICATION_FAILED ) ) 155 { 156 return "authenticationFailed"; 157 } 158 else if ( type.equals( ErrorResponseType.UNRESOLVABLE_URI ) ) 159 { 160 return "unresolvableURI"; 161 } 162 else if ( type.equals( ErrorResponseType.OTHER ) ) 163 { 164 return "other"; 165 } 166 else 167 { 168 return "unknown"; 169 } 170 } 171 172 173 179 public String getMessage() 180 { 181 return message; 182 } 183 184 185 191 public void setMessage( String message ) 192 { 193 this.message = message; 194 } 195 196 197 203 public int getRequestID() 204 { 205 return requestID; 206 } 207 208 209 215 public void setRequestID( int requestID ) 216 { 217 this.requestID = requestID; 218 } 219 220 221 227 public ErrorResponseType getType() 228 { 229 return type; 230 } 231 232 233 239 public void setType( ErrorResponseType type ) 240 { 241 this.type = type; 242 } 243 } 244
| Popular Tags
|