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