Java源码示例:groovy.lang.MissingMethodException

示例1
public void iaszone(ReflexMatchContext ctx, Map<String,Object> config, IasZoneTypes type) {
   int ep = 1;
   int pr = ZigbeeNaming.HA_PROFILE_ID;
   int cl = IasZone.CLUSTER_ID & 0xFFFF;

   if (config.containsKey("endpoint")) {
      ep = ((Number)config.get("endpoint")).intValue();
   }

   if (config.containsKey("profile")) {
      pr = ((Number)config.get("profile")).intValue();
   }

   if (config.containsKey("cluster")) {
      cl = ((Number)config.get("cluster")).intValue();
   }

   switch (type) {
   case ENROLL:
      ctx.addAction(new ReflexActionZigbeeIasZoneEnroll(ep,pr,cl));
      break;

   default:
      throw new MissingMethodException("iaszone", getClass(), new Object[] { type });
   }
}
 
示例2
@Override
public Object invokeMethod(String name, Object args) {
   try {
      return super.invokeMethod(name, args);
   }
   catch(MissingMethodException e) {
      if(name.startsWith("on")) {
         CapabilityDefinition definition = builder.getCapabilityDefinition();
         if(definition == null) {
            throw new IllegalArgumentException("Must specify the 'capability' header before adding a handler");
         }
         throw new IllegalArgumentException(
               "Invalid handler method [" + name + "], only the capability on" + definition.getCapabilityName() +
               " or one of the events " + toEventNames(definition.getCommands()) + " is valid here"
         );
      }
      throw e;
   }
}
 
示例3
public Void methodMissing(String name, Object argsObj) {
    Object[] args = (Object[]) argsObj;

    if (!executingDsl.get()) {
        if (name.equals("$")) {
            throw new GradleException(ATTEMPTED_INPUT_SYNTAX_USED_MESSAGE);
        } else {
            throw new MissingMethodException(name, getClass(), args);
        }
    } else {
        if (args.length != 1 || !(args[0] instanceof Closure)) {
            throw new MissingMethodException(name, getClass(), args);
        } else {
            Closure closure = (Closure) args[0];
            getChildPath(name).registerConfigurationAction(closure);
            return null;
        }
    }
}
 
示例4
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
示例5
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
示例6
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
示例7
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
示例8
@Nullable
public Object methodMissing(@Nonnull String name, @Nullable Object args) {
    final Object[] argsArray = (Object[]) args;
    final Configuration configuration = _project.getConfigurations().findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }
    final List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        //noinspection rawtypes
        return doAdd(name, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(name, normalizedArgs.get(0), null);
    } else {
        for (final Object arg : normalizedArgs) {
            doAdd(name, arg, null);
        }
        return null;
    }
}
 
示例9
private Object invokeImpl(Object thiz, String name, Object... args)
        throws ScriptException, NoSuchMethodException {
    if (name == null) {
        throw new NullPointerException("method name is null");
    }

    try {
        if (thiz != null) {
            return InvokerHelper.invokeMethod(thiz, name, args);
        } else {
            return callGlobal(name, args);
        }
    } catch (MissingMethodException mme) {
        throw new NoSuchMethodException(mme.getMessage());
    } catch (Exception e) {
        throw new ScriptException(e);
    }
}
 
示例10
public void bind() {
    if (!bound) {
        bound = true;
        boundBean = bean;
        boundProperty = propertyName;
        try {
            InvokerHelper.invokeMethodSafe(boundBean, "addPropertyChangeListener", new Object[]{boundProperty, this});
            boundToProperty = true;
        } catch (MissingMethodException mme) {
            try {
                boundToProperty = false;
                InvokerHelper.invokeMethodSafe(boundBean, "addPropertyChangeListener", new Object[]{this});
            } catch (MissingMethodException mme2) {
                throw new RuntimeException("Properties in beans of type " + bean.getClass().getName() + " are not observable in any capacity (no PropertyChangeListener support).");
            }
        }
    }
}
 
示例11
public void unbind() {
    if (bound) {
        if (boundToProperty) {
            try {
                InvokerHelper.invokeMethodSafe(boundBean, "removePropertyChangeListener", new Object[]{boundProperty, this});
            } catch (MissingMethodException mme) {
                // ignore, too bad so sad they don't follow conventions, we'll just leave the listener attached
            }
        } else {
            try {
                InvokerHelper.invokeMethodSafe(boundBean, "removePropertyChangeListener", new Object[]{this});
            } catch (MissingMethodException mme2) {
                // ignore, too bad so sad they don't follow conventions, we'll just leave the listener attached
            }
        }
        boundBean = null;
        boundProperty = null;
        bound = false;
    }
}
 
