001/*
002 * (C) Copyright 2006-20011 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 */
018
019package org.nuxeo.ecm.platform.reporting.api;
020
021import static org.nuxeo.ecm.platform.reporting.api.Constants.BIRT_REPORT_INSTANCE_SCHEMA;
022import static org.nuxeo.ecm.platform.reporting.api.Constants.BIRT_REPORT_MODEL_SCHEMA;
023
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.core.api.adapter.DocumentAdapterFactory;
026
027/**
028 * Factory for the {@link ReportModel} and {@link ReportInstance} adapters Adapters and bound to document types.
029 *
030 * @author Tiry (tdelprat@nuxeo.com)
031 */
032public class AdapterFactory implements DocumentAdapterFactory {
033
034    @Override
035    public Object getAdapter(DocumentModel doc, Class<?> adapterClass) {
036        if (doc == null) {
037            return null;
038        }
039
040        String adapterClassName = adapterClass.getSimpleName();
041        if (adapterClassName.equals(ReportInstance.class.getSimpleName())) {
042            if (doc.hasSchema(BIRT_REPORT_INSTANCE_SCHEMA)) {
043                return new BirtReportInstance(doc);
044            }
045        } else if (adapterClassName.equals(ReportModel.class.getSimpleName())) {
046            if (doc.hasSchema(BIRT_REPORT_MODEL_SCHEMA)) {
047                return new BirtReportModel(doc);
048            }
049        }
050        return null;
051    }
052
053}