/*
* 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.common;
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.RootPanelBinding;
import org.gwtoolbox.ioc.core.client.annotation.RootPanelBindingScan;
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.RootPanelBindingDefinition;
import org.gwtoolbox.ioc.core.rebind.processor.AbstractComponentContainerProcessor;
/**
* @author Uri Boness
*/
public class RootPanelBindingProcessor extends AbstractComponentContainerProcessor<RootPanelBindingScan> {
public RootPanelBindingProcessor() {
super(Integer.MAX_VALUE);
}
public void doInit(EasyTreeLogger logger, RootPanelBindingScan RootPanelBindingScan, JClassType containerType, GeneratorContext context)
throws ProcessorInitializationException {
}
public void doProcess(EasyTreeLogger logger, MutableComponentContainerOracle oracle, GeneratorContext context) throws Exception {
for (ComponentDefinition definition : oracle.getComponentDefinitions()) {
JClassType type = definition.getComponentType();
if (logger.debugEnabled()) {
logger.debug("checking component '" + definition.getId() + "' [" + type.getQualifiedSourceName() + "]");
}
if (!type.isAnnotationPresent(RootPanelBinding.class)) {
continue;
}
if (logger.debugEnabled()) {
logger.debug("Processing root binding for component '" + definition.getId() + "'");
}
RootPanelBinding binding = type.getAnnotation(RootPanelBinding.class);
String rootId = binding.elementId();
if ("".equals(rootId)) {
rootId = null;
}
oracle.addRootPanelBindingDefinition(new RootPanelBindingDefinition(rootId, definition.getId(), binding.useRootLayoutPanel()));
}
}
}