|
ActiveMQ example source code file (IntrospectionSupport.java)
The ActiveMQ IntrospectionSupport.java source code/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.activemq.util; import java.beans.PropertyEditor; import java.beans.PropertyEditorManager; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import javax.net.ssl.SSLServerSocket; import org.apache.activemq.command.ActiveMQDestination; public final class IntrospectionSupport { static { // Add Spring and ActiveMQ specific property editors String[] additionalPath = new String[] { "org.springframework.beans.propertyeditors", "org.apache.activemq.util" }; synchronized (PropertyEditorManager.class) { String[] existingSearchPath = PropertyEditorManager.getEditorSearchPath(); String[] newSearchPath = (String[]) Array.newInstance(String.class, existingSearchPath.length + additionalPath.length); System.arraycopy(existingSearchPath, 0, newSearchPath, 0, existingSearchPath.length); System.arraycopy(additionalPath, 0, newSearchPath, existingSearchPath.length, additionalPath.length); try { PropertyEditorManager.setEditorSearchPath(newSearchPath); PropertyEditorManager.registerEditor(String[].class, StringArrayEditor.class); } catch(java.security.AccessControlException ignore) { // we might be in an applet... } } } private IntrospectionSupport() { } public static boolean getProperties(Object target, Map props, String optionPrefix) { boolean rc = false; if (target == null) { throw new IllegalArgumentException("target was null."); } if (props == null) { throw new IllegalArgumentException("props was null."); } if (optionPrefix == null) { optionPrefix = ""; } Class clazz = target.getClass(); Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; String name = method.getName(); Class type = method.getReturnType(); Class params[] = method.getParameterTypes(); if ((name.startsWith("is") || name.startsWith("get")) && params.length == 0 && type != null && isSettableType(type)) { try { Object value = method.invoke(target, new Object[] {}); if (value == null) { continue; } String strValue = convertToString(value, type); if (strValue == null) { continue; } if (name.startsWith("get")) { name = name.substring(3, 4).toLowerCase() + name.substring(4); } else { name = name.substring(2, 3).toLowerCase() + name.substring(3); } props.put(optionPrefix + name, strValue); rc = true; } catch (Throwable ignore) { } } } return rc; } public static boolean setProperties(Object target, Map<String, ?> props, String optionPrefix) { boolean rc = false; if (target == null) { throw new IllegalArgumentException("target was null."); } if (props == null) { throw new IllegalArgumentException("props was null."); } for (Iterator<String> iter = props.keySet().iterator(); iter.hasNext();) { String name = iter.next(); if (name.startsWith(optionPrefix)) { Object value = props.get(name); name = name.substring(optionPrefix.length()); if (setProperty(target, name, value)) { iter.remove(); rc = true; } } } return rc; } public static Map<String, Object> extractProperties(Map props, String optionPrefix) { if (props == null) { throw new IllegalArgumentException("props was null."); } HashMap<String, Object> rc = new HashMap Other ActiveMQ examples (source code examples)Here is a short list of links related to this ActiveMQ IntrospectionSupport.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.