use of com.googlecode.gwt.test.exceptions.GwtTestUiBinderException in project gwt-test-utils by gwt-test-utils.
the class UiTagBuilder method endTag.
UiTagBuilder<T> endTag(String nameSpaceURI, String localName) {
// ignore <UiBinder> tag
if (UiBinderXmlUtils.isUiBinderTag(nameSpaceURI, localName)) {
return this;
}
Object currentObject = currentTag.endTag();
UiTag<?> parentTag = currentTag.getParentTag();
currentTag = parentTag;
if (UiBinderXmlUtils.isResourceTag(nameSpaceURI, localName) || UiBinderXmlUtils.isImportTag(nameSpaceURI, localName)) {
// ignore <ui:data>, <ui:image>, <ui:style> <ui:text> and <ui:import> tags
return this;
} else if (UiBinderXmlUtils.isMsgTag(nameSpaceURI, localName) || UiBinderXmlUtils.isTextTag(nameSpaceURI, localName)) {
// special <ui:msg> and <ui:text> case
parentTag.appendText((String) currentObject);
return this;
}
if (parentTag == null) {
// parsing is finished, this must be the root component
if (rootComponent != null) {
throw new GwtTestUiBinderException("UiBinder template '" + owner.getClass().getName() + "' should declare only one root widget in its corresponding .ui.xml file");
} else {
rootComponent = currentObject;
}
} else {
// add to its parent
if (IsWidget.class.isInstance(currentObject)) {
parentTag.addWidget((IsWidget) currentObject);
} else if (UIObject.class.isInstance(currentObject)) {
// UIObject instance that is not a Widget
parentTag.addUiObject((UIObject) currentObject);
} else {
parentTag.addElement((Element) currentObject);
}
}
return this;
}
use of com.googlecode.gwt.test.exceptions.GwtTestUiBinderException in project gwt-test-utils by gwt-test-utils.
the class UiBinderInstanciator method getObjectFromUiFactory.
private static <U> U getObjectFromUiFactory(Class<U> clazz, Object owner) {
Map<Method, UiFactory> map = GwtReflectionUtils.getAnnotatedMethod(owner.getClass(), UiFactory.class);
List<Method> compatibleFactories = new ArrayList<Method>();
for (Method factoryMethod : map.keySet()) {
if (clazz.isAssignableFrom(factoryMethod.getReturnType())) {
compatibleFactories.add(factoryMethod);
}
}
switch(compatibleFactories.size()) {
case 0:
return null;
case 1:
return (U) GwtReflectionUtils.callPrivateMethod(owner, compatibleFactories.get(0));
default:
throw new GwtTestUiBinderException("Duplicate factory in class '" + owner.getClass().getName() + " for type '" + clazz.getName() + "'");
}
}
use of com.googlecode.gwt.test.exceptions.GwtTestUiBinderException in project gwt-test-utils by gwt-test-utils.
the class UiResourceManager method registerResource.
/**
* Register a new resource which should correspond to a resource tag in the .ui.xml file.
*
* @param localName The type of the resource ('with', 'style', 'image' or 'data')
* @param attributes Map of attributes parsed from the tag
* @param parentTag The parent tag if any
* @param owner The {@link UiBinder} owner widget, which calls the
* {@link UiBinder#createAndBindUi(Object)} method to initialize itself.
* @return The UiBinderTag which wraps the Resource instance.
* @throws GwtTestUiBinderException If the localName is not managed or if the alias is already
* binded to another Resource object
*/
UiTag<?> registerResource(String localName, Map<String, Object> attributes, UiTag<?> parentTag, Object owner) throws GwtTestUiBinderException {
String alias = getResourceAlias(localName, attributes);
if (resources.containsKey(alias)) {
throw new GwtTestUiBinderException("Two inner resources '" + alias + " are declared in " + owner.getClass().getSimpleName() + ".ui.xml. You should add a 'field' attribute to one of them");
}
Class<?> type = getResourceType(alias, localName, attributes);
if ("with".equals(localName)) {
// special resource <ui:with> : the resource can be annotated with
// @UiConstructor, @UiFactory or @UiField(provided=true)
Object resource = UiBinderInstanciator.getInstance(type, attributes, owner);
resources.put(alias, resource);
return new UiWithTag(resource);
}
ResourcePrototypeProxyBuilder builder = ResourcePrototypeProxyBuilder.createBuilder(type, owner.getClass());
// common properties
builder.name(alias);
if ("style".equals(localName)) {
// <ui:style>
return new UiStyleTag(builder, alias, parentTag, owner, resources);
} else if ("image".equals(localName)) {
// <ui:image>
return new UiImgTag(builder, alias, parentTag, owner, resources, attributes);
} else if ("data".equals(localName)) {
// <ui:data>
return new UiDataTag(builder, alias, parentTag, owner, resources, attributes);
} else {
throw new GwtTestUiBinderException("resource <" + localName + "> element is not yet implemented by gwt-test-utils");
}
}
Aggregations