KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > request > AbstractRequestDsml


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  package org.apache.directory.ldapstudio.dsmlv2.request;
21
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.LdapConstants;
26 import org.apache.directory.shared.ldap.codec.LdapMessage;
27 import org.dom4j.Element;
28
29
30 public abstract class AbstractRequestDsml extends LdapRequestDecorator implements DsmlDecorator
31 {
32     /**
33      * Creates a new instance of AbstractRequestDsml.
34      *
35      * @param ldapMessage
36      * the message to decorate
37      */

38     public AbstractRequestDsml( LdapMessage ldapMessage )
39     {
40         super( ldapMessage );
41     }
42
43
44     /**
45      * Creates the Request Element and adds RequestID and Controls.
46      *
47      * @param root
48      * the root element
49      * @return
50      * the Request Element of the given name containing
51      */

52     public Element toDsml( Element root )
53     {
54         Element element = root.addElement( getRequestName() );
55         
56         // Request ID
57
int requestID = instance.getMessageId();
58         if ( requestID != 0 )
59         {
60             element.addAttribute( "requestID", "" + requestID );
61         }
62
63         // Controls
64
ParserUtils.addControls( element, instance.getControls() );
65         
66         return element;
67     }
68     
69     /**
70      * Gets the name of the request according to the type of the decorated element.
71      *
72      * @return
73      * the name of the request according to the type of the decorated element.
74      */

75     private String JavaDoc getRequestName()
76     {
77         switch ( instance.getMessageType() )
78         {
79             case LdapConstants.ABANDON_REQUEST:
80                 return "abandonRequest";
81             case LdapConstants.ADD_REQUEST:
82                 return "addRequest";
83             case LdapConstants.BIND_REQUEST:
84                 return "authRequest";
85             case LdapConstants.COMPARE_REQUEST:
86                 return "compareRequest";
87             case LdapConstants.DEL_REQUEST:
88                 return "delRequest";
89             case LdapConstants.EXTENDED_REQUEST:
90                 return "extendedRequest";
91             case LdapConstants.MODIFYDN_REQUEST:
92                 return "modDNRequest";
93             case LdapConstants.MODIFY_REQUEST:
94                 return "modifyRequest";
95             case LdapConstants.SEARCH_REQUEST:
96                 return "searchRequest";
97             default:
98                 return "error";
99         }
100     }
101 }
102
Popular Tags