KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.directory.ldapstudio.dsmlv2.DsmlDecorator;
24 import org.apache.directory.ldapstudio.dsmlv2.ParserUtils;
25 import org.apache.directory.shared.ldap.codec.LdapMessage;
26 import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
27 import org.dom4j.Element;
28 import org.dom4j.Namespace;
29 import org.dom4j.QName;
30
31
32 /**
33  * DSML Decorator for ExtendedResponse
34  *
35  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
36  * @version $Rev$, $Date$
37  */

38 public class ExtendedResponseDsml extends LdapResponseDecorator implements DsmlDecorator
39 {
40     /**
41      * Creates a new instance of ExtendedResponseDsml.
42      *
43      * @param ldapMessage
44      * the message to decorate
45      */

46     public ExtendedResponseDsml( LdapMessage ldapMessage )
47     {
48         super( ldapMessage );
49     }
50
51     
52     /* (non-Javadoc)
53      * @see org.apache.directory.ldapstudio.dsmlv2.reponse.LdapMessageDecorator#getMessageType()
54      */

55     public int getMessageType()
56     {
57         return instance.getMessageType();
58     }
59
60     
61     /* (non-Javadoc)
62      * @see org.apache.directory.ldapstudio.dsmlv2.reponse.DsmlDecorator#toDsml(org.dom4j.Element)
63      */

64     public Element toDsml( Element root )
65     {
66         Element element = root.addElement( "extendedResponse" );
67         ExtendedResponse extendedResponse = ( ExtendedResponse ) instance;
68
69         // LDAP Result
70
LdapResultDsml ldapResultDsml = new LdapResultDsml( extendedResponse.getLdapResult(), instance );
71         ldapResultDsml.toDsml( element );
72         
73         // ResponseName
74
String JavaDoc responseName = extendedResponse.getResponseName();
75         if ( responseName != null )
76         {
77             element.addElement( "responseName").addText( responseName );
78         }
79         
80         // Response
81
Object JavaDoc response = extendedResponse.getResponse();
82         if ( response != null )
83         {
84             if ( ParserUtils.needsBase64Encoding( response ) )
85             {
86                 Namespace xsdNamespace = new Namespace( ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI );
87                 Namespace xsiNamespace = new Namespace( ParserUtils.XSI, ParserUtils.XML_SCHEMA_INSTANCE_URI );
88                 element.getDocument().getRootElement().add( xsdNamespace );
89                 element.getDocument().getRootElement().add( xsiNamespace );
90                 
91                 Element responseElement = element.addElement( "response").addText( ParserUtils.base64Encode( response ) );
92                 responseElement.addAttribute( new QName("type", xsiNamespace), ParserUtils.XSD + ":" + ParserUtils.BASE64BINARY );
93             }
94             else
95             {
96                 element.addElement( "response").addText( response.toString() );
97             }
98         }
99         
100         return element;
101     }
102 }
103
Popular Tags