Example usage for java.lang Integer decode

List of usage examples for java.lang Integer decode

Introduction

In this page you can find the example usage for java.lang Integer decode.

Prototype

public static Integer decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into an Integer .

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.BlockChart.java

/**
 * Creates a chart for the specified dataset.
 * /*w  w w .  java  2s.  com*/
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");
    //Creates the xAxis with its label and style
    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setLabel(xLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    //Creates the yAxis with its label and style
    NumberAxis yAxis = new NumberAxis(yLabel);

    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setInverted(false);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setTickLabelsVisible(true);
    yAxis.setLabel(yLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    Color outboundCol = new Color(Integer.decode(outboundColor).intValue());

    //Sets the graph paint scale and the legend paintscale
    LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(),
            outboundCol);
    LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol);

    for (int ke = 0; ke <= (zvalues.length - 1); ke++) {
        Double key = (new Double(zvalues[ke]));
        Color temp = (Color) colorRangeMap.get(key);
        paintScale.add(zvalues[ke], temp);
        legendPaintScale.add(0.5 + ke, temp);
    }
    //Configures the renderer
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    double blockHeight = (new Double(blockH)).doubleValue();
    double blockWidth = (new Double(blockW)).doubleValue();
    renderer.setBlockWidth(blockWidth);
    renderer.setBlockHeight(blockHeight);

    //configures the plot with title, subtitle, axis ecc.
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainCrosshairPaint(Color.black);

    plot.setForegroundAlpha(0.66f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    //Sets legend labels
    SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels);
    scaleAxis.setRange(0.5, 0.5 + zvalues.length);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    scaleAxis.setLabel(zLabel);
    //scaleAxis.setLabelAngle(3.14/2);
    scaleAxis.setLabelFont(addLabelsStyle.getFont());
    scaleAxis.setLabelPaint(addLabelsStyle.getColor());

    //draws legend as chart subtitle
    PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis);
    psl.setAxisOffset(2.0);
    psl.setPosition(RectangleEdge.RIGHT);
    psl.setMargin(new RectangleInsets(5, 1, 5, 1));
    chart.addSubtitle(psl);

    if (yLabels != null) {
        //Sets y legend labels
        LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white);

        for (int ke = 0; ke < yLabels.length; ke++) {
            Color temp = Color.white;
            legendPaintScale2.add(1 + ke, temp);
        }

        SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels);
        scaleAxis2.setRange(0, (yLabels.length - 1));
        scaleAxis2.setPlot(new PiePlot());
        scaleAxis2.setGridBandsVisible(false);

        //draws legend as chart subtitle
        PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2);
        psl2.setAxisOffset(5.0);
        psl2.setPosition(RectangleEdge.LEFT);
        psl2.setMargin(new RectangleInsets(8, 1, 40, 1));
        psl2.setStripWidth(0);
        psl2.setStripOutlineVisible(false);
        chart.addSubtitle(psl2);
    }

    return chart;
}

From source file:com.xlson.standalonewar.Starter.java

