FileDocCategorySizeDatePackage
XmlDescriptors.javaAPI DocAndroid 1.5 API14470Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.xml.descriptors

XmlDescriptors

public final class XmlDescriptors extends Object implements com.android.ide.eclipse.editors.descriptors.IDescriptorProvider
Description of the /res/xml structure. Currently supports the and root nodes.

Fields Summary
public static final String
PREF_KEY_ATTR
private com.android.ide.eclipse.editors.descriptors.DocumentDescriptor
mDescriptor
The root document descriptor for both searchable and preferences.
private com.android.ide.eclipse.editors.descriptors.DocumentDescriptor
mSearchDescriptor
The root document descriptor for searchable.
private com.android.ide.eclipse.editors.descriptors.DocumentDescriptor
mPrefDescriptor
The root document descriptor for preferences.
private com.android.ide.eclipse.editors.descriptors.DocumentDescriptor
mAppWidgetDescriptor
The root document descriptor for widget provider.
Constructors Summary
Methods Summary
private com.android.ide.eclipse.editors.descriptors.ElementDescriptorconvertPref(com.android.ide.eclipse.common.resources.ViewClassInfo info)
Creates an element descriptor from a given {@link ViewClassInfo}.

        String xml_name = info.getShortClassName();
        String tooltip = info.getJavaDoc();
        
        // Process all Preference attributes
        ArrayList<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>();
        DescriptorsUtils.appendAttributes(attributes,
                null,   // elementName
                SdkConstants.NS_RESOURCES,
                info.getAttributes(),
                null,   // requiredAttributes
                null);  // overrides
        
        for (ViewClassInfo link = info.getSuperClass();
                link != null;
                link = link.getSuperClass()) {
            AttributeInfo[] attrList = link.getAttributes();
            if (attrList.length > 0) {
                attributes.add(new SeparatorAttributeDescriptor(
                        String.format("Attributes from %1$s", link.getShortClassName()))); 
                DescriptorsUtils.appendAttributes(attributes,
                        null,   // elementName
                        SdkConstants.NS_RESOURCES,
                        attrList,
                        null,   // requiredAttributes
                        null);  // overrides
            }
        }

        return new ViewElementDescriptor(xml_name,
                xml_name, // ui_name
                info.getCanonicalClassName(),
                tooltip,
                null, // sdk_url
                attributes.toArray(new AttributeDescriptor[attributes.size()]),
                null,
                null, // children
                false /* mandatory */);
    
private com.android.ide.eclipse.editors.descriptors.ElementDescriptorcreateAppWidgetProviderInfo(java.util.Map appWidgetStyleMap, com.android.ide.eclipse.editors.descriptors.XmlnsAttributeDescriptor xmlns)
Returns the new ElementDescriptor for


        if (appWidgetStyleMap == null) {
            return null;
        }
        
        ElementDescriptor appWidget = createElement(appWidgetStyleMap,
                "AppWidgetProviderInfo", //$NON-NLS-1$ styleName
                "appwidget-provider", //$NON-NLS-1$ xmlName
                "AppWidget Provider", // uiName
                null, // sdk url
                xmlns, // extraAttribute
                null, // childrenElements
                false /* mandatory */ );
        return appWidget;
    
private com.android.ide.eclipse.editors.descriptors.ElementDescriptorcreateElement(java.util.Map styleMap, java.lang.String styleName, java.lang.String xmlName, java.lang.String uiName, java.lang.String sdkUrl, com.android.ide.eclipse.editors.descriptors.AttributeDescriptor extraAttribute, com.android.ide.eclipse.editors.descriptors.ElementDescriptor[] childrenElements, boolean mandatory)
Returns a new ElementDescriptor constructed from the information given here and the javadoc & attributes extracted from the style map if any.


        ElementDescriptor element = new ElementDescriptor(xmlName, uiName, null, sdkUrl,
                null, childrenElements, mandatory);

        return updateElement(element, styleMap, styleName, extraAttribute);
    
