public static DataAccessConnectionDescriptor[] fromClass(Class<? extends DataAccess> dataAccess) throws Exception { ArrayList<DataAccessConnectionDescriptor> descriptors = new ArrayList<DataAccessConnectionDescriptor>(); AbstractDataAccess sample = (AbstractDataAccess) dataAccess.newInstance(); Connection[] conns = sample.getAvailableConnections(); if (conns.length > 0) { for (Connection conn : conns) { try { String name = sample.getType() + (!(conn.getGenericType().equals(ConnectionType.NONE)) ? ("_" + conn.getType()) : ""); DataAccessConnectionDescriptor descriptor = new DataAccessConnectionDescriptor(name); descriptor.setDataAccess(sample); descriptor.setConnection(conn); descriptors.add(descriptor); } catch (UnsupportedOperationException e) { logger.warn( "Failed to generate a descriptor for " + sample.getType() + "_" + conn.getType()); } } } return descriptors.toArray(new DataAccessConnectionDescriptor[descriptors.size()]); }
// @Exposed(accessLevel = AccessLevel.PUBLIC, outputType = MimeType.JSON) public void listDataAccessTypes(final OutputStream out, final boolean refreshCache) throws Exception { // boolean refreshCache = Boolean.parseBoolean(requParam.getStringParameter("refreshCache", // "false")); DataAccessConnectionDescriptor[] data = SettingsManager.getInstance().getDataAccessDescriptors(refreshCache); StringBuilder output = new StringBuilder(""); if (data != null) { output.append("{\n"); for (DataAccessConnectionDescriptor datum : data) { output.append(datum.toJSON()).append(",\n"); } writeOut(out, output.toString().replaceAll(",\n\\z", "\n}")); } }