001/*
002 * (C) Copyright 2006-2007 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 *     dragos
018 *
019 * $Id$
020 */
021package org.nuxeo.ecm.platform.rendering.impl;
022
023import org.nuxeo.common.xmap.annotation.XNode;
024import org.nuxeo.ecm.platform.rendering.RenderingEngine;
025
026/**
027 * Rendering Engine Descriptor objects instantiated with configuration from contributions like:
028 *
029 * <pre>
030 *  &lt;engine name=”the_format_name” class=”rendering_engine_impl_class”/&gt;
031 * </pre>
032 *
033 * . Also instantiate rendering engine as defined in contribution.
034 *
035 * @author <a href="mailto:dm@nuxeo.com">Dragos Mihalache</a>
036 */
037public class RenderingEngineDescriptor {
038
039    @XNode("format")
040    private String format;
041
042    @XNode("class")
043    private Class<RenderingEngine> klass;
044
045    public String getFormat() {
046        return format;
047    }
048
049    public void setFormat(String name) {
050        format = name;
051    }
052
053    public Class<?> getEngineClass() {
054        return klass;
055    }
056
057    public RenderingEngine newInstance() throws ReflectiveOperationException {
058        return klass.getDeclaredConstructor().newInstance();
059    }
060
061    @Override
062    public String toString() {
063        StringBuilder sb = new StringBuilder();
064        sb.append(RenderingEngineDescriptor.class.getSimpleName());
065        sb.append(" {name=");
066        sb.append(format);
067        sb.append(", class=");
068        sb.append(klass);
069        sb.append(" }");
070
071        return sb.toString();
072    }
073}