corba/src/share/classes/com/sun/corba/se/impl/naming/pcosnaming/PersistentBindingIterator.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.naming.pcosnaming;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
// Import general CORBA classes
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import org.omg.CORBA.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import org.omg.CORBA.INTERNAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
// Get org.omg.CosNaming Types
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import org.omg.CosNaming.Binding;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.CosNaming.BindingType;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CosNaming.BindingTypeHolder;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.CosNaming.NameComponent;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.PortableServer.POA;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
// Get base implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.impl.naming.pcosnaming.NamingContextImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.impl.naming.pcosnaming.InternalBindingValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import com.sun.corba.se.impl.naming.cosnaming.BindingIteratorImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
// Get a hash table
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * Class TransientBindingIterator implements the abstract methods
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 * defined by BindingIteratorImpl, to use with the TransientNamingContext
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * implementation of the NamingContextImpl. The TransientBindingIterator
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * implementation receives a hash table of InternalBindingValues, and uses
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * an Enumeration to iterate over the contents of the hash table.
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 * @see BindingIteratorImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 * @see TransientNamingContext
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
public class PersistentBindingIterator extends BindingIteratorImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    private POA biPOA;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
     * Constructs a new PersistentBindingIterator object.
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
     * @param orb a org.omg.CORBA.ORB object.
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
     * @param aTable A hashtable containing InternalBindingValues which is
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
     * the content of the PersistentNamingContext.
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
     * @param java.lang.Exception a Java exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
     * @exception Exception a Java exception thrown of the base class cannot
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
     * initialize.
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
   */
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    public PersistentBindingIterator(org.omg.CORBA.ORB orb, Hashtable aTable,
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        POA thePOA ) throws java.lang.Exception
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        super(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
        this.orb = orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        theHashtable = aTable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        theEnumeration = this.theHashtable.keys();
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        currentSize = this.theHashtable.size();
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        biPOA = thePOA;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
   * Returns the next binding in the NamingContext. Uses the enumeration
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
   * object to determine if there are more bindings and if so, returns
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
   * the next binding from the InternalBindingValue.
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
   * @param b The Binding as an out parameter.
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
   * @return true if there were more bindings.
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
   */
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    final public boolean NextOne(org.omg.CosNaming.BindingHolder b)
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        // If there are more elements get the next element
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        boolean hasMore = theEnumeration.hasMoreElements();
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        if (hasMore) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
            InternalBindingKey theBindingKey =
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
                 ((InternalBindingKey)theEnumeration.nextElement());
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            InternalBindingValue theElement =
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
                (InternalBindingValue)theHashtable.get( theBindingKey );
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            NameComponent n = new NameComponent( theBindingKey.id, theBindingKey.kind );
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            NameComponent[] nlist = new NameComponent[1];
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
            nlist[0] = n;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
            BindingType theType = theElement.theBindingType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
            b.value =
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
                new Binding( nlist, theType );
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
            // Return empty but marshalable binding
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
            b.value = new Binding(new NameComponent[0],BindingType.nobject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        return hasMore;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
   * Destroys this BindingIterator by disconnecting from the ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
   */
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    final public void Destroy()
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        // Remove the object from the Active Object Map.
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            byte[] objectId = biPOA.servant_to_id( this );
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
            if( objectId != null ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                biPOA.deactivate_object( objectId );
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        catch( Exception e ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            throw new INTERNAL( "Exception in BindingIterator.Destroy " + e );
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
   * Returns the remaining number of elements in the iterator.
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
   * @return the remaining number of elements in the iterator.
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
   */
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    public final int RemainingElements() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        return currentSize;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    private int currentSize;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    private Hashtable theHashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    private Enumeration theEnumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    private org.omg.CORBA.ORB orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
}