org.apache.shindig.gadgets.features
Class FeatureRegistry

java.lang.Object
  extended by org.apache.shindig.gadgets.features.FeatureRegistry

public class FeatureRegistry
extends Object

Mechanism for loading feature.xml files from a location keyed by a String. That String might be the location of a text file which in turn contains other feature file locations; a directory; or a feature.xml file itself.


Field Summary
static String FILE_SCHEME
           
static String RESOURCE_SCHEME
           
 
Constructor Summary
FeatureRegistry(FeatureResourceLoader resourceLoader, List<String> features)
           
 
Method Summary
 Set<String> getAllFeatureNames()
          Helper method, returns all known feature names.
 List<FeatureResource> getAllFeatures()
          Returns all known FeatureResources in dependency order, as described in getFeatureResources.
 List<FeatureResource> getFeatureResources(GadgetContext ctx, Collection<String> needed, List<String> unsupported)
          Helper method retrieving feature resources, including transitive dependencies.
 List<FeatureResource> getFeatureResources(GadgetContext ctx, Collection<String> needed, List<String> unsupported, boolean transitive)
          For the given list of needed features, retrieves all the FeatureResource objects that contain their content and, if requested, that of their transitive dependencies.
 List<String> getFeatures(Collection<String> needed)
          Calculates and returns a dependency-ordered (as in getFeatureResources) list of features included directly or transitively from the specified list of needed features.
protected  void loadFeature(Uri parent, String xml, Map<String,org.apache.shindig.gadgets.features.FeatureRegistry.FeatureNode> featureMapBuilder)
          Method that loads gadget features.
protected  com.google.common.collect.ImmutableMap<String,org.apache.shindig.gadgets.features.FeatureRegistry.FeatureNode> register(List<String> resourceList)
          Reads and registers all of the features in the directory, or the file, specified by the given resourceKey.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_SCHEME

public static final String RESOURCE_SCHEME
See Also:
Constant Field Values

FILE_SCHEME

public static final String FILE_SCHEME
See Also:
Constant Field Values
Constructor Detail

FeatureRegistry

@Inject
public FeatureRegistry(FeatureResourceLoader resourceLoader,
                              List<String> features)
                throws GadgetException
Parameters:
resourceLoader -
featuresoo -
Throws:
GadgetException
Method Detail

register

protected com.google.common.collect.ImmutableMap<String,org.apache.shindig.gadgets.features.FeatureRegistry.FeatureNode> register(List<String> resourceList)
                                                                                                                           throws GadgetException
Reads and registers all of the features in the directory, or the file, specified by the given resourceKey. Invalid features or invalid paths will yield a GadgetException. All features registered by this method must be valid (well-formed XML, resource references all return successfully), and each "batch" of registered features must be able to be assimilated into the current features tree in a valid fashion. That is, their dependencies must all be valid features as well, and the dependency tree must not contain circular dependencies.

Parameters:
resourceList - The files or directories to load the feature from. If feature.xml is passed in directly, it will be loaded as a single feature. If a directory is passed, any features in that directory (recursively) will be loaded. If res://*.txt or res:*.txt is passed, we will look for named resources in the text file. If path is prefixed with res:// or res:, the file is treated as a resource, and all references are assumed to be resources as well. Multiple locations may be specified by separating them with a comma.
Throws:
GadgetException - If any of the files can't be read, are malformed, or invalid.

getFeatureResources

public List<FeatureResource> getFeatureResources(GadgetContext ctx,
                                                 Collection<String> needed,
                                                 List<String> unsupported,
                                                 boolean transitive)
For the given list of needed features, retrieves all the FeatureResource objects that contain their content and, if requested, that of their transitive dependencies. Resources are returned in order of their place in the dependency tree, with "bottom"/ depended-on resources returned before those that depend on them. Resource objects within a given feature are returned in the order specified in their corresponding feature.xml file. In the case of a dependency tree "tie" eg. A depends on [B, C], B and C depend on D - resources are returned in the dependency order specified in feature.xml. Fills the "unsupported" list, if provided, with unknown features in the needed list.

Parameters:
ctx - Context for the request.
needed - List of all needed features.
unsupported - If non-null, a List populated with unknown features from the needed list.
Returns:
List of FeatureResources that may be used to render the needed features.
Throws:
GadgetException

getFeatureResources

public List<FeatureResource> getFeatureResources(GadgetContext ctx,
                                                 Collection<String> needed,
                                                 List<String> unsupported)
Helper method retrieving feature resources, including transitive dependencies.

Parameters:
ctx - Context for the request.
needed - List of all needed features.
unsupported - If non-null, a List populated with unknown features from the needed list.
Returns:
List of FeatureResources that may be used to render the needed features.

getAllFeatures

public List<FeatureResource> getAllFeatures()
Returns all known FeatureResources in dependency order, as described in getFeatureResources. Returns only GADGET-context resources. This is a convenience method largely for calculating JS checksum.

Returns:
List of all known (RenderingContext.GADGET) FeatureResources.

getFeatures

public List<String> getFeatures(Collection<String> needed)
Calculates and returns a dependency-ordered (as in getFeatureResources) list of features included directly or transitively from the specified list of needed features. This API ignores any unknown features among the needed list.

Parameters:
needed - List of features for which to obtain an ordered dep list.
Returns:
Ordered list of feature names, as described.

getAllFeatureNames

public Set<String> getAllFeatureNames()
Helper method, returns all known feature names.

Returns:
All known feature names.

loadFeature

protected void loadFeature(Uri parent,
                           String xml,
                           Map<String,org.apache.shindig.gadgets.features.FeatureRegistry.FeatureNode> featureMapBuilder)
                    throws GadgetException
Method that loads gadget features.

Parameters:
parent - uri of parent
xml - xml to parse
Throws:
GadgetException


Copyright © 2007-2012. All Rights Reserved.