001/*
002 * (C) Copyright 2006-2009 Nuxeo SAS (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 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webdav.jaxrs;
021
022import javax.ws.rs.core.Response;
023import javax.xml.bind.JAXBContext;
024import javax.xml.bind.JAXBException;
025import javax.xml.bind.Unmarshaller;
026
027import net.java.dev.webdav.jaxrs.xml.conditions.CannotModifyProtectedProperty;
028import net.java.dev.webdav.jaxrs.xml.conditions.LockTokenMatchesRequestUri;
029import net.java.dev.webdav.jaxrs.xml.conditions.LockTokenSubmitted;
030import net.java.dev.webdav.jaxrs.xml.conditions.NoConflictingLock;
031import net.java.dev.webdav.jaxrs.xml.conditions.NoExternalEntities;
032import net.java.dev.webdav.jaxrs.xml.conditions.PreservedLiveProperties;
033import net.java.dev.webdav.jaxrs.xml.conditions.PropFindFiniteDepth;
034import net.java.dev.webdav.jaxrs.xml.elements.ActiveLock;
035import net.java.dev.webdav.jaxrs.xml.elements.AllProp;
036import net.java.dev.webdav.jaxrs.xml.elements.Collection;
037import net.java.dev.webdav.jaxrs.xml.elements.Depth;
038import net.java.dev.webdav.jaxrs.xml.elements.Exclusive;
039import net.java.dev.webdav.jaxrs.xml.elements.HRef;
040import net.java.dev.webdav.jaxrs.xml.elements.Include;
041import net.java.dev.webdav.jaxrs.xml.elements.Location;
042import net.java.dev.webdav.jaxrs.xml.elements.LockEntry;
043import net.java.dev.webdav.jaxrs.xml.elements.LockInfo;
044import net.java.dev.webdav.jaxrs.xml.elements.LockRoot;
045import net.java.dev.webdav.jaxrs.xml.elements.LockScope;
046import net.java.dev.webdav.jaxrs.xml.elements.LockToken;
047import net.java.dev.webdav.jaxrs.xml.elements.LockType;
048import net.java.dev.webdav.jaxrs.xml.elements.MultiStatus;
049import net.java.dev.webdav.jaxrs.xml.elements.Owner;
050import net.java.dev.webdav.jaxrs.xml.elements.Prop;
051import net.java.dev.webdav.jaxrs.xml.elements.PropFind;
052import net.java.dev.webdav.jaxrs.xml.elements.PropName;
053import net.java.dev.webdav.jaxrs.xml.elements.PropStat;
054import net.java.dev.webdav.jaxrs.xml.elements.PropertyUpdate;
055import net.java.dev.webdav.jaxrs.xml.elements.Remove;
056import net.java.dev.webdav.jaxrs.xml.elements.ResponseDescription;
057import net.java.dev.webdav.jaxrs.xml.elements.Set;
058import net.java.dev.webdav.jaxrs.xml.elements.Shared;
059import net.java.dev.webdav.jaxrs.xml.elements.Status;
060import net.java.dev.webdav.jaxrs.xml.elements.TimeOut;
061import net.java.dev.webdav.jaxrs.xml.elements.Write;
062import net.java.dev.webdav.jaxrs.xml.properties.CreationDate;
063import net.java.dev.webdav.jaxrs.xml.properties.DisplayName;
064import net.java.dev.webdav.jaxrs.xml.properties.GetContentLanguage;
065import net.java.dev.webdav.jaxrs.xml.properties.GetContentLength;
066import net.java.dev.webdav.jaxrs.xml.properties.GetContentType;
067import net.java.dev.webdav.jaxrs.xml.properties.GetETag;
068import net.java.dev.webdav.jaxrs.xml.properties.GetLastModified;
069import net.java.dev.webdav.jaxrs.xml.properties.LockDiscovery;
070import net.java.dev.webdav.jaxrs.xml.properties.ResourceType;
071import net.java.dev.webdav.jaxrs.xml.properties.SupportedLock;
072
073/**
074 * Utility functions.
075 */
076public class Util {
077
078    private static JAXBContext jaxbContext;
079
080    private static JAXBContext initJaxbContext() throws JAXBException {
081        return JAXBContext.newInstance(new Class<?>[] { //
082        ActiveLock.class, //
083                AllProp.class, //
084                CannotModifyProtectedProperty.class, //
085                Collection.class, //
086                CreationDate.class, //
087                Depth.class, //
088                DisplayName.class, //
089                net.java.dev.webdav.jaxrs.xml.elements.Error.class, //
090                Exclusive.class, //
091                GetContentLanguage.class, //
092                GetContentLength.class, //
093                GetContentType.class, //
094                GetETag.class, //
095                GetLastModified.class, //
096                HRef.class, //
097                Include.class, //
098                Location.class, //
099                LockDiscovery.class, //
100                LockEntry.class, //
101                LockInfo.class, //
102                LockRoot.class, //
103                LockScope.class, //
104                LockToken.class, //
105                LockTokenMatchesRequestUri.class, //
106                LockTokenSubmitted.class, //
107                LockType.class, //
108                MultiStatus.class, //
109                NoConflictingLock.class, //
110                NoExternalEntities.class, //
111                Owner.class, //
112                PreservedLiveProperties.class, //
113                Prop.class, //
114                PropertyUpdate.class, //
115                PropFind.class, //
116                PropFindFiniteDepth.class, //
117                PropName.class, //
118                PropStat.class, //
119                Remove.class, //
120                ResourceType.class, //
121                Response.class, //
122                ResponseDescription.class, //
123                Set.class, //
124                Shared.class, //
125                Status.class, //
126                SupportedLock.class, //
127                TimeOut.class, //
128                Write.class, //
129                IsCollection.class, //
130                IsFolder.class, //
131                IsHidden.class, //
132                Win32CreationTime.class, //
133                Win32FileAttributes.class, //
134                Win32LastAccessTime.class, //
135                Win32LastModifiedTime.class, //
136        });
137    }
138
139    public static JAXBContext getJaxbContext() throws JAXBException {
140        if (jaxbContext == null) {
141            jaxbContext = initJaxbContext();
142        }
143        return jaxbContext;
144    }
145
146    public static Unmarshaller getUnmarshaller() throws JAXBException {
147        return getJaxbContext().createUnmarshaller();
148    }
149
150}