Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2ab074a0bd84c671982bd4c68120c25cbe6103f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
 * Copyright (c) 2004 - 2011 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.internal.efs;

import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.net4j.util.ObjectUtil;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.provider.FileInfo;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Eike Stepper
 */
public final class CDOFileRoot extends AbstractFileStore
{
  private CDOFileSystem fileSystem;

  private String authority;

  private String repositoryName;

  private IPath branchPath;

  private long timeStamp;

  private transient CDOView view;

  public CDOFileRoot(CDOFileSystem fileSystem, String authority, String repositoryName, IPath branchPath, long timeStamp)
  {
    this.fileSystem = fileSystem;
    this.authority = authority;
    this.repositoryName = repositoryName;
    this.branchPath = branchPath;
    this.timeStamp = timeStamp;
  }

  @Override
  public CDOFileSystem getFileSystem()
  {
    return fileSystem;
  }

  public String getAuthority()
  {
    return authority;
  }

  public String getRepositoryName()
  {
    return repositoryName;
  }

  public IPath getBranchPath()
  {
    return branchPath;
  }

  public long getTimeStamp()
  {
    return timeStamp;
  }

  @Override
  public IPath getPath()
  {
    return Path.EMPTY;
  }

  @Override
  public CDOView getView(IProgressMonitor monitor)
  {
    if (view == null)
    {
      view = fileSystem.getView(this, monitor);
    }

    return view;
  }

  @Override
  protected CDOResourceNode doGetResourceNode(IProgressMonitor monitor)
  {
    return getView(monitor).getRootResource();
  }

  @Override
  public IFileStore getParent()
  {
    return null;
  }

  @Override
  public String getName()
  {
    return "";
  }

  @Override
  public IFileInfo fetchInfo(int options, IProgressMonitor monitor)
  {
    FileInfo info = new FileInfo(getName());
    info.setLastModified(EFS.NONE);
    info.setExists(true); // Root resource is always present
    info.setLength(EFS.NONE);
    info.setDirectory(true);
    info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
    return info;
  }

  @Deprecated
  @Override
  public IFileStore getChild(IPath path)
  {
    return new CDOFileStore(this, path);
  }

  @Override
  public IFileStore getChild(String name)
  {
    return getChild(new Path(name));
  }

  @Override
  public String[] childNames(int options, IProgressMonitor monitor) throws CoreException
  {
    List<String> result = new ArrayList<String>();

    for (EObject object : getView(monitor).getRootResource().getContents())
    {
      if (object instanceof CDOResourceNode)
      {
        CDOResourceNode node = (CDOResourceNode)object;
        result.add(node.getName());
      }
    }

    return result.toArray(new String[result.size()]);
  }

  @Override
  public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException
  {
    throw new UnsupportedOperationException();
  }

  @Override
  public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException
  {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean equals(Object obj)
  {
    if (obj == this)
    {
      return true;
    }

    if (obj.getClass() == CDOFileRoot.class)
    {
      CDOFileRoot that = (CDOFileRoot)obj;
      if (view != null && view == that.view)
      {
        // Optimization
        return true;
      }

      return authority.equals(that.authority) && repositoryName.equals(that.repositoryName)
          && branchPath.equals(that.branchPath) && timeStamp == that.timeStamp;
    }

    return false;
  }

  @Override
  protected int createHashCode()
  {
    return authority.hashCode() ^ repositoryName.hashCode() ^ branchPath.hashCode() ^ ObjectUtil.hashCode(timeStamp);
  }

  @Override
  public void appendURI(StringBuilder builder)
  {
    builder.append(fileSystem.getScheme());
    builder.append("://");
    builder.append(authority);
    builder.append("/");
    builder.append(repositoryName);
    builder.append("/");
    builder.append(branchPath.toPortableString());
    builder.append("/@");
    if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
    {
      builder.append(timeStamp);
    }
  }
}

Back to the top