Java Examples for java.beans.IntrospectionException
The following java examples will help you to understand the usage of java.beans.IntrospectionException. These source code samples are taken from different open source projects.
Example 1
Project: violetumleditor-master File: PropertyUtils.java View source code |
public static void copyProperties(Object fromBean, Object toBean) {
try {
BeanInfo info = Introspector.getBeanInfo(fromBean.getClass());
PropertyDescriptor[] descriptors = (PropertyDescriptor[]) info.getPropertyDescriptors().clone();
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor prop = descriptors[i];
Method getter = prop.getReadMethod();
Method setter = prop.getWriteMethod();
if (getter != null && setter != null) {
Object value = getter.invoke(fromBean, new Object[] {});
setter.invoke(toBean, new Object[] { value });
}
}
} catch (IntrospectionException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
Example 2
Project: cloud-sfsf-benefits-ext-master File: BeanDescriber.java View source code |
public List<String> getPropertyNames() throws IntrospectionException {
BeanInfo beanInfo = Introspector.getBeanInfo(beanObject.getClass(), beanObject.getClass().getSuperclass());
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
List<String> names = new ArrayList<>();
for (PropertyDescriptor propDescriptor : descriptors) {
names.add(propDescriptor.getName());
}
return names;
}
Example 3
Project: acs-master File: NodeUtils.java View source code |
/**
* creates an array of new GPNode objects without from the origNodes.
* Use this in case you need to "cut" the children below your nodes for some reason, e.g.
* because you want to display a list of children in a Tree
*
* @deprecated -- this should use a FilterNode
* @param origNodes the nodes with children that need to be cut off
* @return an array of new GPNode objects that refer to the same beans as the GPNodes passed as argument
*/
public static GPNode[] copyToNewGPNodeArray(GPNode[] origNodes) {
GPNode[] noChildenGPNodes = new GPNode[origNodes.length];
try {
for (int ix = 0; ix < origNodes.length; ix++) {
noChildenGPNodes[ix] = NodeFactory.createNode(origNodes[ix].getBean());
}
} catch (IntrospectionException ex) {
ex.printStackTrace();
return null;
}
return noChildenGPNodes;
}
Example 4
Project: iron-admin-master File: IronObjects.java View source code |
public static Stream<String> streamPropertyNames(Class<?> clazz) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException e) {
throw new AssertionError("Should not happen");
}
return Arrays.stream(beanInfo.getPropertyDescriptors()).map(FeatureDescriptor::getDisplayName).filter(( name) -> !name.equals("class"));
}
Example 5
Project: IsoMsgActionLib-master File: StoreTest.java View source code |
public void testBetwixWritingtOfByteArrays() throws IOException, SAXException, IntrospectionException {
Store store = new Store();
byte[] someByteArray = new byte[] { (byte) 0xA0, (byte) 0xB1, (byte) 0xC2, (byte) 0xFF };
store.setSomeByteArray(someByteArray);
byte[] secondByteArray = new byte[] { (byte) 0xA1, (byte) 0xB2, (byte) 0xC3 };
store.setSecondByteArray(secondByteArray);
BeanWriter beanWriter = new BeanWriter(System.out);
beanWriter.write(store);
}
Example 6
Project: TechnologyReadinessTool-master File: ReportLegendBeanInfo.java View source code |
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
List<PropertyDescriptor> descriptors = new ArrayList<>();
Method getter;
try {
getter = ReportLegend.class.getMethod("getCssClass");
Method setter = ReportLegend.class.getMethod("setCssClass", String.class);
descriptors.add(new PropertyDescriptor("class", getter, setter));
descriptors.add(new PropertyDescriptor("title", ReportLegend.class));
descriptors.add(new PropertyDescriptor("style", ReportLegend.class));
return descriptors.toArray(new PropertyDescriptor[descriptors.size()]);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (SecurityException e) {
throw new RuntimeException(e);
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
Example 7
Project: bbks-master File: BeanUtils.java View source code |
public Map<String, Object> describe(Object bean) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (bean == null) {
return (new HashMap<String, Object>());
}
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
Map<String, Object> description = new HashMap<String, Object>();
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
String name = descriptors[i].getName();
Method reader = descriptors[i].getReadMethod();
if (reader != null) {
Object value = reader.invoke(bean, null);
description.put(name, value);
}
}
description.remove("class");
return (description);
}
Example 8
Project: beanfabrics-master File: BnTableBeanInfo.java View source code |
public PropertyDescriptor[] getPropertyDescriptors() {
try {
final PropertyDescriptor pModel = new PropertyDescriptor("presentationModel", this.getBeanClass(), "getPresentationModel", "setPresentationModel");
final PropertyDescriptor provider = new PropertyDescriptor("modelProvider", beanClass, "getModelProvider", "setModelProvider");
provider.setPreferred(true);
final PropertyDescriptor path = new PropertyDescriptor("path", beanClass, "getPath", "setPath");
final PropertyDescriptor columns = new PropertyDescriptor("columns", beanClass, "getColumns", "setColumns");
columns.setBound(true);
columns.setPropertyEditorClass(BnColumnPropertyEditor.class);
path.setBound(true);
return new PropertyDescriptor[] { pModel, provider, path, columns };
} catch (IntrospectionException ex) {
ExceptionUtil.getInstance().handleException("", ex);
return new PropertyDescriptor[0];
}
}
Example 9
Project: Crawer-master File: BeanUtilsBean.java View source code |
public Map<String, Object> describe(Object bean) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (bean == null) {
return (new HashMap<String, Object>());
}
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
Map<String, Object> description = new HashMap<String, Object>();
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
String name = descriptors[i].getName();
Method reader = descriptors[i].getReadMethod();
if (reader != null) {
Object value = reader.invoke(bean, null);
description.put(name, value);
}
}
description.remove("class");
return (description);
}
Example 10
Project: Dead-Reckoning-Android-master File: HeaderColumnNameMappingStrategyTest.java View source code |
@Test
public void verifyColumnNames() throws IOException, IntrospectionException {
HeaderColumnNameMappingStrategy<MockBean> strat = new HeaderColumnNameMappingStrategy<MockBean>();
strat.setType(MockBean.class);
assertNull(strat.getColumnName(0));
assertNull(strat.findDescriptor(0));
StringReader reader = new StringReader(TEST_STRING);
CSVReader csvReader = new CSVReader(reader);
strat.captureHeader(csvReader);
assertEquals("name", strat.getColumnName(0));
assertEquals(strat.findDescriptor(0), strat.findDescriptor("name"));
assertTrue(strat.matches("name", strat.findDescriptor("name")));
}
Example 11
Project: dropwizard-views-thymeleaf-master File: DropWizardContext.java View source code |
private void initVariableFromViewProperties(View view) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
PropertyDescriptor[] propertyDescs = Introspector.getBeanInfo(view.getClass(), View.class).getPropertyDescriptors();
for (PropertyDescriptor desc : propertyDescs) {
String propName = desc.getDisplayName();
Method method = desc.getReadMethod();
setVariable(propName, method.invoke(view, new Object[0]));
}
}
Example 12
Project: FluentLenium-master File: FluentListSearchTest.java View source code |
@Before
public void before() throws IntrospectionException, NoSuchFieldException, IllegalAccessException {
webElements = new ArrayList<>();
fluentAdapter = new FluentAdapter();
fluentAdapter.initFluent(driver);
fluentWebElement = new FluentWebElement(webElement, fluentAdapter, new DefaultComponentInstantiator(fluentAdapter));
webElements.add(fluentWebElement);
Field field = fluentWebElement.getClass().getDeclaredField("search");
field.setAccessible(true);
field.set(fluentWebElement, search);
fluentList = fluentAdapter.newFluentList(webElements);
}
Example 13
Project: ha-jdbc-master File: CommonDataSourceDatabase.java View source code |
@Override
public Properties getProperties() {
Properties properties = new Properties();
Z dataSource = this.getConnectionSource();
try {
for (PropertyDescriptor descriptor : Introspector.getBeanInfo(dataSource.getClass()).getPropertyDescriptors()) {
Method method = descriptor.getReadMethod();
if ((method != null) && (descriptor.getWriteMethod() != null)) {
try {
Object value = method.invoke(dataSource);
if (value != null) {
PropertyEditor editor = PropertyEditorManager.findEditor(descriptor.getPropertyType());
if (editor != null) {
editor.setValue(value);
properties.setProperty(descriptor.getName(), editor.getAsText());
}
}
} catch (IllegalAccessExceptionInvocationTargetException | e) {
}
}
}
} catch (IntrospectionException e) {
throw new IllegalStateException(e);
}
return properties;
}
Example 14
Project: jdatechooser-master File: DateChooserDialogBeanInfo.java View source code |
/**
* Unique descriptors for DateChooserDialog.<br>
* Óíèêàëüíûå äåñêðèïòîðû ñâîéñòâ äëÿ DateChooserDialog.
* @return Unique descriptors for DateChooserDialog.<br>
* Óíèêàëüíûå äåñêðèïòîðû ñâîéñòâ äëÿ DateChooserDialog.
* @since 1.0
*/
public ArrayList<PropertyDescriptor> getAdditionalDescriptors() throws IntrospectionException {
ArrayList<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
PropertyDescriptor modal = new PropertyDescriptor(DateChooserDialog.PROPERTY_MODAL, getBeanClass(), "isModal", "setModal");
modal.setDisplayName(getCalendarLocaleString("Modal"));
modal.setShortDescription(getCalendarLocaleString("Modal_descript"));
descriptors.add(modal);
PropertyDescriptor caption = new PropertyDescriptor(DateChooserDialog.PROPERTY_CAPTION, getBeanClass(), "getCaption", "setCaption");
caption.setDisplayName(getCalendarLocaleString("Caption"));
caption.setShortDescription(getCalendarLocaleString("Caption_descript"));
descriptors.add(caption);
return descriptors;
}
Example 15
Project: jrunalyzer-master File: Injector.java View source code |
// poor man's @Inject ;-)
public static <T, S> T inject(final T instance, Class<S> clazz, S toInject) {
try {
for (PropertyDescriptor pd : Introspector.getBeanInfo(instance.getClass()).getPropertyDescriptors()) {
Method wm = pd.getWriteMethod();
if (wm != null && wm.isAnnotationPresent(Inject.class) && pd.getPropertyType().equals(clazz)) {
wm.invoke(instance, toInject);
}
}
} catch (IntrospectionException e) {
throw Throwables.propagate(e);
} catch (IllegalArgumentException e) {
throw Throwables.propagate(e);
} catch (IllegalAccessException e) {
throw Throwables.propagate(e);
} catch (InvocationTargetException e) {
throw Throwables.propagate(e);
}
return instance;
}
Example 16
Project: LabelGenerator-master File: BeanInfoUtil.java View source code |
/**
* Checks the given classes for transient attributes and updates the
* BeanInfo accordingly. This is used to prevent the BSAF LocalStorage to
* serialize the transient attributes.
*
* @param classes
*/
public static void markTransientAttributes(Class<?>... classes) {
for (final Class<?> tmpClazz : classes) {
try {
final BeanInfo info = Introspector.getBeanInfo(tmpClazz);
final PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; ++i) {
final PropertyDescriptor pd = propertyDescriptors[i];
if (pd.getReadMethod().isAnnotationPresent(Transient.class)) {
pd.setValue("transient", Boolean.TRUE);
LOGGER.log(Level.INFO, "Marked {0} as transient.", pd.getName());
}
}
} catch (IntrospectionException e) {
LOGGER.log(Level.SEVERE, "Introspection of bean class {0} failed", tmpClazz.getName());
}
}
}
Example 17
Project: liquibase-master File: FluentPropertyBeanIntrospector.java View source code |
@Override public void introspect(IntrospectionContext context) throws IntrospectionException { for (Method method : context.getTargetClass().getMethods()) { try { Class<?>[] argTypes = method.getParameterTypes(); int argCount = argTypes.length; if (argCount == 1 && method.getName().startsWith("set")) { String propertyName = Introspector.decapitalize(method.getName().substring(3)); if (!propertyName.equals("class")) { PropertyDescriptor pd = context.getDescriptor(propertyName); boolean setWriteMethod = false; if (pd == null) { pd = new PropertyDescriptor(propertyName, null, method); context.addDescriptor(pd); setWriteMethod = true; } else if (pd.getWriteMethod() == null && pd.getReadMethod() != null && pd.getReadMethod().getReturnType() == argTypes[0]) { pd.setWriteMethod(method); setWriteMethod = true; } if (setWriteMethod) { for (Class<?> type : method.getExceptionTypes()) { if (type == PropertyVetoException.class) { pd.setConstrained(true); break; } } } } } } catch (IntrospectionException ignored) { } } }
Example 18
Project: old-gosu-repo-master File: PropertyInfoFactory.java View source code |
public static IPropertyInfo make(IFeatureInfo container, String strName, Class javaClass, String strGetter, String strSetter, IType propertyType) throws IntrospectionException {
PropertyDescriptor property = new PropertyDescriptor(strName, javaClass, strGetter, strSetter);
BeanInfoUtil.makeScriptable(property);
return new JavaPropertyInfo(container, new PropertyDescriptorJavaPropertyDescriptor(property, propertyType.getTypeLoader().getModule()), propertyType);
}
Example 19
Project: OpenCSV-3.0-master File: CsvToBeanTest.java View source code |
private MappingStrategy createErrorMappingStrategy() {
return new MappingStrategy() {
public PropertyDescriptor findDescriptor(int col) throws IntrospectionException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Object createBean() throws InstantiationException, IllegalAccessException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public void captureHeader(CSVReader reader) throws IOException {
throw new IOException("This is the test exception");
}
};
}
Example 20
Project: openmap-master File: SimpleBeanContainerBeanInfo.java View source code |
public PropertyDescriptor[] getPropertyDescriptors() {
ArrayList<PropertyDescriptor> list = new ArrayList<PropertyDescriptor>(8);
PropertyDescriptor[] pds = super.getPropertyDescriptors();
list.addAll(Arrays.asList(pds));
try {
list.add(new PropertyDescriptor("widthInNM", SimpleBeanContainer.class));
list.add(new PropertyDescriptor("heightInNM", SimpleBeanContainer.class));
PropertyDescriptor pd = new PropertyDescriptor("layoutClass", SimpleBeanContainer.class);
pd.setPropertyEditorClass(LayoutClassEditor.class);
list.add(pd);
pd = new PropertyDescriptor("layoutManager", SimpleBeanContainer.class, "getLayout", "setLayout");
// since layoutManager property is itself a bean
// (of type BeanLayoutManager), use the
// general purpose BeanLayoutEditor class provided in the
// tools.beanbox
// package as the editor class of this bean property.
pd.setPropertyEditorClass(BeanLayoutEditor.class);
list.add(pd);
} catch (IntrospectionException e) {
e.printStackTrace();
}
return list.toArray(new PropertyDescriptor[list.size()]);
}
Example 21
Project: opentrader.github.com-master File: CsvToBeanTest.java View source code |
private MappingStrategy createErrorMappingStrategy() {
return new MappingStrategy() {
public PropertyDescriptor findDescriptor(int col) throws IntrospectionException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Object createBean() throws InstantiationException, IllegalAccessException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public void captureHeader(CSVReader reader) throws IOException {
throw new IOException("This is the test exception");
}
};
}
Example 22
Project: sad-analyzer-master File: CsvToBeanTest.java View source code |
private MappingStrategy createErrorMappingStrategy() {
return new MappingStrategy() {
public PropertyDescriptor findDescriptor(int col) throws IntrospectionException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Object createBean() throws InstantiationException, IllegalAccessException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public void captureHeader(CSVReader reader) throws IOException {
throw new IOException("This is the test exception");
}
};
}
Example 23
Project: sitebricks-master File: ConcurrentPropertyCache.java View source code |
public boolean exists(String property, Class<?> anObjectClass) {
Map<String, String> properties = cache.get(anObjectClass);
//cache bean properties if needed
if (null == properties) {
PropertyDescriptor[] propertyDescriptors;
try {
propertyDescriptors = Introspector.getBeanInfo(anObjectClass).getPropertyDescriptors();
} catch (IntrospectionException e) {
throw new IllegalArgumentException();
}
properties = new LinkedHashMap<String, String>();
for (PropertyDescriptor descriptor : propertyDescriptors) {
//apply labels here as needed
properties.put(descriptor.getName(), descriptor.getName());
}
cache.putIfAbsent(anObjectClass, properties);
}
return properties.containsKey(property);
}
Example 24
Project: snakeyaml-master File: MethodPropertyTest.java View source code |
public void testToString() throws IntrospectionException {
for (PropertyDescriptor property : Introspector.getBeanInfo(TestBean1.class).getPropertyDescriptors()) {
if (property.getName().equals("text")) {
MethodProperty prop = new MethodProperty(property);
assertEquals("text of class java.lang.String", prop.toString());
}
}
}
Example 25
Project: stocks-master File: PropertyEditingSupport.java View source code |
private PropertyDescriptor descriptorFor(Class<?> subjectType, String attributeName) {
try {
PropertyDescriptor[] properties = Introspector.getBeanInfo(subjectType).getPropertyDescriptors();
for (PropertyDescriptor p : properties) if (attributeName.equals(p.getName()))
return p;
throw new RuntimeException(String.format("%s has no property named %s", //$NON-NLS-1$
subjectType.getName(), attributeName));
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
Example 26
Project: swingx-master File: EquivalentMatcher.java View source code |
@Override
public boolean matches(Object argument) {
if (equalTo(object).matches(argument)) {
//short circuit: equal is always equivalent
return true;
}
if (argument != null && object.getClass() == argument.getClass()) {
BeanInfo beanInfo = null;
try {
beanInfo = Introspector.getBeanInfo(object.getClass());
} catch (IntrospectionException shouldNeverHappen) {
throw new Error(shouldNeverHappen);
}
for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
if (pd.getReadMethod() == null) {
continue;
}
Object value1 = null;
try {
value1 = pd.getReadMethod().invoke(object);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
new Error(e);
}
Object value2 = null;
try {
value2 = pd.getReadMethod().invoke(object);
} catch (RuntimeException e) {
throw e;
} catch (Exception shouldNeverHappen) {
new Error(shouldNeverHappen);
}
if (!equalTo(value1).matches(value2)) {
return false;
}
}
return true;
}
return false;
}
Example 27
Project: testCmpe131-master File: CsvToBeanTest.java View source code |
private MappingStrategy createErrorMappingStrategy() {
return new MappingStrategy() {
public PropertyDescriptor findDescriptor(int col) throws IntrospectionException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Object createBean() throws InstantiationException, IllegalAccessException {
//To change body of implemented methods use File | Settings | File Templates.
return null;
}
public void captureHeader(CSVReader reader) throws IOException {
throw new IOException("This is the test exception");
}
};
}
Example 28
Project: ubc_viscog-master File: MethodPropertyTest.java View source code |
public void testToString() throws IntrospectionException {
for (PropertyDescriptor property : Introspector.getBeanInfo(TestBean1.class).getPropertyDescriptors()) {
if (property.getName().equals("text")) {
MethodProperty prop = new MethodProperty(property);
assertEquals("text of class java.lang.String", prop.toString());
}
}
}
Example 29
Project: CodenameOne-master File: JCollapsiblePaneBeanInfo.java View source code |
/** * Gets the Property Descriptors * * @return The propertyDescriptors value */ public PropertyDescriptor[] getPropertyDescriptors() { try { Vector descriptors = new Vector(); PropertyDescriptor descriptor = null; try { descriptor = new PropertyDescriptor("animated", com.l2fprod.common.swing.JCollapsiblePane.class); } catch (IntrospectionException e) { descriptor = new PropertyDescriptor("animated", com.l2fprod.common.swing.JCollapsiblePane.class, "getAnimated", null); } descriptor.setPreferred(true); descriptor.setBound(true); descriptors.add(descriptor); try { descriptor = new PropertyDescriptor("collapsed", com.l2fprod.common.swing.JCollapsiblePane.class); } catch (IntrospectionException e) { descriptor = new PropertyDescriptor("collapsed", com.l2fprod.common.swing.JCollapsiblePane.class, "getCollapsed", null); } descriptor.setPreferred(true); descriptor.setBound(true); descriptors.add(descriptor); return (PropertyDescriptor[]) descriptors.toArray(new PropertyDescriptor[descriptors.size()]); } catch (Exception e) { e.printStackTrace(); } return null; }
Example 30
Project: jeboorker-master File: JFontChooserBeanInfo.java View source code |
/**
* Gets the Property Descriptors
*
* @return The propertyDescriptors value
*/
public PropertyDescriptor[] getPropertyDescriptors() {
try {
Vector descriptors = new Vector();
PropertyDescriptor descriptor = null;
try {
descriptor = new PropertyDescriptor("selectedFont", com.l2fprod.common.swing.JFontChooser.class);
} catch (IntrospectionException e) {
descriptor = new PropertyDescriptor("selectedFont", com.l2fprod.common.swing.JFontChooser.class, "getSelectedFont", null);
}
descriptor.setShortDescription("The current font the chooser is to display");
descriptor.setPreferred(true);
descriptor.setBound(true);
descriptors.add(descriptor);
return (PropertyDescriptor[]) descriptors.toArray(new PropertyDescriptor[descriptors.size()]);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Example 31
Project: ajah-master File: ReflectionUtilsTest.java View source code |
/**
* Test operations in ReflectionUtils
*/
@Test
public void testReflection() {
try {
final Class<?> clazz = Class.forName(ReflectionUtilsTest.class.getName());
final BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
final PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
for (final PropertyDescriptor prop : props) {
Assert.assertNotNull(ReflectionUtils.propGetSafe(new ReflectionUtilsTest(), prop));
}
} catch (final ClassNotFoundException e) {
e.printStackTrace();
} catch (final IntrospectionException e) {
e.printStackTrace();
}
}
Example 32
Project: alien4cloud-master File: ElasticSearchMapper.java View source code |
public static ElasticSearchMapper getInstance() {
ElasticSearchMapper elasticSearchMapper = new ElasticSearchMapper();
SimpleModule module = new SimpleModule("PropDeser", new Version(1, 0, 0, null, null, null));
try {
module.addDeserializer(PropertyConstraint.class, new PropertyConstraintDeserializer());
} catch (ClassNotFoundExceptionIOException | IntrospectionException | e) {
log.warn("The property constraint deserialialisation failed");
}
elasticSearchMapper.registerModule(module);
return elasticSearchMapper;
}
Example 33
Project: arquillian-cube-master File: CustomAwaitStrategyInstantiator.java View source code |
@Override
public boolean await() {
String className = this.params.getStrategy();
try {
Class<? extends AwaitStrategy> customStrategy = (Class<? extends AwaitStrategy>) Class.forName(className);
AwaitStrategy customStrategyInstance = customStrategy.newInstance();
// Inject if there is a field of type Cuube, DockerClientExecutor or Await.
final Field[] fields = customStrategyInstance.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getType().isAssignableFrom(Cube.class)) {
field.setAccessible(true);
field.set(customStrategyInstance, this.cube);
} else {
if (field.getType().isAssignableFrom(DockerClientExecutor.class)) {
field.setAccessible(true);
field.set(customStrategyInstance, this.dockerClientExecutor);
} else {
if (field.getType().isAssignableFrom(Await.class)) {
field.setAccessible(true);
field.set(customStrategyInstance, this.params);
}
}
}
}
// Inject if there is a setter for Cube, DockerClientExecutor or Await
for (PropertyDescriptor propertyDescriptor : Introspector.getBeanInfo(customStrategyInstance.getClass()).getPropertyDescriptors()) {
final Method writeMethod = propertyDescriptor.getWriteMethod();
if (writeMethod != null) {
if (writeMethod.getParameterTypes()[0].isAssignableFrom(Cube.class)) {
writeMethod.invoke(customStrategyInstance, this.cube);
} else {
if (writeMethod.getParameterTypes()[0].isAssignableFrom(DockerClientExecutor.class)) {
writeMethod.invoke(customStrategyInstance, this.dockerClientExecutor);
} else {
if (writeMethod.getParameterTypes()[0].isAssignableFrom(Await.class)) {
writeMethod.invoke(customStrategyInstance, this.params);
}
}
}
}
}
// Finally we call the await method
return customStrategyInstance.await();
} catch (ClassNotFoundExceptionInstantiationException | IllegalAccessException | IntrospectionException | InvocationTargetException | e) {
throw new IllegalArgumentException(e);
}
}
Example 34
Project: bboss-master File: TestBean.java View source code |
public static void main(String[] args) throws IntrospectionException {
ClassInfo beanInfo_ = ClassUtil.getClassInfo(TestBean.class);
Field[] fields = beanInfo_.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
Class ptype = f.getType();
String name = f.getName();
try {
Object value = f.get(new TestBean());
System.out.println();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
Example 35
Project: beanlib-master File: BeanDebugger.java View source code |
/** Singleton instance. */
// private static final boolean debug = false;
// private final Log log = LogFactory.getLog(this.getClass());
/** Logs at debug level all readable properties of the given bean. */
public void debugBeanProperties(Object bean, Logger log) {
if (log.isDebugEnabled())
log.debug("Reading bean properties for class " + bean.getClass());
try {
BeanInfo bi = Introspector.getBeanInfo(bean.getClass());
PropertyDescriptor[] pda = bi.getPropertyDescriptors();
for (int i = pda.length - 1; i > -1; i--) {
PropertyDescriptor pd = pda[i];
Method m = pd.getReadMethod();
if (m != null) {
if (log.isDebugEnabled())
log.debug(pd.getName() + "={" + m.invoke(bean) + "}");
}
}
} catch (IntrospectionException e) {
log.error(e);
} catch (IllegalAccessException e) {
log.error(e);
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
}
}
Example 36
Project: bigtable-sql-master File: PluginInfoBeanInfo.java View source code |
/**
* See http://tinyurl.com/63no6t for discussion of the proper thread-safe way to implement
* getPropertyDescriptors().
*
* @see java.beans.SimpleBeanInfo#getPropertyDescriptors()
*/
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor[] s_descr = new PropertyDescriptor[8];
s_descr[0] = new PropertyDescriptor(IPropNames.PLUGIN_CLASS_NAME, PluginInfo.class, "getPluginClassName", null);
s_descr[1] = new PropertyDescriptor(IPropNames.IS_LOADED, PluginInfo.class, "isLoaded", null);
s_descr[2] = new PropertyDescriptor(IPropNames.INTERNAL_NAME, PluginInfo.class, "getInternalName", null);
s_descr[3] = new PropertyDescriptor(IPropNames.DESCRIPTIVE_NAME, PluginInfo.class, "getDescriptiveName", null);
s_descr[4] = new PropertyDescriptor(IPropNames.AUTHOR, PluginInfo.class, "getAuthor", null);
s_descr[5] = new PropertyDescriptor(IPropNames.CONTRIBUTORS, PluginInfo.class, "getContributors", null);
s_descr[6] = new PropertyDescriptor(IPropNames.WEB_SITE, PluginInfo.class, "getWebSite", null);
s_descr[7] = new PropertyDescriptor(IPropNames.VERSION, PluginInfo.class, "getVersion", null);
return s_descr;
} catch (IntrospectionException e) {
throw new Error(e);
}
}
Example 37
Project: breeze.server.java-master File: TypeFns.java View source code |
/**
* Finds a PropertyDescriptor for the given propertyName on the Class
* @param clazz
* @param propertyName
* @return
* @throws RuntimeException if property is not found
*/
public static PropertyDescriptor findPropertyDescriptor(Class clazz, String propertyName) {
try {
BeanInfo binfo = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] propDescs = binfo.getPropertyDescriptors();
for (PropertyDescriptor d : propDescs) {
if (d.getName().equals(propertyName)) {
return d;
}
}
} catch (IntrospectionException e) {
throw new RuntimeException("Error finding property " + propertyName + " on " + clazz, e);
}
throw new RuntimeException("Property " + propertyName + " not found on " + clazz);
}
Example 38
Project: citrus-master File: RewriteSubstitutionBeanInfo.java View source code |
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
List<PropertyDescriptor> descriptors;
try {
descriptors = createLinkedList(Introspector.getBeanInfo(RewriteSubstitution.class.getSuperclass()).getPropertyDescriptors());
descriptors.add(new PropertyDescriptor("uri", RewriteSubstitution.class, null, "setUri"));
descriptors.add(new PropertyDescriptor("flags", RewriteSubstitution.class, null, "setFlags"));
descriptors.add(new PropertyDescriptor("parameters", RewriteSubstitution.class, null, "setParameters"));
} catch (IntrospectionException e) {
return super.getPropertyDescriptors();
}
return descriptors.toArray(new PropertyDescriptor[descriptors.size()]);
}
Example 39
Project: components-master File: FacesServiceBase.java View source code |
protected void fillParameters(BaseFacesObjectDescriptor<T> descriptor, T component) {
// get bean attributes for converter, put them into parameters.
try {
BeanInfo beanInfo = Introspector.getBeanInfo(component.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String name = propertyDescriptor.getName();
if (!HIDDEN_PROPERTIES.contains(name)) {
try {
final Method readMethod = propertyDescriptor.getReadMethod();
if (readMethod == null) {
continue;
}
Object value = readMethod.invoke(component);
if (null != value) {
descriptor.addParameter(name, value);
}
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
}
} catch (IntrospectionException e) {
}
}
Example 40
Project: drools-chance-master File: ChanceEnumBuilderImpl.java View source code |
public byte[] buildClass(ClassDefinition classDef) throws IOException, IntrospectionException, SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
if (classDef.getAnnotations() != null) {
for (AnnotationDefinition ad : classDef.getAnnotations()) {
if (ad.getName().equals(LinguisticPartition.class.getName())) {
classDef.setInterfaces(new String[] { BuildUtils.getInternalType(Linguistic.class.getName()) });
}
}
}
return super.buildClass(classDef);
}
Example 41
Project: dropwizardry-master File: DropwizardEnvironmentModule.java View source code |
@SuppressWarnings("unchecked")
private void initConfigurationBindings() {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(configurationClass);
PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
Object current = configuration;
for (PropertyDescriptor prop : props) {
Method readMethod = prop.getReadMethod();
if (readMethod.getParameterTypes().length == 0) {
try {
Object value = readMethod.invoke(current);
//TODO: add support for binding generic types too!
if (value.getClass().getGenericInterfaces().length > 0) {
log.warn("Binding of generic types is not supported yet. Will not bind {}", value.getClass());
continue;
}
bind((Class<Object>) value.getClass()).annotatedWith(Names.named(prop.getName())).toInstance(value);
log.debug("Binding {} annotated with \"{}\"", value.getClass(), prop.getName());
} catch (IllegalAccessExceptionIllegalArgumentException | InvocationTargetException | e) {
log.error("Unable to bind '{}' due to readMethod invoke error", prop.getName(), e);
}
}
}
} catch (IntrospectionException e) {
log.error("Unable to introspect bean info for {}. I will try to continue without binding configurations", configurationClass);
}
}
Example 42
Project: fabric8-master File: ViewPipeline.java View source code |
public static void main(String[] args) {
if (args.length == 0) {
System.err.println("Usage: ViewPipeline jobName [branchName] [gitUrl]");
return;
}
String jobName = args[0];
String branchName = "master";
String gitUrl = null;
if (args.length > 1) {
branchName = args[1];
}
if (args.length > 2) {
gitUrl = args[2];
}
try {
JobEnvironment environment = new JobEnvironment();
environment.setJobName(jobName);
environment.setBranchName(branchName);
environment.setGitUrl(gitUrl);
KubernetesClient kubernetesClient = new DefaultKubernetesClient();
String namespace = kubernetesClient.getNamespace();
if (Strings.isNullOrBlank(namespace)) {
namespace = KubernetesHelper.defaultNamespace();
}
Pipeline pipeline = Pipelines.getPipeline(kubernetesClient, namespace, environment);
System.out.println("Found pipeline for job: " + pipeline.getJobName() + " of kind: " + pipeline.getKind());
} catch (IntrospectionException e) {
System.out.println("Failed with: " + e);
e.printStackTrace();
}
}
Example 43
Project: featurehouse_fstcomp_examples-master File: ClassNodeBeanInfo.java View source code |
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor nameDescriptor = new PropertyDescriptor("name", ClassNode.class);
nameDescriptor.setValue("priority", new Integer(1));
PropertyDescriptor attributesDescriptor = new PropertyDescriptor("attributes", ClassNode.class);
attributesDescriptor.setValue("priority", new Integer(2));
PropertyDescriptor methodsDescriptor = new PropertyDescriptor("methods", ClassNode.class);
methodsDescriptor.setValue("priority", new Integer(3));
return new PropertyDescriptor[] { nameDescriptor, attributesDescriptor, methodsDescriptor };
} catch (IntrospectionException exception) {
return null;
}
}
Example 44
Project: floodlightUI-master File: OFVendorActionFactoriesTest.java View source code |
public void assertBeansEqual(Object expected, Object actual) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(expected.getClass());
for (PropertyDescriptor propertyDesc : beanInfo.getPropertyDescriptors()) {
Object srcValue = propertyDesc.getReadMethod().invoke(expected);
Object dstValue = propertyDesc.getReadMethod().invoke(actual);
assertEquals("Bean Value: " + propertyDesc.getName() + " expected: " + srcValue + " != actual: " + dstValue, srcValue, dstValue);
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Example 45
Project: floodlight_with_topoguard-master File: OFVendorActionFactoriesTest.java View source code |
public void assertBeansEqual(Object expected, Object actual) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(expected.getClass());
for (PropertyDescriptor propertyDesc : beanInfo.getPropertyDescriptors()) {
Object srcValue = propertyDesc.getReadMethod().invoke(expected);
Object dstValue = propertyDesc.getReadMethod().invoke(actual);
assertEquals("Bean Value: " + propertyDesc.getName() + " expected: " + srcValue + " != actual: " + dstValue, srcValue, dstValue);
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Example 46
Project: formio-master File: AnyNotEmptyValidator.java View source code |
/** * Returns getter for appropriate bean class. * * @param beanClass * @param property * @return * @throws IntrospectionException */ private Method getReadMethod(Class<?> beanClass, String property) throws IntrospectionException { BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { if (pd.getName().equals(property) && pd.getReadMethod() != null) { return pd.getReadMethod(); } } throw new IllegalArgumentException("No getter available for property '" + property + "' in '" + beanClass + "'."); }
Example 47
Project: Foundry-master File: DistributionParameterUtil.java View source code |
/** * Finds all the DistributionParameters from a given Distribution. * @param <ConditionalType> * Type of parameterized distribution that generates observations. * @param distribution * Distribution from which to pull the DistributionParameters. * @return * Collection of all DistributionParameters in the Distribution. * @throws IntrospectionException * If the system could not perform introspection on the Distribution. */ static <ConditionalType extends ClosedFormDistribution<?>> Collection<DistributionParameter<?, ConditionalType>> findAll(final ConditionalType distribution) throws IntrospectionException { BeanInfo beaninfo = Introspector.getBeanInfo(distribution.getClass()); ArrayList<DistributionParameter<?, ConditionalType>> parameters = new ArrayList<DistributionParameter<?, ConditionalType>>(beaninfo.getPropertyDescriptors().length); for (PropertyDescriptor property : beaninfo.getPropertyDescriptors()) { if ((property.getReadMethod() != null) && (property.getWriteMethod() != null)) { parameters.add(new DefaultDistributionParameter<Object, ConditionalType>(distribution, property)); } else if (property.getName().equals(DefaultDistributionParameter.MEAN_NAME) && (property.getReadMethod() != null)) { // Look for a setMean method... for (MethodDescriptor method : beaninfo.getMethodDescriptors()) { if (method.getDisplayName().contains(DefaultDistributionParameter.MEAN_SETTER)) { parameters.add(new DefaultDistributionParameter<Object, ConditionalType>(distribution, property.getName())); break; } } } } return parameters; }
Example 48
Project: FoxyDocs-master File: Utils.java View source code |
private static PropertyDescriptor getPropertyDescriptor(Class<?> beanClass, String propertyName) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(beanClass);
} catch (IntrospectionException e) {
return null;
}
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
if (descriptor.getName().equals(propertyName)) {
return descriptor;
}
}
throw new BindingException(MessageFormat.format("Could not find property with name {0} in class {1}", propertyName, beanClass));
}
Example 49
Project: freemarker-old-master File: GetlessMethodsAsPropertyGettersRule.java View source code |
/** This only exists as the tests need to call this through the deprecated method too. */
public void legacyProcess(Class clazz, Method m, MethodAppearanceDecision decision) {
if (m.getDeclaringClass() != Object.class && m.getReturnType() != void.class && m.getParameterTypes().length == 0) {
String mName = m.getName();
if (!looksLikePropertyReadMethod(mName)) {
decision.setExposeMethodAs(null);
try {
decision.setExposeAsProperty(new PropertyDescriptor(mName, clazz, mName, null));
} catch (// Won't happen...
IntrospectionException // Won't happen...
e) {
throw new RuntimeException(e);
}
}
}
}
Example 50
Project: geotools-2.7.x-master File: PolygonPolygonAbstractValidationBeanInfo.java View source code |
/**
* Implementation of getPropertyDescriptors.
*
*
* @see java.beans.BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
PropertyDescriptor[] pd2 = super.getPropertyDescriptors();
ResourceBundle resourceBundle = getResourceBundle(PolygonPolygonAbstractValidation.class);
if (pd2 == null) {
pd2 = new PropertyDescriptor[0];
}
PropertyDescriptor[] pd = new PropertyDescriptor[pd2.length + 2];
int i = 0;
for (; i < pd2.length; i++) pd[i] = pd2[i];
try {
pd[i] = createPropertyDescriptor("polygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i].setExpert(false);
pd[i + 1] = createPropertyDescriptor("restrictedPolygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i + 1].setExpert(false);
} catch (IntrospectionException e) {
pd = pd2;
e.printStackTrace();
}
return pd;
}
Example 51
Project: geotools-master File: PolygonPolygonAbstractValidationBeanInfo.java View source code |
/**
* Implementation of getPropertyDescriptors.
*
*
* @see java.beans.BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
PropertyDescriptor[] pd2 = super.getPropertyDescriptors();
ResourceBundle resourceBundle = getResourceBundle(PolygonPolygonAbstractValidation.class);
if (pd2 == null) {
pd2 = new PropertyDescriptor[0];
}
PropertyDescriptor[] pd = new PropertyDescriptor[pd2.length + 2];
int i = 0;
for (; i < pd2.length; i++) pd[i] = pd2[i];
try {
pd[i] = createPropertyDescriptor("polygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i].setExpert(false);
pd[i + 1] = createPropertyDescriptor("restrictedPolygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i + 1].setExpert(false);
} catch (IntrospectionException e) {
pd = pd2;
e.printStackTrace();
}
return pd;
}
Example 52
Project: geotools-old-master File: PolygonPolygonAbstractValidationBeanInfo.java View source code |
/**
* Implementation of getPropertyDescriptors.
*
*
* @see java.beans.BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
PropertyDescriptor[] pd2 = super.getPropertyDescriptors();
ResourceBundle resourceBundle = getResourceBundle(PolygonPolygonAbstractValidation.class);
if (pd2 == null) {
pd2 = new PropertyDescriptor[0];
}
PropertyDescriptor[] pd = new PropertyDescriptor[pd2.length + 2];
int i = 0;
for (; i < pd2.length; i++) pd[i] = pd2[i];
try {
pd[i] = createPropertyDescriptor("polygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i].setExpert(false);
pd[i + 1] = createPropertyDescriptor("restrictedPolygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i + 1].setExpert(false);
} catch (IntrospectionException e) {
pd = pd2;
e.printStackTrace();
}
return pd;
}
Example 53
Project: geotools-tike-master File: PolygonPolygonAbstractValidationBeanInfo.java View source code |
/**
* Implementation of getPropertyDescriptors.
*
*
* @see java.beans.BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
PropertyDescriptor[] pd2 = super.getPropertyDescriptors();
ResourceBundle resourceBundle = getResourceBundle(PolygonPolygonAbstractValidation.class);
if (pd2 == null) {
pd2 = new PropertyDescriptor[0];
}
PropertyDescriptor[] pd = new PropertyDescriptor[pd2.length + 2];
int i = 0;
for (; i < pd2.length; i++) pd[i] = pd2[i];
try {
pd[i] = createPropertyDescriptor("polygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i].setExpert(false);
pd[i + 1] = createPropertyDescriptor("restrictedPolygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i + 1].setExpert(false);
} catch (IntrospectionException e) {
pd = pd2;
e.printStackTrace();
}
return pd;
}
Example 54
Project: geotools_trunk-master File: PolygonPolygonAbstractValidationBeanInfo.java View source code |
/**
* Implementation of getPropertyDescriptors.
*
*
* @see java.beans.BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
PropertyDescriptor[] pd2 = super.getPropertyDescriptors();
ResourceBundle resourceBundle = getResourceBundle(PolygonPolygonAbstractValidation.class);
if (pd2 == null) {
pd2 = new PropertyDescriptor[0];
}
PropertyDescriptor[] pd = new PropertyDescriptor[pd2.length + 2];
int i = 0;
for (; i < pd2.length; i++) pd[i] = pd2[i];
try {
pd[i] = createPropertyDescriptor("polygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i].setExpert(false);
pd[i + 1] = createPropertyDescriptor("restrictedPolygonTypeRef", PolygonPolygonAbstractValidation.class, resourceBundle);
pd[i + 1].setExpert(false);
} catch (IntrospectionException e) {
pd = pd2;
e.printStackTrace();
}
return pd;
}
Example 55
Project: hector-master File: KeyDefinition.java View source code |
public void setPkClass(Class<?> pkClazz) {
this.pkClazz = pkClazz;
if (null == this.pkClazz) {
throw new IllegalArgumentException("Primary Key Class cannot be null");
}
PropertyDescriptor[] pdArr;
try {
pdArr = Introspector.getBeanInfo(pkClazz, Object.class).getPropertyDescriptors();
} catch (IntrospectionException e) {
throw new HectorObjectMapperException(e);
}
propertyDescriptorMap = new LinkedHashMap<String, PropertyDescriptor>();
for (PropertyDescriptor pd : pdArr) {
propertyDescriptorMap.put(pd.getName(), pd);
}
}
Example 56
Project: infinispan-master File: ReflectionPropertyHelper.java View source code |
@Override
public boolean isRepeatedProperty(Class<?> entityType, String[] propertyPath) {
try {
ReflectionHelper.PropertyAccessor a = ReflectionHelper.getAccessor(entityType, propertyPath[0]);
if (a.isMultiple()) {
return true;
}
for (int i = 1; i < propertyPath.length; i++) {
a = a.getAccessor(propertyPath[i]);
if (a.isMultiple()) {
return true;
}
}
} catch (IntrospectionException e) {
}
return false;
}
Example 57
Project: javablog-master File: CofigIntro.java View source code |
@Test
public void getAllProperty() throws IntrospectionException {
//Introspector 内�类
BeanInfo beanInfo = Introspector.getBeanInfo(Person.class);
//通过BeanInfo获å?–所有的属性æ??è¿°
//获å?–一个类ä¸çš„所有属性æ??述器
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor p : descriptors) {
//获得所有get方法
//get方法
System.out.println(p.getReadMethod());
}
}
Example 58
Project: jbosstools-base-master File: TestSuiteWithParams.java View source code |
@Override
public void runTest(Test test, TestResult result) {
for (Object property : parameters.keySet()) {
String propertyName = property.toString();
try {
PropertyDescriptor propertyDescr = new PropertyDescriptor(propertyName, test.getClass());
Statement setPropertyStatement = new Statement(test, propertyDescr.getWriteMethod().getName(), new Object[] { parameters.get(property) });
setPropertyStatement.execute();
} catch (IntrospectionException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
super.runTest(test, result);
}
Example 59
Project: jCAE-master File: BeanProperty.java View source code |
private static Class getClass(Object bean, String property) throws IntrospectionException {
PropertyDescriptor[] pd = Introspector.getBeanInfo(bean.getClass()).getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(property)) {
if (pd[i].getReadMethod() != null)
return pd[i].getReadMethod().getReturnType();
else
return pd[i].getWriteMethod().getParameterTypes()[0];
}
}
return String.class;
}
Example 60
Project: jmxterm-master File: HelpCommandTest.java View source code |
/** * Test execution with several options * * @throws IOException * @throws IntrospectionException */ @Test public void testExecuteWithOption() throws IOException, IntrospectionException { command.setArgNames(Arrays.asList("a", "b")); final CommandCenter cc = context.mock(CommandCenter.class); command.setCommandCenter(cc); context.checking(new Expectations() { { one(cc).getCommandType("a"); will(returnValue(SelfRecordingCommand.class)); one(cc).getCommandType("b"); will(returnValue(SelfRecordingCommand.class)); } }); command.setSession(new MockSession(output, null)); command.execute(); context.assertIsSatisfied(); }
Example 61
Project: lzusdn-master File: OFVendorActionFactoriesTest.java View source code |
public void assertBeansEqual(Object expected, Object actual) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(expected.getClass());
for (PropertyDescriptor propertyDesc : beanInfo.getPropertyDescriptors()) {
Object srcValue = propertyDesc.getReadMethod().invoke(expected);
Object dstValue = propertyDesc.getReadMethod().invoke(actual);
assertEquals("Bean Value: " + propertyDesc.getName() + " expected: " + srcValue + " != actual: " + dstValue, srcValue, dstValue);
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Example 62
Project: ManagedRuntimeInitiative-master File: Test6277246.java View source code |
public static void main(String[] args) throws IntrospectionException {
Class type = BASE64Encoder.class;
System.setSecurityManager(new SecurityManager());
BeanInfo info = Introspector.getBeanInfo(type);
for (MethodDescriptor md : info.getMethodDescriptors()) {
Method method = md.getMethod();
System.out.println(method);
String name = method.getDeclaringClass().getName();
if (name.startsWith("sun.misc.")) {
throw new Error("found inaccessible method");
}
}
}
Example 63
Project: mapsforge-platform-master File: TrackSegmentNodeFactory.java View source code |
@Override
protected Node createNodeForKey(Trkseg trkseg) {
Node node = null;
try {
node = new TrkSegNode(trkseg, trkseg.getTrkpt() == null || trkseg.getTrkpt().isEmpty() ? Children.LEAF : Children.create(new TrkpointNodeFactory(trkseg.getTrkpt()), true));
} catch (IntrospectionException ex) {
Exceptions.printStackTrace(ex);
}
return node;
}
Example 64
Project: Mecasoft-master File: Utils.java View source code |
private static PropertyDescriptor getPropertyDescriptor(Class<?> beanClass, String propertyName) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(beanClass);
} catch (IntrospectionException e) {
return null;
}
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
if (descriptor.getName().equals(propertyName)) {
return descriptor;
}
}
throw new BindingException(MessageFormat.format("Could not find property with name {0} in class {1}", propertyName, beanClass));
}
Example 65
Project: modellipse-master File: CellEditorHelper.java View source code |
public Class<?> getTargetType() {
ISelection selection = this.tableViewer.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object element = structuredSelection.getFirstElement();
Object property = this.tableViewer.getColumnProperties()[index];
String propertyName = property.toString();
try {
BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(element.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
if (propertyDescriptor.getName().equalsIgnoreCase(propertyName)) {
return propertyDescriptor.getPropertyType();
}
}
} catch (IntrospectionException e) {
throw new XWTException(e);
}
}
return null;
}
Example 66
Project: muikku-master File: SearchIndexer.java View source code |
public void index(String name, Object entity, Map<String, Object> extraProperties) {
Iterator<SearchIndexUpdater> updaters = searchIndexUpdaters.iterator();
while (updaters.hasNext()) {
SearchIndexUpdater updater = updaters.next();
try {
Map<String, Object> indexEntity = indexEntityProcessor.process(entity);
if (indexEntity != null) {
if (extraProperties != null) {
for (String key : extraProperties.keySet()) {
Object value = extraProperties.get(key);
indexEntity.put(key, value);
}
}
updater.addOrUpdateIndex(name, indexEntity);
}
} catch (IllegalArgumentExceptionIllegalAccessException | SecurityException | InvocationTargetException | IntrospectionException | IndexIdMissingException | e) {
logger.log(Level.WARNING, "Entity processing exception", e);
}
}
}
Example 67
Project: ontopia-master File: ListTagBeanInfo.java View source code |
public PropertyDescriptor[] getPropertyDescriptors() {
List proplist = new ArrayList();
try {
proplist.add(new PropertyDescriptor("id", ListTag.class, null, "setId"));
proplist.add(new PropertyDescriptor("readonly", ListTag.class, null, "setReadonly"));
proplist.add(new PropertyDescriptor("class", ListTag.class, null, "setClass"));
proplist.add(new PropertyDescriptor("action", ListTag.class, null, "setAction"));
proplist.add(new PropertyDescriptor("params", ListTag.class, null, "setParams"));
proplist.add(new PropertyDescriptor("collection", ListTag.class, null, "setCollection"));
proplist.add(new PropertyDescriptor("selected", ListTag.class, null, "setSelected"));
proplist.add(new PropertyDescriptor("unspecified", ListTag.class, null, "setUnspecified"));
proplist.add(new PropertyDescriptor("type", ListTag.class, null, "setType"));
} catch (IntrospectionException ex) {
}
PropertyDescriptor[] result = new PropertyDescriptor[proplist.size()];
return ((PropertyDescriptor[]) proplist.toArray(result));
}
Example 68
Project: pentaho-reporting-master File: SharedBeanInfo.java View source code |
public BeanInfo getBeanInfo() {
if (beanInfo == null) {
this.propertyDescriptors = new HashMap<String, PropertyDescriptor>();
try {
beanInfo = Introspector.getBeanInfo(beanClass);
final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
final PropertyDescriptor descriptor = descriptors[i];
propertyDescriptors.put(descriptor.getName(), descriptor);
}
} catch (IntrospectionException e) {
throw new IllegalStateException("Cannot introspect specified " + beanClass);
}
}
return beanInfo;
}
Example 69
Project: shifu-master File: HDFSUtilsTest.java View source code |
@Test
public void test() throws IOException, IntrospectionException {
File tmp = new File("tmp");
if (!tmp.exists()) {
FileUtils.forceMkdir(tmp);
}
// HDFSUtils utils = null;
//utils = new HDFSUtils();
//utils.deleteFolder("tmp");
HDFSUtils.getLocalFS().delete(new Path("tmp"), true);
Assert.assertTrue(!tmp.exists());
}
Example 70
Project: shopizer-master File: BeanUtils.java View source code |
@SuppressWarnings("nls")
public Object getPropertyValue(Object bean, String property) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
if (bean == null) {
throw new IllegalArgumentException("No bean specified");
}
if (property == null) {
throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
}
Class<?> beanClass = bean.getClass();
PropertyDescriptor propertyDescriptor = getPropertyDescriptor(beanClass, property);
if (propertyDescriptor == null) {
throw new IllegalArgumentException("No such property " + property + " for " + beanClass + " exists");
}
Method readMethod = propertyDescriptor.getReadMethod();
if (readMethod == null) {
throw new IllegalStateException("No getter available for property " + property + " on " + beanClass);
}
return readMethod.invoke(bean);
}
Example 71
Project: shr5rcp-master File: Utils.java View source code |
private static PropertyDescriptor getPropertyDescriptor(Class<?> beanClass, String propertyName) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(beanClass);
} catch (IntrospectionException e) {
return null;
}
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
if (descriptor.getName().equals(propertyName)) {
return descriptor;
}
}
throw new BindingException(MessageFormat.format("Could not find property with name {0} in class {1}", propertyName, beanClass));
}
Example 72
Project: SMEdit-master File: TestBeans.java View source code |
public static void main(String[] argv) {
try {
Object bean = new StarMade();
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
if (info == null) {
System.out.println("No bean info!");
return;
}
System.out.println("BeanInfo = " + info.getClass().getSimpleName());
if (info.getIcon(BeanInfo.ICON_COLOR_32x32) != null) {
System.out.println("32x32 color icon present");
} else if (info.getIcon(BeanInfo.ICON_COLOR_16x16) != null) {
System.out.println("16x16 color icon present");
} else if (info.getIcon(BeanInfo.ICON_MONO_32x32) != null) {
System.out.println("32x32 B&W icon present");
} else if (info.getIcon(BeanInfo.ICON_MONO_16x16) != null) {
System.out.println("16x16 B&W icon present");
} else {
System.out.println("No icon");
}
BeanDescriptor desc = info.getBeanDescriptor();
if (desc == null) {
System.out.println("No bean description!");
return;
}
System.out.println("BeanDesc = " + desc.getClass().getSimpleName());
System.out.println("Name = " + desc.getName() + " / " + desc.getDisplayName() + " / " + desc.getShortDescription());
System.out.println("Class = " + desc.getBeanClass());
System.out.println("Customizer = " + desc.getCustomizerClass());
} catch (IntrospectionException e) {
e.printStackTrace();
}
}
Example 73
Project: svarog-master File: SignalPageTreeNode.java View source code |
@Override
public List<LabelledPropertyDescriptor> getPropertyList() throws IntrospectionException {
LinkedList<LabelledPropertyDescriptor> list = new LinkedList<LabelledPropertyDescriptor>();
list.add(new LabelledPropertyDescriptor(_("page"), "page", SignalPageTreeNode.class, "getPage", null));
list.add(new LabelledPropertyDescriptor(_("size"), "size", SignalPageTreeNode.class, "getSize", null));
list.add(new LabelledPropertyDescriptor(_("start time"), "startTime", SignalPageTreeNode.class, "getStartTime", null));
list.add(new LabelledPropertyDescriptor(_("end time"), "endTime", SignalPageTreeNode.class, "getEndTime", null));
return list;
}
Example 74
Project: swagger-core-master File: SerializableParameterTest.java View source code |
/** * Tests if SerializableParameter.class has requiredParameter read method * * @param requiredParameter * @throws IntrospectionException */ @Test(dataProvider = REQUIRED_PARAMETER_METHODS) public void testSerializableParameterReadMethod(String requiredParameter) { String errorMsg = "SerializableParameter - missing property: " + requiredParameter; try { // Gets the method that should be used to read the property value. Assert.assertNotNull(new PropertyDescriptor(requiredParameter, SerializableParameter.class).getReadMethod(), errorMsg); } catch (IntrospectionException e) { Assert.fail(errorMsg + ", " + e.getMessage(), e); } }
Example 75
Project: SwingAppFramework-master File: ZoomLayoutBeanInfo.java View source code |
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor _height = new PropertyDescriptor("height", beanClass, "getHeight", "setHeight");
_height.setShortDescription("Preferred height");
PropertyDescriptor _width = new PropertyDescriptor("width", beanClass, "getWidth", "setWidth");
_width.setShortDescription("Preferred width");
PropertyDescriptor[] pds = new PropertyDescriptor[] { _height, _width };
return pds;
} catch (IntrospectionException ex) {
ex.printStackTrace();
return null;
}
}
Example 76
Project: test-streamer-master File: BeanPrinterFn.java View source code |
@Override
public void eval(Object bean, Printer printer) {
Printer.Fn<Object> fn = (Printer.Fn<Object>) Printers.defaultPrinterProtocol().lookup(bean.getClass());
if (fn != null) {
fn.eval(bean, printer);
} else {
try {
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
Map<Keyword, Object> beanMap = new HashMap<Keyword, Object>();
for (PropertyDescriptor propDesc : info.getPropertyDescriptors()) {
if (propDesc.getName().equals("class"))
continue;
try {
Object val = propDesc.getReadMethod().invoke(bean);
PropertyName propAnno = propDesc.getReadMethod().getAnnotation(PropertyName.class);
String propName = (propAnno != null) ? propAnno.value() : propDesc.getName();
beanMap.put(keywordize(propName), val);
} catch (Exception ignore) {
}
}
printer.printValue(beanMap);
} catch (IntrospectionException ex) {
throw new IllegalArgumentException("Not bean.");
}
}
}
Example 77
Project: toobs-master File: BetwixtUtil.java View source code |
public static String toXml(Object obj, boolean attributesForPrimitives, boolean wrapCollections, boolean mapIds, PropertySuppressionStrategy pss, ObjectStringConverter osc) throws IOException {
if (obj == null) {
return "";
}
// TODO Integrate SAX.
StringWriter writer = new StringWriter();
BeanWriter beanWriter = new BeanWriter(writer);
beanWriter.setLog(log);
// Set propertySuppressionStrategy.
if (pss == null) {
pss = new PropertySuppressionStrategy();
}
if (osc == null) {
osc = new ConvertUtilsObjectStringConverter();
}
beanWriter.getXMLIntrospector().getConfiguration().setPropertySuppressionStrategy(pss);
// Set collection settings.
beanWriter.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(wrapCollections);
beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(attributesForPrimitives);
beanWriter.getBindingConfiguration().setObjectStringConverter(osc);
// MapIDs false makes it so a bean instance is always written
beanWriter.getBindingConfiguration().setMapIDs(mapIds);
beanWriter.getBindingConfiguration().setIdMappingStrategy(new DefaultIdStoringStrategy());
beanWriter.setMixedContentEncodingStrategy(new MixedContentEncodingStrategy());
try {
beanWriter.write(obj);
} catch (SAXException e) {
log.error(e);
throw new IOException();
} catch (IntrospectionException e) {
log.error(e);
throw new IOException();
} catch (Exception e) {
log.error(e);
throw new IOException();
}
return writer.toString();
}
Example 78
Project: visuwall-master File: ELPutListTagBeanInfo.java View source code |
public PropertyDescriptor[] getPropertyDescriptors() {
ArrayList proplist = new ArrayList();
try {
proplist.add(new PropertyDescriptor("name", ELPutListTag.class, null, "setNameExpr"));
} catch (IntrospectionException ex) {
}
PropertyDescriptor[] result = new PropertyDescriptor[proplist.size()];
return ((PropertyDescriptor[]) proplist.toArray(result));
}
Example 79
Project: windowtester-master File: PropertyUtil.java View source code |
/** * Returns the description of the property with the provided * name on the provided object's interface. * @return the description of the property, or null if the * property does not exist. * * @throws IntrospectionException if an error occured using * the JavaBean Introspector class to query the properties * of the provided class. */ public static PropertyDescriptor getPropertyDescriptor(String propertyName, Object fromObj) throws IntrospectionException { BeanInfo beanInfo = Introspector.getBeanInfo(fromObj.getClass()); PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); for (int i = 0; i < properties.length; i++) { if (properties[i].getName().equals(propertyName)) { return properties[i]; } } return null; }
Example 80
Project: Work_book-master File: EventTracer.java View source code |
/**
* Adauga obiecte EventTracer la toate evenimentele care pot fi
* identificate la componentul dat si subclase
* @param c componet
*/
public void add(Component c) {
try {
//Luarea tuturor evenimentelor care pot pot fi citite
BeanInfo info = Introspector.getBeanInfo(c.getClass());
EventSetDescriptor[] eventSets = info.getEventSetDescriptors();
for (EventSetDescriptor eventSet : eventSets) {
addListner(c, eventSet);
}
} catch (IntrospectionException e) {
}
if (c instanceof Container) {
//si recursiv se cheama metoda adds
for (Component comp : ((Container) c).getComponents()) {
add(comp);
}
}
}
Example 81
Project: jautomata-master File: AbstractLayoutAlgorithm.java View source code |
public void tweak(String prop, Object val) {
// recupere les informations sur les proprietes
try {
java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(this.getClass(), AbstractLayoutAlgorithm.class);
java.beans.PropertyDescriptor[] props = info.getPropertyDescriptors();
// parcours les proprietes et essaye de les mettre a jour en fonction des parametres
for (int i = 0; i < props.length; i++) {
if (props[i].getName().equals(prop)) {
System.err.println("DEBUG >>>> tweaking " + prop + " -> " + val);
try {
java.lang.reflect.Method wmeth = props[i].getWriteMethod();
wmeth.invoke(this, new Object[] { val });
} catch (Exception ex) {
System.err.println("DEBUG >>>> Caught exception " + ex);
}
}
}
} catch (java.beans.IntrospectionException ex) {
System.err.println("Error in introspecting : " + ex);
}
}
Example 82
Project: l2fprod-common-master File: JCollapsiblePaneBeanInfo.java View source code |
/** * Gets the Property Descriptors * * @return The propertyDescriptors value */ public PropertyDescriptor[] getPropertyDescriptors() { try { Vector descriptors = new Vector(); PropertyDescriptor descriptor = null; try { descriptor = new PropertyDescriptor("animated", com.l2fprod.common.swing.JCollapsiblePane.class); } catch (IntrospectionException e) { descriptor = new PropertyDescriptor("animated", com.l2fprod.common.swing.JCollapsiblePane.class, "getAnimated", null); } descriptor.setPreferred(true); descriptor.setBound(true); descriptors.add(descriptor); try { descriptor = new PropertyDescriptor("collapsed", com.l2fprod.common.swing.JCollapsiblePane.class); } catch (IntrospectionException e) { descriptor = new PropertyDescriptor("collapsed", com.l2fprod.common.swing.JCollapsiblePane.class, "getCollapsed", null); } descriptor.setPreferred(true); descriptor.setBound(true); descriptors.add(descriptor); return (PropertyDescriptor[]) descriptors.toArray(new PropertyDescriptor[descriptors.size()]); } catch (Exception e) { e.printStackTrace(); } return null; }
Example 83
Project: opennars-master File: JCollapsiblePaneBeanInfo.java View source code |
/** * Gets the Property Descriptors * * @return The propertyDescriptors value */ public PropertyDescriptor[] getPropertyDescriptors() { try { Vector descriptors = new Vector(); PropertyDescriptor descriptor = null; try { descriptor = new PropertyDescriptor("animated", automenta.vivisect.swing.property.swing.JCollapsiblePane.class); } catch (IntrospectionException e) { descriptor = new PropertyDescriptor("animated", automenta.vivisect.swing.property.swing.JCollapsiblePane.class, "getAnimated", null); } descriptor.setPreferred(true); descriptor.setBound(true); descriptors.add(descriptor); try { descriptor = new PropertyDescriptor("collapsed", automenta.vivisect.swing.property.swing.JCollapsiblePane.class); } catch (IntrospectionException e) { descriptor = new PropertyDescriptor("collapsed", automenta.vivisect.swing.property.swing.JCollapsiblePane.class, "getCollapsed", null); } descriptor.setPreferred(true); descriptor.setBound(true); descriptors.add(descriptor); return (PropertyDescriptor[]) descriptors.toArray(new PropertyDescriptor[descriptors.size()]); } catch (Exception e) { e.printStackTrace(); } return null; }
Example 84
Project: aos-xp-master File: XPTagSetHelper.java View source code |
public static void set(XpContext xpContext, String var, String scope, Object target, String property, Object value) throws XpException, ELException {
if (null != var) {
// simple case, setting a scripting variable
if (null == scope) {
xpContext.setAttribute(var, value);
} else {
xpContext.setAttribute(var, value, xpContext.resolveScope(scope));
}
} else {
// must have target and property
if (target instanceof Map) {
if (value == null) {
((Map) target).remove(property);
} else {
((Map) target).put(property, value);
}
} else if (target != null) {
// must be a javaBean
try {
PropertyDescriptor pd[] = Introspector.getBeanInfo(target.getClass()).getPropertyDescriptors();
boolean succeeded = false;
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(property)) {
Method m = pd[i].getWriteMethod();
if (m == null) {
throw new XpException("No setter method");
}
if (value != null) {
try {
m.invoke(target, new Object[] { convertToExpectedType(xpContext, value, m.getParameterTypes()[0]) });
} catch (ELException ex) {
throw new XpException(ex.getMessage());
}
} else {
m.invoke(target, new Object[] { null });
}
succeeded = true;
}
}
if (!succeeded) {
throw new XpException("No setter method");
}
} catch (IllegalAccessException ex) {
throw new XpException(ex.getMessage());
} catch (IntrospectionException ex) {
throw new XpException(ex.getMessage());
} catch (InvocationTargetException ex) {
throw new XpException(ex.getMessage());
}
} else {
throw new XpException("Must provide target or var attribute");
}
}
}
Example 85
Project: archived-net-virt-platform-master File: OFVendorActionFactoriesTest.java View source code |
public void assertBeansEqual(Object expected, Object actual) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(expected.getClass());
for (PropertyDescriptor propertyDesc : beanInfo.getPropertyDescriptors()) {
Object srcValue = propertyDesc.getReadMethod().invoke(expected);
Object dstValue = propertyDesc.getReadMethod().invoke(actual);
assertEquals("Bean Value: " + propertyDesc.getName() + " expected: " + srcValue + " != actual: " + dstValue, srcValue, dstValue);
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Example 86
Project: axis2-java-master File: PopulateRecursiveTest.java View source code |
private void populateAndAssert(String s) throws XMLStreamException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IntrospectionException {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(s.getBytes()));
Class clazz = Class.forName("org.recursion.E");
Class innerClazz = Util.getFactory(clazz);
Method parseMethod = innerClazz.getMethod("parse", new Class[] { XMLStreamReader.class });
Object obj = parseMethod.invoke(null, new Object[] { reader });
assertNotNull(obj);
Object eObject = null;
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
Method readMethod;
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
if ("e".equals(propertyDescriptor.getDisplayName())) {
readMethod = propertyDescriptor.getReadMethod();
eObject = readMethod.invoke(obj, null);
assertNotNull(eObject);
assertTrue(eObject.getClass().equals(Class.forName("org.recursion.TypeE")));
}
}
}
Example 87
Project: BACKUP_FROM_SVN-master File: HeaderColumnNameMappingStrategy.java View source code |
protected PropertyDescriptor findDescriptor(String name) throws IntrospectionException {
//lazy load descriptors
if (null == descriptors)
descriptors = loadDescriptors(getType());
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor desc = descriptors[i];
if (matches(name, desc))
return desc;
}
return null;
}
Example 88
Project: Bio-PEPA-master File: HeaderColumnNameMappingStrategy.java View source code |
protected Map<String, PropertyDescriptor> loadDescriptorMap(Class<T> cls) throws IntrospectionException {
Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
PropertyDescriptor[] descriptors;
descriptors = loadDescriptors(getType());
for (PropertyDescriptor descriptor : descriptors) {
map.put(descriptor.getName().toUpperCase().trim(), descriptor);
}
return map;
}
Example 89
Project: Calendar-Application-master File: HeaderColumnNameMappingStrategy.java View source code |
protected Map<String, PropertyDescriptor> loadDescriptorMap(Class<T> cls) throws IntrospectionException {
Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
PropertyDescriptor[] descriptors;
descriptors = loadDescriptors(getType());
for (PropertyDescriptor descriptor : descriptors) {
map.put(descriptor.getName().toUpperCase().trim(), descriptor);
}
return map;
}
Example 90
Project: CF-reports-master File: ELCaptionTagBeanInfo.java View source code |
/**
* @see java.beans.BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
List proplist = new ArrayList();
try {
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"class", ELCaptionTag.class, null, //$NON-NLS-1$
"setClass"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"dir", ELCaptionTag.class, null, //$NON-NLS-1$
"setDir"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"id", ELCaptionTag.class, null, //$NON-NLS-1$
"setId"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"lang", ELCaptionTag.class, null, //$NON-NLS-1$
"setLang"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"media", ELColumnTag.class, null, //$NON-NLS-1$
"setMedia"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"style", ELCaptionTag.class, null, //$NON-NLS-1$
"setStyle"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"title", ELCaptionTag.class, null, //$NON-NLS-1$
"setTitle"));
} catch (IntrospectionException ex) {
}
PropertyDescriptor[] result = new PropertyDescriptor[proplist.size()];
return ((PropertyDescriptor[]) proplist.toArray(result));
}
Example 91
Project: com.revolsys.open-master File: PropertyDescriptorCache.java View source code |
protected static Map<String, PropertyDescriptor> getPropertyDescriptors(final Class<?> clazz) {
synchronized (propertyDescriptorByClassAndName) {
Map<String, PropertyDescriptor> propertyDescriptors = propertyDescriptorByClassAndName.get(clazz);
if (propertyDescriptors == null) {
propertyDescriptors = new HashMap<>();
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
for (final PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
final String propertyName = propertyDescriptor.getName();
propertyDescriptors.put(propertyName, propertyDescriptor);
Method writeMethod = propertyDescriptor.getWriteMethod();
if (writeMethod == null) {
final String setMethodName = "set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
try {
final Class<?> propertyType = propertyDescriptor.getPropertyType();
writeMethod = clazz.getMethod(setMethodName, propertyType);
propertyDescriptor.setWriteMethod(writeMethod);
} catch (NoSuchMethodExceptionSecurityException | e) {
}
}
Maps.put(propertyWriteMethodByClassAndName, clazz, propertyName, writeMethod);
}
} catch (final IntrospectionException e) {
e.printStackTrace();
}
propertyDescriptorByClassAndName.put(clazz, propertyDescriptors);
}
return propertyDescriptors;
}
}
Example 92
Project: consulo-master File: BeanValueAccessor.java View source code |
public static BeanValueAccessor createAccessor(Object bean, final String propertyName) {
Field[] fields = bean.getClass().getFields();
for (final Field field : fields) {
if (field.getName().equals(propertyName)) {
return new BeanValueAccessor(bean, propertyName) {
protected Object doGetValue() throws IllegalAccessException {
return field.get(myBean);
}
protected void doSetValue(Object value) throws IllegalAccessException {
field.set(myBean, value);
}
@Override
public Class getType() {
return field.getType();
}
};
}
}
try {
BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
for (final PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
if (descriptor.getName().equals(propertyName)) {
return new BeanValueAccessor(bean, propertyName) {
@Override
protected Object doGetValue() throws Exception {
return descriptor.getReadMethod().invoke(myBean);
}
@Override
protected void doSetValue(Object value) throws Exception {
descriptor.getWriteMethod().invoke(myBean, value);
}
@Override
public Class getType() {
return descriptor.getPropertyType();
}
};
}
}
throw new IllegalArgumentException("Property " + propertyName + " not found in " + bean.getClass());
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
Example 93
Project: csv-merger-master File: HeaderColumnNameMappingStrategy.java View source code |
protected Map<String, PropertyDescriptor> loadDescriptorMap(Class<T> cls) throws IntrospectionException {
Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>();
PropertyDescriptor[] descriptors;
descriptors = loadDescriptors(getType());
for (PropertyDescriptor descriptor : descriptors) {
map.put(descriptor.getName().toUpperCase().trim(), descriptor);
}
return map;
}
Example 94
Project: damp.ekeko.snippets-master File: JndiSystemOptionBeanInfo.java View source code |
public PropertyDescriptor[] getPropertyDescriptors() {
try {
return new PropertyDescriptor[] { createPropertyDescriptor(JndiSystemOption.class, "timeOut", JndiRootNode.getLocalizedString("TITLE_TimeOut"), JndiRootNode.getLocalizedString("TIP_TimeOut")) };
} catch (IntrospectionException ie) {
return new PropertyDescriptor[0];
}
}
Example 95
Project: diff-master File: StandardIntrospector.java View source code |
private TypeInfo internalIntrospect(final Class<?> type) throws IntrospectionException {
final TypeInfo typeInfo = new TypeInfo(type);
final PropertyDescriptor[] descriptors = getBeanInfo(type).getPropertyDescriptors();
for (final PropertyDescriptor descriptor : descriptors) {
if (shouldSkip(descriptor)) {
continue;
}
final String propertyName = descriptor.getName();
final Method readMethod = descriptor.getReadMethod();
final Method writeMethod = descriptor.getWriteMethod();
final PropertyAwareAccessor accessor = new PropertyAccessor(propertyName, readMethod, writeMethod);
typeInfo.addPropertyAccessor(accessor);
}
return typeInfo;
}
Example 96
Project: displaytag-master File: CaptionTagBeanInfo.java View source code |
/**
* @see java.beans.BeanInfo#getPropertyDescriptors()
*/
public PropertyDescriptor[] getPropertyDescriptors() {
List<PropertyDescriptor> proplist = new ArrayList<PropertyDescriptor>();
try {
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"class", CaptionTag.class, null, //$NON-NLS-1$
"setClass"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"dir", CaptionTag.class, null, //$NON-NLS-1$
"setDir"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"id", CaptionTag.class, null, //$NON-NLS-1$
"setId"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"lang", CaptionTag.class, null, //$NON-NLS-1$
"setLang"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"media", CaptionTag.class, null, //$NON-NLS-1$
"setMedia"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"style", CaptionTag.class, null, //$NON-NLS-1$
"setStyle"));
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"title", CaptionTag.class, null, //$NON-NLS-1$
"setTitle"));
// make ATG Dynamo happy:
// Attribute "className" of tag "caption" in taglib descriptor file displaytag-11.tld" must have a
// corresponding property in class "org.displaytag.tags.CaptionTag" with a public setter method
proplist.add(new //$NON-NLS-1$
PropertyDescriptor(//$NON-NLS-1$
"className", CaptionTag.class, null, //$NON-NLS-1$
"setClass"));
} catch (IntrospectionException ex) {
throw new UnhandledException("You got an introspection exception - maybe defining a property that is not" + " defined in the CaptionTag?: " + ex.getMessage(), ex);
}
PropertyDescriptor[] result = new PropertyDescriptor[proplist.size()];
return proplist.toArray(result);
}
Example 97
Project: drools-core-master File: NotNodeStep.java View source code |
public void execute(Map<String, Object> context, List<String[]> args) {
BuildContext buildContext = (BuildContext) context.get("BuildContext");
if (args.size() != 0) {
String[] a = args.get(0);
String name = a[0].trim();
String leftInput = a[1].trim();
String rightInput = a[2].trim();
LeftTupleSource leftTupleSource;
if ("mock".equals(leftInput)) {
leftTupleSource = Mockito.mock(LeftTupleSource.class);
;
} else {
leftTupleSource = (LeftTupleSource) context.get(leftInput);
}
ObjectSource rightObjectSource;
if ("mock".equals(rightInput)) {
rightObjectSource = Mockito.mock(ObjectSource.class);
;
} else {
rightObjectSource = (ObjectSource) context.get(rightInput);
}
BetaConstraints constraints;
if (args.size() > 1) {
a = args.get(1);
String fieldName = a[0].trim();
String operator = a[1].trim();
String var = a[2].trim();
Declaration declr = (Declaration) context.get(var);
BetaNodeFieldConstraint betaConstraint;
try {
betaConstraint = this.reteTesterHelper.getBoundVariableConstraint(declr.getPattern(), fieldName, declr, operator);
} catch (IntrospectionException e) {
throw new IllegalArgumentException();
}
constraints = new SingleBetaConstraints(betaConstraint, buildContext.getRuleBase().getConfiguration());
} else {
constraints = new EmptyBetaConstraints();
}
NotNode notNode = new NotNode(buildContext.getNextId(), leftTupleSource, rightObjectSource, constraints, BehaviorManager.NO_BEHAVIORS, buildContext);
notNode.attach();
context.put(name, notNode);
} else {
throw new IllegalArgumentException("Cannot arguments " + args);
}
}
Example 98
Project: droolsjbpm-master File: NotNodeStep.java View source code |
public void execute(Map<String, Object> context, List<String[]> args) {
BuildContext buildContext = (BuildContext) context.get("BuildContext");
if (args.size() != 0) {
String[] a = args.get(0);
String name = a[0].trim();
String leftInput = a[1].trim();
String rightInput = a[2].trim();
LeftTupleSource leftTupleSource;
if ("mock".equals(leftInput)) {
leftTupleSource = Mockito.mock(LeftTupleSource.class);
;
} else {
leftTupleSource = (LeftTupleSource) context.get(leftInput);
}
ObjectSource rightObjectSource;
if ("mock".equals(rightInput)) {
rightObjectSource = Mockito.mock(ObjectSource.class);
;
} else {
rightObjectSource = (ObjectSource) context.get(rightInput);
}
BetaConstraints constraints;
if (args.size() > 1) {
a = args.get(1);
String fieldName = a[0].trim();
String operator = a[1].trim();
String var = a[2].trim();
Declaration declr = (Declaration) context.get(var);
BetaNodeFieldConstraint betaConstraint;
try {
betaConstraint = this.reteTesterHelper.getBoundVariableConstraint(declr.getPattern(), fieldName, declr, operator);
} catch (IntrospectionException e) {
throw new IllegalArgumentException();
}
constraints = new SingleBetaConstraints(betaConstraint, buildContext.getRuleBase().getConfiguration());
} else {
constraints = new EmptyBetaConstraints();
}
NotNode notNode = new NotNode(buildContext.getNextId(), leftTupleSource, rightObjectSource, constraints, BehaviorManager.NO_BEHAVIORS, buildContext);
notNode.attach();
context.put(name, notNode);
} else {
throw new IllegalArgumentException("Cannot arguments " + args);
}
}
Example 99
Project: dwr-master File: ExceptionConverter.java View source code |
/* (non-Javadoc)
* @see org.directwebremoting.convert.BasicBeanConverter#getPropertyDescriptors(java.lang.Class, boolean, boolean)
*/
@Override
public Map<String, Property> getPropertyMapFromClass(Class<?> type, boolean readRequired, boolean writeRequired) throws ConversionException {
Map<String, Property> descriptors = super.getPropertyMapFromClass(type, readRequired, writeRequired);
descriptors.put("javaClassName", new PlainProperty("javaClassName", type.getName()));
// (fix for Bean Introspector peculiarities)
try {
fixMissingThrowableProperty(descriptors, "message", "getMessage");
fixMissingThrowableProperty(descriptors, "cause", "getCause");
} catch (IntrospectionException ex) {
throw new ConversionException(type, ex);
}
return descriptors;
}
Example 100
Project: earthsci-master File: EnumPersistenceDelegate.java View source code |
protected static void installFor(Class<?> enumClass) {
try {
BeanInfo info = Introspector.getBeanInfo(enumClass);
info.getBeanDescriptor().setValue("persistenceDelegate", INSTANCE);
} catch (IntrospectionException exception) {
throw new RuntimeException("Unable to persist enumerated type " + enumClass, exception);
}
}
Example 101
Project: Fudan-Sakai-master File: BeanPropertyAccess.java View source code |
public Method getPropertyGettor(Object source) throws IntrospectionException {
Method propertyGettor = (Method) gettorMap.get(source.getClass());
if (propertyGettor == null) {
BeanInfo info = Introspector.getBeanInfo(source.getClass());
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
if (descriptors[i].getName().equals(getPropertyName())) {
propertyGettor = descriptors[i].getReadMethod();
gettorMap.put(source.getClass(), propertyGettor);
break;
}
}
}
return propertyGettor;
}