001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.core.api.adapter;
023
024import org.apache.commons.logging.Log;
025import org.apache.commons.logging.LogFactory;
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XObject;
028
029/**
030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
031 */
032@XObject("adapter")
033public class DocumentAdapterDescriptor {
034
035    private static final Log log = LogFactory.getLog(DocumentAdapterDescriptor.class);
036
037    @XNode("@facet")
038    private String facet;
039
040    @XNode("@class")
041    private Class itf;
042
043    private DocumentAdapterFactory factory;
044
045    public DocumentAdapterDescriptor() {
046    }
047
048    public DocumentAdapterDescriptor(String facet, Class itf, DocumentAdapterFactory factory) {
049        this.facet = facet;
050        this.itf = itf;
051        this.factory = factory;
052    }
053
054    /**
055     * Used by XMap to set the factory.
056     */
057    @XNode("@factory")
058    void setFactory(Class<DocumentAdapterFactory> factoryClass) throws ReflectiveOperationException {
059        try {
060            factory = factoryClass.newInstance();
061        } catch (ReflectiveOperationException e) {
062            log.error("ERROR instantiating document adapter factory class!");
063            throw e;
064        }
065    }
066
067    public DocumentAdapterFactory getFactory() {
068        return factory;
069    }
070
071    public void setFactory(DocumentAdapterFactory factory) {
072        this.factory = factory;
073    }
074
075    public String getFacet() {
076        return facet;
077    }
078
079    public void setFacet(String facet) {
080        this.facet = facet;
081    }
082
083    public Class getInterface() {
084        return itf;
085    }
086
087    public void setInterface(Class itf) {
088        this.itf = itf;
089    }
090
091    @Override
092    public String toString() {
093        return facet + ": " + itf;
094    }
095
096}