Examples of ClassModel


Examples of net.jangaroo.jooc.model.ClassModel

  public static String capitalize(String name) {
    return name == null || name.length() == 0 ? name : Character.toUpperCase(name.charAt(0)) + name.substring(1);
  }

  private static String generateEventClass(CompilationUnitModel compilationUnitModel, Event event) {
    ClassModel classModel = compilationUnitModel.getClassModel();
    String eventTypeQName = CompilerUtils.qName(compilationUnitModel.getPackage(),
            "events." + classModel.getName() + capitalize(event.name) + "Event");
    CompilationUnitModel extAsClassUnit = createClassModel(eventTypeQName);
    ClassModel extAsClass = (ClassModel)extAsClassUnit.getPrimaryDeclaration();
    extAsClass.setAsdoc(toAsDoc(event.doc) + "\n * @see " + compilationUnitModel.getQName());

    FieldModel eventNameConstant = new FieldModel("NAME", "String", CompilerUtils.quote(event.name));
    eventNameConstant.setStatic(true);
    eventNameConstant.setAsdoc(MessageFormat.format("This constant defines the value of the <code>type</code> property of the event object\nfor a <code>{0}</code> event.\n   * @eventType {0}", event.name));
    extAsClass.addMember(eventNameConstant);

    MethodModel constructorModel = extAsClass.createConstructor();
    constructorModel.addParam(new ParamModel("arguments", "Array"));
    StringBuilder propertyAssignments = new StringBuilder();
    for (int i = 0; i < event.params.size(); i++) {
      Param param = event.params.get(i);

      // add assignment to constructor body:
      if (i > 0) {
        propertyAssignments.append("\n    ");
      }
      propertyAssignments.append(String.format("this['%s'] = arguments[%d];", convertName(param.name), i));

      // add getter method:
      MethodModel property = new MethodModel(MethodType.GET, convertName(param.name), convertType(param.type));
      property.setAsdoc(toAsDoc(param.doc));
      extAsClass.addMember(property);
    }

    constructorModel.setBody(propertyAssignments.toString());

    return eventTypeQName;
View Full Code Here

Examples of net.jangaroo.jooc.model.ClassModel

    }
  }

  @Override
  public void visitClassDeclaration(ClassDeclaration classDeclaration) throws IOException {
    ClassModel classModel = new ClassModel();
    getCurrent(CompilationUnitModel.class).setPrimaryDeclaration(classModel);
    modelStack.push(classModel);
    recordAsdoc(classDeclaration);
    recordAsdoc(classDeclaration.getSymClass());
    consumeRecordedAsdoc();
    classModel.setFinal(classDeclaration.isFinal());
    classModel.setDynamic(classDeclaration.isDynamic());
    generateVisibility(classDeclaration);
    consumeRecordedAnnotations();
    handleExcludeClassByDefault(classModel);
    classDeclaration.getIde().visit(this);
    classModel.setInterface(classDeclaration.isInterface());
    visitIfNotNull(classDeclaration.getOptExtends());
    visitIfNotNull(classDeclaration.getOptImplements());
    classDeclaration.getBody().visit(this);
    modelStack.pop();
  }
View Full Code Here

Examples of net.jangaroo.jooc.model.ClassModel

    return string == null || string.trim().length() == 0;
  }

  public static void main(String[] args) {
    // TODO: move to unit test!
    ClassModel classModel = new ClassModel("com.acme.Foo");
    classModel.setAsdoc("This is the Foo class.");

    AnnotationModel annotation = new AnnotationModel("ExtConfig",
      new AnnotationPropertyModel("target", "'foo.Bar'"));
    classModel.addAnnotation(annotation);

    FieldModel field = new FieldModel("FOOBAR");
    field.setType("String");
    field.setConst(true);
    field.setStatic(true);
    field.setNamespace(NamespacedModel.PRIVATE);
    field.setAsdoc("A constant for foo bar.");
    field.setValue("'foo bar baz'");
    classModel.addMember(field);

    MethodModel method = new MethodModel();
    method.setName("doFoo");
    method.setAsdoc("Some method.");
    method.setBody("trace('foo');");
    ParamModel param = new ParamModel();
    param.setName("foo");
    param.setType("com.acme.sub.Bar");
    param.setValue("null");
    method.setParams(Collections.singletonList(param));
    method.setType("int");
    classModel.addMember(method);

    PropertyModel propertyModel = new PropertyModel();
    propertyModel.setName("baz");
    propertyModel.setType("String");
    propertyModel.setAsdoc("The baz is a string.");
    classModel.addMember(propertyModel);

    StringWriter stringWriter = new StringWriter();
    classModel.visit(new ActionScriptCodeGeneratingModelVisitor(stringWriter));
    System.out.println("Result:\n" + stringWriter);
  }
