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 *     bstefanescu
011 */
012package org.nuxeo.ecm.webengine.jaxrs.servlet.config;
013
014import org.nuxeo.ecm.webengine.jaxrs.ApplicationManager;
015import org.nuxeo.ecm.webengine.jaxrs.views.BundleResource;
016import org.nuxeo.common.xmap.annotation.XNode;
017import org.nuxeo.common.xmap.annotation.XObject;
018import org.osgi.framework.Bundle;
019
020/**
021 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
022 */
023@XObject("resource")
024public class ResourceExtension {
025
026    private Bundle bundle;
027
028    @XNode("@class")
029    protected Class<? extends BundleResource> clazz;
030
031    @XNode("@target")
032    protected String target;
033
034    @XNode("@segment")
035    protected String segment;
036
037    @XNode("@application")
038    protected String application = ApplicationManager.DEFAULT_HOST;
039
040    public ResourceExtension() {
041
042    }
043
044    public ResourceExtension(Bundle bundle, Class<? extends BundleResource> clazz) {
045        this.bundle = bundle;
046        this.clazz = clazz;
047    }
048
049    public void setBundle(Bundle bundle) {
050        this.bundle = bundle;
051    }
052
053    public Bundle getBundle() {
054        return bundle;
055    }
056
057    public String getTarget() {
058        return target;
059    }
060
061    public String getSegment() {
062        return segment;
063    }
064
065    public void setTarget(String target) {
066        this.target = target;
067    }
068
069    public void setSegment(String segment) {
070        this.segment = segment;
071    }
072
073    public String getApplication() {
074        return application;
075    }
076
077    public void setApplication(String application) {
078        this.application = application;
079    }
080
081    public Class<? extends BundleResource> getResourceClass() {
082        return clazz;
083    }
084
085    public String getId() {
086        return target + "#" + segment;
087    }
088
089    @Override
090    public String toString() {
091        return bundle.getSymbolicName() + ":" + target + "#" + segment;
092    }
093}