List of usage examples for org.apache.commons.collections15 ExtendedMapUtils isEmpty
public static final boolean isEmpty(Map<?, ?> map)
From source file:org.apache.sshd.SshServerDevelopment.java
protected static final void testAuthorizedPublicKeysAuthenticator(BufferedReader in, PrintStream out, SshServer sshd) throws Exception { /*//from w w w . ja va2 s. co m { URL url=ANCHOR.getResource(ANCHOR.getSimpleName() + "-authorized_keys"); assertNotNull("Cannot find authorized keys resource", url); Collection<CryptoKeyEntry> entries=CryptoKeyEntry.readAuthorizedKeys(url); server.setPublickeyAuthenticator(PublickeyAuthenticatorUtils.authorizedKeysAuthenticator(entries)); } */ final CommandFactory cmdFactory = new CommandFactory() { @Override public Command createCommand(final String command) { return new AbstractCommand(command) { @Override public void start(Environment env) throws IOException { Map<String, String> values = env.getEnv(); if (ExtendedMapUtils.isEmpty(values)) { logger.warn("start(" + command + ") no environment"); } else { for (Map.Entry<String, String> e : values.entrySet()) { logger.info("start(" + command + ")[" + e.getKey() + "]: " + e.getValue()); } } try { Writer err = new CloseShieldWriter(new OutputStreamWriter(getErrorStream())); try { err.append(command).append(": N/A").append(SystemUtils.LINE_SEPARATOR); } finally { err.close(); } } finally { ExitCallback cbExit = getExitCallback(); cbExit.onExit(-1, "Failed"); } } }; } }; sshd.setCommandFactory(cmdFactory); sshd.setShellFactory(ECHO_SHELL); waitForExit(in, out, sshd); }
From source file:org.springframework.jdbc.repo.impl.AbstractRawPropertiesRepoImpl.java
@Override public E getEntity(String id, Transformer<Map<String, ?>, ? extends E> transformer) { if (transformer == null) { throw new IllegalArgumentException("getEntity(" + id + ") no transformer"); }/*from www .ja v a 2s . c o m*/ Map<String, Serializable> props = getProperties(id); if (ExtendedMapUtils.isEmpty(props)) { return null; } else { return transformer.transform(props); } }
From source file:org.springframework.jdbc.repo.impl.AbstractRawPropertiesRepoImpl.java
@Override public E removeEntity(String id, Transformer<Map<String, ?>, ? extends E> transformer) { if (transformer == null) { throw new IllegalArgumentException("removeEntity(" + id + ") no transformer"); }/* w w w . ja va 2 s .c o m*/ Map<String, Serializable> props = removeProperties(id); if (ExtendedMapUtils.isEmpty(props)) { return null; } else { return transformer.transform(props); } }
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImpl.java
@Override public Map<String, Serializable> removeProperties(String id) { Pair<?, Map<String, Serializable>> propVals = resolveProperties(id); Object internalId = (propVals == null) ? null : propVals.getLeft(); if (internalId == null) { return null; }//from w w w . j a va 2s .co m removeOwnerProperties(id, internalId); int nRows = jdbcAccessor.update( "DELETE FROM " + IDENTIFIED_ENTITIES_TABLE + " WHERE " + INTERNAL_ID_COL + " = :" + INTERNAL_ID_COL, Collections.singletonMap(INTERNAL_ID_COL, internalId)); if (nRows > 1) { logger.warn("removeProperties(" + getEntityClass().getSimpleName() + ")[" + id + "] unexpected rows count (" + nRows + ") for internal ID=" + internalId); } Map<String, Serializable> props = propVals.getRight(); if (ExtendedMapUtils.isEmpty(props)) { if (logger.isDebugEnabled()) { logger.debug( "removeProperties(" + getEntityClass().getSimpleName() + ")[" + id + "] no properties"); } return null; } if (logger.isDebugEnabled()) { logger.debug("removeProperties(" + getEntityClass().getSimpleName() + ")[" + id + "] properties count: " + props.size()); } return props; }
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImpl.java
@Override @SuppressWarnings("synthetic-access") public void setProperties(final String id, final Map<String, ?> props) { if (StringUtils.isEmpty(id)) { throw new IllegalArgumentException( "setProperties(" + getEntityClass().getSimpleName() + ") no identifier"); }// w w w .j a v a 2 s . c o m if (ExtendedMapUtils.isEmpty(props)) { throw new IllegalArgumentException( "setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "] no properties"); } validatePropertyValues(id, props); Object internalId = findInternalId(id); if (internalId == null) { internalId = createEntityEntry(id); } removeEntityProperties(id); Class<?> idType = internalId.getClass(); InternalIdSetter idSetter = InternalIdSetter.SETTERS_MAP.get(idType); if (idSetter == null) { throw new UnsupportedOperationException("setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "]" + " no identifier setter for type " + idType.getSimpleName()); } @SuppressWarnings("unchecked") Map<String, Object>[] batchValues = new Map[props.size()]; int batchIndex = 0; final Object assignedId = internalId; for (Map.Entry<String, ?> pe : props.entrySet()) { final String propName = pe.getKey(); Object orgValue = pe.getValue(); final Class<?> propType = JdbcOperationsUtils.resolveEffectivePropertyType(orgValue); final Object propValue = JdbcOperationsUtils.resolveEffectivePropertyValue(orgValue); batchValues[batchIndex] = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; { if (!conversionService.canConvert(propType, String.class)) { throw new UnsupportedOperationException( "setProperties(" + id + ")" + " cannot convert " + propName + "[" + propType.getSimpleName() + "]" + " to string for value=" + propValue); } put(PROP_OWNER_COL, assignedId); put(PROP_NAME_COL, propName); put(PROP_TYPE_COL, propType.getName()); put(PROP_VALUE_COL, conversionService.convert(propValue, String.class)); } }; batchIndex++; } try { int[] changeSet = jdbcAccessor.batchUpdate( "INSERT INTO " + ENTITY_PROPERTIES_TABLE + " (" + PROP_OWNER_COL + "," + PROP_NAME_COL + "," + PROP_TYPE_COL + "," + PROP_VALUE_COL + ")" + " VALUES(:" + PROP_OWNER_COL + ",:" + PROP_NAME_COL + ",:" + PROP_TYPE_COL + ",:" + PROP_VALUE_COL + ")", batchValues); if (logger.isDebugEnabled()) { logger.debug("setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "] batch size=" + ExtendedArrayUtils.length(changeSet)); } } catch (RuntimeException e) { logger.warn("setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "]" + " failed (" + e.getClass().getSimpleName() + ") to insert props=" + props + ": " + e.getMessage()); throw e; } }
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImpl.java
void validatePropertyValues(String id, Map<String, ?> props) { if (ExtendedMapUtils.isEmpty(props)) { return;//from ww w . jav a 2 s . c o m } final String vid = getEntityClass().getSimpleName() + "[" + id + "]"; for (Map.Entry<String, ?> pe : props.entrySet()) { JdbcOperationsUtils.validatePropertyValue(vid, pe.getKey(), pe.getValue(), conversionService); } }
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImpl.java
@Override protected <R> List<R> removeAll(Class<R> elementType, Transformer<Pair<String, Map<String, ?>>, ? extends R> transformer, Collection<String> ids) { Assert.notNull(elementType, "No removal result element type specified"); if (ExtendedCollectionUtils.isEmpty(ids)) { return Collections.emptyList(); }/*from www.j a v a 2 s . c om*/ List<R> result = new ArrayList<>(ids.size()); for (String id : ids) { Map<String, ?> props = removeProperties(id); if (ExtendedMapUtils.isEmpty(props)) { continue; } R element = transformer.transform(Pair.<String, Map<String, ?>>of(id, props)); if (element == null) { continue; } result.add(element); } return result; }
From source file:org.springframework.jdbc.repo.impl.RawPropertiesPolymorphicIdentifiedEntityRepoImpl.java
@Override public E findEntityById(String id) { Map<String, ?> props = repo.getProperties(id); if (ExtendedMapUtils.isEmpty(props)) { return null; }//from w ww . ja v a2s . c o m Object clazzType = props.get(CLASS_PROP_NAME); if (!(clazzType instanceof Class)) { throw new IllegalStateException("findEntityById(" + id + ") no effective class"); } Transformer<Map<String, ?>, E> transformer = getPropertiesTransformer((Class<?>) clazzType); if (transformer == null) { throw new IllegalStateException("findEntityById(" + id + ") no properties transformer"); } return transformer.transform(props); }
From source file:org.springframework.jdbc.repo.impl.RawPropertiesPolymorphicIdentifiedEntityRepoImpl.java
protected Pair<Transformer<Map<String, ?>, E>, Transformer<E, ? extends Map<String, ?>>> getEntityTransformers( final Class<?> eClass) { /*/*from w ww.j a v a2 s . c o m*/ * NOTE: there might be a "race condition" but we don't care since * result is the same either way */ Pair<Transformer<Map<String, ?>, E>, Transformer<E, ? extends Map<String, ?>>> pair; synchronized (transformersMap) { if ((pair = transformersMap.get(eClass)) != null) { return pair; } } Map<String, Pair<Method, Method>> entityAttributes = ExtendedBeanUtils .removeNonModifiableAttributes(ExtendedBeanUtils.describeBean(eClass, false, true)); @SuppressWarnings("unchecked") final Transformer<Map<String, ?>, E> pureEntityTransformer = ExtendedBeanUtils.propertiesToBeanTransformer( ExtendedConstructorUtils.newInstanceFactory((Class<E>) eClass), entityAttributes); Transformer<Map<String, ?>, E> props2entityTransformer = new Transformer<Map<String, ?>, E>() { @Override public E transform(Map<String, ?> beanProps) { Object value = beanProps.remove(CLASS_PROP_NAME); if (value == null) { throw new IllegalStateException( "transform(" + eClass.getSimpleName() + ") missing reserved type property"); } return pureEntityTransformer.transform(beanProps); } }; @SuppressWarnings("unchecked") final Transformer<E, ? extends Map<String, ?>> purePropsTransformer = ExtendedBeanUtils .beanToPropertiesTransformer((Class<E>) eClass, entityAttributes); Transformer<E, Map<String, ?>> entity2propsTransfomer = new Transformer<E, Map<String, ?>>() { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Map<String, ?> transform(E input) { Map<String, ?> beanProps = purePropsTransformer.transform(input); if (ExtendedMapUtils.isEmpty(beanProps)) { return beanProps; } Object value = beanProps.get(CLASS_PROP_NAME); if (value != null) { throw new IllegalStateException( "transform(" + input.getClass().getSimpleName() + ") reserved property used: " + value); } ((Map) beanProps).put(CLASS_PROP_NAME, eClass); return beanProps; } }; pair = Pair.<Transformer<Map<String, ?>, E>, Transformer<E, ? extends Map<String, ?>>>of( props2entityTransformer, entity2propsTransfomer); synchronized (transformersMap) { transformersMap.put(eClass, pair); } logger.info("getEntityTransformers(" + eClass.getSimpleName() + ") created transformers"); return pair; }
From source file:org.springframework.util.ExtendedPlaceholderResolverUtils.java
public static final NamedExtendedPlaceholderResolver toPlaceholderResolver(final Properties props) { if (ExtendedMapUtils.isEmpty(props)) { return EMPTY_RESOLVER; } else {// ww w . ja v a 2 s. com return new NamedExtendedPlaceholderResolver() { @Override public Collection<String> getPlaceholderNames() { return ExtendedCollectionUtils.collectToList(props.keySet(), ExtendedStringUtils.SAFE_TOSTRING_XFORMER); } @Override public String resolvePlaceholder(String placeholderName) { return props.getProperty(placeholderName); } @Override public String resolvePlaceholder(String placeholderName, String defaultValue) { return props.getProperty(placeholderName, defaultValue); } }; } }