private TypeDefinitionContainer createTypeDefinitionContainer(Map<String, TypeDefinition> allTypes, Map<String, Set<String>> typeDefChildren, String typeId, int depth, boolean includePropertyDefinitions, CmisVersion cmisVersion) { TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl(); result.setTypeDefinition(includePropertyDefinitions ? copy(allTypes.get(typeId), true, cmisVersion) : copy( allTypes.get(typeId), false, cmisVersion)); if (depth != 0) { if (typeDefChildren.containsKey(typeId)) { for (String child : typeDefChildren.get(typeId)) { result.getChildren().add( createTypeDefinitionContainer(allTypes, typeDefChildren, child, depth < 0 ? -1 : depth - 1, includePropertyDefinitions, cmisVersion)); } } } return result; }
/** * Converts a type definition list. */ @SuppressWarnings({ "unchecked" }) public static List<TypeDefinitionContainer> convertTypeDescendants(final List<Object> json) { if (json == null) { return null; } if (json.isEmpty()) { return Collections.emptyList(); } List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>(); for (Object obj : json) { if (obj instanceof Map) { Map<String, Object> jsonContainer = (Map<String, Object>) obj; TypeDefinitionContainerImpl container = new TypeDefinitionContainerImpl(); container.setTypeDefinition(convertTypeDefinition(getMap(jsonContainer.get(JSON_TYPESCONTAINER_TYPE)))); Object children = jsonContainer.get(JSON_TYPESCONTAINER_CHILDREN); if (children instanceof List) { container.setChildren(convertTypeDescendants((List<Object>) children)); } else { container.setChildren(Collections.<TypeDefinitionContainer> emptyList()); } convertExtension(jsonContainer, container, TYPESCONTAINER_KEYS); result.add(container); } } return result; }
/** * Converts a type definition list. */ @SuppressWarnings({ "unchecked" }) public static List<TypeDefinitionContainer> convertTypeDescendants(final List<Object> json) { if (json == null) { return null; } if (json.isEmpty()) { return Collections.emptyList(); } List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>(); for (Object obj : json) { if (obj instanceof Map) { Map<String, Object> jsonContainer = (Map<String, Object>) obj; TypeDefinitionContainerImpl container = new TypeDefinitionContainerImpl(); container.setTypeDefinition(convertTypeDefinition(getMap(jsonContainer.get(JSON_TYPESCONTAINER_TYPE)))); Object children = jsonContainer.get(JSON_TYPESCONTAINER_CHILDREN); if (children instanceof List) { container.setChildren(convertTypeDescendants((List<Object>) children)); } else { container.setChildren(Collections.<TypeDefinitionContainer> emptyList()); } convertExtension(jsonContainer, container, TYPESCONTAINER_KEYS); result.add(container); } } return result; }
/** * Adds a type to collection. */ private void addTypeInternal(AbstractTypeDefinition type) { if (type == null) { return; } TypeDefinitionContainerImpl tc = new TypeDefinitionContainerImpl(); tc.setTypeDefinition(type); // add to parent if (type.getParentTypeId() != null) { TypeDefinitionContainerImpl tdc = fTypes.get(type.getParentTypeId()); if (tdc != null) { if (tdc.getChildren() == null) { tdc.setChildren(new ArrayList<TypeDefinitionContainer>()); } tdc.getChildren().add(tc); } } fTypes.put(type.getId(), tc); }
/** * Internal method which adds a new type, without adding any property definitions automatically.<p> * * @param type the type to add */ private void addTypeInternal(AbstractTypeDefinition type) { if (type == null) { return; } if (m_types.containsKey(type.getId())) { // can't overwrite a type return; } TypeDefinitionContainerImpl tc = new TypeDefinitionContainerImpl(); tc.setTypeDefinition(type); // add to parent if (type.getParentTypeId() != null) { TypeDefinitionContainerImpl tdc = m_types.get(type.getParentTypeId()); if (tdc != null) { if (tdc.getChildren() == null) { tdc.setChildren(new ArrayList<TypeDefinitionContainer>()); } tdc.getChildren().add(tc); } } m_types.put(type.getId(), tc); m_typeList.add(tc); }
/** * Converts a type container list. */ public static List<TypeDefinitionContainer> convertTypeContainerList(List<CmisTypeContainer> typeContainers) { if (typeContainers == null) { return null; } List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>(); for (CmisTypeContainer container : typeContainers) { TypeDefinitionContainerImpl newConatiner = new TypeDefinitionContainerImpl(); newConatiner.setTypeDefinition(convert(container.getType())); newConatiner.setChildren(convertTypeContainerList(container.getChildren())); convertExtension(container, newConatiner); result.add(newConatiner); } return result; }
/** * Gathers the type descendants tree. */ private static TypeDefinitionContainer getTypesDescendants(int depth, TypeDefinitionContainer tc, boolean includePropertyDefinitions) { TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl(); TypeDefinition type = copyTypeDefinition(tc.getTypeDefinition()); if (!includePropertyDefinitions) { type.getPropertyDefinitions().clear(); } result.setTypeDefinition(type); if (depth != 0) { if (tc.getChildren() != null) { result.setChildren(new ArrayList<TypeDefinitionContainer>()); for (TypeDefinitionContainer tdc : tc.getChildren()) { result.getChildren().add( getTypesDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions)); } } } return result; }
/** * Collects the descendants of a type.<p> * * @param depth the depth up to which the descendants should be collected * @param tc the parent type * @param includePropertyDefinitions true if the property definitions should be included * * @return the descendants of the type */ private TypeDefinitionContainer getTypeDescendants( int depth, TypeDefinitionContainer tc, boolean includePropertyDefinitions) { TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl(); TypeDefinition type = copyTypeDefintion(tc.getTypeDefinition()); if (!includePropertyDefinitions) { type.getPropertyDefinitions().clear(); } result.setTypeDefinition(type); if (depth != 0) { if (tc.getChildren() != null) { result.setChildren(new ArrayList<TypeDefinitionContainer>()); for (TypeDefinitionContainer tdc : tc.getChildren()) { result.getChildren().add( getTypeDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions)); } } } return result; }
/** * Gathers the type descendants tree. */ private TypeDefinitionContainer getTypesDescendants( int depth, TypeDefinitionWrapper tdw, boolean includePropertyDefinitions) { TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl(); result.setTypeDefinition(tdw.getTypeDefinition(includePropertyDefinitions)); if (depth != 0) { String typeId = tdw.getTypeId(); List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId); if (children != null) { result.setChildren(new ArrayList<TypeDefinitionContainer>()); for (TypeDefinitionWrapper tdc : children) { result.getChildren().add( getTypesDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions)); } } } return result; }
/** * Gathers the type descendants tree. */ private TypeDefinitionContainer getTypesDescendants( int depth, TypeDefinitionWrapper tdw, boolean includePropertyDefinitions) { TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl(); result.setTypeDefinition(tdw.getTypeDefinition(includePropertyDefinitions)); if (depth != 0) { String typeId = tdw.getTypeId(); List<TypeDefinitionWrapper> children = connector.getOpenCMISDictionaryService().getChildren(typeId); if (children != null) { result.setChildren(new ArrayList<TypeDefinitionContainer>()); for (TypeDefinitionWrapper tdc : children) { result.getChildren().add( getTypesDescendants(depth < 0 ? -1 : depth - 1, tdc, includePropertyDefinitions)); } } } return result; }