Example usage for java.io File toURL

List of usage examples for java.io File toURL

Introduction

In this page you can find the example usage for java.io File toURL.

Prototype

@Deprecated
public URL toURL() throws MalformedURLException 

Source Link

Document

Converts this abstract pathname into a file: URL.

Usage

From source file:it.prato.comune.sit.LayerTerritorio.java

/**
 * Crea uno Shapefile data store usando il file passato come argomento.
 * /*from   w w  w  .  j av a  2 s  .co  m*/
 * @param szFile
 * @return DataStore
 * @throws IOException
 * @throws SITException
 */
protected DataStore CreaSHPDsComp(File szFile) throws IOException, SITException {

    String dsParams = "url;";
    URL anURL;

    try {
        anURL = szFile.toURL();
    } catch (MalformedURLException e) {
        logger.error("Non e' stato possibile creare l'URL per il file " + szFile.getPath(), e);
        throw e;
    }

    dsParams += anURL;
    DataStore newDs;

    try {
        newDs = CreaDsComp(dsParams, "org.geotools.data.shapefile.ShapefileDataStoreFactory", false);
    } catch (IOException e) {
        logger.error("IOException durante creazione shape DataStore", e);
        throw e;
    } catch (SITSchemaException e) {
        logger.error("SITSchemaException durante creazione shape DataStore", e);
        throw e;
    } catch (SITException e) {
        logger.warn("SITException durante creazione shape DataStore", e);
        throw e;
    }

    return newDs;
}

From source file:org.apache.geode.internal.cache.GemFireCacheImpl.java

public URL getCacheXmlURL() {
    if (this.getMyId().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) {
        return null;
    }//  w w w.  j  a va2 s  . c  o  m
    File xmlFile = testCacheXml;
    if (xmlFile == null) {
        xmlFile = this.system.getConfig().getCacheXmlFile();
    }
    if ("".equals(xmlFile.getName())) {
        return null;
    }

    URL url = null;
    if (!xmlFile.exists() || !xmlFile.isFile()) {
        // do a resource search
        String resource = xmlFile.getPath();
        resource = resource.replaceAll("\\\\", "/");
        if (resource.length() > 1 && resource.startsWith("/")) {
            resource = resource.substring(1);
        }
        url = ClassPathLoader.getLatest().getResource(getClass(), resource);
    } else {
        try {
            url = xmlFile.toURL();
        } catch (IOException ex) {
            throw new CacheXmlException(LocalizedStrings.GemFireCache_COULD_NOT_CONVERT_XML_FILE_0_TO_AN_URL
                    .toLocalizedString(xmlFile), ex);
        }
    }
    if (url == null) {
        File defaultFile = DistributionConfig.DEFAULT_CACHE_XML_FILE;
        if (!xmlFile.equals(defaultFile)) {
            if (!xmlFile.exists()) {
                throw new CacheXmlException(
                        LocalizedStrings.GemFireCache_DECLARATIVE_CACHE_XML_FILERESOURCE_0_DOES_NOT_EXIST
                                .toLocalizedString(xmlFile));
            } else /* if (!xmlFile.isFile()) */ {
                throw new CacheXmlException(LocalizedStrings.GemFireCache_DECLARATIVE_XML_FILE_0_IS_NOT_A_FILE
                        .toLocalizedString(xmlFile));
            }
        }
    }

    return url;
}

From source file:org.talend.repository.ui.wizards.metadata.connection.database.DatabaseForm.java

