Example usage for java.util Collections EMPTY_MAP

List of usage examples for java.util Collections EMPTY_MAP

Introduction

In this page you can find the example usage for java.util Collections EMPTY_MAP.

Prototype

Map EMPTY_MAP

To view the source code for java.util Collections EMPTY_MAP.

Click Source Link

Document

The empty map (immutable).

Usage

From source file:org.cloudfoundry.identity.uaa.login.util.LocalUaaRestTemplate.java

@Override
protected OAuth2AccessToken acquireAccessToken(OAuth2ClientContext oauth2Context)
        throws UserRedirectRequiredException {
    ClientDetails client = clientDetailsService.loadClientByClientId(getClientId());
    Set<String> scopes = new HashSet<>();
    for (GrantedAuthority authority : client.getAuthorities()) {
        scopes.add(authority.getAuthority());
    }/*from  w w  w. ja va 2 s  .c o m*/
    Set<String> resourceIds = new HashSet<>();
    resourceIds.add(Origin.UAA);
    Set<String> responseTypes = new HashSet<>();
    responseTypes.add("token");
    Map<String, String> requestParameters = new HashMap<>();
    requestParameters.put(OAuth2Utils.CLIENT_ID, "login");
    requestParameters.put(OAuth2Utils.GRANT_TYPE, "client_credentials");
    OAuth2Request request = new OAuth2Request(requestParameters, "login",
            (Collection<? extends GrantedAuthority>) Collections.EMPTY_SET, true, scopes, resourceIds, null,
            responseTypes, Collections.EMPTY_MAP);
    OAuth2Authentication authentication = new OAuth2Authentication(request, null);
    OAuth2AccessToken result = tokenServices.createAccessToken(authentication);
    oauth2Context.setAccessToken(result);
    return result;
}

From source file:edu.amc.sakai.user.SimpleLdapCandidateAttributeMapper.java

/**
 * Completes configuration of this instance.
 * /* ww  w. ja va 2 s.c o  m*/
 * <p>Initializes internal mappings to a copy of 
 * {@link AttributeMappingConstants#DEFAULT_ATTR_MAPPINGS} if 
 * the current map is empty. Initializes user 
 * type mapping strategy to a 
 * {@link EmptyStringUserTypeMapper} if no strategy
 * has been specified.
 * </p>
 * 
 * <p>This defaulting enables UDP config 
 * forward-compatibility.</p>
 * 
 */
public void init() {

    log.debug("init()");

    if (getAttributeMappings() == null || getAttributeMappings().isEmpty()) {
        log.debug("init(): creating default attribute mappings");
        setAttributeMappings(AttributeMappingConstants.CANDIDATE_ATTR_MAPPINGS);
    }

    if (getUserTypeMapper() == null) {
        setUserTypeMapper(new EmptyStringUserTypeMapper());
        log.debug("init(): created default user type mapper [mapper = {}]", getUserTypeMapper());
    }
    if (getValueMappings() == null) {
        setValueMappings(Collections.EMPTY_MAP);
        log.debug("init(): created default value mapper [mapper = {}]", getValueMappings());
    } else {
        // Check we have good value mappings and throw any out that aren't (warning user).
        Iterator<Entry<String, MessageFormat>> iterator = getValueMappings().entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<String, MessageFormat> entry = iterator.next();
            if (entry.getValue().getFormats().length != 1) {
                iterator.remove();
                log.warn("Removed value mapping as it didn't have one format: {} -> {}", entry.getKey(),
                        entry.getValue().toPattern());
            }
        }
    }
}

From source file:org.grails.plugin.freemarker.TagLibToDirectiveAndFunction.java

@SuppressWarnings("serial")
@Override/*from  w  w w .  j  av a2 s  . c  om*/
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
    if (log.isDebugEnabled()) {
        log.debug("exec(): @" + namespace + "." + tagName);
    }
    try {
        CharArrayWriter writer = new CharArrayWriter();
        tagInstance.invokeMethod("pushOut", writer);

        Object args = null;
        Object body = null;
        if (arguments != null) {
            if (arguments.size() > 0) {
                args = arguments.get(0);
            }
            if (arguments.size() > 1) {
                body = arguments.get(1);
            }
        }

        Object result = null;
        args = args != null ? unwrapParams((TemplateHashModelEx) args, Boolean.TRUE)
                : unwrapParams(Collections.EMPTY_MAP, Boolean.TRUE);
        if (log.isDebugEnabled()) {
            log.debug("exec(): args " + args);
            log.debug("exec(): body " + body);
        }

        if (tagInstance.getMaximumNumberOfParameters() == 1) {
            result = tagInstance.call(args);
        } else {
            Closure bodyClosure = EMPTY_BODY;

            if (body != null || hasReturnValue) {
                final Object fBody = body;
                bodyClosure = new Closure(this) {

                    @SuppressWarnings("unused")
                    public Object doCall(Object it) throws IOException, TemplateException {
                        return fBody;
                    }

                };
            }

            result = tagInstance.call(new Object[] { args, bodyClosure });
            if (result == null) {
                // writer.flush();
                result = writer.toString();
            }
        }

        return result;
    } catch (RuntimeException e) {
        throw new TemplateModelException(e);
    } finally {
        tagInstance.invokeMethod("popOut", null);
    }
}

