com.togethersoft.openapi.sci
Interface SciGenericFactory


public interface SciGenericFactory

A creator of new source code parts of the model with the specified contents/properties.

Methods in this interface are very similar to those defined in the SciFactory interface, but unlike SciFactory's methods they create an element not with some default contents/properties, but with contents/properties basing on the string you pass them. For example, to create a new attibutue "public String myLastName" using methods of the SciFactory, you have to write this:

 SciAttribute newAttribute = SciModelAccess.getModel().getFactory(SciLanguage.JAVA).newAttribute(); //creating a new attribute with default name and type
 newAttribute.setName("myLastName"); //setting the name
 newAttribute.getType().setText("String"); //setting the type
 newAttribute.setProperty(SciProperty.PUBLIC, true); //setting the public modifier
 someSciClass.paste(newAttribute, null, false); //pasting it into someSciClass
 
The beauty of SciGenericFactory is that if you know the singature for a member a priori, you can create it like this:
 SciAttribute newAttribute=null;
 try{
   newAttribute = (SciAttribute)SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newMember("public String myLastName;", someSciClass);
 }
 catch( SciGenericFactoryException e ) {
   IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a member"+e);
   return;
 }
 someSciClass.paste(newAttribute, null, false); //pasting it into someSciClass
 

All methods in this interface have a string parameter which contains a piece of a source code with a complete definition of object being created. If an object cannot be created basing on this information, the SciGenericFactoryException is thrown (it can be dued, for example, by the wrong systax construction in this string). During the process of creation, the source code in this string will be formatted accoring to the settings of the formatter. It is possible also to specify formatting style in operations with additioal parameter or disable formatting. Currently only null and empty string values of that parameter supported. In the first case no any formatting performed. In the second case currently defined set of formatter options is used.

After creation (see example), a newly created element can be pasted into SciContainer using the paste method.

Author:
TogetherSoft
See Also: SciGenericFactoryException, SciFactory

Method Summary
 SciClassnewClass(String text)
           Creates a new SciClass basing on the specified string.
 SciClassnewClass(String text, String formatStyle)
           
 SciClassEnumerationnewClasses(String text)
           Creates a set of SciClasses basing on the specified string.
 SciClassEnumerationnewClasses(String text, String formatStyle)
           
 SciCodeBlocknewCodeBlock(String text)
           Creates a new SciCodeBlock basing on the specified string.
 SciCodeBlocknewCodeBlock(String text, String formatStyle)
           
 SciExpressionnewExpression(String text)
           Creates a new SciExpression basing on the specified string.
 SciExpressionnewExpression(String text, String formatStyle)
           
 SciFilenewFile(String text)
           Creates a new SciFile with the specified contents.
 SciFilenewFile(String text, String formatStyle)
           
 SciMembernewMember(String text, SciClass context)
           Creates a new SciMember basing on the specified string.
 SciMembernewMember(String text, SciClass context, String formatStyle)
           
 SciMemberDefinitionnewMemberDefinition(String text)
           Creates a new SciMemberDefinition basing on the specified string.
 SciMemberDefinitionnewMemberDefinition(String text, String formatStyle)
           
 SciMemberEnumerationnewMembers(String text, SciClass context)
           Creates a set of SciMembers basing on the specified string.
 SciMemberEnumerationnewMembers(String text, SciClass context, String formatStyle)
           
 SciParameternewParameter(String text)
           Creates a new SciParameter with the specified content.
 SciParameternewParameter(String text, String formatStyle)
           
 SciStatementnewStatement(String text)
           Creates a new SciStatement basing on the specified string.
 SciStatementnewStatement(String text, String formatStyle)
           

Method Detail

newClass

public SciClass newClass(String text)
throws SciGenericFactoryException
Creates a new SciClass basing on the specified string.
Parameters:
text - The string containing source code fragment fully defining a class/interface. For example, "class Class1{ void doNothing(){} }".
Returns: a new SciClass with the specified content
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string
See Also:
SciFactory.newClass()

newClass

public SciClass newClass(String text, String formatStyle)
throws SciGenericFactoryException

newClasses

public SciClassEnumeration newClasses(String text)
throws SciGenericFactoryException
Creates a set of SciClasses basing on the specified string.
Parameters:
text - The string containing source code fragment fully defining the classes/interfaces. For example, "public class Class1 {} class Class2{ void doNothing(){} }".
Returns: an enumeration of SciClasses
Throws:
SciGenericFactoryException - if it is not possible to create objects basing on the specified string

newClasses

public SciClassEnumeration newClasses(String text, String formatStyle)
throws SciGenericFactoryException

newCodeBlock

