[
http://issues.apache.org/jira/browse/TUSCANY-516?page=comments#action_12419444
]
Venkatakrishnan commented on TUSCANY-516:
-----------------------------------------
In the approach that I am following to map SDOs to XSDs, I instantiate the SDO
in order to be able to access it 'Type' field and then ofcourse work with the
'Type' instance such as type.is Sequenced(), or type.isDataType()... and so on.
But then how do I instantiate the SDO? I would ideally need information about
the associated DataFactory to be used isn' t it. All that a user might input
is the name of the SDO Type such as com.examples.sequences.MixedQuote". Using
this I must have to instantiate this SDO class. For this I need to know which
is the Factory class over which I can execute 'createMixedQuote' method. i.e.
I need to know com.example.sequences.SequencesFactory
An alternate method of instantiating the SDO is to call its 'protected'
constructor, using Java Reflection APIs. This breaks encapsulation as we break
the 'protected' access. Also if the input SDO Type name is actually the name
of the Interface and not the implementation i.e. if it is MixedQuote and not
MixedQuoteImpl, then this will not work.
On the other hand, if the generated SDO type also had information about the
Factory class that can instantiate it, it can be picked up and used. I am
wondering if we could have annotations in the generated code for this.
Since the code generation cycle for generating SDOs also includes the
generation of the associated Package and Factory classes, I was wondering if we
could capture this information as part of the generated SDOs.
Presently, my requirement is only for information about the Factory but then I
hope that there will be other tools that might need the 'Package' information
as well.
Example use case
-------------------------
//the SDO class name is given by the user
Class sdoClass = Class.forName("com.examples.sequences.MixedQuote");
// I would like to obtain the Factory class name without user intervention
Class sdoFactoryClass =
Class.forName("com.examples.sequences.MixedQuoteFactory");
String factoryMethodName = "create" + sdoClass.getSimpleName();
Method initMethod = sdoFactoryClass.getDeclaredMethod(INIT_METHOD, new
Class[0]);
Object sdoFactory = initMethod.invoke(null, new Object[0]);
// here is how I instantiate the SDO
Method factoryMethod = factoryClass
.getDeclaredMethod(getFactoryMethodName(factoryMethodName, new Class[0]);
dataObject = (DataObject)factoryMethod.invoke(sdoFactory, new Object[0])
Thanks.
> Annotating generated SDO Types for the associated 'Factory' and 'Package'
> generated classes
> -------------------------------------------------------------------------------------------
>
> Key: TUSCANY-516
> URL: http://issues.apache.org/jira/browse/TUSCANY-516
> Project: Tuscany
> Type: Sub-task
> Components: Java SDO Tools
> Versions: Java-Mx
> Reporter: Venkatakrishnan
>
> The SDO needs to be instantiated to obtain a more reliable information about
> it type using the 'getType' method. To minimize user inputs in aid of this
> instantiation, it would be good to have an annotation added to the generated
> SDO, pointing to the Factory class for the SDO.
> Work Around : Currently, the protected constructor of the input SDO class is
> invoked using Java Reflection APIs. This is not an ok approach as we break
> the access and then invoke the constructor. Also, if the input is the SDO
> Type Interface then this work around will fail.
> If having the Factory class information sound ok, then we could also have the
> Package class information. I am sure we are going to need this somewhere
> down the line.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]