blob: 4f5f383165773fe623c398055e11d1556ae6927d [file] [log] [blame]
jlanutifed82ab2005-12-01 22:03:10 +00001/*******************************************************************************
2 * Copyright (c) 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
cbridgha44a17d72005-04-04 07:05:01 +000011package org.eclipse.wst.common.componentcore.internal.util;
cbridghaf654faf2005-02-13 16:27:46 +000012
13import org.eclipse.emf.ecore.EStructuralFeature;
cbridgha44a17d72005-04-04 07:05:01 +000014import org.eclipse.wst.common.componentcore.internal.ComponentcorePackage;
cbridghaf654faf2005-02-13 16:27:46 +000015import org.eclipse.wst.common.internal.emf.resource.GenericTranslator;
16import org.eclipse.wst.common.internal.emf.resource.IDTranslator;
17import org.eclipse.wst.common.internal.emf.resource.RootTranslator;
18import org.eclipse.wst.common.internal.emf.resource.Translator;
cbridghaf654faf2005-02-13 16:27:46 +000019
20
21public class WTPModulesTranslator extends RootTranslator implements WTPModulesXmlMapperI{
22 public static WTPModulesTranslator INSTANCE = new WTPModulesTranslator();
23 private static Translator[] children;
cbridgha44a17d72005-04-04 07:05:01 +000024 private static final ComponentcorePackage MODULE_CORE_PKG = ComponentcorePackage.eINSTANCE;
cbridghaf654faf2005-02-13 16:27:46 +000025 /**
26 * @param domNameAndPath
27 * @param eClass
28 */
29 public WTPModulesTranslator() {
cbridgha44a17d72005-04-04 07:05:01 +000030 super(PROJECT_MODULES, ComponentcorePackage.eINSTANCE.getProjectComponents());
cbridghadc4c1c62005-04-27 18:48:57 +000031 }
32
33// public void setMOFValue(Notifier owner, Object value, int newIndex) {
34// super.setMOFValue(owner, value, newIndex);
35// EObject target = ((EObject)value);
36// IProject project = ProjectUtilities.getProject(target);
37// if(project != null)
38// target.eSet(ComponentcorePackage.eINSTANCE.getProjectComponents_ProjectName(), project.getName());
39// }
cbridghaf654faf2005-02-13 16:27:46 +000040 /* (non-Javadoc)
41 * @see org.eclipse.wst.common.internal.emf.resource.Translator#getChildren(java.lang.Object, int)
42 */
43 public Translator[] getChildren(Object target, int versionID) {
44 if(children == null)
45 children = createWTPModulesTranslator();
46 return children;
47 }
48
49 private static Translator[] createWTPModulesTranslator() {
50 return new Translator[] {
51 IDTranslator.INSTANCE,
cbridgha5059b8b2005-03-15 02:12:30 +000052 createWBModuleTranslator(MODULE_CORE_PKG.getProjectComponents_Components())
cbridghaf654faf2005-02-13 16:27:46 +000053 };
54 }
55
56 /**
57 * @return
58 */
59 private static Translator createWBModuleTranslator(EStructuralFeature afeature) {
cbridgha44a17d72005-04-04 07:05:01 +000060 GenericTranslator result = new GenericTranslator(WORKBENCH_COMPONENT, afeature);
cbridghaf654faf2005-02-13 16:27:46 +000061 result.setChildren(new Translator[] {
62 IDTranslator.INSTANCE,
cbridgha5059b8b2005-03-15 02:12:30 +000063 //new Translator(HANDLE, MODULE_CORE_PKG.getWorkbenchComponent_Handle(), DOM_ATTRIBUTE), REMOVED SINCE HANDLE SHOULD NOW BE DERIVED -MDE
cbridgha44a17d72005-04-04 07:05:01 +000064 new Translator(RUNTIME_NAME, MODULE_CORE_PKG.getWorkbenchComponent_Name(), DOM_ATTRIBUTE),
cbridgha5059b8b2005-03-15 02:12:30 +000065 createModuleTypeTranslator(MODULE_CORE_PKG.getWorkbenchComponent_ComponentType()),
66 createWBResourceTranslator(MODULE_CORE_PKG.getWorkbenchComponent_Resources()),
cbridgha76161c62005-10-18 23:02:29 +000067 createDependentModuleTranslator(MODULE_CORE_PKG.getWorkbenchComponent_ReferencedComponents()),
jlanuti138b3782005-12-06 21:18:47 +000068 new IPathTranslator(META_RESOURCES, MODULE_CORE_PKG.getWorkbenchComponent_MetadataResources()),
cbridgha76161c62005-10-18 23:02:29 +000069 createPropertiesTranslator(MODULE_CORE_PKG.getWorkbenchComponent_Properties())
cbridghaf654faf2005-02-13 16:27:46 +000070 });
71 return result;
72 }
73 private static Translator createModuleTypeTranslator(EStructuralFeature afeature) {
cbridghadb5438b2005-03-02 00:29:55 +000074 GenericTranslator result = new GenericTranslator(MODULE_TYPE, afeature);
cbridghaf654faf2005-02-13 16:27:46 +000075 result.setChildren(new Translator[] {
cbridgha44a17d72005-04-04 07:05:01 +000076 new Translator(COMPONENT_TYPE_ID, MODULE_CORE_PKG.getComponentType_ComponentTypeId(), DOM_ATTRIBUTE),
cbridghab3903172005-03-24 16:12:12 +000077 new Translator(META_RESOURCES, MODULE_CORE_PKG.getComponentType_MetadataResources()),
cbridgha44a17d72005-04-04 07:05:01 +000078 new Translator(COMPONENT_TYPE_VERSION, MODULE_CORE_PKG.getComponentType_Version()),
cbridghab3903172005-03-24 16:12:12 +000079 createPropertiesTranslator(MODULE_CORE_PKG.getComponentType_Properties())
80
cbridghaf654faf2005-02-13 16:27:46 +000081 });
82 return result;
83 }
84
cbridghab3903172005-03-24 16:12:12 +000085 private static Translator createPropertiesTranslator(EStructuralFeature afeature){
86 GenericTranslator result = new GenericTranslator(PROPERTY, afeature);
87 result.setChildren(new Translator[] {
88 new Translator(PROPERTY_NAME, MODULE_CORE_PKG.getProperty_Name(), DOM_ATTRIBUTE ),
89 new Translator(PROPERTY_VALUE, MODULE_CORE_PKG.getProperty_Value(), DOM_ATTRIBUTE ),
90
91 });
92 return result;
93 }
94
95
cbridghaf654faf2005-02-13 16:27:46 +000096 private static Translator createDependentModuleTranslator(EStructuralFeature afeature) {
cbridgha44a17d72005-04-04 07:05:01 +000097 GenericTranslator result = new GenericTranslator(REFERENCED_COMPONENT, afeature);
cbridghaf654faf2005-02-13 16:27:46 +000098 result.setChildren(new Translator[] {
cbridgha44a17d72005-04-04 07:05:01 +000099 new IPathTranslator(RUNTIME_PATH, MODULE_CORE_PKG.getReferencedComponent_RuntimePath(), DOM_ATTRIBUTE),
cbridgha5059b8b2005-03-15 02:12:30 +0000100 new URITranslator(HANDLE, MODULE_CORE_PKG.getReferencedComponent_Handle(), DOM_ATTRIBUTE),
cbridghabe63a8d2005-09-12 02:48:39 +0000101 new HRefTranslator(DEP_OBJECT,MODULE_CORE_PKG.getReferencedComponent_DependentObject()),
cbridghaf654faf2005-02-13 16:27:46 +0000102 new DependencyTypeTranslator()
103 });
104 return result;
105 }
106
cbridghabe63a8d2005-09-12 02:48:39 +0000107
cbridghaf654faf2005-02-13 16:27:46 +0000108 private static Translator createWBResourceTranslator(EStructuralFeature afeature) {
cbridgha44a17d72005-04-04 07:05:01 +0000109 GenericTranslator result = new GenericTranslator(COMPONENT_RESOURCE, afeature);
cbridghaf654faf2005-02-13 16:27:46 +0000110 result.setChildren(new Translator[] {
111 IDTranslator.INSTANCE,
cbridgha44a17d72005-04-04 07:05:01 +0000112 new IPathTranslator(SOURCE_PATH, MODULE_CORE_PKG.getComponentResource_SourcePath(), DOM_ATTRIBUTE),
113 new IPathTranslator(RUNTIME_PATH, MODULE_CORE_PKG.getComponentResource_RuntimePath(), DOM_ATTRIBUTE),
cbridgha63a483d2005-04-06 13:24:45 +0000114 new Translator(RESOURCE_TYPE, MODULE_CORE_PKG.getComponentResource_ResourceType(), DOM_ATTRIBUTE),
cbridgha5059b8b2005-03-15 02:12:30 +0000115 new Translator(EXCLUSIONS, MODULE_CORE_PKG.getComponentResource_Exclusions())
cbridghaf654faf2005-02-13 16:27:46 +0000116 });
117 return result;
118 }
119
120}