List of usage examples for java.io Serializable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:it.geosolutions.geobatch.services.jmx.JMXServiceManager.java
/** * create the configured action on the remote GeoBatch server through the JMX connection * /*from w w w . j av a2 s.c om*/ * @param config A map containing the list of needed parameters, inputs and outputs used by the action * @throws Exception if: * <ul> * <li>the passed map is null</li> * <li>the passed map doesn't contains needed keys</li> * <li>the connection is lost</li> * </ul> */ @Override @org.springframework.jmx.export.annotation.ManagedOperation(description = "runConsumer - used to run a consumer") @ManagedOperationParameters({ @ManagedOperationParameter(name = "jmxConsumer", description = "A map containing the list of needed parameters, inputs and outputs used by the action") }) public void runConsumer(String uuid, Serializable event) throws Exception { if (uuid == null || event == null) { throw new IllegalArgumentException( "Unable to run using null arguments: uuid=" + uuid + " event=" + event); } EventConsumer consumer = getConsumer(uuid); // ///////// SET INPUTS if (event instanceof File) consumer.consume(new FileSystemEvent(File.class.cast(event), FileSystemEventType.FILE_ADDED)); else if (event instanceof String) consumer.consume(new FileSystemEvent(new File(event.toString()), FileSystemEventType.FILE_ADDED)); else throw new IllegalArgumentException("Unable to use the incoming event: bad type ->" + event.getClass()); // ///////// RUN CONSUMER // execute flowManager.getExecutor().submit(consumer); }
From source file:org.nuxeo.ecm.core.api.model.impl.primitives.BinaryProperty.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a va 2 s . c o m*/ public <T> T convertTo(Serializable value, Class<T> toType) throws PropertyConversionException { if (value == null) { return null; } if (InputStream.class.isAssignableFrom(toType)) { return (T) value; } if (toType == String.class && value instanceof InputStream) { try (InputStream in = (InputStream) value) { return (T) IOUtils.toString(in, Charsets.UTF_8); } catch (IOException e) { throw new InvalidPropertyValueException("Failed to read given input stream", e); } } if (toType == byte[].class && value instanceof InputStream) { try { return (T) IOUtils.toByteArray((InputStream) value); } catch (IOException e) { throw new InvalidPropertyValueException("Failed to read given input stream", e); } } throw new PropertyConversionException(value.getClass(), toType); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.TestCswRecordConverter.java
/** * Verifies that Zulu time zone is valid in ISO 8601 date. */// w w w. j a v a2 s .c om @Test public void testConvertISODateMetacardAttribute() { String dateStr = "2013-05-03T17:25:04Z"; Serializable ser = CswUnmarshallHelper.convertStringValueToMetacardValue(AttributeFormat.DATE, dateStr); assertThat(ser, not(nullValue())); assertThat(Date.class.isAssignableFrom(ser.getClass()), is(true)); Date date = (Date) ser; Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTime(date); assertThat(cal.get(Calendar.MONTH), equalTo(Calendar.MAY)); assertThat(cal.get(Calendar.YEAR), equalTo(2013)); assertThat(cal.get(Calendar.DAY_OF_MONTH), equalTo(3)); }
From source file:org.sakaiproject.tool.impl.RebuildBreakdownServiceImpl.java
/** * handleSessionStandardKey() set's the session attribute for the given key and object. * The object will be reconstructed if it is of type StoreableBreakdown; otherwise, it * is stored as the attributes value directly * @param s the Session that will contain the attribute * @param key the key for the attribute//from www . j a va 2 s. co m * @param object the value of the attribute, which will be reconstituted if of type StoreableBreakdown */ private void handleSessionStandardKey(HttpSession s, String key, Serializable object) { if (s != null && key != null) { String className = object.getClass().getName(); if (object instanceof StoreableBreakdown) { if (log.isDebugEnabled()) log.debug("rebuilding StoreableBreakdown, key: [" + key + "], className: [" + className + "]"); StoreableBreakdown storedBreakdown = (StoreableBreakdown) object; Breakdownable<?> handler = breakdownableHandlers.get(storedBreakdown.getClassName()); if (handler != null && handler instanceof BreakdownRebuildCallback) { // Skip the rebuilding and only call the stashing function boolean stashed = ((BreakdownRebuildCallback) handler).makeStash(storedBreakdown, key, s); if (!stashed) { String stashKey = storedBreakdown.makeStash(s.getId(), key); stashingCache.put(stashKey, storedBreakdown); } } else { Object thing = this.rebuildObject(storedBreakdown.getClassName(), storedBreakdown.getSize(), storedBreakdown.getData()); s.setAttribute(key, thing); } } else { if (log.isDebugEnabled()) { log.debug("rebuilding Serializable, key: [" + key + "], className: [" + className + "], value: [" + object + "]"); } s.setAttribute(key, object); } } }
From source file:org.nuxeo.ecm.platform.relations.services.RelationService.java
@Override public Set<Resource> getAllResources(Serializable object, Map<String, Object> context) { // TODO OPTIM implement reverse map in registerContribution Set<Resource> res = new HashSet<Resource>(); for (String ns : resourceAdapterRegistry.keySet()) { ResourceAdapter adapter = getResourceAdapterForNamespace(ns); if (adapter == null) { continue; }/*ww w . j a v a 2s . c o m*/ Class<?> klass = adapter.getKlass(); if (klass == null) { continue; } if (klass.isAssignableFrom(object.getClass())) { res.add(adapter.getResource(object, context)); } } return res; }
From source file:org.alfresco.serializers.NodePropertyHelper.java
/** * Helper method to convert the <code>Serializable</code> value into a full, persistable {@link NodePropertyValue}. * <p>//from ww w . jav a 2 s . com * Where the property definition is null, the value will take on the {@link DataTypeDefinition#ANY generic ANY} * value. * <p> * Collections are NOT supported. These must be split up by the calling code before calling this method. Map * instances are supported as plain serializable instances. * * @param propertyDef the property dictionary definition, may be null * @param value the value, which will be converted according to the definition - may be null * @return Returns the persistable property value */ public PropertyValue makeNodePropertyValue(PropertyDefinition propertyDef, Serializable value) { // get property attributes final QName propertyTypeQName; if (propertyDef == null) // property not recognised { // allow it for now - persisting excess properties can be useful sometimes propertyTypeQName = DataTypeDefinition.ANY; } else { propertyTypeQName = propertyDef.getDataType().getName(); } try { PropertyValue propertyValue = null; propertyValue = new PropertyValue(propertyTypeQName, value); // done return propertyValue; } catch (TypeConversionException e) { throw new TypeConversionException( "The property value is not compatible with the type defined for the property: \n" + " property: " + (propertyDef == null ? "unknown" : propertyDef) + "\n" + " value: " + value + "\n" + " value type: " + value.getClass(), e); } }
From source file:org.alfresco.repo.web.scripts.solr.SOLRSerializer.java
@SuppressWarnings("unchecked") public PropertyValue serialize(QName propName, Serializable value) throws IOException, JSONException { if (value == null) { return new PropertyValue(false, "null"); }/*from ww w. java 2 s . co m*/ PropertyDefinition propertyDef = dictionaryService.getProperty(propName); if (propertyDef == null) { // Treat it as text return new PropertyValue(true, serializeToJSONString(value)); } DataTypeDefinition dataType = propertyDef.getDataType(); QName dataTypeName = dataType.getName(); if (propertyDef.isMultiValued()) { if (!(value instanceof Collection)) { throw new IllegalArgumentException( "Multi value: expected a collection, got " + value.getClass().getName()); } Collection<Serializable> c = (Collection<Serializable>) value; JSONArray body = new JSONArray(); for (Serializable o : c) { if (dataTypeName.equals(DataTypeDefinition.MLTEXT)) { MLText source = (MLText) o; JSONArray array = new JSONArray(); for (Locale locale : source.getLocales()) { JSONObject json = new JSONObject(); json.put("locale", DefaultTypeConverter.INSTANCE.convert(String.class, locale)); json.put("value", source.getValue(locale)); array.put(json); } body.put(array); } else if (dataTypeName.equals(DataTypeDefinition.CONTENT)) { throw new RuntimeException("Multi-valued content properties are not supported"); } else { body.put(serializeToJSONString(o)); } } return new PropertyValue(false, body.toString()); } else { boolean encodeString = true; if (dataTypeName.equals(DataTypeDefinition.MLTEXT)) { encodeString = false; } else if (dataTypeName.equals(DataTypeDefinition.CONTENT)) { encodeString = false; } else { encodeString = true; } String sValue = null; if (value instanceof String && encodeString) { sValue = (String) jsonUtils.encodeJSONString(value); } else { sValue = serializeToJSONString(value); } return new PropertyValue(encodeString, sValue); } }
From source file:org.sakaiproject.tool.impl.RebuildBreakdownServiceImpl.java
/** * rebuildToolSessions() expects to find a Map of Maps. The outer map contains * the ToolSession ID's, and for each ToolSessionId, the inner map contains the * attributes of that tool session//from w w w . ja va2 s .co m * @param mySession a Session that can be resolved to a MySession, giving access to the ToolSession property * @param toolSessionMap a Serialized map of maps. The outer map containing the ToolSession ID, and the inner * map containing the details of the ToolSession */ private void rebuildToolSessions(MySession mySession, Map<String, Serializable> toolSessionMap) { for (Entry<String, Serializable> entry : toolSessionMap.entrySet()) { String toolSessionKey = entry.getKey(); // if a tool session doesn't exist for this key, a new one will be created automatically MyLittleSession toolSession = (MyLittleSession) mySession.getToolSession(toolSessionKey); Serializable serializable = entry.getValue(); if (!(serializable instanceof Map)) { log.warn("inner object for toolSession [" + toolSessionKey + "] should be [Map], found [" + serializable.getClass().getName() + "]"); continue; } @SuppressWarnings("unchecked") Map<String, Serializable> toolAttributes = (Map<String, Serializable>) serializable; processMLSessionMap(toolSession, toolAttributes); } }
From source file:org.sakaiproject.tool.impl.RebuildBreakdownServiceImpl.java
/** * rebuildContextSessions() expects to find a Map of Maps. The outer map contains * the ContextSession ID's, and for each ContextSessionId, the inner map contains the * attributes of that context session/* w w w . ja v a2s . co m*/ * @param mySession a Session that can be resolved to a MySession, giving access to the ToolSession property * @param contextSessionMap a Serialized map of maps. The outer map containing the ContextSession ID, and the inner * map containing the details of the ContextSession */ private void rebuildContextSessions(MySession mySession, Map<String, Serializable> contextSessionMap) { for (Entry<String, Serializable> entry : contextSessionMap.entrySet()) { String contextSessionKey = entry.getKey(); MyLittleSession contextSession = (MyLittleSession) mySession.getContextSession(contextSessionKey); Serializable serializable = entry.getValue(); if (!(serializable instanceof Map)) { log.warn("inner object for contextSession [" + contextSessionKey + "] should be [Map], found [" + serializable.getClass().getName() + "]"); continue; } @SuppressWarnings("unchecked") Map<String, Serializable> contextAttributes = (Map<String, Serializable>) serializable; processMLSessionMap(contextSession, contextAttributes); } }
From source file:org.socraticgrid.docmgr.DocumentManagerImpl.java
/** * Start a background job.//ww w. j a va 2 s . c o m * * @param msg * @return ticket, detail */ public static String[] startBackgroundJob(java.io.Serializable msg) { String result[] = new String[2]; try { //Create job id Date today = new Date(); String identity = String.valueOf(today.getTime()) + String.valueOf(Math.round(Math.random() % 10000)); log.debug("Scheduling job type '" + msg.getClass().getName() + "' with id: " + identity); // define the job and tie it to our HelloJob class XStream xstream = new XStream(); JobDetail job = JobBuilder.newJob(DocumentManagerJob.class).withIdentity(identity, "docmgr") .usingJobData(DOCMGR_JOB_MESSAGE, xstream.toXML(msg)).build(); // Trigger the job to run now, and then repeat every 40 seconds Trigger trigger = TriggerBuilder.newTrigger().withIdentity(identity, "docmgr").startNow().build(); // Tell quartz to schedule the job using our trigger SchedulerFactory sf = new StdSchedulerFactory(); Scheduler scheduler = sf.getScheduler("DocMgrScheduler"); scheduler.scheduleJob(job, trigger); //Set response info result[0] = identity; result[1] = JOB_START_SUCCESS; } catch (Throwable t) { String errMsg = JOB_START_FAILURE + ": error occurred trying to start docmgr job."; log.error(errMsg, t); result[0] = JOB_FAILURE_ID; result[1] = errMsg; } return result; }