001 package biweekly.property.marshaller; 002 003 import java.util.HashMap; 004 import java.util.Map; 005 006 import javax.xml.namespace.QName; 007 008 import biweekly.property.ICalProperty; 009 010 /* 011 Copyright (c) 2013, Michael Angstadt 012 All rights reserved. 013 014 Redistribution and use in source and binary forms, with or without 015 modification, are permitted provided that the following conditions are met: 016 017 1. Redistributions of source code must retain the above copyright notice, this 018 list of conditions and the following disclaimer. 019 2. Redistributions in binary form must reproduce the above copyright notice, 020 this list of conditions and the following disclaimer in the documentation 021 and/or other materials provided with the distribution. 022 023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 026 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 027 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 028 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 029 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 030 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 033 */ 034 035 /** 036 * Contains the listing of all property marshallers. 037 * @author Michael Angstadt 038 */ 039 public class PropertyLibrary { 040 private static final Map<String, ICalPropertyMarshaller<? extends ICalProperty>> byPropName = new HashMap<String, ICalPropertyMarshaller<? extends ICalProperty>>(); 041 private static final Map<Class<? extends ICalProperty>, ICalPropertyMarshaller<? extends ICalProperty>> byClass = new HashMap<Class<? extends ICalProperty>, ICalPropertyMarshaller<? extends ICalProperty>>(); 042 private static final Map<QName, ICalPropertyMarshaller<? extends ICalProperty>> byQName = new HashMap<QName, ICalPropertyMarshaller<? extends ICalProperty>>(); 043 static { 044 //RFC 5545 045 addMarshaller(new ActionMarshaller()); 046 addMarshaller(new AttachmentMarshaller()); 047 addMarshaller(new AttendeeMarshaller()); 048 addMarshaller(new CalendarScaleMarshaller()); 049 addMarshaller(new CategoriesMarshaller()); 050 addMarshaller(new ClassificationMarshaller()); 051 addMarshaller(new CommentMarshaller()); 052 addMarshaller(new CompletedMarshaller()); 053 addMarshaller(new ContactMarshaller()); 054 addMarshaller(new CreatedMarshaller()); 055 addMarshaller(new DateDueMarshaller()); 056 addMarshaller(new DateEndMarshaller()); 057 addMarshaller(new DateStartMarshaller()); 058 addMarshaller(new DateTimeStampMarshaller()); 059 addMarshaller(new DescriptionMarshaller()); 060 addMarshaller(new DurationPropertyMarshaller()); 061 addMarshaller(new ExceptionDatesMarshaller()); 062 addMarshaller(new FreeBusyMarshaller()); 063 addMarshaller(new GeoMarshaller()); 064 addMarshaller(new LastModifiedMarshaller()); 065 addMarshaller(new LocationMarshaller()); 066 addMarshaller(new MethodMarshaller()); 067 addMarshaller(new OrganizerMarshaller()); 068 addMarshaller(new PercentCompleteMarshaller()); 069 addMarshaller(new PriorityMarshaller()); 070 addMarshaller(new ProductIdMarshaller()); 071 addMarshaller(new RecurrenceDatesMarshaller()); 072 addMarshaller(new RecurrenceIdMarshaller()); 073 addMarshaller(new RecurrenceRuleMarshaller()); 074 addMarshaller(new RelatedToMarshaller()); 075 addMarshaller(new RepeatMarshaller()); 076 addMarshaller(new RequestStatusMarshaller()); 077 addMarshaller(new ResourcesMarshaller()); 078 addMarshaller(new SequenceMarshaller()); 079 addMarshaller(new StatusMarshaller()); 080 addMarshaller(new SummaryMarshaller()); 081 addMarshaller(new TimezoneIdMarshaller()); 082 addMarshaller(new TimezoneNameMarshaller()); 083 addMarshaller(new TimezoneOffsetFromMarshaller()); 084 addMarshaller(new TimezoneOffsetToMarshaller()); 085 addMarshaller(new TimezoneUrlMarshaller()); 086 addMarshaller(new TransparencyMarshaller()); 087 addMarshaller(new TriggerMarshaller()); 088 addMarshaller(new UidMarshaller()); 089 addMarshaller(new UrlMarshaller()); 090 addMarshaller(new VersionMarshaller()); 091 092 //RFC 6321 093 addMarshaller(new XmlMarshaller()); 094 } 095 096 /** 097 * Gets a property marshaller by name. 098 * @param propertyName the component name (e.g. "VERSION") 099 * @return the property marshaller or null if not found 100 */ 101 public static ICalPropertyMarshaller<? extends ICalProperty> getMarshaller(String propertyName) { 102 return byPropName.get(propertyName.toUpperCase()); 103 } 104 105 /** 106 * Gets a property marshaller by class. 107 * @param clazz the property class 108 * @return the property marshaller or null if not found 109 */ 110 public static ICalPropertyMarshaller<? extends ICalProperty> getMarshaller(Class<? extends ICalProperty> clazz) { 111 return byClass.get(clazz); 112 } 113 114 /** 115 * Gets a property marshaller by XML local name and namespace. 116 * @param qname the XML local name and namespace 117 * @return the property marshaller or null if not found 118 */ 119 public static ICalPropertyMarshaller<? extends ICalProperty> getMarshaller(QName qname) { 120 return byQName.get(qname); 121 } 122 123 private static void addMarshaller(ICalPropertyMarshaller<? extends ICalProperty> m) { 124 byPropName.put(m.getPropertyName().toUpperCase(), m); 125 byClass.put(m.getPropertyClass(), m); 126 byQName.put(m.getQName(), m); 127 } 128 129 private PropertyLibrary() { 130 //hide 131 } 132 }