Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.releng.projectconfig/src/org/eclipse/emf/cdo/releng/projectconfig/impl/ProjectConfigURIHandlerImpl.java')
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.projectconfig/src/org/eclipse/emf/cdo/releng/projectconfig/impl/ProjectConfigURIHandlerImpl.java129
1 files changed, 129 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.projectconfig/src/org/eclipse/emf/cdo/releng/projectconfig/impl/ProjectConfigURIHandlerImpl.java b/plugins/org.eclipse.emf.cdo.releng.projectconfig/src/org/eclipse/emf/cdo/releng/projectconfig/impl/ProjectConfigURIHandlerImpl.java
new file mode 100644
index 0000000000..e942706a49
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.releng.projectconfig/src/org/eclipse/emf/cdo/releng/projectconfig/impl/ProjectConfigURIHandlerImpl.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2013 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.releng.projectconfig.impl;
+
+import org.eclipse.emf.cdo.releng.projectconfig.WorkspaceConfiguration;
+import org.eclipse.emf.cdo.releng.projectconfig.util.ProjectConfigUtil;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.emf.ecore.resource.impl.URIHandlerImpl;
+
+import org.osgi.service.prefs.BackingStoreException;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class ProjectConfigURIHandlerImpl extends URIHandlerImpl
+{
+ @Override
+ public boolean canHandle(URI uri)
+ {
+ return ProjectConfigUtil.PROJECT_CONFIG_SCHEME.equals(uri.scheme());
+ }
+
+ @Override
+ public InputStream createInputStream(URI uri, final Map<?, ?> options) throws IOException
+ {
+ if (uri.segmentCount() == 1)
+ {
+ class ProjectConfigInput extends InputStream implements URIConverter.Loadable
+ {
+ private InputStream in;
+
+ public void loadResource(Resource resource) throws IOException
+ {
+ resource.getContents().addAll(ProjectConfigUtil.getWorkspaceConfiguration().eResource().getContents());
+ }
+
+ @Override
+ public int read() throws IOException
+ {
+ if (in == null)
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ProjectConfigUtil.getWorkspaceConfiguration().eResource().save(out, null);
+ in = new ByteArrayInputStream(out.toByteArray());
+ }
+ return in.read();
+ }
+ }
+
+ return new ProjectConfigInput();
+ }
+ throw new IOException("No preference value available for ");
+ }
+
+ @Override
+ public OutputStream createOutputStream(URI uri, Map<?, ?> options) throws IOException
+ {
+ if (uri.segmentCount() == 1)
+ {
+ class ProjectConfigOutput extends OutputStream implements URIConverter.Saveable
+ {
+ public void saveResource(Resource resource) throws IOException
+ {
+ try
+ {
+ ProjectConfigUtil.saveWorkspaceConfiguration((WorkspaceConfiguration)resource.getContents().get(0));
+ }
+ catch (BackingStoreException ex)
+ {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public void write(int b) throws IOException
+ {
+ throw new IOException("Write not supported");
+ }
+ }
+
+ return new ProjectConfigOutput();
+ }
+ throw new IOException("Output not supported");
+ }
+
+ @Override
+ public void delete(URI uri, Map<?, ?> options) throws IOException
+ {
+ throw new IOException("Delete not supported");
+ }
+
+ @Override
+ public boolean exists(URI uri, Map<?, ?> options)
+ {
+ // TODO
+ return false;
+ }
+
+ @Override
+ public Map<String, ?> getAttributes(URI uri, Map<?, ?> options)
+ {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public void setAttributes(URI uri, Map<String, ?> attributes, Map<?, ?> options) throws IOException
+ {
+ // Do nothing.
+ }
+}

Back to the top