[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: [newbie qns] reflection and class impl

Alex schrieb:
Hi,

1. is it possible to create an EClass through reflection? e.g. I have a class name as a string ("MyEClass"). Now I would like to create this class with the factory. The factory has a method "EObject create(EClass arg0)" but I don't know how to get the EClass from the string.

2. all our code is in a package seperated from the auto generated packages. If I define an operation in the ecore model (e.g. operation "myOperation" on the class "MyEClass") then I'm supposed to implement the method in the generated class "MyEClassImpl". But I would like to implement the operation in an own class (different package). Therefor I could extend the class "MyEClassImpl" but if I create this class through the factory then an object of type "MyEClassImpl" would be instantiated instead of my own implemention. Is there a good solution for this?

thanks a lot,
Alex

I don't know if this the right thing but in my code (used to instantiate classes for iBatis) I do something like this (I think it was Ed's suggestion in a thread):


((ExtendedSqlMapClient) sqlMap).getDelegate()
					.setResultObjectFactory(new ResultObjectFactory() {

						@SuppressWarnings("unchecked")
						public Object createInstance(String arg0, Class arg1)
								throws InstantiationException,
								IllegalAccessException {

							for (EClassifier cf : ingeniumPackage.eINSTANCE.getEClassifiers()) {
								if (cf.getInstanceClass() == arg1) {
									return EcoreUtil.create((EClass) cf);
								}
							}
							return null;
						}

						public void setProperty(String arg0, String arg1) {
						}

});

I have a class but you could easily exchange this with:

cf.getInstanceClass().getName().equals("MyEClass").

Tom

--
B e s t S o l u t i o n . at
--------------------------------------------------------------------
Tom Schindl                                          JFace-Committer
--------------------------------------------------------------------