I have a class that extends AbstractGinModule
like:
public class ClientModule extends AbstractGinModule {
public ClientModule() { }
#Override
protected void configure() {
...
...
bind(...class).annotatedWith(...).to(...class).in(Singleton.class);
...
}
}
The idea that I have is to bind one class with another class based on a value stored in a property file.
like:
param contains the value coming from the property file
if(param.equals("instanceB"))
bind(a.class).to(b.class)
else
bind(a.class).to(c.class)
I have a class that access this property file and return a string with the value.
This class is called: InstanceParameters.java
I would like to get an instance of this class within my ClientModule.
But I don't find any way to do it.
I tried with:
- InstanceParameters param = new InstanceParameters ();
- GWT.create(InstanceParameters.class); (Error because this method should only be used on the client side)
Is there a way to access this InstanceParameters class within this clientModule?
Thank you for your help
You don't need to read the file before launching the application - just before creating the AbstractGinModule (via GWT.create). So, load the Dictionary in your onModuleLoad method and pass the parameters, either as a whole InstanceParameters class or as the extracted String, via a provider or any other means.
Related
I try to extend my MyDSLProposalProvider from an external Eclipse RCP Project. I created an extension point schema which requires a class property which extends my ProposalProvider. In the new project I extend the class an overrode some methods justs to give me some output so I can see that the external method is called. But this is currently not happening. Is there anything I have to consider?
Currently the hirachy looks like:
MyDSLProposalProvider extends AbstractMyDSLProposalProvider
ExternalProposalProvider extends MyDSLProposalProvider
I rewrote a Method generated in the AbstractMyDSLProposalProvider but when its triggered the predefined Method in the AbstractMyDSLProposalProvider is called and not my new implementation.
public class ExternalMyDSLProposalPovider extends MyDSLProposalProvider
{
#Override
public void completeComponent_Name(EObject model, Assignment
assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
System.err.println("extern");
if(model instanceof Component)
{
createProposal("foo", "foo", context, acceptor);
}
super.completeComponent_Name(model, assignment, context, acceptor);
}
}
This is the class in the external Eclipse Project.
Thanks for the help.
When you declare an extension point using a schema that you have defined Eclipse puts that declaration in the extension point registry. That is all that is does, you must then write code to make uses of those declarations.
You read the extension point registry using something like:
IExtensionRegistry extRegistry = Platform.getExtensionRegistry();
IExtensionPoint extPoint = extRegistry.getExtensionPoint("your extension point id");
IConfigurationElement [] elements = extPoint.getConfigurationElements();
elements is now an array of the declarations in the various plugins using the extension point.
IConfigurationElement has various methods to get the values of the attributes of the declaration.
If you have defined a class in one of the attributes you can create an instance of the class using:
IConfigurationElement element = .... a config element
Object obj = element.createExecutableExtension("attribute name");
In your case the result should be your ExternalMyDSLProposalPovider.
You will then need to hook this object up with whatever is doing to proposals.
I'm trying to debug a library which uses haxe.macro.TypeTools::findField. I've created a simple code for that:
package;
using haxe.macro.TypeTools;
class Main
{
public function new()
{
var test = findField(Child, "hello");
trace(test);
}
}
class Base
{
private function hello()
{
}
}
class Child extends Base
{
public function new() {}
}
However I'm getting error Unknown identifier : findField. Is this because it can only be used in build macro context?
This is what I'm trying to emulate.
First of all, function findField() is not from the haxe.macro.TypeTools.
It is a helper function from edge.core.macro.Macros.
To use it without a class path, import it's class with a wildcard import edge.core.macro.Macros.*
Secondly, findField() should be used in a build macro context only, since it expects Array<Field>, which is obtained by haxe.macro.Context.getBuildFields().
I have an OnMethodBoundaryAspect and within the CompileTimeValidate method I'd like to verify that the Aspect attribute is being applied at the class level.
example:
[MyCustomAspect]
public class SomeClass
{
...
I wouldn't like this to throw a compilation error.
example:
public class SomeClass
{
[MyCustomAspect]
public void SomeMethod() {
...
How can I detect where my Aspect attribute is being applied?
The moment when CompileTimeValidate method executes is already too late to validate the attribute application. The "attribute multicasting" step runs first, and it will propagate the method level aspect applied on a class to the class methods, removing the original attribute at the same time.
To validate the attribute application you can configure the valid targets with [AttributeUsage].
[Serializable]
[AttributeUsage(AttributeTargets.Class)]
public class MyCustomAspect : MethodLevelAspect
{
// ...
}
I'm currently working on a simple GWT project. One of the things I'd like to do is that when the page loads I can dynamically populate the contents of a ListBox based on certain criteria. I actually don't see any handlers for a ListBox to handle the initial render event but I see change handlers.
How does one populate a ListBox contents with data from the server side on pageload with GWT?
Right now I have a class that implements EntryPoint that has a
final ListBox fooList = new ListBox();
I also have a set of beans but I also have a class implementing RemoteService. Since I can't seem to get direct calls to my user defined packages directly in the EntryPoint (which makes sense) how do I populate that ListBox with server side content on initial page load? Right now I'm using a List but I figure if I cant get that to work I can get a DB call to work...
I've tried things in the EntryPoint like:
for (String name : FOOS) {
fooList.addItem(name, name);
}
However FOOS would derive from a server side data and the EntryPoint is supposed to be largerly limited to what can compile to JS! I can't get user defined classes to be recognized on that side as that string is the result of a set of user defined classes.
I also tried creating a method in the class implementing RemoteService that returns a ListBox. This also didn't compile when I tried to call this method. Perhaps I don't fully understand how to call methods in a RemoteService service implementing class.
I've searched a lot and I can't find anything that clearly explains the fundamentals on this. My background is much more ASP.NET and JSPs so perhaps I'm missing something.
I'm using GWT 2.6 is that is relevant.
The usual procedure is the following:
Create a bean class for the data you want to transmit between client and server. Let's call it MyBean.
Place MyBean in the shared package of your project.
This class has to implement either Serializable or IsSerializable, otherwise GWT will complain that it doesn't know how to transmit it.
Create your RemoteService that contains the method you want to use to transmit MyBean from/to the server.
Once you get your data on the client using an AsyncCallback and your RemoteService, fill the ListBox using your beans, e.g. by calling MyBean#getName() or MyBean#toString().
Success!
I based my example on the GWT sample project ( I named it example), just replace the classes and it should work :
public class Example implements EntryPoint {
/**
* Create a remote service proxy to talk to the server-side Greeting
* service.
*/
private final GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final ListBox listBox = new ListBox();
RootPanel.get("sendButtonContainer").add(listBox);
greetingService.getSomeEntries(new AsyncCallback<String[]>() {
#Override
public void onSuccess(String[] result) {
for (int i = 0; i < result.length; i++) {
listBox.addItem(result[i]);
}
}
#Override
public void onFailure(Throwable caught) {
}
});
}
}
This is our EntryPoint, it creates a listbox and calls the server with a AsyncCallback to get some dynamic data. If the call is successfull (onSuccess), the data is written into the listbox.
The GreetingService interface define the synchronous methods, it is implemented in the GreetingServiceImpl class :
#RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
String[] getSomeEntries() ;
}
The asynchronous counterpart is the GreetingServiceAsync interface, we used it before to call the server :
public interface GreetingServiceAsync {
void getSomeEntries(AsyncCallback<String[]> callback) ;
}
The GreetingServiceImpl class is located on the server. Here you could call for example a database:
#SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
#Override
public String[] getSomeEntries() {
String[] entries = { "Entry 1","Entry 2","Entry 3" };
return entries;
}
}
Now if you want to use some Bean/Pojo between the server and client, replace the String[] in each class/interface with the object name, put the class in the shared package and consider that it implements Serializable/IsSerializable.
Actually i wanted to override the runChild() method of BlockJUnit4ClassRunner hence I created a class (MyRunner.java) and exetended BlockJUnit4ClassRunner and overridden the runChild() method.
public class MyRunner extends BlockJUnit4ClassRunner
{
#Override
public void runChild(final FrameworkMethod method, RunNotifier notifier) {
System.out.println("<--------- Inside MyRunner.runChild() -------->");
// my code goes here
}
}
But the call doesn't go to my overridden method (it doesn't even come to MyRunner.java) and calls BlockJUnit4ClassRunner.runChild() method only.
I debugged and found that this is because the runner passed to JunitCore.run(Runner runner) method is BlockJUnit4ClassRunner.
I'm not sure on this but I think this might be coming from JUnit4Builder.runnerForClass() method .
// This is JUnit4Builder.runnerForClass(Class<?>) method
public Runner runnerForClass(Class<?> testClass) throws Throwable
{
return new BlockJUnit4ClassRunner(testClass);
}
I tried to override the JUnit4Builder.runnerForClass() also but that also did not helped.
Can anyone let me know if there's any way to pass the MyRunner or any means to override the BlockJUnit4ClassRunner.runChild() method.
You are probably not using the #RunWith annotation. In order to use your own Runner you need to annotate every TestClass with the #RunWith annotation. This will make sure, that your Test is executed with that runner.
Example:
#RunWith(MyRunner .class)
public class MyTest
{
....
}