org.glassfish.hk2.inhabitants
Class InhabitantsParser

java.lang.Object
  extended by org.glassfish.hk2.inhabitants.InhabitantsParser
All Implemented Interfaces:
InhabitantStore
Direct Known Subclasses:
OSGiInhabitantsParser

public class InhabitantsParser
extends Object
implements InhabitantStore

Parses /META-INF/inhabitants and populate Habitat.

This class can be subclasses to customize the parsing behavior, which is useful for ignoring some components.

Author:
Kohsuke Kawaguchi, Jerome Dochez

Field Summary
 ServiceLocator serviceLocator
           
 
Constructor Summary
InhabitantsParser(ServiceLocator serviceLocator)
           
 
Method Summary
 void add(Inhabitant<?> i)
          Adds the given inhabitant to the habitat
protected  void add(Inhabitant<?> i, InhabitantParser parser)
          Adds the given inhabitant to the habitat, with all its indices.
 void addIndex(Inhabitant<?> i, String typeName, String name)
          Adds the given inhabitant index to the habitat
 void drop(Class<?> component)
          Tells InhabitantsParser that if it encounters the specified component while parsing inhabitants file, simply drop it and pretend that such an inhabitant had never existed.
 void drop(String fullyQualifiedClassName)
           
protected  boolean isFilteredInhabitant(InhabitantParser inhabitantParser)
          Returns true if this inhabitant should be ignored.
protected  boolean isFilteredInhabitant(String typeName)
          Returns true if this inhabitant should be ignored.
 void parse(Iterable<InhabitantParser> scanner, HK2Loader classLoader)
          Parses the inhabitants file (which is represented by InhabitantsScanner).
static String parseIndex(String v, StringBuilder name)
          Returns the contract name given a raw index entry.
 boolean remove(Inhabitant<?> i)
          Removes an inhabitant
 boolean removeIndex(String index, Object serviceOrInhabitant)
          Removes an Inhabitant index for a specific service or inhabitant
 boolean removeIndex(String index, String name)
          Removes a named Inhabitant index for a specific contract and name
 void replace(Class<?> oldComponent, Class<?> newComponent)
          Tells InhabitantsParser that if it encounters the specified component while parsing inhabitants file, ignore the one in the inhabitants file and instead insert the specified 'new' component.
 void replace(String oldComponentFullyQualifiedClassName, Class<?> newComponent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serviceLocator

public final ServiceLocator serviceLocator
Constructor Detail

InhabitantsParser

public InhabitantsParser(ServiceLocator serviceLocator)
Method Detail

drop

public void drop(Class<?> component)
Tells InhabitantsParser that if it encounters the specified component while parsing inhabitants file, simply drop it and pretend that such an inhabitant had never existed.

This is useful when the application that's hosting an HK2 environment wants to tweak the inhabitant population at sub-module level.


drop

public void drop(String fullyQualifiedClassName)

replace

public void replace(Class<?> oldComponent,
                    Class<?> newComponent)
Tells InhabitantsParser that if it encounters the specified component while parsing inhabitants file, ignore the one in the inhabitants file and instead insert the specified 'new' component.

This is useful when the application that's hosting an HK2 environment wants to tweak the inhabitant population at sub-module level.


replace

public void replace(String oldComponentFullyQualifiedClassName,
                    Class<?> newComponent)

parse

public void parse(Iterable<InhabitantParser> scanner,
                  HK2Loader classLoader)
           throws IOException
Parses the inhabitants file (which is represented by InhabitantsScanner).

All the earlier drop/replace commands will be honored during this process.

Throws:
IOException

isFilteredInhabitant

protected boolean isFilteredInhabitant(InhabitantParser inhabitantParser)
Returns true if this inhabitant should be ignored.

Parameters:
inhabitantParser -
Returns:

isFilteredInhabitant

protected boolean isFilteredInhabitant(String typeName)
Returns true if this inhabitant should be ignored.

Parameters:
typeName -
Returns:

add

protected void add(Inhabitant<?> i,
                   InhabitantParser parser)
Adds the given inhabitant to the habitat, with all its indices.


parseIndex

public static String parseIndex(String v,
                                StringBuilder name)
Returns the contract name given a raw index entry.

Parameters:
v - the raw index entry in the format of contract[:name]
name - a StringBuilder used to optionally store the service name
Returns:
the contract name

add

public void add(Inhabitant<?> i)
Adds the given inhabitant to the habitat

Specified by:
add in interface InhabitantStore
Parameters:
i -

addIndex

public void addIndex(Inhabitant<?> i,
                     String typeName,
                     String name)
Adds the given inhabitant index to the habitat

Specified by:
addIndex in interface InhabitantStore

remove

public boolean remove(Inhabitant<?> i)
Description copied from interface: InhabitantStore
Removes an inhabitant

Specified by:
remove in interface InhabitantStore
Parameters:
i - inhabitant to be removed
Returns:
true if the inhabitant was removed

removeIndex

public boolean removeIndex(String index,
                           String name)
Description copied from interface: InhabitantStore
Removes a named Inhabitant index for a specific contract and name

Specified by:
removeIndex in interface InhabitantStore
Parameters:
index - the contract name
name - the instance name, optionally provided
Returns:
true if the removal was successful

removeIndex

public boolean removeIndex(String index,
                           Object serviceOrInhabitant)
Description copied from interface: InhabitantStore
Removes an Inhabitant index for a specific service or inhabitant

Specified by:
removeIndex in interface InhabitantStore
Parameters:
index - the contract name
serviceOrInhabitant - the service instance, or inhabitant instance
Returns:
true if the removal was successful


Copyright © 2013 Oracle Corporation. All Rights Reserved.