private void addListenerForAuthentication() {
    useKeyTab.addSelectionListener(new SelectionAdapter() {

        @Override//from  w  w w .jav  a  2 s. co m
        public void widgetSelected(SelectionEvent e) {
            if (useKeyTab.getSelection()) {
                GridData hadoopData = (GridData) keyTabComponent.getLayoutData();
                hadoopData.exclude = false;
                keyTabComponent.setVisible(true);
                keyTabComponent.setLayoutData(hadoopData);
                keyTabComponent.getParent().layout();
                authenticationGrp.layout();
                authenticationGrp.getParent().layout();
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_USEKEYTAB, "true");
            } else {
                GridData hadoopData = (GridData) keyTabComponent.getLayoutData();
                hadoopData.exclude = true;
                keyTabComponent.setVisible(false);
                keyTabComponent.setLayoutData(hadoopData);
                keyTabComponent.getParent().layout();
                authenticationGrp.layout();
                authenticationGrp.getParent().layout();
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_USEKEYTAB, "false");
            }
        }

    });
    useKerberos.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (useKerberos.getSelection()) {
                GridData hadoopData = (GridData) authenticationCom.getLayoutData();
                hadoopData.exclude = false;
                authenticationCom.setVisible(true);
                authenticationCom.setLayoutData(hadoopData);
                authenticationCom.getParent().layout();
                authenticationGrp.layout();
                authenticationGrp.getParent().layout();
                getConnection().getParameters().put(ConnParameterKeys.CONN_PARA_KEY_USE_KRB, "true");
            } else {
                GridData hadoopData = (GridData) authenticationCom.getLayoutData();
                hadoopData.exclude = true;
                authenticationCom.setVisible(false);
                authenticationCom.setLayoutData(hadoopData);
                authenticationCom.getParent().layout();
                authenticationGrp.layout();
                authenticationGrp.getParent().layout();
                getConnection().getParameters().put(ConnParameterKeys.CONN_PARA_KEY_USE_KRB, "false");
            }
            urlConnectionStringText.setText(getStringConnection());
        }

    });
    hivePrincipalTxt.getTextControl().addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isContextMode()) {
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_HIVEPRINCIPLA,
                        hivePrincipalTxt.getText());
                urlConnectionStringText.setText(getStringConnection());
            }
        }
    });
    metastoreUrlTxt.getTextControl().addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isContextMode()) {
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_METASTOREURL,
                        metastoreUrlTxt.getText());
            }
        }
    });
    driverJarTxt.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (validText(driverJarTxt.getText())) {
                    getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERJAR_PATH,
                            driverJarTxt.getText());
                }
            }
        }
    });
    browseDriverJarBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectDatabaseJarDialog dialog = new SelectDatabaseJarDialog(getShell(), driverJarTxt.getText());
            if (dialog.open() == Window.OK) {
                driverJarTxt.setText(dialog.getJarsString());
            }
        }

    });
    driverClassTxt.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isContextMode()) {
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERCLASS,
                        driverClassTxt.getText());
            }
        }
    });
    browseDriverClassButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            driverClassTxt.removeAll();
            for (String stringToFile : driverJarTxt.getText().trim().split(";")) { //$NON-NLS-1$
                File file = new File(stringToFile);
                if (file != null) {
                    try {
                        MyURLClassLoader cl = new MyURLClassLoader(file.toURL());
                        Class[] classes = cl.getAssignableClasses(Driver.class);
                        for (Class classe : classes) {
                            driverClassTxt.add(classe.getName());
                        }
                    } catch (Exception ex) {
                        ExceptionHandler.process(ex);
                    }
                }
            }
            if (driverClassTxt.getItemCount() > 0) {
                String driverClassName = driverClassTxt.getItem(0);
                driverClassTxt.setText(driverClassName);
            }
        }
    });
    usernameTxt.getTextControl().addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isContextMode()) {
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_USERNAME,
                        usernameTxt.getText());
            }
        }
    });
    passwordTxt.getTextControl().addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isContextMode()) {
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_PASSWORD,
                        passwordTxt.getText());
            }
        }
    });
    principalTxt.getTextControl().addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isContextMode()) {
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_PRINCIPLA,
                        principalTxt.getText());
            }
        }
    });
    keytabTxt.getTextControl().addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isContextMode()) {
                getConnection().getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_KEYTAB,
                        keytabTxt.getText());
            }
        }
    });
}

