List of usage examples for org.apache.commons.collections CollectionUtils size
public static int size(Object object)
From source file:org.kuali.rice.krms.impl.ui.AgendaEditorMaintainable.java
/** * Retrieve a list of {@link RemotableAttributeField}s for the parameters (if any) required by the resolver for * the selected term in the proposition that is under edit. */// w ww. ja va2 s . c o m public List<RemotableAttributeField> retrieveTermParameters(View view, Object model, Container container) { List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>(); AgendaEditor agendaEditor = getAgendaEditor(model); // Figure out which rule is being edited RuleBo rule = agendaEditor.getAgendaItemLine().getRule(); if (null != rule) { // Figure out which proposition is being edited Tree<RuleTreeNode, String> propositionTree = rule.getPropositionTree(); Node<RuleTreeNode, String> editedPropositionNode = findEditedProposition( propositionTree.getRootElement()); if (editedPropositionNode != null) { PropositionBo propositionBo = editedPropositionNode.getData().getProposition(); if (StringUtils.isEmpty(propositionBo.getCompoundOpCode()) && CollectionUtils.size(propositionBo.getParameters()) > 0) { // Get the term ID; if it is a new parameterized term, it will have a special prefix PropositionParameterBo param = propositionBo.getParameters().get(0); if (StringUtils.isNotBlank(param.getValue()) && param.getValue().startsWith(KrmsImplConstants.PARAMETERIZED_TERM_PREFIX)) { String termSpecId = param.getValue() .substring(KrmsImplConstants.PARAMETERIZED_TERM_PREFIX.length()); TermResolverDefinition simplestResolver = getSimplestTermResolver(termSpecId, rule.getNamespace()); // Get the parameters and build RemotableAttributeFields if (simplestResolver != null) { List<String> parameterNames = new ArrayList<String>( simplestResolver.getParameterNames()); Collections.sort(parameterNames); // make param order deterministic for (String parameterName : parameterNames) { // TODO: also allow for DD parameters if there are matching type attributes RemotableTextInput.Builder controlBuilder = RemotableTextInput.Builder.create(); controlBuilder.setSize(64); RemotableAttributeField.Builder builder = RemotableAttributeField.Builder .create(parameterName); builder.setRequired(true); builder.setDataType(DataType.STRING); builder.setControl(controlBuilder); builder.setLongLabel(parameterName); builder.setShortLabel(parameterName); builder.setMinLength(Integer.valueOf(1)); builder.setMaxLength(Integer.valueOf(64)); results.add(builder.build()); } } } } } } return results; }
From source file:org.localmatters.serializer.config.SerializationElementHandler.java
/** * Resolves the extensions//from ww w. java 2s .c o m * @param extensions The map of requested extensions * @param parents The map of potential parents * @return The set of invalid references, if any */ @SuppressWarnings("unchecked") protected static Set<String> resolveExtensions(Map<ComplexSerialization, String> extensions, Map<String, ComplexSerialization> parents) { Set<String> invalids = new HashSet<String>(); int size = CollectionUtils.size(extensions); while (size != 0) { Iterator<Map.Entry<ComplexSerialization, String>> itr = extensions.entrySet().iterator(); while (itr.hasNext()) { Map.Entry<ComplexSerialization, String> extension = itr.next(); String id = extension.getValue(); ComplexSerialization parent = parents.get(id); if (parent == null) { itr.remove(); invalids.add(id); } else if (!extensions.containsKey(parent)) { itr.remove(); ComplexSerialization serialization = extension.getKey(); serialization.setAttributes(mergeAsList(parent.getAttributes(), serialization.getAttributes())); serialization.setElements(mergeAsList(parent.getElements(), serialization.getElements())); if (serialization.getWriteEmpty() == null) { serialization.setWriteEmpty(parent.isWriteEmpty()); } } } int newSize = CollectionUtils.size(extensions); if ((newSize != 0) && (newSize == size)) { throw new ConfigurationException(INVALID_LOOP_REFERENCES); } size = newSize; } return invalids; }
From source file:org.localmatters.serializer.config.SerializationElementHandler.java
/** * Handles the type of the element//from w ww. j a v a 2 s .c o m * which is a special case) * @param element The element * @param attributes The map of attributes consumed for this element * @return The serialization for this element */ @SuppressWarnings("unchecked") protected Serialization handleType(Element element, Map<String, String> attributes) { AbstractSerialization serialization = null; String type = element.getName(); if (TYPE_REFERENCE.equalsIgnoreCase(type)) { serialization = handleReference(element, attributes); } else if (TYPE_COMPLEX.equalsIgnoreCase(type)) { String parent = element.attributeValue(ATTRIBUTE_PARENT); if (StringUtils.isNotBlank(parent)) { attributes.put(ATTRIBUTE_PARENT, parent); } serialization = handleComplex(element, attributes); } else if (TYPE_ATTRIBUTE.equalsIgnoreCase(type)) { serialization = handleAttribute(element, attributes); } else if (TYPE_NAMESPACE.equalsIgnoreCase(type)) { serialization = handleNamespace(element, attributes); } else if (TYPE_VALUE.equalsIgnoreCase(type)) { serialization = handleValue(element, attributes); } else if (TYPE_LIST.equalsIgnoreCase(type)) { serialization = handleList(element, attributes); } else if (TYPE_MAP.equalsIgnoreCase(type)) { serialization = handleMap(element, attributes); } else { throw new ConfigurationException(INVALID_TYPE_FORMAT, type, element.getPath()); } String displayEmpty = element.attributeValue(ATTRIBUTE_DISPLAY_EMPTY); if (StringUtils.isNotBlank(displayEmpty)) { attributes.put(ATTRIBUTE_DISPLAY_EMPTY, displayEmpty); serialization.setWriteEmpty(Boolean.valueOf(displayEmpty)); } // validates the number of attributes with the ones that have been // consumed to see if the element contains invalid attributes if (CollectionUtils.size(element.attributes()) != CollectionUtils.size(attributes)) { List<String> invalids = new ArrayList<String>(); for (Element attribute : (List<Element>) element.attributes()) { String attributeName = attribute.getName(); if (!attributes.containsKey(attributeName)) { invalids.add(attributeName); } } throw new ConfigurationException(INVALID_ATTRIBUTES_FORMAT, invalids, type, element.getPath()); } return serialization; }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the <code>handleId</code> method *///from w w w .java 2s .c om public void testHandleId() { expect(element.attributeValue(ATTRIBUTE_ID)).andReturn("12345"); expect(element.attributeValue(ATTRIBUTE_NAME)).andReturn(null); expect(element.attributeValue(ATTRIBUTE_CONSTANT)).andReturn(null); expect(element.attributeValue(ATTRIBUTE_BEAN)).andReturn(null); expect(element.attributeValue(ATTRIBUTE_PROPERTY)).andReturn(null); expect(element.getName()).andReturn(TYPE_VALUE); expect(element.attributeValue(ATTRIBUTE_DISPLAY_EMPTY)).andReturn(null); expect(element.attributes()).andReturn(Arrays.asList("12345")); replay(element); Serialization result = handler.handleId(element, attributes, true); verify(element); assertTrue(result instanceof ValueSerialization); assertEquals(1, CollectionUtils.size(handler.getSerializations())); }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the <code>handleList</code> method *//*from w ww.j a v a2 s. c om*/ public void testHandleList() { Element child = createMock(Element.class); Element comment = createMock(Element.class); expect(element.elements()).andReturn(Arrays.asList(child, comment)); expect(child.getName()).andReturn(TYPE_VALUE); expect(child.attributeValue(ATTRIBUTE_ID)).andReturn(null); expect(child.attributeValue(ATTRIBUTE_NAME)).andReturn(null); expect(child.attributeValue(ATTRIBUTE_CONSTANT)).andReturn(null); expect(child.attributeValue(ATTRIBUTE_BEAN)).andReturn(null); expect(child.attributeValue(ATTRIBUTE_PROPERTY)).andReturn(null); expect(child.attributeValue(ATTRIBUTE_DISPLAY_EMPTY)).andReturn(null); expect(child.attributes()).andReturn(Collections.emptyList()); expect(child.getName()).andReturn(TYPE_VALUE); expect(comment.getName()).andReturn(TYPE_COMMENT); expect(comment.getStringValue()).andReturn("Hello World"); replay(element, child, comment); Serialization result = handler.handleList(element, attributes); verify(element, child, comment); assertTrue(result instanceof IteratorSerialization); IteratorSerialization ser = (IteratorSerialization) result; assertTrue(ser.getElement() instanceof ValueSerialization); assertFalse(ser.getElement().isWriteEmpty()); assertEquals(1, CollectionUtils.size(ser.getComments())); assertEquals("Hello World", ser.getComments().get(0)); }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the <code>handleType</code> method with a map *//* w w w. j ava 2s . c o m*/ public void testHandleTypeWhenMap() { Element comment = createMock(Element.class); expect(element.getName()).andReturn(TYPE_MAP); expect(element.elements()).andReturn(Arrays.asList(comment)); expect(comment.getName()).andReturn(TYPE_COMMENT); expect(comment.getStringValue()).andReturn("Hello Map"); expect(element.attributeValue(ATTRIBUTE_KEY)).andReturn(null); expect(element.attributeValue(ATTRIBUTE_DISPLAY_EMPTY)).andReturn("true"); expect(element.attributes()).andReturn(Arrays.asList("true")); replay(element, comment); Serialization result = handler.handleType(element, attributes); verify(element, comment); assertTrue(result instanceof MapSerialization); MapSerialization ser = (MapSerialization) result; assertTrue(ser.isWriteEmpty()); assertNull(ser.getKey()); assertTrue(ser.getValue() instanceof ValueSerialization); assertEquals(1, CollectionUtils.size(ser.getComments())); assertEquals("Hello Map", ser.getComments().get(0)); }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the <code>handleReference</code> method *///from ww w . java2s . co m public void testHandleReference() { expect(element.attributeValue(ATTRIBUTE_TARGET)).andReturn("12345"); replay(element); Serialization result = handler.handleReference(element, attributes); verify(element); assertTrue(result instanceof ReferenceSerialization); ReferenceSerialization serialization = (ReferenceSerialization) result; assertNull(serialization.getReferenced()); assertEquals(1, CollectionUtils.size(handler.getReferences())); assertTrue(handler.getReferences().containsKey(serialization)); assertEquals("12345", handler.getReferences().get(serialization)); }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the <code>handleComplex</code> method with name-space *//*from ww w . ja va 2 s . c o m*/ public void testHandleComplexWithNamespace() { Element namespace = createMock(Element.class); expect(element.elements()).andReturn(Arrays.asList(namespace)); expect(namespace.getName()).andReturn(TYPE_NAMESPACE); expect(namespace.attributeValue(ATTRIBUTE_ID)).andReturn(null); expect(namespace.attributeValue(ATTRIBUTE_NAME)).andReturn(null); expect(namespace.attributeValue(ATTRIBUTE_CONSTANT)).andReturn(null); expect(namespace.attributeValue(ATTRIBUTE_BEAN)).andReturn(null); expect(namespace.attributeValue(ATTRIBUTE_PROPERTY)).andReturn(null); expect(namespace.getName()).andReturn(TYPE_NAMESPACE); expect(namespace.attributeValue(ATTRIBUTE_DISPLAY_EMPTY)).andReturn(null); expect(namespace.getParent()).andReturn(element); expect(namespace.attributes()).andReturn(Collections.emptyList()); expect(element.getName()).andReturn(TYPE_COMPLEX); replay(element, namespace); Serialization result = handler.handleComplex(element, attributes); verify(element, namespace); assertTrue(result instanceof ComplexSerialization); ComplexSerialization ser = (ComplexSerialization) result; assertEquals(1, CollectionUtils.size(ser.getAttributes())); assertTrue(ser.getAttributes().get(0) instanceof NamespaceSerialization); assertTrue(CollectionUtils.isEmpty(ser.getElements())); assertTrue(CollectionUtils.isEmpty(ser.getComments())); }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the <code>handleComplex</code> method *//*from ww w . java 2s . c om*/ public void testHandleComplex() { Element attribute = createMock(Element.class); Element subElement = createMock(Element.class); Element comment = createMock(Element.class); expect(element.elements()).andReturn(Arrays.asList(attribute, comment, subElement)); expect(attribute.getName()).andReturn(TYPE_ATTRIBUTE); expect(attribute.attributeValue(ATTRIBUTE_ID)).andReturn(null); expect(attribute.attributeValue(ATTRIBUTE_NAME)).andReturn(null); expect(attribute.attributeValue(ATTRIBUTE_CONSTANT)).andReturn(null); expect(attribute.attributeValue(ATTRIBUTE_BEAN)).andReturn(null); expect(attribute.attributeValue(ATTRIBUTE_PROPERTY)).andReturn(null); expect(attribute.getName()).andReturn(TYPE_ATTRIBUTE); expect(attribute.attributeValue(ATTRIBUTE_DISPLAY_EMPTY)).andReturn(null); expect(attribute.getParent()).andReturn(element); expect(attribute.attributes()).andReturn(Collections.emptyList()); expect(element.getName()).andReturn(TYPE_COMPLEX); expect(comment.getName()).andReturn(TYPE_COMMENT); expect(comment.getStringValue()).andReturn("Hello World"); expect(subElement.getName()).andReturn(TYPE_VALUE); expect(subElement.attributeValue(ATTRIBUTE_ID)).andReturn(null); expect(subElement.attributeValue(ATTRIBUTE_NAME)).andReturn(null); expect(subElement.attributeValue(ATTRIBUTE_CONSTANT)).andReturn(null); expect(subElement.attributeValue(ATTRIBUTE_BEAN)).andReturn(null); expect(subElement.attributeValue(ATTRIBUTE_PROPERTY)).andReturn(null); expect(subElement.getName()).andReturn(TYPE_VALUE); expect(subElement.attributeValue(ATTRIBUTE_DISPLAY_EMPTY)).andReturn(null); expect(subElement.attributes()).andReturn(Collections.emptyList()); replay(element, attribute, comment, subElement); Serialization result = handler.handleComplex(element, attributes); verify(element, attribute, comment, subElement); assertTrue(result instanceof ComplexSerialization); ComplexSerialization ser = (ComplexSerialization) result; assertEquals(1, CollectionUtils.size(ser.getAttributes())); assertTrue(ser.getAttributes().get(0) instanceof AttributeSerialization); assertEquals(1, CollectionUtils.size(ser.getElements())); assertTrue(ser.getElements().get(0) instanceof ValueSerialization); assertEquals(1, CollectionUtils.size(ser.getComments())); assertEquals("Hello World", ser.getComments().get(0)); }
From source file:org.localmatters.serializer.config.SerializationElementHandlerTest.java
/** * Tests the <code>HandleComplex</code> method when has ID and parent *//*from w w w . j a v a 2 s .com*/ public void testHandleComplexWithIdAndParent() { attributes.put(ATTRIBUTE_ID, "54321"); attributes.put(ATTRIBUTE_PARENT, "12345"); expect(element.elements()).andReturn(null); replay(element); Serialization result = handler.handleComplex(element, attributes); verify(element); assertTrue(result instanceof ComplexSerialization); ComplexSerialization ser = (ComplexSerialization) result; assertTrue(CollectionUtils.isEmpty(ser.getAttributes())); assertTrue(CollectionUtils.isEmpty(ser.getElements())); assertEquals(1, CollectionUtils.size(handler.getComplexWithIds())); assertSame(ser, handler.getComplexWithIds().get("54321")); assertEquals(1, CollectionUtils.size(handler.getExtensions())); assertEquals("12345", handler.getExtensions().get(ser)); }