Java Code Examples for java.util.Hashtable.clone()

The following are Jave code examples for showing how to use clone() of the java.util.Hashtable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: CNCtx.java   View Source Code Vote up 6 votes
/**
 * This method is used by the iiop and iiopname URL Context factories.
 */
@SuppressWarnings("unchecked")
public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
throws NamingException {
    CNCtx ctx = new CNCtx();
    if (env != null) {
        env = (Hashtable<?,?>) env.clone();
    }
    ctx._env = (Hashtable<String, java.lang.Object>)env;
    String rest = ctx.initUsingUrl(
        env != null ?
            (org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
            : null,
        url, env);

    // rest is the INS name
    // Return the parsed form to prevent subsequent lookup
    // from parsing the string as a composite name
    // The caller should be aware that a toString() of the name,
    // which came from the environment will yield its INS syntax,
    // rather than a composite syntax
    return new ResolveResult(ctx, parser.parse(rest));
}
 
Example 2
Project: openjdk-jdk10   File: LazySearchEnumerationImpl.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")      // For Hashtable clone: env.clone()
public LazySearchEnumerationImpl(NamingEnumeration<Binding> candidates,
    AttrFilter filter, SearchControls cons,
    Context ctx, Hashtable<String, Object> env, boolean useFactory)
    throws NamingException {

        this.candidates = candidates;
        this.filter = filter;
        this.env = (Hashtable<String, Object>)
                ((env == null) ? null : env.clone());
        this.context = ctx;
        this.useFactory = useFactory;

        if(cons == null) {
            this.cons = new SearchControls();
        } else {
            this.cons = cons;
        }
}
 
Example 3
Project: OpenJSharp   File: DnsContext.java   View Source Code Vote up 6 votes
/**
 * Returns a DNS context for a given domain and servers.
 * Each server is of the form "server[:port]".
 * IPv6 literal host names include delimiting brackets.
 * There must be at least one server.
 * The environment must not be null; it is cloned before being stored.
 */
@SuppressWarnings("unchecked")
public DnsContext(String domain, String[] servers, Hashtable<?,?> environment)
        throws NamingException {

    this.domain = new DnsName(domain.endsWith(".")
                              ? domain
                              : domain + ".");
    this.servers = (servers == null) ? null : servers.clone();
    this.environment = (Hashtable<Object,Object>) environment.clone();
    envShared = false;
    parentIsDns = false;
    resolver = null;

    initFromEnvironment();
}
 
Example 4
Project: openjdk-jdk10   File: DnsContext.java   View Source Code Vote up 6 votes
/**
 * Returns a DNS context for a given domain and servers.
 * Each server is of the form "server[:port]".
 * IPv6 literal host names include delimiting brackets.
 * There must be at least one server.
 * The environment must not be null; it is cloned before being stored.
 */
@SuppressWarnings("unchecked")
public DnsContext(String domain, String[] servers, Hashtable<?,?> environment)
        throws NamingException {

    this.domain = new DnsName(domain.endsWith(".")
                              ? domain
                              : domain + ".");
    this.servers = (servers == null) ? null : servers.clone();
    this.environment = (Hashtable<Object,Object>) environment.clone();
    envShared = false;
    parentIsDns = false;
    resolver = null;

    initFromEnvironment();
}
 
Example 5
Project: jdk8u-jdk   File: DnsContext.java   View Source Code Vote up 6 votes
/**
 * Returns a DNS context for a given domain and servers.
 * Each server is of the form "server[:port]".
 * IPv6 literal host names include delimiting brackets.
 * There must be at least one server.
 * The environment must not be null; it is cloned before being stored.
 */
@SuppressWarnings("unchecked")
public DnsContext(String domain, String[] servers, Hashtable<?,?> environment)
        throws NamingException {

    this.domain = new DnsName(domain.endsWith(".")
                              ? domain
                              : domain + ".");
    this.servers = (servers == null) ? null : servers.clone();
    this.environment = (Hashtable<Object,Object>) environment.clone();
    envShared = false;
    parentIsDns = false;
    resolver = null;

    initFromEnvironment();
}
 
Example 6
Project: OpenJSharp   File: LazySearchEnumerationImpl.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")      // For Hashtable clone: env.clone()
public LazySearchEnumerationImpl(NamingEnumeration<Binding> candidates,
    AttrFilter filter, SearchControls cons,
    Context ctx, Hashtable<String, Object> env, boolean useFactory)
    throws NamingException {

        this.candidates = candidates;
        this.filter = filter;
        this.env = (Hashtable<String, Object>)
                ((env == null) ? null : env.clone());
        this.context = ctx;
        this.useFactory = useFactory;

        if(cons == null) {
            this.cons = new SearchControls();
        } else {
            this.cons = cons;
        }
}
 
Example 7
Project: OpenJSharp   File: DirectoryManager.java   View Source Code Vote up 6 votes
/**
  * Creates a context in which to continue a <tt>DirContext</tt> operation.
  * Operates just like <tt>NamingManager.getContinuationContext()</tt>,
  * only the continuation context returned is a <tt>DirContext</tt>.
  *
  * @param cpe
  *         The non-null exception that triggered this continuation.
  * @return A non-null <tt>DirContext</tt> object for continuing the operation.
  * @exception NamingException If a naming exception occurred.
  *
  * @see NamingManager#getContinuationContext(CannotProceedException)
  */
@SuppressWarnings("unchecked")
public static DirContext getContinuationDirContext(
        CannotProceedException cpe) throws NamingException {

    Hashtable<Object,Object> env = (Hashtable<Object,Object>)cpe.getEnvironment();
    if (env == null) {
        env = new Hashtable<>(7);
    } else {
        // Make a (shallow) copy of the environment.
        env = (Hashtable<Object,Object>) env.clone();
    }
    env.put(CPE, cpe);

    return (new ContinuationDirContext(cpe, env));
}
 
Example 8
Project: OpenJSharp   File: CNCtx.java   View Source Code Vote up 5 votes
/**
  * Create a CNCtx object. Gets the initial naming
  * reference for the COS Naming Service from the ORB.
  * The ORB can be passed in via the java.naming.corba.orb property
  * or be created using properties in the environment properties.
  * @param env Environment properties for initializing name service.
  * @exception NamingException Cannot initialize ORB or naming context.
  */
@SuppressWarnings("unchecked")
CNCtx(Hashtable<?,?> env) throws NamingException {
    if (env != null) {
        env = (Hashtable<?,?>)env.clone();
    }
    _env = (Hashtable<String, java.lang.Object>)env;
    federation = "true".equals(env != null ? env.get(FED_PROP) : null);
    initOrbAndRootContext(env);
}
 
Example 9
Project: OpenJSharp   File: LdapAttribute.java   View Source Code Vote up 5 votes
/**
 * sets the information needed to reconstruct the baseCtx if
 * we are serialized. This must be called _before_ the object is
 * serialized!!!
 */
@SuppressWarnings("unchecked") // clone()
private void setBaseCtxInfo() {
    Hashtable<String, Object> realEnv = null;
    Hashtable<String, Object> secureEnv = null;

    if (baseCtx != null) {
        realEnv = ((LdapCtx)baseCtx).envprops;
        this.baseCtxURL = ((LdapCtx)baseCtx).getURL();
    }

    if(realEnv != null && realEnv.size() > 0 ) {
        // remove any security credentials - otherwise the serialized form
        // would store them in the clear
        for (String key : realEnv.keySet()){
            if (key.indexOf("security") != -1 ) {

                //if we need to remove props, we must do it to a clone
                //of the environment. cloning is expensive, so we only do
                //it if we have to.
                if(secureEnv == null) {
                    secureEnv = (Hashtable<String, Object>)realEnv.clone();
                }
                secureEnv.remove(key);
            }
        }
    }

    // set baseCtxEnv depending on whether we removed props or not
    this.baseCtxEnv = (secureEnv == null ? realEnv : secureEnv);
}
 
Example 10
Project: jdk8u-jdk   File: LdapCtx.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public LdapCtx(String dn, String host, int port_number,
        Hashtable<?,?> props,
        boolean useSsl) throws NamingException {

    this.useSsl = this.hasLdapsScheme = useSsl;

    if (props != null) {
        envprops = (Hashtable<String, java.lang.Object>) props.clone();

        // SSL env prop overrides the useSsl argument
        if ("ssl".equals(envprops.get(Context.SECURITY_PROTOCOL))) {
            this.useSsl = true;
        }

        // %%% These are only examined when the context is created
        // %%% because they are only for debugging or workaround purposes.
        trace = (OutputStream)envprops.get(TRACE_BER);

        if (props.get(NETSCAPE_SCHEMA_BUG) != null ||
            props.get(OLD_NETSCAPE_SCHEMA_BUG) != null) {
            netscapeSchemaBug = true;
        }
    }

    currentDN = (dn != null) ? dn : "";
    currentParsedDN = parser.parse(currentDN);

    hostname = (host != null && host.length() > 0) ? host : DEFAULT_HOST;
    if (hostname.charAt(0) == '[') {
        hostname = hostname.substring(1, hostname.length() - 1);
    }

    if (port_number > 0) {
        this.port_number = port_number;
    } else {
        this.port_number = this.useSsl ? DEFAULT_SSL_PORT : DEFAULT_PORT;
        this.useDefaultPortNumber = true;
    }

    schemaTrees = new Hashtable<>(11, 0.75f);
    initEnv();
    try {
        connect(false);
    } catch (NamingException e) {
        try {
            close();
        } catch (Exception e2) {
            // Nothing
        }
        throw e;
    }
}
 
Example 11
Project: OpenJSharp   File: LdapCtx.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public LdapCtx(String dn, String host, int port_number,
        Hashtable<?,?> props,
        boolean useSsl) throws NamingException {

    this.useSsl = this.hasLdapsScheme = useSsl;

    if (props != null) {
        envprops = (Hashtable<String, java.lang.Object>) props.clone();

        // SSL env prop overrides the useSsl argument
        if ("ssl".equals(envprops.get(Context.SECURITY_PROTOCOL))) {
            this.useSsl = true;
        }

        // %%% These are only examined when the context is created
        // %%% because they are only for debugging or workaround purposes.
        trace = (OutputStream)envprops.get(TRACE_BER);

        if (props.get(NETSCAPE_SCHEMA_BUG) != null ||
            props.get(OLD_NETSCAPE_SCHEMA_BUG) != null) {
            netscapeSchemaBug = true;
        }
    }

    currentDN = (dn != null) ? dn : "";
    currentParsedDN = parser.parse(currentDN);

    hostname = (host != null && host.length() > 0) ? host : DEFAULT_HOST;
    if (hostname.charAt(0) == '[') {
        hostname = hostname.substring(1, hostname.length() - 1);
    }

    if (port_number > 0) {
        this.port_number = port_number;
    } else {
        this.port_number = this.useSsl ? DEFAULT_SSL_PORT : DEFAULT_PORT;
        this.useDefaultPortNumber = true;
    }

    schemaTrees = new Hashtable<>(11, 0.75f);
    initEnv();
    try {
        connect(false);
    } catch (NamingException e) {
        try {
            close();
        } catch (Exception e2) {
            // Nothing
        }
        throw e;
    }
}
 
Example 12
Project: jdk8u-jdk   File: InitialLdapContext.java   View Source Code Vote up 4 votes
/**
 * Constructs an initial context
 * using environment properties and connection request controls.
 * See <tt>javax.naming.InitialContext</tt> for a discussion of
 * environment properties.
 *
 * <p> This constructor will not modify its parameters or
 * save references to them, but may save a clone or copy.
 * Caller should not modify mutable keys and values in
 * <tt>environment</tt> after it has been passed to the constructor.
 *
 * <p> <tt>connCtls</tt> is used as the underlying context instance's
 * connection request controls.  See the class description
 * for details.
 *
 * @param environment
 *          environment used to create the initial DirContext.
 *          Null indicates an empty environment.
 * @param connCtls
 *          connection request controls for the initial context.
 *          If null, no connection request controls are used.
 *
 * @throws  NamingException if a naming exception is encountered
 *
 * @see #reconnect
 * @see LdapContext#reconnect
 */
@SuppressWarnings("unchecked")
public InitialLdapContext(Hashtable<?,?> environment,
                          Control[] connCtls)
        throws NamingException {
    super(true); // don't initialize yet

    // Clone environment since caller owns it.
    Hashtable<Object,Object> env = (environment == null)
        ? new Hashtable<>(11)
        : (Hashtable<Object,Object>)environment.clone();

    // Put connect controls into environment.  Copy them first since
    // caller owns the array.
    if (connCtls != null) {
        Control[] copy = new Control[connCtls.length];
        System.arraycopy(connCtls, 0, copy, 0, connCtls.length);
        env.put(BIND_CONTROLS_PROPERTY, copy);
    }
    // set version to LDAPv3
    env.put("java.naming.ldap.version", "3");

    // Initialize with updated environment
    init(env);
}
 
Example 13
Project: openjdk-jdk10   File: GenericURLContext.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked") // Expect Hashtable<String, Object>
public GenericURLContext(Hashtable<?,?> env) {
    // context that is not tied to any specific URL
    myEnv =
        (Hashtable<String, Object>)(env == null ? null : env.clone());
}
 
Example 14
Project: openjdk-jdk10   File: GenericURLContext.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked") // Expect Hashtable<String, Object>
public GenericURLContext(Hashtable<?,?> env) {
    // context that is not tied to any specific URL
    myEnv =
            (Hashtable<String, Object>)(env == null ? null : env.clone());
}
 
Example 15
Project: openjdk-jdk10   File: ImageFilter.java   View Source Code Vote up 3 votes
/**
 * Passes the properties from the source object along after adding a
 * property indicating the stream of filters it has been run through.
 * <p>
 * Note: This method is intended to be called by the ImageProducer
 * of the Image whose pixels are being filtered.  Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 *
 * @param props the properties from the source object
 * @exception NullPointerException if {@code props} is null
 */
public void setProperties(Hashtable<?,?> props) {
    @SuppressWarnings("unchecked")
    Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
    Object o = p.get("filters");
    if (o == null) {
        p.put("filters", toString());
    } else if (o instanceof String) {
        p.put("filters", ((String) o)+toString());
    }
    consumer.setProperties(p);
}
 
Example 16
Project: openjdk-jdk10   File: ReplicateScaleFilter.java   View Source Code Vote up 3 votes
/**
 * Passes along the properties from the source object after adding a
 * property indicating the scale applied.
 * This method invokes {@code super.setProperties},
 * which might result in additional properties being added.
 * <p>
 * Note: This method is intended to be called by the
 * {@code ImageProducer} of the {@code Image} whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 */
public void setProperties(Hashtable<?,?> props) {
    @SuppressWarnings("unchecked")
    Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
    String key = "rescale";
    String val = destWidth + "x" + destHeight;
    Object o = p.get(key);
    if (o != null && o instanceof String) {
        val = ((String) o) + ", " + val;
    }
    p.put(key, val);
    super.setProperties(p);
}
 
Example 17
Project: OpenJSharp   File: ReplicateScaleFilter.java   View Source Code Vote up 3 votes
/**
 * Passes along the properties from the source object after adding a
 * property indicating the scale applied.
 * This method invokes <code>super.setProperties</code>,
 * which might result in additional properties being added.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 */
public void setProperties(Hashtable<?,?> props) {
    Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
    String key = "rescale";
    String val = destWidth + "x" + destHeight;
    Object o = p.get(key);
    if (o != null && o instanceof String) {
        val = ((String) o) + ", " + val;
    }
    p.put(key, val);
    super.setProperties(p);
}
 
Example 18
Project: jdk8u-jdk   File: ReplicateScaleFilter.java   View Source Code Vote up 3 votes
/**
 * Passes along the properties from the source object after adding a
 * property indicating the scale applied.
 * This method invokes <code>super.setProperties</code>,
 * which might result in additional properties being added.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 */
public void setProperties(Hashtable<?,?> props) {
    Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
    String key = "rescale";
    String val = destWidth + "x" + destHeight;
    Object o = p.get(key);
    if (o != null && o instanceof String) {
        val = ((String) o) + ", " + val;
    }
    p.put(key, val);
    super.setProperties(p);
}
 
Example 19
Project: jdk8u-jdk   File: ImageFilter.java   View Source Code Vote up 3 votes
/**
 * Passes the properties from the source object along after adding a
 * property indicating the stream of filters it has been run through.
 * <p>
 * Note: This method is intended to be called by the ImageProducer
 * of the Image whose pixels are being filtered.  Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 *
 * @param props the properties from the source object
 * @exception NullPointerException if <code>props</code> is null
 */
public void setProperties(Hashtable<?,?> props) {
    Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
    Object o = p.get("filters");
    if (o == null) {
        p.put("filters", toString());
    } else if (o instanceof String) {
        p.put("filters", ((String) o)+toString());
    }
    consumer.setProperties(p);
}
 
Example 20
Project: OpenJSharp   File: CropImageFilter.java   View Source Code Vote up 2 votes
/**
 * Passes along  the properties from the source object after adding a
 * property indicating the cropped region.
 * This method invokes <code>super.setProperties</code>,
 * which might result in additional properties being added.
 * <p>
 * Note: This method is intended to be called by the
 * <code>ImageProducer</code> of the <code>Image</code> whose pixels
 * are being filtered. Developers using
 * this class to filter pixels from an image should avoid calling
 * this method directly since that operation could interfere
 * with the filtering operation.
 */
public void setProperties(Hashtable<?,?> props) {
    Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
    p.put("croprect", new Rectangle(cropX, cropY, cropW, cropH));
    super.setProperties(p);
}