Esempio n. 1
0
 public byte[] serialize() {
   if (nodeName.getLocalName() == null) throw new RuntimeException("Local name is null");
   final short id = getBroker().getSymbols().getSymbol(this);
   final byte idSizeType = Signatures.getSizeType(id);
   int prefixLen = 0;
   if (nodeName.needsNamespaceDecl()) {
     if (nodeName.getPrefix() != null && nodeName.getPrefix().length() > 0)
       prefixLen = UTF8.encoded(nodeName.getPrefix());
   }
   final int nodeIdLen = nodeId.size();
   final byte[] data =
       ByteArrayPool.getByteArray(
           LENGTH_SIGNATURE_LENGTH
               + NodeId.LENGTH_NODE_ID_UNITS
               + nodeIdLen
               + Signatures.getLength(idSizeType)
               + (nodeName.needsNamespaceDecl()
                   ? LENGTH_NS_ID + LENGTH_PREFIX_LENGTH + prefixLen
                   : 0)
               + value.UTF8Size());
   int pos = 0;
   data[pos] = (byte) (Signatures.Attr << 0x5);
   data[pos] |= idSizeType;
   data[pos] |= (byte) (attributeType << 0x2);
   if (nodeName.needsNamespaceDecl()) data[pos] |= 0x10;
   pos += StoredNode.LENGTH_SIGNATURE_LENGTH;
   ByteConversion.shortToByte((short) nodeId.units(), data, pos);
   pos += NodeId.LENGTH_NODE_ID_UNITS;
   nodeId.serialize(data, pos);
   pos += nodeIdLen;
   Signatures.write(idSizeType, id, data, pos);
   pos += Signatures.getLength(idSizeType);
   if (nodeName.needsNamespaceDecl()) {
     final short nsId = getBroker().getSymbols().getNSSymbol(nodeName.getNamespaceURI());
     ByteConversion.shortToByte(nsId, data, pos);
     pos += LENGTH_NS_ID;
     ByteConversion.shortToByte((short) prefixLen, data, pos);
     pos += LENGTH_PREFIX_LENGTH;
     if (nodeName.getPrefix() != null && nodeName.getPrefix().length() > 0)
       UTF8.encode(nodeName.getPrefix(), data, pos);
     pos += prefixLen;
   }
   value.UTF8Encode(data, pos);
   return data;
 }
Esempio n. 2
0
  public static StoredNode deserialize(
      byte[] data, int start, int len, DocumentImpl doc, boolean pooled) {
    int pos = start;
    byte idSizeType = (byte) (data[pos] & 0x3);
    boolean hasNamespace = (data[pos] & 0x10) == 0x10;
    int attrType = (data[pos] & 0x4) >> 0x2;
    pos += StoredNode.LENGTH_SIGNATURE_LENGTH;
    int dlnLen = ByteConversion.byteToShort(data, pos);
    pos += NodeId.LENGTH_NODE_ID_UNITS;
    NodeId dln = doc.getBroker().getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos);
    pos += dln.size();
    short id = (short) Signatures.read(idSizeType, data, pos);
    pos += Signatures.getLength(idSizeType);
    String name = doc.getSymbols().getName(id);
    if (name == null) throw new RuntimeException("no symbol for id " + id);
    short nsId = 0;
    String prefix = null;
    if (hasNamespace) {
      nsId = ByteConversion.byteToShort(data, pos);
      pos += LENGTH_NS_ID;
      int prefixLen = ByteConversion.byteToShort(data, pos);
      pos += LENGTH_PREFIX_LENGTH;
      if (prefixLen > 0) prefix = UTF8.decode(data, pos, prefixLen).toString();
      pos += prefixLen;
    }
    String namespace = nsId == 0 ? "" : doc.getSymbols().getNamespace(nsId);
    XMLString value = UTF8.decode(data, pos, len - (pos - start));

    // OK : we have the necessary material to build the attribute
    AttrImpl attr;
    if (pooled) attr = (AttrImpl) NodePool.getInstance().borrowNode(Node.ATTRIBUTE_NODE);
    //            attr = (AttrImpl)NodeObjectPool.getInstance().borrowNode(AttrImpl.class);
    else attr = new AttrImpl();
    attr.setNodeName(doc.getSymbols().getQName(Node.ATTRIBUTE_NODE, namespace, name, prefix));
    attr.value = value;
    attr.setNodeId(dln);
    if (dln == null) throw new RuntimeException("no node id " + id);
    attr.setType(attrType);
    return attr;
  }
Esempio n. 3
0
 public static StoredNode deserialize(
     byte[] data, int start, int len, DocumentImpl doc, boolean pooled) {
   TextImpl text;
   if (pooled) text = (TextImpl) NodePool.getInstance().borrowNode(Node.TEXT_NODE);
   //            text = (TextImpl)NodeObjectPool.getInstance().borrowNode(TextImpl.class);
   else text = new TextImpl();
   int pos = start;
   pos += LENGTH_SIGNATURE_LENGTH;
   int dlnLen = ByteConversion.byteToShort(data, pos);
   pos += NodeId.LENGTH_NODE_ID_UNITS;
   NodeId dln = doc.getBroker().getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos);
   text.setNodeId(dln);
   int nodeIdLen = dln.size();
   pos += nodeIdLen;
   text.cdata =
       UTF8.decode(
           data, pos, len - (LENGTH_SIGNATURE_LENGTH + nodeIdLen + NodeId.LENGTH_NODE_ID_UNITS));
   return text;
 }
Esempio n. 4
0
 public static void addToList(DBBroker broker, byte[] data, int start, int len, AttrList list) {
   int pos = start;
   byte idSizeType = (byte) (data[pos] & 0x3);
   boolean hasNamespace = (data[pos] & 0x10) == 0x10;
   int attrType = (data[pos] & 0x4) >> 0x2;
   pos += StoredNode.LENGTH_SIGNATURE_LENGTH;
   int dlnLen = ByteConversion.byteToShort(data, pos);
   pos += NodeId.LENGTH_NODE_ID_UNITS;
   NodeId dln = broker.getBrokerPool().getNodeFactory().createFromData(dlnLen, data, pos);
   pos += dln.size();
   short id = (short) Signatures.read(idSizeType, data, pos);
   pos += Signatures.getLength(idSizeType);
   String name = broker.getSymbols().getName(id);
   if (name == null) throw new RuntimeException("no symbol for id " + id);
   short nsId = 0;
   String prefix = null;
   if (hasNamespace) {
     nsId = ByteConversion.byteToShort(data, pos);
     pos += LENGTH_NS_ID;
     int prefixLen = ByteConversion.byteToShort(data, pos);
     pos += LENGTH_PREFIX_LENGTH;
     if (prefixLen > 0) prefix = UTF8.decode(data, pos, prefixLen).toString();
     pos += prefixLen;
   }
   String namespace = nsId == 0 ? "" : broker.getSymbols().getNamespace(nsId);
   String value;
   try {
     value = new String(data, pos, len - (pos - start), "UTF-8");
   } catch (UnsupportedEncodingException uee) {
     LOG.warn(uee);
     value = new String(data, pos, len - (pos - start));
   }
   list.addAttribute(
       broker.getSymbols().getQName(Node.ATTRIBUTE_NODE, namespace, name, prefix),
       value,
       attrType);
 }
 public static XMLString readData(NodeId nodeId, Value value, XMLString string) {
   final int nodeIdLen = nodeId.size();
   UTF8.decode(
       value.data(), value.start() + 3 + nodeIdLen, value.getLength() - 3 - nodeIdLen, string);
   return string;
 }