/*
 * Copyright 2006-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openspaces.admin;

import org.openspaces.admin.internal.admin.DefaultAdmin;

import com.gigaspaces.security.UserDetails;
import com.gigaspaces.logger.GSLogConfigLoader;

/**
 * A factory allowing to create {@link org.openspaces.admin.Admin} instance.
 *
 * <p>Allows to set the Lookup Service Groups and Locators. The Admin listens for events
 * from the lookup service of components added and removed. It will monitor all components
 * that work within the specified group and locator.
 *
 * <p>Allows to set the username and password that will be used to authenticate when secured
 * services are discovered.
 *
 * @author kimchy
 */
public class AdminFactory {

    private final DefaultAdmin admin = new DefaultAdmin();

    private boolean useGsLogging = true;

    public AdminFactory useGsLogging(boolean useGsLogging) {
        this.useGsLogging = useGsLogging;
        return this;
    }

    /**
     * Adds a lookup group that will be used to find Lookup Services (using multicast)
     * that will be used to listen for events.
     */
    public AdminFactory addGroup(String group) {
        admin.addGroup(group);
        return this;
    }

    /**
     * Adds a lookup locator (ip and port) of the lookup service that will be used to listen
     * for events.
     */
    public AdminFactory addLocator(String locator) {
        admin.addLocator(locator);
        return this;
    }

    /**
     * Sets the username that will be used when discovering secured services.
     */
    public AdminFactory setUsername(String username) {
        admin.setUsername(username);
        return this;
    }

    /**
     * Sets the password that will be used when discovering secured services.
     */
    public AdminFactory setPassword(String password) {
        admin.setPassword(password);
        return this;
    }

    /**
     * Sets the user details that will be used when discovering secured services.
     */
    public AdminFactory setUserDetails(UserDetails userDetails) {
        admin.setUserDetails(userDetails);
        return this;
    }

    /**
     * Creates the admin and begins its listening for events from the lookup service.
     */
    public Admin createAdmin() {
        if (useGsLogging) {
            GSLogConfigLoader.getLoader();
        }
        admin.begin();
        return admin;
    }
}

@@ -698,24 +698,59 @@
 efaultAdmin;
+%0Aimport org.jini.rio.boot.BootUtil;
 %0A%0Aimport com
@@ -1844,199 +1844,879 @@
 s a 
-lookup locator (ip and port) of the lookup service that will be used to listen%0A     * for events.%0A     */%0A    public AdminFactory addLocator(String locator) %7B%0A        admin.addLocator(locator
+comma delimited string of groups that will be used to find the Lookup Services%0A     * (using multicast).%0A     */%0A    public AdminFactory addGroups(String groups) %7B%0A        String%5B%5D groupsArr = BootUtil.toArray(groups);%0A        for (String group : groupsArr) %7B%0A            addGroup(group);%0A        %7D%0A        return this;%0A    %7D%0A%0A    /**%0A     * Adds a lookup locator (ip and port) of the lookup service that will be used to listen%0A     * for events.%0A     */%0A    public AdminFactory addLocator(String locator) %7B%0A        admin.addLocator(locator);%0A        return this;%0A    %7D%0A%0A    /**%0A     * Adds a comma delimited lookup locators (ip and port) of the lookup service that will%0A     * be used to listen for events.%0A     */%0A    public AdminFactory addLocators(String locators) %7B%0A        // its already a comma delimited string, so we just add it%0A        admin.addLocator(locators
 );%0A 

add simple compound discovery methods to the admin API