Search in sources :

Example 1 with IMemento

use of org.eclipse.jst.server.core.internal.IMemento in project webtools.servertools by eclipse.

the class RuntimeClasspathProviderDelegate method save.

/**
 * Save source attachment info.
 */
private synchronized void save() {
    List<SourceAttachmentUpdate> srcAttachments = sourceAttachments;
    if (srcAttachments == null)
        return;
    String id = extensionId;
    String filename = JavaServerPlugin.getInstance().getStateLocation().append(id + ".xml").toOSString();
    try {
        XMLMemento memento = XMLMemento.createWriteRoot("classpath");
        Iterator iterator = srcAttachments.iterator();
        while (iterator.hasNext()) {
            SourceAttachmentUpdate sau = (SourceAttachmentUpdate) iterator.next();
            IMemento child = memento.createChild("source-attachment");
            child.putString("runtime-id", sau.runtimeId);
            if (sau.entry != null)
                child.putString("entry", sau.entry.toPortableString());
            if (sau.sourceAttachmentPath != null)
                child.putString("source-attachment-path", sau.sourceAttachmentPath.toPortableString());
            if (sau.sourceAttachmentRootPath != null)
                child.putString("source-attachment-root-path", sau.sourceAttachmentRootPath.toPortableString());
            if (sau.attributes != null) {
                for (IClasspathAttribute attr : sau.attributes) {
                    IMemento attrChild = child.createChild("attribute");
                    attrChild.putString("name", attr.getName());
                    attrChild.putString("value", attr.getValue());
                }
            }
        }
        memento.saveToFile(filename);
    } catch (Exception e) {
        if (Trace.SEVERE) {
            Trace.trace(Trace.STRING_SEVERE, "Error saving source path info", e);
        }
    }
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) XMLMemento(org.eclipse.jst.server.core.internal.XMLMemento) IMemento(org.eclipse.jst.server.core.internal.IMemento)

Example 2 with IMemento

use of org.eclipse.jst.server.core.internal.IMemento in project webtools.servertools by eclipse.

the class RuntimeClasspathProviderDelegate method load.

/**
 * Load source attachment info.
 */
private void load() {
    List<SourceAttachmentUpdate> srcAttachments = new ArrayList<SourceAttachmentUpdate>();
    String id = extensionId;
    String filename = JavaServerPlugin.getInstance().getStateLocation().append(id + ".xml").toOSString();
    if (!(new File(filename)).exists())
        return;
    try {
        IMemento memento = XMLMemento.loadMemento(filename);
        IMemento[] children = memento.getChildren("source-attachment");
        for (IMemento child : children) {
            try {
                SourceAttachmentUpdate sau = new SourceAttachmentUpdate();
                sau.runtimeId = child.getString("runtime-id");
                String temp = child.getString("entry");
                if (temp != null)
                    sau.entry = new Path(temp);
                temp = child.getString("source-attachment-path");
                if (temp != null)
                    sau.sourceAttachmentPath = new Path(temp);
                temp = child.getString("source-attachment-root-path");
                if (temp != null)
                    sau.sourceAttachmentRootPath = new Path(temp);
                IMemento[] attrChildren = child.getChildren("attribute");
                if (attrChildren != null) {
                    int size2 = attrChildren.length;
                    sau.attributes = new IClasspathAttribute[size2];
                    for (int j = 0; j < size2; j++) {
                        String name = attrChildren[j].getString("name");
                        String value = attrChildren[j].getString("value");
                        sau.attributes[j] = JavaCore.newClasspathAttribute(name, value);
                    }
                }
                srcAttachments.add(sau);
            } catch (Exception e) {
                if (Trace.WARNING) {
                    Trace.trace(Trace.STRING_WARNING, "Could not load source attachment: " + e);
                }
            }
        }
    } catch (Exception e) {
        if (Trace.WARNING) {
            Trace.trace(Trace.STRING_WARNING, "Could not load source path info", e);
        }
    }
    sourceAttachments = srcAttachments;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) File(java.io.File) IMemento(org.eclipse.jst.server.core.internal.IMemento)

Aggregations

IMemento (org.eclipse.jst.server.core.internal.IMemento)2 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)1 XMLMemento (org.eclipse.jst.server.core.internal.XMLMemento)1