private com.android.ide.eclipse.editors.descriptors.ElementDescriptorcreatePreference(com.android.ide.eclipse.common.resources.ViewClassInfo[] prefs, com.android.ide.eclipse.common.resources.ViewClassInfo[] prefGroups, com.android.ide.eclipse.editors.descriptors.XmlnsAttributeDescriptor xmlns)
Returns the new ElementDescriptor for


        ArrayList<ElementDescriptor> newPrefs = new ArrayList<ElementDescriptor>();
        if (prefs != null) {
            for (ViewClassInfo info : prefs) {
                ElementDescriptor desc = convertPref(info);
                newPrefs.add(desc);
            }
        }

        ElementDescriptor topPreferences = null;
        
        ArrayList<ElementDescriptor> newGroups = new ArrayList<ElementDescriptor>();
        if (prefGroups != null) {
            for (ViewClassInfo info : prefGroups) {
                ElementDescriptor desc = convertPref(info);
                newGroups.add(desc);
                
                if (info.getCanonicalClassName() == AndroidConstants.CLASS_PREFERENCES) {
                    topPreferences = desc;
                }
            }
        }

        ArrayList<ElementDescriptor> everything = new ArrayList<ElementDescriptor>();
        everything.addAll(newGroups);
        everything.addAll(newPrefs);
        ElementDescriptor[] newArray = everything.toArray(new ElementDescriptor[everything.size()]);

        // Link all groups to everything else here.. recursively
        for (ElementDescriptor layoutDesc : newGroups) {
            layoutDesc.setChildren(newArray);
        }

        // The "top" element to be returned corresponds to the class "Preferences".
        // Its descriptor has already been created. However the root one also needs
        // the hidden xmlns:android definition..
        if (topPreferences != null) {
            AttributeDescriptor[] attrs = topPreferences.getAttributes();
            AttributeDescriptor[] newAttrs = new AttributeDescriptor[attrs.length + 1];
            System.arraycopy(attrs, 0, newAttrs, 0, attrs.length);
            newAttrs[attrs.length] = xmlns;
            return new ElementDescriptor(
                    topPreferences.getXmlName(),
                    topPreferences.getUiName(),
                    topPreferences.getTooltip(),
                    topPreferences.getSdkUrl(),
                    newAttrs,
                    topPreferences.getChildren(),
                    false /* mandatory */);
        } else {
            return null;
        }
    
private com.android.ide.eclipse.editors.descriptors.ElementDescriptorcreateSearchable(java.util.Map searchableStyleMap, com.android.ide.eclipse.editors.descriptors.XmlnsAttributeDescriptor xmlns)
Returns the new ElementDescriptor for


        ElementDescriptor action_key = createElement(searchableStyleMap,
                "SearchableActionKey", //$NON-NLS-1$ styleName
                "actionkey", //$NON-NLS-1$ xmlName
                "Action Key", // uiName
                null, // sdk url
                null, // extraAttribute
                null, // childrenElements
                false /* mandatory */ );

        ElementDescriptor searchable = createElement(searchableStyleMap,
                "Searchable", //$NON-NLS-1$ styleName
                "searchable", //$NON-NLS-1$ xmlName
                "Searchable", // uiName
                null, // sdk url
                xmlns, // extraAttribute
                new ElementDescriptor[] { action_key }, // childrenElements
                false /* mandatory */ );
        return searchable;
    
public com.android.ide.eclipse.editors.descriptors.DocumentDescriptorgetAppWidgetDescriptor()

return
the root descriptor for widget providers.

        return mAppWidgetDescriptor;
    
public com.android.ide.eclipse.editors.descriptors.IDescriptorProvidergetAppWidgetProvider()

        return new IDescriptorProvider() {
            public ElementDescriptor getDescriptor() {
                return mAppWidgetDescriptor;
            }

            public ElementDescriptor[] getRootElementDescriptors() {
                return mAppWidgetDescriptor.getChildren();
            }
        };
    
public com.android.ide.eclipse.editors.descriptors.DocumentDescriptorgetDescriptor()

return
the root descriptor for both searchable and preferences.

 //$NON-NLS-1$ 

              
       
        return mDescriptor;
    
