Apply bugzilla fix - Bug 340436 - [DTE] Custom XSD validation broken
diff --git a/plugins/org.eclipse.wst.sse.sieditor.model/api/org/eclipse/wst/sse/sieditor/model/reconcile/utils/ObjectsForResolveUtils.java b/plugins/org.eclipse.wst.sse.sieditor.model/api/org/eclipse/wst/sse/sieditor/model/reconcile/utils/ObjectsForResolveUtils.java
index 7c92624..8896c73 100644
--- a/plugins/org.eclipse.wst.sse.sieditor.model/api/org/eclipse/wst/sse/sieditor/model/reconcile/utils/ObjectsForResolveUtils.java
+++ b/plugins/org.eclipse.wst.sse.sieditor.model/api/org/eclipse/wst/sse/sieditor/model/reconcile/utils/ObjectsForResolveUtils.java
@@ -20,6 +20,12 @@
 
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.wst.sse.sieditor.command.emf.common.utils.UpdateNSPrefixUtils;
+import org.eclipse.wst.sse.sieditor.model.reconcile.utils.searchresultprocessor.IXsdSearchResultProcessor;
+import org.eclipse.wst.sse.sieditor.model.reconcile.utils.searchresultprocessor.XsdAttributeDeclarationSearchResultProcessor;
+import org.eclipse.wst.sse.sieditor.model.reconcile.utils.searchresultprocessor.XsdElementDeclarationSearchResultProcessor;
+import org.eclipse.wst.sse.sieditor.model.utils.ElementAttributeUtils;
+import org.eclipse.wst.sse.sieditor.model.utils.EmfXsdUtils;
 import org.eclipse.wst.wsdl.Message;
 import org.eclipse.wst.wsdl.Operation;
 import org.eclipse.wst.wsdl.Part;
@@ -35,300 +41,301 @@
 import org.eclipse.xsd.util.XSDConstants;
 import org.w3c.dom.Element;
 
-import org.eclipse.wst.sse.sieditor.command.emf.common.utils.UpdateNSPrefixUtils;
-import org.eclipse.wst.sse.sieditor.model.reconcile.utils.searchresultprocessor.IXsdSearchResultProcessor;
-import org.eclipse.wst.sse.sieditor.model.reconcile.utils.searchresultprocessor.XsdAttributeDeclarationSearchResultProcessor;
-import org.eclipse.wst.sse.sieditor.model.reconcile.utils.searchresultprocessor.XsdElementDeclarationSearchResultProcessor;
-import org.eclipse.wst.sse.sieditor.model.utils.ElementAttributeUtils;
-import org.eclipse.wst.sse.sieditor.model.utils.EmfXsdUtils;
-
 public class ObjectsForResolveUtils {
 
-    private static final ObjectsForResolveUtils INSTANCE = new ObjectsForResolveUtils();
+	private static final ObjectsForResolveUtils INSTANCE = new ObjectsForResolveUtils();
 
-    private ObjectsForResolveUtils() {
+	private ObjectsForResolveUtils() {
 
-    }
+	}
 
-    public static ObjectsForResolveUtils instance() {
-        return INSTANCE;
-    }
+	public static ObjectsForResolveUtils instance() {
+		return INSTANCE;
+	}
 
-    // =========================================================
-    // unresolved elements search helper
-    // =========================================================
+	// =========================================================
+	// unresolved elements search helper
+	// =========================================================
 
-    public ObjectsForResolveContainer findObjectsForResolve(final EObject eObject, final List<XSDSchema> allSchemas) {
-        final List<EObject> visited = new LinkedList<EObject>();
-        return findObjectsForResolveInternal(eObject, allSchemas, visited);
-    }
+	public ObjectsForResolveContainer findObjectsForResolve(final EObject eObject, final List<XSDSchema> allSchemas) {
+		final List<EObject> visited = new LinkedList<EObject>();
+		return findObjectsForResolveInternal(eObject, allSchemas, visited);
+	}
 
-    /**
-     * Utility internal method. Returns container with all the elements, which
-     * need reconciling.
-     */
-    private ObjectsForResolveContainer findObjectsForResolveInternal(final EObject eObject, final List<XSDSchema> allSchemas,
-            final List<EObject> visited) {
-        final ObjectsForResolveContainer container = new ObjectsForResolveContainer();
+	/**
+	 * Utility internal method. Returns container with all the elements, which
+	 * need reconciling.
+	 */
+	private ObjectsForResolveContainer findObjectsForResolveInternal(final EObject eObject,
+			final List<XSDSchema> allSchemas, final List<EObject> visited) {
+		final ObjectsForResolveContainer container = new ObjectsForResolveContainer();
 
-        final Iterator<EObject> eAllContents = eObject.eContents().iterator();
-        while (eAllContents.hasNext()) {
-            final EObject eContent = eAllContents.next();
+		final Iterator<EObject> eAllContents = eObject.eContents().iterator();
+		while (eAllContents.hasNext()) {
+			final EObject eContent = eAllContents.next();
 
-            if (visited.contains(eContent)) {
-                continue;
-            }
+			if (visited.contains(eContent)) {
+				continue;
+			}
 
-            processXsdElementDeclaration(container, allSchemas, eContent);
-            processXsdAttributeDeclaration(container, allSchemas, eContent);
-            processComplexTypeDefinition(container, allSchemas, eContent);
-            processWsdlOperation(container, eContent);
-            processWsdlMessage(container, eContent);
-            processWsdlMessagePart(container, allSchemas, eContent);
-            // TODO: needs to resolve XsdAttributeGroupDefinition &&
-            // XsdModelGroupDefinition
+			processXsdElementDeclaration(container, allSchemas, eContent);
+			processXsdAttributeDeclaration(container, allSchemas, eContent);
+			processComplexTypeDefinition(container, allSchemas, eContent);
+			processWsdlOperation(container, eContent);
+			processWsdlMessage(container, eContent);
+			processWsdlMessagePart(container, allSchemas, eContent);
+			// TODO: needs to resolve XsdAttributeGroupDefinition &&
+			// XsdModelGroupDefinition
 
-            visited.add(eContent);
-            final ObjectsForResolveContainer childsContainer = findObjectsForResolveInternal(eContent, allSchemas, visited);
-            container.addAll(childsContainer);
-        }
-        return container;
-    }
+			visited.add(eContent);
+			final ObjectsForResolveContainer childsContainer = findObjectsForResolveInternal(eContent, allSchemas,
+					visited);
+			container.addAll(childsContainer);
+		}
+		return container;
+	}
 
-    // =========================================================
-    // findObjectsForResolve helpers
-    // =========================================================
+	// =========================================================
+	// findObjectsForResolve helpers
+	// =========================================================
 
-    private void processXsdElementDeclaration(final ObjectsForResolveContainer container, final List<XSDSchema> allSchemas,
-            final EObject eContent) {
-        if (!(eContent instanceof XSDElementDeclaration)) {
-            return;
-        }
-        processXsdNamedDeclaration(allSchemas, (XSDElementDeclaration) eContent, XsdElementDeclarationSearchResultProcessor
-                .instance(), container);
-    }
+	private void processXsdElementDeclaration(final ObjectsForResolveContainer container,
+			final List<XSDSchema> allSchemas, final EObject eContent) {
+		if (!(eContent instanceof XSDElementDeclaration)) {
+			return;
+		}
+		processXsdNamedDeclaration(allSchemas, (XSDElementDeclaration) eContent,
+				XsdElementDeclarationSearchResultProcessor.instance(), container);
+	}
 
-    private void processXsdAttributeDeclaration(final ObjectsForResolveContainer container, final List<XSDSchema> allSchemas,
-            final EObject eContent) {
-        if (!(eContent instanceof XSDAttributeDeclaration)) {
-            return;
-        }
-        processXsdNamedDeclaration(allSchemas, (XSDAttributeDeclaration) eContent, XsdAttributeDeclarationSearchResultProcessor
-                .instance(), container);
-    }
+	private void processXsdAttributeDeclaration(final ObjectsForResolveContainer container,
+			final List<XSDSchema> allSchemas, final EObject eContent) {
+		if (!(eContent instanceof XSDAttributeDeclaration)) {
+			return;
+		}
+		processXsdNamedDeclaration(allSchemas, (XSDAttributeDeclaration) eContent,
+				XsdAttributeDeclarationSearchResultProcessor.instance(), container);
+	}
 
-    private <T extends XSDNamedComponent> void processXsdNamedDeclaration(final List<XSDSchema> allSchemas,
-            final T xsdNamedDeclaration, final IXsdSearchResultProcessor<T> xsdSearchResultProcessor,
-            final ObjectsForResolveContainer container) {
+	private <T extends XSDNamedComponent> void processXsdNamedDeclaration(final List<XSDSchema> allSchemas,
+			final T xsdNamedDeclaration, final IXsdSearchResultProcessor<T> xsdSearchResultProcessor,
+			final ObjectsForResolveContainer container) {
 
-        if (xsdSearchResultProcessor.isReference(xsdNamedDeclaration)) {
-            final T resolvedDeclaration = xsdSearchResultProcessor.getReference(xsdNamedDeclaration);
+		if (xsdSearchResultProcessor.isReference(xsdNamedDeclaration)) {
+			final T resolvedDeclaration = xsdSearchResultProcessor.getReference(xsdNamedDeclaration);
 
-            final boolean prefixAndNamespaceValid = areDestinationSchemaPrefixAndNamespaceValid(xsdNamedDeclaration.getSchema(),
-                    xsdNamedDeclaration.getElement(), XSDConstants.REF_ATTRIBUTE, resolvedDeclaration.getTargetNamespace());
+			final boolean prefixAndNamespaceValid = areDestinationSchemaPrefixAndNamespaceValid(
+					xsdNamedDeclaration.getSchema(), xsdNamedDeclaration.getElement(), XSDConstants.REF_ATTRIBUTE,
+					resolvedDeclaration.getTargetNamespace());
 
-            if (!prefixAndNamespaceValid) {
-                xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(xsdNamedDeclaration);
-            }
+			if (!prefixAndNamespaceValid) {
+				xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(xsdNamedDeclaration);
+			}
 
-            if (resolvedDeclaration.eContainer() == null
-                    || !isContainerXsdSchemaValid(allSchemas, xsdNamedDeclaration, resolvedDeclaration.getSchema(),
-                            resolvedDeclaration.getTargetNamespace())) {
-                xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(xsdNamedDeclaration);
-            }
+			if (resolvedDeclaration.eContainer() == null
+					|| !isContainerXsdSchemaValid(allSchemas, xsdNamedDeclaration, resolvedDeclaration.getSchema(),
+							resolvedDeclaration.getTargetNamespace())) {
+				xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(xsdNamedDeclaration);
+			}
 
-        } else {
-            final XSDTypeDefinition typeDefinition = xsdSearchResultProcessor.getTypeDefinition(xsdNamedDeclaration);
+		} else {
+			final XSDTypeDefinition typeDefinition = xsdSearchResultProcessor.getTypeDefinition(xsdNamedDeclaration);
 
-            final boolean prefixAndNamespaceValid = areDestinationSchemaPrefixAndNamespaceValid(xsdNamedDeclaration.getSchema(),
-                    xsdNamedDeclaration.getElement(), XSDConstants.TYPE_ATTRIBUTE, typeDefinition != null ? typeDefinition
-                            .getTargetNamespace() : null);
+			final boolean prefixAndNamespaceValid = areDestinationSchemaPrefixAndNamespaceValid(
+					xsdNamedDeclaration.getSchema(), xsdNamedDeclaration.getElement(), XSDConstants.TYPE_ATTRIBUTE,
+					typeDefinition != null ? typeDefinition.getTargetNamespace() : null);
 
-            if (!prefixAndNamespaceValid) {
-                xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(xsdNamedDeclaration);
-            }
+			if (!prefixAndNamespaceValid) {
+				xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(xsdNamedDeclaration);
+			}
 
-            if (typeDefinition != null
-                    && typeDefinition.eContainer() == null
-                    || !isContainerXsdSchemaValid(allSchemas, xsdNamedDeclaration, typeDefinition.getSchema(), typeDefinition
-                            .getTargetNamespace())) {
-                if (!EmfXsdUtils.isSchemaForSchemaNS(typeDefinition.getTargetNamespace())) {
-                    xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(xsdNamedDeclaration);
-                }
-            }
-        }
-    }
+			if (typeDefinition != null
+					&& typeDefinition.eContainer() == null
+					|| !isContainerXsdSchemaValid(allSchemas, xsdNamedDeclaration, typeDefinition.getSchema(),
+							typeDefinition.getTargetNamespace())) {
+				if (!EmfXsdUtils.isSchemaForSchemaNS(typeDefinition.getTargetNamespace())) {
+					xsdSearchResultProcessor.getResolveCollection(xsdNamedDeclaration, container).add(
+							xsdNamedDeclaration);
+				}
+			}
+		}
+	}
 
-    private void processComplexTypeDefinition(final ObjectsForResolveContainer container, final List<XSDSchema> allSchemas,
-            final EObject eContent) {
-        if (!(eContent instanceof XSDComplexTypeDefinition)) {
-            return;
-        }
-        final XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) eContent;
-        final XSDTypeDefinition baseTypeDefinition = complexType.getBaseTypeDefinition();
+	private void processComplexTypeDefinition(final ObjectsForResolveContainer container,
+			final List<XSDSchema> allSchemas, final EObject eContent) {
+		if (!(eContent instanceof XSDComplexTypeDefinition)) {
+			return;
+		}
+		final XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) eContent;
+		final XSDTypeDefinition baseTypeDefinition = complexType.getBaseTypeDefinition();
 
-        // destinationSchemaPrefixAndNamespaceAreValid(complexType.getSchema(),
-        // complexType.getElement(),
-        // XSDConstants.BASE_ATTRIBUTE);
+		// destinationSchemaPrefixAndNamespaceAreValid(complexType.getSchema(),
+		// complexType.getElement(),
+		// XSDConstants.BASE_ATTRIBUTE);
 
-        if (baseTypeDefinition != null
-                && baseTypeDefinition.eContainer() == null
-                || !isContainerXsdSchemaValid(allSchemas, complexType, baseTypeDefinition.getSchema(), baseTypeDefinition
-                        .getTargetNamespace())) {
-            container.getComplexTypesForExtensionResolve().add(complexType);
-            container.getComplexTypesForRestrictionResolve().add(complexType);
-        }
-    }
+		if (baseTypeDefinition != null
+				&& baseTypeDefinition.eContainer() == null
+				|| !isContainerXsdSchemaValid(allSchemas, complexType, baseTypeDefinition.getSchema(),
+						baseTypeDefinition.getTargetNamespace())) {
+			container.getComplexTypesForExtensionResolve().add(complexType);
+			container.getComplexTypesForRestrictionResolve().add(complexType);
+		}
+	}
 
