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