Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/************************************************************************
* Copyright (c) 2015 IoT-Solutions e.U.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
package iot.jcypher.domain.genericmodel;
import iot.jcypher.domain.genericmodel.internal.InternalAccess;
import iot.jcypher.domain.internal.DomainAccess;
import iot.jcypher.domain.internal.IIntDomainAccess;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
public class DomainObject {
private DOType domainObjectType;
private Object rawObject;
public DomainObject(DOType doType) {
this(doType, true);
}
DomainObject(DOType doType, boolean toNursery) {
super();
if (doType == null)
throw new RuntimeException("a domain object must be constructed with a domain object type");
this.domainObjectType = doType;
if (toNursery)
this.domainObjectType.getDomainModel().addNurseryObject(getRawObject(), this);
}
/**
* Answer the type of this generic domain object
* @return a DOType
*/
public DOType getDomainObjectType() {
return domainObjectType;
}
/**
* Set a field (attribute) value
* @param fieldName
* @param value
*/
public void setFieldValue(String fieldName, Object value) {
DOField field = this.domainObjectType.getFieldByName(fieldName);
if (field == null)
throw new RuntimeException("field: " + fieldName + " not found in: " + this.domainObjectType.getName());
if (field.getComponentTypeName() != null)
throw new RuntimeException("field: " + fieldName + " is a list field, use list field accessors instead ");
Object val = value;
if (value instanceof DomainObject)
val = ((DomainObject)value).getRawObject();
field.setValue(this.getRawObject(), val);
}
/**
* Add a value to a list or array field
* @param fieldName
* @param value
*/
public void addListFieldValue(String fieldName, Object value) {
Object val = value;
if (value instanceof DomainObject)
val = ((DomainObject)value).getRawObject();
Object lst = getFieldValue(fieldName, true); // internal
DOField fld = getDomainObjectType().getFieldByName(fieldName);
String ctn = fld.getComponentTypeName();
Class> clazz;
try {
clazz = getDomainObjectType().getDomainModel().getClassForName(ctn);
if (!clazz.isAssignableFrom(val.getClass()))
throw new RuntimeException("value must be of type or subtype of: [" + clazz.getName() + "]");
lst = tryInitListOrArray(lst, fld, clazz);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
if (lst instanceof List>) {
@SuppressWarnings("unchecked")
List