当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中i5.las2peer.api.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于i5.las2peer.api包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getServiceNameVersion

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * This method allows to retrieve the service name version.
 *
 * @return Response with service name version as a JSON object.
 */
@GET
@Path("/version")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "This method allows to retrieve the service name version.")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns service name version"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems")
})
public Response getServiceNameVersion() throws ActivityTrackerException {
    try {
        String serviceNameVersion = Context.getCurrent().getService().getAgent().getServiceNameVersion().toString();
        return Response.ok("{\"version\": \"" + serviceNameVersion + "\"}").build();
    } catch (AgentNotKnownException ex) {
        ActivityTrackerException atException = ExceptionHandler.getInstance().convert(ex, ExceptionLocation.ACTIVITYTRACKERSERVICE, ErrorCode.UNKNOWN, ex.getMessage());
        L2pLogger.logEvent(NodeObserver.Event.SERVICE_ERROR, Context.getCurrent().getMainAgent(), "Get service name version failed");
        service.logger.warning(atException.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ExceptionHandler.getInstance().toJSON(atException)).build();
    }
}
 
开发者ID:rwth-acis,项目名称:las2peer-ActivityTracker,代码行数:25,代码来源:ActivityTrackerService.java

示例2: getServiceNameVersion

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * This method allows to retrieve the service name version.
 *
 * @return Response with service name version as a JSON object.
 */
@GET
@Path("/version")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "This method allows to retrieve the service name version.")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Returns service name version"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems")
})
public Response getServiceNameVersion() {
    try {
        String serviceNameVersion = Context.getCurrent().getService().getAgent().getServiceNameVersion().toString();
        return Response.ok("{\"version\": \"" + serviceNameVersion + "\"}").build();
    } catch (AgentNotKnownException ex) {
        BazaarException bex = ExceptionHandler.getInstance().convert(ex, ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, ex.getMessage());
        L2pLogger.logEvent(NodeObserver.Event.SERVICE_ERROR, Context.getCurrent().getMainAgent(), "Get service name version failed");
        bazaarService.logger.warning(bex.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ExceptionHandler.getInstance().toJSON(bex)).build();
    }
}
 
开发者ID:rwth-acis,项目名称:RequirementsBazaar,代码行数:25,代码来源:BazaarService.java

示例3: notifications

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * This method sends all notifications (emails) in the waiting queue. Run this method before shutting down Requirements Bazaar.
 *
 * @return Response
 */
@POST
@Path("/notifications")
@ApiOperation(value = "This method sends all notifications (emails) in the waiting queue. Run this method before shutting down Requirements Bazaar.")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "Notifications send"),
        @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal server problems")
})
public Response sendNotifications() {
    // TODO: Use authorization scopes to limit users who can run this method to admins
    try {
        bazaarService.notificationDispatcher.run();
        return Response.status(Response.Status.CREATED).build();
    } catch (Exception ex) {
        BazaarException bex = ExceptionHandler.getInstance().convert(ex, ExceptionLocation.BAZAARSERVICE, ErrorCode.UNKNOWN, ex.getMessage());
        L2pLogger.logEvent(NodeObserver.Event.SERVICE_ERROR, Context.getCurrent().getMainAgent(), "Send Notifications failed");
        bazaarService.logger.warning(bex.getMessage());
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ExceptionHandler.getInstance().toJSON(bex)).build();
    }
}
 
开发者ID:rwth-acis,项目名称:RequirementsBazaar,代码行数:26,代码来源:BazaarService.java

示例4: getActiveUserInfo

