List of usage examples for java.beans IntrospectionException printStackTrace
public void printStackTrace()
From source file:fedora.server.security.servletfilters.xmluserfile.FedoraUsers.java
public static FedoraUsers getInstance(URI fedoraUsersXML) { FedoraUsers fu = null;//from ww w.ja va 2 s. c om BeanReader reader = new BeanReader(); reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false); reader.getBindingConfiguration().setMapIDs(false); try { reader.registerMultiMapping(getBetwixtMapping()); fu = (FedoraUsers) reader.parse(fedoraUsersXML.toString()); } catch (IntrospectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } return fu; }
From source file:BeanUtil.java
/** * Retreives a property descriptor object for a given property. * <p>//from ww w . j av a2 s .co m * Uses the classes in <code>java.beans</code> to get back * a descriptor for a property. Read-only and write-only * properties will have a slower return time. * </p> * * @param propertyName The programmatic name of the property * @param beanClass The Class object for the target bean. * For example sun.beans.OurButton.class. * @return a PropertyDescriptor for a property that follows the * standard Java naming conventions. * @throws PropertyNotFoundException indicates that the property * could not be found on the bean class. */ private static final PropertyDescriptor getPropertyDescriptor(String propertyName, Class beanClass) { PropertyDescriptor resultPropertyDescriptor = null; char[] pNameArray = propertyName.toCharArray(); pNameArray[0] = Character.toLowerCase(pNameArray[0]); propertyName = new String(pNameArray); try { resultPropertyDescriptor = new PropertyDescriptor(propertyName, beanClass); } catch (IntrospectionException e1) { // Read-only and write-only properties will throw this // exception. The properties must be looked up using // brute force. // This will get the list of all properties and iterate // through looking for one that matches the property // name passed into the method. try { BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (int i = 0; i < propertyDescriptors.length; i++) { if (propertyDescriptors[i].getName().equals(propertyName)) { // If the names match, this this describes the // property being searched for. Break out of // the iteration. resultPropertyDescriptor = propertyDescriptors[i]; break; } } } catch (IntrospectionException e2) { e2.printStackTrace(); } } // If no property descriptor was found, then this bean does not // have a property matching the name passed in. if (resultPropertyDescriptor == null) { System.out.println("resultPropertyDescriptor == null"); } return resultPropertyDescriptor; }
From source file:fedora.server.config.webxml.WebXML.java
/** * Create an instance of WebXML from the specified file. * // www. j a v a 2 s. c o m * @param webxml * Path to web.xml file. * @return instance of WebXML */ public static WebXML getInstance(String webxml) { WebXML wx = null; BeanReader reader = new BeanReader(); reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false); reader.getBindingConfiguration().setMapIDs(false); try { reader.registerMultiMapping(getBetwixtMapping()); wx = (WebXML) reader.parse(new File(webxml).toURI().toString()); } catch (IntrospectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } return wx; }
From source file:edu.harvard.med.screensaver.model.AbstractEntityInstanceTest.java
/** * Subclasses should call this method to build their TestSuite, as it will * include tests for the test methods declared in this class, as well as tests * for each entity property found in the specified AbstractEntity class. * /* ww w . j a v a 2s. c o m*/ * @param entityTestClass * @param entityClass * @return */ public static TestSuite buildTestSuite(Class<? extends AbstractEntityInstanceTest> entityTestClass, Class<? extends AbstractEntity> entityClass) { TestSuite testSuite = new TestSuite(entityTestClass); BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(entityClass); // add all the property-specific tests for this entity class for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { if (propertyDescriptor.getName().equals("class")) { log.debug("not creating test for \"class\" property " + propertyDescriptor.getDisplayName()); } else if (ModelIntrospectionUtil.isTransientProperty(propertyDescriptor)) { log.debug("not creating test for transient (non-persistent) property " + propertyDescriptor.getDisplayName()); } else /*if (ModelIntrospectionUtil.isToManyEntityRelationship(propertyDescriptor))*/ { propertyDescriptor = new GenericTypeAwarePropertyDescriptor(entityClass, propertyDescriptor); testSuite.addTest(new EntityPropertyTest(entityClass, propertyDescriptor)); } } } catch (IntrospectionException e) { e.printStackTrace(); fail(e.getMessage()); } return testSuite; }
From source file:org.hx.rainbow.common.util.JavaBeanUtil.java
@SuppressWarnings("rawtypes") private static Map<String, Class> getFileds(Class clazz) { BeanInfo beanInfo = null;//from www. j ava 2 s.co m try { beanInfo = Introspector.getBeanInfo(clazz); } catch (IntrospectionException e) { e.printStackTrace(); } Map<String, Class> map = new HashMap<String, Class>(); PropertyDescriptor[] pr = beanInfo.getPropertyDescriptors(); for (int i = 1; i < pr.length; i++) { map.put(pr[i].getName(), pr[i].getPropertyType()); } Field[] field = clazz.getDeclaredFields(); for (int i = 1; i < field.length; i++) { map.put(field[i].getName(), field[i].getType()); } return map; }
From source file:acmi.l2.clientmod.xdat.Controller.java
private static List<PropertySheetItem> loadProperties(Object obj) { Class<?> objClass = obj.getClass(); List<PropertySheetItem> list = new ArrayList<>(); while (objClass != Object.class) { try {/*from w w w . j a v a 2 s .c o m*/ List<String> names = Arrays.stream(objClass.getDeclaredFields()) .map(field -> field.getName().replace("Prop", "")).collect(Collectors.toList()); BeanInfo beanInfo = Introspector.getBeanInfo(objClass, objClass.getSuperclass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); Arrays.sort(propertyDescriptors, (pd1, pd2) -> Integer.compare(names.indexOf(pd1.getName()), names.indexOf(pd2.getName()))); for (PropertyDescriptor descriptor : propertyDescriptors) { if ("metaClass".equals(descriptor.getName())) continue; if (Collection.class.isAssignableFrom(descriptor.getPropertyType())) continue; AnnotatedElement getter = descriptor.getReadMethod(); if (getter.isAnnotationPresent(Deprecated.class) || getter.isAnnotationPresent(Hide.class)) continue; String description = ""; if (getter.isAnnotationPresent(Description.class)) description = getter.getAnnotation(Description.class).value(); Class<? extends PropertyEditor<?>> propertyEditorClass = null; if (descriptor.getPropertyType() == Boolean.class || descriptor.getPropertyType() == Boolean.TYPE) { propertyEditorClass = BooleanPropertyEditor.class; } else if (getter.isAnnotationPresent(Tex.class)) { propertyEditorClass = TexturePropertyEditor.class; } else if (getter.isAnnotationPresent(Sysstr.class)) { propertyEditorClass = SysstringPropertyEditor.class; } BeanProperty property = new BeanProperty(descriptor, objClass.getSimpleName(), description, propertyEditorClass); list.add(property); } } catch (IntrospectionException e) { e.printStackTrace(); } objClass = objClass.getSuperclass(); } return list; }
From source file:org.bibsonomy.model.util.BibTexUtils.java
/** * return a bibtex string representation of the given bibtex object * // w w w. jav a 2s .c om * @param bib - a bibtex object * @param mode - the serializing mode (parse misc fields or include misc fields as they are) * @return String bibtexString * * TODO use BibTex.DEFAULT_OPENBRACKET etc. * */ public static String toBibtexString(final BibTex bib, SerializeBibtexMode mode) { try { final BeanInfo bi = Introspector.getBeanInfo(bib.getClass()); /* * start with entrytype and key */ final StringBuilder buffer = new StringBuilder( "@" + bib.getEntrytype() + "{" + bib.getBibtexKey() + ",\n"); /* * append all other fields */ for (final PropertyDescriptor d : bi.getPropertyDescriptors()) { final Method getter = d.getReadMethod(); // loop over all String attributes final Object o = getter.invoke(bib, (Object[]) null); if (String.class.equals(d.getPropertyType()) && o != null && !EXCLUDE_FIELDS.contains(d.getName())) { /* * Strings containing whitespace give empty fields ... we ignore them */ String value = ((String) o); if (present(value)) { if (!NUMERIC_PATTERN.matcher(value).matches()) { value = DEFAULT_OPENING_BRACKET + value + DEFAULT_CLOSING_BRACKET; } buffer.append(" " + d.getName().toLowerCase() + " = " + value + ",\n"); } } } /* * process miscFields map, if present */ if (present(bib.getMiscFields())) { if (mode.equals(SerializeBibtexMode.PARSED_MISCFIELDS) && !bib.isMiscFieldParsed()) { // parse misc field, if not yet done bib.parseMiscField(); } buffer.append(serializeMiscFields(bib.getMiscFields(), true)); } /* * include plain misc fields if desired */ if (mode.equals(SerializeBibtexMode.PLAIN_MISCFIELDS) && present(bib.getMisc())) { buffer.append(" " + bib.getMisc() + ",\n"); } /* * add month */ final String month = bib.getMonth(); if (present(month)) { // we don't add {}, this is done by getMonth(), if necessary buffer.append(" month = " + getMonth(month) + ",\n"); } /* * add abstract */ final String bibAbstract = bib.getAbstract(); if (present(bibAbstract)) { buffer.append(" abstract = {" + bibAbstract + "},\n"); } /* * remove last comma */ buffer.delete(buffer.lastIndexOf(","), buffer.length()); buffer.append("\n}"); return buffer.toString(); } catch (IntrospectionException ex) { ex.printStackTrace(); } catch (InvocationTargetException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } return null; }
From source file:com.unboundid.scim2.common.utils.JsonRefBeanSerializer.java
/** * {@inheritDoc}//from w ww . ja v a2s . co m */ @Override public void serialize(final Object value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException { Class<?> clazz = value.getClass(); try { gen.writeStartObject(); Collection<PropertyDescriptor> propertyDescriptors = SchemaUtils.getPropertyDescriptors(clazz); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { Field field = SchemaUtils.findField(clazz, propertyDescriptor.getName()); if (field == null) { continue; } field.setAccessible(true); Object obj = field.get(value); if (obj instanceof JsonReference) { JsonReference<?> reference = (JsonReference<?>) obj; if (reference.isSet()) { gen.writeFieldName(field.getName()); serializers.defaultSerializeValue(reference.getObj(), gen); } } } gen.writeEndObject(); } catch (IntrospectionException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:jp.gr.java_conf.ka_ka_xyz.processor.JPA20AnnotationProcessor.java
private void registerMethodAnnotation(Field field, Class<?> clazz) { try {/*from w ww. j a v a 2 s. c om*/ String fieldName = field.getName(); PropertyDescriptor pd = new PropertyDescriptor(fieldName, clazz); Column column = pd.getReadMethod().getAnnotation(Column.class); String colName; if (column != null) { colName = column.name(); fieldColMap.put(fieldName, colName); } } catch (IntrospectionException e) { e.printStackTrace(); return; } }
From source file:org.dspace.app.rest.link.DSpaceResourceHalLinkFactory.java
protected void addLinks(DSpaceResource halResource, Pageable page, LinkedList<Link> list) throws Exception { RestAddressableModel data = halResource.getContent(); try {/* www . j av a2s .c o m*/ for (PropertyDescriptor pd : Introspector.getBeanInfo(data.getClass()).getPropertyDescriptors()) { Method readMethod = pd.getReadMethod(); String name = pd.getName(); if (readMethod != null && !"class".equals(name)) { LinkRest linkAnnotation = readMethod.getAnnotation(LinkRest.class); if (linkAnnotation != null) { if (StringUtils.isNotBlank(linkAnnotation.name())) { name = linkAnnotation.name(); } Link linkToSubResource = utils.linkToSubResource(data, name); // no method is specified to retrieve the linked object(s) so check if it is already here if (StringUtils.isBlank(linkAnnotation.method())) { Object linkedObject = readMethod.invoke(data); if (linkedObject instanceof RestAddressableModel && linkAnnotation.linkClass().isAssignableFrom(linkedObject.getClass())) { linkToSubResource = utils.linkToSingleResource((RestAddressableModel) linkedObject, name); } if (linkedObject != null || !linkAnnotation.optional()) { halResource.add(linkToSubResource); } } } else if (RestModel.class.isAssignableFrom(readMethod.getReturnType())) { Link linkToSubResource = utils.linkToSubResource(data, name); halResource.add(linkToSubResource); } } } } catch (IntrospectionException e) { e.printStackTrace(); } halResource.add(utils.linkToSingleResource(data, Link.REL_SELF)); }