private static Attributes encodeReference(char separator,Reference ref,Attributes attrs,Object orig) throws NamingException {
  if (ref == null)   return attrs;
  String s;
  if ((s=ref.getClassName()) != null) {
    attrs.put(new BasicAttribute(JAVA_ATTRIBUTES[CLASSNAME],s));
  }
  if ((s=ref.getFactoryClassName()) != null) {
    attrs.put(new BasicAttribute(JAVA_ATTRIBUTES[FACTORY],s));
  }
  if ((s=ref.getFactoryClassLocation()) != null) {
    attrs.put(new BasicAttribute(JAVA_ATTRIBUTES[CODEBASE],s));
  }
  if (orig != null && attrs.get(JAVA_ATTRIBUTES[TYPENAME]) != null) {
    Attribute tAttr=LdapCtxFactory.createTypeNameAttr(orig.getClass());
    if (tAttr != null) {
      attrs.put(tAttr);
    }
  }
  int count=ref.size();
  if (count > 0) {
    Attribute refAttr=new BasicAttribute(JAVA_ATTRIBUTES[REF_ADDR]);
    RefAddr refAddr;
    BASE64Encoder encoder=null;
    for (int i=0; i < count; i++) {
      refAddr=ref.get(i);
      if (refAddr instanceof StringRefAddr) {
        refAttr.add("" + separator + i+ separator+ refAddr.getType()+ separator+ refAddr.getContent());
      }
 else {
        if (encoder == null)         encoder=new BASE64Encoder();
        refAttr.add("" + separator + i+ separator+ refAddr.getType()+ separator+ separator+ encoder.encodeBuffer(serializeObject(refAddr)));
      }
    }
    attrs.put(refAttr);
  }
  return attrs;
}

private static Attributes encodeReference ( char separator , Reference ref , Attributes attrs , Object orig ) throws NamingException { if ( ref == null ) return attrs ; String s ; if ( ( s = ref . getClassName ( ) ) != null ) { attrs . put ( new BasicAttribute ( JAVA_ATTRIBUTES [ CLASSNAME ] , s ) ) ; } if ( ( s = ref . getFactoryClassName ( ) ) != null ) { attrs . put ( new BasicAttribute ( JAVA_ATTRIBUTES [ FACTORY ] , s ) ) ; } if ( ( s = ref . getFactoryClassLocation ( ) ) != null ) { attrs . put ( new BasicAttribute ( JAVA_ATTRIBUTES [ CODEBASE ] , s ) ) ; } if ( orig != null && attrs . get ( JAVA_ATTRIBUTES [ TYPENAME ] ) != null ) { Attribute tAttr = LdapCtxFactory . createTypeNameAttr ( orig . getClass ( ) ) ; if ( tAttr != null ) { attrs . put ( tAttr ) ; } } int count = ref . size ( ) ; if ( count > 0 ) { Attribute refAttr = new BasicAttribute ( JAVA_ATTRIBUTES [ REF_ADDR ] ) ; RefAddr refAddr ; BASE64Encoder encoder = null ; for ( int i = 0 ; i < count ; i ++ ) { refAddr = ref . get ( i ) ; if ( refAddr instanceof StringRefAddr ) { refAttr . add ( "" + separator + i + separator + refAddr . getType ( ) + separator + refAddr . getContent ( ) ) ; } else { if ( encoder == null ) encoder = new BASE64Encoder ( ) ; refAttr . add ( "" + separator + i + separator + refAddr . getType ( ) + separator + separator + encoder . encodeBuffer ( serializeObject ( refAddr ) ) ) ; } } attrs . put ( refAttr ) ; } return attrs ; }
convert a reference object into several ldap attributes . a reference is stored as into the following attributes : javaclassname value : reference . getclassname ( ) ; javafactory value : reference . getfactoryclassname ( ) ; javacodebase value : reference . getfactoryclasslocation ( ) ; javareferenceaddress value : # 0 # typea # vala value : # 1 # typeb # valb value : # 2 # typec # # [ serialized refaddr c ] value : # 3 # typed # vald where - the first character denotes the separator - the number following the first separator denotes the position of the refaddr within the reference - " typea " is refaddr . gettype ( ) - # # denotes that the base64 - encoded form of the non - stringrefaddr is to follow ; otherwise the value that follows is stringrefaddr . getcontents ( ) the default separator is the hash character ( # ) . may provide property for this in future .
