use of org.qi4j.api.composite.CompositeDescriptor in project qi4j-sdk by Qi4j.
the class ThisInjectionProviderFactory method newInjectionProvider.
@Override
@SuppressWarnings("unchecked")
public InjectionProvider newInjectionProvider(Resolution bindingContext, DependencyModel dependencyModel) throws InvalidInjectionException {
if (bindingContext.model() instanceof CompositeDescriptor) {
// If Composite type then return real type, otherwise use the specified one
final Class<?> thisType = dependencyModel.rawInjectionType();
Iterable<Class<?>> injectionTypes = null;
if (Classes.assignableTypeSpecification(thisType).satisfiedBy(bindingContext.model())) {
injectionTypes = bindingContext.model().types();
} else {
CompositeDescriptor acd = ((CompositeDescriptor) bindingContext.model());
for (Class<?> mixinType : acd.mixinTypes()) {
if (thisType.isAssignableFrom(mixinType)) {
Iterable<? extends Class<?>> iterable = iterable(thisType);
injectionTypes = (Iterable<Class<?>>) iterable;
break;
}
}
if (injectionTypes == null) {
throw new InvalidInjectionException("Composite " + bindingContext.model() + " does not implement @This type " + thisType.getName() + " in fragment " + dependencyModel.injectedClass().getName());
}
}
return new ThisInjectionProvider(injectionTypes);
} else {
throw new InvalidInjectionException("Object " + dependencyModel.injectedClass() + " may not use @This");
}
}
use of org.qi4j.api.composite.CompositeDescriptor in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method processPropertyTypeForQNames.
private void processPropertyTypeForQNames(PropertyDescriptor pType, Map<QualifiedName, QNameInfo> qNameInfos, Set<QualifiedName> newQNames, List<CompositeDescriptorInfo> vDescriptors, Set<String> enumValues, Boolean setQNameTableNameToNull) {
QualifiedName qName = pType.qualifiedName();
if (!newQNames.contains(qName) && !qName.name().equals(Identity.class.getName())) {
newQNames.add(qName);
// System.out.println("QName: " + qName + ", hc: " + qName.hashCode());
QNameInfo info = qNameInfos.get(qName);
if (info == null) {
info = QNameInfo.fromProperty(//
qName, setQNameTableNameToNull ? null : (QNAME_TABLE_NAME_PREFIX + qNameInfos.size()), //
pType);
qNameInfos.put(qName, info);
}
Type vType = info.getFinalType();
while (vType instanceof ParameterizedType) {
vType = ((ParameterizedType) vType).getRawType();
}
if (//
vType instanceof Class<?>) {
final Class<?> vTypeClass = (Class<?>) vType;
if (((Class<?>) vType).isInterface()) {
for (CompositeDescriptorInfo descInfo : vDescriptors) {
CompositeDescriptor desc = descInfo.composite;
if (desc instanceof ValueDescriptor) {
ValueDescriptor vDesc = (ValueDescriptor) desc;
// other Serializable
if (Iterables.matchesAny(new Specification<Class<?>>() {
@Override
public boolean satisfiedBy(Class<?> item) {
return vTypeClass.isAssignableFrom(item);
}
}, vDesc.types())) {
for (PropertyDescriptor subPDesc : vDesc.state().properties()) {
//
this.processPropertyTypeForQNames(//
subPDesc, //
qNameInfos, //
newQNames, //
vDescriptors, //
enumValues, //
setQNameTableNameToNull);
}
}
}
}
} else if (Enum.class.isAssignableFrom((Class<?>) vType)) {
for (Object value : ((Class<?>) vType).getEnumConstants()) {
enumValues.add(QualifiedName.fromClass((Class<?>) vType, value.toString()).toString());
}
}
}
}
}
use of org.qi4j.api.composite.CompositeDescriptor in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method initConnection.
@Override
public void initConnection() throws SQLException {
this._configuration.refresh();
this.initTypes();
this.modifyPrimitiveTypes(this._primitiveTypes, this._state.javaTypes2SQLTypes().get());
String schemaName = this._configuration.get().schemaName().get();
if (schemaName == null) {
schemaName = DEFAULT_SCHEMA_NAME;
} else {
this.checkSchemaName(schemaName);
}
LOGGER.debug("Will use '{}' as schema name", schemaName);
this._state.schemaName().set(schemaName);
this._state.entityTypePKs().set(new HashMap<String, Integer>());
this._state.usedClassesPKs().set(new HashMap<CompositeDescriptor, Integer>());
this._state.entityUsedQNames().set(new HashMap<EntityDescriptor, Set<QualifiedName>>());
this._state.qNameInfos().set(new HashMap<QualifiedName, QNameInfo>());
this._state.enumPKs().set(new HashMap<String, Integer>());
Connection connection = this._dataSource.getConnection();
try {
connection.setAutoCommit(true);
connection.setReadOnly(false);
this.syncDB(connection);
} finally {
SQLUtil.closeQuietly(connection);
}
if (LOGGER.isDebugEnabled()) {
String newline = "\n";
String tab = "\t";
String colonspace = ": ";
StringBuilder report = new StringBuilder();
report.append("schemaName: ").append(_state.schemaName().get()).append(newline);
report.append("qNameInfos: ").append(newline);
for (Map.Entry<QualifiedName, QNameInfo> entry : _state.qNameInfos().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("entityUsedQNames:").append(newline);
for (Map.Entry<EntityDescriptor, Set<QualifiedName>> entry : _state.entityUsedQNames().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("usedClassesPKs:").append(newline);
for (Map.Entry<CompositeDescriptor, Integer> entry : _state.usedClassesPKs().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("javaTypes2SQLTypes:").append(newline);
for (Map.Entry<Class<?>, Integer> entry : _state.javaTypes2SQLTypes().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("entityTypePKs:").append(newline);
for (Map.Entry<String, Integer> entry : _state.entityTypePKs().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
report.append("enumPKs:").append(newline);
for (Map.Entry<String, Integer> entry : _state.enumPKs().get().entrySet()) {
report.append(tab).append(entry.getKey()).append(colonspace).append(entry.getValue()).append(newline);
}
LOGGER.debug("SQLDBState after initConnection:\n{}", report.toString());
}
}
use of org.qi4j.api.composite.CompositeDescriptor in project qi4j-sdk by Qi4j.
the class MethodFinder method findMethod.
/**
* The Methods tab should show all the methods of all Mixins (private and public separated)
* that don't return one of Property, Association or ManyAssociation.
*
* "private" and "public" refers to if the interface they are declared in is extended by the Composite.
* If yes, then it is a public method, meaning, clients can call it.
* If no, then it is a private mixin type, and can only be used internally through @This injections.
*/
private List<CompositeMethodDetailDescriptor> findMethod(Iterable<CompositeMethodDetailDescriptor> iter) {
List<CompositeMethodDetailDescriptor> publicList = new ArrayList<>();
List<CompositeMethodDetailDescriptor> privateList = new ArrayList<>();
for (CompositeMethodDetailDescriptor descriptor : iter) {
CompositeDescriptor compositeDescriptor = descriptor.composite().descriptor();
Iterable<Class<?>> compositeType = compositeDescriptor.types();
Class<?> mixinMethodClass = descriptor.descriptor().method().getDeclaringClass();
for (Class<?> compositeClass : compositeType) {
if (mixinMethodClass.isAssignableFrom(compositeClass)) {
publicList.add(descriptor);
} else {
privateList.add(descriptor);
}
}
}
// combine into one list, with public listed first then private
publicList.addAll(privateList);
// filter Property, Association, ManyAssociation and NamedAssociation
doFilter(publicList);
return publicList;
}
use of org.qi4j.api.composite.CompositeDescriptor in project qi4j-sdk by Qi4j.
the class PDFWriter method writeTypeGeneralPage.
private void writeTypeGeneralPage(Object objectDesciptor) {
setFont(header5Font, header5FontSize);
writeString("General: ", headerLineSpace);
setFont(normalFont, normalFontSize);
if (objectDesciptor instanceof ServiceDetailDescriptor) {
ServiceDescriptor descriptor = ((ServiceDetailDescriptor) objectDesciptor).descriptor();
writeString("- identity: " + descriptor.identity());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
writeString("- startup: " + ((ServiceDetailDescriptor) objectDesciptor).descriptor().isInstantiateOnStartup());
} else if (objectDesciptor instanceof EntityDetailDescriptor) {
EntityDescriptor descriptor = ((EntityDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
} else if (objectDesciptor instanceof ValueDetailDescriptor) {
ValueDescriptor descriptor = ((ValueDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
} else if (objectDesciptor instanceof ObjectDetailDescriptor) {
ObjectDescriptor descriptor = ((ObjectDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
} else if (objectDesciptor instanceof CompositeDetailDescriptor) {
CompositeDescriptor descriptor = ((CompositeDetailDescriptor) objectDesciptor).descriptor();
writeString("- name: " + descriptor.toString());
writeString("- class: " + descriptor.toString());
writeString("- visibility: " + descriptor.visibility().toString());
}
}
Aggregations