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);
}
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());
}
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);
}
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();
}
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);
}
}
Aggregations