From source file:org.talend.repository.ui.wizards.metadata.connection.database.DatabaseForm.java

/**
 * DOC YeXiaowei Comment method "addGeneralDbFieldsListeners".
 *//*w ww  .  j  a  va 2s.  com*/
private void addGeneralDbFieldsListeners() {

    generalJdbcClassNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (validText(generalJdbcClassNameText.getText())) {
                    getConnection().setDriverClass(generalJdbcClassNameText.getText());
                }
                checkFieldsValue();
            }
        }
    });

    generalJdbcDriverjarText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (validText(generalJdbcDriverjarText.getText())) {
                    getConnection().setDriverJarPath(generalJdbcDriverjarText.getText());
                }
                checkFieldsValue();
            }
        }
    });

    generalJdbcUrlText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (validText(generalJdbcUrlText.getText())) {
                    getConnection().setURL(generalJdbcUrlText.getText());
                }
                checkFieldsValue();
            }
        }
    });

    generalJdbcPasswordText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (generalJdbcPasswordText.getText() != null) {
                    getConnection().setRawPassword(generalJdbcPasswordText.getText());
                }
                checkFieldsValue();
            }
        }
    });

    generalJdbcUserText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (validText(generalJdbcUserText.getText())) {
                    getConnection().setUsername(generalJdbcUserText.getText());
                }
                checkFieldsValue();
            }
        }
    });

    jDBCschemaText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                String text = jDBCschemaText.getText();
                schemaText.setText(text);
                if (validText(schemaText.getText())) {
                    getConnection().setUiSchema(schemaText.getText());
                    checkFieldsValue();
                }
            }
        }
    });

    generalMappingFileText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (validText(generalMappingFileText.getText())) {
                    getConnection().setDbmsId(generalMappingFileText.getText());
                }
                checkFieldsValue();
            }
        }
    });

    mappingFileText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (!isContextMode()) {
                if (validText(mappingFileText.getText())) {
                    getConnection().setDbmsId(mappingFileText.getText());
                    checkFieldsValue();
                }
            }
        }
    });

    browseJarFilesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String value = generalJdbcDriverjarText.getText();
            if (value != null && value.length() > 0) {
                IPath path = Path.fromOSString(value);
                if (path.lastSegment() != null) {
                    value = path.lastSegment();
                }
            }
            ModuleListDialog dialog = new ModuleListDialog(getShell(), value, null, true);

            if (dialog.open() == Window.OK) {
                if (dialog.getSelecteModuleArray() != null) {
                    String[] moduleArray = dialog.getSelecteModuleArray();
                    StringBuffer modeleList = new StringBuffer();
                    for (int i = 0; i < moduleArray.length; i++) {
                        String module = moduleArray[i];
                        modeleList.append(module);
                        if (i < moduleArray.length - 1) {
                            modeleList.append(";");
                        }
                    }
                    generalJdbcDriverjarText.setText(modeleList.toString());
                } else if (dialog.getSelecteModule() != null) {
                    String selecteModule = dialog.getSelecteModule();
                    generalJdbcDriverjarText.setText(selecteModule);
                }
            }
        }

    });

    browseClassButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {

            generalJdbcClassNameText.removeAll();
            for (String jarName : generalJdbcDriverjarText.getText().trim().split(";")) { //$NON-NLS-1$
                String stringToFile = getselecteModulePath(jarName);
                if (stringToFile == null) {
                    stringToFile = jarName;
                }
                File file = new File(stringToFile);
                if (file != null) {
                    try {
                        MyURLClassLoader cl = new MyURLClassLoader(file.toURL());
                        Class[] classes = cl.getAssignableClasses(Driver.class);
                        for (Class classe : classes) {
                            generalJdbcClassNameText.add(classe.getName());
                        }
                    } catch (Exception ex) {
                        ExceptionHandler.process(ex);
                    }
                }
            }
            if (generalJdbcClassNameText.getItemCount() > 0) {
                String driverClassName = generalJdbcClassNameText.getItem(0);
                generalJdbcClassNameText.setText(driverClassName);
            }
        }
    });

    generalMappingSelectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MappingFileSelectDialog dialog = new MappingFileSelectDialog(getShell());
            dialog.open();
            generalMappingFileText.setText(dialog.getSelectId());
        }
    });
    mappingSelectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            MappingFileSelectDialog dialog = new MappingFileSelectDialog(getShell());
            dialog.open();
            mappingFileText.setText(dialog.getSelectId());
        }
    });
}