public static void start() throws Exception {
    final String PROP_NAME_WEBSERVER_BIND_ADDRESS = defaultProperties
            .getString("PROP_NAME_WEBSERVER_BIND_ADDRESS", "webserver.bindAddress");
    final String PROP_NAME_WEBSERVER_LISTENPORT = defaultProperties.getString("PROP_NAME_WEBSERVER_LISTENPORT",
            "webserver.listenPort");
    final String PROP_NAME_WEBSERVER_TEMPDIR = defaultProperties.getString("PROP_NAME_WEBSERVER_TEMPDIR",
            "webserver.tempDir");
    final String PROP_NAME_WEBSERVER_ROOT = defaultProperties.getString("PROP_NAME_WEBSERVER_ROOT",
            "webserver.root");
    final String PROP_NAME_WEBSERVER_SSL = defaultProperties.getString("PROP_NAME_WEBSERVER_SSL",
            "webserver.ssl");
    final String PROP_NAME_WEBSERVER_SSL_LISTENPORT = defaultProperties
            .getString("PROP_NAME_WEBSERVER_SSL_LISTENPORT", "webserver.ssl.listenPort");
    final String PROP_NAME_WEBSERVER_SSL_KEYSTORE_TYPE = defaultProperties
            .getString("PROP_NAME_WEBSERVER_SSL_KEYSTORE_TYPE", "webserver.ssl.keyStoreType");
    final String PROP_NAME_WEBSERVER_SSL_KEYSTORE_FILE = defaultProperties
            .getString("PROP_NAME_WEBSERVER_SSL_KEYSTORE_FILE", "webserver.ssl.keyStoreFile");
    final String PROP_NAME_WEBSERVER_SSL_KEYSTORE_PASSWORD = defaultProperties
            .getString("PROP_NAME_WEBSERVER_SSL_KEYSTORE_PASSWORD", "webserver.ssl.keyStorePassword");

    config = loadConfig();/*  ww  w . ja  v a2  s. c  om*/

    String tempPath = getString(PROP_NAME_WEBSERVER_TEMPDIR, System.getProperty("java.io.tmpdir"));
    logger.info("using '" + tempPath + "' as temporary directory");

    String documentRoot = getString(PROP_NAME_WEBSERVER_ROOT, warLocation.toExternalForm());
    logger.info("using '" + documentRoot + "' as the document root");

    server = new Server();

    String bindAddress = getString(PROP_NAME_WEBSERVER_BIND_ADDRESS, "0.0.0.0");

    HttpConfiguration http_config = new HttpConfiguration();
    boolean hasSslConfigured = false;

    if ("true".equalsIgnoreCase(getString(PROP_NAME_WEBSERVER_SSL))) {
        /* Note: the default keystore file type for war-launcher is PKCS12, you create a PKCS12 key store file with:
         *
         *  1) OpenSSL: openssl pkcs12 -export -clcerts -in example.com.crt -inkey example.com.key -out example.com.p12
         *  2) keytool: @TODO
         */
        String keyStoreType = getString(PROP_NAME_WEBSERVER_SSL_KEYSTORE_TYPE, "PKCS12");
        logger.info("using '" + keyStoreType + "' as key store type");

        String keyStoreFile = getString(PROP_NAME_WEBSERVER_SSL_KEYSTORE_FILE, null);
        if (keyStoreFile == null) {
            throw new RuntimeException(
                    "ssl requires a property value for: " + PROP_NAME_WEBSERVER_SSL_KEYSTORE_FILE);
        } else {
            logger.info("using '" + keyStoreFile + "' as key store file");
        }

        String keyStorePassword = getString(PROP_NAME_WEBSERVER_SSL_KEYSTORE_PASSWORD);

        int defaultSslListenPort = Integer
                .parseInt(defaultProperties.getString("webserver.ssl.defaultListenPort", "8443"));
        String sslListenPort = getString(PROP_NAME_WEBSERVER_SSL_LISTENPORT, null);
        int sslPort;
        if (sslListenPort == null) {
            logger.warn(
                    "'" + PROP_NAME_WEBSERVER_SSL_LISTENPORT + "' was not specified, using the default port.");
            sslPort = defaultSslListenPort;
        } else {
            sslPort = Integer.decode(sslListenPort);
            logger.info("using port '" + sslPort + "' for ssl connections");
        }

        http_config.setSecureScheme("https");
        http_config.setSecurePort(sslPort);
        http_config.setOutputBufferSize(1048576);
        http_config.setRequestHeaderSize(16384);
        http_config.setResponseHeaderSize(16384);
        hasSslConfigured = true;

        SslContextFactory sslContextFactory = new SslContextFactory();
        try {
            logger.info("Adding HTTPS connector for " + bindAddress + ":" + sslPort);
            // connector.setKeystoreType(keyStoreType); // @TODO do we need to set this?
            sslContextFactory.setKeyStorePath(keyStoreFile);
            sslContextFactory.setKeyStorePassword(keyStorePassword);
            sslContextFactory.setKeyManagerPassword(keyStorePassword);

        } catch (Exception ex) {
            logger.error("error", ex);
        }
    }

    int defaultListenPort = Integer
            .parseInt(defaultProperties.getString("webserver.defaultListenPort", "8080"));
    String listenPort = getString(PROP_NAME_WEBSERVER_LISTENPORT, null);
    System.out.println("The listenPort from getString: " + listenPort);
    if ((listenPort == null) || (!hasSslConfigured)) {
        ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(http_config));

        if (listenPort == null) {
            logger.warn("'" + PROP_NAME_WEBSERVER_LISTENPORT + "' was not specified, using the default port.");
        }

        int port = getInteger(PROP_NAME_WEBSERVER_LISTENPORT, defaultListenPort);
        connector.setHost(bindAddress);
        connector.setPort(port);
        connector.setIdleTimeout(1000 * 60 * 60);
        connector.setSoLingerTime(-1);

        logger.info("Adding HTTP connector for " + bindAddress + ":" + port);
        server.addConnector(connector);
    } else {
        logger.warn("'" + PROP_NAME_WEBSERVER_LISTENPORT
                + "' was not specified, but other connectors already registered, so no default connector was added for port "
                + defaultListenPort);
    }

    WebAppContext webapp = new WebAppContext();
    String extraClasspath = getString("webserver.extraClasspath", "");

    logger.info("Setting extra classpath for webapp: {}", extraClasspath);

    webapp.setExtraClasspath(extraClasspath);
    webapp.setContextPath("/");
    //      webapp.setTempDirectory(new File(tempPath));
    webapp.setServer(server);
    webapp.setWar(warLocation.toExternalForm());
    if (!"".equals(getString("javax.servlet.context.tempdir", ""))) {
        webapp.setAttribute("javax.servlet.context.tempdir", getString("javax.servlet.context.tempdir"));
    }
    webapp.setPersistTempDirectory(true);
    //      if(!warLocation.toExternalForm().equals(documentRoot)) {
    //         webapp.setResourceBase(documentRoot);
    //      }

    server.setHandler(webapp);
    server.start();
}

From source file:de.crowdcode.kissmda.maven.plugin.KissMdaMojo.java

private void useTransformerNamesWithOrder(Injector parentInjector)
        throws MojoExecutionException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    // Read the list and parse:
    // 1:de.crowdcode.kissmda.cartridges.extensions.ExtensionExamplesTransformer
    // Put it in a map and sort the content after the order
    Map<Integer, String> sortedtTransformerNameWithOrders = new TreeMap<Integer, String>();

    for (String content : transformerNameWithOrders) {
        String order = StringUtils.substringBefore(content, ":");
        Integer orderAsInt = Integer.decode(order);
        String transformerClazz = StringUtils.substringAfter(content, ":");
        sortedtTransformerNameWithOrders.put(orderAsInt, transformerClazz);
    }//w  w w . j  av  a 2s.  co  m

    for (Map.Entry<Integer, String> entry : sortedtTransformerNameWithOrders.entrySet()) {
        // We need the counterpart Guice module for this transformer
        // In the same package but with Module as suffix
        String transformerClazzName = entry.getValue();
        String guiceModuleClazzName = getGuiceModuleName(transformerClazzName);
        Class<? extends Transformer> transformerClazz = Class.forName(transformerClazzName)
                .asSubclass(Transformer.class);
        Class<? extends Module> guiceModuleClazz = Class.forName(guiceModuleClazzName).asSubclass(Module.class);

        logger.info("Start the transformation with following Transformer: " + transformerClazzName
                + " - order: " + entry.getKey());
        // Create the transformer class with Guice module as child
        // injector and execute
        Injector injector = parentInjector.createChildInjector(guiceModuleClazz.newInstance());
        Transformer transformer = injector.getInstance(transformerClazz);
        transformer.transform(context);

        logger.info("Stop the transformation with following Transformer:" + transformerClazzName);
    }
}

From source file:it.geosolutions.opensdi.operations.NDVIStatisticsOperation.java

/**
 * Obtain file name for a NDVI for a String formatted as 'yyMmDecad'.<br />
 * For example, for the input String <code>13011</code> the result it's
 * <code>dv_20130101_20130110.tiff</code>
 * /*from   w w  w . j  a v  a  2s .  c o m*/
 * @param yyMmDekad String with year in the positions (0,1), month in the
 *        positions 2 and 3 and dekad in the last position
 * @return NDVI file name for the parameters
 */
