alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.mdr.test;

import org.openide.util.*;
import org.netbeans.mdr.NBMDRManagerImpl;
import org.netbeans.lib.jmi.xmi.*;
import org.netbeans.lib.jmi.mapping.JMIMapperImpl;

import java.util.*;

/**
 *
 * @author  mmatula
 * @version 
 */
public class MDRTestLookup extends Lookup {
    
    private ArrayList instances = null;

    /** Creates new RepositoryLookup */
    public MDRTestLookup() {
    }

    public Object lookup(Class cls) {
        if (instances == null) {
            instances = new ArrayList();
            instances.add(new NBMDRManagerImpl());
            instances.add(new XMISaxReaderImpl());
            instances.add(new JMIMapperImpl());
            instances.add(new XMIWriterImpl());
        }
        for (Iterator it = instances.iterator(); it.hasNext();) {
            Object instance = it.next();
            if (cls.isAssignableFrom(instance.getClass())) {
                return instance;
            }
        }
        return null;
    }
    
    public Lookup.Result lookup(Lookup.Template template) {        
        return new Result(lookup(template.getType()));
    }
    
    private static class Result extends Lookup.Result {
        private final ArrayList result = new ArrayList();
        
        public Result(Object o) {
            if (o != null) result.add(o);
        }
        
        /** Registers a listener that is invoked when there is a possible
         * change in this result.
         *
         * @param l the listener to add
         */
        public void addLookupListener(LookupListener l) {
            // this lookup never changes so nothing need to be registered
        }
        
        /** Get all instances in the result.
         * @return collection of all instances
         */
        public java.util.Collection allInstances() {
            return result;
        }
        
        /** Unregisters a listener previously added.
         * @param l the listener to remove
         */
        public void removeLookupListener(LookupListener l) {
            // nothing was registered
        }
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.