Examples of ObjectDescriptor


Examples of com.googlecode.mjorm.ObjectDescriptor

    if (descriptors.isEmpty()) {
      throw new MjormException("Unable to find ObjectDescriptor for "+targetClass);
    }

    // get descriptor
    ObjectDescriptor descriptor = descriptors.get(descriptors.size()-1);

    // get the discriminator name
    String discriminatorName = descriptor.getDiscriminatorName();
    Object discriminator = null;
    if (discriminatorName!=null && discriminatorName.trim().length()>0) {
      discriminator = DBObjectUtil.getNestedProperty(source, discriminatorName);
    }

    // if we have a discriminiator - figure out which
    // subclass to use
    if (discriminator!=null) {
      ObjectDescriptor subClass = descriptor.getSubClassObjectDescriptor(discriminator);
      if (subClass==null && Modifier.isAbstract(descriptor.getType().getModifiers())) {
        throw new MjormException(
          "Sublcass for discriminiator value "+discriminator
          +" was not found on abstract ObjectDescriptor for "
          + descriptor.getType().getName());
View Full Code Here

Examples of com.googlecode.mjorm.ObjectDescriptor

    String discriminatorName = entity.discriminatorName();
    DiscriminatorType discriminatorType = entity.discriminatorType();
    SubClass[] subClasses = entity.subClasses();

    // create an object descriptor
    ObjectDescriptor desc = new ObjectDescriptor();
    desc.setType(clazz);
    desc.setDiscriminatorName(discriminatorName);
    desc.setDiscriminatorType(discriminatorType.toString());

    // get BeanInfo
    BeanInfo info = ReflectionUtil.getBeanInfo(clazz);
    Map<Method, java.beans.PropertyDescriptor> methodMap
      = new HashMap<Method, java.beans.PropertyDescriptor>();
    for (java.beans.PropertyDescriptor pd : info.getPropertyDescriptors()) {
      methodMap.put(pd.getReadMethod(), pd);
      methodMap.put(pd.getWriteMethod(), pd);
    }

    // get all of the methods
    for (Method method : clazz.getMethods()) {

      // look for the annotations
      Property property = method.getAnnotation(Property.class);
      Id id = method.getAnnotation(Id.class);
      if (property==null) {
        continue;
      }

      // find pd
      java.beans.PropertyDescriptor pd = methodMap.get(method);
      if (pd==null) {
        throw new MjormException(
          method.getName()+" is not not a valid bean method.");
      }

      // "parse" data
      String propField = !property.field().equals("")
        ? property.field()
        : pd.getName();
      Type propType = !property.type().equals(void.class)
        ? property.type()
        : pd.getReadMethod().getGenericReturnType();
      Type storageType = !property.storageType().equals(void.class)
        ? property.storageType()
        : null;
      Class<?> valueGeneratorClass = !property.valueGeneratorClass().equals(void.class)
        ? property.valueGeneratorClass()
        : null;
      Type[] genericParameterTypes = property.genericParameterTypes().length>0
        ? property.genericParameterTypes()
        : new Type[0];
      boolean propIsIdentifier = (id!=null);
      boolean propIsAutoGen = (id!=null && id.autoGenerated());

      // get the hints
      Map<String, Object> hints = new HashMap<String, Object>();
      if (property.typeConversionHints()!=null) {
        for (TypeConversionHint hint : property.typeConversionHints()) {
          hints.put(hint.name(), hint.stringValue());
        }
      }

      // create the PropertyDescriptor
      PropertyDescriptor prop = new PropertyDescriptor();
      prop.setName(pd.getName());
      prop.setFieldName(propField);
      prop.setGetter(pd.getReadMethod());
      prop.setSetter(pd.getWriteMethod());
      prop.setIdentifier(propIsIdentifier);
      prop.setType(JavaType.fromType(propType));
      prop.setAutoGenerated(propIsAutoGen);
      prop.setConversionHints(hints);
      prop.setGenericParameterTypes(genericParameterTypes);
      if (propIsAutoGen) {
        ValueGenerator<?> valueGenerator = null;
        if (valueGeneratorClass==null) {
          valueGenerator = ObjectIdValueGenerator.INSTANCE;
          storageType =  ObjectId.class;
        } else {
          try {
            valueGenerator = ValueGenerator.class.cast(valueGeneratorClass.newInstance());
          } catch(Exception e) {
            throw new IllegalArgumentException(
              "Unable to create ValueGenerator for "+valueGeneratorClass.getName(), e);
          }
        }
        prop.setValueGenerator(valueGenerator);
      }

      // set the storage type
      if (storageType!=null) {
        prop.setStorageType(JavaType.fromType(storageType));
      }

      // add to descriptor
      desc.addPropertyDescriptor(prop);
    }

    // parse subclasses
    for (SubClass subClassAnot : subClasses) {

      // get discriminator value
      Object discriminatorValue = MappingUtil.parseDiscriminator(
        subClassAnot.discriminiatorValue(), discriminatorType);

      // parse sub class
      ObjectDescriptor subClass = parseClass(subClassAnot.entityClass(), descriptors);

      // add subclass
      desc.addSubClassObjectDescriptor(discriminatorValue, subClass);
      descriptors.add(subClass);
    }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public JobTestHelperBinding() {
    super("job-test-helper");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    ObjectDescriptor descriptor = new ObjectDescriptor(JobTestHelper.class);
    descriptor.addTypedInjection("commandService", CommandService.class);
    return descriptor;
  }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public RepositorySessionBinding() {
    super("repository-session");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    ObjectDescriptor objectDescriptor = new ObjectDescriptor(RepositorySessionImpl.class);
    objectDescriptor.setAutoWireEnabled(true);
    return objectDescriptor;
  }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public AddressResolverBinding() {
    super("address-resolver");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    return new ObjectDescriptor(DefaultAddressResolver.class);
  }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public ScriptManagerBinding() {
    super("script-manager");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    ObjectDescriptor descriptor = new ObjectDescriptor(ScriptManager.class);
   
    if (element.hasAttribute("default-expression-language")) {
      String defaultLanguage = element.getAttribute("default-expression-language");
      descriptor.addInjection("defaultExpressionLanguage", new StringDescriptor(defaultLanguage));
    }

    if (element.hasAttribute("default-script-language")) {
      String defaultLanguage = element.getAttribute("default-script-language");
      descriptor.addInjection("defaultScriptLanguage", new StringDescriptor(defaultLanguage));
    }

    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    List<Element> scriptElements = XmlUtil.elements(element, "script-language");
    for (Element scriptElement : scriptElements) {
      String languageName = null;
      if (scriptElement.hasAttribute("name")) {
        languageName = scriptElement.getAttribute("name");
      } else {
        parse.addProblem("'name' is a required attribute in element <script-language />", element);
      }
      String factoryClassName = null;
      if (scriptElement.hasAttribute("factory")) {
        factoryClassName = scriptElement.getAttribute("factory");
      } else {
        parse.addProblem("'name' is a required attribute in element <script-language />", element);
      }
     
      if ( (languageName!=null)
           && (factoryClassName!=null)
         ) {
        try {
          Class<?> factoryClass = ReflectUtil.loadClass(parse.getClassLoader(), factoryClassName);
          ScriptEngineFactory scriptEngineFactory = (ScriptEngineFactory) factoryClass.newInstance();
          scriptEngineManager.registerEngineName(languageName, scriptEngineFactory);
        } catch (Exception e) {
          parse.addProblem("couldn't instantiate ScriptEngineFactory "+factoryClassName, e);
        }
      }
    }
   
    descriptor.addInjection("scriptEngineManager", new ProvidedObjectDescriptor(scriptEngineManager));
   
    return descriptor;
  }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public IdentityServiceBinding() {
    super("identity-service");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    ObjectDescriptor descriptor = new ObjectDescriptor(IdentityServiceImpl.class);
    descriptor.addInjection("commandService", new ContextTypeRefDescriptor(CommandService.class));
    return descriptor;
  }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public RepositoryServiceBinding() {
    super("repository-service");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    ObjectDescriptor objectDescriptor = new ObjectDescriptor(RepositoryServiceImpl.class);
    objectDescriptor.setAutoWireEnabled(true);
    return objectDescriptor;
  }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public ManagementServiceBinding() {
    super("management-service");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    ObjectDescriptor descriptor = new ObjectDescriptor(ManagementServiceImpl.class);
    descriptor.addInjection("commandService", new ContextTypeRefDescriptor(CommandService.class));
    return descriptor;
  }
View Full Code Here

Examples of org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor

  public IdentitySessionBinding() {
    super("identity-session");
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    ObjectDescriptor objectDescriptor = new ObjectDescriptor(IdentitySessionImpl.class);
    objectDescriptor.addTypedInjection("session", Session.class);
    return objectDescriptor;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.