List of usage examples for java.io Serializable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:edu.clemson.cs.nestbed.server.util.RemoteObservableImpl.java
public void notifyObservers(Serializable msg, Serializable arg) { List<RemoteObserver> deadObservers = new ArrayList<RemoteObserver>(); String msgType = (msg != null) ? msg.getClass().getName() : ""; String argType = (arg != null) ? arg.getClass().getName() : ""; // log.debug("Notifying observers\n" + // " message\n" + // " type: " + msgType + "\n" + // " value: " + msg + "\n" + // " argument\n" + // " type: " + argType + "\n" + // " value: " + arg); for (RemoteObserver i : new ArrayList<RemoteObserver>(observers)) { try {/*from ww w. j a v a2s . c o m*/ i.update(msg, arg); } catch (ConnectException e) { log.info("Dropping RemoteObserver:\n" + i); deadObservers.add(i); } catch (NoSuchObjectException e) { log.info("Dropping RemoteObserver:\n" + i); deadObservers.add(i); } catch (Exception e) { log.error("Exception occured while processing observers", e); e.printStackTrace(); } } try { for (RemoteObserver i : deadObservers) { deleteRemoteObserver(i); } } catch (RemoteException e) { /* empty */ } }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.provider.AbstractFieldPersistenceProvider.java
protected Class<?> getMapFieldType(Serializable instance, FieldManager fieldManager, Property property, PersistenceManager persistenceManager) { Class<?> returnType = null; Field field = fieldManager.getField(instance.getClass(), property.getName().substring(0, property.getName().indexOf(FieldManager.MAPFIELDSEPARATOR))); java.lang.reflect.Type type = field.getGenericType(); if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1]; Class<?>[] entities = persistenceManager.getDynamicEntityDao() .getAllPolymorphicEntitiesFromCeiling(clazz); if (!ArrayUtils.isEmpty(entities)) { returnType = entities[entities.length - 1]; }/*from w w w . j a v a 2s . c om*/ } return returnType; }
From source file:org.ambraproject.hibernate.AmbraIdGeneratorTest.java
@Test(dataProvider = "unsavedObjects") public void testGeneration(Object object, Class expectedIdClass, String expectedPrefix) { Serializable id = idGenerator.generate((SessionImplementor) session, object); assertNotNull(id, "generated null id"); assertFalse(id.toString().isEmpty(), "returned empty id"); assertEquals(id.getClass(), expectedIdClass, "returned id of incorrect class"); assertTrue(id.toString().startsWith(expectedPrefix), "Generated id didn't start with correct prefix; expected: " + expectedPrefix + " but found " + id); }
From source file:org.apache.james.transport.mailets.MimeDecodingMailet.java
@SuppressWarnings("unchecked") private Map<String, byte[]> getAttributeContent(Mail mail) throws MailetException { Serializable attributeContent = mail.getAttribute(attribute); if (!(attributeContent instanceof Map)) { log("Invalid attribute found into attribute " + attribute + "class Map expected but " + attributeContent.getClass() + " found."); return ImmutableMap.of(); }/* ww w .j a v a 2 s .c o m*/ return (Map<String, byte[]>) attributeContent; }
From source file:org.alfresco.repo.rendition.executer.AbstractRenderingEngine.java
/** * Gets the value for the named parameter. Checks the type of the parameter * is correct and throws a {@link RenditionServiceException} if it isn't. * Returns <code>null</code> if the parameter value is <code>null</code> * /*from w w w. jav a 2 s . c o m*/ * @param paramName the name of the parameter being checked. * @param clazz the expected {@link Class} of the parameter value. * @param definition the {@link RenditionDefinition} containing the * parameters. * @return the parameter value or <code>null</code>. */ @SuppressWarnings("unchecked") public static <T> T getCheckedParam(String paramName, Class<T> clazz, RenditionDefinition definition) { Serializable value = definition.getParameterValue(paramName); if (value == null) return null; else { if (clazz == null) throw new RenditionServiceException("The class must not be null!", new NullPointerException()); Class<? extends Serializable> valueClass = value.getClass(); if (!clazz.isAssignableFrom(valueClass)) { throw new RenditionServiceException("The parameter: " + paramName + " must be of type: " + clazz.getName() + "but was of type: " + valueClass.getName()); } else return (T) value; } }
From source file:no.uka.findmyapp.android.rest.client.RestProcessor.java
/** * Send intent broadcast.//from w ww. j a v a 2s. c o m * * @param intentString the intent string * @param obj the obj */ private void sendIntentBroadcast(String intentString, Serializable obj) { Log.v(debug, "sendIntentBroadcast: sending broadcast, object name " + obj.getClass().getName()); Log.v(debug, "sendIntentBroadcast: broadcast sent, extradata identifier: " + IntentMessages.BROADCAST_RETURN_VALUE_NAME); Log.v(debug, "sendIntentBroadcast: Putting extra " + obj.toString()); Intent broadcastedIntent = new Intent(); broadcastedIntent.putExtra(IntentMessages.BROADCAST_RETURN_VALUE_NAME, obj); broadcastedIntent.setAction(intentString); mContext.sendBroadcast(broadcastedIntent); }
From source file:no.uka.findmyapp.android.rest.client.RestProcessor.java
/** * Send to content provider./*from ww w . j a v a 2 s.c om*/ * * @param uri the uri * @param object the object * @param returnType the return type */ private void sendToContentProvider(Uri uri, Serializable object, String returnType) { Log.v(debug, "sendToContentProvider: serializable object " + object.getClass().getName()); ContentResolver cr = mContext.getContentResolver(); if (object instanceof List) { Class theClass = null; try { theClass = Class.forName(returnType); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<ContentValues> list = ContentHelper.getContentValuesList(object, theClass); Log.v(debug, "parsing contentvalue array"); ContentValues[] cva = new ContentValues[list.size()]; for (ContentValues cv : list) { cva[list.indexOf(cv)] = cv; } Log.v(debug, cva.toString()); cr.bulkInsert(UkaEventContract.EVENT_CONTENT_URI, cva); } else { ContentValues cv = new ContentValues(ContentHelper.getContentValues(object)); cr.insert(uri, cv); } }
From source file:org.apache.james.transport.mailets.AmqpForwardAttribute.java
@SuppressWarnings("unchecked") private Map<String, byte[]> getAttributeContent(Mail mail) throws MailetException { Serializable attributeContent = mail.getAttribute(attribute); if (!(attributeContent instanceof Map)) { throw new MailetException("Invalid attribute found into attribute " + attribute + "class Map expected but " + attributeContent.getClass() + " found."); }/*from w ww.ja v a 2 s. c o m*/ return (Map<String, byte[]>) attributeContent; }
From source file:org.apereo.portal.portlet.container.EventProviderImpl.java
@Override public Event createEvent(QName qname, Serializable value) throws IllegalArgumentException { if (this.isDeclaredAsPublishingEvent(qname)) { if (value != null && !this.isValueInstanceOfDefinedClass(qname, value)) { throw new IllegalArgumentException("Payload class (" + value.getClass().getCanonicalName() + ") does not have the right class, check your defined event types in portlet.xml."); }/*from w w w. j a v a 2 s .co m*/ if (value == null) { return new EventImpl(qname); } try { final Thread currentThread = Thread.currentThread(); final ClassLoader cl = currentThread.getContextClassLoader(); final Writer out = new StringWriter(); final Class clazz = value.getClass(); try { currentThread.setContextClassLoader(this.portletClassLoader); final JAXBContext jc = JAXBContext.newInstance(clazz); final Marshaller marshaller = jc.createMarshaller(); final JAXBElement<Serializable> element = new JAXBElement<Serializable>(qname, clazz, value); marshaller.marshal(element, out); } finally { currentThread.setContextClassLoader(cl); } return new EventImpl(qname, out.toString()); } catch (JAXBException e) { // maybe there is no valid jaxb binding // TODO throw exception? logger.error("Event handling failed", e); } catch (FactoryConfigurationError e) { // TODO throw exception? logger.warn(e.getMessage(), e); } } return null; }
From source file:org.devproof.portal.core.module.common.repository.DataProviderRepositoryImpl.java
private StringBuilder createWhereConditions(Serializable beanQuery, List<Object> queryParameter) { StringBuilder hqlQuery = new StringBuilder(); if (beanQuery != null) { appendTableJoin(beanQuery, hqlQuery); Method methods[] = beanQuery.getClass().getMethods(); if (methods.length > 0) { boolean firstClause = true; for (Method method : methods) { if (isGetterWithBeanQuery(method)) { Object value = invokeGetter(beanQuery, method); if (value != null) { if (firstClause) { firstClause = false; hqlQuery.append(" where "); } else { hqlQuery.append(" and "); }/*from w w w. jav a2s . com*/ BeanQuery bean = method.getAnnotation(BeanQuery.class); hqlQuery.append(bean.value()); int countMatches = StringUtils.countMatches(bean.value(), "?"); for (int j = 0; j < countMatches; j++) { queryParameter.add(value); } } } } } } return hqlQuery; }