public static SNode getAttribute(SNode node, IAttributeDescriptor descriptor) { Iterable<SNode> list = getAttributes(node, descriptor); if (Sequence.fromIterable(list).isEmpty()) { return null; } if (Sequence.fromIterable(list).count() > 1) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error( Sequence.fromIterable(list).count() + " nodes match single value attribute. The first found node returned as the value."); } if (LOG.isEnabledFor(Level.ERROR)) { LOG.error( " node=" + node.getReference() + "; attribute=" + ((String) BHReflection.invoke( SNodeOperations.asSConcept( SNodeOperations.getConcept(Sequence.fromIterable(list).first())), SMethodTrimmedId.create("getRole", null, "1653mnvAgoG"))) + " (" + Sequence.fromIterable(list).first().getNodeId() + ")"); } } return Sequence.fromIterable(list).first(); }
public static SNode setAttribute(SNode node, IAttributeDescriptor descriptor, SNode value) { Iterable<SNode> oldlist = getAttributes(node, descriptor); if (Sequence.fromIterable(oldlist).isEmpty() && (value != null)) { addAttribute(node, descriptor, value); } else if ((value == null)) { deleteAttribute(node, descriptor, value); } else { if (Sequence.fromIterable(oldlist).count() > 1) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error( Sequence.fromIterable(oldlist).count() + " nodes match signle value attribute during attribute replacing. Only the first found node replaced."); } if (LOG.isEnabledFor(Level.ERROR)) { LOG.error( " node=" + node.getReference() + "; attribute=" + ((String) BHReflection.invoke( SNodeOperations.asSConcept( SNodeOperations.getConcept(Sequence.fromIterable(oldlist).first())), SMethodTrimmedId.create("getRole", null, "1653mnvAgoG"))) + " (" + Sequence.fromIterable(oldlist).first().getNodeId() + ")"); } } SNodeOperations.replaceWithAnother(Sequence.fromIterable(oldlist).first(), value); descriptor.update(value); } return value; }