Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: ef9b5107905ac01c56a897ec8e7948ce65a1be30 (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
/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.adapters;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDAttributeGroupDefinition;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDModelGroupDefinition;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDSchemaDirective;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDWildcard;
import org.eclipse.xsd.util.XSDSwitch;

public class XSDAdapterFactory extends AdapterFactoryImpl
{
  protected static XSDAdapterFactory instance;
  
  public static XSDAdapterFactory getInstance()
  {
    if (instance == null)
    {
      // first use the one defined by the configuration
      instance = XSDEditorPlugin.getPlugin().getXSDEditorConfiguration().getAdapterFactory();
      // if there isn't one, then use the default
      if (instance == null)
        instance = new XSDAdapterFactory();
    }
    return instance;
  }
  
  public Adapter createAdapter(Notifier target)
  {
    XSDSwitch xsdSwitch = new XSDSwitch()
    {
      public Object caseXSDSchemaDirective(XSDSchemaDirective object)
      {
        return new XSDSchemaDirectiveAdapter();
      }
      
      public Object caseXSDWildcard(XSDWildcard object)
      {
        return new XSDWildcardAdapter();
      }
      
      public Object caseXSDAttributeGroupDefinition(XSDAttributeGroupDefinition object)
      {
        return new XSDAttributeGroupDefinitionAdapter();
      }

      public Object caseXSDModelGroupDefinition(XSDModelGroupDefinition object)
      {
        return new XSDModelGroupDefinitionAdapter();
      }
      
      public Object caseXSDAttributeDeclaration(XSDAttributeDeclaration object)
      {
        return new XSDAttributeDeclarationAdapter();
      }

      public Object caseXSDAttributeUse(XSDAttributeUse object)
      {
        return new XSDAttributeUseAdapter();
      }
      
      public Object caseXSDParticle(XSDParticle object)
      {
        return new XSDParticleAdapter();
      }

      public Object caseXSDElementDeclaration(XSDElementDeclaration object)
      {
        return new XSDElementDeclarationAdapter();
      }
      
      public Object caseXSDSimpleTypeDefinition(XSDSimpleTypeDefinition object)
      {
        // TODO Auto-generated method stub
        return new XSDSimpleTypeDefinitionAdapter();
      }
      
      public Object caseXSDComplexTypeDefinition(XSDComplexTypeDefinition object)
      {
        // we don't like exposing the 'anyType' type as a visible complex type
        // so we adapt it in a specialized way so that it's treated as simple type
        // that way it doesn't show up as a reference from a field
        //
        if ("anyType".equals(object.getName())) //$NON-NLS-1$
        {
          return new XSDAnyTypeDefinitionAdapter(); 
        }  
        else
        {             
          return new XSDComplexTypeDefinitionAdapter();
        }  
      }
      
      public Object caseXSDModelGroup(XSDModelGroup object)
      {
        return new XSDModelGroupAdapter();
      }

      public Object caseXSDSchema(XSDSchema object)
      {
        return new XSDSchemaAdapter();
      }         
    };
    Object o = xsdSwitch.doSwitch((EObject) target);
    Adapter result = null;
    if (o instanceof Adapter)
    {
      result = (Adapter) o;
    }
    else
    {
//      Thread.dumpStack();
    }
    return result;
  }

  public Adapter adapt(Notifier target)
  {
    return adapt(target, this);
  }
}

Back to the top