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 020package org.apache.isis.objectstore.jdo.applib.service.settings; 021 022import javax.jdo.annotations.PersistenceCapable; 023 024import org.joda.time.LocalDate; 025 026import org.apache.isis.applib.DomainObjectContainer; 027import org.apache.isis.applib.annotation.MemberOrder; 028import org.apache.isis.applib.annotation.Named; 029import org.apache.isis.applib.annotation.Optional; 030import org.apache.isis.applib.services.settings.SettingType; 031 032/** 033 * Factors out common implementation; however this is annotated with {@link PersistenceCapable}, 034 * so that each subclass is its own root entity. 035 */ 036public abstract class SettingAbstractJdo extends org.apache.isis.applib.services.settings.SettingAbstract implements org.apache.isis.applib.services.settings.ApplicationSetting { 037 038 private String key; 039 040 @javax.jdo.annotations.Column(allowsNull="false") 041 public String getKey() { 042 return key; 043 } 044 045 public void setKey(final String key) { 046 this.key = key; 047 } 048 049 // ////////////////////////////////////// 050 051 private String description; 052 053 public String getDescription() { 054 return description; 055 } 056 057 public void setDescription(final String description) { 058 this.description = description; 059 } 060 061 @MemberOrder(name="Description", sequence="1") 062 @Named("Update") 063 public SettingAbstractJdo updateDescription(@Named("Description") @Optional String description) { 064 setDescription(description); 065 return this; 066 } 067 public String default0UpdateDescription() { 068 return getDescription(); 069 } 070 071 // ////////////////////////////////////// 072 073 private SettingType type; 074 075 @javax.jdo.annotations.Column(allowsNull="false") 076 public SettingType getType() { 077 return type; 078 } 079 080 public void setType(final SettingType type) { 081 this.type = type; 082 } 083 084 // ////////////////////////////////////// 085 086 private String valueRaw; 087 088 @javax.jdo.annotations.Column(allowsNull="false") 089 public String getValueRaw() { 090 return valueRaw; 091 } 092 093 public void setValueRaw(final String valueAsRaw) { 094 this.valueRaw = valueAsRaw; 095 } 096 097 // ////////////////////////////////////// 098 099 @MemberOrder(name="ValueAsString", sequence="1") 100 @Named("Update") 101 public SettingAbstractJdo updateAsString(@Named("Value") String value) { 102 setValueRaw(value); 103 return this; 104 } 105 public String default0UpdateAsString() { 106 return getValueAsString(); 107 } 108 public boolean hideUpdateAsString() { 109 return typeIsNot(SettingType.STRING); 110 } 111 112 @MemberOrder(name="ValueAsInt", sequence="1") 113 @Named("Update") 114 public SettingAbstractJdo updateAsInt(@Named("Value") Integer value) { 115 setValueRaw(value.toString()); 116 return this; 117 } 118 public Integer default0UpdateAsInt() { 119 return getValueAsInt(); 120 } 121 public boolean hideUpdateAsInt() { 122 return typeIsNot(SettingType.INT); 123 } 124 125 @MemberOrder(name="ValueAsLong", sequence="1") 126 @Named("Update") 127 public SettingAbstractJdo updateAsLong(@Named("Value") Long value) { 128 setValueRaw(value.toString()); 129 return this; 130 } 131 public Long default0UpdateAsLong() { 132 return getValueAsLong(); 133 } 134 public boolean hideUpdateAsLong() { 135 return typeIsNot(SettingType.LONG); 136 } 137 138 @MemberOrder(name="ValueAsLocalDate", sequence="1") 139 @Named("Update") 140 public SettingAbstractJdo updateAsLocalDate(@Named("Value") LocalDate value) { 141 setValueRaw(value.toString(DATE_FORMATTER)); 142 return this; 143 } 144 public LocalDate default0UpdateAsLocalDate() { 145 return getValueAsLocalDate(); 146 } 147 public boolean hideUpdateAsLocalDate() { 148 return typeIsNot(SettingType.LOCAL_DATE); 149 } 150 151 @MemberOrder(name="ValueAsBoolean", sequence="1") 152 @Named("Update") 153 public SettingAbstractJdo updateAsBoolean(@Named("Value") Boolean value) { 154 setValueRaw(value.toString()); 155 return this; 156 } 157 public Boolean default0UpdateAsBoolean() { 158 return getValueAsBoolean(); 159 } 160 public boolean hideUpdateAsBoolean() { 161 return typeIsNot(SettingType.BOOLEAN); 162 } 163 164 // ////////////////////////////////////// 165 166 167 public SettingAbstractJdo delete( 168 @Named("Are you sure?") @Optional Boolean confirm) { 169 if(confirm == null || !confirm) { 170 container.informUser("Setting NOT deleted"); 171 return this; 172 } 173 container.remove(this); 174 container.informUser("Setting deleted"); 175 return null; 176 } 177 178 179 180 181 // ////////////////////////////////////// 182 183 private DomainObjectContainer container; 184 185 public void setDomainObjectContainer(final DomainObjectContainer container) { 186 this.container = container; 187 } 188 189 190}