Gwtp Autobean and rest - rest

I have InfraNameModel (Rest-type) to work with JSON
public interface IInfraNameBeanFactory extends AutoBeanFactory {
IInfraNameBeanFactory INSTANCE = GWT.create(IInfraNameBeanFactory.class);
AutoBean<InfraNameModel> infraName();
AutoBean<InfraNameListModel> results();
}
public interface InfraNameListModel {
List<InfraNameModel> getResults();
void setResults(List<InfraNameModel> results);
}
public class InfraNameListModelImpl implements InfraNameListModel {
private List<InfraNameModel> results;
#Override
public List<InfraNameModel> getResults() {
return results;
}
#Override
public void setResults(List<InfraNameModel> results) {
this.results = results;
}
}
public interface InfraNameModel {
String getInfraName();
void setInfraName(String infraName);
}
public class InfraNameModelImpl implements InfraNameModel {
private String infraName;
#Override
public String getInfraName() {
return infraName;
}
#Override
public void setInfraName(String infraName) {
this.infraName = infraName;
}
}
I wanted to make them into a separate JAR
To make it common for the client and the server
But now I have errors
[WARN] Class by.models.infraNameModel.InfraNameModel is used in Gin, but not available in GWT client code.
Is it real to pull such beans into a separate library?

Related

How to maintain order of methods of interface in implemented class

Suppose I am having below interface inside binary jar:
public interface OrderDemo
{
public void add();
public void shut();
public void manage();
}
When I am adding this as Jar as part of dependency in my project in eclipse after implementing OrderDemo interface order of method get changed.
public class Demo implements OrderDemo
{
#Override
public void add();
{
}
#Override
public void manage()
{
}
#Override
public void shut()
{
}
}
Tried option given in eclipse preference but won't work.

Is it possible to add an extra loglevel in GWT

In normal Java it is pretty easy to add your own custom loglevels.
But all the Java ways I know don't work in GWT because GWT has its own implementation of java.util.logging.Level.
Say I want an extra level between SEVERE (1000), and warning (900) --> ERROR (950).
How can I achieve this ?
I managed to sort this out for myself.
In case anyone is interested in this.
What you have to do is create a "super" directory. This on the same level as the "client" directory of your module.
In this directory you create a java.util.logging.Level class with the same content as the one found in the GWT source. But with the added level.
For example :
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package java.util.logging;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.logging.impl.LevelImpl;
import com.google.gwt.logging.impl.LevelImplNull;
import java.io.Serializable;
/**
* An emulation of the java.util.logging.Level class. See
* <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/Level.html">
* The Java API doc for details</a>
*/
public class Level implements Serializable {
private static LevelImpl staticImpl = GWT.create(LevelImplNull.class);
public static Level ALL = new LevelAll();
public static Level CONFIG = new LevelConfig();
public static Level FINE = new LevelFine();
public static Level FINER = new LevelFiner();
public static Level FINEST = new LevelFinest();
public static Level INFO = new LevelInfo();
public static Level OFF = new LevelOff();
public static Level EXCEPTION = new LevelException();
public static Level WARNING = new LevelWarning();
public static Level ERROR = new LevelError();
public static Level SEVERE = new LevelSevere();
private static class LevelAll extends Level {
#Override public String getName() { return "ALL"; }
#Override public int intValue() { return Integer.MIN_VALUE; }
}
private static class LevelConfig extends Level {
#Override public String getName() { return "CONFIG"; }
#Override public int intValue() { return 700; }
}
private static class LevelFine extends Level {
#Override public String getName() { return "FINE"; }
#Override public int intValue() { return 500; }
}
private static class LevelFiner extends Level {
#Override public String getName() { return "FINER"; }
#Override public int intValue() { return 400; }
}
private static class LevelFinest extends Level {
#Override public String getName() { return "FINEST"; }
#Override public int intValue() { return 300; }
}
private static class LevelInfo extends Level {
#Override public String getName() { return "INFO"; }
#Override public int intValue() { return 800; }
}
private static class LevelOff extends Level {
#Override public String getName() { return "OFF"; }
#Override public int intValue() { return Integer.MAX_VALUE; }
}
private static class LevelException extends Level {
#Override public String getName() { return "EXCEPTION"; }
#Override public int intValue() { return 1000; }
}
private static class LevelSevere extends Level {
#Override public String getName() { return "SEVERE"; }
#Override public int intValue() { return 1000; }
}
private static class LevelError extends Level {
#Override public String getName() { return "ERROR"; }
#Override public int intValue() { return 950; }
}
private static class LevelWarning extends Level {
#Override public String getName() { return "WARNING"; }
#Override public int intValue() { return 900; }
}
public static Level parse(String name) {
return staticImpl.parse(name);
}
protected Level() { }
public String getName() {
return "DUMMY";
}
public int intValue() {
return -1;
}
#Override
public String toString() {
return getName();
}
/* Not Implemented */
// public boolean equals(Object ox) {}
// protected Level(String name, int value, String resourceBundleName) {}
// public String getLocalizedName() {}
// public String getResourceBundleName() {}
// public int hashCode() {}
}
Now you must mark this "super" directory as super source in your gwt.xml
<super-source path="super"/>
If you are using Eclipse you will have to exclude this super directory from the source path to avoid eclipse giving errors. And add it again as a seperate source path so that eclipse does check the file for errors.
Finally, if you do all this in a sub-module, you must ensure that when compiling your main module, this gets priority over the classes in rt.jar. This can be done by using an endorsed directory when compiling.

