Author: rgodfrey
Date: Thu Feb 4 18:04:39 2016
New Revision: 1728524
URL: http://svn.apache.org/viewvc?rev=1728524&view=rev
Log:
QPID-7049 : Add the ability to inject operations
Added:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectInjectedOperation.java
(with props)
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectMethodOperation.java
- copied, changed from r1728523,
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java
(with props)
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeStatisticOrOperation.java
- copied, changed from r1728498,
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java
(with props)
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromAnnotation.java
- copied, changed from r1728523,
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromInjection.java
(with props)
Modified:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/plugin/ConfiguredObjectAttributeInjector.java
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java
Added:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectInjectedOperation.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectInjectedOperation.java?rev=1728524&view=auto
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectInjectedOperation.java
(added)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectInjectedOperation.java
Thu Feb 4 18:04:39 2016
@@ -0,0 +1,236 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.qpid.server.util.ServerScopedRuntimeException;
+
+public class ConfiguredObjectInjectedOperation<C extends ConfiguredObject>
implements ConfiguredObjectOperation<C>,
InjectedAttributeStatisticOrOperation<C>
+{
+ private final Method _operation;
+ private final List<OperationParameter> _params;
+ private final Set<String> _validNames;
+ private final TypeValidator _validator;
+ private final String _name;
+ private final String _description;
+ private final boolean _nonModifying;
+
+ public ConfiguredObjectInjectedOperation(final String name,
+ final String description,
+ final boolean nonModifying,
+ final OperationParameter[]
parameters,
+ final Method operation,
+ final TypeValidator validator)
+ {
+ _operation = operation;
+ _name = name;
+ _description = description;
+ _nonModifying = nonModifying;
+ _validator = validator;
+
+ _params = parameters == null ?
Collections.<OperationParameter>emptyList() : Arrays.asList(parameters);
+
+ Set<String> validNames = new LinkedHashSet<>();
+ for(OperationParameter parameter : _params)
+ {
+ validNames.add(parameter.getName());
+ }
+
+ _validNames = Collections.unmodifiableSet(validNames);
+
+ Class<?>[] opParameterTypes = operation.getParameterTypes();
+ if(!(Modifier.isStatic(operation.getModifiers())
+ && Modifier.isPublic(operation.getModifiers())
+ && opParameterTypes.length == _params.size() + 1
+ && ConfiguredObject.class.isAssignableFrom(opParameterTypes[0])))
+ {
+ throw new IllegalArgumentException("Passed method must be public
and static. The first parameter must derive from ConfiguredObject, and the
rest of the parameters must match the passed in specifications");
+ }
+
+ int paramId = 1;
+ for(OperationParameter parameter : _params)
+ {
+
if(!opParameterTypes[paramId].isAssignableFrom(parameter.getType()))
+ {
+ throw new IllegalArgumentException("Type for parameter " +
parameter.getName() + " does not match");
+ }
+ paramId++;
+ }
+
+ }
+
+ @Override
+ public String getName()
+ {
+ return _name;
+ }
+
+ @Override
+ public List<OperationParameter> getParameters()
+ {
+ return _params;
+ }
+
+ @Override
+ public Object perform(C subject, Map<String, Object> parameters)
+ {
+ if(!_validator.appliesToType((Class<? extends ConfiguredObject<?>>)
subject.getClass()))
+ {
+ throw new IllegalArgumentException("Operation "
+ + _operation.getName()
+ + " cannot be used on an object
of type "
+ +
subject.getClass().getSimpleName());
+ }
+ else
+ {
+
+ Set<String> providedNames = new HashSet<>(parameters.keySet());
+ providedNames.removeAll(_validNames);
+ if (!providedNames.isEmpty())
+ {
+ throw new IllegalArgumentException("Parameters " +
providedNames + " are not accepted by " + getName());
+ }
+ Object[] paramValues = new Object[1+_params.size()];
+ paramValues[0] = subject;
+ for (int i = 0; i < _params.size(); i++)
+ {
+ OperationParameter param = _params.get(i);
+ Object providedVal;
+ if (parameters.containsKey(param.getName()))
+ {
+ providedVal = parameters.get(param.getName());
+ }
+ else if (!"".equals(param.getDefaultValue()))
+ {
+ providedVal = param.getDefaultValue();
+ }
+ else
+ {
+ providedVal = null;
+ }
+ final AttributeValueConverter<?> converter =
+
AttributeValueConverter.getConverter(AttributeValueConverter.convertPrimitiveToBoxed(param.getType()),
+
param.getGenericType());
+ try
+ {
+ final Object convertedVal = converter.convert(providedVal,
subject);
+ paramValues[i+1] = convertedVal;
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new IllegalArgumentException(e.getMessage()
+ + " for parameter '"
+ + param.getName()
+ + "' in "
+ +
_operation.getDeclaringClass().getSimpleName()
+ + "."
+ + _operation.getName()
+ + "(...) operation",
e.getCause());
+ }
+ }
+ try
+ {
+ return _operation.invoke(null, paramValues);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ServerScopedRuntimeException(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ if (e.getCause() instanceof RuntimeException)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ else if (e.getCause() instanceof Error)
+ {
+ throw (Error) e.getCause();
+ }
+ else
+ {
+ throw new ServerScopedRuntimeException(e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean hasSameParameters(final ConfiguredObjectOperation<?> other)
+ {
+ final List<OperationParameter> otherParams = other.getParameters();
+ if(_params.size() == otherParams.size())
+ {
+ for(int i = 0; i < _params.size(); i++)
+ {
+ if(!_params.get(i).isCompatible(otherParams.get(i)))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public Class<?> getReturnType()
+ {
+ return _operation.getReturnType();
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return _description;
+ }
+
+ @Override
+ public boolean isNonModifying()
+ {
+ return _nonModifying;
+ }
+
+ @Override
+ public Type getGenericReturnType()
+ {
+ return _operation.getGenericReturnType();
+ }
+
+ @Override
+ public boolean appliesToConfiguredObjectType(final Class<? extends
ConfiguredObject<?>> type)
+ {
+ return _validator.appliesToType(type);
+ }
+}
Propchange:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectInjectedOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectMethodOperation.java
(from r1728523,
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java)
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectMethodOperation.java?p2=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectMethodOperation.java&p1=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java&r1=1728523&r2=1728524&rev=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectMethodOperation.java
Thu Feb 4 18:04:39 2016
@@ -34,23 +34,23 @@ import java.util.Set;
import org.apache.qpid.server.util.ServerScopedRuntimeException;
-public class ConfiguredObjectOperation<C extends ConfiguredObject>
+public class ConfiguredObjectMethodOperation<C extends ConfiguredObject>
implements ConfiguredObjectOperation<C>
{
private final Method _operation;
- private final OperationParameter[] _params;
+ private final OperationParameterFromAnnotation[] _params;
private final Set<String> _validNames;
private final String _objectType;
private final ConfiguredObjectTypeRegistry _typeRegistry;
- public ConfiguredObjectOperation(Class<C> clazz,
- final Method operation,
- final ConfiguredObjectTypeRegistry
typeRegistry)
+ public ConfiguredObjectMethodOperation(Class<C> clazz,
+ final Method operation,
+ final ConfiguredObjectTypeRegistry
typeRegistry)
{
_objectType = clazz.getSimpleName();
_operation = operation;
_typeRegistry = typeRegistry;
final Annotation[][] allParameterAnnotations =
_operation.getParameterAnnotations();
- _params = new OperationParameter[allParameterAnnotations.length];
+ _params = new
OperationParameterFromAnnotation[allParameterAnnotations.length];
Set<String> validNames = new LinkedHashSet<>();
for(int i = 0; i < allParameterAnnotations.length; i++)
{
@@ -60,7 +60,7 @@ public class ConfiguredObjectOperation<C
if(annotation instanceof Param)
{
- _params[i] = new OperationParameter((Param) annotation,
_operation.getParameterTypes()[i], _operation.getGenericParameterTypes()[i]);
+ _params[i] = new OperationParameterFromAnnotation((Param)
annotation, _operation.getParameterTypes()[i],
_operation.getGenericParameterTypes()[i]);
validNames.add(_params[i].getName());
}
}
@@ -72,16 +72,19 @@ public class ConfiguredObjectOperation<C
_validNames = Collections.unmodifiableSet(validNames);
}
+ @Override
public String getName()
{
return _operation.getName();
}
+ @Override
public List<OperationParameter> getParameters()
{
- return Collections.unmodifiableList(Arrays.asList(_params));
+ return
Collections.unmodifiableList(Arrays.<OperationParameter>asList(_params));
}
+ @Override
public Object perform(C subject, Map<String, Object> parameters)
{
final Map<String, ConfiguredObjectOperation<?>> operationsOnSubject =
@@ -176,13 +179,15 @@ public class ConfiguredObjectOperation<C
}
}
+ @Override
public boolean hasSameParameters(final ConfiguredObjectOperation<?> other)
{
- if(_params.length == other._params.length)
+ final List<OperationParameter> otherParams = other.getParameters();
+ if(_params.length == otherParams.size())
{
for(int i = 0; i < _params.length; i++)
{
- if(!_params[i].isCompatible(other._params[i]))
+ if(!_params[i].isCompatible(otherParams.get(i)))
{
return false;
}
@@ -195,21 +200,25 @@ public class ConfiguredObjectOperation<C
}
}
+ @Override
public Class<?> getReturnType()
{
return _operation.getReturnType();
}
+ @Override
public String getDescription()
{
return _operation.getAnnotation(ManagedOperation.class).description();
}
+ @Override
public boolean isNonModifying()
{
return _operation.getAnnotation(ManagedOperation.class).nonModifying();
}
+ @Override
public Type getGenericReturnType()
{
return _operation.getGenericReturnType();
Added:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java?rev=1728524&view=auto
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java
(added)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java
Thu Feb 4 18:04:39 2016
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+
+public interface ConfiguredObjectOperation<C extends ConfiguredObject>
+{
+ String getName();
+
+ List<OperationParameter> getParameters();
+
+ Object perform(C subject, Map<String, Object> parameters);
+
+ boolean hasSameParameters(ConfiguredObjectOperation<?> other);
+
+ Class<?> getReturnType();
+
+ String getDescription();
+
+ boolean isNonModifying();
+
+ Type getGenericReturnType();
+}
Propchange:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java?rev=1728524&r1=1728523&r2=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java
Thu Feb 4 18:04:39 2016
@@ -685,6 +685,7 @@ public class ConfiguredObjectTypeRegistr
attributeSet.add(attr);
}
}
+
for(ConfiguredObjectInjectedStatistic<?,?> attr :
injector.getInjectedStatistics())
{
if(attr.appliesToConfiguredObjectType((Class<? extends
ConfiguredObject<?>>) clazz))
@@ -692,6 +693,14 @@ public class ConfiguredObjectTypeRegistr
statisticSet.add(attr);
}
}
+
+ for(ConfiguredObjectInjectedOperation<?> operation :
injector.getInjectedOperations())
+ {
+ if(operation.appliesToConfiguredObjectType((Class<? extends
ConfiguredObject<?>>) clazz))
+ {
+ operationsSet.add(operation);
+ }
+ }
}
}
@@ -786,7 +795,7 @@ public class ConfiguredObjectTypeRegistr
throw new ServerScopedRuntimeException("Can only define
ManagedOperations on interfaces which extend " +
ConfiguredObject.class.getSimpleName() + ". " + clazz.getSimpleName() + " does
not meet these criteria.");
}
- ConfiguredObjectOperation<?> operation = new
ConfiguredObjectOperation<>(clazz, m, this);
+ ConfiguredObjectOperation<?> operation = new
ConfiguredObjectMethodOperation<>(clazz, m, this);
Iterator<ConfiguredObjectOperation<?>> iter = operationSet.iterator();
while(iter.hasNext())
{
Modified:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java?rev=1728524&r1=1728523&r2=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java
Thu Feb 4 18:04:39 2016
@@ -20,12 +20,7 @@
*/
package org.apache.qpid.server.model;
-public interface InjectedAttributeOrStatistic<C extends ConfiguredObject, T>
extends ConfiguredObjectAttributeOrStatistic<C, T>
+public interface InjectedAttributeOrStatistic<C extends ConfiguredObject, T>
extends InjectedAttributeStatisticOrOperation<C>,
ConfiguredObjectAttributeOrStatistic<C, T>
{
- boolean appliesToConfiguredObjectType(Class<? extends ConfiguredObject<?>>
type);
- interface TypeValidator
- {
- boolean appliesToType(Class<? extends ConfiguredObject<?>> type);
- }
}
Copied:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeStatisticOrOperation.java
(from r1728498,
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java)
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeStatisticOrOperation.java?p2=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeStatisticOrOperation.java&p1=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java&r1=1728498&r2=1728524&rev=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeOrStatistic.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/InjectedAttributeStatisticOrOperation.java
Thu Feb 4 18:04:39 2016
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.server.model;
-public interface InjectedAttributeOrStatistic<C extends ConfiguredObject, T>
extends ConfiguredObjectAttributeOrStatistic<C, T>
+public interface InjectedAttributeStatisticOrOperation<C extends
ConfiguredObject>
{
boolean appliesToConfiguredObjectType(Class<? extends ConfiguredObject<?>>
type);
Added:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java?rev=1728524&view=auto
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java
(added)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java
Thu Feb 4 18:04:39 2016
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import java.lang.reflect.Type;
+import java.util.List;
+
+public interface OperationParameter
+{
+ String getName();
+
+ String getDefaultValue();
+
+ String getDescription();
+
+ List<String> getValidValues();
+
+ Class<?> getType();
+
+ Type getGenericType();
+
+ boolean isCompatible(OperationParameter that);
+}
Propchange:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromAnnotation.java
(from r1728523,
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java)
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromAnnotation.java?p2=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromAnnotation.java&p1=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java&r1=1728523&r2=1728524&rev=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameter.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromAnnotation.java
Thu Feb 4 18:04:39 2016
@@ -25,81 +25,60 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-public class OperationParameter
+public class OperationParameterFromAnnotation implements OperationParameter
{
private final Param _param;
private final Class<?> _type;
private final Type _genericType;
- public OperationParameter(final Param param, final Class<?> type, final
Type genericType)
+ public OperationParameterFromAnnotation(final Param param, final Class<?>
type, final Type genericType)
{
_param = param;
_type = type;
_genericType = genericType;
}
+ @Override
public String getName()
{
return _param.name();
}
+ @Override
public String getDefaultValue()
{
return _param.defaultValue();
}
+ @Override
public String getDescription()
{
return _param.description();
}
+ @Override
public List<String> getValidValues()
{
return
Collections.unmodifiableList(Arrays.asList(_param.validValues()));
}
+ @Override
public Class<?> getType()
{
return _type;
}
+ @Override
public Type getGenericType()
{
return _genericType;
}
- public boolean isCompatible(final OperationParameter that)
- {
- if (!_param.name().equals(that._param.name()))
- {
- return false;
- }
- if (getType() != null ? !getType().equals(that.getType()) :
that.getType() != null)
- {
- return false;
- }
- return !(getGenericType() != null
- ? !getGenericType().equals(that.getGenericType())
- : that.getGenericType() != null);
-
- }
-
@Override
- public boolean equals(final Object o)
+ public boolean isCompatible(final OperationParameter that)
{
- if (this == o)
- {
- return true;
- }
- if (o == null || getClass() != o.getClass())
- {
- return false;
- }
-
- final OperationParameter that = (OperationParameter) o;
-
- if (_param != null ? !_param.equals(that._param) : that._param != null)
+ if (!_param.name().equals(that.getName()))
{
return false;
}
@@ -113,12 +92,4 @@ public class OperationParameter
}
- @Override
- public int hashCode()
- {
- int result = _param != null ? _param.hashCode() : 0;
- result = 31 * result + (getType() != null ? getType().hashCode() : 0);
- result = 31 * result + (getGenericType() != null ?
getGenericType().hashCode() : 0);
- return result;
- }
}
Added:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromInjection.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromInjection.java?rev=1728524&view=auto
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromInjection.java
(added)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromInjection.java
Thu Feb 4 18:04:39 2016
@@ -0,0 +1,106 @@
+/*
+ *
+ * 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.qpid.server.model;
+
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class OperationParameterFromInjection implements OperationParameter
+{
+ private final Class<?> _type;
+ private final Type _genericType;
+ private final String _name;
+ private final String _defaultValue;
+ private final String _description;
+ private final List<String> _validValues;
+
+ public OperationParameterFromInjection(final String name,
+ final Class<?> type,
+ final Type genericType,
+ final String defaultValue,
+ final String description,
+ final String[] validValues)
+ {
+ _type = type;
+ _genericType = genericType;
+ _name = name;
+ _defaultValue = defaultValue;
+ _description = description;
+ _validValues = validValues == null ? Collections.<String>emptyList() :
Collections.unmodifiableList(Arrays.asList(validValues));
+ }
+
+ @Override
+ public String getName()
+ {
+ return _name;
+ }
+
+ @Override
+ public String getDefaultValue()
+ {
+ return _defaultValue;
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return _description;
+ }
+
+ @Override
+ public List<String> getValidValues()
+ {
+ return _validValues;
+ }
+
+ @Override
+ public Class<?> getType()
+ {
+ return _type;
+ }
+
+ @Override
+ public Type getGenericType()
+ {
+ return _genericType;
+ }
+
+
+ @Override
+ public boolean isCompatible(final OperationParameter that)
+ {
+ if (!getName().equals(that.getName()))
+ {
+ return false;
+ }
+ if (getType() != null ? !getType().equals(that.getType()) :
that.getType() != null)
+ {
+ return false;
+ }
+ return !(getGenericType() != null
+ ? !getGenericType().equals(that.getGenericType())
+ : that.getGenericType() != null);
+
+ }
+
+}
Propchange:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/OperationParameterFromInjection.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/plugin/ConfiguredObjectAttributeInjector.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/plugin/ConfiguredObjectAttributeInjector.java?rev=1728524&r1=1728523&r2=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/plugin/ConfiguredObjectAttributeInjector.java
(original)
+++
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/plugin/ConfiguredObjectAttributeInjector.java
Thu Feb 4 18:04:39 2016
@@ -23,10 +23,12 @@ package org.apache.qpid.server.plugin;
import java.util.Collection;
import org.apache.qpid.server.model.ConfiguredObjectInjectedAttribute;
+import org.apache.qpid.server.model.ConfiguredObjectInjectedOperation;
import org.apache.qpid.server.model.ConfiguredObjectInjectedStatistic;
public interface ConfiguredObjectAttributeInjector extends Pluggable
{
Collection<ConfiguredObjectInjectedAttribute<?,?>> getInjectedAttributes();
Collection<ConfiguredObjectInjectedStatistic<?,?>> getInjectedStatistics();
+ Collection<ConfiguredObjectInjectedOperation<?>> getInjectedOperations();
}
Modified:
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java?rev=1728524&r1=1728523&r2=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
(original)
+++
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/InjectedAttributeTest.java
Thu Feb 4 18:04:39 2016
@@ -21,22 +21,14 @@
package org.apache.qpid.server.model.testmodels.hierarchy;
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.security.AccessControlException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
-import com.google.common.util.concurrent.ListenableFuture;
import org.apache.qpid.server.configuration.IllegalConfigurationException;
-import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.model.*;
import org.apache.qpid.server.plugin.ConfiguredObjectAttributeInjector;
-import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.test.utils.QpidTestCase;
public class InjectedAttributeTest extends QpidTestCase
@@ -47,12 +39,37 @@ public class InjectedAttributeTest exten
private Collection<ConfiguredObjectInjectedAttribute<?, ?>>
_injectedAttributes;
private Collection<ConfiguredObjectInjectedStatistic<?, ?>>
_injectedStatistics;
+ private Collection<ConfiguredObjectInjectedOperation<?>>
_injectedOperations;
+
+ private TestInjector(ConfiguredObjectInjectedAttribute<?, ?> attribute)
+ {
+ this(Collections.<ConfiguredObjectInjectedAttribute<?,
?>>singletonList(attribute),
+ Collections.<ConfiguredObjectInjectedStatistic<?,
?>>emptyList(),
+
Collections.<ConfiguredObjectInjectedOperation<?>>emptyList());
+ }
+
+ private TestInjector(ConfiguredObjectInjectedStatistic<?, ?> statistic)
+ {
+ this(Collections.<ConfiguredObjectInjectedAttribute<?,
?>>emptyList(),
+ Collections.<ConfiguredObjectInjectedStatistic<?,
?>>singletonList(statistic),
+
Collections.<ConfiguredObjectInjectedOperation<?>>emptyList());
+ }
+
+
+ private TestInjector(ConfiguredObjectInjectedOperation<?> operation)
+ {
+ this(Collections.<ConfiguredObjectInjectedAttribute<?,
?>>emptyList(),
+ Collections.<ConfiguredObjectInjectedStatistic<?,
?>>emptyList(),
+
Collections.<ConfiguredObjectInjectedOperation<?>>singletonList(operation));
+ }
private TestInjector(final
Collection<ConfiguredObjectInjectedAttribute<?, ?>> injectedAttributes,
- final
Collection<ConfiguredObjectInjectedStatistic<?, ?>> injectedStatistics)
+ final
Collection<ConfiguredObjectInjectedStatistic<?, ?>> injectedStatistics,
+ final
Collection<ConfiguredObjectInjectedOperation<?>> injectedOperations)
{
_injectedAttributes = injectedAttributes;
_injectedStatistics = injectedStatistics;
+ _injectedOperations = injectedOperations;
}
@Override
@@ -68,6 +85,12 @@ public class InjectedAttributeTest exten
}
@Override
+ public Collection<ConfiguredObjectInjectedOperation<?>>
getInjectedOperations()
+ {
+ return _injectedOperations;
+ }
+
+ @Override
public String getType()
{
return "TEST";
@@ -101,8 +124,7 @@ public class InjectedAttributeTest exten
null,
validator);
- TestModel model = new TestModel(null,
Collections.<ConfiguredObjectAttributeInjector>singleton(new
TestInjector(Collections.<ConfiguredObjectInjectedAttribute<?, ?>>singletonList(
- attrInjector),
Collections.<ConfiguredObjectInjectedStatistic<?, ?>>emptySet())));
+ TestModel model = new TestModel(null, new TestInjector(attrInjector));
TestCar<?> testCar = new
TestStandardCarImpl(Collections.<String,Object>singletonMap("name", "Arthur"),
model);
@@ -150,8 +172,7 @@ public class InjectedAttributeTest exten
new String[] { "42", "49" },
validator);
- TestModel model = new TestModel(null,
Collections.<ConfiguredObjectAttributeInjector>singleton(new
TestInjector(Collections.<ConfiguredObjectInjectedAttribute<?, ?>>singletonList(
- attrInjector),
Collections.<ConfiguredObjectInjectedStatistic<?, ?>>emptySet())));
+ TestModel model = new TestModel(null, new TestInjector(attrInjector));
TestCar<?> testCar = new
TestStandardCarImpl(Collections.<String,Object>singletonMap("name", "Arthur"),
model);
@@ -199,8 +220,7 @@ public class InjectedAttributeTest exten
"",
validator);
- TestModel model = new TestModel(null,
Collections.<ConfiguredObjectAttributeInjector>singleton(new
TestInjector(Collections.<ConfiguredObjectInjectedAttribute<?, ?>>singletonList(
- attrInjector),
Collections.<ConfiguredObjectInjectedStatistic<?, ?>>emptySet())));
+ TestModel model = new TestModel(null, new TestInjector(attrInjector));
TestCar<?> testCar = new
TestStandardCarImpl(Collections.<String,Object>singletonMap("name", "Arthur"),
model);
@@ -233,7 +253,7 @@ public class InjectedAttributeTest exten
StatisticType.POINT_IN_TIME,
"What is 6 x 9?");
- TestModel model = new TestModel(null,
Collections.<ConfiguredObjectAttributeInjector>singleton(new
TestInjector(Collections.<ConfiguredObjectInjectedAttribute<?, ?>>emptyList(),
Collections.<ConfiguredObjectInjectedStatistic<?,
?>>singletonList(statInjector))));
+ TestModel model = new TestModel(null, new TestInjector(statInjector));
TestCar<?> testCar = new
TestStandardCarImpl(Collections.<String,Object>singletonMap("name", "Arthur"),
model);
@@ -243,8 +263,54 @@ public class InjectedAttributeTest exten
}
+ public void testInjectedOperation() throws Exception
+ {
+
+ Method method = InjectedAttributeTest.class.getDeclaredMethod("fly",
TestCar.class, Integer.TYPE);
+ InjectedAttributeOrStatistic.TypeValidator validator =
+ new InjectedAttributeOrStatistic.TypeValidator()
+ {
+ @Override
+ public boolean appliesToType(final Class<? extends
ConfiguredObject<?>> type)
+ {
+ return TestCar.class.isAssignableFrom(type);
+ }
+ };
+
+ final OperationParameter[] params = new OperationParameter[1];
+ params[0] = new OperationParameterFromInjection("height",
Integer.TYPE, Integer.TYPE, "", "", new String[0]);
+ final ConfiguredObjectInjectedOperation<?> operationInjector =
+ new ConfiguredObjectInjectedOperation<TestCar<?>>("fly", "",
true, params, method, validator);
+
+ TestModel model = new TestModel(null, new
TestInjector(operationInjector));
+
+ TestCar testCar = new
TestStandardCarImpl(Collections.<String,Object>singletonMap("name", "Arthur"),
model);
+
+ final Map<String, ConfiguredObjectOperation<?>> allOperations =
+ model.getTypeRegistry().getOperations(testCar.getClass());
+
+ assertTrue("Operation fly(int height) is missing",
allOperations.containsKey("fly"));
+
+ final ConfiguredObjectOperation foundOperation =
allOperations.get("fly");
+
+ Object result = foundOperation.perform(testCar, Collections.<String,
Object>singletonMap("height", 0));
+
+ assertEquals("Car should be able to fly at 0m", Boolean.TRUE, result);
+
+ result = foundOperation.perform(testCar, Collections.<String,
Object>singletonMap("height", 5000));
+
+ assertEquals("Car should not be able to fly at 5000m", Boolean.FALSE,
result);
+ }
+
+
+
public static int getMeaningOfLife(TestCar<?> car)
{
return 42;
}
+
+ public static boolean fly(TestCar<?> car, int height)
+ {
+ return height == 0;
+ }
}
Modified:
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java?rev=1728524&r1=1728523&r2=1728524&view=diff
==============================================================================
---
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java
(original)
+++
qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/hierarchy/TestModel.java
Thu Feb 4 18:04:39 2016
@@ -54,6 +54,12 @@ public class TestModel extends Model
{
this(objectFactory,
Collections.<ConfiguredObjectAttributeInjector>emptySet());
}
+
+ public TestModel(final ConfiguredObjectFactory objectFactory,
ConfiguredObjectAttributeInjector injector)
+ {
+ this(objectFactory, Collections.singleton(injector));
+ }
+
public TestModel(final ConfiguredObjectFactory objectFactory,
Set<ConfiguredObjectAttributeInjector> attributeInjectors)
{
_objectFactory = objectFactory == null ? new
ConfiguredObjectFactoryImpl(this) : objectFactory;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]