Search in sources :

Example 1 with CompositeDescriptor

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");
    }
}
Also used : InvalidInjectionException(org.qi4j.bootstrap.InvalidInjectionException) CompositeDescriptor(org.qi4j.api.composite.CompositeDescriptor)

Example 2 with CompositeDescriptor

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());
                }
            }
        }
    }
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) QualifiedName(org.qi4j.api.common.QualifiedName) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) ParameterizedType(java.lang.reflect.ParameterizedType) QNameType(org.qi4j.index.sql.support.common.QNameInfo.QNameType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ObjectType(org.sql.generation.api.grammar.manipulation.ObjectType) SQLDataType(org.sql.generation.api.grammar.common.datatypes.SQLDataType) CompositeDescriptor(org.qi4j.api.composite.CompositeDescriptor) QNameInfo(org.qi4j.index.sql.support.common.QNameInfo) Identity(org.qi4j.api.entity.Identity)

Example 3 with CompositeDescriptor

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());
    }
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) HashSet(java.util.HashSet) QualifiedName(org.qi4j.api.common.QualifiedName) Connection(java.sql.Connection) BigInteger(java.math.BigInteger) EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) CompositeDescriptor(org.qi4j.api.composite.CompositeDescriptor) QNameInfo(org.qi4j.index.sql.support.common.QNameInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with CompositeDescriptor

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;
}
Also used : CompositeMethodDetailDescriptor(org.qi4j.tools.model.descriptor.CompositeMethodDetailDescriptor) ArrayList(java.util.ArrayList) CompositeDescriptor(org.qi4j.api.composite.CompositeDescriptor)

Example 5 with CompositeDescriptor

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());
    }
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) ServiceDescriptor(org.qi4j.api.service.ServiceDescriptor) ImportedServiceDescriptor(org.qi4j.api.service.ImportedServiceDescriptor) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) CompositeDescriptor(org.qi4j.api.composite.CompositeDescriptor) ObjectDescriptor(org.qi4j.api.object.ObjectDescriptor)

Aggregations

CompositeDescriptor (org.qi4j.api.composite.CompositeDescriptor)6 HashSet (java.util.HashSet)2 QualifiedName (org.qi4j.api.common.QualifiedName)2 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)2 ValueDescriptor (org.qi4j.api.value.ValueDescriptor)2 QNameInfo (org.qi4j.index.sql.support.common.QNameInfo)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 BigInteger (java.math.BigInteger)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Identity (org.qi4j.api.entity.Identity)1 ObjectDescriptor (org.qi4j.api.object.ObjectDescriptor)1 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)1 ImportedServiceDescriptor (org.qi4j.api.service.ImportedServiceDescriptor)1