How to use provider in Errai IOC?

I have a problem with #IocProvider (), annotation does not work.
The code is very similar to https://docs.jboss.org/author/display/ERRAI/Container+Wiring
public interface Test {
String getGreeting();
}
#ApplicationScoped
public class TestImpl implements Test {
public String getGreeting() {
return "Hello:)";
}
}
#IOCProvider
#Singleton
public class TestProvider implements Provider<Test> {
#Override
public Test get() {
return new TestImpl();
}
}
Then I want use DI in my broadcast service (errai-bus).
#Service
public class BroadcastService implements MessageCallback {
#Inject
Test test;
#Inject
MessageBus bus;
#Inject
public BroadcastService(MessageBus bus) {
this.bus = bus;
}
public void callback(Message message) {
MessageBuilder.createMessage()
.toSubject("BroadcastReceiver")
.with("BroadcastText", test.getGreeting()).errorsHandledBy(new ErrorCallback() {
#Override
public boolean error(Message message, Throwable throwable) {
return true;
}
}).sendNowWith(bus);
}
}
I get a error:
1) No implementation for com.gwtplatform.samples.basic.server.Test was bound.
while locating com.gwtplatform.samples.basic.server.Test
for field at com.gwtplatform.samples.basic.server.BroadcastService.test(BroadcastService.java:32)
at org.jboss.errai.bus.server.service.ServiceProcessor$1.configure(ServiceProcessor.java:118)
If I change the code to
#Inject
TestImpl test;
It works, but I need the provider. Do you have some idea?
Because you're trying to use #IOCProvider in server-side code. Errai IOC is completely client-side.

GWT-GIN Multiple Implementations?

