class CreateIiopListener implements AdminCommand {

    @Override
    public void execute(AdminCommandContext context) {
        final Target targetUtil = services.getService(Target.class ) ;
        final Config config = targetUtil.getConfig(target ) ;
        final ActionReport report = context.getActionReport();

        IiopService iiopService = config.getExtensionByType(IiopService.class);

        // ensure we don't already have one of this name
        // check port uniqueness, only for same address
        for (IiopListener listener : iiopService.getIiopListener()) {
            if (listener.getId().equals(listener_id)) {
                String ls = localStrings.getLocalString(
                    "create.iiop.listener.duplicate",
                    "IIOP Listener named {0} already exists.", listener_id);
                report.setMessage(ls);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }

            if (listener.getAddress().trim().equals(listeneraddress) &&
                    listener.getPort().trim().equals((iiopport))) {
                String def = "Port [{0}] is already taken by another listener: "
                    + "[{1}] for address [{2}], choose another port.";
                String ls = localStrings.getLocalString(
                    "create.iiop.listener.port.occupied",
                    def, iiopport, listener.getId(), listeneraddress);
                report.setMessage(ls);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }

        try {
            ConfigSupport.apply(
                new SingleConfigCode<IiopService>() {
                    @Override
                    public Object run(IiopService param)
                        throws PropertyVetoException, TransactionFailure {

                        IiopListener newListener = param.createChild(
                            IiopListener.class);

                        newListener.setId(listener_id);
                        newListener.setAddress(listeneraddress);
                        newListener.setPort(iiopport);
                        newListener.setSecurityEnabled(securityenabled.toString());
                        newListener.setEnabled(enabled.toString());

                        //add properties
                        if (properties != null) {
                            for ( java.util.Map.Entry entry : properties.entrySet()) {
                                Property property =
                                    newListener.createChild(Property.class);
                                property.setName((String)entry.getKey());
                                property.setValue((String)entry.getValue());
                                newListener.getProperty().add(property);
                            }
                        }

                        param.getIiopListener().add(newListener);
                        return newListener;
                    }
                }, iiopService);

            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } catch(TransactionFailure e) {
            String actual = e.getMessage();
            String def = "Creation of: " + listener_id + "failed because of: "
                + actual;
            String msg = localStrings.getLocalString(
                "create.iiop.listener.fail", def, listener_id, actual);
            report.setMessage(msg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
        }
    }

}