001: /*
002: * (c) Copyright 2008 by Volker Bergmann. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, is permitted under the terms of the
006: * GNU General Public License.
007: *
008: * For redistributing this software or a derivative work under a license other
009: * than the GPL-compatible Free Software License as defined by the Free
010: * Software Foundation or approved by OSI, you must first obtain a commercial
011: * license to this software product from Volker Bergmann.
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014: * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015: * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017: * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGE.
025: */
026:
027: package org.databene.model.data;
028:
029: import org.databene.commons.converter.AnyConverter;
030:
031: /**
032: * Describes an ID generation setup.<br/><br/>
033: * Created: 29.01.2008 21:20:59
034: * @since 0.4.0
035: * @author Volker Bergmann
036: */
037: public class IdDescriptor extends ComponentDescriptor {
038:
039: public IdDescriptor(String name) {
040: this (name, null);
041: }
042:
043: public IdDescriptor(ComponentDescriptor parent) {
044: this (parent.getName(), parent);
045: }
046:
047: protected IdDescriptor(String name, ComponentDescriptor parent) {
048: super (name, parent);
049: addDetailConfig("strategy", String.class, false, null);
050: addDetailConfig("scope", String.class, false, null);
051: addDetailConfig("param", String.class, false, "");
052: }
053:
054: // properties ------------------------------------------------------------------------------------------------------
055:
056: public String getStrategy() {
057: return (String) getDetailValue("strategy");
058: }
059:
060: public void setStrategy(String strategy) {
061: setDetail("strategy", strategy);
062: }
063:
064: public String getScope() {
065: return (String) getDetailValue("scope");
066: }
067:
068: public void setScope(String scope) {
069: setDetail("scope", scope);
070: }
071:
072: public String getParam() {
073: return (String) getDetailValue("param");
074: }
075:
076: public void setParam(String param) {
077: setDetail("param", param);
078: }
079:
080: // literate build helpers ------------------------------------------------------------------------------------------
081:
082: public IdDescriptor withStrategy(String strategy) {
083: setStrategy(strategy);
084: return this ;
085: }
086:
087: public IdDescriptor withScope(String scope) {
088: setScope(scope);
089: return this ;
090: }
091:
092: public IdDescriptor withParam(String param) {
093: setParam(param);
094: return this ;
095: }
096:
097: // generic property access -----------------------------------------------------------------------------------------
098:
099: public void setDetail(String detailName, Object detailValue) {
100: Class<? extends Object> targetType = getDetailType(detailName);
101: detailValue = AnyConverter.convert(detailValue, targetType);
102: super.setDetail(detailName, detailValue);
103: }
104:
105: }
|