-    private void processWsdlOperation(final ObjectsForResolveContainer container, final EObject eContent) {
-        if (!(eContent instanceof Operation)) {
-            return;
-        }
-        final Operation operation = (Operation) eContent;
-        container.getOperationsForResolve().add(operation);
-    }
+	private void processWsdlOperation(final ObjectsForResolveContainer container, final EObject eContent) {
+		if (!(eContent instanceof Operation)) {
+			return;
+		}
+		final Operation operation = (Operation) eContent;
+		container.getOperationsForResolve().add(operation);
+	}
 
-    private void processWsdlMessage(final ObjectsForResolveContainer container, final EObject eContent) {
-        if (!(eContent instanceof Message)) {
-            return;
-        }
-        final Message message = (Message) eContent;
-        container.getMessagesForResolve().add(message);
-    }
+	private void processWsdlMessage(final ObjectsForResolveContainer container, final EObject eContent) {
+		if (!(eContent instanceof Message)) {
+			return;
+		}
+		final Message message = (Message) eContent;
+		container.getMessagesForResolve().add(message);
+	}
 
-    private void processWsdlMessagePart(final ObjectsForResolveContainer container, final List<XSDSchema> allSchemas,
-            final EObject eContent) {
-        if (!(eContent instanceof Part)) {
-            return;
-        }
-        final Part part = (Part) eContent;
-        if ((part.getElementDeclaration() != null && (part.getElementDeclaration().eContainer() == null || !allSchemas
-                .contains(part.getElementDeclaration().getSchema())))
-                || (part.getTypeDefinition() != null && (part.getTypeDefinition().eContainer() == null || !allSchemas
-                        .contains(part.getTypeDefinition().getSchema())))) {
+	private void processWsdlMessagePart(final ObjectsForResolveContainer container, final List<XSDSchema> allSchemas,
+			final EObject eContent) {
+		if (!(eContent instanceof Part)) {
+			return;
+		}
+		final Part part = (Part) eContent;
+		if ((part.getElementDeclaration() != null && (part.getElementDeclaration().eContainer() == null || !allSchemas
+				.contains(part.getElementDeclaration().getSchema())))
+				|| (part.getTypeDefinition() != null && (part.getTypeDefinition().eContainer() == null || !allSchemas
+						.contains(part.getTypeDefinition().getSchema())))) {
 
-            container.getMessagePartsForResolve().add(part);
-        }
-    }
+			container.getMessagePartsForResolve().add(part);
+		}
+	}
 
