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

The following examples show how to use java.util.Hashtable#clone() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
  * 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 2
@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
/**
 * 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
/**
 * 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 5
/**
  * 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 6
Source Project: tomee   File: IvmContext.java    License: Apache License 2.0 5 votes vote down vote up
public IvmContext(final Hashtable<String, Object> environment) throws NamingException {
    this();
    if (environment == null) {
        throw new NamingException("Invalid Argument");
    } else {
        myEnv = (Hashtable<String, Object>) environment.clone();
    }

}
 
Example 7
/**
    Obtain a copy of this thread's MDC prior to serialization or
    asynchronous logging.  
 */
 public
 void getMDCCopy() {
   if(mdcCopyLookupRequired) {
     mdcCopyLookupRequired = false;
     // the clone call is required for asynchronous logging.
     // See also bug #5932.
     Hashtable t = (Hashtable) MDC.getContext();
     if(t != null) {
mdcCopy = (Hashtable) t.clone();
     }
   }
 }
 
Example 8
/**
 * 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 9
@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 10
Source Project: JDKSourceCode1.8   File: InitialLdapContext.java    License: MIT License 4 votes vote down vote up
/**
 * 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 11
@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 12
@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 13
/**
 * 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 14
/**
 * 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 15
/**
 * 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 16
/**
 * Constructs a new instance of Continuation.
 * @param top The name of the object that is to be resolved/operated upon.
 *          This becomes the Continuation's 'starter' and is used to
 *          calculate the "resolved name" when filling in a NamingException.
 * @param environment The environment used by the caller. It is used
 *          when setting the "environment" of a CannotProceedException.
 */
@SuppressWarnings("unchecked")  // For Hashtable clone: environment.clone()
public Continuation(Name top, Hashtable<?,?> environment) {
    super();
    starter = top;
    this.environment = (Hashtable<?,?>)
            ((environment == null) ? null : environment.clone());
}
 
Example 17
/**
 * 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
/**
 * 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
/**
 * Constructs a new instance of Continuation.
 * @param top The name of the object that is to be resolved/operated upon.
 *          This becomes the Continuation's 'starter' and is used to
 *          calculate the "resolved name" when filling in a NamingException.
 * @param environment The environment used by the caller. It is used
 *          when setting the "environment" of a CannotProceedException.
 */
@SuppressWarnings("unchecked")  // For Hashtable clone: environment.clone()
public Continuation(Name top, Hashtable<?,?> environment) {
    super();
    starter = top;
    this.environment = (Hashtable<?,?>)
            ((environment == null) ? null : environment.clone());
}
 
Example 20
Source Project: JDKSourceCode1.8   File: CropImageFilter.java    License: MIT License 2 votes vote down vote up
/**
 * 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);
}