@Override public String getRandomPart(String topiaId) { return StringUtils.substringAfter(topiaId, getSeparator()); }
@Override public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, String randomPart) { return entityClass.getName() + getSeparator() + System.currentTimeMillis() + '#' + randomPart; }
@Override public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, TopiaEntity topiaEntity) { if (!entityClass.isInterface()) { throw new IllegalArgumentException( "Only interface is permit to create id: " + entityClass); } double random = Math.random(); while (Double.toString(random).contains("E-")) { random = Math.random(); } return entityClass.getName() + getSeparator() + System.currentTimeMillis() + '#' + random; }
@Override public <E extends TopiaEntity> Class<E> getClassName(String topiaId) { String className = StringUtils.substringBefore(topiaId, getSeparator()); try { Class<E> result = (Class<E>)Class.forName(className); return result; } catch (ClassNotFoundException eee) { throw new TopiaNotFoundException("Can't find class for " + topiaId, eee); } }
@Override public boolean isTopiaId(String str) { boolean isTopiaId = false; if (str != null) { String[] split = str.split(getSeparator()); if (split.length >= 2) { String className = split[0]; try { Class.forName(className); isTopiaId = true; for (int index=1; index<split.length; index++) { isTopiaId &= StringUtils.isNoneBlank(split[index]); } } catch (ClassNotFoundException eee) { // nothing to do, just return false if (log.isDebugEnabled()) { log.debug(eee); } } } } return isTopiaId; } }