Search in sources :

Example 1 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class EntityAssemblyImpl method newEntityModel.

EntityModel newEntityModel(StateDeclarations stateDeclarations, AssociationDeclarations associationDecs, ManyAssociationDeclarations manyAssociationDecs, NamedAssociationDeclarations namedAssociationDecs, AssemblyHelper helper) {
    this.associationDeclarations = associationDecs;
    this.manyAssociationDeclarations = manyAssociationDecs;
    this.namedAssociationDeclarations = namedAssociationDecs;
    try {
        associationsModel = new AssociationsModel();
        manyAssociationsModel = new ManyAssociationsModel();
        namedAssociationsModel = new NamedAssociationsModel();
        buildComposite(helper, stateDeclarations);
        EntityModel entityModel = new EntityModel(types, visibility, metaInfo, (EntityMixinsModel) mixinsModel, (EntityStateModel) stateModel, compositeMethodsModel);
        return entityModel;
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + types, e);
    }
}
Also used : ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) NamedAssociationsModel(org.qi4j.runtime.association.NamedAssociationsModel) EntityModel(org.qi4j.runtime.entity.EntityModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) AssociationsModel(org.qi4j.runtime.association.AssociationsModel) NamedAssociationsModel(org.qi4j.runtime.association.NamedAssociationsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Example 2 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class ValueTypeFactory method newValueType.

public ValueType newValueType(Type type, Class declaringClass, Class compositeType, LayerModel layer, ModuleModel module) {
    ValueType valueType = null;
    if (CollectionType.isCollection(type)) {
        if (type instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) type;
            Type collectionType = pt.getActualTypeArguments()[0];
            if (collectionType instanceof TypeVariable) {
                TypeVariable collectionTypeVariable = (TypeVariable) collectionType;
                collectionType = Classes.resolveTypeVariable(collectionTypeVariable, declaringClass, compositeType);
            }
            ValueType collectedType = newValueType(collectionType, declaringClass, compositeType, layer, module);
            valueType = new CollectionType(Classes.RAW_CLASS.map(type), collectedType);
        } else {
            valueType = new CollectionType(Classes.RAW_CLASS.map(type), newValueType(Object.class, declaringClass, compositeType, layer, module));
        }
    } else if (MapType.isMap(type)) {
        if (type instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) type;
            Type keyType = pt.getActualTypeArguments()[0];
            if (keyType instanceof TypeVariable) {
                TypeVariable keyTypeVariable = (TypeVariable) keyType;
                keyType = Classes.resolveTypeVariable(keyTypeVariable, declaringClass, compositeType);
            }
            ValueType keyedType = newValueType(keyType, declaringClass, compositeType, layer, module);
            Type valType = pt.getActualTypeArguments()[1];
            if (valType instanceof TypeVariable) {
                TypeVariable valueTypeVariable = (TypeVariable) valType;
                valType = Classes.resolveTypeVariable(valueTypeVariable, declaringClass, compositeType);
            }
            ValueType valuedType = newValueType(valType, declaringClass, compositeType, layer, module);
            valueType = new MapType(Classes.RAW_CLASS.map(type), keyedType, valuedType);
        } else {
            valueType = new MapType(Classes.RAW_CLASS.map(type), newValueType(Object.class, declaringClass, compositeType, layer, module), newValueType(Object.class, declaringClass, compositeType, layer, module));
        }
    } else if (ValueCompositeType.isValueComposite(type)) {
        // Find ValueModel in module/layer/used layers
        ValueModel model = new ValueFinder(layer, module, Classes.RAW_CLASS.map(type)).getFoundModel();
        if (model == null) {
            if (type.equals(ValueComposite.class)) {
                // Create default model
                MixinsModel mixinsModel = new MixinsModel();
                Iterable valueComposite = (Iterable) Iterables.iterable(ValueComposite.class);
                model = new ValueModel(valueComposite, Visibility.application, new MetaInfo(), mixinsModel, new ValueStateModel(new PropertiesModel(), new AssociationsModel(), new ManyAssociationsModel()), new CompositeMethodsModel(mixinsModel));
            } else {
                throw new InvalidApplicationException("[" + module.name() + "] Could not find ValueComposite of type " + type);
            }
        }
        return model.valueType();
    } else if (EnumType.isEnum(type)) {
        valueType = new EnumType(Classes.RAW_CLASS.map(type));
    } else {
        valueType = new ValueType(Classes.RAW_CLASS.map(type));
    }
    return valueType;
}
Also used : MixinsModel(org.qi4j.runtime.composite.MixinsModel) ValueModel(org.qi4j.runtime.value.ValueModel) ValueType(org.qi4j.api.type.ValueType) MetaInfo(org.qi4j.api.common.MetaInfo) ValueComposite(org.qi4j.api.value.ValueComposite) MapType(org.qi4j.api.type.MapType) ParameterizedType(java.lang.reflect.ParameterizedType) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) ValueCompositeType(org.qi4j.api.type.ValueCompositeType) EnumType(org.qi4j.api.type.EnumType) MapType(org.qi4j.api.type.MapType) CollectionType(org.qi4j.api.type.CollectionType) ValueType(org.qi4j.api.type.ValueType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) CompositeMethodsModel(org.qi4j.runtime.composite.CompositeMethodsModel) TypeVariable(java.lang.reflect.TypeVariable) EnumType(org.qi4j.api.type.EnumType) CollectionType(org.qi4j.api.type.CollectionType) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) ValueStateModel(org.qi4j.runtime.value.ValueStateModel) PropertiesModel(org.qi4j.runtime.property.PropertiesModel) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) AssociationsModel(org.qi4j.runtime.association.AssociationsModel)