-    // =========================================================
-    // helpers
-    // =========================================================
+	// =========================================================
+	// helpers
+	// =========================================================
 
-    public boolean isContainerXsdSchemaValid(final List<XSDSchema> allSchemas, final XSDNamedComponent sourceComponent,
-            final XSDSchema destinationSchema, final String destinationSchemaTargetNamespace) {
-        if (destinationSchema == null) {
-            return false;
-        }
-        final String destinationSchemaLocation = destinationSchema.getSchemaLocation();
-        final String sourceSchemaLocation = sourceComponent.getSchema().getSchemaLocation();
-        final boolean resolveComponentSchemaIsInSameDocument = destinationSchemaLocation != null
-                && destinationSchemaLocation.equals(sourceSchemaLocation);
+	public boolean isContainerXsdSchemaValid(final List<XSDSchema> allSchemas, final XSDNamedComponent sourceComponent,
+			final XSDSchema destinationSchema, final String destinationSchemaTargetNamespace) {
+		if (destinationSchema == null) {
+			return false;
+		}
+		final String destinationSchemaLocation = destinationSchema.getSchemaLocation();
+		final String sourceSchemaLocation = sourceComponent.getSchema().getSchemaLocation();
+		final boolean resolveComponentSchemaIsInSameDocument = destinationSchemaLocation != null
+				&& destinationSchemaLocation.equals(sourceSchemaLocation);
 
-        final String sourceSchemaTNS = sourceComponent.getSchema().getTargetNamespace();
-        final boolean needsImportOrIncludeDirective = !(resolveComponentSchemaIsInSameDocument && sourceSchemaTNS != null && sourceSchemaTNS
-                .equals(destinationSchemaTargetNamespace));
+		final String sourceSchemaTNS = sourceComponent.getSchema().getTargetNamespace();
+		final boolean sourceAndDestinationNamespaceAreTheSame = (sourceSchemaTNS == null && destinationSchemaTargetNamespace == null)
+				|| (sourceSchemaTNS != null && sourceSchemaTNS.equals(destinationSchemaTargetNamespace));
+		final boolean needsImportOrIncludeDirective = !(resolveComponentSchemaIsInSameDocument && sourceAndDestinationNamespaceAreTheSame);
 
-        boolean hasImportOrIncludeDirective = true;
-        if (needsImportOrIncludeDirective) {
-            hasImportOrIncludeDirective = hasImportOrIncludeDirective(sourceComponent.getSchema(), destinationSchema,
-                    destinationSchemaTargetNamespace);
-        }
+		boolean hasImportOrIncludeDirective = true;
+		if (needsImportOrIncludeDirective) {
+			hasImportOrIncludeDirective = hasImportOrIncludeDirective(sourceComponent.getSchema(), destinationSchema,
+					destinationSchemaTargetNamespace);
+		}
 
-        final boolean isReachable = !needsImportOrIncludeDirective || needsImportOrIncludeDirective
-                && hasImportOrIncludeDirective;
+		final boolean isReachable = !needsImportOrIncludeDirective || needsImportOrIncludeDirective
+				&& hasImportOrIncludeDirective;
 
-        return isReachable
-                && (!resolveComponentSchemaIsInSameDocument || resolveComponentSchemaIsInSameDocument
-                        && isDestinationSchemaInAllSchemas(allSchemas, destinationSchema));
-    }
+		return isReachable
+				&& (!resolveComponentSchemaIsInSameDocument || resolveComponentSchemaIsInSameDocument
+						&& isDestinationSchemaInAllSchemas(allSchemas, destinationSchema));
+	}
 
