use of org.apache.tapestry5.annotations.Mixins 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.annotations.Mixins in project tapestry-5 by apache.
the class ComponentLibraries method generateJSONDescription.
@OnEvent("json")
Object generateJSONDescription(String libraryName) {
for (LibraryMapping mapping : componentClassResolver.getLibraryMappings()) {
if (libraryName.equalsIgnoreCase(mapping.libraryName)) {
this.libraryMapping = mapping;
break;
}
}
JSONObject object = new JSONObject();
object.put("libraryName", libraryName);
object.put("rootPackage", libraryMapping.getRootPackage());
final ComponentLibraryInfo info = getInfo();
if (info != null) {
JSONObject infoJsonObject = new JSONObject();
putIfNotNull("description", info.getDescription(), infoJsonObject);
putIfNotNull("homepage", info.getHomepageUrl(), infoJsonObject);
putIfNotNull("documentationUrl", info.getDocumentationUrl(), infoJsonObject);
putIfNotNull("javadocUrl", info.getJavadocUrl(), infoJsonObject);
putIfNotNull("groupId", info.getGroupId(), infoJsonObject);
putIfNotNull("artifactId", info.getArtifactId(), infoJsonObject);
putIfNotNull("version", info.getVersion(), infoJsonObject);
putIfNotNull("sourceBrowseUrl", info.getSourceBrowseUrl(), infoJsonObject);
putIfNotNull("sourceRootUrl", info.getSourceRootUrl(), infoJsonObject);
putIfNotNull("issueTrackerUrl", info.getIssueTrackerUrl(), infoJsonObject);
putIfNotNull("dependencyInfoUrl", info.getDependencyManagementInfoUrl(), infoJsonObject);
if (info.getTags() != null) {
for (String tag : info.getTags()) {
infoJsonObject.accumulate("tags", tag);
}
}
object.put("info", infoJsonObject);
}
addClasses("components", filter(componentClassResolver.getComponentNames()), Type.COMPONENT, info, object);
addClasses("pages", filter(componentClassResolver.getPageNames()), Type.PAGE, info, object);
addClasses("mixins", filter(componentClassResolver.getMixinNames()), Type.MIXIN, info, object);
return new TextStreamResponse("text/javascript", object.toString());
}
use of org.apache.tapestry5.annotations.Mixins in project tapestry-5 by apache.
the class BindParameterWorker method createConduit.
private FieldConduit<Object> createConduit(final ComponentResources resources, final String fieldTypeName, final String fieldName, final String[] possibleNames) {
if (!resources.isMixin())
throw new TapestryException(String.format("@BindParameter was used on field '%s' of component class '%s', but @BindParameter should only be used in mixins.", fieldName, resources.getComponentModel().getComponentClassName()), null);
InternalComponentResources containerResources = (InternalComponentResources) resources.getContainerResources();
// Evaluate this early so that we get a fast fail.
String containerParameterName = identifyParameterName(resources, InternalUtils.stripMemberName(fieldName), possibleNames);
Class fieldType = componentClassCache.forName(fieldTypeName);
return new BoundParameterFieldValueConduit(containerParameterName, containerResources, fieldType);
}
use of org.apache.tapestry5.annotations.Mixins in project tapestry-5 by apache.
the class ComponentWorker method addMixinClasses.
private void addMixinClasses(PlasticField field, MutableEmbeddedComponentModel model) {
MixinClasses annotation = field.getAnnotation(MixinClasses.class);
if (annotation == null)
return;
boolean orderEmpty = annotation.order().length == 0;
if (!orderEmpty && annotation.order().length != annotation.value().length)
throw new TapestryException(String.format("%d mixins defined via @MixinClasses on field '%s', but %d ordering constraints \\\n" + " specified (expected 0 or %1$d).", annotation.value().length, field.getName(), annotation.order().length), model, null);
for (int i = 0; i < annotation.value().length; i++) {
String[] constraints = orderEmpty ? CommonsUtils.EMPTY_STRING_ARRAY : TapestryInternalUtils.splitMixinConstraints(annotation.order()[i]);
model.addMixin(annotation.value()[i].getName(), constraints);
}
}
use of org.apache.tapestry5.annotations.Mixins in project tapestry-5 by apache.
the class ComponentWorker method addMixinTypes.
private void addMixinTypes(PlasticField field, MutableEmbeddedComponentModel model) {
Mixins annotation = field.getAnnotation(Mixins.class);
if (annotation == null)
return;
for (String typeName : annotation.value()) {
Orderable<String> typeAndOrder = TapestryInternalUtils.mixinTypeAndOrder(typeName);
String mixinClassName = resolver.resolveMixinTypeToClassName(typeAndOrder.getTarget());
model.addMixin(mixinClassName, typeAndOrder.getConstraints());
}
}
Aggregations