Skip to main content
summaryrefslogtreecommitdiffstats
blob: fdefe462ffdf72bc0ec2a243de9f955d053525ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation 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:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20071120   196997 pmoogk@ca.ibm.com - Peter Moogk
 * 20071219   213447 pmoogk@ca.ibm.com - Peter Moogk
 *******************************************************************************/
package org.eclipse.wst.ws.internal.preferences;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;

public class WSDLFilePropertyTester extends PropertyTester
{
  public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
  {
    boolean result = false;
    
    if( receiver instanceof IContainer)
    {
      result = hasWSDLfile( (IContainer) receiver );
    }
    
    return result;
  }
  
  private boolean hasWSDLfile( IContainer container )
  {
    boolean result   = false;
    
    try
    {
      IResource[] children = container.members();
      
      for( IResource child : children )
      {
        if( child instanceof IContainer )
        {
          result = hasWSDLfile( (IContainer) child );
          
        }
        else if( child instanceof IFile )
        {
          String extension = child.getFileExtension();
          
          if( extension != null )
          {
            result = extension.equals( "wsdl" );
          }
        }
        
        // If we found a single wsdl file we will break out of the loop.
        if( result ) break;
      }    
    }
    catch( CoreException exc )
    {
      // Ignore exception and return false.  
    }
    
    return result;
  }
}

Back to the top