-    private boolean isDestinationSchemaInAllSchemas(final List<XSDSchema> allSchemas, final XSDSchema destinationSchema) {
-        for (final XSDSchema xsdSchema : allSchemas) {
-            if (xsdSchema.getTargetNamespace() != null
-                    && xsdSchema.getTargetNamespace().equals(destinationSchema.getTargetNamespace())) {
-                return true;
-            }
-        }
-        return false;
-    }
+	private boolean isDestinationSchemaInAllSchemas(final List<XSDSchema> allSchemas, final XSDSchema destinationSchema) {
+		for (final XSDSchema xsdSchema : allSchemas) {
+			if (xsdSchema.getTargetNamespace() == null && destinationSchema.getTargetNamespace() == null) {
+				return true;
+			}
+			if (xsdSchema.getTargetNamespace() != null
+					&& xsdSchema.getTargetNamespace().equals(destinationSchema.getTargetNamespace())) {
+				return true;
+			}
+		}
+		return false;
+	}
 
-    /**
-     * Checks if the given source schema has access to the destinationSchema. If
-     * destinationSchemaTargetNamespace is for schema for schema always returns
-     * true.
-     */
-    private boolean hasImportOrIncludeDirective(final XSDSchema sourceSchema, final XSDSchema destinationSchema,
-            final String destinationSchemaTargetNamespace) {
-        if (EmfXsdUtils.isSchemaForSchemaNS(destinationSchemaTargetNamespace)) {
-            return true;
-        }
-        if (destinationSchemaTargetNamespace == null) {
-            return false;
-        }
+	/**
+	 * Checks if the given source schema has access to the destinationSchema. If
+	 * destinationSchemaTargetNamespace is for schema for schema always returns
+	 * true.
+	 */
+	private boolean hasImportOrIncludeDirective(final XSDSchema sourceSchema, final XSDSchema destinationSchema,
+			final String destinationSchemaTargetNamespace) {
+		if (EmfXsdUtils.isSchemaForSchemaNS(destinationSchemaTargetNamespace)) {
+			return true;
+		}
+		if (destinationSchemaTargetNamespace == null) {
+			return false;
+		}
 
-        final EList<XSDSchemaContent> sourceComponentSchemaContents = sourceSchema.getContents();
-        for (final XSDSchemaContent content : sourceComponentSchemaContents) {
-            if (content instanceof XSDImport) {
-                final XSDImport xsdImport = (XSDImport) content;
-                if (destinationSchemaTargetNamespace.equals(xsdImport.getNamespace())) {
-                    return true;
-                }
-            } else if (content instanceof XSDInclude) {
-                final XSDInclude include = (XSDInclude) content;
-                final String includeSchemaLocation = include.getSchema().getSchemaLocation();
-                final String destinationSchemaLocation = destinationSchema.getSchema().getSchemaLocation();
-                if (includeSchemaLocation != null && includeSchemaLocation.equals(destinationSchemaLocation)) {
-                    return true;
-                }
-            }
-        }
+		final EList<XSDSchemaContent> sourceComponentSchemaContents = sourceSchema.getContents();
+		for (final XSDSchemaContent content : sourceComponentSchemaContents) {
+			if (content instanceof XSDImport) {
+				final XSDImport xsdImport = (XSDImport) content;
+				if (destinationSchemaTargetNamespace.equals(xsdImport.getNamespace())) {
+					return true;
+				}
+			} else if (content instanceof XSDInclude) {
+				final XSDInclude include = (XSDInclude) content;
+				final String includeSchemaLocation = include.getSchema().getSchemaLocation();
+				final String destinationSchemaLocation = destinationSchema.getSchema().getSchemaLocation();
+				if (includeSchemaLocation != null && includeSchemaLocation.equals(destinationSchemaLocation)) {
+					return true;
+				}
+			}
+		}
 
-        return false;
-    }
+		return false;
+	}
 
-    // =========================================================
-    // helpers
-    // =========================================================
+	// =========================================================
+	// helpers
+	// =========================================================
 
-    /**
-     * This method checks if the prefix value of the given element is as
-     * expected.
-     */
-    private boolean areDestinationSchemaPrefixAndNamespaceValid(final XSDSchema xsdSchema, final Element element,
-            final String attributeName, final String expectedDestinationSchemaNamespace) {
+	/**
+	 * This method checks if the prefix value of the given element is as
+	 * expected.
+	 */
+	private boolean areDestinationSchemaPrefixAndNamespaceValid(final XSDSchema xsdSchema, final Element element,
+			final String attributeName, final String expectedDestinationSchemaNamespace) {
 
-        // FIXME: Intentionally disabling the prefix checks. The WSDL API is not
-        // running the validation on the XSDs when validation performed on the
-        // Definition. The error markers cannot be "removed" when undo of
-        // operation which breaks the prefix value.
-        if (true) {
-            return true;
-        }
-        
-        if(expectedDestinationSchemaNamespace == null) {
-            return true;
-        }
+		// FIXME: Intentionally disabling the prefix checks. The WSDL API is not
+		// running the validation on the XSDs when validation performed on the
+		// Definition. The error markers cannot be "removed" when undo of
+		// operation which breaks the prefix value.
+		if (true) {
+			return true;
+		}
 
-        final String destinationNamespacePrefix = getDestinationNamespacePrefix(element, attributeName);
-        if (destinationNamespacePrefix == null) {
-            // no prefix, same schema
-            return true;
-        }
+		if (expectedDestinationSchemaNamespace == null) {
+			return true;
+		}
 
-        final String actualDestinationNamespace = xsdSchema.getQNamePrefixToNamespaceMap().get(destinationNamespacePrefix);
-        return expectedDestinationSchemaNamespace.equals(actualDestinationNamespace);
-    }
+		final String destinationNamespacePrefix = getDestinationNamespacePrefix(element, attributeName);
+		if (destinationNamespacePrefix == null) {
+			// no prefix, same schema
+			return true;
+		}
 
-    private String getDestinationNamespacePrefix(final Element element, final String attributeName) {
-        if (element == null) {
-            return null;
-        }
-        if (!ElementAttributeUtils.hasAttributeValue(element, attributeName)) {
-            return null;
-        }
-        final String qName = element.getAttribute(attributeName);
-        return UpdateNSPrefixUtils.instance().extractPrefixFromQName(qName);
-    }
+		final String actualDestinationNamespace = xsdSchema.getQNamePrefixToNamespaceMap().get(
+				destinationNamespacePrefix);
+		return expectedDestinationSchemaNamespace.equals(actualDestinationNamespace);
+	}
+
+	private String getDestinationNamespacePrefix(final Element element, final String attributeName) {
+		if (element == null) {
+			return null;
+		}
+		if (!ElementAttributeUtils.hasAttributeValue(element, attributeName)) {
+			return null;
+		}
+		final String qName = element.getAttribute(attributeName);
+		return UpdateNSPrefixUtils.instance().extractPrefixFromQName(qName);
+	}
 
 }
