/**
 * !(#) ResourceVisitorDelegator.java
 * Copyright (c) 2014 DNW Technologies 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:
 *     DNW Technologies - initial API and implementation
 *
 * Create by manbaum since Sep 29, 2014.
 */
package com.dnw.depmap.builder;

import java.util.HashMap;
import java.util.Map;

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

/**
 * Class/Interface ResourceVisitorDelegator.
 * 
 * @author manbaum
 * @since Sep 29, 2014
 */
public class ResourceVisitorDelegator implements IResourceVisitor {

	private final Map<String, IResourceVisitor> map = new HashMap<String, IResourceVisitor>();

	/**
	 * Constructor of SampleResourceVisitor.
	 * 
	 * @author manbaum
	 * @since Sep 29, 2014
	 * 
	 * @param depMapBuilder
	 */
	public ResourceVisitorDelegator() {
		map.put(".java", new JavaFileVisitor());
	}

	/**
	 * Overrider method visit.
	 * 
	 * @author manbaum
	 * @since Sep 29, 2014
	 * 
	 * @param resource
	 * @return
	 * @throws CoreException
	 * 
	 * @see org.eclipse.core.resources.IResourceVisitor#visit(org.eclipse.core.resources.IResource)
	 */
	public boolean visit(IResource resource) throws CoreException {
		IFile file = (IFile) resource.getAdapter(IFile.class);
		if (file != null) {
			IResourceVisitor visitor = map.get(file.getFileExtension());
			if (visitor != null) {
				visitor.visit(file);
			}
		} else if (resource instanceof IContainer) {
			// return true to continue visiting children.
			return true;
		}
		return false;
	}
}
@@ -782,49 +782,257 @@
 %0A * 
-Class/Interface ResourceVisitorDelegator.
+%3Cp%3E%0A * This class implemented can visit resource trees of a Java project.%0A * %3C/p%3E%0A * %3Cp%3E%0A * Usage:%0A * %3C/p%3E%0A * %0A * %3Cpre%3E%0A * ResourceVisitorDelegator visitor = new ResourceVisitorDelegator();%0A * IResource root = ...;%0A * root.accept(visitor);%0A * %3C/pre%3E
 %0A * 
@@ -1268,14 +1268,8 @@
  of 
-Sample
 Reso
@@ -1279,16 +1279,25 @@
 eVisitor
+Delegator
 .%0A%09 * %0A%09
@@ -1459,42 +1459,86 @@
 );%0A%09
-%7D%0A%0A%09/**%0A%09 * Overrider method visit
+%09map.put(%22.xml%22, new XmlFileVisitor());%0A%09%7D%0A%0A%09/**%0A%09 * Visits the given resource
 .%0A%09 
@@ -1617,41 +1617,252 @@
 %09 * 
-@return%0A%09 * @throws CoreException
+           the resource to visit.%0A%09 * @return %3Ccode%3Etrue%3C/code%3E if the resource's members should be visited;%0A%09 *         %3Ccode%3Efalse%3C/code%3E if they should be skipped.%0A%09 * @throws CoreException%0A%09 *             if the visit fails for some reason.
 %0A%09 *
@@ -2109,16 +2109,80 @@
 null) %7B%0A
+%09%09%09String ext = file.getFileExtension();%0A%09%09%09if (ext != null) %7B%0A%09
 %09%09%09IReso
@@ -2215,34 +2215,29 @@
 get(
-file.getFileExtension
+ext.toLowerCase
 ());%0A
+%09
 %09%09%09i
@@ -2254,24 +2254,25 @@
  != null) %7B%0A
+%09
 %09%09%09%09visitor.
@@ -2284,16 +2284,22 @@
 (file);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Support visiting .java & .xml files.