@Override
 public boolean isWrapperFor(Class<?> iface) throws SQLException {
   if (iface.equals(Supported.class) || (iface.equals(DataSource.class))) {
     return true;
   }
   return false;
 }
Example #2
1
 private static Object[] buildArgs(
     PojoPathParam[] pathParams,
     Map<String, String> pathParameters,
     Session session,
     EndpointConfig config,
     Throwable throwable,
     CloseReason closeReason)
     throws DecodeException {
   Object[] result = new Object[pathParams.length];
   for (int i = 0; i < pathParams.length; i++) {
     Class<?> type = pathParams[i].getType();
     if (type.equals(Session.class)) {
       result[i] = session;
     } else if (type.equals(EndpointConfig.class)) {
       result[i] = config;
     } else if (type.equals(Throwable.class)) {
       result[i] = throwable;
     } else if (type.equals(CloseReason.class)) {
       result[i] = closeReason;
     } else {
       String name = pathParams[i].getName();
       String value = pathParameters.get(name);
       try {
         result[i] = Util.coerceToType(type, value);
       } catch (Exception e) {
         throw new DecodeException(
             value, sm.getString("pojoMethodMapping.decodePathParamFail", value, type), e);
       }
     }
   }
   return result;
 }
Example #3
1
 private static TerminalFactory loadFactory(String pn, String type)
     throws NoSuchAlgorithmException {
   TerminalFactory tf = null;
   try {
     Class<?> cls = Class.forName(pn);
     Provider p = (Provider) cls.getConstructor().newInstance();
     tf = TerminalFactory.getInstance(type == null ? "PC/SC" : type, null, p);
   } catch (ClassNotFoundException
       | InstantiationException
       | IllegalAccessException
       | IllegalArgumentException
       | InvocationTargetException
       | NoSuchMethodException
       | SecurityException e) {
     throw new RuntimeException("Could not load " + pn, e);
   } catch (NoSuchAlgorithmException e) {
     if (e.getCause() != null) {
       Class<?> cause = e.getCause().getClass();
       if (cause.equals(java.lang.UnsupportedOperationException.class)) {
         throw new NoSuchAlgorithmException(e.getCause().getMessage());
       }
       if (cause.equals(java.lang.UnsatisfiedLinkError.class)) {
         throw new NoSuchAlgorithmException(e.getCause().getMessage());
       }
     }
     throw e;
   }
   return tf;
 }
Example #4
0
 public boolean isAutoIncreaseType() {
   Class idType = this.getColumnField().getType();
   return idType.equals(int.class)
       || idType.equals(Integer.class)
       || idType.equals(long.class)
       || idType.equals(Long.class);
 }
Example #5
0
  private List<ServiceFunctionDictionary> createSfDictList(
      ServiceFunction sf, Class<? extends SlTransportType> transportType) {
    // For MPLS and MAC transport types, we want the SF to be MAC/VLAN
    Class<? extends SlTransportType> sfTransportType =
        (transportType.equals(VxlanGpe.class) ? transportType : Mac.class);

    SffSfDataPlaneLocatorBuilder sffSfDplBuilder = new SffSfDataPlaneLocatorBuilder();
    // TODO the vlanId needs to be the same as on the SF
    sffSfDplBuilder.setLocatorType(buildSfLocatorType(sfTransportType));
    sffSfDplBuilder.setTransport(sfTransportType);

    ServiceFunctionDictionaryBuilder sfDictBuilder = new ServiceFunctionDictionaryBuilder();
    sfDictBuilder.setName(sf.getName());
    sfDictBuilder.setType(sf.getType());
    sfDictBuilder.setSffSfDataPlaneLocator(sffSfDplBuilder.build());
    sfDictBuilder.setKey(new ServiceFunctionDictionaryKey(sf.getName()));

    // Augment the dictionary with an OfsPortBuilder if its not VxLan
    if (!transportType.equals(VxlanGpe.class)) {
      ServiceFunctionDictionary1Builder ofsSfDictBuilder = new ServiceFunctionDictionary1Builder();
      OfsPortBuilder ofsPortBuilder = new OfsPortBuilder();
      ofsPortBuilder.setMacAddress(new MacAddress(getNextMacAddress()));
      ofsPortBuilder.setPortId(SWITCH_PORT_STR);
      ofsSfDictBuilder.setOfsPort(ofsPortBuilder.build());
      sfDictBuilder.addAugmentation(ServiceFunctionDictionary1.class, ofsSfDictBuilder.build());
    }

    List<ServiceFunctionDictionary> sfDictList = new ArrayList<ServiceFunctionDictionary>();
    sfDictList.add(sfDictBuilder.build());

    return sfDictList;
  }
