All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jugs.webdav.interop.WebDavApplication Maven / Gradle / Ivy

Go to download

A project which focus on a solution for interoperability issues of WebDAV clients.

The newest version!
/*
 * Copyright 2008, 2009 Daniel MANZKE
 *
 * This file is part of webdav-jaxrs.
 *
 * webdav-jaxrs is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * webdav-jaxrs is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with webdav-jaxrs.  If not, see .
 */
package org.jugs.webdav.interop;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;

import javax.ws.rs.core.Application;
import javax.xml.bind.JAXBException;

import org.jugs.webdav.jaxrs.xml.WebDavContextResolver;
import org.slf4j.LoggerFactory;


public class WebDavApplication extends Application {

	private static final Logger logger = LoggerFactory.getLogger(WebDavApplication.class);
	protected Set> entityClasses = new HashSet>();
	protected Set> serviceClasses = new HashSet>();

	public WebDavApplication(Class... serviceClasses) {
		registerService(serviceClasses);
		registerService(WindowsRedirectorPatchResource.class);
		registerEntity(WindowsRedirectorPatchProperty.class);
	}
	
	public void registerEntity(Class... additionalClasses){
		entityClasses.addAll(Arrays.asList(additionalClasses));
	}
	
	public void registerService(Class... additionalClasses){
		serviceClasses.addAll(Arrays.asList(additionalClasses));
	}

	@Override
	public Set> getClasses() {
		return serviceClasses;
	}
	
	@Override
	public Set getSingletons() {
		try {
			return new HashSet(Arrays.asList(new WebDavContextResolver(entityClasses.toArray(new Class[entityClasses.size()]))));
		} catch (final JAXBException e) {
			logger.error("No singletons: ", e);
			return null;
		}
	}
}