KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > domain > PluginAdapterFactoryMappingDomain


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: PluginAdapterFactoryMappingDomain.java,v 1.3 2005/06/08 06:21:43 nickb Exp $
16  */

17 package org.eclipse.emf.mapping.domain;
18
19
20 import org.eclipse.core.runtime.IConfigurationElement;
21 import org.eclipse.core.runtime.IExtension;
22 import org.eclipse.core.runtime.IExtensionPoint;
23 import org.eclipse.core.runtime.IExtensionRegistry;
24 import org.eclipse.core.runtime.Platform;
25
26 import org.eclipse.emf.common.command.CommandStack;
27 import org.eclipse.emf.common.notify.AdapterFactory;
28 import org.eclipse.emf.ecore.resource.ResourceSet;
29 import org.eclipse.emf.mapping.MappingPlugin;
30
31
32 /**
33  * This class extends the AdapterFactoryMappingDomain by providing initialization
34  * using config information specified in the VABase plugin.xml.
35  *
36  * <p>
37  * A sample configuration is like this:
38  * <pre>
39  * &lt;extension point = "org.eclipse.emf.mapping">
40  * &lt;mapping-domain>
41  * &lt;type-mappings id="DTD2DTD">
42  * &lt;type-mapping top="java.xmi:ContainerManagedEntity" bottom="rdbschema.xmi:Table"/>
43  * &lt;type-mapping top="java.xmi:Field" bottom="rdbschema.xmi:Column"/>
44  * &lt;/type-mappings>
45  *
46  * &lt;top-label-separator value=""/>
47  * &lt;bottom-label-separator value="_"/>
48  *
49  * &lt;top-label-case value="mixed"/>
50  * &lt;bottom-label-case value="upper"/>
51  *
52  * &lt;top-label-forms>
53  * &lt;label-form long="Table" short="Tab"/>
54  * &lt;label-form long="Integer" short="Int"/>
55  * &lt;/top-label-forms>
56  *
57  * &lt;bottom-label-forms>
58  * &lt;label-form long="TABLE" short="TBL"/>
59  * &lt;label-form long="INTEGER" short="INT"/>
60  * &lt;/bottom-label-forms>
61  * &lt;/mapping-domain>
62  * &lt;/extension>
63  * </pre>
64  */

