protected java.util.Iterator subElementIterator () throws BeanCoderException { final int type = this.currentType(); if (type == T_ARRAY || type == T_COLLECTION) return new IndexedIterator(this.currentNode()); return new ItemIterator(this.currentNode()); }
/** * A convenience method for decoding a bean from a JCR node. * A null namespace is used. */ public static Object decode (final javax.jcr.Node beanNode) throws BeanCoderException { return decode(null, beanNode); }
protected void beginMap (final java.util.Map map) throws BeanCoderException { beginWithClass(map); }
protected void encodeNull () throws BeanCoderException { beginElement(); this.currentNode() .setProperty(this.nsp + PN_CLASS, C_NULL, PropertyType.NAME); }
protected void encodeField (final String fieldName, final Object value) throws BeanCoderException { //log.debug("encodeField() '"+fieldName+"'"); final Node beanNode = this.currentNode(); this.currentItemName = fieldName; encode(value); //if (this.currentItem != beanNode) // endElement(); if (this.currentItem != beanNode) { this.previousItem = this.currentItem; this.currentItem = beanNode; } }
protected Object decodeFieldValue () throws BeanCoderException { if ( ! this.currentItem.isNode()) return decodePrimitive(); return decode(); }
/** * A convenience method for encoding a bean to a JCR repository. */ public static void encode (final String namespace, final javax.jcr.Node targetNode, final String beanNodeName, final Object bean) throws BeanCoderException { final Node n = (Node)JcrProxy.wrap(targetNode); final JcrBeanCoder jbc = new JcrBeanCoder(namespace, n, beanNodeName); jbc.encode(bean); }
/** * A convenience method for decoding a bean from a JCR node. */ public static Object decode (final String namespace, final javax.jcr.Node beanNode) throws BeanCoderException { final Node n = (Node)JcrProxy.wrap(beanNode); final JcrBeanCoder jbc = new JcrBeanCoder(namespace, n); return jbc.decode(); }
/** * Overriding the decodePrimitive() method of the parent class * to take care of binary values. */ protected Object decodePrimitive () throws BeanCoderException { final Class primitiveClass = currentClass(); if (primitiveClass != byte[].class) return super.decodePrimitive(); return decodeByteArray(); }
@Override protected Object[] asPropertyMapEntry(Object key, Object value) { if ((key instanceof StringAttribute) && isSafeForAnItemName(key.toString())) { if (value instanceof StringAttribute) { return new Object[]{key.toString(), value.toString()}; } } return super.asPropertyMapEntry(key, value); } }
protected void beginElement () throws BeanCoderException { if (this.currentItemName == null) // // use current node (todo #1560001) // return; this.currentItem = this.currentNode().addNode(this.currentItemName); this.currentItemName = null; // // will provoke NPEs :-) //log.debug("beginElement() '"+this.currentItem.getName()+"'"); }
protected void encodeEntry (final int index, final Object entry) throws BeanCoderException { this.currentItemName = this.nsp + index; encode(entry); }
protected String currentText () throws BeanCoderException { //if (this.currentProperty().getDefinition().isMultiple()) // text = this.currentProperty().getValues()[1].getString(); //else return this.currentProperty().getString(); }
protected Object[] asPropertyMapEntry (final Object key, final Object val) { if (isSafeForAnItemName(key) && (val == null || BeanCoderUtils.isPrimitive(val))) { return new Object[] { key, val }; } return null; }
protected void beginArray (int length) throws BeanCoderException { beginElement(); this.currentNode().setProperty (this.nsp + PN_SIZE, ""+length, PropertyType.LONG); }
protected void encodeByteArray (final byte[] array) throws BeanCoderException { this.currentNode().setProperty (this.currentItemName, new java.io.ByteArrayInputStream(array)); }
protected void beginCollection (final java.util.Collection col) throws BeanCoderException { beginWithClass(col); }
protected void beginWithClass (final Object bean) throws BeanCoderException { beginElement(); this.currentNode().setProperty (this.nsp + PN_CLASS, bean.getClass().getName()); }
protected int subElementCount () throws BeanCoderException { return (int)this.currentNode() .getProperty(this.nsp + PN_SIZE).getLong(); }
protected void encodePrimitive (final Object bean) throws BeanCoderException { this.currentNode().setProperty (this.currentItemName, bean.toString(), JcrValueUtils.getJcrType(bean)); }