01: /*
02: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.romaframework.core.schema;
18:
19: /**
20: * In the Object Orientation paradigm it's the instance of the class whereas the class is the SchemaClass class. Instance's values
21: * are customizable, but at construction time are valued with SchemaClass values.
22: *
23: * @author Luca Garulli (luca.garulli@assetdata.it)
24: */
25: public class SchemaObject extends SchemaClassDefinition {
26:
27: private SchemaClass schemaClass;
28: private Object instance;
29:
30: public SchemaObject(SchemaClass iEntityInfo, Object iInstance) {
31: this (iEntityInfo);
32: instance = iInstance;
33: }
34:
35: public SchemaObject(SchemaClass iEntityInfo) {
36: schemaClass = iEntityInfo;
37: copyDefinition(schemaClass);
38: }
39:
40: // @Override
41: // public Iterator<SchemaField> getFieldIterator() {
42: // return new SchemaFieldIteratorWrapper(super.getFieldIterator());
43: // }
44:
45: /**
46: * Load the SchemaObject upon first field access
47: */
48: @Override
49: public SchemaField getField(String iFieldName) {
50: SchemaField field = super .getField(iFieldName);
51:
52: if (field == null)
53: return null;
54:
55: synchronized (field) {
56: if (field.getComplexClass() != null)
57: // COMPLEX CLASS: REPLACE IT WITH A SCHEMA OBJECT INSTANCE
58: field.setComplexClass(new SchemaObject(field
59: .getComplexClass().getSchemaClass()));
60: }
61:
62: return field;
63: }
64:
65: @Override
66: public SchemaClass getSchemaClass() {
67: return schemaClass;
68: }
69:
70: public Object getInstance() {
71: return instance;
72: }
73:
74: public void setInstance(Object instance) {
75: this .instance = instance;
76: }
77:
78: @Override
79: public String toString() {
80: StringBuilder buffer = new StringBuilder();
81: if (instance != null) {
82: buffer.append("Instance: ");
83: buffer.append(instance);
84: buffer.append(" ");
85: }
86: if (schemaClass != null) {
87: buffer.append("Schema: ");
88: buffer.append(schemaClass);
89: }
90: return buffer.toString();
91: }
92:
93: @Override
94: public Object clone() throws CloneNotSupportedException {
95: return super.clone();
96: }
97: }
|