/** * Generates a property descriptor of type {@link PropertyType#String} */ private void generateStringPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, final boolean metatype, String annotationName, String propertyDescriptorName) { final String[] values = (String[]) cad.getValue(annotationName); if (values == null) { return; } final PropertyDescription pd = new PropertyDescription(cad); pd.setName(propertyDescriptorName); pd.setMultiValue(values); pd.setType(PropertyType.String); if (metatype) { pd.setPrivate(true); } classDescription.add(pd); }
final ReferenceDescription ref = new ReferenceDescription(ad); if (ad instanceof FieldAnnotation) { fieldAnnotation = (FieldAnnotation) ad; ref.setField(fieldAnnotation.getAnnotatedField()); } else { fieldAnnotation = null; ref.setName(ad.getStringValue("name", (fieldAnnotation != null ? fieldAnnotation.getAnnotatedField().getName() : null))); String defaultInterfaceName = null; ref.setInterfaceName(ad.getStringValue("referenceInterface", defaultInterfaceName)); ref.setTarget(ad.getStringValue("target", null)); ref.setCardinality(ReferenceCardinality.valueOf(ad.getEnumValue("cardinality", ReferenceCardinality.MANDATORY_UNARY.name()))); ref.setPolicy(ReferencePolicy.valueOf(ad.getEnumValue("policy", ReferencePolicy.STATIC.name()))); ref.setPolicyOption(ReferencePolicyOption.valueOf(ad.getEnumValue("policyOption", ReferencePolicyOption.RELUCTANT.name()))); ref.setStrategy(ReferenceStrategy.valueOf(ad.getEnumValue("strategy", ReferenceStrategy.EVENT.name()))); ref.setBind(ad.getStringValue("bind", null)); ref.setUnbind(ad.getStringValue("unbind", null)); ref.setUpdated(ad.getStringValue("updated", null)); describedClass.add(ref);
final ComponentDescription cd = new ComponentDescription(cad); cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName())); cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL); cd.setLabel(cad.getStringValue("label", null)); cd.setDescription(cad.getStringValue("description", null)); cd.setCreateMetatype(metatype); classDescription.add(cd); final ServiceDescription sd = new ServiceDescription(cad); sd.addInterface("javax.servlet.Filter"); classDescription.add(sd); final PropertyDescription pd = new PropertyDescription(cad); pd.setName("service.ranking"); pd.setValue(String.valueOf(order)); pd.setType(PropertyType.Integer); if (metatype) { pd.setPrivate(true); classDescription.add(pd); final PropertyDescription pdPattern = new PropertyDescription(cad); pdPattern.setName("sling.filter.pattern"); pdPattern.setValue(pattern); pdPattern.setType(PropertyType.String); if (metatype) {
throws SCRDescriptorFailureException, SCRDescriptorException { for (final ScannedAnnotation ad : descs) { final PropertyDescription prop = new PropertyDescription(ad); prop.setType(PropertyType.valueOf(type)); if (values.length == 1) { prop.setValue(values[0]); } else { prop.setMultiValue(values); prop.setMultiValue(newValues); prop.setType(PropertyType.from(fieldAnnotation.getAnnotatedField().getType().getComponentType())); } else { prop.setType(PropertyType.from(value.getClass())); prop.setValue(value.toString()); prop.setMultiValue(newValues); prop.setType(PropertyType.from(fieldAnnotation.getAnnotatedField().getType().getComponentType())); } else { prop.setType(PropertyType.from(value.getClass())); prop.setValue(value.toString()); prop.setName(name); prop.setLabel(ad.getStringValue("label", null)); prop.setDescription(ad.getStringValue("description", null)); if ( prop.getType() == null ) { prop.setType(PropertyType.String);
final ComponentDescription component = new ComponentDescription(cad); final boolean classIsAbstract = Modifier.isAbstract(scannedClass.getScannedClass().getModifiers()); component.setAbstract(cad.getBooleanValue("componentAbstract", classIsAbstract)); component.setCreatePid(false); // always set to false component.setName(cad.getStringValue("name", scannedClass.getScannedClass().getName())); component.setLabel(cad.getStringValue("label", null)); component.setDescription(cad.getStringValue("description", null)); component.setCreateDs(cad.getBooleanValue("ds", true)); component.setCreateMetatype(cad.getBooleanValue("metatype", false)); component.setEnabled(cad.getBooleanValue("enabled", true)); component.setSpecVersion(SpecVersion.fromName(cad.getValue("specVersion").toString())); component.setFactory(cad.getStringValue("factory", null)); component.setImmediate(cad.getBooleanValue("immediate", false)); component.setInherit(cad.getBooleanValue("inherit", true)); component.setConfigurationPolicy(ComponentConfigurationPolicy.valueOf(cad.getEnumValue("policy", ComponentConfigurationPolicy.OPTIONAL.name()))); component.setSetMetatypeFactoryPid(cad.getBooleanValue("configurationFactory", false)); component.setConfigurationPid(cad.getStringValue("configurationPid", null));
final ComponentDescription cd = new ComponentDescription(cad); cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName())); cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL); cd.setLabel(cad.getStringValue("label", null)); cd.setDescription(cad.getStringValue("description", null)); cd.setCreateMetatype(metatype); cd.setCreatePid(false); // always set to false classDescription.add(cd); final ServiceDescription sd = new ServiceDescription(cad); sd.addInterface("javax.servlet.Servlet"); classDescription.add(sd);
describedClass.add(createComponent(cad, scannedClass)); final List<ComponentDescription> componentDescs = describedClass.getDescriptions(ComponentDescription.class); ComponentDescription found = null; if (!componentDescs.isEmpty()) { for (final MethodAnnotation m : methodTags) { if (m.getName().equals(Activate.class.getName())) { cd.setActivate(m.getAnnotatedMethod().getName()); scannedClass.processed(m); } else if (m.getName().equals(Deactivate.class.getName())) { cd.setDeactivate(m.getAnnotatedMethod().getName()); scannedClass.processed(m); } else if (m.getName().equals(Modified.class.getName())) { cd.setModified(m.getAnnotatedMethod().getName()); scannedClass.processed(m); describedClass.add(createService(allServiceTags, scannedClass));
final ServiceDescription service = new ServiceDescription(descs.get(0)); service.setServiceFactory(true); service.addInterface(i);
@Override public AbstractDescription clone() { final ServiceDescription cd = new ServiceDescription(this.annotation); cd.setServiceFactory(this.isServiceFactory); for(final String i : this.getInterfaces()) { cd.addInterface(i); } return cd; } }
DFAgentDescription template = new DFAgentDescription(); ServiceDescription sd= new ServiceDescription(); sd.setType(Service); sd.setName(agentName); template.addServices(sd); try { DFAgentDescription[] result = DFService.search(this, template); listAgents.clear(); for(int i = 0; i<result.length;++i) { listAgents.addElement(result[i].getName()); } //System.out.println(listAgents); } catch (FIPAException e) { // TODO Auto-generated catch block e.printStackTrace(); log(this.getAID() +"!!error in requesting service ="+Service); } return (AID) listAgents.get(0);
public ClassDescription clone() { final ClassDescription cd = new ClassDescription(this.describedClass, this.source); for(final AbstractDescription ad : this.descriptions) { cd.add(ad.clone()); } return cd; } }
/** * Recursively add interfaces to the service. */ private void addInterfaces(final ServiceDescription service, final Class<?> javaClass) { if (javaClass != null) { final Class<?>[] interfaces = javaClass.getInterfaces(); for (final Class<?> i : interfaces) { service.addInterface(i.getName()); // recursivly add interfaces implemented by this interface this.addInterfaces(service, i); } // try super class this.addInterfaces(service, javaClass.getSuperclass()); } }
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 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; }
/** * Get the first description of that type * @param descType The description class * @return THe first description or <code>null</code> */ public <T extends AbstractDescription> T getDescription(final Class<T> descType) { final List<T> result = this.getDescriptions(descType); if ( result.size() > 0 ) { return result.get(0); } return null; }
@Override public String getIdentifier() { if ( this.getField() != null ) { return super.getIdentifier() + "(" + this.getField().getName() + ")"; } return super.getIdentifier(); }
public static ReferenceCardinality fromValue(final String value) { for(final ReferenceCardinality rd : ReferenceCardinality.values() ) { if ( rd.getCardinalityString().equals(value) ) { return rd; } } return null; } }
/** * Add a new description */ public void add(final AbstractDescription desc) { this.descriptions.add(desc); desc.setSource(this.source); }
protected void setup() { ... // Register the book-selling service in the yellow pages DFAgentDescription dfd = new DFAgentDescription(); dfd.setName(getAID()); ServiceDescription sd = new ServiceDescription(); sd.setType("book-selling"); sd.setName("JADE-book-trading"); dfd.addServices(sd); try { DFService.register(this, dfd); } catch (FIPAException fe) { fe.printStackTrace(); } ... }
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); } }