Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8ce7a39b70c22606a161411b88f8bf5093b2d85c (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
package org.eclipse.osee.framework.core.dsl.ui.integration;

import java.util.Collection;
import java.util.HashSet;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.IBasicArtifact;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.model.type.RelationType;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;

public final class ArtifactDataAccessor implements ArtifactDataProvider {

   @Override
   public boolean isApplicable(Object object) {
      return asCastedObject(object) != null;
   }

   @Override
   public ArtifactData asCastedObject(Object object) {
      ArtifactData wrapper = null;
      if (object instanceof Artifact) {
         final Artifact artifact = (Artifact) object;
         wrapper = new ArtifactWrapper(artifact);
      }
      return wrapper;
   }

   private final class ArtifactWrapper implements ArtifactData {
      private final Artifact artifact;

      public ArtifactWrapper(Artifact artifact) {
         this.artifact = artifact;
      }

      @Override
      public String getGuid() {
         return artifact.getGuid();
      }

      @Override
      public ArtifactType getArtifactType() {
         return artifact.getArtifactType();
      }

      @Override
      public boolean isAttributeTypeValid(IAttributeType attributeType) throws OseeCoreException {
         return artifact.isAttributeTypeValid(attributeType);
      }

      @Override
      public Collection<RelationType> getValidRelationTypes() throws OseeCoreException {
         return artifact.getValidRelationTypes();
      }

      @Override
      public IBasicArtifact<?> getObject() {
         return artifact;
      }

      @Override
      public Collection<String> getHierarchy() {
         Collection<String> hierarchy = new HashSet<String>();
         Artifact artifactPtr = artifact;
         while (artifactPtr != null) {
            hierarchy.add(artifactPtr.getGuid());
         }
         return hierarchy;
      }
   }
}

Back to the top