com.togethersoft.openapi.sci
Interface SciGenericFactory

All Known Subinterfaces:
SciNetGenericFactory

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 based on the string you pass them. For example,
to create a new attribute "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 signature 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 the
object being created. If an object cannot be created based on this information, the
SciGenericFactoryException is thrown (for example, this can be due to an incorrect
systax construction in this string). During the process of creation, the source code
in this string will be formatted according to the settings of the formatter. It is possible
also to specify formatting style in operations with additional parameters, or disable formatting.
Currently, only null and empty string values of that parameter are supported.
For null values, no formatting is performed. For empty string values, the 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
Since: Together 3.0
See Also: SciGenericFactoryException, SciFactory

Method Summary
 SciClassnewClass(String text)
          Creates a new SciClass based on the specified string.
 SciClassnewClass(String text, String formatStyle)
           
 SciClassEnumerationnewClasses(String text)
          Creates a set of SciClasses based 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)
           
 SciCommentnewComment(String text)
          Creates a new SciComment based on the specified string.
 SciCommentnewComment(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)
           
 SciInitializernewInitializer(String text)
          Creates a new SciInitializer based on the specified string.
 SciInitializernewInitializer(String text, String formatStyle)
           
 SciMembernewMember(String text, SciClass context)
          Creates a new SciMember based on the specified string.
 SciMembernewMember(String text, SciClass context, String formatStyle)
           
 SciMemberDefinitionnewMemberDefinition(String text)
          Creates a new SciMemberDefinition based on the specified string.
 SciMemberDefinitionnewMemberDefinition(String text, String formatStyle)
           
 SciMemberEnumerationnewMembers(String text, SciClass context)
          Creates a set of SciMembers based 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 based on the specified string.
 SciStatementnewStatement(String text, String formatStyle)
           

Method Detail

newClass

public SciClass newClass(String text)
throws SciGenericFactoryException
Creates a new SciClass based on the specified string.
Parameters:
text The string containing the 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 based
on the specified string
See Also:
SciFactory.newClass()

newClass

public SciClass newClass(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newClasses

public SciClassEnumeration newClasses(String text)
throws SciGenericFactoryException
Creates a set of SciClasses based on the specified string.
Parameters:
text The string containing the 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 based
on the specified string

newClasses

public SciClassEnumeration newClasses(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newCodeBlock

public SciCodeBlock newCodeBlock(String text)
throws SciGenericFactoryException
Creates a new SciCodeBlock basing on the specified string.
Parameters:
text The string containing a source code block. For example, this sets the body of someSciOperation
to "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 based
on the specified string
See Also:
SciFunction.setBody(com.togethersoft.openapi.sci.SciCodeBlock)

newCodeBlock

public SciCodeBlock newCodeBlock(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newComment

public SciComment newComment(String text)
throws SciGenericFactoryException
Creates a new SciComment based on the specified string.
Parameters:
text - The string containing source code fragment fully defining the comment.
Returns: a new SciComment with the specified content
Throws:
SciGenericFactoryException if it is not possible
to create a comment basing on specified string
Since:
Together 6.0

newComment

public SciComment newComment(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 6.0

newExpression

public SciExpression newExpression(String text)
throws SciGenericFactoryException
Creates a new SciExpression basing on the specified string.
Parameters:
text The string containing the 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 based
on the specified string

newExpression

public SciExpression newExpression(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newFile

public SciFile newFile(String text)
throws SciGenericFactoryException
Creates a new SciFile with the specified contents.
Parameters:
text The string containing 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 based
on the specified string
See Also:
SciFactory.newFile()

newFile

public SciFile newFile(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newInitializer

public SciInitializer newInitializer(String text)
throws SciGenericFactoryException
Creates a new SciInitializer based on the specified string.
Parameters:
text - the string containing the source code fragment fully defining an initializer
Returns: a new SciInitializer with the specified content
Throws:
SciGenericFactoryException if it is not possible
Since:
Together 6.0

newInitializer

public SciInitializer newInitializer(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 6.0

newMember

public SciMember newMember(String text, SciClass context)
throws SciGenericFactoryException
Creates a new SciMember based 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 the source code fragment fully defining a member
context The SciClass to which this member is supposed to belong. For example,
a value "public ABCD(){}" for the text parameter is valid only for
the ABCD class.
For other classes, this value will throw an SciGenericFactoryException exception.
Returns: a new SciMember with the specified content
Throws:
SciGenericFactoryException if it is not possible to create an object based
on the specified string

newMember

public SciMember newMember(String text, SciClass context, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newMemberDefinition

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

newMemberDefinition

public SciMemberDefinition newMemberDefinition(String text, String formatStyle)
Since:
Together 3.1

newMembers

public SciMemberEnumeration newMembers(String text, SciClass context)
throws SciGenericFactoryException
Creates a set of SciMembers based on the specified string.
Parameters:
text the string containing the source code fragment fully defining the members
context The SciClass to which these members are supposed to belong. For example,
a value "public ABCD(){} public ABCD(int i){}" for the 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 based
on the specified string

newMembers

public SciMemberEnumeration newMembers(String text, SciClass context, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newParameter

public SciParameter newParameter(String text)
throws SciGenericFactoryException
Creates a new SciParameter with the specified content.
Parameters:
text The string containing the 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 based
on the specified string
See Also:
SciFactory.newParameter()

newParameter

public SciParameter newParameter(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1

newStatement

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

newStatement

public SciStatement newStatement(String text, String formatStyle)
throws SciGenericFactoryException
Since:
Together 3.1