Skip to main content
summaryrefslogblamecommitdiffstats
blob: cb32a9531c01c7edacf5a27f7d9599cb93b4d7e9 (plain) (tree)



















































                                                                                                                                
/******************************************************************************
 * Copyright (c) 2008 BEA Systems, Inc and others.
 * 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:
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
 *    Oracle - copied and modified from org.eclipse.wst.common.project.facet.core.internal.FacetedProjectPropertyTester
 ******************************************************************************/
package org.eclipse.jpt.core.internal;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;

public class JpaTester extends PropertyTester {
	
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
		if (!property.equals("projectFacet")) { //$NON-NLS-1$
			return false;
		}
        if (receiver instanceof IJavaElement) {
        	IProject project = ((IJavaElement) receiver).getResource().getProject();        	
            if (project != null) {

                String val = (String) expectedValue;
                int colon = val.indexOf( ':' );                
                String facetID;
                String facetVer;
                if( colon == -1 || colon == val.length() - 1 )  {
                    facetID = val;
                    facetVer = null;
                } else {
                    facetID = val.substring( 0, colon );
                    facetVer = val.substring( colon + 1 );
                }            	
            	try {            		
            		return FacetedProjectFramework.hasProjectFacet( project, facetID, facetVer );            		
				} catch (CoreException e) {
					JptCorePlugin.log(e.getStatus());
					return false;
				}
            }
        }     
        return false;
	}		
}

Back to the top