use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class ElementImplTests method testCMAttrWithNullImpliedValue.
public void testCMAttrWithNullImpliedValue() {
IDOMModel model = null;
try {
model = (IDOMModel) getModelForRead("testfiles/time.xml");
if (model != null) {
IDOMDocument document = model.getDocument();
final String ATTR_NAME = "second";
// Setup a ModelQueryAdapter whose sole purpose it to provide a attribute declaration with a null implied value
document.addAdapter(new ModelQueryAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(ModelQueryAdapter.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
}
public CMDocumentCache getCMDocumentCache() {
return null;
}
public org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver getIdResolver() {
return null;
}
public ModelQuery getModelQuery() {
return new ModelQueryImpl(null) {
/* (non-Javadoc)
* @see org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.ModelQueryImpl#getCMElementDeclaration(org.w3c.dom.Element)
*/
public CMElementDeclaration getCMElementDeclaration(Element element) {
final CMElementDeclaration decl = new CMElementDeclarationImpl(null, null);
CMNamedNodeMapImpl map = (CMNamedNodeMapImpl) decl.getAttributes();
map.put(new CMAttributeDeclarationImpl(ATTR_NAME, CMAttributeDeclaration.OPTIONAL, new CMDataTypeImpl(ATTR_NAME, (String) null)));
return decl;
}
};
}
public void release() {
}
public void setIdResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver newIdResolver) {
}
});
Element element = document.getDocumentElement();
assertNotNull(element);
// Default value should be 0
assertEquals("", element.getAttribute(ATTR_NAME));
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class CMPrinter method getProperties.
public List getProperties(CMNode cmnode) {
List properties = new Vector();
if (cmnode != null) {
// $NON-NLS-1$
properties.add("CMDocument");
// $NON-NLS-1$
properties.add("documentation");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/usesLocalElementDeclarations");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/isNameSpaceAware");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/nsPrefixQualification");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/nillable");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/mofNotifier");
// $NON-NLS-1$
properties.add("spec");
if (cmnode instanceof CMElementDeclaration) {
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/definitionInfo");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/definition");
// $NON-NLS-1$
properties.add("XSITypes");
// $NON-NLS-1$
properties.add("DerivedElementDeclaration");
// properties.add("SubstitutionGroup"); Currrently broken for nexted xsd files
// $NON-NLS-1$
properties.add("Abstract");
}
if (cmnode instanceof CMDocument) {
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/targetNamespaceURI");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/importedNamespaceInfo");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/namespaceInfo");
// $NON-NLS-1$
properties.add("http://org.eclipse.wst/cm/properties/elementFormDefault");
// $NON-NLS-1$
properties.add("annotationMap");
}
}
return properties;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class CMValidatorTest method main.
public static void main(String[] arg) {
if (arg.length > 1) {
try {
// CMDocumentFactoryRegistry.getInstance().registerCMDocumentBuilderWithClassName("org.eclipse.wst.xml.core.internal.contentmodel.mofimpl.CMDocumentBuilderImpl");
String grammarFileName = arg[0];
String elementName = arg[1];
CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null);
CMNamedNodeMap elementMap = cmDocument.getElements();
CMElementDeclaration element = (CMElementDeclaration) elementMap.getNamedItem(elementName);
if (element != null) {
/*
println("found element [" + elementName + "] contentType = " + element.getContentType());
GraphNode graphNode = createGraph(element);
printGraph(graphNode);
*/
// $NON-NLS-1$
println("-------------- begin validate ---------------");
StringElementContentComparator comparator = new StringElementContentComparator();
CMValidator validator = new CMValidator();
ElementPathRecordingResult result = new ElementPathRecordingResult();
validator.getOriginArray(element, CMValidator.createStringList(arg, 2), comparator, result);
if (result.isValid) {
CMNode[] nodeMapping = result.getOriginArray();
// $NON-NLS-1$
println("Validation Success!");
// $NON-NLS-1$
print(" ");
for (int i = 0; i < nodeMapping.length; i++) {
// $NON-NLS-1$
String name = nodeMapping[i] != null ? nodeMapping[i].getNodeName() : "null";
// $NON-NLS-1$ //$NON-NLS-2$
print("[" + name + "]");
}
// $NON-NLS-1$
println("");
} else {
// $NON-NLS-1$
println("Validation Failed! ");
if (result.errorMessage != null) {
// $NON-NLS-1$
println(" " + result.errorMessage);
}
}
// $NON-NLS-1$
println("-------------- end validate ---------------");
} else {
// $NON-NLS-1$ //$NON-NLS-2$
println("element [" + elementName + "] can not be found");
}
} catch (Exception e) {
// $NON-NLS-1$
println("CMValidator error");
e.printStackTrace();
}
} else {
// $NON-NLS-1$ //$NON-NLS-2$
println("2 args required... only " + arg.length + " provided");
// $NON-NLS-1$
println("usage java org.eclipse.wst.newxml.util.XMLUtil grammarFileName rootElementName pattern");
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class TestAttributesOrder method ensureDocumentHasGrammar.
/**
* Reusable test to make sure the XML model for the given file has a grammar.
*
* @param file
* the file containing the XML document.
*/
private void ensureDocumentHasGrammar(IFile file) throws IOException, CoreException {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", cmElementDeclaration);
assertNotNull("No content assist available for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", modelQuery.getAvailableContent(documentElement, cmElementDeclaration, ModelQuery.INCLUDE_CHILD_NODES));
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration in project webtools.sourceediting by eclipse.
the class TestCyclicGroupReferences method testCyclicGroupReferences.
/**
* Test CMVisitor for cyclic group references.
*/
public void testCyclicGroupReferences() {
// $NON-NLS-1$
IFile file = getFile("Test.xml");
CMVisitor cmVisitor = new CMVisitor();
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
cmElementDeclaration);
cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
} catch (Throwable th) {
fail("Test failed :" + th.getClass().getName());
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
Aggregations