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 // volatile for double-checked locking 081 private static volatile JAXBContext jaxbContext; 082 083 private static final Object jaxbContextLock = new Object(); 084 085 private static JAXBContext initJaxbContext() throws JAXBException { 086 return JAXBContext.newInstance(new Class<?>[] { // 087 ActiveLock.class, // 088 AllProp.class, // 089 CannotModifyProtectedProperty.class, // 090 Collection.class, // 091 CreationDate.class, // 092 Depth.class, // 093 DisplayName.class, // 094 net.java.dev.webdav.jaxrs.xml.elements.Error.class, // 095 Exclusive.class, // 096 GetContentLanguage.class, // 097 GetContentLength.class, // 098 GetContentType.class, // 099 GetETag.class, // 100 GetLastModified.class, // 101 HRef.class, // 102 Include.class, // 103 Location.class, // 104 LockDiscovery.class, // 105 LockEntry.class, // 106 LockInfo.class, // 107 LockRoot.class, // 108 LockScope.class, // 109 LockToken.class, // 110 LockTokenMatchesRequestUri.class, // 111 LockTokenSubmitted.class, // 112 LockType.class, // 113 MultiStatus.class, // 114 NoConflictingLock.class, // 115 NoExternalEntities.class, // 116 Owner.class, // 117 PreservedLiveProperties.class, // 118 Prop.class, // 119 PropertyUpdate.class, // 120 PropFind.class, // 121 PropFindFiniteDepth.class, // 122 PropName.class, // 123 PropStat.class, // 124 Remove.class, // 125 ResourceType.class, // 126 Response.class, // 127 ResponseDescription.class, // 128 Set.class, // 129 Shared.class, // 130 Status.class, // 131 SupportedLock.class, // 132 TimeOut.class, // 133 Write.class, // 134 IsCollection.class, // 135 IsFolder.class, // 136 IsHidden.class, // 137 Win32CreationTime.class, // 138 Win32FileAttributes.class, // 139 Win32LastAccessTime.class, // 140 Win32LastModifiedTime.class, // 141 }); 142 } 143 144 public static JAXBContext getJaxbContext() throws JAXBException { 145 if (jaxbContext == null) { 146 synchronized (jaxbContextLock) { 147 if (jaxbContext == null) { 148 jaxbContext = initJaxbContext(); 149 } 150 } 151 } 152 return jaxbContext; 153 } 154 155 public static Unmarshaller getUnmarshaller() throws JAXBException { 156 return getJaxbContext().createUnmarshaller(); 157 } 158 159}