Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
// If deep, replicate and attach the kids.
if (deep)
for (DOMNode *srckid = source->getFirstChild();
srckid != 0;
srckid = srckid->getNextSibling())
{
newnode->appendChild(importNode(srckid, true, false));
}
if (newnode->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE
|| newnode->getNodeType() == DOMNode::ENTITY_NODE) {
castToNodeImpl(newnode)->setReadOnly(true, true);
errorChecking = oldErrorCheckingFlag;
}
if (!cloningDoc)
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_IMPORTED, source, newnode);
return newnode;
}
// user data utility
void* DOMDocumentImpl::setUserData(DOMNodeImpl* n, const XMLCh* key, void* data, DOMUserDataHandler* handler)
{
void* oldData = 0;
if (!fUserDataTable) {
// create the table on heap so that it can be cleaned in destructor
fUserDataTable = new (this) RefHashTableOf<DOMNodeUserDataTable>(29, true, new HashPtr());
}
else {
node_userDataTable = fUserDataTable->get((void*)n);
DOMUserDataRecord* oldDataRecord = 0;
if (node_userDataTable) {
oldDataRecord = node_userDataTable->get((void*)key);
if (oldDataRecord) {
oldData = oldDataRecord->getKey();
node_userDataTable->removeKey((void*)key);
}
}
}
if (data) {
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
// create on the heap and adopted by the hashtable which will delete it upon removal.
if (!node_userDataTable) {
node_userDataTable = new RefHashTableOf<DOMUserDataRecord>(29, true);
fUserDataTable->put(n, node_userDataTable);
}
// clone the key first, and create the DOMUserDataRecord
// create on the heap and adopted by the hashtable which will delete it upon removal.
node_userDataTable->put((void*)getPooledString(key), new DOMUserDataRecord(data, handler));
}
else {
if (node_userDataTable->isEmpty())
n->hasUserData(false);
}
return oldData;
}
void* DOMDocumentImpl::getUserData(const DOMNodeImpl* n, const XMLCh* key) const
{
if (fUserDataTable) {
DOMNodeUserDataTable* node_userDataTable = fUserDataTable->get((void*)n);
if (node_userDataTable) {
DOMUserDataRecord* dataRecord = node_userDataTable->get((void*)key);
if (dataRecord)
return dataRecord->getKey();
}
}
return 0;
}
void DOMDocumentImpl::callUserDataHandlers(const DOMNodeImpl* n, DOMUserDataHandler::DOMOperationType operation, const DOMNode* src, const DOMNode* dst) const
{
if (fUserDataTable) {
DOMNodeUserDataTable* node_userDataTable = fUserDataTable->get((void*)n);
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
if (node_userDataTable) {
RefHashTableOfEnumerator<DOMUserDataRecord> userDataEnum(node_userDataTable);
// walk through the entire node_userDataTable table
while (userDataEnum.hasMoreElements()) {
// get the key
XMLCh* key = (XMLCh*) userDataEnum.nextElementKey();
// get the DOMUserDataRecord
DOMUserDataRecord* userDataRecord = node_userDataTable->get((void*)key);
// get the handler
DOMUserDataHandler* handler = userDataRecord->getValue();
if (handler) {
// get the data
void* data = userDataRecord->getKey();
handler->handle(operation, key, data, src, dst);
}
}
}
}
}
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
void DOMDocumentImpl::release()
{
DOMDocument* doc = (DOMDocument*) this;
delete doc;
};
void DOMDocumentImpl::release(DOMNode* object, NodeObjectType type)
{
if (!fRecycleNodePtr)
fRecycleNodePtr = new RefArrayOf<DOMNodePtr> (15);
if (!fRecycleNodePtr->operator[](type))
fRecycleNodePtr->operator[](type) = new RefStackOf<DOMNode> (15, false);
fRecycleNodePtr->operator[](type)->push(object);
}
void * DOMDocumentImpl::allocate(size_t amount, NodeObjectType type)
{
if (!fRecycleNodePtr)
return allocate(amount);
DOMNodePtr* ptr = fRecycleNodePtr->operator[](type);
if (!ptr || ptr->empty())
return allocate(amount);
return (void*) ptr->pop();
}