Example usage for java.util NoSuchElementException printStackTrace

List of usage examples for java.util NoSuchElementException printStackTrace

Introduction

In this page you can find the example usage for java.util NoSuchElementException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.mili.ant.PropertiesReplacerImplTest.java

@Test
public void testReplace_OneFileButOneReplaceNotFound() throws Exception {
    StringBuilder s = new StringBuilder();
    s.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    s.append("<properties-description>\n");
    s.append("    <property name=\"xy\" type=\"string\">\n");
    s.append("        <default>8080</default>\n");
    s.append("    </property>\n");
    s.append(//ww w.  j  a  v a  2s. co  m
            "    <replace-file name=\"./tmp/test_properties_description/ab.properties\" halt-on-error=\"true\">\n");
    s.append("        <replace property=\"xy\">\n");
    s.append("            <what><![CDATA[x.y=8080]]></what>\n");
    s.append("            <to><![CDATA[x.y=$1]]></to>\n");
    s.append("        </replace>\n");
    s.append("    </replace-file>\n");
    s.append("</properties-description>\n");
    FileUtils.writeStringToFile(xmlFile, s.toString());
    try {
        PropertiesReplacerImpl pr = new PropertiesReplacerImpl();
        pr.replace(propFile, xmlFile);
        fail("exception sholud be occured !");
    } catch (NoSuchElementException e) {
        assertTrue(true);
    }
    s = new StringBuilder();
    s.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    s.append("<properties-description>\n");
    s.append("    <property name=\"xy\" type=\"string\">\n");
    s.append("        <default>8080</default>\n");
    s.append("    </property>\n");
    s.append(
            "    <replace-file name=\"./tmp/test_properties_description/ab.properties\" halt-on-error=\"false\">\n");
    s.append("        <replace property=\"xy\">\n");
    s.append("            <what><![CDATA[x.y=8080]]></what>\n");
    s.append("            <to><![CDATA[x.y=$1]]></to>\n");
    s.append("        </replace>\n");
    s.append("    </replace-file>\n");
    s.append("</properties-description>\n");
    FileUtils.writeStringToFile(xmlFile, s.toString());
    try {
        PropertiesReplacerImpl pr = new PropertiesReplacerImpl();
        pr.replace(propFile, xmlFile);
        assertTrue(true);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail("exception sholud be occured !");
    }
}

From source file:org.kchine.rpf.db.ServantsProviderFactoryDBProxy.java

public ServantsProviderFactoryDBProxy() throws Exception {
    super();//from w  w w  .j a va  2  s. co  m

    _dbLayer = ((DBLayerProvider) Class.forName(System.getProperty("pools.dbproxymode.class")).newInstance())
            .getDBLayer();
    _defaultPoolName = System.getProperty("pools.dbproxymode.defaultpoolname");

    _poolHashMap = _dbLayer.getPoolDataHashMap();
    _servantProvider = new ServantProvider() {

        public ManagedServant borrowServantProxy(String poolName) throws TimeoutException {

            ManagedServant proxy = null;
            long tstart = System.currentTimeMillis();
            do {
                try {
                    proxy = (ManagedServant) ServantProxyPoolSingletonDB.getInstance(poolName, _dbLayer)
                            .borrowObject();
                } catch (NoSuchElementException e) {
                } catch (Exception ex) {
                    ex.printStackTrace();
                }

                if (proxy != null) {
                    try {
                        // log .info("<" + Thread.currentThread().getName()+
                        // "> obtained resource : "+
                        // proxy.getServantName());
                    } catch (Exception e) {
                    }
                    break;
                } else {

                }

                if (System.currentTimeMillis() - tstart > _poolHashMap.get(poolName).getBorrowTimeout())
                    throw new TimeoutException();
                try {
                    Thread.sleep(20);
                } catch (Exception e) {
                }

                // log.info("<" + Thread.currentThread().getName() + ">
                // thread waiting for resource for : "+
                // ((System.currentTimeMillis() - tstart) / 1000)+ "
                // seconds");

            } while (true);

            return proxy;
        }

        public ManagedServant borrowServantProxyNoWait(String poolName) {
            ManagedServant proxy = null;
            try {
                proxy = (ManagedServant) ServantProxyPoolSingletonDB.getInstance(poolName, _dbLayer)
                        .borrowObject();
            } catch (NoSuchElementException e) {
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            return proxy;
        }

        public void returnServantProxy(ManagedServant proxy) {
            if (proxy == null)
                return;
            try {

                ServantProxyPoolSingletonDB.getInstance(_defaultPoolName, _dbLayer).returnObject(proxy);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(0);
            }
        }

        public void returnServantProxy(String poolName, ManagedServant proxy) {
            if (proxy == null)
                return;
            try {

                ServantProxyPoolSingletonDB.getInstance(poolName, _dbLayer).returnObject(proxy);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(0);
            }
        }

        public ManagedServant borrowServantProxy() throws TimeoutException {
            return borrowServantProxy(_defaultPoolName);
        }

        public ManagedServant borrowServantProxyNoWait() {
            return borrowServantProxyNoWait(_defaultPoolName);
        }

        public String getDefaultPoolName() {
            return _defaultPoolName;
        }

        public Registry getRegistry() {
            return _dbLayer;
        }

    };

}

From source file:forseti.JUtil.java

public static synchronized boolean INIT() {
    boolean init = false;
    // Inicializacion de propiedades de configuracion
    System.out.println("Iniciando JUtil y Configuracion de Sistema");
    m_TAREAS = new JFsiTareas();
    m_REINICIAR = false;// w ww . j  a v  a 2 s . c  o m

    try {
        FileReader file = new FileReader("/usr/local/forseti/bin/.forseti_conf");
        BufferedReader buff = new BufferedReader(file);
        boolean eof = false;
        //masProp = new Properties();

        while (!eof) {
            String line = buff.readLine();
            if (line == null) {
                eof = true;
            } else {
                try {
                    StringTokenizer st = new StringTokenizer(line, "=");
                    String key = st.nextToken();
                    String value = st.nextToken();
                    if (key.equals("LANG"))
                        m_LANG = value;
                    if (key.equals("PASS"))
                        m_PASS = value;
                    else if (key.equals("ADDR"))
                        m_ADDR = value;
                    else if (key.equals("PORT"))
                        m_PORT = value;
                    else if (key.equals("INIT"))
                        init = (value.equals("true") ? true : false);
                } catch (NoSuchElementException e) {
                    continue;
                }
            }
        }
        buff.close();
        return init;
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e.toString());
    }
}

