How to use the replication.share.yidl.src.yidl.java_target.JavaType function in replication

To help you get started, we’ve selected a few replication examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
class JavaBufferType(BufferType, JavaType):
    def getConstantValue( self, value ): return "\"%(value)s\"" % locals()
    def getDefaultInitializer( self, identifier ): return "%(identifier)s = null;" % locals()
    def getObjectDeserializeCall( self, source_identifier, dest_identifier ): declaration_type_name = self.getDeclarationTypeName(); return "%(dest_identifier)s = ( %(declaration_type_name)s )%(source_identifier)s;" % locals() 
    def getObjectSerializeCall( self, identifier ): return identifier        
    def getToStringCall( self, identifier ): return '"\\"" + %(identifier)s + "\\""' % locals()


class JavaConstant(Constant):
    def __repr__( self ):
        return "public static final " + self.getType().getDeclarationTypeName() + " " + \
            self.getIdentifier() + " = " + self.getType().getConstantValue( self.getValue() ) + ';'    


class JavaEnumeratedType(EnumeratedType, JavaType):
    def generate( self ):
        package_name = self.getPackageName()
        name = self.getName()
        enumerators = pad( "\n" + INDENT_SPACES, ( ",\n" + INDENT_SPACES ).join( [repr( enumerator ) for enumerator in self.getEnumerators()] ), ";" )
        writeGeneratedFile( self.getFilePath(), """\
package %(package_name)s;
        
        
public enum %(name)s 
{%(enumerators)s    

    private int __value; 
    
    %(name)s() { this.__value = 0; }
    %(name)s( int value ) { this.__value = value; }    
    public int intValue() { return __value; }
github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
if len( self.getConstants() ) > 0:       
            writeGeneratedFile( os.path.join( self.getPackageDirPath(), "Constants.java" ), """\
package %s;


public interface Constants
{
    %s
};
""" % ( self.getPackageName(), ( "\n" + INDENT_SPACES ).join( [repr( constant ) for constant in self.getConstants()] ) ) ) 
        
        for enumerated_type in self.getEnumeratedTypes():
            enumerated_type.generate()
            

class JavaNumericType(NumericType, JavaType):
    def getBoxedTypeName( self ):
        decl_type = self.getDeclarationTypeName()
        if decl_type == "int": return "Integer"
        else: return decl_type[0].upper() + decl_type[1:]

    def getCastFromObject( self, source_identifier ): 
        return "( " + self.getBoxedTypeName() + " )%(source_identifier)s"  % locals()
    
    def getDeclarationTypeName( self ):
        name = self.getName()
        if name == "float" or name == "double": return name
        elif name.endswith( "int8_t" ): return "int"
        elif name.endswith( "int16_t" ): return "int"
        elif name.endswith( "int32_t" ): return "int"
        elif name.endswith( "int64_t" ): return "long"
        else: return "long" # mode_t, etc.
github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
def getToStringMethod( self ):
        value_boxed_type_name = self.getValueType().getBoxedTypeName()
        value_toString_call = self.getValueType().getToStringCall( "i.next()" )                
        return """\
    public String toString()
    {
        String to_string = new String();
        for ( Iterator<%(value_boxed_type_name)s> i = iterator(); i.hasNext(); )
            to_string += %(value_toString_call)s + ", ";
        return to_string;
    }
""" % locals()
        
    
class JavaStringType(StringType, JavaType):
    def getCastFromObject( self, source_identifier ): return "( String )%(source_identifier)s" % locals()
    def getConstantValue( self, value ): return "\"%(value)s\"" % locals()
    def getDeclarationTypeName( self ): return "String"
    def getDefaultInitializer( self, identifier ): return "%(identifier)s = \"\";" % locals()
    def getObjectDeserializeCall( self, source_identifier, dest_identifier ): return "%(dest_identifier)s = ( String )%(source_identifier)s;" % locals()
    def getObjectSerializeCall( self, identifier ): return identifier
    def getToStringCall( self, identifier ): return '"\\"" + %(identifier)s + "\\""' % locals()


class JavaStructType(StructType, JavaType):
    def generate( self ):
        class_header = self.getClassHeader()
        class_footer = self.getClassFooter()
        qname = self.getQualifiedName( "::" )
        tag = self.getTag()
        constructors = self.getConstructors()
github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
return to_string;
    }
""" % locals()
        
    
class JavaStringType(StringType, JavaType):
    def getCastFromObject( self, source_identifier ): return "( String )%(source_identifier)s" % locals()
    def getConstantValue( self, value ): return "\"%(value)s\"" % locals()
    def getDeclarationTypeName( self ): return "String"
    def getDefaultInitializer( self, identifier ): return "%(identifier)s = \"\";" % locals()
    def getObjectDeserializeCall( self, source_identifier, dest_identifier ): return "%(dest_identifier)s = ( String )%(source_identifier)s;" % locals()
    def getObjectSerializeCall( self, identifier ): return identifier
    def getToStringCall( self, identifier ): return '"\\"" + %(identifier)s + "\\""' % locals()


class JavaStructType(StructType, JavaType):
    def generate( self ):
        class_header = self.getClassHeader()
        class_footer = self.getClassFooter()
        qname = self.getQualifiedName( "::" )
        tag = self.getTag()
        constructors = self.getConstructors()        
        default_initializers = rpad( self.getDefaultInitializers(), " " )
        accessors = lpad( "\n\n", self.getAccessors() )
        toString_method = lpad( "\n\n", self.getToStringMethod() )
        deserialize_methods = lpad( "\n\n", self.getDeserializeMethods() )        
        serialize_methods = lpad( "\n", self.getSerializeMethods() )
        other_methods = lpad( "\n", self.getOtherMethods() )
        declarations = lpad( "\n\n", self.getDeclarations() )
        writeGeneratedFile( self.getFilePath(), """\
%(class_header)s
    public static final int TAG = %(tag)s;
github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
class JavaExceptionType(ExceptionType):
    def generate( self ):
        JavaStructType( self.getScope(), self.getQualifiedName(), self.getTag(), ( "Exception", ), self.getMembers() ).generate()


class JavaInclude(Include): pass


class JavaInterface(Interface, JavaPackage):
    def __init__( self, *args, **kwds ):
        Interface.__init__( self, *args, **kwds )
        JavaPackage.__init__( self )
            

class JavaMapType(MapType, JavaType):
    def generate( self ):
        class_header = self.getClassHeader()
        name = self.getName()
        key_boxed_type_name = self.getKeyType().getBoxedTypeName()
        key_toString_call = self.getKeyType().getToStringCall( "key" )
        value_boxed_type_name = self.getValueType().getBoxedTypeName()
        value_toString_call = self.getValueType().getToStringCall( "value" )
        serialize_methods = self.getSerializeMethods()
        deserialize_methods = self.getDeserializeMethods()
        other_methods = self.getOtherMethods()
        class_footer = self.getClassFooter()
        
        writeGeneratedFile( self.getFilePath(), """\
%(class_header)s
    public %(name)s()
    { }
github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
def getGetter( self, identifier ): return self.getDeclarationTypeName() + " get" + identifier[0].capitalize() + identifier[1:] + "() { return %(identifier)s; }" % locals()    
    def getSetter( self, identifier ): return "void set" + identifier[0].capitalize() + identifier[1:] + "( " + self.getDeclarationTypeName() + " %(identifier)s ) { this.%(identifier)s = %(identifier)s; }" % locals()
    def getToStringCall( self, identifier ): return "%(identifier)s.toString()" % locals()
                       

class JavaBoolType(BoolType, JavaType):
    def getBoxedTypeName( self ): return "Boolean"
    def getCastFromObject( self, source_identifier ): return "( Boolean )%(source_identifier)s" % locals()
    def getDeclarationTypeName( self ): return "boolean"
    def getDefaultInitializer( self, identifier ): return "%(identifier)s = false;" % locals()
    def getObjectDeserializeCall( self, source_identifier, dest_identifier ): return "%(dest_identifier)s = ( ( Boolean )%(source_identifier)s ).booleanValue();" % locals()
    def getObjectSerializeCall( self, identifier ): return "new Boolean( %(identifier)s )" % locals()
    def getToStringCall( self, identifier ): return "Boolean.toString( %(identifier)s )" % locals()    


class JavaBufferType(BufferType, JavaType):
    def getConstantValue( self, value ): return "\"%(value)s\"" % locals()
    def getDefaultInitializer( self, identifier ): return "%(identifier)s = null;" % locals()
    def getObjectDeserializeCall( self, source_identifier, dest_identifier ): declaration_type_name = self.getDeclarationTypeName(); return "%(dest_identifier)s = ( %(declaration_type_name)s )%(source_identifier)s;" % locals() 
    def getObjectSerializeCall( self, identifier ): return identifier        
    def getToStringCall( self, identifier ): return '"\\"" + %(identifier)s + "\\""' % locals()


class JavaConstant(Constant):
    def __repr__( self ):
        return "public static final " + self.getType().getDeclarationTypeName() + " " + \
            self.getIdentifier() + " = " + self.getType().getConstantValue( self.getValue() ) + ';'    


class JavaEnumeratedType(EnumeratedType, JavaType):
    def generate( self ):
        package_name = self.getPackageName()
github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
decl_type_name = self.getDeclarationTypeName()
        if decl_type_name == "int":
            return "%(dest_identifier)s = ( %(source_identifier)s instanceof Integer ) ? ( ( Integer )%(source_identifier)s ).intValue() : ( ( Long )%(source_identifier)s ).intValue();" % locals()
        elif decl_type_name == "long":
            return "%(dest_identifier)s = ( %(source_identifier)s instanceof Integer ) ? ( ( Integer )%(source_identifier)s ).longValue() : ( ( Long )%(source_identifier)s ).longValue();" % locals()
        else:
            return "%(dest_identifier)s = ( ( " % locals() + self.getBoxedTypeName() + " )%(source_identifier)s )." % locals() + self.getDeclarationTypeName() + "Value();"
     
    def getObjectSerializeCall( self, identifier ): 
        return "new " + self.getBoxedTypeName() + "( %(identifier)s )" % locals()
        
    def getToStringCall( self, identifier ): 
        return self.getBoxedTypeName() + ".toString( %(identifier)s )" % locals()


class JavaSequenceType(SequenceType, JavaType):
    def generate( self ):
        class_header = self.getClassHeader()
        constructors = self.getConstructors()
        toString_method = lpad( "\n", self.getToStringMethod() )
        serialize_methods = lpad( "\n", self.getSerializeMethods() )
        deserialize_methods = lpad( "\n", self.getDeserializeMethods() )
        other_methods = lpad( "\n", self.getOtherMethods() )
        class_footer = self.getClassFooter()
        writeGeneratedFile( self.getFilePath(), """\
%(class_header)s
%(constructors)s%(toString_method)s%(serialize_methods)s%(deserialize_methods)s%(other_methods)s
%(class_footer)s
""" % locals() )
    
    def getCastFromObject( self, source_identifier ): type.name = self.getName(); return "new %(name)s( ( Object[] )%(source_identifier)s )" % locals()
github xtreemfs / babudb / replication / share / yidl / src / yidl / java_target.py View on Github external
def getPackageDirPath( self ): return os.sep.join( self.getQualifiedName() )
    def getPackageName( self ): return ".".join( self.getQualifiedName() )           
            
        
class JavaType(JavaClass):  
    def getBoxedTypeName( self ): return self.getDeclarationTypeName()    
    def getConstantValue( self, value ): return value
    def getDeclarationTypeName( self ): return self.getName()
    def getDefaultInitializer( self, identifier ): name = self.getName(); return "%(identifier)s = new %(name)s();" % locals()        
    def getGetter( self, identifier ): return self.getDeclarationTypeName() + " get" + identifier[0].capitalize() + identifier[1:] + "() { return %(identifier)s; }" % locals()    
    def getSetter( self, identifier ): return "void set" + identifier[0].capitalize() + identifier[1:] + "( " + self.getDeclarationTypeName() + " %(identifier)s ) { this.%(identifier)s = %(identifier)s; }" % locals()
    def getToStringCall( self, identifier ): return "%(identifier)s.toString()" % locals()
                       

class JavaBoolType(BoolType, JavaType):
    def getBoxedTypeName( self ): return "Boolean"
    def getCastFromObject( self, source_identifier ): return "( Boolean )%(source_identifier)s" % locals()
    def getDeclarationTypeName( self ): return "boolean"
    def getDefaultInitializer( self, identifier ): return "%(identifier)s = false;" % locals()
    def getObjectDeserializeCall( self, source_identifier, dest_identifier ): return "%(dest_identifier)s = ( ( Boolean )%(source_identifier)s ).booleanValue();" % locals()
    def getObjectSerializeCall( self, identifier ): return "new Boolean( %(identifier)s )" % locals()
    def getToStringCall( self, identifier ): return "Boolean.toString( %(identifier)s )" % locals()    


class JavaBufferType(BufferType, JavaType):
    def getConstantValue( self, value ): return "\"%(value)s\"" % locals()
    def getDefaultInitializer( self, identifier ): return "%(identifier)s = null;" % locals()
    def getObjectDeserializeCall( self, source_identifier, dest_identifier ): declaration_type_name = self.getDeclarationTypeName(); return "%(dest_identifier)s = ( %(declaration_type_name)s )%(source_identifier)s;" % locals() 
    def getObjectSerializeCall( self, identifier ): return identifier        
    def getToStringCall( self, identifier ): return '"\\"" + %(identifier)s + "\\""' % locals()