Package it.hotel.aspects

Source Code of it.hotel.aspects.RemoveMultiLingualInterceptor

/*
Copyright (C) European Community 2008 - Licensed under the EUPL V.1.0 (http://ec.europa.eu/idabc/en/document/6523)
*/

package it.hotel.aspects;

import it.hotel.controller.locale.ILocaleContainer;
import it.hotel.model.abstrakt.manager.IhManager;
import it.hotel.model.label.Label;
import it.hotel.model.label.manager.ILabelManager;

import java.util.HashMap;
import java.util.List;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
*
*
*/
public class RemoveMultiLingualInterceptor implements MethodInterceptor{

  protected ILabelManager labelManager;
  protected ILocaleContainer localeContainer;
 
  public ILocaleContainer getLocaleContainer() {
    return localeContainer;
  }

  public void setLocaleContainer(ILocaleContainer localeContainer) {
    this.localeContainer = localeContainer;
  }

  public ILabelManager getLabelManager() {
    return labelManager;
  }

  public void setLabelManager(ILabelManager labelManager) {
    this.labelManager = labelManager;
  }
   
  /**
   * @throws
   * @return
   */
  @Override
  public Object invoke(MethodInvocation invocation) throws Throwable {
    // TODO Auto-generated method stub
    Object rval = null;
    Object[] obj = invocation.getArguments();
    Object targetManager = invocation.getThis();
   
    Object model = null;
    Integer i = new Integer(1);
   
    if (obj[0].getClass().isInstance(i)){
      Integer modelId = (Integer) obj[0];
      IhManager manager = (IhManager) targetManager;
      model = (Object) manager.get(modelId);
    }
    else {
      model = (Object) obj[0];
    }
   
      try {
        rval = invocation.proceed();
        if (model != null){
          List<String> localisedFieldNames = MultiLingualInterceptor.getLocalisedFields(model);
         
          for (String field: localisedFieldNames){
            String modelName = model.getClass().getSimpleName();
            String descriptor = modelName + "." + field;
            int id = MultiLingualInterceptor.getIdFromModel(model);
           
            String locale = localeContainer.getLocale();
            HashMap<String,Label> list = labelManager.getLabels(id, descriptor);
           
            for (Label label : list.values()){
              labelManager.remove(label);
            }
          }
        }
       
      } catch (Throwable t) {
       
      }
    return null;
  }

}
TOP

Related Classes of it.hotel.aspects.RemoveMultiLingualInterceptor

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.