Example usage for org.apache.commons.collections MultiHashMap get

List of usage examples for org.apache.commons.collections MultiHashMap get

Introduction

In this page you can find the example usage for org.apache.commons.collections MultiHashMap get.

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:org.geotools.xml.impl.BindingPropertyExtractor.java

public List properties(Object object, XSDElementDeclaration element) {
    List properties = new ArrayList();

    //first get all the properties that can be infered from teh schema
    List children = encoder.getSchemaIndex().getChildElementParticles(element);

    O: for (Iterator itr = children.iterator(); itr.hasNext();) {
        XSDParticle particle = (XSDParticle) itr.next();
        XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();

        if (child.isElementDeclarationReference()) {
            child = child.getResolvedElementDeclaration();
        }//from   w  w  w  .j a v a 2s .co m

        //get the object(s) for this element 
        GetPropertyExecutor executor = new GetPropertyExecutor(object, child);

        BindingVisitorDispatch.walk(object, encoder.getBindingWalker(), element, executor, context);

        if (executor.getChildObject() != null) {
            properties.add(new Object[] { particle, executor.getChildObject() });
        }
    }

    //second, get the properties which cannot be infereed from the schema
    GetPropertiesExecutor executor = new GetPropertiesExecutor(object, element);

    BindingVisitorDispatch.walk(object, encoder.getBindingWalker(), element, executor, context);

    if (!executor.getProperties().isEmpty()) {
        //group into a map of name, list
        MultiHashMap map = new MultiHashMap();

        for (Iterator p = executor.getProperties().iterator(); p.hasNext();) {
            Object[] property = (Object[]) p.next();
            map.put(property[0], property[1]);
        }

        //turn each map entry into a particle
        HashMap particles = new HashMap();

        for (Iterator e = map.entrySet().iterator(); e.hasNext();) {
            Map.Entry entry = (Map.Entry) e.next();

            //key could be a name or a particle
            if (entry.getKey() instanceof XSDParticle) {
                XSDParticle particle = (XSDParticle) entry.getKey();
                particles.put(Schemas.getParticleName(particle), particle);
                continue;
            }

            QName name = (QName) entry.getKey();
            Collection values = (Collection) entry.getValue();

            //check for comment
            if (Encoder.COMMENT.equals(name)) {
                //create a dom element which text nodes for the comments
                Element comment = encoder.getDocument().createElement(Encoder.COMMENT.getLocalPart());

                for (Iterator v = values.iterator(); v.hasNext();) {
                    comment.appendChild(encoder.getDocument().createTextNode(v.next().toString()));
                }

                XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();

                XSDElementDeclaration elementDecl = XSDFactory.eINSTANCE.createXSDElementDeclaration();
                elementDecl.setTargetNamespace(Encoder.COMMENT.getNamespaceURI());
                elementDecl.setName(Encoder.COMMENT.getLocalPart());
                elementDecl.setElement(comment);

                particle.setContent(elementDecl);
                particles.put(name, particle);

                continue;
            }

            //find hte element 
            XSDElementDeclaration elementDecl = encoder.getSchemaIndex().getElementDeclaration(name);

            if (elementDecl == null) {
                //look for the element declaration as a particle of the containing type
                XSDParticle particle = Schemas.getChildElementParticle(element.getType(), name.getLocalPart(),
                        true);
                if (particle != null) {
                    particles.put(name, particle);
                    continue;
                }
            }

            if (elementDecl == null) {
                //TODO: resolving like this will return an element no 
                // matter what, modifying the underlying schema, this might
                // be dangerous. What we shold do is force the schema to 
                // resolve all of it simports when the encoder starts
                elementDecl = encoder.getSchema().resolveElementDeclaration(name.getNamespaceURI(),
                        name.getLocalPart());
            }

            //look for a particle in the containing type which is either 
            // a) a base type of the element
            // b) in the same subsittuion group
            // if found use the particle to dervice multiplicity
            XSDParticle reference = null;
            for (Iterator p = Schemas.getChildElementParticles(element.getType(), true).iterator(); p
                    .hasNext();) {
                XSDParticle particle = (XSDParticle) p.next();
                XSDElementDeclaration el = (XSDElementDeclaration) particle.getContent();
                if (el.isElementDeclarationReference()) {
                    el = el.getResolvedElementDeclaration();
                }

                if (Schemas.isBaseType(elementDecl, el)) {
                    reference = particle;
                    break;
                }
            }

            //wrap the property in a particle
            XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
            XSDElementDeclaration wrapper = XSDFactory.eINSTANCE.createXSDElementDeclaration();
            wrapper.setResolvedElementDeclaration(elementDecl);
            particle.setContent(wrapper);
            //particle.setContent(elementDecl);

            //if there is a reference, derive multiplicity
            if (reference != null) {
                particle.setMaxOccurs(reference.getMaxOccurs());
            } else {
                //dervice from collection
                if (values.size() > 1) {
                    //make a multi property
                    particle.setMaxOccurs(-1);
                } else {
                    //single property
                    particle.setMaxOccurs(1);
                }
            }

            particles.put(name, particle);
        }

        //process the particles in order in which we got the properties
        for (Iterator p = executor.getProperties().iterator(); p.hasNext();) {
            Object[] property = (Object[]) p.next();
            Collection values = (Collection) map.get(property[0]);

            QName name;
            if (property[0] instanceof XSDParticle) {
                name = Schemas.getParticleName((XSDParticle) property[0]);
            } else {
                name = (QName) property[0];
            }

            XSDParticle particle = (XSDParticle) particles.get(name);

            if (particle == null) {
                continue; //already processed, must be a multi property
            }

            if (values.size() > 1) {
                //add as is, the encoder will unwrap
                properties.add(new Object[] { particle, values });
            } else {
                //unwrap it
                properties.add(new Object[] { particle, values.iterator().next() });
            }

            //done with this particle
            particles.remove(name);
        }
    }

    //return properties;        
    if (properties.size() <= 1) {
        return properties;
    }

    /*
     feature properties in the "properties" list may not be in the same order as they appear in the schema,
     because in the above implementation, simple attributes and complex attributes are processed separately.
              
     to maintain the feature properties order, sort the properties to their original order as in "children" list               
    */
    if (object instanceof ComplexAttributeImpl && propertiesSortable(properties, children)) {
        List sortedProperties = new ArrayList();

        //sort properties according to their XSDParticle order in "children"
        for (int i = 0; i < children.size(); i++) {
            XSDParticle particle = (XSDParticle) children.get(i);
            XSDElementDeclaration child = (XSDElementDeclaration) particle.getContent();
            if (child.getResolvedElementDeclaration() != null) {
                child = child.getResolvedElementDeclaration();
            }

            for (Iterator itr = properties.iterator(); itr.hasNext();) {
                Object[] prop = (Object[]) itr.next();
                XSDParticle part = (XSDParticle) prop[0];
                XSDElementDeclaration partContent = (XSDElementDeclaration) part.getContent();
                if (partContent.getResolvedElementDeclaration() != null) {
                    partContent = partContent.getResolvedElementDeclaration();
                }
                if (child.getName().equals(partContent.getName())
                        && ((child.getTargetNamespace() != null && partContent.getTargetNamespace() != null)
                                ? child.getTargetNamespace().equals(partContent.getTargetNamespace())
                                : true)) {
                    sortedProperties.add(prop);
                    properties.remove(prop);
                    i--;
                    break;
                }
            }
        }
        //return properties in order they appear in the schema
        return sortedProperties;
    } else {
        return properties;
    }
}

