001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (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 *     Thierry Delprat
016 */
017package org.nuxeo.apidoc.browse;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import javax.ws.rs.GET;
023import javax.ws.rs.Path;
024import javax.ws.rs.Produces;
025
026import org.nuxeo.apidoc.api.ComponentInfo;
027import org.nuxeo.apidoc.api.ExtensionInfo;
028import org.nuxeo.apidoc.api.ExtensionPointInfo;
029import org.nuxeo.apidoc.api.NuxeoArtifact;
030import org.nuxeo.apidoc.api.ServiceInfo;
031import org.nuxeo.ecm.webengine.model.WebObject;
032
033@WebObject(type = "component")
034public class ComponentWO extends NuxeoArtifactWebObject {
035
036    @Override
037    @GET
038    @Produces("text/html")
039    @Path("introspection")
040    public Object doGet() {
041        ComponentInfo ci = getTargetComponentInfo();
042        String bundleId = ci.getBundle().getBundleId();
043        return getView("view").arg("bundleId", bundleId).arg("component", ci);
044    }
045
046    public ComponentInfo getTargetComponentInfo() {
047        return getSnapshotManager().getSnapshot(getDistributionId(), ctx.getCoreSession()).getComponent(nxArtifactId);
048    }
049
050    @Override
051    public NuxeoArtifact getNxArtifact() {
052        return getTargetComponentInfo();
053    }
054
055    public List<ServiceWO> getServices() {
056        List<ServiceWO> result = new ArrayList<ServiceWO>();
057        ComponentInfo ci = getTargetComponentInfo();
058        for (ServiceInfo si : ci.getServices()) {
059            result.add((ServiceWO) ctx.newObject("service", si.getId()));
060        }
061        return result;
062    }
063
064    public List<ExtensionPointWO> getExtensionPoints() {
065        List<ExtensionPointWO> result = new ArrayList<ExtensionPointWO>();
066        ComponentInfo ci = getTargetComponentInfo();
067        for (ExtensionPointInfo ei : ci.getExtensionPoints()) {
068            result.add((ExtensionPointWO) ctx.newObject("extensionPoint", ei.getId()));
069        }
070        return result;
071    }
072
073    public List<ContributionWO> getContributions() {
074        List<ContributionWO> result = new ArrayList<ContributionWO>();
075        ComponentInfo ci = getTargetComponentInfo();
076        for (ExtensionInfo ei : ci.getExtensions()) {
077            result.add((ContributionWO) ctx.newObject("contribution", ei.getId()));
078        }
079        return result;
080    }
081
082}