65 public class PluginAdapterFactoryMappingDomain extends AdapterFactoryMappingDomain
66 {
67   public final String JavaDoc MAPPING_EXTENSION_POINT_ID = "configuration";
68
69   public PluginAdapterFactoryMappingDomain
70     (AdapterFactory mappingDomainAdapterFactory,
71      AdapterFactory editingDomainAdapterFactory,
72      CommandStack commandStack,
73      String JavaDoc mappingDomainKey)
74   {
75     super(mappingDomainAdapterFactory, editingDomainAdapterFactory, commandStack);
76     initializeFromPlugin(mappingDomainKey);
77   }
78
79   public PluginAdapterFactoryMappingDomain
80     (AdapterFactory mappingDomainAdapterFactory,
81      AdapterFactory editingDomainAdapterFactory,
82      CommandStack commandStack,
83      ResourceSet resourceSet,
84      String JavaDoc mappingDomainKey)
85   {
86  
87     super(mappingDomainAdapterFactory, editingDomainAdapterFactory, commandStack, resourceSet);
88     initializeFromPlugin(mappingDomainKey);
89   }
90
91   public PluginAdapterFactoryMappingDomain
92     (AdapterFactory mappingDomainAdapterFactory,
93      AdapterFactory topDomainAdapterFactory,
94      AdapterFactory bottomDomainAdapterFactory,
95      CommandStack commandStack,
96      String JavaDoc mappingDomainKey)
97   {
98     super(mappingDomainAdapterFactory, topDomainAdapterFactory, bottomDomainAdapterFactory, commandStack);
99     initializeFromPlugin(mappingDomainKey);
100   }
101
102   public PluginAdapterFactoryMappingDomain
103     (AdapterFactory mappingDomainAdapterFactory,
104      AdapterFactory topDomainAdapterFactory,
105      AdapterFactory bottomDomainAdapterFactory,
106      CommandStack commandStack,
107      ResourceSet resourceSet,
108      String JavaDoc mappingDomainKey)
109   {
110     super(mappingDomainAdapterFactory, topDomainAdapterFactory, bottomDomainAdapterFactory, commandStack, resourceSet);
111     initializeFromPlugin(mappingDomainKey);
112   }
113
114   protected void initializeFromPlugin(String JavaDoc mappingDomainKey)
115   {
116     if (mappingDomainKey == null) return;
117
118     IExtensionRegistry registry = Platform.getExtensionRegistry();
119     IExtensionPoint pct =
120       registry.getExtensionPoint(MappingPlugin.getPlugin().getBundle().getSymbolicName(), MAPPING_EXTENSION_POINT_ID);
121                 
122     IExtension[] extension = pct.getExtensions();
123     for (int l = 0; l < extension.length; ++l)
124     {
125       IExtension config = extension[l];
126
127       IConfigurationElement[] cElems = config.getConfigurationElements();
128       for (int i=0; i < cElems.length; i++)
129       {
130         IConfigurationElement d = cElems[i];
131         if (d.getName().equals("mapping-domain") && mappingDomainKey.equals(d.getAttribute("key")))
132         {
133           // type-mappings
134
IConfigurationElement typeMappings[] = d.getChildren("type-mappings");
135           for (int j=0; j < typeMappings.length; j++)
136           {
137             IConfigurationElement mapping[] = typeMappings[j].getChildren("type-mapping");
138             for (int k=0; k < mapping.length; k++)
139             {
140               addTypeMapping(mapping[k].getAttribute("top"), mapping[k].getAttribute("bottom"));
141             }
142           }
143   
144           // top-label-separator
145
IConfigurationElement topLabelSeparatorAll[] = d.getChildren("top-label-separator");
146           if (topLabelSeparatorAll.length > 0)
147           {
148             String JavaDoc sep = topLabelSeparatorAll[0].getAttribute("value");
149             if (sep.length() > 0)
150             {
151               topLabelSeparator = sep.charAt(0);
152             }
153           }
154   
155           // bottom-label-separator
156
IConfigurationElement bottomLabelSeparatorAll[] = d.getChildren("bottom-label-separator");
157           if (bottomLabelSeparatorAll.length > 0)
158           {
159             String JavaDoc sep = bottomLabelSeparatorAll[0].getAttribute("value");
160             if (sep.length() > 0)
161             {
162               bottomLabelSeparator = sep.charAt(0);
163             }
164           }
165   
166           // top-label-case
167
IConfigurationElement topLabelCaseAll[] = d.getChildren("top-label-case");
168           if (topLabelCaseAll.length > 0)
169           {
170             String JavaDoc labelCase = topLabelCaseAll[0].getAttribute("value");
171             if (labelCase.equalsIgnoreCase("upper"))
172             {
173               topLabelCase = LABEL_UPPER;
174             }
175             else if (labelCase.equalsIgnoreCase("lower"))
176             {
177               topLabelCase = LABEL_LOWER;
178             }
179             else if (labelCase.equalsIgnoreCase("mixed"))
180             {
181               topLabelCase = LABEL_MIXED;
182             }
183           }
184   
185           // bottom-label-case
186
IConfigurationElement bottomLabelCaseAll[] = d.getChildren("bottom-label-case");
187           if (bottomLabelCaseAll.length > 0)
188           {
189             String JavaDoc labelCase = bottomLabelCaseAll[0].getAttribute("value");
190             if (labelCase.equalsIgnoreCase("upper"))
191             {
192               bottomLabelCase = LABEL_UPPER;
193             }
194             else if (labelCase.equalsIgnoreCase("lower"))
195             {
196               bottomLabelCase = LABEL_LOWER;
197             }
198             else if (labelCase.equalsIgnoreCase("mixed"))
199             {
200               bottomLabelCase = LABEL_MIXED;
201             }
202           }
203   
204           // top-label-forms
205
IConfigurationElement topLabelForms[] = d.getChildren("top-label-forms");
206           for (int j=0; j < topLabelForms.length; j++)
207           {
208             IConfigurationElement labelForm[] = topLabelForms[j].getChildren("label-form");
209             for (int k=0; k < labelForm.length; k++)
210             {
211               topLabelLongForms.add(labelForm[k].getAttribute("long"));
212               topLabelShortForms.add(labelForm[k].getAttribute("short"));
213             }
214           }
215   
216           // bottom-label-forms
217
IConfigurationElement bottomLabelForms[] = d.getChildren("bottom-label-forms");
218           for (int j=0; j < bottomLabelForms.length; j++)
219           {
220             IConfigurationElement labelForm[] = bottomLabelForms[j].getChildren("label-form");
221             for (int k=0; k < labelForm.length; k++)
222             {
223               bottomLabelLongForms.add(labelForm[k].getAttribute("long"));
224               bottomLabelShortForms.add(labelForm[k].getAttribute("short"));
225             }
226           }
227
228           break;
229         } //if
230
} // for
231
} // for
232
}
233
234   protected void addTypeMapping(String JavaDoc topType, String JavaDoc bottomType)
235   {
236     /*
237      * The type string must be qualified by its package uri, e.g. DTD.xmi:DTDElement.
238      * The package uri is used to look up the package by calling RefRegister.getPackage(uri).
239      */

240     topToBottomTypeTable.put(topType, bottomType);
241     bottomToTopTypeTable.put(bottomType, topType);
242   }
243 }
244
Popular Tags