001: /**********************************************************************
002: Copyright (c) 2007 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.metadata;
018:
019: import java.io.Serializable;
020:
021: import org.jpox.util.ClassUtils;
022: import org.jpox.util.StringUtils;
023:
024: /**
025: * Representation of the details of an object stored in a container.
026: * This can be an element in a collection/array, or the key/value of a Map.
027: *
028: * @version $Revision: 1.4 $
029: */
030: class ContainerComponent implements Serializable {
031: /** Whether the component is stored embedded. */
032: protected Boolean embedded;
033:
034: /** Whether the component is stored serialised. */
035: protected Boolean serialized;
036:
037: /** Whether the component is dependent on the container (i.e should be deleted with the container). */
038: protected Boolean dependent;
039:
040: /** Type of the component. */
041: protected String type = "java.lang.Object";
042:
043: /** ClassMetaData for the component. */
044: protected AbstractClassMetaData classMetaData;
045:
046: /**
047: * Default constructor.
048: */
049: public ContainerComponent() {
050: // Do nothing
051: }
052:
053: /**
054: * Simple constructor that sets the component using typical input metadata.
055: * This does not set the "classMetaData" field.
056: * @param packageName Name of the package that this component is in
057: * @param type Type of the component
058: * @param embedded Whether it is embedded "true", "false" or null
059: * @param serialized Whether it is serialised "true", "false" or null
060: * @param dependent Whether it is dependent on the container "true", "false" or null
061: */
062: public ContainerComponent(String packageName, String type,
063: String embedded, String serialized, String dependent) {
064: if (!StringUtils.isWhitespace(type)) {
065: if (ClassUtils.isPrimitiveArrayType(type)) {
066: this .type = type;
067: } else if (ClassUtils.isPrimitiveType(type)) {
068: this .type = type;
069: } else if (packageName != null) {
070: // Apply naming rules - if no package, then assumed to be in same package as this class
071: this .type = ClassUtils.createFullClassName(packageName,
072: type);
073: } else {
074: this .type = type;
075: }
076: }
077: if (embedded != null) {
078: if (embedded.equalsIgnoreCase("true")) {
079: this .embedded = Boolean.TRUE;
080: } else if (embedded.equalsIgnoreCase("false")) {
081: this .embedded = Boolean.FALSE;
082: }
083: }
084: if (dependent != null) {
085: if (dependent.equalsIgnoreCase("true")) {
086: this .dependent = Boolean.TRUE;
087: } else if (dependent.equalsIgnoreCase("false")) {
088: this .dependent = Boolean.FALSE;
089: }
090: }
091: if (serialized != null) {
092: if (serialized.equalsIgnoreCase("true")) {
093: this .serialized = Boolean.TRUE;
094: } else if (serialized.equalsIgnoreCase("false")) {
095: this .serialized = Boolean.FALSE;
096: }
097: }
098: }
099:
100: public String toString() {
101: return "Type=" + type + " embedded=" + embedded
102: + " serialized=" + serialized + " dependent="
103: + dependent + " cmd=" + classMetaData;
104: }
105: }
|