private static Constant qnameConstant(final GeneratedTypeBuilderBase<?> toBuilder, final String constantName, final QName name) { final StringBuilder sb = new StringBuilder(QNAME_FQCN); sb.append(".cachedReference("); sb.append(QNAME_FQCN); sb.append(".create("); sb.append('"'); sb.append(name.getNamespace()); sb.append("\",\""); sb.append(name.getFormattedRevision()); sb.append("\",\""); sb.append(name.getLocalName()); sb.append("\"))"); return toBuilder.addConstant(typeForClass(QName.class), constantName, sb.toString()); }
@Override public SourceIdentifier apply(final QName input) { return new SourceIdentifier(input.getLocalName(), Optional.fromNullable(input.getFormattedRevision())); } };
public static Annotation createModuleQNameANnotation(QName qName) { Map<String, String> parameters = new HashMap<>(); parameters.put("namespace", q(qName.getNamespace().toString())); parameters.put("revision", q(qName.getFormattedRevision())); parameters.put("name", q(qName.getLocalName())); return Annotation.createFromMap(ModuleQName.class, parameters); }
private static Optional<DataNodeContainer> findFirstDataNodeContainerInRpc(final SchemaContext ctx, final Class<? extends DataObject> targetType) { final YangModuleInfo moduleInfo; try { moduleInfo = BindingReflections.getModuleInfo(targetType); } catch (Exception e) { throw new IllegalArgumentException( String.format("Failed to load module information for class %s", targetType), e); } for(RpcDefinition rpc : ctx.getOperations()) { String rpcNamespace = rpc.getQName().getNamespace().toString(); String rpcRevision = rpc.getQName().getFormattedRevision(); if(moduleInfo.getNamespace().equals(rpcNamespace) && moduleInfo.getRevision().equals(rpcRevision)) { Optional<DataNodeContainer> potential = findInputOutput(rpc,targetType.getSimpleName()); if(potential.isPresent()) { return potential; } } } return Optional.absent(); }
@Override protected void writeQName(final QName qname) throws IOException { writeString(qname.getLocalName()); writeString(qname.getNamespace().toString()); writeString(qname.getFormattedRevision()); }
private QName getQNameFromSourceIdentifier(final SourceIdentifier identifier) { // Required sources are all required and provided merged in DeviceSourcesResolver for (final QName qname : deviceSources.getRequiredSourcesQName()) { if(qname.getLocalName().equals(identifier.getName()) == false) { continue; } if(identifier.getRevision().equals(SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION) && qname.getRevision() == null) { return qname; } if (qname.getFormattedRevision().equals(identifier.getRevision())) { return qname; } } throw new IllegalArgumentException("Unable to map identifier to a devices reported capability: " + identifier + " Available: " + deviceSources.getRequiredSourcesQName()); } }
public static Collection<Annotation> createSieAnnotations(ServiceInterfaceEntry sie){ String exportedClassName = sie.getExportedOsgiClassName(); Preconditions.checkNotNull(sie.getQName(), "Cannot create annotation from null qname"); Preconditions.checkNotNull(exportedClassName, "Cannot create annotation from null exportedClassName"); List<Annotation> result = new ArrayList<>(); { List<Parameter> params = Lists.newArrayList(new Parameter("value", q(sie.getQName().toString()))); params.add(new Parameter("osgiRegistrationType", exportedClassName + ".class")); params.add(new Parameter("registerToOsgi", Boolean.toString(sie.isRegisterToOsgi()))); params.add(new Parameter("namespace", q(sie.getQName().getNamespace().toString()))); params.add(new Parameter("revision", q(sie.getQName().getFormattedRevision()))); params.add(new Parameter("localName", q(sie.getQName().getLocalName()))); Annotation sieAnnotation = new Annotation(ServiceInterfaceAnnotation.class.getCanonicalName(), params); result.add(sieAnnotation); } { List<Parameter> params = new ArrayList<>(); params.add(new Parameter("namespace", q(sie.getYangModuleQName().getNamespace().toString()))); params.add(new Parameter("revision", q(sie.getYangModuleQName().getFormattedRevision()))); params.add(new Parameter("name", q(sie.getYangModuleQName().getLocalName()))); Annotation moduleQNameAnnotation = new Annotation(ModuleQName.class.getCanonicalName(), params); result.add(moduleQNameAnnotation); } return result; }