001 // Copyright 2010 Waterken Inc. under the terms of the MIT X license 002 // found at http://www.opensource.org/licenses/mit-license.html 003 package org.ref_send.promise; 004 005 import java.lang.reflect.Method; 006 import java.lang.reflect.Modifier; 007 008 import org.joe_e.Powerless; 009 import org.joe_e.reflect.Reflection; 010 011 /** 012 * Indicates the class provided to {@link Eventual#spawn spawn} is not a Maker. 013 * <p> 014 * A Maker class <strong>MUST</strong>: 015 * </p> 016 * <ul> 017 * <li>be declared in a {@linkplain org.joe_e.IsJoeE Joe-E} package</li> 018 * <li>be <code>public</code></li> 019 * <li>have a single <code>public static</code> method named 020 * "<code>make</code>"</li> 021 * </ul> 022 */ 023 public class 024 NotAMaker extends NullPointerException implements Powerless { 025 static private final long serialVersionUID = 1L; 026 027 public 028 NotAMaker() {} 029 030 private 031 NotAMaker(final Class<?> maker) { 032 super(Reflection.getName(maker)); 033 } 034 035 /** 036 * Finds a Maker's make method. 037 * @param maker maker type 038 * @return corresponding make method 039 * @throws NotAMaker no make method found 040 */ 041 static public Method 042 dispatch(final Class<?> maker) throws NotAMaker { 043 Method make = null; 044 for (final Method m : Reflection.methods(maker)) { 045 if ("make".equals(m.getName()) && 046 Modifier.isStatic(m.getModifiers())) { 047 if (null != make) { throw new NotAMaker(maker); } 048 make = m; 049 } 050 } 051 if (null == make) { throw new NotAMaker(maker); } 052 return make; 053 } 054 }