diff --git a/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/all/ModelCommandsTestSuite.java b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/all/ModelCommandsTestSuite.java
index 2ffb482..3694129 100644
--- a/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/all/ModelCommandsTestSuite.java
+++ b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/all/ModelCommandsTestSuite.java
@@ -103,6 +103,7 @@
 import org.eclipse.wst.sse.sieditor.test.model.commands.xsd.AddFacetCommandTest;

 import org.eclipse.wst.sse.sieditor.test.model.commands.xsd.AddFacetToElementTest;

 import org.eclipse.wst.sse.sieditor.test.model.commands.xsd.AddGlobalElementCommandTest;

+import org.eclipse.wst.sse.sieditor.test.model.commands.xsd.AddGlobalElementToSchemaWithNullTargetNamespaceTest;

 import org.eclipse.wst.sse.sieditor.test.model.commands.xsd.AddSchemaForSchemaXSDCommandTest;

 import org.eclipse.wst.sse.sieditor.test.model.commands.xsd.AddSimpleTypeCommandTest;

 import org.eclipse.wst.sse.sieditor.test.model.commands.xsd.CopyElementCommandTest;

@@ -176,10 +177,11 @@
     AddEnumFacetToElementTest.class,

     AddComplexTypeCommandTest.class,

     AddGlobalElementCommandTest.class,

+    AddGlobalElementToSchemaWithNullTargetNamespaceTest.class,

     /*

      * AddAnotationToXSDTypeDefinitionCommandTest. class , - EXCLUDED UNTIL

      * THE FEATURE IS FIXED

-     */

+     */ 

     AddAnotationToXSDElementDeclarationCommandTest.class,

     AddAnotationToXSDAttributeDeclarationCommandTest.class,

     AddAnotationToXSDAttributeDeclarationSimpleCommandTest.class,

@@ -259,7 +261,6 @@
     SetElementTypeCommandXSDTest.class,

     OperationsOnRemovedObjectTest.class,

     AddMessageNoNSCommandTest.class,

-

     SetElementTypeCannotReuseFacetsCommandTest.class,

     SetElementTypeReuseFacetsCommandTest.class,

     TestRenamePartCommandWithMultiReferredPart.class,

@@ -267,11 +268,9 @@
     MakeTypeAnonymousCommandTest.class,

     InlineStructureTypeCommandTest.class,

     ToggleBetweenMakeTypeAnonymousAndMakeTypeGlobalCommandTest.class,

-

     SetTargetNamespaceTestsSuite.class,

     CompositeTextOperationWrapperTest.class,

     AddGlobalElementAndRenameToExistingOneCommandTest.class,

-

     ExtractNamespaceRunnableWithoutImportTest.class,

     ExtractNamespaceRunnableWithImportTest.class,

     SchemaDependenciesUtilsTest.class,

@@ -283,10 +282,8 @@
     CloneNamespaceCommandTest.class,

     InlineNamespaceCompositeCommandTest.class,

     InlineNamespaceCompositeCommandTestWithAnnotations.class,

-

     SetStructureTypeBaseTypeTestsSuite.class,

     CompositeTextOperationWrapperNotifiesTest.class,

-

     SetAttributeDefaultValueCommandTest.class,

     SetElementDefaultValueCommandTest.class,

     ReconcilerCalledAfterInliningTest.class,

diff --git a/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/model/commands/xsd/AddAnotationToXSDTypeDefinitionCommandTest.java b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/model/commands/xsd/AddAnotationToXSDTypeDefinitionCommandTest.java
index c8b5587..5e57edf 100644
--- a/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/model/commands/xsd/AddAnotationToXSDTypeDefinitionCommandTest.java
+++ b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/model/commands/xsd/AddAnotationToXSDTypeDefinitionCommandTest.java
@@ -15,9 +15,6 @@
 package org.eclipse.wst.sse.sieditor.test.model.commands.xsd;

 

 import org.eclipse.core.runtime.IStatus;

-import org.eclipse.xsd.XSDNamedComponent;

-import org.eclipse.xsd.XSDTypeDefinition;

-

 import org.eclipse.wst.sse.sieditor.command.common.AbstractNotificationOperation;

 import org.eclipse.wst.sse.sieditor.command.emf.xsd.AddAnotationCommand;

 import org.eclipse.wst.sse.sieditor.command.emf.xsd.AddSimpleTypeCommand;

