Search in sources :

Example 16 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadCacheHandler.

private static void loadCacheHandler(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) throws ClassException, BundleException {
    boolean hasCS = configServer != null;
    // first of all we make sure we have a request and timespan cachehandler
    if (!hasCS) {
        config.addCacheHandler("request", new ClassDefinitionImpl(RequestCacheHandler.class));
        config.addCacheHandler("timespan", new ClassDefinitionImpl(TimespanCacheHandler.class));
    }
    // add CacheHandlers from server context to web context
    if (hasCS) {
        Iterator<Entry<String, Class<CacheHandler>>> it = configServer.getCacheHandlers();
        Entry<String, Class<CacheHandler>> entry;
        while (it.hasNext()) {
            entry = it.next();
            config.addCacheHandler(entry.getKey(), entry.getValue());
        }
    }
    Element root = getChildByName(doc.getDocumentElement(), "cache-handlers");
    Element[] handlers = getChildren(root, "cache-handler");
    if (!ArrayUtil.isEmpty(handlers)) {
        ClassDefinition cd;
        String strId;
        for (int i = 0; i < handlers.length; i++) {
            cd = getClassDefinition(handlers[i], "", config.getIdentification());
            strId = getAttr(handlers[i], "id");
            if (cd.hasClass() && !StringUtil.isEmpty(strId)) {
                strId = strId.trim().toLowerCase();
                try {
                    config.addCacheHandler(strId, cd);
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                    log.error("Cache-Handler", t);
                }
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) ClassDefinition(lucee.runtime.db.ClassDefinition) lucee.aprint(lucee.aprint) TimespanCacheHandler(lucee.runtime.cache.tag.timespan.TimespanCacheHandler) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) RequestCacheHandler(lucee.runtime.cache.tag.request.RequestCacheHandler) CacheHandler(lucee.runtime.cache.tag.CacheHandler) TimespanCacheHandler(lucee.runtime.cache.tag.timespan.TimespanCacheHandler) RequestCacheHandler(lucee.runtime.cache.tag.request.RequestCacheHandler)

Example 17 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadDataSources.

/**
 * loads datasource settings from XMl DOM
 *
 * @param configServer
 * @param config
 * @param doc
 * @throws BundleException
 * @throws ClassNotFoundException
 */
private static void loadDataSources(ConfigServerImpl configServer, ConfigImpl config, Document doc, Log log) {
    // load JDBC Driver defintion
    {
        Element jdbc = getChildByName(doc.getDocumentElement(), "jdbc");
        Element[] drivers = getChildren(jdbc, "driver");
        Map<String, JDBCDriver> map = new HashMap<String, JDBCDriver>();
        // first add the server drivers, so they can be overwritten
        if (configServer != null) {
            JDBCDriver[] sds = configServer.getJDBCDrivers();
            for (JDBCDriver sd : sds) {
                map.put(sd.cd.toString(), sd);
            }
        }
        ClassDefinition cd;
        String label;
        for (Element driver : drivers) {
            cd = getClassDefinition(driver, "", config.getIdentification());
            label = getAttr(driver, "label");
            // check if label exists
            if (StringUtil.isEmpty(label)) {
                log.error("Datasource", "missing label for jdbc driver [" + cd.getClassName() + "]");
                continue;
            }
            // check if it is a bundle
            if (!cd.isBundle()) {
                log.error("Datasource", "jdbc driver [" + label + "] does not describe a bundle");
                continue;
            }
            map.put(cd.toString(), new JDBCDriver(label, cd));
        }
        config.setJDBCDrivers(map.values().toArray(new JDBCDriver[map.size()]));
    }
    // When set to true, makes JDBC use a representation for DATE data that
    // is compatible with the Oracle8i database.
    System.setProperty("oracle.jdbc.V8Compatible", "true");
    boolean hasCS = configServer != null;
    Map<String, DataSource> datasources = new HashMap<String, DataSource>();
    // Copy Parent datasources as readOnly
    if (hasCS) {
        Map<String, DataSource> ds = configServer.getDataSourcesAsMap();
        Iterator<Entry<String, DataSource>> it = ds.entrySet().iterator();
        Entry<String, DataSource> entry;
        while (it.hasNext()) {
            entry = it.next();
            if (!entry.getKey().equals(QOQ_DATASOURCE_NAME))
                datasources.put(entry.getKey(), entry.getValue().cloneReadOnly());
        }
    }
    // Default query of query DB
    try {
        setDatasource(config, datasources, QOQ_DATASOURCE_NAME, new ClassDefinitionImpl("org.hsqldb.jdbcDriver", "hsqldb", "1.8.0", config.getIdentification()), "hypersonic-hsqldb", "", -1, "jdbc:hsqldb:.", "sa", "", DEFAULT_MAX_CONNECTION, -1, 60000, true, true, DataSource.ALLOW_ALL, false, false, null, new StructImpl(), "", ParamSyntax.DEFAULT, false, false);
    } catch (Exception e) {
        log.error("Datasource", e);
    }
    SecurityManager sm = config.getSecurityManager();
    short access = sm.getAccess(SecurityManager.TYPE_DATASOURCE);
    int accessCount = -1;
    if (access == SecurityManager.VALUE_YES)
        accessCount = -1;
    else if (access == SecurityManager.VALUE_NO)
        accessCount = 0;
    else if (access >= SecurityManager.VALUE_1 && access <= SecurityManager.VALUE_10) {
        accessCount = access - SecurityManager.NUMBER_OFFSET;
    }
    // Databases
    Element databases = getChildByName(doc.getDocumentElement(), "data-sources");
    // if(databases==null)databases=doc.createElement("data-sources");
    // PSQ
    String strPSQ = getAttr(databases, "psq");
    if (StringUtil.isEmpty(strPSQ)) {
        // prior version was buggy, was the opposite
        strPSQ = getAttr(databases, "preserve-single-quote");
        if (!StringUtil.isEmpty(strPSQ)) {
            Boolean b = Caster.toBoolean(strPSQ, null);
            if (b != null)
                strPSQ = b.booleanValue() ? "false" : "true";
        }
    }
    if (access != SecurityManager.VALUE_NO && !StringUtil.isEmpty(strPSQ)) {
        config.setPSQL(toBoolean(strPSQ, true));
    } else if (hasCS)
        config.setPSQL(configServer.getPSQL());
    // Data Sources
    Element[] dataSources = getChildren(databases, "data-source");
    if (accessCount == -1)
        accessCount = dataSources.length;
    if (dataSources.length < accessCount)
        accessCount = dataSources.length;
    // if(hasAccess) {
    ClassDefinition cd;
    for (int i = 0; i < accessCount; i++) {
        Element dataSource = dataSources[i];
        if (dataSource.hasAttribute("database")) {
            try {
                cd = getClassDefinition(dataSource, "", config.getIdentification());
                if (!cd.isBundle()) {
                    JDBCDriver jdbc = config.getJDBCDriverByClassName(cd.getClassName(), null);
                    if (jdbc != null)
                        cd = jdbc.cd;
                }
                setDatasource(config, datasources, getAttr(dataSource, "name"), cd, getAttr(dataSource, "host"), getAttr(dataSource, "database"), Caster.toIntValue(getAttr(dataSource, "port"), -1), getAttr(dataSource, "dsn"), getAttr(dataSource, "username"), ConfigWebUtil.decrypt(getAttr(dataSource, "password")), Caster.toIntValue(getAttr(dataSource, "connectionLimit"), DEFAULT_MAX_CONNECTION), Caster.toIntValue(getAttr(dataSource, "connectionTimeout"), -1), Caster.toLongValue(getAttr(dataSource, "metaCacheTimeout"), 60000), toBoolean(getAttr(dataSource, "blob"), true), toBoolean(getAttr(dataSource, "clob"), true), Caster.toIntValue(getAttr(dataSource, "allow"), DataSource.ALLOW_ALL), toBoolean(getAttr(dataSource, "validate"), false), toBoolean(getAttr(dataSource, "storage"), false), getAttr(dataSource, "timezone"), toStruct(getAttr(dataSource, "custom")), getAttr(dataSource, "dbdriver"), ParamSyntax.toParamSyntax(dataSource, ParamSyntax.DEFAULT), toBoolean(getAttr(dataSource, "literal-timestamp-with-tsoffset"), false), toBoolean(getAttr(dataSource, "always-set-timeout"), false));
            } catch (Exception e) {
                log.error("Datasource", e);
            }
        }
    }
    // }
    config.setDataSources(datasources);
}
Also used : SecurityManager(lucee.runtime.security.SecurityManager) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) ClassDefinition(lucee.runtime.db.ClassDefinition) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityException(lucee.runtime.exp.SecurityException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) SAXException(org.xml.sax.SAXException) ClassException(lucee.commons.lang.ClassException) MalformedURLException(java.net.MalformedURLException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException) lucee.aprint(lucee.aprint) DataSource(lucee.runtime.db.DataSource) DumpWriterEntry(lucee.runtime.dump.DumpWriterEntry) Entry(java.util.Map.Entry) GatewayEntry(lucee.runtime.gateway.GatewayEntry) ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) StructImpl(lucee.runtime.type.StructImpl) JDBCDriver(lucee.runtime.db.JDBCDriver) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 18 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class CacheRegionNew method _call.

