Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornitind2006-01-30 23:54:58 +0000
committernitind2006-01-30 23:54:58 +0000
commitee366e5d22114e07303e06e8942263c5fe904af3 (patch)
tree714d91f1e59d470880e31ac39024085d978d67f7 /bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml
parent5e5be6638f44b6b506e75d6ab4ea5b5c52bd4e8b (diff)
downloadwebtools.sourceediting-20060130_1915.tar.gz
webtools.sourceediting-20060130_1915.tar.xz
webtools.sourceediting-20060130_1915.zip
This commit was manufactured by cvs2svn to create tag 'v20060130_1915'.v20060130_1915
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml')
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java343
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java509
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERendererFactory.java46
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/UIResourceHandler.java61
4 files changed, 0 insertions, 959 deletions
diff --git a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java
deleted file mode 100644
index 6f144d5c01..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSEAdapter.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 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.emf2xml;
-
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapter;
-import org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapterImpl;
-import org.eclipse.wst.common.internal.emf.resource.EMF2DOMRenderer;
-import org.eclipse.wst.common.internal.emf.resource.Translator;
-import org.eclipse.wst.common.internal.emf.resource.TranslatorResource;
-import org.eclipse.wst.common.internal.emf.utilities.Assert;
-import org.eclipse.wst.common.internal.emf.utilities.DOMUtilities;
-import org.eclipse.wst.common.internal.emf.utilities.FeatureValueConversionException;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-public class EMF2DOMSSEAdapter extends EMF2DOMAdapterImpl implements INodeAdapter {
-
-
-
- public EMF2DOMSSEAdapter(TranslatorResource resource, Document document, EMF2DOMRenderer renderer, Translator translator) {
- super(resource, document, renderer, translator);
- }
-
-
- public EMF2DOMSSEAdapter(Notifier object, Node node, EMF2DOMRenderer renderer, Translator translator) {
- super(object, node, renderer, translator);
- }
-
-
- public EMF2DOMSSEAdapter(Node node, EMF2DOMRenderer renderer, Translator translator) {
- super(node, renderer, translator);
- }
-
- /*
- * This method is called when the DOM node changes. It attempts to update MOF object based on
- * the changes.
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
-
- if (!isNotificationEnabled())
- return;
-
- debugDOMNotify(notifier, eventType, changedFeature, oldValue, newValue);
-
- if (notifier != getNode() && eventType != INodeNotifier.CHANGE) {
- // This is the case where the notification was sent from a
- // sub node. Use the notifiers name to determine which
- // MOF feature to update. Note that is is assumed that if
- // the eventType is CHANGE then it attribute on a path node
- // changing. This was put in for the EGL group.
- if (notifier instanceof Element) {
- if (eventType == INodeNotifier.STRUCTURE_CHANGED || eventType == INodeNotifier.CONTENT_CHANGED || eventType == INodeNotifier.CHANGE) {
- Element notifyingNode = (Element) notifier;
- Translator map = findTranslator(notifyingNode.getNodeName(), false);
- if (map != null)
- updateMOFFeature(map, getNode(), getEObject());
- }
- }
- } else {
- // Update everything on STRUCTURE_CHANGE or CONTENT_CHANGE.
- // Other event types occur too often.
- if (eventType == INodeNotifier.STRUCTURE_CHANGED || eventType == INodeNotifier.CONTENT_CHANGED) {
- updateMOF();
- }
- // Update just the attribute that changed.
- else if (eventType == INodeNotifier.CHANGE) {
- Translator map = findTranslator(changedFeature.toString(), true);
- if (map != null)
- updateMOFFeature(map, getNode(), getEObject());
- }
- }
- }
-
-
- /*
- * Prints out a DOM notification for debugging.
- */
- protected void debugDOMNotify(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue) {
- if (fDebug) {
- String notifType = ""; //$NON-NLS-1$
- switch (eventType) {
- case INodeNotifier.ADD :
- notifType = "ADD"; //$NON-NLS-1$
- break;
- case INodeNotifier.REMOVE :
- notifType = "REMOVE"; //$NON-NLS-1$
- break;
- case INodeNotifier.CHANGE :
- notifType = "CHANGE"; //$NON-NLS-1$
- break;
- case INodeNotifier.CONTENT_CHANGED :
- notifType = "CONTENT_CHANGED"; //$NON-NLS-1$
- break;
- case INodeNotifier.STRUCTURE_CHANGED :
- notifType = "STRUCTURE_CHANGE"; //$NON-NLS-1$
- break;
- }
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError("DOM Change: " + notifType); //$NON-NLS-1$
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError("\tnotifier : " + notifier); //$NON-NLS-1$
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError("\tchangedFeature: " + changedFeature); //$NON-NLS-1$
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError("\toldValue : " + oldValue); //$NON-NLS-1$
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError("\tnewValue : " + newValue); //$NON-NLS-1$
- }
- }
-
- protected String getNewlineString(Node node) {
- // we should always have XMLNode, and Flatmodel,
- // and consquently a valid "preferred" line delimiter,
- // but just to be safe, we'll assign something
- // by default.
- if (node instanceof IDOMNode) {
- IDOMNode xmlNode = (IDOMNode) node;
- IStructuredDocument document = xmlNode.getStructuredDocument();
- if (document != null) {
- return document.getLineDelimiter();
- }
- }
- return DOMUtilities.NEWLINE_STRING;
- }
-
- protected String primGetIndentString(Node node) {
- IStructuredDocument flatModel = ((IDOMNode) node).getStructuredDocument();
- int nodeStartOff = ((IDOMNode) node).getStartOffset();
-
- int startOff = Math.max(0, nodeStartOff - 100);
- int endOff = nodeStartOff;
-
- try {
- String text = flatModel.get(startOff, endOff - startOff);
-
- int inx = text.length() - 1;
- if (inx >= 0) {
- for (; inx >= 0; inx--) {
- char ch = text.charAt(inx);
- if (Character.isWhitespace(ch) && ch != '\n' && ch != '\r') {
- continue;
- }
- inx++;
- break;
- }
-
- return text.substring(inx);
- }
- } catch (org.eclipse.jface.text.BadLocationException ex) {
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(ex);
- }
- return ""; //$NON-NLS-1$
- }
-
- protected IDOMNode getXMLNode() {
- return (IDOMNode) getNode();
- }
-
- /**
- * @see com.ibm.etools.emf2xml.impl.EMF2DOMAdapterImpl#primAddDOMAdapter(Node, EMF2DOMAdapter)
- */
- protected void primAddDOMAdapter(Node aNode, EMF2DOMAdapter anAdapter) {
- ((IDOMNode) aNode).addAdapter((EMF2DOMSSEAdapter) anAdapter);
- }
-
- protected EMF2DOMAdapter primGetExistingAdapter(Node aNode) {
- return (EMF2DOMAdapter) ((IDOMNode) aNode).getExistingAdapter(EMF2DOMAdapter.ADAPTER_CLASS);
-
- }
-
- protected void removeDOMAdapter(Node aNode, EMF2DOMAdapter anAdapter) {
- ((IDOMNode) aNode).removeAdapter((EMF2DOMSSEAdapter) anAdapter);
- }
-
- protected void setEmptyTag(Element element) {
- ((ElementImpl) element).setEmptyTag(true);
- }
-
- protected boolean isEmptyTag(Element parent) {
- return ((ElementImpl) parent).isEmptyTag();
- }
-
- protected IDOMModel getXMLModel() {
- if (getNode() != null)
- return ((IDOMNode) getNode()).getModel();
- return null;
- }
-
- public void updateDOM() {
- if (!isNotificationEnabled())
- return;
- try {
- disableUndoManagementIfNecessary();
- primUpdateDOM();
- } finally {
- enableUndoManagement();
- }
- }
-
- protected void preUpdateDOMFeature(Translator map, Node node, EObject mofObject) {
- super.preUpdateDOMFeature(map, node, mofObject);
- disableUndoManagementIfNecessary();
- }
-
- protected void disableUndoManagementIfNecessary() {
- IDOMModel model = getXMLModel();
- if (model != null && model.getUndoManager() != null)
- model.disableUndoManagement();
- }
-
- protected void postUpdateDOMFeature(Translator map, Node node, EObject mofObject) {
- enableUndoManagement();
- }
-
- protected void enableUndoManagement() {
- IDOMModel model = getXMLModel();
- if (model != null && model.getUndoManager() != null)
- model.enableUndoManagement();
- }
-
- protected void indent(Node node, Translator map) {
- Assert.isNotNull(node.getParentNode(), "Node must be connected into the tree"); //$NON-NLS-1$
- Assert.isNotNull(node);
-
- String indentString = calcIndentString(node);
-
- // Indent before the start tag
- indentStartTag(indentString, node, map);
-
- // Indent before the end tag
- indentEndTag(indentString, node, map);
- }
-
- /**
- * Indent before the end tag of the <node>passed in.
- */
- protected void indentEndTag(String indentString, Node node, Translator map) {
- if (!map.shouldIndentEndTag())
- return;
- String domPath = map.getDOMPath();
-
- if ((!map.isManagedByParent() && !map.isDOMTextValue()) || (map.isManagedByParent() && domPath.length() != 0) && node.getNodeName().equals(domPath)) {
- Text newWS = node.getOwnerDocument().createTextNode(getNewlineString(node) + indentString); //$NON-NLS-1$
- DOMUtilities.insertBeforeNode(node, newWS, null);
- }
- }
-
- /**
- * Indent before the start tag of the <node>passed in.
- */
- protected void indentStartTag(String indentString, Node node, Translator map) {
-
- Node parent = node.getParentNode();
- Text newWS = node.getOwnerDocument().createTextNode(getNewlineString(node) + indentString); //$NON-NLS-1$
- DOMUtilities.insertAfterNode(parent, newWS, DOMUtilities.getPreviousNodeSibling(node));
- }
-
- protected String calcIndentString(Node node) {
- Assert.isNotNull(node);
- Assert.isNotNull(node.getParentNode(), "Node must be connected into the tree"); //$NON-NLS-1$
-
- Node parent = node.getParentNode();
-
- String indentString = getNewlineString(node);
-
- // Find indentation string for this node based on its sibling or parent
- Node previousSibling = DOMUtilities.getPreviousNodeSibling(node);
- if (previousSibling != null) {
- indentString = primGetIndentString(previousSibling);
- } else {
- String parentIndentString = primGetIndentString(parent);
- indentString = parentIndentString + DOMUtilities.INDENT_STRING;
- }
- return indentString;
- }
-
- /**
- * @see com.ibm.etools.emf2xml.impl.AbstractEMF2DOMAdapterImpl#reorderDOMChild(Node, Node, Node,
- * Translator)
- */
- protected void reorderDOMChild(Node parentNode, Node childNode, Node insertBeforeNode, Translator map) {
- super.reorderDOMChild(parentNode, childNode, insertBeforeNode, map);
- // Since reordering deletes all the whitespace before the node, we must indent .
- if (insertBeforeNode != null && insertBeforeNode.getNodeType() == Node.ELEMENT_NODE)
- indentStartTag(calcIndentString(insertBeforeNode), insertBeforeNode, map);
- else
- indentStartTag(calcIndentString(childNode), childNode, map);
- }
-
- /**
- * Create an adapter for a child DOM node
- *
- * @param node
- * org.w3c.dom.Node The node to create the adapter for.
- */
- protected EMF2DOMAdapter primCreateAdapter(EObject mofObject, Translator childMap) {
-
- Element newNode = createNewNode(mofObject, childMap);
- return new EMF2DOMSSEAdapter(mofObject, newNode, fRenderer, childMap);
- }
-
-
- /**
- * Create an adapter for a child DOM node
- *
- * @param node
- * org.w3c.dom.Node The node to create the adapter for.
- */
- protected EMF2DOMAdapter primCreateAdapter(Node node, Translator childMap) {
- return new EMF2DOMSSEAdapter(node, fRenderer, childMap);
- }
-
- /*
- * Do nothing for SED, we will tolerate anything they add
- */
- protected void handleInvalidMultiNodes(String nodeName) {
- //Do nothing
- }
-
- /*
- * Do nothing for SED, we will tolerate anything they add
- */
- protected void handleFeatureValueConversionException(FeatureValueConversionException ex) {
- //Do nothing
- }
-
-
-
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java
deleted file mode 100644
index d7e6d05f1d..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERenderer.java
+++ /dev/null
@@ -1,509 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 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.emf2xml;
-
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.jem.util.emf.workbench.ProjectResourceSet;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapter;
-import org.eclipse.wst.common.internal.emf.resource.EMF2DOMRenderer;
-import org.eclipse.wst.common.internal.emf.resource.TranslatorResource;
-import org.eclipse.wst.common.internal.emf.utilities.DOMUtilities;
-import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
-import org.eclipse.wst.common.internal.emfworkbench.integration.ResourceSetWorkbenchEditSynchronizer;
-import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent;
-import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
-import org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Node;
-
-public class EMF2DOMSSERenderer extends EMF2DOMRenderer implements IModelStateListener, IModelLifecycleListener {
-
- /** The XML DOM model */
- protected IDOMModel xmlModel;
-
- /** Used internally; the unique id for the xml model */
- protected String xmlModelId;
-
- private IModelManager modelManager;
-
- protected Object aboutToChangeNode = null;
-
- protected boolean xmlModelReverted = false;
-
- protected boolean isBatchChanges = false;
-
- private boolean isSaving = false;
-
- public EMF2DOMSSERenderer() {
- super();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.etools.emf2xml.impl.EMF2DOMRenderer#managesDOMAdapters()
- */
- protected boolean managesDOMAdapters() {
- return false;
- }
-
- protected EMF2DOMAdapter createRootDOMAdapter() {
- return new EMF2DOMSSEAdapter(getResource(), document, this, getResource().getRootTranslator());
- }
-
- public void deRegisterAsModelStateListener() {
- if (xmlModel != null)
- xmlModel.removeModelStateListener(this);
- }
-
- public void deRegisterAsModelLifecycleListener() {
- if (xmlModel != null)
- xmlModel.removeModelLifecycleListener(this);
- }
-
- /**
- * Return the DOM model for this resource.
- */
- public IDOMModel getXMLModel() {
- return xmlModel;
- }
-
- public String getXMLModelId() {
- return xmlModelId;
- }
-
- public boolean isModified() {
- return (getXMLModel() != null && getXMLModel().isDirty());
- }
-
- public void modelAboutToBeChanged(IStructuredModel model) {
- if (model.getStructuredDocument() != null)
- aboutToChangeNode = model.getStructuredDocument().getFirstStructuredDocumentRegion();
- }
-
- public void modelChanged(IStructuredModel model) {
- if (isBatchChanges)
- return;
- try {
- if (aboutToChangeNode != null && model.getStructuredDocument() != null && model.getStructuredDocument().getFirstStructuredDocumentRegion() != aboutToChangeNode) {
- modelAccessForWrite();
- try {
- xmlModelReverted = true;
- resource.unload();
- } finally {
- if (getXMLModel() != null)
- getXMLModel().releaseFromEdit();
- }
- }
- } finally {
- aboutToChangeNode = null;
- }
- }
-
- public void accessForRead() {
- if (!resource.isNew()) {
- String id = getModelManagerId();
- getModelManager().getExistingModelForRead(id);
- }
- }
-
- public void accessForWrite() {
- modelAccessForWrite();
- }
-
- private void modelAccessForWrite() {
- String id = getModelManagerId();
- getModelManager().getExistingModelForEdit(id);
- }
-
- public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
- if (!isDirty && resource.isModified()) { //The XMLModel was saved
- resource.setModified(false);
- long stamp = WorkbenchResourceHelper.computeModificationStamp(resource);
- WorkbenchResourceHelper.setSynhronizationStamp(resource, stamp);
- ResourceSetWorkbenchEditSynchronizer synchronizer = (ResourceSetWorkbenchEditSynchronizer) ((ProjectResourceSet) resource.getResourceSet()).getSynchronizer();
- IFile aFile = WorkbenchResourceHelper.getFile(resource);
- synchronizer.preSave(aFile);
- }
- if (isDirty)
- resource.setModified(true);
- }
-
- public void modelResourceDeleted(IStructuredModel model) {
- //Do nothing
- }
-
- public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
- //Do nothing
- }
-
- /**
- * This method is called just prior to being removed from the ResourceSet. Ensure that all
- * reference counts to the XMLModel are removed.
- */
- public void preDelete() {
- if (resource.isLoaded())
- deregisterFromXMLModel();
- }
-
- public void preUnload() {
- deregisterFromXMLModel();
- }
-
- private void deregisterFromXMLModel() {
- deRegisterAsModelStateListener();
- deRegisterAsModelLifecycleListener();
- // This try/catch block is a hack to fix defect 204114. This occurs
- // because
- // the model manager plugin is shut down and unloaded before the j2ee
- // plugin.
- // Calling getModelManager() can result in a class cast exception that
- // should
- // be ignored.
- //ModelManager mgr = null;
- try {
- getModelManager();
- } catch (ClassCastException exc) {
- return;
- }
- if (xmlModel != null) {
- int writeCount = resource.getWriteCount();
- int readCount = resource.getReadCount();
- for (int i = 0; i < writeCount; i++)
- xmlModel.releaseFromEdit();
- for (int ii = 0; ii < readCount; ii++)
- xmlModel.releaseFromRead();
- }
- EMF2DOMAdapter adapter = (EMF2DOMAdapter) EcoreUtil.getAdapter(resource.eAdapters(), EMF2DOMAdapter.ADAPTER_CLASS);
- if (adapter != null) {
- adapter.removeAdapters(adapter.getNode());
- }
- xmlModel = null;
- xmlModelId = null;
- }
-
- /**
- * Insert the method's description here. Creation date: (9/7/2001 10:49:53 AM)
- */
- public void registerAsModelStateListener() {
- this.xmlModel.addModelStateListener(this);
- }
-
- public void registerAsModelLifecycleListener() {
- this.xmlModel.addModelLifecycleListener(this);
- }
-
- /**
- * Return the DOM model for this resource.
- */
- public void setXMLModel(IDOMModel xmlModel) {
- deRegisterAsModelStateListener();
- deRegisterAsModelLifecycleListener();
- this.xmlModel = xmlModel;
- registerAsModelStateListener();
- registerAsModelLifecycleListener();
- }
-
- public void setXMLModelId(String id) {
- xmlModelId = id;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.etools.emf2xml.Renderer#doSave(java.io.OutputStream, java.util.Map)
- */
- public void doSave(OutputStream outputStream, Map options) throws IOException {
-
- try {
- isSaving = true;
- if (null != outputStream) {
- throw new RuntimeException(UIResourceHandler.getString("EMF2DOMSedRenderer_UI_0", new Object[]{this.getClass().getName()}));} //$NON-NLS-1$
- createDOMTreeIfNecessary();
- ResourceSetWorkbenchEditSynchronizer synchronizer = (ResourceSetWorkbenchEditSynchronizer) ((ProjectResourceSet) resource.getResourceSet()).getSynchronizer();
- IFile aFile = WorkbenchResourceHelper.getFile(resource);
- try {
- synchronizer.preSave(aFile);
- xmlModel.save(aFile);
- } catch (CoreException ex) {
- synchronizer.removeFromRecentlySavedList(aFile);
- Logger.getLogger().logError(ex);
- }
- cacheSynchronizationStamp();
- } finally {
- isSaving = false;
- }
- }
-
- /**
- * @see com.ibm.etools.common.mof2dom.XMLDOMResource#wasReverted()
- */
- public boolean wasReverted() {
- return xmlModelReverted;
- }
-
- protected IModelManager getModelManager() {
- if (modelManager == null)
- modelManager = StructuredModelManager.getModelManager();
- return modelManager;
- }
-
- /**
- * Return id used to key the XML resource in the XML ModelManager.
- */
- protected String getModelManagerId() {
- if (xmlModelId == null) {
- IFile file = WorkbenchResourceHelper.getFile(getResource());
- if (file != null) {
- xmlModelId = getModelManager().calculateId(file);
- } else {
- xmlModelId = resource.getURI() + Long.toString(System.currentTimeMillis());
- }
- }
- return xmlModelId;
- }
-
- public void releaseFromRead() {
- if (xmlModel != null)
- xmlModel.releaseFromRead();
- }
-
- public void releaseFromWrite() {
- if (xmlModel != null)
- xmlModel.releaseFromEdit();
- }
-
- protected ResourceSet getResourceSet() {
- return resource == null ? null : resource.getResourceSet();
- }
-
- public boolean isShared() {
- if (getResourceSet() == null || xmlModel == null)
- return false;
- return xmlModel.isShared();
- }
-
- public boolean isSharedForWrite() {
- if (getResourceSet() == null || xmlModel == null)
- return false;
- return xmlModel.isSharedForEdit();
- }
-
- /**
- * Create a new Document given
- *
- * @aResource.
- */
- protected void createDocument() {
- TranslatorResource res = getResource();
- res.setDefaults();
- IFile file = WorkbenchResourceHelper.getFile(resource);
- InputStream is = DOMUtilities.createHeaderInputStream(res.getDoctype(), res.getPublicId(), res.getSystemId());
- if (is == null)
- return;
- try {
- try {
- List folders = new ArrayList();
- IContainer container = file.getParent();
- while (null != container && !container.exists() && container instanceof IFolder) {
- folders.add(container);
- container = container.getParent();
- }
- IFolder folder = null;
- for (int i = 0; i < folders.size(); i++) {
- folder = (IFolder) folders.get(i);
- folder.create(true, true, null);
- }
- file.create(is, true, null);
- file.setLocal(true, 1, null);
- } catch (CoreException e1) {
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(e1);
- } finally {
- if (null != is) {
- is.close();
- }
- }
- initializeXMLModel(file, true);
- } catch (java.io.IOException ex) {
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(UIResourceHandler.getString("Unexpected_IO_exception_occurred_creating_xml_document_1_EXC_"));//$NON-NLS-1$
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(ex);
- }
- }
-
- protected void createDOMTreeIfNecessary() {
- if (needsToCreateDOM)
- createDOMTree();
- }
-
- private IDOMModel initializeXMLModel(IFile file, boolean forWrite) throws UnsupportedEncodingException, IOException {
- if (file == null || !file.exists())
- throw new FileNotFoundException((file == null) ? "null" : file.getFullPath().toOSString()); //$NON-NLS-1$
- try {
- if (forWrite) {
- setXMLModel((IDOMModel) getModelManager().getModelForEdit(file));
- }
- else {
- setXMLModel((IDOMModel) getModelManager().getModelForRead(file));
- }
- setXMLModelId(getXMLModel().getId());
- needsToCreateDOM = false;
- } catch (CoreException e) {
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(e);
- return null;
- }
- String id = getModelManager().calculateId(file);
- syncReferenceCounts(id, forWrite);
- if (xmlModel != null)
- document = xmlModel.getDocument();
- return xmlModel;
- }
-
- private void syncReferenceCounts(String id, boolean forWrite) {
- int editIndex = 0, readIndex = 0;
- if (forWrite)
- editIndex++;
- else
- readIndex++;
- int writeCount = resource.getWriteCount();
- int readCount = resource.getReadCount();
- for (int i = writeCount; i > editIndex; i--)
- modelManager.getExistingModelForEdit(id);
- for (int i = readCount; i > readIndex; i--)
- modelManager.getExistingModelForRead(id);
- }
-
- protected void loadDocument(InputStream in, Map options) throws IOException {
- if (null != in) {
- throw new RuntimeException(UIResourceHandler.getString("EMF2DOMSedRenderer_UI_1", new Object[]{this.getClass().getName()}));} //$NON-NLS-1$
- IFile file = WorkbenchResourceHelper.getFile(resource);
- initializeXMLModel(file, (resource.getWriteCount() != 0));
- cacheSynchronizationStamp();
- }
-
- private void cacheSynchronizationStamp() {
- IFile file = WorkbenchResourceHelper.getFile(resource);
- if (file != null) {
- if (xmlModel != null)
- xmlModel.resetSynchronizationStamp(file);
- }
- }
-
- public void setBatchMode(boolean isBatch) {
- if (isBatch) {
- isBatchChanges = true;
- getXMLModel().aboutToChangeModel();
- setRootNodeAdapterNotificationEnabled(false);
- }
- else {
- getXMLModel().changedModel();
- setRootNodeAdapterNotificationEnabled(true);
- isBatchChanges = false;
- }
- }
- public boolean isBatchMode() {
- return isBatchChanges;
- }
-
- private void setRootNodeAdapterNotificationEnabled(boolean b) {
- EObject root = resource.getRootObject();
- if (root != null) {
- EMF2DOMAdapter adapter = (EMF2DOMAdapter) EcoreUtil.getExistingAdapter(root, EMF2DOMAdapter.ADAPTER_CLASS);
- if (adapter != null)
- adapter.setNotificationEnabled(b);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.etools.emf2xml.impl.EMF2DOMRenderer#getExistingDOMAdapter(org.w3c.dom.Node)
- */
- public EMF2DOMAdapter getExistingDOMAdapter(Node node) {
- IDOMNode xNode = (IDOMNode) node;
- return (EMF2DOMSSEAdapter) xNode.getAdapterFor(EMF2DOMAdapter.ADAPTER_CLASS);
- }
-
- public void removeDOMAdapter(Node aNode, EMF2DOMAdapter anAdapter) {
- ((IDOMNode) aNode).removeAdapter((EMF2DOMSSEAdapter) anAdapter);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jem.internal.util.emf.xml.EMF2DOMRenderer#replaceDocumentType(java.lang.String,
- * java.lang.String, java.lang.String)
- */
- public void replaceDocumentType(String docTypeName, String publicId, String systemId) {
- if (document == null)
- return;
- DocumentTypeImpl docType = (DocumentTypeImpl) document.getDoctype();
- if (docType == null)
- return;
- if (publicId == null && systemId == null)
- document.removeChild(docType);
- else {
- docType.setPublicId(publicId);
- docType.setSystemId(systemId);
- }
- }
-
- public boolean useStreamsForIO() {
- return false;
- }
-
- public void processPostModelEvent(ModelLifecycleEvent event) {
- // TODO Auto-generated method stub
-
- }
-
- public void processPreModelEvent(ModelLifecycleEvent event) {
- if (!isSaving) {
- if (event.getType() == ModelLifecycleEvent.MODEL_SAVED) {
- ResourceSetWorkbenchEditSynchronizer synchronizer = (ResourceSetWorkbenchEditSynchronizer) ((ProjectResourceSet) resource.getResourceSet()).getSynchronizer();
- IFile aFile = WorkbenchResourceHelper.getFile(resource);
- synchronizer.preSave(aFile);
- }
- }
- }
-
- public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
- // TODO Auto-generated method stub
-
- }
-
- public void modelReinitialized(IStructuredModel structuredModel) {
- // TODO Auto-generated method stub
-
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERendererFactory.java b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERendererFactory.java
deleted file mode 100644
index bd527999b1..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/EMF2DOMSSERendererFactory.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 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
- *******************************************************************************/
-
-/*
- * Created on Oct 10, 2003
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package org.eclipse.wst.xml.core.internal.emf2xml;
-
-import org.eclipse.wst.common.internal.emf.resource.Renderer;
-import org.eclipse.wst.common.internal.emf.resource.RendererFactory;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to Window>Preferences>Java>Code
- * Generation>Code and Comments
- */
-public class EMF2DOMSSERendererFactory extends RendererFactory {
-
- public static final EMF2DOMSSERendererFactory INSTANCE = new EMF2DOMSSERendererFactory();
-
- public EMF2DOMSSERendererFactory() {
- //Default constructor
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.etools.emf2xml.RendererFactory#createRenderer()
- */
- public Renderer createRenderer() {
- return new EMF2DOMSSERenderer();
- }
-
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/UIResourceHandler.java b/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/UIResourceHandler.java
deleted file mode 100644
index 8823f39992..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-emfModelSynch/org/eclipse/wst/xml/core/internal/emf2xml/UIResourceHandler.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 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.emf2xml;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-public class UIResourceHandler {
-
- private static ResourceBundle fgResourceBundle;
-
- /**
- * Returns the resource bundle used by all classes in this Project
- */
- public static ResourceBundle getResourceBundle() {
- try {
- return ResourceBundle.getBundle("emftosed");//$NON-NLS-1$
- } catch (MissingResourceException e) {
- // does nothing - this method will return null and
- // getString(String, String) will return the key
- // it was called with
- }
- return null;
- }
-
- public static String getString(String key) {
- if (fgResourceBundle == null) {
- fgResourceBundle = getResourceBundle();
- }
-
- if (fgResourceBundle != null) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$
- }
- }
- return "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$
-
- }
-
- public static String getString(String key, Object[] args) {
-
- try {
- return MessageFormat.format(getString(key), args);
- } catch (IllegalArgumentException e) {
- return getString(key);
- }
-
- }
-} \ No newline at end of file

Back to the top