Example #1
0
 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("."));
   }
 }
Example #2
0
  private void loadCustomAMF3Serializer(XMap element, boolean custom) {
    XMap amf3Serializer = element.getOne("amf3-serializer");
    if (amf3Serializer != null) {
      String type = amf3Serializer.get("@type");
      try {
        Class<AMF3Serializer> amf3SerializerClass = TypeUtil.forName(type, AMF3Serializer.class);
        amf3SerializerConstructor =
            TypeUtil.getConstructor(amf3SerializerClass, new Class<?>[] {OutputStream.class});
      } catch (Exception e) {
        throw new GraniteConfigException(
            "Could not get constructor for AMF3 serializer: " + type, e);
      }
    }

    XMap amf3Deserializer = element.getOne("amf3-deserializer");
    if (amf3Deserializer != null) {
      String type = amf3Deserializer.get("@type");
      try {
        Class<AMF3Deserializer> amf3DeserializerClass =
            TypeUtil.forName(type, AMF3Deserializer.class);
        amf3DeserializerConstructor =
            TypeUtil.getConstructor(amf3DeserializerClass, new Class<?>[] {InputStream.class});
      } catch (Exception e) {
        throw new GraniteConfigException(
            "Could not get constructor for AMF3 deserializer: " + type, e);
      }
    }
  }
Example #3
0
 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));
         }
       }
     }
   }
 }
Example #4
0
  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"));
  }
Example #5
0
  private void forElement(XMap element, boolean custom, String graniteConfigProperties) {
    String scan = element.get("@scan");

    this.scan = Boolean.TRUE.toString().equals(scan);

    loadCustomAMF3Serializer(element, custom);
    loadCustomAMF3DeserializerSecurizer(element, custom);
    loadCustomAMF3MessageInterceptor(element, custom);
    loadCustomConverters(element, custom);
    loadCustomMethodMatcher(element, custom);
    loadCustomInvocationListener(element, custom);
    loadCustomInstantiators(element, custom);
    loadCustomClassGetter(element, custom);
    loadCustomExternalizers(element, custom);
    loadCustomJMFExtendedCodecs(element, custom);
    loadCustomJMFDefaultStoredStrings(element, custom);
    loadCustomJMFReflection(element, custom);
    loadCustomDescriptors(element, custom);
    loadCustomExceptionConverters(element, custom);
    loadCustomTideComponents(element, custom);
    loadCustomSecurity(element, custom);
    loadCustomMessageSelector(element, custom);
    loadCustomGravity(element, custom);
    loadCustomDistributedDataFactory(element, custom);

    if (this.scan) scanConfig(graniteConfigProperties);

    finishCustomConverters(custom);
  }
Example #6
0
 private void loadCustomAMF3DeserializerSecurizer(XMap element, boolean custom) {
   XMap securizer = element.getOne("amf3-deserializer-securizer");
   if (securizer != null) {
     String type = securizer.get("@type");
     try {
       amf3DeserializerSecurizer = (AMF3DeserializerSecurizer) TypeUtil.newInstance(type);
     } catch (Exception e) {
       throw new GraniteConfigException(
           "Could not construct amf3 deserializer securizer: " + type, e);
     }
     String param = securizer.get("@param");
     try {
       amf3DeserializerSecurizer.setParam(param);
     } catch (Exception e) {
       throw new GraniteConfigException(
           "Could not set param of amf3 deserializer securizer: " + type + ", param: " + param, e);
     }
   }
 }
Example #7
0
  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);
        }
      }
    }
  }
Example #8
0
 private void loadCustomMessageSelector(XMap element, boolean custom) {
   XMap selector = element.getOne("message-selector");
   if (selector != null) {
     String type = selector.get("@type");
     try {
       messageSelectorConstructor = TypeUtil.getConstructor(type, new Class<?>[] {String.class});
     } catch (Exception e) {
       throw new GraniteConfigException("Could not construct message selector: " + type, e);
     }
   }
 }
Example #9
0
 private void loadCustomMethodMatcher(XMap element, boolean custom) {
   XMap methodMatcher = element.getOne("method-matcher");
   if (methodMatcher != null) {
     String type = methodMatcher.get("@type");
     try {
       this.methodMatcher = (MethodMatcher) TypeUtil.newInstance(type);
     } catch (Exception e) {
       throw new GraniteConfigException("Could not construct method matcher: " + type, e);
     }
   }
 }
Example #10
0
 /** 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);
     }
   }
 }
Example #11
0
 private void loadCustomClassGetter(XMap element, boolean custom) {
   XMap classGetter = element.getOne("class-getter");
   if (classGetter != null) {
     String type = classGetter.get("@type");
     try {
       this.classGetter = (ClassGetter) TypeUtil.newInstance(type);
       classGetterSet = true;
     } catch (Exception e) {
       throw new GraniteConfigException("Could not instantiate ClassGetter: " + type, e);
     }
   }
 }
Example #12
0
 private void loadCustomAMF3MessageInterceptor(XMap element, boolean custom) {
   XMap interceptor = element.getOne("amf3-message-interceptor");
   if (interceptor != null) {
     String type = interceptor.get("@type");
     try {
       amf3MessageInterceptor = (AMF3MessageInterceptor) TypeUtil.newInstance(type);
     } catch (Exception e) {
       throw new GraniteConfigException(
           "Could not construct amf3 message interceptor: " + type, e);
     }
   }
 }
Example #13
0
 private void loadCustomDistributedDataFactory(XMap element, boolean custom) {
   XMap distributedDataFactory = element.getOne("distributed-data-factory");
   if (distributedDataFactory != null) {
     String type = distributedDataFactory.get("@type");
     try {
       this.distributedDataFactory = (DistributedDataFactory) TypeUtil.newInstance(type);
     } catch (Exception e) {
       throw new GraniteConfigException(
           "Could not construct build distributed data factory: " + type, e);
     }
   }
 }
Example #14
0
 private void loadCustomInvocationListener(XMap element, boolean custom) {
   XMap invocationListener = element.getOne("invocation-listener");
   if (invocationListener != null) {
     String type = invocationListener.get("@type");
     try {
       this.invocationListener = (ServiceInvocationListener) TypeUtil.newInstance(type);
     } catch (Exception e) {
       throw new GraniteConfigException(
           "Could not instantiate ServiceInvocationListener: " + type, e);
     }
   }
 }
Example #15
0
 /**
  * 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);
     }
   }
 }
Example #16
0
 private void loadCustomJMFReflection(XMap element, boolean custom) {
   String jmfReflection = element.get("jmf-reflection/@type");
   if (jmfReflection == null)
     this.jmfReflection = new Reflection(Thread.currentThread().getContextClassLoader());
   else {
     try {
       this.jmfReflection = (Reflection) TypeUtil.newInstance(jmfReflection);
     } catch (Exception e) {
       throw new GraniteConfigException(
           "Could not instantiate JMF reflection: " + jmfReflection, e);
     }
   }
 }
Example #17
0
  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);
      }
    }
  }
Example #18
0
  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);
          }
        }
      }
    }
  }
Example #19
0
  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);
      }
    }
  }