Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
OpenBlueSky - NetBeans Platform Enhancements Copyright (C) 2006-2011 by Tidalwave s.a.s. (http://www.tidalwave.it) 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. WWW: http://openbluesky.kenai.com SCM: https://kenai.com/hg/openbluesky~src /
 
 package it.tidalwave.hierarchy.spi.simple;
 
 import  javax.annotation.CheckForNull;
 import  javax.annotation.Nonnull;
 import java.util.List;
 import java.util.Set;
 import  org.openide.util.Lookup;
 import  org.openide.util.lookup.Lookups;
 import  it.tidalwave.util.Id;
 import  it.tidalwave.role.Displayable;
 import  it.tidalwave.role.IdFactory;
 import  it.tidalwave.role.spi.DefaultDisplayable;
 import  it.tidalwave.role.spi.DefaultMutableDisplayable;

Author(s):
Fabrizio Giudici
Version:
$Id$ /
 
 public class Support extends AsSupport
   {
     @Nonnull
     protected final Lookup lookup;
 
     @Nonnull
     protected final Id id;
 
     public Support (final @Nonnull SimpleBuilder<?> builder,
                     final @Nonnull String toString,
                     final @Nonnull Lookup.Provider parent,
                     final @Nonnull Object ... capabilitiesAsArray)
       {
         final List<Objectcapabilities = new ArrayList<Object>(Arrays.asList(capabilitiesAsArray));
         final String displayName = builder.getDisplayName();
         final Object boundObject = builder.getBoundObject();
         Lookup delegateLookup = null;
 
         if (boundObject != null)
           {
             capabilities.add(boundObject);
           }
 
         if (displayName != null)
           {
             capabilities.add(builder.canBeRenamed() ?
                              new DefaultMutableDisplayable(displayNametoString) :
                              new DefaultDisplayable(displayNametoString));
           }
         else if (boundObject instanceof Lookup.Provider)
           {
             delegateLookup = ((Lookup.Provider)boundObject).getLookup();
             final Displayable displayable = delegateLookup.lookup(Displayable.class);
 
             if (displayable == null)
               {
                 throw new IllegalArgumentException("displayName not provided and the boundObject is not a Displayable");
               }
 
             capabilities.add(displayable);
           }
         else
           {
             throw new IllegalArgumentException("A displayName or a  boudObject that is Displayable must be provided");
           }
 
         IdFactory idFactory = builder.getIdFactory();
 
         if (idFactory == null)
           {
             idFactory = parent.getLookup().lookup(IdFactory.class);
           }
        if (idFactory == null)
          {
            idFactory = Locator.find(IdFactory.class);
          }
        capabilities.add(idFactory);
        capabilities.addAll(builder.getWithObjects());
        if (delegateLookup == null)
          {
             = LookupFactory.createLookup(this, Lookups.fixed(capabilities.toArray()));
          }
        else
          {
            final Set<Class<?>> classesToExclude = new HashSet<Class<?>>();
            for (final Object o : capabilities)
              {
                classesToExclude.add(o.getClass());
              }
            final Lookup exclude = Lookups.exclude(delegateLookupclassesToExclude.toArray(new Class<?>[0]));
            // FIXME: this won't track changes in the original Lookup, but at the moment trigger error in the Wrapper
            capabilities.addAll(exclude.lookupAll(Object.class));
             = LookupFactory.createLookup(this, Lookups.fixed(capabilities.toArray()));
//            lookup = LookupFactory.createLookup(this, new ProxyLookup(Lookups.fixed(capabilities.toArray()), exclude));
          }
         = (builder.getId() != null) ? builder.getId() : nullChecked(idFactory).createId();
      }
    @Nonnull
    public Id getId()
      {
        return ;
      }
    @Override @Nonnull
    public Lookup getLookup()
      {
        return ;
      }
    @Nonnull
    private static IdFactory nullChecked (final @CheckForNull IdFactory idFactory)
      {
        if (idFactory == null)
          {
            throw new IllegalArgumentException("Can't find an IdFactory");
          }
        return idFactory;
      }
  }
New to GrepCode? Check out our FAQ X