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 * https://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 */ 020package org.apache.directory.api.dsmlv2.response; 021 022 023import java.util.Collection; 024 025import org.apache.directory.api.dsmlv2.DsmlLiterals; 026import org.apache.directory.api.ldap.codec.api.LdapApiService; 027import org.apache.directory.api.ldap.model.message.MessageTypeEnum; 028import org.apache.directory.api.ldap.model.message.Referral; 029import org.apache.directory.api.ldap.model.message.SearchResultReference; 030import org.apache.directory.api.ldap.model.message.SearchResultReferenceImpl; 031import org.apache.directory.api.ldap.model.url.LdapUrl; 032import org.dom4j.Element; 033import org.dom4j.tree.DefaultElement; 034 035 036/** 037 * DSML Decorator for SearchResultReference 038 * 039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 040 */ 041public class SearchResultReferenceDsml 042 extends AbstractResponseDsml<SearchResultReference> 043 implements SearchResultReference 044{ 045 /** 046 * Creates a new getDecoratedMessage() of SearchResultReferenceDsml. 047 * 048 * @param codec The LDAP Service to use 049 */ 050 public SearchResultReferenceDsml( LdapApiService codec ) 051 { 052 super( codec, new SearchResultReferenceImpl() ); 053 } 054 055 056 /** 057 * Creates a new getDecoratedMessage() of SearchResultReferenceDsml. 058 * 059 * @param codec The LDAP Service to use 060 * @param ldapMessage the message to decorate 061 */ 062 public SearchResultReferenceDsml( LdapApiService codec, SearchResultReference ldapMessage ) 063 { 064 super( codec, ldapMessage ); 065 } 066 067 068 /** 069 * {@inheritDoc} 070 */ 071 @Override 072 public MessageTypeEnum getType() 073 { 074 return getDecorated().getType(); 075 } 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public Element toDsml( Element root ) 083 { 084 Element element; 085 086 if ( root != null ) 087 { 088 element = root.addElement( DsmlLiterals.SEARCH_RESULT_REFERENCE ); 089 } 090 else 091 { 092 element = new DefaultElement( DsmlLiterals.SEARCH_RESULT_REFERENCE ); 093 } 094 095 // Adding References 096 for ( String url : getDecorated().getReferral().getLdapUrls() ) 097 { 098 element.addElement( DsmlLiterals.REF ).addText( url ); 099 } 100 101 return element; 102 } 103 104 105 /** 106 * Add a new reference to the list. 107 * 108 * @param searchResultReference The search result reference 109 */ 110 public void addSearchResultReference( LdapUrl searchResultReference ) 111 { 112 getDecorated().getReferral().addLdapUrl( searchResultReference.toString() ); 113 } 114 115 116 /** 117 * Get the list of references 118 * 119 * @return An ArrayList of SearchResultReferences 120 */ 121 public Collection<String> getSearchResultReferences() 122 { 123 return getDecorated().getReferral().getLdapUrls(); 124 } 125 126 127 /** 128 * {@inheritDoc} 129 */ 130 @Override 131 public Referral getReferral() 132 { 133 return getDecorated().getReferral(); 134 } 135 136 137 /** 138 * {@inheritDoc} 139 */ 140 @Override 141 public void setReferral( Referral referral ) 142 { 143 getDecorated().setReferral( referral ); 144 } 145}