protected String getNDVIFileName(String yyMmDekad) {
    Integer year = 2000 + Integer.decode(yyMmDekad.substring(0, 2));
    String mm = yyMmDekad.substring(2, 4);
    Integer month = Integer.decode(mm);
    String dekadS = yyMmDekad.substring(4);
    Dekad dekad = dekadS.equals("2") ? Dekad.SECOND : dekadS.equals("3") ? Dekad.THIRD : Dekad.FIRST;
    // First day: can be 01, 11 or 21
    String ddStart = DekadUtils.getFirstDay(year, month, dekad.ordinal()) + "";
    if (ddStart.length() == 1) {
        ddStart = "01";
    }
    // End day: can be: 10, 20 or the last day of the month
    Integer endDay = DekadUtils.getLastDay(year, month, dekad.ordinal());
    String ddEnd = endDay.toString();

    // Final name dv_20130101_20130110.tiff
    return NDVI_FILE_NAME_PREFIX + year + mm + ddStart + "_" + year + mm + ddEnd + NDVI_FILE_NAME_EXTENSION;
}

From source file:org.deegree.tools.rendering.manager.buildings.BuildingManager.java

/**
 * @param f/*from   ww w  .j  av a 2 s.co m*/
 * @return
 * @throws IOException
 */
private List<WorldRenderableObject> readGML(String fileName, CommandLine commandLine) throws IOException {
    LOG.debug("Reading buildings from file: " + fileName);
    String schemaLocation = commandLine.getOptionValue(DataManager.OPT_CITY_GML_SCHEMA);

    String color = commandLine.getOptionValue(DataManager.OPT_CITY_GML_COLOR);
    SimpleGeometryStyle style = new SimpleGeometryStyle();
    if (color != null) {
        try {
            int i = Integer.decode(color);
            int diffuseColor = JOGLUtils.convertColorGLColor(new Color(i));
            style.setDiffuseColor(diffuseColor);
            style.setAmbientColor(diffuseColor);
            style.setSpecularColor(diffuseColor);
        } catch (NumberFormatException e) {
            LOG.warn("Could not decode color into an integer: " + color + " using white instead.");
        }
    }

    boolean useOpengis = commandLine.hasOption(DataManager.OPT_USE_OPENGIS);
    CityGMLImporter importer = new CityGMLImporter(schemaLocation,
            new float[] { (float) wpvsTranslationVector[0], (float) wpvsTranslationVector[1], 0 }, style,
            useOpengis);
    return importer.importFromFile(fileName, numberOfqualityLevels, qualityLevel);
}

From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.Cipherer.java

public void setKeyBytes(String inKeyBytes) {
    String[] keyStringArr = inKeyBytes.split("\\s+");
    keyBytes = new byte[keyStringArr.length];
    for (int i = 0; i < keyStringArr.length; i++) {
        keyBytes[i] = Integer.decode(keyStringArr[i]).byteValue();
    }// www.  java2 s.  com
}

From source file:org.kchine.r.server.http.frontend.CommandServlet.java

