/**
 * Get more info at : www.jrebirth.org .
 * Copyright JRebirth.org © 2011-2013
 * Contact : sebastien.bordes@jrebirth.org
 * 
 * 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.jrebirth.core.link;

import java.util.Collections;
import java.util.List;

import org.jrebirth.core.command.Command;
import org.jrebirth.core.exception.CoreException;
import org.jrebirth.core.facade.FacadeReady;
import org.jrebirth.core.facade.JRebirthEventType;
import org.jrebirth.core.facade.LocalFacade;
import org.jrebirth.core.key.UniqueKey;
import org.jrebirth.core.service.Service;
import org.jrebirth.core.ui.Model;

/**
 * 
 * The class <strong>AbstractReady</strong>.
 * 
 * It allow to retrieve any of available singleton.
 * 
 * @param <R> the class type of the subclass
 */
public abstract class AbstractReady<R extends FacadeReady<R>> implements FacadeReady<R>, ModelReady, CommandReady, ServiceReady {

    /**
     * The facade that manage same kind of object (from Service, Command and Model).
     */
    private LocalFacade<R> localFacade;

    /** The key that is used to register this component. */
    private UniqueKey<R> key;

    /**
     * {@inheritDoc}
     */
    @Override
    public final LocalFacade<R> getLocalFacade() {
        return this.localFacade;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final void setLocalFacade(final LocalFacade<R> localFacade) {
        this.localFacade = localFacade;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public UniqueKey<R> getKey() {
        return this.key;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setKey(final UniqueKey<R> key) {
        this.key = key;
    }

    /**
     * @return Returns the modelObject.
     */
    @SuppressWarnings("unchecked")
    public Object getModelObject() {
        Object modelObject = null;
        if (this.key.getValue() instanceof List && !((List<Object>) this.key.getValue()).isEmpty()) {
            modelObject = ((List<Object>) this.key.getValue()).get(0);
        } else {
            modelObject = this.key.getValue();
        }
        return modelObject;
    }

    /**
     * @return Returns the list of model Object.
     */
    @SuppressWarnings("unchecked")
    public List<Object> getListModelObject() {
        List<Object> listModelObject = null;
        if (this.key.getValue() instanceof List) {
            listModelObject = (List<Object>) this.key.getValue();
        } else {
            listModelObject = Collections.emptyList();
            listModelObject.add(this.key.getValue());
        }
        return listModelObject;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void release() {
        this.key = null;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final <S extends Service> S getService(final Class<S> clazz, final Object... keyPart) {
        getLocalFacade().getGlobalFacade().trackEvent(JRebirthEventType.ACCESS_SERVICE, this.getClass(), clazz);
        return getLocalFacade().getGlobalFacade().getServiceFacade().retrieve(clazz, keyPart);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final <C extends Command> C getCommand(final Class<C> clazz, final Object... keyPart) {
        getLocalFacade().getGlobalFacade().trackEvent(JRebirthEventType.ACCESS_COMMAND, this.getClass(), clazz);
        return getLocalFacade().getGlobalFacade().getCommandFacade().retrieve(clazz, keyPart);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final <M extends Model> M getModel(final Class<M> clazz, final Object... keyPart) {
        getLocalFacade().getGlobalFacade().trackEvent(JRebirthEventType.ACCESS_MODEL, this.getClass(), clazz);
        return getLocalFacade().getGlobalFacade().getUiFacade().retrieve(clazz, keyPart);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public abstract void ready() throws CoreException;

}

@@ -732,24 +732,53 @@
 re.link;%0D%0A%0D%0A
+import java.util.ArrayList;%0D%0A
 import java.
@@ -2795,32 +2795,23 @@
 %0A     * 
-@r
+R
 eturn 
-Returns 
 the list
@@ -2817,21 +2817,304 @@
 t of
+ key parts (considered as model objects).%0D%0A     * %0D%0A     * If the key value is an instance of List it will return it as is%0D%0A     * otherwise it will create a new list and add the unique key part object %0D%0A     * %0D%0A     * @return Returns a list composed by all
  model 
-O
+o
 bject
+s (= component key parts)
 .%0D%0A 
@@ -3422,29 +3422,23 @@
 t = 
-Collections.empt
+new Arra
 yList
+%3C%3E
 ();%0D

Fix #90, bug introduced by 3d6afbe9a9e4be31d31e5d836edef66e476e2b42 commit Don't use Collection.emptyList() for mutable list