xapi.gwt.model.ModelGwt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-gwt Show documentation
Show all versions of xapi-gwt Show documentation
This module exists solely to package all other gwt modules into a single
uber jar. This makes deploying to non-mavenized targets much easier.
Of course, you would be wise to inherit your dependencies individually;
the uber jar is intended for projects like collide,
which have complex configuration, and adding many jars would be a pain.
The newest version!
package xapi.gwt.model;
import static xapi.util.impl.PairBuilder.entryOf;
import java.util.Iterator;
import java.util.Map.Entry;
import xapi.model.impl.AbstractModel;
public class ModelGwt extends AbstractModel{
private final class Itr implements Iterable> {
private final String[] keys;
private Itr(final String[] keys) {
this.keys = keys;
}
@Override
public Iterator> iterator() {
return new Iterator>() {
int pos = 0;
@Override
public boolean hasNext() {
return pos < keys.length;
}
@Override
public Entry next() {
final String key = keys[pos];
Object value = getProperty(key);
if (value == null) {
final Class> type = getPropertyType(key);
if (type.isPrimitive()) {
value = AbstractModel.getPrimitiveValue(type);
}
}
return entryOf(key, value);
}
};
}
}
@Override
public Iterable> getProperties() {
// Because we know all generated Gwt modules MUST implement property names,
// We can safely enforce serialization ordering using .getPropertyNames()
final String[] names = getPropertyNames();
return new Itr(names);
}
@Override
public Class> getPropertyType(final String key) {
throw new UnsupportedOperationException("Type "+getClass()+" does not handle property type "+key);
}
@Override
public String[] getPropertyNames() {
return new String[0];
}
}