/** test if instance cookie is instance of clazz*/ private static boolean instanceOf(InstanceCookie inst, Class clazz) { if (inst instanceof InstanceCookie.Of) { return ((InstanceCookie.Of) inst).instanceOf(clazz); } else { try { return clazz.isAssignableFrom(inst.instanceClass()); } catch (Exception ex) { Logger.getLogger(Services.class.getName()).log(Level.WARNING, null, ex); return false; } } }
/** Query if this instance can create object of given type. * @param type the type to create * @return true or false */ public boolean instanceOf (Class type) { InstanceCookie.Of delegateIC = delegateIC (); if (delegateIC == null) return type.isAssignableFrom(this.getClass()); return delegateIC.instanceOf (type); }
/** * Accepts only cookies that can provide <code>Toolbar</code>. * @param cookie an <code>InstanceCookie</code> to test * @return true if the cookie can provide accepted instances */ protected InstanceCookie acceptCookie (InstanceCookie cookie) throws java.io.IOException, ClassNotFoundException { boolean is; if (cookie instanceof InstanceCookie.Of) { InstanceCookie.Of of = (InstanceCookie.Of)cookie; is = of.instanceOf (Component.class) || of.instanceOf (Presenter.Toolbar.class) || of.instanceOf (Action.class); } else { Class c = cookie.instanceClass(); is = Component.class.isAssignableFrom(c) || Presenter.Toolbar.class.isAssignableFrom(c) || Action.class.isAssignableFrom (c); } return is ? cookie : null; }
continue; } else if (ic instanceof InstanceCookie.Of) { if (((InstanceCookie.Of)ic).instanceOf(JavaPlatform.class)) { platforms.add((JavaPlatform) ic.instanceCreate()); } else {
if (((InstanceCookie.Of)ic).instanceOf(ScalaPlatform.class)) { platforms.add((ScalaPlatform) ic.instanceCreate());
/** Query to find out if the object created by this cookie is * instance of given type. The same code as: * <pre> * Class actualClass = instanceClass (); * result = type.isAsignableFrom (actualClass); * </pre> * But this can prevent the class <code>actualClass</code> to be * loaded into the <em>JavaVM</em>. * * @param type the class type we want to check * @return true if this cookie can produce object of given type */ public boolean instanceOf(Class type) { if (cookie instanceof InstanceCookie.Of) { InstanceCookie.Of of = (InstanceCookie.Of)cookie; return of.instanceOf (type); } // delegate try { Class clazz = cookie.instanceClass (); return type.isAssignableFrom (clazz); } catch (IOException ex) { return false; } catch (ClassNotFoundException ex) { return false; } }
/** Overrides superclass method. It returns instance * for <code>DataObject</code>&<code>InstanceCookie</code> 'pair'. * If the instance is of <code>FolderLookup.Lkp</code> class it is created otherwise * new <code>Lkp.ICItem</code> created and returned. * * @param dobj the data object that is the source of the cookie * @param cookie the instance cookie to read the instance from * @exception IOException when there I/O error * @exception ClassNotFoundException if the class cannot be found */ protected Object instanceForCookie(DataObject dobj, InstanceCookie cookie) throws IOException, ClassNotFoundException { boolean isLookup; if(cookie instanceof InstanceCookie.Of) { isLookup = ((InstanceCookie.Of)cookie).instanceOf(Lookup.class); } else { isLookup = Lookup.class.isAssignableFrom(cookie.instanceClass ()); } if(isLookup) { // Is underlying FolderLookup create it. return cookie.instanceCreate(); } else { return new ICItem(dobj, rootName, cookie); } }
/** The class of the result item. * @return the class of the item */ protected boolean instanceOf (Class clazz) { init (); if (ic instanceof InstanceCookie.Of) { // special handling for special cookies InstanceCookie.Of of = (InstanceCookie.Of)ic; return of.instanceOf (clazz); } // handling of normal instance cookies try { return clazz.isAssignableFrom (ic.instanceClass ()); } catch (ClassNotFoundException ex) { exception(ex, fo); } catch (IOException ex) { exception(ex, fo); } return false; }
protected Object createInstance(InstanceCookie[] cookies) throws java.io.IOException, ClassNotFoundException { List<Object> installers = new ArrayList<Object>(cookies.length); for (int i = 0; i < cookies.length; i++) { InstanceCookie cake = cookies[i]; Object o = null; try { if (cake instanceof InstanceCookie.Of && !((((InstanceCookie.Of)cake).instanceOf(PlatformInstall.class)) || (((InstanceCookie.Of)cake).instanceOf(CustomPlatformInstall.class)))) continue; o = cake.instanceCreate(); } catch (IOException ex) { } catch (ClassNotFoundException ex) { } if (o != null) installers.add(o); } return installers; } }
public boolean instanceOf (Class cls2) { if (ic instanceof InstanceCookie.Of) { return ((InstanceCookie.Of) ic).instanceOf (cls2); } else { try { return cls2.isAssignableFrom (instanceClass ()); } catch (IOException ioe) { // ignore exception return false; } catch (ClassNotFoundException cnfe) { // ignore exception return false; } } }