001/*
002 * Copyright (c) 2006-2011 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 *     Nuxeo - initial API and implementation
011 *
012 * $Id$
013 */
014
015package org.nuxeo.ecm.core.api.adapter;
016
017import org.apache.commons.logging.Log;
018import org.apache.commons.logging.LogFactory;
019import org.nuxeo.common.xmap.annotation.XNode;
020import org.nuxeo.common.xmap.annotation.XObject;
021
022/**
023 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
024 */
025@XObject("adapter")
026public class DocumentAdapterDescriptor {
027
028    private static final Log log = LogFactory.getLog(DocumentAdapterDescriptor.class);
029
030    @XNode("@facet")
031    private String facet;
032
033    @XNode("@class")
034    private Class itf;
035
036    private DocumentAdapterFactory factory;
037
038    public DocumentAdapterDescriptor() {
039    }
040
041    public DocumentAdapterDescriptor(String facet, Class itf, DocumentAdapterFactory factory) {
042        this.facet = facet;
043        this.itf = itf;
044        this.factory = factory;
045    }
046
047    /**
048     * Used by XMap to set the factory.
049     */
050    @XNode("@factory")
051    void setFactory(Class<DocumentAdapterFactory> factoryClass) throws ReflectiveOperationException {
052        try {
053            factory = factoryClass.newInstance();
054        } catch (ReflectiveOperationException e) {
055            log.error("ERROR instantiating document adapter factory class!");
056            throw e;
057        }
058    }
059
060    public DocumentAdapterFactory getFactory() {
061        return factory;
062    }
063
064    public void setFactory(DocumentAdapterFactory factory) {
065        this.factory = factory;
066    }
067
068    public String getFacet() {
069        return facet;
070    }
071
072    public void setFacet(String facet) {
073        this.facet = facet;
074    }
075
076    public Class getInterface() {
077        return itf;
078    }
079
080    public void setInterface(Class itf) {
081        this.itf = itf;
082    }
083
084    @Override
085    public String toString() {
086        return facet + ": " + itf;
087    }
088
089}