@@ -27,58 +24,64 @@
 import org.eclipse.wst.sse.sieditor.model.xsd.api.ISchema;

 import org.eclipse.wst.sse.sieditor.model.xsd.api.IType;

 import org.eclipse.wst.sse.sieditor.test.model.commands.AbstractCommandTest;

+import org.eclipse.xsd.XSDNamedComponent;

+import org.eclipse.xsd.XSDTypeDefinition;

+import org.junit.Ignore;

 

 /**

  * This test fails due to a bug or wrong usage of classes from org.eclipse.xsd

  * When the issue is fixed, the test should perform fine

- * 

- *

- * 

  */

 public class AddAnotationToXSDTypeDefinitionCommandTest extends AbstractCommandTest {

-    private static final String TYPE_NAME = "SimpleTypeWithDoc"; //$NON-NLS-1$

-    private static final String TARGET_NAMESPACE = "http://sap.com/xi/Purchasing"; //$NON-NLS-1$

+	private static final String TYPE_NAME = "SimpleTypeWithDoc"; //$NON-NLS-1$

+	private static final String TARGET_NAMESPACE = "http://sap.com/xi/Purchasing"; //$NON-NLS-1$

 

-    @Override

-    protected void assertPostRedoState(final IStatus redoStatus, final IWsdlModelRoot modelRoot) {

-        final XSDNamedComponent component = modelRoot.getDescription().getSchema(TARGET_NAMESPACE)[0].getType(false, TYPE_NAME)

-                .getComponent();

-        assertTrue(component instanceof XSDTypeDefinition);

-        assertNotNull(((XSDTypeDefinition) component).getAnnotation());

-        assertTrue(((XSDTypeDefinition) component).getAnnotations().size() == 1);

-    }

+	@Ignore("this test is skipped because of bug in the eclipse xsd project")

+	@Override

+	public void testCommandExecution() throws Throwable {

+		super.testCommandExecution();

+	}

 

-    @Override

-    protected void assertPostUndoState(final IStatus undoStatus, final IWsdlModelRoot modelRoot) {

-        final XSDNamedComponent component = modelRoot.getDescription().getSchema(TARGET_NAMESPACE)[0].getType(false, TYPE_NAME)

-                .getComponent();

-        assertTrue(component instanceof XSDTypeDefinition);

-        assertNull(((XSDTypeDefinition) component).getAnnotation());

-        assertTrue(((XSDTypeDefinition) component).getAnnotations().size() == 0);

-    }

+	@Override

+	protected void assertPostRedoState(final IStatus redoStatus, final IWsdlModelRoot modelRoot) {

+		final XSDNamedComponent component = modelRoot.getDescription().getSchema(TARGET_NAMESPACE)[0].getType(false,

+				TYPE_NAME).getComponent();

+		assertTrue(component instanceof XSDTypeDefinition);

+		assertNotNull(((XSDTypeDefinition) component).getAnnotation());

+		assertTrue(((XSDTypeDefinition) component).getAnnotations().size() == 1);

+	}

 

-    @Override

-    protected AbstractNotificationOperation getOperation(final IWsdlModelRoot modelRoot) throws Exception {

-        final ISchema schema = modelRoot.getDescription().getSchema(TARGET_NAMESPACE)[0];

-        final IXSDModelRoot xsdModelRoot = XSDFactory.getInstance().createXSDModelRoot(schema.getComponent());

-        final AddSimpleTypeCommand command = new AddSimpleTypeCommand(xsdModelRoot, schema, TYPE_NAME) {

-            @Override

-            public boolean canUndo() {

-                return false;

-            }

+	@Override

+	protected void assertPostUndoState(final IStatus undoStatus, final IWsdlModelRoot modelRoot) {

+		final XSDNamedComponent component = modelRoot.getDescription().getSchema(TARGET_NAMESPACE)[0].getType(false,

+				TYPE_NAME).getComponent();

+		assertTrue(component instanceof XSDTypeDefinition);

+		assertNull(((XSDTypeDefinition) component).getAnnotation());

+		assertTrue(((XSDTypeDefinition) component).getAnnotations().size() == 0);

+	}

 

-            @Override

-            public boolean canRedo() {

-                return false;

-            }

-        };

-        assertTrue(xsdModelRoot.getEnv().execute(command).isOK());

-        final IType type = schema.getType(false, TYPE_NAME);

-        final XSDNamedComponent component = type.getComponent();

-        assertTrue(component instanceof XSDTypeDefinition);

-        final XSDTypeDefinition typeDef = (XSDTypeDefinition) component;

-        assertNull(typeDef.getAnnotation());

-        return new AddAnotationCommand(typeDef, xsdModelRoot, type);

-    }

+	@Override

+	protected AbstractNotificationOperation getOperation(final IWsdlModelRoot modelRoot) throws Exception {

+		final ISchema schema = modelRoot.getDescription().getSchema(TARGET_NAMESPACE)[0];

+		final IXSDModelRoot xsdModelRoot = XSDFactory.getInstance().createXSDModelRoot(schema.getComponent());

+		final AddSimpleTypeCommand command = new AddSimpleTypeCommand(xsdModelRoot, schema, TYPE_NAME) {

+			@Override

+			public boolean canUndo() {

+				return false;

+			}

+

+			@Override

+			public boolean canRedo() {

+				return false;

+			}

+		};

+		assertTrue(xsdModelRoot.getEnv().execute(command).isOK());

+		final IType type = schema.getType(false, TYPE_NAME);

+		final XSDNamedComponent component = type.getComponent();

+		assertTrue(component instanceof XSDTypeDefinition);

+		final XSDTypeDefinition typeDef = (XSDTypeDefinition) component;

+		assertNull(typeDef.getAnnotation());

+		return new AddAnotationCommand(typeDef, xsdModelRoot, type);

+	}

 

 }