import i5.las2peer.api.Context; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private JSONObject getActiveUserInfo() throws ParseException {
	if (Context.getCurrent().getMainAgent() instanceof UserAgent) {
		UserAgent me = (UserAgent) Context.getCurrent().getMainAgent();
		JSONObject o = new JSONObject();
		if (Context.get().getMainAgent() instanceof AnonymousAgent) {
			o.put("sub", "anonymous");
		} else {

			String md5ide = new String("" + me.getIdentifier());
			o.put("sub", md5ide);
		}
		return o;
	} else {
		return new JSONObject();
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-surveys,代码行数:18,代码来源:SurveyService.java

示例5: getResultSet

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * Execute an sql-query and returns the corresponding result set. <br>
 * The actual database access is done here (by calling sqlDatabase.executeQuery).
 * 
 * @param sqlQuery the query
 * @param databaseKey the key of the database
 * 
 * @return ResultSet of the database query
 * @throws ServiceException
 * @throws SQLException
 */
private ResultSet getResultSet(Connection con, SQLDatabase sqlDatabase, String sqlQuery, String databaseKey)
		throws ServiceException, SQLException {
	try {
		ResultSet resultSet = sqlDatabase.executeQuery(con, sqlQuery);
		if (resultSet == null) {
			throw new Exception("Failed to get an result set from the desired database!");
		}

		return resultSet;
	} catch (SQLException ex) {
		throw ex;
	} catch (Exception e) {
		Context.get().monitorEvent(this, MonitoringEvent.SERVICE_ERROR, e.toString());
		System.out.println(e.getMessage());
		throw new ServiceException("Exception in getResultSet", e);
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:29,代码来源:QueryVisualizationService.java

示例6: saveQuery

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * Saves a query. <br>
 * 
 * @param queryStatement a String containing the query
 * @param databaseKey the key to the database
 * @param useCache if true, a cached result is returned (if available) instead of performing the query again
 * @param modificationTypeIndex the desired modification function
 * @param visualizationTypeIndex the desired visualization
 * @param visualizationParamaters an array of additional parameters for the visualization, including title, height
 *            and weight
 * 
 * @return The id of the saved query as a String
 */
private String saveQuery(String queryStatement, String[] queryParameters, String databaseKey, boolean useCache,
		int modificationTypeIndex, VisualizationType visualizationTypeIndex, String[] visualizationParamaters) {

	SQLDatabase database = null;
	Query query = null;
	String queryKey = ""; // If empty, the query generates a new one
	try {
		String user = Context.get().getMainAgent().getIdentifier();
		SQLDatabaseManager databaseManager = databaseManagerMap.get(user);
		QueryManager queryManager = queryManagerMap.get(user);
		database = databaseManager.getDatabaseInstance(databaseKey);
		query = new Query(Context.getCurrent().getMainAgent().getIdentifier(), database.getJdbcInfo(),
				database.getUser(), database.getPassword(), databaseKey, database.getDatabase(), database.getHost(),
				database.getPort(), queryStatement, queryParameters, useCache, modificationTypeIndex,
				visualizationTypeIndex, visualizationParamaters, queryKey);
		queryManager.storeQuery(query);
	} catch (Exception e) {
		Context.get().monitorEvent(this, MonitoringEvent.SERVICE_ERROR, e.toString());
		return VisualizationException.getInstance().generate(e, "An error occured while trying to save a Query!");
	}

	Context.get().monitorEvent(this, MonitoringEvent.SERVICE_CUSTOM_MESSAGE_17, "" + query.getQueryStatement(),
			true);
	return query.getKey();
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:39,代码来源:QueryVisualizationService.java

示例7: QueryManager

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * Constructor
 * 
 * @param service instance of the qv service
 * @param dbm Database
 */
public QueryManager(QueryVisualizationService service, SQLDatabase dbm) {
	storageDatabase = dbm;
	this.service = service;
	// get the user's security object which contains the database
	// information

	Query[] settings = null;

	try {
		Connection c = storageDatabase.getConnection();
		PreparedStatement p = c.prepareStatement("SELECT * FROM QUERIES WHERE USER = ?;");
		p.setString(1, Context.get().getMainAgent().getIdentifier());
		ResultSet databases = p.executeQuery();
		settings = Query.fromResultSet(databases);
		c.close();
	} catch (Exception e) {
		logMessage("Failed to get the users' SQL settings. " + e.getMessage());
	}

	for (Query setting : settings) {
		userQueryMap.put(setting.getKey(), setting);
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:30,代码来源:QueryManager.java

示例8: databaseDeleted

import i5.las2peer.api.Context; //导入依赖的package包/类
public void databaseDeleted(String dbKey) {
	String db;
	try {
		db = service.databaseManagerMap.get(Context.get().getMainAgent().getIdentifier()).getDatabaseInstance(dbKey)
				.getDatabase();
	} catch (Exception e1) {
		return;
	}
	for (Query q : userQueryMap.values()) {
		if (q.getDatabaseName().equals(db)) {
			try {
				removeQ(q.getKey());
			} catch (Exception e) {
			}
		}
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:18,代码来源:QueryManager.java

示例9: removeQ

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * Remove given database from the database
 * 
 * @param queryKey Key of the query which will be removed
 */
public void removeQ(String queryKey) {
	try {

		Connection c = storageDatabase.getConnection();
		PreparedStatement s = c.prepareStatement("DELETE FROM `QUERIES` WHERE ((`KEY` = ? AND `USER` = ?))");
		s.setString(1, queryKey);
		s.setString(2, Context.get().getMainAgent().getIdentifier());
		s.executeUpdate();
		c.close();
	} catch (Exception e) {
		logMessage("Error removing the Query! " + e);
		System.out.println("QV critical:");
		e.printStackTrace();
	} finally {
		userQueryMap.remove(queryKey);
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:23,代码来源:QueryManager.java

示例10: setStateFromXml

import i5.las2peer.api.Context; //导入依赖的package包/类
public void setStateFromXml(String arg0) throws MalformedXMLException {
	try {
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(arg0);
		int childrenCount = doc.getChildNodes().item(0).getChildNodes().getLength();
		doc.getDocumentElement().normalize();
		Element elm = doc.getDocumentElement();

		if (childrenCount != 1) {
			throw new Exception("Wrong number of children! " + childrenCount + " instead of 1!");
		}

		this.key = elm.getAttribute("key");

		this.query = elm.getAttribute("query");
		this.databaseKey = elm.getAttribute("databaseKey");

	} catch (Exception e) {
		Context.get().monitorEvent(this, MonitoringEvent.SERVICE_ERROR,
				"SQLFilterSettings, setStateFromXML: " + e.getMessage());
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:24,代码来源:SQLFilterSettings.java

示例11: addFilter

import i5.las2peer.api.Context; //导入依赖的package包/类
public boolean addFilter(String databaseKey, String filterName, String sqlQuery) throws Exception {
	StringPair filterKey = new StringPair(databaseKey, filterName);
	try {
		// TODO: sanity checks for the parameters
		if (filterExists(databaseKey, filterName)) {
			throw new Exception("Filter " + filterKey + " already exists!");
		}

		Connection c = storageDatabase.getConnection();
		SQLFilterSettings filterSettings = new SQLFilterSettings(databaseKey, filterName, sqlQuery);
		PreparedStatement p = c.prepareStatement(
				"INSERT INTO `FILTERS` (`KEY`, `QUERY`, `USER`, `DB_KEY`) VALUES (?,	?,	?,	?);");
		p.setString(1, filterName);
		p.setString(2, sqlQuery);
		p.setString(3, Context.get().getMainAgent().getIdentifier());
		p.setString(4, databaseKey);
		p.executeUpdate();
		userFilterMap.put(filterSettings.getKey(), filterSettings);
		c.close();
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		logMessage(e.getMessage());
		throw e;
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:27,代码来源:SQLFilterManager.java

示例12: initializeUser

import i5.las2peer.api.Context; //导入依赖的package包/类
private boolean initializeUser() {
	try {
		Connection c = storageDatabase.getConnection();
		PreparedStatement p = c.prepareStatement("SELECT DISTINCT ID FROM USERS WHERE ID = ?");
		p.setString(1, Context.get().getMainAgent().getIdentifier());
		ResultSet s = p.executeQuery();
		if (!s.next()) {
			p = c.prepareStatement("REPLACE INTO USERS (ID) VALUES (?)");
			p.setString(1, Context.get().getMainAgent().getIdentifier());
			p.executeUpdate();
		}
		c.close();
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
	return true;
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:19,代码来源:SQLDatabaseManager.java

示例13: SQLDatabaseManager

import i5.las2peer.api.Context; //导入依赖的package包/类
public SQLDatabaseManager(Service service, SQLDatabase storageDatabase) {
	this.storageDatabase = storageDatabase;
	// get the user's security object which contains the database
	// information

	initializeUser();

	SQLDatabaseSettings[] settings = null;

	try {
		Connection c = storageDatabase.getConnection();
		PreparedStatement p = c.prepareStatement("SELECT * FROM DATABASE_CONNECTIONS WHERE USER = ?;");
		p.setString(1, Context.get().getMainAgent().getIdentifier());
		ResultSet databases = p.executeQuery();
		settings = SQLDatabaseSettings.fromResultSet(databases);
		c.close();
	} catch (Exception e) {
		logMessage("Failed to get the users' SQL settings. " + e.getMessage());
	}

	for (SQLDatabaseSettings setting : settings) {
		userDatabaseMap.put(setting.getKey(), setting);
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:25,代码来源:SQLDatabaseManager.java

示例14: removeDB

import i5.las2peer.api.Context; //导入依赖的package包/类
/**
 * Remove given database from the database
 */
private void removeDB(String databaseKey) throws SQLException {
	try {

		Connection c = storageDatabase.getConnection();
		PreparedStatement s = c
				.prepareStatement("DELETE FROM `DATABASE_CONNECTIONS` WHERE `KEY` = ? AND `USER` = ?");
		s.setString(1, databaseKey);
		s.setString(2, Context.get().getMainAgent().getIdentifier());
		s.executeUpdate();
		c.close();
	} catch (Exception e) {
		logMessage("Error removing the Database! " + e);
		System.out.println("QV critical:");
		e.printStackTrace();
	}
}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:20,代码来源:SQLDatabaseManager.java

示例15: executeQuery

import i5.las2peer.api.Context; //导入依赖的package包/类
public ResultSet executeQuery(Connection con, String sqlQuery) throws Exception {

		// I don't allow escape characters...
		// at least some very basic escape checking
		// (I don't think it is sufficient for a real attack though....)
		sqlQuery = sqlQuery.replace("\\", "\\\\");
		sqlQuery = sqlQuery.replace("\0", "\\0");
		sqlQuery = sqlQuery.replace(";", "");

		try {
			Statement statement = con.createStatement();
			ResultSet resultSet = statement.executeQuery(sqlQuery);
			return resultSet;
		} catch (SQLException ex) {
			System.out.println(ex.getMessage());
			throw ex;
		} catch (Exception e) {
			System.out.println(e.getMessage());
			Context.get().monitorEvent(this, MonitoringEvent.SERVICE_ERROR, e.toString());
			throw e;
		}
	}
 
开发者ID:rwth-acis,项目名称:mobsos-query-visualization,代码行数:23,代码来源:SQLDatabase.java


注:本文中的i5.las2peer.api.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。