juzu.impl.plugin.ajax.AjaxMetaModelPlugin Maven / Gradle / Ivy
/*
* Copyright 2013 eXo Platform SAS
*
* 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 juzu.impl.plugin.ajax;
import juzu.impl.plugin.application.metamodel.ApplicationMetaModel;
import juzu.impl.plugin.application.metamodel.ApplicationMetaModelPlugin;
import juzu.impl.metamodel.AnnotationKey;
import juzu.impl.metamodel.AnnotationState;
import juzu.impl.compiler.ElementHandle;
import juzu.impl.common.JSON;
import juzu.impl.compiler.ProcessingContext;
import juzu.plugin.ajax.Ajax;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
/** @author Julien Viet */
public class AjaxMetaModelPlugin extends ApplicationMetaModelPlugin {
/** . */
private final HashMap enabledMap = new HashMap();
public AjaxMetaModelPlugin() {
super("ajax");
}
@Override
public Set> init(ProcessingContext env) {
return Collections.>singleton(Ajax.class);
}
@Override
public void processAnnotationAdded(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState added) {
ElementHandle.Package handle = metaModel.getHandle();
enabledMap.put(handle, true);
}
@Override
public void processAnnotationRemoved(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState removed) {
ElementHandle.Package handle = metaModel.getHandle();
enabledMap.remove(handle);
}
@Override
public void init(ApplicationMetaModel application) {
}
@Override
public void destroy(ApplicationMetaModel application) {
enabledMap.remove(application.getHandle());
}
@Override
public JSON getDescriptor(ApplicationMetaModel application) {
ElementHandle.Package handle = application.getHandle();
Boolean enabled = enabledMap.get(handle);
return enabled != null && enabled ? new JSON() : null;
}
}