示例12
public final Object call(final Object receiver, final Object[] args) throws Throwable {
    if (checkCall(receiver)) {
        try {
            try {
                return metaClass.invokeMethod(receiver, name, args);
            } catch (MissingMethodException e) {
                if (e instanceof MissingMethodExecutionFailed) {
                    throw (MissingMethodException)e.getCause();
                } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
                    // in case there's nothing else, invoke the object's own invokeMethod()
                    return ((GroovyObject)receiver).invokeMethod(name, args);
                } else {
                    throw e;
                }
            }
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
        return CallSiteArray.defaultCall(this, receiver, args);
    }
}
 
示例13
static Object invokePogoMethod(Object object, String methodName, Object arguments) {
    GroovyObject groovy = (GroovyObject) object;
    boolean intercepting = groovy instanceof GroovyInterceptable;
    try {
        // if it's a pure interceptable object (even intercepting toString(), clone(), ...)
        if (intercepting) {
            return groovy.invokeMethod(methodName, asUnwrappedArray(arguments));
        }
        //else try a statically typed method or a GDK method
        return groovy.getMetaClass().invokeMethod(object, methodName, asArray(arguments));
    } catch (MissingMethodException e) {
        if (e instanceof MissingMethodExecutionFailed) {
            throw (MissingMethodException) e.getCause();
        } else if (!intercepting && e.getMethod().equals(methodName) && object.getClass() == e.getType()) {
            // in case there's nothing else, invoke the object's own invokeMethod()
            return groovy.invokeMethod(methodName, asUnwrappedArray(arguments));
        } else {
            throw e;
        }
    }
}
 
示例14
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
示例15
/**
 * This method is the workhorse of the builder.
 *
 * @param methodName the name of the method being invoked
 * @param name       the name of the node
 * @param args       the arguments passed into the node
 * @return the object from the factory
 */
private Object doInvokeMethod(String methodName, Object name, Object args) {
    Reference explicitResult = new Reference();
    if (checkExplicitMethod(methodName, args, explicitResult)) {
        return explicitResult.get();
    } else {
        try {
            return dispatchNodeCall(name, args);
        } catch(MissingMethodException mme) {
            if(mme.getMethod().equals(methodName) && methodMissingDelegate != null) {
                return methodMissingDelegate.call(methodName, args);
            }
            throw mme;
        }
    }
}
 
示例16
public Object invokeMethod(Object object, String methodName, Object arguments) {
    try {
        return delegate.invokeMethod(object, methodName, arguments);
    } catch (MissingMethodException mme) {
        // attempt builder resolution
        try {
            if (builder.getMetaClass().respondsTo(builder, methodName).isEmpty()) {
                // dispatch to factories if it is not a literal method
                return builder.invokeMethod(methodName, arguments);
            } else {
                return InvokerHelper.invokeMethod(builder, methodName, arguments);
            }
        } catch (MissingMethodException mme2) {
            // chain secondary exception
            Throwable root = mme;
            while (root.getCause() != null) {
                root = root.getCause();
            }
            root.initCause(mme2);
            // throw original
            throw mme;
        }
    }
}
 
示例17
public Object invokeMethod(Object object, String methodName, Object[] arguments) {
    try {
        return delegate.invokeMethod(object, methodName, arguments);
    } catch (MissingMethodException mme) {
        // attempt builder resolution
        try {
            if (builder.getMetaClass().respondsTo(builder, methodName).isEmpty()) {
                // dispatch to factories if it is not a literal method
                return builder.invokeMethod(methodName, arguments);
            } else {
                return InvokerHelper.invokeMethod(builder, methodName, arguments);
            }
        } catch (MissingMethodException mme2) {
            // chain secondary exception
            Throwable root = mme;
            while (root.getCause() != null) {
                root = root.getCause();
            }
            root.initCause(mme2);
            // throw original
            throw mme;
        }
    }
}
 
示例18
public void testListCoercionPropertyOnJFrame() throws Exception {
    if (HeadlessTestSupport.isHeadless()) return;

    try {
        JFrame bean = new JFrame();
        List list = new ArrayList();
        list.add(Integer.valueOf(10));
        list.add(Integer.valueOf(20));

        InvokerHelper.setProperty(bean, "location", list);
        assertEquals("Should have set a point", new Point(10, 20), bean.getLocation());
    }
    catch (MissingMethodException e) {
        System.out.println("Failed with cause: " + e);
        e.printStackTrace();
        fail("Should not have throw: " + e);
    }
}
 