View Full Code Here

Examples of org.byteliberi.easydriver.generator.model.ClassModel

      final String structureName = Utils.getCamelNameFirstCapital(tableName);
      final String className = structureName + "ObjectModel";
      final PrintStream out = new PrintStream( Utils.getCamelNameFirstCapital(dirPath + className + ".java"), "UTF-8" );
      Logger.getLogger(ObjectModelGeneration.class.getName()).info("Working on: " + tableName);
       
      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  className, false);
      classModel.setPackageName(this.packageName);
     
      // Let's look for the foreign keys and let's add the properties
      final Map<String, String> fks = addExternalClasses(tableInfo, classModel);
         
      // There can be more than one field for just one external table.
      // Let's group by the Class name, saving just the first column name.
      final HashSet<String> usedClasses = new HashSet<String>();
      final Set<Entry<String,String>> fksEntries = fks.entrySet();
      for (Entry<String, String> fksEntry : fksEntries) {
        final String examinedClass = Utils.getCamelNameFirstCapital( fksEntry.getValue() ) + "ObjectModel";
        if (!usedClasses.contains(examinedClass)) {
          usedClasses.add(examinedClass);
          classModel.addProperty(new PropertyModel(Visibility.PRIVATE, examinedClass, fksEntry.getKey()));
        }
      }
     
      // Let's add the properties for the columns
      for (PropertyModel prop : tableInfo.getProperties()) {
        if (!fks.containsKey(prop.getName()))
          classModel.addProperty(prop);
      }
     
      final List<PropertyModel> primaryKeys = new LinkedList<PropertyModel>();
      final List<PropertyModel> presentProps = classModel.getProperties();
      for(PropertyModel primaryKey : tableInfo.getPrimaryKey()) {
        final String key = primaryKey.getName();
        for (PropertyModel presentProp : presentProps) {
           if (presentProp.getName().equals(key)) {
             primaryKeys.add(new PropertyModel(Visibility.PRIVATE, presentProp.getPropertyClass(), key));
           }
        }
      }
     
      classModel.setConstructorGenerator(new PrimaryKeyConstructor(className, primaryKeys));
     
      // Getters
      classModel.createGetters();
      // Setters
      classModel.createSetters();
     
      classModel.write(out);
      out.flush();
      out.close();
    }       
  }   
View Full Code Here

Examples of org.byteliberi.easydriver.generator.model.ClassModel

      final String className = objectModelName + "Factory";
      final PrintStream out = new PrintStream( Utils.getCamelNameFirstCapital(dirPath + className + ".java"), "UTF-8" );
           
      Logger.getLogger(ObjectModelGeneration.class.getName()).info("Working on: " + tableName);

      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  className);
      classModel.setPackageName(this.packageName);       
      classModel.addImport("java.sql.ResultSet");
      classModel.addImport("java.sql.SQLException");
      classModel.addImport("org.byteliberi.easydriver.ObjectFactory");
      classModel.setImplementList(MessageFormat.format("ObjectFactory<{0}>", objectModelName));
     
      classModel.addMethod(new MapRS(objectModelName, structureName, findFieldInit(tableInfo)));
     
      classModel.write(out);
      out.flush();
      out.close();
    }
  }
View Full Code Here

Examples of org.byteliberi.easydriver.generator.model.ClassModel

      final String structureName = Utils.getCamelNameFirstCapital(tableName);
      final String className = structureName + "Service";
      final PrintStream out = new PrintStream( Utils.getCamelNameFirstCapital(dirPath + className + ".java"), "UTF-8" );
      final String objectModelName = structureName + OBJECT_MODEL;
           
      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  className);
      classModel.setPackageName(this.packageName);
      classModel.addImport("java.sql.Connection");
      classModel.addImport("java.sql.SQLException");
      classModel.addImport("org.byteliberi.easydriver.*");
      classModel.addImport("org.byteliberi.easydriver.fields.*");
      classModel.addImport("org.byteliberi.easydriver.expressions.*");
     
       
      classModel.addMethod(new SelectByPKMethod(tableInfo.getPrimaryKey(), structureName, objectModelName));
      classModel.addMethod(new DeleteMethod(tableInfo.getPrimaryKey(), structureName));
      classModel.addMethod(new InsertMethod(tableInfo.getFields(), structureName, objectModelName, tableInfo));
      classModel.addMethod(new UpdateMethod(tableInfo.getFields(), tableInfo.getPrimaryKey(), structureName, objectModelName, tableInfo));
       
      classModel.write(out);
      out.flush();
      out.close();
   
  }
