FileDocCategorySizeDatePackage
ProjectCallback.javaAPI DocAndroid 1.5 API5961Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.layout

ProjectCallback

public final class ProjectCallback extends Object implements com.android.layoutlib.api.IProjectCallback
Loader for Android Project class in order to use them in the layout editor.

Fields Summary
private final HashMap
mLoadedClasses
private final org.eclipse.core.resources.IProject
mProject
private final ClassLoader
mParentClassLoader
private final com.android.ide.eclipse.editors.resources.manager.ProjectResources
mProjectRes
private boolean
mUsed
private String
mNamespace
Constructors Summary
ProjectCallback(ClassLoader classLoader, com.android.ide.eclipse.editors.resources.manager.ProjectResources projectRes, org.eclipse.core.resources.IProject project)

    
          
        mParentClassLoader = classLoader;
        mProjectRes = projectRes;
        mProject = project;
    
Methods Summary
public java.lang.StringgetNamespace()
Returns the namespace for the project. The namespace contains a standard part + the application package.

return
The package namespace of the project or null in case of error.

        if (mNamespace == null) {
            IFile manifestFile = AndroidManifestParser.getManifest(mProject);
            try {
                AndroidManifestParser data = AndroidManifestParser.parseForData(manifestFile);
                String javaPackage = data.getPackage();
                mNamespace = String.format(AndroidConstants.NS_CUSTOM_RESOURCES, javaPackage);
            } catch (CoreException e) {
            }
        }

        return mNamespace;
    
public java.lang.IntegergetResourceValue(java.lang.String type, java.lang.String name)

        if (mProjectRes != null) {
            return mProjectRes.getResourceValue(type, name);
        }
        
        return null;
    
private java.lang.ObjectinstantiateClass(java.lang.Class clazz, java.lang.Class[] constructorSignature, java.lang.Object[] constructorParameters)
Instantiate a class object, using a specific constructor and parameters.

param
clazz the class to instantiate
param
constructorSignature the signature of the constructor to use
param
constructorParameters the parameters to use in the constructor.
return
A new class object, created using a specific constructor and parameters.
throws
Exception

        Constructor<?> constructor = clazz.getConstructor(constructorSignature);
        constructor.setAccessible(true);
        return constructor.newInstance(constructorParameters);
    
booleanisUsed()
Returns whether the loader has received requests to load custom views.

This allows to efficiently only recreate when needed upon code change in the project.

        return mUsed;
    
public java.lang.ObjectloadView(java.lang.String className, java.lang.Class[] constructorSignature, java.lang.Object[] constructorParameters)
{@inheritDoc} This implementation goes through the output directory of the Eclipse project and loads the .class file directly.

        
        // look for a cached version
        Class<?> clazz = mLoadedClasses.get(className);
        if (clazz != null) {
            return instantiateClass(clazz, constructorSignature, constructorParameters);
        }
        
        // load the class.
        ProjectClassLoader loader = new ProjectClassLoader(mParentClassLoader, mProject);
        try {
            clazz = loader.loadClass(className);
            
            if (clazz != null) {
                mUsed = true;
                mLoadedClasses.put(className, clazz);
                return instantiateClass(clazz, constructorSignature, constructorParameters);
            }
        } catch (Error e) {
            // Log this error with the class name we're trying to load and abort.
            AdtPlugin.log(e, "ProjectCallback.loadView failed to find class %1$s", className); //$NON-NLS-1$
        }
        
        return null;
    
public java.lang.String[]resolveResourceValue(int id)

        if (mProjectRes != null) {
            return mProjectRes.resolveResourceValue(id);
        }

        return null;
    
public java.lang.StringresolveResourceValue(int[] id)

        if (mProjectRes != null) {
            return mProjectRes.resolveResourceValue(id);
        }
        
        return null;