By accident I ran into this, thought you'd be interested : http://code.google.com/p/gwt-greflect/
But still, if you're not writing some kind of mystic framework, you better stick with Gin. On 7 août, 15:53, Gal Dolber <[email protected]> wrote: > why don't you try to explain your situation.. I cannot imagine what you are > trying to do. > > 2010/8/6 Fernando Barbat <[email protected]> > > > > > > > Correction... If you want to know the type of the created object, It's > > "almost" type safe. :P If you are alright by knowing it's a Widget, > > it's type-safe. Here's a tidier version of the code: > > > "Almost" type-safe: > > public class Reflector { > > �...@suppresswarnings("unchecked") > > public static <T> T createInstance(Class<T> theClass) { > > if (theClass == TextBox.class) > > return (T)new TextBox(); > > else if (theClass == Button.class) > > return (T)new Button(); > > else > > throw new RuntimeException(); > > } > > } > > > Type-safe: > > public class Reflector { > > public static <T extends Widget> Widget createInstance(Class<T> > > theClass) { > > if (theClass == TextBox.class) > > return new TextBox(); > > else if (theClass == Button.class) > > return new Button(); > > else > > throw new RuntimeException(); > > } > > } > > > On 6 ago, 12:58, Fernando Barbat <[email protected]> wrote: > > > I was't so clear so I want to put it with an example. Let's suppose > > > your > > > helper class is named "Reflector". This class could be something like > > > this: > > > class Reflector { > > > public static T getInstance(Class<T extend Widget> class){ > > > if (class == MyClass1.class) > > > return new MyClass1(); > > > else if (class == MyClass2.class) > > > return new MyClass2(); > > > else > > > throw new CouldntInstanceClassException(); > > > }} > > > > It is type safe, although you can have a > > > CouldntInstanceClassException() if you forget to add the corresponding > > > comparison. > > > > On 6 ago, 08:19, Fernando Barbat <[email protected]> wrote: > > > > > You can do that on the client side. Although you don't have > > > > reflections, you can have a helper class which can do that work for > > > > you. That helper class could have a big "if, else if, else if" clause > > > > and compare classes using instance.getClass(). Every time you add a > > > > new class you want to use reflections with, you can add a new "else if > > > > (instance.getClass() == MyClass.class){ return new MyClass(); }" > > > > That was what I did when I needed to use reflections on the client > > > > side. > > > > > On 6 ago, 05:07, Stephan T <[email protected]> wrote: > > > > > > The reason why I try to do this is that GWT doesn't support > > > > > reflections. I'm trying to use a helper method on the server side > > > > > which receivs the class name, the server side then instatiates the > > > > > class and returns it to the client. > > > > > > Any other suggestions how to solve this problem? > > > > > > On 5 Aug, 15:47, Mikael Couzic <[email protected]> wrote: > > > > > > > Sounds like you violated the SRP principle... > > > > > > If I got it right, Composite depends on the DOM, which doesn't > > exist > > > > > > server-side, so I don't think it is possible. > > > > > > A solution would be to encapsulate the functionnality you want to > > use > > > > > > server-side in a POJO. Your composite would then delegate to the > > POJO, > > > > > > which could be reused server-side. > > > > > > And if you wish to push further towards great design, embrace MVP ! > > > > > > > On 5 août, 14:42, Stephan T <[email protected]> wrote: > > > > > > > > For several reasons I need to instansiate a Composite on the > > server > > > > > > > side that is in the client package. Is it possible? Now I think > > I'm > > > > > > > getting class not found exception when trying... > > > -- > > You received this message because you are subscribed to the Google Groups > > "Google Web Toolkit" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<google-web-toolkit%2Bunsubs > > [email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/google-web-toolkit?hl=en. > > --http://ajax-development.blogspot.com/ -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
