use of org.kie.workbench.common.services.datamodeller.core.Visibility in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method parseProperty.
public ObjectProperty parseProperty(FieldSource<JavaClassSource> field, ClassTypeResolver classTypeResolver) throws ModelDriverException {
Type type;
boolean multiple = false;
String className;
String bag = null;
ObjectProperty property;
Visibility visibility = DriverUtils.buildVisibility(field.getVisibility());
try {
type = field.getType();
if (type.isPrimitive()) {
className = type.getName();
} else {
if (DriverUtils.isSimpleClass(type)) {
className = resolveTypeName(classTypeResolver, type.getName());
} else {
// if this point was reached, we know it's a Collection. Managed type check was done previous to adding the property.
multiple = true;
@SuppressWarnings("unchecked") Type elementsType = ((List<Type>) type.getTypeArguments()).get(0);
className = resolveTypeName(classTypeResolver, elementsType.getName());
bag = resolveTypeName(classTypeResolver, type.getName());
}
}
property = new ObjectPropertyImpl(field.getName(), className, multiple, bag, visibility, field.isStatic(), field.isFinal());
List<AnnotationSource<JavaClassSource>> annotations = field.getAnnotations();
if (annotations != null) {
for (AnnotationSource annotation : annotations) {
addPropertyAnnotation(property, annotation, classTypeResolver);
}
}
} catch (ClassNotFoundException e) {
logger.error(errorMessage(DATA_OBJECT_FIELD_LOAD_ERROR, field.getName(), field.getOrigin().getName()), e);
throw new ModelDriverException(errorMessage(DATA_OBJECT_FIELD_LOAD_ERROR, field.getName(), field.getOrigin().getName()), e);
}
return property;
}
use of org.kie.workbench.common.services.datamodeller.core.Visibility in project kie-wb-common by kiegroup.
the class ModuleDataModelOracleUtils method addEnumType.
private static void addEnumType(DataModel dataModel, String factType, ClassMetadata classMetadata) {
String packageName = NamingUtils.extractPackageName(factType);
String className = NamingUtils.extractClassName(factType);
Visibility visibility = DriverUtils.buildVisibility(classMetadata.getModifiers());
JavaEnum javaEnum = new JavaEnumImpl(packageName, className, visibility);
dataModel.addJavaEnum(javaEnum, ObjectSource.DEPENDENCY);
}
use of org.kie.workbench.common.services.datamodeller.core.Visibility in project kie-wb-common by kiegroup.
the class ModuleDataModelOracleUtils method addDataObjectType.
private static void addDataObjectType(DataModel dataModel, ModuleDataModelOracle oracleDataModel, String factType, ClassMetadata classMetadata) throws ModelDriverException {
String superClass = DataModelOracleUtilities.getSuperType(oracleDataModel, factType);
Visibility visibility = DriverUtils.buildVisibility(classMetadata.getModifiers());
DataObject dataObject;
logger.debug("Adding dataObjectType: " + factType + ", to dataModel: " + dataModel + ", from oracleDataModel: " + oracleDataModel);
dataObject = dataModel.addDataObject(factType, visibility, Modifier.isAbstract(classMetadata.getModifiers()), Modifier.isFinal(classMetadata.getModifiers()), ObjectSource.DEPENDENCY);
dataObject.setSuperClassName(superClass);
Map<String, ModelField[]> fields = oracleDataModel.getModuleModelFields();
if (fields != null) {
ModelField[] factFields = fields.get(factType);
ModelField field;
if (factFields != null && factFields.length > 0) {
for (int j = 0; j < factFields.length; j++) {
field = factFields[j];
if (isLoadableField(field)) {
if (field.getType().equals("Collection")) {
// read the correct bag and item classes.
String bag = DataModelOracleUtilities.getFieldClassName(oracleDataModel, factType, field.getName());
String itemsClass = DataModelOracleUtilities.getParametricFieldType(oracleDataModel, factType, field.getName());
if (itemsClass == null) {
// if we don't know the items class, the property will be managed as a simple property.
dataObject.addProperty(field.getName(), bag);
} else {
dataObject.addProperty(field.getName(), itemsClass, true, bag);
}
} else {
dataObject.addProperty(field.getName(), field.getClassName());
}
}
}
}
} else {
logger.debug("No fields found for factTye: " + factType);
}
}
use of org.kie.workbench.common.services.datamodeller.core.Visibility in project kie-wb-common by kiegroup.
the class DataModelOracleModelDriver method addFactType.
private void addFactType(DataModel dataModel, ModuleDataModelOracle oracleDataModel, String factType, ObjectSource source, ClassLoader classLoader) throws ModelDriverException {
String packageName = NamingUtils.extractPackageName(factType);
String className = NamingUtils.extractClassName(factType);
String superClass = DataModelOracleUtilities.getSuperType(oracleDataModel, factType);
DataObject dataObject;
logger.debug("Adding factType: " + factType + ", to dataModel: " + dataModel + ", from oracleDataModel: " + oracleDataModel);
ClassMetadata classMetadata = readClassMetadata(factType, classLoader);
if (classMetadata != null && !classMetadata.isMemberClass() && !classMetadata.isAnonymousClass() && !classMetadata.isLocalClass()) {
Visibility visibility = DriverUtils.buildVisibility(classMetadata.getModifiers());
dataObject = dataModel.addDataObject(factType, visibility, Modifier.isAbstract(classMetadata.getModifiers()), Modifier.isFinal(classMetadata.getModifiers()), source);
dataObject.setSuperClassName(superClass);
// process type annotations
Set<Annotation> typeAnnotations = DataModelOracleUtilities.getTypeAnnotations(oracleDataModel, factType);
if (typeAnnotations != null) {
for (Annotation annotation : typeAnnotations) {
addFactTypeAnnotation(dataObject, annotation);
}
}
Map<String, ModelField[]> fields = oracleDataModel.getModuleModelFields();
if (fields != null) {
ModelField[] factFields = fields.get(factType);
ModelField field;
ObjectProperty property;
Map<String, Set<Annotation>> typeFieldsAnnotations = DataModelOracleUtilities.getTypeFieldsAnnotations(oracleDataModel, factType);
Set<Annotation> fieldAnnotations;
if (factFields != null && factFields.length > 0) {
for (int j = 0; j < factFields.length; j++) {
field = factFields[j];
if (isLoadableField(field)) {
if (field.getType().equals("Collection")) {
// particular processing for collection types
// read the correct bag and item classes.
String bag = DataModelOracleUtilities.getFieldClassName(oracleDataModel, factType, field.getName());
String itemsClass = DataModelOracleUtilities.getParametricFieldType(oracleDataModel, factType, field.getName());
if (itemsClass == null) {
// if we don't know the items class, the property will be managed as a simple property.
property = dataObject.addProperty(field.getName(), bag);
} else {
property = dataObject.addProperty(field.getName(), itemsClass, true, bag);
}
} else {
property = dataObject.addProperty(field.getName(), getFieldType(oracleDataModel, packageName, field.getClassName()));
}
// process property annotations
if (typeFieldsAnnotations != null && (fieldAnnotations = typeFieldsAnnotations.get(field.getName())) != null) {
for (Annotation fieldAnnotation : fieldAnnotations) {
addFieldAnnotation(dataObject, property, fieldAnnotation);
}
}
}
}
}
} else {
logger.debug("No fields for factTye: " + factType);
}
}
}
use of org.kie.workbench.common.services.datamodeller.core.Visibility in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method parseDataObject.
private Pair<DataObject, List<ObjectProperty>> parseDataObject(JavaClassSource javaClassSource) throws ModelDriverException {
String className;
String packageName;
String superClass;
String qualifiedName;
ClassTypeResolver classTypeResolver;
className = javaClassSource.getName();
packageName = javaClassSource.getPackage();
qualifiedName = NamingUtils.createQualifiedName(packageName, className);
if (logger.isDebugEnabled()) {
logger.debug("Building DataObject for, packageName: " + packageName + ", className: " + className);
}
classTypeResolver = DriverUtils.createClassTypeResolver(javaClassSource, classLoader);
Visibility visibility = DriverUtils.buildVisibility(javaClassSource.getVisibility());
DataObject dataObject = new DataObjectImpl(packageName, className, visibility, javaClassSource.isAbstract(), javaClassSource.isFinal());
List<ObjectProperty> unmanagedProperties = new ArrayList<ObjectProperty>();
try {
if (javaClassSource.getSuperType() != null) {
superClass = resolveTypeName(classTypeResolver, javaClassSource.getSuperType());
dataObject.setSuperClassName(superClass);
}
List<AnnotationSource<JavaClassSource>> annotations = javaClassSource.getAnnotations();
if (annotations != null) {
for (AnnotationSource annotation : annotations) {
addJavaClassAnnotation(dataObject, annotation, classTypeResolver);
}
}
List<MethodSource<JavaClassSource>> classMethods = javaClassSource.getMethods();
if (classMethods != null) {
for (MethodSource<JavaClassSource> classMethod : classMethods) {
if (isAccepted(classMethod)) {
addMethod(dataObject, classMethod, classTypeResolver);
}
}
}
List<JavaSource<?>> nestedTypes = javaClassSource.getNestedTypes();
if (nestedTypes != null) {
for (JavaSource nestedType : nestedTypes) {
if (isAccepted(nestedType)) {
if (nestedType instanceof JavaClassSource) {
JavaClassImpl nestedJavaClass = new JavaClassImpl("", nestedType.getName(), DriverUtils.buildVisibility(nestedType.getVisibility()));
dataObject.addNestedClass(nestedJavaClass);
if (javaClassSource.getInterfaces() != null) {
for (String interfaceDefinition : ((JavaClassSource) nestedType).getInterfaces()) {
nestedJavaClass.addInterface(interfaceDefinition);
}
}
List<AnnotationSource<JavaClassSource>> nestedClassAnnotations = nestedType.getAnnotations();
if (nestedClassAnnotations != null) {
for (AnnotationSource annotation : nestedClassAnnotations) {
addJavaClassAnnotation(nestedJavaClass, annotation, classTypeResolver);
}
}
List<MethodSource<JavaClassSource>> nestedClassMethods = ((JavaClassSource) nestedType).getMethods();
if (nestedClassMethods != null) {
for (Method nestedClassMethod : nestedClassMethods) {
if (isAccepted(nestedClassMethod)) {
addMethod(nestedJavaClass, nestedClassMethod, classTypeResolver);
}
}
}
}
}
}
}
List<FieldSource<JavaClassSource>> fields = javaClassSource.getFields();
if (fields != null) {
for (FieldSource<JavaClassSource> field : fields) {
if (DriverUtils.isManagedType(field.getType(), classTypeResolver)) {
addProperty(dataObject, field, classTypeResolver);
} else {
logger.debug("field: " + field + "with fieldName: " + field.getName() + " won't be loaded by the diver because type: " + field.getType().getName() + " isn't a managed type.");
unmanagedProperties.add(new ObjectPropertyImpl(field.getName(), field.getType().toString(), false, DriverUtils.buildVisibility(field.getVisibility()), field.isStatic(), field.isFinal()));
}
}
}
List<Import> imports = javaClassSource.getImports();
if (imports != null) {
for (Import _import : imports) {
dataObject.addImport(new ImportImpl(_import.getQualifiedName()));
}
}
return new Pair<DataObject, List<ObjectProperty>>(dataObject, unmanagedProperties);
} catch (ClassNotFoundException e) {
logger.error(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
throw new ModelDriverException(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
} catch (ModelDriverException e) {
logger.error(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
throw new ModelDriverException(errorMessage(DATA_OBJECT_LOAD_ERROR, qualifiedName), e);
}
}
Aggregations