Example 3 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class JettyConfigurationHelper method configureSslConnector.

static void configureSslConnector(SslConnector connector, SecureJettyConfiguration config) {
    SslContextFactory ssl = connector.getSslContextFactory();
    boolean needBouncyCastle = false;
    // KeyStore
    String keystoreType = config.keystoreType().get();
    String keystorePath = config.keystorePath().get();
    String keystorePassword = config.keystorePassword().get();
    ssl.setKeyStoreType(keystoreType);
    if ("PKCS12".equals(keystoreType)) {
        // WARN This one needs BouncyCastle on the classpath
        ssl.setKeyStoreProvider("BC");
        needBouncyCastle = true;
    }
    ssl.setKeyStorePath(keystorePath);
    ssl.setKeyStorePassword(keystorePassword);
    // Certificate alias
    String certAlias = config.certAlias().get();
    if (certAlias != null) {
        ssl.setCertAlias(certAlias);
    }
    // TrustStore
    String truststoreType = config.truststoreType().get();
    String truststorePath = config.truststorePath().get();
    String truststorePassword = config.truststorePassword().get();
    if (truststoreType != null && truststorePath != null) {
        ssl.setTrustStoreType(truststoreType);
        if ("PKCS12".equals(truststoreType)) {
            ssl.setTrustStoreProvider("BC");
            needBouncyCastle = true;
        }
        ssl.setTrustStore(truststorePath);
        ssl.setTrustStorePassword(truststorePassword);
    }
    // Need / Want Client Auth
    Boolean want = config.wantClientAuth().get();
    if (want != null) {
        ssl.setWantClientAuth(want);
    }
    Boolean need = config.needClientAuth().get();
    if (need != null) {
        ssl.setNeedClientAuth(need);
    }
    // Algorithms
    String secureRandomAlgo = config.secureRandomAlgorithm().get();
    if (secureRandomAlgo != null) {
        ssl.setSecureRandomAlgorithm(secureRandomAlgo);
    }
    String cipherExcludesConfigString = config.excludeCipherSuites().get();
    if (cipherExcludesConfigString != null) {
        String[] cipherExcludes = cipherExcludesConfigString.split(COMA);
        if (cipherExcludes.length > 0) {
            ssl.setExcludeCipherSuites(cipherExcludes);
        }
    }
    String cipherIncludesConfigString = config.includeCipherSuites().get();
    if (cipherIncludesConfigString != null) {
        String[] cipherIncludes = cipherIncludesConfigString.split(COMA);
        if (cipherIncludes.length > 0) {
            ssl.setIncludeCipherSuites(cipherIncludes);
        }
    }
    // SSL Handling
    Boolean cacheSslSessions = config.cacheSslSessions().get();
    if (cacheSslSessions != null) {
        ssl.setSessionCachingEnabled(cacheSslSessions);
    }
    ssl.setAllowRenegotiate(config.allowRenegotiation().get());
    // Validation Flags
    Integer maxCertPathLength = config.maxCertPathLength().get();
    if (maxCertPathLength != null) {
        ssl.setMaxCertPathLength(maxCertPathLength);
    }
    ssl.setValidateCerts(config.validateServerCert().get());
    ssl.setValidatePeerCerts(config.validatePeerCerts().get());
    // Validation CRL
    String crlFilePath = config.crlFilePath().get();
    if (crlFilePath != null && crlFilePath.length() > 0) {
        ssl.setCrlPath(crlFilePath);
    }
    ssl.setEnableCRLDP(config.enableCRLDP().get());
    // Validation OCSP
    ssl.setEnableOCSP(config.enableOCSP().get());
    String ocspURL = config.ocspResponderURL().get();
    if (ocspURL != null) {
        ssl.setOcspResponderURL(ocspURL);
    }
    // Load BouncyCastle ?
    if (needBouncyCastle) {
        Provider bc = Security.getProvider("BC");
        if (bc == null) {
            try {
                Security.addProvider((Provider) Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance());
            } catch (Exception ex) {
                throw new InvalidApplicationException("Need to open a PKCS#12 but was unable to register BouncyCastle, check your classpath", ex);
            }
        }
    }
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) Provider(java.security.Provider)

