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

The following examples show how to use com.sun.tools.xjc.outline.Outline. These examples are extracted from open source projects. 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 Project: jaxb-lombok-plugin   Source File: LombokPlugin.java    License: 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 2
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 3
Source Project: krasa-jaxb-tools   Source File: JaxbValidationsPlugins.java    License: 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 4
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 5
Source Project: jaxb2-rich-contract-plugin   Source File: MetaPlugin.java    License: 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
@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 7
Source Project: jaxb2-basics   Source File: FieldUtils.java    License: 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 8
Source Project: jaxb2-basics   Source File: FieldUtils.java    License: 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 9
Source Project: mxjc   Source File: ModelBuilder.java    License: 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 10
@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 11
Source Project: hyperjaxb3   Source File: MarshalMappings.java    License: 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 12
Source Project: hyperjaxb3   Source File: AnnotateOutline.java    License: 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 13
Source Project: hyperjaxb3   Source File: DefaultNaming.java    License: 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 14
Source Project: krasa-jaxb-tools   Source File: JaxbValidationsPlugins.java    License: 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 15
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 16
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 17
@Override
protected void beforeRun(Outline outline, Options options) throws Exception {
	super.beforeRun(outline, options);
	final String[] configLocations = getConfigLocations();
	if (!ArrayUtils.isEmpty(configLocations)) {
		final String configLocationsString = ArrayUtils
				.toString(configLocations);
		logger.debug("Loading application context from ["
				+ configLocationsString + "].");
		try {
			applicationContext = new FileSystemXmlApplicationContext(
					configLocations, false);
			applicationContext.setClassLoader(Thread.currentThread()
					.getContextClassLoader());
			applicationContext.refresh();
			if (getAutowireMode() != AutowireCapableBeanFactory.AUTOWIRE_NO) {
				applicationContext.getBeanFactory().autowireBeanProperties(
						this, getAutowireMode(), isDependencyCheck());
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			ex.getCause().printStackTrace();
			logger.error("Error loading applicaion context from ["
					+ configLocationsString + "].", ex);
			throw new BadCommandLineException(
					"Error loading  applicaion context from ["
							+ configLocationsString + "].", ex);
		}
	}
}
 
Example 18
public AbstractSinglePropertyOutline(Outline outline,
		MClassOutline classOutline, MPropertyInfo<NType, NClass> target) {
	super(outline, classOutline, target);
	this.field = generateField();
	this.getter = generateGetter();
	this.setter = generateSetter();
}
 
Example 19
public ConstantPropertyOutline(Outline outline, MClassOutline classOutline,
		MPropertyInfo<NType, NClass> target, final JExpression value) {
	super(outline, classOutline, target);
	Validate.notNull(value);
	this.value = value;
	this.field = generateField();
}
 
Example 20
Source Project: jaxb-visitor   Source File: CreateTraversingVisitorClass.java    License: Apache License 2.0 5 votes vote down vote up
CreateTraversingVisitorClass(JDefinedClass visitor, JDefinedClass progressMonitor,
                             JDefinedClass traverser, Outline outline, JPackage jPackage,
                             Function<String, String> visitMethodNamer,
                             Function<String, String> traverseMethodNamer) {
    super(outline, jPackage);
    this.visitor = visitor;
    this.traverser = traverser;
    this.progressMonitor = progressMonitor;
    this.visitMethodNamer = visitMethodNamer;
    this.traverseMethodNamer = traverseMethodNamer;
}
 
Example 21
Source Project: mxjc   Source File: ClassModelBuilder.java    License: MIT License 5 votes vote down vote up
/**
 * Build class name to element name mapping
 * 
 * @param outline, JAXB schema/code model
 * @return class name to element name map
 */
private static Map<String, QName> buildClass2ElementMapping(Outline outline) {
	Map<String, QName> mapping = new HashMap<String, QName>();
	for(CElementInfo ei : outline.getModel().getAllElements()) {
        JType exposedType = ei.getContentInMemoryType().toType(outline,Aspect.EXPOSED);
        mapping.put(exposedType.fullName(), ei.getElementName());
	}
	return mapping;
}
 
Example 22
@Override
public void doExecute(Options options) throws MojoExecutionException {
	final Model model = loadModel(options);
	final Outline outline = generateCode(model);
	writeCode(outline);

}
 
Example 23
public CMEnumConstantOutlineGenerator(Outline outline,
		CEnumConstant enumConstant) {
	Validate.notNull(outline);
	Validate.notNull(enumConstant);
	this.outline = outline;
	this.enumConstant = enumConstant;
}
 
Example 24
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 25
@Override
public JExpression compute(Outline outline){
	JExpression expression = computeInit(outline);

	if((expression instanceof JFieldRef) || (expression instanceof JStringLiteral)){
		setField(null);

		return expression;
	}

	return JExpr.ref(getField());
}
 
Example 26
public CMPropertyOutlineGenerator(Outline outline,
		CPropertyInfo propertyInfo) {
	Validate.notNull(outline);
	Validate.notNull(propertyInfo);
	this.outline = outline;
	this.propertyInfo = propertyInfo;
}
 
Example 27
Source Project: hyperjaxb3   Source File: DefaultIgnoring.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean isPackageOutlineIgnored(Mapping context, Outline outline,
		PackageOutline packageOutline) {
	for (IgnoredPackage ignoredPackage : getCustomizing()
			.<IgnoredPackage> findCustomizations(outline.getModel(),
					Customizations.IGNORED_PACKAGE_ELEMENT_NAME)) {
		if (packageOutline._package().name()
				.equals(ignoredPackage.getName())) {
			return true;
		}
	}
	return false;
}
 
Example 28
@Override
public void doExecute(Options options) throws MojoExecutionException {
	final Model model = loadModel(options);
	final Outline outline = generateCode(model);
	writeCode(outline);

}
 
Example 29
Source Project: jaxb-visitor   Source File: CreateTraverserInterface.java    License: Apache License 2.0 5 votes vote down vote up
CreateTraverserInterface(JDefinedClass visitor, Outline outline,
                         JPackage jpackage,
                         Function<String, String> traverseMethodNamer) {
    super(outline, jpackage);
    this.visitor = visitor;
    this.traverseMethodNamer = traverseMethodNamer;
}
 
Example 30
public static JDefinedClass generateContextPathAwareClass(
    Outline outline,
    String name,
    Class<?> theClass) {

  return generateContextPathAwareClass(outline, name, theClass == null ? null : outline
      .getCodeModel()
      .ref(theClass));
}