static String _call(PageContext pc, String cacheName, Struct properties, Boolean throwOnError, String strWebAdminPassword) throws PageException {
    Password webAdminPassword = CacheUtil.getPassword(pc, strWebAdminPassword, false);
    try {
        // TODO why we have here EHCache?
        XMLConfigAdmin adminConfig = XMLConfigAdmin.newInstance((ConfigWebImpl) pc.getConfig(), webAdminPassword);
        adminConfig.updateCacheConnection(cacheName, new ClassDefinitionImpl("org.lucee.extension.cache.eh.EHCache", null, null, pc.getConfig().getIdentification()), Config.CACHE_TYPE_NONE, properties, false, false);
        adminConfig.storeAndReload();
    } catch (Exception e) {
        if (throwOnError)
            throw Caster.toPageException(e);
    }
    return null;
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) XMLConfigAdmin(lucee.runtime.config.XMLConfigAdmin) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Password(lucee.runtime.config.Password)

Example 19 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class ModernApplicationContext method toCacheConnection.

public static CacheConnection toCacheConnection(Config config, String name, Struct data) throws ApplicationException, CacheException, ClassException, BundleException {
    // class definition
    String className = Caster.toString(data.get(KeyConstants._class, null), null);
    if (StringUtil.isEmpty(className))
        throw new ApplicationException("missing key class in struct the defines a cachec connection");
    ClassDefinition cd = new ClassDefinitionImpl(className, Caster.toString(data.get(KeyConstants._bundleName, null), null), Caster.toString(data.get(KeyConstants._bundleVersion, null), null), config.getIdentification());
    CacheConnectionImpl cc = new CacheConnectionImpl(config, name, cd, Caster.toStruct(data.get(KeyConstants._custom, null), null), Caster.toBooleanValue(data.get(KeyConstants._readonly, null), false), Caster.toBooleanValue(data.get(KeyConstants._storage, null), false));
    String id = cc.id();
    CacheConnection icc = initCacheConnections.get(id);
    if (icc != null)
        return icc;
    try {
        Method m = cd.getClazz().getMethod("init", new Class[] { Config.class, String[].class, Struct[].class });
        if (Modifier.isStatic(m.getModifiers()))
            m.invoke(null, new Object[] { config, new String[] { cc.getName() }, new Struct[] { cc.getCustom() } });
        else
            SystemOut.print(config.getErrWriter(), "method [init(Config,String[],Struct[]):void] for class [" + cd.toString() + "] is not static");
        initCacheConnections.put(id, cc);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    return cc;
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ApplicationException(lucee.runtime.exp.ApplicationException) CacheConnectionImpl(lucee.runtime.cache.CacheConnectionImpl) Method(java.lang.reflect.Method) ClassDefinition(lucee.runtime.db.ClassDefinition) CacheConnection(lucee.runtime.cache.CacheConnection) Struct(lucee.runtime.type.Struct)

Example 20 with ClassDefinitionImpl

use of lucee.transformer.library.ClassDefinitionImpl in project Lucee by lucee.

the class Admin method doUpdateAdminSyncClass.

private void doUpdateAdminSyncClass() throws PageException {
    ClassDefinition cd = new ClassDefinitionImpl(getString("admin", action, "class"), getString("bundleName", null), getString("bundleVersion", null), config.getIdentification());
    admin.updateAdminSyncClass(cd);
    store();
}
Also used : ClassDefinitionImpl(lucee.transformer.library.ClassDefinitionImpl) ClassDefinition(lucee.runtime.db.ClassDefinition)

Aggregations

ClassDefinitionImpl (lucee.transformer.library.ClassDefinitionImpl)33 ClassDefinition (lucee.runtime.db.ClassDefinition)26 Element (org.w3c.dom.Element)9 ApplicationException (lucee.runtime.exp.ApplicationException)8 PageException (lucee.runtime.exp.PageException)6 IOException (java.io.IOException)5 BundleException (org.osgi.framework.BundleException)5 MalformedURLException (java.net.MalformedURLException)4 lucee.aprint (lucee.aprint)4 ClassException (lucee.commons.lang.ClassException)4 SecurityException (lucee.runtime.exp.SecurityException)4 Struct (lucee.runtime.type.Struct)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 DumpWriterEntry (lucee.runtime.dump.DumpWriterEntry)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 GatewayEntry (lucee.runtime.gateway.GatewayEntry)3