Example 4 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class TransientAssemblyImpl method newTransientModel.

TransientModel newTransientModel(StateDeclarations stateDeclarations, AssemblyHelper helper) {
    try {
        buildComposite(helper, stateDeclarations);
        TransientModel transientModel = new TransientModel(types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel);
        return transientModel;
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + types, e);
    }
}
Also used : TransientModel(org.qi4j.runtime.composite.TransientModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Example 5 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class EntityAssemblyImpl method newEntityModel.

EntityModel newEntityModel(StateDeclarations stateDeclarations, AssociationDeclarations associationDecs, ManyAssociationDeclarations manyAssociationDecs, AssemblyHelper helper) {
    this.associationDeclarations = associationDecs;
    this.manyAssociationDeclarations = manyAssociationDecs;
    try {
        associationsModel = new AssociationsModel();
        manyAssociationsModel = new ManyAssociationsModel();
        buildComposite(helper, stateDeclarations);
        EntityModel entityModel = new EntityModel(types, visibility, metaInfo, (EntityMixinsModel) mixinsModel, (EntityStateModel) stateModel, compositeMethodsModel);
        return entityModel;
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + types, e);
    }
}
Also used : ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) EntityModel(org.qi4j.runtime.entity.EntityModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) AssociationsModel(org.qi4j.runtime.association.AssociationsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Aggregations

InvalidApplicationException (org.qi4j.api.common.InvalidApplicationException)12 AssociationsModel (org.qi4j.runtime.association.AssociationsModel)4 ManyAssociationsModel (org.qi4j.runtime.association.ManyAssociationsModel)4 MetaInfo (org.qi4j.api.common.MetaInfo)3 Provider (java.security.Provider)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 ActivatorsModel (org.qi4j.runtime.activation.ActivatorsModel)2 EntityModel (org.qi4j.runtime.entity.EntityModel)2 ValueModel (org.qi4j.runtime.value.ValueModel)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServletContext (javax.servlet.ServletContext)1 Activator (org.qi4j.api.activation.Activator)1 CollectionType (org.qi4j.api.type.CollectionType)1 EnumType (org.qi4j.api.type.EnumType)1 MapType (org.qi4j.api.type.MapType)1