From source file:org.kalypso.dwd.DWDTaskDelegate.java

public void execute(final ILogger logger, final URL obsRasterURL, final URL dwd2zmlConfUrl,
        final File targetContext, final Date startSim, final Date startForecast, final Date stopSim,
        String filter, final Properties metadata) throws Exception {
    m_metadata = metadata;/*  ww  w .  j  a v a2s  .  co  m*/

    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " inputRaster: " + obsRasterURL);
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " raster to zml mapping: " + dwd2zmlConfUrl);
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " context for targets (zml-files): " + targetContext);
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " unmarshall dwd2zml configuration ...");

    final Unmarshaller unmarshaller = JC.createUnmarshaller();
    final DwdzmlConf conf = (DwdzmlConf) unmarshaller.unmarshal(dwd2zmlConfUrl);
    final String axisType = DWDRasterHelper.getAxisTypeForDWDKey(conf.getDwdKey());
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " type of ZML to generate" + axisType);

    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " read inputraster...");
    DWDObservationRaster obsRaster = null;
    try {
        // conf.getNumberOfCells()
        obsRaster = DWDRasterHelper.loadObservationRaster(obsRasterURL, conf.getDwdKey());
    } catch (final Exception e) {
        logger.log(Level.SEVERE, LoggerUtilities.CODE_SHOW_MSGBOX,
                "Konnte Raster nicht laden, DWD-Vorhersage kann nicht verwendet werden: "
                        + e.getLocalizedMessage());
    }

    if (obsRaster != null) {
        final Calendar baseDateCal = Calendar.getInstance();
        baseDateCal.setTime(obsRaster.getBaseDate());

        // REMARK: as the DWD Date wa previously read with UTC-1 (probably wrongly), because of the Saale-Model (HWVOR00),
        // we now delete that hour from the date in order to have a nice message with even dates 0/12 hours.
        // This has to be corrected as sson as we know what timeszone the DWD-LM-Data is truly in.
        baseDateCal.add(Calendar.HOUR, -1);

        final Date firstRasterDate = baseDateCal.getTime();

        /* Produce warning, if rasterDate is much before startForecast */
        if (firstRasterDate == null || startForecast == null)
            logger.log(Level.SEVERE, LoggerUtilities.CODE_SHOW_MSGBOX,
                    "Startdatum der DWD-Rasterdaten konnte nicht ermittelt werden oder Vorhersagezeitpunkt ist nicht gesetzt. Prfen Sie den Dateneingang.");
        else {
            final long distance = startForecast.getTime() - firstRasterDate.getTime();
            final Double distanceInHours = new Double((double) distance / (1000 * 60 * 60));

            final String msg = String.format("DWD-Lokalmodell vom %s",
                    new Object[] { DWD_DATEFORMAT.format(firstRasterDate) });

            if (distanceInHours.doubleValue() > 12) {
                logger.log(Level.WARNING, LoggerUtilities.CODE_SHOW_MSGBOX,
                        "DWD Daten veraltet, bitte prfen Sie den Dateneingang.");
                logger.log(Level.INFO, LoggerUtilities.CODE_SHOW_DETAILS, msg);
            } else if (distanceInHours.doubleValue() < -12) {
                logger.log(Level.WARNING, LoggerUtilities.CODE_SHOW_MSGBOX,
                        "Vorhersagezeitraum liegt deutlich (>12h) vor dem Datum der DWD Daten. Bitte prfen Sie den Dateneingang.");
                logger.log(Level.INFO, LoggerUtilities.CODE_SHOW_DETAILS, msg);
            } else
                // in order to always have a message, if nothing else happens make this mesage a main message
                logger.log(Level.INFO, LoggerUtilities.CODE_SHOW_MSGBOX, msg);
        }
    }
    final List<Target> targetList = conf.getTarget();
    if (filter == null)
        filter = "";
    else
        logger.log(Level.FINE, LoggerUtilities.CODE_NONE, "benutze Filter: " + filter);

    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, "Zeitraum ");
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " von " + startSim + " (Messung");
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " von " + startForecast + " (Vorhersage)");
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " bis " + stopSim);
    logger.log(Level.FINE, LoggerUtilities.CODE_NONE, " generate zml...");
    // iterate zml to generate

    for (final Target targetZML : targetList) {
        final String targetZMLref = targetZML.getTargetZR();
        final File resultFile = new File(targetContext, targetZMLref);

        // iterate hours

        final Date[] dates;
        if (obsRaster != null)
            dates = obsRaster.getDates(startForecast, stopSim);
        else
            dates = new Date[0];
        final Object[][] tupleData = new Object[dates.length][3];
        for (int i = 0; i < dates.length; i++) {
            final Date date = dates[i];
            // iterate rastercells
            final List<Map> map = targetZML.getMap();
            double value = 0;

            for (final Map mapping : map) {
                final int cellPos = mapping.getCellPos();
                final double factor = mapping.getFactor();
                value += factor * obsRaster.getValueFor(date, cellPos);
            }
            tupleData[i][0] = date;
            tupleData[i][1] = new Double(value);
            tupleData[i][2] = new Integer(KalypsoStati.BIT_OK);
        }
        resultFile.getParentFile().mkdirs();

        try {
            final IAxis dateAxis = new DefaultAxis("Datum", ITimeseriesConstants.TYPE_DATE, "", Date.class,
                    true, true);
            final String title = TimeserieUtils.getName(axisType);
            final IAxis valueAxis = new DefaultAxis(title, axisType, TimeserieUtils.getUnit(axisType),
                    TimeserieUtils.getDataClass(axisType), false, true);
            final IAxis statusAxis = KalypsoStatusUtils.createStatusAxisFor(valueAxis, true);
            final IAxis[] axis = new IAxis[] { dateAxis, valueAxis, statusAxis };

            final ITupleModel tupleModel = new SimpleTupleModel(axis, tupleData);

            final MetadataList metadataList = new MetadataList();

            final IObservation dwdObservation = new SimpleObservation("href", title, metadataList, tupleModel);

            final IObservation forecastObservation;
            // generate href from filter and intervall
            final String href = ZmlURL.insertRequest(filter, new ObservationRequest(startForecast, stopSim));
            forecastObservation = ZmlFactory.decorateObservation(dwdObservation, href, targetContext.toURL());

            // ----------------
            // merge with target:
            // load target
            final ObservationRequest observationRequest = new ObservationRequest(startSim, startForecast);
            final String sourceref = ZmlURL.insertRequest(targetZMLref, observationRequest);

            final URL sourceURL = new UrlResolver().resolveURL(targetContext.toURL(), sourceref);
            IObservation targetObservation = null;
            try {
                targetObservation = ZmlFactory.parseXML(sourceURL);
            } catch (final Exception e) {
                // nothing, if target is not existing it will be ignored
            }
            final ForecastFilter fc = new ForecastFilter();
            final IObservation[] srcObs;
            if (targetObservation != null)
                srcObs = new IObservation[] { targetObservation, forecastObservation };
            else
                srcObs = new IObservation[] { forecastObservation };

            // important: the forecast-filter is based on the target-obs (if existing)
            // in order to keep its metadata & co
            final IObservation baseObservation;
            if (targetObservation != null)
                baseObservation = targetObservation;
            else
                baseObservation = new SimpleObservation(axis);

            fc.initFilter(srcObs, baseObservation, targetContext.toURL());
            MetadataHelper.setTargetForecast(fc.getMetadataList(), startForecast, stopSim);

            // ----------------
            // add all the metadata from task-parameters
            fc.getMetadataList().putAll(m_metadata);
            //
            final Observation observationType = ZmlFactory.createXML(fc, null);
            final Marshaller marshaller = ZmlFactory.getMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

            final FileOutputStream fileWriter = new FileOutputStream(resultFile);
            final OutputStreamWriter streamWriter = new OutputStreamWriter(fileWriter, "UTF-8");
            try {
                marshaller.marshal(observationType, streamWriter);
            } finally {
                IOUtils.closeQuietly(streamWriter);
                IOUtils.closeQuietly(fileWriter);
            }
        } catch (final Exception e) {
            throw e;
        }
    }
}

