Java Class.asSubclass Examples

Java Class.asSubclass - 30 examples found. These are the top rated real world Java examples of Class.asSubclass extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private synchronized ScopeValidator getScopeValidator() throws ServerException {
    if (scopeValidator == null) {
      try {
        final String scopeValidatorClassName =
            getStringSettingValue(OAuth2ProviderService.SCOPE_PLUGIN_CLASS);
        if (isEmpty(scopeValidatorClassName)) {
          logger.message("Scope Validator class not set.");
          throw new ServerException("Scope Validator class not set.");
        }

        final Class<?> scopeValidatorClass = Class.forName(scopeValidatorClassName);

        if (Scope.class.isAssignableFrom(scopeValidatorClass)) {
          final Scope scopeClass =
              InjectorHolder.getInstance(scopeValidatorClass.asSubclass(Scope.class));
          return new LegacyScopeValidator(scopeClass);
        }

        scopeValidator =
            InjectorHolder.getInstance(scopeValidatorClass.asSubclass(ScopeValidator.class));

      } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
        throw new ServerException(e);
      }
    }
    return scopeValidator;
  }
Example #2
0
  public static void register(Class<? extends Event> pore) {
    checkNotNull(pore, "pore");

    Class<? extends org.spongepowered.api.event.Event> sponge = null;
    for (Constructor<?> constructor : pore.getConstructors()) {
      Class<?>[] parameters = constructor.getParameterTypes();
      if (parameters.length == 1) {
        Class<?> parameter = parameters[0];
        if (org.spongepowered.api.event.Event.class.isAssignableFrom(parameter)) {
          sponge = parameter.asSubclass(org.spongepowered.api.event.Event.class);
        }
      }
    }

    checkArgument(sponge != null, "No event constructor found in %s", pore);

    Class<?> superClass = pore.getSuperclass();
    checkState(
        !Modifier.isAbstract(superClass.getModifiers())
            && superClass.getName().startsWith("org.bukkit.event"),
        "Not a Bukkit handle event %s",
        superClass);
    Class<? extends Event> handle = superClass.asSubclass(Event.class);

    HandlerList list = SimplePluginManager.getEventListeners(handle);
    list.addAdapter(create(pore, sponge));
  }
  private ResponseTypeHandler wrap(String responseTypeName, String responseTypeHandlerClassName)
      throws UnsupportedResponseTypeException {

    if (responseTypeHandlerClassName == null || responseTypeHandlerClassName.isEmpty()) {
      logger.warning(
          "Requested a response type that is not configured. response_type=" + responseTypeName);
      throw new UnsupportedResponseTypeException("Response type is not supported");
    } else if (responseTypeHandlerClassName.equalsIgnoreCase("none")) {
      return new NoneResponseTypeHandler();
    }
    try {
      final Class<?> responseTypeHandlerClass = Class.forName(responseTypeHandlerClassName);
      if (ResponseType.class.isAssignableFrom(responseTypeHandlerClass)) {
        ResponseType responseType =
            InjectorHolder.getInstance(responseTypeHandlerClass.asSubclass(ResponseType.class));
        return new LegacyResponseTypeHandler(
            responseType, realm, getSSOCookieName(), cookieExtractor);
      }

      return InjectorHolder.getInstance(
          responseTypeHandlerClass.asSubclass(ResponseTypeHandler.class));

    } catch (ClassNotFoundException e) {
      logger.error(e.getMessage());
      throw new UnsupportedResponseTypeException("Response type is not supported");
    }
  }
Example #4
0
 public static Object convertArrayElements(Class<?> arrayType, Object array) {
   Class<?> src = array.getClass().getComponentType();
   Class<?> dst = arrayType.getComponentType();
   if (src == null || dst == null) throw new IllegalArgumentException("not array type");
   Wrapper sw = (src.isPrimitive() ? Wrapper.forPrimitiveType(src) : null);
   Wrapper dw = (dst.isPrimitive() ? Wrapper.forPrimitiveType(dst) : null);
   int length;
   if (sw == null) {
     Object[] a = (Object[]) array;
     length = a.length;
     if (dw == null) return Arrays.copyOf(a, length, arrayType.asSubclass(Object[].class));
     Object res = dw.makeArray(length);
     dw.copyArrayUnboxing(a, 0, res, 0, length);
     return res;
   }
   length = j86.java.lang.reflect.Array.getLength(array);
   Object[] res;
   if (dw == null) {
     res = Arrays.copyOf(NO_ARGS_ARRAY, length, arrayType.asSubclass(Object[].class));
   } else {
     res = new Object[length];
   }
   sw.copyArrayBoxing(array, 0, res, 0, length);
   if (dw == null) return res;
   Object a = dw.makeArray(length);
   dw.copyArrayUnboxing(res, 0, a, 0, length);
   return a;
 }
Example #5
0
 static {
   for (Class<?> cl : dolda.jglob.Loader.get(ResName.class).classes()) {
     String nm = cl.getAnnotation(ResName.class).value();
     if (ResCons.class.isAssignableFrom(cl)) {
       final ResCons scons;
       try {
         scons = cl.asSubclass(ResCons.class).newInstance();
       } catch (InstantiationException e) {
         throw (new Error(e));
       } catch (IllegalAccessException e) {
         throw (new Error(e));
       }
       rnames.put(
           nm,
           new ResCons2() {
             public Res.Resolver cons(Resource res, Object... args) {
               final GLState ret = scons.cons(res, args);
               return (new Res.Resolver() {
                 public void resolve(Collection<GLState> buf) {
                   if (ret != null) buf.add(ret);
                 }
               });
             }
           });
     } else if (ResCons2.class.isAssignableFrom(cl)) {
       try {
         rnames.put(nm, cl.asSubclass(ResCons2.class).newInstance());
       } catch (InstantiationException e) {
         throw (new Error(e));
       } catch (IllegalAccessException e) {
         throw (new Error(e));
       }
     } else if (GLState.class.isAssignableFrom(cl)) {
       final Constructor<? extends GLState> cons;
       try {
         cons = cl.asSubclass(GLState.class).getConstructor(Resource.class, Object[].class);
       } catch (NoSuchMethodException e) {
         throw (new Error("No proper constructor for res-consable GL state " + cl.getName(), e));
       }
       rnames.put(
           nm,
           new ResCons2() {
             public Res.Resolver cons(final Resource res, final Object... args) {
               return (new Res.Resolver() {
                 public void resolve(Collection<GLState> buf) {
                   buf.add(Utils.construct(cons, res, args));
                 }
               });
             }
           });
     } else {
       throw (new Error("Illegal material constructor class: " + cl));
     }
   }
 }
 public AbstractEJBMetaData<?, ?> toAbstractEJBMetaData() {
   if (session || statelessSession) {
     if (statelessSession) {
       return createStatelessMetaData(remoteClass.asSubclass(EJBObject.class), homeClass, home);
     }
     return createStatefulMetaData(remoteClass.asSubclass(EJBObject.class), homeClass, home);
   } else {
     return createEntityMetaData(
         remoteClass.asSubclass(EJBObject.class), homeClass, home, pkClass);
   }
 }