Search in sources :

Example 36 with Location

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

the class EmbeddedComponentAssemblerImpl method addMixin.

private void addMixin(String className, String... order) {
    Instantiator mixinInstantiator = instantiatorSource.getInstantiator(className);
    String mixinId = InternalUtils.lastTerm(className);
    if (mixinIdToInstantiator.containsKey(mixinId))
        throw new TapestryException(String.format("Mixins applied to a component must be unique. Mixin '%s' has already been applied.", mixinId), location, null);
    mixinIdToInstantiator.put(mixinId, mixinInstantiator);
    mixinsIdToOrderConstraints.put(mixinId, order);
}
Also used : Instantiator(org.apache.tapestry5.internal.services.Instantiator) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 37 with Location

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

the class EmbeddedComponentAssemblerImpl method createParameterBinderFromQualifiedParameterName.

private ParameterBinder createParameterBinderFromQualifiedParameterName(String qualifiedParameterName, String mixinId, String parameterName) {
    if (mixinId.equalsIgnoreCase(componentPsuedoMixinId)) {
        return createParameterBinderForComponent(qualifiedParameterName, parameterName);
    }
    if (!mixinIdToInstantiator.containsKey(mixinId)) {
        throw new TapestryException(String.format("Mixin id for parameter '%s' not found. Attached mixins: %s.", qualifiedParameterName, InternalUtils.joinSorted(mixinIdToInstantiator.keySet())), location, null);
    }
    ParameterBinder binder = parameterNameToBinder.get(qualifiedParameterName);
    if (binder != null) {
        return binder;
    }
    // Ok, so perhaps this is a qualified name for an informal parameter of the mixin.
    Instantiator instantiator = mixinIdToInstantiator.get(mixinId);
    assert instantiator != null;
    return bindInformalParameter(qualifiedParameterName, mixinId, parameterName, instantiator.getModel());
}
Also used : Instantiator(org.apache.tapestry5.internal.services.Instantiator) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 38 with Location

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

the class PageLoaderImpl method connectInheritedParameter.

private void connectInheritedParameter(ComponentPageElement container, ComponentPageElement embedded, String parameterName, String containerParameterName) {
    // TODO: This assumes that the two parameters are both on the core component and not on
    // a mixin. I think this could be improved with more static analysis.
    Binding containerBinding = container.getBinding(containerParameterName);
    if (containerBinding == null)
        return;
    // This helps with debugging, and re-orients any thrown exceptions
    // to the location of the inherited binding, rather than the container component's
    // binding.
    // Binding inherited = new InheritedBinding(description, containerBinding, embedded.getLocation());
    embedded.bindParameter(parameterName, containerBinding);
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding)

Example 39 with Location

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

the class LocationRenderer method render.

public void render(Location location, MarkupWriter writer) {
    writer.write(location.toString());
    /**
     * If the full details were already rendered this request, then skip the rest.
     */
    if (rendered.contains(location))
        return;
    rendered.add(location);
    Resource r = location.getResource();
    int line = location.getLine();
    if (line <= 0)
        return;
    if (!r.exists())
        return;
    int start = line - RANGE;
    int end = line + RANGE;
    writer.element("table", "class", "t-location-outer");
    LineNumberReader reader = null;
    try {
        InputStream is = r.openStream();
        InputStreamReader isr = new InputStreamReader(is);
        reader = new LineNumberReader(new BufferedReader(isr));
        while (true) {
            String input = reader.readLine();
            if (input == null)
                break;
            int current = reader.getLineNumber();
            if (current < start)
                continue;
            if (current > end)
                break;
            writer.element("tr");
            writer.element("td", "class", "t-location-line");
            if (line == current) {
                writer.getElement().attribute("class", "t-location-current");
            }
            writer.write(Integer.toString(current));
            writer.end();
            Element td = writer.element("td", "class", "t-location-content");
            if (line == current) {
                td.attribute("class", "t-location-current");
            }
            if (start == current) {
                td.attribute("class", "t-location-content-first");
            }
            writer.write(input);
            writer.end();
            // tr
            writer.end();
        }
        reader.close();
        reader = null;
    } catch (IOException ex) {
        writer.write(ex.toString());
    } finally {
        InternalUtils.close(reader);
    }
    // div
    writer.end();
}
Also used : Element(org.apache.tapestry5.dom.Element) Resource(org.apache.tapestry5.commons.Resource)

Example 40 with Location

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

the class BeanModelSourceImpl method orderProperties.

/**
 * @param classAdapter  defines the bean that contains the properties
 * @param propertyNames the initial set of property names, which will be rebuilt in the correct order
 */
private void orderProperties(ClassPropertyAdapter classAdapter, List<String> propertyNames) {
    List<PropertyOrder> properties = CollectionFactory.newList();
    for (String name : propertyNames) {
        PropertyAdapter pa = classAdapter.getPropertyAdapter(name);
        Method readMethod = pa.getReadMethod();
        Location location = readMethod == null ? null : proxyFactory.getMethodLocation(readMethod);
        int line = location == null ? -1 : location.getLine();
        properties.add(new PropertyOrder(name, computeDepth(pa), line));
    }
    Collections.sort(properties);
    propertyNames.clear();
    for (PropertyOrder po : properties) {
        propertyNames.add(po.propertyName);
    }
}
Also used : ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) PropertyAdapter(org.apache.tapestry5.commons.services.PropertyAdapter) Method(java.lang.reflect.Method) Location(org.apache.tapestry5.commons.Location)

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