org.loom.addons.confirmation.RequiresConfirmationAnnotationProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of loom-addons Show documentation
Show all versions of loom-addons Show documentation
Uploads all artifacts belonging to configuration ':archives'.
The newest version!
/*
* Copyright 2002-2006 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.loom.addons.confirmation;
import javax.inject.Inject;
import org.apache.commons.lang.StringUtils;
import org.loom.annotation.processor.AbstractAnnotationProcessor;
import org.loom.i18n.MessagesRepositoryFactory;
import org.loom.mapping.Event;
/**
* Process RequiresConfirmation annotations
* @author icoloma
*/
public class RequiresConfirmationAnnotationProcessor extends AbstractAnnotationProcessor {
@Inject
private MessagesRepositoryFactory messagesRepositoryFactory;
private ConfirmationLogger confirmationLogger = new DefaultConfirmationLogger();
@Override
public void process(Event event) {
RequiresConfirmation annotation = event.getJavaMethod().getAnnotation(RequiresConfirmation.class);
if (annotation != null) {
ConfirmationInterceptor interceptor = new ConfirmationInterceptor();
interceptor.setConfirmationLogger(confirmationLogger);
interceptor.setId(annotation.id());
interceptor.setType(annotation.type());
String message = annotation.message();
if (!StringUtils.isEmpty(message)) {
interceptor.setMessage(message);
} else {
message = annotation.id();
}
event.addInterceptor(interceptor);
// add the json keys
messagesRepositoryFactory.addBrowserMessage(message + ".title");
messagesRepositoryFactory.addBrowserMessage(message + ".message");
messagesRepositoryFactory.addBrowserMessage(message + ".accept");
messagesRepositoryFactory.addBrowserMessage(message + ".cancel");
}
}
public void setMessagesRepositoryFactory( MessagesRepositoryFactory messagesRepositoryFactory) {
this.messagesRepositoryFactory = messagesRepositoryFactory;
}
public void setConfirmationLogger(ConfirmationLogger confirmationLogger) {
this.confirmationLogger = confirmationLogger;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy