package com.example.library; import org.eclipse.emf.ecore.EObject; /** * <!-- begin-user-doc --> * A representation of the model object '<em><b>Library</b></em>'. * <!-- end-user-doc --> * * * @see com.example.library.LibraryPackage#getLibrary() * @model * @generated */ public interface Library extends EObject { ... } package com.example.library.impl; import com.example.library.Book; import org.eclipse.emf.ecore.EClass; /** * <!-- begin-user-doc --> * An implementation of the model object '<em><b>Book</b></em>'. * <!-- end-user-doc --> * * @generated */ public class BookImpl extends ItemImpl implements Book { ... } <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="library" nsURI="http:///example/library.ecore" nsPrefix="example.library"> <eClassifiers xsi:type="ecore:EClass" name="Library"> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> <eStructuralFeatures xsi:type="ecore:EReference" name="items" eType="#//Item" containment="true" upperBound="-1" resolveProxies="false"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="Item"> <eStructuralFeatures xsi:type="ecore:EAttribute" name="title" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> <eStructuralFeatures xsi:type="ecore:EAttribute" name="year" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/> <eStructuralFeatures xsi:type="ecore:EAttribute" name="available" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="Book"> <eSuperTypes xsi:type="ecore:EClass" href="#//Item"/> <eStructuralFeatures xsi:type="ecore:EAttribute" name="author" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="LibraryFactory" instanceClassName="com.example.library.LibraryFactory" eInstanceTypeName="example.library.LibraryFactory" eTypeParameters="T"> </eClassifiers> <eClassifiers xsi:type="ecore:EClass" name="LibraryPackage" nsURI="http:///example/library.ecore" nsPrefix="example.library" instanceClassName="com.example.library.LibraryPackage" eInstanceTypeName="example.library.LibraryPackage"> <eStructuralFeatures xsi:type="ecore:EReference" name="eFactoryInstance" eType="#//LibraryFactory" containment="true" upperBound="1" resolveProxies="false"/> <eStructuralFeatures xsi:type="ecore:EReference" name="eClassifiers" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EClass" upperBound="-1" resolveProxies="false" defaultValueLiteral="null" unsettable="true" derived="true"> <eAnnotations xsi:type="ecore:EAnnotation" source="org.eclipse.emf.ecore" references="ecore:EClassifier#name http://www.eclipse.org/emf/2002/GenModel#//GenClass/nestedClassifier ecore:EFactory#ePackage ecore:EPackage ecore:EStructuralFeature#eContainingClass http://www.eclipse.org/emf/2002/GenModel#//GenFeature/eContainingClass ecore:EStructuralFeature#eType ecore:EStructuralFeature#eGenericType http://www.eclipse.org/emf/2002/GenModel#//GenFeature/eType" details="resolveProxies='false'" annotationType="http://www.eclipse.org/emf/2002/GenModel#//GenModel/GenAnnotation/ePackageMetaDataMap" source="Pivot Source" key="/ecore:EPackage"> <details key="nsURI" value="http:///example/library.ecore"/> <details key="implementationPackageSuffix" value=".impl"/> <details key="annotationProvider" value="org.eclipse.xtext.xbase.resource.XbaseResource"/> </eAnnotations> </eStructuralFeatures> </eClassifiers> </ecore:EPackage> package com.example.library; import org.eclipse.emf.ecore.EObject; /** * <!-- begin-user-doc --> * A representation of the model object '<em><b>Library</b></em>'. * <!-- end-user-doc --> * * * @see com.example.library.LibraryPackage#getLibrary() * @model * @generated */ public interface Library extends EObject { \t/** \t * Returns the value of the '<em><b>Name</b></em>' attribute. \t * <!-- begin-user-doc --> \t * <p> \t * If the meaning of the '<em>Name</em>' attribute isn't clear, \t * there really should be more of a description here... \t * </p> \t * <!-- end-user-doc --> \t * @return the value of the '<em>Name</em>' attribute. \t * @see #setName(String) \t * @see com.example.library.LibraryPackage#getLibrary_Name() \t * @model required="true" \t * @generated \t */ \tString getName(); \t/** \t * Sets the value of the '{@link com.example.library.Library#getName <em>Name</em>}' attribute. \t * <!-- begin-user-doc --> \t * <!-- end-user-doc --> \t * @param value the new value of the '<em>Name</em>' attribute. \t * @see #getName() \t * @generated \t */ \tvoid setName(String value); } // Library package com.example.library.impl; import com.example.library.Book; import com.example.library.Library; import com.example.library.LibraryFactory; import com.example.library.LibraryPackage; import com.example.library.Item; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.impl.EFactoryImpl; public class LibraryFactoryImpl extends EFactoryImpl implements LibraryFactory { \t \tpublic static LibraryFactory init() { \t\ttry { \t\t\tLibraryFactory theLibraryFactory = (LibraryFactory)EPackage.Registry.INSTANCE.getEFactory(LibraryPackage.eNS_URI); \t\t\tif (theLibraryFactory != null) { \t\t\t\treturn theLibraryFactory; \t\t\t} \t\t} \t\tcatch (Exception exception) { \t\t\tEcorePlugin.INSTANCE.log(exception); \t\t} \t\treturn new LibraryFactoryImpl(); \t} \t \tpublic LibraryFactoryImpl() { \t\tsuper(); \t} \t \t@Override \tpublic EObject create(EClass eClass) { \t\tswitch (eClass.getClassifierID()) { \t\t\tcase LibraryPackage.LIBRARY: return createLibrary(); \t\t\tcase LibraryPackage.BOOK: return createBook(); \t\t\tcase LibraryPackage.ITEM: return createItem(); \t\t\tdefault: \t\t\t\tthrow new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); \t\t} \t} \t \tpublic Library createLibrary() { \t\tLibraryImpl library = new LibraryImpl(); \t\treturn library; \t} \t \tpublic Book createBook() { \t\tBookImpl book = new BookImpl(); \t\treturn book; \t} \t \tpublic Item createItem() { \t\tItemImpl item = new ItemImpl(); \t\treturn item; \t} \t \t... }


上一篇:
下一篇:
切换中文