001/* 002 * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Bogdan Stefanescu 011 * Florent Guillaume 012 */ 013 014package org.nuxeo.ecm.core.schema.types; 015 016import java.util.Collection; 017import java.util.Collections; 018import java.util.LinkedHashMap; 019import java.util.List; 020import java.util.Map; 021 022/** 023 * A Composite Type resolves fields for several schemas. 024 */ 025public class CompositeTypeImpl extends ComplexTypeImpl implements CompositeType { 026 027 private static final long serialVersionUID = 1L; 028 029 /** The schemas for this composite type. */ 030 protected Map<String, Schema> schemas = new LinkedHashMap<String, Schema>(); 031 032 /** 033 * Constructs a composite type. Schemas must include those from the super type. 034 */ 035 public CompositeTypeImpl(CompositeType superType, String schema, String name, List<Schema> schemaList) { 036 super(superType, schema, name); 037 if (schemaList == null) { 038 schemaList = Collections.emptyList(); 039 } 040 for (Schema s : schemaList) { 041 schemas.put(s.getName(), s); 042 for (Field field : s.getFields()) { 043 addField(field); 044 } 045 } 046 } 047 048 @Override 049 public boolean hasSchemas() { 050 return !schemas.isEmpty(); 051 } 052 053 @Override 054 public Schema getSchema(String name) { 055 return schemas.get(name); 056 } 057 058 @Override 059 public boolean hasSchema(String name) { 060 return schemas.containsKey(name); 061 } 062 063 @Override 064 public String[] getSchemaNames() { 065 return schemas.keySet().toArray(new String[0]); 066 } 067 068 @Override 069 public Collection<Schema> getSchemas() { 070 return schemas.values(); 071 } 072 073 @Override 074 public Field getField(QName name) { 075 // TODO can this be unified with super behavior? 076 return fieldsByName.get(name.getPrefixedName()); 077 } 078 079 @Override 080 public boolean isComplexType() { 081 return false; 082 } 083 084 @Override 085 public boolean isCompositeType() { 086 return true; 087 } 088 089 @Override 090 public boolean validate(Object object) { 091 return true; 092 } 093 094}