blob: 6add410a77a35e24b9c04d1fb3a9a7789de6680a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2006 Oracle Corporation.
* 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:
* Cameron Bateman/Oracle - initial API and implementation
*
********************************************************************************/
package org.eclipse.jst.jsf.designtime.context;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jst.jsf.common.JSFCommonPlugin;
import org.eclipse.jst.jsf.context.symbol.ISymbol;
import org.eclipse.jst.jsf.context.symbol.source.ISymbolConstants;
import org.eclipse.jst.jsf.context.symbol.source.ISymbolSourceProvider;
import org.eclipse.jst.jsf.context.symbol.source.ISymbolSourceProviderFactory;
/**
* A designtime proxy for the Faces ExternalContext
*
* Clients may sub-class.
*
* @author cbateman
*
*/
public class DTJSPExternalContext extends AbstractDTExternalContext
{
/**
*
*/
private final IFile _jspFile;
/**
* Construct a default external context
*
* @param jspFile
*/
protected DTJSPExternalContext(final IAdaptable jspFile)
{
if (jspFile instanceof IFile)
{
_jspFile = (IFile) jspFile;
}
else if (jspFile != null)
{
IFile file = (IFile) jspFile.getAdapter(IFile.class);
if (file != null)
{
_jspFile = file;
}
else
{
_jspFile = null;
throw new AssertionError("jspFile must be adapable to an IFile"); //$NON-NLS-1$
}
}
else
{
_jspFile = null;
throw new AssertionError("jspFile must be adapable to an IFile"); //$NON-NLS-1$
}
}
@Override
protected Map doGetMapForScope(final int scopeMask) {
final Map map = new HashMap();
for (final Iterator it = JSFCommonPlugin.getSymbolSourceProviders().iterator(); it.hasNext();)
{
final ISymbolSourceProviderFactory factory = (ISymbolSourceProviderFactory) it.next();
final ISymbolSourceProvider provider = factory.createInstance(_jspFile.getProject());
final ISymbol[] symbols = provider.getSymbols(_jspFile, scopeMask);
for (int i = 0; i < symbols.length; i++)
{
map.put(symbols[i].getName(), symbols[i]);
}
}
return map;
}
/**
* @param stream
*/
public final void trace(PrintStream stream)
{
String[] scopeNames = {ISymbolConstants.SYMBOL_SCOPE_REQUEST_STRING,
ISymbolConstants.SYMBOL_SCOPE_SESSION_STRING,
ISymbolConstants.SYMBOL_SCOPE_APPLICATION_STRING,
ISymbolConstants.SYMBOL_SCOPE_NONE_STRING
};
Map[] symbolMaps = {getRequestMap(), getSessionMap(), getApplicationMap()};
for (int i = 0; i < scopeNames.length; i++)
{
stream.println("--------------"); //$NON-NLS-1$
stream.println(scopeNames[i]+" Scope:"); //$NON-NLS-1$
stream.println("--------------"); //$NON-NLS-1$
for (final Iterator it = symbolMaps[i].values().iterator(); it.hasNext();)
{
ISymbol symbol = (ISymbol) it.next();
System.out.println(symbol.getName());
}
}
}
}