From source file:be.ibridge.kettle.spoon.Spoon.java

protected void showWelcomePage() {
    try {//from  w w  w.  j  a va  2s .  c o  m
        File file = new File(FILE_WELCOME_PAGE);
        addSpoonBrowser(STRING_WELCOME_TAB_NAME, file.toURL().toString()); // ./docs/English/tips/index.htm
    } catch (MalformedURLException e1) {
        log.logError(toString(), Const.getStackTracker(e1));
    }
}

From source file:de.innovationgate.wgpublisher.WGACore.java

private void buildLibraryLoaders() {

    // Build jars list
    List<URL> jarsList = new ArrayList<URL>();

    String libraries = _wgaConfiguration.getServerOptions().get(WGAConfiguration.SERVEROPTION_LIBRARIES);
    if (libraries != null && !libraries.trim().equals("")) {
        StringTokenizer tokens = new StringTokenizer(libraries, ";");
        String token;/*from  w  w w .  j  a  v a  2s.c o m*/
        while (tokens.hasMoreTokens()) {

            token = tokens.nextToken();

            if (token.endsWith("/*")) {
                File libDir = getWGAFile(token.substring(0, token.length() - 2));
                if (libDir != null && libDir.exists() && libDir.isDirectory()) {
                    for (File libFile : libDir.listFiles()) {
                        if (libFile.getName().endsWith(".jar")) {
                            addLibraryFile(jarsList, libFile);
                        }
                    }
                } else {
                    log.warn("Library entry is not a valid directory: " + token);
                }
            } else {
                File libFile = getWGAFile(token);
                addLibraryFile(jarsList, libFile);
            }
        }
    }

    // add all jars from <configdir>/libs
    File baseLibDir = getBaseLibraryDir();
    if (baseLibDir != null && baseLibDir.exists() && baseLibDir.canRead()) {
        File[] additionalJarFiles = baseLibDir.listFiles(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".jar");
            }

        });

        for (File jarFile : additionalJarFiles) {
            try {
                jarsList.add(jarFile.toURL());
                log.info("Registering library '" + jarFile.getAbsolutePath() + "'.");
            } catch (MalformedURLException e) {
                this.log.warn("Registering library '" + jarFile.getAbsolutePath() + "' failed.", e);
            }
        }
    }

    // Build URL array from jars list
    URL[] loaderURLs = new URL[jarsList.size()];
    for (int idx = 0; idx < jarsList.size(); idx++) {
        loaderURLs[idx] = jarsList.get(idx);
    }

    baseLibraryLoader = new IsolatedJARLoader(loaderURLs, getClass().getClassLoader());
    getLog().info("Creating WGA java library loader");
    libraryClassLoadingChain = new DynamicClassLoadingChain(baseLibraryLoader);
    WGFactory.setImplementationLoader(libraryClassLoadingChain);
    updateLibraryLoader();
    _libraryXStream = new XStream(new Dom4JDriver());
    _libraryXStream.setClassLoader(libraryClassLoadingChain);

}