diff --git a/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/model/commands/xsd/AddGlobalElementToSchemaWithNullTargetNamespaceTest.java b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/model/commands/xsd/AddGlobalElementToSchemaWithNullTargetNamespaceTest.java
new file mode 100644
index 0000000..7fc3d91
--- /dev/null
+++ b/plugins/org.eclipse.wst.sse.sieditor.test/api/org/eclipse/wst/sse/sieditor/test/model/commands/xsd/AddGlobalElementToSchemaWithNullTargetNamespaceTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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:
+ *    Emil Simeonov - initial API and implementation.
+ *    Dimitar Donchev - initial API and implementation.
+ *    Dimitar Tenev - initial API and implementation.
+ *    Nevena Manova - initial API and implementation.
+ *    Georgi Konstantinov - initial API and implementation.
+ *******************************************************************************/
+package org.eclipse.wst.sse.sieditor.test.model.commands.xsd;
+
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.sse.sieditor.command.common.AbstractNotificationOperation;
+import org.eclipse.wst.sse.sieditor.command.emf.xsd.AddStructureTypeCommand;
+import org.eclipse.wst.sse.sieditor.model.api.IXSDModelRoot;
+import org.eclipse.wst.sse.sieditor.model.xsd.api.IElement;
+import org.eclipse.wst.sse.sieditor.model.xsd.api.IStructureType;
+import org.eclipse.wst.sse.sieditor.model.xsd.api.IType;
+import org.eclipse.wst.sse.sieditor.model.xsd.impl.AbstractType;
+import org.eclipse.wst.sse.sieditor.model.xsd.impl.Schema;
+import org.eclipse.wst.sse.sieditor.model.xsd.impl.StructureType;
+import org.eclipse.wst.sse.sieditor.test.model.commands.AbstractXSDCommandTest;
+
+
+/**
+ * This test covers the following test case:
+ * <ol>
+ * <li>Open XSD file without targetNamespace</li>
+ * <li>Add new global element</li>
+ * <li>Check that the element is added and no validation errors are present</li>
+ * </ol>
+ * 
+ * @author Stanislav Nichev
+ *
+ */
+public class AddGlobalElementToSchemaWithNullTargetNamespaceTest extends AbstractXSDCommandTest {
+
+	private static final String NEW_ELEMENT_NAME = "newGlobalElement";
+
+	@Override
+	protected String getFilename() {
+		return "element_null_tns_name_not_resolved.xsd";
+	}
+
+	@Override
+	protected String getFolderName() {
+		return "pub/csns/nullTNS/";
+	}
+
+	private Schema schema;
+	private AbstractType type;
+
+	@Override
+	protected AbstractNotificationOperation getOperation(final IXSDModelRoot modelRoot) throws Exception {
+		schema = (Schema) modelRoot.getSchema();
+		type = (AbstractType) Schema.getDefaultSimpleType();
+
+		assertThereAreNoValidationErrors();
+		return new AddStructureTypeCommand(schema.getModelRoot(), schema, "add global element", NEW_ELEMENT_NAME, true, type);
+	}
+
+	@Override
+	protected void assertPostRedoState(final IStatus redoStatus, final IXSDModelRoot modelRoot) {
+		assertThereAreNoValidationErrors();
+		
+		final IType[] types = schema.getAllTypes(NEW_ELEMENT_NAME);
+		assertEquals(1, types.length);
+		assertNotNull(types[0]);
+		assertTrue(types[0] instanceof IStructureType);
+
+		final IStructureType newElement = (IStructureType) types[0];
+
+		assertTrue(newElement.isElement());
+		assertEquals(StructureType.class, newElement.getType().getClass());
+
+		final Collection<IElement> subElements = newElement.getAllElements();
+
+		assertEquals(1, subElements.size());
+		assertEquals(type, subElements.iterator().next().getType());
+	}
+
+	@Override
+	protected void assertPostUndoState(final IStatus undoStatus, final IXSDModelRoot modelRoot) {
+		assertThereAreNoValidationErrors();
+		assertNull(schema.getAllTypes(NEW_ELEMENT_NAME));
+	}
+
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.sse.sieditor.test/data/pub/csns/nullTNS/element_null_tns_name_not_resolved.xsd b/plugins/org.eclipse.wst.sse.sieditor.test/data/pub/csns/nullTNS/element_null_tns_name_not_resolved.xsd
new file mode 100644
index 0000000..b97fd22
--- /dev/null
+++ b/plugins/org.eclipse.wst.sse.sieditor.test/data/pub/csns/nullTNS/element_null_tns_name_not_resolved.xsd
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+	<xsd:element name="Element1" type="StructureType1"/>
+	<xsd:complexType name="StructureType1">
+		<xsd:sequence>
+			<xsd:element minOccurs="1" maxOccurs="1" name="Element1"
+				type="xsd:string"></xsd:element>
+		</xsd:sequence>
+	</xsd:complexType>
+</xsd:schema>
\ No newline at end of file