001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.plugin; 018 019import javax.xml.bind.JAXBElement; 020import java.lang.reflect.Method; 021import java.util.HashSet; 022import java.util.LinkedList; 023import java.util.List; 024import java.util.Set; 025 026import org.apache.activemq.command.ActiveMQQueue; 027import org.apache.activemq.command.ActiveMQTopic; 028import org.apache.activemq.schema.core.DtoTopic; 029import org.apache.activemq.schema.core.DtoQueue; 030import org.apache.activemq.schema.core.DtoAuthenticationUser; 031import org.apache.activemq.security.AuthenticationUser; 032 033public class JAXBUtils { 034 035 public static Method findSetter(Object instance, String elementName) { 036 String setter = "set" + elementName; 037 for (Method m : instance.getClass().getMethods()) { 038 if (setter.equals(m.getName())) { 039 return m; 040 } 041 } 042 return null; 043 } 044 045 public static Object inferTargetObject(Object elementContent) { 046 if (DtoTopic.class.isAssignableFrom(elementContent.getClass())) { 047 return new ActiveMQTopic(); 048 } else if (DtoQueue.class.isAssignableFrom(elementContent.getClass())) { 049 return new ActiveMQQueue(); 050 } else if (DtoAuthenticationUser.class.isAssignableFrom(elementContent.getClass())) { 051 return new AuthenticationUser(); 052 } else { 053 return new Object(); 054 } 055 } 056 057 public static Object matchType(List<Object> parameterValues, Class<?> aClass) { 058 Object result = parameterValues; 059 if (Set.class.isAssignableFrom(aClass)) { 060 result = new HashSet(parameterValues); 061 } 062 return result; 063 } 064 065}