List of usage examples for java.util IllegalFormatException getMessage
public String getMessage()
From source file:org.openhab.persistence.http.internal.HttpPersistenceService.java
@Override public void store(Item item, String name) { if (!initialized) { return;//from w ww. j a v a 2 s . co m } if (name == null) { name = item.getName(); } Object value = null; if (forceNumeric) { value = castToDouble(item); } else { value = item.getState().toString(); } if (value != null) { try { String url = String.format(urlPattern, URLEncoder.encode(name, "UTF-8"), value, new Date()); logger.debug("Calling " + url); HttpUtil.executeUrl("GET", url, 15); } catch (UnsupportedEncodingException e) { logger.error("No UTF8 encoding avaliable.", e); } catch (IllegalFormatException ife) { logger.error("Error constructing URL using '" + urlPattern + "'. " + ife.getMessage(), ife); } } }
From source file:org.codehaus.enunciate.modules.objc.ObjCDeploymentModule.java
@Override public void initModel(EnunciateFreemarkerModel model) { super.initModel(model); if (!isDisabled() && (this.packageIdentifierPattern != null)) { for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { String pckg = typeDefinition.getPackage().getQualifiedName(); if (!this.packageIdentifiers.containsKey(pckg)) { try { this.packageIdentifiers.put(pckg, String.format(this.packageIdentifierPattern, pckg.split("\\.", 9))); } catch (IllegalFormatException e) { warn("Unable to format package %s with format pattern %s (%s)", pckg, this.packageIdentifierPattern, e.getMessage()); }/*from w w w . ja v a2s.co m*/ } } } } }
From source file:com.webcohesion.enunciate.modules.objc_client.ObjCXMLClientModule.java
@Override public void call(EnunciateContext context) { if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) { info("No JAXB XML data types: Objective-C XML client will not be generated."); return;//from www . j a v a 2 s . c om } if (usesUnmappableElements()) { warn("Web service API makes use of elements that cannot be handled by the Objective-C XML client. Objective-C XML client will not be generated."); return; } List<String> namingConflicts = JAXBErrors .findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext()); if (namingConflicts != null && !namingConflicts.isEmpty()) { error("JAXB naming conflicts have been found:"); for (String namingConflict : namingConflicts) { error(namingConflict); } error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:"); error("1. Explicitly exclude one or the other."); error("2. Put the annotations on the property instead of the field."); error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation."); throw new EnunciateException("JAXB naming conflicts detected."); } EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext(); Map<String, String> packageIdentifiers = getPackageIdentifiers(); String packageIdentifierPattern = getPackageIdentifierPattern(); if ((packageIdentifierPattern != null)) { for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { String pckg = typeDefinition.getPackage().getQualifiedName().toString(); if (!packageIdentifiers.containsKey(pckg)) { try { packageIdentifiers.put(pckg, String.format(packageIdentifierPattern, pckg.split("\\.", 9))); } catch (IllegalFormatException e) { warn("Unable to format package %s with format pattern %s (%s)", pckg, packageIdentifierPattern, e.getMessage()); } } } } } Map<String, Object> model = new HashMap<String, Object>(); String slug = getSlug(); model.put("slug", slug); File srcDir = getSourceDir(); TreeMap<String, String> translations = new TreeMap<String, String>(); translations.put("id", getTranslateIdTo()); model.put("clientSimpleName", new ClientSimpleNameMethod(translations)); List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>(); ExtensionDepthComparator comparator = new ExtensionDepthComparator(); for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator); if (position < 0) { position = -position - 1; } schemaTypes.add(position, typeDefinition); } } model.put("schemaTypes", schemaTypes); NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod( getTypeDefinitionNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers); model.put("nameForTypeDefinition", nameForTypeDefinition); model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers)); TreeMap<String, String> conversions = new TreeMap<String, String>(); for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { if (typeDefinition.isEnum()) { conversions.put(typeDefinition.getQualifiedName().toString(), "enum " + nameForTypeDefinition.calculateName(typeDefinition)); } else { conversions.put(typeDefinition.getQualifiedName().toString(), (String) nameForTypeDefinition.calculateName(typeDefinition)); } } } ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jaxbContext); model.put("classnameFor", classnameFor); model.put("functionIdentifierFor", new FunctionIdentifierForMethod(nameForTypeDefinition, jaxbContext)); model.put("objcBaseName", slug); model.put("separateCommonCode", isSeparateCommonCode()); model.put("findRootElement", new FindRootElementMethod(jaxbContext)); model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext)); model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes())); model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod()); model.put("file", new FileDirective(srcDir, this.enunciate.getLogger())); Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes()); facetIncludes.addAll(getFacetIncludes()); Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes()); facetExcludes.addAll(getFacetExcludes()); FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes); model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter)); if (!isUpToDateWithSources(srcDir)) { debug("Generating the C data structures and (de)serialization functions..."); URL apiTemplate = getTemplateURL("api.fmt"); try { processTemplate(apiTemplate, model); } catch (IOException e) { throw new EnunciateException(e); } catch (TemplateException e) { throw new EnunciateException(e); } } else { info("Skipping C code generation because everything appears up-to-date."); } ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "objc.client.library", "Objective C Client Library"); FileArtifact sourceHeader = new FileArtifact(getName(), "objc.client.h", new File(srcDir, slug + ".h")); sourceHeader.setPublic(false); sourceHeader.setArtifactType(ArtifactType.sources); FileArtifact sourceImpl = new FileArtifact(getName(), "objc.client.m", new File(srcDir, slug + ".m")); sourceImpl.setPublic(false); sourceImpl.setArtifactType(ArtifactType.sources); String description = readResource("library_description.fmt", model, nameForTypeDefinition); //read in the description from file artifactBundle.setDescription(description); artifactBundle.addArtifact(sourceHeader); artifactBundle.addArtifact(sourceImpl); if (isSeparateCommonCode()) { FileArtifact commonSourceHeader = new FileArtifact(getName(), "objc.common.client.h", new File(srcDir, "enunciate-common.h")); commonSourceHeader.setPublic(false); commonSourceHeader.setArtifactType(ArtifactType.sources); commonSourceHeader.setDescription("Common header needed for all projects."); FileArtifact commonSourceImpl = new FileArtifact(getName(), "objc.common.client.m", new File(srcDir, "enunciate-common.m")); commonSourceImpl.setPublic(false); commonSourceImpl.setArtifactType(ArtifactType.sources); commonSourceImpl.setDescription("Common implementation code needed for all projects."); artifactBundle.addArtifact(commonSourceHeader); artifactBundle.addArtifact(commonSourceImpl); } this.enunciate.addArtifact(artifactBundle); }
From source file:com.webcohesion.enunciate.modules.objc_json_client.ObjCJSONClientModule.java
@Override public void call(EnunciateContext context) { if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) { info("No JAXB XML data types: Objective-C JSON client will not be generated."); return;//from ww w .j a v a2 s . com } if (usesUnmappableElements()) { warn("Web service API makes use of elements that cannot be handled by the Objective-C XML client. Objective-C XML client will not be generated."); return; } List<String> namingConflicts = JAXBCodeErrors .findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext()); if (namingConflicts != null && !namingConflicts.isEmpty()) { error("JAXB naming conflicts have been found:"); for (String namingConflict : namingConflicts) { error(namingConflict); } error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:"); error("1. Explicitly exclude one or the other."); error("2. Put the annotations on the property instead of the field."); error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation."); throw new EnunciateException("JAXB naming conflicts detected."); } EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext(); Map<String, String> packageIdentifiers = getPackageIdentifiers(); String packageIdentifierPattern = getPackageIdentifierPattern(); if ((packageIdentifierPattern != null)) { for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { String pckg = typeDefinition.getPackage().getQualifiedName().toString(); if (!packageIdentifiers.containsKey(pckg)) { try { packageIdentifiers.put(pckg, String.format(packageIdentifierPattern, pckg.split("\\.", 9))); } catch (IllegalFormatException e) { warn("Unable to format package %s with format pattern %s (%s)", pckg, packageIdentifierPattern, e.getMessage()); } } } } } Map<String, Object> model = new HashMap<String, Object>(); String slug = getSlug(); final String objectBaseName = slug + "_objc_json_client"; model.put("slug", slug); File srcDir = getSourceDir(); // TreeMap<String, String> translations = new TreeMap<String, String>(); // translations.put("id", getTranslateIdTo()); model.put("clientSimpleName", new ClientSimpleNameMethod()); List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>(); ExtensionDepthComparator comparator = new ExtensionDepthComparator(); for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator); if (position < 0) { position = -position - 1; } schemaTypes.add(position, typeDefinition); } } model.put("schemaTypes", schemaTypes); NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod( getTypeDefinitionNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers); model.put("nameForTypeDefinition", nameForTypeDefinition); model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers)); TreeMap<String, String> conversions = new TreeMap<String, String>(); for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { if (typeDefinition.isEnum()) { // conversions.put(typeDefinition.getQualifiedName().toString(), "enum // " + nameForTypeDefinition.calculateName(typeDefinition)); conversions.put(typeDefinition.getQualifiedName().toString(), "NSString"); } else { conversions.put(typeDefinition.getQualifiedName().toString(), (String) nameForTypeDefinition.calculateName(typeDefinition)); } } } ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jaxbContext); model.put("classnameFor", classnameFor); model.put("memoryAccessTypeFor", new MemoryAccessTypeMethod()); model.put("getFieldNameTransfer", new GetFieldNameTransferMethod()); model.put("isAccessorPrimitive", new IsAccessorPrimitiveMethod()); model.put("getEnumVariablesFor", new GetEnumVariablesMethod(jaxbContext)); model.put("functionIdentifierFor", new FunctionIdentifierForMethod(nameForTypeDefinition, jaxbContext)); model.put("objcBaseName", objectBaseName); model.put("separateCommonCode", isSeparateCommonCode()); model.put("findRootElement", new FindRootElementMethod(jaxbContext)); model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext)); model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes())); model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod()); model.put("file", new FileDirective(srcDir, this.enunciate.getLogger())); Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes()); facetIncludes.addAll(getFacetIncludes()); Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes()); facetExcludes.addAll(getFacetExcludes()); FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes); model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter)); if (!isUpToDateWithSources(srcDir)) { debug("Generating the C data structures and (de)serialization functions..."); URL apiTemplate = getTemplateURL("api.fmt"); try { processTemplate(apiTemplate, model); } catch (IOException e) { throw new EnunciateException(e); } catch (TemplateException e) { throw new EnunciateException(e); } } else { info("Skipping C code generation because everything appears up-to-date."); } ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "objc.json.client.library", "Objective C JSON Client Library"); FileArtifact sourceHeader = new FileArtifact(getName(), "objc.json.client.h", new File(srcDir, objectBaseName + ".h")); sourceHeader.setPublic(false); sourceHeader.setArtifactType(ArtifactType.sources); FileArtifact sourceImpl = new FileArtifact(getName(), "objc.json.client.m", new File(srcDir, objectBaseName + ".m")); sourceImpl.setPublic(false); sourceImpl.setArtifactType(ArtifactType.sources); String description = readResource("library_description.fmt", model, nameForTypeDefinition); artifactBundle.setDescription(description); artifactBundle.addArtifact(sourceHeader); artifactBundle.addArtifact(sourceImpl); if (isSeparateCommonCode()) { // FileArtifact commonSourceHeader = new FileArtifact(getName(), // "objc.json.common.client.h", // new File(srcDir, "enunciate-json-common.h")); // commonSourceHeader.setPublic(false); // commonSourceHeader.setArtifactType(ArtifactType.sources); // commonSourceHeader.setDescription("Common header needed for all // projects."); // FileArtifact commonSourceImpl = new FileArtifact(getName(), // "objc.json.common.client.m", // new File(srcDir, "enunciate-json-common.m")); // commonSourceImpl.setPublic(false); // commonSourceImpl.setArtifactType(ArtifactType.sources); // commonSourceImpl.setDescription("Common implementation code needed for // all projects."); // artifactBundle.addArtifact(commonSourceHeader); // artifactBundle.addArtifact(commonSourceImpl); } this.enunciate.addArtifact(artifactBundle); }
From source file:edu.hawaii.soest.pacioos.text.SimpleTextSource.java
/** * Constructor: create an instance of the simple SimpleTextSource * @param xmlConfig /*from w w w . j a va 2 s . c o m*/ */ public SimpleTextSource(XMLConfiguration xmlConfig) throws ConfigurationException { this.xmlConfig = xmlConfig; // Pull the general configuration from the properties file Configuration config = new PropertiesConfiguration("textsource.properties"); this.archiveMode = config.getString("textsource.archive_mode"); this.rbnbChannelName = config.getString("textsource.rbnb_channel"); this.serverName = config.getString("textsource.server_name "); this.delimiter = config.getString("textsource.delimiter"); this.pollInterval = config.getInt("textsource.poll_interval"); this.retryInterval = config.getInt("textsource.retry_interval"); this.defaultDateFormat = new SimpleDateFormat(config.getString("textsource.default_date_format")); // parse the record delimiter from the config file // set the XML configuration in the simple text source for later use this.setConfiguration(xmlConfig); // set the common configuration fields String connectionType = this.xmlConfig.getString("connectionType"); this.setConnectionType(connectionType); String channelName = xmlConfig.getString("channelName"); this.setChannelName(channelName); String identifier = xmlConfig.getString("identifier"); this.setIdentifier(identifier); String rbnbName = xmlConfig.getString("rbnbName"); this.setRBNBClientName(rbnbName); String rbnbServer = xmlConfig.getString("rbnbServer"); this.setServerName(rbnbServer); int rbnbPort = xmlConfig.getInt("rbnbPort"); this.setServerPort(rbnbPort); int archiveMemory = xmlConfig.getInt("archiveMemory"); this.setCacheSize(archiveMemory); int archiveSize = xmlConfig.getInt("archiveSize"); this.setArchiveSize(archiveSize); // set the default channel information Object channels = xmlConfig.getList("channels.channel.name"); int totalChannels = 1; if (channels instanceof Collection) { totalChannels = ((Collection<?>) channels).size(); } // find the default channel with the ASCII data string for (int i = 0; i < totalChannels; i++) { boolean isDefaultChannel = xmlConfig.getBoolean("channels.channel(" + i + ")[@default]"); if (isDefaultChannel) { String name = xmlConfig.getString("channels.channel(" + i + ").name"); this.setChannelName(name); String dataPattern = xmlConfig.getString("channels.channel(" + i + ").dataPattern"); this.setPattern(dataPattern); String fieldDelimiter = xmlConfig.getString("channels.channel(" + i + ").fieldDelimiter"); // handle hex-encoded field delimiters if (fieldDelimiter.startsWith("0x") || fieldDelimiter.startsWith("\\x")) { Byte delimBytes = Byte.parseByte(fieldDelimiter.substring(2), 16); byte[] delimAsByteArray = new byte[] { delimBytes.byteValue() }; String delim = null; try { delim = new String(delimAsByteArray, 0, delimAsByteArray.length, "ASCII"); } catch (UnsupportedEncodingException e) { throw new ConfigurationException("There was an error parsing the field delimiter." + " The message was: " + e.getMessage()); } this.setDelimiter(delim); } else { this.setDelimiter(fieldDelimiter); } String[] recordDelimiters = xmlConfig .getStringArray("channels.channel(" + i + ").recordDelimiters"); this.setRecordDelimiters(recordDelimiters); // set the date formats list List<String> dateFormats = (List<String>) xmlConfig .getList("channels.channel(" + i + ").dateFormats.dateFormat"); if (dateFormats.size() != 0) { for (String dateFormat : dateFormats) { // validate the date format string try { SimpleDateFormat format = new SimpleDateFormat(dateFormat); } catch (IllegalFormatException ife) { String msg = "There was an error parsing the date format " + dateFormat + ". The message was: " + ife.getMessage(); if (log.isDebugEnabled()) { ife.printStackTrace(); } throw new ConfigurationException(msg); } } setDateFormats(dateFormats); } else { log.warn("No date formats have been configured for this instrument."); } // set the date fields list List<String> dateFieldList = xmlConfig.getList("channels.channel(" + i + ").dateFields.dateField"); List<Integer> dateFields = new ArrayList<Integer>(); if (dateFieldList.size() != 0) { for (String dateField : dateFieldList) { try { Integer newDateField = new Integer(dateField); dateFields.add(newDateField); } catch (NumberFormatException e) { String msg = "There was an error parsing the dateFields. The message was: " + e.getMessage(); throw new ConfigurationException(msg); } } setDateFields(dateFields); } else { log.warn("No date fields have been configured for this instrument."); } String timeZone = xmlConfig.getString("channels.channel(" + i + ").timeZone"); this.setTimezone(timeZone); break; } } // Check the record delimiters length and set the first and optionally second delim characters if (this.recordDelimiters.length == 1) { this.firstDelimiterByte = (byte) Integer.decode(this.recordDelimiters[0]).byteValue(); } else if (this.recordDelimiters.length == 2) { this.firstDelimiterByte = (byte) Integer.decode(this.recordDelimiters[0]).byteValue(); this.secondDelimiterByte = (byte) Integer.decode(this.recordDelimiters[1]).byteValue(); } else { throw new ConfigurationException("The recordDelimiter must be one or two characters, " + "separated by a pipe symbol (|) if there is more than one delimiter character."); } byte[] delimiters = new byte[] {}; }
From source file:wjhk.jupload2.policies.DefaultUploadPolicy.java
/** @see UploadPolicy#getLocalizedString(String, Object...) */ public String getLocalizedString(String key, Object... args) { String ret = this.resourceBundle.getString(key); try {//from w w w.j a v a 2 s . com // We have to recreate the correct call to String.format switch (args.length) { case 0: return String.format(ret); case 1: return String.format(ret, args[0]); case 2: return String.format(ret, args[0], args[1]); case 3: return String.format(ret, args[0], args[1], args[2]); case 4: return String.format(ret, args[0], args[1], args[2], args[3]); case 5: return String.format(ret, args[0], args[1], args[2], args[3], args[4]); case 6: return String.format(ret, args[0], args[1], args[2], args[3], args[4], args[5]); case 7: return String.format(ret, args[0], args[1], args[2], args[3], args[4], args[5], args[6]); default: throw new IllegalArgumentException( "DefaultUploadPolicy.getLocalizedString accepts up to 7 variable parameters (" + args.length + " values were given for the 'args' argument"); } } catch (IllegalFormatException ife) { displayErr(ife.getClass().getName() + " (" + ife.getMessage() + ")when managing this string: " + ret); throw ife; } }