1 /* 2 * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.jndi.ldap; 27 28 import javax.naming.ldap.UnsolicitedNotification; 29 import javax.naming.NamingException; 30 import javax.naming.ldap.Control; 31 import java.util.Vector; 32 33 /** 34 * A concrete implementation of an UnsolicitedNotification. 35 * @author Rosanna Lee 36 */ 37 final class UnsolicitedResponseImpl implements UnsolicitedNotification { 38 private String oid; 39 private String[] referrals; 40 private byte[] extensionValue; 41 private NamingException exception; 42 private Control[] controls; 43 44 UnsolicitedResponseImpl(String oid, byte[] berVal, Vector<Object> ref, 45 int status, String msg, String matchedDN, Control[] controls) { 46 this.oid = oid; 47 this.extensionValue = berVal; 48 49 if (ref != null && ref.size() > 0) { 50 int len = ref.size(); 51 referrals = new String[len]; 52 for (int i = 0; i < len; i++) { 53 referrals[i] = (String)ref.elementAt(i); 54 } 55 } 56 exception = LdapCtx.mapErrorCode(status, msg); 57 // matchedDN ignored for now; could be used to set resolvedName 58 // exception.setResolvedName(new CompositeName().add(matchedDN)); 59 60 this.controls = controls; 61 } 62 63 /** 64 * Retrieves the object identifier of the response. 65 * 66 * @return A possibly null object identifier string representing the LDAP 67 * <tt>ExtendedResponse.responseName</tt> component. 68 */ 69 public String getID() { 70 return oid; 71 } 72 73 /** 74 * Retrieves the ASN.1 BER encoded value of the LDAP extended operation 75 * response. Null is returned if the value is absent from the response 76 * sent by the LDAP server. 77 * The result is the raw BER bytes including the tag and length of 78 * the response value. It does not include the response OID. 79 * 80 * @return A possibly null byte array representing the ASN.1 BER encoded 81 * contents of the LDAP <tt>ExtendedResponse.response</tt> 82 * component. 83 */ 84 public byte[] getEncodedValue() { 85 return extensionValue; 86 } 87 88 /** 89 * Retrieves the referral(s) sent by the server. 90 * 91 * @return A possibly null array of referrals, each of which is represented 92 * by a URL string. If null, no referral was sent by the server. 93 */ 94 public String[] getReferrals() { 95 return referrals; 96 } 97 98 /** 99 * Retrieves the exception as constructed using information 100 * sent by the server. 101 * @return A possibly null exception as constructed using information 102 * sent by the server. If null, a "success" status was indicated by 103 * the server. 104 */ 105 public NamingException getException() { 106 return exception; 107 } 108 109 public Control[] getControls() throws NamingException { 110 return controls; 111 } 112 113 private static final long serialVersionUID = 5913778898401784775L; 114 }