Common utilities and foundational infrastructure for the Errai GWT-based framework
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Errai Common provides foundational utilities and infrastructure for the Errai GWT-based framework. It contains essential client-side components including JSON encoding/decoding utilities, type marshalling and demarshalling infrastructure, callback frameworks, and GWT integration helpers that enable seamless communication between client and server components.
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-common</artifactId>
<version>1.0.1</version>
</dependency>import org.jboss.errai.common.client.ErraiCommon;
import org.jboss.errai.common.client.framework.AcceptsCallback;
import org.jboss.errai.common.client.json.JSONEncoderCli;
import org.jboss.errai.common.client.json.JSONDecoderCli;
import org.jboss.errai.common.client.types.*;// JSON encoding/decoding
JSONEncoderCli encoder = new JSONEncoderCli();
String json = encoder.encode(myObject);
JSONDecoderCli decoder = new JSONDecoderCli();
Object decoded = decoder.decode(json);
// Type conversion
Object converted = TypeHandlerFactory.convert(String.class, Integer.class, "123");
// Custom marshalling
TypeMarshallers.addMarshaller(MyClass.class, new MyClassMarshaller());
Marshaller<MyClass> marshaller = TypeMarshallers.getMarshaller(MyClass.class);
// GWT text selection utility
ErraiCommon.disableTextSelection(element, true);Errai Common is built around several key components:
TypeHandlerFactory with built-in handlers for collections and numbersMarshaller and Demarshaller interfaces with registry classesorg.jboss.errai.common.client/
├── ErraiCommon # Main GWT entry point class
├── framework/
│ └── AcceptsCallback # Callback interface for async operations
├── json/
│ ├── JSONEncoderCli # Client-side JSON encoding
│ └── JSONDecoderCli # Client-side JSON decoding
└── types/
├── TypeHandler<V,T> # Type conversion interface
├── Marshaller<T> # Object to string marshalling interface
├── Demarshaller<T> # JSON object to typed object interface
├── TypeHandlerFactory # Central factory for type conversions
├── TypeMarshallers # Registry for marshaller instances
├── TypeDemarshallers # Registry for demarshaller instances
├── JSONTypeHelper # JSON-type conversion utilities
└── handlers/ # Built-in type handler implementations
├── collections/ # Collection to array/collection conversions
├── numbers/ # Number to primitive/Date conversions
└── primitives/ # Limited primitive conversionsCore type conversion system for converting between Java types, with built-in support for collections, numbers, and custom type handlers.
public class TypeHandlerFactory {
public static <T> T convert(Class from, Class<? extends T> to, Object value);
public static Map<Class, TypeHandler> getHandler(Class from);
public static void addHandler(Class from, Class to, TypeHandler handler);
}
public interface TypeHandler<V, T> {
public T getConverted(V in);
}Client-side JSON encoding and decoding with support for custom marshalling and type-aware conversion.
public class JSONEncoderCli {
public String encode(Object v);
public String encodeMap(Map<Object, Object> map);
public Map<String, String> getMarshalledTypes();
}
public class JSONDecoderCli {
public Object decode(Object value);
}Extensible marshalling system for converting objects to/from string representations and JSON objects.
public interface Marshaller<T> {
public String marshall(T object);
}
public interface Demarshaller<T> {
public T demarshall(JSONObject o);
}
public class TypeMarshallers {
public static void addMarshaller(Class type, Marshaller d);
public static <T> Marshaller<T> getMarshaller(Class<? extends T> type);
public static boolean hasMarshaller(Class type);
}
public class TypeDemarshallers {
public static void addDemarshaller(Class type, Demarshaller d);
public static <T> Demarshaller<T> getDemarshaller(Class<? extends T> type);
public static boolean hasDemarshaller(Class type);
}GWT integration utilities and callback framework for building interactive applications.
public class ErraiCommon implements EntryPoint {
public void onModuleLoad();
public static void disableTextSelection(Element e, boolean disable);
}
public interface AcceptsCallback {
public static final String MESSAGE_OK = "OK";
public static final String MESSAGE_CANCEL = "CANCEL";
public void callback(Object message, Object data);
}// GWT JSON types
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.json.client.JSONArray;
// GWT DOM types
import com.google.gwt.dom.client.Element;
// Errai type system imports
import org.jboss.errai.common.client.types.JSONTypeHelper;
// Standard Java types
import java.util.*;
import java.io.Serializable;