Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2006, 2008, 2009, 2010 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
 // http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry5.internal.transform;
Supports the org.apache.tapestry5.annotations.Mixin annotation, which allows a mixin to be part of the implementation of a component. The annotation is applied to a field, which will become read-only, and contain a reference to the mixin instance.
public class MixinWorker implements ComponentClassTransformWorker
    private final ComponentClassResolver resolver;
    public MixinWorker(final ComponentClassResolver resolver)
    {
        this. = resolver;
    }
    public void transform(ClassTransformation transformationMutableComponentModel model)
    {
        for (TransformField field : transformation.matchFieldsWithAnnotation(Mixin.class))
        {
            replaceFieldWithMixin(modelfield);
        }
    }
    private void replaceFieldWithMixin(MutableComponentModel modelTransformField field)
    {
        Mixin annotation = field.getAnnotation(Mixin.class);
        field.claim(annotation);
        String mixinType = annotation.value();
        String[] order = annotation.order();
        String fieldType = field.getType();
        String mixinClassName = InternalUtils.isBlank(mixinType) ? fieldType : 
                .resolveMixinTypeToClassName(mixinType);
        model.addMixinClassName(mixinClassNameorder);
        replaceFieldAccessWithMixin(fieldmixinClassName);
    }
    private void replaceFieldAccessWithMixin(TransformField fieldString mixinClassName)
    {
        ComponentValueProvider<FieldValueConduitprovider = createMixinFieldProvider(field.getName(), mixinClassName);
        field.replaceAccess(provider);
    }
            final String mixinClassName)
    {
        return new ComponentValueProvider<FieldValueConduit>()
        {
            public FieldValueConduit get(ComponentResources resources)
            {
                final InternalComponentResources icr = (InternalComponentResourcesresources;
                return new ReadOnlyFieldValueConduit(resourcesfieldName)
                {
                    public Object get()
                    {
                        return icr.getMixinByClassName(mixinClassName);
                    }
                };
            }
        };
    }
New to GrepCode? Check out our FAQ X