From source file:org.infoscoop.service.AuthCredentialService.java

public String addCredential(String uid, String authType, String authUid, String authPasswd, String authDomain,
        String targetUrl, MultiHashMap headerMap) {
    if (authType != null && "ntlm".equalsIgnoreCase(authType))
        authUid = authUid.toLowerCase();

    ProxyRequest proxy = new ProxyRequest(targetUrl, "NoOperation");
    proxy.setPortalUid(uid);/*ww w  . j ava2  s.  c o  m*/
    Set<String> keys = headerMap.keySet();
    for (String key : keys) {
        Collection<String> headers = (Collection<String>) headerMap.get(key);
        for (String header : headers) {
            proxy.putRequestHeader(key, header);
        }
    }
    proxy.putRequestHeader("authType", authType);
    proxy.putRequestHeader("authUserid", authUid);
    proxy.putRequestHeader("authpassword", authPasswd);
    int status = 0;
    try {
        if (authType != null && authType.indexOf("post") == 0) {
            status = proxy.executePost();
        } else {
            status = proxy.executeGet();
        }
    } catch (Exception e) {
        log.warn(e.getMessage());
    }
    if (status == 401) {
        return null;
    } else if (status < 200 || status >= 300) {
        throw new RuntimeException("Status " + status + " returned from " + targetUrl + ".");
    }

    AuthCredential c = new AuthCredential();
    c.setUid(uid);
    c.setAuthType(authType);
    c.setAuthUid(authUid);
    c.setAuthPasswd(authPasswd);
    c.setAuthDomain(authDomain);

    return authCredentialDAO.add(c).toString();
}

From source file:org.infoscoop.service.TabLayoutService.java

/**
 * Return map of Customization information related to role information.
 * Return default Customization information if role can not be found.
 *
 * @param resource/*from  w  w  w .  j a v a 2  s .  c o m*/
 * @return Map
 * <UL>
 *    <LI>key      : tabId</LI>
 *    <LI>value   : XmlObject</LI>
 * </UL>
 * @throws DataResourceException
 */
public Map getMyTabLayout(String tabId) {
    Map resultMap = new HashMap();
    Subject loginUser = SecurityController.getContextSubject();
    if (loginUser == null) {
        // Return default
        resultMap = getDefaultTabLayout(null);
    } else {
        long start = System.currentTimeMillis();
        MultiHashMap map = this.tabLayoutDAO.getTabLayout(tabId);
        Iterator ite = map.keySet().iterator();

        while (ite.hasNext()) {
            boolean isEmpty = true;
            String key = (String) ite.next();
            List layoutList = (List) map.get(key);

            Iterator docIte = layoutList.iterator();
            while (docIte.hasNext()) {
                TabLayout layout = (TabLayout) docIte.next();

                try {
                    if (RoleUtil.isPermitted(layout.getPrincipaltype(), layout.getRole())) {
                        isEmpty = false;
                        resultMap.put(key, layout);
                        break;
                    }
                } catch (ClassNotFoundException e) {
                    log.error("", e);
                }
            }

            if (isEmpty) {
                // Default of tab is obtained if tab information can not be found.
                putDefaultTabLayout(key, layoutList, resultMap);
            }
        }
    }
    Map map = sortMapBySortId(resultMap);
    return map;
}

From source file:org.infoscoop.service.TabLayoutService.java

/**
 * Obtain default tablayout information.
 *
 * @param resource/*from w ww  . ja  v a2s  .com*/
 * @param layoutMap
 * @return Map
 * <UL>
 *    <LI>key      : tabId</LI>
 *    <LI>value   : XmlObject</LI>
 * </UL>
 * @throws DataResourceException
 */
public Map getDefaultTabLayout(MultiHashMap layoutMap) {
    Map resultMap = new HashMap();
    if (layoutMap == null) {
        layoutMap = this.tabLayoutDAO.getTabLayout(null);
        //         layoutMap = TabLayoutDAO.newInstance().getTabLayout(null);
    }

    Iterator ite = layoutMap.keySet().iterator();
    while (ite.hasNext()) {
        String key = (String) ite.next();
        List tabList = (List) layoutMap.get(key);
        putDefaultTabLayout(key, tabList, resultMap);
    }
    return resultMap;
}

From source file:org.unigram.likelike.lsh.TestLSHRecommendations.java

private void check(MultiHashMap resultMap) {
    /* basic test cases */
    Collection coll = (Collection) resultMap.get(new Long(0));
    assertTrue(coll.size() >= 2 && coll.size() <= 4);
    coll = (Collection) resultMap.get(new Long(1));
    assertTrue(coll.size() >= 2 && coll.size() <= 4);
    coll = (Collection) resultMap.get(new Long(2));
    assertTrue(coll.size() >= 2 && coll.size() <= 4);
    coll = (Collection) resultMap.get(new Long(3));
    assertTrue(coll.size() >= 1 && coll.size() <= 3);

    /* examples with no recommendation */
    assertFalse(resultMap.containsKey(new Long(7)));
    assertFalse(resultMap.containsKey(new Long(8)));
}