How creating a new class and saving it to disk with spoon - inria-spoon

I'm newbie with Spoon and, if I managed to transform class I did not find the way to generate a new class from scratch and save it to disk.
I managed to create a new class but I did not see it in the generation directory.
Any help would be greatly appreciated.
Best regards,
Alain

If you would only create a new class you can do something like this:
final Launcher spoon = new Launcher();
CtClass<?> aClass = spoon.getFactory().Class().create("package.MyClass");
new JavaOutputProcessor(new File("output"), spoon.createPrettyPrinter()).createJavaFile(aClass);

Related

devexpress CheckedComboBoxEdit.DataBindings connect to xpcollection

I'm trying to connect xpcollection, below is xpcollection code I'm using:
Private Agent As New XPCollection(Of clAgent)(UOW)
I would like data from this collection to be visible in CheckedComboBoxEdit, I think it should be DataBindings, however it's not working, or I don't know how to work it out. Any ideas of how to add results from xpcollection to CheckedComboBoxEdit?
Thanks
Patryk
You need to use the RepositoryItemCheckedComboBoxEdit.DataSource property to assign a data source to CheckedComboBoxEdit.
Private Agent As New XPCollection(Of clAgent)(UOW)
CheckedComboBoxEdit.Properties.DataSource = Agent

Hadoop Map reduce Testing - custom record reader

I have written a custom record reader and looking for sample test code to test my custom reader using MRUnit or any other testing framework. Its working fine as per the functionality but I would like to add test cases before I make an install. Any help would be appreciable.
In my opinion, a custom record reader is like any iterator. For testing my record reader I have been able to work without MRUnit or any other hadoop junit frameworks. The test executes quickly and the footprint is small too. Initialize the record reader in your test case and keep iterating on it. Here is a pseudocode from one of my tests. I can provide you more details if you want to proceed in this direction.
MyInputFormat myInputFormat = new MyInputFormat();
//configure job and provide input format configuration
Job job = Job.getInstance(conf, "test");
conf = job.getConfiguration();
// verify split type and count if you want to verify the input format also
List<InputSplit> splits = myInputFormat.getSplits(job);
TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
RecordReader<LongWritable, Text> reader = myInputFormat.createRecordReader(splits.get(1), context);
reader.initialize(splits.get(1), context);
for (; number of expected value;) {
assertTrue(reader.nextKeyValue());
// verify key and value
assertEquals(expectedLong, reader.getCurrentKey());
}

How can I Seed data from a SQL file?

I have a database connected to a MVC 4 Project.
The Database is creating automatically from this code:
public class ContextInitializer : DropCreateDatabaseIfModelChanges<ContextModel>
{
protected override void Seed(ContextModel context)
{
base.Seed(context);
}
}
I saw that people Seed back the database after drop and recreate with this code:
System.Data.Entity.Database.SetInitializer(new CarStore.Models.SampleData.cs);
This works grate. But my question is:
1st. How can I seed data from a SQL file, i have that SampleData.sql, and how can I 'run' that file to insert back all the data.
and 2nd is there a way to make BackUp to latest version from your database data, before you DropAndCreateIfModelChanges ?
And then to seed that data back from that file ?
Thanks.
I GOT THE ANSWER :)
I finally manage to solve this problem.
Here is the code, maybe someone needs it !
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
context.Database.ExecuteSqlCommand(File.ReadAllText(baseDirectory +
"\\IF YOU HAVE ANOTHER DIRECTOR INSIDE BASEDIR \\SQL" + "\\YOURFILENAME.sql"));
It works for me very good and fast.
It's optimized and readable.

Properties file load and write is not working

Hi guys I am having problems with writing on a properties file. The properties file can be loaded without any problem and the key value can be changed but after I have store it with a fileoutoutstream it seems it did its job but there is no change on the properties file.
Resource resource = new ClassPathResource("application.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);
props.setProperty("image.path", "empty");
OutputStream propOut = new FileOutputStream(new File("application.properties"));
props.store(propOut, "User change");
propOut.close();
I am trying it in a Spring project. The file application.properties cannot be changed and there is no error so I can have any clue about the problem.
What do you think I am missing? Any help will be much appreciated. Cheers
You have to store the properties as follows:
props.store(resource.getOutputStream(), "comments");

Importing owl files

I have a problem with importing owl files using owl api in Java. I successfully can import 2 owl files. However, a problem occurs, when I try to import 3 or more owl files that are integrated to each other.
E.g.
Base.owl -- base ontology
Electronics.owl -- electronics ontology which imports Base.owl
Telephone.owl -- telephone ontology which imports Base.owl and Electronics.owl
When, I just import Base.owl and run Electronics.owl, it works smoothly. The code is given below:
File fileBase = new File("filepath/Base.owl");
File fileElectronic = new File("filePath/Electronic.owl");
SimpleIRIMapper iriMapper = new SimpleIRIMapper(IRI.create("url/Base.owl"),
IRI.create(fileBase));
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
manager.addIRIMapper(iriMapper);
OWLOntology ont = manager.loadOntologyFromOntologyDocument(fileElectronic);
However, when I want to load Telephone.owl, I just create an additional iriMapper and add it to the manager. The additional code is shown with ** :
File fileBase = new File("filepath/Base.owl");
File fileElectronic = new File("filePath/Electronic.owl");
**File fileTelephone = new File("filePath/Telephone.owl");**
SimpleIRIMapper iriMapper = new SimpleIRIMapper(IRI.create("url/Base.owl"),
IRI.create(fileBase));
**SimpleIRIMapper iriMapper2 = new SimpleIRIMapper(IRI.create("url/Electronic.owl"),
IRI.create(fileElectronic));**
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
manager.addIRIMapper(iriMapper);
**manager.addIRIMapper(iriMapper2);**
OWLOntology ont = manager.loadOntologyFromOntologyDocument(**fileTelephone**);
The code shown above gives this error :
Could not load import:
Import(url/Electronic.owl>)
Reason: Could not loaded imported ontology:
<url/Base.owl> Cause: null
It would be really appreciated, if someone gives me a hand...
Thanks in advance...
I know this question is old, but it was my first hit on google seraching for a similar problem (loading many owl-imports). And I need a lot of time to find an answer.
So for all who have the problem that the owlapi will say: "Could not loaded imported ontology": The owlapi provides a utility-class named "AutoIRIMapper" (described here: http://owlapi.sourceforge.net/2.x.x/utilityclasses.html and http://owlapi.sourceforge.net/javadoc/index.html).
Once created an instance of "AutoIRIMapper" can be addaded to the "OWLOntologyManager" using the following code:
"manager.addIRIMapper(autoIRIMapper);"
After that the OWLOntologyManager will be able to automatically load all imported OWL-Files.
I hope that will help someone.
if you want to make a request to the manager to load an ontology declared in an imports statement, you can use the makeLoadImportRequest method, which takes an OWLImportsDeclaration as a parameter.
See whether that solves your problem.
Good luck!