/
Validator.java
666 lines (602 loc) · 32 KB
/
Validator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/*
* 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.felix.scrplugin.helper;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Map;
import org.apache.felix.scrplugin.Options;
import org.apache.felix.scrplugin.Project;
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.description.AbstractDescription;
import org.apache.felix.scrplugin.description.ClassDescription;
import org.apache.felix.scrplugin.description.ComponentDescription;
import org.apache.felix.scrplugin.description.PropertyDescription;
import org.apache.felix.scrplugin.description.PropertyType;
import org.apache.felix.scrplugin.description.ReferenceCardinality;
import org.apache.felix.scrplugin.description.ReferenceDescription;
import org.apache.felix.scrplugin.description.ReferencePolicy;
import org.apache.felix.scrplugin.description.ReferencePolicyOption;
import org.apache.felix.scrplugin.description.ReferenceStrategy;
import org.apache.felix.scrplugin.description.ServiceDescription;
public class Validator {
private final ComponentContainer container;
private final Options options;
private final Project project;
private final IssueLog iLog;
public Validator(final ComponentContainer container,
final Project project,
final Options options,
final IssueLog iLog) {
this.container = container;
this.project = project;
this.options = options;
this.iLog = iLog;
}
private void logWarn(final AbstractDescription desc, final String message) {
// check if location of description is the same as the class
final String classLocation = this.container.getComponentDescription().getSource();
if ( classLocation.equals(desc.getSource()) ) {
iLog.addWarning(desc.getIdentifier() + " : " + message, desc.getSource());
} else {
iLog.addWarning(desc.getIdentifier() + " (" + desc.getSource() + ") : " + message, classLocation);
}
}
private void logError(final AbstractDescription desc, final String message) {
// check if location of description is the same as the class
final String classLocation = this.container.getComponentDescription().getSource();
if ( classLocation.equals(desc.getSource()) ) {
iLog.addError(desc.getIdentifier() + " : " + message, desc.getSource());
} else {
iLog.addError(desc.getIdentifier() + " (" + desc.getSource() + ") : " + message, classLocation);
}
}
/**
* Validate the component description. If errors occur a message is added to
* the issues list, warnings can be added to the warnings list.
*/
public void validate()
throws SCRDescriptorException {
final ComponentDescription component = this.container.getComponentDescription();
// nothing to check if this is ignored
if (!component.isCreateDs()) {
return;
}
final int currentIssueCount = iLog.getNumberOfErrors();
// if the component is abstract, we do not validate everything
if (!component.isAbstract()) {
// if configuration pid is set and different from name, we need 1.2
if ( component.getConfigurationPid() != null && !component.getConfigurationPid().equals(component.getName())
&& options.getSpecVersion().ordinal() < SpecVersion.VERSION_1_2.ordinal() ) {
this.logError(component, "Different configuration pid requires "
+ SpecVersion.VERSION_1_2.getName() + " or higher.");
}
// ensure non-abstract, public class
if (!Modifier.isPublic(this.container.getClassDescription().getDescribedClass().getModifiers())) {
this.logError(component, "Class must be public: "
+ this.container.getClassDescription().getDescribedClass().getName());
}
if (Modifier.isAbstract(this.container.getClassDescription().getDescribedClass().getModifiers())
|| this.container.getClassDescription().getDescribedClass().isInterface()) {
this.logError(component, "Class must be concrete class (not abstract or interface) : "
+ this.container.getClassDescription().getDescribedClass().getName());
}
// no errors so far, let's continue
if (iLog.getNumberOfErrors() == currentIssueCount) {
final String activateName = component.getActivate() == null ? "activate" : component.getActivate();
final String deactivateName = component.getDeactivate() == null ? "deactivate" : component.getDeactivate();
// check activate and deactivate methods
this.checkLifecycleMethod(activateName, true, component.getActivate() != null);
this.checkLifecycleMethod(deactivateName, false, component.getDeactivate() != null);
if (component.getModified() != null) {
if ( this.options.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal() ) {
this.checkLifecycleMethod(component.getModified(), true, true);
} else {
this.logError(component, "If modified version is specified, spec version must be " +
SpecVersion.VERSION_1_1.name() + " or higher : " + component.getModified());
}
}
// ensure public default constructor
boolean constructorFound = true;
Constructor<?>[] constructors = this.container.getClassDescription().getDescribedClass().getDeclaredConstructors();
for (int i = 0; constructors != null && i < constructors.length; i++) {
// if public default, succeed
if (Modifier.isPublic(constructors[i].getModifiers())
&& (constructors[i].getParameterTypes() == null || constructors[i].getParameterTypes().length == 0)) {
constructorFound = true;
break;
}
// non-public/non-default constructor found, must have
// explicit
constructorFound = false;
}
if (!constructorFound) {
this.logError(component, "Class must have public default constructor: " + this.container.getClassDescription().getDescribedClass().getName());
}
// verify properties
for (final PropertyDescription prop : this.container.getProperties().values()) {
this.validateProperty(prop);
}
// verify service
boolean isServiceFactory = false;
if (this.container.getServiceDescription() != null) {
if (this.container.getServiceDescription().getInterfaces().size() == 0) {
this.logError(component, "Service interface information is missing!");
}
this.validateService(this.container.getServiceDescription());
isServiceFactory = this.container.getServiceDescription().isServiceFactory();
}
// serviceFactory must not be true for immediate of component factory
if (isServiceFactory && component.getImmediate() != null && component.getImmediate().booleanValue()
&& component.getFactory() != null) {
this.logError(component,
"Component must not be a ServiceFactory, if immediate and/or component factory: "
+ this.container.getClassDescription().getDescribedClass().getName());
}
// immediate must not be true for component factory
if (component.getImmediate() != null && component.getImmediate().booleanValue() && component.getFactory() != null) {
this.logError(component,
"Component must not be immediate if component factory: " + this.container.getClassDescription().getDescribedClass().getName());
}
}
// additional check for metatype (FELIX-4035)
if ( this.container.getMetatypeContainer() != null ) {
if ( this.container.getMetatypeContainer().getProperties().size() == 0 ) {
this.logError(component, "Component is defined to generate metatype information, however no properties have been " +
"defined; in case no properties are wanted, consider to use 'metatype=false'");
}
}
if (iLog.getNumberOfErrors() == currentIssueCount) {
// verify references
for (final ReferenceDescription ref : this.container.getReferences().values()) {
this.validateReference(ref, component.isAbstract());
}
}
}
}
private static final String TYPE_COMPONENT_CONTEXT = "org.osgi.service.component.ComponentContext";
private static final String TYPE_BUNDLE_CONTEXT = "org.osgi.framework.BundleContext";
private static final String TYPE_MAP = "java.util.Map";
private static final String TYPE_INT = "int";
private static final String TYPE_INTEGER = "java.lang.Integer";
private Method getMethod(final String name, final String[] sig)
throws SCRDescriptorException {
Class<?>[] classSig = (sig == null ? null : new Class<?>[sig.length]);
if ( sig != null ) {
for(int i = 0; i<sig.length; i++) {
try {
if ( sig[i].equals("int") ) {
classSig[i] = int.class;
} else {
classSig[i] = this.project.getClassLoader().loadClass(sig[i]);
}
} catch (final ClassNotFoundException e) {
throw new SCRDescriptorException("Unable to load class.", e);
}
}
}
return getMethod(this.container.getClassDescription(), name, classSig);
}
/**
* Check for existence of lifecycle methods.
*
* @param methodName
* The method name.
* @param isActivate Whether this is the activate or deactivate method.
* @param isSpecified Whether this method has explicitely been specified or is just
* the default
*/
private void checkLifecycleMethod(final String methodName,
final boolean isActivate,
final boolean isSpecified)
throws SCRDescriptorException {
// first candidate is (de)activate(ComponentContext)
Method method = this.getMethod(methodName, new String[] { TYPE_COMPONENT_CONTEXT });
if (method == null) {
if (this.options.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal() ) {
// second candidate is (de)activate(BundleContext)
method = this.getMethod(methodName, new String[] { TYPE_BUNDLE_CONTEXT });
if (method == null) {
// third candidate is (de)activate(Map)
method = this.getMethod(methodName, new String[] { TYPE_MAP });
if (method == null) {
// if this is a deactivate method, we have two
// additional possibilities
// a method with parameter of type int and one of type
// Integer
if (!isActivate) {
method = this.getMethod(methodName, new String[] { TYPE_INT });
if (method == null) {
method = this.getMethod(methodName, new String[] { TYPE_INTEGER });
}
}
}
if (method == null) {
// fourth candidate is (de)activate with two or three
// arguments (type must be BundleContext, ComponentCtx
// and Map)
// as we have to iterate now and the fifth candidate is
// zero arguments
// we already store this option
Method zeroArgMethod = null;
Method found = method;
final Method[] methods = this.container.getClassDescription().getDescribedClass().getDeclaredMethods();
int i = 0;
while (i < methods.length) {
if (methodName.equals(methods[i].getName())) {
if (methods[i].getParameterTypes() == null || methods[i].getParameterTypes().length == 0) {
zeroArgMethod = methods[i];
} else if (methods[i].getParameterTypes().length >= 2) {
boolean valid = true;
for (int m = 0; m < methods[i].getParameterTypes().length; m++) {
final String type = methods[i].getParameterTypes()[m].getName();
if (!type.equals(TYPE_BUNDLE_CONTEXT) && !type.equals(TYPE_COMPONENT_CONTEXT)
&& !type.equals(TYPE_MAP)) {
// if this is deactivate, int and
// integer are possible as well
if (isActivate || (!type.equals(TYPE_INT) && !type.equals(TYPE_INTEGER))) {
valid = false;
}
}
}
if (valid) {
if (found == null) {
found = methods[i];
} else {
// print warning
this.logWarn(this.container.getComponentDescription(), "Lifecycle method " + methods[i].getName()
+ " occurs several times with different matching signature.");
}
}
}
}
i++;
}
if (found != null) {
method = found;
} else {
method = zeroArgMethod;
}
}
}
}
}
// if no method is found, we check for any method with that name to print some warnings or errors!
if (method == null) {
final Method[] methods = this.container.getClassDescription().getDescribedClass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methodName.equals(methods[i].getName())) {
if (methods[i].getParameterTypes() == null || methods[i].getParameterTypes().length != 1) {
final String msg = "Lifecycle method " + methods[i].getName() + " has wrong number of arguments";
if ( isSpecified ) {
this.logError(container.getComponentDescription(), msg);
} else {
this.logWarn(container.getComponentDescription(), msg);
}
} else {
final String msg = "Lifecycle method " + methods[i].getName() + " has wrong argument "
+ methods[i].getParameterTypes()[0].getName();
if ( isSpecified ) {
this.logError(container.getComponentDescription(), msg);
} else {
this.logWarn(container.getComponentDescription(), msg);
}
}
}
}
}
// method must be protected for version 1.0
if (method != null && options.getSpecVersion() == SpecVersion.VERSION_1_0) {
// check protected
if (Modifier.isPublic(method.getModifiers())) {
this.logWarn(container.getComponentDescription(), "Lifecycle method " + method.getName() + " should be declared protected");
} else if (!Modifier.isProtected(method.getModifiers())) {
this.logWarn(container.getComponentDescription(), "Lifecycle method " + method.getName() +
" has wrong qualifier, public or protected required");
}
}
}
/**
* Validate the service and its interfaces
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
private void validateService(final ServiceDescription service) throws SCRDescriptorException {
for (final String interfaceName : service.getInterfaces()) {
if (this.container.getClassDescription().getDescribedClass().isInterface()) {
this.logError(service, "Must be declared in a Java class - not an interface");
} else {
try {
final Class<?> interfaceClass = project.getClassLoader().loadClass(interfaceName);
if (!interfaceClass.isAssignableFrom(this.container.getClassDescription().getDescribedClass())) {
// interface not implemented
this.logError(service, "Class must implement provided interface " + interfaceName);
}
} catch (final ClassNotFoundException cnfe) {
throw new SCRDescriptorException("Unable to load interface class.", cnfe);
}
}
}
}
/**
* Validate the property.
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
private void validateProperty(final PropertyDescription property) {
if (property.getName() == null || property.getName().trim().length() == 0) {
this.logError(property, "Property name can not be empty.");
}
if (property.getType() != null) {
// now check for old and new char
if (this.options.getSpecVersion() == SpecVersion.VERSION_1_0 && property.getType() == PropertyType.Character) {
property.setType(PropertyType.Char);
}
if (this.options.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal()
&& property.getType() == PropertyType.Char) {
property.setType(PropertyType.Character);
}
// check character property value
if ( property.getType() == PropertyType.Char || property.getType() == PropertyType.Character ) {
if ( property.getValue() != null ) {
if ( property.getValue().length() != 1 ) {
this.logError(property, "Value is not a character: " + property.getValue());
}
}
if ( property.getMultiValue() != null ) {
for(final String value : property.getMultiValue() ) {
if ( value.length() != 1 ) {
this.logError(property, "Value is not a character: " + value);
}
}
}
}
}
// TODO might want to check value
}
/**
* Validate the reference.
* If errors occur a message is added to the issues list,
* warnings can be added to the warnings list.
*/
private void validateReference(final ReferenceDescription ref, final boolean componentIsAbstract)
throws SCRDescriptorException {
final int currentIssueCount = iLog.getNumberOfErrors();
// validate name
if (StringUtils.isEmpty(ref.getName())) {
if (this.options.getSpecVersion().ordinal() < SpecVersion.VERSION_1_1.ordinal() ) {
this.logError(ref, "Reference has no name");
}
}
// validate interface
if (StringUtils.isEmpty(ref.getInterfaceName())) {
this.logError(ref, "Missing interface name");
} else {
try {
this.project.getClassLoader().loadClass(ref.getInterfaceName());
} catch (final ClassNotFoundException e) {
this.logError(ref, "Interface class can't be loaded: " + ref.getInterfaceName());
}
}
// validate cardinality
if (ref.getCardinality() == null) {
ref.setCardinality(ReferenceCardinality.MANDATORY_UNARY);
}
// validate policy
if (ref.getPolicy() == null) {
ref.setPolicy(ReferencePolicy.STATIC);
}
// validate policy option
if ( ref.getPolicyOption() == null ) {
ref.setPolicyOption(ReferencePolicyOption.RELUCTANT);
}
if ( ref.getPolicyOption() != ReferencePolicyOption.RELUCTANT ) {
if ( this.options.getSpecVersion().ordinal() < SpecVersion.VERSION_1_2.ordinal() ) {
this.logError(ref, "ReferencePolicyOption " + ref.getPolicyOption().name() +
" requires spec version " + SpecVersion.VERSION_1_2.getName() + " or higher.");
}
}
// validate strategy
if (ref.getStrategy() == null) {
ref.setStrategy(ReferenceStrategy.EVENT);
}
// validate methods only if interface name is set
if (!StringUtils.isEmpty(ref.getInterfaceName())) {
// validate bind and unbind methods
if (ref.getStrategy() != ReferenceStrategy.LOOKUP) {
String bindName = ref.getBind();
String unbindName = ref.getUnbind();
final boolean canGenerate = this.options.isGenerateAccessors() &&
ref.getField() != null
&& (ref.getCardinality() == ReferenceCardinality.OPTIONAL_UNARY || ref.getCardinality() == ReferenceCardinality.MANDATORY_UNARY);
if (bindName == null && !canGenerate ) {
bindName = "bind";
}
if (unbindName == null && !canGenerate ) {
unbindName = "unbind";
}
if ( bindName != null ) {
bindName = this.validateMethod(ref, bindName, componentIsAbstract);
if ( bindName == null && ref.getField() != null ) {
this.logError(ref, "Something went wrong: " + canGenerate + " - " + this.options.isGenerateAccessors() + " - " + ref.getCardinality());
}
} else {
bindName = "bind" + Character.toUpperCase(ref.getName().charAt(0)) + ref.getName().substring(1);
}
if ( unbindName != null ) {
if ( "-".equals(unbindName) )
{
unbindName = null;
} else {
unbindName = this.validateMethod(ref, unbindName, componentIsAbstract);
}
} else {
unbindName = "unbind" + Character.toUpperCase(ref.getName().charAt(0)) + ref.getName().substring(1);
}
// check for volatile on dynamic field reference with cardinality unary
if ( !this.options.isSkipVolatileCheck() ) {
if ( ref.getField() != null
&& (ref.getCardinality() == ReferenceCardinality.OPTIONAL_UNARY || ref.getCardinality() == ReferenceCardinality.MANDATORY_UNARY)
&& ref.getPolicy() == ReferencePolicy.DYNAMIC ) {
final boolean fieldIsVolatile = Modifier.isVolatile(ref.getField().getModifiers());
if ( ref.isBindMethodCreated() || ref.isUnbindMethodCreated() ) {
// field must be volatile
if (!fieldIsVolatile) {
this.logError(ref, "Dynamic field must be declared volatile for unary references");
}
}
}
}
if (iLog.getNumberOfErrors() == currentIssueCount) {
ref.setBind(bindName);
ref.setUnbind(unbindName);
}
} else {
ref.setBind(null);
ref.setUnbind(null);
}
// validate updated method
if (ref.getUpdated() != null) {
if (this.options.getSpecVersion().ordinal() < SpecVersion.VERSION_1_1_FELIX.ordinal()) {
this.logError(ref, "Updated method declaration requires version "
+ SpecVersion.VERSION_1_1_FELIX.getName() + ", " + SpecVersion.VERSION_1_2.getName() + " or newer");
}
this.validateMethod(ref, ref.getUpdated(), componentIsAbstract);
}
}
}
private String validateMethod(final ReferenceDescription ref, final String methodName, final boolean componentIsAbstract)
throws SCRDescriptorException {
final MethodResult result = findMethod(this.project, this.options, this.container.getClassDescription(), ref, methodName);
if (result == null) {
if (!componentIsAbstract) {
this.logError(ref,
"Missing method " + methodName + " for reference "
+ (ref.getName() == null ? "" : ref.getName()));
}
return null;
}
// method needs to be protected for 1.0
if (this.options.getSpecVersion() == SpecVersion.VERSION_1_0) {
if (Modifier.isPublic(result.method.getModifiers())) {
this.logWarn(ref, "Method " + result.method.getName() + " should be declared protected");
} else if (!Modifier.isProtected(result.method.getModifiers())) {
this.logError(ref, "Method " + result.method.getName() + " has wrong qualifier, public or protected required");
return null;
}
}
if (this.options.getSpecVersion().ordinal() < result.requiredSpecVersion.ordinal() ) {
this.logError(ref, "Method declaration for '" + result.method.getName() + "' requires version "
+ result.requiredSpecVersion + " or newer");
}
return result.method.getName();
}
private static final String TYPE_SERVICE_REFERENCE = "org.osgi.framework.ServiceReference";
private static Method getMethod(final ClassDescription cd, final String name, final Class<?>[] sig) {
Class<?> checkClass = cd.getDescribedClass();
while ( checkClass != null ) {
try {
return checkClass.getDeclaredMethod(name, sig);
} catch (final SecurityException e) {
// ignore
} catch (final NoSuchMethodException e) {
// ignore
}
checkClass = checkClass.getSuperclass();
}
return null;
}
public static final class MethodResult {
public Method method;
public SpecVersion requiredSpecVersion;
}
/**
* Find the method and the required spec version
* @throws SCRDescriptorException If the class can't be found
*/
public static MethodResult findMethod(final Project project,
final Options options,
final ClassDescription cd,
final ReferenceDescription ref,
final String methodName)
throws SCRDescriptorException {
if ( "-".equals(methodName) ) {
return null;
}
SpecVersion requiredVersion = SpecVersion.VERSION_1_0;
try {
final Class<?>[] sig = new Class<?>[] { project.getClassLoader().loadClass(TYPE_SERVICE_REFERENCE) };
final Class<?>[] sig2 = new Class<?>[] { project.getClassLoader().loadClass(ref.getInterfaceName()) };
final Class<?>[] sig3 = new Class<?>[] { project.getClassLoader().loadClass(ref.getInterfaceName()), Map.class };
// service interface or ServiceReference first
String realMethodName = methodName;
Method method = getMethod(cd, realMethodName, sig);
if (method == null) {
method = getMethod(cd, realMethodName, sig2);
if (method == null && (options.getSpecVersion() == null || options.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal()) ) {
method = getMethod(cd, realMethodName, sig3);
requiredVersion = SpecVersion.VERSION_1_1;
}
}
// append reference name with service interface and ServiceReference
if (method == null) {
final String info;
if (StringUtils.isEmpty(ref.getName())) {
final String interfaceName = ref.getInterfaceName();
final int pos = interfaceName.lastIndexOf('.');
info = interfaceName.substring(pos + 1);
} else {
info = ref.getName();
}
realMethodName = methodName + Character.toUpperCase(info.charAt(0)) + info.substring(1);
method = getMethod(cd, realMethodName, sig);
}
if (method == null) {
method = getMethod(cd, realMethodName, sig2);
if (method == null && (options.getSpecVersion() == null || options.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal()) ) {
method = getMethod(cd, realMethodName, sig3);
requiredVersion = SpecVersion.VERSION_1_1;
}
}
// append type name with service interface and ServiceReference
if (method == null) {
int lastDot = ref.getInterfaceName().lastIndexOf('.');
realMethodName = methodName + ref.getInterfaceName().substring(lastDot + 1);
method = getMethod(cd, realMethodName, sig);
}
if (method == null) {
method = getMethod(cd, realMethodName, sig2);
if (method == null && (options.getSpecVersion() == null || options.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal()) ) {
method = getMethod(cd, realMethodName, sig3);
requiredVersion = SpecVersion.VERSION_1_1;
}
}
if ( method == null ) {
return null;
}
final MethodResult result = new MethodResult();
result.method = method;
result.requiredSpecVersion = requiredVersion;
return result;
} catch (final ClassNotFoundException cnfe) {
throw new SCRDescriptorException("Unable to load class!", cnfe);
}
}
}