From source file:de.suse.swamp.core.workflow.WorkflowTemplate.java

/**
* Checks if the User has the given role in the Workflowtemplate.
* This is configured in the Workflow definition.
* Example roles are "admin" - "starter" - "user" - "owner"
*
* swampadmins as defined in the SWAMP usermanagement have all roles
* @throws Exception if named role does not exist
*///from w  w  w  .java2  s .co  m
public boolean hasRole(String username, String role) {
    boolean hasRole = false;
    WorkflowRole wfrole = getWorkflowRole(role);

    // check if the user is in the role the regular way,
    // but mind that the needed databit may not yet be attached
    try {
        if (wfrole.hasRole(username, this)) {
            hasRole = true;
        }
    } catch (NoSuchElementException e) {
        // skip exception, because templates often haven't yet attached the needed values
    } catch (Exception e) {
        Logger.ERROR("Error when checking for role " + role + " Msg: " + e.getMessage());
        return false;
    }

    //for anonymous users, we can stop here:
    if (username.equals("anonymous")) {
        return hasRole;
    }

    try {
        if (hasRole == false) {
            SWAMPUser user = null;
            try {
                user = SecurityManager.getUser(username);
            } catch (StorageException e) {
                Logger.ERROR("Error fetching user: " + username + ". Reason: " + e.getMessage());
                return false;
            }
            // SWAMPAdmins, Workflow-Admins and "Owner"
            // always have all permissions in a workflow
            if (SecurityManager.isGroupMember(user, "swampadmins")
                    || getWorkflowRole("admin").hasRole(username, this)) {
                hasRole = true;
            }
        }

        // at last if the user has a role in any single instance of that workflowtemplate
        // he has that role of that template
        if (!hasRole && !wfrole.isStaticRole(this)) {
            long time = System.currentTimeMillis();
            List ids = new ArrayList();
            PropertyFilter templateFilter = new PropertyFilter();
            templateFilter.addWfTemplate(this.getName());

            // if we have more databitpaths, the id lists need to be merged,
            // because the different roles are like an OR statement
            List paths = new ArrayList();
            if (wfrole instanceof DatabitRole) {
                paths.add(((DatabitRole) wfrole).getRoleDatabit());
            } else if (wfrole instanceof ReferencesRole) {
                paths = ((ReferencesRole) wfrole).getAllRoleDatabits(this);
            }

            for (Iterator it = paths.iterator(); it.hasNext();) {
                ArrayList filters = new ArrayList();
                filters.add(templateFilter);
                String datapath = (String) it.next();
                ContentFilter cfilter = new ContentFilter();
                cfilter.setDatabitPath(datapath);
                // names are stored: name1, name2...
                String regexp = "(" + username + "$|" + username + ",)";
                cfilter.setDatabitValueRegex(regexp);
                filters.add(cfilter);
                ids.addAll(WorkflowManager.getInstance().getWorkflowIds(filters, null));
                if (ids.size() > 0) {
                    hasRole = true;
                    break;
                }
            }
            Logger.DEBUG("non-static check for " + role + "/" + username + "/" + this.getName() + " (" + hasRole
                    + ") took " + (System.currentTimeMillis() - time) + "ms");
        }
    } catch (NoSuchElementException e) {
        // skip exception, because templates often haven't yet attached the needed values
    } catch (Exception e) {
        Logger.ERROR("Error when checking for role " + role + " Msg: " + e.getMessage());
        e.printStackTrace();
        return false;
    }
    return hasRole;
}