diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src-contentmodel')
78 files changed, 0 insertions, 10592 deletions
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMAnyElement.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMAnyElement.java deleted file mode 100644 index c3230ae481..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMAnyElement.java +++ /dev/null @@ -1,24 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMAnyElement interface - */ -public interface CMAnyElement extends CMContent { -/** - * getNamespaceURI method - * @return java.lang.String - */ -String getNamespaceURI(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMAttributeDeclaration.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMAttributeDeclaration.java deleted file mode 100644 index a85cbdef14..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMAttributeDeclaration.java +++ /dev/null @@ -1,52 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -import java.util.Enumeration; - -/** - * AttributeDeclaration interface - */ -public interface CMAttributeDeclaration extends CMNode { - public static final int OPTIONAL = 1; - public static final int REQUIRED = 2; - public static final int FIXED = 3; - public static final int PROHIBITED = 4; -/** - * getAttrName method - * @return java.lang.String - */ -String getAttrName(); -/** - * getAttrType method - * @return CMDataType - */ -CMDataType getAttrType(); -/** - * getDefaultValue method - * @return java.lang.String - * @deprecated -- to be replaced in future with additional CMDataType methods (currently found on CMDataTypeHelper) - */ -String getDefaultValue(); -/** - * getEnumAttr method - * @return java.util.Enumeration - * @deprecated -- to be replaced in future with additional CMDataType methods (currently found on CMDataTypeHelper) - */ -Enumeration getEnumAttr(); -/** - * getUsage method - * @return int - */ -int getUsage(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMContent.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMContent.java deleted file mode 100644 index 429bacd0cf..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMContent.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -public interface CMContent extends CMNode -{ -/** - * getMaxOccur method - * @return int - * - * If -1, it's UNBOUNDED. - */ -int getMaxOccur(); -/** - * getMinOccur method - * @return int - * - * If 0, it's OPTIONAL. - * If 1, it's REQUIRED. - */ -int getMinOccur(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDataType.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDataType.java deleted file mode 100644 index cdef96280c..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDataType.java +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMDataType - */ -public interface CMDataType extends CMNode { - - // todo... at some point we should remove these names to - // avoid exposing implementation details via the interfaces - // - static final String CDATA = "CDATA"; //$NON-NLS-1$ - static final String ID = "ID"; //$NON-NLS-1$ - static final String IDREF = "IDREF"; //$NON-NLS-1$ - static final String ENTITY = "ENTITY"; //$NON-NLS-1$ - static final String ENTITIES = "ENTITIES"; //$NON-NLS-1$ - static final String NOTATION = "NOTATION"; //$NON-NLS-1$ - static final String NMTOKEN = "NMTOKEN"; //$NON-NLS-1$ - static final String NMTOKENS = "NMTOKENS"; //$NON-NLS-1$ - static final String NUMBER = "NUMBER"; //$NON-NLS-1$ - static final String URI = "URI"; //$NON-NLS-1$ - static final String ENUM = "ENUM"; //$NON-NLS-1$ - - static final int IMPLIED_VALUE_NONE = 1; - static final int IMPLIED_VALUE_FIXED = 2; - static final int IMPLIED_VALUE_DEFAULT = 3; - -/** - * getTypeName method - * @return java.lang.String - */ -String getDataTypeName(); - -/** - * getImpliedValueKind method - * @return int - * - * Returns one of : - * IMPLIED_VALUE_NONE, IMPLIED_VALUE_FIXED, IMPLIED_VALUE_DEFAULT. - */ - -int getImpliedValueKind(); - -/** - * getTypeName method - * @return java.lang.String - * - * Returns the implied value or null if none exists. - */ -String getImpliedValue(); - -/** - * getTypeName method - * @return java.lang.String[] - * - */ -String[] getEnumeratedValues(); - -/** - * getTypeName method - * @return java.lang.String - * - * This method returns a suitable default value that can be used when an instance of the data type is created. - * This returns null of a suitable default is not available. - */ -String generateInstanceValue(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDocument.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDocument.java deleted file mode 100644 index 74ad25b193..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDocument.java +++ /dev/null @@ -1,38 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMDocument interface - */ -public interface CMDocument extends CMNode { -/** - * getElements method - * @return CMNamedNodeMap - * - * Returns CMNamedNodeMap of ElementDeclaration - */ -CMNamedNodeMap getElements(); -/** - * getEntities method - * @return CMNamedNodeMap - * - * Returns CMNamedNodeMap of EntityDeclaration - */ -CMNamedNodeMap getEntities(); -/** - * getNamespace method - * @return CMNamespace - */ -CMNamespace getNamespace(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDocumentation.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDocumentation.java deleted file mode 100644 index 477aaec397..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMDocumentation.java +++ /dev/null @@ -1,22 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMDocumentation interface - */ -public interface CMDocumentation extends CMNode { - public String getValue(); - public String getLanguage(); - public String getSource(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMElementDeclaration.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMElementDeclaration.java deleted file mode 100644 index bd780c5cdf..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMElementDeclaration.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMElementDeclaration interface - */ -public interface CMElementDeclaration extends CMContent { - - public static final int ANY = 0; - public static final int EMPTY = 1; - public static final int ELEMENT = 2; - public static final int MIXED = 3; - public static final int PCDATA = 4; - public static final int CDATA = 5; // todo... clarify this one -/** - * getAttributes method - * @return CMNamedNodeMap - * - * Returns CMNamedNodeMap of AttributeDeclaration - */ -CMNamedNodeMap getAttributes(); -/** - * getCMContent method - * @return CMContent - * - * Returns the root node of this element's content model. - * This can be an CMElementDeclaration or a CMGroup - */ -CMContent getContent(); -/** - * getContentType method - * @return int - * - * Returns one of : - * ANY, EMPTY, ELEMENT, MIXED, PCDATA, CDATA. - */ -public int getContentType(); -/** - * getElementName method - * @return java.lang.String - */ -String getElementName(); - -/** - * getDataType method - * @return java.lang.String - */ -CMDataType getDataType(); - -/** - * getLocalElements method - * @return CMNamedNodeMap - * - * Returns a list of locally defined elements. - */ -CMNamedNodeMap getLocalElements(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMEntityDeclaration.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMEntityDeclaration.java deleted file mode 100644 index 1e00265c1c..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMEntityDeclaration.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMEntityDeclaration interface - */ -public interface CMEntityDeclaration extends CMNode { - -/** - * getName method - * @return java.lang.String - */ -String getName(); -/** - * getValue method - * @return java.lang.String - */ -String getValue(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMGroup.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMGroup.java deleted file mode 100644 index d0248d984d..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMGroup.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMGroup interface - */ -public interface CMGroup extends CMContent { - - static final int ALL = 3; - static final int CHOICE = 2; - static final int SEQUENCE = 1; -/** - * getChildNodes method - * @return CMNodeList - * - * Returns child CMNodeList, which includes ElementDefinition or CMElement. - */ -CMNodeList getChildNodes(); - -/** - * getOperation method - * @return int - * - * Returns one of : - * ALONE (a), SEQUENCE (a,b), CHOICE (a|b), ALL (a&b). - */ -int getOperator(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNamedNodeMap.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNamedNodeMap.java deleted file mode 100644 index 260d07cbca..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNamedNodeMap.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; -import java.util.Iterator; -/** - * NamedCMNodeMap - */ -public interface CMNamedNodeMap { -/** - * getLength method - * @return int - */ -int getLength(); -/** - * getNamedItem method - * @return CMNode - * @param name java.lang.String - */ -CMNode getNamedItem(String name); -/** - * item method - * @return CMNode - * @param index int - */ -CMNode item(int index); - -/** - * - */ -Iterator iterator(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNamespace.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNamespace.java deleted file mode 100644 index eca84b84b6..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNamespace.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMNamespace interface - */ -public interface CMNamespace extends CMNode { - -/** - * getPrefix method - * @return java.lang.String - */ -String getPrefix(); -/** - * getURI method - * @return java.lang.String - */ -String getURI(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNode.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNode.java deleted file mode 100644 index af1e1e366b..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNode.java +++ /dev/null @@ -1,61 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMNode interface - */ -public interface CMNode { - - static final int ANY_ELEMENT = 1; - static final int ATTRIBUTE_DECLARATION = 2; - static final int DATA_TYPE = 3; - static final int DOCUMENT = 4; - static final int ELEMENT_DECLARATION = 5; - static final int ENTITY_DECLARATION = 6; - static final int GROUP = 7; - static final int NAME_SPACE = 8; - static final int DOCUMENTATION = 9; -/** - * getNodeName method - * @return java.lang.String - */ -String getNodeName(); -/** - * getNodeType method - * @return int - * - * Returns one of : - * - */ -int getNodeType(); - -/** - * supports method - * @return boolean - * - * Returns true if the CMNode supports a specified property - * - */ -boolean supports(String propertyName); - -/** - * getProperty method - * @return java.lang.Object - * - * Returns the object property desciped by the propertyName - * - */ -Object getProperty(String propertyName); //todo throw unsupported property exception - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNodeList.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNodeList.java deleted file mode 100644 index 46d9b339b1..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/CMNodeList.java +++ /dev/null @@ -1,31 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel; - -/** - * CMNodeList interface - */ -public interface CMNodeList { - -/** - * getLength method - * @return int - */ -int getLength(); -/** - * item method - * @return CMNode - * @param index int - */ -CMNode item(int index); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/ContentModelManager.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/ContentModelManager.java deleted file mode 100644 index df00d0e067..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/ContentModelManager.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel; - -import java.util.List; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.wst.xml.core.internal.contentmodel.factory.CMDocumentFactory; -import org.eclipse.wst.xml.core.internal.contentmodel.factory.CMDocumentFactoryRegistry; -import org.eclipse.wst.xml.core.internal.contentmodel.factory.CMDocumentFactoryRegistryReader; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileRegistry; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileRegistryReader; - - -/** - * ContentModelManager class - */ -public class ContentModelManager extends Plugin { - // private static InferredGrammarFactory inferredGrammarFactory; - private CMDocumentFactoryRegistry cmDocumentFactoryRegistry; - private AnnotationFileRegistry annotationFileRegistry; - - private static ContentModelManager instance; - - public ContentModelManager() { - super(); - } - - public static ContentModelManager getInstance() { - if (instance == null) { - instance = new ContentModelManager(); - } - return instance; - } - - public CMDocument createCMDocument(String uri, String resourceType) { - if (resourceType == null && uri != null) { - int index = uri.lastIndexOf("."); //$NON-NLS-1$ - resourceType = uri.substring(index + 1); - } - - if (resourceType != null) { - resourceType = resourceType.toLowerCase(); - } - CMDocumentFactory factory = getCMDocumentFactoryRegistry().getFactory(resourceType); - return factory != null ? factory.createCMDocument(uri) : null; - } - - - private CMDocumentFactoryRegistry getCMDocumentFactoryRegistry() { - if (cmDocumentFactoryRegistry == null) { - cmDocumentFactoryRegistry = new CMDocumentFactoryRegistry(); - new CMDocumentFactoryRegistryReader(cmDocumentFactoryRegistry).readRegistry(); - } - return cmDocumentFactoryRegistry; - } - - - public List getAnnotationFilesInfos(String publicId) { - return getAnnotationFileRegistry().getAnnotationFilesInfos(publicId); - } - - private AnnotationFileRegistry getAnnotationFileRegistry() { - if (annotationFileRegistry == null) { - annotationFileRegistry = new AnnotationFileRegistry(); - new AnnotationFileRegistryReader(annotationFileRegistry).readRegistry(); - } - return annotationFileRegistry; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/Annotation.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/Annotation.java deleted file mode 100644 index e9968a82ef..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/Annotation.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.annotation; - -import java.util.Hashtable; -import java.util.List; - -/** - * - */ -public class Annotation -{ - protected Hashtable hashtable = new Hashtable(); - - public Annotation() - { - } - - public void setSpec(String spec) - { - hashtable.put("spec", spec); //$NON-NLS-1$ - } - - public String getSpec() - { - return (String)hashtable.get("spec"); //$NON-NLS-1$ - } - - public void setProperty(String name, String value) - { - hashtable.put(name, value); - } - - public String getProperty(String propertyName) - { - return (String)hashtable.get(propertyName); - } - - public List getAttributeList() - { - return null; // todo - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/AnnotationMap.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/AnnotationMap.java deleted file mode 100644 index 5c94ac88af..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/annotation/AnnotationMap.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.annotation; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileInfo; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationFileParser; - - -/** - * AnnotationMap - */ -public class AnnotationMap { - protected List list = new Vector(); - protected Hashtable hashtable = new Hashtable(); - protected boolean isCaseSensitive = true; - - public AnnotationMap() { - } - - public void setCaseSensitive(boolean isCaseSensitive) { - this.isCaseSensitive = isCaseSensitive; - } - - public void addAnnotation(Annotation annotation) { - String spec = annotation.getSpec(); - if (spec != null) { - list.add(annotation); - StringTokenizer st = new StringTokenizer(spec, "[]|\t\n\r\f "); //$NON-NLS-1$ - while (st.hasMoreTokens()) { - String cmNodeSpec = st.nextToken(); - addAnnotationForCMNodeSpec(cmNodeSpec, annotation); - } - } - } - - protected void addAnnotationForCMNodeSpec(String cmNodeSpec, Annotation annotation) { - String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase(); - List list = (List) hashtable.get(key); - if (list == null) { - list = new Vector(); - - hashtable.put(key, list); - } - list.add(annotation); - } - - public String getProperty(String cmNodeSpec, String propertyName) { - String result = null; - String key = isCaseSensitive ? cmNodeSpec : cmNodeSpec.toLowerCase(); - List annotationList = (List) hashtable.get(key); - if (annotationList != null) { - for (Iterator i = annotationList.iterator(); i.hasNext();) { - Annotation annotation = (Annotation) i.next(); - result = annotation.getProperty(propertyName); - if (result != null) { - break; - } - } - } - return result; - } - - public String getProperty(CMNode cmNode, String propertyName) { - String result = null; - String cmNodeSpec = (String) cmNode.getProperty("spec"); //$NON-NLS-1$ - if (cmNodeSpec == null) { - cmNodeSpec = cmNode.getNodeName(); - } - if (cmNodeSpec != null) { - result = getProperty(cmNodeSpec, propertyName); - } - return result; - } - - public List getAnnotations() { - return list; - } - - public void load(String uri, String bundleId) throws Exception { - AnnotationFileParser parser = new AnnotationFileParser(); - AnnotationFileInfo fileInfo = new AnnotationFileInfo(uri, bundleId); - parser.parse(this, fileInfo); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMAnyElementImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMAnyElementImpl.java deleted file mode 100644 index 9913ae2605..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMAnyElementImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; - - -public class CMAnyElementImpl extends CMContentImpl implements CMAnyElement -{ - protected String namespaceURI; - - public CMAnyElementImpl(String namespaceURI) - { - this.namespaceURI = namespaceURI; - minOccur = -1; - } - - public static String computeNodeName(String uri) - { - return uri != null ? ("any#" + uri) : "any"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - // implements CMNode - // - public String getNodeName() - { - return computeNodeName(namespaceURI); - } - - public int getNodeType() - { - return ANY_ELEMENT; - } - - // implements CMAnyElement - // - public String getNamespaceURI() - { - return namespaceURI; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMAttributeDeclarationImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMAttributeDeclarationImpl.java deleted file mode 100644 index 60b2603d2e..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMAttributeDeclarationImpl.java +++ /dev/null @@ -1,123 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import java.util.Enumeration; -import java.util.List; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; - - -public class CMAttributeDeclarationImpl extends CMNodeImpl implements CMAttributeDeclaration -{ - protected CMDataType dataType; - protected String nodeName; - protected int usage; - protected CMDocument cmDocument; - protected boolean prefixQualification; - protected List xsiTypes; - - public CMAttributeDeclarationImpl(String nodeName, int usage) - { - this(nodeName, usage, null); - } - - public CMAttributeDeclarationImpl(String nodeName, int usage, CMDataType dataType) - { - this.nodeName = nodeName; - this.usage = usage; - this.dataType = dataType; - } - - public int getNodeType() - { - return CMNode.ATTRIBUTE_DECLARATION; - } - - public Object getProperty(String propertyName) - { - Object result = null; - if (propertyName.equals("CMDocument")) //$NON-NLS-1$ - { - result = cmDocument; - } - else if (propertyName.equals("XSITypes")) //$NON-NLS-1$ - { - result = xsiTypes; - } - else if (propertyName.equals("http://org.eclipse.wst/cm/properties/nsPrefixQualification")) //$NON-NLS-1$ - { - result = prefixQualification ? "qualified" : "unqualified"; //$NON-NLS-1$ //$NON-NLS-2$ - } - else - { - result = super.getProperty(propertyName); - } - return result; - } - - public void setPrefixQualification(boolean qualified) - { - prefixQualification = qualified; - } - - public void setXSITypes(List list) - { - xsiTypes = list; - } - - public void setCMDocument(CMDocument cmDocument) - { - this.cmDocument = cmDocument; - } - - public String getNodeName() - { - return nodeName; - } - - public String getAttrName() - { - return nodeName; - } - - public void setAttrType(CMDataType dataType) - { - this.dataType = dataType; - } - - public CMDataType getAttrType() - { - return dataType; - } - - public int getUsage() - { - return usage; - } - - /** @deprecated */ - public String getDefaultValue() - { - return ""; //$NON-NLS-1$ - } - - /** @deprecated */ - public Enumeration getEnumAttr() - { - return null; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMContentImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMContentImpl.java deleted file mode 100644 index 69e51df722..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMContentImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; - - -public abstract class CMContentImpl extends CMNodeImpl implements CMContent -{ - protected int minOccur = 0; - protected int maxOccur = -1; - - // implements CMContent - // - public int getMaxOccur() - { - return maxOccur; - } - - public int getMinOccur() - { - return minOccur; - } - - // implementation specific - // - public void setMaxOccur(int n) - { - maxOccur = n; - } - - public void setMinOccur(int n) - { - minOccur = n; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMDataTypeImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMDataTypeImpl.java deleted file mode 100644 index 6e6df245c3..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMDataTypeImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; - -public class CMDataTypeImpl extends CMNodeImpl implements CMDataType -{ - protected String dataTypeName; - protected String[] enumeratedValues; - protected String instanceValue; - - public CMDataTypeImpl(String dataTypeName, String instanceValue) - { - this.dataTypeName = dataTypeName; - this.instanceValue = instanceValue; - this.enumeratedValues = new String[0]; - } - - public CMDataTypeImpl(String dataTypeName, String[] enumeratedValues) - { - this.dataTypeName = dataTypeName; - this.enumeratedValues = enumeratedValues; - this.instanceValue = enumeratedValues[0]; - } - - - public int getNodeType() - { - return CMNode.DATA_TYPE; - } - - public String getNodeName() - { - return getDataTypeName(); - } - - public String getDataTypeName() - { - return dataTypeName; - } - - public int getImpliedValueKind() - { - return IMPLIED_VALUE_NONE; - } - - public String getImpliedValue() - { - return null; - } - - public String[] getEnumeratedValues() - { - return enumeratedValues; - } - - public String generateInstanceValue() - { - return instanceValue; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMDocumentImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMDocumentImpl.java deleted file mode 100644 index 933fcb8812..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMDocumentImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamespace; - - -public class CMDocumentImpl extends CMNodeImpl implements CMDocument -{ - protected String targetNamespace; - protected CMNamedNodeMapImpl elements = new CMNamedNodeMapImpl(); - protected CMNamedNodeMapImpl localElementPool; - protected CMNamedNodeMapImpl anyElements; - - public CMDocumentImpl(String targetNamespace) - { - this.targetNamespace = targetNamespace; - } - - public int getNodeType() - { - return DOCUMENT; - } - - public String getNodeName() - { - return ""; //$NON-NLS-1$ - } - - public Object getProperty(String propertyName) - { - Object result = null; - if (propertyName.equals("http://org.eclipse.wst/cm/properties/targetNamespaceURI")) //$NON-NLS-1$ - { - result = targetNamespace; - } - else - { - result = super.getProperty(propertyName); - } - return result; - } - - public CMNamedNodeMap getElements() - { - return elements; - } - - public CMNamedNodeMapImpl getAnyElements() - { - if (anyElements == null) - { - anyElements = new CMNamedNodeMapImpl(); - } - return anyElements; - } - - public CMNamedNodeMapImpl getLocalElementPool() - { - if (localElementPool == null) - { - localElementPool = new CMNamedNodeMapImpl(); - } - return localElementPool; - } - - public CMNamedNodeMap getEntities() - { - return new CMNamedNodeMapImpl(); - } - - public CMNamespace getNamespace() - { - return null; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMElementDeclarationImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMElementDeclarationImpl.java deleted file mode 100644 index 9bdf866ed9..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMElementDeclarationImpl.java +++ /dev/null @@ -1,121 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; - - -public class CMElementDeclarationImpl extends CMContentImpl implements CMElementDeclaration -{ - protected String name; - protected CMDocument cmDocument; - protected CMNamedNodeMapImpl attributeMap = new CMNamedNodeMapImpl(); - protected CMNamedNodeMapImpl localElementMap = new CMNamedNodeMapImpl(); - protected CMContent content; - protected CMDataType dataType; - protected boolean isLocal; - - public CMElementDeclarationImpl(CMDocument cmDocument, String name) - { - this.cmDocument = cmDocument; - this.name = name; - } - - // implements CMNode - // - public String getNodeName() - { - return name; - } - - public int getNodeType() - { - return ELEMENT_DECLARATION; - } - - public Object getProperty(String propertyName) - { - Object result = null; - if (propertyName.equals("http://org.eclipse.wst/cm/properties/nsPrefixQualification")) //$NON-NLS-1$ - { - result = isLocal ? "unqualified" : "qualified"; //$NON-NLS-1$ //$NON-NLS-2$ - } - else if (propertyName.equals("CMDocument")) //$NON-NLS-1$ - { - result = cmDocument; - } - else - { - result = super.getProperty(propertyName); - } - return result; - } - - // implements CMElementDeclaration - // - public CMNamedNodeMap getAttributes() - { - return attributeMap; - } - - public CMContent getContent() - { - return content; - } - - public int getContentType() - { - return MIXED; - } - - public String getElementName() - { - return name; - } - - public CMDataType getDataType() - { - return dataType; - } - - public CMNamedNodeMap getLocalElements() - { - return localElementMap; - } - - // - // - public void setContent(CMContent cmContent) - { - content = cmContent; - } - - public void setDataType(CMDataType cmDataType) - { - dataType = cmDataType; - } - - public CMNamedNodeMapImpl getAttributeMap() - { - return attributeMap; - } - - public void setLocal(boolean isLocal) - { - this.isLocal = isLocal; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMEntityDeclarationImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMEntityDeclarationImpl.java deleted file mode 100644 index af0fcc3a82..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMEntityDeclarationImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration; - -public class CMEntityDeclarationImpl extends CMNodeImpl implements CMEntityDeclaration -{ - protected String name; - protected String value; - - public CMEntityDeclarationImpl(String name, String value) - { - this.name = name; - this.value = value; - } - - public int getNodeType() - { - return ENTITY_DECLARATION; - } - - public String getNodeName() - { - return name; - } - - public String getName() - { - return name; - } - - public String getValue() - { - return value; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMGroupImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMGroupImpl.java deleted file mode 100644 index 8335e1f4c0..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMGroupImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; - -public class CMGroupImpl extends CMContentImpl implements CMGroup -{ - protected CMNodeList nodeList; - protected int operator; - - public CMGroupImpl(CMNodeList nodeList, int operator) - { - this.nodeList = nodeList; - this.operator = operator; - } - - public int getNodeType() - { - return GROUP; - } - - public CMNodeList getChildNodes() - { - return nodeList; - } - - public int getOperator() - { - return operator; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNamedNodeMapImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNamedNodeMapImpl.java deleted file mode 100644 index cafef41889..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNamedNodeMapImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Iterator; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; - - - -public class CMNamedNodeMapImpl implements CMNamedNodeMap -{ - public static CMNamedNodeMapImpl EMPTY_NAMED_NODE_MAP = new CMNamedNodeMapImpl(); - protected Hashtable table = new Hashtable(); - - /** - * CMNamedNodeMapImpl constructor comment. - */ - public CMNamedNodeMapImpl() - { - super(); - } - - /** - * getLength method - * @return int - */ - public int getLength() - { - return table.size(); - } - - /** - * getNamedItem method - * @return CMNode - * @param name java.lang.String - */ - public CMNode getNamedItem(String name) - { - return (CMNode)table.get(name); - } - - /** - * item method - * @return CMNode - * @param index int - */ - public CMNode item(int index) - { - CMNode result = null; - int size = table.size(); - if (index < size) - { - Enumeration values = table.elements(); - for(int i = 0; i <= index; i++) - { - result = (CMNode)values.nextElement(); - } - } - return result; - } - - public Hashtable getHashtable() - { - return table; - } - - public Iterator iterator() - { - return table.values().iterator(); - } - - public void put(CMNode cmNode) - { - table.put(cmNode.getNodeName(), cmNode); - } -} - diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNodeImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNodeImpl.java deleted file mode 100644 index 5c63598deb..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNodeImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; - - -public abstract class CMNodeImpl implements CMNode -{ - protected boolean isInferred = false; - - public String getNodeName() - { - return ""; //$NON-NLS-1$ - } - - public boolean supports(String propertyName) - { - return false; - } - - public Object getProperty(String propertyName) - { - Object result = null; - if ("isInferred".equals(propertyName)) //$NON-NLS-1$ - { - result = isInferred ? Boolean.TRUE : Boolean.FALSE; - } - return result; - } - - public void setInferred(boolean isInferred) - { - this.isInferred = isInferred; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNodeListImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNodeListImpl.java deleted file mode 100644 index bc9b6b9f04..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/basic/CMNodeListImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.basic; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; - - -public class CMNodeListImpl implements CMNodeList -{ - public static CMNodeListImpl EMPTY_NODE_LIST = new CMNodeListImpl(Collections.EMPTY_LIST); - protected List list; - - public CMNodeListImpl() - { - this(new Vector()); - } - - public CMNodeListImpl(List list) - { - this.list = list; - } - - /** - * getLength method - * @return int - */ - public int getLength() - { - return list.size(); - } - /** - * item method - * @return CMNode - * @param index int - */ - public CMNode item(int index) - { - return (CMNode)list.get(index); - } - - public List getList() - { - return list; - } - - public Iterator iterator() - { - return list.iterator(); - } - - public boolean contains(CMNode cmNode) - { - return list.contains(cmNode); - } - - public void add(CMNode cmNode) - { - list.add(cmNode); - } -} - diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactory.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactory.java deleted file mode 100644 index 39b540b5ef..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactory.java +++ /dev/null @@ -1,22 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.factory; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; - -// this interface is used to build a grammar document given a local file name -// -public interface CMDocumentFactory -{ - public CMDocument createCMDocument(String uri); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryDescriptor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryDescriptor.java deleted file mode 100644 index c509802bce..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryDescriptor.java +++ /dev/null @@ -1,44 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.factory; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.wst.xml.core.internal.Logger; - - -public class CMDocumentFactoryDescriptor -{ - private IConfigurationElement fElement; - private CMDocumentFactory factory; - - public CMDocumentFactoryDescriptor(IConfigurationElement element) - { - this.fElement = element; - } - - public CMDocumentFactory getFactory() - { - if (factory == null) - { - try - { - factory = (CMDocumentFactory) fElement.createExecutableExtension("class"); //$NON-NLS-1$ - } - catch (Exception e) - { - Logger.logException("Exception loading CMDocumentFactory",e); //$NON-NLS-1$ - } - } - return factory; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryRegistry.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryRegistry.java deleted file mode 100644 index 3f2db4404b..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryRegistry.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.factory; - -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; - -/** - * - * - */ -public class CMDocumentFactoryRegistry -{ - protected static CMDocumentFactoryRegistry instance; - - private static String DEFAULT_RESOURCE_TYPE = "*"; //$NON-NLS-1$ - - protected Map resourceTypeMap = new HashMap(); - - protected Vector documentBuilderList = new Vector(); - - public CMDocumentFactoryRegistry() { - } - - public void putFactory(String resourceType, CMDocumentFactoryDescriptor factoryDescriptor) { - resourceTypeMap.put(resourceType, factoryDescriptor); - } - - public CMDocumentFactory getFactory(String resourceType) { - CMDocumentFactoryDescriptor factoryDescriptor = null; - if (resourceType != null) { - factoryDescriptor = (CMDocumentFactoryDescriptor) resourceTypeMap.get(resourceType); - } - if (factoryDescriptor == null) { - // (dmw) issue: a default type of '*' means what? registered as - // '*' is the way this works now. is that the intent? Or should it - // mean registered as any other type? - factoryDescriptor = (CMDocumentFactoryDescriptor) resourceTypeMap.get(DEFAULT_RESOURCE_TYPE); - } - return factoryDescriptor != null ? factoryDescriptor.getFactory() : null; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryRegistryReader.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryRegistryReader.java deleted file mode 100644 index 87e2b78041..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/factory/CMDocumentFactoryRegistryReader.java +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.factory; - -import java.util.StringTokenizer; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.xml.core.internal.Logger; - - - - -public class CMDocumentFactoryRegistryReader -{ - protected static final String EXTENSION_POINT_ID = "documentFactories"; //$NON-NLS-1$ - protected static final String TAG_NAME = "factory"; //$NON-NLS-1$ - protected static final String ATT_CLASS = "class"; //$NON-NLS-1$ - protected static final String ATT_TYPE = "type"; //$NON-NLS-1$ - protected String pluginId, extensionPointId; - - protected CMDocumentFactoryRegistry registry; - - public CMDocumentFactoryRegistryReader(CMDocumentFactoryRegistry registry) - { - this.registry = registry; - } - - public void readRegistry() - { - String bundleid = "org.eclipse.wst.xml.core"; //$NON-NLS-1$ - IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(bundleid, EXTENSION_POINT_ID); - if (point != null) - { - IConfigurationElement[] elements = point.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) - { - readElement(elements[i]); - } - } - } - - protected void readElement(IConfigurationElement element) - { - if (element.getName().equals(TAG_NAME)) - { - String factoryClass = element.getAttribute(ATT_CLASS); - String filenameExtensions = element.getAttribute(ATT_TYPE); - if (factoryClass != null && filenameExtensions != null) - { - try - { - CMDocumentFactoryDescriptor descriptor = new CMDocumentFactoryDescriptor(element); - for (StringTokenizer st = new StringTokenizer(filenameExtensions, ","); st.hasMoreTokens(); ) //$NON-NLS-1$ - { - String token = st.nextToken().trim(); - registry.putFactory(token, descriptor); - } - } - catch (Exception e) - { - Logger.logException(e); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileInfo.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileInfo.java deleted file mode 100644 index 7eab4f2820..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileInfo.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation; - -/** - * Contains information about annotation files - */ -public class AnnotationFileInfo { - private String fAnnotationFileLocation; - private String fBundleId; - - public AnnotationFileInfo(String annotationFileLocation, String bundleId) { - fAnnotationFileLocation = annotationFileLocation; - fBundleId = bundleId; - } - - /** - * Get the location of the annotation file as originally specified. - * - * @return String - */ - public String getAnnotationFileLocation() { - return fAnnotationFileLocation; - } - - /** - * Get the bundle id where the annotation file is located. - * - * @return String - */ - public String getBundleId() { - return fBundleId; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileParser.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileParser.java deleted file mode 100644 index 11279e99e5..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileParser.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.xml.core.internal.Logger; -import org.eclipse.wst.xml.core.internal.contentmodel.annotation.Annotation; -import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - - -/** - * - */ -public class AnnotationFileParser { - public static final String TAG_ID_ANNOTATIONS = "abstractGrammarAnnotations"; //$NON-NLS-1$ - public static final String TAG_ID_ANNOTATION = "annotation"; //$NON-NLS-1$ - public static final String TAG_ID_PROPERTY = "property"; //$NON-NLS-1$ - - /** - * This method is called to parse an annotation file and store the - * contents into an annotationMap - */ - private void parse(AnnotationMap annotationMap, InputStream input, AnnotationFileInfo fileInfo) throws Exception { - // move to Xerces-2.... add 'contextClassLoader' stuff - ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader(); - try { - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(true); - SAXParser parser = factory.newSAXParser(); - parser.parse(new InputSource(input), new AnnotationMapContentHandler(annotationMap, fileInfo)); - } - finally { - Thread.currentThread().setContextClassLoader(prevClassLoader); - } - } - - /** - * This method is called to parse an annotation file and store the - * contents into an annotationMap - */ - public void parse(AnnotationMap map, AnnotationFileInfo fileInfo) throws Exception { - InputStream inputStream = null; - try { - URL url = Platform.find(Platform.getBundle(fileInfo.getBundleId()), Path.fromOSString(fileInfo.getAnnotationFileLocation())); - if (url != null) { - inputStream = url.openStream(); - parse(map, inputStream, fileInfo); - } - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - throw (e); - } - finally { - try { - if (inputStream != null) { - inputStream.close(); - } - } - catch (IOException e) { - } - } - } - - protected class AnnotationMapContentHandler extends DefaultHandler { - private AnnotationMap annotationMap; - private Annotation currentAnnotation; - private String currentPropertyName; - private StringBuffer propertyValueBuffer; - private ResourceBundle resourceBundle; - private AnnotationFileInfo fFileInfo; - - public AnnotationMapContentHandler(AnnotationMap annotationMap, AnnotationFileInfo fileInfo) { - this.annotationMap = annotationMap; - this.fFileInfo = fileInfo; - } - - private URL generatePropertiesFileURL(AnnotationFileInfo fileInfo, String propertiesLocation) { - URL propertiesURL = null; - - // prepend $nl$ variable to location - IPath annotationPath = Path.fromOSString("$nl$/" + fileInfo.getAnnotationFileLocation()); //$NON-NLS-1$ - // remove the annotation.xml file - IPath annotationFolder = annotationPath.removeLastSegments(1); - // append location of propertiles file - IPath propertiesFile = annotationFolder.append(propertiesLocation); - // append .properties extension if needed - if (propertiesFile.getFileExtension() == null) - propertiesFile = propertiesFile.addFileExtension("properties"); //$NON-NLS-1$ - // create a URL out of the properties file location - propertiesURL = Platform.find(Platform.getBundle(fileInfo.getBundleId()), propertiesFile); - return propertiesURL; - } - - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - propertyValueBuffer = new StringBuffer(); - if (localName.equals(TAG_ID_ANNOTATIONS)) { - int attributesLength = attributes.getLength(); - for (int i = 0; i < attributesLength; i++) { - String attributeName = attributes.getLocalName(i); - String attributeValue = attributes.getValue(i); - if (attributeName.equals("propertiesLocation")) //$NON-NLS-1$ - { - URL bundleURL = generatePropertiesFileURL(fFileInfo, attributeValue); - if (bundleURL != null) { - InputStream bundleStream = null; - try { - bundleStream = bundleURL.openStream(); - resourceBundle = new PropertyResourceBundle(bundleStream); - } - catch (IOException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - finally { - try { - if (bundleStream != null) - bundleStream.close(); - } - catch (IOException x) { - Logger.log(Logger.WARNING_DEBUG, x.getMessage(), x); - } - } - } - } - else if (attributeName.equals("caseSensitive")) //$NON-NLS-1$ - { - if (attributeValue.trim().equals("false")) //$NON-NLS-1$ - { - annotationMap.setCaseSensitive(false); - } - } - } - } - else if (localName.equals(TAG_ID_ANNOTATION)) { - currentAnnotation = null; - String specValue = attributes.getValue("spec"); //$NON-NLS-1$ - if (specValue != null) { - currentAnnotation = new Annotation(); - currentAnnotation.setSpec(specValue); - } - annotationMap.addAnnotation(currentAnnotation); - } - else if (localName.equals(TAG_ID_PROPERTY)) { - if (currentAnnotation != null) { - currentPropertyName = attributes.getValue("name"); //$NON-NLS-1$ - } - } - } - - public void endElement(String uri, String localName, String qName) throws SAXException { - if (currentPropertyName != null && currentAnnotation != null) { - String propertyValue = propertyValueBuffer.toString(); - if (propertyValue != null) { - if (propertyValue.startsWith("%") && resourceBundle != null) //$NON-NLS-1$ - { - try { - propertyValue = resourceBundle.getString(propertyValue.substring(1)); - } - catch (Exception e) { - // ignore any exception that occurs while trying - // to fetch a resource - } - } - currentAnnotation.setProperty(currentPropertyName, propertyValue); - } - } - - if (localName.equals(TAG_ID_ANNOTATION)) { - currentAnnotation = null; - } - else if (localName.equals(TAG_ID_PROPERTY)) { - currentPropertyName = null; - } - } - - public void characters(char[] ch, int start, int length) { - if (currentPropertyName != null && currentAnnotation != null) { - propertyValueBuffer.append(ch, start, length); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistry.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistry.java deleted file mode 100644 index e2d455bad5..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistry.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * This class is used to associate one or more annotation files with a grammar - * file. - * - */ -public class AnnotationFileRegistry { - private Map map = new HashMap(); - - public AnnotationFileRegistry() { - new AnnotationFileRegistryReader(this).readRegistry(); - } - - public synchronized List getAnnotationFilesInfos(String publicId) { - List theList = (List) map.get(publicId); - return theList != null ? theList : new ArrayList(); - } - - public synchronized void addAnnotationFile(String publicId, AnnotationFileInfo fileInfo) { - List fileInfos = (List) map.get(publicId); - if (fileInfos == null) { - fileInfos = new ArrayList(); - map.put(publicId, fileInfos); - } - fileInfos.add(fileInfo); - } - - public synchronized void removeAnnotationFile(String publicId, AnnotationFileInfo fileInfo) { - List fileInfos = (List) map.get(publicId); - if (fileInfos != null) { - fileInfos.remove(fileInfo); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistryReader.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistryReader.java deleted file mode 100644 index 896acd6c86..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationFileRegistryReader.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.xml.core.internal.Logger; - - -/** - * This class reads the plugin manifests and adds each specified gramamr - * annotation file with the AnnotationProvider - */ -public class AnnotationFileRegistryReader { - protected static final String EXTENSION_POINT_ID = "annotationFiles"; //$NON-NLS-1$ - protected static final String TAG_NAME = "annotationFile"; //$NON-NLS-1$ - protected static final String ATT_PUBLIC_ID = "publicId"; //$NON-NLS-1$ - protected static final String ATT_LOCATION = "location"; //$NON-NLS-1$ - - private AnnotationFileRegistry annotationFileRegistry; - - public AnnotationFileRegistryReader(AnnotationFileRegistry annotationFileRegistry) { - this.annotationFileRegistry = annotationFileRegistry; - } - - /** - * read from plugin registry and parse it. - */ - public void readRegistry() { - IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); - String pluginId = "org.eclipse.wst.xml.core"; //$NON-NLS-1$ - IExtensionPoint point = extensionRegistry.getExtensionPoint(pluginId, EXTENSION_POINT_ID); - if (point != null) { - IConfigurationElement[] elements = point.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - readElement(elements[i]); - } - } - } - - /** - * readElement() - parse and deal with an extension like: - * - * <extension - * point="org.eclipse.wst.xml.core.internal.contentmodel.util_implementation"> - * <util_implementation class = - * corg.eclipse.wst.baseutil.CMUtilImplementationImpl /> </extension> - */ - protected void readElement(IConfigurationElement element) { - if (element.getName().equals(TAG_NAME)) { - String publicId = element.getAttribute(ATT_PUBLIC_ID); - String location = element.getAttribute(ATT_LOCATION); - if (publicId != null && location != null) { - try { - String bundleId = element.getNamespace(); - AnnotationFileInfo fileInfo = new AnnotationFileInfo(location, bundleId); - annotationFileRegistry.addAnnotationFile(publicId, fileInfo); - } - catch (Exception e) { - Logger.logException("problem adding annotation file " + location, e); //$NON-NLS-1$ - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationUtility.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationUtility.java deleted file mode 100644 index fe1634bcc0..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/AnnotationUtility.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.xml.core.internal.Logger; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager; -import org.eclipse.wst.xml.core.internal.contentmodel.annotation.AnnotationMap; - - -/** - * - */ -public class AnnotationUtility { - public static void loadAnnotationsForGrammar(String publicId, CMDocument cmDocument) { - List annotationFiles = ContentModelManager.getInstance().getAnnotationFilesInfos(publicId); - AnnotationMap map = (AnnotationMap) cmDocument.getProperty("annotationMap"); //$NON-NLS-1$ - if (map != null) { - for (Iterator i = annotationFiles.iterator(); i.hasNext();) { - try { - AnnotationFileInfo annotationFileInfo = (AnnotationFileInfo) i.next(); - AnnotationFileParser parser = new AnnotationFileParser(); - parser.parse(map, annotationFileInfo); - } - catch (Exception e) { - Logger.logException(e); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/ResourceBundleHelper.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/ResourceBundleHelper.java deleted file mode 100644 index 687041919d..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/annotation/ResourceBundleHelper.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation; - -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Locale; -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.Platform; - - -public class ResourceBundleHelper -{ - public static ResourceBundle getResourceBundle(String resourceURI, Locale targetLocale) throws Exception - { - // try to load bundle from the location specified in the resourceURI - // we make the assumption that the resourceURI points to the local file system - - int index = resourceURI.lastIndexOf("/"); //$NON-NLS-1$ - if (index == -1) - { - throw new Exception("Invalid resourceURI"); //$NON-NLS-1$ - } - - // Below we set 'resourceDirectory' so that it ends with a '/'. - // Here's an excerpt from the ClassLoader Javadoc ... - // Any URL that ends with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed - // to refer to a JAR file which will be opened as needed. - // - String resourceDirectory = resourceURI.substring(0, index + 1); - String resourceBundleName = resourceURI.substring(index + 1); - - // create a class loader with a class path that points to the resource bundle's location - // - URL[] classpath = new URL[1]; - classpath[0] = Platform.resolve(new URL(resourceDirectory)); - ClassLoader resourceLoader = new URLClassLoader(classpath, null); - - return ResourceBundle.getBundle(resourceBundleName, targetLocale, resourceLoader); - } - - public static ResourceBundle getResourceBundle(String resourceURI) throws Exception - { - return getResourceBundle(resourceURI, Locale.getDefault()); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/InferredGrammarFactory.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/InferredGrammarFactory.java deleted file mode 100644 index 59bcfc740c..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/InferredGrammarFactory.java +++ /dev/null @@ -1,156 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.modelqueryimpl; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMAnyElementImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMAttributeDeclarationImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMDocumentImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMElementDeclarationImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNodeListImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; - - - -public class InferredGrammarFactory -{ - public InferredGrammarFactory() - { - } - - public CMDocument createCMDocument(String uri) - { - CMDocumentImpl cmdocument =new CMDocumentImpl(uri); - cmdocument.setInferred(true); - return cmdocument; - } - - public CMElementDeclaration createCMElementDeclaration(CMDocument cmDocument, Element element, boolean isLocal) - { - String localName = element.getLocalName(); - CMDocumentImpl cmDocumentImpl = (CMDocumentImpl)cmDocument; - - CMNamedNodeMapImpl elementMap = isLocal ? - (CMNamedNodeMapImpl)cmDocumentImpl.getLocalElementPool() : - (CMNamedNodeMapImpl)cmDocumentImpl.getElements(); - - CMElementDeclarationImpl ed = (CMElementDeclarationImpl)elementMap.getNamedItem(localName); - if (ed == null) - { - //System.out.println("create ed " + localName); - ed = new CMElementDeclarationImpl(cmDocument, localName); - ed.setInferred(true); - ed.setLocal(isLocal); - ed.setMaxOccur(1); - CMGroupImpl group = new CMGroupImpl(new CMNodeListImpl(), CMGroup.CHOICE); - group.setInferred(true); - group.setMinOccur(0); - group.setMaxOccur(-1); - ed.setContent(group); - elementMap.put(ed); - } - - // lookup or create the attributes - // - NamedNodeMap attributeMap = element.getAttributes(); - int attributeMapLength = attributeMap.getLength(); - for (int i = 0; i < attributeMapLength; i++) - { - Attr attr = (Attr)attributeMap.item(i); - CMAttributeDeclarationImpl ad = (CMAttributeDeclarationImpl)ed.getAttributeMap().getNamedItem(attr.getNodeName()); - if (ad == null) - { - // todo... use an attribute pool to be more efficient? - ad = new CMAttributeDeclarationImpl(attr.getNodeName(), CMAttributeDeclaration.OPTIONAL); - ad.setInferred(true); - ed.getAttributeMap().put(ad); - } - } - return ed; - } - - public void createCMContent(CMDocument parentCMDocument, CMElementDeclaration parentEd, CMDocument childCMDocument, CMElementDeclaration childEd, boolean isLocal, String uri) - { - // add element to the parent's content - // consider all content to be of the form (A | B | C)* - // - CMGroupImpl group = (CMGroupImpl)parentEd.getContent(); - CMNodeListImpl groupChildNodeList = (CMNodeListImpl)group.getChildNodes(); - - if (parentCMDocument == childCMDocument) - { - if (!groupChildNodeList.contains(childEd)) - { - groupChildNodeList.add(childEd); - } - if (isLocal) - { - CMNamedNodeMapImpl localElementMap = (CMNamedNodeMapImpl)parentEd.getLocalElements(); - localElementMap.put(childEd); - } - } - else - { - CMAnyElement cmAnyElement = lookupOrCreateCMAnyElement((CMDocumentImpl)parentCMDocument, uri); - if (!groupChildNodeList.contains(cmAnyElement)) - { - groupChildNodeList.add(cmAnyElement); - } - } - } - - protected CMAnyElement lookupOrCreateCMAnyElement(CMDocumentImpl parentCMDocument, String uri) - { - CMNamedNodeMapImpl anyElementMap = parentCMDocument.getAnyElements(); - CMAnyElementImpl anyElement = (CMAnyElementImpl)anyElementMap.getNamedItem(CMAnyElementImpl.computeNodeName(uri)); - if (anyElement == null) - { - //System.out.println("create anyElement " + uri); - anyElement = new CMAnyElementImpl(uri); - anyElement.setInferred(true); - anyElementMap.put(anyElement); - } - return anyElement; - } - - - public void debugPrint(Collection collection) - { - for (Iterator iter = collection.iterator(); iter.hasNext(); ) - { - CMDocument cmDocument = (CMDocument)iter.next(); - System.out.println("-----------------------------------------------"); //$NON-NLS-1$ - System.out.println("cmDocument (" + cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI") +")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - CMNamedNodeMapImpl elementMap = (CMNamedNodeMapImpl)cmDocument.getElements(); - int size = elementMap.getLength(); - for (int i = 0; i < size; i++) - { - CMElementDeclaration ed = (CMElementDeclaration)elementMap.item(i); - CMDescriptionBuilder builder = new CMDescriptionBuilder(); - System.out.println(" ELEMENT " + ed.getNodeName() + " = " + builder.buildDescription(ed)); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionDescriptor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionDescriptor.java deleted file mode 100644 index 93e43a1572..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionDescriptor.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.modelqueryimpl; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension; - -; -/** - * Describes an extension to the <code>modelQueryExtension</code> extension - * point. - * - */ -public class ModelQueryExtensionDescriptor -{ - private static final String CONTENT_TYPE_ATTRIBUTE = "contentType"; //$NON-NLS-1$ - private static final String NAMESPACE_ATTRIBUTE = "namespace"; //$NON-NLS-1$ - private static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ - private IConfigurationElement configuration; - private String contentTypeId; - private String namespace; - private ModelQueryExtension extension; - - public ModelQueryExtensionDescriptor(IConfigurationElement element) - { - configuration = element; - } - - public ModelQueryExtension createModelQueryExtension() throws CoreException - { - if (extension == null) - { - extension = (ModelQueryExtension) configuration.createExecutableExtension(CLASS_ATTRIBUTE); - } - return extension; - } - - public String getContentTypeId() - { - if (contentTypeId == null) - { - contentTypeId = configuration.getAttribute(CONTENT_TYPE_ATTRIBUTE); - } - return contentTypeId; - } - - public String getNamespace() - { - if (namespace == null) - { - namespace = configuration.getAttribute(NAMESPACE_ATTRIBUTE); - } - return namespace; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionManagerImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionManagerImpl.java deleted file mode 100644 index 81136f073d..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionManagerImpl.java +++ /dev/null @@ -1,111 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.modelqueryimpl; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtensionManager; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - - -public class ModelQueryExtensionManagerImpl implements ModelQueryExtensionManager -{ - protected ModelQueryExtensionRegistry modelQueryExtensionRegistry = new ModelQueryExtensionRegistry(); - - public List getDataTypeValues(Element element, CMNode cmNode) - { - List list = new ArrayList(); - String contentTypeId = getContentTypeId(element); - String namespace = getNamespace(cmNode); - String name = cmNode.getNodeName(); - - for (Iterator i = modelQueryExtensionRegistry.getApplicableExtensions(contentTypeId, namespace).iterator(); i.hasNext();) - { - ModelQueryExtension extension = (ModelQueryExtension)i.next(); - String[] values = null; - if (cmNode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) - { - values = extension.getAttributeValues(element, namespace, name); - } - else - { - values = extension.getElementValues(element, namespace, name); - } - if (values != null) - { - list.addAll(Arrays.asList(values)); - } - } - return list; - } - - public void filterAvailableElementContent(List cmnodes, Element element, CMElementDeclaration ed) - { - String contentTypeId = getContentTypeId(element); - String parentNamespace = element.getNamespaceURI(); - - List modelQueryExtensions = modelQueryExtensionRegistry.getApplicableExtensions(contentTypeId, parentNamespace); - - for (Iterator j = cmnodes.iterator(); j.hasNext(); ) - { - CMNode cmNode = (CMNode)j.next(); - String namespace = getNamespace(cmNode); - String name = cmNode.getNodeName(); - - boolean include = true; - for(int k = 0; k < modelQueryExtensions.size() && include; k++) { - { - ModelQueryExtension extension = (ModelQueryExtension)modelQueryExtensions.get(k); - include = extension.isApplicableChildElement(element, namespace, name); - if (!include) - { - // remove the cmNode from the list - j.remove(); - } - } - } - } - } - - private String getNamespace(CMNode cmNode) - { - String namespace = null; - CMDocument cmDocument = (CMDocument)cmNode.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - namespace = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - } - return namespace; - } - - private String getContentTypeId(Node node) - { - String contentTypeId = "org.eclipse.core.runtime.xml"; //$NON-NLS-1$ - if (node instanceof IDOMNode) - { - IDOMNode domNode = (IDOMNode) node; - contentTypeId = domNode.getModel().getContentTypeIdentifier(); - } - return contentTypeId; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionRegistry.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionRegistry.java deleted file mode 100644 index 63261d3b5c..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/modelqueryimpl/ModelQueryExtensionRegistry.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.modelqueryimpl; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.xml.core.internal.Logger; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtension; - -public class ModelQueryExtensionRegistry -{ - protected static final String EXTENSION_POINT_ID = "modelQueryExtensions"; //$NON-NLS-1$ - protected static final String TAG_NAME = "modelQueryExtension"; //$NON-NLS-1$ - private List descriptors; - - public List getApplicableExtensions(String contentTypeId, String namespace) - { - List list = new ArrayList(); - if (contentTypeId != null) - { - ensureExtensionsLoaded(); - for (Iterator i = descriptors.iterator(); i.hasNext();) - { - ModelQueryExtensionDescriptor descriptor = (ModelQueryExtensionDescriptor) i.next(); - if (contentTypeId.equals(descriptor.getContentTypeId())) - { - if (descriptor.getNamespace() == null || descriptor.getNamespace().equals(namespace)) - { - try - { - ModelQueryExtension extension = descriptor.createModelQueryExtension(); - list.add(extension); - } - catch (CoreException e) { - Logger.logException("problem creating model query extension", e); //$NON-NLS-1$ - } - } - } - } - } - return list; - } - - /* - * TODO : consider providing a non-plugin means add/remove extensions - * - public void addExtension(ModelQueryExtension extension) - { - } - - public void removeExtension(ModelQueryExtensionDeprecated extension) - { - }*/ - - /** - * Reads all extensions. - * <p> - * This method can be called more than once in order to reload from a changed - * extension registry. - * </p> - */ - private synchronized void reloadExtensions() - { - descriptors = new ArrayList(); - String bundleid = "org.eclipse.wst.xml.core"; //$NON-NLS-1$ - IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(bundleid, EXTENSION_POINT_ID); - for (int i = 0; i < elements.length; i++) - { - ModelQueryExtensionDescriptor descriptor = new ModelQueryExtensionDescriptor(elements[i]); - descriptors.add(descriptor); - } - } - - /** - * Ensures the extensions have been loaded at least once. - */ - private void ensureExtensionsLoaded() - { - if (descriptors == null) - { - reloadExtensions(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/CMDataTypeValueHelper.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/CMDataTypeValueHelper.java deleted file mode 100644 index f027bf7839..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/CMDataTypeValueHelper.java +++ /dev/null @@ -1,161 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.util; - -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable; - - -public class CMDataTypeValueHelper -{ - protected int idCount = 0; - - - public String getValue(CMAttributeDeclaration ad, NamespaceTable namespaceTable) - { - String value = null; - - if (isXSIType(ad)) - { - List list = getQualifiedXSITypes(ad, namespaceTable); - value = list.size() > 0 ? (String)list.get(0) : null; - } - - // shameless hack - // - if (value == null) - { - if (ad.getAttrName().equals("xml:lang")) //$NON-NLS-1$ - { - value = "EN"; //$NON-NLS-1$ - } - } - - if (value == null) - { - CMDataType dataType = ad.getAttrType(); - if (dataType != null) - { - value = getValue(dataType); - } - } - return value; - } - - - public String getValue(CMDataType dataType) - { - String value = null; - value = dataType.getImpliedValue(); - - if (value == null) - { - String[] values = dataType.getEnumeratedValues(); - if (values != null && values.length > 0) - { - value = values[0]; - } - } - - if (value == null) - { - value = dataType.generateInstanceValue(); - } - - // Here is a special case where we handle DTD's ID related datatypes. - // These values must be generated/validate by considering the entire xml file - // so we can't rely on the 'generateInstanceValue' method. - // - // todo... find a nicer way to handle this - if (value == null) - { - String dataTypeName = dataType.getDataTypeName(); - if (dataTypeName != null) - { - if (dataTypeName.equals("ID")) //$NON-NLS-1$ - { - value = "idvalue" + idCount++; //$NON-NLS-1$ - } - else if (dataTypeName.equals("IDREF") || dataTypeName.equals("IDREFS")) //$NON-NLS-1$ //$NON-NLS-2$ - { - value = "idvalue0"; //$NON-NLS-1$ - } - } - } - return value; - } - - - public boolean isValidEmptyValue(CMAttributeDeclaration ad) - { - boolean result = true; - CMDataType dataType = ad.getAttrType(); - if (dataType != null) - { - String propertyValue = (String)dataType.getProperty("isValidEmptyValue"); //$NON-NLS-1$ - if (propertyValue != null && propertyValue.equals("false")) //$NON-NLS-1$ - { - result = false; - } - } - return result; - } - - - public boolean isXSIType(CMAttributeDeclaration ad) - { - boolean result = false; - if (ad.getNodeName().equals("type")) //$NON-NLS-1$ - { - CMDocument cmDocument = (CMDocument)ad.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - String namespaceName = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - if (namespaceName != null && namespaceName.equals("http://www.w3.org/2001/XMLSchema-instance")) //$NON-NLS-1$ - { - result = true; - } - } - } - return result; - } - - - public List getQualifiedXSITypes(CMAttributeDeclaration ad, NamespaceTable table) - { - List list = new Vector(); - - List xsiTypes = (List)ad.getProperty("XSITypes"); //$NON-NLS-1$ - if (xsiTypes != null && xsiTypes.size() > 0) - { - for (Iterator i = xsiTypes.iterator(); i.hasNext(); ) - { - String uriQualifiedName = (String)i.next(); - String[] components = DOMNamespaceHelper.getURIQualifiedNameComponents(uriQualifiedName); - String prefix = table.getPrefixForURI(components[0] != null ? components[0] : ""); //$NON-NLS-1$ - String typeName = (prefix != null && prefix.length() > 0) ? - prefix + ":" + components[1] : //$NON-NLS-1$ - components[1]; - list.add(typeName); - } - } - return list; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/CMValidator.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/CMValidator.java deleted file mode 100644 index 0cb9bd5677..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/CMValidator.java +++ /dev/null @@ -1,1244 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.util; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor; - - - -public class CMValidator -{ - protected static StringElementContentComparator stringContentComparitor = new StringElementContentComparator(); - protected Hashtable graphNodeTable = new Hashtable(); - - /** - * GraphNode - */ - protected static class GraphNode - { - public String name; - public boolean isTerminal; - public Vector arcList = new Vector(); - - public GraphNode(String name) - { - this.name = name; - } - - public void addArc(Arc arc) - { - arcList.addElement(arc); - } - - public String toString() - { - return "[GraphNode " + name + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - - /** - * Arc - */ - protected static class Arc - { - public static final int ELEMENT = 1; - public static final int REPEAT = 2; - public static final int OPTIONAL = 3; - public static final int PREV_IN = 4; - public static final int OUT_NEXT = 5; - public static final int LINK = 6; - - public int kind; - public String name; - public GraphNode node; - public CMNode cmNode; - - public Arc(int kind, GraphNode node, CMNode cmNode) - { - this(kind, "", node, cmNode); //$NON-NLS-1$ - } - - protected Arc(int kind, String name, GraphNode node, CMNode cmNode) - { - this.name = name; - this.kind = kind; - this.node = node; - this.cmNode = cmNode; - } - } - - - /** - * GraphGenerator - */ - protected static class GraphGenerator extends CMVisitor - { - public int indent; - public int count; - public GraphNode startGraphNode; - public Context context; - - protected static class Context - { - GraphNode from; - GraphNode to; - - Context(GraphNode from, GraphNode to) - { - this.from = from; - this.to = to; - } - - GraphNode getLastGraphNode() - { - return (to != null) ? to : from; - } - } - - - protected GraphGenerator() - { - startGraphNode = new GraphNode(getGraphNodeName()); - context = new Context(startGraphNode, null); - } - - - protected void generateGraph(CMElementDeclaration ed) - { - int contentType = ed.getContentType(); - - if (contentType == CMElementDeclaration.MIXED || - contentType == CMElementDeclaration.ELEMENT) - { - visitCMNode(ed.getContent()); - } - // CMElementDeclaration.PCDATA... no graph required - // CMElementDeclaration.ANY... no graph required - context.getLastGraphNode().isTerminal = true; - } - - - protected String getGraphNodeName() - { - return "n" + count++; //$NON-NLS-1$ - } - - - protected GraphNode getStartGraphNode() - { - return startGraphNode; - } - - - /** - * repeat - * +----#-----+ - * | | - * v | - * prev --#-> in --'x'-> out --#-> next - * | ^ - * | | - * +----------------#--------------+ - * optional - * - */ - protected void createArcs(GraphNode in, GraphNode out, CMContent cmContent) - { - createArcs(in, out, cmContent, false); - } - - protected void createArcs(GraphNode in, GraphNode out, CMContent cmContent, boolean isAllGroup) - { - //println("+createArcs() " + ed.getDescription() + " " + ed.getMinOccur()); - GraphNode prev = context.from; - GraphNode next = new GraphNode(getGraphNodeName()); - - prev.addArc(new Arc(Arc.PREV_IN, in, cmContent)); - out.addArc(new Arc(Arc.OUT_NEXT, next, cmContent)); - - if (context.to != null) - { - next.addArc(new Arc(Arc.LINK, context.to, cmContent)); - } - else - { - context.from = next; - } - - if (cmContent.getMinOccur() == 0) - { - // todo... should we see if an optional arc has already been added? - prev.addArc(new Arc(Arc.OPTIONAL, next, cmContent)); - } - - if (cmContent.getMaxOccur() == -1 || cmContent.getMaxOccur() > 1 || isAllGroup) - { - out.addArc(new Arc(Arc.REPEAT, in, cmContent)); - } - } - - - public void visitCMGroup(CMGroup group) - { - Context prevContext = context; - GraphNode in = new GraphNode("(" + getGraphNodeName()); //$NON-NLS-1$ - GraphNode out = new GraphNode(")" + getGraphNodeName()); //$NON-NLS-1$ - - int groupOperator = group.getOperator(); - if (groupOperator == CMGroup.SEQUENCE) - { - context = new Context(in, null); - super.visitCMGroup(group); - context.from.addArc(new Arc(Arc.LINK, out, group)); - } - else if (groupOperator == CMGroup.CHOICE || - groupOperator == CMGroup.ALL) - { - context = new Context(in, out); - super.visitCMGroup(group); - } - - context = prevContext; - createArcs(in, out, group, groupOperator == CMGroup.ALL); - } - - - public void visitCMElementDeclaration(CMElementDeclaration ed) - { - GraphNode in = new GraphNode(getGraphNodeName()); - GraphNode out = new GraphNode(getGraphNodeName()); - createArcs(in, out, ed); - in.addArc(new Arc(Arc.ELEMENT, ed.getElementName(), out, ed)); - } - - - public void visitCMAnyElement(CMAnyElement anyElement) - { - GraphNode in = new GraphNode(getGraphNodeName()); - GraphNode out = new GraphNode(getGraphNodeName()); - createArcs(in, out, anyElement); - in.addArc(new Arc(Arc.ELEMENT, "any", out, anyElement)); //$NON-NLS-1$ - } - } - - // todo.. implement cache strategy hook, handle name spaces, locals etc. - // - public GraphNode lookupOrCreateGraph(CMElementDeclaration element) - { - Object key = element; - GraphNode node = (GraphNode)graphNodeTable.get(key); - if (node == null) - { - node = createGraph(element); - graphNodeTable.put(key, node); - } - return node; - } - - public GraphNode createGraph(CMElementDeclaration element) - { - GraphGenerator generator = new GraphGenerator(); - generator.generateGraph(element); - return generator.getStartGraphNode(); - } - - - public void printGraph(GraphNode node, Vector namedArcList, Vector unamedArcList, int indent) - { - //String decoration = node.isTerminal ? " *" : ""; - //printlnIndented(indent, "GraphNode:" + node.name + decoration); - - indent += 2; - for (Enumeration e = node.arcList.elements() ; e.hasMoreElements() ;) - { - Arc arc = (Arc)e.nextElement(); - //boolean visit = false; - //printlnIndented(indent, "Arc:" + arc.name + " (" + arc.kind + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (arc.kind == Arc.ELEMENT) - { - //table.add(currentGrammarObject, arc.grammarObject); - if (!namedArcList.contains(arc)) - { - namedArcList.add(arc); - unamedArcList = new Vector(); - printGraph(arc.node, namedArcList, unamedArcList, indent + 2); - } - } - else - { - if (!unamedArcList.contains(arc)) - { - unamedArcList.add(arc); - printGraph(arc.node, namedArcList, unamedArcList, indent + 2); - } - } - } - } - - public void printGraph(GraphNode node) - { - printGraph(node, new Vector(), new Vector(), 0); - } - - - public void validateElementList(ElementList list, GraphNode node, ElementContentComparator comparator, Result result, boolean loopFlag) - { - //println("+validateElementList " + node + " " + list); - if (list == null && node.isTerminal) - { - result.isValid = true; - } - else - { - for (Iterator i = node.arcList.iterator(); i.hasNext();) - { - Arc arc = (Arc)i.next(); - boolean traverseArc = false; - if (arc.kind == Arc.ELEMENT) - { - if (list != null && comparator.matches(list.head, arc.cmNode)) - { - loopFlag = false; - traverseArc = true; - list = list.tail; // increment our position in the list - } - } - else if (arc.kind == Arc.REPEAT) - { - if (!loopFlag) - { - traverseArc = true; - } - loopFlag = true; - } - else - { - traverseArc = true; - } - - if (traverseArc) - { - // test to see if we can push this arc due to facet constraints - // - if (result.canPush(arc)) - { - // see if this arc leads to a correct solution - result.push(arc); - validateElementList(list, arc.node, comparator, result, loopFlag); - if (result.isValid) - { - break; - } - result.pop(arc); - } - } - } - } - } - - - /** - * - */ - protected static ElementList createElementList(int contentType, List v, ElementContentComparator comparator, Result result) - { - ElementList first = null; - ElementList prev = null; - - int size = v.size(); - for (int i = 0; i < size; i++) - { - Object o = v.get(i); - if (o != null && !comparator.isIgnorable(o)) - { - if (comparator.isElement(o)) - { - ElementList list = new ElementList(); - list.head = o; - - if (prev != null) - { - prev.tail = list; - } - else - { - first = list; - } - prev = list; - } - else if (contentType == CMElementDeclaration.ELEMENT) - { - result.isValid = false; - result.errorIndex = i; - result.errorMessage = "Element can not include PCDATA content"; //$NON-NLS-1$ - } - } - } - return first; - } - - /** - * - */ - public void validate(CMElementDeclaration ed, List elementContent, ElementContentComparator comparator, Result result) - { - int contentType = ed.getContentType(); - - if (contentType == CMElementDeclaration.MIXED || - contentType == CMElementDeclaration.ELEMENT) - { - ElementList elementList = createElementList(contentType, elementContent, comparator, result); - if (result.isValid == true) - { - // defect 226213 ... elements with a large number of children will cause the recursion based validation - // algorithm to stack overflow ... as a quick fix assume any element with a large number of children is valid - if (elementContent.size() < 500) - { - boolean isGraphValidationNeeded = !(elementList == null && contentType == CMElementDeclaration.MIXED); - - // exlicity handle 'All' groups - // - CMContent content = ed.getContent(); - if (content.getNodeType() == CMNode.GROUP) - { - CMGroup group = (CMGroup)content; - if (group.getOperator() == CMGroup.ALL) - { - isGraphValidationNeeded = false; - validatAllGroupContent(elementContent, comparator, group, result); - } - } - - if (isGraphValidationNeeded) - { - // validate the elementList using a graph - // - result.isValid = false; - GraphNode node = lookupOrCreateGraph(ed); - validateElementList(elementList, node, comparator, result, false); - } - } - } - } - else if (contentType == CMElementDeclaration.PCDATA) - { - int size = elementContent.size(); - for (int i = 0; i < size; i++) - { - Object o = elementContent.get(i); - if (comparator.isElement(o)) - { - result.isValid = false; - result.errorIndex = i; - result.errorMessage = "Element may only include PCDATA content"; //$NON-NLS-1$ - break; - } - } - } - else if (contentType == CMElementDeclaration.EMPTY) - { - int size = elementContent.size(); - for (int i = 0; i < size; i++) - { - Object o = elementContent.get(i); - if (!comparator.isIgnorable(o)) - { - result.isValid = false; - result.errorIndex = i; - result.errorMessage = "Element may not contain PCDATA or Element content"; //$NON-NLS-1$ - break; - } - } - } - //else if (contentType == CMElementDeclaration.ANY) - // { - // assume elementContent will always be valid for this content type - // } - } - - static class ItemCount - { - int count = 0; - } - - private void validatAllGroupContent(List elementContent, ElementContentComparator comparator, CMGroup allGroup, Result result) - { - boolean isValid = true; - boolean isPartiallyValid = true; - HashMap map = new HashMap(); - CMNodeList list = allGroup.getChildNodes(); - for (int j = list.getLength() - 1; j >= 0; j--) - { - CMNode node = list.item(j); - if (map.get(node) == null) - { - map.put(node, new ItemCount()); - } - } - int validitionCount = 0; - for (Iterator i = elementContent.iterator(); i.hasNext(); validitionCount++) - { - Object o = i.next(); - if (comparator.isElement(o)) - { - // test to see if the element is listed in the all group - // - CMNode matchingCMNode = null; - for (int j = list.getLength() - 1; j >= 0; j--) - { - CMNode node = list.item(j); - if (comparator.matches(o, node)) - { - matchingCMNode = node; - break; - } - } - if (matchingCMNode == null) - { - isPartiallyValid = false; - isValid = false; - break; - } - else - { - // test to see that the element occurs only once - // - ItemCount itemCount = (ItemCount)map.get(matchingCMNode); - if (itemCount != null) - { - if (itemCount.count > 0) - { - // we don't want to allow too many elements! - // we consider 'not enough' to be partially valid... but not 'too many' - isPartiallyValid = false; - break; - } - else - { - itemCount.count++; - } - } - } - } - } - if (isValid) - { - for (int j = list.getLength() - 1; j >= 0; j--) - { - CMNode node = list.item(j); - if (node.getNodeType() == CMNode.ELEMENT_DECLARATION) - { - CMContent content = (CMContent)node; - ItemCount itemCount = (ItemCount)map.get(node); -// System.out.print("content " + content.getNodeName() + " " + content.getMinOccur()); - if (itemCount.count < content.getMinOccur()) - { - isValid = false; - break; - } - } - } - } - if (result instanceof ElementPathRecordingResult && isPartiallyValid) - { - ((ElementPathRecordingResult)result).setPartialValidationCount(validitionCount); - } - result.isValid = isValid; - } - - - public void getOriginArray(CMElementDeclaration ed, List elementContent, ElementContentComparator comparator, ElementPathRecordingResult result) - { - CMNode[] cmNodeArray = null; - validate(ed, elementContent, comparator, result); - if (result.isValid) - { - CMDataType dataType = ed.getDataType(); - int size = elementContent.size(); - cmNodeArray = new CMNode[size]; - Vector originList = result.getElementOriginList(); - int originListSize = originList.size(); - int originListIndex = 0; - for (int i = 0; i < size; i++) - { - Object o = elementContent.get(i); - if (comparator.isElement(o)) - { - if (originListIndex < originListSize) - { - cmNodeArray[i] = (CMNode)originList.get(originListIndex); - originListIndex++; - } - } - else if (comparator.isPCData(o)) - { - cmNodeArray[i] = dataType; - } - // else the CMNode at this index is null - } - result.setOriginArray(cmNodeArray); - } - } - - private void collectNamedArcs(GraphNode node, List namedArcList, int indent) - { - //printlnIndented(indent, "GraphNode:" + node.name + decoration); - indent += 2; - for (Iterator i = node.arcList.iterator(); i.hasNext() ;) - { - Arc arc = (Arc)i.next(); - //printlnIndented(indent, "Arc:" + arc.name + " (" + arc.kind + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (arc.kind == Arc.ELEMENT) - { - if (!namedArcList.contains(arc)) - { - namedArcList.add(arc); - collectNamedArcs(arc.node, namedArcList, indent + 2); - } - } - else if (arc.kind != Arc.REPEAT && arc.kind != Arc.OPTIONAL) - { - collectNamedArcs(arc.node, namedArcList, indent + 2); - } - } - } - - - private List getMatchingArcs(CMElementDeclaration ed, String elementName) - { - List arcList = new ArrayList(); - GraphNode graphNode = lookupOrCreateGraph(ed); - if (elementName == null) - { - // here we add the 'root' arc - for (Iterator i = graphNode.arcList.iterator(); i.hasNext() ;) - { - Arc arc = (Arc)i.next(); - if (arc.kind == Arc.PREV_IN) - { - arcList.add(arc); - break; - } - } - } - else - { - List namedArcs = new ArrayList(); - collectNamedArcs(graphNode, namedArcs, 0); - for (Iterator i = namedArcs.iterator(); i.hasNext(); ) - { - Arc arc = (Arc)i.next(); - if (arc.cmNode != null && elementName.equals(arc.cmNode.getNodeName())) - { - arcList.add(arc); - } - } - } - return arcList; - } - - - private void collectNextSiblings(GraphNode node, List nextSiblingList, List namedArcList, List unamedArcList, int indent) - { - //printlnIndented(indent, "GraphNode:" + node.name + decoration); - indent += 2; - for (Iterator i = node.arcList.iterator(); i.hasNext(); ) - { - Arc arc = (Arc)i.next(); - if (arc.kind == Arc.ELEMENT) - { - if (!namedArcList.contains(arc)) - { - if (arc.cmNode != null) - { - nextSiblingList.add(arc.cmNode); - if (arc.cmNode.getNodeType() == CMNode.ELEMENT_DECLARATION || - arc.cmNode.getNodeType() == CMNode.ANY_ELEMENT) - { - namedArcList.add(arc); - CMContent cmNode = (CMContent)arc.cmNode; - if (cmNode.getMinOccur() == 0) - { - unamedArcList = new ArrayList(); - collectNextSiblings(arc.node, nextSiblingList, namedArcList, unamedArcList, indent + 2); - } - } - } - } - } - else - { - if (!unamedArcList.contains(arc)) - { - unamedArcList.add(arc); - collectNextSiblings(arc.node, nextSiblingList, namedArcList, unamedArcList, indent + 2); - } - } - } - } - - public CMNode[] getNextSiblings(CMElementDeclaration ed, String elementName) - { - List arcList = getMatchingArcs(ed, elementName); - List nextSiblingList = new ArrayList(); - for (Iterator i = arcList.iterator(); i.hasNext(); ) - { - Arc arc = (Arc)i.next(); - collectNextSiblings(arc.node, nextSiblingList, new ArrayList(), new ArrayList(), 0); - } - CMNode[] result = new CMNode[nextSiblingList.size()]; - nextSiblingList.toArray(result); - //System.out.print("getNextSibling(" +elementName + ")"); - //for (int i = 0; i < result.length; i++) - //{ - // System.out.print("[" + result[i].getNodeName() + "]"); - //} - //System.out.println(); - return result; - } - - /** - * - */ - public static class Result - { - public boolean isValid = true; - public int errorIndex = -1; - public String errorMessage; - public boolean isRepeatTraversed; // detects if a repeat has been traversed - - public boolean canPush(Arc arc) - { - return true; - } - - public void push(Arc arc) - { - // overide this method to record traversed nodes - } - public void pop(Arc arc) - { - // overide this method to record traversed nodes - } - public CMNode[] getOriginArray() - { - return null; - } - } - - /** - * - */ - public static class ElementPathRecordingResult extends Result - { - protected List activeItemCountList = new ArrayList(); - protected List inactiveItemCountList = new ArrayList(); - protected Vector elementOriginStack = new Vector(); - protected CMNode[] originArray = null; - protected int partialValidationCount = 0; - - - // this method is used to support facet counts - // - public boolean canPush(Arc arc) - { - boolean result = true; - try - { - if (arc.kind == Arc.REPEAT) - { - if (arc.cmNode instanceof CMContent) - { - CMContent content = (CMContent)arc.cmNode; - - // we only need to do 'special' facet checking if the maxOccurs is > 1 - // values of '0' and '-1' (unbounded) work 'for free' without any special checking - // - if (content.getMaxOccur() > 1) - { - ItemCount itemCount = (ItemCount)activeItemCountList.get(activeItemCountList.size() - 1); - - // here we need to compute if we can do another repeat - // if we increase the repeat count by '1' will this violate the maxOccurs - // - if (itemCount.count + 1 >= content.getMaxOccur()) - { - result = false; - } - } - //System.out.println("canPush REPEAT (" + itemCount.count + ")" + content.getNodeName() + " result= " + result); - } - } - } - catch (Exception e) - { - e.printStackTrace(); - } - //System.out.flush(); - return result; - } - - public void push(Arc arc) - { - if (arc.kind == Arc.ELEMENT) - { - //System.out.println("[X]push(" + arc.kind + ")" + arc.cmNode.getNodeName()); - elementOriginStack.add(arc.cmNode); - partialValidationCount = Math.max(elementOriginStack.size(), partialValidationCount); - } - else if (arc.kind == Arc.PREV_IN) - { - //System.out.println("[X]push(" + arc.kind + ")" + arc.cmNode.getNodeName()); - activeItemCountList.add(new ItemCount()); - } - else if (arc.kind == Arc.OUT_NEXT) - { - //System.out.println("[X]push(" + arc.kind + ")" + arc.cmNode.getNodeName() + "[" + arc + "]"); - int size = activeItemCountList.size(); - ItemCount itemCount = (ItemCount)activeItemCountList.get(size - 1); - activeItemCountList.remove(size - 1); - inactiveItemCountList.add(itemCount); - } - else if (arc.kind == Arc.REPEAT) - { - //System.out.println("[X]push(" + arc.kind + ")" + arc.cmNode.getNodeName()); - ItemCount itemCount = (ItemCount)activeItemCountList.get(activeItemCountList.size() - 1); - itemCount.count++; - //System.out.println("repeat(" + itemCount.count + ")" + arc.cmNode.getNodeName()); - } - } - - public void pop(Arc arc) - { - if (arc.kind == Arc.ELEMENT) - { - //System.out.println("[X]pop(" + arc.kind + ")" + arc.cmNode.getNodeName()); - int size = elementOriginStack.size(); - elementOriginStack.remove(size - 1); - } - else if (arc.kind == Arc.PREV_IN) - { - //System.out.println("[X]pop(" + arc.kind + ")" + arc.cmNode.getNodeName()); - activeItemCountList.remove(activeItemCountList.size() - 1); - } - else if (arc.kind == Arc.OUT_NEXT) - { - //System.out.println("[X]pop(" + arc.kind + ")" + arc.cmNode.getNodeName()); - int size = inactiveItemCountList.size(); - ItemCount itemCount = (ItemCount)inactiveItemCountList.get(size - 1); - inactiveItemCountList.remove(size - 1); - activeItemCountList.add(itemCount); - } - else if (arc.kind == Arc.REPEAT) - { - //System.out.println("[X]pop(" + arc.kind + ")" + arc.cmNode.getNodeName()); - ItemCount itemCount = (ItemCount)activeItemCountList.get(activeItemCountList.size() - 1); - itemCount.count--; - } - } - - public Vector getElementOriginList() - { - return elementOriginStack; - } - - public CMNode[] getOriginArray() - { - return originArray; - } - - public void setOriginArray(CMNode[] originArray) - { - this.originArray = originArray; - } - - public int getPartialValidationCount() - { - return partialValidationCount; - } - - public void setPartialValidationCount(int partialValidationCount) - { - this.partialValidationCount = partialValidationCount; - } - } - - /** - * - */ - public static class PathRecordingResult extends Result - { - protected Vector arcList = new Vector(); - - public void push(Arc arc) - { - arcList.add(arc); - } - - public void pop(Arc arc) - { - int size = arcList.size(); - arcList.remove(size - 1); - } - - public List getArcList() - { - List list = new Vector(); - for (Iterator iterator = arcList.iterator(); iterator.hasNext(); ) - { - Arc arc = (Arc)iterator.next(); - if (arc.kind == Arc.ELEMENT) - { - list.add(arc); - } - } - return list; - } - - public MatchModelNode getMatchModel() - { - MatchModelNodeBuilder builder = new MatchModelNodeBuilder(arcList); - builder.buildMatchModel(); - return builder.getRoot(); - } - } - - /** - * - */ - public static class MatchModelNode - { - public CMNode cmNode; - public List children = new Vector(); - public Object data; - - public MatchModelNode(MatchModelNode parent, CMNode cmNode) - { - this.cmNode = cmNode; - } - - public void printModel(int indent) - { - //String cmNodeName = cmNode != null ? cmNode.getNodeName() : "null"; - //printlnIndented(indent, "MatchModelNode : " + cmNodeName); - for (Iterator iterator = children.iterator(); iterator.hasNext(); ) - { - MatchModelNode child = (MatchModelNode)iterator.next(); - child.printModel(indent + 2); - } - } - } - - public static class MatchModelNodeBuilder - { - protected List arcList; - protected List stack = new Vector(); - protected MatchModelNode root; - protected MatchModelNode current; - - public MatchModelNodeBuilder(List arcList) - { - this.arcList = arcList; - root = new MatchModelNode(null, null); - push(root); - } - - protected void push(MatchModelNode node) - { - current = node; - stack.add(node); - } - - protected void pop() - { - int size = stack.size(); - stack.remove(size - 1); - current = (MatchModelNode)stack.get(size - 2); - } - - public boolean isCMGroup(CMNode cmNode) - { - return cmNode != null && cmNode.getNodeType() == CMNode.GROUP; - } - - public void buildMatchModel() - { - for (Iterator iterator = arcList.iterator(); iterator.hasNext(); ) - { - Arc arc = (Arc)iterator.next(); - - if (arc.kind == Arc.ELEMENT) - { - current.children.add(new MatchModelNode(current, arc.cmNode)); - } - else if (arc.kind == Arc.PREV_IN) - { - if (isCMGroup(arc.cmNode)) - { - MatchModelNode newModelNode = new MatchModelNode(current, arc.cmNode); - current.children.add(newModelNode); - push(newModelNode); - } - } - else if (arc.kind == Arc.OUT_NEXT) - { - if (isCMGroup(arc.cmNode)) - { - pop(); - } - } - else if (arc.kind == Arc.REPEAT) - { - if (isCMGroup(arc.cmNode)) - { - pop(); - MatchModelNode newModelNode = new MatchModelNode(current, arc.cmNode); - current.children.add(newModelNode); - push(newModelNode); - } - } - } - } - - public MatchModelNode getRoot() - { - return root; - } - } - - - /** - * - */ - public interface ElementContentComparator - { - public boolean isIgnorable(Object o); - public boolean isPCData(Object o); - public boolean isElement(Object o); - public boolean matches(Object o, CMNode cmNode); - } - - /** - * A linked list - */ - public static class ElementList - { - protected Object head; - protected ElementList tail; - - public static ElementList create(List v) - { - ElementList first = null; - ElementList prev = null; - - for (Iterator iterator = v.iterator(); iterator.hasNext(); ) - { - Object o = iterator.next(); - if (o != null) - { - ElementList list = new ElementList(); - list.head = o; - - if (prev != null) - { - prev.tail = list; - } - else - { - first = list; - } - prev = list; - } - } - return first; - } - - - public String toString() - { - String string = "[" + head + "],"; //$NON-NLS-1$ //$NON-NLS-2$ - - if (tail != null) - { - string += tail.toString(); - } - - return string; - } - } - - /** - * StringElementContentComparator - */ - public static class StringElementContentComparator implements ElementContentComparator - { - public boolean isIgnorable(Object o) - { - String string = o.toString(); - return string.startsWith("!") || string.startsWith("?"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public boolean isPCData(Object o) - { - String string = o.toString(); - return string.startsWith("'") || string.startsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public boolean isElement(Object o) - { - return !isIgnorable(o) && !isPCData(o); - } - - public boolean matches(Object o, CMNode cmNode) - { - boolean result = false; - if (cmNode.getNodeType() == CMNode.ELEMENT_DECLARATION) - { - CMElementDeclaration element = (CMElementDeclaration)cmNode; - String name = o.toString(); - int index = name.indexOf("]"); //$NON-NLS-1$ - if (index != -1) - { - name = name.substring(index + 1); - } - result = name.equalsIgnoreCase(element.getElementName()); - - // TODO... here's we consider substitution groups... revisit to see if this should be moved into validator code - if (!result) - { - CMNodeList cmNodeList = (CMNodeList)element.getProperty("SubstitutionGroup"); //$NON-NLS-1$ - if (cmNodeList != null) - { - int cmNodeListLength = cmNodeList.getLength(); - if (cmNodeListLength > 1) - { - for (int i = 0; i < cmNodeListLength; i++) - { - CMElementDeclaration alternativeCMElementDeclaration = (CMElementDeclaration)cmNodeList.item(i); - String altName = alternativeCMElementDeclaration.getElementName(); - result = name.equalsIgnoreCase(altName); - if (result) - { - break; - } - } - } - } - } - } - else if (cmNode.getNodeType() == CMNode.ANY_ELEMENT) - { - String string = o.toString(); - if (string.equals("*")) //$NON-NLS-1$ - { - result = true; - } - else - { - CMAnyElement anyElement = (CMAnyElement)cmNode; - String anyElementURI = anyElement.getNamespaceURI(); - if (anyElementURI != null) - { - if (anyElementURI.equals("##any")) //$NON-NLS-1$ - { - result = true; - } - else if (anyElementURI.equals("##other")) //$NON-NLS-1$ - { - result = true; - CMDocument cmDocument = (CMDocument)anyElement.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - String excludedURI = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - if (excludedURI != null) - { - String specifiedURI = getURIForContentSpecification(string); - if (specifiedURI != null && excludedURI.equals(specifiedURI)) - { - result = false; - } - } - } - } - else if (anyElementURI.equals("##targetNamespace")) //$NON-NLS-1$ - { - result = true; - CMDocument cmDocument = (CMDocument)anyElement.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - String targetNamespaceURI = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - String specifiedURI = getURIForContentSpecification(string); - if (specifiedURI != null && !targetNamespaceURI.equals(specifiedURI)) - { - result = false; - } - } - } - else - { - result = true; - String specifiedURI = getURIForContentSpecification(string); - if (specifiedURI != null && !anyElementURI.equals(specifiedURI)) - { - result = false; - } - } - } - else - { - result = true; - } - } - } - return result; - } - - - protected String getURIForContentSpecification(String specification) - { - String result = null; - int index = specification.indexOf("]"); //$NON-NLS-1$ - if (index != -1) - { - result = specification.substring(1, index); - } - return result; - } - } - - public static List createStringList(String arg[], int startIndex) - { - Vector v = new Vector(); - for (int i = startIndex; i < arg.length; i++) - { - v.add(arg[i]); - } - return v; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/DOMValidator.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/DOMValidator.java deleted file mode 100644 index 8696df407f..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/internal/util/DOMValidator.java +++ /dev/null @@ -1,424 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.internal.util; - -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - - -/** - * A special CMValidator that knows about DOMs - */ -public class DOMValidator extends CMValidator -{ - protected String getNamespaceURI(Node node) - { - return DOMNamespaceHelper.getNamespaceURI(node); - //return node.getNamespaceURI(); - } - - - // - // This is a temporary hack!! - // - protected String getFallbackNamepaceURI(CMElementDeclaration ed) - { - String fallbackNamepaceURI = null; - CMDocument cmDocument = (CMDocument)ed.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - fallbackNamepaceURI = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - } - return fallbackNamepaceURI; - } - - /** - * Encode the Element's NodeList as a List of strings that the validator recognizes - */ - public List createContentSpecificationList(Element element, CMElementDeclaration ed) - { - boolean isNamespaceAware = isNamespaceAware(ed); - Vector v = new Vector(); - for (Node childNode = element.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) - { - v.add(createContentSpecification(childNode, isNamespaceAware, isNamespaceAware ? getFallbackNamepaceURI(ed) : null)); - } - return v; - } - - - public List createContentSpecificationList(List nodeList, CMElementDeclaration ed) - { - boolean isNamespaceAware = isNamespaceAware(ed); - Vector v = new Vector(); - - for (Iterator i = nodeList.iterator(); i.hasNext(); ) - { - Node node = (Node)i.next(); - v.add(createContentSpecification(node, isNamespaceAware, getFallbackNamepaceURI(ed))); - } - return v; - } - - - /** - * Encode the Node as a string that the validator recognizes - */ - public String createContentSpecification(Node node, boolean isNamespaceAware, String fallbackNamepaceURI) - { - String result = "!"; //$NON-NLS-1$ - switch (node.getNodeType()) - { - case Node.ELEMENT_NODE : - { - String nodeName = node.getNodeName(); - if (nodeName.startsWith("jsp:")) //$NON-NLS-1$ - { - result = "!"; // treat it as a comment so that it's ignored by the validator //$NON-NLS-1$ - } - else - { - if (isNamespaceAware) - { - result = DOMNamespaceHelper.getUnprefixedName(nodeName); - String uri = getNamespaceURI(node); - if (uri != null) - { - result = "[" + uri + "]" + result; //$NON-NLS-1$ //$NON-NLS-2$ - } - else if (fallbackNamepaceURI != null) - { - result = "[" + fallbackNamepaceURI + "]" + result; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - else - { - result = nodeName; - } - } - //ContentModelManager.println("result " + result); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : - { - result = "?"; //$NON-NLS-1$ - break; - } - case Node.COMMENT_NODE : - { - result = "!"; //$NON-NLS-1$ - break; - } - case Node.CDATA_SECTION_NODE : - { - result = "\"" + node.getNodeName() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - case Node.TEXT_NODE : - { - String data = ((Text)node).getData(); - // here we test to see if the test node is 'ignorable' - if (data != null && data.trim().length() > 0) - { - result = "\"" + node.getNodeName() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - } - else - { - result = "!"; // todo... use another symbol? //$NON-NLS-1$ - } - break; - } - } - return result; - } - - - /** - * - */ - public List createContentSpecificationList(CMNode cmNode) - { - List list = new Vector(); - switch (cmNode.getNodeType()) - { - case CMNode.ELEMENT_DECLARATION : - { - list.add(createContentSpecificationForCMElementDeclaration((CMElementDeclaration)cmNode)); - break; - } - case CMNode.DATA_TYPE : - { - list.add("\"" + cmNode.getNodeName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - case CMNode.GROUP : - { - createContentSpecificationListForCMGroup((CMGroup)cmNode, list); - break; - } - case CMNode.ANY_ELEMENT : - { - list.add("*"); //$NON-NLS-1$ - break; - } - default : - { - list.add("!"); //$NON-NLS-1$ - } - } - return list; - } - - - /** - * - */ - protected String createContentSpecificationForCMElementDeclaration(CMElementDeclaration ed) - { - CMDocument document = (CMDocument)ed.getProperty("CMDocument"); //$NON-NLS-1$ - String uri = document != null ? (String)document.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI") : null; //$NON-NLS-1$ - String string = ed.getNodeName(); - if (uri != null) - { - string = "[" + uri + "]" + string; //$NON-NLS-1$ //$NON-NLS-2$ - } - return string; - } - - /** - * - */ - protected void createContentSpecificationListForCMGroup(CMGroup group, List list) - { - CMGroupContentVisitor visitor = new CMGroupContentVisitor(group, list); - visitor.visitCMNode(group); - } - - protected class CMGroupContentVisitor extends CMVisitor - { - protected CMGroup root; - protected List list; - - public CMGroupContentVisitor(CMGroup root, List list) - { - this.root = root; - this.list = list; - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) - { - if (ed.getMinOccur() > 0) - { - list.add(createContentSpecificationForCMElementDeclaration(ed)); - } - } - - public void visitCMAnyElement(CMAnyElement anyElement) - { - list.add("*"); //$NON-NLS-1$ - } - - public void visitCMGroup(CMGroup group) - { - if (group == root || group.getMinOccur() > 0) - { - int op = group.getOperator(); - if (op == CMGroup.SEQUENCE) - { - super.visitCMGroup(group); - } - else if (op == CMGroup.CHOICE) - { - CMNodeList nodeList = group.getChildNodes(); - if (nodeList.getLength() > 0) - { - visitCMNode(nodeList.item(0)); - } - } - } - } - } - - public boolean isNamespaceAware(CMElementDeclaration ed) - { - return ed != null ? ed.getProperty("http://org.eclipse.wst/cm/properties/isNameSpaceAware") != null : false; //$NON-NLS-1$ - } - - /** - * - */ - public CMNode[] getOriginArray(CMElementDeclaration ed, Element element) - { - ElementPathRecordingResult result = new ElementPathRecordingResult(); - getOriginArray(ed, createContentSpecificationList(element, ed), stringContentComparitor, result); - return result.getOriginArray(); - } - - /** - * - */ - public MatchModelNode getMatchModel(CMElementDeclaration ed, Element element) - { - MatchModelNode matchModelNode = null; - PathRecordingResult result = new PathRecordingResult(); - validate(ed, createContentSpecificationList(element, ed), stringContentComparitor, result); - if (result.isValid) - { - matchModelNode = result.getMatchModel(); - } - return matchModelNode; - } - - - public List clone(List list) - { - List result = new Vector(list.size()); - result.addAll(list); - return result; - } - - /** - * - */ - public boolean canInsert(CMElementDeclaration ed, List contentSpecificationList, int insertIndex, CMNode cmNode) - { - List clonedList = clone(contentSpecificationList); - insert(clonedList, insertIndex, cmNode); - boolean result = isPartiallyValid(ed, clonedList); - return result; - } - - /** - * - */ - public boolean canInsert(CMElementDeclaration ed, List contentSpecificationList, int insertIndex, List cmNodeList) - { - List clonedList = clone(contentSpecificationList); - insert(clonedList, insertIndex, cmNodeList); - return isValid(ed, clonedList); - } - - /** - * - */ - public boolean canRemove(CMElementDeclaration ed, List contentSpecificationList, int startRemoveIndex) - { - return canRemove(ed, contentSpecificationList, startRemoveIndex, startRemoveIndex); - } - - /** - * - */ - public boolean canRemove(CMElementDeclaration ed, List contentSpecificationList, int startRemoveIndex, int endRemoveIndex) - { - List clonedList = clone(contentSpecificationList); - remove(clonedList, startRemoveIndex, endRemoveIndex); - return isValid(ed, clonedList); - } - - /** - * - */ - public boolean canReplace(CMElementDeclaration ed, List contentSpecificationList, int startRemoveIndex, int endRemoveIndex, CMNode cmNode) - { - List clonedList = clone(contentSpecificationList); - remove(clonedList, startRemoveIndex, endRemoveIndex); - insert(clonedList, startRemoveIndex, cmNode); - return isValid(ed, clonedList); - } - - /** - * - */ - public boolean isValid(CMElementDeclaration ed, List contentSpecificationList) - { - Result result = new Result(); - validate(ed, contentSpecificationList, stringContentComparitor, result); - return result.isValid; - } - - public boolean isPartiallyValid(CMElementDeclaration ed, List contentSpecificationList) - { - CMValidator.ElementPathRecordingResult result = new CMValidator.ElementPathRecordingResult(); - validate(ed, contentSpecificationList, stringContentComparitor, result); - int count = getElementCount(contentSpecificationList); - //System.out.println("elementOriginList " + result.getPartialValidationCount() + "vs" + count); - return result.getPartialValidationCount() >= count; - } - - public int getElementCount(List contentSpecificationList) - { - int count = 0; - for (Iterator i = contentSpecificationList.iterator(); i.hasNext(); ) - { - if (stringContentComparitor.isElement(i.next())) - { - count++; - } - } - return count; - } - - protected Result validate(CMElementDeclaration ed, Element element) - { - Result result = new Result(); - validate(ed, createContentSpecificationList(element, ed), stringContentComparitor, result); - return result; - } - - - protected void remove(List stringList, int startRemoveIndex, int endRemoveIndex) - { - if (startRemoveIndex != -1) - { - for (int i = startRemoveIndex; i <= endRemoveIndex; i++) - { - stringList.remove(i); - } - } - } - - protected void insert(List stringList, int insertIndex, CMNode cmNode) - { - if (insertIndex != -1) - { - stringList.addAll(insertIndex, createContentSpecificationList(cmNode)); - } - } - - protected void insert(List stringList, int insertIndex, List cmNodeList) - { - if (insertIndex != -1) - { - int insertListSize = cmNodeList.size(); - for (int i = insertListSize - 1; i >= 0; i--) - { - CMNode cmNode = (CMNode)cmNodeList.get(i); - stringList.addAll(insertIndex, createContentSpecificationList(cmNode)); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentManager.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentManager.java deleted file mode 100644 index 8c4a7b62f5..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentManager.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - */ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; - - -/** - * The CMDocumentManager can be visualized as a table of CMDocument - * references, each with a corresponding entry in a CMDocument cache. The - * CMDocumentManager also performs the task of loading CMDocuments providing - * support for synchronous and asynchronous loading. - * - * publicIdTable CMDocumentCache --------------------------- - * --------------------------------------- | publicId | resolvedURI | -> | - * resolvedURI | status | CMDocument | --------------------------- - * --------------------------------------- | (null) | file:/x.dtd | | - * file:/x.dtd | loading | (null) | --------------------------- - * --------------------------------------- | http:/... | file:/y.xsd | | - * file:/y.xsd | loaded | | --------------------------- - * --------------------------------------- - * - */ -public interface CMDocumentManager { - /** - * This property specifies WHEN CMDocuments are loaded. Setting this - * property to true allows the CMDocumentManager to load CMDocuments on - * demand. Settings this property a false puts the onus on the client to - * call addCMDocumentReference() to explicity trigger a load. This allows - * the client to control exactly when loading should take place. ) - */ - public static final String PROPERTY_AUTO_LOAD = "autoLoad"; //$NON-NLS-1$ - - /** - * This property specifies HOW CMDocuments are loaded. When set to false, - * the getCMDocument() method will load the CMDocument synchronously and - * return a CMDocument object when loading is successful. When set to - * true, the getCMDocument() will load the CMDocument asynchronously and - * will immediately return null. When loading is complete, the - * CMDocumentManager will inform its listeners that the CMDocument has - * been loaded. - */ - public static final String PROPERTY_ASYNC_LOAD = "asyncLoad"; //$NON-NLS-1$ - - /** - * - */ - public static final String PROPERTY_USE_CACHED_RESOLVED_URI = "useCachedResovledURI"; //$NON-NLS-1$ - - /** - * Set the enabled state of a property. - */ - public void setPropertyEnabled(String propertyName, boolean enabled); - - /** - * Get the enabled state of the property. - */ - public boolean getPropertyEnabled(String propertyName); - - /** - * Adds a listener. Listeners should expect to receive call backs on a - * secondary thread when asynchronously loading is used. - */ - public void addListener(CMDocumentManagerListener listener); - - /** - * Removes a listener. - */ - public void removeListener(CMDocumentManagerListener listener); - - /** - * Lookup or create a CMDocument (depending on PROPERTY_AUTO_LOAD). - * - * @param publicId - * @param systemId - * @param type - - * 'dtd', 'xsd', 'tld', etc. if null is given as the type, then - * the type is calculated as last segment (e.g. file extension) - * of the resolved URI - * @return - */ - public CMDocument getCMDocument(String publicId, String systemId, String type); - - /** - * Lookup a CMDocument. - */ - public CMDocument getCMDocument(String publicId); - - /** - * Get the status of a CMDocument. - */ - public int getCMDocumentStatus(String publicId); - - /** - * Creates a CMDocument and adds the associated CMDocument reference - * information to the table. Calling this method always triggers a - * CMDocument load. - */ - public void addCMDocumentReference(String publicId, String systemId, String type); - - /** - * Add an existingCMDocument and the reference information to the table. - */ - public void addCMDocument(String publicId, String systemId, String resolvedURI, String type, CMDocument cmDocument); - - /** - * Remove all entries from the table. - */ - public void removeAllReferences(); - - /** - * Get the CMDocumentCache that is used to store loaded CMDocuments and - * associated status. - */ - public CMDocumentCache getCMDocumentCache(); - - /** - * Builds a CMDocument given a resoulvedURI. Note that no entries are - * added to the table. - */ - public CMDocument buildCMDocument(String publicId, String resolvedURI, String type); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentManagerListener.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentManagerListener.java deleted file mode 100644 index b236092d29..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentManagerListener.java +++ /dev/null @@ -1,23 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCacheListener; - -/** - * - */ -public interface CMDocumentManagerListener extends CMDocumentCacheListener -{ - public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentReference.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentReference.java deleted file mode 100644 index 7a234187d7..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentReference.java +++ /dev/null @@ -1,20 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - - -public interface CMDocumentReference -{ - public String getPublicId(); - public String getSystemId(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentReferenceProvider.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentReferenceProvider.java deleted file mode 100644 index c8d93d1357..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/CMDocumentReferenceProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - -import java.util.List; - -import org.w3c.dom.Node; - -/** - * The interface is used to abstract the task of computing the document references associated with a DOM - * or a particular node within the DOM. - */ -public interface CMDocumentReferenceProvider -{ - List getCMDocumentReferences(Node node, boolean deep); - String resolveGrammarURI(String publicId, String systemId); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQuery.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQuery.java deleted file mode 100644 index 3b0c0d3484..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQuery.java +++ /dev/null @@ -1,195 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - -import java.util.List; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtensionManager; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -/** - * This class provides an interface for performing higher level queries based on - * a xml model (DOM) and one or more associated content models (CMDocument). - * - * The queries provided can be organized into three groups: - * - * 1) DOM Node to CMNode mapping - * Given a grammatically valid DOM Node the corresponding CMNode can be determined. - * (i.e. Element -> CMElementDeclaration, Attr -> CMAttributeDeclaration, CharacterData -> CMDataType) - * - * 2) DOM editing tests ("Can I do this?") - * Questions such as canInsert, canRemove, canReplace can assist in the editing of a DOM. - * - * The validityChecking argument determines the strictness of the validity testing that occurs. - * - * - VALIDITY_NONE : The current content of the Element is ignored. - * Only the content model is considered. - * This is most useful for codeassist related queries. - * - * - VALIDITY_STRICT : The current content of the Element is considered. - * Returns true only if the operation preserves content validity. - * This is useful when DOM editing needs to be constrained to maintain validity. - * - * - VALIDITY_PARTIAL : Some optimized compromise between the two options above. - * - * 3) DOM editing actions ("What can I do here?") - * These methods return ModelQueryActions that are relevant at some specified DOM Node. - * The actions indicate what kinds of DOM Node can be inserted where (at what index). - */ -public interface ModelQuery -{ - public static final int VALIDITY_NONE = 0; - public static final int VALIDITY_PARTIAL = 1; - public static final int VALIDITY_STRICT = 2; - - public static final int INCLUDE_ALL = 0xFF; - public static final int INCLUDE_ATTRIBUTES = 0x01; - public static final int INCLUDE_CHILD_NODES = 0x02; - public static final int INCLUDE_SEQUENCE_GROUPS = 0x04; - public static final int INCLUDE_TEXT_NODES = 0x08; - public static final int INCLUDE_ENCLOSING_REPLACE_ACTIONS = 0x10; - - public static final int EDIT_MODE_UNCONSTRAINED = 0; - public static final int EDIT_MODE_CONSTRAINED_LENIENT= 1; - public static final int EDIT_MODE_CONSTRAINED_STRICT = 2; - - - void setEditMode(int editMode); - - int getEditMode(); - - /** - * Returns the CMDocument that corresponds to the DOM Node. - * or null if no CMDocument is appropriate for the DOM Node. - */ - CMDocument getCorrespondingCMDocument(Node node); - - /** - * Returns the corresponding CMNode for the DOM Node - * or null if no CMNode is appropriate for the DOM Node. - */ - CMNode getCMNode(Node node); - - /** - * Returns the corresponding CMAttribute for the DOM Node - * or null if no CMNode is appropriate for the DOM Node. - */ - CMAttributeDeclaration getCMAttributeDeclaration(Attr attr); - - /** - * Returns the corresponding CMAttribute for the DOM Node - * or null if no CMNode is appropriate for the DOM Node. - */ - CMElementDeclaration getCMElementDeclaration(Element element); - - /** - * Returns true if the content of the element is valid - */ - boolean isContentValid(Element element); - - /** - * Returns the CMNode of the parent element's content model - * that corresponds to the node - */ - CMNode getOrigin(Node node); - - /** - * Returns an array of CMNodes of the parent element's content model - * that corresponds to the node - */ - CMNode[] getOriginArray(Element element); - - /** - * Returns a list of all CMNode 'meta data' that may be potentially added to the element. - */ - List getAvailableContent(Element element, CMElementDeclaration ed, int includeOptions); - - /** - * Can a DOM Node corresponding to the CMNode 'meta data' be added to the parent - */ - boolean canInsert(Element parent, CMNode cmNode, int index, int validityChecking); - - /** - * Can multiple DOM Nodes corresponding to the list of CMNode 'meta data' be added to the parent - */ - boolean canInsert(Element parent, List cmNodeList, int index, int validityChecking); - - /** - * Can the DOM Node be removed - */ - boolean canRemove(Node node, int validityChecking); - - /** - * Can the list of DOM Nodes be removed - */ - boolean canRemove(List nodeList, int validityChecking); - - /** - * Can the children within the indicated indices be replaced with a DOM Node corresponding to the CMNode 'meta data' - */ - boolean canReplace(Element parent, int startIndex, int endIndex, CMNode cmNode, int validityChecking); - - /** - * Can the children within the indicated indices be replaced with multiple DOM Nodes corresponding to the list of CMNode 'meta data' - */ - boolean canReplace(Element parent, int startIndex, int endIndex, List cmNodeList, int validityChecking); - - /** - * - */ - void getInsertActions(Element parent, CMElementDeclaration ed, int index, int includeOptions, int validityChecking, List actionList); - - /** - * - */ - void getInsertActions(Document parent, CMDocument cmDocument, int index, int includeOptions, int validityChecking, List actionList); - - /** - * Return a list of replace actions that can be performed on the parent's content - */ - void getReplaceActions(Element parent, CMElementDeclaration ed, int includeOptions, int validityChecking, List actionList); - - /** - * Return a list of replace actions that can be performed on the selected children of that parent - */ - void getReplaceActions(Element parent, CMElementDeclaration ed, List selectedChildren, int includeOptions, int validityChecking, List actionList); - - - /** - * @deprecated - use getPossibleDataTypeValues() - */ - List getDataTypeValues(Element element, CMNode cmNode); - - /** - * This methods return an array of possible values corresponding to the datatype of the CMNode (either an CMAttributeDeclaration or a CMElementDeclaration) - */ - String[] getPossibleDataTypeValues(Element element, CMNode cmNode); - - /** - * This method may return null if a CMDocumentManager is not used by the ModelQuery - */ - CMDocumentManager getCMDocumentManager(); - - /** - * This method may return null the ModelQuery doesn't support the use of extensions - */ - ModelQueryExtensionManager getExtensionManager(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryAction.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryAction.java deleted file mode 100644 index 098f4f362f..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryAction.java +++ /dev/null @@ -1,36 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.w3c.dom.Node; - - -public interface ModelQueryAction -{ - public static final int INSERT = 1; - public static final int REMOVE = 2; - public static final int REPLACE = 4; - - public int getKind(); - /** - * if start index == -1 then no insert is possible - * if start index != -1 and endIndex == -1 then an insert at any position is possible - */ - public int getStartIndex(); - public int getEndIndex(); - public Node getParent(); - public CMNode getCMNode(); - public Object getUserData(); - public void setUserData(Object object); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryAssociationProvider.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryAssociationProvider.java deleted file mode 100644 index 9fa1000424..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryAssociationProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - - -/** - * - * - */ -public interface ModelQueryAssociationProvider extends ModelQueryCMProvider -{ - public CMNode getCMNode(Node node); - public CMDataType getCMDataType(Text text); - public CMAttributeDeclaration getCMAttributeDeclaration(Attr attr); - public CMElementDeclaration getCMElementDeclaration(Element element); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryCMProvider.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryCMProvider.java deleted file mode 100644 index e9cc02ebb6..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/ModelQueryCMProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.w3c.dom.Node; - - - -/** - * - */ -public interface ModelQueryCMProvider -{ - /** - * Returns the CMDocument that corresponds to the DOM Node. - * or null if no CMDocument is appropriate for the DOM Node. - */ - CMDocument getCorrespondingCMDocument(Node node); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/extension/ModelQueryExtension.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/extension/ModelQueryExtension.java deleted file mode 100644 index e92e6689b4..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/extension/ModelQueryExtension.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public abstract class ModelQueryExtension -{ - protected static final String[] EMPTY_STRING_ARRAY = {}; - - public String[] getAttributeValues(Element ownerElement, String namespace, String name) - { - return EMPTY_STRING_ARRAY; - } - - public String[] getElementValues(Node parentNode, String namespace, String name) - { - return EMPTY_STRING_ARRAY; - } - - public boolean isApplicableChildElement(Node parentNode, String namespace, String name) - { - return true; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/extension/ModelQueryExtensionManager.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/extension/ModelQueryExtensionManager.java deleted file mode 100644 index 2cdf95072c..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/extension/ModelQueryExtensionManager.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension; - -import java.util.List; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.w3c.dom.Element; - - - -public interface ModelQueryExtensionManager -{ - List getDataTypeValues(Element element, CMNode cmNode); - - void filterAvailableElementContent(List availableContent, Element element, CMElementDeclaration ed); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/BaseAssociationProvider.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/BaseAssociationProvider.java deleted file mode 100644 index 6618e1266c..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/BaseAssociationProvider.java +++ /dev/null @@ -1,88 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAssociationProvider; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - - -/** - * - */ -public abstract class BaseAssociationProvider implements ModelQueryAssociationProvider -{ - public BaseAssociationProvider() - { - } - - public CMNode getCMNode(Node node) - { - CMNode result = null; - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE : - { - result = getCMAttributeDeclaration((Attr)node); - break; - } - case Node.ELEMENT_NODE : - { - result = getCMElementDeclaration((Element)node); - break; - } - case Node.CDATA_SECTION_NODE : - case Node.TEXT_NODE : - { - result = getCMDataType((Text)node); - break; - } - } - return result; - } - - - public CMDataType getCMDataType(Text text) - { - CMDataType result = null; - Node parentNode = text.getParentNode(); - if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) - { - CMElementDeclaration ed = getCMElementDeclaration((Element)parentNode); - result = ed.getDataType(); - } - return result; - } - - - 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()); - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentLoader.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentLoader.java deleted file mode 100644 index 5b0ddb4c6b..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentLoader.java +++ /dev/null @@ -1,214 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - - -/** - * - */ -public class CMDocumentLoader -{ - protected Document document; - protected ModelQuery modelQuery; - protected CMDocumentManager cmDocumentManager; - protected boolean isInferredGrammarEnabled = true; - protected CMDocumentLoadingNamespaceTable namespaceTable; - protected int count = 0; - - public CMDocumentLoader(Document document, ModelQuery modelQuery) - { - this(document, modelQuery.getCMDocumentManager()); - } - - public CMDocumentLoader(Document document, CMDocumentManager cmDocumentManager) - { - this.document = document; - this.cmDocumentManager = cmDocumentManager; - } - - public void loadCMDocuments() - { - //System.out.println("----------loadCMDocuments ------------"); - //long time = System.currentTimeMillis(); - - boolean walkDocument = false; - - cmDocumentManager.removeAllReferences(); - - String[] doctypeInfo = XMLAssociationProvider.getDoctypeInfo(document); - if (doctypeInfo != null) - { - // load the doctype if required - walkDocument = handleGrammar(doctypeInfo[0], doctypeInfo[1], "DTD"); //$NON-NLS-1$ - } - else - { - Element element = getRootElement(document); - if (element != null) - { - namespaceTable = new CMDocumentLoadingNamespaceTable(document); - namespaceTable.addElement(element); - if (namespaceTable.isNamespaceEncountered()) - { - walkDocument = true; - //System.out.println("isNamespaceAware"); - } - else - { - namespaceTable = null; - walkDocument = isInferredGrammarEnabled; - //System.out.println("is NOT namespaceAware"); - } - } - } - - if (walkDocument) - { - visitNode(document); - } - - //System.out.println("--- elapsed time (" + count + ") = " + (System.currentTimeMillis() - time)); - } - - - public boolean handleGrammar(String publicId, String systemId, String type) - { - boolean result = false; - - int status = cmDocumentManager.getCMDocumentStatus(publicId); - if (status == CMDocumentCache.STATUS_NOT_LOADED) - { - cmDocumentManager.addCMDocumentReference(publicId, systemId, type); - } - else if (status == CMDocumentCache.STATUS_ERROR) - { - result = true; - } - return result; - } - - - public void handleElement(Element element) - { - visitChildNodes(element); - } - - - public void handleElementNS(Element element) - { - namespaceTable.addElement(element); - visitChildNodes(element); - } - - - public void visitNode(Node node) - { - int nodeType = node.getNodeType(); - if (nodeType == Node.ELEMENT_NODE) - { - count++; - - Element element = (Element)node; - if (namespaceTable == null) - { - handleElement(element); - } - else - { - handleElementNS(element); - } - } - else if (nodeType == Node.DOCUMENT_NODE) - { - visitChildNodes(node); - } - } - - - protected void visitChildNodes(Node node) - { - for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) - { - visitNode(child); - } - } - - - protected class CMDocumentLoadingNamespaceTable extends NamespaceTable - { - protected List newNamespaceList; - - public CMDocumentLoadingNamespaceTable(Document document) - { - super(document); - } - - - public void addElement(Element element) - { - newNamespaceList = null; - super.addElement(element); - if (newNamespaceList != null) - { - for (Iterator i = newNamespaceList.iterator(); i.hasNext(); ) - { - NamespaceInfo info = (NamespaceInfo)i.next(); - handleGrammar(info.uri, info.locationHint, "XSD"); //$NON-NLS-1$ - } - } - } - - - protected void internalAddNamespaceInfo(String key, NamespaceInfo info) - { - super.internalAddNamespaceInfo(key, info); - if (newNamespaceList == null) - { - newNamespaceList = new ArrayList(); - } - newNamespaceList.add(info); - } - } - - - protected Element getRootElement(Document document) - { - Element result = null; - NodeList nodeList = document.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0 ; i < nodeListLength; i++) - { - Node node = nodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) - { - result = (Element)node; - break; - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentManagerImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentManagerImpl.java deleted file mode 100644 index 1f908056c5..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentManagerImpl.java +++ /dev/null @@ -1,282 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.wst.xml.core.internal.Logger; -import org.eclipse.wst.xml.core.internal.XMLCoreMessages; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.annotation.AnnotationUtility; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentReferenceProvider; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; - - -/** - * - */ -public class CMDocumentManagerImpl implements CMDocumentManager -{ - protected CMDocumentCache cmDocumentCache; - protected CMDocumentReferenceProvider cmDocumentReferenceProvider; - protected List listenerList = new Vector(); - protected Hashtable propertyTable = new Hashtable(); - protected Hashtable publicIdTable = new Hashtable(); - - - public CMDocumentManagerImpl(CMDocumentCache cmDocumentCache, CMDocumentReferenceProvider cmDocumentReferenceProvider) - { - this.cmDocumentCache = cmDocumentCache; - this.cmDocumentReferenceProvider = cmDocumentReferenceProvider; - setPropertyEnabled(PROPERTY_AUTO_LOAD, true); - setPropertyEnabled(PROPERTY_USE_CACHED_RESOLVED_URI, false); - } - - - public CMDocumentCache getCMDocumentCache() - { - return cmDocumentCache; - } - - - public void setPropertyEnabled(String propertyName, boolean value) - { - propertyTable.put(propertyName, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ - for (Iterator i = listenerList.iterator(); i.hasNext(); ) - { - CMDocumentManagerListener listener = (CMDocumentManagerListener)i.next(); - listener.propertyChanged(this, propertyName); - } - } - - - public boolean getPropertyEnabled(String propertyName) - { - Object object = propertyTable.get(propertyName); - return object != null && object.equals("true"); //$NON-NLS-1$ - } - - - public void addListener(CMDocumentManagerListener listener) - { - listenerList.add(listener); - cmDocumentCache.addListener(listener); - } - - - public void removeListener(CMDocumentManagerListener listener) - { - listenerList.remove(listener); - cmDocumentCache.removeListener(listener); - } - - - protected String lookupResolvedURI(String publicId) - { - String key = publicId != null ? publicId : ""; //$NON-NLS-1$ - return (String)publicIdTable.get(key); - } - - - protected String lookupOrCreateResolvedURI(String publicId, String systemId) - { - String resolvedURI = null; - - String key = publicId != null ? publicId : ""; //$NON-NLS-1$ - - if (getPropertyEnabled(PROPERTY_USE_CACHED_RESOLVED_URI)) - { - resolvedURI = (String)publicIdTable.get(key); - } - - if (resolvedURI == null) - { - resolvedURI = cmDocumentReferenceProvider.resolveGrammarURI(publicId, systemId); - if (resolvedURI == null) - { - resolvedURI = ""; //$NON-NLS-1$ - } - publicIdTable.put(key, resolvedURI); - } - - return resolvedURI; - } - - - public int getCMDocumentStatus(String publicId) - { - int status = CMDocumentCache.STATUS_NOT_LOADED; - String resolvedURI = lookupResolvedURI(publicId); - if (resolvedURI != null) - { - status = cmDocumentCache.getStatus(resolvedURI); - } - return status; - } - - - public CMDocument getCMDocument(String publicId) - { - CMDocument result = null; - String resolvedURI = lookupResolvedURI(publicId); - if (resolvedURI != null) - { - result = cmDocumentCache.getCMDocument(resolvedURI); - } - return result; - } - - - /* (non-Javadoc) - * @see org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager#getCMDocument(java.lang.String, java.lang.String, java.lang.String) - */ -public CMDocument getCMDocument(String publicId, String systemId, String type) - { - CMDocument cmDocument = null; - String resolvedURI = null; - - if (getPropertyEnabled(PROPERTY_AUTO_LOAD)) - { - resolvedURI = lookupOrCreateResolvedURI(publicId, systemId); - } - else - { - resolvedURI = lookupResolvedURI(publicId); - } - - if (resolvedURI != null) - { - int status = cmDocumentCache.getStatus(resolvedURI); - if (status == CMDocumentCache.STATUS_LOADED) - { - cmDocument = cmDocumentCache.getCMDocument(resolvedURI); - } - else if (status == CMDocumentCache.STATUS_NOT_LOADED) - { - if (getPropertyEnabled(PROPERTY_AUTO_LOAD)) - { - cmDocument = loadCMDocument(publicId, resolvedURI, type, getPropertyEnabled(PROPERTY_ASYNC_LOAD)); - } - } - } - return cmDocument; - } - - public void addCMDocumentReference(String publicId, String systemId, String type) - { - String resolvedURI = lookupOrCreateResolvedURI(publicId, systemId); - if (resolvedURI != null && resolvedURI.length() > 0) - { - int status = cmDocumentCache.getStatus(resolvedURI); - if (status == CMDocumentCache.STATUS_NOT_LOADED) - { - loadCMDocument(publicId, resolvedURI, type, getPropertyEnabled(PROPERTY_ASYNC_LOAD)); - } - } - } - - - public void addCMDocument(String publicId, String systemId, String resolvedURI, String type, CMDocument cmDocument) - { - String key = publicId != null ? publicId : ""; //$NON-NLS-1$ - publicIdTable.put(key, resolvedURI); - cmDocumentCache.putCMDocument(resolvedURI, cmDocument); - } - - - protected CMDocument loadCMDocument(final String publicId, final String resolvedURI, final String type, boolean async) - { - CMDocument result = null; - - //System.out.println("about to build CMDocument(" + publicId + ", " + unresolvedURI + " = " + resolvedURI + ")"); - if (async) - { - cmDocumentCache.setStatus(resolvedURI, CMDocumentCache.STATUS_LOADING); - //Thread thread = new Thread(new AsyncBuildOperation(publicId, resolvedURI, type)); - //thread.start(); - Job job = new Job(XMLCoreMessages.loading + resolvedURI) - { - public boolean belongsTo(Object family) - { - boolean result = (family == CMDocumentManager.class); - return result; - } - - protected IStatus run(IProgressMonitor monitor) - { - try - { - buildCMDocument(publicId, resolvedURI, type); - } - catch (Exception e) - { - Logger.logException(e); - } - return Status.OK_STATUS; - } - }; - job.schedule(); - } - else - { - result = buildCMDocument(publicId, resolvedURI, type); - } - return result; - } - - - - public synchronized CMDocument buildCMDocument(String publicId, String resolvedURI, String type) - { - cmDocumentCache.setStatus(resolvedURI, CMDocumentCache.STATUS_LOADING); - - CMDocument result = null; - int x = 1; - x++; - if (resolvedURI != null && resolvedURI.length() > 0) - { - // TODO... pass the TYPE thru to the CMDocumentBuilder - result = ContentModelManager.getInstance().createCMDocument(resolvedURI, type); - } - if (result != null) - { - // load the annotation files for the document - if (publicId != null) - { - AnnotationUtility.loadAnnotationsForGrammar(publicId, result); - } - cmDocumentCache.putCMDocument(resolvedURI, result); - } - else - { - cmDocumentCache.setStatus(resolvedURI, CMDocumentCache.STATUS_ERROR); - } - return result; - } - - public void removeAllReferences() - { - // TODO... initiate a timed release of the entries in the CMDocumentCache - publicIdTable = new Hashtable(); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentReferenceImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentReferenceImpl.java deleted file mode 100644 index 10b9de25c8..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/CMDocumentReferenceImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentReference; - -public class CMDocumentReferenceImpl implements CMDocumentReference -{ - protected String systemId; - protected String publicId; - - public CMDocumentReferenceImpl(String publicId, String systemId) - { - this.publicId = publicId; - this.systemId = systemId; - } - - public String getPublicId() - { - return publicId; - } - - public String getSystemId() - { - return systemId; - } - - public String toString() - { - return "[" + publicId + ", " + systemId + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/InferredGrammarBuildingCMDocumentLoader.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/InferredGrammarBuildingCMDocumentLoader.java deleted file mode 100644 index 29d93f35c6..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/InferredGrammarBuildingCMDocumentLoader.java +++ /dev/null @@ -1,189 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import java.util.Hashtable; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.modelqueryimpl.InferredGrammarFactory; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - - -/** - * - */ -public class InferredGrammarBuildingCMDocumentLoader extends CMDocumentLoader -{ - protected CMElementDeclaration inferredCMElementDeclaration; - protected CMDocument inferredCMDocument; - protected InferredGrammarFactory inferredGrammarFactory; - protected Hashtable createdCMDocumentTable; - - public InferredGrammarBuildingCMDocumentLoader(Document document, ModelQuery modelQuery) - { - this(document, modelQuery.getCMDocumentManager()); - } - - public InferredGrammarBuildingCMDocumentLoader(Document document, CMDocumentManager cmDocumentManager) - { - super(document, cmDocumentManager); - createdCMDocumentTable = new Hashtable(); - inferredGrammarFactory = new InferredGrammarFactory(); - } - - - public void loadCMDocuments() - { - //System.out.println("----------loadCMDocuments ------------"); - if (inferredGrammarFactory != null) - { - //long time = System.currentTimeMillis(); - super.loadCMDocuments(); - //System.out.println("--- elapsed time (" + count + ") = " + (System.currentTimeMillis() - time)); - //inferredGrammarFactory.debugPrint(createdCMDocumentTable.values()); - } - - } - - public void handleElement(Element element) - { - CMElementDeclaration parentInferredCMElementDeclaration = inferredCMElementDeclaration; - - if (inferredCMDocument == null) - { - String cacheKey = "inferred-document"; //$NON-NLS-1$ - inferredCMDocument = inferredGrammarFactory.createCMDocument(""); //$NON-NLS-1$ - cmDocumentManager.addCMDocument("", "", cacheKey, "DTD", inferredCMDocument); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - createdCMDocumentTable.put(cacheKey, inferredCMDocument); - } - - inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, false); - - if (parentInferredCMElementDeclaration != null) - { - inferredGrammarFactory.createCMContent(inferredCMDocument, parentInferredCMElementDeclaration, inferredCMDocument, inferredCMElementDeclaration, false, null); - } - - - visitChildNodes(element); - - // reset the 'current' state to inital values - inferredCMElementDeclaration = parentInferredCMElementDeclaration; - } - - - public void handleElementNS(Element element) - { - CMDocument parentInferredCMDocument = inferredCMDocument; - CMElementDeclaration parentInferredCMElementDeclaration = inferredCMElementDeclaration; - - inferredCMDocument = null; - inferredCMElementDeclaration = null; - - // by adding the element to the namespaceTable, handleGrammar() will get called for any schema references - if (element.getParentNode() != document) - { - namespaceTable.addElement(element); - } - - String prefix = element.getPrefix(); - String uri = namespaceTable.getURIForPrefix(prefix); - - if (uri == null && element.getParentNode() == document) - { - // when this is the root element - // we need to add an implied "no namespace schema location" - uri = "ommitted-namespace"; //$NON-NLS-1$ - namespaceTable.addNamespaceInfo(prefix, uri, ""); //$NON-NLS-1$ - } - - // here's where we update the inferred grammar if required - // - boolean createCMElementDeclaration = true; - - boolean isLocal = (uri == null && prefix == null); - if (isLocal) - { - if (parentInferredCMDocument == null) - { - // this is a local element... and the parent is not inferred (e.g) it has a known grammar - // so we don't need to create an element declaration for this element - createCMElementDeclaration = false; - } - else - { - if (uri == null) - { - uri = "ommitted-namespace"; //$NON-NLS-1$ - } - } - } - - if (createCMElementDeclaration) - { - if (isLocal) - { - inferredCMDocument = parentInferredCMDocument; - inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, true); - } - else - { - boolean createCMDocument = false; - - String cacheKey = "inferred-document" + uri; //$NON-NLS-1$ - inferredCMDocument = (CMDocument)createdCMDocumentTable.get(cacheKey); - - if (inferredCMDocument == null) - { - // we don't have an inferred document for this uri yet... let's see of we need one - int status = cmDocumentManager.getCMDocumentStatus(uri); - if (status == CMDocumentCache.STATUS_NOT_LOADED || status == CMDocumentCache.STATUS_ERROR) - { - // the cache does not contain a 'proper' CMDocument for this uri - // so we need to create an inferred one - createCMDocument = true; - } - } - - if (createCMDocument) - { - //System.out.println("encountered element {" + element.getNodeName() + "} ... creating inferred CMDocument for " + uri); - inferredCMDocument = inferredGrammarFactory.createCMDocument(uri); - cmDocumentManager.addCMDocument(uri, "", cacheKey, "XSD", inferredCMDocument); //$NON-NLS-1$ //$NON-NLS-2$ - createdCMDocumentTable.put(cacheKey, inferredCMDocument); - } - - if (inferredCMDocument != null) - { - inferredCMElementDeclaration = inferredGrammarFactory.createCMElementDeclaration(inferredCMDocument, element, false); - } - } - - if (parentInferredCMElementDeclaration != null) - { - inferredGrammarFactory.createCMContent(parentInferredCMDocument, parentInferredCMElementDeclaration, inferredCMDocument, inferredCMElementDeclaration, isLocal, uri); - } - } - - visitChildNodes(element); - - // reset the 'current' state to inital values - inferredCMElementDeclaration = parentInferredCMElementDeclaration; - inferredCMDocument = parentInferredCMDocument; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/ModelQueryActionHelper.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/ModelQueryActionHelper.java deleted file mode 100644 index c813dac7f7..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/ModelQueryActionHelper.java +++ /dev/null @@ -1,574 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMValidator; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - - -/** - * - */ -public class ModelQueryActionHelper -{ - protected ModelQueryImpl modelQuery; - - protected static class Action implements ModelQueryAction - { - public int kind; - public int startIndex; - public int endIndex; - public Node parent; - public CMNode cmNode; - public Object userData; - - public Action(int kind, Node parent, CMNode cmNode) - { - this.kind = kind; - this.parent = parent; - this.cmNode = cmNode; - } - - public Action(int kind, Node parent, CMNode cmNode, int startIndex, int endIndex) - { - this.kind = kind; - this.parent = parent; - this.cmNode = cmNode; - this.startIndex = startIndex; - this.endIndex = endIndex; - } - - public int getKind() - { - return kind; - } - - public int getStartIndex() - { - return startIndex; - } - - public int getEndIndex() - { - return endIndex; - } - - public Node getParent() - { - return parent; - } - - public CMNode getCMNode() - { - return cmNode; - } - - public Object getUserData() - { - return userData; - } - - public void setUserData(Object object) - { - userData = object; - } - - public void performAction() - { - } - } - - - public ModelQueryActionHelper(ModelQueryImpl modelQuery) - { - this.modelQuery = modelQuery; - } - - - public void getAllActions(Element parent, CMElementDeclaration ed, int validityChecking, List actionList) - { - } - - - // insert actions - // - public void getInsertActions(Element parent, CMElementDeclaration ed, int index, int includeOptions, int validityChecking, List actionList) - { - if ((includeOptions & ModelQuery.INCLUDE_ATTRIBUTES) != 0) - { - getInsertAttributeActions(parent, ed, validityChecking, actionList); - } - includeOptions &= ~ModelQuery.INCLUDE_ATTRIBUTES; - if ((includeOptions & ModelQuery.INCLUDE_CHILD_NODES) != 0) - { - if (index != -1) - { - getInsertChildNodeActionsAtIndex(parent, ed, index, includeOptions, validityChecking, actionList); - } - else - { - getInsertChildNodeActions(parent, ed, includeOptions, validityChecking, actionList); - } - } - } - - - - protected void getInsertAttributeActions(Element parent, CMElementDeclaration ed, int validityChecking, List actionList) - { - // get actions for each insertable attribute - // - List availableAttributeList = modelQuery.getAvailableContent(parent, ed, ModelQuery.INCLUDE_ATTRIBUTES); - - for (Iterator i = availableAttributeList.iterator(); i.hasNext(); ) - { - CMAttributeDeclaration ad = (CMAttributeDeclaration)i.next(); - if (modelQuery.canInsert(parent, ed, ad, 0, validityChecking)) - { - Action action = new Action(ModelQueryAction.INSERT, parent, ad); - actionList.add(action); - } - } - } - - - protected void getInsertChildNodeActionsAtIndex(Element parent, CMElementDeclaration ed, int index, int includeOptions, int validityChecking, List actionList) - { - // get actions for each insertable attribute - // - int size = parent.getChildNodes().getLength(); - if (index <= size) - { - List contentSpecificationList = modelQuery.getValidator().createContentSpecificationList(parent, ed); - List availableChildNodeList = modelQuery.getAvailableContent(parent, ed, includeOptions); - - boolean isSimpleChoice = isSimpleChoiceGroupContentModel(ed); - - for (Iterator i = availableChildNodeList.iterator(); i.hasNext(); ) - { - CMNode cmNode = (CMNode)i.next(); - if (isSimpleChoice || modelQuery.canInsert(parent, ed, cmNode, index, validityChecking, contentSpecificationList)) - { - Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, index, index); - actionList.add(action); - } - } - } - } - - - protected boolean isSimpleChoiceGroupContentModel(CMElementDeclaration ed) - { - boolean result = false; - CMNode cmNode = ed.getContent(); - if (cmNode != null && cmNode.getNodeType() == CMNode.GROUP) - { - CMGroup cmGroup = (CMGroup)cmNode; - if (cmGroup.getOperator() == CMGroup.CHOICE && cmGroup.getMaxOccur() == -1) - { - result = true; - CMNodeList list = cmGroup.getChildNodes(); - for (int i = list.getLength() - 1; i >= 0; i--) - { - if (list.item(i).getNodeType() != CMNode.ELEMENT_DECLARATION) - { - result = false; - break; - } - } - } - } - return result; - } - - - protected void getInsertChildNodeActions(Element parent, CMElementDeclaration ed, int includeOptions, int validityChecking, List actionList) - { - int size = parent.getChildNodes().getLength(); - List contentSpecificationList = modelQuery.getValidator().createContentSpecificationList(parent, ed); - List availableChildNodeList = modelQuery.getAvailableContent(parent, ed, includeOptions); - - boolean isSimpleChoice = isSimpleChoiceGroupContentModel(ed); - - for (Iterator iterator = availableChildNodeList.iterator(); iterator.hasNext(); ) - { - CMNode cmNode = (CMNode)iterator.next(); - for (int i = size; i >= 0; i--) - { - if (isSimpleChoice || modelQuery.canInsert(parent, ed, cmNode, i, validityChecking, contentSpecificationList)) - { - Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, i, i); - actionList.add(action); - break; - } - } - } - } - - public void getInsertActions(Document parent, CMDocument cmDocument, int index, int includeOptions, int validityChecking, List actionList) - { - // get the root element and doctype index (if any) - // - int doctypeIndex = -1; - DocumentType doctype = null; - Element rootElement = null; - NodeList nodeList = parent.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) - { - Node childNode = nodeList.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE) - { - rootElement = (Element)childNode; - break; - } - else if (childNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) - { - doctype = (DocumentType)childNode; - doctypeIndex = i; - } - } - - // make sure that root elements are only added after the doctype (if any) - if (rootElement == null && index > doctypeIndex) - { - CMNamedNodeMap map = cmDocument.getElements(); - int mapLength = map.getLength(); - for (int i = 0; i < mapLength; i++) - { - CMNode cmNode = map.item(i); - - boolean canAdd = true; - if (validityChecking == ModelQuery.VALIDITY_STRICT) - { - canAdd = doctype == null || doctype.getName().equals(cmNode.getNodeName()); - } - - if (canAdd) - { - Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, index, index); - actionList.add(action); - } - } - } - } - - - - public void getInsertChildNodeActionTable(Element parent, CMElementDeclaration ed, int validityChecking, Hashtable actionTable) - { - } - - - public void getReplaceActions(Element parent, CMElementDeclaration ed, int includeOptions, int validityChecking, List actionList) - { - CMValidator.MatchModelNode matchModelNode = modelQuery.getValidator().getMatchModel(ed, parent); - if (matchModelNode != null) - { - MatchModelVisitor visitor = new MatchModelVisitor(parent, actionList); - visitor.visitMatchModelNode(matchModelNode); - } - } - - public void getReplaceActions(Element parent, CMElementDeclaration ed, List selectedChildren, int includeOptions, int validityChecking, List actionList) - { - int[] range = getRange(parent, selectedChildren); - if (range != null) - { - if (isContiguous(parent, range, selectedChildren)) - { - List tempList = new Vector(); - getReplaceActions(parent, ed, includeOptions, validityChecking, tempList); - if ((includeOptions & ModelQuery.INCLUDE_ENCLOSING_REPLACE_ACTIONS) != 0) - { - removeActionsNotContainingRange(tempList, range[0], range[1]); - } - else - { - removeActionsNotMatchingRange(tempList, range[0], range[1]); - } - actionList.addAll(tempList); - } - } - - if (selectedChildren.size() == 1) - { - Node node = (Node)selectedChildren.get(0); - if (node.getNodeType() == Node.ELEMENT_NODE) - { - Element childElement = (Element)node; - CMNode childEd = modelQuery.getCMElementDeclaration(childElement); - if (childEd != null) - { - - CMNode childOrigin= modelQuery.getOrigin(childElement); - - CMNodeList cmNodeList = childOrigin != null ? - (CMNodeList)childOrigin.getProperty("SubstitutionGroup") : //$NON-NLS-1$ - (CMNodeList)childEd.getProperty("SubstitutionGroup"); //$NON-NLS-1$ - - if (cmNodeList != null && cmNodeList.getLength() > 1) - { - int replaceIndex = getIndex(parent, childElement); - String childEdName = childEd.getNodeName(); - for (int i = 0; i < cmNodeList.getLength(); i++) - { - CMNode substitution = cmNodeList.item(i); - if (!substitution.getNodeName().equals(childEdName) && !Boolean.TRUE.equals(substitution.getProperty("Abstract"))) //$NON-NLS-1$ - { - Action action = new Action(ModelQueryAction.REPLACE, parent, cmNodeList.item(i), replaceIndex, replaceIndex); - actionList.add(action); - } - } - } - } - } - } - } - - - // returns true if the selected nodes are contiguous - // - protected boolean isContiguous(Element parent, int[] range, List selectedNodeList) - { - boolean result = true; - NodeList nodeList = parent.getChildNodes(); - // issue: nodeListLength was never read, but in theory, - // nodelList.getLength() might cause some clearing of cached - // data, or something, so leaving in a potential meaningless call, for now. - //int nodeListLength = nodeList.getLength(); - nodeList.getLength(); - for (int i = range[0]; i < range[1]; i++) - { - Node node = nodeList.item(i); - if (!isWhitespaceNode(node) && !selectedNodeList.contains(node)) - { - result = false; - break; - } - } - return result; - } - - - protected int[] getRange(Element parent, List list) - { - int[] result = null; - int first = -1; - int last = -1; - - NodeList nodeList = parent.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) - { - Node node = nodeList.item(i); - if (list.contains(node)) - { - first = (first == -1) ? i : Math.min(first, i); - last = Math.max(last, i); - } - } - - if (first != -1 && last!= -1) - { - result = new int[2]; - result[0] = first; - result[1] = last; - } - return result; - } - - - protected boolean isWhitespaceNode(Node node) - { - return node.getNodeType() == Node.TEXT_NODE && - node.getNodeValue().trim().length() == 0; - } - - - protected int getIndex(Node parentNode, Node child) - { - NodeList nodeList = parentNode.getChildNodes(); - int index = -1; - int size = nodeList.getLength(); - for (int i = 0; i < size; i++) - { - if (nodeList.item(i) == child) - { - index = i; - break; - } - } - return index; - } - - - protected boolean isActionContainingRange(ModelQueryAction action, int startIndex, int endIndex) - { - int actionStartIndex = action.getStartIndex(); - int actionEndIndex = action.getEndIndex(); - - return (actionStartIndex <= startIndex && - actionEndIndex >= endIndex); - } - - - protected boolean isActionMatchingRange(ModelQueryAction action, int startIndex, int endIndex) - { - int actionStartIndex = action.getStartIndex(); - int actionEndIndex = action.getEndIndex(); - return (actionStartIndex == startIndex && - actionEndIndex == endIndex); - } - - - protected void removeActionsNotContainingRange(List actionList, int startIndex, int endIndex) - { - for (int i = actionList.size() - 1; i >= 0; i--) - { - ModelQueryAction action = (ModelQueryAction)actionList.get(i); - if (!isActionContainingRange(action, startIndex, endIndex)) - { - actionList.remove(i); - } - } - } - - - protected void removeActionsNotMatchingRange(List actionList, int startIndex, int endIndex) - { - for (int i = actionList.size() - 1; i >= 0; i--) - { - ModelQueryAction action = (ModelQueryAction)actionList.get(i); - if (!isActionMatchingRange(action, startIndex, endIndex)) - { - actionList.remove(i); - } - } - } - - - public static class MatchModelVisitor - { - int indent; - int elementIndex; - Node parent; - List actionList; - - public MatchModelVisitor(Node parent, List actionList) - { - this.parent = parent; - this.actionList = actionList; - } - - public int indexOfNextElement(int start) - { - NodeList nodeList = parent.getChildNodes(); - int length = nodeList.getLength(); - int result = length; - for (int i = start; i < length; i++) - { - Node node = nodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) - { - result = i; - break; - } - } - return result; - } - - public void visitMatchModelNode(CMValidator.MatchModelNode matchModelNode) - { - int startIndex = indexOfNextElement(elementIndex); - - //String cmNodeName = matchModelNode.cmNode != null ? matchModelNode.cmNode.getNodeName() : "null"; - //printIndented(indent, "+MatchModelNode : " + cmNodeName + " " + startIndex); - - indent += 2; - for (Iterator iterator = matchModelNode.children.iterator(); iterator.hasNext(); ) - { - CMValidator.MatchModelNode child = (CMValidator.MatchModelNode)iterator.next(); - visitMatchModelNode(child); - } - indent -= 2; - - if (matchModelNode.cmNode != null) - { - int nodeType = matchModelNode.cmNode.getNodeType(); - if (nodeType == CMNode.GROUP) - { - CMGroup group = (CMGroup)matchModelNode.cmNode; - if (group.getOperator() == CMGroup.CHOICE) - { - addReplaceActions(matchModelNode, group, startIndex, elementIndex - 1); - } - } - else if (nodeType == CMNode.ELEMENT_DECLARATION) - { - elementIndex = startIndex + 1; - } - //printIndented(indent, "-MatchModelNode : " + cmNodeName + " " + (elementIndex - 1)); - } - } - - public void addReplaceActions(CMValidator.MatchModelNode matchModelNode, CMGroup group, int startIndex, int endIndex) - { - CMNode excludeCMNode = null; - if (matchModelNode.children.size() > 0) - { - CMValidator.MatchModelNode child = (CMValidator.MatchModelNode)matchModelNode.children.get(0); - excludeCMNode = child.cmNode; - } - - CMNodeList nodeList = group.getChildNodes(); - int size = nodeList.getLength(); - for (int i = 0; i < size; i++) - { - CMNode alternative = nodeList.item(i); - if (alternative != excludeCMNode) - { - Action action = new Action(ModelQueryAction.REPLACE, parent, alternative, startIndex, endIndex); - actionList.add(action); - } - } - } - } - - //public static void printIndented(int indent, String string) - //{ - // for (int i = 0; i < indent; i++) - // { - // System.out.print(" "); - // } - // System.out.println(string); - //} -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/ModelQueryImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/ModelQueryImpl.java deleted file mode 100644 index 1ff4182581..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/ModelQueryImpl.java +++ /dev/null @@ -1,856 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.modelqueryimpl.ModelQueryExtensionManagerImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMDataTypeValueHelper; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.DOMValidator; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAssociationProvider; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.ModelQueryExtensionManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMVisitor; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; - - -/** - * This class implements a large portion of the ModelQuery interfaces. - * Some work is delegated to the DOMHelper, CMDocumentManager, and DOMValidator. - */ -public class ModelQueryImpl implements ModelQuery -{ - protected ModelQueryAssociationProvider modelQueryAssociationProvider; - protected ModelQueryActionHelper modelQueryActionHelper; - protected DOMValidator validator; - protected ModelQueryExtensionManagerImpl extensionManager; - protected CMDataTypeValueHelper valueHelper; - protected int editMode = EDIT_MODE_CONSTRAINED_STRICT; - - public ModelQueryImpl(ModelQueryAssociationProvider modelQueryAssociationProvider) - { - this.modelQueryAssociationProvider = modelQueryAssociationProvider; - modelQueryActionHelper = createModelQueryActionHelper(); - validator = new DOMValidator(); - extensionManager = new ModelQueryExtensionManagerImpl(); - valueHelper = new CMDataTypeValueHelper(); - } - - public int getEditMode() - { - return editMode; - } - - public void setEditMode(int editMode) - { - this.editMode =editMode; - } - - - // factory methods - public ModelQueryActionHelper createModelQueryActionHelper() - { - return new ModelQueryActionHelper(this); - } - - public DOMValidator getValidator() - { - return validator; - } - - public CMDocument getCorrespondingCMDocument(Node node) - { - return modelQueryAssociationProvider.getCorrespondingCMDocument(node); - } - - public CMNode getCMNode(Node node) - { - return modelQueryAssociationProvider.getCMNode(node); - } - - public CMDataType getCMDataType(Text text) - { - return modelQueryAssociationProvider.getCMDataType(text); - } - - public CMAttributeDeclaration getCMAttributeDeclaration(Attr attr) - { - return modelQueryAssociationProvider.getCMAttributeDeclaration(attr); - } - - public CMElementDeclaration getCMElementDeclaration(Element element) - { - return modelQueryAssociationProvider.getCMElementDeclaration(element); - } - - public CMDocumentManager getCMDocumentManager() - { - CMDocumentManager result = null; - if (modelQueryAssociationProvider instanceof XMLAssociationProvider) - { - XMLAssociationProvider xmlAssociationProvider = (XMLAssociationProvider)modelQueryAssociationProvider; - result = xmlAssociationProvider.getCMDocumentManager(); - } - return result; - } - - - /** - * @deprected - use 3 arg version below - */ - public List getCMDocumentList(Element element, String uri) - { - return Collections.EMPTY_LIST; - } - - public List getCMDocumentList(Element element, CMElementDeclaration ed, String uri) - { - List result = new Vector(); - if (modelQueryAssociationProvider instanceof XMLAssociationProvider) - { - XMLAssociationProvider xmlAssociationProvider = (XMLAssociationProvider)modelQueryAssociationProvider; - - // todo... revist... handle each ##thing explicitly - // - if (uri == null) - { - uri = "##any"; //$NON-NLS-1$ - } - - if (uri.equals("##targetNamespace")) //$NON-NLS-1$ - { - CMDocument cmDocument = (CMDocument)ed.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - result.add(cmDocument); - } - } - else if (uri.equals("##any") || uri.equals("##other")) //$NON-NLS-1$ //$NON-NLS-2$ - { - String excludedURI = null; - if (uri.equals("##other")) //$NON-NLS-1$ - { - CMDocument cmDocument = (CMDocument)ed.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - excludedURI = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - } - } - - // in this case we should consider all of the schema related to this document - // - NamespaceTable namespaceTable = new NamespaceTable(element.getOwnerDocument()); - namespaceTable.addElementLineage(element); - List list = namespaceTable.getNamespaceInfoList(); - for (Iterator i = list.iterator(); i.hasNext();) - { - NamespaceInfo info = (NamespaceInfo)i.next(); - if (info.uri != null && !info.uri.equals(excludedURI)) - { - CMDocument document = xmlAssociationProvider.getCMDocument(info.uri, info.locationHint, "XSD"); //$NON-NLS-1$ - if (document != null) - { - result.add(document); - } - } - } - } - else - { - CMDocument document = xmlAssociationProvider.getCMDocument(element, uri); - if (document != null) - { - result.add(document); - } - } - } - return result; - } - - - public CMDocument getCMDocument(Element element, String uri) - { - - CMDocument result = null; - if (modelQueryAssociationProvider instanceof XMLAssociationProvider) - { - XMLAssociationProvider xmlAssociationProvider = (XMLAssociationProvider)modelQueryAssociationProvider; - result = xmlAssociationProvider.getCMDocument(element, uri); - } - //ContentModelManager.println("ModelQueryImpl.getCMDocument(" + element.getNodeName() + ", " + uri + ") = " + result); - return result; - } - - public boolean isContentValid(Element element) - { - CMElementDeclaration ed = getCMElementDeclaration(element); - return isContentValid(ed, element); - } - - public boolean isContentValid(CMElementDeclaration ed, Element element) - { - boolean result = true; - if (ed != null) - { - // first check to see if all the required attributes are present - // - CMNamedNodeMap map = ed.getAttributes(); - int mapLength = map.getLength(); - for (int i = 0; i < mapLength; i++) - { - CMAttributeDeclaration ad = (CMAttributeDeclaration)map.item(i); - String attributeName = DOMNamespaceHelper.computeName(ad, element, null); - if (ad.getUsage() == CMAttributeDeclaration.REQUIRED) - { - Attr attr = element.getAttributeNode(attributeName); - if (attr == null) - { - result = false; - break; - } - } - } - - // now check to see of the children validate properly - // - if (result) - { - CMNode[] originArray = getOriginArray(element); - result = originArray != null && originArray.length == element.getChildNodes().getLength(); - } - } - return result; - } - - - public CMNode getOrigin(Node node) - { - CMNode result = null; - // todo... make sure parent is right - // - Node parentNode = getParentOrOwnerNode(node); - if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) - { - Element parentElement = (Element)parentNode; - CMNode[] array = getOriginArray(parentElement); - if (array != null) - { - int index = getIndexOfNode(parentElement.getChildNodes(), node); - if (index < array.length) - { - result = array[index]; - } - } - } - return result; - } - - public CMNode[] getOriginArray(Element element) - { - CMElementDeclaration ed = getCMElementDeclaration(element); - return (ed != null) ? getValidator().getOriginArray(ed, element) : null; - } - - public int getIndexOfNode(NodeList nodeList, Node node) - { - int result = -1; - int size = nodeList.getLength(); - for (int i = 0; i < size; i++) - { - if (nodeList.item(i) == node) - { - result = i; - break; - } - } - return result; - } - - - /** - * Returns a list of all CMNode 'meta data' that may be potentially added to the element. - */ - public List getAvailableContent(Element element, CMElementDeclaration ed, int includeOptions) - { - AvailableContentCMVisitor visitor = new AvailableContentCMVisitor(element, ed); - List list = visitor.computeAvailableContent(includeOptions); - if (extensionManager != null) - { - extensionManager.filterAvailableElementContent(list, element, ed); - } - return list; - } - - - public boolean canInsert(Element parent, CMNode cmNode, int index, int validityChecking) - { - boolean result = true; - CMElementDeclaration ed = getCMElementDeclaration(parent); - if (ed != null) - { - result = canInsert(parent, ed, cmNode, index, validityChecking); - } - return result; - } - - - public boolean canInsert(Element parent, CMElementDeclaration ed, CMNode cmNode, int index, int validityChecking) - { - return canInsert(parent, ed, cmNode, index, validityChecking, null); - } - - protected boolean canInsert(Element parent, CMElementDeclaration ed, CMNode cmNode, int index, int validityChecking, Object reuseableData) - { - boolean result = true; - switch (cmNode.getNodeType()) - { - case CMNode.ATTRIBUTE_DECLARATION : - { - String attributeName = DOMNamespaceHelper.computeName(cmNode, parent, null); - result = parent.getAttributeNode(attributeName) == null; - break; - } - case CMNode.ELEMENT_DECLARATION : - case CMNode.GROUP : - { - if (validityChecking == VALIDITY_STRICT) - { - // create list - List contentSpecificationList = null; - if (reuseableData != null) - { - contentSpecificationList = (List)reuseableData; - } - else - { - contentSpecificationList = getValidator().createContentSpecificationList(parent, ed); - } - result = getValidator().canInsert(ed, contentSpecificationList, index, cmNode); - } - break; - } - case CMNode.DATA_TYPE : - { - int contentType = ed.getContentType(); - result = (contentType == CMElementDeclaration.MIXED || - contentType == CMElementDeclaration.PCDATA || - contentType == CMElementDeclaration.ANY); - break; - } - default : - { - result = false; - break; - } - } - return result; - } - - public boolean canInsert(Element parent, List cmNodeList, int index, int validityChecking) - { - // todo - return true; - } - - - public boolean canRemove(Node node, int validityChecking) - { - boolean result = true; - if (validityChecking == VALIDITY_STRICT) - { - int nodeType = node.getNodeType(); - switch (nodeType) - { - case Node.ATTRIBUTE_NODE: - { - CMAttributeDeclaration ad = getCMAttributeDeclaration((Attr)node); - if (ad != null) - { - result = (ad.getUsage() == CMAttributeDeclaration.OPTIONAL); - } - break; - } - case Node.ELEMENT_NODE: - { - Node parentNode = node.getParentNode(); - if (parentNode.getNodeType() == Node.ELEMENT_NODE) - { - Element parentElement = (Element)parentNode; - CMElementDeclaration ed = getCMElementDeclaration(parentElement); - if (ed != null) - { - List contentSpecificationList = getValidator().createContentSpecificationList(parentElement, ed); - int index = getIndexOfNode(parentElement.getChildNodes(), node); - result = getValidator().canRemove(ed, contentSpecificationList, index); - } - } - break; - } - } - } - return result; - } - - - 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; - } - - public boolean canReplace(Element parent, int startIndex, int endIndex, CMNode cmNode, int validityChecking) - { - return true; - } - - public boolean canReplace(Element parent, int startIndex, int endIndex, List cmNodeList, int validityChecking) - { - return true; - } - - /** - * 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; - } - - public void getInsertActions(Element parent, CMElementDeclaration ed, int index, int includeOptions, int validityChecking, List actionList) - { - modelQueryActionHelper.getInsertActions(parent, ed, index, includeOptions, validityChecking, actionList); - } - - public void getInsertActions(Document parent, CMDocument cmDocument, int index, int includeOptions, int validityChecking, List actionList) - { - modelQueryActionHelper.getInsertActions(parent, cmDocument, index, includeOptions, validityChecking, actionList); - } - - public void getReplaceActions(Element parent, CMElementDeclaration ed, int includeOptions, int validityChecking, List actionList) - { - modelQueryActionHelper.getReplaceActions(parent, ed, includeOptions, validityChecking, actionList); - } - - public void getReplaceActions(Element parent, CMElementDeclaration ed, List selectedChildren, int includeOptions, int validityChecking, List actionList) - { - modelQueryActionHelper.getReplaceActions(parent, ed, selectedChildren, includeOptions, validityChecking, actionList); - } - - public void getInsertChildNodeActionTable(Element parent, CMElementDeclaration ed, int validityChecking, Hashtable actionTable) - { - modelQueryActionHelper.getInsertChildNodeActionTable(parent, ed, validityChecking, actionTable); - } - - public void getActionTable(Element parent, CMElementDeclaration ed, int index, int validityChecking, Hashtable actionTable) - { - //modelQueryActionHelper.getAllActions(parent, ed, validityChecking, actionList); - } - - - // some helper methods - // - protected Node getParentOrOwnerNode(Node node) - { - return (node.getNodeType() == Node.ATTRIBUTE_NODE) ? - ((Attr)node).getOwnerElement() : - node.getParentNode(); - } - - protected Element getParentOrOwnerElement(Node node) - { - Node parent = getParentOrOwnerNode(node); - return (parent.getNodeType() == Node.ELEMENT_NODE) ? (Element)parent : null; - } - - - protected List nodeListToList(NodeList nodeList) - { - int size = nodeList.getLength(); - Vector v = new Vector(size); - for (int i = 0; i < size; i++) - { - v.add(nodeList.item(i)); - } - return v; - } - - /** - protected List getCMNodeList(NodeList nodeList) - { - int size = nodeList.getLength(); - Vector v = new Vector(size); - for (int i = 0; i < size; i++) - { - v.add(getCMNode(nodeList.item(i)); - } - return v; - } - */ - - public class AvailableContentCMVisitor extends CMVisitor - { - public Hashtable childNodeTable = new Hashtable(); - public Hashtable attributeTable = new Hashtable(); - public Element rootElement; - public CMElementDeclaration rootElementDeclaration; - public boolean isRootVisited; - protected boolean includeSequenceGroups; - - public AvailableContentCMVisitor(Element rootElement, CMElementDeclaration rootElementDeclaration) - { - this.rootElement = rootElement; - this.rootElementDeclaration = rootElementDeclaration; - } - - protected String getKey(CMNode cmNode) - { - String key = cmNode.getNodeName(); - CMDocument cmDocument = (CMDocument)cmNode.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - String namespaceURI = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - if (namespaceURI != null) - { - key = "[" + namespaceURI + "]" + key; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - return key; - } - - protected void addToTable(Hashtable table, CMNode cmNode) - { - String nodeName = cmNode.getNodeName(); - if (nodeName != null && nodeName.length() > 0) - { - table.put(getKey(cmNode), cmNode); - } - } - - public List computeAvailableContent(int includeOptions) - { - Vector v = new Vector(); - - int contentType = rootElementDeclaration.getContentType(); - includeSequenceGroups = ((includeOptions & INCLUDE_SEQUENCE_GROUPS) != 0); - visitCMNode(rootElementDeclaration); - - if ((includeOptions & INCLUDE_ATTRIBUTES) != 0) - { - v.addAll(attributeTable.values()); - CMAttributeDeclaration nillableAttribute = (CMAttributeDeclaration)rootElementDeclaration.getProperty("http://org.eclipse.wst/cm/properties/nillable"); //$NON-NLS-1$ - if (nillableAttribute != null) - { - v.add(nillableAttribute); - } - } - - if ((includeOptions & INCLUDE_CHILD_NODES) != 0) - { - if (contentType == CMElementDeclaration.MIXED || - contentType == CMElementDeclaration.ELEMENT) - { - v.addAll(childNodeTable.values()); - } - else if (contentType == CMElementDeclaration.ANY) - { - CMDocument cmDocument = (CMDocument)rootElementDeclaration.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - CMNamedNodeMap elements = cmDocument.getElements(); - for (Iterator i = elements.iterator(); i.hasNext(); ) - { - v.add(i.next()); - } - } - } - - if (contentType == CMElementDeclaration.MIXED || - contentType == CMElementDeclaration.PCDATA || - contentType == CMElementDeclaration.ANY) - { - CMDataType dataType = rootElementDeclaration.getDataType(); - if (dataType != null) - { - v.add(dataType); - } - } - } - return v; - } - - public void visitCMAnyElement(CMAnyElement anyElement) - { - String uri = anyElement.getNamespaceURI(); - List list = getCMDocumentList(rootElement, rootElementDeclaration, uri); - for (Iterator iterator = list.iterator(); iterator.hasNext(); ) - { - CMDocument cmdocument = (CMDocument)iterator.next(); - if (cmdocument != null) - { - CMNamedNodeMap map = cmdocument.getElements(); - int size = map.getLength(); - for (int i = 0; i < size; i++) - { - CMNode ed = map.item(i); - addToTable(childNodeTable,ed); - } - } - } - } - - public void visitCMAttributeDeclaration(CMAttributeDeclaration ad) - { - super.visitCMAttributeDeclaration(ad); - attributeTable.put(ad.getNodeName(), ad); - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) - { - if (ed == rootElementDeclaration && !isRootVisited) - { - isRootVisited = true; - super.visitCMElementDeclaration(ed); - } - else - { - if (!Boolean.TRUE.equals(ed.getProperty("Abstract"))) //$NON-NLS-1$ - { - addToTable(childNodeTable,ed); - } - - CMNodeList substitutionGroup = (CMNodeList)ed.getProperty("SubstitutionGroup"); //$NON-NLS-1$ - if (substitutionGroup != null) - { - handleSubstitutionGroup(substitutionGroup); - } - } - } - - protected void handleSubstitutionGroup(CMNodeList substitutionGroup) - { - int substitutionGroupLength = substitutionGroup.getLength(); - if (substitutionGroupLength > 1) - { - for (int i = 0; i < substitutionGroupLength; i++) - { - CMNode ed = substitutionGroup.item(i); - if (!Boolean.TRUE.equals(ed.getProperty("Abstract"))) //$NON-NLS-1$ - { - addToTable(childNodeTable,ed); - } - } - } - } - - public void visitCMGroup(CMGroup group) - { - if (includeSequenceGroups) - { - if (group.getOperator() == CMGroup.SEQUENCE && - group.getChildNodes().getLength() > 1 && - includesRequiredContent(group)) - { - childNodeTable.put(group, group); - } - } - super.visitCMGroup(group); - } - - public boolean includesRequiredContent(CMGroup group) - { - List list = getValidator().createContentSpecificationList(group); - return list.size() > 1; - } - } - - - /** - * @deprected - use getPossibleDataTypeValues() - */ - public List getDataTypeValues(Element element, CMNode cmNode) - { - return Arrays.asList(getPossibleDataTypeValues(element, cmNode)); - } - - /** - * 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 Vector(); - - 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)); - } - - int listSize = list.size(); - String[] result = new String[listSize]; - for (int i = 0; i < listSize; i++) - { - result[i] = (String)list.get(i); - } - return result; - } - - - protected void addValuesForXSIType(Element element, CMNode cmNode, List list) - { - if (cmNode != null && cmNode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) - { - CMAttributeDeclaration ad = (CMAttributeDeclaration)cmNode; - if (valueHelper.isXSIType(ad)) - { - NamespaceTable table = new NamespaceTable(element.getOwnerDocument()); - table.addElementLineage(element); - list.addAll(valueHelper.getQualifiedXSITypes(ad, table)); - } - } - } - - - public ModelQueryExtensionManager getExtensionManager() - { - return extensionManager; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/SimpleAssociationProvider.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/SimpleAssociationProvider.java deleted file mode 100644 index 0331531c25..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/SimpleAssociationProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryCMProvider; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -/** - * - */ -public class SimpleAssociationProvider extends BaseAssociationProvider -{ - protected ModelQueryCMProvider modelQueryCMProvider; - - public SimpleAssociationProvider(ModelQueryCMProvider modelQueryCMProvider) - { - this.modelQueryCMProvider = modelQueryCMProvider; - } - - public CMDocument getCorrespondingCMDocument(Node node) - { - return modelQueryCMProvider.getCorrespondingCMDocument(node); - } - - public CMElementDeclaration getCMElementDeclaration(Element element) - { - CMElementDeclaration result = null; - CMDocument cmDocument = getCorrespondingCMDocument(element); - if (cmDocument != null) - { - result = (CMElementDeclaration)cmDocument.getElements().getNamedItem(element.getNodeName()); - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/XMLAssociationProvider.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/XMLAssociationProvider.java deleted file mode 100644 index 646629a533..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelqueryimpl/XMLAssociationProvider.java +++ /dev/null @@ -1,403 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.xml.core.internal.Logger; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentReferenceProvider; -import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - - -/** - * - */ -public abstract class XMLAssociationProvider extends BaseAssociationProvider implements CMDocumentReferenceProvider -{ - protected CMDocumentCache cmDocumentCache; - protected CMDocumentManagerImpl documentManager; - - public XMLAssociationProvider(CMDocumentCache cmDocumentCache) - { - this.cmDocumentCache = cmDocumentCache; - documentManager = new CMDocumentManagerImpl(cmDocumentCache, this); - } - - public CMDocumentManager getCMDocumentManager() - { - return documentManager; - } - - - public static String[] getDoctypeInfo(Document document) - { - String[] result = null; - DocumentType doctype = document.getDoctype(); - - // defect 206833 ... here we test for DTDs that are declared inline - // since we currently have no way of making use of inline DTDs we ingore them - // so that the implict DTD (if any) can be used - if (doctype != null && (doctype.getPublicId() != null || doctype.getSystemId() != null)) - { - result = new String[2]; - result[0] = doctype.getPublicId(); - result[1] = doctype.getSystemId(); - } - else if (getImplictDoctype(document) != null) - { - result = getImplictDoctype(document); - } - return result; - } - - - protected static String[] getImplictDoctype(Document document) - { - String[] result = null; - /* - DOMExtension domExtension = DOMExtensionProviderRegistry.getInstance().getDOMExtension(document); - if (domExtension != null) - { - result = domExtension.getImplicitDoctype(); - }*/ - return result; - } - - public CMDocument getCorrespondingCMDocument(Node node) - { - return getCorrespondingCMDocument(node, true); - } - - protected CMDocument getCorrespondingCMDocument(Node node, boolean getDocumentFromCMNode) - { - CMDocument result = null; - try - { - Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document)node : node.getOwnerDocument(); - - String[] doctypeInfo = getDoctypeInfo(document); - - if (doctypeInfo != null) - { - result = getCMDocument(doctypeInfo[0], doctypeInfo[1], "DTD"); //$NON-NLS-1$ - } - // defect 211236 ... in some cases calling this method can result in a cycle - // we use the getDocumentFromCMNode as a flag to avoid this - // TODO... see if there is a way to re-organize to avoid the need for this flag - else if (getDocumentFromCMNode) - { - CMNode cmNode = getCMNode(node); - if (cmNode != null) - { - // todo... add a getCMDocument() methods to CMNode - // for now use the getProperty interface - result = (CMDocument)cmNode.getProperty("CMDocument"); //$NON-NLS-1$ - } - } - } - catch (Exception e) - { - Logger.logException("exception locating CMDocument for " + node, e); //$NON-NLS-1$ - } - return result; - } - - - public CMDocument getCMDocument(Element element, String uri) - { - CMDocument result = null; - NamespaceTable namespaceTable = new NamespaceTable(element.getOwnerDocument()); - namespaceTable.addElementLineage(element); - NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForURI(uri); - if (namespaceInfo != null) - { - result = getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD"); //$NON-NLS-1$ - } - return result; - } - - - public CMDocument getCMDocument(String publicId, String systemId, String type) - { - //String resolvedGrammarURI = resolveGrammarURI(document, publicId, systemId); - return documentManager.getCMDocument(publicId, systemId, type); - } - - //public CMDocument getCMDocument(Document document, String publicId, String systemId) - //{ - // //String resolvedGrammarURI = resolveGrammarURI(document, publicId, systemId); - // return documentManager.getCMDocument(publicId, systemId); - //} - - public String resolveGrammarURI(String publicId, String systemId) - { - return resolveGrammarURI(null, publicId, systemId); - } - - - /** - * This method should be specialized in order to implement specialized uri resolution - */ - protected String resolveGrammarURI(Document document, String publicId, String systemId) - { - return systemId; - } - - - public CMElementDeclaration getCMElementDeclaration(Element element) - { - CMElementDeclaration result = null; - Document document = element.getOwnerDocument(); - String[] doctypeInfo = getDoctypeInfo(document); - if (doctypeInfo != null) - { - // we have detected doctype information so we assume that we can locate the CMElementDeclaration - // in the CMDocument's table of global elements - CMDocument cmDocument = getCorrespondingCMDocument(element, false); - - // TODO... consider replacing above with - // CMDocument cmDocument = getCMDocument(document, doctypeInfo[0], doctypeInfo[1]); - - if (cmDocument != null) - { - result = (CMElementDeclaration)cmDocument.getElements().getNamedItem(element.getNodeName()); - - // this is a hack to get our xsl code assist working... we might want to handle similar - // grammar behaviour via some established model query setting - if (result == null && getImplictDoctype(document) != null) - { - Node parent = element.getParentNode(); - if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) - { - result = getCMElementDeclaration((Element)parent); - } - } - } - } - else - { - // here we use a namespaceTable to consider if the root element has any namespace information - // - NamespaceTable namespaceTable = new NamespaceTable(element.getOwnerDocument()); - List list = NamespaceTable.getElementLineage(element); - Element rootElement = (Element)list.get(0); - namespaceTable.addElement(rootElement); - - if (namespaceTable.isNamespaceEncountered()) - { - // we assume that this is an XMLSchema style namespace aware document - result = getCMElementDeclaration(element, list, namespaceTable); - } - else - { - // we assume that this is an inferred CMDocument for a DTD style 'namespaceless' document - CMDocument cmDocument = getCMDocument("", "", "DTD"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (cmDocument != null) - { - result = (CMElementDeclaration)cmDocument.getElements().getNamedItem(element.getNodeName()); - } - } - } - return result; - } - - - 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; - - // see if the element is a local of the currentED - // - if (currentED != null) - { - ed = (CMElementDeclaration)currentED.getLocalElements().getNamedItem(unprefixedName); - } - - if (ed == null) - { - NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(prefix); - if (namespaceInfo != null) - { - CMDocument cmDocument = getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD"); //$NON-NLS-1$ - 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) - { - Logger.logException("exception locating element declaration for " + targetElement, e); //$NON-NLS-1$ - } - - return currentED; - } - - - protected CMElementDeclaration getDerivedCMElementDeclaration(Element element, CMElementDeclaration ed, NamespaceTable namespaceTable) - { - CMElementDeclaration result = null; - String xsiPrefix = namespaceTable.getPrefixForURI("http://www.w3.org/2001/XMLSchema-instance"); //$NON-NLS-1$ - if (xsiPrefix != null) - { - String xsiTypeValue = element.getAttribute(xsiPrefix + ":type"); //$NON-NLS-1$ - if (xsiTypeValue != null) - { - String typePrefix = DOMNamespaceHelper.getPrefix(xsiTypeValue); - String typeName = DOMNamespaceHelper.getUnprefixedName(xsiTypeValue); - String typeURI = namespaceTable.getURIForPrefix(typePrefix); - String uriQualifiedTypeName = typeName; - if (typeURI != null && typeURI.length() > 0) - { - uriQualifiedTypeName = "[" + typeURI + "]" + typeName; //$NON-NLS-1$ //$NON-NLS-2$ - } - result = (CMElementDeclaration)ed.getProperty("DerivedElementDeclaration=" + uriQualifiedTypeName); //$NON-NLS-1$ - } - } - return result; - } - - - 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; - } - - /** - * This method returns a list of CMDocumentReferences associated with a particular node or subtree - */ - public List getCMDocumentReferences(Node node, boolean deep) - { - List result = new ArrayList(); - Document document = (node.getNodeType() == Node.DOCUMENT_NODE) ? (Document)node : node.getOwnerDocument(); - DocumentType doctype = document.getDoctype(); - // defect 206833 ... here we test for DTDs that are declared inline - // since we currently have no way of making use of inline DTDs we ingore them - // so that the implict DTD (if any) can be used - if (doctype != null && (doctype.getPublicId() != null || doctype.getSystemId() != null)) - { - String uri = resolveGrammarURI(document, doctype.getPublicId(), doctype.getSystemId()); - result.add(new CMDocumentReferenceImpl(doctype.getPublicId(), uri)); - } - else if (getImplictDoctype(document) != null) - { - String[] implicitDoctype = getImplictDoctype(document); - String uri = resolveGrammarURI(document, implicitDoctype[0], implicitDoctype[1]); - result.add(new CMDocumentReferenceImpl(implicitDoctype[0], uri)); - } - else - { - NamespaceTable namespaceTable = new NamespaceTable(document); - if (node.getNodeType() == Node.ELEMENT_NODE) - { - namespaceTable.addElement((Element)node); - } - if (deep) - { - addChildElementsToNamespaceTable(node, namespaceTable); - } - List list = namespaceTable.getNamespaceInfoList(); - for (Iterator i = list.iterator(); i.hasNext();) - { - NamespaceInfo info = (NamespaceInfo) i.next(); - String uri = resolveGrammarURI(document, info.uri, info.locationHint); - result.add(new CMDocumentReferenceImpl(info.uri, uri)); - } - } - return result; - } - - protected void addChildElementsToNamespaceTable(Node node, NamespaceTable namespaceTable) - { - NodeList nodeList = node.getChildNodes(); - if (nodeList != null) - { - int nodeListLength = nodeList.getLength(); - for (int i = 0; i < nodeListLength; i++) - { - Node childNode = nodeList.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE) - { - namespaceTable.addElement((Element)childNode); - addChildElementsToNamespaceTable(childNode, namespaceTable); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDescriptionBuilder.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDescriptionBuilder.java deleted file mode 100644 index b55003a49f..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDescriptionBuilder.java +++ /dev/null @@ -1,138 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; - -public class CMDescriptionBuilder extends CMVisitor -{ - protected StringBuffer sb; - protected CMNode root; - protected boolean isRootVisited; - - public String buildDescription(CMNode node) - { - sb = new StringBuffer(); - root = node; - isRootVisited = false; - visitCMNode(node); - return sb.toString(); - } - - public void visitCMAnyElement(CMAnyElement anyElement) - { - sb.append("namespace:uri=\"" + anyElement.getNamespaceURI() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void visitCMDataType(CMDataType dataType) - { - sb.append("#PCDATA"); //$NON-NLS-1$ - } - - public void visitCMDocument(CMDocument document) - { - CMNamedNodeMap map = document.getElements(); - int size = map.getLength(); - for (int i = 0; i < size; i++) - { - visitCMNode(map.item(i)); - } - } - - public void visitCMGroup(CMGroup group) - { - int op = group.getOperator(); - if (op == CMGroup.ALL) - { - sb.append("all"); //$NON-NLS-1$ - } - - sb.append("("); //$NON-NLS-1$ - - String separator = ", "; //$NON-NLS-1$ - - if (op == CMGroup.CHOICE) - { - separator = " | "; //$NON-NLS-1$ - } - - CMNodeList nodeList = group.getChildNodes(); - int size = nodeList.getLength(); - for (int i = 0; i < size; i++) - { - visitCMNode(nodeList.item(i)); - if (i < size - 1) - { - sb.append(separator); - } - } - sb.append(")"); //$NON-NLS-1$ - addOccurenceSymbol(group); - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) - { - if (ed == root && !isRootVisited) - { - isRootVisited = true; - CMContent content = ed.getContent(); - if (content != null) - { - if (content.getNodeType() != CMNode.GROUP) - { - sb.append("("); //$NON-NLS-1$ - visitCMNode(content); - sb.append(")"); //$NON-NLS-1$ - } - else - { - visitCMNode(content); - } - } - } - else - { - sb.append(ed.getElementName()); - addOccurenceSymbol(ed); - } - } - - public void addOccurenceSymbol(CMContent content) - { - int min = content.getMinOccur(); - int max = content.getMaxOccur(); - if (min == 0) - { - if (max > 1 || max == -1) - { - sb.append("*"); //$NON-NLS-1$ - } - else - { - sb.append("?"); //$NON-NLS-1$ - } - } - else if (max > 1 || max == -1) - { - sb.append("+"); //$NON-NLS-1$ - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java deleted file mode 100644 index 961878a3ab..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java +++ /dev/null @@ -1,203 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; - - - -/** - * - */ -public class CMDocumentCache -{ - public static final int STATUS_NOT_LOADED = 0; - public static final int STATUS_LOADING = 2; - public static final int STATUS_LOADED = 3; - public static final int STATUS_ERROR = 4; - - protected class Entry - { - public String uri; - public int status = STATUS_NOT_LOADED; - public float progress; - public CMDocument cmDocument; - - public Entry(String uri) - { - this.uri = uri; - } - - public Entry(String uri, int status, CMDocument cmDocument) - { - this.uri = uri; - this.status = status; - this.cmDocument = cmDocument; - } - } - - protected Hashtable hashtable; - protected List listenerList = new Vector(); - - - /** - * temporarily public until caching problem is solved - */ - public CMDocumentCache() - { - hashtable = new Hashtable(); - } - - public void addListener(CMDocumentCacheListener listener) - { - listenerList.add(listener); - } - - public void removeListener(CMDocumentCacheListener listener) - { - listenerList.remove(listener); - } - - /** - * - */ - public CMDocument getCMDocument(String grammarURI) - { - CMDocument result = null; - if (grammarURI != null) - { - Entry entry = (Entry)hashtable.get(grammarURI); - if (entry != null) - { - result = entry.cmDocument; - } - } - return result; - } - - /** - * - */ - public int getStatus(String grammarURI) - { - int result = STATUS_NOT_LOADED; - if (grammarURI != null) - { - Entry entry = (Entry)hashtable.get(grammarURI); - if (entry != null) - { - result = entry.status; - } - - } - return result; - } - - /** - * - */ - protected Entry lookupOrCreate(String grammarURI) - { - Entry entry = (Entry)hashtable.get(grammarURI); - if (entry == null) - { - entry = new Entry(grammarURI); - hashtable.put(grammarURI, entry); - } - return entry; - } - - - /** - * - */ - public void putCMDocument(String grammarURI, CMDocument cmDocument) - { - if (grammarURI != null && cmDocument != null) - { - Entry entry = lookupOrCreate(grammarURI); - int oldStatus = entry.status; - entry.status = STATUS_LOADED; - entry.cmDocument = cmDocument; - notifyCacheUpdated(grammarURI, oldStatus, entry.status, entry.cmDocument); - } - } - - /** - * - */ - public void setStatus(String grammarURI, int status) - { - if (grammarURI != null) - { - Entry entry = lookupOrCreate(grammarURI); - int oldStatus = entry.status; - entry.status = status; - notifyCacheUpdated(grammarURI, oldStatus, entry.status, entry.cmDocument); - } - } - - /** - * - */ - public void clear() - { - hashtable.clear(); - notifyCacheCleared(); - } - - /** - * - */ - protected void notifyCacheUpdated(String uri, int oldStatus, int newStatus, CMDocument cmDocument) - { - List list = new Vector(); - list.addAll(listenerList); - for (Iterator i = list.iterator(); i.hasNext(); ) - { - CMDocumentCacheListener listener = (CMDocumentCacheListener)i.next(); - listener.cacheUpdated(this, uri, oldStatus, newStatus, cmDocument); - } - } - - /** - * - */ - protected void notifyCacheCleared() - { - List list = new Vector(); - list.addAll(listenerList); - for (Iterator i = list.iterator(); i.hasNext(); ) - { - CMDocumentCacheListener listener = (CMDocumentCacheListener)i.next(); - listener.cacheCleared(this); - } - } - - public List getCMDocuments() - { - List list = new ArrayList(); - for (Iterator i = hashtable.values().iterator(); i.hasNext(); ) - { - Entry entry = (Entry)i.next(); - list.add(entry.cmDocument); - } - return list; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCacheListener.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCacheListener.java deleted file mode 100644 index 4843d1eb49..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCacheListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; - - -/** - * todo... add more interface methods - */ -public interface CMDocumentCacheListener -{ - /** Tells the client that the cache has been cleared. - * This gives clients an opportunity to flush any state that depends on the CMDocument - * since this CMDocument will be recomputed on a subsequent 'lookup' request - */ - public void cacheCleared(CMDocumentCache cache); - - /** - * Tells the client that the cache has been updated. - */ - public void cacheUpdated(CMDocumentCache cache, String uri, int oldStatus, int newStatus, CMDocument cmDocument); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMVisitor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMVisitor.java deleted file mode 100644 index 68f78a745e..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMVisitor.java +++ /dev/null @@ -1,118 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; - -public class CMVisitor -{ - protected int indent = 0; - - public void visitCMNode(CMNode node) - { - if (node != null) - { - //ContentModelManager.printlnIndented("visitCMNode : " + node.getNodeName() + " " + node); - indent += 2; - int nodeType = node.getNodeType(); - switch (nodeType) - { - case CMNode.ANY_ELEMENT : - { - visitCMAnyElement((CMAnyElement)node); - break; - } - case CMNode.ATTRIBUTE_DECLARATION : - { - visitCMAttributeDeclaration((CMAttributeDeclaration)node); - break; - } - case CMNode.DATA_TYPE : - { - visitCMDataType((CMDataType)node); - break; - } - case CMNode.DOCUMENT : - { - visitCMDocument((CMDocument)node); - break; - } - case CMNode.ELEMENT_DECLARATION : - { - visitCMElementDeclaration((CMElementDeclaration)node); - break; - } - case CMNode.GROUP : - { - visitCMGroup((CMGroup)node); - break; - } - } - indent -= 2; - } - } - - public void visitCMAnyElement(CMAnyElement anyElement) - { - } - - public void visitCMAttributeDeclaration(CMAttributeDeclaration ad) - { - } - - public void visitCMDataType(CMDataType dataType) - { - } - - public void visitCMDocument(CMDocument document) - { - CMNamedNodeMap map = document.getElements(); - int size = map.getLength(); - for (int i = 0; i < size; i++) - { - visitCMNode(map.item(i)); - } - } - - public void visitCMGroup(CMGroup group) - { - CMNodeList nodeList = group.getChildNodes(); - int size = nodeList.getLength(); - for (int i = 0; i < size; i++) - { - visitCMNode(nodeList.item(i)); - } - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) - { - CMNamedNodeMap nodeMap = ed.getAttributes(); - int size = nodeMap.getLength(); - for (int i = 0; i < size; i++) - { - visitCMNode(nodeMap.item(i)); - } - - visitCMNode(ed.getContent()); - - visitCMDataType(ed.getDataType()); - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/ContentBuilder.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/ContentBuilder.java deleted file mode 100644 index 841de7421c..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/ContentBuilder.java +++ /dev/null @@ -1,171 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; - - -/** - * This class lets you traverse a 'CM' model providing callbacks to build content. - */ -public class ContentBuilder extends CMVisitor -{ - public static final int BUILD_ALL_CONTENT = 1; - public static final int BUILD_ONLY_REQUIRED_CONTENT = 2; - protected int buildPolicy = BUILD_ALL_CONTENT; - - protected boolean alwaysVisit; - protected Vector visitedCMElementDeclarationList = new Vector(); - - public ContentBuilder() - { - } - - public void setBuildPolicy(int buildPolicy) - { - this.buildPolicy = buildPolicy; - } - - public int getBuildPolicy() - { - return buildPolicy; - } - - protected void createAnyElementNode(CMAnyElement anyElement) - { - } - - protected void createElementNodeStart(CMElementDeclaration ed) - { - } - - protected void createElementNodeEnd(CMElementDeclaration ed) - { - } - - protected void createTextNode(CMDataType dataType) - { - } - - protected void createAttributeNode(CMAttributeDeclaration attribute) - { - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) - { - int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0; - int min = Math.max(ed.getMinOccur(), forcedMin); - alwaysVisit = false; - - if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) - { - visitedCMElementDeclarationList.add(ed); - for (int i = 1; i <= min; i++) - { - createElementNodeStart(ed); - - // instead of calling super.visitCMElementDeclaration() - // we duplicate the code with some minor modifications - CMNamedNodeMap nodeMap = ed.getAttributes(); - int size = nodeMap.getLength(); - for (int j = 0; j < size; j++) - { - visitCMNode(nodeMap.item(j)); - } - - CMContent content = ed.getContent(); - if (content != null) - { - visitCMNode(content); - } - - if (ed.getContentType() == CMElementDeclaration.PCDATA) - { - CMDataType dataType = ed.getDataType(); - if (dataType != null) - { - visitCMDataType(dataType); - } - } - // end duplication - createElementNodeEnd(ed); - } - int size = visitedCMElementDeclarationList.size(); - visitedCMElementDeclarationList.remove(size - 1); - } - } - - - public void visitCMDataType(CMDataType dataType) - { - createTextNode(dataType); - } - - - public void visitCMGroup(CMGroup e) - { - int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0; - int min = Math.max(e.getMinOccur(), forcedMin); - alwaysVisit = false; - - for (int i = 1; i <= min; i++) - { - if (e.getOperator() == CMGroup.CHOICE) - { - // add only 1 element from the group - // todo... perhaps add something other than the first one - CMNodeList nodeList = e.getChildNodes(); - if (nodeList.getLength() > 0) - { - visitCMNode(nodeList.item(0)); - } - } - else // SEQUENCE, ALL - { - // visit all of the content - super.visitCMGroup(e); - } - } - } - - public void visitCMAttributeDeclaration(CMAttributeDeclaration ad) - { - if (alwaysVisit || - buildPolicy == BUILD_ALL_CONTENT || - ad.getUsage() == CMAttributeDeclaration.REQUIRED) - { - createAttributeNode(ad); - } - } - - - public void visitCMAnyElement(CMAnyElement anyElement) - { - int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0; - alwaysVisit = false; - int min = Math.max(anyElement.getMinOccur(), forcedMin); - for (int i = 1; i <= min; i++) - { - createAnyElementNode(anyElement); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilder.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilder.java deleted file mode 100644 index 8b6dda7eae..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.List; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.w3c.dom.Node; - - -public interface DOMContentBuilder -{ - public static final int BUILD_OPTIONAL_ATTRIBUTES = 1; - public static final int BUILD_OPTIONAL_ELEMENTS = 1<<1; - public static final int BUILD_FIRST_CHOICE = 1<<2; - public static final int BUILD_TEXT_NODES = 1<<3; - public static final int BUILD_FIRST_SUBSTITUTION = 1<<4; - - public static final int - BUILD_ONLY_REQUIRED_CONTENT = - BUILD_FIRST_CHOICE - | BUILD_TEXT_NODES; - public static final int - BUILD_ALL_CONTENT = - BUILD_OPTIONAL_ATTRIBUTES - | BUILD_OPTIONAL_ELEMENTS - | BUILD_FIRST_CHOICE - | BUILD_TEXT_NODES; - - public static final String PROPERTY_BUILD_BLANK_TEXT_NODES = "buildBlankTextNodes"; //$NON-NLS-1$ - - public void setBuildPolicy(int buildPolicy); - public int getBuildPolicy(); - public void setProperty(String propertyName, Object value); - public Object getProperty(String propertyName); - public List getResult(); - public void build(Node parent, CMNode child); - public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration) throws Exception; - public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration, List namespaceInfoList) throws Exception; - public void createDefaultContent(Node parent, CMElementDeclaration ed) throws Exception; -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java deleted file mode 100644 index f07e8ddc77..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java +++ /dev/null @@ -1,692 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.Hashtable; -import java.util.List; -import java.util.Stack; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMContent; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList; -import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager; -import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMDataTypeValueHelper; -import org.w3c.dom.Attr; -import org.w3c.dom.DOMImplementation; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - - -/** - * todo... common up this code with 'ContentBuilder' - */ -public class DOMContentBuilderImpl extends CMVisitor implements DOMContentBuilder -{ - protected int buildPolicy = BUILD_ALL_CONTENT; - protected Hashtable propertyTable = new Hashtable(); - - protected boolean alwaysVisit = false; - protected List resultList; - protected Document document; - protected Node currentParent; - protected Node topParent; - protected Vector visitedCMElementDeclarationList = new Vector(); - protected boolean attachNodesToParent = true; - protected NamespaceTable namespaceTable; - - protected List namespaceInfoList; - protected Element rootElement; // this is used only teporarily via createDefaultRootContent - protected ExternalCMDocumentSupport externalCMDocumentSupport; - - public boolean supressCreationOfDoctypeAndXMLDeclaration; - - protected CMDataTypeValueHelper valueHelper = new CMDataTypeValueHelper(); - - protected int numOfRepeatableElements = 1; - protected Stack cmGroupStack = new Stack(); - - public interface ExternalCMDocumentSupport - { - public CMDocument getCMDocument(Element element, String uri); - } - - public void setExternalCMDocumentSupport(ExternalCMDocumentSupport externalCMDocumentSupport) - { - this.externalCMDocumentSupport = externalCMDocumentSupport; - } - - public DOMContentBuilderImpl(Document document) - { - this.document = document; - namespaceTable = new NamespaceTable(document); - } - - public void setBuildPolicy(int buildPolicy) - { - this.buildPolicy = buildPolicy; - } - - public int getBuildPolicy() - { - return buildPolicy; - } - - protected boolean buildAllContent(int policy) - { - return (policy & BUILD_ALL_CONTENT) == BUILD_ALL_CONTENT; - } - - protected boolean buildOptionalElements(int policy) - { - return (policy & BUILD_OPTIONAL_ELEMENTS) == BUILD_OPTIONAL_ELEMENTS; - } - - protected boolean buildOptionalAttributes(int policy) - { - return (policy & BUILD_OPTIONAL_ATTRIBUTES) == BUILD_OPTIONAL_ATTRIBUTES; - } - - protected boolean buildFirstChoice(int policy) - { - return (policy & BUILD_FIRST_CHOICE) == BUILD_FIRST_CHOICE; - } - - protected boolean buildTextNodes(int policy) - { - return (policy & BUILD_TEXT_NODES) == BUILD_TEXT_NODES; - } - - protected boolean buildFirstSubstitution(int policy) - { - return (policy & BUILD_FIRST_SUBSTITUTION) == BUILD_FIRST_SUBSTITUTION; - } - - public List getResult() - { - return resultList; - } - - public void setProperty(String propertyName, Object value) - { - propertyTable.put(propertyName, value); - } - - public Object getProperty(String propertyName) - { - return propertyTable.get(propertyName); - } - - public void build(Node parent, CMNode child) - { - resultList = new Vector(); - topParent = parent; - currentParent = parent; - if (parent instanceof Element) - { - namespaceTable.addElementLineage((Element)parent); - } - attachNodesToParent = false; - alwaysVisit = true; - visitCMNode(child); - } - - public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration, List namespaceInfoList) throws Exception - { - this.namespaceInfoList = namespaceInfoList; - createDefaultRootContent(cmDocument, rootCMElementDeclaration); - } - - public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration) throws Exception - { - String grammarFileName = cmDocument.getNodeName(); - if (!supressCreationOfDoctypeAndXMLDeclaration) - { - // TODO cs... investigate to see if this code path is ever used, doesn't seem to be - // for now I'm setting the encoding to UTF-8 just incase this code path is used somewhere - // - String piValue = "version=\"1.0\""; //$NON-NLS-1$ - String encoding = "UTF-8"; //$NON-NLS-1$ - piValue += " encoding=\"" + encoding + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - ProcessingInstruction pi = document.createProcessingInstruction("xml", piValue); //$NON-NLS-1$ - document.appendChild(pi); - - // if we have a 'dtd' then add a DOCTYPE tag - // - if (grammarFileName != null && grammarFileName.endsWith("dtd")) //$NON-NLS-1$ - { - DOMImplementation domImpl = document.getImplementation(); - DocumentType documentType = domImpl.createDocumentType(rootCMElementDeclaration.getElementName(), grammarFileName, grammarFileName); - document.appendChild(documentType); - } - } - - // if we have a schema add an xsi:schemaLocation attribute - // - if (grammarFileName != null && grammarFileName.endsWith("xsd") && namespaceInfoList != null) //$NON-NLS-1$ - { - DOMNamespaceInfoManager manager = new DOMNamespaceInfoManager(); - String name = rootCMElementDeclaration.getNodeName(); - if (namespaceInfoList.size() > 0) - { - NamespaceInfo info = (NamespaceInfo)namespaceInfoList.get(0); - if (info.prefix != null && info.prefix.length() > 0) - { - name = info.prefix + ":" + name; //$NON-NLS-1$ - } - } - rootElement = createElement(rootCMElementDeclaration, name, document); - manager.addNamespaceInfo(rootElement, namespaceInfoList, true); - } - createDefaultContent(document, rootCMElementDeclaration); - } - - public void createDefaultContent(Node parent, CMElementDeclaration ed) - { - currentParent = parent; - alwaysVisit = true; - visitCMElementDeclaration(ed); - } - - public String computeName(CMNode cmNode, Node parent) - { - String prefix = null; - return DOMNamespaceHelper.computeName(cmNode, parent, prefix, namespaceTable); - } - - // overide the following 'create' methods to control how nodes are created - // - protected Element createElement(CMElementDeclaration ed, String name, Node parent) - { - return document.createElement(name); - } - - protected Attr createAttribute(CMAttributeDeclaration ad, String name, Node parent) - { - return document.createAttribute(name); - } - - protected Text createTextNode(CMDataType dataType, String value, Node parent) - { - return document.createTextNode(value); - } - - protected void handlePushParent(Element parent, CMElementDeclaration ed) - { - } - - protected void handlePopParent(Element element, CMElementDeclaration ed) - { - } - - // The range must be between 1 and 99. - public void setNumOfRepeatableElements(int i) - { - numOfRepeatableElements = i; - } - - protected int getNumOfRepeatableElements() - { - return numOfRepeatableElements; - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) - { - int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0; - int min = Math.max(ed.getMinOccur(), forcedMin); - - // Correct the min value if the element is contained in - // a group. - if (!cmGroupStack.isEmpty()) - { - CMGroup group = (CMGroup)cmGroupStack.peek(); - int gmin = group.getMinOccur(); - if (gmin == 0) - if (buildOptionalElements(buildPolicy)) - ; // min = min - else - min = min * gmin; // min = 0 - else - min = min * gmin; - } - - int max = Math.min(ed.getMaxOccur(), getNumOfRepeatableElements()); - if (max < min) - max = min; - - alwaysVisit = false; - - // Note - ed may not be abstract but has substitutionGroups - // involved. - if (buildFirstSubstitution(buildPolicy) - || isAbstract(ed)) // leave this for backward compatibility for now - { - // Note - To change so that if ed is optional, we do not - // generate anything here. - ed = getSubstitution(ed); - - // Note - the returned ed may be an abstract element in - // which case the xml will be invalid. - } - - if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) - { - visitedCMElementDeclarationList.add(ed); - for (int i = 1; i <= max; i++) - { - // create an Element for each - Element element = null; - if (rootElement != null) - { - element = rootElement; - rootElement = null; - } - else - { - element = createElement(ed, computeName(ed, currentParent), currentParent); - } - - // visit the children of the GrammarElement - Node oldParent = currentParent; - currentParent = element; - handlePushParent(element, ed); - - namespaceTable.addElement(element); - - boolean oldAttachNodesToParent = attachNodesToParent; - attachNodesToParent = true; - - // instead of calling super.visitCMElementDeclaration() - // we duplicate the code with some minor modifications - CMNamedNodeMap nodeMap = ed.getAttributes(); - int size = nodeMap.getLength(); - for (int j = 0; j < size; j++) - { - visitCMNode(nodeMap.item(j)); - } - - CMContent content = ed.getContent(); - if (content != null) - { - visitCMNode(content); - } - - if (ed.getContentType() == CMElementDeclaration.PCDATA) - { - CMDataType dataType = ed.getDataType(); - if (dataType != null) - { - visitCMDataType(dataType); - } - } - // end duplication - attachNodesToParent = oldAttachNodesToParent; - handlePopParent(element, ed); - currentParent = oldParent; - linkNode(element); - } - int size = visitedCMElementDeclarationList.size(); - visitedCMElementDeclarationList.remove(size - 1); - } - } - - - public void visitCMDataType(CMDataType dataType) - { - Text text = null; - String value = null; - - // For backward compatibility: - // Previous code uses a property value but new one uses - // buildPolicy. - if (getProperty(PROPERTY_BUILD_BLANK_TEXT_NODES) != null - && getProperty(PROPERTY_BUILD_BLANK_TEXT_NODES).equals("true")) //$NON-NLS-1$ - buildPolicy = buildPolicy ^ BUILD_TEXT_NODES; - - if (buildTextNodes(buildPolicy)) - { - value = valueHelper.getValue(dataType); - if (value == null) - { - if (currentParent != null && currentParent.getNodeType() == Node.ELEMENT_NODE) - { - value = currentParent.getNodeName(); - } - else - { - value = "pcdata"; //$NON-NLS-1$ - } - } - } - else - { - value = ""; //$NON-NLS-1$ - } - text = createTextNode(dataType, value, currentParent); - linkNode(text); - } - - - public void visitCMGroup(CMGroup e) - { - cmGroupStack.push(e); - - int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0; - int min = Math.max(e.getMinOccur(), forcedMin); - - int max = 0; - if (e.getMaxOccur() == -1) // unbounded - max = getNumOfRepeatableElements(); - else - max = Math.min(e.getMaxOccur(), getNumOfRepeatableElements()); - - if (max < min) - max = min; - - alwaysVisit = false; - - for (int i = 1; i <= max; i++) - { - if (e.getOperator() == CMGroup.CHOICE - && buildFirstChoice(buildPolicy)) - { - CMNode hintNode = null; - - // todo... the CMGroup should specify the hint... but it seems as though - // the Yamato guys are making the CMElement specify the hint. - // I do it that way for now until... we should fix this post GA - // - int listSize = visitedCMElementDeclarationList.size(); - if (listSize > 0) - { - CMElementDeclaration ed = (CMElementDeclaration)visitedCMElementDeclarationList.get(listSize - 1); - Object contentHint = ed.getProperty("contentHint"); //$NON-NLS-1$ - if (contentHint instanceof CMNode) - { - hintNode = (CMNode)contentHint; - } - } - - // see if this hint corresponds to a valid choice - // - CMNode cmNode = null; - - if (hintNode != null) - { - CMNodeList nodeList = e.getChildNodes(); - int nodeListLength = nodeList.getLength(); - for (int j = 0; j < nodeListLength; j++) - { - if (hintNode == nodeList.item(j)) - { - cmNode = hintNode; - } - } - } - - // if no cmNode has been determined from the hint, just use the first choice - // - if (cmNode == null) - { - CMNodeList nodeList = e.getChildNodes(); - if (nodeList.getLength() > 0) - { - cmNode = nodeList.item(0); - } - } - - if (cmNode != null) - { - visitCMNode(cmNode); - } - } - else if (e.getOperator() == CMGroup.ALL // ALL - || e.getOperator() == CMGroup.SEQUENCE) // SEQUENCE - { - // visit all of the content - super.visitCMGroup(e); - } - } - - cmGroupStack.pop(); - } - - static int count = 0; - - public void visitCMAttributeDeclaration(CMAttributeDeclaration ad) - { - if (alwaysVisit || - buildOptionalAttributes(buildPolicy) || - ad.getUsage() == CMAttributeDeclaration.REQUIRED) - { - alwaysVisit = false; - String name = computeName(ad, currentParent); - String value = valueHelper.getValue(ad, namespaceTable); - Attr attr = createAttribute(ad, name, currentParent); - attr.setValue(value != null ? value : ""); //$NON-NLS-1$ - linkNode(attr); - } - } - - protected boolean isAbstract(CMNode ed) - { - boolean result = false; - if (ed != null) - { - Object value = ed.getProperty("Abstract"); //$NON-NLS-1$ - result = (value == Boolean.TRUE); - } - return result; - } - - protected CMElementDeclaration getSubstitution(CMElementDeclaration ed) - { - CMElementDeclaration result = ed; - CMNodeList l = (CMNodeList)ed.getProperty("SubstitutionGroup"); //$NON-NLS-1$ - if (l != null) - { - for (int i=0; i < l.getLength(); i++) - { - CMNode candidate = l.item(i); - if (!isAbstract(candidate) && (candidate instanceof CMElementDeclaration)) - { - result = (CMElementDeclaration)candidate; - break; - } - } - } - return result; - } - - protected CMElementDeclaration getParentCMElementDeclaration() - { - CMElementDeclaration ed = null; - int listSize = visitedCMElementDeclarationList.size(); - if (listSize > 0) - { - ed = (CMElementDeclaration)visitedCMElementDeclarationList.get(listSize - 1); - } - return ed; - } - - public void visitCMAnyElement(CMAnyElement anyElement) - { - // ingnore buildPolicy for ANY elements... only create elements if absolutely needed - // - int forcedMin = alwaysVisit ? 1 : 0; - int min = Math.max(anyElement.getMinOccur(), forcedMin); - alwaysVisit = false; - - String uri = anyElement.getNamespaceURI(); - String targetNSProperty = "http://org.eclipse.wst/cm/properties/targetNamespaceURI"; //$NON-NLS-1$ - CMDocument parentCMDocument = (CMDocument)anyElement.getProperty("CMDocument"); //$NON-NLS-1$ - CMElementDeclaration ed = null; - - //System.out.println("parentCMDocument = " + parentCMDocument); //$NON-NLS-1$ - if (parentCMDocument != null) - { - if (uri == null || uri.startsWith("##") || uri.equals(parentCMDocument.getProperty(targetNSProperty))) //$NON-NLS-1$ - { - ed = getSuitableElement(getParentCMElementDeclaration(), parentCMDocument); - } - } - - - if (ed == null && externalCMDocumentSupport != null && uri != null && !uri.startsWith("##") && currentParent instanceof Element) //$NON-NLS-1$ - { - CMDocument externalCMDocument = externalCMDocumentSupport.getCMDocument((Element)currentParent, uri); - if (externalCMDocument != null) - { - ed = getSuitableElement(null, externalCMDocument); - } - } - - for (int i = 1; i <= min; i++) - { - if (ed != null) - { - visitCMElementDeclaration(ed); - } - else - { - Element element = document.createElement("ANY-ELEMENT"); //$NON-NLS-1$ - linkNode(element); - } - } - } - - protected CMElementDeclaration getSuitableElement(CMNamedNodeMap nameNodeMap) - { - CMElementDeclaration result = null; - int size = nameNodeMap.getLength(); - for (int i = 0; i < size; i++) - { - CMElementDeclaration candidate = (CMElementDeclaration)nameNodeMap.item(i); - if (!visitedCMElementDeclarationList.contains(candidate)) - { - result = candidate; - break; - } - } - return result; - } - - protected CMElementDeclaration getSuitableElement(CMElementDeclaration ed, CMDocument cmDocument) - { - CMElementDeclaration result = null; - - if (ed != null) - { - result = getSuitableElement(ed.getLocalElements()); - } - - if (result == null && cmDocument != null) - { - result = getSuitableElement(cmDocument.getElements()); - } - - return result; - } - - - public void linkNode(Node node) - { - if (attachNodesToParent && currentParent != null) - { - if (node.getNodeType() == Node.ATTRIBUTE_NODE) - { - ((Element)currentParent).setAttributeNode((Attr)node); - } - else - { - currentParent.appendChild(node); - } - } - else if (resultList != null) - { - resultList.add(node); - } - } - - public static void testPopulateDocumentFromGrammarFile(Document document, String grammarFileName, String rootElementName, boolean hack) - { - try - { - CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null); - CMNamedNodeMap elementMap = cmDocument.getElements(); - CMElementDeclaration element = (CMElementDeclaration)elementMap.getNamedItem(rootElementName); - - DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(document); - contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = hack; - contentBuilder.createDefaultRootContent(cmDocument, element); - - System.out.println(); - System.out.println("-----------------------------"); //$NON-NLS-1$ - DOMWriter writer = new DOMWriter(); - if (hack) - { - writer.print(document, grammarFileName); - } - else - { - writer.print(document); - } - System.out.println("-----------------------------"); //$NON-NLS-1$ - } - catch (Exception e) - { - System.out.println("Error: " + e); //$NON-NLS-1$ - e.printStackTrace(); - } - } - - // test - // - /* - public static void main(String arg[]) - { - if (arg.length >= 2) - { - try - { - CMDocumentFactoryRegistry.getInstance().registerCMDocumentBuilderWithClassName("org.eclipse.wst.xml.core.internal.contentmodel.mofimpl.CMDocumentBuilderImpl"); - - String grammarFileName = arg[0]; - String rootElementName = arg[1]; - - Document document = (Document)Class.forName("org.apache.xerces.dom.DocumentImpl").newInstance(); - testPopulateDocumentFromGrammarFile(document, grammarFileName, rootElementName, true); - } - catch (Exception e) - { - System.out.println("DOMContentBuilderImpl error"); - e.printStackTrace(); - } - } - else - { - System.out.println("Usage : java org.eclipse.wst.xml.util.DOMContentBuildingCMVisitor grammarFileName rootElementName"); - } - }*/ -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceHelper.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceHelper.java deleted file mode 100644 index 2bc784f2e4..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceHelper.java +++ /dev/null @@ -1,198 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -public class DOMNamespaceHelper -{ - protected static String getURIForPrefix(Element element, String prefix) - { - String result = null; - String nsAttrName = null; - if (prefix != null && prefix.length() > 0) - { - nsAttrName = "xmlns:" + prefix; //$NON-NLS-1$ - } - else - { - nsAttrName = "xmlns"; //$NON-NLS-1$ - } - - // assume the node is qualified... look up the URI base on the prefix - // - for (Node node = element; node != null; node = node.getParentNode()) - { - if (node.getNodeType() == Node.ELEMENT_NODE) - { - Element theElement = (Element)node; - Attr attr = theElement.getAttributeNode(nsAttrName); - if (attr != null) - { - result = attr.getValue(); - } - } - else - { - break; - } - } - - // see if we can find some info from an 'implicit' namespace - // - if (result == null) - { - NamespaceTable table = new NamespaceTable(element.getOwnerDocument()); - result = table.getURIForPrefix(prefix); - } - return result; - } - - public static String getNamespaceURI(Node node) - { - String result = null; - if (node.getNodeType() == Node.ELEMENT_NODE) - { - Element element = (Element)node; - String prefix = element.getPrefix(); - result = getURIForPrefix(element, prefix); - } - else if (node.getNodeType() == Node.ATTRIBUTE_NODE) - { - Attr attr = (Attr)node; - String prefix = attr.getPrefix(); - result = getURIForPrefix(attr.getOwnerElement(), prefix); - } - return result; - } - - // todo... this is an ugly hack... needs to be fixed - // - public static String computePrefix(CMNode cmNode, Node parentNode) - { - String result = null; - for (Node node = parentNode; node != null; node = node.getParentNode()) - { - if (node.getNodeType() == Node.ELEMENT_NODE) - { - result = getPrefix(node.getNodeName()); - if (result != null) - { - break; - } - } - } - return result; - } - - - public static String getPrefix(String name) - { - String prefix = null; - int index = name.indexOf(":"); //$NON-NLS-1$ - if (index != -1) - { - prefix = name.substring(0, index); - } - return prefix; - } - - - public static String getUnprefixedName(String name) - { - int index = name.indexOf(":"); //$NON-NLS-1$ - if (index != -1) - { - name = name.substring(index + 1); - } - return name; - } - - - public static String computeName(CMNode cmNode, Node parent, String prefix) - { - return computeName(cmNode, parent, prefix, null); - } - - - public static String computeName(CMNode cmNode, Node parent, String prefix, NamespaceTable namespaceTable) - { - String result = cmNode.getNodeName(); - - // if the cmNode has a hard coded prefix then we don't need to do anything - // - if (getPrefix(result) == null) - { - String qualification = (String)cmNode.getProperty("http://org.eclipse.wst/cm/properties/nsPrefixQualification"); //$NON-NLS-1$ - // see if we need a namespace prefix - // - if (qualification != null && qualification.equals("qualified")) //$NON-NLS-1$ - { - if (prefix == null) - { - // todo... add getCMDocument() method to CMNode - // for now use this getProperty() hack - CMDocument cmDocument = (CMDocument)cmNode.getProperty("CMDocument"); //$NON-NLS-1$ - if (cmDocument != null) - { - String namespaceURI = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$ - if (namespaceURI != null) - { - // use the NamespaceTable to figure out the correct prefix for this namespace uri - // - if (namespaceTable == null) - { - Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document)parent : parent.getOwnerDocument(); - namespaceTable = new NamespaceTable(document); - if (parent instanceof Element) - { - namespaceTable.addElementLineage((Element)parent); - } - } - prefix = namespaceTable.getPrefixForURI(namespaceURI); - } - } - } - if (prefix != null && prefix.length() > 0) - { - result = prefix + ":" + result; //$NON-NLS-1$ - } - } - } - return result; - } - - - public static String[] getURIQualifiedNameComponents(String uriQualifiedName) - { - String[] result = new String[2]; - int firstIndex = uriQualifiedName.indexOf("["); //$NON-NLS-1$ - int lastIndex = uriQualifiedName.indexOf("]"); //$NON-NLS-1$ - if (firstIndex != -1 && lastIndex > firstIndex) - { - result[0] = uriQualifiedName.substring(firstIndex + 1, lastIndex); - result[1] = uriQualifiedName.substring(lastIndex + 1); - } - else - { - result[1] = uriQualifiedName; - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceInfoManager.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceInfoManager.java deleted file mode 100644 index e16579cff6..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceInfoManager.java +++ /dev/null @@ -1,225 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - - -/** - * DOMNamespaceInfoManager - * - * - */ -public class DOMNamespaceInfoManager -{ - public static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - - public DOMNamespaceInfoManager() - { - } - - public List getNamespaceInfoList(Element element) - { - NamespaceInfoReader reader = new NamespaceInfoReader(); - return reader.getNamespaceInfoList(element); - } - - public void removeNamespaceInfo(Element element) - { - NamespaceInfoRemover remover = new NamespaceInfoRemover(); - remover.removeNamespaceInfo(element); - } - - public void addNamespaceInfo(Element element, List namespaceInfoList, boolean needsXSI) - { - // first we create an xmlns attribute for each namespace - // - Document document = element.getOwnerDocument(); - - String schemaLocationValue = ""; //$NON-NLS-1$ - - for (Iterator iterator = namespaceInfoList.iterator(); iterator.hasNext(); ) - { - NamespaceInfo nsInfo = (NamespaceInfo)iterator.next(); - nsInfo.normalize(); - - if (nsInfo.uri != null) - { - String attrName = nsInfo.prefix != null ? "xmlns:" + nsInfo.prefix : "xmlns"; //$NON-NLS-1$ //$NON-NLS-2$ - Attr namespaceAttr = document.createAttribute(attrName); - namespaceAttr.setValue(nsInfo.uri); - element.setAttributeNode(namespaceAttr); - - // in this case we use the attribute "xsi:schemaLocation" - // here we build up its value - // - if (nsInfo.locationHint != null) - { - schemaLocationValue += nsInfo.uri; - schemaLocationValue += " "; //$NON-NLS-1$ - schemaLocationValue += nsInfo.locationHint; - schemaLocationValue += " "; //$NON-NLS-1$ - } - - if (nsInfo.uri.equals(XSI_URI)) - { - needsXSI = false; - } - } - else if (nsInfo.locationHint != null) - { - // in this case we use the attribute "xsi:noNamespaceSchemaLocation" - // - Attr attr = document.createAttribute("xsi:noNamespaceSchemaLocation"); //$NON-NLS-1$ - attr.setValue(nsInfo.locationHint); - element.setAttributeNode(attr); - } - } - - if (needsXSI) - { - // we add an xmlns:xsi attribute to define 'xsi:schemaLocation' attribute - // - Attr attr = document.createAttribute("xmlns:xsi"); //$NON-NLS-1$ - attr.setValue(XSI_URI); - element.setAttributeNode(attr); - } - - if (schemaLocationValue.length() > 0) - { - // create the "xsi:schemaLocation" attribute - // - Attr attr = document.createAttribute("xsi:schemaLocation"); //$NON-NLS-1$ - attr.setValue(schemaLocationValue); - element.setAttributeNode(attr); - } - } - - /** - * - */ - protected static class NamespaceInfoReader extends NamespaceAttributeVisitor - { - protected List namespaceInfoList = new Vector(); - - public List getNamespaceInfoList(Element element) - { - visitElement(element); - return namespaceInfoList; - } - - - public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String value) - { - NamespaceInfo info = createNamespaceInfo(); - info.locationHint = value; - } - - public void visitXMLNamespaceAttribute(Attr attr, String prefix, String uri) - { - NamespaceInfo info = createNamespaceInfo(); - info.uri = uri; - info.prefix = prefix; - super.visitXMLNamespaceAttribute(attr, prefix, uri); - } - - public void visitXSISchemaLocationValuePair(String uri, String locationHint) - { - NamespaceInfo info = getNamespaceInfoForURI(uri); - if (info != null) - { - info.locationHint = locationHint; - } - else - { - info = createNamespaceInfo(); - info.uri = uri; - info.locationHint = locationHint; - } - } - - protected NamespaceInfo getNamespaceInfoForURI(String uri) - { - NamespaceInfo result = null; - for (Iterator i = namespaceInfoList.iterator(); i.hasNext(); ) - { - NamespaceInfo info = (NamespaceInfo)i.next(); - if (info.uri != null && info.uri.equals(uri)) - { - result = info; - break; - } - } - return result; - } - - protected NamespaceInfo createNamespaceInfo() - { - NamespaceInfo info = new NamespaceInfo(); - namespaceInfoList.add(info); - return info; - } - } - - - /** - * - */ - protected static class NamespaceInfoRemover extends NamespaceAttributeVisitor - { - protected List attributesToRemove = new Vector(); - - public void removeNamespaceInfo(Element element) - { - visitElement(element); - removeAttributes(); - } - - public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String value) - { - attributesToRemove.add(attr); - } - - public void visitXMLNamespaceAttribute(Attr attr, String namespacePrefix, String namespaceURI) - { - attributesToRemove.add(attr); - super.visitXMLNamespaceAttribute(attr, namespacePrefix, namespaceURI); - } - - public void visitXSISchemaLocationAttribute(Attr attr, String value) - { - attributesToRemove.add(attr); - } - - public void removeAttributes() - { - for (Iterator i = attributesToRemove.iterator(); i.hasNext(); ) - { - Attr attr = (Attr)i.next(); - Element element = attr.getOwnerElement(); - if (element != null) - { - element.removeAttributeNode(attr); - } - } - } - } - - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMVisitor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMVisitor.java deleted file mode 100644 index bf0710b263..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMVisitor.java +++ /dev/null @@ -1,133 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import org.w3c.dom.Attr; -import org.w3c.dom.CDATASection; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - -// todo.. move this class to another package (perhaps xmlutility) -// -public class DOMVisitor -{ - public void visitNode(Node node) - { - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE : - { - visitAttr((Attr)node); - break; - } - case Node.CDATA_SECTION_NODE : - { - visitCDATASection((CDATASection)node); - break; - } - case Node.COMMENT_NODE : - { - visitComment((Comment)node); - break; - } - case Node.DOCUMENT_NODE : - { - visitDocument((Document)node); - break; - } - case Node.DOCUMENT_TYPE_NODE : - { - visitDocumentType((DocumentType)node); - break; - } - case Node.ELEMENT_NODE : - { - visitElement((Element)node); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : - { - visitProcessingInstruction((ProcessingInstruction)node); - break; - } - case Node.TEXT_NODE : - { - visitText((Text)node); - break; - } - } - } - - protected void visitDocument(Document document) - { - visitChildNodesHelper(document); - } - - protected void visitDocumentType(DocumentType doctype) - { - - } - - protected void visitElement(Element element) - { - visitAttributesHelper(element); - visitChildNodesHelper(element); - } - - - public void visitAttr(Attr attr) - { - } - - protected void visitText(Text text) - { - } - - protected void visitCDATASection(CDATASection cdataSection) - { - } - - protected void visitComment(Comment comment) - { - } - - protected void visitProcessingInstruction(ProcessingInstruction pi) - { - } - - - protected void visitChildNodesHelper(Node node) - { - NodeList children = node.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) - { - visitNode(children.item(i)); - } - } - - protected void visitAttributesHelper(Node node) - { - NamedNodeMap map = node.getAttributes(); - for (int i = 0; i < map.getLength(); i++ ) - { - visitNode(map.item(i)); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMWriter.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMWriter.java deleted file mode 100644 index 03aca74c77..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMWriter.java +++ /dev/null @@ -1,411 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; - -import org.w3c.dom.Attr; -import org.w3c.dom.CDATASection; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - - -/** - * This is a hacked up dom writer stolen from a Xerces sample. - * I'd like to use an exisitng 'generic DOM' writer - * If anyone can find such a thing then please go ahead and junk this. - * - * @version - */ -public class DOMWriter -{ - protected boolean formattingEnabled = true; - protected boolean outputDoctypeEnabled = true; - protected PrintWriter out; - protected int indent = 0; - - public DOMWriter() throws UnsupportedEncodingException - { - this(System.out); - } - - public DOMWriter(OutputStream outputSteam) - { - out = new PrintWriter(outputSteam); - } - - public DOMWriter(Writer writer) - { - out = new PrintWriter(writer); - } - - public void setFormattingEnabled(boolean enabled) - { - formattingEnabled = enabled; - } - - public boolean getFormattingEnabled() - { - return formattingEnabled; - } - - public void setOutputDoctypeEnabled(boolean enabled) - { - outputDoctypeEnabled = enabled; - } - - public class XMLVisitor - { - protected boolean currentElementHasChildElements = false; - - public void visitNode(Node node) - { - switch (node.getNodeType()) - { - case Node.ATTRIBUTE_NODE : - { - visitAttr((Attr)node); - break; - } - case Node.CDATA_SECTION_NODE : - { - visitCDATASection((CDATASection)node); - break; - } - case Node.COMMENT_NODE : - { - visitComment((Comment)node); - break; - } - case Node.DOCUMENT_NODE : - { - visitDocument((Document)node); - break; - } - case Node.DOCUMENT_TYPE_NODE : - { - visitDocumentType((DocumentType)node); - break; - } - case Node.ELEMENT_NODE : - { - visitElement((Element)node); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : - { - visitProcessingInstruction((ProcessingInstruction)node); - break; - } - case Node.TEXT_NODE : - { - visitText((Text)node); - break; - } - } - } - - public void visitDocument(Document document) - { - visitChildNodesHelper(document); - } - - public void visitDocumentType(DocumentType doctype) - { - if (outputDoctypeEnabled) - { - String data = getDocumentTypeData(doctype); - print("<!DOCTYPE " + data + ">"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - public void visitElement(Element element) - { - if (!doShow(element)) - return; - - boolean parentElementHasChildNodes = currentElementHasChildElements; - currentElementHasChildElements = hasChildElements(element); - - printIndent(); - print("<"); //$NON-NLS-1$ - print(element.getNodeName()); - visitAttributesHelper(element); - - boolean hasChildNodes = element.getChildNodes().getLength() > 0; - boolean isRootElement = element.getParentNode().getNodeType() == Node.DOCUMENT_NODE; - if (hasChildNodes || isRootElement) - { - if (currentElementHasChildElements || isRootElement) - { - println(">"); //$NON-NLS-1$ - } - else - { - print(">"); //$NON-NLS-1$ - } - indent += 2; - visitChildNodesHelper(element); - indent -= 2; - - if (currentElementHasChildElements || isRootElement) - { - printIndent(); - } - print("</"); //$NON-NLS-1$ - print(element.getNodeName()); - println(">"); //$NON-NLS-1$ - } - else - { - println("/>"); //$NON-NLS-1$ - } - - currentElementHasChildElements = parentElementHasChildNodes; - } - - public void visitAttr(Attr attr) - { - print(" "); //$NON-NLS-1$ - print(attr.getNodeName()); - print("=\""); //$NON-NLS-1$ - print(createPrintableCharacterData(attr.getValue())); - print("\""); //$NON-NLS-1$ - } - - public void visitText(Text text) - { - if (currentElementHasChildElements) - { - printIndent(); - print(createPrintableCharacterData(text.getNodeValue())); - println(); - } - else - { - print(createPrintableCharacterData(text.getNodeValue())); - } - } - - public void visitCDATASection(CDATASection cdataSection) - { - } - - public void visitComment(Comment comment) - { - printIndent(); - print("<!--"); //$NON-NLS-1$ - print(comment.getNodeValue()); - println("-->"); //$NON-NLS-1$ - } - - public void visitProcessingInstruction(ProcessingInstruction pi) - { - printIndent(); - print("<?"); //$NON-NLS-1$ - print(pi.getNodeName()); - print(" "); //$NON-NLS-1$ - print(pi.getNodeValue()); - println("?>"); //$NON-NLS-1$ - } - - - public boolean hasChildElements(Node node) - { - boolean result = false; - NodeList children = node.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) - { - if (children.item(i).getNodeType() == Node.ELEMENT_NODE) - { - result = true; - break; - } - } - return result; - } - - public void visitChildNodesHelper(Node node) - { - NodeList children = node.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) - { - visitNode(children.item(i)); - } - } - - public void visitAttributesHelper(Node node) - { - NamedNodeMap map = node.getAttributes(); - for (int i = 0; i < map.getLength(); i++ ) - { - visitNode(map.item(i)); - } - } - } - - /** an ugly hack until I restruct this code a little - * - */ - protected boolean doShow(Element element) - { - return true; - } - - /** converts DOM text values to 'printable' values - * - converts '&' to '&' - */ - protected String createPrintableCharacterData(String string) - { - String result = ""; //$NON-NLS-1$ - int index = 0; - while (true) - { - int ampersandIndex = string.indexOf("&", index); //$NON-NLS-1$ - if (ampersandIndex != -1) - { - result += string.substring(index, ampersandIndex); - result += "&"; //$NON-NLS-1$ - index = ampersandIndex + 1; - } - else - { - break; - } - } - result += string.substring(index); - return result; - } - - - /** Prints the specified node, recursively. */ - public void print(Node node) - { - // is there anything to do? - if (node != null) - { - XMLVisitor visitor = new XMLVisitor(); - visitor.visitNode(node); - } - out.flush(); - } - - /** a temporary hack to workaround our inability to create a DocumentType tag*/ - public void print(Document document, String grammarURL) - { - String systemId = null; - if (grammarURL.endsWith("dtd")) //$NON-NLS-1$ - { - int lastSlashIndex = Math.max(grammarURL.lastIndexOf("/"), grammarURL.lastIndexOf("\\")); //$NON-NLS-1$ //$NON-NLS-2$ - if (lastSlashIndex != -1) - { - systemId = grammarURL.substring(lastSlashIndex + 1); - } - } - print(document, "UTF-8", grammarURL, null, systemId); //$NON-NLS-1$ - - } - - /** a temporary hack to workaround our inability to create a DocumentType tag*/ - public void print(Document document, String encoding, String grammarFileName, String publicId, String systemId) - { - out.println("<?xml version=\"1.0\"" + " encoding=\"" + encoding + "\"?>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (grammarFileName.endsWith(".dtd")) //$NON-NLS-1$ - { - String docTypeLine = "<!DOCTYPE " + document.getDocumentElement().getNodeName() + " "; //$NON-NLS-1$ //$NON-NLS-2$ - if (publicId != null) - { - docTypeLine += "PUBLIC \"" + publicId + "\" "; //$NON-NLS-1$ //$NON-NLS-2$ - if (systemId != null) - { - docTypeLine += "\"" + systemId + "\" "; //$NON-NLS-1$ //$NON-NLS-2$ - } - docTypeLine += ">"; //$NON-NLS-1$ - out.println(docTypeLine); - } - else if (systemId != null) - { - docTypeLine += "SYSTEM \"" + systemId + "\" >"; //$NON-NLS-1$ //$NON-NLS-2$ - out.println(docTypeLine); - } - } - print(document); - } - - public static String getDocumentTypeData(DocumentType doctype) - { - String data = doctype.getName(); - if (doctype.getPublicId() != null) - { - data += " PUBLIC \"" + doctype.getPublicId() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - String systemId = doctype.getSystemId(); - if (systemId == null) - { - systemId = ""; //$NON-NLS-1$ - } - data += " \"" + systemId + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - } - else - { - data += " SYSTEM \"" + doctype.getSystemId() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ - } - return data; - } - - public void println() - { - if (formattingEnabled) - { - out.println(); - } - } - - public void println(String string) - { - if (formattingEnabled) - { - out.println(string); - } - else - { - out.print(string); - } - } - - public void printIndent() - { - if (formattingEnabled) - { - for (int i = 0; i < indent; i++) - { - out.print(" "); //$NON-NLS-1$ - } - } - } - - public void print(String string) - { - out.print(string); - } -} - diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/InferredGrammarFactory.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/InferredGrammarFactory.java deleted file mode 100644 index 601b8bacd0..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/InferredGrammarFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.Collection; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.w3c.dom.Element; - - -// this interface is used to build a grammar document given a local file name -// -public interface InferredGrammarFactory -{ - public CMDocument createCMDocument(String uri); - public CMElementDeclaration createCMElementDeclaration(CMDocument cmDocument, Element element, boolean isLocal); - public void createCMContent(CMDocument parentCMDocument, CMElementDeclaration parentEd, CMDocument childCMDocument, CMElementDeclaration childEd, boolean isLocal, String uri); - public void debugPrint(Collection collection); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceAttributeVisitor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceAttributeVisitor.java deleted file mode 100644 index f14a5b7979..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceAttributeVisitor.java +++ /dev/null @@ -1,94 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.StringTokenizer; - -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; - - -public class NamespaceAttributeVisitor -{ - public static final String XML_SCHEMA_INSTANCE_URI = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - public String xsiPrefix = "xsi"; //$NON-NLS-1$ - - public void visitXMLNamespaceAttribute(Attr attr, String namespacePrefix, String namespaceURI) - { - if (namespaceURI.equals(XML_SCHEMA_INSTANCE_URI)) - { - xsiPrefix = namespacePrefix; - } - } - - public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String value) - { - } - - public void visitXSISchemaLocationAttribute(Attr attr, String value) - { - StringTokenizer st = new StringTokenizer(value); - while (true) - { - String nsURI = st.hasMoreTokens() ? st.nextToken() : null; - String locationHint = st.hasMoreTokens() ? st.nextToken() : null; - if (nsURI != null && locationHint != null) - { - visitXSISchemaLocationValuePair(nsURI, locationHint); - } - else - { - break; - } - } - } - - public void visitXSISchemaLocationValuePair(String uri, String locationHint) - { - } - - public void visitElement(Element element) - { - NamedNodeMap map = element.getAttributes(); - int mapLength = map.getLength(); - for (int i = 0; i < mapLength; i++) - { - Attr attr = (Attr)map.item(i); - String prefix = DOMNamespaceHelper.getPrefix(attr.getName()); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attr.getName()); - if (prefix != null && unprefixedName != null) - { - if (prefix.equals("xmlns")) //$NON-NLS-1$ - { - visitXMLNamespaceAttribute(attr, unprefixedName, attr.getValue()); - } - else if (prefix.equals(xsiPrefix) && unprefixedName.equals("schemaLocation")) //$NON-NLS-1$ - { - visitXSISchemaLocationAttribute(attr, attr.getValue()); - } - else if (prefix.equals(xsiPrefix) && unprefixedName.equals("noNamespaceSchemaLocation")) //$NON-NLS-1$ - { - visitXSINoNamespaceSchemaLocationAttribute(attr, attr.getValue()); - } - } - else if (unprefixedName != null) - { - if (unprefixedName.equals("xmlns")) //$NON-NLS-1$ - { - visitXMLNamespaceAttribute(attr, "", attr.getValue()); //$NON-NLS-1$ - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceInfo.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceInfo.java deleted file mode 100644 index d1cbde891e..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceInfo.java +++ /dev/null @@ -1,83 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -public class NamespaceInfo -{ - public String uri; - public String prefix; - public String locationHint; - public boolean isPrefixRequired; - protected Hashtable hashtable; - - public NamespaceInfo() - { - } - - public NamespaceInfo(String uri, String prefix, String locationHint) - { - this.uri = uri; - this.prefix = prefix; - this.locationHint = locationHint; - } - - public NamespaceInfo(NamespaceInfo that) - { - this.uri = that.uri; - this.prefix = that.prefix; - this.locationHint = that.locationHint; - // todo... see if we need to clone the hastable - } - - public void normalize() - { - uri = getNormalizedValue(uri); - prefix = getNormalizedValue(prefix); - locationHint= getNormalizedValue(locationHint); - } - - protected String getNormalizedValue(String string) - { - return (string != null && string.trim().length() == 0) ? null : string; - } - - public void setProperty(String property, Object value) - { - if (hashtable == null) - { - hashtable = new Hashtable(); - } - hashtable.put(property, value); - } - - public Object getProperty(String property) - { - return (hashtable != null) ? hashtable.get(property) : null; - } - - public static List cloneNamespaceInfoList(List oldList) - { - List newList = new Vector(oldList.size()); - for (Iterator i = oldList.iterator(); i.hasNext(); ) - { - NamespaceInfo oldInfo = (NamespaceInfo)i.next(); - newList.add(new NamespaceInfo(oldInfo)); - } - return newList; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceTable.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceTable.java deleted file mode 100644 index 617f11ee1e..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceTable.java +++ /dev/null @@ -1,251 +0,0 @@ -/* -* Copyright (c) 2002 IBM Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Common Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/cpl-v10.html -* -* Contributors: -* IBM - Initial API and implementation -* Jens Lukowski/Innoopract - initial renaming/restructuring -* -*/ -package org.eclipse.wst.xml.core.internal.contentmodel.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -public class NamespaceTable extends NamespaceAttributeVisitor -{ - public Hashtable hashtable = new Hashtable(); - - public NamespaceTable(Document document) - { - //DOMExtension domExtension = DOMExtensionProviderRegistry.getInstance().getDOMExtension(document); - //if (domExtension != null) - //{ - // addNamespaceInfoList(domExtension.getImplictNamespaceInfoList(), true); - // } - } - - private NamespaceTable() - { - } - - public boolean isNamespaceEncountered() - { - return hashtable.values().size() > 0; - } - - public String getPrefixForURI(String uri) - { - String result = null; - NamespaceInfo entry = getNamespaceInfoForURI(uri, true); - if (entry != null) - { - result = entry.prefix; - } - return result; - } - - - public String getURIForPrefix(String prefix) - { - String result = null; - NamespaceInfo info = getNamespaceInfoForPrefix(prefix); - if (info != null) - { - result = info.uri; - } - return result; - } - - - protected boolean isMatchingString(String a, String b) - { - return ((a == null && b == null) || (a != null && b != null && a.equals(b))); - } - - - public NamespaceInfo getNamespaceInfoForURI(String uri) - { - return getNamespaceInfoForURI(uri, false); - } - - - public NamespaceInfo getNamespaceInfoForURI(String uri, boolean testImplied) - { - NamespaceInfo result = null; - for (Iterator i = hashtable.values().iterator(); i.hasNext(); ) - { - NamespaceInfo nsInfo = (NamespaceInfo)i.next(); - if (isMatchingString(nsInfo.uri, uri)) - { - result = nsInfo; - if (testImplied && nsInfo.getProperty("isImplied") != null) //$NON-NLS-1$ - { - // continue - } - else - { - break; - } - } - } - return result; - } - - - public void setLocationHintForURI(String uri, String locationHint) - { - // List list = new Vector(); - for (Iterator i = hashtable.values().iterator(); i.hasNext(); ) - { - NamespaceInfo nsInfo = (NamespaceInfo)i.next(); - if (isMatchingString(nsInfo.uri, uri)) - { - nsInfo.locationHint = locationHint; - } - } - } - - - public NamespaceInfo getNamespaceInfoForPrefix(String prefix) - { - prefix = prefix != null ? prefix : ""; //$NON-NLS-1$ - return (NamespaceInfo)hashtable.get(prefix); - } - - - public void visitXMLNamespaceAttribute(Attr attr, String namespacePrefix, String namespaceURI) - { - NamespaceInfo nsInfo = new NamespaceInfo(); - nsInfo.prefix = namespacePrefix; - nsInfo.uri = namespaceURI; - - NamespaceInfo matchingNamespaceInfo = getNamespaceInfoForURI(namespaceURI); - if (matchingNamespaceInfo != null) - { - nsInfo.locationHint = matchingNamespaceInfo.locationHint; - } - - internalAddNamespaceInfo(namespacePrefix, nsInfo); - - super.visitXMLNamespaceAttribute(attr, namespacePrefix, namespaceURI); - } - - public void visitXSISchemaLocationValuePair(String uri, String locationHint) - { - setLocationHintForURI(uri, locationHint); - } - - public void addNamespaceInfo(NamespaceInfo info) - { - String key = (info.prefix != null) ? info.prefix : ""; //$NON-NLS-1$ - internalAddNamespaceInfo(key, info); - } - - protected void internalAddNamespaceInfo(String key, NamespaceInfo info) - { - hashtable.put(key, info); - } - - protected void addNamespaceInfoList(List list, boolean isImplied) - { - if (list != null) - { - for (Iterator i = list.iterator(); i.hasNext(); ) - { - NamespaceInfo info = (NamespaceInfo)i.next(); - NamespaceInfo clone = new NamespaceInfo(info); - if (isImplied) - { - clone.setProperty("isImplied", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - } - addNamespaceInfo(clone); - } - } - } - - public void addNamespaceInfoList(List list) - { - addNamespaceInfoList(list, false); - } - - public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String locationHint) - { - addNoNamespaceSchemaLocation(locationHint); - } - - public void addNoNamespaceSchemaLocation(String locationHint) - { - NamespaceInfo nsInfo = new NamespaceInfo(); - nsInfo.prefix = null; - nsInfo.uri = ""; //$NON-NLS-1$ - nsInfo.locationHint = locationHint; - internalAddNamespaceInfo("", nsInfo); //$NON-NLS-1$ - } - - public void addNamespaceInfo(String prefix, String uri, String locationHint) - { - NamespaceInfo nsInfo = new NamespaceInfo(); - nsInfo.prefix = prefix; - nsInfo.uri = uri; - nsInfo.locationHint = locationHint; - internalAddNamespaceInfo(prefix != null ? prefix : "", nsInfo); //$NON-NLS-1$ - } - - public void addElement(Element element) - { - visitElement(element); - } - - public void addElementLineage(Element targetElement) - { - List list = NamespaceTable.getElementLineage(targetElement); - for (Iterator i = list.iterator(); i.hasNext(); ) - { - Element element = (Element)i.next(); - addElement(element); - } - } - - public static List getElementLineage(Element element) - { - List result = new ArrayList(); - for (Node node = element; node != null; node = node.getParentNode()) - { - if (node.getNodeType() == Node.ELEMENT_NODE) - { - result.add(0, node); - } - else - { - break; - } - } - return result; - } - - public Collection getNamespaceInfoCollection() - { - return hashtable.values(); - } - - public List getNamespaceInfoList() - { - List list = new Vector(); - list.addAll(hashtable.values()); - return list; - } -} |