com.sun.tools.xjc.outline.Outline Java Examples

The following examples show how to use com.sun.tools.xjc.outline.Outline. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarshalMappings.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Collection<ClassOutline> process(EjbPlugin context, Outline outline,
		Options options) throws Exception {
	logger.debug("Processing outline with context path ["
			+ OutlineUtils.getContextPath(outline) + "].");

	final Collection<? extends ClassOutline> classes = outline.getClasses();
	final Collection<ClassOutline> processedClassOutlines = new ArrayList<ClassOutline>(
			classes.size());

	for (final ClassOutline classOutline : classes) {
		if (!getIgnoring()
				.isClassOutlineIgnored(getMapping(), classOutline)) {
			final ClassOutline processedClassOutline = process(this,
					classOutline, options);
			if (processedClassOutline != null) {
				processedClassOutlines.add(processedClassOutline);
			}
		}
	}
	return processedClassOutlines;
}
 
Example #2
Source File: AutoInheritancePlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
	for (final ClassOutline classOutline : outline.getClasses()) {
		if (classOutline.target.getElementName() != null) {
			processGlobalElement(classOutline);
		} else {
			processGlobalComplexType(classOutline);
		}
	}
	for (final CElementInfo elementInfo : outline.getModel()
			.getAllElements()) {
		final ElementOutline elementOutline = outline
				.getElement(elementInfo);
		if (elementOutline != null) {
			processGlobalJAXBElement(elementOutline);
		}
	}
	return true;
}
 
Example #3
Source File: XJCCMInfoFactory.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected NClass getClazz(final Class<?> _clas) {
	return new NClass() {

		@Override
		public boolean isBoxedType() {
			return false;
		}

		@Override
		public String fullName() {
			return _clas.getName();
		}

		@Override
		public JClass toType(Outline o, Aspect aspect) {
			return o.getCodeModel().ref(_clas);
		}

		@Override
		public boolean isAbstract() {
			return false;
		}
	};
}
 
Example #4
Source File: JaxbValidationsPlugins.java    From krasa-jaxb-tools with Apache License 2.0 6 votes vote down vote up
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
	try {
		for (ClassOutline co : model.getClasses()) {
			List<CPropertyInfo> properties = co.target.getProperties();
			for (CPropertyInfo property : properties) {
				if (property instanceof CElementPropertyInfo) {
					processElement((CElementPropertyInfo) property, co, model);
				} else if (property instanceof CAttributePropertyInfo) {
					processAttribute((CAttributePropertyInfo) property, co, model);
				} else if (property instanceof CValuePropertyInfo) {
					processAttribute((CValuePropertyInfo) property, co, model);
				}
			}
		}
		return true;
	} catch (Exception e) {
		log(e);
		return false;
	}
}
 
Example #5
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 6 votes vote down vote up
@Override
public boolean run(final Outline outline, final Options opt, final ErrorHandler errorHandler) throws SAXException {
	final PluginContext pluginContext = PluginContext.get(outline, opt, errorHandler);
	if (this.extended && this.generateTools) {
		pluginContext.writeSourceFile(PropertyInfo.class);
		pluginContext.writeSourceFile(SinglePropertyInfo.class);
		pluginContext.writeSourceFile(CollectionPropertyInfo.class);
		pluginContext.writeSourceFile(IndirectCollectionPropertyInfo.class);
		pluginContext.writeSourceFile(IndirectPrimitiveCollectionPropertyInfo.class);
		pluginContext.writeSourceFile(PropertyVisitor.class);
		pluginContext.writeSourceFile(Property.class);
		pluginContext.writeSourceFile(SingleProperty.class);
		pluginContext.writeSourceFile(CollectionProperty.class);
		pluginContext.writeSourceFile(IndirectCollectionProperty.class);
		pluginContext.writeSourceFile(IndirectPrimitiveCollectionProperty.class);
		pluginContext.writeSourceFile(ItemProperty.class);
	}
	for (final ClassOutline classOutline : outline.getClasses()) {
		generateMetaClass(pluginContext, classOutline, errorHandler);
	}
	return true;
}
 
