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 */ 020 021 package org.apache.directory.shared.dsmlv2.reponse; 022 023 024 import java.util.List; 025 026 import org.apache.directory.shared.dsmlv2.DsmlDecorator; 027 import org.apache.directory.shared.ldap.codec.LdapMessageCodec; 028 import org.apache.directory.shared.ldap.codec.MessageTypeEnum; 029 import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec; 030 import org.apache.directory.shared.ldap.util.LdapURL; 031 import org.dom4j.Element; 032 033 034 /** 035 * DSML Decorator for SearchResultReference 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 * @version $Rev$, $Date$ 039 */ 040 public class SearchResultReferenceDsml extends LdapResponseDecorator implements DsmlDecorator 041 { 042 /** 043 * Creates a new instance of SearchResultReferenceDsml. 044 */ 045 public SearchResultReferenceDsml() 046 { 047 super( new SearchResultReferenceCodec() ); 048 } 049 050 051 /** 052 * Creates a new instance of SearchResultReferenceDsml. 053 * 054 * @param ldapMessage 055 * the message to decorate 056 */ 057 public SearchResultReferenceDsml( LdapMessageCodec ldapMessage ) 058 { 059 super( ldapMessage ); 060 } 061 062 063 /* (non-Javadoc) 064 * @see org.apache.directory.shared.dsmlv2.reponse.LdapMessageDecorator#getMessageType() 065 */ 066 public MessageTypeEnum getMessageType() 067 { 068 return instance.getMessageType(); 069 } 070 071 072 /* (non-Javadoc) 073 * @see org.apache.directory.shared.dsmlv2.reponse.DsmlDecorator#toDsml(org.dom4j.Element) 074 */ 075 public Element toDsml( Element root ) 076 { 077 Element element = root.addElement( "searchResultReference" ); 078 SearchResultReferenceCodec searchResultReference = ( SearchResultReferenceCodec ) instance; 079 080 // Adding References 081 List<LdapURL> refsList = searchResultReference.getSearchResultReferences(); 082 for ( int i = 0; i < refsList.size(); i++ ) 083 { 084 element.addElement( "ref" ).addText( refsList.get( i ).toString() ); 085 } 086 087 return element; 088 } 089 090 091 /** 092 * Add a new reference to the list. 093 * 094 * @param searchResultReference The search result reference 095 */ 096 public void addSearchResultReference( LdapURL searchResultReference ) 097 { 098 ( ( SearchResultReferenceCodec ) instance ).addSearchResultReference( searchResultReference ); 099 } 100 101 102 /** 103 * Get the list of references 104 * 105 * @return An ArrayList of SearchResultReferences 106 */ 107 public List<LdapURL> getSearchResultReferences() 108 { 109 return ( ( SearchResultReferenceCodec ) instance ).getSearchResultReferences(); 110 } 111 }