/** * Dereference a href and return the object if it is of the expected type. * * @return the resolved object * @param file the URI of the file in which the referenced element is located, used to absolutize * references * @param href the reference to resolve * @param clazz the class of object expected */ @SuppressWarnings("unchecked") protected <T> T dereferenceLocalHref(URI file, String href, Class<T> clazz) { Object o = null; String id = file.toString() + href.substring(href.indexOf('#')); o = idMap.get(id); if (o == null) { System.err.println(Wadl2JavaMessages.SKIPPING_REFERENCE(href, file.toString())); return null; } else if (!clazz.isInstance(o)) { System.err.println(Wadl2JavaMessages.SKIPPING_REFERENCE_TYPE(href, file.toString())); return null; } return (T) o; }
/** * Unmarshall a WADL file, process any schemas referenced in the WADL file, add any items with an * ID to a global ID map, and follow any references to additional WADL files. * * @param desc the URI of the description file * @return the unmarshalled WADL application element * @throws javax.xml.bind.JAXBException if the WADL file is invalid or if the code generator * encounters a problem. * @throws java.io.IOException if the specified WADL file cannot be read. */ public Application processDescription(URI desc) throws JAXBException, IOException { // check for files that have already been processed to prevent loops if (processedDocs.contains(desc.toString())) return null; processedDocs.add(desc.toString()); // read in WADL file System.out.println(Wadl2JavaMessages.PROCESSING(desc.toString())); Application a = (Application) u.unmarshal(desc.toURL()); // process embedded schemas Grammars g = a.getGrammars(); if (g != null) { for (Include i : g.getInclude()) { URI incl = desc.resolve(i.getHref()); if (processedDocs.contains(incl.toString())) continue; processedDocs.add(incl.toString()); System.out.println(Wadl2JavaMessages.PROCESSING(incl.toString())); InputSource input = new InputSource(incl.toURL().openStream()); input.setSystemId(incl.toString()); s2j.parseSchema(input); } int embeddedSchemaNo = 0; // used to generate unique system ID for (Object any : g.getAny()) { if (any instanceof Element) { Element element = (Element) any; s2j.parseSchema( desc.toString() + "#schema" + Integer.toString(embeddedSchemaNo), element); embeddedSchemaNo++; } } } for (File customization : customizations) { URI incl = desc.resolve(customization.toURI()); System.out.println(Wadl2JavaMessages.PROCESSING(incl.toString())); InputSource input = new InputSource(incl.toURL().openStream()); input.setSystemId(incl.toString()); s2j.parseSchema(input); } buildIDMap(a, desc); return a; }
/** * Add a type to a resource. Follow references to types across WADL file boundaries * * @param href the identifier of the resource_type element to process * @param resource the resource * @param file the URI of the current WADL file being processed */ protected void addTypeToResource(ResourceNode resource, String href, URI file) { // dereference resource if (!href.startsWith("#")) { // referecnce to element in another document file = getReferencedFile(file, href); } ResourceTypeNode n = ifaceMap.get(file.toString() + href.substring(href.indexOf('#'))); if (n != null) { resource.addResourceType(n); } else { System.err.println(Wadl2JavaMessages.SKIPPING_REFERENCE(href, file.toString())); } }
/** * Report an error. * * @param sAXParseException the exception that caused the error. */ public void error(SAXParseException sAXParseException) { System.err.println(Wadl2JavaMessages.ERROR(sAXParseException.getMessage())); }
/** * Report informative message * * @param sAXParseException the exception that caused the informative message. */ public void info(SAXParseException sAXParseException) { System.err.println(Wadl2JavaMessages.INFO(sAXParseException.getMessage())); }
/** * Report a warning * * @param sAXParseException the exception that caused the warning. */ public void warning(SAXParseException sAXParseException) { System.err.println(Wadl2JavaMessages.WARNING(sAXParseException.getMessage())); }