001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: * The contents of this file are subject to the Mozilla Public License Version
004: * 1.1 (the "License"); you may not use this file except in compliance with
005: * the License. You may obtain a copy of the License at
006: * http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the
011: * License.
012: *
013: * The Original Code is Riot.
014: *
015: * The Initial Developer of the Original Code is
016: * Neteye GmbH.
017: * Portions created by the Initial Developer are Copyright (C) 2006
018: * the Initial Developer. All Rights Reserved.
019: *
020: * Contributor(s):
021: * Felix Gnass [fgnass at neteye dot de]
022: *
023: * ***** END LICENSE BLOCK ***** */
024: package org.riotfamily.components.model;
025:
026: import java.util.HashMap;
027: import java.util.Map;
028:
029: import org.riotfamily.components.config.ComponentRepository;
030: import org.riotfamily.components.config.component.Component;
031:
032: /**
033: * Versioned model for a component. The component properties are stored as
034: * map of Strings, additionally a type information is included which is used
035: * to look up a {@link Component} instance from the {@link ComponentRepository}.
036: */
037: public class ComponentVersion {
038:
039: private Long id;
040:
041: private String type;
042:
043: private Map properties;
044:
045: private boolean dirty;
046:
047: private VersionContainer container;
048:
049: public ComponentVersion() {
050: }
051:
052: public ComponentVersion(String type) {
053: this .type = type;
054: }
055:
056: public ComponentVersion(ComponentVersion prototype) {
057: if (prototype != null) {
058: this .type = prototype.getType();
059: this .container = prototype.getContainer();
060: this .properties = new HashMap(prototype.getProperties());
061: }
062: }
063:
064: /**
065: * Returns the entity's id set via {@link #setId(Long)}.
066: */
067: public Long getId() {
068: return this .id;
069: }
070:
071: /**
072: * Sets the entity's id.
073: */
074: public void setId(Long id) {
075: this .id = id;
076: }
077:
078: /**
079: * Returns the component-type. The String returned by this method is used
080: * to lookup a component implementation from the ComponentRepository.
081: */
082: public String getType() {
083: return this .type;
084: }
085:
086: /**
087: * Sets the component-type.
088: */
089: public void setType(String type) {
090: this .type = type;
091: setDirty(true);
092: }
093:
094: public Map getProperties() {
095: if (properties == null) {
096: properties = new HashMap();
097: }
098: return properties;
099: }
100:
101: public void setProperties(Map properties) {
102: this .properties = properties;
103: }
104:
105: public String getProperty(String key) {
106: if (properties == null) {
107: return null;
108: }
109: return (String) properties.get(key);
110: }
111:
112: public void setProperty(String key, String text) {
113: getProperties().put(key, text);
114: setDirty(true);
115: }
116:
117: /**
118: * Returns the VersionContainer this version belongs to.
119: */
120: public VersionContainer getContainer() {
121: return container;
122: }
123:
124: public void setContainer(VersionContainer container) {
125: this .container = container;
126: }
127:
128: public boolean isDirty() {
129: return this .dirty;
130: }
131:
132: public void setDirty(boolean dirty) {
133: this.dirty = dirty;
134: }
135:
136: }
|