I have the following code
public class AppGinModule extends AbstractGinModule{
#Override
protected void configure() {
bind(ContactListView.class).to(ContactListViewImpl.class);
bind(ContactDetailView.class).to(ContactDetailViewImpl.class);
}
}
#GinModules(AppGinModule.class)
public interface AppInjector extends Ginjector{
ContactDetailView getContactDetailView();
ContactListView getContactListView();
}
In my entry point
AppInjector appInjector = GWT.create(AppGinModule.class);
appInjector.getContactDetailsView();
Here ContactDetailView is always bind with ContactsDetailViewImpl. But i want that to bind with ContactDetailViewImplX under some conditions.
How can i do that? Pls help me.
You can't declaratively tell Gin to inject one implementation sometimes and another at other times. You can do it with a Provider or a #Provides method though.
Provider Example:
public class MyProvider implements Provider<MyThing> {
private final UserInfo userInfo;
private final ThingFactory thingFactory;
#Inject
public MyProvider(UserInfo userInfo, ThingFactory thingFactory) {
this.userInfo = userInfo;
this.thingFactory = thingFactory;
}
public MyThing get() {
//Return a different implementation for different users
return thingFactory.getThingFor(userInfo);
}
}
public class MyModule extends AbstractGinModule {
#Override
protected void configure() {
//other bindings here...
bind(MyThing.class).toProvider(MyProvider.class);
}
}
#Provides Example:
public class MyModule extends AbstractGinModule {
#Override
protected void configure() {
//other bindings here...
}
#Provides
MyThing getMyThing(UserInfo userInfo, ThingFactory thingFactory) {
//Return a different implementation for different users
return thingFactory.getThingFor(userInfo);
}
}

How to respond to URLs with GWT's built-in MVP-framework?

I'm building a very simple calendar app to get familiar with the MVP-framework introduced with the 2.1 version of GWT.
What I want to achieve is being able to switch between a list of scheduled appointments and a list of the avialable time.
I have created the a CalendarPlace, CalendarActivity, CalendarView and CalendarViewImpl.
I know that to navigate to a different place i would call PlaceController.goTo(Place), so in my calendar app I would call:
clientFactory.getPlaceController.goTo(new CalendarPlace("freeTime");
The URL would be index.html#CalendarPlace:freeTime for the list of free time or
clientFactory.getPlaceController.goTo(new CalendarPlace("appointments");
for the list of scheduled appointments. The URL would be index.html#CalendarPlace:appointments
But the question is where do I respond to the different tokens? I guess the CalendarPlace would be the right place, but how would I do that?
Here is my source code(I took most of the boilerplate from the tutorial here:
CalendarPlace:
public class CalendarPlace extends Place {
private String calendarName;
public CalendarPlace(String token) {
this.calendarName = token;
}
public String getCalendarName() {
return calendarName;
}
public static class Tokenizer implements PlaceTokenizer<CalendarPlace> {
#Override
public CalendarPlace getPlace(String token) {
return new CalendarPlace(token);
}
#Override
public String getToken(CalendarPlace place) {
return place.getCalendarName();
}
}
}
CalendarActivity:
public class CalendarActivity extends AbstractActivity
implements
CalendarView.Presenter {
private ClientFactory clientFactory;
private String name;
public CalendarActivity(CalendarPlace place, ClientFactory clientFactory) {
this.name = place.getCalendarName();
this.clientFactory = clientFactory;
}
#Override
public void goTo(Place place) {
clientFactory.getPlaceController().goTo(place);
}
#Override
public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
CalendarView calendarView = clientFactory.getCalendarView();
calendarView.setName(name);
calendarView.setPresenter(this);
containerWidget.setWidget(calendarView.asWidget());
}
}
CalendarViewImpl:
public class CalendarViewImpl extends Composite implements CalendarView {
private VerticalPanel content;
private String name;
private Presenter presenter;
private OptionBox optionBox;
public CalendarViewImpl() {
//optionBox is used for navigation
//optionBox is where I call PlaceController.goTo() from
optionBox=new OptionBox();
RootPanel.get("bluebar").add(optionBox);
content=new VerticalPanel();
this.initWidget(content);
}
#Override
public void setPresenter(Presenter listener) {
this.presenter=listener;
}
#Override
public void setName(String calendarName) {
this.name = calendarName;
}
public void displayFreeTime() {
//called from somewhere to display the free time
}
public void getAppointments() {
//called from somewhere to display the appointments
}
}
In your CalendarActivity constructor you have access to the place, and therefore the token. Tuck it aside, and then in your start() method you can use it. Activities are meant to be lightweight objects, created for each new navigation.