List of usage examples for java.io Serializable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.jbpm.scheduler.ejbtimer.TimerServiceBean.java
public void ejbTimeout(javax.ejb.Timer ejbTimer) { log.debug("ejb timer " + ejbTimer + " fires"); String localCommandServiceJndiName = "java:comp/env/ejb/LocalCommandServiceBean"; try {/*ww w. ja v a 2s.c om*/ Context initial = new InitialContext(); LocalCommandServiceHome localCommandServiceHome = (LocalCommandServiceHome) initial .lookup(localCommandServiceJndiName); LocalCommandService localCommandService = localCommandServiceHome.create(); Serializable info = ejbTimer.getInfo(); if (!(info instanceof TimerInfo)) { if (info == null) { throw new NullPointerException("timer info is null"); } else { throw new ClassCastException("timer info (" + info.getClass().getName() + ") is not of the expected class " + TimerInfo.class.getName()); } } TimerInfo timerInfo = (TimerInfo) info; Timer timer = (Timer) localCommandService.execute(new ExecuteTimerCommand(timerInfo.getTimerId())); // if the timer has repeat if ((timer != null) && (timer.getRepeat() != null)) { // create a new timer log.debug("scheduling timer for repeat at " + timer.getDueDate()); createTimer(timer); } } catch (Exception e) { JbpmException jbpmException = new JbpmException("couldn't execute timer", e); log.error(jbpmException); throw jbpmException; } }
From source file:org.alfresco.repo.web.scripts.solr.SOLRSerializer.java
public String serializeToJSONString(Serializable value) { if (value != null && typeConverter.INSTANCE.getConverter(value.getClass(), String.class) == null) { // There is no converter return value.toString(); } else {/* w w w. j a va 2 s. c o m*/ return typeConverter.INSTANCE.convert(String.class, value); } }
From source file:org.bonitasoft.engine.command.ExecuteBDMQueryCommandIT.java
@Test public void should_execute_returns_a_single_employee() throws Exception { final Map<String, Serializable> parameters = new HashMap<String, Serializable>(); parameters.put(QUERY_NAME, "BonitaEmployee.getEmployeeByFirstNameAndLastName"); parameters.put(RETURN_TYPE, EMPLOYEE_QUALIF_CLASSNAME); final Map<String, Serializable> queryParameters = new HashMap<String, Serializable>(); queryParameters.put("firstName", "Romain"); queryParameters.put("lastName", "Bioteau"); parameters.put(QUERY_PARAMETERS, (Serializable) queryParameters); final byte[] result = (byte[]) getCommandAPI().execute(EXECUTE_BDM_QUERY_COMMAND, parameters); final Serializable employee = deserializeSimpleResult(result); assertThat(employee).isNotNull().isInstanceOf(Entity.class); assertThat(employee.getClass().getName()).isEqualTo(EMPLOYEE_QUALIF_CLASSNAME); assertThat(employee.getClass().getMethod("getFirstName", new Class[0]).invoke(employee)) .isEqualTo("Romain"); assertThat(employee.getClass().getMethod("getLastName", new Class[0]).invoke(employee)) .isEqualTo("Bioteau"); final Object invoke = employee.getClass().getMethod("getAddresses", new Class[0]).invoke(employee); assertThat(invoke).isInstanceOf(List.class); assertThat((List<?>) invoke).isEmpty(); }
From source file:com.clican.pluto.fsm.model.Variable.java
public void setValue(Serializable value) { this.value = value; if (value == null) { this.persistentValue = null; this.classType = null; return;//from www. j a v a 2s .c o m } this.classType = value.getClass().getName(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); if (value instanceof Date) { this.persistentValue = sdf.format((Date) value); } else if (value instanceof Calendar) { this.persistentValue = sdf.format(((Calendar) value).getTime()); } else if (value instanceof Number) { this.persistentValue = value.toString(); } else if (value instanceof String) { this.persistentValue = value.toString(); } else { this.persistentValue = value.toString(); } }
From source file:net.projectmonkey.spring.acl.hbase.repository.AclRecord.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private byte[] createKey(final Serializable identifier, final AclIdentifierConverter converter) { byte[] toReturn; if (identifier instanceof byte[]) { toReturn = (byte[]) identifier; } else if (converter != null) { verifyConverterType(converter, identifier.getClass()); try {//from w w w . jav a 2s . co m toReturn = converter.toByteArray(identifier); } catch (Exception e) { throw new AuthorizationServiceException("An unexpected exception occurred converting from " + identifier + " to byte[] using converter " + converter, e); } } else { throw new AuthorizationServiceException( "No converter configured for identifier type " + identifier.getClass()); } if (toReturn == null) { throw new AuthorizationServiceException( "Null key returned for " + identifier + " and converter " + converter); } return toReturn; }
From source file:org.sigmah.server.endpoint.gwtrpc.handler.calendar.ActivityCalendarHandler.java
@Override public Calendar getCalendar(Serializable identifier) { if (!(identifier instanceof ActivityCalendarIdentifier)) { throw new IllegalArgumentException( "Identifier must be an instance of ActivityCalendarIdentifier, received an instance of " + identifier.getClass().getSimpleName()); }/*from w ww. j a v a2s . co m*/ final ActivityCalendarIdentifier activityCalendarIdentifier = (ActivityCalendarIdentifier) identifier; em.clear(); final Query query = em.createQuery("SELECT l FROM LogFrame l WHERE l.parentProject.id = :projectId"); query.setParameter("projectId", activityCalendarIdentifier.getProjectId()); // Configuring the calendar final Calendar calendar = new Calendar(); calendar.setIdentifier(identifier); calendar.setName(activityCalendarIdentifier.getCalendarName()); calendar.setEditable(false); final HashMap<Date, List<Event>> eventMap = new HashMap<Date, List<Event>>(); calendar.setEvents(eventMap); try { final LogFrame logFrame = (LogFrame) query.getSingleResult(); // Preparing the activity code final StringBuilder codeBuilder = new StringBuilder(activityCalendarIdentifier.getActivityPrefix()); codeBuilder.append(' '); // Looping on the logical framework objects final List<SpecificObjective> specificObjectives = logFrame.getSpecificObjectives(); for (final SpecificObjective specificObjective : specificObjectives) { int baseSize = codeBuilder.length(); codeBuilder.append((char) ('A' + specificObjective.getCode() - 1)); codeBuilder.append('.'); final List<ExpectedResult> expectedResults = specificObjective.getExpectedResults(); for (final ExpectedResult expectedResult : expectedResults) { int specificObjectiveSize = codeBuilder.length(); codeBuilder.append(expectedResult.getCode()); codeBuilder.append('.'); // For each activity final List<LogFrameActivity> activities = expectedResult.getActivities(); for (final LogFrameActivity activity : activities) { int expectedResultSize = codeBuilder.length(); codeBuilder.append(activity.getCode()); codeBuilder.append('.'); final Date startDate = activity.getStartDate(); if (activity.getTitle() != null) { codeBuilder.append(' '); codeBuilder.append(activity.getTitle()); } // For each day if (startDate != null) { //if activity end date is not spcified set its value to start date if (activity.getEndDate() == null) { activity.setEndDate(startDate); } for (Date date = new Date(startDate.getYear(), startDate.getMonth(), startDate.getDate()); date.compareTo(activity.getEndDate()) < 1; date .setDate(date.getDate() + 1)) { final Date key = new Date(date.getTime()); final Event event = new Event(); event.setSummary(codeBuilder.toString()); event.setDtstart(new Date(startDate.getTime())); if (startDate.equals(activity.getEndDate())) { event.setDtend(new Date(startDate.getYear(), startDate.getMonth(), startDate.getDate() + 1)); } else { event.setDtend(new Date(activity.getEndDate().getTime())); } event.setParent(calendar); event.setIdentifier(activity.getId()); // Adding the event to the event map List<Event> list = eventMap.get(key); if (list == null) { list = new ArrayList<Event>(); eventMap.put(key, list); } list.add(event); } } codeBuilder.setLength(expectedResultSize); } codeBuilder.setLength(specificObjectiveSize); } codeBuilder.setLength(baseSize); } } catch (NoResultException e) { // No activities in the current project } return calendar; }
From source file:com.formtek.dashlets.sitetaskmgr.SiteTaskInstancePut.java
@SuppressWarnings("unchecked") private Map<QName, Serializable> parseTaskProperties(JSONObject json, WorkflowTask workflowTask) throws JSONException { Map<QName, Serializable> props = new HashMap<QName, Serializable>(); // gets the array of properties names String[] names = JSONObject.getNames(json); if (names != null) { // array is not empty for (String name : names) { // build the qname of property QName key = QName.createQName(name.replaceFirst("_", ":"), namespaceService); Object jsonValue = json.get(name); Serializable value = null; // process null values if (jsonValue.equals(JSONObject.NULL)) { props.put(key, null);//www . j av a2 s . c o m } else { // gets the property definition from dictionary PropertyDefinition prop = dictionaryService.getProperty(key); if (prop != null) { // convert property using its data type specified in model value = (Serializable) DefaultTypeConverter.INSTANCE.convert(prop.getDataType(), jsonValue); } else { // property definition was not found in dictionary if (jsonValue instanceof JSONArray) { value = new ArrayList<String>(); for (int i = 0; i < ((JSONArray) jsonValue).length(); i++) { ((List<String>) value).add(((JSONArray) jsonValue).getString(i)); } } else { // If the JSON returns an Object which is not a String, we use that type. // Otherwise, we try to convert the string if (jsonValue instanceof String) { logger.debug("Writing value: " + key + " : " + jsonValue); // Check if the task already has the property, use that type. Serializable existingValue = workflowTask.getProperties().get(key); if (existingValue != null) { try { value = DefaultTypeConverter.INSTANCE.convert(existingValue.getClass(), jsonValue); } catch (TypeConversionException tce) { // TODO: is this the right approach, ignoring exception? // Ignore the exception, revert to using String-value } } else { // Revert to using string-value value = (String) jsonValue; } } else { // Use the value provided by JSON value = (Serializable) jsonValue; } } } } props.put(key, value); } } return props; }
From source file:org.jbpm.ejb.impl.CommandListenerBean.java
protected Command extractCommand(Message message) throws JMSException { Command command = null;/*from w w w. ja va 2 s. co m*/ if (message instanceof ObjectMessage) { log.debug("deserializing command from jms message..."); ObjectMessage objectMessage = (ObjectMessage) message; Serializable object = objectMessage.getObject(); if (object instanceof Command) { command = (Command) object; } else { log.warn("ignoring object message cause it isn't a command '" + object + "'" + (object != null ? " (" + object.getClass().getName() + ")" : "")); } } else { log.warn("ignoring message '" + message + "' cause it isn't an ObjectMessage (" + message.getClass().getName() + ")"); } return command; }
From source file:org.apache.atlas.storm.hook.StormAtlasHook.java
private Referenceable createBoltInstance(String boltName, Bolt stormBolt) throws IllegalAccessException { Referenceable boltReferenceable = new Referenceable(StormDataTypes.STORM_BOLT.getName()); boltReferenceable.set(AtlasClient.NAME, boltName); Serializable instance = Utils.javaDeserialize(stormBolt.get_bolt_object().get_serialized_java(), Serializable.class); boltReferenceable.set("driverClass", instance.getClass().getName()); Map<String, String> flatConfigMap = StormTopologyUtil.getFieldValues(instance, true, null); boltReferenceable.set("conf", flatConfigMap); return boltReferenceable; }
From source file:org.nuxeo.ecm.core.api.model.impl.primitives.BlobProperty.java
@SuppressWarnings("unchecked") @Override//w ww .j av a 2 s .c o m public <T> T convertTo(Serializable value, Class<T> toType) throws PropertyConversionException { if (value == null) { return null; } if (Blob.class.isAssignableFrom(toType)) { return (T) value; } throw new PropertyConversionException(value.getClass(), toType); }