Search in sources :

Example 6 with Mixins

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());
}
Also used : Instantiator(org.apache.tapestry5.internal.services.Instantiator) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 7 with Mixins

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());
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) ComponentLibraryInfo(org.apache.tapestry5.services.ComponentLibraryInfo) TextStreamResponse(org.apache.tapestry5.util.TextStreamResponse) LibraryMapping(org.apache.tapestry5.services.LibraryMapping) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Example 8 with Mixins

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);
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 9 with Mixins

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);
    }
}
Also used : MixinClasses(org.apache.tapestry5.annotations.MixinClasses) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 10 with Mixins

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());
    }
}
Also used : Mixins(org.apache.tapestry5.annotations.Mixins)

Aggregations

TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)7 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)2 Instantiator (org.apache.tapestry5.internal.services.Instantiator)2 Formatter (java.util.Formatter)1 QName (javax.xml.namespace.QName)1 Binding (org.apache.tapestry5.Binding)1 MixinClasses (org.apache.tapestry5.annotations.MixinClasses)1 Mixins (org.apache.tapestry5.annotations.Mixins)1 OnEvent (org.apache.tapestry5.annotations.OnEvent)1 Location (org.apache.tapestry5.commons.Location)1 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)1 Version (org.apache.tapestry5.internal.services.SaxTemplateParser.Version)1 ServiceActivity (org.apache.tapestry5.ioc.services.ServiceActivity)1 ServiceActivityScoreboard (org.apache.tapestry5.ioc.services.ServiceActivityScoreboard)1 Status (org.apache.tapestry5.ioc.services.Status)1 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 ComponentLibraryInfo (org.apache.tapestry5.services.ComponentLibraryInfo)1 LibraryMapping (org.apache.tapestry5.services.LibraryMapping)1 TextStreamResponse (org.apache.tapestry5.util.TextStreamResponse)1