Package org.springframework.roo.felix.pgp

Source Code of org.springframework.roo.felix.pgp.PgpKeyIdConverter

package org.springframework.roo.felix.pgp;

import java.util.List;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.shell.Completion;
import org.springframework.roo.shell.Converter;
import org.springframework.roo.shell.MethodTarget;

/**
* {@link Converter} for {@link PgpKeyId}.
*
* @author Ben Alex
* @since 1.1
*/
@Component
@Service
public class PgpKeyIdConverter implements Converter<PgpKeyId> {

    @Reference private PgpService pgpService;

    public PgpKeyId convertFromText(final String value,
            final Class<?> requiredType, final String optionContext) {
        return new PgpKeyId(value.trim());
    }

    public boolean getAllPossibleValues(final List<Completion> completions,
            final Class<?> requiredType, final String originalUserInput,
            final String optionContext, final MethodTarget target) {
        for (final PgpKeyId candidate : pgpService.getDiscoveredKeyIds()) {
            final String id = candidate.getId();
            if (id.toUpperCase().startsWith(originalUserInput.toUpperCase())) {
                completions.add(new Completion(id));
            }
        }

        return false;
    }

    public boolean supports(final Class<?> requiredType,
            final String optionContext) {
        return PgpKeyId.class.isAssignableFrom(requiredType);
    }
}
TOP

Related Classes of org.springframework.roo.felix.pgp.PgpKeyIdConverter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.