List of usage examples for java.util Vector toArray
@SuppressWarnings("unchecked") public synchronized <T> T[] toArray(T[] a)
From source file:sos.scheduler.cron.CronConverter.java
private String[] getArrayFromColumn(final String column) { String[] elements = column.split(","); Vector<String> result = new Vector<String>(); for (String element : elements) { if (element.indexOf("-") == -1) { result.add(element);/*from ww w. j ava 2s . c o m*/ } else { String[] range = element.split("[-/]"); if (range.length < 2 || range.length > 3) { try { logger.warn("unknown crontab synthax: " + element); } catch (Exception e) { } } else { int from = Integer.parseInt(range[0]); int to = Integer.parseInt(range[1]); int stepSize = 1; // if e.g. 8-20/2 if (range.length == 3) stepSize = Integer.parseInt(range[2]); for (int j = from; j <= to; j = j + stepSize) result.add("" + j); } } } String[] dummy = new String[1]; return result.toArray(dummy); }
From source file:org.bdval.DAVMode.java
protected void setupGeneLists(final JSAPResult result, final DAVOptions options) { String singleGeneListFilename = result.getString("gene-list"); if (singleGeneListFilename != null) { String[] tokens = { singleGeneListFilename, singleGeneListFilename }; final Vector<GeneList> list = new Vector<GeneList>(); try {/* w ww . j a v a2 s.c o m*/ if (singleGeneListFilename.split("[|]").length == 2) { // single gene list filename may be suffixed with name of gene list // for instance HM200|/path/to/HM200.txt tokens = singleGeneListFilename.split("[|]"); singleGeneListFilename = tokens[1]; } final GeneList geneList = GeneList.createList(tokens, ""); geneList.setPlatforms(options.platforms); list.add(geneList); } catch (IOException e) { LOG.error("Cannot read gene list from file " + singleGeneListFilename, e); } options.geneLists = list.toArray(new GeneList[list.size()]); } else { final String geneListFilename = result.getString("gene-lists"); if (geneListFilename != null) { readGeneLists(geneListFilename, options.platforms, options); } else { // use all the probesets if no gene list was specified: options.geneLists = new GeneList[1]; options.geneLists[0] = new FullGeneList("full"); } } }
From source file:org.fusesource.meshkeeper.distribution.provisioner.embedded.Execute.java
/** * Patch the current environment with the new values from the user. * @return the patched environment./* w ww . java2 s . co m*/ */ @SuppressWarnings("unchecked") private String[] patchEnvironment() { // On OpenVMS Runtime#exec() doesn't support the environment array, // so we only return the new values which then will be set in // the generated DCL script, inheriting the parent process environment if (Os.isFamily("openvms")) { return env; } Vector<String> osEnv = (Vector<String>) getProcEnvironment().clone(); for (int i = 0; i < env.length; i++) { String keyValue = env[i]; // Get key including "=" String key = keyValue.substring(0, keyValue.indexOf('=') + 1); if (environmentCaseInSensitive) { // Nb: using default locale as key is a env name key = key.toLowerCase(); } int size = osEnv.size(); // Find the key in the current enviroment copy // and remove it. for (int j = 0; j < size; j++) { String osEnvItem = (String) osEnv.elementAt(j); String convertedItem = environmentCaseInSensitive ? osEnvItem.toLowerCase() : osEnvItem; if (convertedItem.startsWith(key)) { osEnv.removeElementAt(j); if (environmentCaseInSensitive) { // Use the original casiness of the key keyValue = osEnvItem.substring(0, key.length()) + keyValue.substring(key.length()); } break; } } // Add the key to the enviromnent copy osEnv.addElement(keyValue); } return (String[]) (osEnv.toArray(new String[osEnv.size()])); }
From source file:org.kchine.rpf.db.DBLayer.java
public String[] list() throws RemoteException, AccessException { Vector<String> result = new Vector<String>(); Statement stmt = null;/*www . j av a2 s .c o m*/ ResultSet rset = null; try { checkConnection(); stmt = _connection.createStatement(); rset = stmt.executeQuery("select NAME from SERVANTS"); while (rset.next()) { result.add(rset.getString(1)); } } catch (SQLException sqle) { if (isNoConnectionError(sqle) && canReconnect()) { return list(); } else { throw new RemoteException("", (sqle)); } } finally { if (rset != null) try { stmt.close(); } catch (Exception e) { throw new RemoteException("", (e)); } if (stmt != null) try { stmt.close(); } catch (Exception e) { throw new RemoteException("", (e)); } } return result.toArray(new String[0]); }
From source file:de.juwimm.cms.remote.ClientServiceSpringImpl.java
@Override protected ViewComponentValue[] handleGetAllViewComponents4UnitAndStatus(Integer unitId, Integer viewDocumentId, int status) throws Exception { try {/*from w ww . j ava 2s .c o m*/ Vector<ViewComponentValue> vec = new Vector<ViewComponentValue>(); ViewComponentHbm view = super.getViewComponentHbmDao().find4Unit(unitId, viewDocumentId); this.getAllViewComponentsChildren4Status(view, vec, status, unitId); return vec.toArray(new ViewComponentValue[0]); } catch (Exception e) { throw new UserException(e.getMessage()); } }
From source file:org.energy_home.jemma.ah.internal.configurator.Configuratore.java
public Object traversePropertyNode(Node node) { int nodeType = node.getNodeType(); switch (nodeType) { // print element with attributes case Node.ELEMENT_NODE: NamedNodeMap attrs = node.getAttributes(); String tag = node.getNodeName(); Node item = attrs.getNamedItem("type"); String type = null;//from w w w . j a v a2s . co m if (item != null) { type = item.getNodeValue(); } if (tag.equals("property")) { if (type.endsWith("[]")) { isArray = true; arrayType = type.substring(0, type.length() - 2); } else { isArray = false; arrayType = null; } if (type.equals("Vector")) { NodeList children = node.getChildNodes(); int len = children.getLength(); Vector container = new Vector(); for (int i = 0; i < len; i++) { Object res = traverseItemNode(children.item(i)); if (res != null) { container.add(res); log.debug("added to vector/array " + res.toString()); } } return container; } else if (isArray) { NodeList children = node.getChildNodes(); int len = children.getLength(); Vector container = new Vector(); for (int i = 0; i < len; i++) { Object res = traverseItemNode(children.item(i)); if (res != null) { container.add(res); log.debug("added to vector/array " + res.toString()); } } if (isBaseType(this.arrayType)) { return fillBaseTypeArrayInstance(arrayType, container); } else { return container.toArray(getArrayInstance(arrayType, 0)); } } else { return this.getInstance(type, getTextContent(node)); } } } return null; }
From source file:com.sos.VirtualFileSystem.SFTP.SOSVfsSFtp.java
@Override public String[] getFilelist(final String folder, final String regexp, final int flag, final boolean withSubFolder) { vecDirectoryListing = null; // start with a fresh copy of this list (due to polling ...) if (vecDirectoryListing == null) { String strT = folder.replaceAll("\\\\", "/"); vecDirectoryListing = nList(folder, withSubFolder); }/* w ww. ja v a2 s . co m*/ Vector<String> strB = new Vector<String>(); Pattern pattern = Pattern.compile(regexp, 0); for (String strFile : vecDirectoryListing) { /** * the file_spec has to be compared to the filename only ... excluding the path */ String strFileName = new File(strFile).getName(); Matcher matcher = pattern.matcher(strFileName); if (matcher.find() == true) { strB.add(strFile); } } return strB.toArray(new String[strB.size()]); }
From source file:com.sos.VirtualFileSystem.SFTP.SOSVfsSFtp.java
@Override public String[] getFolderlist(final String folder, final String regexp, final int flag, final boolean withSubFolder) { vecDirectoryListing = null; // start with a fresh copy of this list (due to polling ...) if (vecDirectoryListing == null) { String strT = folder.replaceAll("\\\\", "/"); vecDirectoryListing = nList(folder, withSubFolder); }//from w w w .j a va2 s.com Vector<String> strB = new Vector<String>(); Pattern pattern = Pattern.compile(regexp, 0); for (String strFile : vecDirectoryListing) { /** * the file_spec has to be compared to the filename only ... excluding the path */ String strFileName = new File(strFile).getName(); Matcher matcher = pattern.matcher(strFileName); if (matcher.find() == true) { strB.add(strFile); } } return strB.toArray(new String[strB.size()]); }
From source file:SWTFileViewerDemo.java
/** * Gets filesystem root entries/*w w w. j ava 2 s. co m*/ * * @return an array of Files corresponding to the root directories on the * platform, may be empty but not null */ File[] getRoots() { /* * On JDK 1.22 only... */ // return File.listRoots(); /* * On JDK 1.1.7 and beyond... -- PORTABILITY ISSUES HERE -- */ if (System.getProperty("os.name").indexOf("Windows") != -1) { Vector /* of File */ list = new Vector(); list.add(new File(DRIVE_A)); list.add(new File(DRIVE_B)); for (char i = 'c'; i <= 'z'; ++i) { File drive = new File(i + ":" + File.separator); if (drive.isDirectory() && drive.exists()) { list.add(drive); if (initial && i == 'c') { currentDirectory = drive; initial = false; } } } File[] roots = (File[]) list.toArray(new File[list.size()]); sortFiles(roots); return roots; } else { File root = new File(File.separator); if (initial) { currentDirectory = root; initial = false; } return new File[] { root }; } }
From source file:com.alfaariss.oa.helper.stylesheet.StyleSheetEngine.java
/** * Reads following configuration and creates the optional handler object: * <pre>/*w ww. ja va2 s . c o m*/ * <helpers> * <stylesheet> * <default location="" /> * <handler class="" /> * </stylesheet> * </helpers> * </pre> * * @param configurationManager The configuration manager. * @param eStyleSheet The configuration section. * @param sHelperID The id of the helper. * @param context Servlet context. * @throws OAException If initialization fails. */ public void start(IConfigurationManager configurationManager, Element eStyleSheet, String sHelperID, ServletContext context) throws OAException { try { _configurationManager = configurationManager; Engine oEngine = Engine.getInstance(); _sessionFactory = oEngine.getSessionFactory(); _bEnabled = true; String sEnabled = _configurationManager.getParam(eStyleSheet, "enabled"); if (sEnabled != null) { if (sEnabled.equalsIgnoreCase("FALSE")) _bEnabled = false; else if (!sEnabled.equalsIgnoreCase("TRUE")) { _logger.error("Invalid 'enabled' item found in configuration: " + sEnabled); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } } if (_bEnabled) { _sDefaultLocation = DEFAULT_CSS; _sDefaultMobileLocation = DEFAULT_MOBILE_CSS; Element eDefault = _configurationManager.getSection(eStyleSheet, "default"); if (eDefault == null) { _logger.warn("No optional 'default' section found in configuration"); } else { _sDefaultLocation = _configurationManager.getParam(eDefault, "location"); _sDefaultMobileLocation = _configurationManager.getParam(eDefault, "mobile"); if (_sDefaultLocation == null && _sDefaultMobileLocation == null) { _logger.error( "No 'location' or 'mobile' parameter in 'default' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } if (_sDefaultLocation == null) { _logger.info("No 'location' parameter in 'default' section found in configuration"); _sDefaultLocation = DEFAULT_CSS; } if (_sDefaultMobileLocation == null) { _logger.info("No 'mobile' parameter in 'default' section found in configuration"); _sDefaultMobileLocation = DEFAULT_MOBILE_CSS; } } _logger.info("Using default stylesheet location: " + _sDefaultLocation); _logger.info("Using default mobile stylesheet location: " + _sDefaultMobileLocation); Element eHandler = _configurationManager.getSection(eStyleSheet, "handler"); if (eHandler == null) _logger.info("No optional stylesheet handler configured, using default stylesheet"); else _oHandler = createHandler(eHandler, sHelperID); //instantiate optional wurflManager String rootPath = null; File rootFile = null; Element eWURFL = _configurationManager.getSection(eStyleSheet, "wurfl"); if (eWURFL != null) { Element eLocation = _configurationManager.getSection(eWURFL, "location"); if (eLocation == null) { _logger.error("No 'location' section in 'wurfl' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } rootPath = _configurationManager.getParam(eLocation, "uri"); if (rootPath == null) { _logger.info( "No 'uri' parameter in 'location' section found in configuration, trying file"); String sWURFLFile = _configurationManager.getParam(eLocation, "file"); if (sWURFLFile == null) { _logger.error("No 'file' parameter in 'location' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } rootFile = resolveFile(sWURFLFile, context); } //load optional patches Vector<String> patchesPath = null; Vector<File> patchesFile = null; Element ePatch = _configurationManager.getSection(eLocation, "patch"); while (ePatch != null) { if (rootFile != null) //Configured by file { String sWURFLPatchFile = _configurationManager.getParam(ePatch, "file"); if (sWURFLPatchFile == null) { _logger.error("No 'file' parameter in 'patch' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } File patchFile = resolveFile(sWURFLPatchFile, context); if (patchesFile == null) patchesFile = new Vector<File>(); patchesFile.add(patchFile); } else //Configured by uri's { String sWURFLPatchURI = _configurationManager.getParam(ePatch, "uri"); if (sWURFLPatchURI == null) { _logger.error("No 'uri' parameter in 'patch' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } if (patchesPath == null) patchesPath = new Vector<String>(); patchesPath.add(sWURFLPatchURI); } ePatch = _configurationManager.getNextSection(ePatch); } //Create WURFLHolder WURFLHolder wurflHolder = null; if (rootFile != null) //File configured { if (patchesFile != null) { wurflHolder = new CustomWURFLHolder(rootFile, patchesFile.toArray(new File[] {})); } else { _logger.info("No wurfl patches configured"); wurflHolder = new CustomWURFLHolder(rootFile); } } else //uri configured { if (patchesPath != null) { wurflHolder = new CustomWURFLHolder(rootPath, patchesPath.toArray(new String[] {})); } else { _logger.info("No wurfl patches configured"); wurflHolder = new CustomWURFLHolder(rootPath); } } _wurflManager = wurflHolder.getWURFLManager(); if (_wurflManager == null) { _logger.error("Could not instantiate WURFL Manager"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } Element eDevices = _configurationManager.getSection(eWURFL, "devices"); if (eDevices != null) { Element eDevice = _configurationManager.getSection(eDevices, "device"); if (eDevice == null) { _logger.error( "No 'device' parameter in 'device_specific' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } while (eDevice != null) { String sDeviceId = _configurationManager.getParam(eDevice, "id"); if (sDeviceId == null) { _logger.error("No 'id' parameter in 'device' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } String sDeviceCSSLocation = _configurationManager.getParam(eDevice, "location"); if (sDeviceCSSLocation == null) { _logger.error("No 'location' parameter in 'device' section found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } _htDeviceSpecificStyleSheets.put(sDeviceId, sDeviceCSSLocation); eDevice = _configurationManager.getNextSection(eDevice); } } else { _logger.info("No device specific stylesheet defined"); } } else { _logger.info("No 'wurfl' configuration section found in configuration, disabling wurfl"); } } _logger.info("StyleSheet engine: " + (_bEnabled ? "enabled" : "disabled")); } catch (OAException e) { throw e; } catch (Exception e) { _logger.fatal("Error during start", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } }