@Override public String getRandomPart(String topiaId) { return StringUtils.substringAfter(topiaId, getSeparator()); }
@Override public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, TopiaEntity topiaEntity) { String randomPart = UUID.randomUUID().toString(); String result = newTopiaId(entityClass, randomPart); return result; }
@Override public <E extends TopiaEntity> String newTopiaId(Class<E> entityClass, String randomPart) { if (!entityClass.isInterface()) { throw new IllegalArgumentException( "Only interface is permit to create id: " + entityClass); } String className = entityClass.getName(); Preconditions.checkArgument(!className.contains(getSeparator()), "Your entity class name must not contains the separator"); String result = className + getSeparator() + randomPart; return result; }
@Override public <E extends TopiaEntity> Class<E> getClassName(String topiaId) { String className = StringUtils.substringBefore(topiaId, getSeparator()); try { Class<E> entityClass = (Class<E>) Class.forName(className); return entityClass; } catch (ClassNotFoundException e) { throw new TopiaException("can't find class for topiaId = '" + topiaId + "'", e); } }
@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 = StringUtils.isNotBlank(split[1]); } catch (ClassNotFoundException eee) { // nothing to do, just return false if (log.isDebugEnabled()) { log.debug(eee); } } } } return isTopiaId; }