Package org.springframework.ide.eclipse.beans.ui.search.internal.queries

Source Code of org.springframework.ide.eclipse.beans.ui.search.internal.queries.BeanNameQuery

/*******************************************************************************
* Copyright (c) 2006, 2007 Spring IDE Developers
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Spring IDE Developers - initial API and implementation
*******************************************************************************/
package org.springframework.ide.eclipse.beans.ui.search.internal.queries;

import java.util.regex.Pattern;

import org.eclipse.core.runtime.IProgressMonitor;
import org.springframework.ide.eclipse.beans.core.internal.model.Bean;
import org.springframework.ide.eclipse.beans.core.model.IBean;
import org.springframework.ide.eclipse.beans.ui.search.internal.BeansSearchMessages;
import org.springframework.ide.eclipse.beans.ui.search.internal.BeansSearchScope;
import org.springframework.ide.eclipse.core.MessageUtils;
import org.springframework.ide.eclipse.core.model.IModelElement;

/**
* This {@link ISearchQuery} looks for all {@link IBean}s which ID or alias
* names match a given name.
* @author Torsten Juergeleit
* @author Christian Dupuis
*/
public class BeanNameQuery extends AbstractBeansQuery {

  public BeanNameQuery(BeansSearchScope scope, String pattern,
      boolean isCaseSensitive, boolean isRegexSearch) {
    super(scope, pattern, isCaseSensitive, isRegexSearch);
  }

  public String getLabel() {
    Object[] args = new Object[] { getPattern(),
        getScope().getDescription() };
    return MessageUtils.format(
        BeansSearchMessages.SearchQuery_searchFor_name, args);
  }

  @Override
  protected boolean doesMatch(IModelElement element, Pattern pattern,
      IProgressMonitor monitor) {
    if (element instanceof IBean) {
      Bean bean = (Bean) element;

      // Compare bean name first
      if (pattern.matcher(bean.getElementName()).matches()) {
        return true;
      }

      // Now compare aliases
      String[] aliases = bean.getAliases();
      if (aliases != null) {
        for (String alias : aliases) {
          if (pattern.matcher(alias).matches()) {
            return true;
          }

        }
      }
    }
    return false;
  }
}
TOP

Related Classes of org.springframework.ide.eclipse.beans.ui.search.internal.queries.BeanNameQuery

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.