All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.ExtensionListView Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2009, Oracle Corporation
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *
 *
 *
 *
 *******************************************************************************/ 

package hudson;

import hudson.model.Hudson;
import hudson.tasks.UserNameResolver;
import hudson.util.CopyOnWriteList;

import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;

/**
 * Compatibility layer for legacy manual registration of extension points.
 *
 * 

Instances of this class can be created statically as a singleton, but it * provides the view to {@link ExtensionList} of the current {@link Hudson}. * Write operations to this list will update the legacy instances on * {@link ExtensionList}. * *

Whereas we used to use some simple data structure to keep track of static * singletons, we can now use this instances, so that {@link ExtensionList} sees * all the auto-registered and manually registered instances. * *

Similarly, the old list (such as {@link UserNameResolver#LIST} continues * to show all auto and manually registered instances, thus providing necessary * bi-directional interoperability. * * @author Kohsuke Kawaguchi */ public class ExtensionListView { /** * Creates a plain {@link List} backed by the current {@link ExtensionList}. */ public static List createList(final Class type) { return new AbstractList() { private ExtensionList storage() { return Hudson.getInstance().getExtensionList(type); } @Override public Iterator iterator() { return storage().iterator(); } public T get(int index) { return storage().get(index); } public int size() { return storage().size(); } @Override public boolean add(T t) { return storage().add(t); } @Override public void add(int index, T t) { // index ignored storage().add(t); } @Override public T remove(int index) { return storage().remove(index); } @Override public boolean remove(Object o) { return storage().remove(o); } }; } /** * Creates a enhanced {@link CopyOnWriteList} that acts as a view to the * current {@link ExtensionList}. */ public static CopyOnWriteList createCopyOnWriteList(final Class type) { return new CopyOnWriteList() { private ExtensionList storage() { return Hudson.getInstance().getExtensionList(type); } @Override public void add(T t) { storage().add(t); } @Override public boolean remove(T t) { return storage().remove(t); } @Override public Iterator iterator() { return storage().iterator(); } @Override public void replaceBy(CopyOnWriteList that) { throw new UnsupportedOperationException(); } @Override public void replaceBy(Collection that) { throw new UnsupportedOperationException(); } @Override public void replaceBy(T... that) { throw new UnsupportedOperationException(); } @Override public void clear() { throw new UnsupportedOperationException(); } @Override public T[] toArray(T[] array) { return storage().toArray(array); } @Override public List getView() { return storage(); } @Override public void addAllTo(Collection dst) { dst.addAll(storage()); } @Override public boolean isEmpty() { return storage().isEmpty(); } }; } // TODO: we need a few more types whose implementations get uglier }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy