/** * Read custom class descriptors. Descriptor must have 'type' or 'instanceof' attribute and one of * 'java' or 'as3' attributes specified. */ private void loadCustomDescriptors(XMap element, boolean custom) { for (XMap descriptor : element.getAll("descriptors/descriptor")) { String type = descriptor.get("@type"); if (type != null) { String java = descriptor.get("@java"); String as3 = descriptor.get("@as3"); if (java == null && as3 == null) throw new GraniteConfigException( "Element 'descriptor' has no attributes 'java' or 'as3'\n" + descriptor); if (java != null) javaDescriptorsByType.put(type, JC_DESCRIPTOR_FACTORY.getInstance(java, this)); if (as3 != null) as3DescriptorsByType.put(type, ASC_DESCRIPTOR_FACTORY.getInstance(as3, this)); } else { String instanceOf = descriptor.get("@instance-of"); if (instanceOf == null) throw new GraniteConfigException( "Element 'descriptor' has no attribute 'type' or 'instance-of'\n" + descriptor); String java = descriptor.get("@java"); String as3 = descriptor.get("@as3"); if (java == null && as3 == null) { throw new GraniteConfigException( "Element 'descriptor' has no attributes 'java' or 'as3' in:\n" + descriptor); } if (java != null) javaDescriptorsByInstanceOf.put(instanceOf, java); if (as3 != null) as3DescriptorsByInstanceOf.put(instanceOf, as3); } } }
private void loadCustomInstantiators(XMap element, boolean custom) { XMap instantiators = element.getOne("instantiators"); if (instantiators != null) { for (XMap instantiator : instantiators.getAll("instantiator")) this.instantiators.put(instantiator.get("@type"), instantiator.get(".")); } }
private void loadCustomTideComponents(XMap element, boolean custom) { for (XMap component : element.getAll("tide-components/tide-component")) { boolean disabled = Boolean.TRUE.toString().equals(component.get("@disabled")); String type = component.get("@type"); if (type != null) tideComponentMatchers.add(TIDE_COMPONENT_MATCHER_FACTORY.getTypeMatcher(type, disabled)); else { String name = component.get("@name"); if (name != null) tideComponentMatchers.add(TIDE_COMPONENT_MATCHER_FACTORY.getNameMatcher(name, disabled)); else { String instanceOf = component.get("@instance-of"); if (instanceOf != null) tideComponentMatchers.add( TIDE_COMPONENT_MATCHER_FACTORY.getInstanceOfMatcher(instanceOf, disabled)); else { String annotatedWith = component.get("@annotated-with"); if (annotatedWith == null) throw new GraniteConfigException( "Element 'component' has no attribute 'type', 'name', 'instance-of' or 'annotated-with'"); tideComponentMatchers.add( TIDE_COMPONENT_MATCHER_FACTORY.getAnnotatedWithMatcher(annotatedWith, disabled)); } } } } }
/** Read custom class exception converters Converter must have 'type' attribute */ private void loadCustomExceptionConverters(XMap element, boolean custom) { for (XMap exceptionConverter : element.getAll("exception-converters/exception-converter")) { String type = exceptionConverter.get("@type"); ExceptionConverter converter = null; try { converter = (ExceptionConverter) TypeUtil.newInstance(type); exceptionConverters.add(converter); } catch (Exception e) { throw new GraniteConfigException("Could not construct exception converter: " + type, e); } } }
private void loadCustomJMFDefaultStoredStrings(XMap element, boolean custom) { String jmfDefaultStoredStringsMode = element.get("jmf-default-stored-strings/@mode"); if (jmfDefaultStoredStringsMode != null) { try { this.jmfDefaultStoredStringsMode = JMF_EXTENSIONS_MODE.valueOf(jmfDefaultStoredStringsMode.toLowerCase()); } catch (Exception e) { throw new GraniteConfigException( "Illegal JMF default stored strings mode: " + jmfDefaultStoredStringsMode, e); } } for (XMap codec : element.getAll("jmf-default-stored-strings/jmf-default-stored-string")) jmfDefaultStoredStrings.add(codec.get("@value")); }
private void loadCustomExternalizers(XMap element, boolean custom) { externalizersConfiguration = element.getOne("externalizers/configuration"); for (XMap externalizer : element.getAll("externalizers/externalizer")) { String externalizerType = externalizer.get("@type"); for (XMap include : externalizer.getAll("include")) { String type = include.get("@type"); if (type != null) externalizersByType.put(type, EXTERNALIZER_FACTORY.getInstance(externalizerType, this)); else { String instanceOf = include.get("@instance-of"); if (instanceOf != null) externalizersByInstanceOf.put(instanceOf, externalizerType); else { String annotatedWith = include.get("@annotated-with"); if (annotatedWith == null) throw new GraniteConfigException( "Element 'include' has no attribute 'type', 'instance-of' or 'annotated-with'"); externalizersByAnnotatedWith.put(annotatedWith, externalizerType); } } } } }
private void loadCustomConverters(XMap element, boolean custom) { XMap converters = element.getOne("converters"); if (converters != null) { // Should we override standard config converters? String override = converters.get("@override"); if (Boolean.TRUE.toString().equals(override)) converterClasses.clear(); int i = 0; for (XMap converter : converters.getAll("converter")) { String type = converter.get("@type"); try { // For custom config, shifts any standard converters to the end of the list... converterClasses.add(i++, TypeUtil.forName(type, Converter.class)); } catch (Exception e) { throw new GraniteConfigException("Could not get converter class for: " + type, e); } } } }
private void loadCustomJMFExtendedCodecs(XMap element, boolean custom) { String jmfExtendedCodecsMode = element.get("jmf-extended-codecs/@mode"); if (jmfExtendedCodecsMode != null) { try { this.jmfExtendedCodecsMode = JMF_EXTENSIONS_MODE.valueOf(jmfExtendedCodecsMode.toLowerCase()); } catch (Exception e) { throw new GraniteConfigException( "Illegal JMF extended codecs mode: " + jmfExtendedCodecsMode, e); } } for (XMap codec : element.getAll("jmf-extended-codecs/jmf-extended-codec")) { String codecType = codec.get("@type"); try { jmfExtendedCodecs.add((ExtendedObjectCodec) TypeUtil.newInstance(codecType)); } catch (Exception e) { throw new GraniteConfigException( "Could not instantiate JMF extended codec: " + codecType, e); } } }
private void loadCustomSecurity(XMap element, boolean custom) { XMap security = element.getOne("security"); if (security != null) { String type = security.get("@type"); try { securityService = (SecurityService) TypeUtil.newInstance(type); } catch (Exception e) { throw new GraniteConfigException("Could not instantiate SecurityService: " + type, e); } Map<String, String> params = new HashMap<String, String>(); for (XMap param : security.getAll("param")) { String name = param.get("@name"); String value = param.get("@value"); params.put(name, value); } try { securityService.configure(params); } catch (Exception e) { throw new GraniteConfigException( "Could not configure SecurityService " + type + " with: " + params, e); } } }