Search in sources :

Example 1 with TranslatorResource

use of org.eclipse.wst.common.internal.emf.resource.TranslatorResource in project webtools.sourceediting by eclipse.

the class EMF2DOMSSERenderer method createDocument.

/**
 * 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) {
            Logger.logException(e1);
        } finally {
            if (null != is) {
                is.close();
            }
        }
        initializeXMLModel(file, resource.getWriteCount() != 0);
    } catch (IOException ex) {
        // $NON-NLS-1$
        Logger.log(Logger.ERROR, "IWAE0017E Unexpected IO exception occurred creating xml document");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with TranslatorResource

use of org.eclipse.wst.common.internal.emf.resource.TranslatorResource in project webtools.sourceediting by eclipse.

the class EMF2DOMSSERenderer method getExistingDOMAdapter.

public EMF2DOMAdapter getExistingDOMAdapter(Node node) {
    // IDOMNode xNode = (IDOMNode) node;
    // return (EMF2DOMSSEAdapter) xNode.getAdapterFor(EMF2DOMAdapter.ADAPTER_CLASS);
    INodeNotifier sseNode = (INodeNotifier) node;
    Collection adapters = sseNode.getAdapters();
    for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
        INodeAdapter adapter = (INodeAdapter) iterator.next();
        // First Check if it's an EMF2DOMAdapter
        if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
            // Cast to EMF2DOMSSEAdapter
            EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
            // Use the resourceClass to make sure the resource type is identical
            if (getResource() == null || e2DAdapter.getTarget() == null)
                if (resourceClass.equals(e2DAdapter.getResourceClass()))
                    return e2DAdapter;
                else
                    continue;
            // First check if targets are resources
            if (e2DAdapter.getTarget() instanceof Resource) {
                /*
					 * Now check if it's the right one (Multiple resources
					 * could be attached)
					 */
                if (e2DAdapter.getTarget() == getResource()) {
                    return e2DAdapter;
                }
            } else {
                // Check if targets are EObjects with the same resources
                TranslatorResource myTarget = getResource();
                EObject adapterTarget = (EObject) e2DAdapter.getTarget();
                /*
					 * Now check if it's the right one (Multiple resources could
					 * be attached)
					 */
                if (adapterTarget.eResource() == myTarget || adapterTarget.eResource() == null) {
                    return e2DAdapter;
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Resource(org.eclipse.emf.ecore.resource.Resource) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Collection(java.util.Collection) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Aggregations

TranslatorResource (org.eclipse.wst.common.internal.emf.resource.TranslatorResource)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)1