001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *
010     *        http://www.apache.org/licenses/LICENSE-2.0
011     *
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License.
018     */
019    
020    package org.apache.isis.core.progmodel.facets.value.time;
021    
022    import java.text.DateFormat;
023    import java.util.Date;
024    import java.util.Map;
025    
026    import org.apache.isis.applib.adapters.EncoderDecoder;
027    import org.apache.isis.applib.adapters.Parser;
028    import org.apache.isis.applib.value.Time;
029    import org.apache.isis.core.commons.config.IsisConfiguration;
030    import org.apache.isis.core.metamodel.facetapi.FacetHolder;
031    import org.apache.isis.core.progmodel.facets.object.value.ValueSemanticsProviderContext;
032    
033    import com.google.inject.internal.Maps;
034    
035    public class TimeValueSemanticsProvider extends TimeValueSemanticsProviderAbstract<org.apache.isis.applib.value.Time> {
036    
037        private static final Map<String, DateFormat> formats = Maps.newHashMap();
038    
039        static {
040            initFormats(formats);
041        }
042    
043        /**
044         * Required because implementation of {@link Parser} and {@link EncoderDecoder}.
045         */
046        public TimeValueSemanticsProvider() {
047            this(null, null, null);
048        }
049    
050        public TimeValueSemanticsProvider(final FacetHolder holder, final IsisConfiguration configuration,
051            final ValueSemanticsProviderContext context) {
052            super(holder, org.apache.isis.applib.value.Time.class, configuration, context);
053        }
054    
055        @Override
056        protected Map<String, DateFormat> formats() {
057            return formats;
058        }
059    
060        @Override
061        protected boolean ignoreTimeZone() {
062            return true;
063        }
064    
065        @Override
066        protected Time add(final Time original, final int years, final int months, final int days, final int hours,
067            final int minutes) {
068            Time time = original;
069            time = time.add(hours, minutes);
070            return time;
071        }
072    
073        @Override
074        protected Date dateValue(final Object object) {
075            final Time time = (Time) object;
076            return time == null ? null : time.asJavaDate();
077        }
078    
079        @Override
080        protected Time now() {
081            return new Time();
082        }
083    
084        @Override
085        protected Time setDate(final Date date) {
086            return new Time(date.getTime());
087        }
088    
089    }