Example #6
0
  @Override
  public Set<Element> get(Object key) {
    Get get = new Get(ByteArraySerializer.fromObject(key));
    Result result;
    try {
      result = backingTable.get(get);
    } catch (IOException e) {
      LOG.severe("Cannot get from backing table");
      e.printStackTrace();
      return null;
    }

    NavigableMap<byte[], byte[]> map = result.getFamilyMap(Bytes.toBytes(VALUES));
    if (null == map) return null;

    HashSet<Element> elementHashSet = new HashSet<Element>();

    for (byte[] byteArray : map.keySet()) {

      if (indexClass.equals(HVertex.class) || indexClass.equals(Vertex.class)) {
        HVertex hVertex = new HVertex(hGraph);
        hVertex.setId(byteArray);
        elementHashSet.add(hVertex);
      } else {
        final HEdge hEdge = new HEdge(hGraph);
        hEdge.setId(byteArray);
        elementHashSet.add(hEdge);
      }
    }

    return elementHashSet;
  }
  private boolean checkRecursiveInstance(Class<?> class2, Class<?> test) {
    Class<?> superclass = class2.getSuperclass();
    if (superclass.equals(Shape.class)) return false;
    else if (superclass.equals(test)) return true;

    return checkRecursiveInstance(superclass, test);
  }
Example #8
0
 /**
  * @param <T>
  * @param source
  * @param targetType
  * @return
  * @throws NoSuchMethodException
  */
 @SuppressWarnings("unchecked")
 public static <T> T getTypeViaValueOfMethod(final String source, final Class<T> targetType)
     throws NoSuchMethodException {
   Class<?> actualTarget = targetType;
   /*
    * if this is a primitive type, use the Object class's "valueOf()"
    * method.
    */
   if (targetType.isPrimitive()) {
     actualTarget = PRIMITIVES.get(targetType);
   }
   T result = null;
   try {
     // if the type has a static "valueOf()" method, try and create the instance that way
     Method valueOf = actualTarget.getDeclaredMethod(VALUE_OF_METHOD, String.class);
     Object value = valueOf.invoke(null, source);
     if (actualTarget.equals(targetType) && targetType.isInstance(value)) {
       result = targetType.cast(value);
     }
     /*
      * handle the primitive case
      */
     else if (!actualTarget.equals(targetType) && actualTarget.isInstance(value)) {
       // because you can't use targetType.cast() with primitives.
       result = (T) value;
     }
   } catch (IllegalAccessException e) {
     throw new ExceptionAdapter(e);
   } catch (InvocationTargetException e) {
     throw new ExceptionAdapter(e);
   }
   return result;
 }
 /**
  * Creates a new DomElement object.
  *
  * @param contentType_QNAME the content type_ qname
  * @param class1 the class1
  * @param object the object
  * @param value the value
  * @return the element
  */
 private String createElement(
     String contentType_QNAME, Class<?> class1, Object object, Object value) {
   if (value != null) {
     StringWriter writer = new StringWriter();
     try {
       XmlSerializer serializer = XML_SERIALIZER_FACTORY.newSerializer();
       serializer.setOutput(writer);
       serializer = serializer.startTag(null, contentType_QNAME);
       if (class1.equals(InviteConnectType.class)) {
         XppUtils.setElementValue(serializer, ((InviteConnectType) value).value());
       } else if (class1.equals(NetworkUpdateReturnType.class)) {
         XppUtils.setElementValue(serializer, ((NetworkUpdateReturnType) value).value());
       } else if (class1.equals(NetworkUpdateContentType.class)) {
         XppUtils.setElementValue(serializer, ((NetworkUpdateContentType) value).value());
       } else {
         XppUtils.setElementValue(serializer, String.valueOf(value));
       }
       serializer.endTag(null, contentType_QNAME);
       serializer.flush();
     } catch (Exception e) {
       LOG.log(Level.SEVERE, "An error occurred while creating xml content.", e);
     }
     return writer.toString();
   } else {
     return null;
   }
 }
