attrMap = allAttributes;
}
List descriptorList = new ArrayList();
List names = new ArrayList();
IPropertyDescriptor descriptor;
CMAttributeDeclaration attrDecl = null;
// add descriptors for existing attributes
NamedNodeMap attributes = fNode.getAttributes();
if (attributes != null) {
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
// if metainfo is present for this attribute, use the
// CMAttributeDeclaration to derive a descriptor
if (attrMap != null) {
String attrName = attr.getName();
if (fCaseSensitive) {
attrDecl = (CMAttributeDeclaration) attrMap.getNamedItem(attrName);
}
else {
attrDecl = null;
for (int j = 0; j < attrMap.getLength(); j++) {
if (!fCaseSensitive && attrMap.item(j).getNodeName().equalsIgnoreCase(attrName)) {
attrDecl = (CMAttributeDeclaration) attrMap.item(j);
break;
}
}
}
}
// be consistent: if there's metainfo, use *that* as the
// descriptor ID
descriptor = null;
if (attrDecl != null) {
String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null);
if (!names.contains(attrName)) {
descriptor = createPropertyDescriptor(attrDecl, attr);
if (descriptor != null)
names.add(attrName);
}
}
else {
if (!names.contains(attr.getName())) {
descriptor = createDefaultPropertyDescriptor(attr.getName());
if (descriptor != null)
names.add(attr.getName());
}
}
if (descriptor != null) {
descriptorList.add(descriptor);
}
}
}
// add descriptors from the metainfo that are not yet listed
if (attrMap != null) {
for (int i = 0; i < attrMap.getLength(); i++) {
attrDecl = (CMAttributeDeclaration) attrMap.item(i);
String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null);
if (!names.contains(attrName)) {
IPropertyDescriptor holdDescriptor = createPropertyDescriptor(attrDecl, null);
if (holdDescriptor != null) {
names.add(attrName);
descriptorList.add(holdDescriptor);
}
}
}
}
// add MQE-based descriptors
if (ed != null && fNode.getNodeType() == Node.ELEMENT_NODE) {
List nodes = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument()).getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES);
for (int i = 0; i < nodes.size(); i++) {
CMNode node = (CMNode) nodes.get(i);
if (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
attrDecl = (CMAttributeDeclaration) node;
String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null);
if (!names.contains(attrName)) {
IPropertyDescriptor holdDescriptor = createPropertyDescriptor(attrDecl, null);
if (holdDescriptor != null) {
names.add(attrName);
descriptorList.add(holdDescriptor);
}
}