Package org.gwtoolbox.ioc.core.rebind.processor.multicaster

Source Code of org.gwtoolbox.ioc.core.rebind.processor.multicaster.MulticasterProcessor

/*
* Copyright 2002-2008 the original author or authors.
*
* 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.gwtoolbox.ioc.core.rebind.processor.multicaster;

import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.typeinfo.JClassType;
import org.gwtoolbox.commons.generator.rebind.EasyTreeLogger;
import org.gwtoolbox.ioc.core.client.annotation.Multicaster;
import org.gwtoolbox.ioc.core.client.event.ApplicationEventMulticaster;
import org.gwtoolbox.ioc.core.client.event.DefaultApplicationEventMulticaster;
import org.gwtoolbox.ioc.core.rebind.ProcessorInitializationException;
import org.gwtoolbox.ioc.core.rebind.config.ComponentDefinition;
import org.gwtoolbox.ioc.core.rebind.config.MutableComponentContainerOracle;
import org.gwtoolbox.ioc.core.rebind.config.SimpleComponentDefinition;
import org.gwtoolbox.ioc.core.rebind.processor.AbstractComponentContainerProcessor;

/**
* @author Uri Boness
*/
public class MulticasterProcessor extends AbstractComponentContainerProcessor<Multicaster> {

    private final static String DEFAULT_MULTICASTER_ID = "__multicaster__id";

    public MulticasterProcessor() {
        super(Integer.MAX_VALUE-1);
    }

    public void doInit(EasyTreeLogger logger, Multicaster multicaster, JClassType containerType, GeneratorContext context)
            throws ProcessorInitializationException {
    }

    public void doProcess(EasyTreeLogger logger, MutableComponentContainerOracle oracle, GeneratorContext context) throws Exception {
        JClassType multicasterInterface = context.getTypeOracle().findType(ApplicationEventMulticaster.class.getName());
        String componentId = null;
        for (ComponentDefinition definition : oracle.getComponentDefinitions()) {
            JClassType type = definition.getComponentType();
            if (!type.isAssignableTo(multicasterInterface)) {
                continue;
            }
            componentId = definition.getId();
            if (logger.debugEnabled()) {
                logger.debug("Found multicaster component '" + componentId + "'");
            }
            break;
        }

        if (componentId == null) {
            componentId = DEFAULT_MULTICASTER_ID;
            JClassType type = context.getTypeOracle().findType(DefaultApplicationEventMulticaster.class.getName());
            SimpleComponentDefinition definition = new SimpleComponentDefinition(DEFAULT_MULTICASTER_ID, type, true, false, true);
            oracle.registerComponentDefinition(definition);
        }

        oracle.setMulticasterComponentId(componentId);
    }

}
TOP

Related Classes of org.gwtoolbox.ioc.core.rebind.processor.multicaster.MulticasterProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.