View Full Code Here

Examples of org.byteliberi.easydriver.generator.model.ClassModel

      final String tableName = tableInfo.getTableName();
      final PrintStream out = new PrintStream( dirPath + Utils.getCamelNameFirstCapital(tableName) + ".java", "UTF-8" );
     
      logger.info("Working on: " + tableName);

      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  tableName, true);
       
      classModel.setEnumList("INSTANCE");
      classModel.setPackageName(this.packageName);
      classModel.addImport("org.byteliberi.easydriver.*")
      classModel.addImport("org.byteliberi.easydriver.fields.*");
     
      classModel.addProperty(new PropertyModel(Visibility.PRIVATE, DBTable.class.getSimpleName(), "table"));

      // Let's look for the fields       
      final List<FieldPropertyAssociation> fieldAssoc = tableInfo.getFields();
      final HashSet<String> usedFields = new HashSet<String>();
     
      for (FieldPropertyAssociation fa : fieldAssoc) {
        final String fieldName = fa.getFieldName();
        if (!usedFields.contains(fieldName)) {
          classModel.addProperty(fa.getProp());
          usedFields.add(fieldName);
        }
      }
       
      // Let's look for the relationships
      final Collection<List<RelationModel>> rels = tableInfo.getRelationships();
      // Now we add the properties for the relationships that we have found         
     
      final HashSet<String> ext = new HashSet<String>();
      if ((rels != null) && (rels.size() > 0)) {
        Iterator<List<RelationModel>> relsIterator = rels.iterator();
        while (relsIterator.hasNext()) {
          final List<RelationModel> relList = relsIterator.next();
          if (relList.size() > 0) {
            final String oneTable = relList.get(0).getOneTable();
            ext.add(oneTable);
          }
        }       
      } 
     
      for (String name : ext) {
        classModel.addProperty(new PropertyModel(Visibility.PRIVATE,
                             ManyToOne.class.getSimpleName(),
                             "fk" + Utils.getCamelNameFirstCapital(name)));
      }
       
      classModel.setConstructorGenerator(new TableStructureConstructor(tableName, fieldAssoc, rels, tableInfo.getPrimaryKey()));

      classModel.createGetters();
      classModel.write(out);
      out.flush();
      out.close();
   
  } 
View Full Code Here

Examples of org.fluxtream.core.mvc.models.ClassModel

            if (className == null)
                throw new ClassNotFoundException();
            List<ClassModel> list = new ArrayList<ClassModel>();
            Iterator<Model> i = ModelConverters.readAll(Class.forName(className)).iterator();
            while (i.hasNext())
                list.add(new ClassModel(i.next()));
            for (ClassModel model : list){
                if (model.qualifiedType.equals(className))
                    return Response.ok(model).build();
            }
            throw new ClassNotFoundException();
View Full Code Here

Examples of org.milyn.ejc.ClassModel

    public static final String ORG_SMOOKS_EJC_TEST = "org.smooks.ejc.test";

    public static void dumpModel(InputStream mappingModel) throws EDIConfigurationException, ClassNotFoundException, IOException, SAXException, IllegalNameException {
        EJC ejc = new EJC();

        ClassModel model = ejc.compile(mappingModel, ORG_SMOOKS_EJC_TEST);

        Writer writer = new PrintWriter(System.out);
        BeanWriter.writeBeans(model, writer);
        BindingWriter.writeBindingConfig(model, writer);
    }
View Full Code Here

Examples of org.platformlayer.model.ClassModel

  }

  private void processClassRequestFactory(Class<?> clazz) throws MojoExecutionException {
    Map<String, Object> model = new HashMap<String, Object>();

    ClassModel classModel = new ClassModel();
    classModel.className = clazz.getSimpleName();
    classModel.proxyClassName = classModel.className + "Proxy";
    classModel.serviceClassName = classModel.className + "GwtService";
    classModel.editorClassName = classModel.className + "Editor";
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.