blob: b92af251b7676fb1ba3b456e8382eb6a500c0454 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/* --- BEGIN COPYRIGHT BLOCK ---
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* --- END COPYRIGHT BLOCK --- */
package com.netscape.dsml.gateway;
import netscape.ldap.*;
import org.w3c.dom.*;
public class OperationAdd extends GenericOperation {
public javax.xml.soap.SOAPElement getResponse(gatewayContext ctx) {
ldapConn = ctx.getLdapConnection();
root = ctx.getRootNode();
LDAPAttributeSet ldAttrSet = new LDAPAttributeSet();
// XXX is this really necessary?
// if (ldAttrSet == null ) {
// throw new Exception("MEMORY_ALLOCATION_ERROR");
// }
String dn = root.getAttributes().getNamedItem("dn").getNodeValue().trim();
org.w3c.dom.NodeList nl = root.getChildNodes();
for (int i=0; i< nl.getLength(); i++) {
if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
try {
Node attr = nl.item(i).getFirstChild();
if (attr.getNodeType() == Node.TEXT_NODE)
attr = attr.getNextSibling();
String attrName = nl.item(i).getAttributes().getNamedItem("name").getNodeValue();
byte[] attrValue;
if (nl.item(i).getFirstChild().getNodeType() == Node.ELEMENT_NODE)
attrValue = ParseValue.parseValueFromNode( nl.item(i).getFirstChild() );
else
attrValue = ParseValue.parseValueFromNode( nl.item(i).getFirstChild().getNextSibling() );
LDAPAttribute ldapAttr = new LDAPAttribute( attrName, attrValue);
if (ldapAttr != null ) {
ldAttrSet.add(ldapAttr);
}
}
catch (Exception e) { e.printStackTrace();}
}
}
int resultCode= 0;
String errorMessage = "completed";
LDAPEntry entry = new LDAPEntry(dn,ldAttrSet);
javax.xml.soap.SOAPElement output = null;
try {
if (ctx.getConstraints() != null) {
ldapConn.add(entry, ctx.getConstraints() ); }
else {
ldapConn.add( entry ); }
} catch (LDAPException E) {
resultCode = E.getLDAPResultCode();
errorMessage = E.getLDAPErrorMessage();
}
javax.xml.soap.SOAPBodyElement sbe = null;
try {
sbe = messageFactory.createMessage().getSOAPBody().addBodyElement(messageFactory.createMessage().getSOAPPart().getEnvelope().createName("addResponse") );
sbe.addChildElement("resultCode").addAttribute(messageFactory.createMessage().getSOAPPart().getEnvelope().createName("code"), new Integer(resultCode).toString() );
if (errorMessage != null)
sbe.addChildElement("errorMessage").addTextNode(errorMessage);
} catch (Exception E) {
E.printStackTrace();
}
return sbe;
}
}
|