Example #6
Source File: ModelBuilder.java    From mxjc with MIT License 6 votes vote down vote up
public static CGModel buildCodeGenModel(Outline outline, ErrorReceiver errorReceiver) {
	
	CGModel cgModel = new CGModel();
	
	if (errorReceiver != null)
		errorReceiver.debug("Building class model ...");
	// build class/bean model
	ClassModelBuilder.buildClassModel(outline, cgModel, errorReceiver);
	
	if (errorReceiver != null)
		errorReceiver.debug("Building enum model ...");
	// build enum model
	EnumModelBuilder.buildEnumModel(outline, cgModel, errorReceiver);
	
	return cgModel;
}
 
Example #7
Source File: JsonixPlugin.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt,
		final ErrorHandler errorHandler) throws SAXException {

	final Model model = outline.getModel();
	final JCodeModel codeModel = outline.getCodeModel();

	final ProgramWriter<NType, NClass> programWriter = new CodeModelProgramWriter(
			codeModel, errorHandler);

	final JsonStructureWriter<NType, NClass> jsonStructureWriter = new CodeModelJsonStructureWriter(
			codeModel, errorHandler);

	new JsonixInvoker().execute(getSettings(), model, programWriter,
			jsonStructureWriter);

	return true;
}
 
Example #8
Source File: AnnotateOutline.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Collection<ClassOutline> process(EjbPlugin context, Outline outline,
		Options options) throws Exception {
	logger.debug("Processing outline with context path ["
			+ OutlineUtils.getContextPath(outline) + "].");

	final Collection<? extends ClassOutline> classes = outline.getClasses();
	final Collection<ClassOutline> processedClassOutlines = new ArrayList<ClassOutline>(
			classes.size());

	for (final ClassOutline classOutline : classes) {
		if (!getIgnoring()
				.isClassOutlineIgnored(getMapping(), classOutline)) {
			final ClassOutline processedClassOutline = process(this,
					classOutline, options);
			if (processedClassOutline != null) {
				processedClassOutlines.add(processedClassOutline);
			}
		}
	}
	return processedClassOutlines;
}
 
Example #9
Source File: AbstractPropertyOutline.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public AbstractPropertyOutline(Outline outline, MClassOutline classOutline,
		MPropertyInfo<NType, NClass> target) {
	Validate.notNull(outline);
	Validate.notNull(classOutline);
	Validate.notNull(target);
	this.outline = outline;
	this.modelOutline = classOutline.getParent();
	this.classOutline = classOutline;
	this.propertyInfo = target;
	this.codeModel = classOutline.getParent().getCode();

	this.referenceClass = classOutline.getReferenceCode();
	this.implementationClass = classOutline.getImplementationCode();
	this.implementationReferenceClass = classOutline
			.getImplementationReferenceCode();

	this.type = generateType();
}
 
Example #10
Source File: FieldUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Set<JType> getPossibleTypes(FieldOutline fieldOutline,
		Aspect aspect) {
	Validate.notNull(fieldOutline);
	final ClassOutline classOutline = fieldOutline.parent();
	final Outline outline = classOutline.parent();
	final CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();

	final Set<JType> types = new HashSet<JType>();

	if (propertyInfo.getAdapter() != null) {
		types.add(propertyInfo.getAdapter().customType.toType(fieldOutline
				.parent().parent(), aspect));
	} else if (propertyInfo.baseType != null) {
		types.add(propertyInfo.baseType);
	} else {
		Collection<? extends CTypeInfo> typeInfos = propertyInfo.ref();
		for (CTypeInfo typeInfo : typeInfos) {
			types.addAll(getPossibleTypes(outline, aspect, typeInfo));
		}
	}
	return types;
}
 
Example #11
Source File: DefaultNaming.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String getPersistenceUnitName(Mapping context, Outline outline) {
	final StringBuffer sb = new StringBuffer();
	boolean first = true;

	for (final Iterator<? extends PackageOutline> packageOutlines = outline
			.getAllPackageContexts().iterator(); packageOutlines.hasNext();) {
		final PackageOutline packageOutline = packageOutlines.next();
		if (!getIgnoring().isPackageOutlineIgnored(context, outline,
				packageOutline)) {
			if (!first) {
				sb.append(':');
			} else {
				first = false;
			}
			final String packageName = packageOutline._package().name();
			sb.append(packageName);
		}

	}
	return sb.toString();
}
 
Example #12
Source File: JaxbValidationsPlugins.java    From krasa-jaxb-tools with Apache License 2.0 6 votes vote down vote up
/**
 * XS:Attribute
 */
public void processAttribute(CAttributePropertyInfo property, ClassOutline clase, Outline model) {
	FieldOutline field = model.getField(property);
	String propertyName = property.getName(false);
	String className = clase.implClass.name();

	log("Attribute " + propertyName + " added to class " + className);
	XSComponent definition = property.getSchemaComponent();
	AttributeUseImpl particle = (AttributeUseImpl) definition;
	XSSimpleType type = particle.getDecl().getType();

	JFieldVar var = clase.implClass.fields().get(propertyName);
	if (particle.isRequired()) {
		if (!hasAnnotation(var, NotNull.class)) {
			processNotNull(clase, var);
		}
	}

	validAnnotation(type, var, propertyName, className);
	processType(type, var, propertyName, className);
}
 
Example #13
Source File: MappingFilePersistenceProcessor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Collection<ClassOutline> process(EjbPlugin plugin, Outline outline,
		Options options) throws Exception {

	Collection<ClassOutline> includedClasses = getOutlineProcessor()
			.process(plugin, outline, options);

	final String pun = plugin.getPersistenceUnitName();
	final String persistenceUnitName = pun != null ? pun : getNaming()
			.getPersistenceUnitName(plugin.getMapping(), outline);

	final PersistenceUnit persistenceUnit = getPersistenceUnitFactory()
			.createPersistenceUnit(includedClasses);

	final Persistence persistence = createPersistence(plugin,
			persistenceUnit, persistenceUnitName);

	getPersistenceMarshaller().marshallPersistence(outline.getCodeModel(),
			persistence);

	// TODO Auto-generated method stub
	return includedClasses;
}
 
Example #14
Source File: LombokPlugin.java    From jaxb-lombok-plugin with MIT License 6 votes vote down vote up
@Override
public boolean run(Outline outline, Options options, ErrorHandler errorHandler) {
    // for each generated classes
    for (ClassOutline generatedClassOutline : outline.getClasses()) {
        JDefinedClass generatedClass = generatedClassOutline.implClass;
        if (!isAbstractClass(generatedClass) &&
                !generatedClass.fields().isEmpty()) {
            boolean commandExecuted = false;
            for (Command command : commands.values()) {
                if (command.isEnabled()) {
                    command.editGeneratedClass(generatedClass);
                    commandExecuted = true;
                }
            }

            if (!commandExecuted) {
                defaultCommand.editGeneratedClass(generatedClass);
            }
        }
    }
    return true;
}
 
Example #15
Source File: ClassPersistenceProcessor.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Collection<ClassOutline> process(EjbPlugin plugin, Outline outline,
		Options options) throws Exception {

	Collection<ClassOutline> includedClasses = getOutlineProcessor()
			.process(plugin, outline, options);

	final String pun = plugin.getPersistenceUnitName();
	final String persistenceUnitName = pun != null ? pun : getNaming()
			.getPersistenceUnitName(plugin.getMapping(), outline);

	final PersistenceUnit persistenceUnit = getPersistenceUnitFactory()
			.createPersistenceUnit(includedClasses);

	final Persistence persistence = createPersistence(plugin,
			persistenceUnit, persistenceUnitName);

	getPersistenceMarshaller().marshallPersistence(outline.getCodeModel(),
			persistence);

	return includedClasses;
}
 
Example #16
Source File: FieldUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Set<JType> getPossibleTypes(Outline outline, Aspect aspect,
		CTypeInfo typeInfo) {

	final Set<JType> types = new HashSet<JType>();

	types.add(typeInfo.getType().toType(outline, aspect));
	if (typeInfo instanceof CElementInfo) {

		final CElementInfo elementInfo = (CElementInfo) typeInfo;
		for (CElementInfo substitutionMember : elementInfo
				.getSubstitutionMembers()) {
			types.addAll(getPossibleTypes(outline, aspect,
					substitutionMember));
		}
	}
	return types;
}
 
Example #17
Source File: XJC20Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void writeCode(Outline outline) throws MojoExecutionException {

		if (getWriteCode()) {
			final Model model = outline.getModel();
			final JCodeModel codeModel = model.codeModel;
			final File targetDirectory = model.options.targetDir;
			if (getVerbose()) {
				getLog().info(
						MessageFormat.format("Writing output to [{0}].",
								targetDirectory.getAbsolutePath()));
			}
			try {
				if (getCleanPackageDirectories()) {
					if (getVerbose()) {
						getLog().info("Cleaning package directories.");
					}
					cleanPackageDirectories(targetDirectory, codeModel);
				}
				final CodeWriter codeWriter = new LoggingCodeWriter(
						model.options.createCodeWriter(), getLog(),
						getVerbose());
				codeModel.build(codeWriter);
			} catch (IOException e) {
				throw new MojoExecutionException("Unable to write files: "
						+ e.getMessage(), e);
			}
		} else {
			getLog().info(
					"The [writeCode] setting is set to false, the code will not be written.");
		}
	}
 
Example #18
Source File: ClassDiscoverer.java    From jaxb-visitor with Apache License 2.0 5 votes vote down vote up
/**
 * Handles the extraction of the schema type from the XmlElement
 * annotation. This was surprisingly difficult. Apparently the
 * model doesn't provide access to the annotation we're referring to
 * so I need to print it and read the string back. Even the formatter
 * itself is final!
 * @param outline root of the generated code
 * @param directClasses set of classes to append to
 * @param type annotation we're analysing
 */
private static void handleXmlElement(Outline outline, Set<String> directClasses, JAnnotationValue type) {
    StringWriter sw = new StringWriter();
    JFormatter jf = new JFormatter(new PrintWriter(sw));
    type.generate(jf);
    String s = sw.toString();
    s = s.substring(0, s.length()-".class".length());
    if (!s.startsWith("java") && outline.getCodeModel()._getClass(s) == null && !foundWithinOutline(s, outline)) {
        directClasses.add(s);
    }
}
 
Example #19
Source File: MetaPlugin.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private void generateNameOnlyMetaField(final PluginContext pluginContext, final JDefinedClass metaClass, final FieldOutline fieldOutline) {
	final PropertyOutline propertyOutline = new DefinedPropertyOutline(fieldOutline);
	final String constantName = getConstantName(fieldOutline);
	final Outline outline = pluginContext.outline;
	final String propertyName = constantName != null ? constantName : propertyOutline.getFieldName();
	final String metaFieldName = this.camelCase ? propertyName : fieldOutline.parent().parent().getModel().getNameConverter().toConstantName(propertyName);
	metaClass.field(JMod.PUBLIC | JMod.STATIC | JMod.FINAL | JMod.TRANSIENT, String.class, metaFieldName, JExpr.lit(propertyName));
}
 
Example #20
Source File: PrimitiveFixerPlugin.java    From krasa-jaxb-tools with Apache License 2.0 5 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException {
    for (ClassOutline co : outline.getClasses()) {
        HashMap<String, Class> hashMap = new HashMap<String, Class>();
        hashMap.put("int", Integer.class);
        hashMap.put("long", Long.class);
        hashMap.put("boolean", Boolean.class);
        hashMap.put("double", Double.class);
        hashMap.put("float", Float.class);
        hashMap.put("byte", Byte.class);
        hashMap.put("short", Short.class);
        Map<String, JFieldVar> fields = co.implClass.fields();

        for (Map.Entry<String, JFieldVar> stringJFieldVarEntry : fields.entrySet()) {
            JFieldVar fieldVar = stringJFieldVarEntry.getValue();
            JType type = fieldVar.type();
            
            /*
             * Exclude "serialVersionUID" from processing XReplacePrimitives as this will 
             * have no getter or setter defined.
             */
            if ("serialVersionUID".equals(fieldVar.name())) {
            	continue;
            }
                
            if (type.isPrimitive()) {
                Class o = hashMap.get(type.name());
                if (o != null) {
                    JCodeModel jCodeModel = new JCodeModel();
                    JClass newType = jCodeModel.ref(o);
                    fieldVar.type(newType);
                    setReturnType(newType, getMethodsMap(MethodType.GETTER, fieldVar, co));
                    setParameter(newType, getMethodsMap(MethodType.SETTER, fieldVar, co));
                }
            }
        }
    }
    return true;
}
 
Example #21
Source File: EjbPlugin.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private FieldOutline generateFieldDecl(Outline outline,
		ClassOutlineImpl cc, CPropertyInfo prop) {

	try {
		return (FieldOutline) generateFieldDecl.invoke(outline,
				new Object[] { cc, prop });
	} catch (Exception ex) {
		ex.printStackTrace();
		throw new RuntimeException(ex);
	}
}
 
Example #22
Source File: EjbPlugin.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void checkCustomizations(Outline outline) {
	for (final CClassInfo classInfo : outline.getModel().beans().values()) {
		checkCustomizations(classInfo);
		for (final CPropertyInfo propertyInfo : classInfo.getProperties()) {
			checkCustomizations(classInfo, propertyInfo);
		}
	}
}
 
Example #23
Source File: PluginImpl.java    From xero-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException {
  JCodeModel model = outline.getModel().codeModel;
  for (ClassOutline co : outline.getClasses()) {
    updateArrayOfGetters(co, model);
    updateArrayOfSetters(co, model);
  }

  return true;
}
 
Example #24
Source File: ClassDiscoverer.java    From jaxb-visitor with Apache License 2.0 5 votes vote down vote up
/**
 * Finds all external class references
 * @param outline root of the generated code
 * @param classes set of generated classes
 * @return set of external classes
 * @throws IllegalAccessException throw if there's an error introspecting the annotations
 */
static Set<JClass> discoverDirectClasses(Outline outline, Set<ClassOutline> classes) throws IllegalAccessException {

    Set<String> directClassNames = new LinkedHashSet<>();
    for(ClassOutline classOutline : classes) {
        // for each field, if it's a bean, then visit it
        List<FieldOutline> fields = findAllDeclaredAndInheritedFields(classOutline);
        for(FieldOutline fieldOutline : fields) {
            JType rawType = fieldOutline.getRawType();
            CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo();
            boolean isCollection = propertyInfo.isCollection();
            if (isCollection) {
                JClass collClazz = (JClass) rawType;
                JClass collType = collClazz.getTypeParameters().get(0);
                addIfDirectClass(directClassNames, collType);
            } else {
                addIfDirectClass(directClassNames, rawType);
            }
            parseXmlAnnotations(outline, fieldOutline, directClassNames);
        }
    }

    Set<JClass> direct = directClassNames
            .stream()
            .map(cn -> outline.getCodeModel().directClass(cn))
            .collect(Collectors.toCollection(LinkedHashSet::new));

    return direct;

}
 
Example #25
Source File: AbstractCodeGeneratorPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
	this.codeGenerator = createCodeGenerator(outline.getCodeModel());
	for (final ClassOutline classOutline : outline.getClasses()) {
		if (!getIgnoring().isIgnored(classOutline)) {
			processClassOutline(classOutline);
		}
	}
	return true;
}
 
Example #26
Source File: ToStringPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
	for (final ClassOutline classOutline : outline.getClasses())
		if (!getIgnoring().isIgnored(classOutline)) {
			processClassOutline(classOutline);
		}
	return true;
}
 
Example #27
Source File: AvroSchemagenPlugin.java    From Avro-Schema-Generator with Apache License 2.0 5 votes vote down vote up
@Override
public boolean run(Outline outline, Options options, ErrorHandler errorHandler) throws SAXException {
	helper = new SchemagenHelper(outline);

	// set up special schemas
	helper.getSpecialSchemas().put(ReferenceAvroType.class, new HashSet<String>());
	helper.getSpecialSchemas().put(DateAvroType.class, new HashSet<String>());

	// do the work
	inferAvroSchema(outline);	

	// true because we're done and processing should continue
	return true;
}
 
Example #28
Source File: EqualsPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
	for (final ClassOutline classOutline : outline.getClasses()) {
		if (!getIgnoring().isIgnored(classOutline)) {
			processClassOutline(classOutline);
		}
	}
	return true;
}
 
Example #29
Source File: DefaultOutlineProcessor.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<ClassOutline, T> process(C context, Outline outline,
		Options options) throws Exception {

	final Map<ClassOutline, T> classMappingsMap = new HashMap<ClassOutline, T>();
	for (final ClassOutline classOutline : outline.getClasses()) {
		final T result = getClassOutlineProcessor().process(context,
				classOutline, options);
		if (result != null) {
			classMappingsMap.put(classOutline, result);
		}
	}
	return classMappingsMap;
}
 
Example #30
Source File: CustomizationUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CPluginCustomization findCustomization(Outline outline, QName name) {
	final CCustomizations customizations = CustomizationUtils.getCustomizations(outline);
	final CPluginCustomization customization = customizations.find(name.getNamespaceURI(), name.getLocalPart());
	if (customization != null) {
		customization.markAsAcknowledged();
	}
	return customization;
}