📄 adminbean.java
字号:
+ "/" + sc.getConnectorName() + "/" + syncSourceTypes[y].getDescription() + "/" + sync4jSources[z].getUri(); if ( t != null) msg += ": " + t.getMessage(); log.throwing(getClass().getName(), "getModule", t); syncSourcesFailed.add( new SyncSourceException( sync4jSources[z].getUri(), sync4jSources[z].getConfig(), t) ); } } SyncSource[] syncSourcesOK = (SyncSource[])syncSources.toArray(new SyncSource[syncSources.size()]); syncSourceTypes[y].setSyncSources(syncSourcesOK); SyncSourceException[] syncSourcesNO = (SyncSourceException[])syncSourcesFailed.toArray(new SyncSourceException[syncSourcesFailed.size()]); syncSourceTypes[y].setSyncSourcesFailed(syncSourcesNO); } } } catch (PersistentStoreException e) { String msg = "Error getting module: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe("Error getting Module: " + e.getMessage()); } log.throwing(getClass().getName(), "getModule", e); throw new ServerException(msg, e); } return module; } public void insertModule(Sync4jModule module, byte[] filess4j) throws ServerException, AdminException { log.fine("AdminBean method insertModule"); throw new AdminException("Not implemented yet"); } public void deleteModule(String moduleId) throws ServerException, AdminException { log.fine("AdminBean method deleteModule"); throw new AdminException("Not implemented yet"); } /** * Insert a new source into datastore and create a relative file xml with configuration. * The source must have a defined source type. * The source type must refer to a connector. * The connector must refer to a module. * * @param moduleId the module id * @param connectorId the connector id * @param sourceTypeId the source type id * @param source the information of the new source * * @throws ServerException * @throws AdminException */ public void insertSource(String moduleId, String connectorId, String sourceTypeId, SyncSource source) throws ServerException, AdminException { log.fine("AdminBean method insertSource"); String uri = source.getSourceURI(); String sourceName = source.getName(); String config = moduleId+File.separator+connectorId+File.separator+sourceTypeId; Sync4jSource s4j = new Sync4jSource(uri,config+File.separator+sourceName+".xml",sourceTypeId,sourceName); // //checking for the existance of the source before inserting // Sync4jSource existSource[] = null; try { WhereClause[] wc = new WhereClause[2]; String value[] = new String[1]; value[0] = uri; wc[0] = new WhereClause("uri",value, WhereClause.OPT_EQ, false); value[0] = sourceName; wc[1] = new WhereClause("name",value, WhereClause.OPT_EQ, false); LogicalClause lc = new LogicalClause(LogicalClause.OPT_OR, wc); existSource = (Sync4jSource[])ps.read(s4j, lc); } catch (PersistentStoreException e) { String msg = "Error reading sources existing: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "insertSource", e); throw new ServerException(msg, e); } if (existSource == null || existSource.length == 0) { try { ps.store(sourceTypeId, s4j, OPT_INSERT); } catch (PersistentStoreException e) { String msg = "Error adding the SyncSource: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "insertSource", e); throw new ServerException(msg, e); } } else { String msg = "A SyncSource with URI " + uri + " or with Name " + sourceName + " is already present."; throw new AdminException(msg); } try { String path = configPath + config; if (path.startsWith("file:")) path = path.substring(6); File f = new File(path); f.mkdirs(); XMLEncoder encoder = null; encoder = new XMLEncoder(new FileOutputStream(path+File.separator+sourceName+".xml")); encoder.writeObject((Object)source); encoder.flush(); encoder.close(); } catch(FileNotFoundException e) { String msg = "Error storing the SyncSource on file system: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "insertSource", e); throw new ServerException(msg, e); } } /** * Update a specific source into datastore and create a relative file xml with configuration. * The source must have a defined source type. * The source type must refer to a connector. * The connector must refer to a module. * * @param moduleId the module id * @param connectorId the connector id * @param sourceTypeId the source type id * @param source the information of the new source * * @throws ServerException * @throws AdminException */ public void setSource(String moduleId, String connectorId, String sourceTypeId, SyncSource source) throws ServerException, AdminException{ log.fine("AdminBean method setSource"); String uri = source.getSourceURI(); String sourceName = source.getName(); String config = moduleId + File.separator + connectorId + File.separator + sourceTypeId ; Sync4jSource s4j = new Sync4jSource(uri,null,sourceTypeId,null); try { ps.read(s4j); } catch (PersistentStoreException e) { String msg = "Error reading sources existing: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "insertSource", e); throw new ServerException(msg, e); } s4j.setSourceName(sourceName); String nameFileXml = s4j.getConfig().substring(config.length() + 1); try { ps.store(sourceTypeId, s4j, OPT_UPDATE); } catch (PersistentStoreException e) { String msg = "Error storing SyncSource: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "insertSource", e); throw new ServerException(msg, e); } try { String path = configPath + config; if (path.startsWith("file:")) path = path.substring(6); File f = new File(path); f.mkdirs(); XMLEncoder encoder = null; encoder = new XMLEncoder(new FileOutputStream(path+File.separator+nameFileXml)); encoder.writeObject((Object)source); encoder.flush(); encoder.close(); } catch(FileNotFoundException e) { String msg = "Error storing SyncSource: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "insertSource", e); throw new ServerException(msg, e); } } /** * Delete a specific source and the relative file of configuration. * * @param sourceUri the uri that identifies the source * * @throws ServerException * @throws AdminException */ public void deleteSource(String sourceUri) throws ServerException, AdminException{ log.fine("AdminBean method deleteSource"); Sync4jSource s4j = new Sync4jSource(sourceUri,null,null,null); try { ps.read(s4j); } catch (PersistentStoreException e) { String msg = "Error reading source: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "deleteSource", e); throw new ServerException(msg, e); } try { ps.delete(s4j); } catch (PersistentStoreException e) { String msg = "Error deleting SyncSource: " + e.getMessage(); if (log.isLoggable(Level.SEVERE)) { log.severe(msg); } log.throwing(getClass().getName(), "deleteSource", e); throw new ServerException(msg, e); } String path = configPath + s4j.getConfig(); if (path.startsWith("file:")) path = path.substring(6); File f = new File(path); f.delete(); } // --------------------------------------------------------- private methods /** * Loads the configuration for the server. The URI from which the configuration * is must be set as the envirnoment property named as <i>ENV_SERVER_CONFIG_URI</i>. * * @throws ConfigurationException in case of errors. */ private void loadConfiguration() throws ConfigurationException { config = new Configuration(); try { InitialContext ctx = new InitialContext(); // // The following two entries should be two URIs, but in the case // they are not (they do not start with http://, https:// or file://, // they are considered simple files // configURI = fixURI((String)ctx.lookup(ENV_SERVER_CONFIG_URI )); configPath = fixURI((String)ctx.lookup(ENV_SERVER_CONFIG_PATH)); config.setClassLoader( new ConfigClassLoader( new URL[] { configPath }, getClass().getClassLoader() ) ); config.load(configURI.toString()); if (log.isLoggable(Level.FINEST)) { log.finest("Configuration: " + config); } } catch (ConfigurationException e) { e.printStackTrace(); throw e; } catch (Exception e) { throw new ConfigurationException("Error loading configuration from " + configURI, e); } } /** * Checks if the given string is an accepted URL (starting with http://, * https:// or file://). If yes, a new URL object representing the given * url is returned; otherwise, the given string is considered a file name * and a new URL is obtained calling File.toURL(). * * @param s the string to check * * @return the corresponding URL if the string represents a URL or the * fixed URL if the string is a pathname/filename * * @throws MalformedURLException */ private URL fixURI(final String s) throws MalformedURLException { String minS = s.toLowerCase(); try { return new URL(s); } catch (MalformedURLException e) { // // This is not a URL, let's consider it just a file } try { return new File(new File(s).getCanonicalPath()).toURL(); } catch (IOException e) { throw new MalformedURLException("Unable to convert" + s + " to a URL"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -