protected void encodeByteArray (final byte[] array) throws BeanCoderException { this.currentNode().setProperty (this.currentItemName, new java.io.ByteArrayInputStream(array)); }
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 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 void beginWithClass (final Object bean) throws BeanCoderException { beginElement(); this.currentNode().setProperty (this.nsp + PN_CLASS, bean.getClass().getName()); }
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()); }
protected void encodePrimitive (final Object bean) throws BeanCoderException { this.currentNode().setProperty (this.currentItemName, bean.toString(), JcrValueUtils.getJcrType(bean)); }
protected int subElementCount () throws BeanCoderException { return (int)this.currentNode() .getProperty(this.nsp + PN_SIZE).getLong(); }
protected void encodeNull () throws BeanCoderException { beginElement(); this.currentNode() .setProperty(this.nsp + PN_CLASS, C_NULL, PropertyType.NAME); }
protected void beginArray (int length) throws BeanCoderException { beginElement(); this.currentNode().setProperty (this.nsp + PN_SIZE, ""+length, PropertyType.LONG); }
protected String currentClassName () throws BeanCoderException { if ( ! this.currentItem.isNode()) return currentPrimitiveClass().getName(); if ( ! this.currentNode().hasProperty(this.nsp + PN_CLASS)) return null; return this.currentNode() .getProperty(this.nsp + PN_CLASS).getString(); }
protected void beginBean (final Object bean) throws BeanCoderException { beginWithClass(bean); if (BeanCoderUtils.isPrimitive(bean)) // // this may happen, for map entry keys that are primitive but // whose value is not a primitive { this.currentNode() .setProperty(this.nsp + PN_PVALUE, bean.toString()); } }
/** * Overriding encode() to remove potential previous nodes with the * same name ('override'). Only occurs at the very beginning of * the encoding work. */ public void encode (final Object o) throws BeanCoderException { if (this.override && ( ! this.overrideDone)) { final java.util.Iterator it = this.currentNode().getNodes(); while (it.hasNext()) { final Node n = (Node)it.next(); if (n.getName().equals(this.currentItemName)) n.remove(); } this.overrideDone = true; } super.encode(o); }
this.currentNode().setProperty(key.toString(), sVal, tVal); final Node mapNode = this.currentNode();
/** * Overriding decodeBean() to intercept decode request for * primitive encoded as beans (it occurs for certains map keys). */ protected Object decodeBean () throws BeanCoderException { if (this.currentNode().hasProperty(this.nsp + PN_PVALUE)) { return BeanCoderUtils.newPrimitive (currentClass(), this.currentNode().getProperty (this.nsp + PN_PVALUE).getString()); } return super.decodeBean(); }
protected int currentType () throws BeanCoderException { if (this.currentItem instanceof Property) return T_PRIMITIVE; final String className = currentClassName(); if (className == null) { if (this.currentNode().hasProperty(this.nsp + PN_SIZE)) return T_ARRAY; throw new JcrException ("property 'class' is missing "+ "("+this.currentItem.getPath()+")"); } if (className.equals(C_NULL)) { return T_NULL; } final Class c = currentClass(); //if (byte[].class == c) // return T_BYTE_ARRAY; if (java.util.Map.class.isAssignableFrom(c)) return T_MAP; if (java.util.Collection.class.isAssignableFrom(c)) return T_COLLECTION; return T_BEAN; }
protected Class currentClass () throws BeanCoderException { if ( ! this.currentItem.isNode()) return currentPrimitiveClass(); String className = null; try { className = this.currentNode() .getProperty(this.nsp + PN_CLASS).getString(); return Class.forName(className); } catch (final JcrException e) { throw e; } catch (final Throwable t) { throw new BeanCoderException ("failed to find class named '"+className+"'", t); } }
final Node nk = this.currentNode();