public SciCodeBlock newCodeBlock(String text)
throws SciGenericFactoryException
Creates a new SciCodeBlock basing on the specified string.
Parameters:
text - The string containing source code block. For example, this sets the body of someSciOperation to the "int s = getSalary(2000); return s*2;" :
 SciCodeBlock newCodeBlock=null;
  try{
    newCodeBlock = SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newCodeBlock("int s = getSalary(2000); return s*2;");
  }
  catch( SciGenericFactoryException e ) {
    IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating SciCodeBlock"+e);
    return;
  }
  someSciOperation.setBody(newCodeBlock);
 
Returns: a new SciCodeBlock with the specified content
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string
See Also:
SciFunction.setBody(com.togethersoft.openapi.sci.SciCodeBlock)

newCodeBlock

public SciCodeBlock newCodeBlock(String text, String formatStyle)
throws SciGenericFactoryException

newExpression

public SciExpression newExpression(String text)
throws SciGenericFactoryException
Creates a new SciExpression basing on the specified string.
Parameters:
text - The string containing source code fragment fully defining an expression. For example, "myClassInstance.myOperation(0)".
Returns: a new SciExpression
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string

newExpression

public SciExpression newExpression(String text, String formatStyle)
throws SciGenericFactoryException

newFile

public SciFile newFile(String text)
throws SciGenericFactoryException
Creates a new SciFile with the specified contents.
Parameters:
text - The string containing a content for a file. For example,
  SciFile f=null;
  try{
    f = SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newFile("import java.io.*; public class R{}");
  }
  catch( SciGenericFactoryException exc ) {
    IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a file"+e);
    return;
  }
  f.setName("R.java");
  someRwiPackage.paste(f,null,false);
 
will create a new file R.java containing "import java.io.*; public class R{}".
Returns: a new SciFile with the specified content
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string
See Also:
SciFactory.newFile()

newFile

public SciFile newFile(String text, String formatStyle)
throws SciGenericFactoryException

newMember

public SciMember newMember(String text, SciClass context)
throws SciGenericFactoryException
Creates a new SciMember basing on the specified string. For example, this creates a new attribute "public String myLastName":
  SciAttribute newAttribute=null;
  try{
    newAttribute = (SciAttribute)SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newMember("public String myLastName;", someSciClass);
  }
  catch( SciGenericFactoryException e ) {
    IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a member"+e);
    return;
  }
  someSciClass.paste(newAttribute, null, false); //pasting it into someSciClass
 

And this creates a new operation "public int getSalary(int year){ return 100; }":

 SciOperation newOperation=null;
 try{
   newOperation = (SciOperation)SciModelAccess.getModel().getGenericFactory(SciLanguage.JAVA).newMember("public int getSalary(int year){ return 100; }", someSciClass);
 }
 catch( SciGenericFactoryException e ) {
   IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR,"Error while creating a member"+e);
   return;
 }
 someSciClass.paste(newOperation, null, false); //pasting it into someSciClass
 
Parameters:
text - the string containing source code fragment fully defining a member
context - The SciClass to which this member is supposed to belong. For example, a value "public ABCD(){}" of text parameter is valid only for the ABCD class. For other classes this value will throw an SciGenericFactoryExcepetion exception.
Returns: a new SciMember with the specified content
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string

newMember

public SciMember newMember(String text, SciClass context, String formatStyle)
throws SciGenericFactoryException

newMemberDefinition

public SciMemberDefinition newMemberDefinition(String text)
Creates a new SciMemberDefinition basing on the specified string. For C++ language only.
Parameters:
text - the string containing source code fragment fully defining an expression
Returns: a new SciMemberDefinition

newMemberDefinition

public SciMemberDefinition newMemberDefinition(String text, String formatStyle)

newMembers

public SciMemberEnumeration newMembers(String text, SciClass context)
throws SciGenericFactoryException
Creates a set of SciMembers basing on the specified string.
Parameters:
text - the string containing source code fragment fully defining the members
context - The SciClass to which these member is supposed to belong. For example, a value "public ABCD(){} public ABCD(int i){}" of text parameter is valid only for ABCD class. For other classes this value of text will throw an SciGenericFactoryException exception.
Returns: an enumeration of SciMembers
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string

newMembers

public SciMemberEnumeration newMembers(String text, SciClass context, String formatStyle)
throws SciGenericFactoryException

newParameter

public SciParameter newParameter(String text)
throws SciGenericFactoryException
Creates a new SciParameter with the specified content.
Parameters:
text - The string containing source code fragment fully defining a parameter. For example, "int i".
Returns: a new SciParameter with the specified content
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string
See Also:
SciFactory.newParameter()

newParameter

public SciParameter newParameter(String text, String formatStyle)
throws SciGenericFactoryException

newStatement

public SciStatement newStatement(String text)
throws SciGenericFactoryException
Creates a new SciStatement basing on the specified string.
Parameters:
text - the string containing source code fragment fully defining a statement
Returns: a new SciStatement
Throws:
SciGenericFactoryException - if it is not possible to create an object basing on the specified string

newStatement

public SciStatement newStatement(String text, String formatStyle)
throws SciGenericFactoryException