KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > xmi > impl > EMOFResourceFactoryImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-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: EMOFResourceFactoryImpl.java,v 1.3 2005/06/08 06:16:07 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.xmi.impl;
18
19
20 import org.eclipse.emf.common.util.URI;
21 import org.eclipse.emf.ecore.EcorePackage;
22 import org.eclipse.emf.ecore.resource.Resource;
23 import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
24 import org.eclipse.emf.ecore.xmi.XMIResource;
25 import org.eclipse.emf.ecore.xmi.XMLResource;
26
27
28 public class EMOFResourceFactoryImpl extends ResourceFactoryImpl
29 {
30   protected EMOFExtendedMetaData extendedMetaData;
31
32   public EMOFResourceFactoryImpl()
33   {
34     super();
35
36     XMLResource.XMLMap xmlMap = new XMLMapImpl();
37
38     xmlMap.add(EcorePackage.eINSTANCE.getEFactory(), createXMLInfo("Factory"));
39     xmlMap.add(EcorePackage.eINSTANCE.getEPackage(), createXMLInfo("Package"));
40     xmlMap.add(EcorePackage.eINSTANCE.getEAttribute(), createXMLInfo("Property"));
41     xmlMap.add(EcorePackage.eINSTANCE.getEReference(), createXMLInfo("Property"));
42     xmlMap.add(EcorePackage.eINSTANCE.getEParameter(), createXMLInfo("Parameter"));
43     xmlMap.add(EcorePackage.eINSTANCE.getEOperation(), createXMLInfo("Operation"));
44     xmlMap.add(EcorePackage.eINSTANCE.getEEnumLiteral(), createXMLInfo("EnumerationLiteral"));
45     xmlMap.add(EcorePackage.eINSTANCE.getEDataType(), createXMLInfo("PrimitiveType"));
46     xmlMap.add(EcorePackage.eINSTANCE.getEEnum(), createXMLInfo("Enumeration"));
47     xmlMap.add(EcorePackage.eINSTANCE.getEClass(), createXMLInfo("Class"));
48
49     xmlMap.add(EcorePackage.eINSTANCE.getEFactory_EPackage(), createXMLInfo("package"));
50
51     xmlMap.add(EcorePackage.eINSTANCE.getEPackage_NsURI(), createXMLInfo("uri"));
52     xmlMap.add(EcorePackage.eINSTANCE.getEPackage_ESubpackages(), createXMLInfo("nestedPackage"));
53     xmlMap.add(EcorePackage.eINSTANCE.getEPackage_ESuperPackage(), createXMLInfo("nestingPackage"));
54     xmlMap.add(EcorePackage.eINSTANCE.getEPackage_EClassifiers(), createXMLInfo("ownedType"));
55     xmlMap.add(EcorePackage.eINSTANCE.getEPackage_NsPrefix(), createXMLInfo()); // no property
56

57     xmlMap.add(EcorePackage.eINSTANCE.getETypedElement_EType(), createXMLInfo("type"));
58     xmlMap.add(EcorePackage.eINSTANCE.getETypedElement_Ordered(), createXMLInfo("isOrdered"));
59     xmlMap.add(EcorePackage.eINSTANCE.getETypedElement_Unique(), createXMLInfo("isUnique"));
60     xmlMap.add(EcorePackage.eINSTANCE.getETypedElement_LowerBound(), createXMLInfo("lower"));
61     xmlMap.add(EcorePackage.eINSTANCE.getETypedElement_UpperBound(), createXMLInfo("upper"));
62
63     xmlMap.add(EcorePackage.eINSTANCE.getEStructuralFeature_Changeable(), createXMLInfo("isReadOnly")); // boolean not
64
xmlMap.add(EcorePackage.eINSTANCE.getEStructuralFeature_DefaultValueLiteral(), createXMLInfo("default"));
65     xmlMap.add(EcorePackage.eINSTANCE.getEStructuralFeature_Volatile(), createXMLInfo()); // no property
66
xmlMap.add(EcorePackage.eINSTANCE.getEStructuralFeature_Unsettable(), createXMLInfo()); // no property
67
xmlMap.add(EcorePackage.eINSTANCE.getEStructuralFeature_Transient(), createXMLInfo()); // no property
68
xmlMap.add(EcorePackage.eINSTANCE.getEStructuralFeature_Derived(), createXMLInfo("isDerived"));
69
70     xmlMap.add(EcorePackage.eINSTANCE.getEAttribute_ID(), createXMLInfo("isID"));
71
72     xmlMap.add(EcorePackage.eINSTANCE.getEReference_Containment(), createXMLInfo("isComposite"));
73     xmlMap.add(EcorePackage.eINSTANCE.getEReference_EOpposite(), createXMLInfo("opposite"));
74     xmlMap.add(EcorePackage.eINSTANCE.getEReference_ResolveProxies(), createXMLInfo()); // no property
75

76     xmlMap.add(EcorePackage.eINSTANCE.getEEnumLiteral_Value(), createXMLInfo()); // no property
77

78     xmlMap.add(EcorePackage.eINSTANCE.getEOperation_EParameters(), createXMLInfo("ownedParameter"));
79     xmlMap.add(EcorePackage.eINSTANCE.getEOperation_EExceptions(), createXMLInfo("raisedException"));
80
81     xmlMap.add(EcorePackage.eINSTANCE.getEClassifier_InstanceClassName(), createXMLInfo()); // no property
82

83     xmlMap.add(EcorePackage.eINSTANCE.getEDataType_Serializable(), createXMLInfo()); // no property
84

85     xmlMap.add(EcorePackage.eINSTANCE.getEEnum_ELiterals(), createXMLInfo("ownedLiteral"));
86
87     xmlMap.add(EcorePackage.eINSTANCE.getEClass_Abstract(), createXMLInfo("isAbstract"));
88     xmlMap.add(EcorePackage.eINSTANCE.getEClass_EStructuralFeatures(), createXMLInfo("ownedAttribute")); // ownedProperty???
89
xmlMap.add(EcorePackage.eINSTANCE.getEClass_EOperations(), createXMLInfo("ownedOperation"));
90     xmlMap.add(EcorePackage.eINSTANCE.getEClass_ESuperTypes(), createXMLInfo("superClass"));
91     xmlMap.add(EcorePackage.eINSTANCE.getEClass_Interface(), createXMLInfo()); // no property
92

93     extendedMetaData = new EMOFExtendedMetaData(xmlMap);
94   }
95
96   public Resource createResource(URI uri)
97   {
98     EMOFResourceImpl result = new EMOFResourceImpl(uri);
99
100     result.setEncoding("UTF-8");
101
102     result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
103     result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
104
105     result.getDefaultSaveOptions().put(XMLResource.OPTION_LINE_WIDTH, new Integer JavaDoc(80));
106     result.getDefaultSaveOptions().put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
107
108     return result;
109   }
110
111   protected XMLResource.XMLInfo createXMLInfo(String JavaDoc name)
112   {
113     XMLResource.XMLInfo info = new XMLInfoImpl();
114     info.setName(name);
115     return info;
116   }
117
118   protected XMLResource.XMLInfo createXMLInfo()
119   {
120     XMLResource.XMLInfo info = new XMLInfoImpl();
121     info.setXMLRepresentation(XMLResource.XMLInfo.ELEMENT); // We will use an xmi:Extension element for these
122
return info;
123   }
124 }
125
Popular Tags