public com.android.ide.eclipse.editors.descriptors.DocumentDescriptorgetPreferencesDescriptor()

return
the root descriptor for preferences.

        return mPrefDescriptor;
    
public com.android.ide.eclipse.editors.descriptors.IDescriptorProvidergetPreferencesProvider()

        return new IDescriptorProvider() {
            public ElementDescriptor getDescriptor() {
                return mPrefDescriptor;
            }

            public ElementDescriptor[] getRootElementDescriptors() {
                return mPrefDescriptor.getChildren();
            }
        };
    
public com.android.ide.eclipse.editors.descriptors.ElementDescriptor[]getRootElementDescriptors()

        return mDescriptor.getChildren();
    
public com.android.ide.eclipse.editors.descriptors.DocumentDescriptorgetSearchableDescriptor()

return
the root descriptor for searchable.

        return mSearchDescriptor;
    
public com.android.ide.eclipse.editors.descriptors.IDescriptorProvidergetSearchableProvider()

        return new IDescriptorProvider() {
            public ElementDescriptor getDescriptor() {
                return mSearchDescriptor;
            }

            public ElementDescriptor[] getRootElementDescriptors() {
                return mSearchDescriptor.getChildren();
            }
        };
    
public synchronized voidupdateDescriptors(java.util.Map searchableStyleMap, java.util.Map appWidgetStyleMap, com.android.ide.eclipse.common.resources.ViewClassInfo[] prefs, com.android.ide.eclipse.common.resources.ViewClassInfo[] prefGroups)
Updates the document descriptor.

It first computes the new children of the descriptor and then updates them all at once.

param
searchableStyleMap The map style=>attributes for from the attrs.xml file
param
appWidgetStyleMap The map style=>attributes for from the attrs.xml file
param
prefs The list of non-group preference descriptions
param
prefGroups The list of preference group descriptions


        XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(
                "android", //$NON-NLS-1$
                SdkConstants.NS_RESOURCES); 

        ElementDescriptor searchable = createSearchable(searchableStyleMap, xmlns);
        ElementDescriptor appWidget = createAppWidgetProviderInfo(appWidgetStyleMap, xmlns);
        ElementDescriptor preferences = createPreference(prefs, prefGroups, xmlns);
        ArrayList<ElementDescriptor> list =  new ArrayList<ElementDescriptor>();
        if (searchable != null) {
            list.add(searchable);
            mSearchDescriptor.setChildren(new ElementDescriptor[]{ searchable });
        }
        if (appWidget != null) {
            list.add(appWidget);
            mAppWidgetDescriptor.setChildren(new ElementDescriptor[]{ appWidget });
        }
        if (preferences != null) {
            list.add(preferences);
            mPrefDescriptor.setChildren(new ElementDescriptor[]{ preferences });
        }

        if (list.size() > 0) {
            mDescriptor.setChildren(list.toArray(new ElementDescriptor[list.size()]));
        }
    
private com.android.ide.eclipse.editors.descriptors.ElementDescriptorupdateElement(com.android.ide.eclipse.editors.descriptors.ElementDescriptor element, java.util.Map styleMap, java.lang.String styleName, com.android.ide.eclipse.editors.descriptors.AttributeDescriptor extraAttribute)
Updates an ElementDescriptor with the javadoc & attributes extracted from the style map if any.

        ArrayList<AttributeDescriptor> descs = new ArrayList<AttributeDescriptor>();

        DeclareStyleableInfo style = styleMap != null ? styleMap.get(styleName) : null;
        if (style != null) {
            DescriptorsUtils.appendAttributes(descs,
                    null,   // elementName
                    SdkConstants.NS_RESOURCES,
                    style.getAttributes(),
                    null,   // requiredAttributes
                    null);  // overrides
            element.setTooltip(style.getJavaDoc());
        }

        if (extraAttribute != null) {
            descs.add(extraAttribute);
        }

        element.setAttributes(descs.toArray(new AttributeDescriptor[descs.size()]));
        return element;