io.quarkus.launcher.shaded.org.eclipse.sisu.plexus.RequirementImpl Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2010, 2015 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Stuart McCulloch (Sonatype, Inc.) - initial API and implementation
*******************************************************************************/
package org.eclipse.sisu.plexus;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.List;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.sisu.inject.DeferredClass;
import org.eclipse.sisu.space.LoadedClass;
/**
* Runtime implementation of Plexus @{@link Requirement} annotation.
*/
public final class RequirementImpl
implements Requirement
{
// ----------------------------------------------------------------------
// Implementation fields
// ----------------------------------------------------------------------
private final DeferredClass role;
private final boolean optional;
private final String hint;
private final String[] hints;
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
public RequirementImpl( final DeferredClass role, final boolean optional, final List hints )
{
if ( null == role || null == hints || hints.contains( null ) )
{
throw new IllegalArgumentException( "@Requirement cannot contain null values" );
}
this.role = role;
this.optional = optional;
final int length = hints.size();
if ( length == 0 )
{
hint = "";
this.hints = Hints.NO_HINTS;
}
else if ( length == 1 )
{
hint = hints.get( 0 );
this.hints = Hints.NO_HINTS;
}
else
{
hint = "";
this.hints = hints.toArray( new String[length] );
}
}
/**
* For testing purposes only.
*/
@Deprecated
public RequirementImpl( final Class role, final boolean optional, final String... hints )
{
this( new LoadedClass