KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > reponse > SearchResultEntryDsml


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.dsmlv2.reponse;
22
23
24 import javax.naming.NamingEnumeration JavaDoc;
25 import javax.naming.NamingException JavaDoc;
26 import javax.naming.directory.Attribute JavaDoc;
27 import javax.naming.directory.Attributes JavaDoc;
28
29 import org.apache.directory.ldapstudio.dsmlv2.DsmlDecorator;
30 import org.apache.directory.ldapstudio.dsmlv2.ParserUtils;
31 import org.apache.directory.shared.ldap.codec.LdapMessage;
32 import org.apache.directory.shared.ldap.codec.search.SearchResultEntry;
33 import org.dom4j.Element;
34 import org.dom4j.Namespace;
35 import org.dom4j.QName;
36
37
38 /**
39  * DSML Decorator for SearchResultEntry
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class SearchResultEntryDsml extends LdapResponseDecorator implements DsmlDecorator
45 {
46     /**
47      * Creates a new instance of SearchResultEntryDsml.
48      *
49      * @param ldapMessage
50      * the message to decorate
51      */

52     public SearchResultEntryDsml( LdapMessage ldapMessage )
53     {
54         super( ldapMessage );
55     }
56
57
58     /* (non-Javadoc)
59      * @see org.apache.directory.ldapstudio.dsmlv2.reponse.LdapMessageDecorator#getMessageType()
60      */

61     public int getMessageType()
62     {
63         return instance.getMessageType();
64     }
65
66
67     /* (non-Javadoc)
68      * @see org.apache.directory.ldapstudio.dsmlv2.reponse.DsmlDecorator#toDsml(org.dom4j.Element)
69      */

70     public Element toDsml( Element root )
71     {
72         Element element = root.addElement( "searchResultEntry" );
73         SearchResultEntry searchResultEntry = ( SearchResultEntry ) instance;
74         element.addAttribute( "dn", searchResultEntry.getObjectName().toString() );
75
76         Attributes JavaDoc attributes = searchResultEntry.getPartialAttributeList();
77         NamingEnumeration JavaDoc ne = attributes.getAll();
78
79         // Looping on Attributes Enumeration
80
while ( ne.hasMoreElements() )
81         {
82             Attribute JavaDoc attribute = ( Attribute JavaDoc ) ne.nextElement();
83
84             Element attributeElement = element.addElement( "attr" );
85             attributeElement.addAttribute( "name", attribute.getID() );
86
87             // Looping on Values Enumeration
88
try
89             {
90                 NamingEnumeration JavaDoc ne2 = attribute.getAll();
91
92                 while ( ne2.hasMoreElements() )
93                 {
94                     Object JavaDoc value = ne2.nextElement();
95
96                     if ( ParserUtils.needsBase64Encoding( value ) )
97                     {
98                         Namespace xsdNamespace = new Namespace( ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI );
99                         Namespace xsiNamespace = new Namespace( ParserUtils.XSI, ParserUtils.XML_SCHEMA_INSTANCE_URI );
100                         attributeElement.getDocument().getRootElement().add( xsdNamespace );
101                         attributeElement.getDocument().getRootElement().add( xsiNamespace );
102
103                         Element valueElement = attributeElement.addElement( "value" ).addText(
104                             ParserUtils.base64Encode( value ) );
105                         valueElement
106                             .addAttribute( new QName( "type", xsiNamespace ), ParserUtils.XSD + ":" + ParserUtils.BASE64BINARY );
107                     }
108                     else
109                     {
110                         attributeElement.addElement( "value" ).addText( value.toString() );
111                     }
112                 }
113             }
114             catch ( NamingException JavaDoc e )
115             {
116             }
117         }
118
119         return element;
120     }
121 }
122
Popular Tags