Example #10
0
 private static int checkSingleArgument(
     String subroutineName,
     Class expectedType,
     ArgumentsList arguments,
     List<LispObject> args,
     int argsCounter,
     int i) {
   try {
     if (!(expectedType.isInstance(args.get(argsCounter)))) {
       if (expectedType.equals(LispList.class)
           && args.get(argsCounter).equals(LispSymbol.ourNil)) {
         arguments.setValue(i, LispList.list());
         return argsCounter + 1;
       }
       if (expectedType.equals(LispSymbol.class)
           && args.get(argsCounter).equals(LispSymbol.ourNil)) {
         arguments.setValue(i, LispSymbol.ourNil);
         return argsCounter + 1;
       }
       if (arguments.isOptional(i)) return -1;
       throw new WrongTypeArgumentException(expectedType.getSimpleName(), args.get(argsCounter));
     }
     arguments.setValue(i, args.get(argsCounter));
     return argsCounter + 1;
   } catch (IndexOutOfBoundsException e) {
     if (arguments.isOptional(i)) return -1;
     throw new WrongNumberOfArgumentsException(subroutineName, i);
   }
 }
 private Annotation findMappingAnnotation(Annotation[] annotations) {
   if (annotations == null || annotations.length == 0) {
     return null;
   }
   Annotation match = null;
   for (Annotation annotation : annotations) {
     Class<? extends Annotation> type = annotation.annotationType();
     if (type.equals(Payload.class)
         || type.equals(Payloads.class)
         || type.equals(Header.class)
         || type.equals(Headers.class)) {
       if (match != null) {
         throw new MessagingException(
             "At most one parameter annotation can be provided for message mapping, "
                 + "but found two: ["
                 + match.annotationType().getName()
                 + "] and ["
                 + annotation.annotationType().getName()
                 + "]");
       }
       match = annotation;
     }
   }
   return match;
 }
  private <T extends DataObject> boolean hasDataInCF(Class<T> clazz) {
    if (excludeClasses.contains(clazz)) {
      return false; // ignore the data in those CFs
    }

    // true: query only active object ids, for below reason:
    // add VDC should succeed just when remove the data in vdc2.
    List<URI> ids = dbClient.queryByType(clazz, true, null, 2);

    if (clazz.equals(TenantOrg.class) || clazz.equals(ObjectStore.class)) {
      if (ids.size() > 1) {
        // at least one non-root tenant exist
        return true;
      }

      return false;
    }

    if (!ids.isEmpty()) {
      log.info("The class {} has data e.g. id={}", clazz.getSimpleName(), ids.get(0));
      return true;
    }

    return false;
  }
  private PropertyDescriptor findExistingPropertyDescriptor(
      String propertyName, Class<?> propertyType) {

    for (PropertyDescriptor pd : this.propertyDescriptors) {
      final Class<?> candidateType;
      final String candidateName = pd.getName();
      if (pd instanceof IndexedPropertyDescriptor) {
        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
        candidateType = ipd.getIndexedPropertyType();
        if (candidateName.equals(propertyName)
            && (candidateType.equals(propertyType)
                || candidateType.equals(propertyType.getComponentType()))) {
          return pd;
        }
      } else {
        candidateType = pd.getPropertyType();
        if (candidateName.equals(propertyName)
            && (candidateType.equals(propertyType)
                || propertyType.equals(candidateType.getComponentType()))) {
          return pd;
        }
      }
    }
    return null;
  }
 @Override
 public Object resolve(RoutingContext context, RequestBody annotation, Class<?> resultClass) {
   String body = context.getBodyAsString();
   if (resultClass.equals(String.class)) {
     return body;
   }
   String contentType = ContentTypeProcessor.getContentType(context);
   if (contentType == null) {
     log.error("No suitable Content-Type found, request body can't be read");
     return null;
   }
   if (contentType.equals("application/json") && resultClass.equals(JsonObject.class)) {
     return new JsonObject(body);
   }
   PayloadMarshaller marshaller = marshallers.get(contentType);
   if (marshaller == null) {
     log.error(
         "No marshaller found for Content-Type : " + contentType + ", request body can't be read");
     return null;
   }
   try {
     return marshaller.unmarshallPayload(body, resultClass);
   } catch (MarshallingException me) {
     context.fail(me);
     return null;
   }
 }
 public boolean equals(Object paramObject) {
   boolean bool2 = false;
   boolean bool1 = bool2;
   if ((paramObject instanceof ali)) {
     paramObject = (ali) paramObject;
     bool1 = bool2;
     if (b.equals(b)) {
       bool1 = bool2;
       if (g.equals(g)) {
         bool1 = bool2;
         if (d == d) {
           bool1 = bool2;
           if (c == c) {
             bool1 = bool2;
             if (h.equals(h)) {
               bool1 = bool2;
               if (e.equals(e)) {
                 bool1 = bool2;
                 if (f.equals(f)) {
                   bool1 = bool2;
                   if (i.equals(i)) {
                     bool1 = true;
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
   return bool1;
 }
  @SuppressWarnings("unchecked")
  public Object convert(Class arg0, Object arg1) {
    if (arg1 == null) return null;

    long time = 0L;
    if (java.util.Date.class.equals(arg1.getClass())) time = ((java.util.Date) arg1).getTime();
    else if (java.sql.Date.class.equals(arg1.getClass())) time = ((java.sql.Date) arg1).getTime();
    else if (java.sql.Timestamp.class.equals(arg1.getClass()))
      time = ((java.sql.Timestamp) arg1).getTime();
    else {
      String p = arg1.toString();
      if (p == null || p.trim().length() == 0) {
        return null;
      }

      Date value = null;

      for (String pattern : PATTERN) {
        try {
          SimpleDateFormat df = new SimpleDateFormat(pattern);
          value = df.parse(p.trim());
          break;
        } catch (Exception e) {
          continue;
        }
      }
      if (value == null) return null;
      time = value.getTime();
    }

    if (arg0.equals(java.util.Date.class)) return new java.util.Date(time);
    else if (arg0.equals(java.sql.Date.class)) return new java.sql.Date(time);
    else if (arg0.equals(java.sql.Timestamp.class)) return new java.sql.Timestamp(time);
    return null;
  }
Example #17
0
  /**
   * This method checks, if the Login has the specified permission.
   *
   * @param clazz the clazz
   * @param permission the permission
   * @return true, if checks for permission
   */
  public boolean hasPermission(Class<? extends AbstractDomainObject> clazz, Permission permission) {
    // TODO Check permission delete
    boolean hasPermission = false;

    if (clazz.equals(Login.class) || clazz.equals(Person.class)) {

      for (Role r : roles) {
        if (permission.getMask() == PermissionHibernate.CREATE.getMask()) {
          hasPermission = hasPermission || r.isCreateUser();
        } else if (permission.getMask() == PermissionHibernate.WRITE.getMask()) {
          hasPermission = hasPermission || r.isWriteOtherUser();
        } else if (permission.getMask() == PermissionHibernate.READ.getMask()) {
          hasPermission = hasPermission || r.isReadOtherUser();
        } else if (permission.getMask() == PermissionHibernate.ADMINISTRATION.getMask()) {
          hasPermission = hasPermission || r.isAdminOtherUser();
        }
      }
    } else if (clazz.equals(TrialSite.class)) {

      for (Role r : roles) {
        if (permission.getMask() == PermissionHibernate.CREATE.getMask()) {
          hasPermission = hasPermission || r.isCreateTrialSite();
        } else if (permission.getMask() == PermissionHibernate.WRITE.getMask()) {
          hasPermission = hasPermission || r.isWriteTrialSite();
        } else if (permission.getMask() == PermissionHibernate.READ.getMask()) {
          hasPermission = hasPermission || r.isReadTrialSite();
        } else if (permission.getMask() == PermissionHibernate.ADMINISTRATION.getMask()) {
          hasPermission = hasPermission || r.isAdminTrialSite();
        }
      }
    } else if (clazz.equals(Trial.class)) {

      for (Role r : roles) {
        if (permission.getMask() == PermissionHibernate.CREATE.getMask()) {
          hasPermission = hasPermission || r.isCreateTrial();
        } else if (permission.getMask() == PermissionHibernate.WRITE.getMask()) {
          hasPermission = hasPermission || r.isWriteTrial();
        } else if (permission.getMask() == PermissionHibernate.READ.getMask()) {
          hasPermission = hasPermission || r.isReadTrial();
        } else if (permission.getMask() == PermissionHibernate.ADMINISTRATION.getMask()) {
          hasPermission = hasPermission || r.isAdminTrial();
        }
      }
    } else if (clazz.equals(TrialSubject.class)) {

      for (Role r : roles) {
        if (permission.getMask() == PermissionHibernate.CREATE.getMask()) {
          hasPermission = hasPermission || r.isCreateTrialSubject();
        } else if (permission.getMask() == PermissionHibernate.WRITE.getMask()) {
          hasPermission = hasPermission || r.isWriteTrialSubject();
        } else if (permission.getMask() == PermissionHibernate.READ.getMask()) {
          hasPermission = hasPermission || r.isReadTrialSubject();
        } else if (permission.getMask() == PermissionHibernate.ADMINISTRATION.getMask()) {
          hasPermission = hasPermission || r.isAdminTrialSubject();
        }
      }
    }

    return hasPermission;
  }
Example #18
0
  private Configurable getComponentFromAnnotation(String name, S4Component s4Component) {
    Configurable configurable;
    Class<? extends Configurable> defClass = s4Component.defaultClass();

    if (defClass.equals(Configurable.class) && s4Component.mandatory()) {
      throw new InternalConfigurationException(
          getInstanceName(), name, "mandatory property is not set!");
    }

    if (Modifier.isAbstract(defClass.getModifiers()) && s4Component.mandatory())
      throw new InternalConfigurationException(
          getInstanceName(), name, defClass.getName() + " is abstract!");

    // because we're forced to use the default type, make sure that it
    // is set
    if (defClass.equals(Configurable.class)) {
      if (s4Component.mandatory()) {
        throw new InternalConfigurationException(
            getInstanceName(), name, instanceName + ": no default class defined for " + name);
      } else {
        return null;
      }
    }

    configurable = ConfigurationManager.getInstance(defClass);
    if (configurable == null) {
      throw new InternalConfigurationException(
          getInstanceName(), name, "instantiation of referenenced configurable failed");
    }

    return configurable;
  }
  @SuppressWarnings("unchecked")
  public <T> T getHandler(Class<T> cls) {
    Core.ActivityRegistry registry =
        new Core.ActivityRegistry() {

          @Override
          public FragmentManager getFragment() {
            return getSupportFragmentManager();
          }

          @Override
          public Intent getIntent(Class<?> activity) {
            return new Intent(getApplicationContext(), activity);
          }

          @Override
          public void kickActivity(Intent intent) {
            startActivity(intent);
          }
        };
    if (cls.equals(ConnectionActionInterface.class)) return (T) new ConnectionListHandler(registry);
    if (cls.equals(WebviewActionInterface.class)) return (T) new IssueViewHandler(registry);
    if (cls.equals(IssueActionInterface.class)) return (T) new IssueViewHandler(registry);
    if (cls.equals(TimeentryActionInterface.class)) return (T) new TimeEntryHandler(registry);
    if (cls.equals(AttachmentActionInterface.class))
      return (T) new AttachmentActionHandler(registry);
    return null;
  }
 @Override
 @SuppressWarnings("unchecked")
 public <T extends IRepositoryFileData> java.util.List<T> getDataForReadInBatch(
     final List<RepositoryFile> files, final Class<T> dataClass) {
   List<RepositoryFileDto> fileDtos = new ArrayList<RepositoryFileDto>(files.size());
   for (RepositoryFile file : files) {
     fileDtos.add(repositoryFileAdapter.marshal(file));
   }
   if (dataClass.equals(NodeRepositoryFileData.class)) {
     List<NodeRepositoryFileDataDto> nodeData =
         repoWebService.getDataAsNodeForReadInBatch(fileDtos);
     List<T> data = new ArrayList<T>(nodeData.size());
     for (NodeRepositoryFileDataDto node : nodeData) {
       data.add((T) nodeRepositoryFileDataAdapter.unmarshal(node));
     }
     return data;
   } else if (dataClass.equals(SimpleRepositoryFileData.class)) {
     List<SimpleRepositoryFileDataDto> nodeData =
         repoWebService.getDataAsBinaryForReadInBatch(fileDtos);
     List<T> data = new ArrayList<T>(nodeData.size());
     for (SimpleRepositoryFileDataDto node : nodeData) {
       data.add((T) SimpleRepositoryFileDataDto.convert(node));
     }
     return data;
   } else {
     throw new IllegalArgumentException();
   }
 }
Example #21
0
  /**
   * @param entity
   * @param sql
   * @param params
   * @return 下午1:11:38 created by Darwin(Tianxin)
   */
  @SuppressWarnings("unchecked")
  private ENTITY createAndFetchKey(ENTITY entity, final String sql, final List<Object> params) {

    KeyHolder keyHolder = new GeneratedKeyHolder();
    recordLog(sql);

    // 执行操作
    int rowCount =
        this.jdbcTemplate.update(
            new PreparedStatementCreator() {
              public PreparedStatement createPreparedStatement(Connection connection)
                  throws SQLException {
                PreparedStatement ps = connection.prepareStatement(sql);
                int index = 1;
                for (Object param : params) ps.setObject(index++, param);
                return ps;
              }
            },
            keyHolder);

    // 如果插入成功则获取keyHolder中的key
    if (rowCount != 0) {
      Class<KEY> keyClass = orMapping.getKeyClass();
      if (keyClass.equals(Integer.class)) {
        entity.setId((KEY) Integer.valueOf(keyHolder.getKey().intValue()));
      } else if (keyClass.equals(Long.class)) {
        entity.setId((KEY) Long.valueOf(keyHolder.getKey().longValue()));
      }
    }

    return rowCount == 1 ? entity : null;
  }
  // ----- protected methods -----
  protected Direction getDirectionForType(
      final Class<S> sourceType,
      final Class<T> targetType,
      final Class<? extends NodeInterface> type) {

    if (sourceType.equals(type) && targetType.equals(type)) {
      return Direction.BOTH;
    }

    if (sourceType.equals(type)) {
      return Direction.OUTGOING;
    }

    if (targetType.equals(type)) {
      return Direction.INCOMING;
    }

    if (sourceType.isAssignableFrom(type)) {
      return Direction.OUTGOING;
    }

    if (targetType.isAssignableFrom(type)) {
      return Direction.INCOMING;
    }

    return Direction.BOTH;
  }
  @EventHandler
  public void openInventory(InventoryOpenEvent ioe) {
    if (!(ioe.getPlayer() instanceof Player)) {
      return;
    }

    Player player = (Player) ioe.getPlayer();
    Game game = Main.getInstance().getGameManager().getGameOfPlayer(player);

    if (game == null) {
      return;
    }

    if (game.getState() != GameState.RUNNING) {
      return;
    }

    if (ioe.getInventory().getType() == InventoryType.ENCHANTING
        || ioe.getInventory().getType() == InventoryType.BREWING
        || (ioe.getInventory().getType() == InventoryType.CRAFTING
            && !Main.getInstance().getBooleanConfig("allow-crafting", false))) {
      ioe.setCancelled(true);
      return;
    } else if (ioe.getInventory().getType() == InventoryType.CRAFTING
        && Main.getInstance().getBooleanConfig("allow-crafting", false)) {
      return;
    }

    if (game.isSpectator(player)) {
      if (ioe.getInventory().getName().equals(Main._l("ingame.spectator"))) {
        return;
      }

      ioe.setCancelled(true);
    }

    if (ioe.getInventory().getHolder() == null) {
      return;
    }

    if (game.getRegion().getInventories().contains(ioe.getInventory())) {
      return;
    }

    InventoryHolder holder = ioe.getInventory().getHolder();
    for (Class<?> interfaze : holder.getClass().getInterfaces()) {

      if (interfaze.equals(BlockState.class)) {
        game.getRegion().addInventory(ioe.getInventory());
        return;
      }

      for (Class<?> interfaze2 : interfaze.getInterfaces()) {
        if (interfaze2.equals(BlockState.class)) {
          game.getRegion().addInventory(ioe.getInventory());
          return;
        }
      }
    }
  }
  /**
   * Creates a new GraveYardSign / SpawnChest with the given {@link PlayerDropModificator}
   *
   * @param piMod
   * @return the list of Items NOT saved
   */
  public List<ItemStack> createSpawnContainer(PlayerDropModificator piMod) {
    Player player = piMod.getPlayer();
    piMod.modifyForSpawnContainer();

    World world = piMod.getPlayer().getWorld();
    if (worldIsOnIgnore(world)) {
      return piMod.getTransferredItems();
    }

    if (!DeathChest.getPlugin()
        .getPermissionsManager()
        .checkPermissionsSilent(player, PermissionNode.spawnChest)) {
      return (piMod.getTransferredItems());
    }

    Class<?> clazz = plugin.getConfigManager().getSpawnContainerUsage();

    if (clazz == null) return piMod.getTransferredItems();

    if (clazz.equals(SpawnChest.class)) return spawnChest(piMod);

    if (clazz.equals(SpawnSign.class)) return createSign(piMod);

    return null;
  }
Example #25
0
 /* Initialize this instance. */
 public void init() {
   /* If the underMin message was not injected, create a default. */
   if (underMin == null) {
     underMin = new MessageSpecification();
     underMin.setDetailMessage("{validator.range.underMin.detail}");
     underMin.setSummaryMessage("{validator.range.underMin.summary}");
   }
   /* If the overMax message was not injected, create a default. */
   if (overMax == null) {
     overMax = new MessageSpecification();
     overMax.setDetailMessage("{validator.range.overMax.detail}");
     overMax.setSummaryMessage("{validator.range.overMax.summary");
   }
   /* If the type was not injected, stop initialization. */
   if (type == null) {
     return;
   }
   /* Initialize based on type for all Integer value
    * so that LongRangeValidator can be used
    * for int, short, byte, and long. */
   if (!isInitialized()) {
     if (type.equals(Integer.class)) {
       init(new Integer(min.intValue()), new Integer(max.intValue()));
     } else if (type.equals(Byte.class)) {
       init(new Byte(min.byteValue()), new Byte(max.byteValue()));
     } else if (type.equals(Short.class)) {
       init(new Short(min.byteValue()), new Short(max.byteValue()));
     } else {
       init(min, max);
     }
   }
 }
 @SuppressWarnings("unchecked")
 Request populate(Request toPopulate) {
   for (Map.Entry<String, String> header : headers.entrySet()) {
     toPopulate.addHeader(header.getKey(), header.getValue());
   }
   if (content == null) return toPopulate;
   if (contentClass.equals(byte[].class)) {
     toPopulate.bodyByteArray((byte[]) content);
   } else if (contentClass.equals(String.class)) {
     toPopulate.bodyString((String) content, contentType);
   } else if (Map.class.isAssignableFrom(contentClass)) {
     List<NameValuePair> formContent = Lists.newArrayList();
     for (Map.Entry<String, String> val : ((Map<String, String>) content).entrySet()) {
       formContent.add(new BasicNameValuePair(val.getKey(), val.getValue()));
     }
     toPopulate.bodyForm(formContent);
   } else if (contentClass.equals(File.class)) {
     toPopulate.bodyFile((File) content, contentType);
   } else if (InputStream.class.isAssignableFrom(contentClass)) {
     toPopulate.bodyStream((InputStream) content);
   } else {
     throw new IllegalArgumentException(
         String.format(
             "Unknown content class %s. Only byte[], String, Map, File and InputStream are accepted",
             contentClass));
   }
   return toPopulate;
 }
    @Override
    public Void visitNewArray(NewArrayTree tree, AnnotatedTypeMirror type) {

      List<? extends ExpressionTree> dimensions = tree.getDimensions();
      List<? extends ExpressionTree> initializers = tree.getInitializers();

      // Dimensions provided
      if (!dimensions.isEmpty()) {
        handleDimensions(dimensions, (AnnotatedArrayType) type);
      } else {
        // Initializer used
        handleInitalizers(initializers, (AnnotatedArrayType) type);

        AnnotationMirror newQual;
        Class<?> clazz = ValueCheckerUtils.getClassFromType(type.getUnderlyingType());
        String stringVal = null;
        if (clazz.equals(byte[].class)) {
          stringVal = getByteArrayStringVal(initializers);
        } else if (clazz.equals(char[].class)) {
          stringVal = getCharArrayStringVal(initializers);
        }

        if (stringVal != null) {
          newQual = createStringAnnotation(Collections.singletonList(stringVal));
          type.replaceAnnotation(newQual);
        }
      }

      return null;
    }
Example #28
0
 @SuppressWarnings("unchecked")
 @Override
 public A adapt(UriRef value, Class<A> type) {
   if (type.equals(URI.class)) {
     try {
       return (A) new URI(value.getUnicodeString());
     } catch (URISyntaxException e) {
       log.warn("Unable to parse an URI for UriRef " + value, e);
       return null;
     }
   } else if (type.equals(URL.class)) {
     try {
       return (A) new URL(value.getUnicodeString());
     } catch (MalformedURLException e) {
       log.warn("Unable to parse an URL for UriRef " + value, e);
     }
   } else if (type.equals(String.class)) {
     return (A) value.getUnicodeString();
   } else if (type.equals(UriRef.class)) { // Who converts UriRef -> UriRef ^
     return (A) value;
   } else {
     log.warn(type + " is not a supported target type for " + UriRef.class);
   }
   return null;
 }
 @SuppressWarnings("unchecked")
 @Override
 public <T> T getAdapter(Class<T> adapter) {
   if (adapter.equals(IUndoContext.class)) {
     return (T) undoContext;
   }
   if (adapter.equals(IProgressMonitor.class)) {
     if (progressDialog != null) {
       return (T) progressDialog.getProgressMonitor();
     }
   }
   if (site != null) {
     if (adapter.equals(Shell.class)) {
       return (T) getWorkbenchWindow().getShell();
     }
     if (adapter.equals(IWorkbenchWindow.class)) {
       return (T) getWorkbenchWindow();
     }
     if (adapter.equals(IWorkbenchPart.class)) {
       return (T) site.getPart();
     }
     // Refer all other requests to the part itself.
     // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=108144
     IWorkbenchPart part = site.getPart();
     if (part != null) {
       return Adapters.adapt(part, adapter);
     }
   }
   return null;
 }
  /** Function called when a proxy object function is invoked. */
  public Object invoke(Object proxy, Method method, Object[] args) throws LuaException {
    synchronized (obj.L) {
      String methodName = method.getName();
      LuaObject func = obj.getField(methodName);

      if (func.isNil()) {
        return null;
      }

      Class<?> retType = method.getReturnType();
      Object ret;

      // Checks if returned type is void. if it is returns null.
      if (retType.equals(Void.class) || retType.equals(void.class)) {
        func.call(args, 0);
        ret = null;
      } else {
        ret = func.call(args, 1)[0];
        if (ret != null && ret instanceof Double) {
          ret = LuaState.convertLuaNumber((Double) ret, retType);
        }
      }

      return ret;
    }
  }