From source file:de.betterform.agent.web.flux.FluxFacade.java

public List<XMLEvent> dispatchEventType(String id, String eventType, String sessionKey) throws XFormsException {
    return dispatchEventTypeWithContext(id, eventType, sessionKey, Collections.EMPTY_MAP);
}

From source file:de.betterform.session.DefaultSerializer.java

/**
 * inlines all instances from the processor into the output document. Eventually existent @src Attributes
 * have already been removed during the 'reset' transformation.
 *
 * @param out the output document for serialization
 *//*from w  w  w. j  a  v a2 s.c o  m*/
public void inlineInstances(Document out) throws XFormsException {
    //imlining instances
    NodeInfo context = getDocumentElementContext(out);
    //iterate all models to get all instances
    List models = this.processor.getContainer().getModels();
    for (int i = 0; i < models.size(); i++) {
        Model model = (Model) models.get(i);

        List instances = model.getInstances();
        for (int j = 0; j < instances.size(); j++) {
            Instance instance = (Instance) instances.get(j);
            String id = instance.getId();

            //get node from out
            String search = "//*[@id='" + id + "']";
            Node outInstance = XPathUtil.getAsNode(
                    XPathCache.getInstance().evaluate(context, search, Collections.EMPTY_MAP, null), 1);
            Node imported = out.adoptNode(instance.getInstanceDocument().getDocumentElement());
            if (imported == null) {
                throw new XFormsException("Root Element for Instance '" + instance.getId() + "' not found");
            }

            Node firstChild = DOMUtil.getFirstChildElement(outInstance);

            if (firstChild != null) {
                outInstance.removeChild(firstChild);
            }

            outInstance.appendChild(imported);
            //                    outInstance.replaceChild(imported,DOMUtil.getFirstChildElement(outInstance));

        }
    }
}

From source file:org.apache.cocoon.faces.context.ExternalContextImpl.java

public Map getRequestCookieMap() {
    // TODO: Implement getRequestCookieMap
    System.err.println("WARNING: getRequestCookieMap called.");
    return Collections.EMPTY_MAP;
}

From source file:de.hybris.platform.jdbcwrapper.GenericObjectPoolTest.java

private void runTest(final int threads, final int minIdle, final int max, final int durationSeconds,
        final int dbOutageIntervalSeconds, final int dbOutageDurationSeconds, final int closeSecondsBeforeEnd,
        final long holdTimeMs) {
    System.out.println("run test with " + threads + " threads, duration:" + durationSeconds + " s, minIdle:"
            + minIdle + ", maxActive:" + max + ", dbOutageInt:" + dbOutageIntervalSeconds
            + ", dbOutageDuration:" + dbOutageDurationSeconds + ", holdTimeAvg:" + holdTimeMs + " ms");

    final DummyPool pool = createPool(minIdle, max);

    final TestThreadsHolder<PoolAccessor> workers = new TestThreadsHolder<PoolAccessor>(threads, false) {
        @Override// www.java2s .  co m
        public PoolAccessor newRunner(final int threadNumber) {
            return new PoolAccessor(threadNumber, pool, holdTimeMs);
        }
    };

    workers.startAll();

    final long startMs = System.currentTimeMillis();
    final long endMs = startMs + (durationSeconds * 1000);
    final long closeBeforeEndMs = closeSecondsBeforeEnd > 0 ? endMs - (closeSecondsBeforeEnd * 1000) : -1;
    do {
        if (dbOutageDurationSeconds > 0) {
            if (!simulateOutage(pool, dbOutageIntervalSeconds, dbOutageDurationSeconds)) {
                break;
            }
        } else if (closeBeforeEndMs > 0 && closeBeforeEndMs < System.currentTimeMillis()) {
            try {
                pool.close();
            } catch (final Exception e) {
                System.err.println("error closing pool before workers end: " + e.getMessage());
                break;
            }
        } else {
            if (!sleepNoOutage(pool)) {
                break;
            }
        }
    } while (endMs > System.currentTimeMillis());

    assertTrue("not all workers finished in time", workers.stopAndDestroy(durationSeconds / 2));
    assertEquals(Collections.EMPTY_MAP, workers.getErrors());

    try {
        pool.close();
    } catch (final Exception e) {
        fail("error closing pool : " + e.getMessage());
    }

    // wait for unused connections to be evicted
    final long t = 2 * pool.getMinEvictableIdleTimeMillis();
    final long maxWaitForEviction = System.currentTimeMillis() + t;
    System.out.println("Waiting " + t + "ms for pool to evict unused connections");
    do {
        try {
            Thread.sleep(1000);
        } catch (final InterruptedException e1) {
            Thread.currentThread().interrupt();
            break;
        }
    } while (maxWaitForEviction > System.currentTimeMillis());

    //      assertEquals(minIdle, pool.getFactory().alive.get());
    //      assertEquals(0, pool.getFactory().active.get());

    assertEquals(0, pool.getFactory().alive.get());
    assertEquals(0, pool.getFactory().active.get());
}