protected void doAny(final HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession session = null;/*from   w ww .j a  va  2  s.c  o  m*/
    Object result = null;

    try {
        final String command = request.getParameter("method");
        do {

            if (command.equals("ping")) {
                result = "pong";
                break;
            } else if (command.equals("logon")) {

                session = request.getSession(false);
                if (session != null) {
                    result = session.getId();
                    break;
                }

                String login = (String) PoolUtils.hexToObject(request.getParameter("login"));
                String pwd = (String) PoolUtils.hexToObject(request.getParameter("pwd"));
                boolean namedAccessMode = login.contains("@@");
                String sname = null;
                if (namedAccessMode) {
                    sname = login.substring(login.indexOf("@@") + "@@".length());
                    login = login.substring(0, login.indexOf("@@"));
                }

                System.out.println("login :" + login);
                System.out.println("pwd :" + pwd);

                if (_rkit == null && (!login.equals(System.getProperty("login"))
                        || !pwd.equals(System.getProperty("pwd")))) {
                    result = new BadLoginPasswordException();
                    break;
                }

                HashMap<String, Object> options = (HashMap<String, Object>) PoolUtils
                        .hexToObject(request.getParameter("options"));
                if (options == null)
                    options = new HashMap<String, Object>();
                System.out.println("options:" + options);

                RPFSessionInfo.get().put("LOGIN", login);
                RPFSessionInfo.get().put("REMOTE_ADDR", request.getRemoteAddr());
                RPFSessionInfo.get().put("REMOTE_HOST", request.getRemoteHost());

                boolean nopool = !options.keySet().contains("nopool")
                        || ((String) options.get("nopool")).equals("")
                        || !((String) options.get("nopool")).equalsIgnoreCase("false");
                boolean save = options.keySet().contains("save")
                        && ((String) options.get("save")).equalsIgnoreCase("true");
                boolean selfish = options.keySet().contains("selfish")
                        && ((String) options.get("selfish")).equalsIgnoreCase("true");

                String privateName = (String) options.get("privatename");

                int memoryMin = DEFAULT_MEMORY_MIN;
                int memoryMax = DEFAULT_MEMORY_MAX;
                try {
                    if (options.get("memorymin") != null)
                        memoryMin = Integer.decode((String) options.get("memorymin"));
                    if (options.get("memorymax") != null)
                        memoryMax = Integer.decode((String) options.get("memorymax"));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                boolean privateEngineMode = false;
                RServices r = null;
                URL[] codeUrls = null;

                if (_rkit == null) {

                    if (namedAccessMode) {

                        try {
                            if (System.getProperty("submit.mode") != null
                                    && System.getProperty("submit.mode").equals("ssh")) {

                                if (PoolUtils.isStubCandidate(sname)) {
                                    r = (RServices) PoolUtils.hexToStub(sname,
                                            PoolUtils.class.getClassLoader());
                                } else {
                                    r = (RServices) ((DBLayerInterface) SSHTunnelingProxy.getDynamicProxy(
                                            System.getProperty("submit.ssh.host"),
                                            Integer.decode(System.getProperty("submit.ssh.port")),
                                            System.getProperty("submit.ssh.user"),
                                            System.getProperty("submit.ssh.password"),
                                            System.getProperty("submit.ssh.biocep.home"),
                                            "java -Dpools.provider.factory=org.kchine.rpf.db.ServantsProviderFactoryDB -Dpools.dbmode.defaultpoolname=R -Dpools.dbmode.shutdownhook.enabled=false -cp %{install.dir}/biocep-core.jar org.kchine.rpf.SSHTunnelingWorker %{file}",
                                            "db", new Class<?>[] { DBLayerInterface.class })).lookup(sname);
                                }

                            } else {

                                if (PoolUtils.isStubCandidate(sname)) {
                                    r = (RServices) PoolUtils.hexToStub(sname,
                                            PoolUtils.class.getClassLoader());
                                } else {
                                    ServantProviderFactory spFactory = ServantProviderFactory.getFactory();
                                    if (spFactory == null) {
                                        result = new NoRegistryAvailableException();
                                        break;
                                    }
                                    r = (RServices) spFactory.getServantProvider().getRegistry().lookup(sname);
                                }

                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    } else {
                        if (nopool) {

                            /*                         
                            ServantProviderFactory spFactory = ServantProviderFactory.getFactory();
                                    
                            if (spFactory == null) {
                               result = new NoRegistryAvailableException();
                               break;
                            }
                                    
                            String nodeName = options.keySet().contains("node") ? (String) options.get("node") : System
                                  .getProperty("private.servant.node.name");
                            Registry registry = spFactory.getServantProvider().getRegistry();
                            NodeManager nm = null;
                            try {
                               nm = (NodeManager) registry.lookup(System.getProperty("node.manager.name") + "_" + nodeName);
                            } catch (NotBoundException nbe) {
                               nm = (NodeManager) registry.lookup(System.getProperty("node.manager.name"));
                            } catch (Exception e) {
                               result = new NoNodeManagerFound();
                               break;
                            }
                            r = (RServices) nm.createPrivateServant(nodeName);
                             */

                            if (System.getProperty("submit.mode") != null
                                    && System.getProperty("submit.mode").equals("ssh")) {

                                DBLayerInterface dbLayer = (DBLayerInterface) SSHTunnelingProxy.getDynamicProxy(
                                        System.getProperty("submit.ssh.host"),
                                        Integer.decode(System.getProperty("submit.ssh.port")),
                                        System.getProperty("submit.ssh.user"),
                                        System.getProperty("submit.ssh.password"),
                                        System.getProperty("submit.ssh.biocep.home"),
                                        "java -Dpools.provider.factory=org.kchine.rpf.db.ServantsProviderFactoryDB -Dpools.dbmode.defaultpoolname=R -Dpools.dbmode.shutdownhook.enabled=false -cp %{install.dir}/biocep-core.jar org.kchine.rpf.SSHTunnelingWorker %{file}",
                                        "db", new Class<?>[] { DBLayerInterface.class });
                                if (privateName != null && !privateName.equals("")) {
                                    try {
                                        r = (RServices) dbLayer.lookup(privateName);
                                    } catch (Exception e) {
                                        //e.printStackTrace();
                                    }
                                }

                                if (r == null) {

                                    final String uid = (privateName != null && !privateName.equals(""))
                                            ? privateName
                                            : UUID.randomUUID().toString();
                                    final String[] jobIdHolder = new String[1];
                                    new Thread(new Runnable() {
                                        public void run() {
                                            try {

                                                String command = "java -Dlog.file="
                                                        + System.getProperty("submit.ssh.biocep.home")
                                                        + "/log/%{uid}.log" + " -Drmi.port.start="
                                                        + System.getProperty("submit.ssh.rmi.port.start")
                                                        + " -Dname=%{uid}" + " -Dnaming.mode=db" + " -Ddb.host="
                                                        + System.getProperty("submit.ssh.host") + " -Dwait=true"
                                                        + " -jar "
                                                        + System.getProperty("submit.ssh.biocep.home")
                                                        + "/biocep-core.jar";

                                                jobIdHolder[0] = SSHUtils.execSshBatch(command, uid,
                                                        System.getProperty("submit.ssh.prefix"),
                                                        System.getProperty("submit.ssh.host"),
                                                        Integer.decode(System.getProperty("submit.ssh.port")),
                                                        System.getProperty("submit.ssh.user"),
                                                        System.getProperty("submit.ssh.password"),
                                                        System.getProperty("submit.ssh.biocep.home"));
                                                System.out.println("jobId:" + jobIdHolder[0]);

                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    }).start();

                                    long TIMEOUT = Long.decode(System.getProperty("submit.ssh.timeout"));
                                    long tStart = System.currentTimeMillis();
                                    while ((System.currentTimeMillis() - tStart) < TIMEOUT) {
                                        try {
                                            r = (RServices) dbLayer.lookup(uid);
                                        } catch (Exception e) {

                                        }
                                        if (r != null)
                                            break;
                                        try {
                                            Thread.sleep(10);
                                        } catch (Exception e) {
                                        }
                                    }

                                    if (r != null) {
                                        try {
                                            r.setJobId(jobIdHolder[0]);
                                        } catch (Exception e) {
                                            r = null;
                                        }
                                    }

                                }

                            } else {
                                System.out.println("LocalHttpServer.getLocalHttpServerPort():"
                                        + LocalHttpServer.getLocalHttpServerPort());
                                System.out.println("LocalRmiRegistry.getLocalRmiRegistryPort():"
                                        + LocalHttpServer.getLocalHttpServerPort());
                                if (privateName != null && !privateName.equals("")) {
                                    try {
                                        r = (RServices) LocalRmiRegistry.getInstance().lookup(privateName);
                                    } catch (Exception e) {
                                        //e.printStackTrace();
                                    }
                                }

                                if (r == null) {
                                    codeUrls = (URL[]) options.get("urls");
                                    System.out.println("CODE URL->" + Arrays.toString(codeUrls));
                                    //String 
                                    r = ServerManager.createR(System.getProperty("r.binary"), false, false,
                                            PoolUtils.getHostIp(), LocalHttpServer.getLocalHttpServerPort(),
                                            ServerManager.getRegistryNamingInfo(PoolUtils.getHostIp(),
                                                    LocalRmiRegistry.getLocalRmiRegistryPort()),
                                            memoryMin, memoryMax, privateName, false, codeUrls, null,
                                            (_webAppMode ? "javaws" : "standard"), null, "127.0.0.1");
                                }

                                privateEngineMode = true;
                            }

                        } else {

                            if (System.getProperty("submit.mode") != null
                                    && System.getProperty("submit.mode").equals("ssh")) {

                                ServantProvider servantProvider = (ServantProvider) SSHTunnelingProxy
                                        .getDynamicProxy(System.getProperty("submit.ssh.host"),
                                                Integer.decode(System.getProperty("submit.ssh.port")),
                                                System.getProperty("submit.ssh.user"),
                                                System.getProperty("submit.ssh.password"),
                                                System.getProperty("submit.ssh.biocep.home"),
                                                "java -Dpools.provider.factory=org.kchine.rpf.db.ServantsProviderFactoryDB -Dpools.dbmode.defaultpoolname=R -Dpools.dbmode.shutdownhook.enabled=false -cp %{install.dir}/biocep-core.jar org.kchine.rpf.SSHTunnelingWorker %{file}",
                                                "servant.provider", new Class<?>[] { ServantProvider.class });
                                boolean wait = options.keySet().contains("wait")
                                        && ((String) options.get("wait")).equalsIgnoreCase("true");
                                String poolname = ((String) options.get("poolname"));
                                if (wait) {
                                    r = (RServices) (poolname == null || poolname.trim().equals("")
                                            ? servantProvider.borrowServantProxy()
                                            : servantProvider.borrowServantProxy(poolname));
                                } else {
                                    r = (RServices) (poolname == null || poolname.trim().equals("")
                                            ? servantProvider.borrowServantProxyNoWait()
                                            : servantProvider.borrowServantProxyNoWait(poolname));
                                }

                                System.out.println("---> borrowed : " + r);

                            } else {
                                ServantProviderFactory spFactory = ServantProviderFactory.getFactory();

                                if (spFactory == null) {
                                    result = new NoRegistryAvailableException();
                                    break;
                                }

                                boolean wait = options.keySet().contains("wait")
                                        && ((String) options.get("wait")).equalsIgnoreCase("true");
                                String poolname = ((String) options.get("poolname"));
                                if (wait) {
                                    r = (RServices) (poolname == null || poolname.trim().equals("")
                                            ? spFactory.getServantProvider().borrowServantProxy()
                                            : spFactory.getServantProvider().borrowServantProxy(poolname));
                                } else {
                                    r = (RServices) (poolname == null || poolname.trim().equals("")
                                            ? spFactory.getServantProvider().borrowServantProxyNoWait()
                                            : spFactory.getServantProvider()
                                                    .borrowServantProxyNoWait(poolname));
                                }
                            }
                        }
                    }
                } else {
                    r = _rkit.getR();
                }

                if (r == null) {
                    result = new NoServantAvailableException();
                    break;
                }

                session = request.getSession(true);

                Integer sessionTimeOut = null;
                try {
                    if (options.get("sessiontimeout") != null)
                        sessionTimeOut = Integer.decode((String) options.get("sessiontimeout"));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (sessionTimeOut != null) {
                    session.setMaxInactiveInterval(sessionTimeOut);
                }

                session.setAttribute("TYPE", "RS");
                session.setAttribute("R", r);
                session.setAttribute("NOPOOL", nopool);
                session.setAttribute("SAVE", save);
                session.setAttribute("LOGIN", login);
                session.setAttribute("NAMED_ACCESS_MODE", namedAccessMode);
                session.setAttribute("PROCESS_ID", r.getProcessId());
                session.setAttribute("JOB_ID", r.getJobId());
                session.setAttribute("SELFISH", selfish);
                session.setAttribute("IS_RELAY", _rkit != null);

                if (privateName != null)
                    session.setAttribute("PRIVATE_NAME", privateName);

                if (codeUrls != null && codeUrls.length > 0) {
                    session.setAttribute("CODEURLS", codeUrls);
                }

                session.setAttribute("THREADS", new ThreadsHolder());

                ((HashMap<String, HttpSession>) getServletContext().getAttribute("SESSIONS_MAP"))
                        .put(session.getId(), session);
                saveSessionAttributes(session);

                Vector<HttpSession> sessionVector = ((HashMap<RServices, Vector<HttpSession>>) getServletContext()
                        .getAttribute("R_SESSIONS")).get(r);
                if (sessionVector == null) {
                    sessionVector = new Vector<HttpSession>();
                    ((HashMap<RServices, Vector<HttpSession>>) getServletContext().getAttribute("R_SESSIONS"))
                            .put(r, sessionVector);
                }

                sessionVector.add(session);

                if (_rkit == null && save) {
                    UserUtils.loadWorkspace((String) session.getAttribute("LOGIN"), r);
                }

                System.out.println("---> Has Collaboration Listeners:" + r.hasRCollaborationListeners());
                if (selfish || !r.hasRCollaborationListeners()) {
                    try {
                        if (_rkit != null && _safeModeEnabled)
                            ((ExtendedReentrantLock) _rkit.getRLock()).rawLock();

                        GDDevice[] devices = r.listDevices();
                        for (int i = 0; i < devices.length; ++i) {
                            String deviceName = devices[i].getId();
                            System.out.println("??? ---- deviceName=" + deviceName);
                            session.setAttribute(deviceName, devices[i]);
                        }

                    } finally {
                        if (_rkit != null && _safeModeEnabled)
                            ((ExtendedReentrantLock) _rkit.getRLock()).rawUnlock();
                    }
                }

                if (privateEngineMode) {

                    if (options.get("newdevice") != null) {
                        GDDevice deviceProxy = null;
                        GDDevice[] dlist = r.listDevices();
                        if (dlist == null || dlist.length == 0) {
                            deviceProxy = r.newDevice(480, 480);
                        } else {
                            deviceProxy = dlist[0];
                        }
                        String deviceName = deviceProxy.getId();
                        session.setAttribute(deviceName, deviceProxy);
                        session.setAttribute("maindevice", deviceProxy);
                        saveSessionAttributes(session);
                    }

                    if (options.get("newgenericcallbackdevice") != null) {
                        GenericCallbackDevice genericCallBackDevice = null;
                        GenericCallbackDevice[] clist = r.listGenericCallbackDevices();
                        if (clist == null || clist.length == 0) {
                            genericCallBackDevice = r.newGenericCallbackDevice();
                        } else {
                            genericCallBackDevice = clist[0];
                        }
                        String genericCallBackDeviceName = genericCallBackDevice.getId();
                        session.setAttribute(genericCallBackDeviceName, genericCallBackDevice);
                        session.setAttribute("maingenericcallbackdevice", genericCallBackDevice);
                        saveSessionAttributes(session);
                    }

                }

                result = session.getId();

                break;

            } else if (command.equals("logondb")) {

                ServantProviderFactory spFactory = ServantProviderFactory.getFactory();
                if (spFactory == null) {
                    result = new NoRegistryAvailableException();
                    break;
                }

                String login = (String) PoolUtils.hexToObject(request.getParameter("login"));
                String pwd = (String) PoolUtils.hexToObject(request.getParameter("pwd"));
                HashMap<String, Object> options = (HashMap<String, Object>) PoolUtils
                        .hexToObject(request.getParameter("options"));
                if (options == null)
                    options = new HashMap<String, Object>();
                System.out.println("options:" + options);

                session = request.getSession(true);

                Integer sessionTimeOut = null;
                try {
                    if (options.get("sessiontimeout") != null)
                        sessionTimeOut = Integer.decode((String) options.get("sessiontimeout"));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (sessionTimeOut != null) {
                    session.setMaxInactiveInterval(sessionTimeOut);
                }

                session.setAttribute("TYPE", "DBS");
                session.setAttribute("REGISTRY", (DBLayer) spFactory.getServantProvider().getRegistry());
                session.setAttribute("SUPERVISOR",
                        new SupervisorUtils((DBLayer) spFactory.getServantProvider().getRegistry()));
                session.setAttribute("THREADS", new ThreadsHolder());
                ((HashMap<String, HttpSession>) getServletContext().getAttribute("SESSIONS_MAP"))
                        .put(session.getId(), session);
                saveSessionAttributes(session);

                result = session.getId();

                break;

            }

            session = request.getSession(false);
            if (session == null) {
                result = new NotLoggedInException();
                break;
            }

            if (command.equals("logoff")) {

                if (session.getAttribute("TYPE").equals("RS")) {
                    if (_rkit != null) {
                        /*
                        Enumeration<String> attributeNames = session.getAttributeNames();
                        while (attributeNames.hasMoreElements()) {
                           String aname = attributeNames.nextElement();
                           if (session.getAttribute(aname) instanceof GDDevice) {
                              try {
                                 _rkit.getRLock().lock();
                                 ((GDDevice) session.getAttribute(aname)).dispose();
                              } catch (Exception e) {
                                 e.printStackTrace();
                              } finally {
                                 _rkit.getRLock().unlock();
                              }
                           }
                        }
                        */
                    }
                }

                try {

                    session.invalidate();

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                result = null;
                break;
            }

            final boolean[] stop = { false };
            final HttpSession currentSession = session;

            if (command.equals("invoke")) {

                String servantName = (String) PoolUtils.hexToObject(request.getParameter("servantname"));
                final Object servant = session.getAttribute(servantName);
                if (servant == null) {
                    throw new Exception("Bad Servant Name :" + servantName);
                }
                String methodName = (String) PoolUtils.hexToObject(request.getParameter("methodname"));

                ClassLoader urlClassLoader = this.getClass().getClassLoader();
                if (session.getAttribute("CODEURLS") != null) {
                    urlClassLoader = new URLClassLoader((URL[]) session.getAttribute("CODEURLS"),
                            this.getClass().getClassLoader());
                }

                Class<?>[] methodSignature = (Class[]) PoolUtils
                        .hexToObject(request.getParameter("methodsignature"));

                final Method m = servant.getClass().getMethod(methodName, methodSignature);
                if (m == null) {
                    throw new Exception("Bad Method Name :" + methodName);
                }
                final Object[] methodParams = (Object[]) PoolUtils
                        .hexToObject(request.getParameter("methodparameters"), urlClassLoader);
                final Object[] resultHolder = new Object[1];
                Runnable rmiRunnable = new Runnable() {
                    public void run() {
                        try {
                            if (_rkit != null && _safeModeEnabled)
                                ((ExtendedReentrantLock) _rkit.getRLock()).rawLock();
                            resultHolder[0] = m.invoke(servant, methodParams);
                            if (resultHolder[0] == null)
                                resultHolder[0] = RMICALL_DONE;
                        } catch (InvocationTargetException ite) {
                            if (ite.getCause() instanceof ConnectException) {
                                currentSession.invalidate();
                                resultHolder[0] = new NotLoggedInException();
                            } else {
                                resultHolder[0] = ite.getCause();
                            }
                        } catch (Exception e) {
                            final boolean wasInterrupted = Thread.interrupted();
                            if (wasInterrupted) {
                                resultHolder[0] = new RmiCallInterrupted();
                            } else {
                                resultHolder[0] = e;
                            }
                        } finally {
                            if (_rkit != null && _safeModeEnabled)
                                ((ExtendedReentrantLock) _rkit.getRLock()).rawUnlock();
                        }
                    }
                };

                Thread rmiThread = InterruptibleRMIThreadFactory.getInstance().newThread(rmiRunnable);
                ((ThreadsHolder) session.getAttribute("THREADS")).getThreads().add(rmiThread);
                rmiThread.start();

                long t1 = System.currentTimeMillis();

                while (resultHolder[0] == null) {

                    if ((System.currentTimeMillis() - t1) > RMICALL_TIMEOUT_MILLISEC || stop[0]) {
                        rmiThread.interrupt();
                        resultHolder[0] = new RmiCallTimeout();
                        break;
                    }

                    try {
                        Thread.sleep(10);
                    } catch (Exception e) {
                    }
                }
                try {
                    ((ThreadsHolder) session.getAttribute("THREADS")).getThreads().remove(rmiThread);
                } catch (IllegalStateException e) {
                }

                if (resultHolder[0] instanceof Throwable) {
                    throw (Throwable) resultHolder[0];
                }

                if (resultHolder[0] == RMICALL_DONE) {
                    result = null;
                } else {
                    result = resultHolder[0];
                }

                break;

            }

            if (command.equals("interrupt")) {
                final Vector<Thread> tvec = (Vector<Thread>) ((ThreadsHolder) session.getAttribute("THREADS"))
                        .getThreads().clone();
                for (int i = 0; i < tvec.size(); ++i) {
                    try {
                        tvec.elementAt(i).interrupt();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                stop[0] = true;
                ((Vector<Thread>) ((ThreadsHolder) session.getAttribute("THREADS")).getThreads())
                        .removeAllElements();
                result = null;
                break;
            } else if (command.equals("saveimage")) {
                UserUtils.saveWorkspace((String) session.getAttribute("LOGIN"),
                        (RServices) session.getAttribute("R"));
                result = null;
                break;
            } else if (command.equals("loadimage")) {
                UserUtils.loadWorkspace((String) session.getAttribute("LOGIN"),
                        (RServices) session.getAttribute("R"));
                result = null;
                break;
            } else if (command.equals("newdevice")) {
                try {
                    if (_rkit != null && _safeModeEnabled)
                        ((ExtendedReentrantLock) _rkit.getRLock()).rawLock();
                    boolean broadcasted = new Boolean(request.getParameter("broadcasted"));
                    GDDevice deviceProxy = null;
                    if (broadcasted) {
                        deviceProxy = ((RServices) session.getAttribute("R")).newBroadcastedDevice(
                                Integer.decode(request.getParameter("width")),
                                Integer.decode(request.getParameter("height")));
                    } else {
                        deviceProxy = ((RServices) session.getAttribute("R")).newDevice(
                                Integer.decode(request.getParameter("width")),
                                Integer.decode(request.getParameter("height")));
                    }

                    String deviceName = deviceProxy.getId();
                    System.out.println("deviceName=" + deviceName);
                    session.setAttribute(deviceName, deviceProxy);
                    saveSessionAttributes(session);
                    result = deviceName;
                    break;
                } finally {
                    if (_rkit != null && _safeModeEnabled)
                        ((ExtendedReentrantLock) _rkit.getRLock()).rawUnlock();
                }
            } else if (command.equals("listdevices")) {
                try {
                    if (_rkit != null && _safeModeEnabled)
                        ((ExtendedReentrantLock) _rkit.getRLock()).rawLock();

                    result = new Vector<String>();
                    for (Enumeration<String> e = session.getAttributeNames(); e.hasMoreElements();) {
                        String attributeName = e.nextElement();
                        if (attributeName.startsWith("device_")) {
                            ((Vector<String>) result).add(attributeName);
                        }
                    }

                    break;

                } finally {
                    if (_rkit != null && _safeModeEnabled)
                        ((ExtendedReentrantLock) _rkit.getRLock()).rawUnlock();
                }
            } else if (command.equals("newgenericcallbackdevice")) {
                try {
                    if (_rkit != null && _safeModeEnabled)
                        ((ExtendedReentrantLock) _rkit.getRLock()).rawLock();
                    GenericCallbackDevice genericCallBackDevice = ((RServices) session.getAttribute("R"))
                            .newGenericCallbackDevice();

                    String genericCallBackDeviceName = genericCallBackDevice.getId();
                    session.setAttribute(genericCallBackDeviceName, genericCallBackDevice);
                    saveSessionAttributes(session);

                    result = genericCallBackDeviceName;

                    break;
                } finally {
                    if (_rkit != null && _safeModeEnabled)
                        ((ExtendedReentrantLock) _rkit.getRLock()).rawUnlock();
                }
            } else if (command.equals("newspreadsheetmodeldevice")) {

                String spreadsheetModelDeviceId = request.getParameter("id");
                SpreadsheetModelRemote model = null;

                if (spreadsheetModelDeviceId == null || spreadsheetModelDeviceId.equals("")) {
                    model = ((RServices) session.getAttribute("R")).newSpreadsheetTableModelRemote(
                            Integer.decode(request.getParameter("rowcount")),
                            Integer.decode(request.getParameter("colcount")));
                } else {
                    model = ((RServices) session.getAttribute("R"))
                            .getSpreadsheetTableModelRemote(spreadsheetModelDeviceId);
                }

                SpreadsheetModelDevice spreadsheetDevice = model.newSpreadsheetModelDevice();
                String spreadsheetDeviceId = spreadsheetDevice.getId();
                session.setAttribute(spreadsheetDeviceId, spreadsheetDevice);
                saveSessionAttributes(session);
                result = spreadsheetDeviceId;
                break;

            } else if (command.equals("list")) {
                ServantProviderFactory spFactory = ServantProviderFactory.getFactory();
                if (spFactory == null) {
                    result = new NoRegistryAvailableException();
                    break;
                }
                result = spFactory.getServantProvider().getRegistry().list();
                break;
            }

        } while (true);

    } catch (TunnelingException te) {
        result = te;
        te.printStackTrace();
    } catch (Throwable e) {
        result = new TunnelingException("Server Side", e);
        e.printStackTrace();
    }
    response.setContentType("application/x-java-serialized-object");
    new ObjectOutputStream(response.getOutputStream()).writeObject(result);
    response.flushBuffer();

}

From source file:com.prowidesoftware.swift.model.SwiftBlockUser.java

/**
 * Checks if the block name is valid for a user defined block.
 * @param blockName the block name/*from www . j  av  a2  s . c  om*/
 * @return true if the block name and number are valid 
 * 
 * @since 5.0
 */
static public Boolean isValidName(String blockName) {
    // name and number must be defined
    if (blockName == null)
        return (Boolean.FALSE);

    // try as a number
    try {
        Integer num = Integer.decode(blockName);
        if (!SwiftBlockUser.isValidName(num).booleanValue())
            return (Boolean.FALSE);
    } catch (NumberFormatException nfe) {
        // do nothing (it was not a number)
    }
    ;

    // for named blocks, the name must be only one letter
    if (blockName.length() != 1)
        return (Boolean.FALSE);

    // only upper or lower case letters
    char c = Character.toLowerCase(blockName.charAt(0));
    if (!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z')))
        return (Boolean.FALSE);

    return (Boolean.TRUE);
}

From source file:org.apache.marmotta.commons.sesame.facading.util.FacadeUtils.java

/**
 * Transform a value passed as string to the base type (i.e. non-complex type) given as argument
 *
 * @param <T>/*from   w  ww . j a  v a  2s  .  c om*/
 * @param value
 * @param returnType
 * @return
 * @throws IllegalArgumentException
 */
@SuppressWarnings("unchecked")
public static <T> T transformToBaseType(String value, Class<T> returnType) throws IllegalArgumentException {
    // transformation to appropriate primitive type
    /*
     * README: the "dirty" cast: "(T) x" instead of "returnType.cast(x)" is required since
     * .cast does not work for primitive types (int, double, float, etc...).
     * Somehow it results in a ClassCastException
     */
    if (Integer.class.equals(returnType) || int.class.equals(returnType)) {
        if (value == null) {
            return (T) (Integer) (0);
        }
        return (T) (Integer.decode(value));
    } else if (Long.class.equals(returnType) || long.class.equals(returnType)) {
        if (value == null) {
            return (T) (Long) (0L);
        }
        return (T) (Long.decode(value));
    } else if (Double.class.equals(returnType) || double.class.equals(returnType)) {
        if (value == null) {
            return (T) (Double) (0.0);
        }
        return (T) (Double.valueOf(value));
    } else if (Float.class.equals(returnType) || float.class.equals(returnType)) {
        if (value == null) {
            return (T) (Float) (0.0F);
        }
        return (T) (Float.valueOf(value));
    } else if (Byte.class.equals(returnType) || byte.class.equals(returnType)) {
        if (value == null) {
            return (T) (Byte) ((byte) 0);
        }
        return (T) (Byte.decode(value));
    } else if (Boolean.class.equals(returnType) || boolean.class.equals(returnType)) {
        return (T) (Boolean.valueOf(value));
    } else if (Character.class.equals(returnType) || char.class.equals(returnType)) {
        if (value == null) {
            if (Character.class.equals(returnType)) {
                return null;
            } else {
                return (T) new Character((char) 0);
            }
        } else if (value.length() > 0) {
            return (T) (Character) (value.charAt(0));
        } else {
            return null;
        }
    } else if (Locale.class.equals(returnType)) {
        if (value == null) {
            return null;
        } else {
            return returnType.cast(LocaleUtils.toLocale(value));
        }
    } else if (Date.class.equals(returnType)) {
        if (value == null) {
            return null;
        } else {
            try {
                return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value).toDate());
            } catch (final IllegalArgumentException e) {
                e.printStackTrace();
                return null;
            }
        }
    } else if (DateTime.class.equals(returnType)) {
        if (value == null) {
            return null;
        } else {
            try {
                return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value));
            } catch (final IllegalArgumentException e) {
                e.printStackTrace();
                return null;
            }
        }
    } else if (String.class.equals(returnType)) {
        return returnType.cast(value);
    } else {
        throw new IllegalArgumentException(
                "primitive type " + returnType.getName() + " not supported by transformation");
    }
}

From source file:fr.gael.dhus.sync.impl.ODataProductSynchronizer.java

/**
 * Creates a new ODataSynchronizer.//w  w w.jav a 2 s  . c o  m
 *
 * @param sc configuration for this synchronizer.
 *
 * @throws IllegalStateException if the configuration doe not contains the
 *    required fields, or those fields are malformed.
 * @throws IOException when the OdataClient fails to contact the server
 *    at {@code url}.
 * @throws ODataException when no OData service have been found at the
 *    given url.
 * @throws NumberFormatException if the value of the `target_collection`
 *    configuration field is not a number.
 */
public ODataProductSynchronizer(SynchronizerConf sc) throws IOException, ODataException {
    super(sc);

    // Checks if required configuration is set
    String urilit = sc.getConfig("service_uri");
    serviceUser = sc.getConfig("service_username");
    servicePass = sc.getConfig("service_password");
    if (urilit == null || urilit.isEmpty()) {
        throw new IllegalStateException("`service_uri` is not set");
    }

    try {
        client = new ODataClient(urilit, serviceUser, servicePass);
    } catch (URISyntaxException e) {
        throw new IllegalStateException("`service_uri` is malformed");
    }

    String dec_name = client.getSchema().getDefaultEntityContainer().getName();
    if (!dec_name.equals(V1Model.ENTITY_CONTAINER)) {
        throw new IllegalStateException("`service_uri` does not reference a DHuS odata service");
    }

    String last_cr = sc.getConfig("last_created");
    if (last_cr != null && !last_cr.isEmpty()) {
        lastCreated = new Date(Long.decode(last_cr));
    } else {
        lastCreated = new Date(0L);
    }

    String last_up = sc.getConfig("last_updated");
    if (last_up != null && !last_up.isEmpty()) {
        lastUpdated = new Date(Long.decode(last_up));
    } else {
        lastUpdated = new Date(0L);
    }

    String last_del = sc.getConfig("last_deleted");
    if (last_del != null && !last_del.isEmpty()) {
        lastDeleted = new Date(Long.decode(last_del));
    } else {
        lastDeleted = new Date(0L);
    }

    String page_size = sc.getConfig("page_size");
    if (page_size != null && !page_size.isEmpty()) {
        pageSize = Integer.decode(page_size);
    } else {
        pageSize = 30; // FIXME get that value from the config?
    }

    String remote_incoming = sc.getConfig("remote_incoming_path");
    if (remote_incoming != null && !remote_incoming.isEmpty()) {
        File ri = new File(remote_incoming);
        if (!ri.exists() || !ri.isDirectory() || !ri.canRead()) {
            throw new IOException("Cannot access remote incoming " + remote_incoming);
        }
        this.remoteIncoming = remote_incoming;
    } else {
        this.remoteIncoming = null;
    }

    String target_collection = sc.getConfig("target_collection");
    if (target_collection != null && !target_collection.isEmpty()) {
        this.targetCollection = Long.parseLong(target_collection);
    } else {
        this.targetCollection = null;
    }

    String filter_param = sc.getConfig("filter_param");
    if (filter_param != null && !filter_param.isEmpty()) {
        filterParam = filter_param;
    } else {
        filterParam = null;
    }

    String source_collection = sc.getConfig("source_collection");
    if (source_collection != null && !source_collection.isEmpty()) {
        sourceCollection = source_collection;
    } else {
        sourceCollection = "";
    }

    String copy_product = sc.getConfig("copy_product");
    if (copy_product != null && !copy_product.isEmpty()) {
        this.copyProduct = Boolean.parseBoolean(copy_product);
    } else {
        this.copyProduct = false;
    }
}