use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class ModelQueryImpl method canWrap.
/**
* This method is experimental... use at your own risk
*/
public boolean canWrap(Element childElement, CMElementDeclaration wrapElement, int validityChecking) {
boolean result = true;
Node parentNode = childElement.getParentNode();
if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
Element parentElement = (Element) parentNode;
CMElementDeclaration parentEd = getCMElementDeclaration(parentElement);
if (parentEd != null) {
if (validityChecking == VALIDITY_STRICT) {
int index = getIndexOfNode(parentElement.getChildNodes(), childElement);
List contentSpecificationList = getValidator().createContentSpecificationList(parentElement, parentEd);
List subList = contentSpecificationList.subList(index, index + 1);
result = getValidator().canReplace(parentEd, contentSpecificationList, index, index, wrapElement);
if (result) {
result = getValidator().isValid(wrapElement, subList);
}
}
}
} else {
result = false;
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class ModelQueryImpl method canRemove.
public boolean canRemove(List nodeList, int validityChecking) {
boolean result = true;
if (validityChecking == VALIDITY_STRICT) {
Element parentElement = null;
List childList = null;
for (Iterator i = nodeList.iterator(); i.hasNext(); ) {
Node node = (Node) i.next();
if (parentElement == null) {
parentElement = getParentOrOwnerElement(node);
} else if (parentElement != getParentOrOwnerElement(node)) {
// make sure the parent are the same
result = false;
break;
}
if (parentElement == null) {
result = true;
break;
}
int nodeType = node.getNodeType();
if (nodeType == Node.ATTRIBUTE_NODE) {
if (!canRemove(node, validityChecking)) {
result = false;
break;
}
} else {
if (childList == null) {
childList = nodeListToList(parentElement.getChildNodes());
}
childList.remove(node);
}
}
if (result && childList != null) {
CMElementDeclaration ed = getCMElementDeclaration(parentElement);
if (ed != null) {
List contentSpecificationList = getValidator().createContentSpecificationList(childList, ed);
result = getValidator().isValid(ed, contentSpecificationList);
}
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class ModelQueryImpl method getPossibleDataTypeValues.
/**
* This methods return an array of possible values corresponding to the datatype of the CMNode (either an CMAttributeDeclaration or a CMElementDeclaration)
*/
public String[] getPossibleDataTypeValues(Element element, CMNode cmNode) {
List list = new ArrayList();
if (cmNode != null) {
CMDataType dataType = null;
if (cmNode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
dataType = ((CMAttributeDeclaration) cmNode).getAttrType();
} else if (cmNode.getNodeType() == CMNode.ELEMENT_DECLARATION) {
dataType = ((CMElementDeclaration) cmNode).getDataType();
}
String[] enumeratedValues = dataType != null ? dataType.getEnumeratedValues() : null;
if (enumeratedValues != null) {
for (int i = 0; i < enumeratedValues.length; i++) {
list.add(enumeratedValues[i]);
}
}
}
addValuesForXSIType(element, cmNode, list);
if (extensionManager != null) {
list.addAll(extensionManager.getDataTypeValues(element, cmNode));
}
// Remove duplicates
List duplicateFreeList = new ArrayList();
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
Object next = iterator.next();
if (duplicateFreeList.indexOf(next) == -1) {
duplicateFreeList.add(next);
}
}
return (String[]) duplicateFreeList.toArray(new String[duplicateFreeList.size()]);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLAssociationProvider method getCMAttributeDeclaration.
public CMAttributeDeclaration getCMAttributeDeclaration(Attr attr) {
CMAttributeDeclaration result = null;
Element element = attr.getOwnerElement();
if (element != null) {
CMElementDeclaration ed = getCMElementDeclaration(element);
if (ed != null) {
result = (CMAttributeDeclaration) ed.getAttributes().getNamedItem(attr.getName());
if (result == null) {
// try to get the unprefixed name
String name = DOMNamespaceHelper.getUnprefixedName(attr.getName());
result = (CMAttributeDeclaration) ed.getAttributes().getNamedItem(name);
}
if (result == null) {
// todo... perhaps this is a globally defined attribute...
}
}
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class XMLAssociationProvider method getCMElementDeclaration.
protected CMElementDeclaration getCMElementDeclaration(Element targetElement, List list, NamespaceTable namespaceTable) {
CMElementDeclaration currentED = null;
try {
int listSize = list.size();
for (int i = 0; i < listSize; i++) {
Element element = (Element) list.get(i);
if (i != 0) {
namespaceTable.addElement(element);
}
String nodeName = element.getNodeName();
String unprefixedName = DOMNamespaceHelper.getUnprefixedName(nodeName);
String prefix = DOMNamespaceHelper.getPrefix(nodeName);
CMElementDeclaration ed = null;
//
if (currentED != null) {
ed = (CMElementDeclaration) currentED.getLocalElements().getNamedItem(unprefixedName);
}
if (ed == null) {
NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(prefix);
if (namespaceInfo != null) {
// $NON-NLS-1$
CMDocument cmDocument = getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD");
if (cmDocument != null) {
ed = (CMElementDeclaration) cmDocument.getElements().getNamedItem(unprefixedName);
}
}
}
currentED = ed;
// handle XSIType
if (currentED != null) {
CMElementDeclaration derivedED = getDerivedCMElementDeclaration(element, currentED, namespaceTable);
if (derivedED != null) {
currentED = derivedED;
}
}
}
} catch (Exception e) {
// $NON-NLS-1$
Logger.logException("exception locating element declaration for " + targetElement, e);
}
return currentED;
}
Aggregations