1 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 65 public class PluginAdapterFactoryMappingDomain extends AdapterFactoryMappingDomain 66 { 67 public final String MAPPING_EXTENSION_POINT_ID = "configuration"; 68 69 public PluginAdapterFactoryMappingDomain 70 (AdapterFactory mappingDomainAdapterFactory, 71 AdapterFactory editingDomainAdapterFactory, 72 CommandStack commandStack, 73 String 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 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 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 mappingDomainKey) 109 { 110 super(mappingDomainAdapterFactory, topDomainAdapterFactory, bottomDomainAdapterFactory, commandStack, resourceSet); 111 initializeFromPlugin(mappingDomainKey); 112 } 113 114 protected void initializeFromPlugin(String 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 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 IConfigurationElement topLabelSeparatorAll[] = d.getChildren("top-label-separator"); 146 if (topLabelSeparatorAll.length > 0) 147 { 148 String sep = topLabelSeparatorAll[0].getAttribute("value"); 149 if (sep.length() > 0) 150 { 151 topLabelSeparator = sep.charAt(0); 152 } 153 } 154 155 IConfigurationElement bottomLabelSeparatorAll[] = d.getChildren("bottom-label-separator"); 157 if (bottomLabelSeparatorAll.length > 0) 158 { 159 String sep = bottomLabelSeparatorAll[0].getAttribute("value"); 160 if (sep.length() > 0) 161 { 162 bottomLabelSeparator = sep.charAt(0); 163 } 164 } 165 166 IConfigurationElement topLabelCaseAll[] = d.getChildren("top-label-case"); 168 if (topLabelCaseAll.length > 0) 169 { 170 String 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 IConfigurationElement bottomLabelCaseAll[] = d.getChildren("bottom-label-case"); 187 if (bottomLabelCaseAll.length > 0) 188 { 189 String 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 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 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 } } } } 233 234 protected void addTypeMapping(String topType, String bottomType) 235 { 236 240 topToBottomTypeTable.put(topType, bottomType); 241 bottomToTopTypeTable.put(bottomType, topType); 242 } 243 } 244 | Popular Tags |