public void afterPropertiesSet()

in gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/CommandBundle.java [104:166]


    public void afterPropertiesSet() throws Exception {
        log.debug("Initializing command bundle");
        if (commandRegistry == null) {
            String[] names = applicationContext.getBeanNamesForType(CommandRegistry.class);
            if (names.length == 1) {
                commandRegistry = (CommandRegistry) applicationContext.getBean(names[0], CommandRegistry.class);
            }
        }
        if (aliasRegistry == null) {
            String[] names = applicationContext.getBeanNamesForType(AliasRegistry.class);
            if (names.length == 1) {
                aliasRegistry = (AliasRegistry) applicationContext.getBean(names[0], AliasRegistry.class);
            }
        }
        if (commandRegistry != null && aliasRegistry != null) {
            log.debug("Command bundle is using the auto wired command/alias registry");
            if (commands != null) {
                for (Command command : commands) {
                    log.debug("Registering command: {}", command.getLocation());
                    commandRegistry.registerCommand(command);
                }
            }
            if (links != null) {
                for (Link link : links) {
                    log.debug("Registering link: {}", link.getName());
                    LinkCommand cmd = new LinkCommand(commandRegistry, link.getTarget());
                    cmd.setLocation(new CommandLocationImpl(link.getName()));
                    commandRegistry.registerCommand(cmd);
                }
            }
            if (aliases != null) {
                for (Alias alias : aliases) {
                    log.debug("Registering alias: {}", alias.getName());
                    aliasRegistry.registerAlias(alias.getName(), alias.getAlias());
                }
            }
        } else if (bundleContext != null) {
            log.debug("Command bundle is using the OSGi registry");
            if (commands != null) {
                for (Command command : commands) {
                    log.debug("Registering command: {}", command.getLocation());
                    Dictionary props = new Properties();
                    props.put(OsgiCommandRegistry.NAME, command.getLocation().getFullPath());
                    registrations.add(bundleContext.registerService(Command.class.getName(), command, props));
                }
            }
            if (links != null) {
                for (Link link : links) {
                    log.debug("Registering link: {}", link.getName());
                    registrations.add(bundleContext.registerService(Link.class.getName(), link, new Properties()));
                }
            }
            if (aliases != null) {
                for (Alias alias : aliases) {
                    log.debug("Registering alias: {}", alias.getName());
                    Dictionary props = new Properties();
                    registrations.add(bundleContext.registerService(Alias.class.getName(), alias, new Properties()));
                }
            }
        } else {
            throw new Exception("Command bundle should be wired to the command/alias registry or be used in an OSGi context");
        }
    }