Information

1
Story Points

Technologies

Decompiled Java File
package org.exolab.castor.dsml.jndi;

import java.util.Enumeration;
import java.util.Vector;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchResult;
import org.exolab.castor.dsml.Consumer;
import org.exolab.castor.dsml.ImportDescriptor;
import org.exolab.castor.dsml.ImportExportException;
import org.exolab.castor.dsml.Importer;
import org.exolab.castor.dsml.jndi.JNDIConsumer;

public class JNDIImporter extends Importer {
   private DirContext _ctx;

   public JNDIImporter(DirContext ctx) {
      this._ctx = ctx;
   }

   protected Consumer createConsumer() {
      return new JNDIConsumer();
   }

   public void importEntry(SearchResult result, int policy) throws NamingException {
      if(result.getAttributes().size() == 0) {
         if((policy & 1) != 0) {
            try {
               this._ctx.lookup(result.getName());
               this._ctx.unbind(result.getName());
               this.notify(result.getName(), 3);
            } catch (NameNotFoundException var9) {
               this.notify(result.getName(), 0);
            }
         } else {
            this.notify(result.getName(), 0);
         }
      } else {
         try {
            Attributes existing = this._ctx.getAttributes(result.getName());
            Vector except = new Vector();
            Attributes attrSet = result.getAttributes();
            NamingEnumeration enumeration = attrSet.getAll();

            Attribute attr;
            while(enumeration.hasMore()) {
               attr = (Attribute)enumeration.next();
               if(existing.get(attr.getID()) != null) {
                  if((policy & 8) == 0) {
                     if(attr.size() > 0) {
                        except.addElement(new ModificationItem(2, attr));
                     } else {
                        except.addElement(new ModificationItem(3, attr));
                     }
                  }
               } else if((policy & 16) == 0 && attr.size() > 0) {
                  except.addElement(new ModificationItem(1, attr));
               }
            }

            if((policy & 2) != 0) {
               enumeration = existing.getAll();

               while(enumeration.hasMore()) {
                  attr = (Attribute)enumeration.next();
                  if(attrSet.get(attr.getID()) == null) {
                     except.addElement(new ModificationItem(3, attr));
                  }
               }
            }

            if(except.size() > 0) {
               ModificationItem[] array = new ModificationItem[except.size()];
               except.copyInto(array);
               this._ctx.modifyAttributes(result.getName(), array);
               this.notify(result.getName(), 2);
            } else {
               this.notify(result.getName(), 0);
            }
         } catch (NameNotFoundException var10) {
            if((policy & 4) == 0) {
               this._ctx.bind(result.getName(), (Object)null, result.getAttributes());
               this.notify(result.getName(), 1);
            } else {
               this.notify(result.getName(), 0);
            }
         }
      }

   }

   public void importEntries(NamingEnumeration results) throws NamingException {
      if(this.getImportDescriptor() == null) {
         this.setImportDescriptor(new ImportDescriptor());
      }

      while(results.hasMore()) {
         SearchResult result = (SearchResult)results.next();
         this.importEntry(result, this.getImportDescriptor().getPolicy(result.getName()));
      }

   }

   public void importEntries(Enumeration results) throws ImportExportException {
      if(this.getImportDescriptor() == null) {
         this.setImportDescriptor(new ImportDescriptor());
      }

      try {
         while(results.hasMoreElements()) {
            SearchResult except = (SearchResult)results.nextElement();
            this.importEntry(except, this.getImportDescriptor().getPolicy(except.getName()));
         }

      } catch (NamingException var3) {
         throw new ImportExportException(var3);
      }
   }
}
Page generated: Oct 19, 2017 2:34:20 PM