final Element root = parse( handle.extension() );
if( root != null )
{
final NodeList nodes = root.getChildNodes();
final Context context = handle.context();
for( int i = 0, n = nodes.getLength(); i < n; i++ )
{
final Node node = nodes.item( i );
if( node instanceof Element )
{
final Element el = (Element) node;
final String elname = el.getLocalName();
try
{
if( elname.equals( EL_SERVICE ) )
{
final String id = value( el, EL_ID ).required();
final Set<String> contexts = SetFactory.unmodifiable( values( el, EL_CONTEXT ) );
final Set<String> overrides = SetFactory.unmodifiable( values( el, EL_OVERRIDES ) );
final Class<? extends Service> implementation = context.findClass( value( el, EL_IMPLEMENTATION ).required() );
final String conditionClassName = value( el, EL_CONDITION ).optional();
Class<? extends ServiceCondition> condition = null;
if( conditionClassName != null )
{
condition = context.findClass( conditionClassName );
}
if( implementation != null )
{
serviceExtensionsFactory.add( new ServiceExtension( id, implementation, condition, contexts, overrides ) );
}
}
else if( elname.equals( EL_FUNCTION ) )
{
final String name = value( el, EL_NAME ).required().toLowerCase();
final Class<? extends Function> impl = context.findClass( value( el, EL_IMPL ).required() );
final Element signatureElement = element( el, EL_SIGNATURE ).optional();
final List<Class<?>> signature;
if( signatureElement == null )
{
signature = null;
}
else
{
final ListFactory<Class<?>> parameters = ListFactory.start();
for( String string : values( signatureElement, EL_PARAMETER ) )
{
final Class<?> parameter;
try
{
parameter = context.findClass( string );
}
catch( IllegalArgumentException e )
{
throw new InvalidExtensionException();
}