Search in sources :

Example 41 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class BeanModelSourceImpl method create.

public <T> BeanModel<T> create(Class<T> beanClass, boolean filterReadOnlyProperties, Messages messages) {
    assert beanClass != null;
    assert messages != null;
    ClassPropertyAdapter adapter = propertyAccess.getAdapter(beanClass);
    BeanModel<T> model = new BeanModelImpl<T>(beanClass, propertyConduitSource, typeCoercer, messages, locator);
    for (final String propertyName : adapter.getPropertyNames()) {
        PropertyAdapter pa = adapter.getPropertyAdapter(propertyName);
        if (!pa.isRead()) {
            continue;
        }
        if (isStaticFieldProperty(pa)) {
            continue;
        }
        if (pa.getAnnotation(NonVisual.class) != null) {
            continue;
        }
        if (filterReadOnlyProperties && !pa.isUpdate()) {
            continue;
        }
        final String dataType = dataTypeAnalyzer.identifyDataType(pa);
        if (dataType == null) {
            continue;
        }
        model.add(propertyName).dataType(dataType);
    }
    // First, order the properties based on the location of the getter method
    // within the class.
    List<String> propertyNames = model.getPropertyNames();
    orderProperties(adapter, propertyNames);
    model.reorder(propertyNames.toArray(new String[propertyNames.size()]));
    // Next, check for an annotation with specific ordering information.
    ReorderProperties reorderAnnotation = beanClass.getAnnotation(ReorderProperties.class);
    if (reorderAnnotation != null) {
        BeanModelUtils.reorder(model, reorderAnnotation.value());
    }
    return model;
}
Also used : BeanModelImpl(org.apache.tapestry5.beanmodel.internal.beanmodel.BeanModelImpl) NonVisual(org.apache.tapestry5.beaneditor.NonVisual) ReorderProperties(org.apache.tapestry5.beaneditor.ReorderProperties) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) PropertyAdapter(org.apache.tapestry5.commons.services.PropertyAdapter)

Example 42 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class ValidateBindingFactory method newBinding.

public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) {
    Object fieldAsObject = component.getComponent();
    if (!Field.class.isInstance(fieldAsObject))
        throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null);
    final Field field = (Field) fieldAsObject;
    return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) {

        public Object get() {
            return fieldValidatorSource.createValidators(field, expression);
        }
    };
}
Also used : Field(org.apache.tapestry5.Field) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 43 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class DynamicTemplateSaxParser method block.

private DynamicTemplateElement block(final String blockId) {
    Location location = getLocation();
    removeContent();
    return createBlockElement(blockId, location);
}
Also used : Location(org.apache.tapestry5.commons.Location)

Example 44 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class DynamicTemplateSaxParser method createBlockElement.

private static DynamicTemplateElement createBlockElement(final String blockId, final Location location) {
    return new DynamicTemplateElement() {

        public void render(MarkupWriter writer, RenderQueue queue, DynamicDelegate delegate) {
            try {
                Block block = delegate.getBlock(blockId);
                queue.push((RenderCommand) block);
            } catch (Exception ex) {
                throw new TapestryException(String.format("Exception rendering block '%s' as part of dynamic template: %s", blockId, ExceptionUtils.toMessage(ex)), location, ex);
            }
        }
    };
}
Also used : RenderQueue(org.apache.tapestry5.runtime.RenderQueue) Block(org.apache.tapestry5.Block) DynamicDelegate(org.apache.tapestry5.services.dynamic.DynamicDelegate) MarkupWriter(org.apache.tapestry5.MarkupWriter) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 45 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PageElementFactoryImplTest method attribute.

@Test
public void attribute() {
    TypeCoercer typeCoercer = mockTypeCoercer();
    BindingSource bindingSource = mockBindingSource();
    MarkupWriter writer = new MarkupWriterImpl(xmlModel);
    Location l = mockLocation();
    RenderQueue queue = mockRenderQueue();
    replay();
    PageElementFactory factory = new PageElementFactoryImpl(typeCoercer, bindingSource);
    AttributeToken token = new AttributeToken(null, "name", "value", l);
    RenderCommand element = factory.newAttributeElement(null, token);
    writer.element("root");
    element.render(writer, queue);
    verify();
    assertEquals(writer.toString(), "<?xml version=\"1.0\"?>\n<root name=\"value\"/>");
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) BindingSource(org.apache.tapestry5.services.BindingSource) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) RenderQueue(org.apache.tapestry5.runtime.RenderQueue) AttributeToken(org.apache.tapestry5.internal.parser.AttributeToken) MarkupWriter(org.apache.tapestry5.MarkupWriter) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Aggregations

Location (org.apache.tapestry5.commons.Location)51 Test (org.testng.annotations.Test)41 ComponentResources (org.apache.tapestry5.ComponentResources)33 Binding (org.apache.tapestry5.Binding)25 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)21 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 BindingSource (org.apache.tapestry5.services.BindingSource)6 Resource (org.apache.tapestry5.commons.Resource)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 Component (org.apache.tapestry5.runtime.Component)4 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 Environment (org.apache.tapestry5.services.Environment)3 Logger (org.slf4j.Logger)3 Matcher (java.util.regex.Matcher)2 QName (javax.xml.namespace.QName)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2