From source file:de.betterform.xml.config.DefaultConfig.java

/**
 * Returns the specified configuration section in a hash map.
 * //  www .  j a v  a2s . c om
 * @param configContext
 *            the context holding the configuration.
 * @param sectionPath
 *            the context relative path to the section.
 * @param nameAttribute
 *            the name of the attribute to be used as a hash map key.
 * @param valueAttribute
 *            the name of the attribute to be used as a hash map value.
 * @return the specified configuration section in a hash map.
 * @throws Exception
 *             if any error occured during configuration loading.
 */
private HashMap load(NodeInfo configContext, String sectionPath, String nameAttribute, String valueAttribute)
        throws Exception {
    HashMap map = new HashMap();
    List nodeset = XPathCache.getInstance().evaluate(configContext, sectionPath, Collections.EMPTY_MAP, null);

    for (int i = 0; i < nodeset.size(); ++i) {
        Element element = (Element) XPathUtil.getAsNode(nodeset, i + 1);

        String attributeValue = StrSubstitutor.replaceSystemProperties(element.getAttribute(valueAttribute));

        map.put(element.getAttribute(nameAttribute), attributeValue);
    }

    return map;
}

From source file:marshalsec.SnakeYAML.java

/**
 * {@inheritDoc}//from  ww w.java  2  s  .  c  o  m
 *
 * @see marshalsec.gadgets.CommonsConfiguration#makeConfigurationMap(marshalsec.UtilFactory, java.lang.String[])
 */
@Override
@Args(minArgs = 1, args = { "jndiUrl" }, defaultArgs = { MarshallerBase.defaultJNDIUrl })
public Object makeConfigurationMap(UtilFactory uf, String[] args) throws Exception {
    return writeSet(writeObject(ConfigurationMap.class, Collections.EMPTY_MAP, 1,
            writeConstructor(JNDIConfiguration.class, true, writeConstructor(InitialContext.class, true),
                    writeString(args[0]))));
}

From source file:org.intermine.api.profile.ProfileManagerTest.java

private void setUpUserProfiles() throws Exception {
    PathQuery query = new PathQuery(Model.getInstanceByName("testmodel"));
    Date date = new Date();
    SavedQuery sq = new SavedQuery("query1", date, query);

    // bob's details
    String bobName = "bob";
    List<String> classKeys = new ArrayList<String>();
    classKeys.add("name");
    InterMineBag bag = new InterMineBag("bag1", "Department", "This is some description", new Date(),
            BagState.CURRENT, os, bobId, uosw, classKeys);

    Department deptEx = new Department();
    deptEx.setName("DepartmentA1");
    Set<String> fieldNames = new HashSet<String>();
    fieldNames.add("name");
    Department departmentA1 = (Department) os.getObjectByExample(deptEx, fieldNames);
    bag.addIdToBag(departmentA1.getId(), "Department");

    Department deptEx2 = new Department();
    deptEx2.setName("DepartmentB1");
    Department departmentB1 = (Department) os.getObjectByExample(deptEx2, fieldNames);
    bag.addIdToBag(departmentB1.getId(), "Department");

    ApiTemplate template = new ApiTemplate("template", "ttitle", "tcomment",
            new PathQuery(Model.getInstanceByName("testmodel")));

    bobProfile = new Profile(pm, bobName, bobId, bobPass, Collections.EMPTY_MAP, Collections.EMPTY_MAP,
            Collections.EMPTY_MAP, bobKey, true, false);
    pm.createProfile(bobProfile);/*from   ww  w  . j a  v  a 2s.c  o m*/
    bobProfile.saveQuery("query1", sq);
    bobProfile.saveBag("bag1", bag);
    bobProfile.saveTemplate("template", template);

    query = new PathQuery(Model.getInstanceByName("testmodel"));
    sq = new SavedQuery("query1", date, query);

    // sally details
    String sallyName = "sally";

    // employees and managers
    //    <bag name="sally_bag2" type="org.intermine.model.CEO">
    //        <bagElement type="org.intermine.model.CEO" id="1011"/>
    //    </bag>

    CEO ceoEx = new CEO();
    ceoEx.setName("EmployeeB1");
    fieldNames = new HashSet<String>();
    fieldNames.add("name");
    CEO ceoB1 = (CEO) os.getObjectByExample(ceoEx, fieldNames);

    InterMineBag objectBag = new InterMineBag("bag2", "Employee", "description", new Date(), BagState.CURRENT,
            os, sallyId, uosw, classKeys);
    objectBag.addIdToBag(ceoB1.getId(), "CEO");

    template = new ApiTemplate("template", "ttitle", "tcomment",
            new PathQuery(Model.getInstanceByName("testmodel")));
    sallyProfile = new Profile(pm, sallyName, sallyId, sallyPass, Collections.EMPTY_MAP, Collections.EMPTY_MAP,
            Collections.EMPTY_MAP, true, false);
    pm.createProfile(sallyProfile);
    sallyProfile.saveQuery("query1", sq);
    sallyProfile.saveBag("sally_bag1", objectBag);

    sallyProfile.saveTemplate("template", template);
}