@Override public SequenceType[] getArgumentTypes() { SequenceType[] result = new SequenceType[xdf.getParameters().size()]; int idx = 0; for (Parameter xdp: xdf.getParameters()) { result[idx] = type2Sequence(xdp); idx++; } return result; }
@Override public StructuredQName getFunctionQName() { //return new StructuredQName(bg_schema, bg_ns, "store-document"); return new StructuredQName(xdf.getPrefix(), xdf.getClassName(), xdf.getMethod()); }
public static String getParamAnnotationType(Function fn, String pName) { String xpName = "{$" + pName + "}"; for (Map.Entry<String, List<List<String>>> ant: fn.getAnnotations().entrySet()) { for (List<String> values: ant.getValue()) { for (String val: values) { //if (pName.equals(val) || xpName.equals(val)) { if (xpName.equals(val)) { return ant.getKey(); } } } } return null; }
@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { try { Class cls = Class.forName(xdf.getClassName()); Method m = cls.getMethod(xdf.getMethod(), params); m.setAccessible(true); logger.trace("call; invoking: {}; params: {}", m, params); Object result = m.invoke(null, args2Params(arguments)); return object2Sequence(result); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new XPathException(ex); } } };
@Override public void write(ObjectDataOutput out, Function xFunc) throws IOException { out.writeUTF(xFunc.getClassName()); out.writeUTF(xFunc.getMethod()); out.writeObject(xFunc.getResult()); out.writeUTF(xFunc.getDescription()); out.writeUTF(xFunc.getPrefix()); out.writeInt(xFunc.getParameters().size()); for (Parameter xp: xFunc.getParameters()) { out.writeObject(xp); } out.writeInt(xFunc.getAnnotations().size()); for (Map.Entry<String, List<List<String>>> entry: xFunc.getAnnotations().entrySet()) { out.writeUTF(entry.getKey()); out.writeInt(entry.getValue().size()); for (List<String> values: entry.getValue()) { out.writeInt(values.size()); for (String value: values) { out.writeUTF(value); } } } }
private void buildMethod(Resource.Builder builder, Module module, Function fn) { logger.debug("buildMethod; got fn: {}", fn.getSignature()); Map<String, List<List<String>>> annotations = fn.getAnnotations(); List<List<String>> values = annotations.get(an_path); if (values != null && values.size() == 1) { int offset = query.length(); query.append(fn.getPrefix()).append(":").append(fn.getMethod()).append("("); StringBuilder params = new StringBuilder(); int cnt = 0; for (Parameter param: fn.getParameters()) { if (cnt > 0) { query.append(", ");
Function fn = rm.getFunction(); logger.debug("afterScan; processing function: {}", fn); Map<String, List<List<String>>> annotations = fn.getAnnotations(); List<String> consumes = fn.getFlatAnnotations(an_consumes); List<String> produces = fn.getFlatAnnotations(an_produces); List<String> paths = fn.getFlatAnnotations(an_path); String fullPath = base; if (!paths.isEmpty()) { op.addScheme(Scheme.HTTP); op.addScheme(Scheme.HTTPS); op.setDescription(fn.getDescription()); if (consumes != null) { op.consumes(consumes); op.produces(produces); op.setOperationId(fn.getMethod()); op.setSummary(fn.getSignature()); op.addTag(base.substring(1)); for (Parameter param: fn.getParameters()) { String pName = param.getName(); io.swagger.models.parameters.Parameter pm = null;
@Override public Function read(ObjectDataInput in) throws IOException { Function xFunc = new Function( in.readUTF(), in.readUTF(), (DataType) in.readObject(), in.readUTF(), in.readUTF()); int cnt = in.readInt(); for (int i=0; i < cnt; i++) { Parameter xp = in.readObject(); xFunc.getParameters().add(xp); } cnt = in.readInt(); for (int i=0; i < cnt; i++) { String name = in.readUTF(); int sz1 = in.readInt(); for (int j=0; j < sz1; j++) { int sz2 = in.readInt(); List<String> values = new ArrayList<>(sz2); for (int k=0; k < sz2; k++) { values.add(in.readUTF()); } xFunc.addAnnotation(name, values); } } return xFunc; }
Function xdf = new Function(className, method, resultType, description, prefix); StringTokenizer st = new StringTokenizer(args.trim(), " ,"); List<Class> clsa = new ArrayList<>(); xdf.getParameters().add(xdp);
/** * {@inheritDoc} */ public String toString() { return getSignature(); }
@Override public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) { return type2Sequence(xdf.getResult()); }
Function result = new Function(null, fn.getFunctionName().getLocalPart(), type, null, fn.getFunctionName().getPrefix()); for (UserFunctionParameter ufp: fn.getParameterDefinitions()) { Parameter param = new Parameter(ufp.getVariableQName().getLocalPart(), getTypeName(ufp.getRequiredType().getPrimaryType()), getCardinality(ufp.getRequiredType().getCardinality())); result.getParameters().add(param); result.addAnnotation(aName, values);
/** * {@inheritDoc} */ @Override public int hashCode() { return getSignature().hashCode(); }
private Class[] buildParams() throws ClassNotFoundException { Class[] result = new Class[xdf.getParameters().size()]; int idx = 0; for (Parameter xp: xdf.getParameters()) { result[idx] = ReflectUtils.type2Class(xp.getType()); idx++; } return result; }
private Properties getQueryProperties() { Properties props = new Properties(); List<List<String>> paa = fn.getAnnotations().get(apn_properties); if (paa != null) { for (List<String> properties: paa) { for (String property: properties) { int pos = property.indexOf("="); if (pos > 0) { props.setProperty(property.substring(0, pos), property.substring(pos + 1)); } } } } paa = fn.getAnnotations().get(apn_property); if (paa != null) { for (List<String> properties: paa) { if (properties.size() == 2) { props.setProperty(properties.get(0), properties.get(1)); } } } logger.debug("getQueryProperties; resolved props: {}", props); return props; }
/** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Function other = (Function) obj; return getSignature().equals(other.getSignature()); }
private Map<String, Object> getParameters(ContainerRequestContext context) { Map<String, Object> params = new HashMap<>(fn.getParameters().size()); for (Parameter pm: fn.getParameters()) { logger.trace("getParameters; processing param: {}", pm);
private void setNotFoundParam(Map<String, Object> params, String pType, Parameter pm) { // handle default values List<List<String>> atns = fn.getAnnotations().get(pType); if (atns != null) { String pName = pm.getName(); String xpName = "{$" + pm.getName() + "}"; for (List<String> values: atns) { if (values.size() > 2) { if (pName.equals(values.get(0)) || xpName.equals(values.get(1))) { params.put(pm.getName(), getAtomicValue(pm.getType(), values.get(2))); return; } } } } if (pm.getCardinality().isOptional()) { // pass empty value.. params.put(pm.getName(), null); } }
private void buildMethodHandler(Resource.Builder builder, String method, String query, Function fn) { Map<String, List<List<String>>> annotations = fn.getAnnotations(); List<List<String>> consumes = annotations.get(an_consumes); List<List<String>> produces = annotations.get(an_produces);