示例19
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
示例20
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
示例21
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
示例22
@Override
public Object invokeMethod(String name, Object args) {
   MessageDescriptor message = cluster.getMessageByName(name.toLowerCase());
   Object[] arguments = (Object[])args;
   if (arguments.length == 1 && arguments[0] instanceof Closure) {
      addHandler((byte)ZigbeeMessage.Zdp.ID, message.getIdAsShort(), null, null, (Closure<?>)arguments[0]);
      return null;
   }
   else {
      throw new MissingMethodException(name, getClass(), arguments);
   }
}
 
示例23
@Override
public Object invokeMethod(String name, Object args) {
   MessageDescriptor message = cluster.getMessageByName(name.toLowerCase());
   Object[] arguments = (Object[])args;
   if (arguments.length == 1 && arguments[0] instanceof Closure) {
      addHandler((byte)ZigbeeMessage.Zcl.ID, cluster.getId(), message.getIdAsByte(), message.getGroup(), (Closure<?>)arguments[0]);
      return null;
   }
   else {
      throw new MissingMethodException(name, getClass(), arguments);
   }
}
 
示例24
public void send(ReflexMatchContext.ProtocolClosureProcessor proc, Map<String,Object> payload) {
   if (payload == null) {
      throw new MissingMethodException("send", getClass(), new Object[] { proc, payload });
   }

   proc.process(extractMessage(payload), ImmutableMap.<String,Object>of());
}
 
示例25
public void match(ReflexMatchContext.ProtocolClosureProcessor proc, Map<String,Object> payload) {
   if (payload == null) {
      throw new MissingMethodException("match", getClass(), new Object[] { proc, payload });
   }

   StringBuilder rex = new StringBuilder();
   ZclFieldNamingSupport.INSTANCE.match(rex, payload, ImmutableMap.<String,Object>of());

   List<String> msg = ReflexUtil.extractAsMatchList(payload, "payload");
   proc.process(new ZigbeeReflex.ProtocolMatch(rex,msg), ImmutableMap.<String,Object>of());
}
 
示例26
public void send(ReflexMatchContext.ProtocolClosureProcessor proc, Map<String,Object> payload) {
   if (payload == null) {
      throw new MissingMethodException("send", getClass(), new Object[] { proc, payload });
   }

   proc.process(extractMessage(payload), ImmutableMap.<String,Object>of());
}
 
示例27
public void match(ReflexMatchContext.ProtocolClosureProcessor proc, Map<String,Object> payload) {
   if (payload == null) {
      throw new MissingMethodException("match", getClass(), new Object[] { proc, payload });
   }

   StringBuilder rex = new StringBuilder();
   ZdpFieldNamingSupport.INSTANCE.match(rex, payload, ImmutableMap.<String,Object>of());

   List<String> msg = ReflexUtil.extractAsMatchList(payload, "payload");
   proc.process(new ZigbeeReflex.ProtocolMatch(rex,msg), ImmutableMap.<String,Object>of());
}
 
示例28
public void on(Map<String,Object> config, AlertmeTypes ame) {
   switch (ame) {
   case LIFESIGN:
      onAlertmeLifesign(config);
      break;

   default:
      throw new MissingMethodException("on", getClass(), new Object[] {config, ame});
   }
}
 
示例29
public void amlifesign(Map<String,Object> config, GroovyCapabilityDefinition cap) {
   switch (cap.getNamespace()) {
   case "temp":
      amlifesign(config, ReflexNames.TEMPERATURE);
      break;

   default:
      throw new MissingMethodException("amlifesign", getClass(), new Object[] { config, cap });
   }
}
 
示例30
public void iaszone(Map<String,Object> config, ZigbeeConfigContext.IasZoneTypes type) {
   final CapabilityHandlerContext ctx = GroovyCapabilityDefinition.CapabilityHandlerContext.getContext(this);
   switch (type) {
   case ENROLL:
      int ep = 1;
      int pr = ZigbeeNaming.HA_PROFILE_ID;
      int cl = IasZone.CLUSTER_ID;

      if (config.containsKey("endpoint")) {
         ep = ((Number)config.get("endpoint")).intValue();
      }

      if (config.containsKey("profile")) {
         pr = ((Number)config.get("profile")).intValue();
      }

      if (config.containsKey("cluster")) {
         cl = ((Number)config.get("cluster")).intValue();
      }

      ctx.addAction(new ZigbeeSendAction(ZigbeeMessage.IasZoneEnroll.builder()
         .setEndpoint(ep)
         .setProfile(pr)
         .setCluster(cl)
         .create()
      ));
      break;

   default:
      throw new MissingMethodException("iaszone", getClass(), new Object[] { type });
   } 
}